Using Camera

This topic contains 18 replies, has 3 voices, and was last updated by  dgu 4 years, 3 months ago.

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #31310

    hellboy
    Member

    Hi,

    I have a rectangle rendered. I want to move the camera along the line cutting the rectangle into half, say 0.1 units per frame. I went through the IntroducingPOD sample program. The problem is that the program uses CPVRTModelPOD class and hence has functions to get the world matrices etc. I have all the vertex data and index data stored in 2D arrays. I don’t know how to start the navigation of camera. Can someone help ?

    #37477

    dgu
    Member

    Hi

    everything is in the sample about camera ,did you change the value of vFrom over the time ? (maybe a nice as a plus Lerp function will make it )

    regards
    david

    #37478

    dgu
    Member

    all the beginner samples are superbe 🙂 i am still looking at it everyday 🙂

    #37479

    dgu
    Member

    some nice easing function for your camera : http://gizma.com/easing/

    #37480

    hellboy
    Member

    The function for navigation is not a problem for me. The problem is that I have prepared the “View” and the “Projection” matrices as :

    PVRTMat4 ViewMatrix = PVRTMat4::LookAtRH(vFrom, vTo, vUp);

    PVRTMat4 ProjectionMatrix = PVRTMat4::PerspectiveFovRH(DEG2RAD(fFOV), AspectRatio, CameraNear, CameraFar, PVRTMat4::OGL, rotate);

    PVRTMat4 ViewProjectionMatrix = ProjectionMatrix * ViewMatrix;

    But I don’t know what the “Model” matrix means and how should it be prepared.

    Additionally, I have passed the matrix as :

    int i32Location = glGetUniformLocation(m_uiProgramObject, “myPMVMatrix”);

    glUniformMatrix4fv(i32Location, 1, GL_FALSE, ViewProjectionMatrix.ptr());

    Is this correct ?

    #37481

    Joe Davis
    Member

    Hi,

    View & Projection matrices describe the camera position & how it sees the scene. The Model matrix (a.k.a. World matrix) describes your objects position in the scene, for example if it should be translated from it’s default position (0,0,0).

    #37482

    hellboy
    Member

    So, the matrix which is passed through glUniformMatrix4fv() is (P*M*V) or (P*V) ? Where should the model matrix be translated to from its default position ?

    #37483

    dgu
    Member

    Hello

    mTrans = PVRTMat4::Translation (x,y,z) for instance and
    mMVP = m_mProjection * mTrans * m_mView;

    of course the view is define by

    m_mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp);

    the model-view-projection matrix is pass to the shader to transform the vertices
    example :
    glUniformMatrix4fv(Uniforms[j].nLocation, 1, GL_FALSE, mMVP.f);
    regards
    david

    #37484

    hellboy
    Member

    Thanks David, but I can’t understand the idea behind translating the model matrix in the first place. Why is it needed ? Sorry for being so noob.

    What is the difference between mMVP.f and mMVP.ptr() ?

    #37485

    dgu
    Member

    No worry man, from the doc

    f= Array of float
    ptr=pointer to an array of float or element

    #37486

    hellboy
    Member

    And about the model matrix ?

    #37487

    dgu
    Member

    define your model view matrix as

    PVRTMat4 mMVP;
    mMVP = m_mProjection * mTrans * m_mView;

    The SDK provide a lot of sample about it , i am sure you will find the answer there as well

    regards
    david
    ps
    http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#The_Model_matrix

    #37488

    hellboy
    Member

    No, that’s not my question. I asked why is the translation (mTrans = PVRTMat4::Translation (x,y,z)) required ?

    #37489

    dgu
    Member

    in the demo your were looking at
    you saw
    // Pass the model-view-projection matrix (MVP) to the shader to transform the vertices

    		PVRTMat4 mModelView, mMVP;
    mModelView = mView * mWorld;
    mMVP = mProjection * mModelView;
    glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.f);

    like is said before as well you could change your view model only by changing the vFrom value depending where you camera should be.

    the translation that i introduce was to make life easier to move the camera as you like but it s not mandatory..a simple matrix calculation here

    #37490

    hellboy
    Member

    Some more questions.

    1. How is mWorld defined ?

    2. Will there be as many model matrices as there are meshes in the scene ? If yes, what will the model matrix be for a 3D box ?

    3. Will the values of x,y,z in Translation(x,y,z) be the coordinates of vFrom ?

Viewing 15 posts - 1 through 15 (of 19 total)
You must be logged in to reply to this topic.