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
ROCKET.CPP
Package: openglsystem.rar [view]
Upload User: nthssl
Upload Date: 2022-04-05
Package Size: 25357k
Code Size: 4k
Category:
OpenCV
Development Platform:
Visual C++
- #include "rocket.h"
- CRocket::CRocket()
- {
- velocity = CVector(0.0, 0.0, 120.0);
- acceleration = CVector(0.0, 0.0, 0.0);
- distanceTravel = 0.0;
- size = 1.0f;
- isExplosion = false;
- explosion = NULL;
- explosionTex = new CTexture;
- Load();
- }
- CRocket::~CRocket()
- {
- if (explosion != NULL)
- {
- explosion->KillSystem();
- delete [] explosion;
- explosion = NULL;
- }
- if (explosionTex != NULL)
- {
- delete explosionTex;
- explosionTex = NULL;
- }
- }
- void CRocket::SetupExplosionTexture()
- {
- glGenTextures(1, &explosionTex->texID);
- glBindTexture(GL_TEXTURE_2D, explosionTex->texID);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, 4, explosionTex->width, explosionTex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, explosionTex->data);
- gluBuild2DMipmaps(GL_TEXTURE_2D, 4, explosionTex->width, explosionTex->height, GL_RGBA, GL_UNSIGNED_BYTE, explosionTex->data);
- }
- void CRocket::OnAnimate(scalar_t deltaTime)
- {
- float cosYaw = (float)cos(DEG2RAD(direction));
- float sinYaw = (float)sin(DEG2RAD(direction));
- float sinPitch = (float)sin(DEG2RAD(pitch));
- float speed = velocity.z * deltaTime;
- position.x += float(cosYaw)*speed;
- position.y += float(sinPitch)*speed;
- position.z += float(sinYaw)*speed;
- distanceTravel += position.Length();
- if (isExplosion)
- explosion->Update(deltaTime);
- if (!isExplosion)
- {
- if (distanceTravel >= 500000.0f)
- {
- isExplosion = true;
- velocity = CVector(0.0, 0.0, 0.0);
- explosion = new CExplosion(10, position, 0.1, explosionTex->texID);
- }
- }
- }
- void CRocket::OnCollision(CObject *collisionObject)
- {
- if (!isExplosion)
- {
- if (typeid(*collisionObject) == typeid(CTerrain))
- {
- if (((CTerrain*)collisionObject)->GetHeight(position.x, position.z) + size >= position.y)
- {
- isExplosion = true;
- velocity = CVector(0.0, 0.0, 0.0);
- explosion = new CExplosion(500, position, 8.0, explosionTex->texID);
- PlaySound();
- }
- // 爆炸
- }
- if (typeid(*collisionObject) == typeid(COgroEnemy))
- {
- isExplosion = true;
- velocity = CVector(0.0, 0.0, 0.0);
- explosion = new CExplosion(500, position, 8.0, explosionTex->texID);
- PlaySound();
- }
- if (typeid(*collisionObject) == typeid(CSodEnemy))
- {
- isExplosion = true;
- velocity = CVector(0.0, 0.0, 0.0);
- explosion = new CExplosion(500, position, 8.0, explosionTex->texID);
- PlaySound();
- }
- }
- }
- void CRocket::OnDraw(CCamera *camera)
- {
- // 如果火箭没有爆炸,则绘制火箭模型
- if (!isExplosion)
- {
- glEnable(GL_TEXTURE_2D);
- glColor3f(1.0, 1.0, 1.0);
- glTranslatef(position.x, position.y, position.z);
- glRotatef(-direction, 0.0, 1.0, 0.0);
- glScalef(0.025f, 0.025f, 0.025f);
- RenderFrame(0);
- glDisable(GL_TEXTURE_2D);
- }
- // 绘制爆炸
- else
- {
- glDisable(GL_FOG);
- explosion->Render();
- glEnable(GL_FOG);
- }
- }
- void CRocket::Load()
- {
- CMD2Model::Load("models\rocketair.md2", "models\rocket.pcx");
- explosionTex->LoadTexture("explosion.bmp");
- SetupExplosionTexture();
- }
- void CRocket::Unload()
- {
- }
- void CRocket::OnPrepare()
- {
- // 进行该实体与其他对象之间的碰撞检测操作
- if (!isExplosion)
- ProcessCollisions(FindRoot());
- if (isExplosion)
- {
- if (explosion->IsDead() && !audioSys->GetPerformance()->IsPlaying(entitySound->GetSegment(), NULL))
- {
- explosion->KillSystem();
- delete explosion;
- explosion = NULL;
- isExplosion = false;
- isDead = true;
- }
- }
- }