• Popular Now

• 15
• 15
• 11
• 9
• 10

Archived

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

Rottating without glRotatef()

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

Recommended Posts

Hey folks, I have a simple 3D engine I am building. I don't want to use matrix transforms because it will muss with a bunch of my other math and I don't want to rewrite everything. The game loads in a model and then the drawing code works like this:
    v = obj->numFaces;

glBegin(GL_TRIANGLES);
for(i = 0; i <= v; i++)
{
f = obj->face[i];

uv = obj->uvface[i];

glTexCoord2f(obj->uv[uv].y, obj->uv[uv].x);
glVertex3f(obj->vertex[f].x + x,   obj->vertex[f].y, obj->vertex[f].z + z);
}
glEnd();

Now, I want to rotate the object around the y axis. I am assuming that I can apply some sort of equation to the x and z values of each vertex that will inturn create a rotating effect around the objects y axis. I belive I would use sin() and cos() to do this. But I am as of yet unsure as to how to go about it. Basicaly I want to give the object an angle, then modify the x and z values per vertex to rotate it. If anyone can help I would really apreciate it! Thanx. [edited by - psyjax on March 29, 2004 7:45:56 PM]

Share on other sites
just maintain a set of orientations for each class. don't actually change the values of the vertices just draw them transformed like so:

glPushMatrix();
glRotatef(xAngle, 1,0,0); //x rot
glRotatef(yAngle, 0,1,0); //y rot
glRotatef(zAngle, 0,0,1); //z rot

DrawModel();

glPopMatrix();

that will draw it transformed and won't mess with any of your math.

-me

[edited by - Palidine on March 29, 2004 7:51:47 PM]

Share on other sites
hrmmm...

Well, maybe I chose the wrong way to draw my map. Let me explain.

See the code in my first post wehere an x and z variable are added to the vertexes. Well, these are equivilant to positions on a 2D map array.

Just as in a 2D game you would take two coordinates of a map and translate your sprite accordingly, so is my 3D game doing with it's objects.

Problem is, when I use the matrix transforms it also drasticaly affects where the objects are placed, as x and z now mean something totaly different given the new matrix. Thus the gameboard apears normal, and the objects land in the wrong areas all together.

I was hopeing someone could tell me how I could get an object to rotate by manipulating the vertex alone, that way I could get it to spin within its own "tile".

[edited by - psyjax on March 29, 2004 8:09:08 PM]

Share on other sites
either change your game object positions to be in accordance with the openGL axes (reccommended), or fudge the meanings of x,y,z in your classes:

the fudged version"

glPushMatrix();//do your rotatesglRotatef(...);//or whatever fudged order is appropriate to get the objs in the '//right placeglTranslatef(z,y,x); glPopMatrix();

[EDIT: SERIOUSLY consider changing your x/y/z coords to work properly with openGL. it really shouldn't take that long and it's going to make your life 1,000 times easier. it's silly that you are trying to engineer complicated solutions to a trivial problem simply because your data is wrong and you don't want to spend the time fixing it. you'll eventually get to situations where you really really want to use the openGL functions and can't and at that point you really will have too much data & code to change. also, getting in the habit of throwing out code when you find a better solution is really good practice for professional development. there are plenty of times where you realize a better way to do things and have to change a bunch of things to get it working. to do otherwise is foolish.]

-me

[edited by - Palidine on March 29, 2004 8:20:17 PM]

Share on other sites
Paladine. Ya... I think yor right. It would be better to rewrite the object possitioning functions around the OpenGL matrix manipulations.

The engine started ontop of an old 2D tiling engine, so I figured I wouldn''t stray to far from the origional design, but I think you make a good point regarding the availability of regular OpenGL commands versus some hacks.

Thanks again.