gpt4 book ai didi

c++ - 如何根据方向/幅度 vector 和碰撞三角形偏转方向/幅度 vector ?

转载 作者:太空宇宙 更新时间:2023-11-04 14:25:09 24 4
gpt4 key购买 nike

所以,我有一个 Triangle->AABB 碰撞算法,我让它返回 AABB 碰撞的三角形。我希望三角形的 3 个 vector 和运动的方向/幅度能让我确定一个偏转 vector ,这样当你以一个角度撞墙时,你移动得更慢,这取决于碰撞的角度,但沿着侧面墙。这将消除只有在没有碰撞时才移动的粘性碰撞问题。任何建议或引用将不胜感激!谢谢。

最佳答案

首先,我会将幅度/方向转换为 vector (这样更方便)。

然后(C++):

float towards=dot(velocity,norm);  // velocity component into triangle
if(towards<0) // is moving into triangle
velocity-=towards*norm; // remove component

那么它不能移动到三角形中。 towards<0可能需要根据您的正常情况进行逆转。有 Spring 力将其推出也很不错。

关于c++ - 如何根据方向/幅度 vector 和碰撞三角形偏转方向/幅度 vector ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4575331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com