Thread: glTranslatef(); not working with verts loaded from file

  1. #1
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071

    Question glTranslatef(); not working with verts loaded from file

    Iv'e loaded in 3D model verticies from a .raw file, and rendered it to the screen. However, when I try to use glTranslatef(); to move the object around, it dosn't work. glScalef(); and glRotatef(); do work on the object however.
    Anyone know why this is?

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Well I can tell you from experience that the glTranslatef() function works as expected, but without seeing any code I can't tell you why it's not working for you. You are calling glTranslatef() before drawing the vertices, right?

  3. #3
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    vertex loading and rendering functions:
    Code:
    void fFormat::LoadVerticies()
    {
    	// Create a file pointer and load the model from a file of vertices
    	FILE *fp = fopen(FILE_NAME, "r");
    
    	// Make sure we opened the file correctly and it was found
    	if(!fp) 
    		MessageBox(NULL, "Can't Open File", "Error", MB_OK);
    
    	// Create a temporary variable to hold what we read in from the file
    	CVector3 vTemp;
    
    	// Read in the number of vertices that are stored in the file
    	while(1)
    	{
    		// Read in a vertice and get the return value. If it's EOF we are done reading
    		int result = fscanf(fp, "%f %f %f\n", &vTemp.x, &vTemp.y, &vTemp.z);
    														
    
    		// If we hit End Of File then we are done reading in the vertices, break
    		if(result == EOF) 
    			break;
    
    		// Increase the vertice count
    		g_NumberOfVerts++;
    	}
    
    	// Allocate the needed memory to hold the vertices
    	pp_3DF     = new CVector3 [ g_NumberOfVerts ];
    
    	// Go back to the beginning of the file so we can store the vertices now
    	rewind(fp);
    
    	// Create a counter for the index of the g_vWorld[] array
    	int index = 0;
    
    	// Read in the vertices that are stored in the file
    	for(int i = 0; i < g_NumberOfVerts; i++)
    	{
    		// Read in the current vertice and at the end, then add 1 to the index
    		fscanf(fp, "%f %f %f\n", &pp_3DF[ index ].x, 
    								 &pp_3DF[ index ].y, 
    								 &pp_3DF[ index ].z);
    											 
    		index++;				// Increase our index for the vertex list
    	}
    
    	// Close our file because we are done
    	fclose(fp);
    }
    
    void fFormat::RenderFile()
    {
    	glBindTexture(GL_TEXTURE_2D, g_Texture[0]);
    	glBegin(GL_TRIANGLES);								// This is our BEGIN to draw the polys
    	
    	// Go through all the vertices and draw them
    	for(int i = 0; i < g_NumberOfVerts; i += 3)
    	{
    		glTexCoord2f(pp_3DF[i].x, pp_3DF[i].y); glVertex3f(pp_3DF[i].x, pp_3DF[i].y, pp_3DF[i].z);
    		glTexCoord2f(pp_3DF[i+1].x, pp_3DF[i+1].y); glVertex3f(pp_3DF[i+1].x, pp_3DF[i+1].y, pp_3DF[i+1].z);
    		glTexCoord2f(pp_3DF[i+2].x, pp_3DF[i+2].y); glVertex3f(pp_3DF[i+2].x, pp_3DF[i+2].y, pp_3DF[i+2].z);
    	}
    	
    	glEnd();	
    }
    rendering function
    Code:
    void OGLrender::Render()
    {
    	// clear screen and depth buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     
        glLoadIdentity();
    	
    	gCam.Look();
    	
    	_glDynaLight->DefaultLight();
    	//_glGeometry->DrawGrid(300);
    	//glRotatef(rotation, 1, 1, 1);
    	//_glGeometry->DrawSolidCube(0, 0, 0, 1.0, 1.0, 1.0); //Draw solid cube with default position and size. Will become dependant on user input.	
    	_glskyBox->RenderSkyBox(0, 0, 0, 750, 750, 370);
    	_glTerrain->DrawTerrain();
    	glScalef(0.04, 0.04, 0.04);
    	glRotatef(225, 0, 1, 0);
    	glTranslatef(0, 0, -10);
    	_gl3DF->RenderFile();
    	_gl2D->DrawCrosshair(gCam.m_vView.x, gCam.m_vView.y, gCam.m_vView.z);
    	//rotation += 0.1;
    }
    Last edited by psychopath; 01-12-2005 at 05:58 PM.
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    Probably not the problem but, the functions which end in 'f' eg glTranslatef() mean that the parameters are type float.

  5. #5
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    no, I don't think thats it either, because glScalef() and glRotatef() work.

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I bet the glTranslatef() function is working just fine, you just can't tell. You are only translating along the z axis, and if your perspective is set to orthographic you would never see a difference. Try translating along the x or y axis, and see if that works.

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    also try translating it first before you rotate
    See you in 13

  8. #8
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    I bet the glTranslatef() function is working just fine, you just can't tell. You are only translating along the z axis, and if your perspective is set to orthographic you would never see a difference. Try translating along the x or y axis, and see if that works.
    Ok, thanks, that worked. I thought I was in perspective mode. Guess not

    -psychopath
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  4. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM