mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-17 07:28:12 +08:00
[CORE][ADD] Ray class
This commit is contained in:
parent
44417cd6ec
commit
a924b4dd30
@ -119,6 +119,7 @@
|
|||||||
<ClCompile Include="modelthumbnailwidget.cpp" />
|
<ClCompile Include="modelthumbnailwidget.cpp" />
|
||||||
<ClCompile Include="pagewidget.cpp" />
|
<ClCompile Include="pagewidget.cpp" />
|
||||||
<ClCompile Include="pushbutton.cpp" />
|
<ClCompile Include="pushbutton.cpp" />
|
||||||
|
<ClCompile Include="ray.cpp" />
|
||||||
<ClCompile Include="renderable.cpp" />
|
<ClCompile Include="renderable.cpp" />
|
||||||
<ClCompile Include="roundedcornerwidget.cpp" />
|
<ClCompile Include="roundedcornerwidget.cpp" />
|
||||||
<ClCompile Include="sceneviewer.cpp" />
|
<ClCompile Include="sceneviewer.cpp" />
|
||||||
@ -140,6 +141,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="aboutpage.h" />
|
<QtMoc Include="aboutpage.h" />
|
||||||
|
<ClInclude Include="boundary.h" />
|
||||||
<ClInclude Include="camera.h" />
|
<ClInclude Include="camera.h" />
|
||||||
<QtMoc Include="editorpage.h" />
|
<QtMoc Include="editorpage.h" />
|
||||||
<QtMoc Include="framelesswindow.h" />
|
<QtMoc Include="framelesswindow.h" />
|
||||||
@ -154,6 +156,7 @@
|
|||||||
<QtMoc Include="roundedcornerwidget.h" />
|
<QtMoc Include="roundedcornerwidget.h" />
|
||||||
<QtMoc Include="scrolllistwidget.h" />
|
<QtMoc Include="scrolllistwidget.h" />
|
||||||
<QtMoc Include="modelthumbnailwidget.h" />
|
<QtMoc Include="modelthumbnailwidget.h" />
|
||||||
|
<ClInclude Include="ray.h" />
|
||||||
<ClInclude Include="skybox.h" />
|
<ClInclude Include="skybox.h" />
|
||||||
<ClInclude Include="texture.h" />
|
<ClInclude Include="texture.h" />
|
||||||
<ClInclude Include="utils.h" />
|
<ClInclude Include="utils.h" />
|
||||||
|
|||||||
@ -171,6 +171,9 @@
|
|||||||
<ClCompile Include="skybox.cpp">
|
<ClCompile Include="skybox.cpp">
|
||||||
<Filter>Source Files\OpenGL Abstractions</Filter>
|
<Filter>Source Files\OpenGL Abstractions</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="ray.cpp">
|
||||||
|
<Filter>Source Files\OpenGL Abstractions</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="camera.h">
|
<ClInclude Include="camera.h">
|
||||||
@ -218,6 +221,12 @@
|
|||||||
<ClInclude Include="skybox.h">
|
<ClInclude Include="skybox.h">
|
||||||
<Filter>Header Files\OpenGL Abstractions</Filter>
|
<Filter>Header Files\OpenGL Abstractions</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="boundary.h">
|
||||||
|
<Filter>Header Files\OpenGL Abstractions</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="ray.h">
|
||||||
|
<Filter>Header Files\OpenGL Abstractions</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="mainwindow.h">
|
<QtMoc Include="mainwindow.h">
|
||||||
|
|||||||
14
FinalProject/ray.cpp
Normal file
14
FinalProject/ray.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include "ray.h"
|
||||||
|
|
||||||
|
Ray Ray::toLocalSpace(glm::mat4 modelMatrix) {
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
23
FinalProject/ray.h
Normal file
23
FinalProject/ray.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <GLM/glm.hpp>
|
||||||
|
|
||||||
|
class Ray {
|
||||||
|
private:
|
||||||
|
glm::vec3 _origin;
|
||||||
|
glm::vec3 _direction;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Ray() {}
|
||||||
|
Ray(glm::vec3 origin, glm::vec3 direction) : _origin(origin), _direction(direction) {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline glm::vec3 origin() const { return _origin; }
|
||||||
|
inline glm::vec3 direction() const { return _direction; }
|
||||||
|
|
||||||
|
inline void setOrigin(glm::vec3 origin) { _origin = origin; }
|
||||||
|
inline void setDirection(glm::vec3 direction) { _direction = direction; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
Ray toLocalSpace(glm::mat4 modelMatrix);
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user