void Box2dJointComponent::OnInitialise() { b2RevoluteJointDef& jointDef = static_cast<b2RevoluteJointDef&>(*mJointDef); std::shared_ptr<k::SceneNode> bodyANode = GetSceneNode().GetRootParent()->FindFirstInChildrenRecursive(mBodyA.c_str()); kassert(&*bodyANode); jointDef.bodyA = &bodyANode->GetSceneObject().GetComponent<Box2dBodyComponent>("Box2dBodyComponent")->GetBody(); std::shared_ptr<k::SceneNode> bodyBNode = GetSceneNode().GetRootParent()->FindFirstInChildrenRecursive(mBodyB.c_str()); kassert(&*bodyBNode); jointDef.bodyB = &bodyBNode->GetSceneObject().GetComponent<Box2dBodyComponent>("Box2dBodyComponent")->GetBody(); mJoint = mWorldComponent.lock()->GetWorld().CreateJoint(&jointDef); mJointDef = nullptr; }
void BaseRenderComponent::PostInit() { shared_ptr<SceneNode> pSceneNode(GetSceneNode()); // fire event that a new render component has been created shared_ptr<Event_NewRenderComponent> pEvent(CB_NEW Event_NewRenderComponent(m_pOwner->GetId(), pSceneNode)); IEventManager::Get()->TriggerEvent(pEvent); }
void plWinAudible::SetSceneNode(plKey newNode) { plKey oldNode = GetSceneNode(); if( oldNode == newNode ) return; if( !oldNode ) Activate(); if( newNode ) { plNodeRefMsg* refMsg = new plNodeRefMsg(newNode, plNodeRefMsg::kOnRequest, -1, plNodeRefMsg::kAudible); hsgResMgr::ResMgr()->AddViaNotify(GetKey(), refMsg, plRefFlags::kPassiveRef); } if( oldNode ) { oldNode->Release(GetKey()); } if( !newNode ) { DeActivate(); } fSceneNode = newNode; }
Box2dJointComponent::Box2dJointComponent(k::ViewSceneComponentInitialiseData& data) : k::SceneComponent(data.mSceneNode, data.mStartActive) , mJoint(nullptr) , mWorldComponent(data.mSceneNode.lock()->GetRootParent()->GetSceneObject().GetComponentOrFirstInChildren<Box2dWorldComponent>("Box2dWorldComponent")) { const gmtl::Vec3f& trans = GetSceneNode().GetTransform().GetWorldPosition(); const char* jointType = data.mAttributeHandler.GetString(data.mXmlNode.attribute("type")); if (strcmp(jointType, "revolute") == 0) { mJointDef = std::shared_ptr<b2RevoluteJointDef>(new b2RevoluteJointDef); b2RevoluteJointDef& jointDef = static_cast<b2RevoluteJointDef&>(*mJointDef); float localAnchorAX = data.mAttributeHandler.GetFloat(data.mXmlNode.attribute("localAnchorAX")) + trans[0]; float localAnchorAY = data.mAttributeHandler.GetFloat(data.mXmlNode.attribute("localAnchorAY")) + trans[1]; float localAnchorBX = data.mAttributeHandler.GetFloat(data.mXmlNode.attribute("localAnchorBX")) + trans[0]; float localAnchorBY = data.mAttributeHandler.GetFloat(data.mXmlNode.attribute("localAnchorBY")) + trans[1]; jointDef.localAnchorA = b2Vec2(localAnchorAX, localAnchorAY); jointDef.localAnchorB = b2Vec2(localAnchorBX, localAnchorBY); jointDef.enableMotor = data.mAttributeHandler.GetBool(data.mXmlNode.attribute("enableMotor")); jointDef.maxMotorTorque = data.mAttributeHandler.GetFloat(data.mXmlNode.attribute("maxMotorTorque")); jointDef.enableLimit = data.mAttributeHandler.GetBool(data.mXmlNode.attribute("enableLimit")); jointDef.motorSpeed = data.mAttributeHandler.GetFloat(data.mXmlNode.attribute("motorSpeed")); jointDef.lowerAngle = data.mAttributeHandler.GetFloat(data.mXmlNode.attribute("lowerAngle")) * b2_pi / 180.0f; jointDef.upperAngle = data.mAttributeHandler.GetFloat(data.mXmlNode.attribute("upperAngle")) * b2_pi / 180.0f; mBodyA = data.mAttributeHandler.GetString(data.mXmlNode.attribute("bodyA")); mBodyB = data.mAttributeHandler.GetString(data.mXmlNode.attribute("bodyB")); } else kassert(false); }
Ogre::Light* LuaScriptUtilities::GetLight( lua_State* const luaVM, const int stackIndex) { Ogre::SceneNode* const node = GetSceneNode(luaVM, stackIndex); if (node) { Ogre::SceneNode::ObjectIterator it = node->getAttachedObjectIterator(); while (it.hasMoreElements()) { const Ogre::String movableType = it.current()->second->getMovableType(); if (movableType == Ogre::LightFactory::FACTORY_TYPE_NAME) { return static_cast<Ogre::Light*>(it.current()->second); } it.getNext(); } } return NULL; }
bool Scene::RemoveChild(unsigned int ActorID) { std::shared_ptr<ISceneNode> kid = GetSceneNode(ActorID); // Check if it is any of the different node types (like light) and act accordingly) std::shared_ptr<LightNode> pLight = std::dynamic_pointer_cast<LightNode>(kid); if (pLight) { // child is a LightNode; also remove reference to the LightManager GetLightManager()->RemoveLight(pLight); } // Otherwise, erase as normal m_ActorMap.erase(ActorID); return m_Root->RemoveChild(ActorID); }
void Block::Update() { OnFloor::Update(); Matrix mat = m_lastFloorRotation; mat.TranslateKeepRotation(m_pos); GetSceneNode()->SetLocalTransform(mat); // TODO As crates can rotate, recalc OBB and AABB ? // This kind of works but errors accumulate. Reset box coords each time. // Vec3f dPos = m_pos - GetOldPos(); // m_pSceneNode->GetAABB()->Translate(dPos); // ? }
void AnchorComponent::Advance(float32 distance) { m_totalDistance += distance; // For now, just move along Z axis auto& mLocal = GetSceneNode()->ModifyLocalToParent(); mLocal.trans += mLocal.axisZ * distance; //TWEAKABLE float32 speed = 0.005f; //TWEAKABLE float32 amplitude = 100.f; //const float32 lastS = MathEx::Sin(speed * (m_totalDistance - distance)); //const float32 currS = MathEx::Sin(speed * m_totalDistance); //const float32 delta = (lastS - currS) * amplitude; //mLocal.trans += mLocal.axisX * delta; }
/** * @brief * Called when the scene node assigned with this visibility container was destroyed */ void VisContainer::OnDestroy() { SceneNode *pSceneNode = GetSceneNode(); if (pSceneNode && pSceneNode->IsContainer()) { // Get the parent visibility container const VisNode *pParent = GetParent(); if (pParent && pParent->IsContainer()) { VisContainer *pParentVisContainer = const_cast<VisContainer*>(static_cast<const VisContainer*>(pParent)); // Unregister within the parent container VisContainer *pContainer = pParentVisContainer->m_mapContainers.Get(pSceneNode->GetName()); if (pContainer) { pParentVisContainer->m_lstNodes.Remove(pContainer); delete pContainer; pParentVisContainer->m_mapContainers.Remove(pSceneNode->GetName()); } } } }
bool Dino::CreateSceneNode() { if (!Npc::CreateSceneNode()) { return false; } BlinkCharacter* bc = dynamic_cast<BlinkCharacter*>(GetSceneNode()); Assert(bc); Md2Model* md2 = bc->GetMd2(); Md2Model::Animation anim = md2->GetAnimationFromName("stunned"); if (anim != -1) { md2->SetDoesFreeze(anim, true); } anim = md2->GetAnimationFromName("eat"); if (anim != -1) { md2->SetDoesFreeze(anim, true); } return true; }
void Dino::Eat(OnFloorCharacter* pet) { Assert(!IsEating()); Assert(!IsDead()); Assert(!pet->IsDead()); Assert(pet->CanBeEaten()); SetAnim("eat"); // Change to eating behaviour SetAI(AITurnToFace::NAME); m_ai->SetTarget(pet); m_ais[AIEatPet::NAME]->SetTarget(pet); // Change texture to bloody version. BlinkCharacter* bc = dynamic_cast<BlinkCharacter*>(GetSceneNode()); Assert(bc); bc->LoadTextures(m_bloodTex[0], m_bloodTex[1]); // TODO Load the textures up front as this will hit frame rate on first load. pet->StartBeingEaten(this); // Pause action and zoom camera on Dino?? }