Cornell Cocos
Cornell Extensions to Cocos2d
CUWheelObstacle.h
1 //
2 // CUWheelObstacle.h
3 // Cornell Extensions to Cocos2D
4 //
5 // This class implements a circular Physics object. We do not use it in any of our
6 // samples, but it is included for your education. Note that the shape must be
7 // circular, not elliptical. If you want to make an ellipse, you will need to use
8 // the PolygonObstacle class.
9 //
10 // This file is based on the CS 3152 PhysicsDemo Lab by Don Holden, 2007
11 //
12 // Author: Walker White
13 // Version: 11/24/15
14 //
15 #ifndef __CU_WHEEL_OBSTACLE_H__
16 #define __CU_WHEEL_OBSTACLE_H__
17 
18 #include <Box2D/Collision/Shapes/b2CircleShape.h>
19 #include "CUSimpleObstacle.h"
20 
21 
22 NS_CC_BEGIN
23 
24 #pragma mark -
25 #pragma mark Wheel Obstacle
26 
35 class CC_DLL WheelObstacle : public SimpleObstacle {
36 private:
38  CC_DISALLOW_COPY_AND_ASSIGN(WheelObstacle);
39 
40 protected:
42  b2CircleShape _shape;
44  b2Fixture* _geometry;
45 
46 
47 #pragma mark -
48 #pragma mark Scene Graph Methods
49 
57  virtual void resetDebugNode() override;
58 
59 
60 public:
61 #pragma mark -
62 #pragma mark Static Constructors
63 
68  static WheelObstacle* create();
69 
82  static WheelObstacle* create(const Vec2& pos);
83 
97  static WheelObstacle* create(const Vec2& pos, float radius);
98 
99 
100 #pragma mark -
101 #pragma mark Dimensions
102 
107  float getRadius() const { return _shape.m_radius; }
108 
114  void setRadius(float value) { _shape.m_radius = value; markDirty(true); }
115 
116 
117 #pragma mark -
118 #pragma mark Physics Methods
119 
124  virtual void createFixtures() override;
125 
131  virtual void releaseFixtures() override;
132 
133 
134 
135 #pragma mark -
136 #pragma mark Initializers
137 CC_CONSTRUCTOR_ACCESS:
138  /*
139  * Creates a new wheel object at the origin.
140  */
141  WheelObstacle(void) : SimpleObstacle(), _geometry(nullptr) { }
142 
148  virtual bool init() override { return init(Vec2::ZERO,0.0); }
149 
162  virtual bool init(const Vec2& pos) override { return init(pos,0.0); }
163 
177  virtual bool init(const Vec2& pos, float radius);
178 };
179 
180 NS_CC_END
181 #endif /* defined(__CU_WHEEL_OBSTACLE_H__) */
b2Fixture * _geometry
Definition: CUWheelObstacle.h:44
Definition: CUWheelObstacle.h:35
virtual bool init() override
Definition: CUWheelObstacle.h:148
float getRadius() const
Definition: CUWheelObstacle.h:107
b2CircleShape _shape
Definition: CUWheelObstacle.h:42
virtual void createFixtures()
Definition: CUSimpleObstacle.h:792
virtual void releaseFixtures()
Definition: CUSimpleObstacle.h:799
Definition: CUSimpleObstacle.h:36
virtual void resetDebugNode()
Definition: CUObstacle.h:106
virtual bool init()
Definition: CUObstacle.h:982
void markDirty(bool value)
Definition: CUObstacle.h:758
virtual bool init(const Vec2 &pos) override
Definition: CUWheelObstacle.h:162
void setRadius(float value)
Definition: CUWheelObstacle.h:114