Moving an entity with the mouse?

Blitz3D Forums/Blitz3D Programming/Moving an entity with the mouse?

Hi, I want to be able to move an entity forward, back, left & right with the mouse, the problem im having is coming up with a good function to compensate for a change in the camera angle.

The code bellow shows the problem, if you rotate the camera(right mouse) and move the object(left mouse) the mouse movements obviously have to alter with the angle.

Any help would be great.

Graphics3D 800,600,32,2

Global camPiv=CreatePivot()
MoveEntity camPiv,1.5,0,0
Global Camera=CreateCamera(camPiv)
CameraClsColor Camera,0,0,0
CameraRange Camera,1,1000
MoveEntity Camera,0,30,-35
RotateEntity Camera,20,0,0
CameraViewport Camera, 0, 0, GraphicsWidth (), GraphicsHeight ()

Global nyaw#,npitch#
Global dampen#=0.2
Global gameFPS = 60

Global Light=CreateLight()

RotateEntity Light,45,-90,0
LightColor Light,200,200,200
AmbientLight 130,130,130

Plane=CreatePlane()
EntityAlpha Plane,0.7
PlaneTexture=CreateTexture(128,128,9)

ClsColor 0,0,0
Cls

Color 255,255,255

Rect 0,0,64,64,1
Rect 64,64,64,64,1

CopyRect 0,0,128,128,0,0,BackBuffer(),TextureBuffer(PlaneTexture)
ScaleTexture PlaneTexture,20,20
EntityTexture Plane,PlaneTexture,0,0

Mirror=CreateMirror()

cube=CreateCube()
ScaleEntity cube,4,4,4
PositionEntity cube,0,10,0


framePeriod = 1000 / gameFPS
frameTime = MilliSecs () - framePeriod

Repeat
	FlushMouse 
	Repeat
		frameElapsed = MilliSecs () - frameTime
	Until frameElapsed

	frameTicks = frameElapsed / framePeriod
	frameTween# = Float (frameElapsed Mod framePeriod) / Float (framePeriod)

	For frameLimit = 1 To frameTicks
	
		If frameLimit = frameTicks Then CaptureWorld
		frameTime = frameTime + framePeriod

		If MouseDown(1)
			MoveEntity cube,MouseXSpeed()/5,0,-MouseYSpeed()/5
			MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
		EndIf
	
		If MouseDown(2)
			nyaw#=-MouseXSpeed()*dampen+EntityYaw(camPiv)
			RotateEntity camPiv,0,nyaw#,0
			MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
		EndIf

		MXS = MouseXSpeed()
		MYS = MouseYSpeed()
		MZS = MouseZSpeed()
		
	Next

	RenderWorld frameTween

	Flip False
Until KeyHit(1)

End


Maybe...
TFormVector MouseXSpeed()/5.0,0,-MouseYSpeed()/5.0,campiv,0
TranslateEntity cube,TFormedX(),0,TFormedZ()

or ...

TFormVector MouseXSpeed()/5.0,0,-MouseYSpeed()/5.0,campiv,cube
MoveEntity cube,TFormedX(),TformedY(),TFormedZ()

Edit... I have added tformedy() back into the second one, just in case you decide to start rotating the cube.

Something to bear in mind is using moveentity the movement will be scaled by the entity scale. Not so bad perhaps and maybe what you are after, but if the entity is not uniformly scaled it is going to go every which way, so you will have to scale your movement accordingly. i.e.
TFormVector MouseXSpeed(),0,-MouseYSpeed(),campiv,cube
MoveEntity cube,TFormedX()*xscale*0.2,TFormedY()*yscale*0.2,TFormedZ()*zscale*0.2

The first option using translateentity avoids this issue.

Easy solution.

guide = createpivot()

repeat

positionentity guide,0,0,0
rotateentity guide,0,entityyaw(camera),0
moveentity guide,mousexspeed(),0,mouseyspeed()

moveentity thingy,entityx(guide),0,entityz(guide)

until keyhit(1)

Anyway... totally untested but you get the idea.

Thanks guys.

It always seems to be a pivot. I have the same prob! : )
-RZ