1
\$\begingroup\$

I am using "GraphicsDevice.Viewport.Project()" to create a "3D" waypoint system like so;

Waypoint

I have a farPlaneDistance of 5000 in my camera;

objProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), flAspectRatio, 1.0f, 5000.0f);

Obviously when the waypoint is farther than 5000, it cant find it within the viewport and bugs out. Is there another way to display waypoints on screen (within a 3D world) without using GraphicsDevice.Viewport.Project()?

Or, is increasing my z buffer out to 100,000 not that big of an issue (i find this hard to believe)?

Learning as I go, Thanks in advance!

Linuxx

\$\endgroup\$
  • 1
    \$\begingroup\$ Is it only the waypoints that suffer from this problem? If so, you might be able to relocate that part of the drawing into some sort of 2D overlay along with the rest of your user interface. \$\endgroup\$ – Seth Battin May 6 '13 at 0:39
  • \$\begingroup\$ As seth mentioned, the better solution would be to implement a 2D overlay. Additionally, if you want the indicator to be rendered in the 3D space, simply clip it to the end of the view frustum to ensure it is visible if the actual waypoint is further away. \$\endgroup\$ – Evan May 6 '13 at 21:03
2
\$\begingroup\$

The problem with a large farPlaneDistance is floating point errors. This can cause things to draw in the wrong order because multiple verts are getting are falling withing the values that a float can re-present.

I recommend doing something like the below to lock the object a certain distance from the camera if it is too far away.

var location = Vector3.Subtract(object.Vector3, camera.Vector3);
if (location.length > 5000) {
    location.normalize();
    location.Multiply(5000)
    object.Vector3 = Vector3.Addition(camera.Vector3 + location);
}

Another common solution is to use point sprites but they are not supported in XNA 4.0.

\$\endgroup\$
  • \$\begingroup\$ XNA 4.0 doesn't seem to have a Scale() method, so I created my own version of this and failed miserably. pastebin.com/uiAGPGS1 \$\endgroup\$ – Linuxx May 6 '13 at 17:25
  • \$\begingroup\$ My bad its Vector2.Multiply. \$\endgroup\$ – ClassicThunder May 6 '13 at 20:14
  • \$\begingroup\$ w00t, it worked. Thanks a ton. Sorry for the noobish, I'm still learning. Here is the end result, just in case someone wants to see it. pastebin.com/YFed0DKZ \$\endgroup\$ – Linuxx May 7 '13 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.