Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
FIGHTERTESTVIEW.CPP
Package: openglsystem.rar [view]
Upload User: nthssl
Upload Date: 2022-04-05
Package Size: 25357k
Code Size: 19k
Category:
OpenCV
Development Platform:
Visual C++
- // FighterTestView.cpp : implementation of the CFighterTestView class
- //
- #include "stdafx.h"
- #include "FighterTest.h"
- #include "MilkshapeModel.h"
- #include "FighterTestDoc.h"
- #include "FighterTestView.h"
- #include "math.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- GLuint texture[4]; // Storage For 3 Textures
- /////////////////////////////////////////////////////////////////////////////
- // CFighterTestView
- IMPLEMENT_DYNCREATE(CFighterTestView, CView)
- BEGIN_MESSAGE_MAP(CFighterTestView, CView)
- //{{AFX_MSG_MAP(CFighterTestView)
- ON_WM_CREATE()
- ON_WM_DESTROY()
- ON_WM_SIZE()
- ON_WM_TIMER()
- ON_WM_KEYDOWN()
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFighterTestView construction/destruction
- CFighterTestView::CFighterTestView()
- {
- // TODO: add construction code here
- pModel = NULL;
- active=TRUE;
- Ioan=0;
- sky=true;
- timebullet=0;
- cameratype=1;
- nb,smoke=false;
- }
- CFighterTestView::~CFighterTestView()
- {
- }
- BOOL CFighterTestView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- ////////////////////////////////////////////////////////////////
- //设置窗口类型
- cs.style |=WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
- ////////////////////////////////////////////////////////////////
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CFighterTestView drawing
- void CFighterTestView::OnDraw(CDC* pDC)
- {
- CFighterTestDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- //////////////////////////////////////////////////////////////////
- RenderScene(); //渲染场景
- //////////////////////////////////////////////////////////////////
- }
- /////////////////////////////////////////////////////////////////////////////
- // CFighterTestView printing
- BOOL CFighterTestView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CFighterTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CFighterTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CFighterTestView diagnostics
- #ifdef _DEBUG
- void CFighterTestView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CFighterTestView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CFighterTestDoc* CFighterTestView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFighterTestDoc)));
- return (CFighterTestDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CFighterTestView message handlers
- int CFighterTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- // TODO: Add your specialized creation code here
- //////////////////////////////////////////////////////////////////
- //初始化OpenGL和设置定时器
- m_pDC = new CClientDC(this);
- SetTimer(1, 20, NULL);
- InitializeOpenGL(m_pDC);
- //////////////////////////////////////////////////////////////////
- pModel = new MilkshapeModel();
- if ( pModel->loadModelData( "Aereo.ms3d" ) == false )
- {
- MessageBox("Couldn't load the model Aereo.ms3d", "Error", MB_OK | MB_ICONERROR );
- return 0;
- }
- InitGL();
- return 0;
- }
- void CFighterTestView::OnDestroy()
- {
- CView::OnDestroy();
- // TODO: Add your message handler code here
- /////////////////////////////////////////////////////////////////
- //删除调色板和渲染上下文、定时器
- ::wglMakeCurrent(0,0);
- ::wglDeleteContext( m_hRC);
- if (m_hPalette)
- DeleteObject(m_hPalette);
- if ( m_pDC )
- {
- delete m_pDC;
- }
- KillTimer(1);
- /////////////////////////////////////////////////////////////////
- }
- void CFighterTestView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- if (cy==0)
- {
- cy=1;
- }
- /////////////////////////////////////////////////////////////////
- //添加窗口缩放时的图形变换函数
- glViewport(0,0,cx,cy);
- /////////////////////////////////////////////////////////////////
- glViewport(0,0,cx,cy);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.0f,(GLfloat)cx/(GLfloat)cy,0.1f,2000.0f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- void CFighterTestView::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- /////////////////////////////////////////////////////////////////
- //添加定时器响应函数和场景更新函数
- Invalidate(FALSE);
- /////////////////////////////////////////////////////////////////
- CView::OnTimer(nIDEvent);
- }
- /////////////////////////////////////////////////////////////////////
- // 设置逻辑调色板
- //////////////////////////////////////////////////////////////////////
- void CFighterTestView::SetLogicalPalette(void)
- {
- struct
- {
- WORD Version;
- WORD NumberOfEntries;
- PALETTEENTRY aEntries[256];
- } logicalPalette = { 0x300, 256 };
- BYTE reds[] = {0, 36, 72, 109, 145, 182, 218, 255};
- BYTE greens[] = {0, 36, 72, 109, 145, 182, 218, 255};
- BYTE blues[] = {0, 85, 170, 255};
- for (int colorNum=0; colorNum<256; ++colorNum)
- {
- logicalPalette.aEntries[colorNum].peRed =
- reds[colorNum & 0x07];
- logicalPalette.aEntries[colorNum].peGreen =
- greens[(colorNum >> 0x03) & 0x07];
- logicalPalette.aEntries[colorNum].peBlue =
- blues[(colorNum >> 0x06) & 0x03];
- logicalPalette.aEntries[colorNum].peFlags = 0;
- }
- m_hPalette = CreatePalette ((LOGPALETTE*)&logicalPalette);
- }
- //////////////////////////////////////////////////////////
- // 初始化openGL场景
- //////////////////////////////////////////////////////////
- BOOL CFighterTestView::InitializeOpenGL(CDC* pDC)
- {
- m_pDC = pDC;
- SetupPixelFormat();
- //生成绘制描述表
- m_hRC = ::wglCreateContext(m_pDC->GetSafeHdc());
- //置当前绘制描述表
- ::wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC);
- return TRUE;
- }
- //////////////////////////////////////////////////////////
- // 设置像素格式
- //////////////////////////////////////////////////////////
- BOOL CFighterTestView::SetupPixelFormat()
- {
- PIXELFORMATDESCRIPTOR pfd = {
- sizeof(PIXELFORMATDESCRIPTOR), // pfd结构的大小
- 1, // 版本号
- PFD_DRAW_TO_WINDOW | // 支持在窗口中绘图
- PFD_SUPPORT_OPENGL | // 支持 OpenGL
- PFD_DOUBLEBUFFER, // 双缓存模式
- PFD_TYPE_RGBA, // RGBA 颜色模式
- 24, // 24 位颜色深度
- 0, 0, 0, 0, 0, 0, // 忽略颜色位
- 0, // 没有非透明度缓存
- 0, // 忽略移位位
- 0, // 无累加缓存
- 0, 0, 0, 0, // 忽略累加位
- 32, // 32 位深度缓存
- 0, // 无模板缓存
- 0, // 无辅助缓存
- PFD_MAIN_PLANE, // 主层
- 0, // 保留
- 0, 0, 0 // 忽略层,可见性和损毁掩模
- };
- int pixelformat;
- pixelformat = ::ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);//选择像素格式
- ::SetPixelFormat(m_pDC->GetSafeHdc(), pixelformat, &pfd); //设置像素格式
- if(pfd.dwFlags & PFD_NEED_PALETTE)
- SetLogicalPalette(); //设置逻辑调色板
- return TRUE;
- }
- //////////////////////////////////////////////////////////
- // 场景绘制与渲染
- //////////////////////////////////////////////////////////
- BOOL CFighterTestView::RenderScene()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- Camera();
- // 绘制蓝天白云背景
- if(sky==true)
- {
- glEnable(GL_TEXTURE_2D);
- glPushMatrix();
- glBindTexture(GL_TEXTURE_2D, texture[0]);
- glTranslatef(Io.x,0,Io.z);
- glRotatef(90,1,0,0);
- glColor4f(1,1,1,1);
- gluSphere(qobj,1000,32,32);
- glPopMatrix();
- glDisable(GL_TEXTURE_2D);
- }
- if(rand()%100==3)
- timebullet=10+rand()%100; // 随机产生子弹
- if(timebullet>0)
- {
- timebullet--;
- if( timebullet%4==0 )
- ActiveBullet(); // 激活子弹
- }
- DrawTerrain(); // 绘制地形
- MoveAereo(); // 实现飞机运动
- DrawAereo(); // 绘制飞行
- if(smoke==true)
- {
- InitSmoke02(); // 初始化尾部烟雾
- DrawSmoke(); // 绘制尾部烟雾
- }
- MoveDrawBullet(); // 实现子弹运动
- ::SwapBuffers(m_pDC->GetSafeHdc()); //交互缓冲区
- return TRUE;
- }
- int CFighterTestView::InitGL(GLvoid) // All Setup For OpenGL Goes Here
- {
- GLfloat LightPosition[]={ 1.0f, 140.0f, 1.0f, 1.0f };
- if(!m_texture.LoadTextures())
- return FALSE;
- InitBullet(); // 初始化子弹
- InitTerrain(); // 初始化地形
- InitAereo(); // 初始化飞机
- InitSmoke01(); // 初始化尾部烟雾
- pModel->reloadTextures(); // 装入模型纹理
- glShadeModel(GL_SMOOTH);
- glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
- glClearDepth(1.0f);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LEQUAL);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
- glLightfv(GL_LIGHT0, GL_POSITION,LightPosition);
- glEnable(GL_LIGHT0);
- qobj = gluNewQuadric();
- gluQuadricNormals(qobj,GLU_SMOOTH);
- gluQuadricTexture(qobj,GL_TRUE);
- return TRUE;
- }
- double CFighterTestView::VectorLength( Vector v )
- {
- return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
- }
- Vector CFighterTestView::VectorNormalize( Vector v )
- {
- Vector vresult;
- double l = VectorLength( v );
- vresult.x = v.x/l;
- vresult.y = v.y/l;
- vresult.z = v.z/l;
- return vresult;
- }
- Vector CFighterTestView::VectorMultiply( Vector v1, Vector v2 )
- {
- Vector vresult;
- vresult.x = v1.y * v2.z - v1.z * v2.y;
- vresult.y = v1.z * v2.x - v1.x * v2.z;
- vresult.z = v1.x * v2.y - v1.y * v2.x;
- return vresult;
- }
- Vector CFighterTestView::VectorScalarMultiply( Vector v, double s )
- {
- Vector vresult;
- vresult.x = v.x * s;
- vresult.y = v.y * s;
- vresult.z = v.z * s;
- return vresult;
- }
- Vector CFighterTestView::VectorDiff( Vector v1, Vector v2 )
- {
- Vector vresult;
- vresult.x = v1.x - v2.x;
- vresult.y = v1.y - v2.y;
- vresult.z = v1.z - v2.z;
- return vresult;
- }
- void CFighterTestView::Luce(double x, double y, double z,double dimensione,float r,float g,float b,float iox,float ioy,float ioz,int Tex)
- {
- Vector Position;
- Vector MyPosition;
- Position.x = x;
- Position.y = y;
- Position.z = z;
- MyPosition.x=iox;
- MyPosition.y=ioy;
- MyPosition.z=ioz;
- Vector sight = VectorDiff(MyPosition, Position);
- Vector cz;
- cz.x = 0;
- cz.y = 0;
- cz.z = 1;
- Vector cross1 = VectorMultiply( sight, cz );
- Vector cross2 = VectorMultiply( sight, cross1 );
- cross1 = VectorNormalize(cross1);
- cross2 = VectorNormalize(cross2);
- cross1 = VectorScalarMultiply(cross1, dimensione);
- cross2 = VectorScalarMultiply(cross2, dimensione);
- glColor3f(r,g,b);
- glEnable(GL_TEXTURE_2D);
- glEnable (GL_BLEND);
- glBlendFunc( (1,1,1,1), (1,1,1,1));
- glDepthMask (GL_FALSE);
- glBindTexture( GL_TEXTURE_2D, texture[Tex] );
- glBegin(GL_QUADS);
- glTexCoord2d( 0.0, 0.0 );
- glVertex3d( Position.x + cross1.x, Position.y + cross1.y, Position.z + cross1.z);
- glTexCoord2d( 1.0, 0.0 );
- glVertex3d( Position.x - cross2.x, Position.y - cross2.y, Position.z - cross2.z);
- glTexCoord2d( 1.0, 1.0 );
- glVertex3d( Position.x - cross1.x, Position.y - cross1.y, Position.z - cross1.z);
- glTexCoord2d( 0.0, 1.0 );
- glVertex3d( Position.x + cross2.x, Position.y + cross2.y, Position.z + cross2.z);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- glDisable (GL_BLEND);
- glDepthMask (GL_TRUE);
- }
- void CFighterTestView::InitBullet(void)
- {
- int t;
- for(t=0;t<MAXBULLET;t++)
- {
- bul[t].active=false; // 所有子弹未激活
- bul[t].explosion=false; // 所有子弹未爆炸
- }
- }
- void CFighterTestView::InitTerrain(void)
- {
- int x,z;
- double xi,zi;
- for(z=0;z<DIMZ;z++)
- {
- zi=(double)z-((double)DIMZ/2);
- zi=zi*SIZE;
- for(x=0;x<DIMX;x++)
- {
- xi=(double)x-((double)DIMX/2);
- xi=xi*SIZE;
- Terrain[x][z].x=xi;
- Terrain[x][z].y=0;
- Terrain[x][z].z=zi;
- }
- }
- }
- void CFighterTestView::InitAereo(void)
- {
- // 初始化飞机的位置
- aereo.x=150+(float)(rand()%1000)/10;
- aereo.z=20+(float)(rand()%10000)/20;
- aereo.y=10;
- // 初始化飞机的角度
- aereo.an=(float)90+(float)(rand()%45);
- aereo.anend=0;
- aereo.dan=0;
- // 初始化飞机的速度
- aereo.vel=4+(float)(rand()%100)/20;
- aereo.fvirata=0;
- aereo.virata=false;
- aereo.attivo=true;
- aereo.tempovirata=0;
- aereo.cntscia=5;
- // 视点位置
- Io.x=aereo.x;
- Io.y=aereo.y+4;
- Io.z=aereo.z;
- Ioan=20;
- }
- void CFighterTestView::InitSmoke01(void)
- {
- int t;
- for(t=0;t<MAXPUF;t++)
- Smoke[t].time=-1; //所有烟雾未激活
- }
- void CFighterTestView::ActiveBullet(void)
- {
- int t;
- int r;
- for(t=0;t<MAXBULLET;t++)
- {
- if(bul[t].active==false)
- {
- r=rand()%4-rand()%4;
- bul[t].explosion=false; // 是否爆炸
- bul[t].active=true; // 是否激活
- // 子弹的位置
- bul[t].x=aereo.x;
- bul[t].y=aereo.y;
- bul[t].z=aereo.z;
- // 子弹的位移速度
- bul[t].dx=(aereo.vel*2)*cos((aereo.an+90+r)*3.141/180);
- bul[t].dy=0;
- bul[t].dz=(aereo.vel+2)*sin((aereo.an+90+r)*3.141/180);
- break;
- }
- }
- }
- void CFighterTestView::InitSmoke02(void)
- {
- register int t;
- int flag=1;
- float dx,dy,dz;
- for(t=0;t<MAXPUF;t++)
- {
- if(Smoke[t].time<0 && flag>=0)
- {
- if(flag!=0)
- {
- dx=cos(aereo.an*3.141/180);
- dy=0;
- dz=sin(aereo.an*3.141/180);
- }
- else
- {
- dx=1+cos(-aereo.an*3.141/180);
- dy=2*sin(aereo.dan*aereo.fvirata*3.141/180);
- dz=1+sin(-aereo.an*3.141/180);
- }
- // 烟雾的寿命
- Smoke[t].time=TIMEPUF;
- // 烟雾的位置
- Smoke[t].x=aereo.x+dx;
- Smoke[t].y=aereo.y-dy-1.2;
- Smoke[t].z=aereo.z+dz;
- // 烟雾的尺寸
- Smoke[t].dim=0;
- // 烟雾的颜色
- Smoke[t].r=1;
- Smoke[t].g=1;
- Smoke[t].b=1;
- flag--;
- if(flag<0)
- break;
- }
- }
- }
- void CFighterTestView::MoveDrawBullet(void)
- {
- int t;
- for(t=0;t<MAXBULLET;t++)
- {
- if(bul[t].explosion==false)
- {
- if(bul[t].active==true)
- {
- bul[t].x+=bul[t].dx;
- bul[t].y-=bul[t].dy;
- bul[t].z+=bul[t].dz;
- bul[t].dy+=(float)GRAVITY;
- if(bul[t].y<0)
- {
- bul[t].active=false;
- bul[t].explosion=true;
- bul[t].dim=0;
- }
- glColor3f(1,1,1);
- glBegin(GL_POINTS);
- glVertex3f(bul[t].x,bul[t].y,bul[t].z);
- glEnd();
- }
- }
- else
- {
- bul[t].dim+=0.1;
- if(bul[t].dim>1)
- bul[t].explosion=false;
- Luce(bul[t].x,bul[t].y,bul[t].z,4*bul[t].dim,1-bul[t].dim,0,0,Io.x,Io.y,Io.z,3);
- }
- }
- glColor3f(1,1,1);
- }
- void CFighterTestView::MoveAereo(void)
- {
- register float dx,dz;
- dx=aereo.vel*cos((90+aereo.an)*3.141/180);
- dz=aereo.vel*sin((90+aereo.an)*3.141/180);
- aereo.x+=dx;
- aereo.z+=dz;
- if(aereo.x<-4000)
- aereo.x=4000;
- if(aereo.x>4000)
- aereo.x=-4000;
- if(aereo.z<-4000)
- aereo.z=4000;
- if(aereo.z>4000)
- aereo.z=-4000;
- // Virata
- if(aereo.virata==false )
- {
- if(rand()%100==0)
- {
- float dan;
- dan=(float)(rand()%160-rand()%160);
- aereo.anend=aereo.an+dan;
- aereo.dan=dan/TEMPOVIRATA;
- aereo.virata=true;
- aereo.tempovirata=0;
- aereo.fvirata=0;
- }
- }
- else
- {
- aereo.an+=aereo.dan;
- if(aereo.an<(aereo.anend+1) && aereo.an>(aereo.anend-1))
- aereo.virata=false;
- }
- }
- void CFighterTestView::DrawTerrain(void)
- {
- register int x,z;
- register float fk=(float)1/100;
- glEnable(GL_TEXTURE_2D);
- glBindTexture( GL_TEXTURE_2D, texture[1] );
- for(z=0;z<DIMZ-1;z++)
- {
- for(x=0;x<DIMX-1;x++)
- {
- glBegin(GL_QUADS);
- glTexCoord2d( 0.0, 0.0 );
- glVertex3f(Terrain[x][z].x,Terrain[x][z].y,Terrain[x][z].z);
- glTexCoord2d( 0.0, 1.0 );
- glVertex3f(Terrain[x][z+1].x,Terrain[x][z+1].y,Terrain[x][z+1].z);
- glTexCoord2d( 1.0, 1.0 );
- glVertex3f(Terrain[x+1][z+1].x,Terrain[x+1][z+1].y,Terrain[x+1][z+1].z);
- glTexCoord2d( 1.0, 0.0 );
- glVertex3f(Terrain[x+1][z].x,Terrain[x+1][z].y,Terrain[x+1][z].z);
- glEnd();
- }
- }
- glDisable(GL_TEXTURE_2D);
- }
- void CFighterTestView::DrawAereo(void)
- {
- glPushMatrix();
- glEnable(GL_LIGHTING);
- glTranslatef(aereo.x,aereo.y,aereo.z);
- glRotatef(-aereo.an,0,1,0);
- if(aereo.virata==true)
- {
- glRotatef(aereo.dan*aereo.fvirata,0,0,1);
- if(aereo.tempovirata<TEMPOVIRATA/2)
- aereo.fvirata+=0.5;
- else
- aereo.fvirata-=0.5;
- aereo.tempovirata++;
- }
- pModel->draw();
- glDisable(GL_LIGHTING);
- glPopMatrix();
- }
- void CFighterTestView::DrawSmoke(void)
- {
- int t;
- float fk=(float)2/TIMEPUF;
- for(t=0;t<MAXPUF;t++)
- {
- if(Smoke[t].time>0)
- {
- Luce(Smoke[t].x,Smoke[t].y,Smoke[t].z,Smoke[t].dim,Smoke[t].r,Smoke[t].g,Smoke[t].b,Io.x,Io.y,Io.z,2);
- Smoke[t].dim+=0.05; // 烟雾的尺寸变大
- // 烟雾的颜色变化
- Smoke[t].r-=fk;
- Smoke[t].g-=fk;
- Smoke[t].b-=fk;
- // 烟雾的寿命缩短
- Smoke[t].time--;
- if(Smoke[t].time<=0)
- Smoke[t].time=-1; // 烟雾消息
- }
- }
- glColor3f(1,1,1);
- }
- void CFighterTestView::Camera(void)
- {
- float dist;
- float dx,dy,dz;
- if(cameratype==0)
- {
- dist=sqrt( (aereo.x-Io.x)*(aereo.x-Io.x)+(aereo.z-Io.z)*(aereo.z-Io.z) );
- if(dist>400)
- {
- Io.x=aereo.x+150*cos((aereo.an+rand()%180)*3.141/180);
- Io.y=(float)(1+rand()%35);
- Io.z=aereo.z+150*sin((aereo.an+rand()%180)*3.141/180);
- aereo.vel=1+(float)(rand()%100)/50;
- }
- }
- if(cameratype==1)
- {
- dx=30*cos((aereo.an-90+Ioan)*3.141/180);
- dy=6;
- dz=30*sin((aereo.an-90+Ioan)*3.141/180);
- Io.x=aereo.x+dx;
- Io.y=aereo.y+dy;
- Io.z=aereo.z+dz;
- }
- if(cameratype==2)
- {
- if(bul[nb].active==true)
- {
- Io.x=bul[nb].x;
- Io.y=bul[nb].y;
- Io.z=bul[nb].z;
- }
- else
- cameratype=0;
- }
- gluLookAt(Io.x,Io.y,Io.z,aereo.x,aereo.y,aereo.z,0.0f,1.0f,0.0f);
- }
- void CFighterTestView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- // Camera position
- if(nChar==VK_LEFT)
- Ioan++;
- if(nChar==VK_RIGHT)
- Ioan--;
- if(nChar==VK_UP)
- Io.y+=0.1;
- if(nChar==VK_DOWN)
- Io.y-=0.1;
- if(nChar==65) // 按下'A'键
- {
- timebullet=rand()%100;
- }
- if(nChar==83) // 按下'S'键
- {
- if(sky==false)
- sky=true;
- else
- sky=false;
- }
- if(nChar==77) // 按下'M'键
- {
- if(smoke==false)
- smoke=true;
- else
- smoke=false;
- }
- // 视点模式
- if(nChar==49) // 按下'1'键
- {
- cameratype=0;
- }
- if(nChar==50) // 按下'2'键
- {
- cameratype=1;
- }
- if(nChar==51) // 按下'3'键
- {
- int t;
- cameratype=2;
- nb=-1;
- for(t=0;t<MAXBULLET;t++)
- {
- if(bul[t].active==true)
- {
- nb=t;
- break;
- }
- }
- if(nb==-1)
- cameratype=0;
- }
- CView::OnKeyDown(nChar, nRepCnt, nFlags);
- }