x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
GameFactoryDemo.cpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\GameFactoryDemo.cpp
旋转
特效
属性
历史版本
/* ----------------------------------------------------------------------------- This source file is part of OGRE (Object-oriented Graphics Rendering Engine) For the latest info, see http://www.ogre3d.org/ Copyright (c) 2000-2006 Torus Knot Software Ltd Also see acknowledgements in Readme.html You may use this sample code for anything you like, it is not covered by the LGPL like the rest of the engine. ----------------------------------------------------------------------------- */ //#define _GF_RECORD_BONES //to enable bone recording at SkinnedVisObj //#include "references\scintilla\include\Platform.h" //#include "references\scintilla\include\Scintilla.h" //#include "references\scintilla\include\SciLexer.h" #include "GameFactory\ScriptEditor.h"//must include it first, due to namespace conflict #include "GameFactoryDemo.h" HWND hWndMainWin; bool IsRunAsIDE = true; int renderWinWidth = 800; int renderWinHeight = 600; int editorWidth = 600; int editorHeight = 600; HWND hwndScintilla; HWND hwndRender; HINSTANCE hMainInstance; ScriptEditor* editor; #include "Soldier.h" #include "GameFactory\GameScene.h" #include "GameFactory\C2Template\C2GameScene.h" #include "GameFactory\C2Template\BilliardsGameScene.h" #include "GameFactory\RigidEntity.h" using namespace GameFactory; Soldier* soldiers[NUM_JAIQUAS]; GameScene* myScene; Light* redLight; //#include "OgreMaxScene.hpp" #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 #define WIN32_LEAN_AND_MEAN #include "windows.h" #endif #include "utilities.h" //from PhysX #ifdef __cplusplus extern "C" { #endif AnimationState* mAnimState[NUM_JAIQUAS]; AnimationState* mAnimStateHead[NUM_JAIQUAS]; Real mAnimationSpeed[NUM_JAIQUAS]; Vector3 mSneakStartOffset; Vector3 mSneakEndOffset; Quaternion mOrientations[NUM_JAIQUAS]; Vector3 mBasePositions[NUM_JAIQUAS]; SceneNode* mSceneNode[NUM_JAIQUAS]; Degree mAnimationRotation(-60); Real mAnimChop = 7.96666f; Real mAnimChopBlend = 0.3f; //physX code here // Physics static NxPhysicsSDK* gPhysicsSDK = NULL; static NxScene* gScene = NULL; static bool InitNx() { // Initialize PhysicsSDK NxPhysicsSDKDesc desc; NxSDKCreateError errorCode = NXCE_NO_ERROR; gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, NULL, new ErrorStream(), desc, &errorCode); if(gPhysicsSDK == NULL) { printf("\nSDK create error (%d - %s).\nUnable to initialize the PhysX SDK, exiting the sample.\n\n", errorCode, getNxSDKCreateError(errorCode)); return false; } #if SAMPLES_USE_VRD // The settings for the VRD host and port are found in SampleCommonCode/SamplesVRDSettings.h if (gPhysicsSDK->getFoundationSDK().getRemoteDebugger()) gPhysicsSDK->getFoundationSDK().getRemoteDebugger()->connect(SAMPLES_VRD_HOST, SAMPLES_VRD_PORT, SAMPLES_VRD_EVENTMASK); #endif gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.05f); // Create a scene NxSceneDesc sceneDesc; sceneDesc.gravity = NxVec3(0.0f, 0.0f, GameScene::GravityValue); gScene = gPhysicsSDK->createScene(sceneDesc); if(gScene == NULL) { printf("\nError: Unable to create a PhysX scene, exiting the sample.\n\n"); return false; } // Set default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.0f); defaultMaterial->setStaticFriction(0.5f); defaultMaterial->setDynamicFriction(0.5f); // Create ground plane NxPlaneShapeDesc planeDesc; planeDesc.normal = NxVec3(0,0,1); planeDesc.d = -2; NxActorDesc actorDesc; actorDesc.shapes.pushBack(&planeDesc); //actorDesc.globalPose.t = NxVec3(0,0,-2); gScene->createActor(actorDesc); //gScene->raycastClosestShape() return true; } SkeletalApplication* SkeletalApplication::theSoleInstance = NULL; void SkeletalApplication::updateStats(void) { static String currFps = "Current FPS: "; static String avgFps = "Average FPS: "; static String bestFps = "Best FPS: "; static String worstFps = "Worst FPS: "; static String tris = "Triangle Count: "; static String batches = "Batch Count: "; // update stats when necessary try { OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Core/AverageFps"); OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Core/CurrFps"); OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("Core/BestFps"); OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Core/WorstFps"); const RenderTarget::FrameStats& stats = mWindow->getStatistics(); guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS)); guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS) +" "+StringConverter::toString(stats.bestFrameTime)+" ms"); guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS) +" "+StringConverter::toString(stats.worstFrameTime)+" ms"); OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Core/NumTris"); guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount)); OverlayElement* guiBatches = OverlayManager::getSingleton().getOverlayElement("Core/NumBatches"); guiBatches->setCaption(batches + StringConverter::toString(stats.batchCount)); OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText"); guiDbg->setCaption(mDebugText); } catch(...) { /* ignore */ } } void SkeletalApplication::Initialize(bool bufferedKeys, bool bufferedMouse, bool bufferedJoy) { //mCamera = cam; mTranslateVector = Vector3::ZERO; //mWindow = win; mStatsOn = true; mNumScreenShots = 0; mMoveScale = 0.0f; mRotScale = 0.0f; mTimeUntilNextToggle = 0; mFiltering = TFO_BILINEAR; mAniso = 1; mSceneDetailIndex = 0; mMoveSpeed = 10; mRotateSpeed = 36; mDebugOverlay = 0; mInputManager = 0; mMouse = 0; mKeyboard = 0; mJoy = 0; using namespace OIS; mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); ParamList pl; size_t windowHnd = 0; std::ostringstream windowHndStr; mWindow->getCustomAttribute("WINDOW", &windowHnd); //windowHndStr << windowHnd; windowHndStr << (size_t)hWndMainWin; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" ))); pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); mInputManager = OIS::InputManager::createInputSystem( pl ); //Create all devices (We only catch joystick exceptions here, as, most people have Key/Mouse) mKeyboard = static_cast
(mInputManager->createInputObject( OISKeyboard, bufferedKeys )); mMouse = static_cast
(mInputManager->createInputObject( OISMouse, bufferedMouse )); try { mJoy = static_cast
(mInputManager->createInputObject( OISJoyStick, bufferedJoy )); } catch(...) { mJoy = 0; } //Set initial mouse clipping size windowResized(mWindow); showDebugOverlay(true); //Register as a Window listener WindowEventUtilities::addWindowEventListener(mWindow, this); } void SkeletalApplication::windowResized(RenderWindow* rw) { unsigned int width, height, depth; int left, top; rw->getMetrics(width, height, depth, left, top); const OIS::MouseState &ms = mMouse->getMouseState(); ms.width = width; ms.height = height; } void SkeletalApplication::windowClosed(RenderWindow* rw) { //Only close for window that created OIS (the main window in these demos) if( rw == mWindow ) { if( mInputManager ) { mInputManager->destroyInputObject( mMouse ); mInputManager->destroyInputObject( mKeyboard ); mInputManager->destroyInputObject( mJoy ); OIS::InputManager::destroyInputSystem(mInputManager); mInputManager = 0; } } } void SkeletalApplication::Destroy() { //Remove ourself as a Window listener WindowEventUtilities::removeWindowEventListener(mWindow, this); windowClosed(mWindow); } void SkeletalApplication::moveCamera() { // Make all the changes to the camera // Note that YAW direction is around a fixed axis (freelook style) rather than a natural YAW //(e.g. airplane) mCamera->yaw(mRotX); mCamera->pitch(mRotY); mCamera->moveRelative(mTranslateVector); } void SkeletalApplication::showDebugOverlay(bool show) { if (mDebugOverlay) { if (show) mDebugOverlay->show(); else mDebugOverlay->hide(); } } void SkeletalApplication::CreateCube(const Vector3& pos, Real size, const Vector3& initialVelocity) { if(gScene == NULL) return; //size/=2; static int numBox = 0; Entity* box; SceneNode* boxNode; //int index = mSceneMgr->getRootSceneNode()->numChildren(); int index = numBox++; box = mSceneMgr->createEntity("box"+StringConverter::toString(index), "cube.mesh"); //box->setMaterialName("Examples/Rockwall"); boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); boxNode->attachObject(box); boxNode->translate(pos); boxNode->scale(size,size*2.0f,size*0.7f); //boxNode->showBoundingBox(true); // Create body NxBodyDesc bodyDesc; bodyDesc.angularDamping = 0.5f; NxVec3 initialVelocityNX = NxVec3(initialVelocity.x,initialVelocity.y,initialVelocity.z); /*if(initialVelocity)*/ bodyDesc.linearVelocity = initialVelocityNX; NxBoxShapeDesc boxDesc; boxDesc.dimensions = NxVec3(size/2.0f, size, size/2*0.7f); boxDesc.skinWidth = 0.0025f; NxActorDesc actorDesc; actorDesc.shapes.pushBack(&boxDesc); actorDesc.body = &bodyDesc; actorDesc.density = 10.0f; actorDesc.globalPose.t = NxVec3(pos.x,pos.y,pos.z); //gScene->createActor(actorDesc)->userData = (void*)size_t(size); gScene->createActor(actorDesc)->userData = (void*)boxNode; //printf("Total: %d actors\n", gScene->getNbActors()); } /** Configures the application - returns false if the user chooses to abandon configuration. */ bool ExampleApplication::configure(void) { // Show the configuration dialog and initialise the system // You can skip this and use root.restoreConfig() to load configuration // settings if you were sure there are valid ones saved in ogre.cfg if(mRoot->showConfigDialog()) { if (IsRunAsIDE){ // Do not add this to the application mRoot->initialise(false); //HWND hWnd = 0; // Get the hWnd of the application! NameValuePairList misc; misc["externalWindowHandle"] = StringConverter::toString((int)hwndRender); mWindow = mRoot->createRenderWindow("Game Factory Demo", 0, 0, false, &misc);//two zeros are the size, they are somehow not used, the size of the hWndMainWin is used instead }else{ // If returned true, user clicked OK so initialise // Here we choose to let the system create a default rendering window by passing 'true' mWindow = mRoot->initialise(true,"Game Factory Demo"); } return true; } else { return false; } } LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; /* Switch according to what type of message we have received */ switch ( iMsg ) { //case WM_PAINT: // /* We receive WM_PAINT every time window is updated */ // hdc = BeginPaint(hwnd, &ps); // TextOut(hdc, 100, 100, "Hello, world!", 13); // EndPaint(hwnd, &ps); // return 0; case WM_CREATE: //create the scintilla edit control editor = new ScriptEditor(renderWinWidth,0,editorWidth-15,editorHeight-35,hwnd, hMainInstance); hwndScintilla = scriptEditor->GetWindowHandle(); //Scintilla_RegisterClasses(hMainInstance); //hwndScintilla = CreateWindowEx(0, // "Scintilla","Source", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPCHILDREN, // renderWinWidth,0,editorWidth-15,editorHeight-35,hwnd,NULL, hMainInstance,NULL); //ShowWindow(hwndScintilla, 5); //create render window! hwndRender = CreateWindow("static", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, /*CW_USEDEFAULT, CW_USEDEFAULT,*/ renderWinWidth,renderWinHeight, hwnd, NULL, hMainInstance, NULL); //ShowWindow(hwndRender, 5); return 0; case WM_DESTROY: /* Window has been destroyed, so exit cleanly */ SAFE_DELETE(editor); PostQuitMessage(0); return 0; case WM_NOTIFY: NMHDR* lpnmhdr = (LPNMHDR) lParam; if(lpnmhdr->hwndFrom==hwndScintilla) { switch(lpnmhdr->code) { case SCN_CHARADDED: int aa; aa=0; /* Hey, Scintilla just told me that a new */ /* character was added to the Edit Control.*/ /* Now i do something cool with that char. */ break; } } break; } /* Send any messages we don't handle to default window procedure */ return DefWindowProc(hwnd, iMsg, wParam, lParam); } #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT iCmdShow) #else int main(int argc, char **argv) #endif { hMainInstance = hInst; if (IsRunAsIDE){ //create a window static char szAppName[] = "winhello"; MSG msg; WNDCLASSEX wndclass; /* Fill in WNDCLASSEX struct members */ wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInst; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wndclass.lpszClassName = szAppName; wndclass.lpszMenuName = NULL; /* Register a new window class with Windows */ RegisterClassEx(&wndclass); /* Create a window based on our new class */ hWndMainWin = CreateWindow(szAppName, "Hello, world!", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, /*CW_USEDEFAULT, CW_USEDEFAULT,*/ renderWinWidth+editorWidth,renderWinHeight, NULL, NULL, hInst, NULL); ShowWindow(hWndMainWin, iCmdShow); UpdateWindow(hWndMainWin); } //init PhysX InitNx(); // Create application object SkeletalApplication app; try { app.go(); } catch( Exception& e ) { #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); int aa_pause = 0; #else std::cerr << "An exception has occured: " << e.getFullDescription(); #endif } SAFE_DELETE(myScene); //destroy PhysX //ExitNx(); return 0; } bool SkeletalApplication::processUnbufferedKeyInput(const FrameEvent& evt) { using namespace OIS; static bool spaceDown = false; const MouseState &ms = mMouse->getMouseState(); if (mKeyboard->isKeyDown(KC_SPACE)){ if (!spaceDown){ ////shoot the Cube into the scene //Ray rr = mCamera->getCameraToViewportRay((float)ms.X.abs/mWindow->getViewport(0)->getActualWidth(), // (float)ms.Y.abs/mWindow->getViewport(0)->getActualHeight()); //CreateCube(mCamera->getPosition(),0.3f,rr.getDirection().normalisedCopy()*20); ////RigidEntity* newEntity = new RigidEntity("cube"); ////newEntity->SetPosition(Vec3(0,0,3)); } spaceDown = true; }else { spaceDown = false; } static bool pDown = false; if (mKeyboard->isKeyDown(KC_P)){ if (!pDown){ myScene->SetIsRunning(!myScene->GetIsRunning()); } pDown = true; }else { pDown = false; } if(mKeyboard->isKeyDown(KeyCode::KC_LSHIFT)){ //rotate the camera mRotX = Degree(-ms.X.rel * 0.13); mRotY = Degree(-ms.Y.rel * 0.13); //translate the camera //mTranslateVector.x += ms.X.rel * 0.13; //mTranslateVector.y -= ms.Y.rel * 0.13; } if(mKeyboard->isKeyDown(KC_A)) mTranslateVector.x = -mMoveScale; // Move camera left if(mKeyboard->isKeyDown(KC_D)) mTranslateVector.x = mMoveScale; // Move camera RIGHT if(mKeyboard->isKeyDown(KC_UP) || mKeyboard->isKeyDown(KC_W) ) mTranslateVector.z = -mMoveScale; // Move camera forward if(mKeyboard->isKeyDown(KC_DOWN) || mKeyboard->isKeyDown(KC_S) ) mTranslateVector.z = mMoveScale; // Move camera backward if(mKeyboard->isKeyDown(KC_PGUP)) mTranslateVector.y = mMoveScale; // Move camera up if(mKeyboard->isKeyDown(KC_PGDOWN)) mTranslateVector.y = -mMoveScale; // Move camera down if(mKeyboard->isKeyDown(KC_RIGHT)) mCamera->yaw(-mRotScale); if(mKeyboard->isKeyDown(KC_LEFT)) mCamera->yaw(mRotScale); if( mKeyboard->isKeyDown(KC_ESCAPE) || mKeyboard->isKeyDown(KC_Q) ) return false; if( mKeyboard->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0 ) { mStatsOn = !mStatsOn; showDebugOverlay(mStatsOn); mTimeUntilNextToggle = 1; } if( mKeyboard->isKeyDown(KC_T) && mTimeUntilNextToggle <= 0 ) { switch(mFiltering) { case TFO_BILINEAR: mFiltering = TFO_TRILINEAR; mAniso = 1; break; case TFO_TRILINEAR: mFiltering = TFO_ANISOTROPIC; mAniso = 8; break; case TFO_ANISOTROPIC: mFiltering = TFO_BILINEAR; mAniso = 1; break; default: break; } MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering); MaterialManager::getSingleton().setDefaultAnisotropy(mAniso); showDebugOverlay(mStatsOn); mTimeUntilNextToggle = 1; } if(mKeyboard->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0) { std::ostringstream ss; ss << "screenshot_" << ++mNumScreenShots << ".png"; mWindow->writeContentsToFile(ss.str()); mTimeUntilNextToggle = 0.5; mDebugText = "Saved: " + ss.str(); } if(mKeyboard->isKeyDown(KC_R) && mTimeUntilNextToggle <=0) { mSceneDetailIndex = (mSceneDetailIndex+1)%3 ; switch(mSceneDetailIndex) { case 0 : mCamera->setPolygonMode(PM_SOLID); break; case 1 : mCamera->setPolygonMode(PM_WIREFRAME); break; case 2 : mCamera->setPolygonMode(PM_POINTS); break; } mTimeUntilNextToggle = 0.5; } static bool displayCameraDetails = false; if(mKeyboard->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0) { displayCameraDetails = !displayCameraDetails; mTimeUntilNextToggle = 0.5; if (!displayCameraDetails) mDebugText = ""; } // Print camera details if(displayCameraDetails) mDebugText = "P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " + "O: " + StringConverter::toString(mCamera->getDerivedOrientation()); // Return true to continue rendering return true; } bool SkeletalApplication::processUnbufferedMouseInput(const FrameEvent& evt) { using namespace OIS; // Rotation factors, may not be used if the second mouse button is pressed // 2nd mouse button - slide, otherwise rotate const MouseState &ms = mMouse->getMouseState(); static bool leftDown = false; if( ms.buttonDown( MB_Right ) ) { if (Soldier::selectedSoldier!=NULL){ Soldier::selectedSoldier->ReachTo(mLineDrawer->GetMouse3DPos(ms.X.abs,ms.Y.abs) ); } } else if (ms.buttonDown( MB_Left ) ){ //if (!leftDown){ // //select the soldier // Ray rr = mCamera->getCameraToViewportRay((float)ms.X.abs/mWindow->getViewport(0)->getActualWidth(), // (float)ms.Y.abs/mWindow->getViewport(0)->getActualHeight()); // Vector3 hitPos, hitNorm; // if (RayCast(rr.getOrigin(),rr.getOrigin()+rr.getDirection(),&hitPos,&hitNorm,true)){ // //drawSmoke // //smoke->AddSmoke(hitPos,hitNorm); // } //} leftDown = true; }else if (ms.buttonDown(MB_Middle)) { Vector3 hitPos; Ray rr = mCamera->getCameraToViewportRay((float)ms.X.abs/mWindow->getViewport(0)->getActualWidth(), (float)ms.Y.abs/mWindow->getViewport(0)->getActualHeight()); if (RayCast(rr.getOrigin(),rr.getOrigin()+rr.getDirection(),&hitPos,NULL)){ if (Soldier::selectedSoldier){ Soldier::selectedSoldier->ShotAt(hitPos,evt.timeSinceLastFrame); } } }else{ } if (!ms.buttonDown(MB_Left)) leftDown = false; return true; } bool SkeletalApplication::RayCast(Vector3 from, Vector3 to, Vector3* hitPos, Vector3* hitNorm, bool pickSoldier, bool shoot){ NxRaycastHit hit; NxShape* shape = gScene->raycastClosestShape(NxRay(Vector3ToNxVec3(from),Vector3ToNxVec3( (to-from).normalisedCopy() )),NX_ALL_SHAPES,hit,-1,3.40e+38, NX_RAYCAST_IMPACT | NX_RAYCAST_NORMAL ); if (shape!=NULL){ if (hitPos!=NULL) *hitPos = NxVec33ToVector3( hit.worldImpact ); if (hitNorm!=NULL) *hitNorm = NxVec33ToVector3( hit.worldNormal ); if (pickSoldier){ Soldier::SelectSoldier(shape); } if (shoot){ if (!shape->getActor().readBodyFlag(NX_BF_KINEMATIC)){ shape->getActor().addForceAtPos(Vector3ToNxVec3((to-from).normalisedCopy()*2),hit.worldImpact, NX_VELOCITY_CHANGE); //shape->getActor().addForce(NxVec3(0,10,0),NX_VELOCITY_CHANGE ); } } return true; }else return false; } bool SkeletalApplication::frameStarted(const FrameEvent& evt) { //change the light redLight->setDirection(mCamera->getDirection()); redLight->setPosition(mCamera->getPosition()+mCamera->getDirection().normalisedCopy()*0.00f); //capture all inputs using namespace OIS; if(mWindow->isClosed()) return false; //Need to capture/update each device mMouse->capture(); //const MouseState &ms2 = mMouse->getMouseState(); //if (ms2.X.abs<=renderWinWidth && ms2.Y.abs <= renderWinHeight){//got focus // mKeyboard->capture(); //} mKeyboard->capture(); if( mJoy ) mJoy->capture(); bool buffJ = (mJoy) ? mJoy->buffered() : true; //Check if one of the devices is not buffered if( !mMouse->buffered() || !mKeyboard->buffered() || !buffJ ) { // one of the input modes is immediate, so setup what is needed for immediate movement if (mTimeUntilNextToggle >= 0) mTimeUntilNextToggle -= evt.timeSinceLastFrame; // Move about 100 units per second mMoveScale = mMoveSpeed * evt.timeSinceLastFrame; // Take about 10 seconds for full rotation mRotScale = mRotateSpeed * evt.timeSinceLastFrame; mRotX = 0; mRotY = 0; mTranslateVector = Ogre::Vector3::ZERO; } //Check to see which device is not buffered, and handle it if( !mKeyboard->buffered() ) if( processUnbufferedKeyInput(evt) == false ) return false; if( !mMouse->buffered() ) if( processUnbufferedMouseInput(evt) == false ) return false; if( !mMouse->buffered() || !mKeyboard->buffered() || !buffJ ) moveCamera(); /////////////////// myScene->FrameMove(/*1/30.0f*/ evt.timeSinceLastFrame); ////////////////// //////////////////////physX frameMove here if(gScene == NULL) return false; //// Start simulation (non blocking) //gScene->simulate(1/30.0f /*evt.timeSinceLastFrame*/); //////////////////////physX frameMove end here int nbActors = gScene->getNbActors(); NxActor** actors = gScene->getActors(); while(nbActors--) { NxActor* actor = *actors++; if(!actor->userData) continue; if (actor->readBodyFlag(NX_BF_KINEMATIC)){//kinematic actors }else{ //SceneNode* boxNode = (SceneNode*)actor->userData; //NxVec3 actorPos = actor->getGlobalPosition(); //boxNode->setPosition(actorPos.x,actorPos.y,actorPos.z); //float aa[3][3]; //actor->getGlobalOrientation().getRowMajor(aa); //boxNode->setOrientation(Quaternion(Matrix3(aa))); ////boxNode->setOrientation(actor->getGlobalOrientation()); } } //Ogre framemove here // for (int i = 0; i < NUM_JAIQUAS; ++i) // { //soldiers[i]->FrameMove(evt.timeSinceLastFrame); // } smoke->FrameMove(evt.timeSinceLastFrame); mLineDrawer->ClearAll(); //Vector3 from = Vector3(0,20,0); //Vector3 dir2 = Vector3(0,-1,0); //NxRaycastHit hit; //if (gScene->raycastClosestShape(NxRay(Vector3ToNxVec3(from),Vector3ToNxVec3(dir2)),NX_ALL_SHAPES,hit)!=NULL){ // mLineDrawer->DrawDebugLine(from,from+dir2*hit.distance); //} const MouseState &ms = mMouse->getMouseState(); mLineDrawer->DrawFromMousePos( ms.X.abs, ms.Y.abs); //soldiers[0]->MoveTo(mouse3dPos,evt.timeSinceLastFrame); return true; } bool SkeletalApplication::frameEnded(const FrameEvent& evt) { //if( ExampleFrameListener::frameEnded(evt) == false ) // return false; updateStats(); //////////////////////physX frameMove here //Fetch simulation results //gScene->flushStream(); //gScene->fetchResults(NX_RIGID_BODY_FINISHED, true); //////////////////////physX frameMove here return true; } void SkeletalApplication::createScene(void) { //NxVec3 aa = NxVec3(1,2,3); //Vector3* bb; //bb = reinterpret_cast
(&aa); //NxVec3* aa2 = &aa; //Quaternion q; //NxQuat qq; myScene = new C2GameScene("test_scene_2",mSceneMgr,mWindow, mCamera, gPhysicsSDK, gScene); //myScene = new BilliardsGameScene("BilliardsScene",mSceneMgr,mWindow, mCamera, gPhysicsSDK, gScene); mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED); //mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE); mSceneMgr->setShadowTextureSelfShadow(false); mSceneMgr->setShadowTextureSize(1024); mSceneMgr->setShadowTextureCount(2); mSceneMgr->setShadowColour(ColourValue(0.8, 0.8, 0.8)); mSceneMgr->setShadowFarDistance(500); // Setup animation default Animation::setDefaultInterpolationMode(Animation::IM_LINEAR); Animation::setDefaultRotationInterpolationMode(Animation::RIM_LINEAR); // Set ambient light mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); mSceneMgr->setSkyBox(true, "Examples/StormySkyBox",1000, true, Quaternion(Radian(Degree(90)),Vector3::UNIT_X)); //Entity *ent; Real rotInc = Math::TWO_PI / (float)NUM_JAIQUAS; Real rot = 0.0f; // for (int i = 0; i < NUM_JAIQUAS; ++i) // { //Quaternion q; //q.FromAngleAxis(Radian(rot), Vector3::UNIT_Z); //mOrientations[i] = q; //mBasePositions[i] = q * Vector3(0,-2,0); //soldiers[i] = new Soldier(mSceneMgr,this->mWindow,gScene); //mSceneNode[i] = soldiers[i]->GetRootNode(); //soldiers[i]->Rotate(q); //soldiers[i]->Translate(mBasePositions[i]); //rot += rotInc; // } // Give it a little ambience with lights Light* l; l = mSceneMgr->createLight("BlueLight"); l->setType(Light::LT_SPOTLIGHT); l->setPosition(-5,-5,50); Vector3 dir(-l->getPosition()); dir.normalise(); l->setDirection(dir); l->setSpotlightOuterAngle(Radian(Degree(65))); l->setSpotlightInnerAngle(Radian(Degree(45))); l->setDiffuseColour(0.55, 0.55, 0.55); l->setCastShadows(true); l->setVisible(true); l = mSceneMgr->createLight("RedLight"); redLight = l; l->setType(Light::LT_SPOTLIGHT); l->setPosition(2,-5,20); dir = -l->getPosition(); dir.normalise(); l->setDirection(dir); l->setDiffuseColour(0.95, 0.95, 0.95); l->setCastShadows(true); l->setVisible(true); // Position the camera mCamera->setPosition(20,0,6); mCamera->lookAt(0,0,0); mCamera->roll(Radian(Degree(90))); mCamera->setFixedYawAxis(true,Vector3::UNIT_Z); mCamera->setNearClipDistance(1.0f); //mCamera->setProjectionType(ProjectionType::PT_ORTHOGRAPHIC); Vector3 myVec = mCamera->getRealUp(); //Plane plane; //plane.normal = Vector3::UNIT_Z; //plane.d = 0; ////plane.d = 0; //MeshManager::getSingleton().createPlane("Myplane", // ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, // 15,15,1,1,true,1,60,60,Vector3::UNIT_Y); //Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); //pPlaneEnt->setMaterialName("Examples/Rockwall"); ////pPlaneEnt->getSubEntity(0)->getMaterial()->setReceiveShadows(false); ////pPlaneEnt->setCastShadows(false); //mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,0,-2))->attachObject(pPlaneEnt); //create the box entity //Entity* box; //SceneNode* boxNode; int boxNum = 5; float boxSize = 4*0.1f; // Add entity to the scene node for (int x=0;x
getRootSceneNode()->createChildSceneNode("mySoldier"); //myScene->Load("marine.scene",this->mWindow,OgreMax::OgreMaxScene::NO_OPTIONS,mSceneMgr,soldier); //soldier->scale(5,5,5); //SceneNode* soldier_body = (SceneNode*)soldier->getChild("Marine-body"); //SceneNode* soldier_head = (SceneNode*)soldier->getChild("head"); //Entity* bodyEnt = (Entity*)soldier_body->getAttachedObject(0); //AnimationState* animState = bodyEnt->getAnimationState("all"); //animState->setEnabled(true); //animState->setLoop(true); //bodyEnt = (Entity*)soldier_head->getAttachedObject(0); //animState = bodyEnt->getAnimationState("all"); //animState->setEnabled(true); //animState->setLoop(true); //MaterialPtr matPtr = MaterialManager::getSingleton().getByName("marine-body"); //matPtr->setReceiveShadows(true); //matPtr->setLightingEnabled(true); //mSceneNode[i] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //mSceneNode[i]->attachObject(ent); //mSceneNode[i]->rotate(q); //mSceneNode[i]->translate(mBasePositions[i]); //mSceneNode[i]->scale(5,5,5); mLineDrawer = new DebugLine(mSceneMgr); smoke = new Smoke(mSceneMgr); } #ifdef __cplusplus } #endif
GameFactoryDemo.cpp
网页地址
文件地址
上一页
19/45
下一页
下载
( 29 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.