相机跟随玩家打开
Camera following player opengl
我一直在研究这个问题一段时间,但我找不到解决方案。现在我的相机正确地跟随球员的位置,但相机的旋转出错了。如果我只使用一个旋转,它会正确运行,比如说我只沿 x 轴旋转,那么它工作正常。但是当我添加另一个旋转的第二个说"y"事情出错并且相机开始看向错误的方向时。
现在我的相机只有一个位置和一个旋转。
下面是一些代码。
glm::vec4 cameraPosition;
//This gives the camera the distance it keaps from the player.
cameraPosition.x = 0.0;
cameraPosition.y = 0.0;
cameraPosition.z = 20.0;
cameraPosition.w = 0.0;
// mStartingModel is the rotation matrix of the player.
glm::vec4 result = mStartingModel * cameraPosition;
//here I set the camera's position and rotation. The z rotation is given a extra 180 degrees so the camera is behind the player.
CameraHandler::getSingleton().getDefaultCamera()->setPosition(Vector3f(-player->mPosition.x + result.x, -player->mPosition.y + result.y, -player->mPosition.z + result.z), Vector3f(-(player->mRotation.x + 180), -player->mRotation.y, -player->mRotation.z) );
也知道我正在使用opengl,c ++和glm。
如果你想要一个简单的行为,使用gluLookAt
可能是最简单的选择!更多信息在这里。
看到你使用glm
,考虑类似
glm::mat4 CameraMatrix = glm::LookAt(
cameraPosition, // the position of your camera, in world space
cameraTarget, // where you want to look at, in world space
upVector // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too
);
取自这个网站关于 opengl 教程。
相关文章:
- 跟随整数索引列表的自定义类迭代器
- 根据用户回答声明"Players"。用户选择玩家数量。播放器是结构体
- 玩家加速穿越世界(C++)
- C++:如何根据地形高度更新玩家身高?
- 预测玩家输赢,博弈论问题
- C++对玩家进行排序
- C++ 如何处理所有可能的玩家移动输入?
- 玩家中的%是什么意思=(玩家%2)?1:2;
- 为什么玩家控制器"own"偏航俯仰和滚动,但角色"owns"它的位置?
- 我在视觉工作室中制作了一个类似胭脂的游戏,我想显示玩家的生命值
- 在UE4中,玩家进行光线投射、击中物体并触发自定义事件C++
- 玩家移动和碰撞之间的交互问题
- 如何根据物体位置和速度,玩家位置和向前矢量计算左耳和右耳的音量?(3D声音)
- 在跟随中,哪个地方更有效率?
- 如何让"Enemies"围绕玩家运行?
- 在OpenGL中,如何将鼠标跟随更改为鼠标单击,拖动并移动释放?
- 相机跟随玩家打开
- 敌人不会跟随玩家。SDL2/C++
- 让敌方车辆跟随玩家车辆C++
- 如何让敌人在一定距离内随机循环并跟随玩家?c++主机游戏