I am writing a game where essentially a sphere moves around a 3 dimensional grid. I allow the user to rotate the grid around itself so he can get better views. The keys to move left and right, however, are mapped to increasing or decreasing the x value of this ball. Unfortunately, this means that in the grid, rotated 90 degrees around the y axis (y axis rotation is like that of a tornado), right and left (increase / decrease x value) instead mean away / toward. At 180, right means left and left means right. At 270, right means toward and left means away. I'm sorry if I confused anyone, but this is sort of hard to explain. Grab a tissue box and try it. Anyway, does anyone know how to turn the rotation amount (like amntxrot , amntyrot, amntzrot which are measured in degrees...in the above example the amntxrot is zero, amntyrot is 90, and amntzrot is zero) into some form of left and right? I can't rotate the universe around the user to solve it and I can't hard-wire it in for every value - things become very complicated when doing compound rotations (90x, 0y, 90z for example)

05-12-2002

red_baron

oh boy, you managed to rotate my head around! :eek:

hehe, i got no clue...

05-13-2002

*ClownPimp*

why not just have a function like displaySphere that will display the sphere for any orientation of the coordinates. Then, your left and right will be simply left and right without regards to orientation, and leave orientation up to the display function.

Does this help any?

05-13-2002

*ClownPimp*

although, you could probably use some semi-complicated trig.

lets say you have a coordinate vector Vx and Vy and they are parallel to the screens x and y axis. Then a shift 1 unit along Vx will equal a shift of i unit along x.

x = Vx(cosT) and y = Vx(sinT) where 'x' is the x axis of the screen and T is the angle between the Vx and the x axis. In this case T = 0, and cos(0) = 1, sin(0) = 0, so a translation of 1 unit along Vx equals a translation of 1 unit along x and a translation of 0 along the y axis.

This code will handle rotation, scaling, translation, etc.,etc.
It also handles transformation, projection, and allows you to specify how far along the pipeline you wish to go.

All functions have not been tested so there might be a few minor errors. Sorry its so long, but I could not get my winzip to work.
I normally dont post code snippets this long but had no choice.

Perhaps I need to re-install WinZip.

Any questions PM me.

This assumes:

Local space coords are centered in object - otherwise you will get an off balance local rotation.

Z coords have been properly clipped prior to transformation and backface culling has already been done.

Vertexes that are not visible (as well as polies/triangles) have been properly removed from the vertex list.

The view matrix is setup after using this class and then concatenated with the final master matrix - returned from the Execute function.

Z coordinates move into the screen, X is left and right, and Y is up (right handed coord system I believe)

05-14-2002

VirtualAce

To use this class:

MatrixPackage1 constructor is incorrect. Should just be
MatrixPackage. MatrixP..1 is from a prev template version of this class.

Create an instance of MatrixPackage.

Setup translation, scaling, and rotation with calls to these functions. The reason there are two versions of these functions is so that I can change the underlying code later on, but the public interface will remain the same.

After you set all of these up, simply pass your vertex list to the WorldTransform function when calling it. This will convert from Local to World space.

Reset the master matrix

Perform any rotation,scaling,translation. This is done now in World space.

Call ViewTransform and pass your vertexes to the function. Note that you do not have to explicity pass the World vertexes to the function since these are members of the Vertex struct. The View Transform function will automatically use these members.

(optional and not implemented) Retrieve a pointer to the master matrix - concatenate with self-made view matrix (must be double data type)

Call Project (after setting the desired projection distance and center of the screen) to convert View vertexes into Screen space (3D to 2D).

Draw the objects from the vertex list. (not handled by this class). Vertexes must be taken from each object (thus each poly in the object) and placed into a master list - this way all vertexes for all visible objects can be transformed with one master multiply.

Note that this class is not done since it does not support the view matrix. But it should give you an idea of how to do it.

I've worked very hard on this code for some time and it is the result of reading several books and many hours of headaches. Most of this is not needed within environments like OpenGL (though you do have to setup the matrices) or DirectX.

If you have suggestions about this code, PM me. If we could test this code completely (through several users) I would be interested in placing it on the FAQ board. We have lots of questions regarding matrices on these boards and this might help a bit.