예제 #1
0
Ogre::ManualObject* TerrainManager::createTerrainDecal(Ogre::String& name, Ogre::String& material, Ogre::String& resourceGroup)
{
	if(!_OgreManager)
		return NULL;

	Ogre::ManualObject* meshDecal = new Ogre::ManualObject(name);

	_OgreManager->getSceneManager()->getRootSceneNode()->attachObject(meshDecal);
	
	int x_size = 4;  // number of polygons
	int z_size = 4;
 
	meshDecal->begin(material, Ogre::RenderOperation::OT_TRIANGLE_LIST, resourceGroup);
	for (int i=0; i<=x_size; i++)
	{
		for (int j=0; j<=z_size; j++)
		{
			meshDecal->position(Ogre::Vector3(i, 0, j));
			meshDecal->textureCoord((float)i / (float)x_size, (float)j / (float)z_size);
		}
	}
 
	for (int i=0; i<x_size; i++)
	{
		for (int j=0; j<z_size; j++)
		{
			meshDecal->quad( i * (x_size+1) + j,
							 i * (x_size+1) + j + 1,
							(i + 1) * (x_size+1) + j + 1,
							(i + 1) * (x_size+1) + j);
		}
	}
	meshDecal->end();

	return meshDecal;
}
예제 #2
0
CFootballPlayer::CFootballPlayer(CSimulationManager *simulationManager, const CPfTeamPlayers *teamPlayer, int number, CTeam *team, bool sideLeft)
:CMovingEntity()
{
	m_simulationManager = simulationManager;

	Ogre::SceneManager *scnMgr = Ogre::Root::getSingletonPtr()->getSceneManager(SIMULATION_SCENE_MANAGER_NODE_NAME);

    m_teamPlayer = new CPfTeamPlayers(*teamPlayer);
    m_stateMachine = new CStateMachine<CFootballPlayer>(this);
    Ogre::String id;
    char charId[20];
    m_centerOfMassOffset.setOrigin(btVector3(0,-0.9,0));
    m_sideLeft = sideLeft;
    m_team = team;
    m_number = number; //TODO
    m_lastKickBallCycle = -1;

    //m_direction.normalize();
    sprintf(charId,"%s%d", team->getName().c_str(), m_number);
    id = charId;
    m_entity = scnMgr->createEntity("Player"+id, "Human.mesh");
    if(sideLeft) {
        if(m_number == 1) {
            m_entity->setMaterialName("goalie_red");
        } else {
            m_entity->setMaterialName("player_red");
        }
    } else {
        if(m_number == 1) {
            m_entity->setMaterialName("goalie_yellow");
        } else {
            m_entity->setMaterialName("player_yellow");
        }
    }
    btVector3 *initialPos = team->getPlayerStrategicPosition(m_number)->getInitialPosition();
    btVector3 pos(initialPos->x(), initialPos->y(), initialPos->z());
    if(!m_sideLeft) {
        pos.setX(-pos.x());
        pos.setZ(-pos.z());
    }
    m_node = scnMgr->getRootSceneNode()->createChildSceneNode("PlayerNode"+id, Ogre::Vector3(pos.x(), pos.y(), pos.z()));
    m_node->attachObject(m_entity);
    m_shape = new btCylinderShape(btVector3(btScalar(0.5),btScalar(0.9),btScalar(0.5)));
    btScalar mass(70.0);

    //rigidbody is dynamic if and only if mass is non zero, otherwise static
    bool isDynamic = (mass != 0.f);

    btVector3 localInertia(0,0,0);
    if (isDynamic)
        m_shape->calculateLocalInertia(mass,localInertia);
    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,this,m_shape,localInertia);
    m_body = new btRigidBody(rbInfo);
    m_body->setAngularFactor(btScalar(0));
    m_body->setActivationState(DISABLE_DEACTIVATION);

    m_steeringBehavior = new CSteeringBehaviors(this);


    //Draw Circle
    Ogre::ManualObject * circle = scnMgr->createManualObject("circle_name"+id);

    float const radius = 1.5,
                thickness = 0.7, // Of course this must be less than the radius value.
                accuracy = 5,
                height = 0.01;

    Ogre::MaterialPtr matptr;
    Ogre::Pass* pass;

    if(sideLeft) {
        matptr = Ogre::MaterialManager::getSingleton().createOrRetrieve("Red"+id, "General").first;
        matptr->setReceiveShadows(true);
        pass = matptr->getTechnique(0)->getPass(0);
        Ogre::ColourValue colour = Ogre::ColourValue::Red;
        pass->setDiffuse(colour);
        pass->setAmbient(colour);
        pass->setSpecular(colour);
        pass->setSelfIllumination(colour);
        //pass->setEmissive(ColourValue(0,0,0,colour.a));
        pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
        pass->setDepthWriteEnabled(false);
    } else {
        matptr = Ogre::MaterialManager::getSingleton().createOrRetrieve("Blue"+id, "General").first;
        matptr->setReceiveShadows(true);
        pass = matptr->getTechnique(0)->getPass(0);
        Ogre::ColourValue colour = Ogre::ColourValue::Blue;
        pass->setDiffuse(colour);
        pass->setAmbient(colour);
        pass->setSpecular(colour);
        pass->setSelfIllumination(colour);
        //pass->setEmissive(ColourValue(0,0,0,colour.a));
        pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
        pass->setDepthWriteEnabled(false);
    }
    circle->begin(matptr->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST);

    unsigned point_index = 0;
    for(float theta = 0; theta <= 2 * Ogre::Math::PI; theta += Ogre::Math::PI / (radius * accuracy)) {
        circle->position(radius * cos(theta),
                         height,
                         radius * sin(theta));
        circle->position(radius * cos(theta - Ogre::Math::PI / (radius * accuracy)),
                         height,
                         radius * sin(theta - Ogre::Math::PI / (radius * accuracy)));
        circle->position((radius - thickness) * cos(theta - Ogre::Math::PI / (radius * accuracy)),
                         height,
                         (radius - thickness) * sin(theta - Ogre::Math::PI / (radius * accuracy)));
        circle->position((radius - thickness) * cos(theta),
                         height,
                         (radius - thickness) * sin(theta));
        // Join the 4 vertices created above to form a quad.
        circle->quad(point_index, point_index + 1, point_index + 2, point_index + 3);
        point_index += 4;
    }

    circle->end();

    m_ringNode = m_node->createChildSceneNode();
    m_ringNode->attachObject(circle);
}
예제 #3
0
// Given a scene node for a terrain, find the manual object on that scene node and
// update the manual object with the heightmap passed. If  there is no manual object on
// the scene node, remove all it's attachments and add the manual object.
// The heightmap is passed in a 1D array ordered by width rows (for(width) {for(length) {hm[w,l]}})
// This must be called between frames since it touches the scene graph
// BETWEEN FRAME OPERATION
void Region::UpdateTerrain(const int hmWidth, const int hmLength, const float* hm) {
	Ogre::SceneNode* node = this->TerrainSceneNode;
	LG::Log("Region::UpdateTerrain: updating terrain for region %s", this->Name.c_str());

	if (node == NULL) {
		LG::Log("Region::UpdateTerrain: terrain scene node doesn't exist. Not updating terrain.");
		return;
	}

	// Find the movable object attached to the scene node. If not found remove all.
	if (node->numAttachedObjects() > 0) {
		Ogre::MovableObject* attached = node->getAttachedObject(0);
		if (attached->getMovableType() != "ManualObject") {
            // don't know why this would ever happen but clean out the odd stuff
            LG::Log("Found extra stuff on terrain scene node");
			node->detachAllObjects();
		}
	}
	// if there is not a manual object on the node, create a new one
	if (node->numAttachedObjects() == 0) {
		LG::Log("Region::UpdateTerrain: creating terrain ManualObject for region %s", this->Name.c_str());
        // if no attached objects, we add our dynamic ManualObject
		Ogre::ManualObject* mob = LG::RendererOgre::Instance()->m_sceneMgr->createManualObject("ManualObject/" + node->getName());
		mob->addQueryFlags(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
		mob->setDynamic(true);
		mob->setCastShadows(true);
		mob->setVisible(true);
		node->attachObject(mob);
		// m_visCalc->RecalculateVisibility();
	}

	Ogre::ManualObject* mo = (Ogre::ManualObject*)node->getAttachedObject(0);

	// stuff our heightmap information into the dynamic manual object
	mo->estimateVertexCount(hmWidth * hmLength);
	mo->estimateIndexCount(hmWidth * hmLength * 6);

	if (mo->getNumSections() == 0) {
		// if first time
		mo->begin(LG::GetParameter("Renderer.Ogre.DefaultTerrainMaterial"));
	}
	else {
		mo->beginUpdate(0);					// we've been here before
	}

	int loc = 0;
	for (int xx = 0; xx < hmWidth; xx++) {
		for (int yy = 0; yy < hmLength; yy++) {
			mo->position((Ogre::Real)xx, (Ogre::Real)yy, hm[loc++]);
			mo->textureCoord((float)xx / (float)hmWidth, (float)yy / (float)hmLength);
			mo->normal(0.0, 1.0, 0.0);	// always up (for the moment)
		}
	}

	for (int px = 0; px < hmLength-1; px++) {
		for (int py = 0; py < hmWidth-1; py++) {
			mo->quad(px      + py       * hmWidth,
					 px      + (py + 1) * hmWidth,
					(px + 1) + (py + 1) * hmWidth,
					(px + 1) + py       * hmWidth
					 );
		}
	}

	mo->end();

	return;
}
예제 #4
0
		void SetUpCustomContent()
		{
			Ogre::String CustomCameraName = "TestRenderTargetCamera";
			Ogre::String CustomTextureName = "TestRenderTargetTexture";
			Ogre::String CustomMaterialName = "CustomRenderTargetMaterial";
			Ogre::String CustomWorkSpaceName = "TestCustomRenderTargetWorkSpaceName";

			m_CustomRTTCamera = mSceneManager->createCamera(CustomCameraName);
			m_CustomRTTCamera->setPosition(0, 30, 0);
			m_CustomRTTCamera->lookAt(0, 0, 0);
			m_CustomRTTCamera->setFarClipDistance(1000);
			m_CustomRTTCamera->setNearClipDistance(0.1);

			m_CustomRenderTexture = Ogre::TextureManager::getSingleton().createManual(CustomTextureName, 
				Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 
				512, 512, 1, Ogre::PF_A8B8G8R8, Ogre::TU_RENDERTARGET);
			m_CustomRenderTexture->load();

			Ogre::RenderTexture* rtt = m_CustomRenderTexture->getBuffer(0)->getRenderTarget();


			Ogre::CompositorManager2 *compositorManager = mRoot->getCompositorManager2();

			const Ogre::IdString workspaceName(CustomWorkSpaceName);
			if( !compositorManager->hasWorkspaceDefinition( workspaceName ) )
			{
				compositorManager->createBasicWorkspaceDef( workspaceName, mBackgroundColour,
					Ogre::IdString() );
			}

			m_CustomRenderTarget = compositorManager->addWorkspace( mSceneManager, (Ogre::RenderTarget*)rtt, m_CustomRTTCamera,
					workspaceName, false );
			//m_CustomRenderTarget->setEnabled(false);			// not auto update
#if 0
			// create manual object
			Ogre::MaterialPtr CustomMaterial = Ogre::MaterialManager::getSingleton().create(CustomMaterialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
			CustomMaterial->getTechnique(0)->removeAllPasses();
			Ogre::Pass* pass = CustomMaterial->getTechnique(0)->createPass();
			Ogre::TextureUnitState* tu = pass->createTextureUnitState();
			tu->setTextureName(CustomTextureName);
#endif
			Ogre::HlmsManager *hlmsManager = Ogre::Root::getSingleton().getHlmsManager();
			Ogre::Hlms *hlms = hlmsManager->getHlms( Ogre::HLMS_UNLIT );
			Ogre::HlmsDatablock *datablock = hlms->createDatablock( CustomMaterialName, CustomMaterialName,
				Ogre::HlmsMacroblock(), Ogre::HlmsBlendblock(), Ogre::HlmsParamVec() );
			Ogre::HlmsUnlitDatablock *unlitDb = static_cast<Ogre::HlmsUnlitDatablock*>( datablock );
			unlitDb->setTexture( 0, 0, m_CustomRenderTexture );
			
#if 1
			Ogre::ManualObject* CustomManualObject = mSceneManager->createManualObject();
			CustomManualObject->begin(CustomMaterialName);
			CustomManualObject->position(-100, -100, -100);
			CustomManualObject->textureCoord(0, 0);
			CustomManualObject->position(100, -100, -100);
			CustomManualObject->textureCoord(1, 0);
			CustomManualObject->position(100, 100, -100);
			CustomManualObject->textureCoord(1, 1);
			CustomManualObject->position(-100, 100, -100);
			CustomManualObject->textureCoord(0, 1);
			CustomManualObject->quad(0, 1, 2, 3);
			CustomManualObject->end();
//			CustomManualObject->setDatablock(0, CustomMaterialName);

			Ogre::SceneNode *sceneNodeLines = mSceneManager->getRootSceneNode( Ogre::SCENE_DYNAMIC )->
				createChildSceneNode( Ogre::SCENE_DYNAMIC );
			sceneNodeLines->attachObject(CustomManualObject);
			sceneNodeLines->scale(0.4f, 0.4f, 0.4f);
			sceneNodeLines->translate(0.0f, 0.0f, 0.0f, Ogre::SceneNode::TS_WORLD);
#endif
		}