Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Side by Side Diff: nacltoons/src/physics_layer.h

Issue 12387095: [nacltoons] Use box2d sensors to detect collisions. (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #ifndef PHYSICS_LAYER_H_ 4 #ifndef PHYSICS_LAYER_H_
5 #define PHYSICS_LAYER_H_ 5 #define PHYSICS_LAYER_H_
6 6
7 #include "cocos2d.h" 7 #include "cocos2d.h"
8 #include "Box2D/Box2D.h" 8 #include "Box2D/Box2D.h"
9 9
10 #ifdef COCOS2D_DEBUG 10 #ifdef COCOS2D_DEBUG
11 #include "GLES-Render.h" 11 #include "GLES-Render.h"
12 #endif 12 #endif
13 13
14 USING_NS_CC; 14 USING_NS_CC;
15 15
16 typedef std::vector<cocos2d::CCPoint> PointList; 16 typedef std::vector<cocos2d::CCPoint> PointList;
17 17
18 /** 18 /**
19 * Physics layer that the user interacts with. 19 * Physics layer that the user interacts with.
20 */ 20 */
21 class PhysicsLayer : public CCLayerColor { 21 class PhysicsLayer : public CCLayerColor, b2ContactListener {
binji 2013/03/04 19:31:13 public b2ContactListener
Sam Clegg 2013/03/04 20:08:18 Done.
22 public: 22 public:
23 PhysicsLayer(); 23 PhysicsLayer();
24 ~PhysicsLayer(); 24 ~PhysicsLayer();
25 25
26 // Add static create() method which encapsulates new + init 26 // Add static create() method which encapsulates new + init
27 CREATE_FUNC(PhysicsLayer); 27 CREATE_FUNC(PhysicsLayer);
28 28
29 virtual bool init(); 29 virtual bool init();
30 virtual void draw(); 30 virtual void draw();
31 virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event); 31 virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
32 virtual void ccTouchMoved(CCTouch* touch, CCEvent* event); 32 virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
33 virtual void ccTouchEnded(CCTouch* touch, CCEvent* event); 33 virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
34 virtual void registerWithTouchDispatcher(); 34 virtual void registerWithTouchDispatcher();
35 35
36 b2World* GetWorld() { return box2d_world_; } 36 b2World* GetWorld() { return box2d_world_; }
37 37
38 // Add the current (most recently created) instance. 38 // Add the current (most recently created) instance.
39 // Unfortunately this is needed by the lua bindings so the it can access the 39 // Unfortunately this is needed by the lua bindings so the it can access the
40 // GetWorld method. 40 // GetWorld method.
41 // TODO(sbc): find a way to do without this. 41 // TODO(sbc): find a way to do without this.
42 static PhysicsLayer* GetCurrent() { return current_instance_; } 42 static PhysicsLayer* GetCurrent() { return current_instance_; }
43 43
44 #ifdef COCOS2D_DEBUG 44 #ifdef COCOS2D_DEBUG
45 void ToggleDebug(); 45 void ToggleDebug();
46 #endif 46 #endif
47 47
48 // Called by box2d when contact occurs
49 void BeginContact(b2Contact* contact);
48 private: 50 private:
49 // Called by ccTouchesMoved to draw between two points 51 // Called by ccTouchesMoved to draw between two points
50 void DrawLine(CCPoint& start, CCPoint& end); 52 void DrawLine(CCPoint& start, CCPoint& end);
51 // Called by ccTouchesBegan to draw a single point. 53 // Called by ccTouchesBegan to draw a single point.
52 void DrawPoint(CCPoint& location); 54 void DrawPoint(CCPoint& location);
53 // Clamp brush location to within the visible area 55 // Clamp brush location to within the visible area
54 void ClampBrushLocation(CCPoint& point); 56 void ClampBrushLocation(CCPoint& point);
55 57
56 void AddLineToBody(b2Body *body, CCPoint start, CCPoint end); 58 void AddLineToBody(b2Body *body, CCPoint start, CCPoint end);
57 void AddSphereToBody(b2Body *body, CCPoint* location); 59 void AddSphereToBody(b2Body *body, CCPoint* location);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 101
100 #ifdef COCOS2D_DEBUG 102 #ifdef COCOS2D_DEBUG
101 // Debug drawing support for Box2D. 103 // Debug drawing support for Box2D.
102 GLESDebugDraw* box2d_debug_draw_; 104 GLESDebugDraw* box2d_debug_draw_;
103 // Flag to enable drawing of Box2D debug data. 105 // Flag to enable drawing of Box2D debug data.
104 bool debug_enabled_; 106 bool debug_enabled_;
105 #endif 107 #endif
106 }; 108 };
107 109
108 #endif // PHYSICS_LAYER_H_ 110 #endif // PHYSICS_LAYER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698