glm::dvec3
时间: 2023-08-20 16:07:49 浏览: 298
glm::dvec3是一个双精度浮点数向量,用于表示三维空间中的坐标或方向。它由三个双精度浮点数组成,分别表示x、y和z轴上的分量。在使用glm库时,可以使用glm::dvec3来表示双精度浮点数向量。
#### 引用[.reference_title]
- *1* *2* *3* [总结GLM库中glm::transform(位移), glm:scale(缩放), glm::rotate(旋转)](https://blog.csdn.net/sinat_36301420/article/details/89372482)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关问题
glm::dvec3 头文件
根据提供的引用内容,glm::dvec3 头文件应该是 glm/glm.hpp。\[2\]在使用 glm::dvec3 类型之前,需要包含 glm/glm.hpp 头文件。
#### 引用[.reference_title]
- *1* *3* [关于 C/C++ 引入头文件的一点理解](https://blog.csdn.net/Wonz5130/article/details/83099566)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [总结GLM库中glm::transform(位移), glm:scale(缩放), glm::rotate(旋转)](https://blog.csdn.net/sinat_36301420/article/details/89372482)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
inline void Revolve(float fwdDist, float yawDifDeg, float pitchDifDeg) { float pitchDifRad = glm::radians(-pitchDifDeg); float yawDifRad = glm::radians(-yawDifDeg); constexpr float PITCH_LIMIT = glm::radians(60.f); pitchRad += pitchDifRad; // avoid deadlock if (pitchRad > PITCH_LIMIT) pitchRad = PITCH_LIMIT; else if (pitchRad < -PITCH_LIMIT) pitchRad = -PITCH_LIMIT; yawRad += yawDifRad; // avoid reaching float limit if (yawRad > glm::pi<float>()) yawRad -= 2 * glm::pi<float>(); else if (yawRad < -glm::pi<float>()) yawRad += 2 * glm::pi<float>(); auto center = pos + fwdDist * forward; { float cy = cosf(yawRad), sy = sinf(yawRad); float cp = cosf(pitchRad), sp = sinf(pitchRad); forward.x = cp * cy, forward.y = sp, forward.z = -cp * sy; forward = glm::normalize(forward); } right = glm::normalize(glm::cross(forward, worldUp)); up = glm::normalize(glm::cross(right, forward)); pos = center - fwdDist * forward; view[0][0] = right.x; view[1][0] = right.y; view[2][0] = right.z; view[0][1] = up.x; view[1][1] = up.y; view[2][1] = up.z; view[0][2] = -forward.x; view[1][2] = -forward.y; view[2][2] = -forward.z; view[3][0] = -glm::dot(right, pos); view[3][1] = -glm::dot(up, pos); view[3][2] = glm::dot(forward, pos); view[3][3] = 1.f; view[0][3] = view[1][3] = view[2][3] = 0; } 使用该方法实现当鼠标按下且同时移动时,相机旋转
要实现当鼠标按下且同时移动时相机旋转,你可以使用 GLFW 库的鼠标移动回调函数来获取鼠标的偏移量,然后根据偏移量来更新相机的旋转角度。以下是一个示例代码,说明如何在上述方法中实现该功能:
首先,在你的代码中添加一个全局变量来追踪鼠标的上一次位置:
```cpp
double lastX = 0.0;
double lastY = 0.0;
bool firstMouse = true;
```
然后,在你的 GLFW 鼠标移动回调函数中添加以下代码:
```cpp
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
{
if (firstMouse)
{
lastX = xpos;
lastY = ypos;
firstMouse = false;
}
float xoffset = xpos - lastX;
float yoffset = lastY - ypos; // 注意这里的坐标系,需要反过来计算
lastX = xpos;
lastY = ypos;
// 根据偏移量更新相机的旋转角度
Revolve(1.0f, xoffset, yoffset);
}
```
在这段代码中,我们首先检查 `firstMouse` 变量,如果是第一次移动鼠标,则将当前鼠标位置赋值给 `lastX` 和 `lastY`。然后,我们计算当前鼠标位置与上一次鼠标位置的偏移量 `xoffset` 和 `yoffset`。最后,我们将当前鼠标位置更新为上一次鼠标位置,并调用 `Revolve` 方法来根据偏移量更新相机的旋转角度。
记得在 `main` 函数中设置鼠标移动回调函数:
```cpp
glfwSetCursorPosCallback(window, mouse_callback);
```
这样,当鼠标按下且同时移动时,`mouse_callback` 函数将被触发,并更新相机的旋转角度。
阅读全文