x
Yes
No
Do you want to visit DriveHQ English website?
Inicio
Características
Precios
Prueba gratuita
Software cliente
Acerca de nosotros
Servidor de archivos
|
Solución de copias de seguridad
|
Servidor FTP
|
Servidor de correo electrónico
|
Alojamiento web
|
Software cliente
Servidor de archivos
Solución de copia de seguridad
Servidor FTP
Servidor de correo electrónico
Alojamiento web
Software cliente
GameScene.cpp - Hosted on DriveHQ Cloud IT Platform
Arriba
Subir
Descargar
Compartir
Publicar
Nueva carpeta
Nuevo archivo
Copiar
Cortar
Eliminar
Pegar
Clasificación
Actualizar
Ruta de la carpeta: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\GameFactory\GameScene.cpp
Girar
Efecto
Propiedad
Historial
#include "GameScene.h" #include "RigidEntity.h" #include "LoadedVisObj.h" #include "CompoundEntity.h" #include "ControllablePhysObj.h" //#include "SkinnedEntity.h" #include "RecordReplay.h" #include "ScriptEngine.h" GameScene* GameScene::theSingleton = NULL; Real GameScene::GravityValue = -9.81f; #define CLONE_STR(dest,source) {dest = new char[strlen(source)+1];strcpy(dest,source);} String trimNumericSuffix(const String& src){ const char* src_str = src.c_str(); char* dest; CLONE_STR(dest,src_str); int alphaCount=0; char* curChar = dest; while ((*curChar<'0' || *curChar>'9') && (*curChar != 0)){//while not a number and not null alphaCount++; curChar++; }; myassert(alphaCount<=strlen(dest)); char* trimedStr = new char[alphaCount]; char* curTrimedChar = trimedStr; curChar = dest; int count =0; while (count < alphaCount){ *curTrimedChar = *curChar; curChar++; curTrimedChar++; count++; }; *curTrimedChar=0; //end the newly created string SAFE_DELETE_ARRAY(dest); return String(trimedStr); } GameScene::GameScene(const String& resourceName, SceneManager* pSceneManager, RenderWindow* renderWindow, Camera* camera, NxPhysicsSDK* pPhysicSDK, NxScene* pPhysicScene): mSceneMgr(pSceneManager),mRenderWindow(renderWindow),mCamera(camera),mPhysSDK(pPhysicSDK),mPhysScene(pPhysicScene), mIsRunning(true){ myassert(theSingleton==NULL); theSingleton = this; //load visual objects OgreMax::OgreMaxScene* loadedScene = new OgreMax::OgreMaxScene(); loadedScene->Load(resourceName+".scene",mRenderWindow,OgreMax::OgreMaxScene::NO_OPTIONS,mSceneMgr,mSceneMgr->getRootSceneNode()); //iterate through all scene node and loaded the corresponding physical object for (Node::ChildNodeIterator iter = loadedScene->GetSceneManager()->getRootSceneNode()->getChildIterator();iter.hasMoreElements();){ SceneNode* sceneNode = (SceneNode*)iter.getNext(); myassert(sceneNode!=NULL); String name = sceneNode->getName(); String trimedName = trimNumericSuffix(name); //if (sceneNode->getChildIterator().hasMoreElements()){//group // CompoundVisObj* visObj = new CompoundVisObj(sceneNode); // CompoundEntity* compoundEntity = new CompoundEntity(trimedName,"base",visObj); //}else{//single object // VisualObject* visObj = new VisualObject(sceneNode); // RigidEntity* rigidEntity = new RigidEntity(trimedName,visObj); //} VisualObject* visObj = new VisualObject(sceneNode); RigidEntity* rigidEntity = new RigidEntity(trimedName,visObj); } SAFE_DELETE(loadedScene);//delete the loader mInputManager = new InputManager(); RecordReplay* pRecordReplay = new RecordReplay(); ScriptEngine* pScriptEngine = new ScriptEngine(); } GameScene::~GameScene(){ while (mEntityPool.GetPool().size()>0){ GameEntity* firstElement = (GameEntity*)*(mEntityPool.GetPool().begin()); SAFE_DELETE(firstElement); } SAFE_DELETE(mInputManager); if(mPhysSDK!= NULL) { if(mPhysScene != NULL) mPhysSDK->releaseScene(*mPhysScene); mPhysScene = NULL; NxReleasePhysicsSDK(mPhysSDK); mPhysSDK = NULL; } delete recordReplay;//cannot use SAFE_DELETE in this case! //mEntityPool.Clear();//TODO: review this line theSingleton = NULL; } //void GameScene::NXU_notifyActor(NxActor *actor, const char *userProperties){ // //SceneNode* visualObjNode = mSceneMgr->getSceneNode(actor->getName()); // //VisualObject* visObj = new VisualObject(visualObjNode); // //RigidPhysObj* ridObj = new RigidPhysObj(actor,visObj); // //GameEntity* entity = new GameEntity(visObj,ridObj); //} void GameScene::FrameMove(Real elapsedTime){ if (mIsRunning){ //if (elapsedTime<1.0f/60.0f) elapsedTime = 1.0f/60.0f; if (elapsedTime>1.0f/15.0f) elapsedTime = 1.0f/15.0f;//limit the speed! elapsedTime = recordReplay->funcWrapper(elapsedTime); //elapsedTime = 1.0f/60.0f; //printf("%f\n",elapsedTime); for (list
::iterator iter = mEntityPool.GetPool().begin(); iter!=mEntityPool.GetPool().end(); iter++){ (static_cast
(*iter))->FrameMove(elapsedTime); } ControllablePhysObj::UpdateAllControllablePhysObj(); mInputManager->FrameMove(elapsedTime); mPhysScene->simulate(elapsedTime); mPhysScene->flushStream(); mPhysScene->fetchResults(NX_RIGID_BODY_FINISHED, true); } } PhysicalEventHandler* GameScene::RayCastClosest(const Vec3& from, const Vec3& direction, Vec3* hitPosition, Vec3* hitNormal){ NxRaycastHit hit; NxShape* shape = mPhysScene->raycastClosestShape(NxRay(from,(Vec3)(direction.normalisedCopy())),NX_ALL_SHAPES,hit,-1,3.40e+38, NX_RAYCAST_IMPACT | NX_RAYCAST_NORMAL ); if (shape!=NULL){ if (shape->getActor().userData != NULL){ if (hitPosition!=NULL) *hitPosition = hit.worldImpact; if (hitNormal!=NULL) *hitNormal = hit.worldNormal; return static_cast
(shape->getActor().userData); }else return NULL; }else return NULL; } void GameScene::_GetRayCameraToViewport(const Vec3& mousePos, Vec3& from, Vec3& direction){ Ray rr = mCamera->getCameraToViewportRay((float)mousePos.x/mRenderWindow->getViewport(0)->getActualWidth(), (float)mousePos.y/mRenderWindow->getViewport(0)->getActualHeight()); from = rr.getOrigin(); from = recordReplay->funcWrapper(from); //from.x = recordReplay->funcWrapper(from.x); //from.y = recordReplay->funcWrapper(from.y); //from.z = recordReplay->funcWrapper(from.z); direction = rr.getDirection(); direction = recordReplay->funcWrapper(direction); //direction.x = recordReplay->funcWrapper(direction.x); //direction.y = recordReplay->funcWrapper(direction.y); //direction.z = recordReplay->funcWrapper(direction.z); } void GameScene::FrustumCheck(const Vec3& mouseTopLeft, const Vec3& mouseBottomRight, void (*callback)(PhysicalEventHandler*)){ //this->mPhysScene->cullShapes(4,,NX_ALL_SHAPES,) };
GameScene.cpp
Dirección de la página
Dirección del archivo
Anterior
19/55
Siguiente
Descargar
( 5 KB )
Comments
Total ratings:
0
Average rating:
No clasificado
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.