void InputListener::updateWater(const Ogre::FrameEvent& evt)
{
  float WaterFlow = FLOW_SPEED * evt.timeSinceLastFrame;
  static float FlowAmount = 0.0f;
  static bool FlowUp = true;
  Ogre::SceneNode *pWaterNode = static_cast<Ogre::SceneNode*>(this->_currentScene->getCamera()->getSceneManager()->getRootSceneNode()->getChild("WaterNode"));
  if (FlowUp)
    FlowAmount += WaterFlow;
  else
    FlowAmount -= WaterFlow;
  if (FlowAmount >= this->_currentScene->getWorld()->getWaterLevel() + FLOW_HEIGHT)
    FlowUp = false;
  else if (FlowAmount <=this->_currentScene->getWorld()->getWaterLevel())
    FlowUp = true;
  pWaterNode->translate(0, (FlowUp ? WaterFlow : -WaterFlow), 0);
  if (this->_Game->getGameType() == Game::GameType::SUDDEN_DEATH)
    this->_currentScene->getWorld()->riseWater();
  this->_Game->killWormsUnderWater(pWaterNode);
}
Example #2
0
//-------------------------------------------------------------------------------------
bool
PlayersManager::hidle(zappy::Player *p, int i)
{
  OPlayer *OPlayer = this->mOPlayers.at(i);

  if (OPlayer->stateHasChanged())
    OPlayer->detachAnim();
  Ogre::Vector3 position(p->getX() * Constants::SquareSize, 0, p->getY() * Constants::SquareSize);
  Ogre::AnimationState *anim = OPlayer->getEntity()->
    getAnimationState("Idle");
  Ogre::SceneNode *node = OPlayer->getSceneNode();
  anim->setEnabled(true);
  if (position != node->getPosition())
      node->setPosition(position);
  anim->setLoop(true);
  anim->setEnabled(true);
  anim->addTime(this->tslf);
  return true;
}
Example #3
0
void OgreApplication::addActor(std::shared_ptr<OgreActor> actor)
{

    try {
        Ogre::Entity* ent;
        ent = mSceneMgr->createEntity(actor->entName(), actor->meshName());
        ent->setCastShadows(actor->castShadows());

        Ogre::SceneNode *node;
        node = mSceneMgr->getRootSceneNode()->createChildSceneNode(actor->nodeName());
        node->setPosition(toOgreVector3(actor->position()));
        node->setOrientation(toOgreQuaternion(actor->orientation()));
        node->scale(actor->scale().x(),actor->scale().y(), actor->scale().z());
        node->attachObject(ent);
    }
    catch (Ogre::ItemIdentityException e){
        std::cerr << "OgreApplication::addActor, warning: Node " << actor->nodeName() << " already exists. Actor was not added." << std::endl;
    }
}
Example #4
0
void Laser::Initialize(Ogre::SceneManager *sceneManager, Ogre::SceneNode* parentNode, PhysicsEngine &physicsEngine, unsigned int parentID)
{
	PhysicsEntity::Initialize(sceneManager, parentNode, physicsEngine, parentID);

	//setting our mass to 0
	bodyType = ENTITY_BODY_METAPHYSICAL;
	dynamic = false;
	mass = 0.0f;

	Ogre::Entity *laserEntity = sceneManager->createEntity("Cylinder");
	laserEntity->setMaterialName("LaserMaterial");
	Ogre::SceneNode *laserSceneNode = sceneNode->createChildSceneNode("Laser" + Ogre::StringConverter::toString(entityCount));
	laserSceneNode->attachObject(laserEntity);
	laserSceneNode->scale(0.3f, 1000.0f, 0.3f);
	laserSceneNode->pitch(Ogre::Radian(-Ogre::Math::HALF_PI));
	laserSceneNode->translate(0,0,-500.0f);

	sceneNode->setVisible(false);
}
void NavigationMesh::setShow( bool show )
{
    Ogre::Root *root = Ogre::Root::getSingletonPtr();
    Ogre::SceneManager* mgr = root->getSceneManager( "SceneManagerInstance" );
    Ogre::ManualObject* debug;
    Ogre::SceneNode* debugNode;

    mShow = show;

    if( mgr->hasSceneNode( "debugDrawNode2" ) )
    {
        debugNode = mgr->getSceneNode( "debugDrawNode2" );
    }
    else
    {
        debugNode = mgr->getRootSceneNode()->createChildSceneNode( "debugDrawNode2" );
        debugNode->translate( 0, 1, 0 );    // Move up slightly to see lines better.
    }

    if( mgr->hasManualObject( "debugDraw2" ) )
        debug = mgr->getManualObject( "debugDraw2" );
    else
    {
        debug = mgr->createManualObject( "debugDraw2" );
        debugNode->attachObject( debug );
        debug->setQueryFlags( 0 );
        debug->setRenderQueueGroup( Ogre::RENDER_QUEUE_OVERLAY );
    }

    if( !mShow )
    {
        mgr->destroyManualObject( debug );
        return;
    }

    for( CellVector::iterator i = mCells.begin(); i != mCells.end(); i++ )
    {
        i->debugDrawCell( debug, "debug/yellow", "debug/blue" );
    }

    return;
}
Example #6
0
void EC_Mesh::RemoveAttachmentMesh(uint index)
{
    if (renderer_.expired())
        return;
    RendererPtr renderer = renderer_.lock();   
        
    if (!entity_)
        return;
        
    if (index >= attachment_entities_.size())
        return;
    
    Ogre::SceneManager* scene_mgr = renderer->GetSceneManager();
    
    if (attachment_entities_[index] && attachment_nodes_[index])
    {
        // See if attached to a tagpoint or an ordinary node
        Ogre::TagPoint* tag = dynamic_cast<Ogre::TagPoint*>(attachment_nodes_[index]);
        if (tag)
        {
            entity_->detachObjectFromBone(attachment_entities_[index]);
        }
        else
        {
            Ogre::SceneNode* scenenode = dynamic_cast<Ogre::SceneNode*>(attachment_nodes_[index]);
            if (scenenode)
            {
                scenenode->detachObject(attachment_entities_[index]);
                scene_mgr->destroySceneNode(scenenode);
            }
        }
        
        attachment_nodes_[index] = 0;
    }
    if (attachment_entities_[index])
    {
        if (attachment_entities_[index]->sharesSkeletonInstance())
            attachment_entities_[index]->stopSharingSkeletonInstance();
        scene_mgr->destroyEntity(attachment_entities_[index]);
        attachment_entities_[index] = 0;
    }
}
// Manage physics from this loop
// Please don't alter the Ogre scene manager directly. Instead use the designated methods (setPositionX, setPositionY, setPositionZ, setRoll, setPitch, setYaw, animate)
void loop(Ogre::SceneManager* smgr){
	int dir = 1;
	int timeStep = 10;
	while(true){
		// If the message array has any elements, the render loop is applying changes from physics loop
		// If so, abort this timestep
		if((*::message).size() == 1){
			continue;
		}
		Sleep(timeStep);
		Ogre::SceneManager::MovableObjectIterator iterator = smgr->getMovableObjectIterator("Entity");
		while(iterator.hasMoreElements()){
			// If the message array has any elements, the render loop is applying changes from physics loop
			// If so, abort this timestep
			if((*::message).size() == 1){
				continue;
			}
			Ogre::Entity* entity = static_cast<Ogre::Entity*>(iterator.getNext());

			// <>< <>< Make the cute fishy swim <>< <><
			// This only moves fish
			if(entity->hasAnimationState("swim")){
			
				Ogre::SceneNode* sceneNode = entity->getParentSceneNode();

				// Update position
				Ogre::Vector3 pos = sceneNode->getPosition();
				if(pos.x > 120){
					dir = -1;
					setYaw(entity, 180);
				}
				if(pos.x < -120){
					dir = 1;
					setYaw(entity, 180);
				}
				setPositionX(entity, sceneNode->getPosition().x + dir);
				animate(entity, "swim");
			}

		}
	}
}
Example #8
0
OGRERendererRacer::OGRERendererRacer(Ogre::SceneManager* a_sceneMgr, Application* app, std::string aname) {

    name = aname;

    mpApp = app;

    mSceneManager = a_sceneMgr;
    //mpVehicle = app->mLocalPlayerRacer;

    mRollAngle = 0;
    mPitchAngle = 0;

    mOrientation.FromAngleAxis(Ogre::Radian(0), Ogre::Vector3(1, 0, 0));

    mVehicleNode = mSceneManager->getRootSceneNode()->createChildSceneNode();

    mVehicleMeshNode = mVehicleNode->createChildSceneNode();
    //mVehicleMeshNode->setScale(0.05,0.05,0.05);

    //Ogre::Entity* entVehicle = mSceneManager->getEntity("Vehicle");
    // Racer model:
    mMeshEntity = mSceneManager->createEntity("Vehicle.mesh");

    mVehicleMeshNode->attachObject(mMeshEntity);

    // TODO 1: Reimplement

    // Set up engine flame particle system:

    mEngineFlameParticleSystem = mSceneManager->createParticleSystem(name + "_flame", "SpaceRoads/EngineFlame");

    Ogre::SceneNode* particleNode = mVehicleMeshNode->createChildSceneNode();
    particleNode->setPosition(0, -1.5, 3);
    particleNode->attachObject((Ogre::ParticleSystem*) mEngineFlameParticleSystem);

    // Set up engine flame particle system:
    mEngineSmokeParticleSystem = mSceneManager->createParticleSystem(name + "_smoke", "SpaceRoads/EngineSmoke");
    particleNode = mVehicleMeshNode->createChildSceneNode();
    particleNode->setPosition(0, -1.5, 3);
    particleNode->attachObject((Ogre::ParticleSystem*) mEngineSmokeParticleSystem);

}
  void createScene()
  {
    // Create the Entity
    Ogre::Entity* robot = mSceneMgr->createEntity("Robot", "robot.mesh");
    // Attach robot to scene graph
    Ogre::SceneNode* RobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Robot");
    //RobotNode->setPosition((Ogre::Real)-0.3, (Ogre::Real)0.2, (Ogre::Real)0);
    RobotNode->attachObject(robot);
    RobotNode->scale((Ogre::Real)0.001,(Ogre::Real)0.001,(Ogre::Real)0.001);
    RobotNode->pitch(Ogre::Degree(180));
    RobotNode->yaw(Ogre::Degree(-90));

    // The animation
    // Set the good animation
    mAnimationState = robot->getAnimationState( "Idle" );
    // Start over when finished
    mAnimationState->setLoop( true );
    // Animation enabled
    mAnimationState->setEnabled( true );
  }
Example #10
0
//-------------------------------------------------------------------------------------
void ProjectO3d::createScene(void)
{
    // create your scene here :)
	 // Set the scene's ambient light
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
 
    // Create an Entity
    Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
 
    // Create a SceneNode and attach the Entity to it
    Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HeadNode");
    headNode->attachObject(ogreHead);
 
    // Create a Light and set its position
    Ogre::Light* light = mSceneMgr->createLight("MainLight");
    light->setPosition(20.0f, 80.0f, 50.0f);

	 // here we will load a forsaken model when the loader is finished
	 //MXloader* mxl = new MXloader("titan.mx");
}
Example #11
0
	/**
	 * @brief Dtor.
	 */
	~EntityPointMarker()
	{
		if (mMarkerEntity) {
			mMarkerEntity->_getManager()->destroyEntity(mMarkerEntity);
		}
		if (mMarkerNode) {
			mMarkerNode->getCreator()->destroySceneNode(mMarkerNode);
		}

		delete mMarkerDirectionIndicator;
	}
Example #12
0
void Replicator::createChildren(int value)
{
	Ogre::Entity *childEnt = _sceneManager->createEntity(_meshType);
	Ogre::SceneNode* childNode = _node->createChildSceneNode();	
	if ( _materialName != "" ) {
		childEnt->setMaterialName(_materialName);
	}
	childNode->attachObject(childEnt);
	
	Ogre::Real childMinSize = getScale().x * 5;
	Ogre::Real childMaxSize = getScale().x * 10;
	Ogre::Real size = Ogre::Math::RangeRandom(childMinSize, childMaxSize);

	childNode->setScale(size + (value / 1.5), size + (value / 1.5), size + (value / 1.5));
	Ogre::Real x = Ogre::Math::RangeRandom(-300,300);
	Ogre::Real z = Ogre::Math::RangeRandom(-300,300);
	Ogre::Real y = Ogre::Math::RangeRandom(-300,300);
	childNode->setPosition(x, y, z);
	children.push_back(childEnt);
}
Example #13
0
float3x4 EC_Mesh::LocalToWorld() const
{
    if (!entity_)
    {
        LogError(QString("EC_Mesh::LocalToWorld failed! No entity exists in mesh \"%1\" (entity: \"%2\")!").arg(meshRef.Get().ref).arg(ParentEntity() ? ParentEntity()->Name() : "(EC_Mesh with no parent entity)"));
        return float3x4::identity;
    }

    Ogre::SceneNode *node = entity_->getParentSceneNode();
    if (!node)
    {
        LogError(QString("EC_Mesh::LocalToWorld failed! Ogre::Entity is not attached to a Ogre::SceneNode! Mesh \"%1\" (entity: \"%2\")!").arg(meshRef.Get().ref).arg(ParentEntity() ? ParentEntity()->Name() : "(EC_Mesh with no parent entity)"));
        return float3x4::identity;
    }

    assume(!float3(node->_getDerivedScale()).IsZero());
    float3x4 tm = float3x4::FromTRS(node->_getDerivedPosition(), node->_getDerivedOrientation(), node->_getDerivedScale());
    assume(tm.IsColOrthogonal());
    return tm;
}
Example #14
0
void OgreApplication::updateNodes(std::list<std::shared_ptr<OgreActor> > newActors, std::list<std::shared_ptr<DiffActor> > diffActor)
{

    for(std::shared_ptr<OgreActor> actor : newActors){
        addActor(actor);
    }

    for (std::shared_ptr<DiffActor> actor : diffActor)
    {
        Ogre::SceneNode *node;
        try {
          node = getSceneManager()->getSceneNode(actor->nodeName());
          node->setPosition(toOgreVector3(actor->position()));
          node->setOrientation(toOgreQuaternion(actor->orientation()));
        }
        catch (Ogre::ItemIdentityException e){
            std::cerr << "OgreApplication::updateNodes, warning: Node " << actor->nodeName() << " was not found. DiffActor was ignored." << std::endl;
        }
    }
}
void Camera::onSetTarget(const GameHandle& target)
{
	//! \hack const offset for camera
	v3 offset(0.0f, 3.0f, -14);

	Ogre::SceneManager* sceneMgr = Ogre::Root::getSingleton().getSceneManager(BFG_SCENEMANAGER);

	if (!sceneMgr->hasSceneNode(stringify(target)))
	{
		errlog << "Target (" << stringify(target) << ") for camera (" << mHandle << ") does not exist!";
		return;
	}

	Ogre::SceneNode* newParent = sceneMgr->getSceneNode(stringify(target));
	Ogre::SceneNode* oldParent = mCameraNode->getParentSceneNode();
	oldParent->removeChild(mCameraNode);
	newParent->addChild(mCameraNode);

	mCameraNode->setPosition(toOgre(offset));
}
void RenderComponentBillboardSet::setVisible(bool visible)
{
	Ogre::SceneNode * pSceneNode;
	pSceneNode=getParent()->getPositionalComponent()->getSceneNode();

	if(visible)
	{
		if(!mBillboardSet->isAttached())
		{
			pSceneNode->attachObject(mBillboardSet);
		}
	}
	else
	{
		if(mBillboardSet->isAttached() && mBillboardSet->getParentSceneNode()->getName().compare(pSceneNode->getName())==0)
		{
			pSceneNode->detachObject(mBillboardSet->getName());
		}
	}
}
TowerTemporal::~TowerTemporal(void)
{
  printf("~TowerTemporal\n");
  if (mpShotGraphics)
  {
    // Remove from scene node
    Ogre::SceneNode* node = mpShotGraphics->getParentSceneNode();
    if (node)
    {
      node->removeAndDestroyAllChildren();
      node->getParentSceneNode()->removeChild(node);
      mpsSceneMgr->destroySceneNode(node);
      node = NULL;
    }

    // Destroy shot graphics
    mpsSceneMgr->destroyManualObject(mpShotGraphics);
    mpShotGraphics = NULL;
  }
}
Example #18
0
	const Ogre::Vector3 Mesh::getWorldSpacePosition(const Ogre::Vector3& ObjectSpacePosition) const
	{
		Ogre::Matrix4 mWorldMatrix;

		if (mCreated)
		{
			mWorldMatrix = mEntity->getParentSceneNode()->_getFullTransform();
		}
		else
		{
			Ogre::SceneNode *mTmpSN = new Ogre::SceneNode(0);
		    mTmpSN->setPosition(mHydrax->getPosition());

			mWorldMatrix = mTmpSN->_getFullTransform();

		    delete mTmpSN;
		}

		return mWorldMatrix.transformAffine(ObjectSpacePosition);
	}
Example #19
0
void McsHudGui::addFrameGraph(CEGUI::Window* sheet)
{
    Ogre::TexturePtr tex = mOgreRoot->getTextureManager()->createManual(
                               "FrameGraph", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
                               TimeGraphMaxFrames, TimeGraphMaxResolution, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);

    Ogre::SceneManager* debugSceneMgr = mOgreRoot->createSceneManager(Ogre::ST_GENERIC);
    debugSceneMgr->setAmbientLight(Ogre::ColourValue(1.0f, 1.0f, 1.0f));

    Ogre::MaterialPtr frameLinesMaterial = Ogre::MaterialManager::getSingleton().create("frameLinesMaterial","Game");
    frameLinesMaterial->setReceiveShadows(false);
    frameLinesMaterial->getTechnique(0)->setLightingEnabled(false);
    frameLinesMaterial->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
    frameLinesMaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);

    mFrameLines = new FrameGraphRenderable(TimeGraphMaxFrames, TimeGraphMaxResolution);
    mFrameLines->setMaterial("frameLinesMaterial");

    Ogre::SceneNode* frameLinesNode = debugSceneMgr->getRootSceneNode()->createChildSceneNode("frameGraph_node");
    frameLinesNode->attachObject(mFrameLines);
    Ogre::Camera* dbg_camera = debugSceneMgr->createCamera("item_camera");
    dbg_camera->setAspectRatio(static_cast<Ogre::Real>(TimeGraphMaxFrames) / static_cast<Ogre::Real>(TimeGraphMaxResolution));
    Ogre::Viewport *v = tex->getBuffer()->getRenderTarget()->addViewport(dbg_camera);
    v->setClearEveryFrame( true );
    v->setBackgroundColour( Ogre::ColourValue::Black );



    CEGUI::Texture& guiTex = mCeRenderer->createTexture(tex);
    CEGUI::Imageset& imageSet = CEGUI::ImagesetManager::getSingleton().create("FrameGraphImageset", guiTex);
    imageSet.defineImage("FrameGraphImage", CEGUI::Point(0.0f, 0.0f), CEGUI::Size(guiTex.getSize()), CEGUI::Point(0.0f, 0.0f));
    CEGUI::Window* si = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage", "FrameGraphWindow");
    si->setSize(CEGUI::UVector2(CEGUI::UDim(0.0f, TimeGraphMaxFrames), CEGUI::UDim(0.0f, TimeGraphMaxResolution)));
    si->setPosition(CEGUI::UVector2(CEGUI::UDim(0.0f, 0), CEGUI::UDim(1.0f, -TimeGraphMaxResolution)));
    si->setProperty("Image", CEGUI::PropertyHelper::imageToString(&imageSet.getImage("FrameGraphImage")));
    si->setAlpha(0.6f);
    si->setProperty("BackgroundEnabled", "False");
    si->setProperty("FrameEnabled", "False");

    sheet->addChildWindow(si);
}
Example #20
0
//----------------------------------------------------------------------------------------
ImageConverter::ImageConverter(const size_t& width/*=128*/, const size_t& height/*=128*/)
{
    mWidth = width;
    mHeight = height;

    mResourceManager = Ogre::ResourceGroupManager::getSingletonPtr();
    mResourceManager->createResourceGroup("QTImageConverter");
    mResourceManager->initialiseResourceGroup("QTImageConverter");
    
    mSceneMgrPtr = Ogre::Root::getSingletonPtr()->createSceneManager("OctreeSceneManager", "QTImageConverterSceneManager");
    mSceneMgrPtr->setAmbientLight(Ogre::ColourValue(1, 1, 1));

    Ogre::TexturePtr rendertexture = Ogre::TextureManager::getSingleton().createManual("RenderTex", 
                   "QTImageConverter", Ogre::TEX_TYPE_2D, 
                   mWidth, mHeight, 1, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);

    mRttTex = rendertexture->getBuffer()->getRenderTarget();

    // create our plane to set a texture to
    Ogre::Plane plane(Ogre::Vector3::UNIT_Z, 0);
    Ogre::MeshManager::getSingleton().createPlane("terrain", "QTImageConverter",
        plane, 100, 100, 1, 1, true, 1, 1, 1, Ogre::Vector3::UNIT_Y);

    // attach the plane to the scene manager and rotate it so the camera can see it
    mEntityTerrain = mSceneMgrPtr->createEntity("terrainEntity", "terrain");
    Ogre::SceneNode* node = mSceneMgrPtr->getRootSceneNode()->createChildSceneNode();
    node->attachObject(mEntityTerrain);
    mEntityTerrain->setCastShadows(false);    
    
    Ogre::Camera* RTTCam = mSceneMgrPtr->createCamera("QTImageConverterCam");
    RTTCam->setNearClipDistance(0.01F);
    RTTCam->setFarClipDistance(0);
    RTTCam->setAspectRatio(1);
    RTTCam->setFOVy(Ogre::Degree(90));
    RTTCam->setPosition(0, 0, 50);
    RTTCam->lookAt(0, 0, 0);
    
    Ogre::Viewport *v = mRttTex->addViewport(RTTCam);
    v->setBackgroundColour(Ogre::ColourValue(1, 1, 1));
    v->setClearEveryFrame(true);
}
	//-----------------------------------------------------------------------
	void RibbonTrailRenderer::_updateRenderQueue(Ogre::RenderQueue* queue, ParticlePool* pool)
	{
		// Always perform this one
		ParticleRenderer::_updateRenderQueue(queue, pool);

		if (!mVisible)
			return;

		Particle* particle = static_cast<Particle*>(pool->getFirst());
		RibbonTrailRendererVisualData* visualData = 0;
		while (!pool->end())
		{
			if (particle)
			{
				if (!particle->visualData && !mVisualData.empty())
				{
					particle->visualData = mVisualData.back();
					mVisualData.pop_back();
					visualData = static_cast<RibbonTrailRendererVisualData*>(particle->visualData);
				}
				visualData = static_cast<RibbonTrailRendererVisualData*>(particle->visualData);
				if (visualData)
				{
					Ogre::SceneNode* node = visualData->node;
					node->_setDerivedPosition(particle->position);

					// Set the width of the trail if required
					if (particle->particleType == Particle::PT_VISUAL)
					{
						VisualParticle* visualParticle = static_cast<VisualParticle*>(particle);
						if (visualParticle->ownDimensions)
						{
							mTrail->setInitialWidth(visualData->index, visualParticle->width);
						}
					}
					visualData->setVisible(true);
				}
			}
			particle = static_cast<Particle*>(pool->getNext());
		}
	}
Example #22
0
void DotSceneLoader::processLookTarget(rapidxml::xml_node<>* XMLNode,
		Ogre::SceneNode *pParent) {
	// Process attributes
	Ogre::String nodeName = getAttrib(XMLNode, "nodeName");

	Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_PARENT;
	Ogre::String sValue = getAttrib(XMLNode, "relativeTo");
	if (sValue == "local")
		relativeTo = Ogre::Node::TS_LOCAL;
	else if (sValue == "parent")
		relativeTo = Ogre::Node::TS_PARENT;
	else if (sValue == "world")
		relativeTo = Ogre::Node::TS_WORLD;

	rapidxml::xml_node<>* pElement;

	// Process position (?)
	Ogre::Vector3 position;
	pElement = XMLNode->first_node("position");
	if (pElement)
		position = parseVector3(pElement);

	// Process localDirection (?)
	Ogre::Vector3 localDirection = Ogre::Vector3::NEGATIVE_UNIT_Z;
	pElement = XMLNode->first_node("localDirection");
	if (pElement)
		localDirection = parseVector3(pElement);

	// Setup the look target
  try {
    if (!nodeName.empty()) {
      Ogre::SceneNode *pLookNode = mSceneMgr->getSceneNode(nodeName);
      position = pLookNode->_getDerivedPosition();
    }

    pParent->lookAt(position, relativeTo, localDirection);
  } catch(...) {
    Ogre::LogManager::getSingleton().logMessage(
        "[DotSceneLoader] Error processing a look target!");
  }
}
Example #23
0
    void Scene::unloadCell (CellStoreCollection::iterator iter)
    {
        std::cout << "Unloading cell\n";
        ListHandles functor;






        (*iter)->forEach<ListHandles>(functor);

        {


            // silence annoying g++ warning
            for (std::vector<Ogre::SceneNode*>::const_iterator iter2 (functor.mHandles.begin());
                iter2!=functor.mHandles.end(); ++iter2){
                 Ogre::SceneNode* node = *iter2;
                mPhysics->removeObject (node->getName());
            }

            if (!((*iter)->cell->data.flags & ESM::Cell::Interior))
            {
                ESM::Land* land = MWBase::Environment::get().getWorld()->getStore().lands.search((*iter)->cell->data.gridX,(*iter)->cell->data.gridY);
                if (land)
                    mPhysics->removeHeightField( (*iter)->cell->data.gridX, (*iter)->cell->data.gridY );
            }
        }

		mRendering.removeCell(*iter);
		//mPhysics->removeObject("Unnamed_43");

        MWBase::Environment::get().getWorld()->getLocalScripts().clearCell (*iter);
        MWBase::Environment::get().getMechanicsManager()->dropActors (*iter);
        MWBase::Environment::get().getSoundManager()->stopSound (*iter);
		mActiveCells.erase(*iter);



    }
Example #24
0
    // ------------------------- Scene description ------------------------- //
    SceneManager* createOgreScene() {
        SceneManager* scene = mRoot->createSceneManager(ST_GENERIC);

        // Initialize camera
        Camera* camera = scene->createCamera("MainCamera");
        camera->setPosition(Vector3(0, 10, 30));
        camera->lookAt(Vector3(0, 0, 0));
        camera->setNearClipDistance(0.5);
        camera->setFOVy(Ogre::Degree(60.0));
        camera->setAspectRatio((float) mWindow->getWidth() / mWindow->getHeight());

        // Set up lighting (~ glEnable(GL_LIGHTING), glEnable(GL_LIGHT0), glLightfv(...)):
        scene->setAmbientLight(ColourValue(0.5f, 0.5f, 0.5f));
        Light* light = scene->createLight("MainLight");
        light->setType(Light::LT_POINT);
        light->setDiffuseColour(1, 1, 1);
        light->setSpecularColour(1, 1, 1);
        light->setPosition(20.0f, 80.0f, 50.0f);

        // Enable shadow computations
        scene->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);

        // Scenery
        Ogre::Entity* plane = scene->createEntity("Plane", Ogre::SceneManager::PT_PLANE);
        Ogre::SceneNode* planeNode = scene->getRootSceneNode()->createChildSceneNode("PlaneNode");
        planeNode->attachObject(plane);
        planeNode->rotate(Ogre::Vector3(-1, 0, 0), Ogre::Degree(90));
        plane->setCastShadows(false);
        plane->setMaterialName("Floor/Marble");

        // Load character mesh
		mBodyNode = scene->getRootSceneNode()->createChildSceneNode(Vector3::UNIT_Y * 5);
		mBodyEnt = scene->createEntity("SinbadBody", "Sinbad.mesh");
		mBodyNode->attachObject(mBodyEnt);

        // Load animations
        // Exercise 5: Get pointer to animation state
        // ...

        return scene;
    }
Example #25
0
//!
//! Remove and destroy this scene children.
//! \param The scenenode to be destroyed
//!
void Model2SceneNode::resizeNodes( Ogre::SceneNode* i_pSceneNode )
{
	if ( !i_pSceneNode || i_pSceneNode->numChildren() == 0 )
      return;

   // Destroy all the attached objects
   Ogre::SceneNode::ObjectIterator itObject = i_pSceneNode->getAttachedObjectIterator();

   // Recurse to child SceneNodes
   Ogre::SceneNode::ChildNodeIterator itChild = i_pSceneNode->getChildIterator();

   while ( itChild.hasMoreElements() )
   {
      Ogre::SceneNode* pChildNode = static_cast<Ogre::SceneNode*>(itChild.getNext());

	  // obtain the OGRE scene manager
	  Ogre::SceneManager *sceneManager = OgreManager::getSceneManager();
	  if (pChildNode != m_sceneNode)
		  pChildNode->setScale(m_size);
   }
}
Example #26
0
void EC_WaterPlane::ComponentAdded(IComponent* component, AttributeChange::Type type)
{
    if (component->TypeName() == EC_Placeable::TypeNameStatic())
    {
        DetachEntity();

        EC_Placeable* placeable = static_cast<EC_Placeable* >(component);
        if (placeable == 0)
            return;
        if (entity_ == 0)
            return;

        Ogre::SceneNode* node = placeable->GetSceneNode();
        
        node->addChild(node_);
        node_->attachObject(entity_);
        node_->setVisible(true);

        attached_ = true;
    }
}
    //-----------------------------------------------------------------------
	void MeshParticleVisualData::modifyMesh(const String &meshName)
	{
		// destroy old entity
		assert(mEntity);

		Ogre::SceneNode* parent = mEntity->getParentSceneNode();
		assert(parent);
		Ogre::SceneManager* creator = parent->getCreator();
		assert(creator);

		parent->detachObject(mEntity->getName());
		creator->destroyMovableObject(mEntity);

		mEntity = NULL;

		// create new entity
		mEntity = creator->createEntity( mSceneNode->getName(), meshName );
		assert (mEntity);

		mSceneNode->attachObject(mEntity);
	}
bool TutorialApplication::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
    if (m_mode == TrollMode) {
        const Vector3 p = m_cursorNode->getPosition();
        m_ogres.push_back(p);

        Ogre::Entity *troll = m_SceneMgr->createEntity("ogrehead.mesh");
        Vector3 bounds = troll->getBoundingBox().getSize();
        Real dim = std::max({bounds.x, bounds.y, bounds.z});
        Real scale = GRID_SPACING / dim;
        bounds = bounds * scale * 0.5f;

        Ogre::SceneNode *node = m_SceneMgr->getRootSceneNode()->createChildSceneNode();
        node->setPosition(p.x + bounds.x, p.y + bounds.y, p.z + bounds.z);
//        node->showBoundingBox(true);
        node->scale(scale, scale, scale);
        node->attachObject(troll);
    }

    return BaseApplication::mouseReleased(arg, id);
}
	//-----------------------------------------------------------------------
	void SceneDecoratorExtern::_notifyStart (void)
	{
		// Scale the node
		if (!mSubnode && mParentTechnique->getParentSystem())
		{
			std::stringstream ss; 
			ss << this;
			String sceneNodeName = "ParticleUniverse" + ss.str() + StringConverter::toString(mCount++);
			Ogre::SceneNode* sceneNode = mParentTechnique->getParentSystem()->getParentSceneNode();
			mSubnode = sceneNode->createChildSceneNode(sceneNodeName);
		}

		if (!mEntity)
		{
			createEntity();
			mSubnode->attachObject(mEntity);
		}

		mSubnode->setScale(mScale);
		mSubnode->setPosition(mPosition);
	}
Example #30
0
Entity Factory::createBlock(entityx::ptr<entityx::EntityManager> entityMgr, int x, int y, int z, std::string material)
{
    Entity block = entityMgr->create();
    Ogre::SceneManager* sceneMgr = RenderManager::getPtr()->getSceneManager();
    Ogre::Entity* wall = sceneMgr->createEntity("Cube.mesh");
    wall->setMaterialName(material);
    Ogre::SceneNode* wallNode = sceneMgr->getRootSceneNode()->createChildSceneNode();

    wallNode->attachObject(wall);

    block.assign<Position>(x,y,z);
    wallNode->setPosition(x,y,z);
    block.assign<Orientation>(wallNode->getOrientation());
    block.assign<Renderable>(wallNode);
    block.assign<Name>("Block");
    if(material == "Wall"){
        block.assign<Destroyable>(200);
    }

    return block;
}