3D Rotation?

Blitz3D Forums/Blitz3D Beginners Area/3D Rotation?

Hotshot2005(Posted 2005) [#1]
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]


WolRon(Posted 2005) [#2]
You know, to be very honest with you, I don't know what you are trying to achieve.

I see a 'snake' kinda slithering and bouncing around the screen. What is it that you are trying to do with it?

what I am trying to do is get Z rotation coming toward the screen and coming away from the screen...
Could you please elaborate on this?


big10p(Posted 2005) [#3]
Hmmm. I think he want's the 'snake' segments to get bigger as they come closer to the screen, and smaller as the move away. i.e. simulate a 3rd dimesion. Kinda like the dragon in the original Space Harrier.

This is tricky in pure 2D as you'd need many different sized segment images to simulate the effect. Not worth the bother/resources. If you want 3 dimesions then use 3D! Go figure. :)


WolRon(Posted 2005) [#4]
Ah, I see. By Z rotation, he must have meant Z scaling. I guess you could get by with scaling the segments using ScaleImage, but it would be extremely slow.


jhocking(Posted 2005) [#5]
Do 2D-in-3D. That'll make scaling nice and simple.


Ross C(Posted 2005) [#6]
There's also no need to really use sin and cos look up tables. There's no real speed gain to be had, and it can actually be slower on some computers, like mine.