Permalink
Browse files

Tests: Improved Chipmunk test

  • Loading branch information...
1 parent a280559 commit b51028c6e376a1ce4ca5ea9e71ccd58a9cf4ff66 @ricardoquesada committed Jul 9, 2012
Showing with 24 additions and 16 deletions.
  1. +1 −0 CHANGELOG
  2. +23 −16 tests/ChipmunkAccelTouchTest.m
View
@@ -4,6 +4,7 @@ version 2.0.0 8-Jul-2012
. [FIX] Macros: CCLOGERROR defined in ccDeprecated as CCLOGWARN
. [FIX] Scheduler: removeUpdateFromHash calls [target release] at the very end to prevent a possible crash
. [FIX] Templates: Generate no-flicker-at-startup code
+ Improved Physics templates: multitouch and gravity+accel works OK
. [FIX] TexturePVR: wrong type when calculating PVR lenght
. [FIX] Xcode: Fixed compile errors and warnings in Xcode 4.5
. [3RD] libpng: updated to 1.2.49
@@ -131,11 +131,9 @@ -(void) initPhysics
CGSize s = [[CCDirector sharedDirector] winSize];
// init chipmunk
-// cpInitChipmunk();
space_ = cpSpaceNew();
-
- space_->gravity = cpv(0, -100);
+ cpSpaceSetGravity(space_, cpv(0, -100) );
//
// rogue shapes
@@ -154,8 +152,8 @@ -(void) initPhysics
walls_[3] = cpSegmentShapeNew( space_->staticBody, cpv(s.width,0), cpv(s.width,s.height), 0.0f);
for( int i=0;i<4;i++) {
- walls_[i]->e = 1.0f;
- walls_[i]->u = 1.0f;
+ cpShapeSetElasticity(walls_[i], 1.0f );
+ cpShapeSetFriction(walls_[i], 1.0f );
cpSpaceAddStaticShape(space_, walls_[i] );
}
}
@@ -228,12 +226,12 @@ -(void) addNewSpriteAtPosition:(CGPoint)pos
};
cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero));
-
- body->p = cpv(pos.x, pos.y);
+ cpBodySetPos( body, cpv(pos.x, pos.y) );
cpSpaceAddBody(space_, body);
cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero);
- shape->e = 0.5f; shape->u = 0.5f;
+ cpShapeSetElasticity( shape, 0.5f );
+ cpShapeSetFriction(shape, 0.5f );
cpSpaceAddShape(space_, shape);
[sprite setPhysicsBody:body];
@@ -261,20 +259,24 @@ - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
}
- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
-{
+{
static float prevX=0, prevY=0;
-
+
#define kFilterFactor 0.05f
-
+
float accelX = (float) acceleration.x * kFilterFactor + (1- kFilterFactor)*prevX;
float accelY = (float) acceleration.y * kFilterFactor + (1- kFilterFactor)*prevY;
-
+
prevX = accelX;
prevY = accelY;
-
- CGPoint v = ccp( accelX, accelY);
-
- space_->gravity = ccpMult(v, 200);
+
+ cpVect v;
+ if( [[CCDirector sharedDirector] interfaceOrientation] == UIInterfaceOrientationLandscapeRight )
+ v = cpv( -accelY, accelX);
+ else
+ v = cpv( accelY, -accelX);
+
+ cpSpaceSetGravity( space_, cpvmult(v, 200) );
}
#elif defined(__CC_PLATFORM_MAC)
@@ -340,6 +342,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}
+
+-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return UIInterfaceOrientationIsLandscape(interfaceOrientation);
+}
@end
#elif defined(__CC_PLATFORM_MAC)

0 comments on commit b51028c

Please sign in to comment.