3D Vertex Rotation

Previous topic - Next topic

matchy

I'm trying to create a wireframe for 3D array of vertices with just X_LINE output (no X_GETMATRIX or X_GETFACES input) although I can't seem to get it right. Any suggestion why this classic function isn't right as the object is skewed at certain angles but okay near the perpendicular? :'(
Code (glbasic) Select

FUNCTION rotation AS _point: ob AS _obj, v AS _point
LOCAL p AS _point
p = v
INC p.x, v.x
INC p.y, (COS(ob.angle.x) * v.y) - (SIN(ob.angle.x) * v.z)
INC p.z, (SIN(ob.angle.x) * v.y) - (COS(ob.angle.x) * v.z)

INC p.x, (SIN(ob.angle.y) * p.z) + (COS(ob.angle.y) * p.x)
INC p.y, v.y
INC p.z, (COS(ob.angle.y) * p.z) - (SIN(ob.angle.y) * p.x)

INC p.x, (COS(ob.angle.z) * p.x) - (SIN(ob.angle.z) * p.y)
INC p.y, (SIN(ob.angle.z) * p.x) + (COS(ob.angle.z) * p.y)
INC p.z, v.z
RETURN p
ENDFUNCTION

FUNCTION wire: ob AS _obj
IF self.mouse.b1
ob.rotate.x = self.mouse.y_axis
ob.rotate.y = self.mouse.x_axis
INC ob.angle.x, ob.rotate.x
INC ob.angle.y, ob.rotate.y
ENDIF
LOCAL e AS _point
LOCAL f AS _point
FOR i = 0 TO ob.vertices - 2
ALIAS v AS ob.ver[i]
ALIAS u AS ob.ver[i + 1]
e = self.rotation(ob, v)
f = self.rotation(ob, u)
X_LINE  e.x, e.y, e.z,  f.x, f.y, f.z,  1, 0xffffff // v.color.value
NEXT
ENDFUNCTION


bigsofty

Just a guess, as there is no perspective transform, so it may look off when rotating without it?
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)