News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

3D Rotate vs 2D Rotate _ need help

Started by stevmjon, October 16, 2021, 10:12:39 AM

Previous topic - Next topic

stevmjon

having an issue at getting a 3D rotate calc to work correctly.
the 2D calc works fine.

what i am doing is trying to get the red circle(3D) and yellow circle(2D) to rotate around the screen following the white path.
> each frame i am resetting the x,y location around the screen zero (top left). acts like a translate to be around zero.
> calc both 3D rotate & 2D rotate
> rotate gets increased each frame, so 'angle offset' gets bigger from reset position
> translate circles back around screen center.
> what should happen is the both circles should be in the same location around the white path. but the red 3D circle forms a figure 8...???

can't seem to work out the issue. any help is appreciated.
note: the calc works great in my 3D engine.



SetFPS 50


Do

Cls 0

;--- reset acts like translate around zero pos each frame ---
x# = 300  :  y# = 0
radius = 300


;--- 3D rotate calc ---
   m1# = Cos(Player_Angle2#)  :  m2# = -Sin(Player_Angle2#)  ;  x
m3# = Sin(Player_Angle2#)  :  m4# = Cos(Player_Angle2#)  ;  y

   x# = x# * m1# + y# * m2#
   y# = x# * m3# + y# * m4#
   
   ;--- translate back around screen center ---
   CircleC 400+x#,300+y#,15,0,RGB(255,0,0)  ;  red circle (3D rotate)
   
   
   Text 0,0,"Player Angle = " + Str$(player_angle)
   ;;text 0,15,"Heading Angle = " + str$(player_angle2#)
   
   ;--- standard rotate calc ---
   x1# = radius * Cos(Player_Angle)
   y1# = radius * Sin(Player_Angle)
   
   ;--- translate back around screen center ---
   CircleC 400+x1#,300+y1#,10,1,RGB(255,255,0)  ;  yellow circle (standard rotate)
   
   
   ;--- path ---
   Circle 400,300,300,0
   LineC 400,300,400+x1#,300+y1#,RGB(0,100,0)  ;  degrees
   
   Sync
   
   ;;flushkeys  :  waitkey
   
   Inc player_angle,1
   player_angle = WrapValue(player_angle,0,360)  ;  show angle as green line
   
   Inc player_angle2#,1
   player_angle2# = WrapAngle(player_angle2#,360)
   
Loop

It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin

  x# is being transformed in the first expression, then used in the second expression..   So just preserve it.

PlayBASIC Code: [Select]
  xr# = x# * m1# + y# * m2#
y# = x# * m3# + y# * m4#
x#=xr#






PlayBASIC Code: [Select]
SetFPS 50


Do

Cls 0

;--- reset acts like translate around zero pos each frame ---
x# = 300 : y# = 0
radius = 300


;--- 3D rotate calc ---
m1# = Cos(Player_Angle2#) : m2# = -Sin(Player_Angle2#) ; x
m3# = Sin(Player_Angle2#) : m4# = Cos(Player_Angle2#) ; y

xr# = x# * m1# + y# * m2#
y# = x# * m3# + y# * m4#
x#=xr#
;--- translate back around screen center ---
CircleC 400+x#,300+y#,15,0,RGB(255,0,0) ; red circle (3D rotate)


Text 0,0,"Player Angle = " + Str$(player_angle)
;;text 0,15,"Heading Angle = " + str$(player_angle2#)

;--- standard rotate calc ---
x1# = radius * Cos(Player_Angle)
y1# = radius * Sin(Player_Angle)

;--- translate back around screen center ---
CircleC 400+x1#,300+y1#,10,1,RGB(255,255,0) ; yellow circle (standard rotate)


;--- path ---
Circle 400,300,300,0
LineC 400,300,400+x1#,300+y1#,RGB(0,100,0) ; degrees

Sync

;;flushkeys : waitkey

Inc player_angle,1
player_angle = WrapValue(player_angle,0,360) ; show angle as green line

Inc player_angle2#,1
player_angle2# = WrapAngle(player_angle2#,360)

Loop







stevmjon

#2
OMG kev, talk about a newbie mistake.

i was actually waiting up last night for the minecraft live show to start, so was up till 3am waiting for it to start. so i guess i was in tired mode.

p.s. yay i finally got 500 posts. now i go from sr member to hero member. do i wear a vip pass before i log on?
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.