Skip to content
Snippets Groups Projects
Commit 6eb92c3d authored by JonShard's avatar JonShard
Browse files

Impoved specular lights being a bit off in FREELOOK mode. ORBITAL mode is...

Impoved specular lights being a bit off in FREELOOK mode. ORBITAL mode is still not taking cam pos into account correctly.
parent 7ef6a672
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@ private:
float m_nearClip;
float m_farClip;
enum CameraMode m_cameraMode;
glm::vec3 m_modelSpacePos;
glm::mat4 getViewMatrix(glm::mat4 parentMatrix = glm::mat4(1));
glm::mat4 getModelToWorldMatrix(glm::mat4 parentMatrix = glm::mat4(1));
......
......@@ -10,6 +10,7 @@ EntityCamera::EntityCamera(C::Tag entityTag, int entityID,
float FOV, float aspectRatio, float nearClip, float farclip)
: Entity(entityTag, entityID, pos, rot, glm::vec3(1), vel, angVel) // default scale is 1.
{
m_modelSpacePos = pos;
m_cameraMode = camMode;
m_FOV = glm::radians<float>(FOV);
m_aspectRatio = aspectRatio;
......@@ -28,7 +29,7 @@ glm::mat4 EntityCamera::getModelToWorldMatrix(glm::mat4 parentModelMatrix)
rotation = glm::rotate(rotation, m_rotation.x, glm::vec3(1, 0, 0)); //Rotate in model space.
rotation = glm::rotate(rotation, m_rotation.z, glm::vec3(0, 0, 1));
worldPos = glm::translate(glm::mat4(1), glm::vec3(m_position.x, m_position.y, -m_position.z)); //Translate in world space.
worldPos = glm::translate(glm::mat4(1), glm::vec3(m_modelSpacePos.x, m_modelSpacePos.y, -m_modelSpacePos.z)); //Translate in world space.
if (m_cameraMode == FREELOOK)
{
......@@ -63,62 +64,62 @@ void EntityCamera::checkInput()
case FREELOOK:
if (Input::m_navKeyPressed[W])
{
m_position += glm::vec3(C::PanSensitivity * -glm::sin(m_rotation.y) * glm::cos(m_rotation.x),
m_modelSpacePos += glm::vec3(C::PanSensitivity * -glm::sin(m_rotation.y) * glm::cos(m_rotation.x),
C::PanSensitivity * glm::sin(m_rotation.x),
C::PanSensitivity * glm::cos(m_rotation.y) * glm::cos(m_rotation.x));
}
if (Input::m_navKeyPressed[S])
{
m_position += glm::vec3(C::PanSensitivity * glm::sin(m_rotation.y) * glm::cos(m_rotation.x),
m_modelSpacePos += glm::vec3(C::PanSensitivity * glm::sin(m_rotation.y) * glm::cos(m_rotation.x),
C::PanSensitivity * -glm::sin(m_rotation.x),
C::PanSensitivity * -glm::cos(m_rotation.y) * glm::cos(m_rotation.x));
}
if (Input::m_navKeyPressed[D])
{
m_position += glm::vec3(C::PanSensitivity * glm::cos(m_rotation.y) * glm::cos(m_rotation.x),
m_modelSpacePos += glm::vec3(C::PanSensitivity * glm::cos(m_rotation.y) * glm::cos(m_rotation.x),
0,
C::PanSensitivity * glm::sin(m_rotation.y) * glm::cos(m_rotation.x));
}
if (Input::m_navKeyPressed[A])
{
m_position += glm::vec3(-C::PanSensitivity * glm::cos(m_rotation.y) * glm::cos(m_rotation.x),
m_modelSpacePos += glm::vec3(-C::PanSensitivity * glm::cos(m_rotation.y) * glm::cos(m_rotation.x),
0,
-C::PanSensitivity * glm::sin(m_rotation.y) * glm::cos(m_rotation.x));
}
if (Input::m_navKeyPressed[Q])
{
m_position += glm::vec3(0, -C::PanSensitivity, 0);
m_modelSpacePos += glm::vec3(0, -C::PanSensitivity, 0);
}
if (Input::m_navKeyPressed[E])
{
m_position += glm::vec3(0, C::PanSensitivity, 0);
m_modelSpacePos += glm::vec3(0, C::PanSensitivity, 0);
}
break;
case ORBITAL:
if (Input::m_navKeyPressed[W])
{
m_position += glm::vec3(0, 0, C::PanSensitivity);
m_modelSpacePos += glm::vec3(0, 0, C::PanSensitivity);
}
if (Input::m_navKeyPressed[S])
{
m_position += glm::vec3(0, 0, -C::PanSensitivity);
m_modelSpacePos += glm::vec3(0, 0, -C::PanSensitivity);
}
if (Input::m_navKeyPressed[D])
{
m_position += glm::vec3(C::PanSensitivity, 0, 0);
m_modelSpacePos += glm::vec3(C::PanSensitivity, 0, 0);
}
if (Input::m_navKeyPressed[A])
{
m_position += glm::vec3(-C::PanSensitivity, 0, 0);
m_modelSpacePos += glm::vec3(-C::PanSensitivity, 0, 0);
}
if (Input::m_navKeyPressed[Q])
{
m_position += glm::vec3(0, -C::PanSensitivity, 0);
m_modelSpacePos += glm::vec3(0, -C::PanSensitivity, 0);
}
if (Input::m_navKeyPressed[E])
{
m_position += glm::vec3(0, C::PanSensitivity, 0);
m_modelSpacePos += glm::vec3(0, C::PanSensitivity, 0);
}
break;
}
......@@ -143,7 +144,7 @@ void EntityCamera::cycleMode()
void EntityCamera::update(float dt, glm::mat4 parentMatrix)
{
m_position += m_velocity * dt;
m_position = m_modelSpacePos + m_velocity + glm::vec3(parentMatrix[3]) * dt;
m_rotation += m_angularVelocity * dt;
m_cameraTransform.viewMatrix = getViewMatrix(parentMatrix);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment