Moving 3D objects with the mouse

Blitz3D Forums/Blitz3D Beginners Area/Moving 3D objects with the mouse

nivek(Posted 2004) [#1]
I’ve noticed that 2D mouse coordinates are not the same as 3D object coordinates. So it’s difficult to move a 3D object with the 2D mouse. I figured out a basic formula but when I scale the 3D object the simple formula no longer works. I’ve looked at a lot of different code to help me figure this out but it all seems to complicated for me at my present level of 3D programming knowledge. Is there a simple formula that takes the 3D object’s scale into account?

Thanks


RiverRatt(Posted 2004) [#2]
Well how about attatching an invisible object you don't need to scale, like say a vector, or a cube with alpha 0.

Yall go easy on me now.


WolRon(Posted 2004) [#3]
Just move the entity in relation to the CHANGE in mouse co-ordinates using the MouseXSpeed(), MouseYSpeed() and MouseZSpeed() commands.


jhocking(Posted 2004) [#4]
There's an example in the code archives to move an object around on a plane parallel to the camera. I modified that function into this to move an object around on a ground plane:

; -----------------------------------------------------------------------------
; Positions an entity in 3D from given 2D coordinates
Function PositionEntityFrom2D(usecam,entity,x2d#,y2d#,height#=0,camZoom#=1)
gw=GraphicsWidth()
gh=GraphicsHeight()
x#=-((gw/2)-x2d)
y#=(gh/2)-y2d
parent=GetParent(entity)
EntityParent entity,usecam
z#=Abs(EntityZ(entity))
div#=(gw/(2/camzoom))/z
x=x/div
y=y/div

;z distance determined by a straight line from camera, through xyz coordinates, to height
TFormPoint x,y,z,usecam,0
y3d#=height
x3d#=TFormedX()
z3d#=TFormedZ()
EntityParent entity,parent
PositionEntity entity,x3d,y3d,z3d
End Function
;-----------------------------------------------------------------------------


BlitzSupport(Posted 2004) [#5]
Nivek, this code should do what you want:

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