获取碰撞的总冲量值--chipmunk spacemanager cocos2d
我正在使用 spacemanager,我想计算物体碰撞的力,以便我可以根据损坏情况调整声音和适当的精灵。谁能告诉我如何计算力。这是我在这个网站上得到的代码。
if(!cpArbiterIsFirstContact(arb)) return;
cpFloat 脉冲 = cpvlength(cpArbiterTotalImpulse(arb));
浮子体积 = MIN(脉冲/500.0f, 1.0f); NSLog(@"脉冲是:%f",音量);
NSLog(@" 脉冲 x:%fy:%f", cpArbiterTotalImpulse(arb).x , cpArbiterTotalImpulse(arb).y); if(体积>0.05f){ [SimpleSound playSoundWithVolume:音量]; 我在 POSTSOLVE 方法中有这个。
我也在 BEGIN 中尝试过它,它打印的所有内容都是 0。我浏览了这个网站,发现我需要这样做。 smgr.space->elasticIterations = smgr.space->iterations;
即使完成上述操作后,有时我会得到 1,有时它会显示“nan”。有什么我需要知道的基本知识吗?
谢谢
i am using spacemanager and i want to calculate the force with which the objects collide so that i can adjust the sounds and appropirate spirtes depending on the damage. can some one tell me how to calculate the forces. here is the code i got on this site.
if(!cpArbiterIsFirstContact(arb)) return;
cpFloat impulse = cpvlength(cpArbiterTotalImpulse(arb));
float volume = MIN(impulse/500.0f, 1.0f);
NSLog(@"impulse is :%f",volume);
NSLog(@" impluse x:%f y:%f", cpArbiterTotalImpulse(arb).x , cpArbiterTotalImpulse(arb).y);
if(volume > 0.05f){
[SimpleSound playSoundWithVolume:volume];
}
i have this in my POSTSOLVE method.i tried it in BEGIN aswell and all it prints is 0. i went through this site and found that i needs to do this.
smgr.space->elasticIterations = smgr.space->iterations;
even after doing the above , sometimes i get 1 and some times it says "nan". is there something basic i need to know?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 cpArbiterTotalImpulse() 的文档:
From the documentation for cpArbiterTotalImpulse():