mouse troubles

Blitz3D Forums/Blitz3D Programming/mouse troubles

Jeroen(Posted 2005) [#1]
Hi there!

I am trying to control a object in 3D space by moving the mouse.

y#=(MouseYSpeed()/3)*-1
MoveMouse gfx_w/2, gfx_h/2
MoveEntity p\entity,0,0,y#


The /3 dividing is just a number...I need to follow a different direction.

The camera is tilted and up in the air, and now I notice the object moves in a very difficult way.

How can I make my object exactly follow my mouse?
Translate x,y coordinates to 3d so my object sticks to it
(in two axes, Y must always be 0, Z and X are variable)

Thank you!


KuRiX(Posted 2005) [#2]
There is some code in the codearchives posted by BlitzSupport to do this. Something that entity2dIn3d or so... i can't remember now where... sorry...


Baystep Productions(Posted 2005) [#3]
I try CameraPick/Project on the MouseX/Y
Or PositionEntity entity,mousex*multiplier,etc,etc.


Shifty Geezer(Posted 2005) [#4]
http://www.blitzbasic.com/codearcs/codearcs.php?code=379

Works perfectly for me


Jeroen(Posted 2005) [#5]
Hi there,

Thanks for the answers. I tried to change PositionEntityFrom2D so that it would work on X and Z (and keep Y=1), but the problem is that I need to do CameraPick and so forth, which is not an option: the object should be glued to the mouse directly :-(


jhocking(Posted 2005) [#6]
That code archive function works great. For a project years ago, I wrote a variation that moved the object on a horizontal plane (that code moves the object on a plane parallel to the camera.)

Here's the code:
; -----------------------------------------------------------------------------
; 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
;-----------------------------------------------------------------------------