Hi,
I implemented a Contact listener with the following code:
(box2D Header file is already included in prefixHeader)
CollisionContactListener.h
class MyContactListener : public b2ContactListener {
}
CollisionContactListener.mm
#import "CollisionContactListener.h"
#import "Vehicle.h"
const int32 k_maxContactPoints = 2048;
struct ContactPoint
{
b2Fixture* fixtureA;
b2Fixture* fixtureB;
b2Vec2 normal;
b2Vec2 position;
b2PointState state;
};
int32 m_pointCount;
ContactPoint m_points[k_maxContactPoints];
void BeginContact(b2Contact* contact)
{
b2Fixture* fixtureA = contact->GetFixtureA();
b2Fixture* fixtureB = contact->GetFixtureB();
b2Body *bodyA = fixtureA->GetBody();
b2Body *bodyB = fixtureB->GetBody();
id userDataA = (id)bodyA->GetUserData();
id userDataB = (id)bodyB->GetUserData();
if([userDataA isKindOfClass:[Vehicle class] && userDataB isKindOfClass:[Vehicle class]){
Vehicle *vehicleA = (Vehicle*)userDataA;
Vehicle *vehicleB = (Vehicle*)userDataB;
if (vehicleA.currentLane != IZLaneOutOfScreen && vehicleB != IZLaneOutOfScreen) {
NSLog(@"Collision on Screen!!!");
}
}
}
void EndContact(b2Contact* contact)
{
NSLog(@"end contact");
}
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
const b2Manifold* manifold = contact->GetManifold();
}
void PostSolve(b2Contact* contact)
{
const b2ContactImpulse* impulse;
}
But I get errors , the compiler says that Vehicle was not declared and i get some errors like the following:
Vehicle.h:21: error: misplaced '@property' Objective-C++ construct
I tried to rename Vehicle.m to Vehicle.mm but the same errors occur.
What could i do?