Coordinate transfer question

Jul 18, 2008 at 1:32 PM
Dear all

Could someone tell me how to get the projected X,Y coordinate on screen from a Actor.Position(Vector3) ?

Jul 19, 2008 at 8:45 PM
Edited Jul 19, 2008 at 8:49 PM
This will unproject a Vector3. You need to pass in the vector and camera, and the actor's world matrix and position. I'd put this in the XTools class.

public Vector3 UnprojectVector3(Vector3 Vector, XCamera Camera, Matrix World)
        return X.GraphicsDevice.Viewport.Unproject(Vector, Camera.Projection, Camera.View, World);

This is will get the world matrix from an actor, put it in the XActor class to use it.

public Matrix GetWorldMatrix()
return PhysicsBody.GetWorldMatrix(model.Model, modeloffset);

From there you could create another method to get the screen coordinates directly from the actor class.

public Vector3 GetScreenCoordinates(XCamera Camera)
        return X.Tools.UnprojectVector3(this.Position, Camera, GetWorldMatrix());