move 3d object w mouse

Blitz3D Forums/Blitz3D Programming/move 3d object w mouse

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I wrote this code based on a function from the code archives:

; -----------------------------------------------------------------------------
; 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
;-----------------------------------------------------------------------------


The code from the archives moved 3D objects on a plane parallel to the camera but I wanted to move the objects around on the ground plane. The parameters are pretty simple: usecam is the camera, entity is the object being moved, x2d is the mouse's x position, y2d is the mouse's y position, and the optional parameters are height to define the plane to move on and camZoom is the camera's zoom setting.