コード例 #1
0
	TwoBogieVehicle* instance(){
		UniqueIdGenerator& gen = UniqueIdGenerator::getSingleton();
		Entity* fBogie = mFrontBogie->clone(mFrontBogieEntityName+gen.getAsHexadecimal());
		SceneNode* fBogieN = mTargetGround->createChildSceneNode();
        fBogieN->attachObject(fBogie);
        fBogieN->setScale(mFrontBogieScale);

        Entity* rBogie = mRearBogie->clone(mRearBogieEntityName+gen.getAsHexadecimal());
        SceneNode* rBogieN = mTargetGround->createChildSceneNode();
        rBogieN->attachObject(rBogie);
		rBogieN->setScale(mRearBogieScale);

        Entity* body = mBody->clone(mBodyEntityName+gen.getAsHexadecimal());
        SceneNode* bodyN = mTargetGround->createChildSceneNode(Ogre::Vector3(0.0f,1,0.0f));
        bodyN->setScale(mBodyScale);
        bodyN->attachObject(body);
		// Initial body rotation
		//bodyN->roll(Ogre::Radian(-Ogre::Math::HALF_PI));

		if (mBodyRotate.x) {
			bodyN->rotate(Ogre::Vector3::UNIT_X, Ogre::Radian(mBodyRotate.x));
		}
		if (mBodyRotate.y) {
			bodyN->rotate(Ogre::Vector3::UNIT_Y, Ogre::Radian(mBodyRotate.y));
		}
		if (mBodyRotate.z) {
			bodyN->rotate(Ogre::Vector3::UNIT_Z, Ogre::Radian(mBodyRotate.z));
		}

		return new TwoBogieVehicle(	fBogieN,fBogie,rBogieN,rBogie,bodyN,body,mGapSize,mLength,mFrontBogieOffset,mRearBogieOffset,mBogieHeight );
	}
コード例 #2
0
	//-----------------------------------------------------------------------
	void EntityRenderer::_prepare(ParticleTechnique* technique)
	{
		/** 
			- This renderer is a ´hacky´ solution to display geometry-based particles. It pre-creates a 
			number of SceneNodes (childs of the parent Node to which the ParticleSystem is attached) and 
			Entities and uses these pools to display the particles. There are better solutions, but 
			this one is simple and fast enough, although it has some drawbacks.
			- Future solutions should rather make use of hardware instancing to display a large number of
			geometry-based particles at once.
		*/

		// Use the given technique, although it should be the same as mParentTechnique (must be set already)
		if (!technique || mRendererInitialised)
			return;

		std::stringstream ss; 
		ss << this;
		mEntityName = mMeshName + ss.str();
		mQuota = technique->getVisualParticleQuota();
		Ogre::SceneNode* parentNode = technique->getParentSystem()->getParentSceneNode();
		Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load(mMeshName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		Ogre::Mesh* meshPointer = mesh.getPointer();
		Vector3 size = meshPointer->getBounds().getSize();
		mBoxWidth = size.x == 0.0f ? 1.0f : size.x;
		mBoxHeight = size.y == 0.0f ? 1.0f : size.y;
		mBoxDepth = size.z == 0.0f ? 1.0f : size.z;

		if (parentNode)
		{
			// Create number of VisualData objects including SceneNodes
			String sceneNodeName;
			for (size_t i = 0; i < mQuota; i++)
			{
				sceneNodeName = "ParticleUniverse" + ss.str() + StringConverter::toString(i);
				EntityRendererVisualData* visualData = 
					PU_NEW_T(EntityRendererVisualData, MEMCATEGORY_SCENE_OBJECTS)(parentNode->createChildSceneNode(sceneNodeName));

				mAllVisualData.push_back(visualData); // Managed by this renderer
				mVisualData.push_back(visualData); // Used to assign to a particle
			}

			// Create number of Entities
			Ogre::Entity* entity = technique->getParentSystem()->getSceneManager()->createEntity(mEntityName, mMeshName); // Base entity
			vector<EntityRendererVisualData*>::const_iterator it;
			vector<EntityRendererVisualData*>::const_iterator itEnd = mAllVisualData.end();
			size_t j;
			for (it = mAllVisualData.begin(), j = 0; it != itEnd; ++it, ++j)
			{
				Ogre::Entity* clonedEntity = entity->clone(mEntityName + StringConverter::toString(j));
				clonedEntity->setMaterialName(technique->getMaterialName());
				clonedEntity->setRenderQueueGroup(mQueueId);
				mEntities.push_back(clonedEntity);
				(*it)->node->attachObject(clonedEntity);
			}
			technique->getParentSystem()->getSceneManager()->destroyEntity(mEntityName);
		}

		_makeNodesVisible(false);
		mRendererInitialised = true;
	}
コード例 #3
0
ファイル: EC_Clone.cpp プロジェクト: caocao/naali
void EC_Clone::Create()
{
    if (renderer_.expired())
        return;

    Ogre::SceneManager *scene = renderer_.lock()->GetSceneManager();
    assert(scene);
    if (!scene)
        return;

    Scene::Entity *entity = GetParentEntity();
    assert(entity);
    if (!entity)
        return;

    OgreRenderer::EC_OgrePlaceable *placeable = entity->GetComponent<OgreRenderer::EC_OgrePlaceable>().get();
    assert(placeable);
    if (!placeable)
        return;

    // Check out if this entity has EC_OgreMesh or EC_OgreCustomObject.
    Ogre::Entity *originalEntity  = 0;
    if (entity->GetComponent(OgreRenderer::EC_OgreMesh::NameStatic()))
    {
        OgreRenderer::EC_OgreMesh *ec_mesh= entity->GetComponent<OgreRenderer::EC_OgreMesh>().get();
        assert(ec_mesh);

        originalEntity = ec_mesh->GetEntity();
        sceneNode_ = ec_mesh->GetAdjustmentSceneNode();
    }
    else if(entity->GetComponent(OgreRenderer::EC_OgreCustomObject::NameStatic()))
    {
        OgreRenderer::EC_OgreCustomObject *ec_custom = entity->GetComponent<OgreRenderer::EC_OgreCustomObject>().get();
        assert(ec_custom);
        if (!ec_custom->IsCommitted())
        {
            LogError("Mesh entity have not been created for the target primitive. Cannot create EC_Highlight.");
            return;
        }

        originalEntity = ec_custom->GetEntity();
        sceneNode_ = placeable->GetSceneNode();
    }
    else
    {
        LogError("This entity doesn't have either EC_OgreMesh or EC_OgreCustomObject present. Cannot create EC_Highlight.");
        return;
    }

    assert(originalEntity);
    if (!originalEntity)
        return;

    assert(sceneNode_);
    if (!sceneNode_)
        return;

    // Clone the Ogre entity.
    cloneName_ = std::string("entity") + renderer_.lock()->GetUniqueObjectName();
    entityClone_ = originalEntity->clone(cloneName_);
    assert(entityClone_);

    // Disable casting of shadows for the clone.
    entityClone_->setCastShadows(false);

    ///\todo If original entity has skeleton, (try to) link it to the clone.
/*
    if (originalEntity->hasSkeleton())
    {
        Ogre::SkeletonInstance *skel = originalEntity->getSkeleton();
        // If sharing a skeleton, force the attachment mesh to use the same skeleton
        // This is theoretically quite a scary operation, for there is possibility for things to go wrong
        Ogre::SkeletonPtr entity_skel = originalEntity->getMesh()->getSkeleton();
        if (entity_skel.isNull())
        {
            LogError("Cannot share skeleton for attachment, not found");
        }
        else
        {
            try
            {
                entityClone_->getMesh()->_notifySkeleton(entity_skel);
            }
            catch (Ogre::Exception &e)
            {
                LogError("Could not set shared skeleton for attachment: " + std::string(e.what()));
            }
        }
    }
*/

    std::string newMatName = std::string("HighlightMaterial") + renderer_.lock()->GetUniqueObjectName();
    try
    {
        Ogre::MaterialPtr highlightMaterial = OgreRenderer::CloneMaterial("Highlight", newMatName);
        entityClone_->setMaterialName(newMatName);
    }
    catch (Ogre::Exception &e)
    {
        LogError("Could not set material \"" + newMatName + "\": " + std::string(e.what()));
        return;
    }

    sceneNode_->attachObject(entityClone_);
}
//-------------------------------------------------------------------------------------
void RollerCoaster::createScene( void )
{
	initSceneManager();
	initTrack();
	initTrain();
	initCamera();
	initLight();
	initTerrain();

	snTar = mSceneMgr->getRootSceneNode()->createChildSceneNode("aaa");
	Ogre::Entity *temp =mSceneMgr->createEntity("ogrehead.mesh");
	enTar = temp->clone ("mTarget");
	snTar->attachObject(enTar);
	snTar ->setPosition(0,0,50);
	snTar ->setScale(0.1,0.1,0.1);


	Ogre::SceneNode *sn =mSceneMgr->getRootSceneNode()->createChildSceneNode("aaa");
	Ogre::ManualObject *mo=mSceneMgr->createManualObject("aaa");
	mo->begin("Box", Ogre::RenderOperation::OT_TRIANGLE_LIST);
	//White side-Back
	 mo->position(1,1,1  );mo->colour(1,0,0);mo->textureCoord(0,0);
	 mo->position(1,-1,1 );mo->colour(1,0,0);mo->textureCoord(0,1);
	 mo->position(1,1,-1 );mo->colour(1,0,0);mo->textureCoord(1,0);
	 mo->position(1,-1,1 );mo->colour(1,0,0);mo->textureCoord(0,1);
	 mo->position(1,-1,-1);mo->colour(1,0,0);mo->textureCoord(1,1);
	 mo->position(1,1,-1 );mo->colour(1,0,0);mo->textureCoord(1,0);
	objControl = new ObjectControl(mSceneMgr, mCamera);
	objControl->init();
	mRayScnQuery = mSceneMgr->createRayQuery(Ogre::Ray());


	//Ogre::SceneNode *stest=mSceneMgr->getRootSceneNode()->createChildSceneNode("bb");
	//Ogre::ManualObject *mtest=mSceneMgr->createManualObject("bb");
	//mtest->position(1,1,1);  mtest->colour(0,1,0); mtest->textureCoord(0,0);
	//mtest->position(1,1,1);  mtest->colour(0,1,0); mtest->textureCoord(0,0);
	//mtest->position(1,1,1);  mtest->colour(0,1,0); mtest->textureCoord(0,0);
	//mtest->position(1,1,1);  mtest->colour(0,1,0); mtest->textureCoord(0,0);
	//mtest->quad(3,2,1,0);
	//mtest->setVisible(true);
	//mtest->end();






	//enAnim = mSceneMgr->createEntity("Robot","robot.mesh");
	//mAnimationState =enAnim->getAnimationState("Walk");
	//mAnimationState ->setLoop(true);
	//mAnimationState ->setEnabled(true);
	//snAnim = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	//snAnim->attachObject(enAnim);








}