Hi guys,
Because I'm on a tight deadline for my schoolproject, and that I'm not progessing on the code below, it would be great if someone could help me with this. Afterwards I can post this in the code archives.
The code below turns a cube in 8 direction using a "smooth" transition. Only: the rotation values from blitz are not from 0 to 360 degrees. Result is that the circle sometimes does not take the shortest route available.
Can someone help me out on how I can choose the shortest path? I'm almost "there", but this is keeping me away from implementing it into the game.
Thanks,
Jeroen
Edit: adjusted to 0-360 coordinates
Because I'm on a tight deadline for my schoolproject, and that I'm not progessing on the code below, it would be great if someone could help me with this. Afterwards I can post this in the code archives.
The code below turns a cube in 8 direction using a "smooth" transition. Only: the rotation values from blitz are not from 0 to 360 degrees. Result is that the circle sometimes does not take the shortest route available.
Can someone help me out on how I can choose the shortest path? I'm almost "there", but this is keeping me away from implementing it into the game.
Thanks,
Jeroen
Graphics3D 800,600,32 SetBuffer BackBuffer() Const KEY_UP = 200 Const KEY_DOWN = 208 Const KEY_LEFT = 203 Const KEY_RIGHT = 205 Global targetang#, angoffset,thisang#, ang Global entity = CreateCube() Global Cam = CreateCamera() light = CreateLight() MoveEntity (Cam, 0, 9, -30) CameraRange (Cam, 0.2, 2000) PointEntity (cam,entity) sphere=CreateSphere(8,entity) MoveEntity sphere,0,0,3 ref#=1 direction$ = "left" While Not KeyHit (1) repondToKeys() thisang# = EntityYaw(entity) ConvAng = convertAng(thisang) If direction$ = "left" TurnEntity(entity, 0, 0.25*(targetang - ConvAng ), 0) If direction$ = "right" TurnEntity(entity, 0, -0.25*(targetang - ConvAng ), 0) If Abs(targetang-ConvAng )<8 readyToWalk=True Else readyToWalk=False RenderWorld ; THIS CODE IS THE PROBLEM ; --------------------------------------------------- If (targetang - ConvAng)<-180 ; probably we are taking a wrong direction now Text 0,180,"not a good idea" targetang = 360 - targetang Else If (targetang - ConvAng)>180 ; probably we are taking a wrong direction now Text 0,180,"not a good idea" targetang = targetang + 360 End If ; --------------------------------------------------- Text 0,100,"target angle:"+targetang Text 0,120,"This angle:"+ConvAng Text 0,140,"Ready to walk:"+readyToWalk Text 0,160,"TargetAng - ConvAng = "+(targetang - ConvAng) Delay(40) Flip Wend End ; ------------------------------------------------------------------------------------ Function convertAng(ta) If ta<0 ta=360+ta Return ta End Function ; ------------------------------------------------------------------------------------ Function repondToKeys() If KeyDown(KEY_UP) And KeyDown(KEY_LEFT) targetang = 45 Else If KeyDown(KEY_DOWN) And KeyDown(KEY_LEFT) targetang = 135 Else If KeyDown(KEY_DOWN) And KeyDown(KEY_RIGHT) targetang = 225 Else If KeyDown(KEY_UP) And KeyDown(KEY_RIGHT) targetang = 315 Else If KeyDown(KEY_UP) targetang = 0 Else If KeyDown(KEY_DOWN) targetang = 180 Else If KeyDown(KEY_LEFT) targetang = 90 Else If KeyDown(KEY_RIGHT) targetang = 270 End If End Function ; ------------------------------------------------------------------------------------
Edit: adjusted to 0-360 coordinates