Joined: 17 Feb 2008 Posts: 524 Location: Inside the Intel CET shadow stack
Posted: Wed Sep 15, 2010 8:48 am Post subject: Projecting 3D object to 2D plane
I'm working on some C# code that uses GDI to display some graphics, and I'd like to draw a '3D' cube using some projection math. The basic idea is that given a set of points in 3D space and a viewplane (i.e. a camera) you can create a 2D image displaying the 3D object. DirectX and OpenGL do these transformations. I believe it's known as Perspective Projection.
What I can't figure out is exactly how this math is done. I've read up on Wikipedia, but they go full frontal crazy with matrix multiplication.
Does anyone know how to do it? It's driving me insane. _________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time.
If you're doing raster graphics, the best way to get started (IMHO) is to simply omit the depth coordinates. This is the simplest form of projection (orthographic).
Once you can spin a cube around in such a fashion, the need for something more sophisticated will probably become evident - you have to compensate for the fact that distant objects appear smaller. One approach you could try would be to scale points according to their depth. This works, but only for objects that are viewed from one perspective (directly overhead). Start moving things around, and you introduce distortion.
The generally approved approach is to "project" objects using a plane some distance from the viewpoint and scaling according to distance from the plane rather than depth from the viewpoint. To calculate the projection, you pass a ray from the viewpoint to the point to be drawn and look at its intersection with the plane. This is where the trig comes into play. You can absolutely do this process without matrices, but there's no way to avoid the trig.
I'm terrible at explaining this because I'm fairly awful at implementing it. Make sense, though?
Posted: Wed Sep 15, 2010 1:42 pm Post subject: Re: Projecting 3D object to 2D plane
Burningmace wrote:
I'm working on some C# code that uses GDI to display some graphics, and I'd like to draw a '3D' cube using some projection math. The basic idea is that given a set of points in 3D space and a viewplane (i.e. a camera) you can create a 2D image displaying the 3D object. DirectX and OpenGL do these transformations. I believe it's known as Perspective Projection.
What I can't figure out is exactly how this math is done. I've read up on Wikipedia, but they go full frontal crazy with matrix multiplication.
Does anyone know how to do it? It's driving me insane.
The matrix stuff is pretty simple, as far as you need to know, at it's most basic level, it's just an object that can handle / hold translation, rotation, and scaling of an object. In this case, it's a 4x4 array that holds numbers. Probably the most important operation you'll be doing on them is concatenation.
and create a world matrix:
... which is just a matrix set to its identity (for now). I never bothered setting up a view matrix because I was lazy, so I just move the actual world itself.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum