Skip to content

Commit

Permalink
changed collision callbacks to properties: colliding and collidingWit…
Browse files Browse the repository at this point in the history
…h in cc3phycisobject3d
  • Loading branch information
fu5ha committed Jul 2, 2011
1 parent 960b1a0 commit 55eb4d8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified Bullet Wrapping/.DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions Bullet Wrapping/Wrapper/CC3PhysicsObject3D.h
Expand Up @@ -48,6 +48,8 @@ class btRigidBody;
btCollisionShape *_shape;
btPoint2PointConstraint *p2p;
BOOL isStatic;
BOOL colliding;
CC3PhysicsObject3D * collidingWith;

}

Expand All @@ -70,6 +72,10 @@ class btRigidBody;
*/
@property (readonly) BOOL isStatic;

@property (nonatomic, assign) BOOL colliding;

@property (nonatomic, assign) CC3PhysicsObject3D * collidingWith;

/**
* Initialises the CC3PhysicsObject3D with an CC3Node and a btRigidBody.
* @param node The CC3Node.
Expand Down
4 changes: 4 additions & 0 deletions Bullet Wrapping/Wrapper/CC3PhysicsObject3D.mm
Expand Up @@ -38,13 +38,17 @@ @implementation CC3PhysicsObject3D
@synthesize rigidBody = _rigidBody;
@synthesize shape = _shape;
@synthesize isStatic;
@synthesize colliding;
@synthesize collidingWith;

- (id) initWithNode:(CC3Node *)node andRigidBody:(btRigidBody *)rigidBody isStatic:(BOOL)isstatic {
if ((self = [super init])) {
_node = [node retain];
_rigidBody = rigidBody;
_shape = _rigidBody->getCollisionShape();
isStatic = isstatic;
colliding = NO;
collidingWith = nil;

}

Expand Down
3 changes: 2 additions & 1 deletion Bullet Wrapping/Wrapper/CC3PhysicsWorld.h
Expand Up @@ -50,6 +50,7 @@ class btCollisionShape;

NSDate * _lastStepTime;
NSMutableArray * _physicsObjects;
NSMutableArray * _collidingObjects;
CC3PhysicsObject3D *_collisionObject1;
CC3PhysicsObject3D *_collisionObject2;

Expand Down Expand Up @@ -110,6 +111,6 @@ class btCollisionShape;
*/
- (CC3PhysicsObject3D *) createPhysicsObject:(CC3Node *)node shape:(btCollisionShape *)shape mass:(float)mass restitution:(float)restitution position:(CC3Vector)position;

- (void) onCollision:(CC3PhysicsObject3D *)object1 body2:(CC3PhysicsObject3D *)object2 point1:(CC3Vector)point1 point2:(CC3Vector)point2;
- (NSMutableArray *) getCollidingObjects;

@end
24 changes: 21 additions & 3 deletions Bullet Wrapping/Wrapper/CC3PhysicsWorld.mm
Expand Up @@ -46,6 +46,7 @@ - (id) init {
solver = new btSequentialImpulseConstraintSolver();
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
[self setDiscreteDynamicsWorld:dynamicsWorld];
_collidingObjects = [[NSMutableArray alloc] init];
}

return self;
Expand All @@ -56,6 +57,7 @@ - (void) dealloc

[_lastStepTime release];
[_physicsObjects release];
[_collidingObjects release];
delete broadphase;
delete dynamicsWorld;
delete collisionConfiguration;
Expand Down Expand Up @@ -141,6 +143,7 @@ - (void) synchTransformation {
int numManifolds = _discreteDynamicsWorld->getDispatcher()->getNumManifolds();
for (int i=0;i<numManifolds;i++)
{
NSMutableArray *_thisCollidingObjects = [[[NSMutableArray alloc] init] autorelease];
btVector3 ptA;
btVector3 ptB;
int objectNum = 0;
Expand All @@ -166,21 +169,36 @@ - (void) synchTransformation {
} else {
_collisionObject2 = object;
}
if (object.colliding) {
[_thisCollidingObjects addObject:object];
} else {
[_collidingObjects addObject:object];
[_thisCollidingObjects addObject:object];
object.colliding = YES;
}
}
}
_collisionObject1.collidingWith = _collisionObject2;
_collisionObject2.collidingWith = _collisionObject1;
for (CC3PhysicsObject3D *object in _collidingObjects) {
if (![_thisCollidingObjects containsObject:object]) {
[_collidingObjects removeObject:object];
object.colliding = NO;
object.collidingWith = nil;
}
}
CC3Vector cptA = cc3v(ptA.getX(), ptA.getY(), ptA.getZ());
CC3Vector cptB = cc3v(ptB.getX(), ptB.getY(), ptB.getZ());
[self onCollision:_collisionObject1 body2:_collisionObject2 point1:cptA point2:cptB];
}
}

- (void) setGravity:(float)x y:(float)y z:(float)z {
_discreteDynamicsWorld->setGravity(btVector3(x, y, z));
}

- (void) onCollision:(CC3PhysicsObject3D *)object1 body2:(CC3PhysicsObject3D *)object2 point1:(CC3Vector)point1 point2:(CC3Vector)point2
- (NSMutableArray *) getCollidingObjects
{

return _collidingObjects;
}

- (CC3PhysicsObject3D *) createPhysicsObject:(CC3Node *)node shape:(btCollisionShape *)shape mass:(float)mass restitution:(float)restitution position:(CC3Vector)position {
Expand Down

0 comments on commit 55eb4d8

Please sign in to comment.