View Full Version : Vertex Rotations...

Sephiroth

09-28-2002, 01:08 PM

OK, say I have an object made of two triangles (like a wall that is paper-thin). I can already compute the exact middle of the object as a vertex, but how would I then rotate the two triangles' vertices around the center vertex? I need to actually move the points in memory and not use glRotatef() to rotate it when drawn. How is this done? Right now my only concern is rotating on the Y (up/down) axis. What I mean is rotation that, if you were looking down at the map from up high, rotation like a clock's hands. How is this done?

To rotate about a point not located at the origin, you must first translate the point to the origin, rotate, and then translate back. If you only want to rotate about the Y-axis, you only have to transate the object in the XZ-plane, so the center vertex's X and Y coordinates are zero.

In OpenGL-code, it would look like this. This will rotate about the point (x,y,z).

glTranslate(x, y, z); // translate point of rotation back to it's original place

glRotate(...); // rotate

glTranslate(-x, -y, -z); // translate point of rotation to the origin

If the rotation is only about the Y-axis, y in the above code can be replaced by 0.

nexusone

09-28-2002, 04:10 PM

So you do not want to use glRotate command.

Do you want to do the rotation inside openGL by using the gl matrix?

Or you want rotate the points, in there data array?

But the easy way would be to use glRotate.

Originally posted by Sephiroth:

OK, say I have an object made of two triangles (like a wall that is paper-thin). I can already compute the exact middle of the object as a vertex, but how would I then rotate the two triangles' vertices around the center vertex? I need to actually move the points in memory and not use glRotatef() to rotate it when drawn. How is this done? Right now my only concern is rotating on the Y (up/down) axis. What I mean is rotation that, if you were looking down at the map from up high, rotation like a clock's hands. How is this done?

Sephiroth

09-28-2002, 04:45 PM

I need to change the actual vertex coordinates. See I am near-completing my world editor, so I need to vertex locations EXACTLY where they will appear in the game. The game engine (OpenGL) will simply read in all the vertices and draw them as-is. The engine itself does NOT rotate them or modify them in any way unless the object is a "mover", but that stuff is coded into the world memory location so OpenGL still does nothing but provide a grogeous and fast display. Will using this "glMatrix" function or whatever change the vertex data in memory so when I save the vertex it will save the vertices as the appear on-screen? If so, how do I use this function?

Jambolo

09-28-2002, 11:31 PM

You basically have to implement code to do exactly what OpenGL does. You can find this stuff everywhere - search for "3D transformations". Every 3D graphics book has a chapter on it. There are lots of math libraries available. If you write a math library from scratch (I don't recommend it), you need to implement matrix and vector multiplication functions, and functions to build rotation and translation matrices.

nexusone

09-29-2002, 03:57 AM

First remember OpenGL does not have a camera per say, it moves the world to be in front of the camera. So every part of your world data will be rotated and translate at some point by openGL anyway.

You could do as you say all the vertex rotation yourself, but why do something that can be done in openGL already. And make things over complicated

If you let openGL handle moving the world around all you need to do is keep track of the moving objects on the map and tell openGL there new location.

Originally posted by Sephiroth:

I need to change the actual vertex coordinates. See I am near-completing my world editor, so I need to vertex locations EXACTLY where they will appear in the game. The game engine (OpenGL) will simply read in all the vertices and draw them as-is. The engine itself does NOT rotate them or modify them in any way unless the object is a "mover", but that stuff is coded into the world memory location so OpenGL still does nothing but provide a grogeous and fast display. Will using this "glMatrix" function or whatever change the vertex data in memory so when I save the vertex it will save the vertices as the appear on-screen? If so, how do I use this function?

Sephiroth

09-29-2002, 08:33 AM

The primary reason is that there is also a D3D renderer. I need the world to be stored properly so D3D can look at it also. Not everybody owns an nVidia card with 100% OpenGL support, and many own ATI cards and Matrox cards, which generally (from personal experience of myself and friends) have minor problems with OpenGL (for instance, ATI Radeon 8500LE makes OpenGL super-dark when compared to an nVidia anything). I need D3D support for owners of video cards like these or ones that are no-name brands, such as ones built into a motherboard.

I've found rotation tutorials but they all start about 6 light-years over my head. I keep wondering "wtf is a dotproduct?", or "where the heck did that value magically appear from?", and other such stuff. I need a tutorial that doesn't take a nine-year college course in math to understand. I am in college (had two years of it) but although I can code C/C++ to the moon and back, I'm not super-bright at advanced math like that. At least not yet. Can you recomend a site that will actually explain what these values that appear out of thin air are for and what these terms mean?

nexusone

09-29-2002, 12:54 PM

I personaly use ATI video cards, and I have been happy with the openGL support todate and rendering.

I am sorry but if you are going to be doing your own math instead of useing openGL functions you better brush up on your math, since you will be seening a lot of it.....

And from what I read in your message, any tutor on doing the math it would be over your head at this point and time...

and at some point even using Direct X you would have to be doing some higher math.

Originally posted by Sephiroth:

The primary reason is that there is also a D3D renderer. I need the world to be stored properly so D3D can look at it also. Not everybody owns an nVidia card with 100% OpenGL support, and many own ATI cards and Matrox cards, which generally (from personal experience of myself and friends) have minor problems with OpenGL (for instance, ATI Radeon 8500LE makes OpenGL super-dark when compared to an nVidia anything). I need D3D support for owners of video cards like these or ones that are no-name brands, such as ones built into a motherboard.

I've found rotation tutorials but they all start about 6 light-years over my head. I keep wondering "wtf is a dotproduct?", or "where the heck did that value magically appear from?", and other such stuff. I need a tutorial that doesn't take a nine-year college course in math to understand. I am in college (had two years of it) but although I can code C/C++ to the moon and back, I'm not super-bright at advanced math like that. At least not yet. Can you recomend a site that will actually explain what these values that appear out of thin air are for and what these terms mean?

SThomas

09-29-2002, 04:36 PM

here's a decent 3d math/geometry tutorial: http://www.flipcode.com/geometry/

if you find that that stuff is over your head, i would recommend taking a linear algebra course at school, which is how i learned about 3d math concepts. taking a college course will offer an easier introduction than an online tutorial. good luck friend.

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.