当前位置: 代码迷 >> Open API >> opengl图形旋转与放缩有关问题
  详细解决方案

opengl图形旋转与放缩有关问题

热度:9353   发布时间:2013-02-26 00:00:00.0
opengl图形旋转与放缩问题
下面是程序代码的一部分,运行结果是图形不能实现绕形心旋转,
请高手指点一下:

// Begin a new triangle fan to cover the bottom
glClear(GL_COLOR_BUFFER_BIT); //用背景色清窗口  
// Save matrix state and do the rotation
float color_r,color_g,color_b;
glPushMatrix();

glRotatef(xRot, 1.0f,0.0f,0.0f);
glRotatef(yRot, 0.0f,1.0f,0.0f);
glColor3f(0.0f, 0.0f, 0.0f);

for(int i = begin_i+2; i<ROW-4;i=i+1)
{
for(int j =begin_i+2; j<COL-4;j=j+1)
{
if (TextImage_r[i*COL+j]!=-1)
{
glColor3f(TextImage_r[i*COL+j]/256, TextImage_g[i*COL+j]/256, TextImage_b[i*COL+j]/256);

glBegin(GL_POINTS);
glVertex3f((Topography_x[i*COL+j])/ZOOMSIZE, (Topography_y[i*COL+j])/ZOOMSIZE, (Topography_z[i*COL+j])/ZOOMSIZE+10);
/*
glVertex3f((Topography_x[(i-2)*Y_SIZE+j-2])/ZOOMSIZE, (Topography_y[(i-2)*Y_SIZE+j-2])/ZOOMSIZE, (Topography_z[(i-2)*Y_SIZE+j-2])/ZOOMSIZE);
glVertex3f((Topography_x[(i)*Y_SIZE+j-2])/ZOOMSIZE, (Topography_y[(i)*Y_SIZE+j-2])/ZOOMSIZE, (Topography_z[(i)*Y_SIZE+j-2])/ZOOMSIZE);
glVertex3f((Topography_x[(i+2)*Y_SIZE+j-2])/ZOOMSIZE, (Topography_y[(i+2)*Y_SIZE+j-2])/ZOOMSIZE, (Topography_z[(i+2)*Y_SIZE+j-2])/ZOOMSIZE);
glVertex3f((Topography_x[(i+2)*Y_SIZE+j]/ZOOMSIZE), (Topography_y[(i+2)*Y_SIZE+j]/ZOOMSIZE), (Topography_z[(i+2)*Y_SIZE+j])/ZOOMSIZE);
glVertex3f((Topography_x[(i+2)*Y_SIZE+j+2]/ZOOMSIZE), (Topography_y[(i+2)*Y_SIZE+j+2]/ZOOMSIZE), (Topography_z[(i+2)*Y_SIZE+j+2]/ZOOMSIZE));
glVertex3f((Topography_x[(i)*Y_SIZE+j+2]/ZOOMSIZE), (Topography_y[(i)*Y_SIZE+j+2]/ZOOMSIZE), (Topography_z[(i)*Y_SIZE+j+2]/ZOOMSIZE));
glVertex3f((Topography_x[(i-2)*Y_SIZE+j+2]/ZOOMSIZE), (Topography_y[(i-2)*Y_SIZE+j+2]/ZOOMSIZE), (Topography_z[(i-2)*Y_SIZE+j+2]/ZOOMSIZE));
glVertex3f((Topography_x[(i-2)*Y_SIZE+j]/ZOOMSIZE), (Topography_y[(i-2)*Y_SIZE+j]/ZOOMSIZE), (Topography_z[(i-2)*Y_SIZE+j]/ZOOMSIZE));
*/

glEnd();


}

}
}


glPopMatrix();

------解决方案--------------------------------------------------------
glBegin(GL_POINTS);
for(int i = begin_i+2; i<ROW-4;i=i+1)
{
for(int j =begin_i+2; j<COL-4;j=j+1)
{
if (TextImage_r[i*COL+j]!=-1)
{
glColor3f(TextImage_r[i*COL+j]/256, TextImage_g[i*COL+j]/256, TextImage_b[i*COL+j]/256);


glVertex3f((Topography_x[i*COL+j])/ZOOMSIZE, (Topography_y[i*COL+j])/ZOOMSIZE, (Topography_z[i*COL+j])/ZOOMSIZE+10);

}

}
}
glEnd();


其他的部分还行, 是可以实现 几所有点绕某点公转的。
------解决方案--------------------------------------------------------
先平移,再旋转,再平移回去。就实现了绕心旋转。
------解决方案--------------------------------------------------------
这个区真冷~~~~
------解决方案--------------------------------------------------------
探讨
先平移,再旋转,再平移回去。就实现了绕心旋转。

------解决方案--------------------------------------------------------
对啊,是学这个的人少么?
------解决方案--------------------------------------------------------
还是一般和别的软件语言什么的相关了去别处了
------解决方案--------------------------------------------------------
最近打算学这个,关注