🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #1430

Re: 3D rotation update

#1430
From: 2fmlcalls
Date: Thu, 11 Apr 1991 00:35
70 lines
4253 bytes
> If anyone has experience in this area of 3D rotation, please keep posting.
> If I am just missing a small point, don't flame me.  I will see it soon
> enough.  I am bound to find out what I am missing eventually.  All your
> help is appreciated.
> 
> Thanks a lot, Keith Murray

I got a bit lost in your process you described.  Let me try to explain a
process I used as clearly as I can.

Lets take a square.  We all know its shape and (as opposed to a cube) it has
few points.  As emntioned in an earlier post, you want an array of 'triples'
(the x, y, and z coords for each point) and a sequence to connect the dots.  If
the points are A,B,C,D then we could come up with values like this:
A = (-10, 10, 0)
B = (10, 10, 0)
C = (10, -10, 0)
D = (-10, -10, 0)
If you plot these on a piece of graph paper (ignoring the last 'z' component)
you get a square 20 x 20 about the origin.  Connect A to B to C to D to A. 
There's the dot-to-dot.
These 'local' coordinates are important because they define a simple rotational
axis for the shape (you can rotate about any arbitrary point, but putting 0,0,0
as the center of gravity just makes sense).
So, the above points might be thought of as the source points.

Since you seem to understand transform matrices, I'll skip that rather tedious
part.  But basically, you pop in sin and cos values for the angle(s) you want
to rotate all these points about.  The transformation entails putting feeding
source points into the matrix and extracting transformed points.  If you feed
in these original points AS THEY ARE assigned above, the transformation will be
about the local origin (say, for example the square is rolling and tumbling
about its own axis).  The points you get out lets call tA, tB, tC, and tD -
small t for the local transformation.

Now you do the global transformation (as if the observer is rotating, tumbling
etc.).  First you need to translate (shift) the points tA, tB, tC, tD by the
amount that they are distant from the observer.  If the global position of the
square is a point P(distX, distY, distZ), then add distX to the x component of
tA, tB, tC, tD.  Not that we are translating the transformed points and not the
original 'raw' source points.  All four points of the square have now been:
1) rotated about their own axis and
2) shifted in space to represent their distance from the observer.
The now shifted points we could call tsA, tsB, tsC, tsD.  That is, these are
the original points after rotating and then shifting.

The last` step is to pop the sines and cosines for the OBSERVERS roll, pitch,
and yaw into a transform matrix  and run tsA, tsB, tsC, tsD through.  What you
get out we can call tsTA, tsTB, tsTC, tsTD.

These are the final points.  Use your similar triangles and clipping on these
points.  And there it is.

For the next frame, add rolls, pitches and yaws to the roll, pitch and yaw of
the object and observer.  Figure your new distance point P.  And run the whole
gauntlet again with the source points.

A final note.  As pointed out in same earlier post, so long as you maintain
your original source points and never modify them, you'll get no accumualted
round-off errors (read - a parallelogram or rhombus).  The points you derive
from all the transofroms can be tossed after you draw the scene.  In fact, you
may have realized that after the first rotation (about the objects axis) you
need not keep this copy of points when you translate them and then when you
rotate about the observer).

Also, rotations and distance are cumulative.  If the square is rotated 10
degrees off North and rotates +5 degrees in one loop through the game, you put
15 degrees (not 5) into the transform matrix.

john calhoun
Technical Details
Message-ID: <1991Apr10.193547.29604@kuhub.cc.ukans.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!kuhub.cc.ukans.edu!2fmlcalls
References: <1991Apr10.191212.5249@lynx.CS.ORST.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!kuhub.cc.ukans.edu!2fmlcalls
From: 2fmlcalls@kuhub.cc.ukans.edu
Newsgroups: rec.games.programmer,alt.msdos.programmer,comp.os.msdos.programmer
Subject: Re: 3D rotation update
Message-ID: <1991Apr10.193547.29604@kuhub.cc.ukans.edu>
Date: 10 Apr 91 19:35:47 CDT
References: <1991Apr10.191212.5249@lynx.CS.ORST.EDU>
Organization: University of Kansas Academic Computing Services
Lines: 70