//---------------------------------------------------------------------------- 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 BipedManager::DoAnimation(NodeCtrlArray& ncArray) { for (auto& nc : ncArray) { Node* node = nc.first; TransformController* ctrl = nc.second.get(); ctrl->repeat = Controller::RT_WRAP; node->DetachAllControllers(); node->AttachController(ctrl); } }
//---------------------------------------------------------------------------- void Character::_CalAnimNode(Movable *mov) { const std::string &movName = mov->GetName(); Node *node = DynamicCast<Node>(mov); if (node) { BlendTransformController *btc = DynamicCast<BlendTransformController>( node->GetControllerByName("BTC")); if (!btc) { btc = new0 BlendTransformController(0, 0, true); node->AttachController(btc); btc->SetName("BTC"); } mBTCMap[movName.c_str()] = btc; for (int i = 0; i < node->GetNumChildren(); i++) { _CalAnimNode(node->GetChild(i)); } } }
//---------------------------------------------------------------------------- Node* SkinnedBiped::GetNode (const std::string& name) { Node* node = new0 Node(); node->SetName(name); // Load the keyframe controller. std::string filename = name + ".keyf.raw"; std::string path = Environment::GetPathR(filename); FileIO inFile(path, FileIO::FM_DEFAULT_READ); int repeat; float minTime, maxTime, phase, frequency; inFile.Read(sizeof(float), &repeat); inFile.Read(sizeof(float), &minTime); inFile.Read(sizeof(float), &maxTime); inFile.Read(sizeof(float), &phase); inFile.Read(sizeof(float), &frequency); int numTranslations, numRotations, numScales; inFile.Read(sizeof(int), &numTranslations); inFile.Read(sizeof(int), &numRotations); inFile.Read(sizeof(int), &numScales); KeyframeController* ctrl = new0 KeyframeController(0, numTranslations, numRotations, numScales, Transform::IDENTITY); ctrl->Repeat = (Controller::RepeatType)repeat; ctrl->MinTime = (double)minTime; ctrl->MaxTime = (double)maxTime; ctrl->Phase = (double)phase; ctrl->Frequency = (double)frequency; if (numTranslations > 0) { float* translationTimes = ctrl->GetTranslationTimes(); APoint* translations = ctrl->GetTranslations(); inFile.Read(sizeof(float), numTranslations, translationTimes); for (int i = 0; i < numTranslations; ++i) { inFile.Read(sizeof(float), 3, &translations[i]); translations[i][3] = 1.0f; } } else { APoint translate; inFile.Read(sizeof(float), 3, &translate); node->LocalTransform.SetTranslate(translate); } if (numRotations > 0) { float* rotationTimes = ctrl->GetRotationTimes(); HQuaternion* rotations = ctrl->GetRotations(); inFile.Read(sizeof(float), numRotations, rotationTimes); inFile.Read(sizeof(float), 4*numRotations, rotations); } else { float entry[9]; inFile.Read(sizeof(float), 9, entry); HMatrix rotate( entry[0], entry[1], entry[2], 0.0f, entry[3], entry[4], entry[5], 0.0f, entry[6], entry[7], entry[8], 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); node->LocalTransform.SetRotate(rotate); } if (numScales > 0) { float* scaleTimes = ctrl->GetScaleTimes(); float* scales = ctrl->GetScales(); inFile.Read(sizeof(float), numScales, scaleTimes); inFile.Read(sizeof(float), numScales, scales); } else { float scale; inFile.Read(sizeof(float), &scale); node->LocalTransform.SetUniformScale(scale); } ctrl->SetTransform(node->LocalTransform); inFile.Close(); node->AttachController(ctrl); return node; }