#### Archived

This topic is now archived and is closed to further replies.

# Manual vs. Matrix translation

This topic is 5642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, this should be an easy one. Here''s the setup for my modelview:
	glLoadIdentity();
gluLookAt(mCamZoom(0), mCamZoom(0)*1.25, mCamZoom(0),
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);

After this, I call the DrawMesh function, which translates the mesh (the entire mesh shares a single x,y, & z for translation), then sets up pointers for DrawElements. Works dandy. But I wanted better performance, and each drawn mesh is stored seperately, so I figured I''d just add the x,y & z to each vertex in those meshes rather than translating them each pass. It didn''t work...some of them all clustered in the center of the screen this way, and the rest are off in la-la land somewhere. I know I must have done something obvious and stupid, but I''m stumped.

##### Share on other sites
Sounds like something is wrong with the modelview matrix during drawing. Could be caused by a lot of things. My guess is this: you were pushing and popping it during the draw sequence. But now you are drawing the vertices one by one (aren''t you) and now the order is completely wrong...

It may sound like a silly advise, but boy, you don''t know how often I made a really stupid mistake and found myself debugging until 3 am before I found it.

Best advise: test your algorithm with something really simply (just a triangle) and see what happens.

Good luck!

##### Share on other sites
Maybe it helps when you show your algorith that changes the relative coors. of the vertices to absolute coors.

##### Share on other sites
quote:
Sounds like something is wrong with the modelview matrix during drawing. Could be caused by a lot of things. My guess is this: you were pushing and popping it during the draw sequence. But now you are drawing the vertices one by one (aren''t you) and now the order is completely wrong...

In the Draw sequence, I do have a PushMatrix at the very beginning (before doing any rotation), and a PopMatrix at the very end. Taking them out and explicitly setting up the view for each mesh render didn''t change anything except performance.

quote:
Maybe it helps when you show your algorith that changes the relative coors. of the vertices to absolute coors.

Fair enough. I''m loading the coordinates from a custom mesh file. Here are the relevant lines:

RootMesh[MeshIndex].vertices.push_back(fParseVerts[0]+x);
RootMesh[MeshIndex].vertices.push_back(fParseVerts[1]+y);
RootMesh[MeshIndex].vertices.push_back(fParseVerts[2]+z);

I''m passing x,y, and z to the LoadMesh function. Previously, I simply set the Mesh x,y, and z translations to these values, then did a translate in the draw function with them. So my change was simply to add these to the coords on loading, and not translate later.

##### Share on other sites
So am I doomed to glTranslatef everything?

##### Share on other sites
glTranslate will operate on the current rotational matrix NOTE this can (good chance) be different than adding x,y,z to a vertex

http://uk.geocities.com/sloppyturds/gotterdammerung.html

##### Share on other sites
quote:
glTranslate will operate on the current rotational matrix NOTE this can (good chance) be different than adding x,y,z to a vertex

Understood, but this wasn''t the issue. The issue was that I was a n00b idiot with C++...

I am storing meshes in a vector, and storing vertices in vectors inside this (vector in a vector). For optimization, I was checking to see if a mesh had been previously loaded, and if so, I was copying the vector to the new vector...

I was running into pointer vs. value, in other words. Once I figured it out, the problem was solved.

You may all beat on me now.