Debris* ThrowableGenerator::CreateThrowable(const String& Throwable) { EntityManager* EntMan = static_cast<EntityManager*>( Entresol::GetSingletonPtr()->GetWorld(0)->GetManager(ManagerBase::MT_EntityManager) ); ThrowableData* ToBeCreated = GetThrowableData(Throwable); if(!ToBeCreated) return NULL; std::stringstream NameGen; (ToBeCreated->ThrowableCount)++; NameGen << ToBeCreated->ThrowableName << ToBeCreated->ThrowableCount; RigidDebris* Created = EntMan->CreateRigidDebris(ToBeCreated->Mass); Created->SetName(NameGen.str()); Created->GetRigidProxy()->SetLinearMovementFactor(Vector3(1,1,0)); Created->GetRigidProxy()->SetFriction(ToBeCreated->Friction); Created->GetRigidProxy()->SetRestitution(ToBeCreated->Restitution); // ©reated->GetRigidProxy()->SetActivationState(Physics::WOAS_DisableDeactivation); Created->GetItemProxy()->SetMesh(ToBeCreated->MeshName,ToBeCreated->GroupName); Created->SetOrientation(Quaternion(MathTools::GetPi(),Vector3(0,1,0))); /*if("Rubber"==Throwable) { //generate sphere shape }else{ //generate convex hull //probably make more if's for cylinders and such }// */ return Created; }
void LoadContent() { DebrisManager* DebrisMan = static_cast<DebrisManager*>( DemoWorld->GetManager(ManagerBase::MT_DebrisManager) ); Graphics::SceneManager* SceneMan = static_cast<Graphics::SceneManager*>( DemoWorld->GetManager(ManagerBase::MT_SceneManager) ); Physics::PhysicsManager* PhysMan = static_cast<Physics::PhysicsManager*>( DemoWorld->GetManager(ManagerBase::MT_PhysicsManager) ); Resource::ResourceManager* ResourceMan = static_cast<Resource::ResourceManager*>( TheEntresol->GetManager(ManagerBase::MT_ResourceManager) ); SceneMan->SetAmbientLight(0.10,0.10,0.10,0.10); RigidDebris* object1; RigidDebris* object2; RigidDebris* object3; RigidDebris* object4; RigidDebris* object5; RigidDebris* object6; RigidDebris* object7; //Ogre Setup Code String groupname("Group1"); String filerobot("robot.mesh"); String robotprefix("Robot"); Real mass = 15.0; /// @todo Figure why the EngineDemo fails on Linux when trying to find items in the ResourceMan->AddAssetLocation("data/common", Resource::AT_FileSystem, groupname, false); ResourceMan->AddAssetLocation("data/common/music", Resource::AT_FileSystem, groupname, false); ResourceMan->AddAssetLocation("data/common/sounds", Resource::AT_FileSystem, groupname, false); //ResourceMan->AddAssetLocation(zipname.str(), "Zip", groupname, false); ResourceMan->AddAssetLocation("", Resource::AT_FileSystem, groupname, false); ResourceMan->InitAssetGroup(groupname); Vector3 grav( 0.0, -400.0, 0.0 ); PhysMan->SetWorldGravity(grav); PhysMan->SetWorldSoftGravity(grav); //ParticleEffect *GreenPart = SceneMan->CreateParticleEffect("GreenParticles", "Examples/GreenyNimbus"); //GreenPart->SetLocation(Vector3(-70,70,-100)); Physics::CollisionShapeManager* CSMan = static_cast<Physics::CollisionShapeManager*>( TheEntresol->GetManager(ManagerBase::MT_CollisionShapeManager) ); Physics::CollisionShape* RobitCH = CSMan->GenerateConvexHull("RobitConvexHull",filerobot,groupname); //Physics::CollisionShape* RobitCD = CSMan->PerformConvexDecomposition("RobitConvexDecomp",filerobot,groupname,5.0,5.0,10.0); Physics::CollisionShape* PlaneStatic = CSMan->GenerateStaticTriMesh("PlaneShape","Plane.mesh",groupname); Physics::CollisionShape* WoodenSphere = new Physics::SphereCollisionShape("WoodSphere",250.0); Physics::CollisionShape* MetalSphere = new Physics::SphereCollisionShape("MetalSphere",250.0); Physics::CollisionShape* MetalSphere2 = new Physics::SphereCollisionShape("MetalSphere2",250.0); // Now Lets make some bowling pins Real PinSpacing=75.0; //This is how far apart we want the pins RigidDebris* RigDeb = NULL; for(unsigned int c=0; c<4; c++) //make the back row { std::stringstream namestream; namestream << robotprefix << c; RigDeb = DebrisMan->CreateRigidDebris(namestream.str(),mass); RigDeb->GetRigidProxy()->SetCollisionShape(RobitCH); RigDeb->GetEntityProxy()->SetMesh(filerobot,groupname); //TheEntresol->GetResourceManager()->ImportShapeData(RigDeb, "data/common/RobotDecomp3.bullet"); RigDeb->SetLocation(Vector3( (-2.0*PinSpacing)+(c*PinSpacing), -90.0, 0)); RigDeb->AddToWorld(); } for(unsigned int c=0; c<3; c++) //the row with three pins { std::stringstream namestream; namestream << robotprefix << (c+4); RigDeb = DebrisMan->CreateRigidDebris(namestream.str(),mass); RigDeb->GetRigidProxy()->SetCollisionShape(RobitCH); RigDeb->GetEntityProxy()->SetMesh(filerobot,groupname); //TheEntresol->GetResourceManager()->ImportShapeData(RigDeb, "data/common/RobotDecomp3.bullet"); RigDeb->SetLocation(Vector3( (-1.5*PinSpacing)+(c*PinSpacing), -66.0, -PinSpacing)); RigDeb->AddToWorld(); } //TheEntresol->Resources->ImportShapeData(RigDeb, "RobotDecomp3.bullet"); for(unsigned int c=0; c<2; c++) //the row with 2 pins { std::stringstream namestream; namestream << robotprefix << (c+7); RigDeb = DebrisMan->CreateRigidDebris(namestream.str(),mass); RigDeb->GetRigidProxy()->SetCollisionShape(RobitCH); RigDeb->GetEntityProxy()->SetMesh(filerobot,groupname); RigDeb->SetLocation(Vector3( (-PinSpacing)+(c*PinSpacing), -30.0, -PinSpacing*2)); if (c+7==7) {Robot7=RigDeb;} if (c+7==8) {Robot8=RigDeb;} RigDeb->AddToWorld(); } std::stringstream namestream; //make the front pin namestream << robotprefix << 9; RigDeb = DebrisMan->CreateRigidDebris(namestream.str(),mass); RigDeb->GetRigidProxy()->SetCollisionShape(RobitCH); RigDeb->GetEntityProxy()->SetMesh(filerobot,groupname); RigDeb->SetLocation(Vector3( (-0.5*PinSpacing), 0.0, -PinSpacing*3)); RigDeb->AddToWorld(); object5 = DebrisMan->CreateRigidDebris("Plane",0); object5->GetRigidProxy()->SetCollisionShape(PlaneStatic); object5->GetEntityProxy()->SetMesh("Plane.mesh",groupname); object5->SetLocation(Vector3(0.0,-100,-300.0)); object5->AddToWorld(); object6 = DebrisMan->CreateRigidDebris("Ramp",0); object6->GetRigidProxy()->SetCollisionShape(PlaneStatic); object6->GetEntityProxy()->SetMesh("Plane.mesh",groupname); object6->SetLocation(Vector3(00.0,300.0,-1100.0)); object6->SetOrientation(Quaternion(0.5, 0.0, 0.0, -0.25)); object6->AddToWorld(); object1 = DebrisMan->CreateRigidDebris("RobotWayUpFrontRight",mass); object1->GetRigidProxy()->SetCollisionShape(RobitCH); object1->GetEntityProxy()->SetMesh(filerobot,groupname); object1->SetLocation(Vector3(400,70,100)); object1->SetOrientation(Quaternion(0.5, 0.5, 0.0, 0.9)); object1->AddToWorld(); object2 = DebrisMan->CreateRigidDebris("WoodSphere",150.0); object2->GetRigidProxy()->SetCollisionShape(WoodenSphere); object2->GetEntityProxy()->SetMesh("Sphere_Wood.mesh",groupname); object2->SetScale(Vector3(0.5,0.5,0.5)); object2->SetLocation(Vector3(-140.0,2800.0,-1150.0)); object2->AddToWorld(); object3 = DebrisMan->CreateRigidDebris("MetalSphere",200.0); object3->GetRigidProxy()->SetCollisionShape(MetalSphere); object3->GetEntityProxy()->SetMesh("Sphere_Metal.mesh",groupname); object3->SetScale(Vector3(0.7,0.7,0.7)); object3->SetLocation(Vector3(150.0,1800.0,-1300.0)); object3->AddToWorld(); object4 = DebrisMan->CreateRigidDebris("RobotWayUpFrontLeft",mass); object4->GetRigidProxy()->SetCollisionShape(RobitCH); object4->GetEntityProxy()->SetMesh(filerobot,groupname); object4->SetLocation(Vector3(-400,10, 100)); object4->SetOrientation(Quaternion(0.5, 0.5, 0.0, 0.9)); object4->AddToWorld(); object7 = DebrisMan->CreateRigidDebris("MetalSphere2",800.0); object7->GetRigidProxy()->SetCollisionShape(MetalSphere2); object7->GetEntityProxy()->SetMesh("Sphere_Metal.mesh",groupname); object7->SetScale(Vector3(0.3,0.3,0.3)); object7->SetLocation(Vector3(10.0,25000.0,-1300.0)); object7->GetRigidProxy()->SetDamping(0.3,0.0); object7->AddToWorld(); //GravityField /*GravityField* Reverse = new GravityField(String("UpField"), Vector3(0.0,-100.0,0.0)); Reverse->CreateCylinderShapeY(Vector3(100.0,200.0,100)); Reverse->SetLocation(Vector3(200,50,-5.0)); PhysMan->AddAreaEffect(Reverse); // Now that we have passed it, we can forget about it*/ //GravityWell /*GravityWell* BlackHole = new GravityWell("BlackHole", Vector3(0.0,200.0,-300.0)); BlackHole->GetPhysicsSettings()->SetCollisionShape(new Physics::SphereCollisionShape("GravWellShape",750.0)); BlackHole->SetAllowWorldGravity(false); BlackHole->SetFieldStrength(1000.0); BlackHole->SetAttenuation(3.000,Mezzanine::Att_Linear); //BlackHole->GetGraphicsSettings()->SetMesh(MeshManager::GetSingletonPtr()->CreateSphereMesh("GravWellMesh",ColourValue(0.8,0.1,0.1,0.15),750.0)); PhysMan->AddAreaEffect(BlackHole);// */ Physics::RigidProxy* InvisFloor = PhysMan->CreateRigidProxy(0,NULL); InvisFloor->SetCollisionShape( new Physics::PlaneCollisionShape("InvisFloor",Plane(Vector3::Unit_Y(),Vector3(0,-300,0))) ); InvisFloor->AddToWorld(); //Final Steps Audio::iSound* Sound = NULL; Audio::AudioManager* AudioMan = static_cast<Audio::AudioManager*>( TheEntresol->GetManager(ManagerBase::MT_AudioManager) ); Sound = AudioMan->CreateDialogSound("welcomefun-1-edit.ogg", groupname); Announcer.push_back(Sound); Sound = AudioMan->CreateDialogSound("welcomefun-1-edit.ogg", groupname); Announcer.push_back(Sound); Sound = AudioMan->CreateMusicSound("cAudioTheme1.ogg", groupname); Soundtrack.push_back(Sound); Sound = AudioMan->CreateMusicSound("cAudioTheme2.ogg", groupname); Soundtrack.push_back(Sound); TheEntresol->_Log("Debris Count "); TheEntresol->_Log( DebrisMan->GetNumDebris() ); }
void DoWork(Threading::DefaultThreadSpecificStorage::Type& CurrentThreadStorage) { //User Input through a WorldQueryTool Input::InputManager* InputMan = Input::InputManager::GetSingletonPtr(); Input::Mouse* SysMouse = InputMan->GetSystemMouse(); Input::Keyboard* SysKeyboard = InputMan->GetSystemKeyboard(); Input::Controller* Controller1 = NULL; if( InputMan->GetNumControllers() > 0 ) Controller1 = InputMan->GetController(0); if( SysKeyboard->IsButtonPressed(Input::KEY_LEFT) || (Controller1 ? Controller1->IsHatPushedInDirection(1,Input::CONTROLLERHAT_LEFT) : false) ) { CamControl->StrafeLeft( 300 * ( TheEntresol->GetLastFrameTimeMilliseconds() * 0.001 ) ); } if( SysKeyboard->IsButtonPressed(Input::KEY_RIGHT) || (Controller1 ? Controller1->IsHatPushedInDirection(1,Input::CONTROLLERHAT_RIGHT) : false) ) { CamControl->StrafeRight( 300 * ( TheEntresol->GetLastFrameTimeMilliseconds() * 0.001 ) ); } if( SysKeyboard->IsButtonPressed(Input::KEY_UP) || (Controller1 ? Controller1->IsHatPushedInDirection(1,Input::CONTROLLERHAT_UP) : false) ) { CamControl->MoveForward( 300 * ( TheEntresol->GetLastFrameTimeMilliseconds() * 0.001 ) ); } if( SysKeyboard->IsButtonPressed(Input::KEY_DOWN) || (Controller1 ? Controller1->IsHatPushedInDirection(1,Input::CONTROLLERHAT_DOWN) : false) ) { CamControl->MoveBackward( 300 * ( TheEntresol->GetLastFrameTimeMilliseconds() * 0.001 ) ); } static bool MouseCam = false; if( SysKeyboard->IsButtonPressed(Input::KEY_HOME) ) { MouseCam = true; } if( SysKeyboard->IsButtonPressed(Input::KEY_END)) { MouseCam = false; } Physics::PhysicsManager* PhysMan = static_cast<Physics::PhysicsManager*>( this->OneWorld->GetManager(ManagerBase::MT_PhysicsManager) ); if( SysKeyboard->IsButtonPressed(Input::KEY_BACKSLASH) ) { PhysMan->SetTimeMultiplier(1.0); } if( SysKeyboard->IsButtonPressed(Input::KEY_RIGHTBRACKET) ) { Real Factor = PhysMan->GetTimeMultiplier() * 1.5; if( Factor > 2.0 ) { Factor = 2.0; } PhysMan->SetTimeMultiplier(Factor); } if( SysKeyboard->IsButtonPressed(Input::KEY_LEFTBRACKET) ) { Real Factor = PhysMan->GetTimeMultiplier() * .75; if( Factor < 0.01 ) { Factor = 0.01; } PhysMan->SetTimeMultiplier(Factor); } Vector2 Offset = SysMouse->GetMouseDelta(); if( MouseCam && Vector2(0,0) != Offset ) CamControl->Rotate(Offset.X * 0.01,Offset.Y * 0.01,0); if( SysKeyboard->IsButtonPressing(Input::KEY_M) || (Controller1 ? Controller1->IsButtonPressed(1) : false) ) { Audio::iSound* Theme = Soundtrack.at(1); if( !Theme->IsPlaying() ) { Theme->Play(); } } if( SysKeyboard->IsButtonPressing(Input::KEY_N) || (Controller1 ? Controller1->IsButtonPressed(2) : false) ) { Audio::iSound* Theme = Soundtrack.at(1); if( Theme->IsPlaying() ) { Theme->Stop(); } } // Audio test fun if( SysKeyboard->IsButtonPressing(Input::KEY_T) ) { static Boole Toggle = true; Audio::iSound* Welcome = ( Announcer.size() >= 2 ? ( Toggle ? Announcer[1] : Announcer[0] ) : NULL ); if( Welcome != NULL ) { if( Welcome->IsPlaying() ) { Welcome->Stop(); } Welcome->Play(); } Toggle = !Toggle; } // Make a declaration for a static constrain so it survives the function lifetime static Physics::Point2PointConstraint* Dragger = NULL; if( SysMouse->IsButtonPressed(1) ) { UI::UIManager* UIMan = UI::UIManager::GetSingletonPtr(); if( UIMan->MouseIsInUISystem() ) { //UI::Screen* DScreen = UIMan->GetScreen("DefaultScreen"); UI::Widget* Hover = UIMan->GetHoveredWidget(); if(Hover) { Hover = Hover->GetBottomMostHoveredWidget(); if( "D_Exit" == Hover->GetName() ) { TheEntresol->BreakMainLoop(); } } }else{ Ray MouseRay = RayQueryTool::GetMouseRay(); RayCaster.GetFirstObjectOnRayByPolygon(MouseRay,Mezzanine::WO_RigidDebris); bool firstframe=false; if( 0 == RayCaster.LastQueryResultsObjectPtr() ) { #ifdef MEZZDEBUG //TheEntresol->Log("No Object Clicked on"); #endif }else{ #ifdef MEZZDEBUG //TheEntresol->Log("Object Clicked on"); TheEntresol->Log(*ClickOnActor); //TheEntresol->Log("MouseRay"); TheEntresol->Log(*MouseRay); //TheEntresol->Log("PlaneOfPlay"); TheEntresol->Log(PlaneOfPlay); //TheEntresol->Log("ClickOnActor"); TheEntresol->Log(*ClickOnActor); #endif if( !( RayCaster.LastQueryResultsObjectPtr()->IsStatic() ) ) { if(!Dragger) { //If we have a dragger, then this is dragging, not clicking if(RayCaster.LastQueryResultsObjectPtr()->GetType() == Mezzanine::WO_RigidDebris) { //This is Dragging let's do some checks for sanity Vector3 LocalPivot = RayCaster.LastQueryResultsOffset(); RigidDebris* rigid = static_cast<RigidDebris*>(RayCaster.LastQueryResultsObjectPtr()); rigid->GetRigidProxy()->SetActivationState(Physics::AS_DisableDeactivation); //Dragger = new Generic6DofConstraint(rigid, LocalPivot, Quaternion(0,0,0,1), false); Dragger = PhysMan->CreatePoint2PointConstraint(rigid->GetRigidProxy(),LocalPivot); Dragger->SetTAU(0.001); Dragger->EnableConstraint(true); Dragger->SetParam(Physics::Con_Stop_CFM,0.8,-1); Dragger->SetParam(Physics::Con_Stop_CFM,0.8,-1); Dragger->SetParam(Physics::Con_Stop_CFM,0.8,-1); Dragger->SetParam(Physics::Con_Stop_ERP,0.1,-1); Dragger->SetParam(Physics::Con_Stop_ERP,0.1,-1); Dragger->SetParam(Physics::Con_Stop_ERP,0.1,-1); firstframe=true; }else{ // since we don't #ifdef MEZZDEBUG //TheEntresol->Log("Object is not an ActorRigid. Aborting."); #endif } } }else{ #ifdef MEZZDEBUG //TheEntresol->Log("Object is Static/Kinematic. Aborting."); #endif } } // This chunk of code calculates the 3d point that the actor needs to be dragged to if( RayCaster.RayPlaneIntersection(MouseRay, PlaneOfPlay) ) { if(Dragger&&!firstframe) { Dragger->SetPivotB(RayCaster.LastQueryResultsOffset()); } } } }else{ //Since we are no longer clicking we need to setup for the next clicking if( Dragger ) { Physics::RigidProxy* Prox = Dragger->GetProxyA(); PhysMan->DestroyConstraint(Dragger); Dragger = NULL; Prox->SetActivationState(Physics::AS_Active); } } }