Point a 3Dsprite at the mouse pointer

Blitz3D Forums/Blitz3D Programming/Point a 3Dsprite at the mouse pointer

Tracer(Posted 2005) [#1]
I just can't seem to figure this out.

I have a 3Dsprite (which is drawn by normal x,y coords, not using the usual blitz3d coords of x,y,z).. ie, the sprite is located at, say, 320x400, and will be at that pixel location on screen.

I need to rotate this 3dsprite to point at the mousepointer.

I have tried:

angle# = ATan2(MouseX() - 320,MouseY() - 400) + 90

But that doesn't quite work the way i was hoping it would (it does return an angle it seems, but if i rotate the pivot the 3d sprite is on to that angle, it screws up, it doesn't point towards the mouse pointer_).

Any ideas?

Tracer


WolRon(Posted 2005) [#2]
Could this be your problem:

Notice the reverse order, ATan2( y, x ) rather than ATan2( x, y).
ATan2( y, x ) is analogous to ATan( y / x), but covers 360 degrees.



Rob Farley(Posted 2005) [#3]
This might help...

http://www.blitzbasic.com/codearcs/codearcs.php?code=321


_PJ_(Posted 2005) [#4]
Well you can pick the mousex(),mousey() co-ords, perhaps this could be interpreted and a pivot permanently following the pointer (A lattice of pivots either 2d or 3d as required may be required as 'markers' for the '3d' representation of specific mouse pointer coords.

Then, point the entity at the relevant pivot.

Hope that makes sense to you, if its not clear, lemme know Il try and explain it better!


Tracer(Posted 2005) [#5]
Wolron hit the head on the nail there.. i, indeed, wasn't aware of the reverse order there.

Thanks all.

Tracer


_PJ_(Posted 2005) [#6]
:)