简体   繁体   English

Android OpenGL ES 1.0 中的广告牌

[英]Billboarding in Android OpenGL ES 1.0

I'm trying to get billboarding to work, but having trouble with the last step.我试图让广告牌工作,但在最后一步遇到了麻烦。

After following these directions from NeHe's tutorials (http://nehe.gamedev.net/data/articles/article.asp?article=19) I have my look, right, and up vectors, and I have already translated the modelview matrix to the centerpoint of the billboard by using glTranslatef().在遵循 NeHe 教程 (http://nehe.gamedev.net/data/articles/article.asp?article=19) 中的这些指示后,我有我的外观、右和上向量,并且我已经将模型视图矩阵转换为使用 glTranslatef() 获得广告牌的中心点。

float[] m = {right.x,right.y,right.z,0f,
            up.x,up.y,up.z,0f,
            look.x,look.y,look.z,0f,
            pos.x,pos.y,pos.z,1f}; //pos is the centerpoint position
gl.glMultMatrixf(m, 0);

When I try to create a multiplication matrix out of these like so, the billboards are displayed all over the place in the wrong positions and orientations.当我尝试像这样创建乘法矩阵时,广告牌会以错误的位置和方向显示在各处。

I guess my problem is that I don't know how to correctly create and multiply the matrix.我想我的问题是我不知道如何正确创建和乘以矩阵。 I tried doing this instead, but then half the lines (the ones that need to rotate counter-clockwise) are rotated in the wrong direction:我尝试这样做,但是一半的线(需要逆时针旋转的线)以错误的方向旋转:

//normal is the vector that the billboard faces before any manipulations.
float angle = look.getAngleDeg(normal); //returns angle between 0 and 180.
gl.glRotatef(angle, up.x,up.y,up.z);

Got it, using my second method.明白了,用我的第二种方法。 Calculating the angle between vectors (arccos of the dot product) can only give an angle between 0 and 180, so half the time you want to negate the angle so the rotation is in the opposite direction.计算向量之间的角度(点积的 arccos)只能给出 0 到 180 之间的角度,所以一半的时间你想否定这个角度,所以旋转方向是相反的。

This is easy to check...since I already have the right vector, I can just check if the angle between the right vector and the normal is acute.这很容易检查......因为我已经有了正确的矢量,我可以检查正确的矢量和法线之间的角度是否是锐角。 If it's acute, then you want to negate the original angle.如果它是尖锐的,那么你想否定原始角度。

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

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