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
ENGINE.CPP
Package: openglsystem.rar [view]
Upload User: nthssl
Upload Date: 2022-04-05
Package Size: 25357k
Code Size: 2k
Category:
OpenCV
Development Platform:
Visual C++
- #define WIN32_LEAN_AND_MEAN
- #define WIN32_EXTRA_LEAN
- #include <stdlib.h>
- #include "engine.h"
- #include "HiResTimer.h"
- #include "camera.h"
- #include "world.h"
- void CEngine::CheckInput(float deltaTime)
- {
- static float buttonDelta = 0.0f;
- int mouseDeltaX, mouseDeltaY; // changes in the mouse position
- // decrease amount of time until next possible recognized button pressing
- buttonDelta -= deltaTime;
- if (buttonDelta < 0.0f)
- buttonDelta = 0.0f;
- // update devices
- inputSystem->Update();
- // retrieve the latest mouse movements
- inputSystem->GetMouseMovement(mouseDeltaX, mouseDeltaY);
- OnMouseMove(mouseDeltaX, mouseDeltaY);
- if (inputSystem->KeyDown(DIK_W))
- OnKeyDown(VK_UP);
- if (inputSystem->KeyDown(DIK_S))
- OnKeyDown(VK_DOWN);
- if (inputSystem->KeyDown(DIK_A))
- OnKeyDown(VK_LEFT);
- if (inputSystem->KeyDown(DIK_D))
- OnKeyDown(VK_RIGHT);
- if (inputSystem->KeyDown(DIK_ADD))
- OnKeyDown(VK_ADD);
- if (inputSystem->KeyDown(DIK_SUBTRACT))
- OnKeyDown(VK_SUBTRACT);
- if (inputSystem->KeyDown(DIK_ESCAPE))
- OnKeyDown(VK_ESCAPE);
- if (inputSystem->ButtonDown(0))
- {
- if (buttonDelta == 0.0f)
- {
- OnMouseDownL(0,0);
- buttonDelta = 0.5f;
- }
- }
- }
- void CEngine::GameCycle(float deltaTime)
- {
- CCamera *camera = OnGetCamera(); // get the camera
- CWorld *world = OnGetWorld(); // get the world
- if (useDInput)
- CheckInput(deltaTime);
- // setup opengl for frame (clear, identity)
- OnPrepare();
- // prepare objects and perform collisions
- world->Prepare();
- // move/orient camera
- camera->Animate(deltaTime);
- // move/orient objects
- world->Animate(deltaTime);
- // draw objects
- world->Draw(camera);
- // swap buffers
- SwapBuffers(hDC);
- }
- // EnterMessageLoop()
- // desc: the Windows message loop
- LRESULT CEngine::EnterMessageLoop()
- {
- // Message loop
- MSG msg;
- timer = new CHiResTimer;
- timer->Init();
- for (;;)
- {
- GameCycle(timer->GetElapsedSeconds(1));
- SetWindowText(hWnd, "恐怖之战");
- while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
- {
- // we always update if there are any events, even if we're paused
- if (!GetMessage (&msg, NULL, 0, 0))
- {
- delete timer;
- return msg.wParam;
- }
- TranslateMessage (&msg);
- DispatchMessage (&msg);
- }
- }
- delete timer;
- return msg.wParam;
- }