赞 | 0 |
VIP | 0 |
好人卡 | 1 |
积分 | 0 |
经验 | 7054 |
最后登录 | 2014-2-23 |
在线时间 | 177 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 49
- 在线时间
- 177 小时
- 注册时间
- 2011-7-3
- 帖子
- 235
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 TheRebirth 于 2013-7-30 18:36 编辑
关键源码如下:(只求各位别光看着就晕过去了就行了)
void CylinderRender(float x1,float x2,float y1,float y2,float z1,float z2,float distance1,float distance2,
float xscale1=1.0,float xscale2=1.0,float yscale1=1.0,float yscale2=1.0,
int stockings=16,float xangle=0.0,float yangle=0.0,float zangle=0.0)
{
glRotatef(xangle,1.0f,0.0f,0.0f);
glRotatef(yangle,0.0f,1.0f,0.0f);
glRotatef(zangle,0.0f,0.0f,1.0f);
for (int i=1;i<stockings;i++)
{
glColor3f(((float)i/stockings)*1.0f,((float)i/stockings)*1.0f,1.0f);
glVertex3f(x1+distance1*((cos(360.0/i*stockings)))*xscale1,y1+distance1*((sin(360.0/i*stockings)))*yscale1,z1);
glVertex3f(x2+distance1*((cos(360.0/i*stockings)))*xscale2,y2+distance1*((sin(360.0/i*stockings)))*yscale2,z2);
glVertex3f(x2+distance1*((cos(360.0/(i+1)*stockings)))*xscale2,y2+distance1*((sin(360.0/(i+1)*stockings)))*yscale2,z2);
glVertex3f(x1+distance1*((cos(360.0/(i+1)*stockings)))*xscale1,y1+distance1*((sin(360.0/(i+1)*stockings)))*yscale1,z1);
}
}
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();
gluLookAt(5.0f,5.0f,-20.0f,5.0f,-2.5f,10.0f,0.0f,1.0f,0.0f);
// glTranslatef(0.0f,0.0f,20.0f);
glBegin(GL_QUADS);
glColor3f(0.0f,0.4f,1.0f);
for (int i=0;i<25;i++)
{
glVertex3f(i*1.5f-0.125f-2.0f,-2.0f,-100.0f);
glVertex3f(i*1.5f+0.125f-2.0f,-2.0f,-100.0f);
glVertex3f(i*1.5f+0.125f-2.0f,-2.0f,100.0f);
glVertex3f(i*1.5f-0.125f-2.0f,-2.0f,100.0f);
glVertex3f(-100.0f,-2.0f,i*1.5f+0.125f-2.0f);
glVertex3f(100.0f,-2.0f,i*1.5f+0.125f-2.0f);
glVertex3f(100.0f,-2.0f,i*1.5f-0.125f-2.0f);
glVertex3f(-100.0f,-2.0f,i*1.5f-0.125f-2.0f);
}
glEnd();
glRotatef(rtri,0.0f,1.0f,0.0f);
glRotatef(rquad,1.0f,0.0f,0.0f);
glRotatef(rz,0.0f,0.0f,1.0f);
glBegin(GL_QUADS);
CylinderRender(-5.0,5.0,2.0,2.0,-5.0,5.0,3.0,5.0,1.0,1.0,1.0,1.0,16,0.0,0.0,0.0);
glEnd();
return TRUE; // Keep Going
}
根据原计划,CylinderRender函数中的x1是初始X位置,x2是末X位置,y1是初始Y位置,y2是末Y位置,z1是初始Z位置,z2是末Z位置,distance1是初始半径,distance2是末半径,xscale1是初始X缩放,yscale1是初始Y缩放,xscale2是末X缩放,yscale2是末Y缩放,stockings是侧面多边形数量,xangle是X角度,yangle是Y角度,zangle是Z角度
以下函数已定义:
glColor3f的作用是设置该点的颜色,三个参数的最大值是1.0,相当于255.
gluLookat的参数分别是视点X,视点Y,视点Z,目标点X,目标点Y,目标点Z,头部朝向X,头部朝向Y,头部朝向Z
不知为啥原因,运行出来的效果就这么奇葩……(是不是还是该让数学帝来…)
旋转一定角度后……
我本来想着如果这函数用得好的话建模可以完全不用担心的,看来代码建模得等一会儿了…… (限于各种原因我很难实现打开模型文件和操作模型和使模型骨骼旋转兼得,所以只能用代码建模了) |
|