CUGL
Cornell University Game Library
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
6 // our samples, but it is included for your education. Note that the shape
7 // must be circular, not elliptical. If you want to make an ellipse, you will
8 // need to use the PolygonObstacle class.
9 //
10 // This class uses our standard shared-pointer architecture.
11 //
12 // 1. The constructor does not perform any initialization; it just sets all
13 // attributes to their defaults.
14 //
15 // 2. All initialization takes place via init methods, which can fail if an
16 // object is initialized more than once.
17 //
18 // 3. All allocation takes place via static constructors which return a shared
19 // pointer.
20 //
21 // CUGL zlib License:
22 // This software is provided 'as-is', without any express or implied
23 // warranty. In no event will the authors be held liable for any damages
24 // arising from the use of this software.
25 //
26 // Permission is granted to anyone to use this software for any purpose,
27 // including commercial applications, and to alter it and redistribute it
28 // freely, subject to the following restrictions:
29 //
30 // 1. The origin of this software must not be misrepresented; you must not
31 // claim that you wrote the original software. If you use this software
32 // in a product, an acknowledgment in the product documentation would be
33 // appreciated but is not required.
34 //
35 // 2. Altered source versions must be plainly marked as such, and must not
36 // be misrepresented as being the original software.
37 //
38 // 3. This notice may not be removed or altered from any source distribution.
39 //
40 // This file is based on the CS 3152 PhysicsDemo Lab by Don Holden, 2007
41 //
42 // Author: Walker White
43 // Version: 11/6/16
44 //
45 #ifndef __CU_WHEEL_OBSTACLE_H__
46 #define __CU_WHEEL_OBSTACLE_H__
47 
48 #include <Box2D/Collision/Shapes/b2CircleShape.h>
49 #include "CUSimpleObstacle.h"
50 
51 
52 namespace cugl {
53 
54 #pragma mark -
55 #pragma mark Wheel Obstacle
56 
65 class WheelObstacle : public SimpleObstacle {
66 protected:
68  b2CircleShape _shape;
70  b2Fixture* _geometry;
71 
72 
73 #pragma mark -
74 #pragma mark Scene Graph Methods
75 
83  virtual void resetDebug() override;
84 
85 #pragma mark -
86 #pragma mark Constructors
87 public:
94  WheelObstacle(void) : SimpleObstacle(), _geometry(nullptr) { }
95 
105  virtual ~WheelObstacle() {
106  CUAssertLog(_geometry == nullptr, "You must deactive physics before deleting an object");
107  }
108 
114  virtual bool init() override { return init(Vec2::ZERO,0.0); }
115 
128  virtual bool init(const Vec2& pos) override { return init(pos,0.0); }
129 
143  virtual bool init(const Vec2& pos, float radius);
144 
145 
146 #pragma mark -
147 #pragma mark Static Constructors
148 
153  static std::shared_ptr<WheelObstacle> alloc() {
154  std::shared_ptr<WheelObstacle> result = std::make_shared<WheelObstacle>();
155  return (result->init() ? result : nullptr);
156  }
157 
170  static std::shared_ptr<WheelObstacle> alloc(const Vec2& pos) {
171  std::shared_ptr<WheelObstacle> result = std::make_shared<WheelObstacle>();
172  return (result->init(pos) ? result : nullptr);
173  }
174 
188  static std::shared_ptr<WheelObstacle> alloc(const Vec2& pos, float radius) {
189  std::shared_ptr<WheelObstacle> result = std::make_shared<WheelObstacle>();
190  return (result->init(pos,radius) ? result : nullptr);
191  }
192 
193 
194 #pragma mark -
195 #pragma mark Dimensions
196 
201  float getRadius() const { return _shape.m_radius; }
202 
208  void setRadius(float value) { _shape.m_radius = value; markDirty(true); }
209 
210 
211 #pragma mark -
212 #pragma mark Physics Methods
213 
218  virtual void createFixtures() override;
219 
225  virtual void releaseFixtures() override;
226 
227 };
228 
229 }
230 #endif /* __CU_WHEEL_OBSTACLE_H__ */
virtual void releaseFixtures() override
static std::shared_ptr< WheelObstacle > alloc(const Vec2 &pos)
Definition: CUWheelObstacle.h:170
WheelObstacle(void)
Definition: CUWheelObstacle.h:94
Definition: CUVec2.h:61
void markDirty(bool value)
Definition: CUObstacle.h:811
static std::shared_ptr< WheelObstacle > alloc(const Vec2 &pos, float radius)
Definition: CUWheelObstacle.h:188
virtual void createFixtures() override
virtual ~WheelObstacle()
Definition: CUWheelObstacle.h:105
void setRadius(float value)
Definition: CUWheelObstacle.h:208
Definition: CUSimpleObstacle.h:63
virtual bool init(const Vec2 &pos) override
Definition: CUWheelObstacle.h:128
float getRadius() const
Definition: CUWheelObstacle.h:201
Definition: CUWheelObstacle.h:65
virtual bool init() override
Definition: CUWheelObstacle.h:114
b2Fixture * _geometry
Definition: CUWheelObstacle.h:70
virtual void resetDebug() override
Definition: CUAnimationNode.h:52
static std::shared_ptr< WheelObstacle > alloc()
Definition: CUWheelObstacle.h:153
static const Vec2 ZERO
Definition: CUVec2.h:71
b2CircleShape _shape
Definition: CUWheelObstacle.h:68