I'd like to draw a line in 3D space that is always exactly one pixel wide on screen, no matter how far away from the camera it is. (And the same for single points too).
Any hints on how I could do that?
|
I'd like to draw a line in 3D space that is always exactly one pixel wide on screen, no matter how far away from the camera it is. (And the same for single points too). Any hints on how I could do that? |
||||
|
|
|
Rendering Lines - Method 1 (Primitives) For simple lines in 3D space you can draw them using a
I basically created a simple Of course there are many ways to optimize it, most of which involve the creation of a Rendering Points - Method 1 (SpriteBatch) As for drawing points, this used to be easy using point sprites but they were removed from XNA 4.0. There's a few alternatives though. The easiest way is to create a 1x1 white You can create the required
And render it at location (x,y,z) like this:
Rendering Lines - Method 2 (SpriteBatch) Alternatively, you can also draw lines using a Rendering Points - Method 2 (Small Line with Primitives) In the comments, eBusiness raised the following question:
I gave it a try and rendering a The trick is not to use the same start and end points, but instead to draw a line so small, that it only appears as one pixel when drawn. So, in order to choose the correct end point, I first projected the world space point into screen space, moved it right one pixel in screen space, and finally projected it back into world space. That's the end point of your line in order to make it look like a dot. Something like this:
Followed by rendering it as a normal line primitive. Demonstration Here's what I got drawing a white line in 3D space using a line list primitive, and red dots at both ends of the line using a 1x1 texture and SpriteBatch. The code used is pretty much what I wrote above. I've also zoomed in so you can confirm that they're exactly one pixel wide:
|
|||||||||||
|
|
This is tagged as XNA so I'm assuming that's what you're asking about? If so, this article should be helpful for lines: http://msdn.microsoft.com/en-us/library/bb196414(v=xnagamestudio.40).aspx Of course you can use your own view/projection matrices instead of theirs. Basically, As for points, you can no longer use PrimitiveType.PointList to draw points anymore in XNA 4.0. Instead you would have to make very small triangles. This sample provides a good baseline: http://create.msdn.com/education/catalog/sample/primitives_3d For previous versions of XNA, if you're using one of those, you can go ahead and read the Point part of the XNA 3.0 version of the article posted above: http://msdn.microsoft.com/en-us/library/bb196414(v=xnagamestudio.30).aspx Note the link has:
Obviously change that to |
|||
|
|