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

本文介绍了一种称为圆柱体化广告牌的技术,它通过调整模型视图矩阵中的right向量和lookAt向量来实现。这种方法适用于树木等不需要随摄像机上下移动的对象,能有效减少不必要的旋转。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 matrix
glPushMatrix();

// get the current modelview matrix
glGetFloatv(GL_MODELVIEW_MATRIX , modelview);

// The only difference now is that
// the i variable will jump over the
// up vector, 2nd column in OpenGL convention

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 matrix with the 
// up vector unchanged
glLoadMatrixf(modelview);

drawObject();

// restores the modelview matrix
glPopMatrix();


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 matrix
	glPushMatrix();

	// get the current modelview matrix
	glGetFloatv(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 matrix
	glLoadMatrixf(modelview);
}



void billboardEnd() {

	// restore the previously 
	// stored modelview matrix
	glPopMatrix();
}


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 call billboardCheatCylindricalBegin().

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值