mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-17 07:28:12 +08:00
14 lines
632 B
C++
14 lines
632 B
C++
#include "ray.h"
|
|
|
|
Ray Ray::toLocalSpace(glm::mat4 modelMatrix) const {
|
|
// The model matrix is the matrix that transforms local space to world space
|
|
// Therefore the inverse of the model matrix transforms world space to local space
|
|
glm::mat4 inversedModelMatrix = glm::inverse(modelMatrix);
|
|
|
|
// Transform the origin and direction of the ray to local space
|
|
glm::vec4 localOrigin = inversedModelMatrix * glm::vec4(_origin, 1.0f);
|
|
glm::vec4 localDirection = inversedModelMatrix * glm::vec4(_direction, 0.0f);
|
|
|
|
// Return the new ray
|
|
return Ray(glm::vec3(localOrigin), glm::vec3(localDirection));
|
|
} |