00001
00006 #ifndef __EXAMPLEENGINE_H
00007 #define __EXAMPLEENGINE_H
00008
00009
00010
00011 #include "RAS_IRenderTools.h"
00012 #include "RAS_BucketManager.h"
00013 #include "RAS_MeshObject.h"
00014
00015
00016 #include "KX_GameObject.h"
00017 #include "KX_ObjectActuator.h"
00018 #include "KX_Camera.h"
00019 #include "SM_Scene.h"
00020
00021
00022 #include "OpenALScene.h"
00023
00024
00025
00026 const MT_Scalar UpperBoundForFuzzicsIntegrator = 0.01;
00027
00028
00029 class ExampleEngine: public SCA_IMainLoop
00030 {
00031 SCA_LogicManager* m_logicmgr;
00032 RAS_IRasterizer* m_rasty;
00033 KX_Camera* m_pCamera;
00034 float m_viewdist;
00035 RAS_IRenderTools *m_rendertools;
00036 SM_Scene* m_sumoscene;
00037 CMatrix4x4 m_projection;
00038 CMatrix4x4 m_viewmat;
00039 KX_GameObject* m_gameobj;
00040 SND_IScene* m_sndscene ;
00041 bool m_bInitialized;
00042 double m_curtime;
00043
00044 public:
00045 ExampleEngine() : m_logicmgr(NULL), m_rasty(NULL), m_rendertools(NULL),
00046 m_pCamera(NULL), m_gameobj(NULL), m_sndscene(NULL), m_bInitialized(false),
00047 m_curtime(0)
00048 {
00049 m_sumoscene = new SM_Scene();
00050 }
00051 virtual ~ExampleEngine() {delete m_sumoscene;}
00052 void SetLogicMgr(SCA_LogicManager* mgr) {m_logicmgr=mgr;};
00053 void SetGameObject(KX_GameObject* gameobj)
00054 {
00055 m_gameobj = gameobj;
00056 }
00057 bool Init(RAS_IRasterizer* rasterizer, RAS_ICanvas* canvas,
00058 RAS_IRenderTools* rendertools,SND_IScene *sndscene)
00059 {
00060 m_sndscene = sndscene;
00061 m_rasty = rasterizer;
00062 m_pCamera = new KX_Camera(NULL, NULL);
00063 m_pCamera->NodeSetLocalPosition(MT_Point3(0,-8.0,0));
00064 m_pCamera->NodeSetLocalOrientation(MT_Matrix3x3(
00065 1, 0, 0,
00066 0, 0, -1,
00067 0, 1, 0));
00068
00069 m_rendertools = rendertools;
00070
00071 double value[16] = {
00072 1.0937443971634,0,0,0,
00073 0,2.0305602550507,0,0,
00074 0,0,-1.0020020008087,-1.0000000000000,
00075 0,0,-0.20020020008087,0};
00076 m_projection = CMatrix4x4(value);
00077
00078 MT_Scalar cammat[16];
00079 m_pCamera->NodeUpdateGS(0,true);
00080 m_pCamera->GetWorldToCamera().getValue(cammat);
00081 m_viewmat = cammat;
00082
00083 m_bInitialized=true;
00084
00085 return true;
00086 }
00087
00088 virtual int MainLoopCallback()
00089 {
00090 double deltatime=0.02;
00091 m_curtime += deltatime;
00092
00093 if(!m_bInitialized)
00094 return false;
00095 if(m_logicmgr)
00096 {
00097 m_logicmgr->BeginFrame(m_curtime, deltatime);
00098 m_logicmgr->UpdateFrame(m_curtime, deltatime);
00099 m_logicmgr->EndFrame();
00100 }
00101
00102 if (m_rasty)
00103 {
00104 m_rasty->BeginFrame();
00105
00106 m_rasty->SetProjectionMatrix(m_projection);
00107 m_rasty->SetViewMatrix(m_viewmat, MT_Point3(0, 0, 0) );
00108
00109 m_gameobj->NodeUpdateGS(m_curtime, true);
00110 m_gameobj->Bucketize();
00111 m_gameobj->MarkVisible(true);
00112
00113 if (m_pCamera)
00114 KX_Renderbuckets(m_pCamera->GetWorldToCamera(),m_rasty, m_viewdist,m_rendertools);
00115
00116
00117 m_rasty->EndFrame();
00118 m_rendertools->RenderText2D(
00119 "this is only a standalone game engine test\n\
00120 press 'P' for pythonscript and 'R' for rotation (see console output)\n\
00121 KeyboardSensor + AlwaysSensor connected to And/PythonController and Motion/DebugActuator",10,50);
00122
00123 m_sumoscene->proceed(deltatime,UpperBoundForFuzzicsIntegrator);
00124
00125 MT_Point3 listenerpos = m_pCamera->NodeGetWorldPosition();
00126 m_sndscene->SetListenerPosition(listenerpos);
00127
00128 m_sndscene->proceed(m_curtime,deltatime);
00129
00130 m_rasty->SwapBuffers();
00131 }
00132
00133 return 0;
00134 };
00135 };
00136
00137
00138 #endif // __EXAMPLEENGINE_H