Perspective divide produces gibberish

Perspective divide produces gibberish

Post by George Col » Tue, 22 Feb 2000 04:00:00



Hi. I'm having trouble getting the perspective divide to work.
I'm trying to display particles in a simple window. All I do is rotate
their vector co-ordinates by an x, y and z angle and then display this
on the screen. Unfortunately when I put in the perspective divide I get
very strange results and I can't figure out why.
Here's my code:

X1 = Particle.XPos
Y1 = Particle.YPos
Z1 = Particle.ZPos

'ROTATING AN AXIS AT A TIME
'x axis rotation
Y2 = (Y1 * Cos(XAngle) - Z1 * Sin(XAngle))
Z2 = (Y1 * Sin(XAngle) + Z1 * Cos(XAngle))

'y axis rotation
X2 = (X1 * Cos(YAngle) - Z2 * Sin(YAngle))
Z = (X1 * Sin(YAngle) + Z2 * Cos(YAngle))

'z axis rotation
X = X2 * Cos(ZAngle) - Y2 * Sin(ZAngle)
Y = X2 * Sin(ZAngle) + Y2 * Cos(ZAngle)

'PERSPECTIVE DIVIDE
X = Perspective * X / Z
Y = Perspective * Y / Z

'DRAW PIXEL
l = SetPixel(Display(3).hdc, MidX + X / 1000 * SizeX, MidY - Y / 1000 *
SizeY, White)

Where "Perspective" controls the amount of perspective. The SetPixel API
call is as follows:

Declare Function SetPixel Lib "gdi32" (ByVal hdc As _
   Long, ByVal X As Long, ByVal Y As Long, ByVal _
   crColor As Long) As Long

+++++++++++++++
If I leave out the perspective divide I get nice results like this (but
no perspective):
http://freespace.*.net/cole.family/tmp/nopersp.gif

However with the perspective divide code in place it all goes a bit pear
shaped:
http://freespace.*.net/cole.family/tmp/persp.gif
(note the grid has no perspective divide here)

Can anyone tell me what I'm doing wrong? I am right in thinking that by
rotating the particle's vector by set angles, and then dividing the new
x and y values by the new z value I can produce a perspective image?
Thanks in advance,
George Cole

 
 
 

Perspective divide produces gibberish

Post by Samuel Pai » Fri, 03 Mar 2000 04:00:00



> Hi. I'm having trouble getting the perspective divide to work.
> I'm trying to display particles in a simple window. All I do is rotate
> their vector co-ordinates by an x, y and z angle and then display this
> on the screen. Unfortunately when I put in the perspective divide I get
> very strange results and I can't figure out why.

You aren't clipping to the near clipping plane.  The perspective
divide then wraps points that are "behind" the eyepoint out in front.

As a side note, you may want to reconsider using Euler angles for
an orientation representation.
--
Samuel S. Paik | http://www.webnexus.com/users/paik/
3D and multimedia, architecture and implementation
You dont know enough about X86 or kernel architectures to argue with me.