Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Using matrix stack - my code seems to modify the whole stack

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    5

    Using matrix stack - my code seems to modify the whole stack

    I want to place objects using matrix stack, but the following code seems to modify the whole stack, so that using stack becomes a nonsense. What would you do in order to use stack? I need it to create a simple tree.

    Code :
    MatrixStack store;
     
    void DrawTree1(glutil::MatrixStack &modelMatrix)
    {
    	int branches=3;
    	float bl=14.0f;
    	float ratio=0.55f;
    	float bl1=bl*ratio;
    	float bl2=bl1*ratio;
    	float bl3=bl2*ratio;
    	float r=0.9f;
    	float x=20.0f;
    	float y=20.0f;
    	float z=0.5f;
    	float z1=1.0f;
    	float z2=1.5f;
    	float z3=2.0f;
    	float alpha=30.0f;
     
    	modelMatrix.Translate(glm::vec3(x, bl/2, y));
    	glutil::PushStack push(modelMatrix);
    	modelMatrix.Scale(glm::vec3(r, bl, r));
    	glUseProgram(UniformColorTint.theProgram);
    	glUniformMatrix4fv(UniformColorTint.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
    	glUniform4f(UniformColorTint.baseColorUnif, 0.5f, 0.5f, 0.5f, 0.0f);
    	g_pCubeTintMesh->Render();
    	glUseProgram(0);
     
    	for(int i=0;i<=branches;i++)
    	{
    //		z=1.0f;
    		glutil::PushStack pop(modelMatrix);
    		glutil::PushStack push(modelMatrix);
    		modelMatrix.Translate(glm::vec3(0, bl/2, 0));
    		modelMatrix.RotateZ(alpha+sin(i*3.0f)*10.0f);
    		modelMatrix.Translate(glm::vec3(0, bl1/2, 0));
    		modelMatrix.Scale(1.0f,ratio,1.0f);
    		glUseProgram(UniformColorTint.theProgram);
    		glUniformMatrix4fv(UniformColorTint.modelToWorldMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top()));
    		glUniform4f(UniformColorTint.baseColorUnif, 0.5f, 0.5f, 0.5f, 0.0f);
    		g_pCubeTintMesh->Render();
    		glUseProgram(0);
    	}
    }
    Last edited by chromosom; 06-03-2014 at 06:30 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •