简体   繁体   中英

Applying World Transform

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.

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 .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM