Inverse of CameraProject

Blitz3D Forums/Blitz3D Programming/Inverse of CameraProject

KuRiX(Posted 2005) [#1]
how can i know a 3d position giving x and y viewport coordinates and a distance?

Thanks in Advance!


Beaker(Posted 2005) [#2]
If you put a flat mesh at the correct distance in front of the camera, make it pickable and do a camerapick() you will get what you need from PickedX/Y/Z(). The mesh can have an alpha of 0.0 of course.


KuRiX(Posted 2005) [#3]
Well, thanks, but there could be some object in front...


Rroff(Posted 2005) [#4]
after about 50 post edits heh everything you need can be found in this example:

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

below is a version I used in a specific situation with the Z distance specified.

Function PositionEntityFrom2D (usecam, entity, x2d#, y2d#, z3d#, positionGlobal = 0, camZoom# = 1.0)
gw = camWidth
gh = camHeight
dx# = -((gw / 2) - x2d)
dy# = (gh / 2) - y2d
parent = GetParent (entity)
EntityParent entity, usecam
;z3d# = Abs (EntityZ (entity))
div# = (gw / (2 / camzoom)) / z3d
PositionEntity entity, dx / div, dy / div, z3d, positionGlobal
EntityParent entity, parent
End Function


KuRiX(Posted 2005) [#5]
mmm, Thanks!. I have been playing with TFormPoint.
It seems that TFormPoint function makes something similar:

TFormPoint Mousex()-CamWidth/2.0,CamHeight/2.0-MouseY(),Z#,Camera,0

is it ok?

P.D: Anyway, that code works perfect, thanks!