Converting an angle in 2d co-ords to 3d co-ords
Blitz3D Forums/Blitz3D Programming/Converting an angle in 2d co-ords to 3d co-ords
| ||
What I'm basically trying to do is take the angle the mouse is at, in relation to the centre of the screen. Now, I can get that by doing: ATan2( (GraphicsHeight()*0.5) - MouseY() , (GraphicsWidth()*0.5) - MouseX()) And obviously the angle of the mesh if a piece of cake: EntityYaw(player) Where I'm having trouble is converting the two. Changing the angle to a minus, then adding 90 degrees, brings the angle together, however, the value aren't the same, so i'm having trouble when the 2d angle generated from the mouse, rolls back or forward when it reaches 180 or -180, or after i'm finished altering it, -270 or 90. The point behind this, is to get the mesh to gradually align it's angle with the angle the mouse is at. Can anyone lend a hand. It really is getting the better of me :( |
| ||
here is something in the code archives that should help. http://www.blitzbasic.com/codearcs/codearcs.php?code=2712 If I'm reading your post correctly. |
| ||
Afraid not, but thanks. That may come in handy later :) If anyone's interested, i solved it. I was totally overcomplicating the issue :D Const Graphics_Width = 800, Graphics_Height = 600 Graphics3D Graphics_Width,Graphics_Height SetBuffer BackBuffer() Global light = CreateLight() Global camera = CreateCamera() PositionEntity camera,0,30,0 RotateEntity camera,90,0,0 Global player = CreateCone() RotateMesh player,90,0,0 EntityColor player,255,0,0 Global mouse_angle_now# Global player_angle_dif# Global player_angle_move# While Not KeyHit(1) mouse_angle_now = ATan2(MouseY() - (Graphics_Height*0.5), MouseX() - (Graphics_Width*0.5)) mouse_angle_now = mouse_angle_now *-1 -90 If mouse_angle_now <-180 Then mouse_angle_now = mouse_angle_now + 360 End If player_angle_dif = mouse_angle_now - EntityYaw(player,True) If player_angle_dif > 180 Then player_angle_dif = player_angle_dif - 360 ElseIf player_angle_dif < -180 Then player_angle_dif = player_angle_dif + 360 End If player_angle_move = player_angle_dif*0.1 RotateEntity player,0,EntityYaw(player,True)+player_angle_move,0 UpdateWorld RenderWorld Text 0,0,"mouse_angle = "+mouse_angle_now Text 0,10,"entity_angle = "+EntityYaw(player,True) Text 0,20,"mouse_angle_dif = "+mouse_angle_dif Text 0,30,"player_angle_move = "+player_angle_move Flip Wend End |
| ||
If I'm reading this right, wouldn't it be easier to use DeltaYaw() and do away completely with all the fannying about? |
| ||
I don't have a source mesh to work from. I'm getting the angle of the mouse from the centre of the screen. However... I could have just made a pivot, and set the angle of the pivot to the mouse angle i got... Jesus :D Anyway, thanks again man. Haven't touched programming in about 6 month... |