This project is read-only.

2D Coordinates

Apr 21, 2011 at 4:23 PM

Hi,

I have a marker which generates a sphere and I want to know X,Y  of this sphere. I think I need what I require is the Screen Coordinates (640,480) image. Anyone who can help me out here?.

Thanks

Regards,

Janidu

Apr 21, 2011 at 6:52 PM
Edited Apr 21, 2011 at 6:53 PM

I assume your sphere is attached to a sphereTransformNode and the sphereTransformNode is attached to a markerNode.  You can use the XNA's Viewport.Project method to get the screen coordinates of a 3D point in your scene.  You can access the default Viewport through Goblin's State class.  It will look something like this:

var coor2d = State.Device.Viewport.Project(
                     sphereTransformNode.Translation, // The 3D coordinates (Vector3) you want to project to screen space
                     State.ProjectionMatrix,          // Projection matrix of your camera
                     Matrix.Identity,                 // View matrix of your camera (since ALVAR camera is located at 0,0,0 we can just pass Identity)
                     markerNode.WorldTransformation); // The world transform of your Vector3.  We pass the marker's transform since it's attached to the marker

The Viewport.Project function will return a Vector3.  The X and Y values will be your screen coordinates.  The Z value will be between 0 and 1 and will specify the value of the 3d point in the depth buffer.  Please refer to XNA's documentation if you need more info.

Apr 21, 2011 at 7:35 PM

Thank you so much it worked :) . I set the PreferredBackBufferWidth to 640 and PreferredBackBufferHeight to 480I hope that it does not make an negative effect for the coordinations.

Really appriciate for taking your time,

Regards,

Janidu