简体   繁体   English

包装OpenGL矩阵翻译

[英]Wrap OpenGL Matrix translation

Let's say i have an OpenGL 4x4 Matrix i use for some transformation, inside my call i use "translate" many times but then, at the end, i want to "wrap" that translation around a specific size, so, in 2D terms, let's say that i translate X by 210, then i want to wrap that translation into a "50 width" box, resulting in a translation of 10 (210 % 50). 假设我有一个用于转换的OpenGL 4x4矩阵,在我的调用中,我多次使用“翻译”,但最后,我想将转换翻译“包裹”在特定尺寸附近,因此,以2D术语来说,假设我将X翻译为210,然后我想将该翻译包装到“ 50宽度”框中,得到10的翻译(210%50)。

Since i need to convert the coordinates into screen pixels i init my Matrix in this way: 由于我需要将坐标转换为屏幕像素,因此我以这种方式初始化矩阵:

private float[] mScreenMatrix = {
        2f / width, 0f, 0f, 0f,
        0f, -2f / height, 0f, 0f,
        0f, 0f, 0f, 0f,
        -1f, 1f, 0f, 1f
};

So, if width is "50" and i call Matrix.translateM(210,0,0) how can i then "wrap" this Matrix so the final translation on x is just 10? 因此,如果宽度为“ 50”并且我调用Matrix.translateM(210,0,0),那么我该如何“包装”此矩阵,以使x上的最终转换仅为10?

You can't (without doing extra work) because that wrap introduces modulo arithmetic (or a toroidal topology) which doesn't match the way OpenGL's NDC space (which roughly translate to the volume you can see in the window) is laid out. 您不能(不做额外的工作)是因为该包装引入了模算术(或环形拓扑),该算术与OpenGL的NDC空间(大致转化为您在窗口中看到的体积)的布局方式不匹配。 When a primitive reaches out of NDC space it gets clipped so that what remains is within NDC space. 当图元超出NDC空间时,它会被裁剪,以便保留在NDC空间中。

So in order to get a toroidal topology you have to duplicate primitives that get clipped by the NDC and reintroduce them to appear the opposite end of NDC. 因此,为了获得环形拓扑,您必须复制被NDC裁剪的图元,然后重新引入它们以显示NDC的另一端。 The only ways to do this is either by explicit submission of extra geometry or by using the geometry shader to create such geometry in-situ. 做到这一点的唯一方法是通过明确提交额外的几何图形或使用几何图形着色器在原位创建此类几何图形。

If you are using orthogonal projection then you can render to a texture and then wrap it as you wish in the second render pass. 如果使用的是正交投影,则可以渲染为纹理,然后根据需要在第二个渲染过程中将其包装。 If you are using perspective projection, still you can use the same method, but the result will be unrealistic. 如果您使用透视投影,仍然可以使用相同的方法,但是结果将是不现实的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM