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

Unified Diff: nacltoons/src/physics_layer.cc

Issue 12380036: [nacltoons] Add design resolution. (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « nacltoons/src/physics_layer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: nacltoons/src/physics_layer.cc
diff --git a/nacltoons/src/physics_layer.cc b/nacltoons/src/physics_layer.cc
index 7fdd18d274cc087c92ff950d05c5c1f16d3cdaf1..d3c115299e892757dda87b09b4e285d66f1f0d9e 100644
--- a/nacltoons/src/physics_layer.cc
+++ b/nacltoons/src/physics_layer.cc
@@ -144,29 +144,24 @@ bool PhysicsLayer::InitPhysics() {
box2d_world_->SetAllowSleeping(true);
box2d_world_->SetContinuousPhysics(true);
+ // Find visible rect, and convert to box2d space.
+ CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
+ CCSize visible_size = CCDirector::sharedDirector()->getVisibleSize();
+ float world_width = SCREEN_TO_WORLD(visible_size.width);
+ b2Vec2 world_origin(SCREEN_TO_WORLD(origin.x), SCREEN_TO_WORLD(origin.y));
+
// create the ground
b2BodyDef groundBodyDef;
- groundBodyDef.position.Set(0, 0);
+ groundBodyDef.position = world_origin;
b2Body* groundBody = box2d_world_->CreateBody(&groundBodyDef);
- CCSize win_size = CCDirector::sharedDirector()->getWinSize();
- int world_width = SCREEN_TO_WORLD(win_size.width);
- int world_height = SCREEN_TO_WORLD(win_size.height);
+ CCLog("origin: %.fx%.f", origin.x, origin.y);
+ CCLog("size: %.fx%f", visible_size.width, visible_size.height);
// Define the ground box shape.
b2EdgeShape groundBox;
- // bottom
groundBox.Set(b2Vec2(0, 0), b2Vec2(world_width, 0));
groundBody->CreateFixture(&groundBox, 0);
- // top
- groundBox.Set(b2Vec2(0, world_height), b2Vec2(world_width, world_height));
- groundBody->CreateFixture(&groundBox, 0);
- // left
- groundBox.Set(b2Vec2(0, world_height), b2Vec2(0,0));
- groundBody->CreateFixture(&groundBox, 0);
- // right
- groundBox.Set(b2Vec2(world_width, world_height), b2Vec2(world_width, 0));
- groundBody->CreateFixture(&groundBox, 0);
#ifdef COCOS2D_DEBUG
box2d_debug_draw_ = new GLESDebugDraw(PTM_RATIO);
@@ -262,6 +257,7 @@ void PhysicsLayer::LevelComplete(CCNode* sender) {
}
void PhysicsLayer::DrawPoint(CCPoint& location) {
+ ClampBrushLocation(location);
render_target_->begin();
brush_->setPosition(ccp(location.x, location.y));
brush_->visit();
@@ -283,8 +279,26 @@ void PhysicsLayer::draw() {
#endif
}
+void PhysicsLayer::ClampBrushLocation(CCPoint& point) {
+ CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
+ CCSize visible_size = CCDirector::sharedDirector()->getVisibleSize();
+
+ float min_x = origin.x + brush_radius_;
+ float min_y = origin.y + brush_radius_;
+ if (point.x < min_x) point.x = min_x;
+ if (point.y < min_y) point.y = min_y;
+
+ float max_x = origin.x + visible_size.width - brush_radius_;
+ float max_y = origin.y + visible_size.height - brush_radius_;
+ if (point.x > max_x) point.x = max_x;
+ if (point.y > max_y) point.y = max_y;
+}
+
void PhysicsLayer::DrawLine(CCPoint& start, CCPoint& end)
{
+ ClampBrushLocation(start);
+ ClampBrushLocation(end);
+
// calculate distance moved
float distance = ccpDistance(start, end);
« no previous file with comments | « nacltoons/src/physics_layer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698