• Create Account

### #ActualKoder4Fun

Posted 06 August 2012 - 04:26 AM

If I understood correctly you want to draw 3d elements on the graphics user interface of your game.
You are right, you can use Unproject() but the parameters you feed are incorrect.

Near and far points must contain:
Vector3 NearScreenPoint = new Vector3(cx, cy, 0);
Vector3 FarScreenPoint = new Vector3(cx, cy, 1);

where cx and cy are the position in pixels referred to the current viewport (so take care of what is the current active viewport).

Now you can calculate Direction using:
Direction = Vector3.Lerp(NearScreenPoint, FarScreenPoint, dist);

where dist is a number in range [0..1] to choice the distance of your 3D object from the camera. If you use 0 or 1 you can't see the object, it's clipped away.

Now, to render the object I think is better to use a translation matrix or, more simpler, to send the Direction vector to a shader that do the per-vertex transform on the GPU adding Direction to the mesh vertex position. If you do this on CPU you waste time.

If i'm not clear please post.

### #2Koder4Fun

Posted 06 August 2012 - 04:25 AM

If I understood correctly you want to draw 3d elements on the graphics user interface of your game.
You are right, you can use Unproject() but the parameters you feed are incorrect.

Near and far points must contain:
Vector3 NearScreenPoint = new Vector3(cx, cy, 0);
Vector3 FarScreenPoint = new Vector3(cx, cy, 1);

where cx and cy are the position in pixels referred to the current viewport (so take care of what is the current active viewport).

Now you can calculate Direction using:
Direction = Vector3.Lerp(NearScreenPoint, FarScreenPoint, dist);

where dist is a number in range [0..1] to choice the distance of your 3D object from the camera. If you use 0 or 1 you can't see the object, it's clipped away.

Now, to render the object I think is better to use a translation matrix or, more simpler, to send the Direction vector to a shader that do the per-vertex transform on the GPU adding Direction to the mesh vertex position. If you do this on CPU you waste time.

If i'm not clear please post.

### #1Koder4Fun

Posted 06 August 2012 - 04:24 AM

If I understood correctly you want to draw 3d elements on the graphics user interface of your game.
You are right, you can use Unproject() but the parameters you feed are incorrect.

Near and far points must contain:
Vector3 NearScreenPoint = new Vector3(cx, cy, 0);
Vector3 FarScreenPoint = new Vector3(cx, cy, 1);

where cx and cy are the position in pixels referred to the current viewport (so take care of what is the current active viewport).

Now you can calculate Directon using:
Vector3.Lerp(NearScreenPoint, FarScreenPoint, dist);

where dist is a number in range [0..1] to choice the distance of your 3D object from the camera. If you use 0 or 1 you can't see the object, it's clipped away.

Now, to render the object I think is better to use a translation matrix or, more simpler, to send the Direction vector to a shader that do the per-vertex transform on the GPU adding Direction to the mesh vertex position. If you do this on CPU you waste time.

If i'm not clear please post.

PARTNERS