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

前端 未结 1 726
一个人的身影
一个人的身影 2021-01-02 03:33

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 f

相关标签:
1条回答
  • 2021-01-02 04:21

    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.

    0 讨论(0)
提交回复
热议问题