Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert 3D space coordinates to 2D space coordinates?

I'm using a Lua API. I'm trying to transform 3D space coordinates to 2D space coordinates. I've asked google but I can't find anything apart from snippets using OpenGL function. I don't need source code or anything just a simple way on how to do it? I can acquire the Camera's perspective, the original position to be transformed, window size and aspect ratio if that's any help? Thanks in advance for any suggestions :)

like image 829
Conros Avatar asked May 26 '11 13:05

Conros


People also ask

What is a 3D world coordinate system?

This coordinate system is a convention used to define the coordinates [0,0,0] in our 3D virtual space and three unit axes orthogonal to each other (figure 4). It's the prime meridian of a 3D scene, a reference to which any other point or any other arbitrary coordinate system is measured to.


1 Answers

If you're talking about transforming world-space (x,y,z) coordinates to screen-space (u,v) coordinates, then the basic approach is:

u = x / z;
v = y / z;

If the camera is not at the origin, transform (x,y,z) by the view matrix before the projection matrix. You may also want to adjust for the camera perspective, aspect ratio etc., in which case I'd refer to this Wikipedia article.

My apologies if you're looking for something specific to the Lua API, which I am not familiar with.

like image 178
ReturningTarzan Avatar answered Oct 23 '22 19:10

ReturningTarzan