AnimatedMesh* GraphicsEngineImp::CreateAnimatedMesh(string filename, D3DXVECTOR3 pos, const char* billboardFilePath, float distanceToSwapToBillboard) { AnimatedMesh* mesh = new AnimatedMesh(pos, filename, billboardFilePath, distanceToSwapToBillboard); // If we have it in memory dont put it on the other thread. if(!this->useLoadingThread && GetResourceManager()->HasMeshStripsResource(filename.c_str())) { //Check if loading the animation from file was successful... if(mesh->LoadFromFile(filename)) { //...and if so, add it this->dx->CreateAnimatedMesh(mesh); } else { //If not, delete the mesh. MaloW::Debug("Warning: Deleting animated mesh because of failure."); delete mesh; } } else { LoadMeshEvent* re = new LoadMeshEvent(filename, NULL, mesh, NULL); this->PutEvent(re); } return mesh; }
//************************************************************************************************************* void Render(float alpha, float elapsedtime) { static float time = 0; D3DXMATRIX viewproj; D3DXMatrixMultiply(&viewproj, &view, &proj); D3DXMatrixScaling(&world, 0.1f, 0.1f, 0.1f); time += elapsedtime; device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xff6694ed, 1.0f, 0); device->SetTransform(D3DTS_WORLD, &world); device->SetTransform(D3DTS_VIEW, &view); device->SetTransform(D3DTS_PROJECTION, &proj); mesh.Update(elapsedtime, &world); effect->SetMatrix("matViewProj", &viewproj); if( SUCCEEDED(device->BeginScene()) ) { mesh.Draw(); device->EndScene(); } device->Present(NULL, NULL, NULL, NULL); }
void Scene::Update(float timeElapsed) { TIME_PROFILE("Scene::Update"); uint64 time = SystemTimer::Instance()->AbsoluteMS(); updatableSystem->UpdatePreTransform(); transformSystem->Process(); updatableSystem->UpdatePostTransform(); if(RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::UPDATE_LODS)) { lodSystem->SetCamera(currentCamera); lodSystem->Process(); } switchSystem->Process(); // entityManager->Flush(); int32 size; size = (int32)animations.size(); for (int32 animationIndex = 0; animationIndex < size; ++animationIndex) { SceneNodeAnimationList * anim = animations[animationIndex]; anim->Update(timeElapsed); } referenceNodeSuffixChanged = false; if(RenderManager::Instance()->GetOptions()->IsOptionEnabled(RenderOptions::UPDATE_ANIMATED_MESHES)) { size = (int32)animatedMeshes.size(); for (int32 animatedMeshIndex = 0; animatedMeshIndex < size; ++animatedMeshIndex) { AnimatedMesh * mesh = animatedMeshes[animatedMeshIndex]; mesh->Update(timeElapsed); } } //if(imposterManager) //{ // imposterManager->Update(timeElapsed); //} updateTime = SystemTimer::Instance()->AbsoluteMS() - time; }
Scene::~Scene() { for (Vector<AnimatedMesh*>::iterator t = animatedMeshes.begin(); t != animatedMeshes.end(); ++t) { AnimatedMesh * obj = *t; obj->Release(); } animatedMeshes.clear(); for (Vector<Camera*>::iterator t = cameras.begin(); t != cameras.end(); ++t) { Camera * obj = *t; obj->Release(); } cameras.clear(); SafeRelease(currentCamera); SafeRelease(clipCamera); for (Map<String, ProxyNode*>::iterator it = rootNodes.begin(); it != rootNodes.end(); ++it) { SafeRelease(it->second); } rootNodes.clear(); // Children should be removed first because they should unregister themselves in managers RemoveAllChildren(); SafeRelease(imposterManager); transformSystem = 0; renderUpdateSystem = 0; lodSystem = 0; uint32 size = (uint32)systems.size(); for (uint32 k = 0; k < size; ++k) SafeDelete(systems[k]); systems.clear(); SafeDelete(eventSystem); SafeDelete(renderSystem); }
Scene::~Scene() { SceneCache::Instance()->RemoveScene(this); for (Vector<AnimatedMesh*>::iterator t = animatedMeshes.begin(); t != animatedMeshes.end(); ++t) { AnimatedMesh * obj = *t; obj->Release(); } animatedMeshes.clear(); for (Vector<Camera*>::iterator t = cameras.begin(); t != cameras.end(); ++t) { Camera * obj = *t; obj->Release(); } cameras.clear(); SafeRelease(mainCamera); SafeRelease(drawCamera); for (ProxyNodeMap::iterator it = rootNodes.begin(); it != rootNodes.end(); ++it) { SafeRelease(it->second); } rootNodes.clear(); // Children should be removed first because they should unregister themselves in managers RemoveAllChildren(); SafeRelease(imposterManager); SafeRelease(sceneGlobalMaterial); transformSystem = 0; renderUpdateSystem = 0; lodSystem = 0; debugRenderSystem = 0; particleEffectSystem = 0; updatableSystem = 0; lightUpdateSystem = 0; switchSystem = 0; soundSystem = 0; actionSystem = 0; skyboxSystem = 0; staticOcclusionSystem = 0; materialSystem = 0; speedTreeUpdateSystem = 0; foliageSystem = 0; windSystem = 0; waveSystem = 0; uint32 size = (uint32)systems.size(); for (uint32 k = 0; k < size; ++k) SafeDelete(systems[k]); systems.clear(); systemsToProcess.clear(); SafeDelete(eventSystem); SafeDelete(renderSystem); }
void test() { GraphicsEngine* ge = GetGraphicsEngine(); // Example of GE useage GraphicsEngine* eng = GetGraphicsEngine(); eng->GetCamera()->setPosition(D3DXVECTOR3(0, 15, -15.6f)); eng->GetCamera()->LookAt(D3DXVECTOR3(30, 10, 10)); StaticMesh* testBall = eng->CreateStaticMesh("Media/Ball.obj", D3DXVECTOR3(8, 15, 8)); StaticMesh* testCylinder = eng->CreateStaticMesh("Media/Cylinder.obj", D3DXVECTOR3(10, 10, 10)); StaticMesh* bth = eng->CreateStaticMesh("Media/bth.obj", D3DXVECTOR3(5, 20, 15)); AnimatedMesh* flag = eng->CreateAnimatedMesh("Media/FlagRed.ani", D3DXVECTOR3(8, 15, 8)); flag->LoopSeamless(); AnimatedMesh* flagb = eng->CreateAnimatedMesh("Media/FlagBlue.ani", D3DXVECTOR3(10, 15, 8)); flagb->LoopSeamless(); StaticMesh* flag1 = eng->CreateStaticMesh("Media/FlagBlue1.obj", D3DXVECTOR3(12, 15, 8)); StaticMesh* flag2 = eng->CreateStaticMesh("Media/FlagBlue2.obj", D3DXVECTOR3(14, 15, 8)); StaticMesh* flag3 = eng->CreateStaticMesh("Media/FlagBlue3.obj", D3DXVECTOR3(16, 15, 8)); StaticMesh* flag4 = eng->CreateStaticMesh("Media/FlagBlue4.obj", D3DXVECTOR3(18, 15, 8)); StaticMesh* flag5 = eng->CreateStaticMesh("Media/FlagBlue5.obj", D3DXVECTOR3(20, 15, 8)); StaticMesh* ball1 = eng->CreateStaticMesh("Media/Ball1.obj", D3DXVECTOR3(12, 30, 8)); StaticMesh* ball2 = eng->CreateStaticMesh("Media/Ball2.obj", D3DXVECTOR3(14, 30, 8)); StaticMesh* ball3 = eng->CreateStaticMesh("Media/Ball3.obj", D3DXVECTOR3(16, 30, 8)); StaticMesh* ball4 = eng->CreateStaticMesh("Media/Ball4.obj", D3DXVECTOR3(18, 30, 8)); //StaticMesh* wlmap = eng->CreateStaticMesh("Media/WarlockMap.obj", D3DXVECTOR3(100, 4, 8)); //StaticMesh* hb = eng->CreateStaticMesh("Media/HardenedBall.obj", D3DXVECTOR3(12, 15, 12)); bth->Scale(0.1f); Light* testLight = eng->CreateLight(D3DXVECTOR3(15, 30, 15)); testLight->SetLookAt(testBall->GetPosition()); //testBall->SetSpecialColor(RED_COLOR); //testCylinder->SetSpecialColor(GREEN_COLOR); //AnimatedMesh* ani = eng->CreateAnimatedMesh("Media/AniTest.ani", D3DXVECTOR3(12, 16, 12)); //ani->LoopNormal(); //ani->LoopSeamless(); SoundEngine* seng = eng->GetSoundEngine(); SoundEffect* se1 = seng->LoadSoundEffect("Media/Sounds/SoundEffects/ball_vs_ball.mp3", false); //SoundEffect* se2 = seng->LoadSoundEffect("Media/Sounds/SoundEffects/ball_vs_wall.mp3", false); //SoundSong* ss1 = seng->LoadSong("Media/Sounds/Songs/america_fuck_yeah.mp3", true); seng->SetMasterVolume(0.5f); //ss1->Play(); //eng->LoadingScreen("Media/LoadingScreen/LoadingScreenBG.png", "Media/LoadingScreen/LoadingScreenPB.png"); // going to LoadingScreen to load the above meshes //eng->LoadingScreen("Media/LoadingScreen/LoadingScreenBG.png", "Media/LoadingScreen/LoadingScreenPB.png", 0.0f, 1.0f, 1.0f, 1.0f); eng->LoadingScreen("Media/LoadingScreen/StartScreen.png", "", 0.0f, 1.0f, 1.0f, 1.0f); Text* text = eng->CreateText("Lol ", D3DXVECTOR2(500, 500), 1.0f, "Media/Fonts/1"); //Image* testImg = eng->CreateImage(D3DXVECTOR2(50, 50), D3DXVECTOR2(500, 75), "Media/PowerBall.png"); //testLight->SetPosition(testBall->GetPosition() + D3DXVECTOR3(0, 5, 0)); //testLight->SetLookAt(testLight->GetPosition() - D3DXVECTOR3(0, 5, 0)); //Light* testLight2 = eng->CreateLight(D3DXVECTOR3(3, 20, 3)); CamRecording* camRec = new CamRecording(2000, true); // How many milliseconds between each way point camRec->Init(eng->GetCamera()); /*camRec->AddCameraWaypoint(D3DXVECTOR3(0, 0, 0), D3DXVECTOR3(8, 16, 8)); camRec->AddCameraWaypoint(D3DXVECTOR3(0, 30, 0), D3DXVECTOR3(8, 16, 8)); camRec->AddCameraWaypoint(D3DXVECTOR3(30, 30, 30), D3DXVECTOR3(8, 16, 8)); camRec->AddCameraWaypoint(D3DXVECTOR3(-20, 20, 30), D3DXVECTOR3(8, 16, 8)); camRec->AddCameraWaypoint(D3DXVECTOR3(0, 50, 0), D3DXVECTOR3(8, 16, 8)); camRec->AddCameraWaypoint(D3DXVECTOR3(0, 20, 0), D3DXVECTOR3(8, 16, 8));*/ //camRec->Load(CIRCLE_AROUND); camRec->CircleAround(true, 50, 1000, 0, D3DXVECTOR3(30, 50, 0), D3DXVECTOR3(0,0,30)); bool sw = true; float size = 1.0f; bool go = true; while(eng->isRunning() && go) // Returns true as long as ESC hasnt been pressed, if it's pressed the game engine will shut down itself (to be changed) { float diff = eng->Update(); // Updates camera etc, does NOT render the frame, another process is doing that, so diff should be very low. text->SetText("Distance to Lava: " + MaloW::convertNrToString(eng->GetCamera()->getPosition().y - eng->GetLavaHeightAt(eng->GetCamera()->getPosition().x, eng->GetCamera()->getPosition().z))); //testBall->Rotate(D3DXVECTOR3(2*PI, 0, 0) * (diff/1000.0f)); // Divide diff by 1000 to get seconds since diff is in milliseconds. testBall->RotateAxis(D3DXVECTOR3(2, 0, 0), 2* PI * (diff/1000.0f)); // Divide diff by 1000 to get seconds since diff is in milliseconds. CursorControl cc; if(eng->GetKeyListener()->IsPressed('W')) eng->GetCamera()->moveForward(diff); if(eng->GetKeyListener()->IsPressed(VK_RETURN)) // For keys other than the main-chars you use the VK_ Enums, rightclick on VK_RETURN and "Go to definition" to find the list of all keys cc.SetVisibility(true); if(eng->GetKeyListener()->IsPressed('A')) eng->GetCamera()->moveLeft(diff); if(eng->GetKeyListener()->IsPressed('S')) eng->GetCamera()->moveBackward(diff); if(eng->GetKeyListener()->IsPressed('D')) eng->GetCamera()->moveRight(diff); if(eng->GetKeyListener()->IsPressed(VK_ESCAPE)) go = false; if(eng->GetKeyListener()->IsPressed(VK_BACK)) { if(sw) { //se1->Play(); text->DeleteFromEnd(1); } sw = false; } else sw = true; if(eng->GetKeyListener()->IsClicked(1)) { size += diff * 0.001f; text->SetSize(size); //ss1->SetVolume(0.5f); text->AppendText("LoL "); //ss1->Play(); } //else //se1->Play(); if(eng->GetKeyListener()->IsClicked(2)) { testBall->UseInvisibilityEffect(true); } else testBall->UseInvisibilityEffect(false); if(eng->GetKeyListener()->IsPressed('G')) { //ani->LoopNormal(); flag->LoopNormal(); flagb->LoopNormal(); eng->GetEngineParameters().FXAAQuality = 4; ge->GetEngineParameters().FXAAQuality = 4; //camRec->Play(); // Play to start moving the camera along the path } camRec->Update(diff); // update needed to move the camera when play is initialized. if(eng->GetKeyListener()->IsPressed('V')) { //ani->NoLooping(); flag->NoLooping(); flagb->NoLooping(); } if(eng->GetKeyListener()->IsPressed('B')) { //ani->LoopSeamless(); flag->LoopSeamless(); flagb->LoopSeamless(); eng->GetEngineParameters().FXAAQuality = 0; //ge->GetEngineParameters().FXAAQuality = 0; for(int i = 0; i < 200; i++) { //se1->Play(); } } } // Delete camera recording delete camRec; }
void DxManager::CalculateCulling() { D3DXMATRIX view = this->camera->GetViewMatrix(); D3DXMATRIX proj = this->camera->GetProjectionMatrix(); /* float zMinimum = -proj._43 / proj._33; float r = this->params.FarClip / (this->params.FarClip - zMinimum); proj._33 = r; proj._43 = -r * zMinimum; */ D3DXMATRIX VP; D3DXMatrixMultiply(&VP, &view, &proj); // Calculate near plane of frustum. FrustrumPlanes[0].a = VP._14 + VP._13; FrustrumPlanes[0].b = VP._24 + VP._23; FrustrumPlanes[0].c = VP._34 + VP._33; FrustrumPlanes[0].d = VP._44 + VP._43; D3DXPlaneNormalize(&FrustrumPlanes[0], &FrustrumPlanes[0]); // Calculate far plane of frustum. FrustrumPlanes[1].a = VP._14 - VP._13; FrustrumPlanes[1].b = VP._24 - VP._23; FrustrumPlanes[1].c = VP._34 - VP._33; FrustrumPlanes[1].d = VP._44 - VP._43; D3DXPlaneNormalize(&FrustrumPlanes[1], &FrustrumPlanes[1]); // Calculate left plane of frustum. FrustrumPlanes[2].a = VP._14 + VP._11; FrustrumPlanes[2].b = VP._24 + VP._21; FrustrumPlanes[2].c = VP._34 + VP._31; FrustrumPlanes[2].d = VP._44 + VP._41; D3DXPlaneNormalize(&FrustrumPlanes[2], &FrustrumPlanes[2]); // Calculate right plane of frustum. FrustrumPlanes[3].a = VP._14 - VP._11; FrustrumPlanes[3].b = VP._24 - VP._21; FrustrumPlanes[3].c = VP._34 - VP._31; FrustrumPlanes[3].d = VP._44 - VP._41; D3DXPlaneNormalize(&FrustrumPlanes[3], &FrustrumPlanes[3]); // Calculate top plane of frustum. FrustrumPlanes[4].a = VP._14 - VP._12; FrustrumPlanes[4].b = VP._24 - VP._22; FrustrumPlanes[4].c = VP._34 - VP._32; FrustrumPlanes[4].d = VP._44 - VP._42; D3DXPlaneNormalize(&FrustrumPlanes[4], &FrustrumPlanes[4]); // Calculate bottom plane of frustum. FrustrumPlanes[5].a = VP._14 + VP._12; FrustrumPlanes[5].b = VP._24 + VP._22; FrustrumPlanes[5].c = VP._34 + VP._32; FrustrumPlanes[5].d = VP._44 + VP._42; D3DXPlaneNormalize(&FrustrumPlanes[5], &FrustrumPlanes[5]); //Terrain for(int i = 0; i < this->terrains.size(); i++) { Terrain* terr = this->terrains.get(i); float scale = max(terr->GetScale().x, max(terr->GetScale().y, terr->GetScale().z)); if(pe.FrustrumVsSphere(this->FrustrumPlanes, terr->GetBoundingSphere(), terr->GetWorldMatrix(), scale)) { terr->SetCulled(false); } else { terr->SetCulled(true); } } //Static meshes for(int i = 0; i < this->objects.size(); i++) { StaticMesh* ms = this->objects.get(i); MaloW::Array<MeshStrip*>* strips = ms->GetStrips(); for(int u = 0; u < strips->size(); u++) { MeshStrip* s = strips->get(u); float scale = max(ms->GetScaling().x, max(ms->GetScaling().y, ms->GetScaling().z)); if(pe.FrustrumVsSphere(this->FrustrumPlanes, s->GetBoundingSphere(), ms->GetWorldMatrix(), scale)) { s->SetCulled(false); } else { s->SetCulled(true); } } } //Animated meshes for(int i = 0; i < this->animations.size(); i++) { AnimatedMesh* ms = this->animations.get(i); MeshStrip* s = ms->GetStrips()->get(0); float scale = max(ms->GetScaling().x, max(ms->GetScaling().y, ms->GetScaling().z)); if(pe.FrustrumVsSphere(this->FrustrumPlanes, s->GetBoundingSphere(), ms->GetWorldMatrix(), scale)) { s->SetCulled(false); } else { s->SetCulled(true); } } }
void Scenario::loadFromXml(ofxBulletWorldRigid &world){ ofxXmlSettings ScenarioXml; if(ScenarioXml.loadFile(PinballChinoManager::projectName+"/scenario.xml")){ ScenarioXml.pushTag("scenario"); int numberOfSavedObjects = ScenarioXml.getNumTags("object"); for(int i = 0; i < numberOfSavedObjects; i++){ ScenarioXml.pushTag("object", i); SimpleObject::shapeType Type = (SimpleObject::shapeType)ScenarioXml.getValue("type", 0); int objId = ScenarioXml.getValue("id", 0); ofVec3f pos, scale; pos.x = ScenarioXml.getValue("positionX",0.0, 0); pos.y = ScenarioXml.getValue("positionY",0.0, 0); pos.z = ScenarioXml.getValue("positionZ",0.0, 0); scale.x = ScenarioXml.getValue("scaleX",0.0, 0); scale.y = ScenarioXml.getValue("scaleY",0.0, 0); scale.z = ScenarioXml.getValue("scaleZ",0.0, 0); ofQuaternion rotation; ofVec4f rot; rot.x = ScenarioXml.getValue("rotationX",0.0,0); rot.y = ScenarioXml.getValue("rotationY",0.0,0); rot.z = ScenarioXml.getValue("rotationZ",0.0,0); rot.w = ScenarioXml.getValue("rotationW",0.0,0); rotation.set(rot); string path; path = ScenarioXml.getValue("path","", 0); //TODO uncomment the line below when the xml is properly configured //string strcolor = ScenarioXml.getValue("color", "0xFFFFFF", 0); int color = ScenarioXml.getValue("color", 0xFFFFFF, 0); int pointsCollision = ScenarioXml.getValue("pointsCollision", 0, 0); int invisible = 0; // Visible by default event if this value is not implemented in the Xml editor invisible = ScenarioXml.getValue("invisible", 0, 0); switch(Type){ case SimpleObject::ShapeTypeBall:{ Ball *oBall = new Ball(currentMissions); float mass = ScenarioXml.getValue("mass", 0.0); float radius = ScenarioXml.getValue("radius", 0.0); float restitution = ScenarioXml.getValue("restitution", 0.0); float friction = ScenarioXml.getValue("friction", 0.0); oBall->setup(world, pos, mass, radius, restitution, friction); oBall->SetObjectId(objId); oBall->setRotation(rotation); oBall->color = color; oBall->setVisibility(invisible); ScenarioObjects.push_back(oBall); } break; case SimpleObject::ShapeTypeHammer:{ Hammer *oHammer = new Hammer(currentMissions); oHammer->setup(world, pos); oHammer->SetObjectId(objId); oHammer->setRotation(rotation); oHammer->color = color; oHammer->setVisibility(invisible); ScenarioObjects.push_back(oHammer); oHammer->setupRot(); } break; case SimpleObject::ShapeTypeLever:{ Lever *oLever = new Lever(currentMissions); int dir = ScenarioXml.getValue("LeverType", 0); oLever->setup(world, pos, path, scale, dir); oLever->SetObjectId(objId); oLever->setRotation(rotation); oLever->color = color; oLever->setVisibility(invisible); ScenarioObjects.push_back(oLever); } break; case SimpleObject::ShapeTypeObstacle:{ Obstacle *oObstable = new Obstacle(currentMissions); //oObstable->setup(world, pos, "3DModels/chino_6.dae"); oObstable->setup(world, pos, path, scale); oObstable->SetObjectId(objId); oObstable->setRotation(rotation); oObstable->color = color; oObstable->setVisibility(invisible); ScenarioObjects.push_back(oObstable); oObstable->setPointsCollision(pointsCollision); oObstable->setupRot(); } break; case SimpleObject::ShapeTypeGravity:{ Gravity *oGravity = new Gravity(currentMissions); //oObstable->setup(world, pos, "3DModels/chino_6.dae"); oGravity->setup(world, pos, path, scale); oGravity->SetObjectId(objId); oGravity->setRotation(rotation); oGravity->color = color; oGravity->setVisibility(invisible); ScenarioObjects.push_back(oGravity); oGravity->setPointsCollision(pointsCollision); oGravity->setupRot(); } break; case SimpleObject::ShapeTypeTeleporter:{ Teleporter *oTeleporter = new Teleporter(currentMissions); //oObstable->setup(world, pos, "3DModels/chino_6.dae"); oTeleporter->setup(world, pos, path, scale); oTeleporter->SetObjectId(objId); oTeleporter->setRotation(rotation); oTeleporter->color = color; oTeleporter->setVisibility(invisible); ScenarioObjects.push_back(oTeleporter); oTeleporter->setPointsCollision(pointsCollision); oTeleporter->setupRot(); } break; case SimpleObject::ShapeTypeRamp:{ Ramp *oRamp = new Ramp(currentMissions); //oObstable->setup(world, pos, "3DModels/chino_6.dae"); oRamp->setup(world, pos, path, scale); oRamp->SetObjectId(objId); oRamp->setRotation(rotation); oRamp->color = color; oRamp->setVisibility(invisible); ScenarioObjects.push_back(oRamp); oRamp->setPointsCollision(pointsCollision); oRamp->setupRot(); } break; case SimpleObject::ShapeTypeObstacleTriShapeMesh:{ ObstacleTriShapeMesh *oObstacleTriShapeMesh= new ObstacleTriShapeMesh(currentMissions); oObstacleTriShapeMesh->setup(world, pos, path, scale); oObstacleTriShapeMesh->SetObjectId(objId); oObstacleTriShapeMesh->setRotation(rotation); oObstacleTriShapeMesh->color = color; oObstacleTriShapeMesh->setVisibility(invisible); ScenarioObjects.push_back(oObstacleTriShapeMesh); oObstacleTriShapeMesh->setPointsCollision(pointsCollision); oObstacleTriShapeMesh->setupRot(); } break; case SimpleObject::ShapeTypeAnimatedObject:{ AnimatedObject *oAnimatedObject = new AnimatedObject(currentMissions); //oObstable->setup(world, pos, "3DModels/chino_6.dae"); oAnimatedObject->setup(world, pos, path, scale); oAnimatedObject->SetObjectId(objId); oAnimatedObject->setRotation(rotation); oAnimatedObject->color = color; oAnimatedObject->setVisibility(invisible); ScenarioObjects.push_back(oAnimatedObject); oAnimatedObject->setPointsCollision(pointsCollision); oAnimatedObject->setupRot(); } break; case SimpleObject::ShapeTypeAnimatedMotionPath:{ string pathMotionModel; pathMotionModel = ScenarioXml.getValue("pathMotionModel","", 0); AnimatedMotionPath *oAnimatedMotionPath = new AnimatedMotionPath(currentMissions); oAnimatedMotionPath->setup(world, pos, path, pathMotionModel, scale); oAnimatedMotionPath->SetObjectId(objId); oAnimatedMotionPath->setRotation(rotation); oAnimatedMotionPath->color = color; oAnimatedMotionPath->setVisibility(invisible); ScenarioObjects.push_back(oAnimatedMotionPath); oAnimatedMotionPath->setPointsCollision(pointsCollision); oAnimatedMotionPath->setupRot(); } break; case SimpleObject::ShapeTypeAnimatedMesh:{ AnimatedMesh *oAnimatedMesh = new AnimatedMesh(currentMissions); //oObstable->setup(world, pos, "3DModels/chino_6.dae"); oAnimatedMesh->setup(world, pos, path, scale); oAnimatedMesh->SetObjectId(objId); oAnimatedMesh->setRotation(rotation); oAnimatedMesh->color = color; oAnimatedMesh->setVisibility(invisible); ScenarioObjects.push_back(oAnimatedMesh); oAnimatedMesh->setPointsCollision(pointsCollision); oAnimatedMesh->setupRot(); } break; case SimpleObject::ShapeTypeGeneratedMesh:{ GeneratedMesh *oGeneratedMesh = new GeneratedMesh(currentMissions); //oObstable->setup(world, pos, "3DModels/chino_6.dae"); oGeneratedMesh->setup(world, pos, path, scale); oGeneratedMesh->SetObjectId(objId); oGeneratedMesh->setRotation(rotation); oGeneratedMesh->color = color; oGeneratedMesh->setVisibility(invisible); ScenarioObjects.push_back(oGeneratedMesh); oGeneratedMesh->setPointsCollision(pointsCollision); oGeneratedMesh->setupRot(); } break; case SimpleObject::ShapeTypeBounds:{ Bounds *oBounds = new Bounds(currentMissions); oBounds->setup(world, pos, path, scale); oBounds->SetObjectId(objId); oBounds->setRotation(rotation); oBounds->color = color; oBounds->setVisibility(invisible); ScenarioObjects.push_back(oBounds); oBounds->setupRot(); } break; } ScenarioXml.popTag(); } ScenarioXml.popTag(); //pop position } else{ ofLogError("Scenario file did not load!"); } }
HRESULT InitScene() { HRESULT hr; LPD3DXBUFFER errors = NULL; SetWindowText(hwnd, TITLE); hr = D3DXCreateEffectFromFileA(device, "../media/shaders/skinning.fx", NULL, NULL, D3DXSHADER_DEBUG, NULL, &effect, &errors); if( FAILED(hr) ) { if( errors ) { char* str = (char*)errors->GetBufferPointer(); std::cout << str << "\n\n"; errors->Release(); } MYERROR("Could not create effect"); return hr; } // load animated model mesh.Effect = effect; mesh.Method = SM_Shader; mesh.Path = "../media/meshes/dwarf/"; if( FAILED(hr = mesh.Load(device, "../media/meshes/dwarf/dwarf.X")) ) { MYERROR("Could not load dwarf"); return hr; } // all the possible skins are contained in this file => turn off some mesh.SetAnimation(6); mesh.EnableFrame("LOD0_attachment_weapon3", false); mesh.EnableFrame("LOD0_attachment_weapon2", false); mesh.EnableFrame("LOD0_attachment_shield3", false); mesh.EnableFrame("LOD0_attachment_shield2", false); mesh.EnableFrame("LOD0_attachment_head2", false); mesh.EnableFrame("LOD0_attachment_head1", false); mesh.EnableFrame("LOD0_attachment_torso2", false); mesh.EnableFrame("LOD0_attachment_torso3", false); mesh.EnableFrame("LOD0_attachment_legs2", false); mesh.EnableFrame("LOD0_attachment_legs3", false); mesh.EnableFrame("LOD0_attachment_Lpads1", false); mesh.EnableFrame("LOD0_attachment_Lpads2", false); mesh.EnableFrame("Rshoulder", false); D3DXVECTOR3 eye(0.5f, 1.0f, -1.5f); D3DXVECTOR3 look(0, 0.7f, 0); D3DXVECTOR3 up(0, 1, 0); D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 3, (float)screenwidth / (float)screenheight, 0.1f, 100); D3DXMatrixLookAtLH(&view, &eye, &look, &up); D3DXMatrixIdentity(&world); std::cout << "Press Space to cycle animations\n"; return S_OK; }
//************************************************************************************************************* void KeyPress(WPARAM wparam) { if( wparam == VK_SPACE ) mesh.NextAnimation(); }