The first part of the prgm part states
In the Camera class, implement the ViewProjection transform, the projection transform is already implemented, and the view transform is implemented in the Static Camera class
My camera Class contains this snippet
glm::mat4 Camera::GetViewProjectionMatrix() const
{
// @TODO 1 - Calculate View Projection Matrix
glm::mat4 viewProjection(1.0f); // identity, you need to change this
return viewProjection;
}
glm::mat4 Camera::GetProjectionMatrix() const
{
return glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
}
and my StaticCamera Class contains
StaticCamera::StaticCamera(glm::vec3 position, glm::vec3 lookAtPoint, glm::vec3 upVector)
: Camera(), mPosition(position), mLookAtPoint(lookAtPoint), mUpVector(upVector)
{
}
StaticCamera::~StaticCamera()
{
}
void StaticCamera::Update(float dt)
{
EventManager::EnableMouseCursor();
}
glm::mat4 StaticCamera::GetViewMatrix() const
{
return glm::lookAt( mPosition, // Camera position
mLookAtPoint, // Look towards this point
mUpVector // Up vector
);
}
so what I understood was to calculate MVP therefore can i add this to the Camera Class ?
glm::mat4 Camera::GetViewProjectionMatrix() const
{
// @TODO 1 - Calculate View Projection Matrix
glm::mat4 viewProjection(1.0f); // identity, you need to change this
//Our ModelViewProjection : multiplication of our 3 matrices
glm::mat4 MVP = viewProjection * GetViewMatrix() * GetViewProjectionMatrix();
return MVP;
}
Thank you for your help in advance!
You are usually using 3 Matrices:
Model-Matrix - Descripes the Object
View-Matrix - Descripes position and direction of the camera
Proj-Matrix - Descripes camera parameters like field of view etc.
A combination of these matrices for example the ViewProjectionMatrix is just a multiplication of the base matrices.
mat4 ViewProj= Proj*View; //note: order is reversed
You need:
glm::mat4 Camera::GetViewProjectionMatrix() const
{
return GetProjectionMatrix() * GetViewMatrix();
}
The transforms are applied intuitively in the following order:
Model -> View -> Projection
The model matrix brings the object into world space. The view matrix brings the world into view/camera space. The projection matrix then projects the view space into a 2D projected space.
Because matrix multiplication is applied 'backwards', you get:
Projection * View * Model
In this case your function is returning just the ViewProjection matrix and not the ModelViewProjection, so you apply only those transforms.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.