如何朝面向方向移动第一人称对象?(C )
How to Move a First-Person Object in the Facing Direction? (C++)
我正在在子弹中重现一个基本的厄运,并想知道如何朝我的对象面对的方向移动。
目前,我的框架正在设置,我的相机将其旋转和位置设置为播放器,谁的位置和旋转设置为由子弹创建的物理主体。
这是我目前针对玩家运动的运动代码:
GameObject::Update( deltatime );
if( m_pController == 0 )
return;
vec3 dir(0, 0, 0);
vec3 rot(0, 0, 0);
if( m_pController->IsButtonPressed( PCB_Up ) )
dir.z += 1;
if( m_pController->IsButtonPressed( PCB_Down ) )
dir.z -= 1;
if( m_pController->IsButtonPressed( PCB_Left ) )
dir.x -= 1;
if( m_pController->IsButtonPressed( PCB_Right ) )
dir.x += 1;
if (m_pController->IsButtonPressed(PCB_RotLeft))
rot.y -= 1;
if (m_pController->IsButtonPressed(PCB_RotRight))
rot.y += 1;
dir.Normalize();
rot.Normalize();
float speed = 10.0f;
btVector3 force = btVector3(dir.x, dir.y, dir.z) * speed;
btVector3 rotForce = btVector3(rot.x, rot.y, rot.z) * speed;
if( m_pBody )
{
m_pBody->applyForce( force, btVector3(0,0,0) );
m_pBody->applyTorque(rotForce);
m_pBody->forceActivationState( DISABLE_DEACTIVATION );
}
我知道可以通过从相机创建一个矩阵并提取视图来完成,但事实是我的相机正在设置为播放器的旋转和翻译。
可以通过使用我的物理体值创建SRT矩阵并从这些数字中计算方向向量,然后具有:
来完成:if( m_pController->IsButtonPressed( PCB_Up ) )
dir += ForwardFacing;
if( m_pController->IsButtonPressed( PCB_Down ) )
dir -= ForwardFacing;
我不确定如何为左右钥匙完成。
无论如何,感谢您的时间!
是的。
mat4 mat;
mat.CreateSRT(m_Scale, m_Rotation, m_Position);
vec3 forceDir = mat.GetAt() * dir.z + mat.GetRight()*dir.x;
btVector3 force = btVector3(forceDir.x, forceDir.y, forceDir.z) * speed;
btVector3 rotForce = btVector3(rot.x, rot.y, rot.z) * speed;
相关文章:
- 我有两个类需要在同一 cpp 文件中相互引用,但第一个类无法识别第二个类类型的对象
- "main"函数堆栈中的对象在第一个任务运行时被覆盖 (FreeRTOS)
- 如何从对象/类中找到第一个字段?
- 在C++到第一个对象中创建第二个对象时,第一个对象会去哪里?
- C++ : 如何在使用 getline() 和 ifstream 对象从文件中读取一行时跳过第一个空格?
- 访问指向对象指针向量的指针的第一个元素?
- 初始化类构造函数初始化列表中的对象数组的第一个条目
- 基于Quaternion的第一人称视图相机
- 如何朝面向方向移动第一人称对象?(C )
- C++ std::队列推送弹出两个不同的对象获取第一个对象
- OpenGL第一人称摄像机不移动
- OpenGL-第一人称相机矩阵出现问题
- 3D第一人称摄像机以角度扫射
- 使用四元数方向的第一人称摄像机中的钳制间距
- 在第一人称视图和第三人称视图之间切换(OpenGL)
- OpenGL第一人称相机旋转和平移
- 第一人称相机,旋转OPENGL
- c++第一人称相机在directx
- 可扩展的第一人称射击在c++
- C++DirectX第一人称相机