使用花栗鼠物理学 - 我如何知道两个碰撞物体的力
如果我在花栗鼠中有两个物体(我使用的是 cocos2d-iphone),一旦我检测到它们发生碰撞,我如何知道它们彼此碰撞的力度有多大?
我希望他们的力(相对于速度)知道碰撞的损坏。
我见过关于如何做到这一点的讨论,但从未见过具体的工作代码(而且我无法让它工作,即使我认为我知道我在做什么。)为了完整起见,这里是我用来确定碰撞的速度,那么,我该如何准确地检测碰撞的力呢?
- (BOOL) handleCollisionBetweenBalls:(CollisionMoment)moment arbiter:(cpArbiter*)arb space:(cpSpace*)space {
JjrFootprint(@"handleCollisionBetweenBalls");
if (moment == COLLISION_BEGIN) {
JjrLog(@"Balls Collide");
CP_ARBITER_GET_SHAPES(arb, a, b);
cpVect va;
cpVect vb;
va = a->body->v;
vb = b->body->v;
cpVect vNet = cpvadd(va,vb);
cpFloat Length = cpvlength(vNet);
// 7 = barely touching
// 1000 = hard
if (Length > 100) {
[[SimpleAudioEngine sharedEngine] playEffect:@"board.wav"];
}
}
return YES;
}
谢谢, 杰杰
If I have two objects in chipmunk (I'm using cocos2d-iphone), once I've detected that they collided, how can I tell how hard they are hitting each other?
I want their force (vs. the velocity) to know the damage of the collision.
I've seen discussion about how to do this, but never concrete working code (and I couldn't get it work, even though I thought I knew what I was doing.) For completeness, here is the code that I am using to determine the Velocity of the collision, so, how, precisely, would I go about detecting the Force of a collision?
- (BOOL) handleCollisionBetweenBalls:(CollisionMoment)moment arbiter:(cpArbiter*)arb space:(cpSpace*)space {
JjrFootprint(@"handleCollisionBetweenBalls");
if (moment == COLLISION_BEGIN) {
JjrLog(@"Balls Collide");
CP_ARBITER_GET_SHAPES(arb, a, b);
cpVect va;
cpVect vb;
va = a->body->v;
vb = b->body->v;
cpVect vNet = cpvadd(va,vb);
cpFloat Length = cpvlength(vNet);
// 7 = barely touching
// 1000 = hard
if (Length > 100) {
[[SimpleAudioEngine sharedEngine] playEffect:@"board.wav"];
}
}
return YES;
}
Thanks,
JJ
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://chipmunk-physicals .net/release/Chipmunk-6.x/Chipmunk-6.0.3-Docs/#CollisionCallbacks-Handlers
您只能从解决后回调内部获取碰撞脉冲。
http://chipmunk-physics.net/release/Chipmunk-6.x/Chipmunk-6.0.3-Docs/#CollisionCallbacks-Handlers
You can only get the collision impulse from inside the post solve callback.