Beispiel #1
0
	// Dibujado de raycast para depurar
	void CShootRaycast::drawRaycast(const Ray& raycast) {
		Graphics::CScene *scene = Graphics::CServer::getSingletonPtr()->getActiveScene();
		Ogre::SceneManager *mSceneMgr = scene->getSceneMgr();

		std::stringstream aux;
		aux << "laser" << _nameWeapon << _temporal;
		++_temporal;
		std::string laser = aux.str();

		Ogre::ManualObject* myManualObject =  mSceneMgr->createManualObject(laser); 
		Ogre::SceneNode* myManualObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(laser+"_node"); 
 
		myManualObject->begin("laser", Ogre::RenderOperation::OT_LINE_STRIP);
		Vector3 v = raycast.getOrigin();
		myManualObject->position(v.x,v.y,v.z);

		for(int i=0; i < _distance;++i){
			Vector3 v = raycast.getPoint(i);
			myManualObject->position(v.x,v.y,v.z);
			// etc 
		}

		myManualObject->end(); 
		myManualObjectNode->attachObject(myManualObject);
	}// drawRaycast
void NavigationCell::debugDrawClassification( Ogre::Vector3 start, Ogre::Vector3 end )
{
    Ogre::Root *root = Ogre::Root::getSingletonPtr();
    Ogre::SceneManager* mgr = root->getSceneManager( "SceneManagerInstance" );
    Ogre::ManualObject* debug;
    Ogre::SceneNode* node;

    if( mgr->hasManualObject( "debugDrawClassification" ) )
        debug = mgr->getManualObject( "debugDrawClassification" );
    else
    {
        debug = mgr->createManualObject( "debugDrawClassification" );
        node = mgr->getRootSceneNode()->createChildSceneNode();
        node->attachObject( debug );
        node->translate( 0, 1, 0 );
        debug->setQueryFlags( 0 );
        debug->setRenderQueueGroup( Ogre::RENDER_QUEUE_OVERLAY );
    }

    debug->begin( "debug/blue", Ogre::RenderOperation::OT_LINE_LIST );
    debug->position( start );
    debug->position( end );
    debug->end();

//    debugDrawCell( debug, "debug/yellow", "debug/blue" );
}
Entity* EntityFactory::createBeamGun(const BeamGunConfig& config)
{
	EntityManager* entityMgr = engine_->entityMgr_;
	Entity* entity = entityMgr->create();

	float y = 0.1f;

	b2BodyDef bd;
	bd.type = b2_dynamicBody;
	bd.position.Set(config.posX_, config.posY_);
	b2Body* body = engine_->sysPhysics_->getWorld()->CreateBody(&bd);

	b2PolygonShape shape;
	b2Vec2 vertices[4];
	vertices[0].Set(0, y);
	vertices[1].Set(0, -y);
	vertices[2].Set(config.beamRange_, -y);
	vertices[3].Set(config.beamRange_, y);
	shape.Set(vertices, 4);

	b2FixtureDef sd;
	sd.shape = &shape;
	sd.density = 0;
	sd.filter.categoryBits = ComPhysics::CATEG_PlayerBeam;
	sd.filter.maskBits = ComPhysics::MASK_PlayerBeam;

	body->CreateFixture(&sd);

	ComPhysics* comPhysics = entityMgr->assignComponent<ComPhysics>(entity);
	comPhysics->setMainBody(body, entity);


	Ogre::SceneManager* sceneMgr = engine_->sysGraphics_->getSceneManager();
	Ogre::ManualObject* manual = sceneMgr->createManualObject();
	manual->begin("beam", Ogre::RenderOperation::OT_LINE_STRIP);
	manual->position(0, y, 0);
	manual->position(0, -y, 0);
	manual->position(config.beamRange_, -y, 0);
	manual->position(config.beamRange_, y, 0);
	manual->position(0, y, 0);
	manual->end();
	Ogre::SceneNode* node = engine_->sysGraphics_->getSceneRoot()->createChildSceneNode(
		Ogre::Vector3(config.posX_, config.posY_, 0));
	node->attachObject(manual);

	ComGraphics* comGraphics = entityMgr->assignComponent<ComGraphics>(entity);
	comGraphics->sceneNode_ = node;

	return entity;
}
Beispiel #4
0
EC_SelectionBox::EC_SelectionBox(Scene* scene) :
    IComponent(scene),
    selectionBox_(0)
{
    if (scene)
        world_ = scene->GetWorld<OgreWorld>();
    OgreWorldPtr world = world_.lock();
    Ogre::SceneManager* sceneMgr = world->GetSceneManager();
    selectionBox_ = sceneMgr->createManualObject(world->GetUniqueObjectName("EC_Selected"));
    selectionBox_->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
    selectionBox_->setUseIdentityProjection(true);
    selectionBox_->setUseIdentityView(true);
    selectionBox_->setQueryFlags(0);
    sceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(selectionBox_);
}
void NavigationCell::debugDrawCellAndNeigbours()
{
    Ogre::Root *root = Ogre::Root::getSingletonPtr();
    Ogre::SceneManager* mgr = root->getSceneManager( "SceneManagerInstance" );
    Ogre::ManualObject* debug;
    Ogre::SceneNode* debugNode;

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

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

    for( int i = 0; i < 3; i++ )
    {
        if( mLinks[i] )
        {
            debug->begin( "debug/blue", Ogre::RenderOperation::OT_LINE_STRIP );
            debug->position( mLinks[i]->mVertices[0] );
            debug->position( mLinks[i]->mVertices[1] );
            debug->position( mLinks[i]->mVertices[2] );
            debug->position( mLinks[i]->mVertices[0] );
            debug->end();
        }
    }

    debug->begin( "debug/yellow", Ogre::RenderOperation::OT_LINE_STRIP );
    debug->position( mVertices[0].x, mVertices[0].y+1, mVertices[0].z );
    debug->position( mVertices[1].x, mVertices[1].y+1, mVertices[1].z );
    debug->position( mVertices[2].x, mVertices[2].y+1, mVertices[2].z );
    debug->position( mVertices[0].x, mVertices[0].y+1, mVertices[0].z );
    debug->end();

}
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;
}
Ogre::MeshPtr Path::realizeMesh(const std::string& name)
{
    Ogre::SceneManager *smgr = Ogre::Root::getSingleton().getSceneManagerIterator().begin()->second;
    Ogre::ManualObject * manual = smgr->createManualObject();
    manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);

    for (std::vector<Ogre::Vector3>::iterator itPos = mPoints.begin(); itPos != mPoints.end(); itPos++)
        manual->position(*itPos);
    if (mClosed)
        manual->position(*(mPoints.begin()));
    manual->end();

    Ogre::MeshPtr mesh;
    if (name=="")
        mesh = manual->convertToMesh(Utils::getName());
    else
        mesh = manual->convertToMesh(name);

    return mesh;
}
InfluenceMapDrawer::InfluenceMapDrawer(Ogre::SceneManager& sceneManager)
{
    manualObject_ = sceneManager.createManualObject();
    manualObjectNode =
        sceneManager.getRootSceneNode()->createChildSceneNode();
    manualObjectNode->attachObject(manualObject_);
    manualObject_->setDynamic(true);

    manualObject_->begin("debug_draw", Ogre::RenderOperation::OT_LINE_LIST);
    manualObject_->position(Ogre::Vector3::ZERO);
    manualObject_->colour(Ogre::ColourValue::ZERO);
    manualObject_->index(0);
    manualObject_->end();
    manualObject_->begin("debug_draw", Ogre::RenderOperation::OT_TRIANGLE_LIST);
    manualObject_->position(Ogre::Vector3::ZERO);
    manualObject_->colour(Ogre::ColourValue::ZERO);
    manualObject_->index(0);
    manualObject_->end();

    manualObject_->setBoundingBox(Ogre::AxisAlignedBox::BOX_INFINITE);
    manualObjectNode->_updateBounds();
}
Beispiel #9
0
    /**
     * This is the most basic "triangle" example, done as a Scene in Ogre.
     */
    Ogre::SceneManager* createTriangleScene() {
        Ogre::SceneManager* scene = mRoot->createSceneManager(Ogre::ST_GENERIC);

        // Configure camera (~ view & projection transforms, i.e. gluLookAt + glOrtho)
        Ogre::Camera* camera = scene->createCamera("MainCamera"); // We can use an arbitrary name here
        camera->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
        camera->setOrthoWindow(2, 2);              // ~ glOrtho(-1, 1, -1, 1)
        camera->setAspectRatio((float) mWindow->getWidth() / mWindow->getHeight());
        camera->setNearClipDistance(0.5);
        camera->setPosition(Ogre::Vector3(0,0,1)); // Move camera away from (0, 0, 0), otherwise the triangle at z=0 will be clipped

        // Now add some geometry to the scene
        Ogre::ManualObject* triangle = scene->createManualObject("Triangle");

        // ~ glBegin, glVertex, glEnd
        // "BaseWhiteNoLighting" is a built-in name for a basic non-lit material
        triangle->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
        triangle->position(0, 0.5, 0);            // ~ glVertex.
                                                  // Contrary to OpenGL we *first* must create the vertex
        triangle->colour(Ogre::ColourValue::Red); // .. and then provide its attributes such as color (~ glColor)
        triangle->position(-0.5, -0.5, 0);
        triangle->colour(Ogre::ColourValue::Green);
        triangle->position(0.5, -0.5, 0);
        triangle->colour(Ogre::ColourValue::Blue);
        triangle->end();

        // Add the created triangle object to the scene graph
        // For this we create a SceneNode object, which will combine information about
        // the object's geometry with its modeling transform
        // (see frameRenderingQueued to understand how to rotate the triangle by changing this transform)
        scene->getRootSceneNode()->createChildSceneNode("Triangle")->attachObject(triangle);

        // Exercise 1: Create new object, add vertices, attach the object to a new SceneNode
        // ...

        return scene;
    }
Ogre::ManualObject * CCone::CreateCone(Ogre::Real Intensity)
{
	Ogre::ManualObject *Cone = NULL;
	Ogre::SceneManager *SceneManager = Ogre::Root::getSingleton().getSceneManager("DynamicEffects");
	Cone = SceneManager->createManualObject("Cone");
	Cone->setDynamic(false);
    Cone->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);

	Ogre::Real deltaAngle = (Ogre::Math::TWO_PI / m_BaseSegments);
	Ogre::Real deltaHeight = m_Height/(Ogre::Real)m_HeightSegments;
	
	Ogre::Vector3 Normal = Ogre::Vector3(m_Radius, m_Height, 0.f).normalisedCopy();
	Ogre::Quaternion Quaternion;
	
	int Offset = 0;

	for (int HeightSegmentIndex = 0; HeightSegmentIndex <= m_HeightSegments; HeightSegmentIndex++)
	{
		Ogre::Real Radius = m_Radius * (1 - HeightSegmentIndex / (Ogre::Real)m_HeightSegments);
		
		for (int BaseSegmentIndex = 0; BaseSegmentIndex <= m_BaseSegments; BaseSegmentIndex++)
		{
			Ogre::Real x = Radius* cosf(BaseSegmentIndex * deltaAngle);
			Ogre::Real z = Radius * sinf(BaseSegmentIndex * deltaAngle);
			Cone->position(x, HeightSegmentIndex * deltaHeight, z);
			
			Cone->colour(Intensity, Intensity, 0.0, 1.0);
			Quaternion.FromAngleAxis(Ogre::Radian(-BaseSegmentIndex*deltaAngle), Ogre::Vector3::NEGATIVE_UNIT_Y);
			Cone->normal(Quaternion * Normal);
			Cone->textureCoord(BaseSegmentIndex / (Ogre::Real)m_BaseSegments, HeightSegmentIndex / (Ogre::Real)m_HeightSegments);

			if (HeightSegmentIndex != m_HeightSegments && BaseSegmentIndex != m_BaseSegments)
			{
				Cone->index(Offset + m_BaseSegments + 2);
				Cone->index(Offset);
				Cone->index(Offset + m_BaseSegments + 1);
				Cone->index(Offset + m_BaseSegments + 2);
				Cone->index(Offset + 1);
				Cone->index(Offset);
			}

			Offset++;
		}
	}

	int centerIndex = Offset;
	
	Cone->position(0,0,0);
	Cone->normal(Ogre::Vector3::NEGATIVE_UNIT_Y);
	Cone->textureCoord(0.0,1);
	Offset++;
	
	for (int BaseSegmentIndex=0; BaseSegmentIndex <= m_BaseSegments; BaseSegmentIndex++)
	{
		Ogre::Real x = m_Radius * cosf(BaseSegmentIndex*deltaAngle);
		Ogre::Real z = m_Radius * sinf(BaseSegmentIndex*deltaAngle);

		Cone->position(x, 0.0f, z);
		Cone->colour(Intensity, Intensity, 0.0, 0.0);
		Cone->normal(Ogre::Vector3::NEGATIVE_UNIT_Y);
		Cone->textureCoord(BaseSegmentIndex/(Ogre::Real)m_BaseSegments,0.0);
		if (BaseSegmentIndex != m_BaseSegments)
		{
			Cone->index(centerIndex);
			Cone->index(Offset);
			Cone->index(Offset+1);
		}
		Offset++;
	}

	Cone->end();

	return Cone;
}
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);
}
void CSceletalAnimationView::EngineSetup(void)
{
	Ogre::Root *Root = ((CSceletalAnimationApp*)AfxGetApp())->m_Engine->GetRoot();
	Ogre::SceneManager *SceneManager = NULL;
	SceneManager = Root->createSceneManager(Ogre::ST_GENERIC, "Animation");
 
    //
    // Create a render window
    // This window should be the current ChildView window using the externalWindowHandle
    // value pair option.
    //

    Ogre::NameValuePairList parms;
    parms["externalWindowHandle"] = Ogre::StringConverter::toString((long)m_hWnd);
    parms["vsync"] = "true";

	CRect   rect;
    GetClientRect(&rect);
	Ogre::RenderTarget *RenderWindow = Root->getRenderTarget("Mouse Input");

	if (RenderWindow == NULL)
	{
	try
	{
		m_RenderWindow = Root->createRenderWindow("Mouse Input", rect.Width(), rect.Height(), false, &parms);
	}
    catch(...)
	{
		MessageBox("Cannot initialize\nCheck that graphic-card driver is up-to-date", "Initialize Render System", MB_OK | MB_ICONSTOP);
		exit(EXIT_SUCCESS);
	}
	}
// Load resources
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    // Create the camera
    m_Camera = SceneManager->createCamera("Camera");
    m_Camera->setNearClipDistance(0.5);
	m_Camera->setFarClipDistance(5000); 
	m_Camera->setCastShadows(false);
	m_Camera->setUseRenderingDistance(true);
	m_Camera->setPosition(Ogre::Vector3(5.0, 5.0, 10.0));
	Ogre::SceneNode *CameraNode = NULL;
	CameraNode = SceneManager->getRootSceneNode()->createChildSceneNode("CameraNode");

	Ogre::Viewport* Viewport = NULL;
	
	if (0 == m_RenderWindow->getNumViewports())
	{
		Viewport = m_RenderWindow->addViewport(m_Camera);
		Viewport->setBackgroundColour(Ogre::ColourValue(0.8f, 0.8f, 0.8f));
	}

    // Alter the camera aspect ratio to match the viewport
    m_Camera->setAspectRatio(Ogre::Real(rect.Width()) / Ogre::Real(rect.Height()));
	m_Camera->lookAt(Ogre::Vector3(0.5, 0.5, 0.5));
	m_Camera->setPolygonMode(Ogre::PolygonMode::PM_WIREFRAME);

	Ogre::ManualObject* ManualObject = NULL;
	ManualObject = SceneManager->createManualObject("Animation");
	ManualObject->setDynamic(false);
    ManualObject->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
	//face 1
	ManualObject->position(0, 0, 0);//0
	ManualObject->position(1, 0, 0);//1
	ManualObject->position(1, 1, 0);//2
	ManualObject->triangle(0, 1, 2);//3
	
	ManualObject->position(0, 0, 0);//4
	ManualObject->position(1, 1, 0);//5
	ManualObject->position(0, 1, 0);//6
	ManualObject->triangle(3, 4, 5);//7
	//face 2
	ManualObject->position(0, 0, 1);//8
	ManualObject->position(1, 0, 1);//9
	ManualObject->position(1, 1, 1);//10
	ManualObject->triangle(6, 7, 8);//11

	ManualObject->position(0, 0, 1);//12
	ManualObject->position(1, 1, 1);//13
	ManualObject->position(0, 1, 1);//14
	ManualObject->triangle(9, 10, 11);//15
	//face 3
	ManualObject->position(0, 0, 0);//16
	ManualObject->position(1, 0, 0);//17
	ManualObject->position(1, 0, 1);//18
	ManualObject->triangle(12, 13, 14);//19

	ManualObject->position(0, 0, 0);
	ManualObject->position(1, 0, 1);
	ManualObject->position(0, 1, 1);
	ManualObject->triangle(15, 16, 17);
	//face 4
	ManualObject->position(1, 0, 0);
	ManualObject->position(1, 1, 0);
	ManualObject->position(1, 1, 1);
	ManualObject->triangle(18, 19, 20);

	ManualObject->position(1, 0, 0);
	ManualObject->position(1, 1, 1);
	ManualObject->position(1, 0, 1);
	ManualObject->triangle(21, 22, 23);
	//face 5
	ManualObject->position(0, 1, 0);
	ManualObject->position(1, 1, 0);
	ManualObject->position(0, 1, 1);
	ManualObject->triangle(24, 25, 26);

	ManualObject->position(1, 1, 0);
	ManualObject->position(1, 1, 1);
	ManualObject->position(0, 1, 1);
	ManualObject->triangle(27, 28, 29);
	
	//face 6
	ManualObject->position(0, 0, 0);
	ManualObject->position(0, 1, 1);
	ManualObject->position(0, 0, 1);
	ManualObject->triangle(30, 31, 32);

	ManualObject->position(0, 0, 0);
	ManualObject->position(0, 1, 0);
	ManualObject->position(0, 1, 1);
	ManualObject->triangle(33, 34, 35);

	ManualObject->end();
	Ogre::MeshPtr MeshPtr = ManualObject->convertToMesh("Animation");
	Ogre::SubMesh* sub = MeshPtr->getSubMesh(0);
	
	Ogre::SkeletonPtr Skeleton = Ogre::SkeletonManager::getSingleton().create("Skeleton", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	MeshPtr.getPointer()->_notifySkeleton(Skeleton);
	Ogre::Bone *Root1 = NULL;
	Ogre::Bone *Child1 = NULL;
	Ogre::Bone *Child2 = NULL;

	Root1 = Skeleton.getPointer()->createBone("Root");
	Root1->setPosition(Ogre::Vector3(0.0, 0.0, 0.0));
	Root1->setOrientation(Ogre::Quaternion::IDENTITY);
	
	Child1 = Root1->createChild(1);
	Child1->setPosition(Ogre::Vector3(4.0, 0.0, 0.0));
	Child1->setOrientation(Ogre::Quaternion::IDENTITY);
	Child2 = Root1->createChild(2);
	Child2->setPosition(Ogre::Vector3(5.0, 0.0, 0.0));
	Child2->setOrientation(Ogre::Quaternion::IDENTITY);

	Ogre::VertexBoneAssignment Assignment;

	Assignment.boneIndex = 0;
	Assignment.vertexIndex = 0;
	Assignment.weight = 1.0;
	Skeleton->setBindingPose();

	sub->addBoneAssignment(Assignment);

	Assignment.vertexIndex = 1;
	sub->addBoneAssignment(Assignment);

	Assignment.vertexIndex = 2;
	sub->addBoneAssignment(Assignment);

	Ogre::Animation *Animation = MeshPtr->createAnimation("HandAnimation", 100.0);
	Ogre::NodeAnimationTrack *Track = Animation->createNodeTrack(0, Root1);
	Ogre::TransformKeyFrame *KeyFrame = NULL;

	for (float FrameTime = 0.0; FrameTime < 100.0; FrameTime += 0.1)
	{
		KeyFrame = Track->createNodeKeyFrame(FrameTime);
		KeyFrame->setTranslate(Ogre::Vector3(10.0, 0.0, 0.0));
	}

	Root1->setManuallyControlled(true);
	Child1->setManuallyControlled(true);
	Child2->setManuallyControlled(true);
	MeshPtr->load();

	MeshPtr.getPointer()->_notifySkeleton(Skeleton);
		
//	Ogre::SkeletonSerializer skeletonSerializer;
//	skeletonSerializer.exportSkeleton(Skeleton.get(), "C:\\Users\\Ilya\\Documents\\Visual Studio 2010\\Projects\\Recipes\\media\\models\\testskeleton.skeleton");
//	Ogre::MeshSerializer ser;
//    ser.exportMesh(MeshPtr.get(), "C:\\Users\\Ilya\\Documents\\Visual Studio 2010\\Projects\\Recipes\\media\\models\\testskeleton.mesh");

	Ogre::Entity *Entity = SceneManager->createEntity("Animation", "Animation"/*"testskeleton.mesh"*/);
	Ogre::SceneNode *SceneNode = SceneManager->getRootSceneNode()->createChildSceneNode();
	SceneNode->attachObject(Entity);
	Entity->setDisplaySkeleton(true);

	m_AnimationState = Entity->getAnimationState("HandAnimation");
	m_AnimationState->setEnabled(true);
	m_AnimationState->setLoop(true);
	
	m_Camera->setPolygonMode(Ogre::PolygonMode::PM_WIREFRAME);
	 
	Root->renderOneFrame();
}
Beispiel #13
0
			// funcion donde se coloca lo que se desea desplegar.
			void createScene(){
								

				_sceneManager->setAmbientLight(Ogre::ColourValue(0.2,0.2,0.2));
				_sceneManager->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
				

			
				// LUZ
				

				Ogre::Light* LuzPuntual01 = _sceneManager->createLight("Luz01");
				LuzPuntual01->setType(Ogre::Light::LT_DIRECTIONAL);
				LuzPuntual01->setDiffuseColour(1.0,1.0,1.0);
				LuzPuntual01->setDirection(Ogre::Vector3( 1, -1, -1 ));

				Ogre::Light* LuzPuntual02 = _sceneManager->createLight("Luz02");
				LuzPuntual02->setType(Ogre::Light::LT_DIRECTIONAL);
				LuzPuntual02->setDiffuseColour(1.0,1.0,1.0);
				LuzPuntual02->setDirection(Ogre::Vector3( -1, -1, -1 ));



				//Chasis Carro
				_nodeChasisCarro = _sceneManager->createSceneNode("ChasisCarro");
				_sceneManager->getRootSceneNode()->addChild(_nodeChasisCarro);
				
				Ogre::Entity* _entChasisCarro = _sceneManager->createEntity("ChasisCarro", "chasisCarro.mesh");
				_nodeChasisCarro->attachObject(_entChasisCarro);



				/* Ruedas Izquierdas */
				_nodeRuedaSimple0 = _sceneManager->createSceneNode("RuedaSimple0");
				_sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple0);
			//	_nodeRuedaSimple00 = _nodeRuedaSimple0->createChildSceneNode("RuedaSimple00");
			//	_sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple00);

				Ogre::Entity* _entRuedaSimple0 = _sceneManager->createEntity("RuedaSimple0", "RuedaDetallada.mesh");
				_nodeRuedaSimple0->attachObject(_entRuedaSimple0);
			//	_nodeRuedaSimple00->attachObject(_entRuedaSimple0);

				_nodeRuedaSimple0->translate(9,3,5);


				_nodeRuedaSimple2 = _sceneManager->createSceneNode("RuedaSimple2");
				_sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple2);
			//	_nodeRuedaSimple22 = _nodeRuedaSimple2->createChildSceneNode("RuedaSimple22");
			//	_sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple22);
				
				Ogre::Entity* _entRuedaSimple2 = _sceneManager->createEntity("RuedaSimple2", "RuedaDetallada.mesh");
				_nodeRuedaSimple2->attachObject(_entRuedaSimple2);
			//	_nodeRuedaSimple22->attachObject(_entRuedaSimple2);

				_nodeRuedaSimple2->translate(9,3,-5);

				/* Ruedas Derechas */
				_nodeRuedaSimple1 = _sceneManager->createSceneNode("RuedaSimple1");
				_sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple1);
			//	_nodeRuedaSimple11 = _nodeRuedaSimple1->createChildSceneNode("RuedaSimple11");
			//	_sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple11);

				Ogre::Entity* _entRuedaSimple1 = _sceneManager->createEntity("RuedaSimple1", "RuedaDetallada.mesh");
				_nodeRuedaSimple1->attachObject(_entRuedaSimple1);
			//	_nodeRuedaSimple11->attachObject(_entRuedaSimple1);

				_nodeRuedaSimple1->translate(-7,3,5);


				_nodeRuedaSimple3 = _sceneManager->createSceneNode("RuedaSimple3");
				_sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple3);
			//	_nodeRuedaSimple33 = _nodeRuedaSimple3->createChildSceneNode("RuedaSimple33");
				//_sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple33);
				
				Ogre::Entity* _entRuedaSimple3 = _sceneManager->createEntity("RuedaSimple3", "RuedaDetallada.mesh");
				_nodeRuedaSimple3->attachObject(_entRuedaSimple3);
				//_nodeRuedaSimple33->attachObject(_entRuedaSimple3);

				_nodeRuedaSimple3->translate(-7,3,-5);


				/* ALA DERECHA INFERIOR

				Se crea el nodo padre de la nave llamado eje */
				eje = _sceneManager->getRootSceneNode()->createChildSceneNode("eje");

				padreDI = eje->createChildSceneNode("padreDI");

				Ogre::ManualObject* alad = _sceneManager->createManualObject("alad"); 

				alad->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN);
				alad->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0));

				alad->position(4.0, -0.5, 0.0);  
				alad->position(15.0, -0.5, 0.0); 
				alad->position(15.0, 0.0, 0.0);
				alad->position(5.0, 0.0, 0.0);

				alad->index(0);
				alad->index(1);
				alad->index(2);
				alad->index(3);
				alad->index(0);

				alad->end();
				padreDI->attachObject(alad);


				Ogre::ManualObject* alad2 = _sceneManager->createManualObject("alad2");
				alad2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN);
				alad2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0));
	
				alad2->position(5.0,  0.0, 0.0);  
				alad2->position(15.0,  0.0, 0.0); 
				alad2->position(14.0, 0.0, -3.0);
				alad2->position(5.0,  0.0, -4.0);

				alad2->index(0);
				alad2->index(1);
				alad2->index(2);
				alad2->index(3);
				alad2->index(0);

				alad2->end();
				padreDI->attachObject(alad2);

	
				/* ALA DERECHA SUPERIOR */

				padreDS = eje->createChildSceneNode("padreDS");

				Ogre::ManualObject* aladS = _sceneManager->createManualObject("aladS");
				aladS->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN);
				aladS->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0));

				aladS->position(4.0, 0.0, 0.0);  
				aladS->position(15.0, 0.0, 0.0); 
				aladS->position(15.0, 0.5, 0.0);
				aladS->position(5.0, 0.5, 0.0);

				aladS->index(0);
				aladS->index(1);
				aladS->index(2);
				aladS->index(3);
				aladS->index(0);

				aladS->end();
				padreDS->attachObject(aladS);


				Ogre::ManualObject* aladS2 = _sceneManager->createManualObject("aladS2");
				aladS2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN);
				aladS2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0));
	
				aladS2->position(5.0,  0.5, 0.0);  
				aladS2->position(15.0,  0.5, 0.0); 
				aladS2->position(14.0, 0.5, -3.0);
				aladS2->position(5.0,  0.5, -3.0);

				aladS2->index(0);
				aladS2->index(1);
				aladS2->index(2);
				aladS2->index(3);
				aladS2->index(0);

				aladS2->end();
				padreDS->attachObject(aladS2);



			/* ALA IZQUIERDA INFERIOR */

				padreII = eje->createChildSceneNode("padreII");

				Ogre::ManualObject* aladI = _sceneManager->createManualObject("aladI");
				aladI->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN);
				aladI->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0));

				aladI->position(-15.0, -0.5, 0.0);
				aladI->position(5.0, -0.5, 0.0);		
				aladI->position(-5.0, 0.0, 0.0);  
				aladI->position(-15.0, 0.0, 0.0); 


				aladI->index(0);
				aladI->index(1);
				aladI->index(2);
				aladI->index(3);
				aladI->index(0);

				aladI->end();
				padreII->attachObject(aladI);


				Ogre::ManualObject* aladI2 = _sceneManager->createManualObject("aladI2");
				aladI2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN);
				aladI2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0));
	
				aladI2->position(-15.0,  0.0, 0.0); 
				aladI2->position(-5.0,  0.0, 0.0);  
				aladI2->position(-5.0,  0.0, -4.0);
				aladI2->position(-14.0, 0.0, -3.0);



				aladI2->index(0);
				aladI2->index(1);
				aladI2->index(2);
				aladI2->index(3);
				aladI2->index(0);

				aladI2->end();
				padreII->attachObject(aladI2);


			/* ALA IZQUIERDA SUPERIOR */

				padreIS = eje->createChildSceneNode("padreIS");

				Ogre::ManualObject* aladIS = _sceneManager->createManualObject("aladIS");
				aladIS->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN);
				aladIS->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0));

				aladIS->position(-15.0, 0.0, 0.0);
				aladIS->position(5.0, 0.0, 0.0);		
				aladIS->position(-5.0, 0.5, 0.0);  
				aladIS->position(-15.0, 0.5, 0.0); 


				aladIS->index(0);
				aladIS->index(1);
				aladIS->index(2);
				aladIS->index(3);
				aladIS->index(0);

				aladIS->end();
				padreIS->attachObject(aladIS);


				Ogre::ManualObject* aladIS2 = _sceneManager->createManualObject("aladIS2");
				aladIS2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN);
				aladIS2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0));
	
				aladIS2->position(-15.0,  0.5, 0.0); 
				aladIS2->position(-5.0,  0.5, 0.0);  
				aladIS2->position(-5.0,  0.5, -3.0);
				aladIS2->position(-14.0, 0.5, -2.0);

				aladIS2->index(0);
				aladIS2->index(1);
				aladIS2->index(2);
				aladIS2->index(3);
				aladIS2->index(0);

				aladIS2->end();
				padreIS->attachObject(aladIS2);

				/* Rotaciones de las alas */
				eje->scale(2.5,2.5,2.5);
				eje->translate(0,5,0);
				eje->yaw(Ogre::Degree(180));

				/* Trasladar las alas */
				padreIS->translate(4,0,0);
				padreDS->translate(-4,0,0);
				padreDI->translate(-4,0,0);
				padreII->translate(4,0,0); 

				eje->scale(0.1,0.1,0.1);

				//BordePista
				Ogre::SceneNode* _nodeBPista = _sceneManager->createSceneNode("BordePista");
				_sceneManager->getRootSceneNode()->addChild(_nodeBPista);
				
				Ogre::Entity* _entBPista = _sceneManager->createEntity("BordePista", "bordePista02.mesh");
				_nodeBPista->attachObject(_entBPista);
				_entBPista->setMaterialName("Examples/pared");


				//PisoObstaculo
				Ogre::SceneNode* _nodePObstaculo = _sceneManager->createSceneNode("PistaObstaculo");
				_sceneManager->getRootSceneNode()->addChild(_nodePObstaculo);
				
				Ogre::Entity* _entPObstaculo = _sceneManager->createEntity("PistaObstaculo", "pisoObstaculo02.mesh");
				_nodePObstaculo->attachObject(_entPObstaculo);

				//PisoNOObstaculo
				Ogre::SceneNode* _nodePNObstaculo = _sceneManager->createSceneNode("PistaNoObstaculo");
				_sceneManager->getRootSceneNode()->addChild(_nodePNObstaculo);
				
				Ogre::Entity* _entPNOObstaculo = _sceneManager->createEntity("PistaNoObstaculo", "pisoNoObstaculo02.mesh");
				_nodePNObstaculo->attachObject(_entPNOObstaculo);
				_entPNOObstaculo->setMaterialName("Examples/piso");


				//PosterInicioFinal
				Ogre::SceneNode* _nodePoster = _sceneManager->createSceneNode("PosterInicioFinal");
				_sceneManager->getRootSceneNode()->addChild(_nodePoster);
				
				Ogre::Entity* _entPoster = _sceneManager->createEntity("PosterInicioFinal", "posterInicioFinal02.mesh");
				_nodePoster->attachObject(_entPoster);

				
				//BanderaInicial
				Ogre::SceneNode* _nodeBInicial = _sceneManager->createSceneNode("BanderaInicial");
				_sceneManager->getRootSceneNode()->addChild(_nodeBInicial);
				
				Ogre::Entity* _entBanderaI = _sceneManager->createEntity("BanderaInicial", "banderaInicial02.mesh");
				_nodeBInicial->attachObject(_entBanderaI);

				//BanderaFinal
				Ogre::SceneNode* _nodeBFinal = _sceneManager->createSceneNode("BanderaFinal");
				_sceneManager->getRootSceneNode()->addChild(_nodeBFinal);
				
				Ogre::Entity* _entBanderaF = _sceneManager->createEntity("BanderaFinal", "banderaFinal.mesh");
				_nodeBFinal->attachObject(_entBanderaF);

				_sceneManager->setSkyDome(true,"Examples/cielo",5,8);


			}
void CTransparentMaterialView::EngineSetup(void)
{
	Ogre::Root *Root = ((CTransparentMaterialApp*)AfxGetApp())->m_Engine->GetRoot();

	Ogre::SceneManager *SceneManager = NULL;

	SceneManager = Root->createSceneManager(Ogre::ST_GENERIC, "MFCOgre");

    //
    // Create a render window
    // This window should be the current ChildView window using the externalWindowHandle
    // value pair option.
    //

    Ogre::NameValuePairList parms;
    parms["externalWindowHandle"] = Ogre::StringConverter::toString((long)m_hWnd);
    parms["vsync"] = "true";

	CRect   rect;
    GetClientRect(&rect);

	Ogre::RenderTarget *RenderWindow = Root->getRenderTarget("Ogre in MFC");

	if (RenderWindow == NULL)
	{
	try
	{
		m_RenderWindow = Root->createRenderWindow("Ogre in MFC", rect.Width(), rect.Height(), false, &parms);
	}
    catch(...)
	{
		MessageBox("Cannot initialize\nCheck that graphic-card driver is up-to-date", "Initialize Render System", MB_OK | MB_ICONSTOP);
		exit(EXIT_SUCCESS);
	}
	}
// Load resources
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    // Create the camera
    m_Camera = SceneManager->createCamera("Camera");
    m_Camera->setNearClipDistance(0.5);
	m_Camera->setFarClipDistance(5000); 
	m_Camera->setCastShadows(false);
	m_Camera->setUseRenderingDistance(true);
	m_Camera->setPosition(Ogre::Vector3(320.0, 240.0, 500.0));
	Ogre::SceneNode *CameraNode = NULL;
	CameraNode = SceneManager->getRootSceneNode()->createChildSceneNode("CameraNode");

	Ogre::Viewport* Viewport = NULL;
	
	if (0 == m_RenderWindow->getNumViewports())
	{
		Viewport = m_RenderWindow->addViewport(m_Camera);
		Viewport->setBackgroundColour(Ogre::ColourValue(0.8f, 1.0f, 0.8f));
	}

    // Alter the camera aspect ratio to match the viewport
    m_Camera->setAspectRatio(Ogre::Real(rect.Width()) / Ogre::Real(rect.Height()));

	Ogre::ManualObject *Screen = SceneManager->createManualObject("Screen");
	Screen->setDynamic(true);
	Screen->begin("window", Ogre::RenderOperation::OT_TRIANGLE_LIST);

	Screen->position(-100,-100,50);
	Screen->textureCoord(0,0);

	Screen->position(300,-100,50);
	Screen->textureCoord(1,0);

	Screen->position(300,300,50);
	Screen->textureCoord(1,1);

	Screen->triangle(0, 1, 2);
		
	Screen->position(-100,-100,50);
	Screen->textureCoord(0,0);

	Screen->position(300,300,50);
	Screen->textureCoord(1,1);

	Screen->position(-100,300,50);
	Screen->textureCoord(0,1);

	Screen->triangle(3, 4, 5);
	 
	Screen->end();
	
	Ogre::Entity *RobotEntity = SceneManager->createEntity("Robot", "robot.mesh");
	Ogre::SceneNode *RobotNode = SceneManager->getRootSceneNode()->createChildSceneNode();
	RobotNode->attachObject(RobotEntity);

	Ogre::SceneNode *WindowNode = SceneManager->getRootSceneNode()->createChildSceneNode();
	WindowNode->attachObject(Screen);
}
/* ----------------------------------------------------------------------- 
 | build bullet height field shape and generate ogre mesh from grayscale image
 | 
 | @param in : 
 | @param out: raw data of height field terrain
 | ToDo: adjest grid scale, grid height, local scale, max/min height
   ----------------------------------------------------------------------- */
bool
buildHeightFieldTerrainFromImage(const Ogre::String& filename, 
                                 btDynamicsWorld* dynamicsWorld, 
                                 btAlignedObjectArray<btCollisionShape*>& collisionShapes,
                                 void* &data)
{
    Ogre::Image img;
    try
    {
        img.load(filename, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    }   
    catch(Ogre::Exception err)
    {
        LOG(err.what());
        return false;
    }
    
    size_t grid_w = 65, grid_h = 65; // must be (2^N) + 1
    size_t grid_max_w = 129, grid_max_h = 129; // must be (2^N) + 1
    size_t img_w = img.getWidth();
    size_t img_h = img.getHeight();
    
    // validate image size is (2^N) + 1
    if ((img_w-1) & (img_w-2)) img_w = grid_w; 
    if ((img_h-1) & (img_h-2)) img_h = grid_h;
    //if (img_w > grid_max_w) img_w = grid_max_w; 
    //if (img_h > grid_max_h) img_h = grid_max_h; 

    LOG("LoadImage name=%s, width=%d, height=%d, width^2+1=%d, height^2+1=%d",
        filename.c_str(), img.getWidth(), img.getHeight(), img_w, img_h);
    img.resize(img_w, img_h);

    size_t pixelSize = Ogre::PixelUtil::getNumElemBytes(img.getFormat());    
    size_t bufSize = img.getSize() / pixelSize;
    data = new Ogre::Real[ bufSize ];
    Ogre::Real* dest = static_cast<Ogre::Real*>(data);
    memset(dest, 0, bufSize);
        
    /*
     | @ Notice the alignment problem
     | - uchar to float alignment
     | - pixel format in bytes as rawdata type, also affects alignment
     */
    Ogre::uchar* src = img.getData();    
    for (size_t i=0;i<bufSize;++i)
    {        
        dest[i] = ((Ogre::Real)src[i * pixelSize] - 127.0f)/16.0f;
    }
          
    // parameter    
    int upAxis = 1;
    btScalar gridSpacing = 5.0f;
    btScalar gridHeightScale = 0.2f;
    btScalar minHeight = -10.0f;
    btScalar maxHeight = 10.0f;
    btScalar defaultContactProcessingThreshold = BT_LARGE_FLOAT;

	btHeightfieldTerrainShape *heightfieldShape =  
        new btHeightfieldTerrainShape(img_w, img_h,
                                      dest,
                                      gridHeightScale,
                                      minHeight, maxHeight,
                                      upAxis, PHY_FLOAT, false);
	btAssert(heightfieldShape && "null heightfield");

	// shape
	btVector3 localScaling(1.0f, 1.0f, 1.0f);
	heightfieldShape->setLocalScaling(localScaling);    
    collisionShapes.push_back(heightfieldShape);

    // rigidBody
    btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)));
    btRigidBody::btRigidBodyConstructionInfo cInfo(0, motionState, heightfieldShape, btVector3(0,0,0));
    btRigidBody* rigidBody = new btRigidBody(cInfo);        	
	rigidBody->setContactProcessingThreshold(defaultContactProcessingThreshold);
    int flags = rigidBody->getCollisionFlags();
    rigidBody->setCollisionFlags(flags | btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT);
    
    dynamicsWorld->addRigidBody(rigidBody);
    
    // add ogre height field mesh
    Ogre::SceneManager* sceneMgr = Ogre::Root::getSingletonPtr()->getSceneManager("DefaultSceneManager");
    btAssert(sceneMgr);
    
    Ogre::ManualObject* obj = sceneMgr->createManualObject("btHeightFieldEntity");

    btVector3 aabbMin, aabbMax;
    heightfieldShape->getAabb(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)), aabbMin, aabbMax);

    btHeightFieldProcessor callback(obj, "DefaultPlane");
    heightfieldShape->processAllTriangles(&callback, aabbMin, aabbMax);
   
    sceneMgr->getRootSceneNode()->attachObject(obj);

    return true;
}
void CGeoImageView::EngineSetup(void)
{
	Ogre::Root *Root = ((CGeoImageApp*)AfxGetApp())->m_Engine->GetRoot();

	Ogre::SceneManager *SceneManager = NULL;

	SceneManager = Root->createSceneManager(Ogre::ST_GENERIC, "MFCOgre");

    //
    // Create a render window
    // This window should be the current ChildView window using the externalWindowHandle
    // value pair option.
    //

    Ogre::NameValuePairList parms;
    parms["externalWindowHandle"] = Ogre::StringConverter::toString((long)m_hWnd);
    parms["vsync"] = "true";

	CRect   rect;
    GetClientRect(&rect);

	Ogre::RenderTarget *RenderWindow = Root->getRenderTarget("Ogre in MFC");

	if (RenderWindow == NULL)
	{
	try
	{
		m_RenderWindow = Root->createRenderWindow("Ogre in MFC", rect.Width(), rect.Height(), false, &parms);
	}
    catch(...)
	{
		MessageBox("Cannot initialize\nCheck that graphic-card driver is up-to-date", "Initialize Render System", MB_OK | MB_ICONSTOP);
		exit(EXIT_SUCCESS);
	}
	}
// Load resources
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    // Create the camera
    m_Camera = SceneManager->createCamera("Camera");
    m_Camera->setNearClipDistance(0.5);
	m_Camera->setFarClipDistance(5000); 
	m_Camera->setCastShadows(false);
	m_Camera->setUseRenderingDistance(true);
//	m_Camera->setPosition(Ogre::Vector3(320.0, 240.0, 500.0));
	Ogre::SceneNode *CameraNode = NULL;
	CameraNode = SceneManager->getRootSceneNode()->createChildSceneNode("CameraNode");

	Ogre::Viewport* Viewport = NULL;
	
	if (0 == m_RenderWindow->getNumViewports())
	{
		Viewport = m_RenderWindow->addViewport(m_Camera);
		Viewport->setBackgroundColour(Ogre::ColourValue(0.8f, 1.0f, 0.8f));
	}

    // Alter the camera aspect ratio to match the viewport
    m_Camera->setAspectRatio(Ogre::Real(rect.Width()) / Ogre::Real(rect.Height()));
		

	TIFF 	*Tif = (TIFF*)0;  /* TIFF-level descriptor */
  	GTIF	*GTif = (GTIF*)0; /* GeoKey-level descriptor */

	CString SourcePath = "C:\\Users\\Ilya\\Documents\\Visual Studio 2010\\Projects\\Recipes\\media\\materials\\textures\\o41078a1.tif";
 int ImageWidth;
 int ImageHeight;

 double LowerLeftX;
 double LowerLeftY;

 double UpperRightX;
 double UpperRightY;

 int Xpos;
 int Ypos;

	Tif = XTIFFOpen((LPCSTR)SourcePath, "r");
	GTif = GTIFNew(Tif);
 
	GTIFDefn Definition;
	GTIFGetDefn(GTif, &Definition);
 
	GTIFPrint(GTif, 0, 0);

	TIFFGetField( Tif, TIFFTAG_IMAGEWIDTH, &ImageWidth);
 	TIFFGetField( Tif, TIFFTAG_IMAGELENGTH, &ImageHeight);

int res = 0;

 double LowerRightX = ImageWidth;
 double LowerRightY = ImageHeight;

 res = GTIFImageToPCS(GTif, &LowerRightX, &LowerRightY);
  //Lower Left
 LowerLeftX = 0.0;
 LowerLeftY = ImageHeight;

 res = GTIFImageToPCS(GTif, &LowerLeftX, &LowerLeftY);

 //Upper Right
 UpperRightX = ImageWidth;
 UpperRightY = 0.0;

 res = GTIFImageToPCS(GTif, &UpperRightX, &UpperRightY);

 double UpperLeftX = 0.0;
 double UpperLeftY = 0.0;

 res = GTIFImageToPCS(GTif, &UpperLeftX, &UpperLeftY);

  	Ogre::ManualObject *Terrain = SceneManager->createManualObject("Terrain");
	Terrain->setDynamic(false);
	Terrain->begin("Terrain", Ogre::RenderOperation::OT_TRIANGLE_FAN);

#define MIN(x,y)     (((x) < (y)) ? (x) : (y))
#define MAX(x,y)     (((x) > (y)) ? (x) : (y))

#define SW     0
#define NW     1
#define NE     2
#define SE     3

FILE *File = NULL;
char            Dummy[160];
char inText[24];
 char *Dest;
	int             base[2048];         /* array of base elevations */
char            mapLabel[145];
int             DEMlevel, elevationPattern, groundSystem, groundZone;
double          projectParams[15];
int             planeUnitOfMeasure, elevUnitOfMeasure, polygonSizes;
double          groundCoords[4][2], elevBounds[2], localRotation;
int             accuracyCode;
double          spatialResolution[3];
int             profileDimension[2];
int             firstRow, lastRow;
int             wcount = 0;

double          verticalScale = 1.0;      /* to stretch or shrink elevations */
double          deltaY;
char *junk;

double eastMost;
double westMost;
double southMost;
double northMost;

int  eastMostSample;
int  westMostSample;
int southMostSample;
int northMostSample;

int        rowCount, columnCount, r, c;
int	rowStr = 1;
int rowEnd;
int colStr = 1;
int colEnd;
int colInt = 1;
int rowInt = 1;
int outType = 0;
 int k,l ;
 double comp = 0.0;

     int 	   mod ;
    int             tempInt, lastProfile = 0;

    float           noValue = 0.0f;
    int             profileID[2], profileSize[2];
    double          planCoords[2], localElevation, elevExtremea[2];


 File = fopen("C:\\Users\\Ilya\\Documents\\Visual Studio 2010\\Projects\\Recipes\\media\\geotiff\\karthaus_pa.dem", "r");

 fscanf(File, "%144c%6d%6d%6d%6d",
	     mapLabel,              /* 1 */
	     &DEMlevel,             /* 2 */
	     &elevationPattern,     /* 3 */
             &groundSystem,         /* 4 */
             &groundZone );         /* 5 */


    for (k=0; k<15 ; k++) 
	{
     fscanf(File,"%24c", inText);    /* 6 */
      Dest = strchr(inText,'D');  *Dest = 'E';
      projectParams[k]  = strtod(inText,&junk);
    }

    fscanf(File,"%6d%6d%6d",
             &planeUnitOfMeasure,   /* 7 */
             &elevUnitOfMeasure,    /* 8 */
             &polygonSizes);        /* 9 */

    for (k=0; k < 4 ; k++)
       for (l=0; l < 2 ; l++)
	   { 
        fscanf(File,"%24c", inText);    /* 6 */
        Dest = strchr(inText,'D');  *Dest = 'E';
        groundCoords[k][l]  = strtod(inText,&junk);
	   }

    fscanf(File,"%24c", inText);
    Dest = strchr(inText,'D');  *Dest = 'E';
    elevBounds[0] = strtod(inText,&junk);       /* 10 */
    fscanf(File,"%24c", inText);
    
	Dest = strchr(inText,'D');  *Dest = 'E';
    elevBounds[1] = strtod(inText,&junk);      /* 11 */
    fscanf(File,"%24c", inText);
    Dest = strchr(inText,'D');  *Dest = 'E';
    localRotation  = strtod(inText,&junk);      /* 12 */

   fscanf(File,"%1d%12le%12le%12le%6d%6d",
             &accuracyCode,             /* 13 */
	     &spatialResolution[0],     /* 14 */
             &spatialResolution[1],     /* 14 */
             &spatialResolution[2],     /* 14 */
             &profileDimension[0],      /* 15 */
             &profileDimension[1]);     /* 15 */

   fscanf(File, "%160c", Dummy);

    if (spatialResolution[0] == 3.0) 
	{
	 comp   = spatialResolution[0] - 1.0 ;
	 deltaY = spatialResolution[1] / 3600.  ;
    }
    else
	{
	 comp   = 0.;
	 deltaY = spatialResolution[1] ;
    }

    eastMost  = MAX(groundCoords[NE][0], groundCoords[SE][0]);
    westMost  = MIN(groundCoords[NW][0], groundCoords[SW][0]);
    northMost = MAX(groundCoords[NE][1], groundCoords[NW][1]);
    southMost = MIN(groundCoords[SW][1], groundCoords[SE][1]);
    eastMostSample =  ((int) (eastMost / spatialResolution[0]))
		     * (int) spatialResolution[0];
    westMostSample =  ((int) ((westMost + comp) / spatialResolution[0]))
		     * (int) spatialResolution[0] ;
    northMostSample = ((int) (northMost / spatialResolution[1]))
		     * (int) spatialResolution[1] ;
    southMostSample = ((int) ((southMost + comp) / spatialResolution[1]))
		     * (int) spatialResolution[1] ;
    
	columnCount = (eastMostSample  - westMostSample)
		  / (int) spatialResolution[0] + 1;
    rowCount    = (northMostSample - southMostSample)
		  / (int) spatialResolution[1] + 1;

    if (columnCount != profileDimension[1])
	  columnCount =MIN( profileDimension[1], columnCount);

for (c = 1; c <= columnCount; c++) 
 {
  fscanf(File, "%d%d%d%d",
		 &profileID[0],        /* 1 */
		 &profileID[1],        /* 1 */
		 &profileSize[0],      /* 2 */
		 &profileSize[1]);     /* 2 */

       fscanf(File,"%24c", inText);
       Dest = strchr(inText,'D');  *Dest = 'E';
       planCoords[0]   = strtod(inText,&junk);     /* 3 */
	  fscanf(File,"%24c", inText);
       Dest = strchr(inText,'D');  *Dest = 'E';
       planCoords[1]   = strtod(inText,&junk);     /* 3 */
	   fscanf(File,"%24c", inText);
       Dest = strchr(inText,'D');  *Dest = 'E';
       localElevation  = strtod(inText,&junk);     /* 4 */
	 fscanf(File,"%24c", inText);
       Dest = strchr(inText,'D');  *Dest = 'E';
       elevExtremea[0] = strtod(inText,&junk);     /* 5 */
	   fscanf(File,"%24c", inText);
       Dest = strchr(inText,'D');  *Dest = 'E';
       elevExtremea[1] = strtod(inText,&junk);     /* 5 */

       lastProfile =  profileID[1];

       firstRow = abs(((int) (planCoords[1] - southMostSample))
		 / (int) spatialResolution[1]);
       lastRow = firstRow + profileSize[0] - 1;

       for ( r = 0 ; r < firstRow  ; r++ ) 
		   base[r] = 0;

/*     read in all the data for this column */
       for (r = firstRow; r <= lastRow; r++ )
       {
	  fscanf(File, "%6d",	&tempInt);
	   base[r] = tempInt;
       }

    double          tempFloat;

   for (r = firstRow; r <= lastRow; r += rowInt) 
   {
    tempFloat = (float) base[r]  * verticalScale;
 	Terrain->position(planCoords[0], tempFloat, planCoords[1]);

	Ogre::Real u = 0.0;
	Ogre::Real v = 0.0;

	if (planCoords[0] > LowerLeftX && planCoords[0] < UpperRightX)
	{
		u = (planCoords[0] - LowerLeftX) / (UpperRightX - LowerLeftX);
	}

	if (planCoords[1] > LowerLeftY && planCoords[1] < UpperRightY)
	{
		v = (planCoords[1] - LowerLeftY) / (UpperRightY - LowerLeftY);
	}

	Terrain->textureCoord(u, v); 
	planCoords[1] += deltaY;
   }
 }

 Terrain->end();
 fclose(File);

	Ogre::SceneNode* node = SceneManager->getRootSceneNode()->createChildSceneNode();
	node->setPosition(0, 0, 0);
	node->attachObject(Terrain);

	Ogre::AxisAlignedBox Box = Terrain->getBoundingBox();
	Ogre::Vector3 Center = Box.getCenter();

	Ogre::Vector3 Target = Center;
	Ogre::Vector3 Position = Center;

	Position[1] += 5000.0;
	m_Camera->setPosition(Position);
	m_Camera->lookAt(Target);
}