hiya all
I have code the advance stuff but what I am trying to do is get Z rotation coming toward the screen and coming away from the screen...
Have I got right Z rotation?
p.s. I have done 2D rotation and now I am moving on 3D Rotation in 2D Program
here the code
I hope people understand what I am trying to do here
here the code
[code]
AppTitle "3D ROTATION"
Press_Esc=1
Const Speed=2
Graphics 640,480,16,2
bobImage = CreateImage( 32, 32 )
MidHandle bobImage
SetBuffer ImageBuffer( bobImage )
Color 255, 0, 0
Oval 10, 10, 320, 32
Color 200, 0, 200
Oval 6, 6, 20, 20
Dim bobx( 64 ), boby( 64 )
For i = 0 To 63
bobx( i ) = i * 5 Mod 360
boby( i ) = i * 4 Mod 360
Next
bobxadd = 2
bobyadd = 2
SetBuffer BackBuffer()
;-------------------------------------------------
; Set up sine tables;
;-------------------------------------------------
Dim sintable#(361)
Dim costable#(361)
For a=1 To 360
sintable#(a) = Sin(Float(a))
costable#(a) = Cos(Float(a))
Next
;-------------------------------------------------
;
;-------------------------------------------------
Bx=100
by=100
While Not KeyDown(Press_ESC)
For value = 0 To 255
red = 255 - value
green = 225 blue = value
Color red , green , blue
; Convert color position to vertical position
relative = value * GraphicsHeight () / 255 Rect 0 , lastheight , GraphicsWidth () , relative
; Remember previous vertical position
lastheight = relative
Next
; rx = bx * Sintable#(angle) - by * Costable#(angle) ; X ROTATION
; ry = by * Sintable#(angle) + bx * Costable#(angle) ; Y ROTATION
; rz = bx * Sintable#(angle) + by * Costable#(angle) ; Z ROTATION
; Rotation around the X-axis:
ry = Cos(angle_x) * by - Sin(angle_x) * bz
rz = Sin(angle_x) * by + Cos(angle_x) * bz
; Rotation around the Y-axis:
rx = Cos(angle_y) * bx + Sin(angle_y) * rz
rrz = -Sin(angle_y) * bx + Cos(angle_y) * rz
; Rotation around the Z-axis:
rrx = Cos(angle_z) * rx - Sin(angle_z) * ry
rry = Sin(angle_z) * rx + Cos(angle_z) * ry
For i = 0 To 63
;draw the bobs onto the screen
DrawImage bobImage, 320 + Sin( bobx( i ) ) * rx+rrx ,240 + Sin( boby( i ) ) * ry+rry
Next
If MilliSecs() > bobsUpdate + 15 Then ; here we find the next position of the bobs
bobsUpdate = MilliSecs()
For i = 0 To 63
bobx( i ) = bobx( i ) + bobxadd Mod 360
boby( i ) = boby( i ) + bobyadd Mod 360
Next
End If
Flip:Cls
Angle_x=Angle_x+Speed
Angle_y=Angle_y+Speed
Angle_z=Angle_z+Speed
Wend
[\code]
I have code the advance stuff but what I am trying to do is get Z rotation coming toward the screen and coming away from the screen...
Have I got right Z rotation?
p.s. I have done 2D rotation and now I am moving on 3D Rotation in 2D Program
here the code
I hope people understand what I am trying to do here
here the code
[code]
AppTitle "3D ROTATION"
Press_Esc=1
Const Speed=2
Graphics 640,480,16,2
bobImage = CreateImage( 32, 32 )
MidHandle bobImage
SetBuffer ImageBuffer( bobImage )
Color 255, 0, 0
Oval 10, 10, 320, 32
Color 200, 0, 200
Oval 6, 6, 20, 20
Dim bobx( 64 ), boby( 64 )
For i = 0 To 63
bobx( i ) = i * 5 Mod 360
boby( i ) = i * 4 Mod 360
Next
bobxadd = 2
bobyadd = 2
SetBuffer BackBuffer()
;-------------------------------------------------
; Set up sine tables;
;-------------------------------------------------
Dim sintable#(361)
Dim costable#(361)
For a=1 To 360
sintable#(a) = Sin(Float(a))
costable#(a) = Cos(Float(a))
Next
;-------------------------------------------------
;
;-------------------------------------------------
Bx=100
by=100
While Not KeyDown(Press_ESC)
For value = 0 To 255
red = 255 - value
green = 225 blue = value
Color red , green , blue
; Convert color position to vertical position
relative = value * GraphicsHeight () / 255 Rect 0 , lastheight , GraphicsWidth () , relative
; Remember previous vertical position
lastheight = relative
Next
; rx = bx * Sintable#(angle) - by * Costable#(angle) ; X ROTATION
; ry = by * Sintable#(angle) + bx * Costable#(angle) ; Y ROTATION
; rz = bx * Sintable#(angle) + by * Costable#(angle) ; Z ROTATION
; Rotation around the X-axis:
ry = Cos(angle_x) * by - Sin(angle_x) * bz
rz = Sin(angle_x) * by + Cos(angle_x) * bz
; Rotation around the Y-axis:
rx = Cos(angle_y) * bx + Sin(angle_y) * rz
rrz = -Sin(angle_y) * bx + Cos(angle_y) * rz
; Rotation around the Z-axis:
rrx = Cos(angle_z) * rx - Sin(angle_z) * ry
rry = Sin(angle_z) * rx + Cos(angle_z) * ry
For i = 0 To 63
;draw the bobs onto the screen
DrawImage bobImage, 320 + Sin( bobx( i ) ) * rx+rrx ,240 + Sin( boby( i ) ) * ry+rry
Next
If MilliSecs() > bobsUpdate + 15 Then ; here we find the next position of the bobs
bobsUpdate = MilliSecs()
For i = 0 To 63
bobx( i ) = bobx( i ) + bobxadd Mod 360
boby( i ) = boby( i ) + bobyadd Mod 360
Next
End If
Flip:Cls
Angle_x=Angle_x+Speed
Angle_y=Angle_y+Speed
Angle_z=Angle_z+Speed
Wend
[\code]