box2d * cocos2d *にContactListenerを実装しようとしています。そして、 NSNotificationCenterをPostSolve関数に統合したい のですが、オブジェクトをポイントしようとすると、パラメーター:エラーが発生します:
No viable conversion from 'MyContact' to 'id'
NSNotificationCenterを介してMyContactオブジェクトを送信するにはどうすればよいですか?
MyContactListenerクラス
//
// MyContactListener.m
// Box2DPong
//
// Created by Ray Wenderlich on 2/18/10.
// Copyright 2010 Ray Wenderlich. All rights reserved.
//
#import "MyContactListener.h"
#import "ConfigMacro.h"
MyContactListener::MyContactListener() : _contacts(),_contactsObjects(){}
MyContactListener::~MyContactListener() {}
void MyContactListener::BeginContact(b2Contact* contact) {
b2Body *bodyA = contact->GetFixtureA()->GetBody();
b2Body *bodyB = contact->GetFixtureB()->GetBody();
if(bodyA->GetUserData() != NULL && bodyB->GetUserData() != NULL)
{
MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
_contacts.push_back(myContact);
}
}
void MyContactListener::EndContact(b2Contact* contact) {
MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
std::vector<MyContact>::iterator pos;
pos = std::find(_contacts.begin(), _contacts.end(), myContact);
if (pos != _contacts.end()) {
_contacts.erase(pos);
}
}
void MyContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold) {}
void MyContactListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) {
b2Body *bodyA = contact->GetFixtureA()->GetBody();
b2Body *bodyB = contact->GetFixtureB()->GetBody();
if(bodyA->GetUserData() != NULL && bodyB->GetUserData() != NULL)
{
int32 count = contact->GetManifold()->pointCount;
float32 maxImpulse = 0.0f;
b2Vec2 collision;
for (int32 i = 0; i < count; ++i) {
maxImpulse = b2Max(maxImpulse, impulse->normalImpulses[i]);
if (i == 0) {
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
collision = worldManifold.points[0];
}
}
MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB(), maxImpulse, collision };
[[NSNotificationCenter defaultCenter] postNotificationName:kReceivedImpulse object:myContact userInfo:nil];
}
}