camera refactor

This commit is contained in:
Sandro Sobczyński
2020-11-05 14:53:42 +01:00
parent eba254f13b
commit b11df0262e
4 changed files with 34 additions and 13 deletions
+25 -1
View File
@@ -24,13 +24,37 @@ public:
CameraBase(ScreenSettings *t_screen, Vector3 *t_position, Vector3 *t_up); CameraBase(ScreenSettings *t_screen, Vector3 *t_position, Vector3 *t_up);
virtual ~CameraBase(){}; virtual ~CameraBase(){};
void updatePlanes(Vector3 t_target); /**
* Frustum planes.
* Set by lookAt() method.
*/
Plane planes[6]; Plane planes[6];
/**
* Projection matrix
* Set by lookAt() method.
*/
Matrix worldView; Matrix worldView;
protected: protected:
/** Pointer to screen settings */
ScreenSettings *screen; ScreenSettings *screen;
/**
* Adaption of OpenGL lookAt camera.
* Calculates worldView matrix and update frustum planes
* Should be called every frame.
*/
void lookAt(Vector3 &t_target);
/**
* Do not call this method unless you know what you do.
* Called via lookAt().
* Calculate and update frustum planes.
* http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-extracting-the-planes/
*/
void updatePlanes(Vector3 t_target);
private: private:
Vector3 *p_position, *p_up; Vector3 *p_position, *p_up;
float farPlaneDist, nearPlaneDist, nearHeight, nearWidth, farHeight, farWidth; float farPlaneDist, nearPlaneDist, nearHeight, nearWidth, farHeight, farWidth;
+6 -7
View File
@@ -18,10 +18,6 @@
// Constructors/Destructors // Constructors/Destructors
// ---- // ----
/** Initializes vars and calculate width/height of near and far plane
* @param fov (FOV in radians)/2
* @param ratio Aspect ratio
*/
CameraBase::CameraBase(ScreenSettings *t_screen, Vector3 *t_position, Vector3 *t_up) CameraBase::CameraBase(ScreenSettings *t_screen, Vector3 *t_position, Vector3 *t_up)
: screen(t_screen) : screen(t_screen)
{ {
@@ -42,9 +38,12 @@ CameraBase::CameraBase(ScreenSettings *t_screen, Vector3 *t_position, Vector3 *t
// Methods // Methods
// ---- // ----
/** Calculates and updates frustum planes void CameraBase::lookAt(Vector3 &t_target)
* http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-extracting-the-planes/ {
*/ updatePlanes(t_target);
worldView.lookAt(*p_up, *p_position, t_target);
}
void CameraBase::updatePlanes(Vector3 t_target) void CameraBase::updatePlanes(Vector3 t_target)
{ {
Vector3 nearCenter, farCenter, X, Y, Z; Vector3 nearCenter, farCenter, X, Y, Z;
+2 -3
View File
@@ -39,9 +39,8 @@ void Camera::update(Pad &t_pad, Mesh &t_mesh)
{ {
rotate(t_pad); rotate(t_pad);
followBy(t_mesh); followBy(t_mesh);
updatePlanes(t_mesh.position); // TODO move it out Vector3 lookPos = Vector3(t_mesh.position.x, t_mesh.position.y + 10.0F, t_mesh.position.z);
Vector3 newPos = Vector3(t_mesh.position.x, t_mesh.position.y + 10.0F, t_mesh.position.z); lookAt(lookPos);
worldView.lookAt(up, position, newPos);
} }
/** Set camera rotation by pad right joy and update unit circle /** Set camera rotation by pad right joy and update unit circle
+1 -2
View File
@@ -39,8 +39,7 @@ void Camera::update(Pad &t_pad, Mesh &t_mesh)
{ {
rotate(t_pad); rotate(t_pad);
followBy(t_mesh); followBy(t_mesh);
updatePlanes(t_mesh.position); lookAt(t_mesh.position);
worldView.lookAt(up, position, t_mesh.position);
} }
/** Set camera rotation by pad right joy and update unit circle /** Set camera rotation by pad right joy and update unit circle