Thread: cant think of what is wrong

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743

    Question cant think of what is wrong

    I am still having a little trouble with rotations.

    Here is some psuedocode, and the results of what is happening when i implement that version of the code.

    Version 1:

    glPushMatrix();
    translate to the pivot point
    rotate
    glPopMatrix();

    result: works as if glPushMatrix() and glPopMatrix never even occurred. it translates based off its world coordinate and rotates based off of its world coordinate.

    Version 2:

    glPushMatrix();
    glLoadIdentity();
    translate
    rotate
    glPopMatrix();

    result: rotates around "me" (being the viewer, or person walking around the world, as in a first person shooter).

    Version 3:

    glPushMatrix();
    load the mesh's matrix
    translate
    rotate
    glPopMatrix();

    result: the same as version 2

    i just cant figure out what is wrong...anybody have an idea?
    My Website

    "Circular logic is good because it is."

  2. #2
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    Okay, the first version should work, meaning you push and translate, and then rotate and pop. That is how it is done and will always work just as long as:

    1-the object is centered in the modelling program
    2-you don't have any push's or pop's that you don't know about hanging around before you got to #1, i.e if you pushed the matrix before doing #1, you're translating from the last matrix you pushed. I realize you're probably doing something like joint/skeletal animating where you need to push a matrix, then push down another matrix (i.e going from a shoulder to an arm or something). The most likely problem is that the number of push's don't equal the number of pop's, which is a common error when doing something complicated where body parts are connected.

    also, what do you mean by 'rotating based off of its world coordinate' ? Also, how are you doing the rotations? I've found that in order to get the rotations to work properly I need to rotate about the Y axis using glRotatef, and then rotate about the x axis second, not the other way around (assuming you even need both pitch and yaw rotations, which you very well may not). If you don't mind, post some code. I'll try to not lose it this time (I lost your project a whilea go when I was supposed to help).
    Last edited by Silvercord; 12-15-2003 at 06:57 PM.

  3. #3
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    I have attatched the entire file at the bottom if you want to take a look at it.

    Code:
    void MODEL_DTP::DrawModel	( void )
    {
    	ROTATE_DTP rotate;	//the current rotation that needs to be done
    	bool isRotate = false;			
    
    	//Push the matrix for rotation purposes
    	glPushMatrix ( );
    
    	//Do the rotations that need to be done on the rotation stack
    	while ( !rotation.empty() )
    	{
    		
    		rotate = rotation.top();
    		rotation.pop();
    		
    
    		if ( rotate.entireModel ) //if the rotation is being done on the entire 3d model
    		{
    			//glTranslatef ( rotate.pivotX, rotate.pivotY, rotate.pivotZ );
    			glRotatef ( rotate.rotateDeg, (rotate.rotateAxis == X),
    						(rotate.rotateAxis == Y), (rotate.rotateAxis == Z) );
    		}	
    		else if ( rotate.isRotationBlock ) //if the rotation is being done on a group of meshes
    		{
    			glPushMatrix ( );
    
    			glTranslatef ( rotate.pivotX, rotate.pivotY, rotate.pivotZ );
    
    			glRotatef ( rotate.xRot, 1.0, 0.0, 0.0 );
    			glRotatef ( rotate.yRot, 0.0, 1.0, 0.0 );
    			glRotatef ( rotate.zRot, 0.0, 0.0, 1.0 );
    
    			for ( int n = 0; n < UnitModel.GetMeshCount(); n++ )
    			{
    
    
    								if ( rotate.rotationBlockMeshID[n] )
    				{
    					glBindTexture ( GL_TEXTURE_2D, texture [MECH_METAL] );	
    					LMesh &mesh = UnitModel.GetMesh(n);
    		
    					// Texturing Contour Anchored To The Object
    					glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
    					// Texturing Contour Anchored To The Object
    					glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
    					glEnable(GL_TEXTURE_GEN_S);			// Auto Texture Generation
    					glEnable(GL_TEXTURE_GEN_T);			// Auto Texture Generation		
    
    					glVertexPointer(4, GL_FLOAT, 0, &mesh.GetVertex(0));
    					glNormalPointer(GL_FLOAT, 0, &mesh.GetNormal(0));
    					glColorPointer(3, GL_FLOAT, 0, &mesh.GetBinormal(0));
    					glDrawElements(GL_TRIANGLES, mesh.GetTriangleCount()*3, 
                            GL_UNSIGNED_SHORT, &mesh.GetTriangle(0));
    
    					//set the master list variable to true for this mesh
    					//so we know not to draw this mesh in the main drawing loop
    					rotationBlockMeshIDMasterList[n] = true;
    				}
    			}
    
    			glPopMatrix ( );
    		}
    		else //if the rotation is only being done on a single mesh
    		{
    			rotateMeshMatrix[rotate.rotateMeshID][rotate.rotateAxis] = rotate;
    		}
    	}
    	
    
    	//Do the drawing of the model after the rotating has been done
    	for (uint i= 0; i<UnitModel.GetMeshCount(); i++)
        {
    		isRotate =  (!rotateMeshMatrix[i][0].entireModel) ||
    					(!rotateMeshMatrix[i][1].entireModel) ||
    					(!rotateMeshMatrix[i][2].entireModel);
    
    		//Skip the drawing of this mesh, if it was part of a rotation block
    		//and no more rotations need to be done to it.
    		if ( rotationBlockMeshIDMasterList[i] )
    		{
    			rotationBlockMeshIDMasterList[i] = false; //resets it for the next frame			
    			continue;
    		}			
    		
    
    		if ( isRotate ) 
    		{
    			glPushMatrix ( );			
    			
    			if ( !rotateMeshMatrix[i][0].entireModel )
    				glRotatef ( rotateMeshMatrix[i][0].rotateDeg,
    							1.0f, 0.0f, 0.0f );
    			if ( !rotateMeshMatrix[i][1].entireModel )
    				glRotatef ( rotateMeshMatrix[i][1].rotateDeg,
    							0.0f, 1.0f, 0.0f );
    			if ( !rotateMeshMatrix[i][2].entireModel )
    				glRotatef ( rotateMeshMatrix[i][2].rotateDeg,
    							0.0f, 0.0f, 1.0f );
    		}
    
    		glBindTexture ( GL_TEXTURE_2D, texture [MECH_METAL] );	
            LMesh &mesh = UnitModel.GetMesh(i);
    		
    		// Texturing Contour Anchored To The Object
    		glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
    		// Texturing Contour Anchored To The Object
    		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
    		glEnable(GL_TEXTURE_GEN_S);			// Auto Texture Generation
    		glEnable(GL_TEXTURE_GEN_T);			// Auto Texture Generation
    
    		
    
            glVertexPointer(4, GL_FLOAT, 0, &mesh.GetVertex(0));
            glNormalPointer(GL_FLOAT, 0, &mesh.GetNormal(0));
            glColorPointer(3, GL_FLOAT, 0, &mesh.GetBinormal(0));
            glDrawElements(GL_TRIANGLES, mesh.GetTriangleCount()*3, 
                            GL_UNSIGNED_SHORT, &mesh.GetTriangle(0));
    
    		if ( isRotate )
    			glPopMatrix ( );
    		
    
        }
    
    	glDisable ( GL_TEXTURE_GEN_S );
    	glDisable ( GL_TEXTURE_GEN_T );
    
    	//Pop off the matrix
    	glPopMatrix ( );		
    
    }
    If you want to see the entire .cpp file, I will attatch it. Of course it will not compile because it needs the rest of the project to be able to do that, but it might be helpful to look at.
    Last edited by DavidP; 12-17-2003 at 01:27 AM.
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM