广告牌技术:欺骗-圆柱体化广告牌

来源:互联网 发布:云计算安全问题 编辑:程序博客网 时间:2024/04/27 20:51

As mentioned in the previous section, the modelview matrix contains the transformations required to perform the change of coordinates between local coordinates and world coordinates. It has been shown that by replacing the top 3x3 submatrix with the identity matrix a cheating version of spherical billboarding can be obtained. But what about Cylindrical billboarding?

正如先前提到的,模型视图矩阵包括使物体坐标在局部坐标空间与世界坐标空间转变的变换操作。已经展示过了,通过替换top3X3子矩阵为单位矩阵,一个欺骗性质的球体化广告牌获得了。但是圆柱体化的广告牌呢?

Let us analyze in depth what is actually the structure of the top 3X3 submatrix. This matrix contains 3 columns, and each has a special meaning. The first is the right vector, the second column is the up vector and the 3rd represents the lookAt vector. These vectors are relative to the cameras orientation. Setting the top 3x3 submatrix to the identity matrix effectively causes the camera's coordinate system to be aligned with the worlds coordinate system.

让我们深度分析一下top3X3子矩阵的实际结构。这个矩阵包括3列,每一列都有一个特殊含义。第一列是右向量,第二列是上向量,第三列是lookAt向量。这些向量是相机方向相关的。设置top3X3子矩阵为单位矩阵将引起相机坐标系统的坐标轴与世界坐标系的轴平行。

In order to achieve a (cheating) Cylindrical Billboard, it is sufficient to align the right and lookAt vectors, leaving the up vector unchanged. The difference between this version and the spherical one, presented in the previous section, is that when the camera looks up or down the billboard won't move. The billboard will only be rotated when the camera looks right or left.

为了获得(欺骗性质)圆柱体化广告牌,有必要调整right向量和lookAt向量,保持up向量不变。这个版本和球体化广告牌的区别在前文中已经讲述过,也就是当相机looks up或者down的时候广告牌不移动。当相机向右或向左看的时候广告牌仅仅被旋转。

This type of billboards can be applied to trees. Trees don't bend backwards and forwards as the camera looks down or up because the up vector is fixed, so it doesn't make much sense to use a spherical billboard. Beware that the illusion is broken when you fly over the tree. In this case you'll see your tree getting thinner and thinner and all is lost. However if you're application keeps you on the terrain then cylindrical billboarding is a good option.

这个类型的广告牌可以被应用于树木。树木不会向前或向后倾斜当相机向上或向下观察的时候,因为up向量是固定不变的,所以使用球体化的广告牌没有多大意义。要意识到当你从树木顶部飞过的时候这个假象会暴露。这种情况下你会发现你的树越来越细直至消失。然而如果你的应用程序保持你在地面那么圆柱体化广告牌将会是一个不错的选择。

The code for cheating cylindrical billboards is almost identical to the spherical version.
欺骗性质的圆柱体化广告牌的代码几乎和球体化的相同。
float modelview[16];int i,j;// save the current modelview matrixglPushMatrix();// get the current modelview matrixglGetFloatv(GL_MODELVIEW_MATRIX , modelview);// The only difference now is that// the i variable will jump over the// up vector, 2nd column in OpenGL conventionfor( i=0; i<3; i+=2 ) for( j=0; j<3; j++ ) {if ( i==j )modelview[i*4+j] = 1.0;elsemodelview[i*4+j] = 0.0;}// set the modelview matrix with the // up vector unchangedglLoadMatrixf(modelview);drawObject();// restores the modelview matrixglPopMatrix();


As we did before, the above code can be divided in two functions, besides the rendering function,drawObject. The first function will setup the modelview matrix, and the second will restore the current matrix.
正如我们先前做的,上面的代码可以被分为两个函数,包括渲染函数,drawObject函数。第一个函数设置模型视图矩阵,第二个恢复当前矩阵。

void billboardCheatCylindricalBegin() {float modelview[16];int i,j;// save the current modelview matrixglPushMatrix();// get the current modelview matrixglGetFloatv(GL_MODELVIEW_MATRIX , modelview);for( i=0; i<3; i+=2 )     for( j=0; j<3; j++ ) {if ( i==j )    modelview[i*4+j] = 1.0;else    modelview[i*4+j] = 0.0;    }// set the modelview matrixglLoadMatrixf(modelview);}void billboardEnd() {// restore the previously // stored modelview matrixglPopMatrix();}


The source code for rendering a billboard object becomes:

渲染物体的源代码如下:

billboardCheatCylindricalBegin();    drawObject();billboardEnd();


Again, beware with scaling operations. Scaling in the X and Y axis will be undone using this approach, but scaling in the Z axis will persist. the best option is to scale after you callbillboardCheatCylindricalBegin().

再一次要注意缩放操作。使用这个方法,缩放x y坐标轴将被撤销,但是缩放z轴的操作将被保持。最好的选择是在调用billboardCheatCylindricalBegin()函数之后缩放。

 

原创粉丝点击