bsipic.cpp
资源名称:XLT.rar [点击查看]
上传用户:yunyi28
上传日期:2021-04-25
资源大小:6978k
文件大小:9k
源码类别:
分形几何
开发平台:
Visual C++
- #include "math.h"
- #include "bsipic.h"
- #include "stdio.h"
- #include "Tree.h"
- #include <list>
- #include "Data.h"
- #define PI 3.14159
- float rtri;
- float rquad;
- GLfloat xrot;
- GLfloat yrot;
- GLfloat zyot;
- bsipic::bsipic(void)
- {
- }
- bsipic::~bsipic(void)
- {
- }
- int bsipic::Pbmp()
- {
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,texture[0]);
- // glShadeModel(GL_SMOOTH);
- glClearColor(0.0f,0.0f,0.0f,0.0f);
- glClearDepth(1.0f);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LEQUAL);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_FASTEST);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glTranslatef(1.5f,0.0f,-7.0f);
- glRotatef(rquad,1.0f,0.0f,0.0f);
- glBegin(GL_QUADS);
- // glColor3f(0.0f,1.0f,0.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(1.0f,1.0f,-1.0f);
- glTexCoord2f(1.0f,0.0f);
- glVertex3f(-1.0f,1.0f,-1.0f);//上
- glTexCoord2f(1.0f,1.0f);
- glVertex3f(-1.0f,1.0f,1.0f);
- glTexCoord2f(0.0f,1.0f);
- glVertex3f(1.0f,1.0f,1.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(1.0f,-1.0f,1.0f);
- glTexCoord2f(1.0f,0.0f);
- glVertex3f(-1.0f,-1.0f,1.0f);//下
- glTexCoord2f(1.0f,1.0f);
- glVertex3f(-1.0f,-1.0f,-1.0f);
- glTexCoord2f(0.0f,1.0f);
- glVertex3f(1.0f,-1.0f,-1.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(1.0f,1.0f,1.0f);
- glTexCoord2f(0.5f,0.0f);
- glVertex3f(-1.0f,1.0f,1.0f);//前
- glTexCoord2f(0.5f,1.0f);
- glVertex3f(-1.0f,-1.0f,1.0f);
- glTexCoord2f(0.0f,1.0f);
- glVertex3f(1.0f,-1.0f,1.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(1.0f,-1.0f,-1.0f);
- glTexCoord2f(1.0f,0.0f);
- glVertex3f(-1.0f,-1.0f,-1.0f);//后
- glTexCoord2f(1.0f,1.0f);
- glVertex3f(-1.0f,1.0f,-1.0f);
- glTexCoord2f(0.0f,1.0f);
- glVertex3f(1.0f,1.0f,-1.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(-1.0f,1.0f,1.0f);
- glTexCoord2f(1.0f,0.0f);
- glVertex3f(-1.0f,1.0f,-1.0f);//左
- glTexCoord2f(1.0f,1.0f);
- glVertex3f(-1.0f,-1.0f,-1.0f);
- glTexCoord2f(0.0f,1.0f);
- glVertex3f(-1.0f,-1.0f,1.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(1.0f,1.0f,-1.0f);
- glTexCoord2f(1.0f,0.0f);
- glVertex3f(1.0f,1.0f,1.0f);//右
- glTexCoord2f(1.0f,1.0f);
- glVertex3f(1.0f,-1.0f,1.0f);
- glTexCoord2f(0.0f,1.0f);
- glVertex3f(1.0f,-1.0f,-1.0f);
- glEnd();
- rtri+=0.2f;
- rquad-=0.15f;
- return TRUE;
- }
- void bsipic::Park()
- {
- glColor3f(0,0,0);
- glPushMatrix();
- glTranslatef(-5,-4,-13);
- glBegin(GL_TRIANGLE_FAN);
- glVertex3f(0,0,0.0f);
- for(int i=0;i<=360;i+=5)
- {
- float p=(float)(i*3.14/180);
- glVertex3f((float)sin(p),(float)cos(p),0.0f);
- }
- glEnd();
- glPopMatrix();
- }
- void bsipic::airplane(float x,float y,float z,int r)
- {
- glPushMatrix();
- glTranslatef(x,y,z);
- glRotatef(-r,0.0,1.0,0.0);
- glColor3f(1.0,1.0,1.0);
- //螺旋桨
- glColor3f(0,1,0);
- auxSolidBox(1.6,0.3,0.05);
- //机头
- glColor3f(0.1,0.3,0.4);
- glTranslatef(0.0,0.0,-0.5);
- auxSolidSphere(0.5);
- //机身
- glColor3f(0.7,0.2,0.4);
- glRotatef(90,1.0,0.0,0.0);
- glTranslatef(0.0f,-1.0f,0);
- auxSolidCylinder(.4f,2.0);
- //机尾
- glColor3f(0.1,0.5,0.7);
- glRotatef(-270,1.0,0.0,0.0);
- glTranslatef(0.0f,-0.0f,1.0f);
- auxSolidCone(.4,1.5);
- //后翼
- glColor3f(1,1,1);
- glTranslatef(0.0f,-0.5f,1.2f);
- auxSolidBox(3,0.05f,0.5f);
- glTranslatef(0.0f,-0.0f,0.0f);
- auxSolidBox(0.05,1.0f,0.60f);
- //前翼
- glColor3f(0.3,0.4,0.4);
- glTranslatef(0.0f,0.7f,-1.9f);
- auxSolidBox(8,0.05f,0.7f);
- glPopMatrix();
- }
- void bsipic::TriAndQuad()
- {
- glClearColor(0.0f,0.0f,0.0f,0.0f);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glTranslatef(-1.5f,0.0f,-6.0f);
- glRotatef(rtri,0.0f,1.0f,0.0f);
- glBegin(GL_TRIANGLES);
- glColor3f(1.0f,0.0f,0.0f);
- glVertex3f(0.0f,1.0f,0.0f);
- glColor3f(0.0f,1.0f,0.0f);
- glVertex3f(1.0f,0.0f,0.0f);
- glColor3f(0.0f,0.0f,1.0f);
- glVertex3f(-1.0f,0.0f,0.0f);
- glEnd();
- glLoadIdentity();//重置模型观察矩阵
- glTranslatef(0.0f,0.0f,-7.0f);
- glRotatef(rquad,1.0f,0.0f,0.0f);
- glColor3f(0.5f,0.5f,1.0f);
- glBegin(GL_QUADS);
- glVertex3f(-1.0f,1.0f,0.0f);
- glVertex3f(1.0f,1.0f,0.0f);
- glVertex3f(1.0f,-1.0f,0.0f);
- glVertex3f(-1.0f,-1.0f,0.0f);
- glEnd();
- rtri+=0.2f;
- rquad-=0.15f;
- }
- void bsipic::TriAndQuad_3D()
- {
- glClearColor(0.0f,0.0f,0.0f,0.0f);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glTranslatef(-1.5f,0.0f,-6.0f);
- glRotatef(rtri,0.0f,1.0f,0.0f);
- glBegin(GL_TRIANGLES);
- glColor3f(1.0f,0.0f,0.0f);
- glVertex3f(0.0f,1.0f,0.0f);
- glColor3f(0.0f,1.0f,0.0f);
- glVertex3f(-1.0f,-1.0f,1.0f);
- glColor3f(0.0f,0.0f,1.0f);
- glVertex3f(1.0f,-1.0f,1.0f);
- glColor3f(1.0f,0.0f,0.0f);
- glVertex3f(0.0f,1.0f,0.0f);
- glColor3f(0.0f,0.0f,1.0f);
- glVertex3f(1.0f,-1.0f,1.0f);
- glColor3f(0.0f,1.0f,0.0f);
- glVertex3f(0.0f,-1.0f,-1.0f);
- glColor3f(1.0f,0.0f,0.0f);
- glVertex3f(0.0f,1.0f,0.0f);
- glColor3f(0.0f,1.0f,-1.0f);
- glVertex3f(0.0f,-1.0f,-1.0f);
- glColor3f(0.0f,0.0f,1.0f);
- glVertex3f(-1.0f,-1.0f,1.0f);
- glColor3f(1.0f,0.0f,0.0f);
- glVertex3f(0.0f,-1.0f,-1.0f);
- glColor3f(0.0f,0.0f,1.0f);
- glVertex3f(1.0f,-1.0f,1.0f);
- glColor3f(0.0f,1.0f,0.0f);
- glVertex3f(-1.0f,-1.0f,1.0f);
- glEnd();
- glLoadIdentity();//重置模型观察矩阵
- glTranslatef(1.5f,0.0f,-7.0f);
- glRotatef(rquad,1.0f,0.0f,0.0f);
- glBegin(GL_QUADS);
- glColor3f(0.0f,1.0f,0.0f);
- glVertex3f(1.0f,1.0f,-1.0f);
- glVertex3f(-1.0f,1.0f,-1.0f);
- glVertex3f(-1.0f,1.0f,1.0f);
- glVertex3f(1.0f,1.0f,1.0f);
- glColor3f(1.0f,0.5f,0.0f);
- glVertex3f(1.0f,-1.0f,1.0f);
- glVertex3f(-1.0f,-1.0f,1.0f);
- glVertex3f(-1.0f,-1.0f,-1.0f);
- glVertex3f(1.0f,-1.0f,-1.0f);
- glColor3f(1.0f,0.0f,0.0f);
- glVertex3f(1.0f,1.0f,1.0f);
- glVertex3f(-1.0f,1.0f,1.0f);
- glVertex3f(-1.0f,-1.0f,1.0f);
- glVertex3f(1.0f,-1.0f,1.0f);
- glColor3f(1.0f,1.0f,0.0f);
- glVertex3f(1.0f,-1.0f,-1.0f);
- glVertex3f(-1.0f,-1.0f,-1.0f);
- glVertex3f(-1.0f,1.0f,-1.0f);
- glVertex3f(1.0f,1.0f,-1.0f);
- glColor3f(0.0f,0.0f,1.0f);
- glVertex3f(-1.0f,1.0f,1.0f);
- glVertex3f(-1.0f,1.0f,-1.0f);
- glVertex3f(-1.0f,-1.0f,-1.0f);
- glVertex3f(-1.0f,-1.0f,1.0f);
- glColor3f(1.0f,0.0f,1.0f);
- glVertex3f(1.0f,1.0f,-1.0f);
- glVertex3f(1.0f,1.0f,1.0f);
- glVertex3f(1.0f,-1.0f,1.0f);
- glVertex3f(1.0f,-1.0f,-1.0f);
- glEnd();
- ;
- rtri+=0.2f;
- rquad-=0.15f;
- }
- void bsipic::StencilQuads()
- {
- // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
- glPushMatrix();
- glColor3f(1.0f,1.0f,0.0f);
- glEnable(GL_STENCIL_TEST);
- glStencilFunc(GL_ALWAYS , 5 ,1);
- glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
- glLoadIdentity();
- glTranslatef(0.0f,2.0f,-90.0f);
- glBegin(GL_QUADS);
- glVertex3f(-10.0f,10.0f,0.0f);
- glVertex3f(10.0f,10.0f,0.0f);
- glVertex3f(10.0f,-10.0f,0.0f);
- glVertex3f(-10.0f,-10.0f,0.0f);
- glEnd();
- glDisable(GL_STENCIL_TEST);
- glPopMatrix();
- }
- void bsipic::Trees()
- {
- glEnable(GL_TEXTURE_2D);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Clear Screen And Depth Buffer
- glClearColor(1.0,1.0,1.0,0.5);
- glClearDepth(-50.0f);
- glEnable(GL_BLEND);
- glDisable(GL_DEPTH_TEST);
- glLoadIdentity();
- gluLookAt(
- 0.0f,0.0f,200.0f,
- 0.0f,0.0f,0.0f,
- 0.0f,1.0f,0.0f);
- //设置观察点,目标点,向上方向
- glTranslatef(0.0f,-50.0f,-10.0f);
- glRotatef(rquad,0.0f,1.0f,0.0f);
- rquad-=pause*0.15f;
- list<Tree>::iterator i = trees.begin();
- int numtriangles = 0;
- // StencilQuads();
- // glEnable(GL_STENCIL_TEST);
- glStencilFunc(GL_EQUAL ,7 ,1);
- glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
- while(i!=trees.end()) //end()函数什么意思
- {
- numtriangles+=i->RenderTree();
- i++;
- }
- // numtriangles+=i->RenderTree();
- // glDisable(GL_STENCIL_TEST);
- glDisable(GL_BLEND);
- glEnable(GL_DEPTH_TEST);
- }
- void bsipic::IsPlane()
- {
- Vertex pt[4];
- float x = 0.0f,y = 0.0f,z = 0.0f;
- // float sqrt2s = sqrt(2.0f);
- float salpha = sin(45.0/180*PI);
- float calpha = cos(45.0/180*PI);
- float cbeta = cos(45.0/180*PI);
- float sbeta = sin(45.0/180*PI);
- float sqrt3s = sqrt(2.0f);
- float sqrt2s = 4;
- pt[0].x = x;
- pt[0].y = y;
- pt[0].z = z;
- pt[2].x = x+sqrt2s*salpha*cbeta;
- pt[2].y = y+sqrt2s*calpha;
- pt[2].z = z+sqrt2s*salpha*sbeta;
- pt[1].x = x+sqrt2s*salpha*cos((0)* PI /180)/2;//(cbeta*sqrt2+sbeta*sqrt2)/2;
- pt[1].y = y/2+pt[2].y/2;
- pt[1].z = z+sqrt2s*salpha*sin((0)* PI /180)/2;//(sbeta*sqrt2-cbeta*sqrt2)/2;
- pt[3].x = x+sqrt2s*salpha*cos((90)* PI /180)/2;//(cbeta*sqrt2-sbeta*sqrt2)/2;
- pt[3].y = pt[1].y;
- pt[3].z = z+sqrt2s*salpha*sin((90)* PI /180)/2;//(sbeta*sqrt2+cbeta*sqrt2)/2;
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,texture[0]);
- // glShadeModel(GL_SMOOTH);
- glClearColor(0.0f,0.0f,0.0f,0.0f);
- // glClearDepth(1.0f);
- // glEnable(GL_DEPTH_TEST);
- // glDepthFunc(GL_LEQUAL);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_FASTEST);
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- gluLookAt(5.0f,0.0f,5.0f,0.0f,sqrt2s/2,0.0f,0.0f,1.0f,0.0f);
- glTranslatef(0.0f,0.0f,0.0f);
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(pt[0].x,pt[0].y,pt[0].z);
- glTexCoord2f(0.0f,1.0f);
- glVertex3f(pt[3].x,pt[3].y,pt[3].z);
- glTexCoord2f(1.0f,1.0f);
- glVertex3f(pt[2].x,pt[2].y,pt[2].z);
- glTexCoord2f(1.0f,0.0f);
- glVertex3f(pt[1].x,pt[1].y,pt[1].z);//上
- glEnd();
- }