mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-04-19 01:32:58 +02:00
add camera view dir helper
This commit is contained in:
parent
49ed05dfd6
commit
f5eb0e0dfa
@ -51,20 +51,7 @@ void Camera3D::updateView(void) {
|
|||||||
pitch = glm::clamp(pitch, -(glm::pi<float>()/2 - 0.00001f), glm::pi<float>()/2 - 0.00001f);
|
pitch = glm::clamp(pitch, -(glm::pi<float>()/2 - 0.00001f), glm::pi<float>()/2 - 0.00001f);
|
||||||
yaw = glm::mod(yaw, 2*glm::pi<float>());
|
yaw = glm::mod(yaw, 2*glm::pi<float>());
|
||||||
|
|
||||||
glm::vec3 front {0,0,0};
|
glm::vec3 front = getViewDir();
|
||||||
{ // TODO: optimize
|
|
||||||
// if y up/down
|
|
||||||
front.x += up.y * glm::cos(pitch) * glm::cos(-yaw); // TODO: y is yaw inverted??
|
|
||||||
front.y += up.y * glm::sin(pitch);
|
|
||||||
front.z += up.y * glm::cos(pitch) * glm::sin(-yaw);
|
|
||||||
|
|
||||||
// if z up/down
|
|
||||||
front.x += up.z * glm::cos(pitch) * glm::cos(yaw);
|
|
||||||
front.y += up.z * glm::cos(pitch) * glm::sin(yaw);
|
|
||||||
front.z += up.z * glm::sin(pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
front = glm::normalize(front);
|
|
||||||
|
|
||||||
_view = glm::lookAt(translation, translation + front, up);
|
_view = glm::lookAt(translation, translation + front, up);
|
||||||
}
|
}
|
||||||
@ -82,6 +69,27 @@ glm::mat4 Camera3D::getProjection() const {
|
|||||||
return _projection;
|
return _projection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 Camera3D::getViewDir(void) const {
|
||||||
|
glm::vec3 front {0,0,0};
|
||||||
|
{ // TODO: optimize
|
||||||
|
#if 0
|
||||||
|
// if y up/down
|
||||||
|
front.x += up.y * glm::cos(pitch) * glm::cos(-yaw); // TODO: y is yaw inverted??
|
||||||
|
front.y += up.y * glm::sin(pitch);
|
||||||
|
front.z += up.y * glm::cos(pitch) * glm::sin(-yaw);
|
||||||
|
#else
|
||||||
|
// if z up/down
|
||||||
|
front.x += up.z * glm::cos(pitch) * glm::cos(yaw);
|
||||||
|
front.y += up.z * glm::cos(pitch) * glm::sin(yaw);
|
||||||
|
front.z += up.z * glm::sin(pitch);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
front = glm::normalize(front);
|
||||||
|
|
||||||
|
return front;
|
||||||
|
}
|
||||||
|
|
||||||
std::array<glm::vec4, 6> Camera3D::getFrustumPlanes(void) const {
|
std::array<glm::vec4, 6> Camera3D::getFrustumPlanes(void) const {
|
||||||
ZoneScopedN("Camera3D::getFrustumPlanes")
|
ZoneScopedN("Camera3D::getFrustumPlanes")
|
||||||
|
|
||||||
|
@ -47,6 +47,8 @@ namespace MM::OpenGL {
|
|||||||
glm::mat4 getView(void) const;
|
glm::mat4 getView(void) const;
|
||||||
glm::mat4 getProjection(void) const;
|
glm::mat4 getProjection(void) const;
|
||||||
|
|
||||||
|
glm::vec3 getViewDir(void) const;
|
||||||
|
|
||||||
// call updateView beforehand, does not cache
|
// call updateView beforehand, does not cache
|
||||||
std::array<glm::vec4, 6> getFrustumPlanes(void) const;
|
std::array<glm::vec4, 6> getFrustumPlanes(void) const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user