Subject: 3d graphics question

From: [email-masked] (Ray)
Date: Thu, 9 Jan 92 17:28:28 WET

I realize this is probably the wrong place to be asking this, but
can someone give me the 4x4 homogenous rotation matrix? I have books
that show how to rotate on the X, Y, Z axis seperately but I want
the general 3 axis method, since I can optimize it myself for special
cases if I want. The 2d method is easily derivable

 ..   .            .  .    
|x'|=| cos a  sin a ||x|
|y'|=|-sin a  cos a ||y|  (yea, it doesn't look pretty)
`  ' `              '` '

  I'm looking for  

|x'| |x  x  x  x||x|
|y'|=|x  x  x  x||y|
|z'| |x  x  x  x||z|
|  | |x  x  x  x|| |

  Or a 3x3 method.

 Please , no book citations. I know all the standard ones like Foley's, 
and Newmann. My library doesn't have them, and my bookstore doesn't
have them either.. In fact, because of budget cuts in my state, govt is
shutting down many of our libraries including my local one.

  And a small question with regard to clipping. I derived using simultaneous
algebraic equations, a formula that returns the intersection point of
a vector and a screen boundary (very quick, since a screen boundary
is either a vertical or horizontal line so only one coordinate of
the intersection is unknown. This is 2d clipping with a special check for
the Z coordinate).  My question is, is this the fastest clipping method
availible for this particular special case? I only know of one other
method, binary something, which reminds me of a binary search. It basically
starts at the midpoint, checks if it is inside or outside of the
clipping rectangle, and then moves to the midpoint between the current 
midpoint and the end point of the line chosen. So it creeps up very quickly
on the intersection, but is it faster than the algebraic method?
I think my method uses 5 mults/divs and 5 add/subs. It takes 2 adds/subs
and 2 mults/divs to calculate the midpoint plus the if statements so
it seems like the binary method is both slow and inaccurate. I could do
screen boundary clipping during the line draw routine only I am using
hardware to draw lines.

---

From: Dave Stampe-Psy+Eng <[email-masked]>
Date: Thu, 9 Jan 92 18:16:34 -0500

Use the 3x3 matrix, the homogenous is much slower.  Compute 9 factors,
A = cos(t)cos(a) + sin(a)sin(t)sin(p)
B = -sin(a)cos(t) + cos(a)sin(t)sin(p)
C = -sin)t)cos(p)
D = sin(a)cos(p)
E = cos(a)cos(p)
F = sin(p)
G = cos(a)sin(t) - sin(a)sin(p)cos(t)
H = -sin(a)sin(t) - cos(a)sin(p)cos(t)
J = cos(p)cos(t)

Now, subtract the viewpoint coords from the point coords to get xyz.
The transformed points are:

X = Ax+By+Cz
Y = Dx+Ey+Fz
Z = Gx+Yy+Jz

Scale the coefficients in each equation to scale X and Y (to set aspect
ratio) and Z (to scale display zoom).

Clip (Hither only for now) so Z>=1 for all points.
Divide X and Y by Z to get screen coords in perspective.  Clip by X and Y
to get final coords.

As for clipping, compute the line slope then substitute in the
new "clipped" X, Y or Z and recompute the other coords using the
slope.  In assembly, I find it most effective to (for a Z clip)
- multiply by dX
- Divide by dZ
- add left X
- do the same for Y

The exact coord specs may not be right: I'll have some clip code
to post Real Soon Now.  But I can do this in 5 uS or less.

For poly clipping, you may have to clip each point several times
(Z, X left, X right, Ytop, Ybottom) but in most cases you just do
a compare and skip the test.  I have a really efficient routine worked
out, but I haven't coded it yet.

- Dave Stampe