Skip to content

Commit

Permalink
Tests: Improved Chipmunk test
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoquesada committed Jul 9, 2012
1 parent a280559 commit b51028c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -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
Expand Down
39 changes: 23 additions & 16 deletions tests/ChipmunkAccelTouchTest.m
Expand Up @@ -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
Expand All @@ -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] );
}
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -340,6 +342,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

return YES;
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
@end

#elif defined(__CC_PLATFORM_MAC)
Expand Down

0 comments on commit b51028c

Please sign in to comment.