主题:[讨论]象素问题(附图)
Craig
[专家分:0] 发布于 2006-07-18 20:27:00
本人在编一个3D眼球加鼠标动作形变的程序
以下是其中一段构造模型的代码
初始是以60乘60构造.即60条经线60条纬线划分球体
/*Generate vertices*/
void vertices (void)
{
int i,k,l;
GLdouble x_temp,r_temp;
GLdouble c=pi/60;
i=1;
for (k=1;k<31;k++)
{x_temp = r*cos(k*c);
r_temp = r*sin(k*c);
for (l = 0; l < 31; l++)
{
vertex[i].x = x_temp;
vertex[i].y = r_temp*cos(l*c);
vertex[i].z = r_temp*sin(l*c);
i++;}
for (l = 1; l < 31; l++)
{
vertex[i].x = vertex[i-2*l].x;
vertex[i].y = -vertex[i-2*l].y;
vertex[i].z = vertex[i-2*l].z;
i++;}
}
for (k=1;k<31;k++)
{for (l = 0; l < 61; l++)
{
vertex[i].x = -vertex[i-122*k].x;
vertex[i].y = vertex[i-122*k].y;
vertex[i].z = vertex[i-122*k].z;
i++;}}
vertex[0].x = r;
vertex[0].y = 0.0;
vertex[0].z = 0.0;
vertex[3600].x = -r;
vertex[3600].y = 0.0;
vertex[3600].z = 0.0;
}
回复列表 (共4个回复)
沙发
Craig [专家分:0] 发布于 2006-07-18 20:29:00
随后用了一幅2D的BMP图铺上去了球体给予皮肤(省)
接着就开始绘制网络
/*Draw geometrical model of human eye*/
void draw_meshes (void)
{
int i,m,u;
glClear(GL_COLOR_BUFFER_BIT);
glPolygonMode(GL_FRONT, GL_FILL);
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,1.0,1.0);
glEnable(GL_NORMALIZE);
/*Draw starting part*/
m=0;/*产生眼球体右极点起一圈的三角形坐标(因为起于极点,所以为三角形)*/
for (i=0; i<60;i++)
{
glBegin(GL_TRIANGLES);
glNormal3d(normal[m+2].x, normal[m+2].y, normal[m+2].z);
glTexCoord2d(texel[m+2].s, texel[m+2].t);
glVertex3d(vertex[m+2].x, vertex[m+2].y,vertex[m+2].z);
glNormal3d(normal[0].x, normal[0].y, normal[0].z);
glTexCoord2d(texel[0].s, texel[0].t);
glVertex3d(vertex[0].x, vertex[0].y,vertex[0].z);
glNormal3d(normal[m+1].x, normal[m+1].y, normal[m+1].z);
glTexCoord2d(texel[m+1].s, texel[m+1].t);
glVertex3d(vertex[m+1].x, vertex[m+1].y, vertex[m+1].z);
glEnd();
m++;
}
m = 1;/*产生眼球体主体部分的四边形坐标)*/
for (u=0;u<58;u++)
{
for (i=0;i<60;i++)
{glBegin(GL_QUADS);
glNormal3d(normal[m].x, normal[m].y,normal[m].z);
glTexCoord2d(texel[m].s, texel[m].t);
glVertex3d(vertex[m].x, vertex[m].y,vertex[m].z);
glNormal3d(normal[m+61].x, normal[m+61].y,normal[m+61].z);
glTexCoord2d(texel[m+61].s, texel[m+61].t);
glVertex3d(vertex[m+61].x, vertex[m+61].y,vertex[m+61].z);
glNormal3d(normal[m+62].x, normal[m+62].y,normal[m+62].z);
glTexCoord2d(texel[m+62].s, texel[m+62].t);
glVertex3d(vertex[m+62].x, vertex[m+62].y,vertex[m+62].z);
glNormal3d(normal[m+1].x, normal[m+1].y,normal[m+1].z);
glTexCoord2d(texel[m+1].s, texel[m+1].t);
glVertex3d(vertex[m+1].x, vertex[m+1].y,vertex[m+1].z);
glEnd();
m++;
}
m++;
}
m=3538;/*产生眼球体左极点起一圈的三角形坐标(因为起于极点,所以为三角形)*/
for (i=0; i<60;i++)
{
glBegin(GL_TRIANGLES);
glNormal3d(normal[3600].x, normal[3600].y,normal[3600].z);
glTexCoord2d(texel[3600].s, texel[3600].t);
glVertex3d(vertex[3600].x, vertex[3600].y,vertex[3600].z);
glNormal3d(normal[m+2].x, normal[m+2].y,normal[m+2].z);
glTexCoord2d(texel[m+2].s, texel[m+2].t);
glVertex3d(vertex[m+2].x, vertex[m+2].y,vertex[m+2].z);
glNormal3d(normal[m+1].x, normal[m+1].y,normal[m+1].z);
glTexCoord2d(texel[m+1].s, texel[m+1].t);
glVertex3d(vertex[m+1].x, vertex[m+1].y,vertex[m+1].z);
glEnd();
m++;
}
if (mode == 0)
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINES);
glVertex3d(winx+5,winy+5,winz);
glVertex3d(winx-5,winy-5,winz);
glVertex3d(winx-5,winy+5,winz);
glVertex3d(winx+5,winy-5,winz);
glEnd();
}
glutSwapBuffers();
glFlush();
}
板凳
Craig [专家分:0] 发布于 2006-07-18 20:29:00
/*Reshape function用于让形变时随时移动*/
void reshapeFcn (GLint newWidth, GLint newHeight)
{
winWidth = newWidth;
winHeight = newHeight;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-winWidth/2, winWidth/2, -winHeight/2, winHeight/2,0,400);
glViewport(0,0,winWidth,winHeight);
}
程序后面还有缓冲,定位接触点与造成形变的代码.这里不列出了
目前问题是,想在鼠标造成球体表面形变同时实现: 让形变区域增加象素(原来是3600).
本人目前想一个方法是,用一块新定义的高象素跟形变区域相吻合的区域去即时取代旧区域.这样来实现当鼠标移动,形变区域同时移动,而该区域不断地由原来3600象素变为更高的如10000象素的效果.我称为铺布法,也可以叫魔镜.但目前头疼不知道如何实现该目标.故发贴请教高手.望有人指点迷津!感激不尽!
[IMG]http://www.babymq.com/msnblog/pic/60pushing.jpg[/img]
3 楼
euc [专家分:4310] 发布于 2006-07-19 14:04:00
不知道,向lz学习~~ 为什么要让眼睛变形呢?
4 楼
Craig [专家分:0] 发布于 2006-07-22 23:45:00
这是deformable ojects类的一个设计...
我来回复