C:/irrlicht/IrrLib/IrrLib.cpp

Go to the documentation of this file.
00001 /*
00002     Irrlicht Library Wrapper
00003     Created by:
00004         Nathan Adams
00005         Denzel Morris
00006     Copyright (C) 2007
00007 
00008     This software is licensed under the GNU/GPL.
00009     This software may not be used for commerical purposes.
00010 */
00011 
00012 #include <iostream>
00013 #include <irrlicht.h>
00014 #include <strings.h>
00015 #include <sstream>
00016 #include <time.h>
00017 
00018 #include "IrrLib.h"
00019 //Libraries we create go here
00020 //#include "IrrSphere.h"
00021 #include "IrrColor.h"
00022 //#include "Irr2D.h"
00023 
00024 using namespace irr;
00025 using namespace core;
00026 using namespace scene;
00027 using namespace video;
00028 using namespace io;
00029 using namespace gui;
00030 
00031 using namespace std;
00032 
00033 
00034 /*IrrLib::IrrLib(MastEventReceiver & receiver){
00035     this->device = createDevice(EDT_SOFTWARE, dimension2d<s32>(640, 480), 16, false, false, false, &receiver);
00036     if (this->device == 0)
00037         exit(1);
00038     IrrLib::Init();
00039 }*/
00040 
00041 IrrLib::IrrLib(){
00042     this->device = createDevice(EDT_SOFTWARE, dimension2d<s32>(640, 480), 16, false, false, false, &this->IrrEvent);
00043     if (this->device == 0)
00044         exit(1);
00045     IrrLib::Init();
00046 }
00047 
00048 IrrLib::IrrLib(video::E_DRIVER_TYPE drivertype, core::dimension2d<s32> & res, u32 bits, bool fullscreen, bool stencilbuffer, bool vsync){
00049     //MyEventReceiver receiver;
00050     this->device = createDevice(drivertype, res, bits, fullscreen, stencilbuffer, vsync, &this->IrrEvent);
00051     if (this->device == 0)
00052         exit(1);
00053     IrrLib::Init();
00054 }
00055 
00056 IrrLib::IrrLib(int nDrivertype, int width, int height, int bits, bool fullscreen, bool stencilbuffer, bool vsync){
00057     //MyEventReceiver receiver;
00058     video::E_DRIVER_TYPE drivertype;
00059     switch (nDrivertype){
00060         case 0: //TODO: finish this switch case
00061             drivertype = EDT_NULL;
00062             break;
00063         case 1:
00064             drivertype = EDT_SOFTWARE;
00065             break;
00066         case 2:
00067             drivertype = EDT_BURNINGSVIDEO;
00068             break;
00069         case 3:
00070             drivertype = EDT_OPENGL;
00071             break;
00072         case 4:
00073             drivertype = EDT_DIRECT3D8;
00074             //*Note: It seems as Microsoft has stoped supporting DX 8.1, so you can not compile it into Irrlicht engine anymore
00075             //TODO: Find how to detect if DX is complied into Irrlicht
00076             //TODO: Find how to detecht for linux
00077             break;
00078         case 5:
00079             drivertype = EDT_DIRECT3D9;
00080             break;
00081         default:
00082             drivertype = EDT_SOFTWARE;
00083             break;
00084     }
00085     this->device = createDevice(drivertype, dimension2d<s32>(width, height), bits, fullscreen, stencilbuffer, vsync, &this->IrrEvent);
00086     if (this->device == 0)
00087         exit(1);
00088     IrrLib::Init();
00089 }
00090 
00091 IrrLib::~IrrLib (){ //Our moms wont clean up after us!
00092     //Although I'm sure Irrlicht does this for us already, its always a good idea to check!
00093     /*if (this->device != NULL)
00094         delete this->device;
00095     if (this->driver != NULL)
00096         delete this->driver;
00097     if (this->smgr != NULL)
00098         delete this->smgr;
00099     if (this->mesh != NULL)
00100         delete this->mesh;
00101     if (this->node != NULL)
00102         delete this->node;*/ //it seems Irrlicht picks up after us...
00103         //however we created newNodes, now we need to delete it!
00104 }
00105 
00106 void IrrLib::Init(){
00107     //this->numNodes = 0;
00108     //this->nodeNew = new ISceneNode[10];
00109         //this->env->addStaticText(L"Transparent Control:", rect<s32>(20,30,300,80), true);
00110     this->env = this->device->getGUIEnvironment();
00111     this->driver = this->device->getVideoDriver();
00112     this->smgr = this->device->getSceneManager();
00113     Irr3DLib.SetSmgr(this->smgr);
00114     Irr3DLib.SetDriver(this->driver);
00115         Irr2DLib.SetSmgr(this->smgr);
00116         Irr2DLib.SetDriver(this->driver);
00117         GUI.SetEnv(this->env);
00118         IrrEvent.SetDevice(this->device);
00119         this->timer = this->device->getTimer();
00120         tick = this->timer->getRealTime();
00121 }
00122 
00123 void IrrLib::ReadArchive(stringc file){
00124     this->device->getFileSystem()->addZipFileArchive(file.c_str());
00125 }
00126 
00127 void IrrLib::LoadQ3Level(stringc q3level){
00128     this->mesh = this->smgr->getMesh(q3level.c_str());
00129     this->node = 0;
00130     if (this->mesh)
00131                 this->node = this->smgr->addOctTreeSceneNode(this->mesh->getMesh(0), 0, -1, 128);
00132 }
00133 
00134 void IrrLib::MapPos(int x, int y, int z){
00135     if (this->node)
00136                 this->node->setPosition(core::vector3df(x, y, z));
00137 }
00138 
00139 void IrrLib::MapPos(){
00140     if (this->node)
00141                 this->node->setPosition(core::vector3df(0, 0, 0));
00142 }
00143 
00144 void IrrLib::AddFPSCam(){
00145     this->cam = this->smgr->addCameraSceneNodeFPS();
00146 }
00147 
00148 void IrrLib::AddFPSCam(f32 x, f32 y, f32 z)
00149 {
00150     this->cam = this->smgr->addCameraSceneNodeFPS();
00151     this->cam->setPosition(irr::core::vector3df(x, y, z));
00152 }
00153 
00154 void IrrLib::VisibleCursor(bool tf){
00155     if (tf == false)
00156         this->device->getCursorControl()->setVisible(false);
00157     else
00158         this->device->getCursorControl()->setVisible(true);
00159 }
00160 
00161 int IrrLib::GetFPSCount(){
00162     return this->driver->getFPS();
00163 }
00164 
00165 bool IrrLib::DeviceIsRunning(){
00166     return this->device->run();
00167 }
00168 
00169 bool IrrLib::IsActiveWindow(){
00170     return this->device->isWindowActive();
00171 }
00172 
00173 void IrrLib::BeginScene(){
00174     this->driver->beginScene(true, true, video::SColor(0,200,200,200));
00175 }
00176 
00177 void IrrLib::BeginScene(const irr::video::SColor& color){
00178     this->driver->beginScene(true, true, color);
00179 }
00180 
00181 void IrrLib::BeginScene(bool usebackBuffer, bool usezBuffer, irr::video::SColor color){
00182     this->driver->beginScene(usebackBuffer, usezBuffer, color);
00183 }
00184 
00185 void IrrLib::DrawAll(){
00186         //position2d<int> start(50, 50);
00187      //position2d<int> end(100,100);
00188       //   SColor whitecolor(255,255,255,255);
00189 //driver->draw2DLine(start, end, whitecolor);
00190     this->smgr->drawAll();
00191     this->env->drawAll();
00192     //this->device->getGUIEnvironment()->drawAll();
00193  }
00194 
00195 void IrrLib::EndScene(){
00196     this->driver->endScene();
00197 }
00198 
00199 void IrrLib::SetWindowCaption(stringw str){
00200     this->device->setWindowCaption(str.c_str());
00201 }
00202 
00203 irr::core::stringw IrrLib::GetDriverName(){
00204     return this->driver->getName();
00205 }
00206 
00207 void IrrLib::EndIrrlicht(){
00208         if(this->device != NULL){
00209                 this->device->drop();
00210                 this->device = NULL;
00211         }
00212 }
00213 
00214 void IrrLib::KeyPress(char key){
00215     this->key = key;
00216 }
00217 
00218 char IrrLib::KeyPressed(){
00219     return key;
00220 }
00221 
00222 irr::f32 IrrLib::getX(){
00223     return this->smgr->getActiveCamera()->getPosition().X;
00224 }
00225 
00226 irr::f32 IrrLib::getY(){
00227     return this->smgr->getActiveCamera()->getPosition().Y;
00228 }
00229 
00230 irr::f32 IrrLib::getZ(){
00231     return this->smgr->getActiveCamera()->getPosition().Z;
00232 }
00233 
00234 bool IrrLib::CheckGameLoop(){
00235         u32 now;
00236         now = this->timer->getRealTime();
00237         if ((now - this->tick) >= 30){
00238                 //this->tick == time (NULL);
00239                 return true;
00240         } else {
00241                 return false;
00242         }
00243 }
00244 
00245 bool IrrLib::CheckGameLoop(u32 ms){
00246         u32 now;
00247         now = this->timer->getRealTime();
00248         if ((now - this->tick) >= ms){
00249                 this->tick = now;
00250                 return true;
00251         } else {
00252                 return false;
00253         }
00254 }
00255 
00256 void IrrLib::Exit()
00257 {
00258         this->device->closeDevice();
00259 }
00260 
00261 PixelSize IrrLib::GetScreenSize()
00262 {
00263         return this->driver->getScreenSize();
00264         /*pixels returnres;
00265         returnres.width = screenres.Width;
00266         returnres.height = screenres.Height;
00267         return returnres;*/
00268 
00269 }
00270 
00271 //template <class T> std::string IrrLib::to_string (T t)
00272 /*std::string IrrLib::int_to_string (int t)
00273 {
00274         std::stringstream ss;
00275         ss << t;
00276         return ss.str();
00277 }*/
00278 // This is in the base class now, every class that decends from that class has this ability.

Generated on Thu Dec 27 18:25:19 2007 for IrrLib by  doxygen 1.5.4