//---------------------------------------------------------------------------- void Actor::SetScene (Scene *scene) { if (mScene == scene) return; if (scene) { Node *sceneNode = scene->GetSceneNode(); if (sceneNode) { double appTime = GetTimeInSeconds(); if (mMovable) { sceneNode->AttachChild(mMovable); //mMovable->Update(appTime); } if (mHelpMovable) { sceneNode->AttachChild(mHelpMovable); //mHelpMovable->Update(appTime); } } } else { if (mScene) { Node *sceneNode = mScene->GetSceneNode(); if (sceneNode) { if (mMovable) { sceneNode->DetachChild(mMovable); } if (mHelpMovable) { sceneNode->DetachChild(mHelpMovable); } } } } mScene = scene; }
//---------------------------------------------------------------------------- bool EditMap::RemoveUI (PX2::Object *obj) { if (!Project::GetSingletonPtr()) return false; if (obj == Project::GetSingleton().GetUI()) return false; Movable *mov = DynamicCast<Movable>(obj); if (!mov) return false; UIFrame *frame = DynamicCast<UIFrame>(obj); UIPicBox *pixBox = DynamicCast<UIPicBox>(obj); UIStaticText *staticText = DynamicCast<UIStaticText>(obj); Node *parent = DynamicCast<Node>(mov->GetParent()); if (parent) { parent->DetachChild(mov); Event *event = 0; event = EditorEventSpace::CreateEventX (EditorEventSpace::RemoveUI); event->SetData<Object*>(obj); EventWorld::GetSingleton().BroadcastingLocalEvent(event); return true; } return false; }
//---------------------------------------------------------------------------- Node* Game::LoadAndInitializeScene() { Importer importer("Data/Scene/"); Node* pScene = importer.LoadSceneFromXml("Scene.xml", mspPhysicsWorld); if (!pScene) { return NULL; } NodeCamera* pCameraNode = pScene->FindChild<NodeCamera>(); WIRE_ASSERT(pCameraNode /* No Camera in scene.xml */); mspSceneCamera = pCameraNode->Get(); mSortingCuller.SetCamera(mspSceneCamera); // The maximum number of objects that are going to be culled is the // number of objects we imported. If we don't set the size of the set now, // the culler will dynamically increase it during runtime. This is not // a big deal, however it is better to avoid memory allocations during the // render loop. UInt renderObjectCount = importer.GetStatistics()->RenderObjectCount; mSortingCuller.SetMaxQuantity(renderObjectCount); // Create and configure probe robot controller SpatialPtr spRedHealthBar = mspGUI->FindChild("RedHealthBar"); WIRE_ASSERT(spRedHealthBar /* No RedHealthBar in GUI.xml */); Node* pProbeRobotSpatial = DynamicCast<Node>(pScene->FindChild("Probe Robot")); WIRE_ASSERT(pProbeRobotSpatial /* No Probe Robot in Scene.xml */); // Detach red energy/health bar and attach it robot probe as a billboard NodeBillboard* pBillboard = WIRE_NEW NodeBillboard; pProbeRobotSpatial->AttachChild(pBillboard); Node* pParent = DynamicCast<Node>(spRedHealthBar->GetParent()); WIRE_ASSERT(pParent); pParent->DetachChild(spRedHealthBar); pBillboard->AttachChild(spRedHealthBar); Spatial* pPlayerSpatial = pScene->FindChild("Player"); WIRE_ASSERT(pPlayerSpatial /* No Player in Scene.xml */); mspProbeRobot = WIRE_NEW ProbeRobot(mspPhysicsWorld, pPlayerSpatial, spRedHealthBar); pProbeRobotSpatial->AttachController(mspProbeRobot); // Create and configure player controller mspPlayer = WIRE_NEW Player(mspSceneCamera, mspPhysicsWorld); pPlayerSpatial->AttachController(mspPlayer); Spatial* pPlatform = pScene->FindChild("Platform"); WIRE_ASSERT(pPlatform /* Platform object missing in scene */); pPlatform->AttachController(WIRE_NEW Elevator(mspPhysicsWorld)); pScene->Bind(GetRenderer()); pScene->WarmUpRendering(GetRenderer()); return pScene; }
//---------------------------------------------------------------------------- void ModelController::SetMovable(Movable *mov) { Node *node = DynamicCast<Node>(GetControlledable()); if (mMovable && node) node->DetachChild(mMovable); mMovable = mov; if (mMovable && node) node->AttachChild(mMovable); CollectAnchors(); mov->SetSaveWriteIngore(false); }
//---------------------------------------------------------------------------- void Character::PlayAnim(Animation *anim) { if (!HasAnim(anim)) return; bool sameAnim = false; if (mCurPlayingAnim == anim) sameAnim = true; if (mCurPlayingAnim) mCurPlayingAnim->Stop(); Node *charNode = DynamicCast<Node>(GetMovable()); if (mCurPlayingAnim && charNode) { Animation3DSkeleton *anim3dSk = DynamicCast<Animation3DSkeleton>(mCurPlayingAnim); if (anim3dSk) { Node *animNode = anim3dSk->GetAnimNode(); charNode->DetachChild(animNode); } if (!sameAnim) { mLastAnimObj = new0 AnimationObject(); mLastAnimObj->TheAnim = mCurPlayingAnim; mLastAnimObj->BlendTime = 0.0f; mLastAnimObj->TheCharacter = this; } else { mLastAnimObj = 0; } } mCurPlayingAnim = anim; if (mCurPlayingAnim) mCurPlayingAnim->OnPlay(this); }