Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically, you're looking for a replacement of the opengl matrix stack to do your transformations.</p> <p>Assuming you are using c/c++, I suggest having a look at the GLM library : <a href="http://glm.g-truc.net/" rel="nofollow">http://glm.g-truc.net/</a></p> <p>It's a header-only library, easy to use and the perfect replacement for the pre-opengl es 2.0 matrix stack. It even provides functionality for deprecated glu functions like gluOrtho() and gluPerspective(). Glm's matrices can easily be passed to your shader as they are conceived with shaders in mind.</p> <p>You will have to make a few changes to your code; for instance converting your own vertex / matrix definitions to glm::vec3 / glm::mat4.</p> <p>Here's an example of how I construct my mvp matrix that I pass to the vertex shader: in this case the actorInstance class has a few attributes like position (in the world) and rotation defined as glm::vec3's. The constructed model, model/view and model/view/projection matrices are all a property of the class:</p> <pre><code>void CActorInstance::update(glm::mat4 viewMatrix, glm::mat4 projectionMatrix) { // act according to class behavior this-&gt;actorClass-&gt;act(&amp;input, &amp;world, &amp;direction, &amp;rotation); // calculate the translation matrix glm::mat4 translate = glm::mat4(); translate = glm::translate( glm::mat4(), world); // calculate the rotation matrix glm::mat4 rotateX = glm::rotate( glm::mat4(1.0f), rotation.x, glm::vec3(1,0,0)); glm::mat4 rotateY = glm::rotate( glm::mat4(1.0f), rotation.y, glm::vec3(0,1,0)); glm::mat4 rotateZ = glm::rotate( glm::mat4(1.0f), rotation.z, glm::vec3(0,0,1)); glm::mat4 rotate = rotateX * rotateY * rotateZ; // calculate the model matrix mMatrix = translate * rotate; // calculate the model/view matrix mvMatrix = viewMatrix * mMatrix; // calculate the model/view/projection matrix mvpMatrix = projectionMatrix * mvMatrix; }; </code></pre> <p>Obviously the mvp matrix for each object gets updated every frame according to the object's position and rotation. The viewMatrix and projectionMatrix are passed down from my camera class. That matrix is then used to render a mesh:</p> <pre><code> void CMesh::renderMesh(GLuint program, glm::mat4 *mvp) { glUseProgram(program); int mvpLocation = glGetUniformLocation(program, "mvpMatrix"); int texLocation = glGetUniformLocation(program, "baseMap"); glUniformMatrix4fv( mvpLocation, 1, GL_FALSE, glm::value_ptr(*mvp)); // rendering code ommitted }; </code></pre> <p>Hope this helps :)</p> <p><strong>EDIT</strong> : suggestions for implementing a matrix stack</p> <pre><code>stl::stack&lt;glm::mat4&gt; matrixStack; // the matrix stack matrixStack.push_back(glm::mat4()); // push an identity matrix on the stack </code></pre> <p>And that is your glLoadIdentity()...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload