int MyTerrain::GetSelectAreaID( Ogre::Ray ray )
{
    Ogre::TerrainGroup::RayResult result=m_pTerrainGroup->rayIntersects(ray);
    if(!result.hit)
        return -1;
    //m_pSceneMgr->getSceneNode("test")->setPosition(result.position);
    bool nosign=false;
    Ogre::Terrain* terrain = m_pTerrainGroup->getTerrain(0,0);


    int size= terrain->getLayerBlendMapSize();

    int x=result.position.x*m_EdgeImage.width()/(float)terrain->getWorldSize();
    int y=result.position.z*m_EdgeImage.height()/(float)terrain->getWorldSize();

    QRgb resultrgb=m_AreaImage.pixel(x,y);
    int gray=qGray(m_EdgeImage.pixel(x,y));
    if(gray!=255)
    {
        return -1;
    }
    else
    {
        int id=qGreen(resultrgb)*256+qBlue(resultrgb);
        if(id<65535)
            return id;
        else
            return -1;
    }
}
Ogre::Vector2 MyTerrain::GetWorldPointFromImagePoint( Ogre::Vector2 point )
{
    Ogre::Vector2 v;
    Ogre::Terrain* terrain = m_pTerrainGroup->getTerrain(0,0);
    v.x=point.x*m_EdgeImage.width()/(float)terrain->getWorldSize();
    v.y=point.y*m_EdgeImage.height()/(float)terrain->getWorldSize();
    return v;
}
void TerrainManager::CreatePhysicsShape(void)
{
    Ogre::TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
    while (ti.hasMoreElements())
    {
        Ogre::Terrain *t = ti.getNext()->instance;
        LoadTerrainGeometry(t->getMaterialName(), t->getHeightData(),
                            t->getSize(), t->getWorldSize(), t->getMinHeight(), t->getMaxHeight(), t->getPosition());
    }
}
Exemple #4
0
void Scene::createBulletTerrain() {
	Ogre::Terrain* baseTerrain = mTerrainGroup->getTerrain(0, 0);
	btHeightfieldTerrainShape* hfShape = new btHeightfieldTerrainShape(
			baseTerrain->getSize(), baseTerrain->getSize(), baseTerrain->getHeightData(), 1, 0, 0,
			2, PHY_FLOAT, false);
	// Min and max height were set to 0 to force the terrain to be completely flat
	hfShape->setUseDiamondSubdivision(true);

	// This scale is based on the tutorial, but it may not be true...
	float metersBetweenVerts = baseTerrain->getWorldSize() / (baseTerrain->getSize() - 1);
	btVector3 scale(metersBetweenVerts, metersBetweenVerts, 1);
	hfShape->setLocalScaling(scale);

	hfShape->setUserPointer((void*) SU_Terrain);

	btCollisionObject* colObj = new btCollisionObject();
	colObj->setCollisionShape(hfShape);
	colObj->setFriction(0.9); colObj->setRestitution(0.0);
	colObj->setCollisionFlags(colObj->getCollisionFlags() |
							  btCollisionObject::CF_STATIC_OBJECT |
							  btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT);
	mSim->getCollisionWorld()->getDynamicsWorld()->addCollisionObject(colObj);
	mSim->getCollisionWorld()->addShape(hfShape);

	// Border planes
	const float px[4] = {-1, 1, 0, 0};
	const float py[4] = { 0, 0,-1, 1};
	for (int i = 0; i < 4; ++i) {
		btVector3 vpl(px[i], py[i], 0);
		btCollisionShape* shp = new btStaticPlaneShape(vpl, 0);
		shp->setUserPointer((void*) SU_Border);

		btTransform tr;  tr.setIdentity();
		tr.setOrigin(vpl * -0.5 * worldSize);

		btCollisionObject* col = new btCollisionObject();
		col->setCollisionShape(shp);
		col->setWorldTransform(tr);
		col->setFriction(0.3);   //+
		col->setRestitution(0.0);
		col->setCollisionFlags(col->getCollisionFlags() |
							   btCollisionObject::CF_STATIC_OBJECT |
							   btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT);

		mSim->getCollisionWorld()->getDynamicsWorld()->addCollisionObject(col);
		mSim->getCollisionWorld()->addShape(shp);
	}
}
float MyTerrain::GetImageYFromWorldY( float y )
{
    Ogre::Terrain* terrain = m_pTerrainGroup->getTerrain(0,0);
    return y*m_EdgeImage.height()/(float)terrain->getWorldSize();
}
float MyTerrain::GetImageXFromWorldX( float x )
{
    Ogre::Terrain* terrain = m_pTerrainGroup->getTerrain(0,0);
    return x*m_EdgeImage.width()/(float)terrain->getWorldSize();
}