Move 3D Object on Screen
Try to use mouse to move the object on screen. Such as the "PAN" action for 3d application. I converted screen coordinate to world coordinate. But result is wrong. Wish to get help. Thanks.
Try to use mouse to move the object on screen. Such as the "PAN" action for 3d application. I converted screen coordinate to world coordinate. But result is wrong. Wish to get help. Thanks.
"It doesn't work - please help" is saldy not enough information to go on.
There are lots of samples for 'picking' out there in native, managed, DirectX and OpenGL - have you tried to work through those?
Maybe if you let us know
a) what language you are using
b) what you have tried so far and what doesn't work
c) what samples you have searched for yourself and why those don't work for you. Searching google, these forums and those on gamedev.net and you will find this questions has been answered many, many times. e.g. here is one using c# http://www.mdxinfo.com/tutorials/picking.php
Thanks. It's great help. I am using C# and similar method you mentioned. Here is my code:
Movement is the class which has the properties of mouse drag start position(XStart, YStart) and end position (X, Y)
Thanks a lot.
public void Move(Movement movement)
{
Vector3 startPosition = new Vector3(movement.XStart, movement.YStart, 0.0F);
Vector3 endPosition = new Vector3(movement.X, movement.Y, 0.0F);
startPosition = Vector3.Unproject(
startPosition,
device.Viewport,
device.Transform.Projection,
device.Transform.View,
device.Transform.World);
endPosition = Vector3.Unproject(
endPosition,
device.Viewport,
device.Transform.Projection,
device.Transform.View,
device.Transform.World);
Vector3 moveVector = Vector3.Subtract(endPosition, startPosition);
Matrix translationMatrix = Matrix.Translation(moveVector);
device.Transform.World *= translationMatrix;
}