Finished camera for now
This commit is contained in:
parent
06614dd1b0
commit
a5ab0c9adb
|
@ -71,10 +71,9 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
oglu::Enable(GL_DEPTH_TEST);
|
oglu::Enable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
oglu::Camera camera(60.0f, 0.0f, 0.1f, 100.0f);
|
oglu::Camera camera(45.0f, 1.0f, 0.1f, 100.0f);
|
||||||
camera.Move(0.0f, -4.0f, -10.0f);
|
|
||||||
//camera.LookAt(utah);
|
float t = 0.0f;
|
||||||
//camera.GetMatrix();
|
|
||||||
|
|
||||||
// Window loop
|
// Window loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
|
@ -83,7 +82,8 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
oglu::ClearScreen(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f));
|
oglu::ClearScreen(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f));
|
||||||
|
|
||||||
utah.Rotate(0.0f, 1.0f, 0.0f);
|
camera.SetPosition(10.0f * cosf(t), -5.0f, 10.0f * sinf(t));
|
||||||
|
camera.LookAt(utah);
|
||||||
|
|
||||||
shader->Use();
|
shader->Use();
|
||||||
shader->SetUniform("model", utah);
|
shader->SetUniform("model", utah);
|
||||||
|
@ -95,6 +95,8 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
|
t += 0.01f;
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
|
|
||||||
namespace oglu
|
namespace oglu
|
||||||
{
|
{
|
||||||
class Object;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A camera object in 3D space.
|
* @brief A camera object in 3D space.
|
||||||
*
|
*
|
||||||
|
@ -88,7 +86,7 @@ namespace oglu
|
||||||
*
|
*
|
||||||
* @param[in] target An object to target
|
* @param[in] target An object to target
|
||||||
*/
|
*/
|
||||||
void LookAt(const Object& target);
|
void LookAt(const Transformable& target);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the projection matrix of the camera.
|
* @brief Gets the projection matrix of the camera.
|
||||||
|
|
|
@ -239,23 +239,23 @@ namespace oglu
|
||||||
*
|
*
|
||||||
* @returns A pointer to an array of floats
|
* @returns A pointer to an array of floats
|
||||||
*/
|
*/
|
||||||
const float* GetPosition();
|
const float* GetPosition() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get rotation as a matrix.
|
* @brief Get rotation as a matrix.
|
||||||
*
|
*
|
||||||
* @returns A pointer to a 4x4 matrix
|
* @returns A pointer to a 4x4 matrix
|
||||||
*/
|
*/
|
||||||
const float* GetRotation();
|
const float* GetRotation() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get scaling as a 3D vector.
|
* @brief Get scaling as a 3D vector.
|
||||||
*
|
*
|
||||||
* @returns A pointer to an array of floats
|
* @returns A pointer to an array of floats
|
||||||
*/
|
*/
|
||||||
const float* GetScaling();
|
const float* GetScaling() const;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
// TODO: Separate translation, rotation and scaling matrices.
|
// TODO: Separate translation, rotation and scaling matrices.
|
||||||
// Combine them only when the user wants the transformation matrix
|
// Combine them only when the user wants the transformation matrix
|
||||||
float* position; ///< Position vector
|
float* position; ///< Position vector
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtx/matrix_decompose.hpp>
|
||||||
|
#include <glm/gtx/quaternion.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
namespace oglu
|
namespace oglu
|
||||||
|
@ -51,14 +53,42 @@ namespace oglu
|
||||||
|
|
||||||
void Camera::LookAt(GLfloat x, GLfloat y, GLfloat z)
|
void Camera::LookAt(GLfloat x, GLfloat y, GLfloat z)
|
||||||
{
|
{
|
||||||
|
glm::mat4 newTransform = glm::lookAt(glm::make_vec3(position), glm::vec3(x, y, z), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
glm::vec3 scale;
|
||||||
|
glm::vec3 pos;
|
||||||
|
glm::quat rot;
|
||||||
|
glm::vec3 skew;
|
||||||
|
glm::vec4 pers;
|
||||||
|
glm::decompose(newTransform, scale, rot, pos, skew, pers);
|
||||||
|
|
||||||
|
memcpy(
|
||||||
|
position,
|
||||||
|
glm::value_ptr(pos),
|
||||||
|
3 * sizeof(float)
|
||||||
|
);
|
||||||
|
|
||||||
|
memcpy(
|
||||||
|
rotation,
|
||||||
|
glm::value_ptr(glm::toMat4(rot)),
|
||||||
|
16 * sizeof(float)
|
||||||
|
);
|
||||||
|
|
||||||
|
memcpy(
|
||||||
|
scaling,
|
||||||
|
glm::value_ptr(scale),
|
||||||
|
3 * sizeof(float)
|
||||||
|
);
|
||||||
|
calculateMatrix = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::LookAt(const GLfloat* target)
|
void Camera::LookAt(const GLfloat* target)
|
||||||
{
|
{
|
||||||
|
LookAt(target[0], target[1], target[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::LookAt(const Object& target)
|
void Camera::LookAt(const Transformable& target)
|
||||||
{
|
{
|
||||||
|
LookAt(target.GetPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
const float* Camera::GetProjectionMatrix()
|
const float* Camera::GetProjectionMatrix()
|
||||||
|
|
|
@ -250,17 +250,17 @@ namespace oglu
|
||||||
return transformation;
|
return transformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float* Transformable::GetPosition()
|
const float* Transformable::GetPosition() const
|
||||||
{
|
{
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float* Transformable::GetRotation()
|
const float* Transformable::GetRotation() const
|
||||||
{
|
{
|
||||||
return rotation;
|
return rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float* Transformable::GetScaling()
|
const float* Transformable::GetScaling() const
|
||||||
{
|
{
|
||||||
return scaling;
|
return scaling;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue