In article <19980119162600.LAA09...@ladder01.news.aol.com>, MuDoDragon

<URL:mailto:mudodra...@aol.com> wrote:

> I'm a newcomer, so bear with me. I am trying to rotate a simple object made

> up of polygons in 3d space. Sounds simple, eh? Okay. Suppose I am writing a

> flight sim, I am in 1 aircraft, and looking at another aircraft. My question

> concerns the orientation and application of rotational forces to the "other"

> craft, ie, the one being viewed.

> Suppose the craft being viewed has a current "orientation" of (0, 0, 0), ie,

> unrotated on any axis relative to the world. It is flying, let's say, due

> north, straight and level with the earth.

> The next iteration thru the graphics pipeline, let's say the craft rotates 45

> degrees about the z axis, ie, rolls 45. Then it gets drawn. So far, so good.

> Now let's say it pitches 90 degrees about its x-axis. Its rotation is relative

> to the plane's x-axis, but not the world's x-axis since previously the craft

> rolled 45 degrees. It occurs to me the "pitch force" (for lack of a better

> term) of 90 degrees must be translated into some amount of yaw, and some amount

> of pitch based on the current roll amount. The trig algorithms I have found

> thus far in books look like they address the issue, but, in fact, don't.

> Furthermore, the rendering routines which attempt to rotate objects local

> coordinates to world coordinates are written so as to rotate all objects in a

> certain order. For instance, I could write the RotateObject() function to

> rotate about the y, then the x, then the z, which means all objects are drawn

> as if they first yaw, then pitch then roll. Therefore, in order to be drawn

> correctly, the application of rotational forces previously described need to

> yield angles that are correct for the order of rotations specified by the

> RotateObject() function.

> For example, if I roll 45 degrees, then pitch 90, I need to convert thos

> movements to yaw 90, pitch 45, then rotate 45 in order to draw the plane so it

> looks correct.

> If anyone understands what I'm talking about, please help me! I cannot seem to

> find a tome that addresses this, in spite of the numerous volumes I am finding.

> Thanks a bunch for your help.

> - MuDoDragon -

OTMMATX.DOC - matrix transformation tutorial

(or if you prefer, "A proven antidote for VLA 3d tutorials" :)

Copyright (C) 1995, Zach Mortensen [Voltaire OTM.TAP]

All rights reserved.

email - morte...@nersc.gov

Introduction

It has been entirely too long since I wrote my last doc, I just

had to make another one :) This is a topic which I have spent a great

deal of time teaching lately, so I decided to make a doc that would

expedite the process for me.

If you are looking for advice from a certified expert, you will

not find it in this doc. I am merely an individual who has spent the

past year studying realtime rendering, and who is willing to share

what he has learned. However, you should rest assured that I do not

write docs about things I have never implemented in working code, and

I never code anything I don't fully understand. In other words, I

think I know what I am talking about here :)

All of the techniques in this file can be implemented regardless

of the programming language you use, from assembler to C to Visual

Basic. I will, however, be giving any pseudocode examples in C,

because it seems to be the universal language of coders right now.

For the sake of simplicity, all code examples will use floating point

math. Floating point is the wave of the future, as a matter of fact

its faster than fixed point integer math on the newest RISC machines

(PowerPC, DEC Alpha). Unfortunately, Intel users have been given

hideously slow floating point processors in the past and are less than

confident in the ability of their machines; but things will get better

very shortly.

Math Prerequisites

Sadly, matrix math is something that is all but ignored in most

high school curricula in the United States. But hey, the best stuff

is skipped in high school, everybody knows that :) You should not be

afraid of matrix math just because your high school math teacher does

not teach it. Now that I think about it, matrix math is probably

skipped in high school simply because there is nothing taught in high

school that applies its principles.

The only matrix math I was taught in high school was for solving

systems of equations. Basically, we were taught that a matrix is a

simple and powerful way to represent a complex system of equations.

This is a great explanation, although extremely simplistic. Keep this

in mind throughout the course of this doc.

The math of matrices is very simple. Nothing higher than first

year algebra is used, although an understanding of trigenometry will

make your life much easier when it comes to understanding the meaning

of all those numbers in a matrix. If you have had a course in Linear

Algebra at a university, this doc will probably be old news to you.

Importance of Correct Transformations

When I first began coding vector graphics, I had a great

understanding of trigenometry and anything but fond memories of matrix

math as it was presented in my high school courses. To me, matrix

math seemed to be an unneccessarily complex way to solve a simple

algebraic problem, like trying to swat a fly with an elephant gun.

Indeed, many algebraic problems can be solved without the use of

matrix math.

However, vector graphics pose a system of equations that are

anything but simple to solve algebraically. Consider the following:

in a typical vector world, there are many objects. Each of these

objects moves in its own space (object space), relative to its own set

of coordinate axes. There are several cameras, each of which moves in

its own space (camera space or eyespace) according to its own set of

coordinate axes. At some point, the objects must be transformed from

object space to eyespace so they can be displayed as the eye sees

them. Apart from this, there is the issue of object hierarchies. In

a realistic vector environment, object hierarchies must be handled

correctly. These issues present formidable challenges without the use

of matrix math. However, by using matrix math we can deal with all

of these issues in a simple and speedy manner.

Granted, I am assuming that everyone wants to make simulation

quality vector code. This type of code requires correct

transformations. Speaking from a demo scene point of view, very few

demos implement correct transformations simply because they are not

required for the application. The stereotypical vector scene in a

demo is a childish attempt to display speed and pretty rendering on a

single object. Most demo coders do not care if their objects are

moving correctly, they just want them to move around a bit. This

attitude is fine, assuming you never want to do anything with your

code besides show a spinning cube or toroid.

Any impressive vector application (game, simulator, etc.) requires

correct transformations. Consider the following example. An airplane

is oriented such that its nose is pointing in the positive z

direction, its right wing is pointing in the positive x direction, its

cockpit is pointing in the positive y direction. The airplane's local

x, y, and z axes are aligned with the world x, y, and z axes. If this

airplane were rotated 90 degrees about its y axis, its nose would be

pointing toward the world -x axis, its right wing pointing toward

the world +z, and its cockpit remaining in the world +y direction.

Most transformations, whether correct or incorrect, would accomplish

this. Here is the 'acid test' to see whether your transformations are

correct. From this new position, rotate the airplane about its z

axis. If your transformations are correct, the airplane will rotate

about its own z axis (it will roll). If your transformation is

incorrect, the airplane will rotate about the world z axis (its nose

will pitch up or down).

This rather silly example poses quite a serious question. If your

transformations are not correct, how will you control object movement

in a vector world? How will you guarantee your airplane will roll

when you tell it to instead of pitching? The same problem arises with

incorrect camera rotation. The consequences of such incorrectness in

a flight simulator or game would make the game unplayable.

The solution to this problem is simple; the use of 4x4 matrix

transformations.

What a Matrix Represents

Before we continue, it will help you greatly to understand what

the values in a matrix represent. A 4x4 matrix contains 4 vectors,

which represent the world space coordinates of the x, y and z unit

axis vectors, and the world space coordinate which is the origin of

these axis vectors.

X Y Z C

X X X 0

Y Y Y 0

Z Z Z 0

O X Y Z 1

The X column contains the world space coordinates of the local X axis

The Y column contains the world space coordinates of the local Y axis

The Z column contains the world space coordinates of the local Z axis

These vectors are unit vectors. A unit vector is a vector whose

magnitude is 1. Basically, unit vectors are used to define

directions, when magnitude is not really important.

The C column always contains the specified values

The O row contains the world space coordinates of the object's origin

You can make life easy for yourself by storing matrices which contain

axis information in each object. I keep two matrices for every

object; omatrix, which stores the object space matrix, and ematrix,

which stores the eyespace matrix for the object.

A special matrix is the identity matrix:

1 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

Notice why the identity matrix is special? The identity matrix

represents a set of object axes that are aligned with the world axes.

Remember that the vectors stored in the matrix
...

**read more »**