UnderwareDESIGN

PlayBASIC => Beginners => Topic started by: stevmjon on October 16, 2021, 10:12:39 AM

Title: 3D Rotate vs 2D Rotate _ need help
Post by: stevmjon on October 16, 2021, 10:12:39 AM
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

Title: Re: 3D Rotate vs 2D Rotate _ need help
Post by: kevin on October 16, 2021, 10:36:09 AM
  x# is being transformed in the first expression, then used in the second expression..   So just preserve it.

[pbcode]
 xr# = x# * m1# + y# * m2#
  y# = x# * m3# + y# * m4#
  x#=xr#


[/pbcode]


[pbcode]



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


[/pbcode]


Title: Re: 3D Rotate vs 2D Rotate _ need help
Post by: stevmjon on October 16, 2021, 08:58:09 PM
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?