Reputation: 262
New to OpenGl I am trying to make sure i did this part right, im told to build the world matrix from the position, scaling and rotation information.
From the material i found online my understanding is
p^world = p^world∗p^Model
P^Model = Scaling * Rotation * Translation
Therefore i coded the following:
glm::mat4 Model::GetWorldMatrix() const
{
// @TODO 2, you must build the world matrix from the position, scaling and rotation informations
glm::mat4 pModel = GetScaling() * GetRotationAngle() * GetPosition();
glm::mat4 worldMatrix(1.0f);
worldMatrix = worldMatrix* pModel;
// @TODO 4 - Maybe you should use the parent world transform when you do hierarchical modeling
return worldMatrix;
}
void Model::SetPosition(glm::vec3 position)
{
mPosition = position;
}
void Model::SetScaling(glm::vec3 scaling)
{
mScaling = scaling;
}
void Model::SetRotation(glm::vec3 axis, float angleDegrees)
{
mRotationAxis = axis;
mRotationAngleInDegrees = angleDegrees;
}
Is this correct?? Thank you for your time and help.
Upvotes: 0
Views: 654
Reputation: 2455
The way to do it is to save one 4x4 Matrix for every Model. This matrix is although called the ModelMatrix.
All important informations (position,rotation,scale) of the object are saved in this matrix. If you want to translate,rotate or scale your object you generate a transformation matrix and multiply it from the left side to your model matrix. model = trafo * model;
You can generate these transformation matrices with GLM http://glm.g-truc.net/0.9.2/api/a00245.html .
Upvotes: 4