grabbing an objects X and Y position on the screen

Blitz3D Forums/Blitz3D Programming/grabbing an objects X and Y position on the screen

AvestheFox(Posted 2014) [#1]
I need to figure out how to get an objects absolute x and y position on the screen (in pixels, not 3D space)

how would I go about doing this?


Rob the Great(Posted 2014) [#2]
From the manual: http://blitzbasic.com/b3ddocs/command.php?name=CameraProject&ref=3d_cat

Basically, use the command CameraProject to obtain the coordinates, and then use ProjectedX and ProjectedY to obtain these values.

Here's some psuedo if it helps:
Global camera = CreateCamera()
Global theObject = CreateSphere()
MoveEntity theObject,0,0,5

CameraProject camera,EntityX(theObject),EntityY(theObject),EntityZ(theObject)

Print "The x coordinate of theObject is " + ProjectedX
Print "The y coordinate of theObject is " + ProjectedY

One thing to note is that this is based on the very center of the object by default, so it's possible for the values to go outside of the screen resolution range. You can either off-set the x,y,z values of CameraProject, or you can store each value returned and check to see if they are within the range you are wanting.


AvestheFox(Posted 2014) [#3]
thanks for that :)

I've been puzzling over it for a while now. and I need it for a Metroid Prime style targeting system