什么是背后的3D广告牌精灵的数学? (是:3D转换矩阵二维矩阵)矩阵、广告牌、精灵、数学

2023-09-07 17:54:42 作者:空城旧梦

我有一个三维点的空间。该点的准确定位/位置是通过的4x4变换矩阵pssed EX $ P $。

I have a 3D point in space. The point's exact orientation/position is expressed through a 4x4 transformation matrix.

我要画一个广告牌(3D雪碧)本点。 我知道了突出位置的点(即3D-> 2D);广告牌正对着相机,这是非常有帮助了。 什么我不知道的是缩放的广告牌应该有!的

I want to draw a billboard (3D Sprite) to this point. I know the projected position (i.e. 3D->2D) of the point; the billboard is facing the camera so that's very helpful too. What I don't know is the scaling that the billboard should have!

为了让事情更加复杂,在 4x4矩阵可能有各种各样的变换:3D旋转,3D缩放,3D换位。假设相机一样简单,因为它可以:(0,0,0)的位置,没有旋转

To make things more complex, the 4x4 matrix may have all sorts of transformations: 3D rotation, 3D scaling, 3D transposition. Assume that the camera is as simple as it can be: position at (0,0,0), no rotation.

所以,我可以从这个4x4矩阵提取的广告牌精灵的比例?

So, can I "extract" the scaling of the billboard sprite from this 4x4 matrix?

我有一个3D仿射变换4x4矩阵。我需要它(项目)转换为2D仿射变换3x3矩阵,它看起来是这样的:

I have a 3D affine transformation 4x4 matrix. I need to convert it (project) to a 2D affine transformation 3x3 matrix, which looks like this:

3D旋转是不相关的,如果present可能会被丢弃;我感兴趣的只是翻译,最重要的尺度。

3D rotations are irrelevant and if present may be discarded; I am only interested in translation and most importantly scaling.

任何人都可以帮助方程为每个六类 4 值? (可以说的 T X ,T 是 也被称为)

Can anyone help with the equations for each of the six 4 values? (lets say tx, ty are also known)

附加信息:

将Matrix3D是一个三维点的全球变革,说(0,0,0)。其目的是在2D平面上(计算机屏幕),以进行投影。

The Matrix3D is the global transformation of a 3D point, say (0,0,0). Its purpose is to be projected on a 2D plane (the computer screen).

我知道如何投射3D点到二维空间的,我找的是preserve超出了位置的附加转换信息,即缩放:正如你可能知道,在缩放投影在2D平面上的点时,属性也改变了。

I know how to project a 3D point to 2D space, what I am looking for is to preserve additional transformation information beyond position, i.e. scaling: as you may know, the scaling property is also altered when projecting the point on a 2D plane.

我也忘了提及,在透视投影性质也是已知的,即:

I also forgot to mention that the perspective projection properties are also known, i.e.:

field of view (single value)
focal length (single value)
projection center (viewpoint position - 2D value)

推荐答案

如果您不使用球面坐标系那么这个任务不解决的。

if you not using spherical coordinate system then this task is not solvable

因为discarting投影之前的Z坐标 将删除的距离形成的投影点 ,所以你不知道如何应用透视

您有两个选择(除非我忽略的东西):

You have two choices (unless I overlooked something):

1.适用3D变换矩阵

1.apply 3D transform matrix

,然后只用X,Y - 结果的坐标

旋转/投影2.创建3x3变换矩阵

2.create 3x3 transformation matrix for rotation/projection

并应用它之前或之后加偏移向量 请注意,这种方法不使用齐次坐标!

- 方程清楚

请不要忘记,3x3矩阵+矢量变换不累积! 这就是为什么4×4变换被用来代替的原因 现在,你可以扔掉矩阵/矢量的最后一行(XZ,YZ,ZZ),(Z0) ,然后将输出向量只是(X',Y') 当然,在这之后,你不能使用逆变换,因为你失去了Z坐标 缩放是通过改变轴方向向量 的尺寸做 do not forget that 3x3 matrix + vector transforms are not cumulative !!! that is the reason why 4x4 transforms are used instead now you can throw away the last row of matrix/vector (Xz,Yz,Zz), (z0) and then the output vector is just (x', y') of course after this you cannot use the inverse transform because you lost Z coordinate scaling is done by changing the size of axis direction vectors

顺便说一句。如果你的投影平面也是XY平面没有旋转,那么:

Btw. if your projection plane is also XY-plane without rotations then:

x' = (x-x0)*d/(z-z0)
y' = (y-y0)*d/(z-z0)

(X,Y,Z) - 点项目 (X',Y') - 投影点 (X0,Y0,Z0) - 投影原点 ð - 焦距

(x,y,z) - point to project (x',y') - projected point (x0,y0,z0) - projection origin d - focal length

好后的问题编辑的意义是完全不同的

我想你想的精灵总是面对镜头

丑陋,但简化了的东西,如草,树木,... I assume you want sprite always facing camera

ugly but simplifies things like grass,trees,...

米 - 你的矩阵

1。如果你知道投影矩阵(我假设它是glFrustrum或gluPerspective ...)

1.if you know the projection matrix (I assume it is glFrustrum or gluPerspective ... )

(x,y,z,w)=(M*(P^-1))*pnt  // transformed center of billboard without projection
A=P*(x-dx,y-dy,z,w)
B=P*(x-dx,y+dy,z,w)
C=P*(x+dx,y+dy,z,w)
D=P*(x+dx,y-dy,z,w)

2,如果你的×M矩阵是太复杂,一上班

2.If your M matrix is too complex for 1. to work

MM=(M*(P^-1))     // transform matrix without projection
XX=MM(Xx,Xy,Xz)   // X - axis vector from MM [GCS](look at the image above on the right for positions inside matrix)
YY=MM(Yx,Yy,Yz)   // Y - axis vector from MM [GCS]
X =(M^-1)*XX*dx   // X - axis vector from MM [LCS] scaled to dx
Y =(M^-1)*YY*dy   // Y - axis vector from MM [LCS] scaled to dy
A = M*(pnt-X-Y)
B = M*(pnt-X+Y)
C = M*(pnt+X+Y)
D = M*(pnt+X-Y)

仅scalling

MM=(M*(P^-1))     // transform matrix without projection
sx=|MM(Xx,Xy,Xz)|  // size of X - axis vector from MM [GCS] = scale x
sy=|MM(Yx,Yy,Yz)|  // size of Y - axis vector from MM [GCS] = scale y