예제 #1
0
 void RenderSystem::RenderPoint3DSet(std::string psName, std::string psMaterialName, const MagicDGP::Point3DSet* pPS)
 {
     Ogre::ManualObject* pMObj = NULL;
     if (mpSceneMgr->hasManualObject(psName))
     {
         pMObj = mpSceneMgr->getManualObject(psName);
         pMObj->clear();
     }
     else
     {
         pMObj = mpSceneMgr->createManualObject(psName);
         if (mpSceneMgr->hasSceneNode("ModelNode"))
         {
             mpSceneMgr->getSceneNode("ModelNode")->attachObject(pMObj);
         }
         else
         {
             mpSceneMgr->getRootSceneNode()->createChildSceneNode("ModelNode")->attachObject(pMObj);
         }
     }
     if (pPS->HasNormal())
     {
         int pointNum = pPS->GetPointNumber();
         pMObj->begin(psMaterialName, Ogre::RenderOperation::OT_POINT_LIST);
         for (int i = 0; i < pointNum; i++)
         {
             const MagicDGP::Point3D* pPoint = pPS->GetPoint(i);
             if (pPoint->IsValid() == false)
             {
                 continue;
             }
             MagicMath::Vector3 pos = pPoint->GetPosition();
             MagicMath::Vector3 nor = pPoint->GetNormal();
             MagicMath::Vector3 color = pPoint->GetColor();
             pMObj->position(pos[0], pos[1], pos[2]);
             pMObj->normal(nor[0], nor[1], nor[2]);
             pMObj->colour(color[0], color[1], color[2]);
         }
         pMObj->end();
     }
     else
     {
         int pointNum = pPS->GetPointNumber();
         pMObj->begin(psMaterialName, Ogre::RenderOperation::OT_POINT_LIST);
         for (int i = 0; i < pointNum; i++)
         {
             const MagicDGP::Point3D* pPoint = pPS->GetPoint(i);
             if (pPoint->IsValid() == false)
             {
                 continue;
             }
             MagicMath::Vector3 pos = pPoint->GetPosition();
             MagicMath::Vector3 color = pPoint->GetColor();
             pMObj->position(pos[0], pos[1], pos[2]);
             pMObj->colour(color[0], color[1], color[2]);
         }
         pMObj->end();
     }
     
 }
예제 #2
0
//-------------------------------------------------------
Ogre::MeshPtr Ground::CreateRegion(size_t id, const std::string & material, const Ogre::Box & roi, const Ogre::Vector3 & offset, const Ogre::Vector3 & steps, const Ogre::Vector2 & texOffset)
{
    assert(mSceneManager != nullptr);

    Ogre::ManualObject* object = mSceneManager->createManualObject();
    object->begin(material, Ogre::RenderOperation::OT_TRIANGLE_LIST);
    {
        size_t lastIdx = 0;
        for (size_t y = 0; y < REGION_SIZE; ++y)
        {
            size_t texY = static_cast<size_t>(static_cast<float>(y) / REGION_SIZE * (roi.getHeight() - 1));
            size_t texYn = static_cast<size_t>(static_cast<float>(y + 1) / REGION_SIZE * (roi.getHeight() - 1));

            //Flip texture vertically
            texY  = roi.getHeight() - 1 - texY;
            texYn = roi.getHeight() - 1 - texYn;

            float texCrdT = texOffset[1] + static_cast<float>(texY) / (mImage->getHeight() - 1);
            float texCrdTn = texOffset[1] + static_cast<float>(texYn) / (mImage->getHeight() - 1);

            for (size_t x = 0; x < REGION_SIZE; ++x)
            {
                size_t texX = static_cast<size_t>(static_cast<float>(x) / REGION_SIZE * (roi.getWidth() - 1));
                size_t texXn = static_cast<size_t>(static_cast<float>(x + 1) / REGION_SIZE * (roi.getWidth() - 1));

                float texCrdS = texOffset[0] + static_cast<float>(texX) / (mImage->getWidth() - 1);
                float texCrdSn = texOffset[0] + static_cast<float>(texXn) / (mImage->getWidth() - 1);

                float h00 = mImage->getColourAt(roi.left + texX,  roi.top + texY, 0)[0];
                float h10 = mImage->getColourAt(roi.left + texXn, roi.top + texY, 0)[0];
                float h01 = mImage->getColourAt(roi.left + texX,  roi.top + texYn, 0)[0];
                float h11 = mImage->getColourAt(roi.left + texXn, roi.top + texYn, 0)[0];

                object->position(x * steps[0] + offset[0], y * steps[1] + offset[1], h00 * steps[2]);
                object->textureCoord(texCrdS, texCrdT);
                object->colour(h00, h00, h00);
                
                object->position((x + 1) * steps[0] + offset[0], y * steps[1] + offset[1], h10 * steps[2]);
                object->textureCoord(texCrdSn, texCrdT);
                object->colour(h10, h10, h10);

                object->position(x * steps[0] + offset[0], (y + 1) * steps[1] + offset[1], h01 * steps[2]);
                object->textureCoord(texCrdS, texCrdTn);
                object->colour(h01, h01, h01);

                object->position((x + 1) * steps[0] + offset[0], (y + 1) * steps[1] + offset[1], h11 * steps[2]);
                object->textureCoord(texCrdSn, texCrdTn);
                object->colour(h11, h11, h11);

                object->triangle(lastIdx + 1, lastIdx + 2, lastIdx);
                object->triangle(lastIdx + 3, lastIdx + 2, lastIdx + 1);
                lastIdx += 4;
            }
        }
    }
    object->end();
    return object->convertToMesh("Mesh/" + CLASS_NAME  + "/" + mName + "/" + std::to_string(id));
}
void Chart::indicator(const Ogre::Real chartX, const Ogre::Real chartY)
{
	const std::string chartXString = Ogre::StringConverter::toString(chartX).substr(0, std::min(Ogre::StringConverter::toString(chartX).size(), (std::string::size_type)4));
	const std::string chartYString = Ogre::StringConverter::toString(chartY).substr(0, std::min(Ogre::StringConverter::toString(chartY).size(), (std::string::size_type)3));
	const Ogre::Vector3 x = chartToScreen( Ogre::Vector2(chartX, mMin.y) );
	const Ogre::Vector3 y = chartToScreen( Ogre::Vector2(mMin.x, chartY) );
	const Ogre::ColourValue magenta(1,0,1);

	// indicator
    Ogre::ManualObject *chartIndicator = mSceneMgr->createManualObject();
    chartIndicator->setUseIdentityProjection(true);
    chartIndicator->setUseIdentityView(true);
    chartIndicator->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
    chartIndicator->setBoundingBox(Ogre::AxisAlignedBox::BOX_INFINITE);
    chartIndicator->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);
    chartIndicator->position( x );
	chartIndicator->colour( magenta );
    chartIndicator->position( chartToScreen( Ogre::Vector2(chartX, chartY) ) );
	chartIndicator->colour( magenta );
    chartIndicator->position( y );
	chartIndicator->colour( magenta );
    chartIndicator->end();

	// text of values on the sides of the axes
	if(first)
	{
		TextRenderer::getSingleton().addTextBox("txt6" + rndIDString, chartXString, x.x - 0.01 * chartXString.size(), x.y - 0.035, 20, 20, magenta);
		TextRenderer::getSingleton().addTextBox("txt7" + rndIDString, chartYString, y.x - 0.035 - 0.01 * chartYString.size(), y.y - 0.0025, 20, 20, magenta);
		first = false;
	} 
	else
	{
		TextRenderer::getSingleton().removeTextBox("txt6" + rndIDString);
		TextRenderer::getSingleton().removeTextBox("txt7" + rndIDString);
		TextRenderer::getSingleton().addTextBox("txt6" + rndIDString, chartXString, x.x - 0.01 * chartXString.size(), x.y - 0.035, 20, 20, magenta);
		TextRenderer::getSingleton().addTextBox("txt7" + rndIDString, chartYString, y.x - 0.035 - 0.01 * chartYString.size(), y.y - 0.0025, 20, 20, magenta);
	}

    if (mChartIndicator)
    {
        mChartSceneNode->detachObject(mChartIndicator);
        mSceneMgr->destroyManualObject(mChartIndicator);
    }
    mChartIndicator = chartIndicator;
    mChartSceneNode->attachObject(mChartIndicator);

    mChartSceneNode->needUpdate();
}
예제 #4
0
static void BuildCellLines(
    Ogre::ManualObject& manualObject,
    const float cellWidth,
    const float cellHeight,
    const Ogre::Vector3& minBoundary,
    const Ogre::ColourValue& color,
    const size_t xOffset,
    const size_t yOffset,
    const size_t zOffset)
{
    const unsigned int vertexCount =
        static_cast<unsigned int>(manualObject.getCurrentVertexCount());

    const Ogre::Vector3 offset = minBoundary +
        Ogre::Vector3(
        xOffset * cellWidth, yOffset * cellHeight, zOffset * cellWidth);

    manualObject.position(offset);
    manualObject.colour(color);

    manualObject.position(offset + Ogre::Vector3(cellWidth, 0, 0));
    manualObject.colour(color);

    manualObject.position(offset + Ogre::Vector3(0, 0, cellWidth));
    manualObject.colour(color);

    manualObject.position(offset + Ogre::Vector3(cellWidth, 0, cellWidth));
    manualObject.colour(color);

    manualObject.index(vertexCount);
    manualObject.index(vertexCount + 1);

    manualObject.index(vertexCount);
    manualObject.index(vertexCount + 2);

    manualObject.index(vertexCount + 2);
    manualObject.index(vertexCount + 3);

    manualObject.index(vertexCount + 1);
    manualObject.index(vertexCount + 3);
}
void ParticleFactory::CreateExplosionParticleGeometry(Ogre::String object_name, int num_particles){

		/* Retrieve scene manager and root scene node */
        //Ogre::SceneManager* scene_manager = ogre_root_->getSceneManager("MySceneManager");
        Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode();

        /* Create the 3D object */
        Ogre::ManualObject* object = NULL;
        object = scene_manager->createManualObject(object_name);
        object->setDynamic(false);

        /* Create point list for the object */
		object->begin("", Ogre::RenderOperation::OT_POINT_LIST);

		/* Initialize random numbers */
		std::srand(std::time(0));

		/* Create a set of points which will be the particles */
		/* This is similar to drawing a sphere: we will sample points on a sphere, but will allow them to also
		   deviate a bit from the sphere along the normal (change of radius) */
		float trad = 0.04; // Defines the starting point of the particles
        float maxspray = 0.01; // This is how much we allow the points to deviate from the sphere
		float u, v, w, theta, phi, spray; // Work variables
		for (int i = 0; i < num_particles; i++){
			
			// Randomly select three numbers to define a point in spherical coordinates
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
            w = ((double) rand() / (RAND_MAX));

			// Use u to define the angle theta along one direction of a sphere
            theta = u * 2.0 * 3.1416;
			// Use v to define the angle phi along the other direction of the sphere
			phi = acos(2.0*v - 1.0);
			// Use we to define how much we can deviate from the surface of the sphere (change of radius)
            spray = maxspray*pow((float) w, (float) (1.0/3.0)); // Cubic root of w

			// Define the normal and point based on theta, phi and the spray
            Ogre::Vector3 normal = Ogre::Vector3(spray*cos(theta)*sin(phi), spray*sin(theta)*sin(phi), spray*cos(phi));
			object->position(normal.x*trad, normal.y*trad, normal.z*trad);
			object->normal(normal);
			object->colour(Ogre::ColourValue(i/(float) num_particles, 0.0, 1.0 - (i/(float) num_particles))); // We can use the color for debug, if needed
		}
		
		/* We finished the object */
        object->end();
		
        /* Convert triangle list to a mesh */
        object->convertToMesh(object_name);

}
예제 #6
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;
    }
예제 #7
0
 void RenderSystem::RenderMesh3D(std::string meshName, std::string materialName, const MagicDGP::Mesh3D* pMesh)
 {
     InfoLog << "RenderSystem::RenderMesh3D" << std::endl;
     Ogre::ManualObject* pMObj = NULL;
     if (mpSceneMgr->hasManualObject(meshName))
     {
         pMObj = mpSceneMgr->getManualObject(meshName);
         pMObj->clear();
     }
     else
     {
         pMObj = mpSceneMgr->createManualObject(meshName);
         if (mpSceneMgr->hasSceneNode("ModelNode"))
         {
             mpSceneMgr->getSceneNode("ModelNode")->attachObject(pMObj);
         }
         else
         {
             mpSceneMgr->getRootSceneNode()->createChildSceneNode("ModelNode")->attachObject(pMObj);
         }
     }
     pMObj->begin(materialName, Ogre::RenderOperation::OT_TRIANGLE_LIST);
     int vertNum = pMesh->GetVertexNumber();
     for (int i = 0; i < vertNum; i++)
     {
         const MagicDGP::Vertex3D* pVert = pMesh->GetVertex(i);
         MagicMath::Vector3 pos = pVert->GetPosition();
         MagicMath::Vector3 nor = pVert->GetNormal();
         MagicMath::Vector3 color = pVert->GetColor();
         pMObj->position(pos[0], pos[1], pos[2]);
         pMObj->normal(nor[0], nor[1], nor[2]);
         pMObj->colour(color[0], color[1], color[2]);
     }
     int faceNum = pMesh->GetFaceNumber();
     for (int i = 0; i < faceNum; i++)
     {
         if (pMesh->GetFace(i)->IsValid())
         {
             const MagicDGP::Edge3D* pEdge = pMesh->GetFace(i)->GetEdge();
             pMObj->triangle(pEdge->GetVertex()->GetId(), pEdge->GetNext()->GetVertex()->GetId(), pEdge->GetPre()->GetVertex()->GetId());
         }
     }
     pMObj->end();
 }
예제 #8
0
void BasicWindow::addAxesLines(float length) {	
	Ogre::ManualObject* mo = mSceneMgr->createManualObject("axesLines");
	mo->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
	mo->position(-length,0,0);				   //<- 0
	mo->colour(Ogre::ColourValue::Red);
	mo->position(length,0,0);                  //<- 1
	mo->colour(Ogre::ColourValue::Red);
	mo->position(0,-length,0);                 //<- 2
	mo->colour(Ogre::ColourValue::Green);
	mo->position(0,length,0);                  //<- 3
	mo->colour(Ogre::ColourValue::Green);
	mo->position(0,0,-length);                 //<- 4
	mo->colour(Ogre::ColourValue::Blue);   
	mo->position(0,0,length);                  //<- 5
	mo->colour(Ogre::ColourValue::Blue);
	mo->index(0);
	mo->index(1);
	mo->index(2);
	mo->index(3);
	mo->index(4);
	mo->index(5);
	mo->end();
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(mo);
}
Ogre::SceneNode * Chart::attachTo(Ogre::SceneManager &sceneMgr)
{
    mSceneMgr = &sceneMgr;

    if (mLineNames.size() < 3)
    {
        OGRE_EXCEPT(Ogre::Exception::ERR_INVALID_STATE, "I need exactly three line names. Yeah, it\'s hardcoded ;)", "Chart::attachTo()");
    }

    Ogre::LogManager::getSingletonPtr()->logMessage("mpoints: " + Ogre::StringConverter::toString(mPoints.size()));
    Ogre::LogManager::getSingletonPtr()->logMessage("msize: " + Ogre::StringConverter::toString(mSize));
    Ogre::LogManager::getSingletonPtr()->logMessage("mchartunitstep: " + Ogre::StringConverter::toString(mChartUnitStep));
    Ogre::LogManager::getSingletonPtr()->logMessage("mmax: " + Ogre::StringConverter::toString(mMax));
    Ogre::LogManager::getSingletonPtr()->logMessage("mmin: " + Ogre::StringConverter::toString(mMin));

    // chart quad bg
    Ogre::ManualObject *chartQuad = sceneMgr.createManualObject();
    chartQuad->setUseIdentityProjection(true);
    chartQuad->setUseIdentityView(true);
    chartQuad->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
    chartQuad->setBoundingBox(Ogre::AxisAlignedBox::BOX_INFINITE);
    chartQuad->begin("Chart/Background", Ogre::RenderOperation::OT_TRIANGLE_LIST);
    chartQuad->position(mOffset.x, mOffset.y, 0.5);
    chartQuad->position(mOffset.x + mSize.x, mOffset.y, 0.5);
    chartQuad->position(mOffset.x + mSize.x, mOffset.y + mSize.y, 0.5);
    chartQuad->position(mOffset.x, mOffset.y + mSize.y, 0.5);
    chartQuad->position(mOffset.x, mOffset.y, 0.5);
    chartQuad->position(mOffset.x + mSize.x, mOffset.y + mSize.y, 0.5);
    chartQuad->end();

    // chart y axis
    Ogre::ManualObject *chartAxisY = sceneMgr.createManualObject();
    chartAxisY->setUseIdentityProjection(true);
    chartAxisY->setUseIdentityView(true);
    chartAxisY->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
    chartAxisY->setBoundingBox(Ogre::AxisAlignedBox::BOX_INFINITE);
    chartAxisY->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
    chartAxisY->position(mOffset.x + mPadding.x, mOffset.y + mSize.y - 0.02, 0.0);
	chartAxisY->colour( 0.7, 0.7, 0.7 );
    chartAxisY->position(mOffset.x + mPadding.x, mOffset.y + 0.02, 0.0);
	chartAxisY->colour( 0.7, 0.7, 0.7 );
    chartAxisY->end();

    // chart x axis
    Ogre::ManualObject *chartAxisX = sceneMgr.createManualObject();
    chartAxisX->setUseIdentityProjection(true);
    chartAxisX->setUseIdentityView(true);
    chartAxisX->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
    chartAxisX->setBoundingBox(Ogre::AxisAlignedBox::BOX_INFINITE);
    chartAxisX->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
    chartAxisX->position(mOffset.x + 0.02, mOffset.y + mPadding.y, 0.0);
	chartAxisX->colour( 0.7, 0.7, 0.7 );
    chartAxisX->position(mOffset.x + mSize.x - 0.02, mOffset.y + mPadding.y, 0.0);
	chartAxisX->colour( 0.7, 0.7, 0.7 );
    chartAxisX->end();

    // lines
    const Ogre::ColourValue colours[] = { Ogre::ColourValue(1.0, 0.2, 0.2),
                                          Ogre::ColourValue(0.0, 0.9, 0.0),
                                          Ogre::ColourValue(0.2, 0.2, 1.0) };

    Ogre::ManualObject *lines = sceneMgr.createManualObject();
    lines->setUseIdentityProjection(true);
    lines->setUseIdentityView(true);
    lines->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
    lines->setBoundingBox(Ogre::AxisAlignedBox::BOX_INFINITE);
    lines->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);
    for (std::vector<ChartPointsVector>::const_iterator it = mPoints.begin(); it != mPoints.end(); ++it)
    {
        for (ChartPointsVector::const_iterator jt = it->begin(); jt != it->end(); ++jt)
        {
            lines->position(chartToScreen(*jt));
            lines->colour(colours[it - mPoints.begin()]);
        }
    }
    lines->end();

	// caption text
	const Ogre::Real rndID = Ogre::Math::RangeRandom(0, 9999999999) + Ogre::Math::RangeRandom(0, 9999999999);
	TextRenderer::getSingleton().addTextBox("txt0" + Ogre::StringConverter::toString(rndID+ Ogre::Math::RangeRandom(0, 999999)), mCaption, mOffset.x + mSize.x * 0.40, mOffset.y + mSize.y, 100, 20, Ogre::ColourValue::Black);

    // text above the lines	
    TextRenderer::getSingleton().addTextBox("txt1" + Ogre::StringConverter::toString(rndID+ Ogre::Math::RangeRandom(0, 999999)), mLineNames[0], mOffset.x + mPadding.x + 0.0025, mOffset.y + mSize.y - mPadding.y + 0.04, 100, 20, colours[0]);
    TextRenderer::getSingleton().addTextBox("txt2" + Ogre::StringConverter::toString(rndID+ Ogre::Math::RangeRandom(0, 999999)), mLineNames[1], mOffset.x + mPadding.x + 0.0025 + (mSize.x - mPadding.x * 2.0) * 0.35, mOffset.y + mSize.y - mPadding.y + 0.04, 100, 20, colours[1]);
    TextRenderer::getSingleton().addTextBox("txt3" + Ogre::StringConverter::toString(rndID+ Ogre::Math::RangeRandom(0, 999999)), mLineNames[2], mOffset.x + mPadding.x + 0.0025 + (mSize.x - mPadding.x * 2.0) * 0.75, mOffset.y + mSize.y - mPadding.y + 0.04, 100, 20, colours[2]);

    // text on y axis (1)
    TextRenderer::getSingleton().addTextBox("txt4" + Ogre::StringConverter::toString(rndID+ Ogre::Math::RangeRandom(0, 999999)), "1", mOffset.x + mPadding.x - 0.02, mOffset.y + mSize.y - mPadding.y, 20, 20, Ogre::ColourValue::Black);

    // text on x axis
	Ogre::Real rndID2 = Ogre::Math::RangeRandom(0, 9999999999) + Ogre::Math::RangeRandom(0, 9999999999);
    for (std::vector<ChartPointsVector>::const_iterator it = mPoints.begin(); it != mPoints.end(); ++it)
    {
		Ogre::Real rndID3 = Ogre::Math::RangeRandom(0, 9999999999) + Ogre::Math::RangeRandom(0, 9999999999);
        for (ChartPointsVector::const_iterator jt = it->begin(); jt != it->end(); ++jt)
        {
            const Ogre::Real rndID4 = Ogre::Math::RangeRandom(0, 9999999999) + Ogre::Math::RangeRandom(0, 9999999999);
            const Ogre::Vector3 chartVec = chartToScreen(*jt);
			const std::string xString = Ogre::StringConverter::toString(jt->x).substr(0, std::min(Ogre::StringConverter::toString(jt->x).size(), (std::string::size_type)3));

            TextRenderer::getSingleton().addTextBox("txt100" + Ogre::StringConverter::toString(rndID2) + Ogre::StringConverter::toString(rndID3) + Ogre::StringConverter::toString(rndID4), xString, chartVec.x - 0.01 * xString.size(), mOffset.y + mPadding.y - 0.0025, 20, 20, Ogre::ColourValue::Black);
        }
    }

    mChartSceneNode = sceneMgr.getRootSceneNode()->createChildSceneNode();
    mChartSceneNode->attachObject(chartQuad);
    mChartSceneNode->attachObject(chartAxisY);
    mChartSceneNode->attachObject(chartAxisX);
    mChartSceneNode->attachObject(lines);

	setVisible(false);

    return mChartSceneNode;
}
예제 #10
0
void CubeWorld::createChunkWater (const int StartX, const int StartY, const int StartZ)
{
	block_t LastBlock = 0;

	int iVertex = 0;
	block_t Block;
	block_t Block1;

	/* Only create visible faces of chunk */
	block_t DefaultBlock = 1;
	int SX = 0;
	int SY = 0;
	int SZ = 0;
	int MaxSize = WORLD_SIZE;

	float BlockLight;
	float BlockLight1;
	float BlockLight2;

	float V1, V2;

	Ogre::ManualObject* MeshChunk = new Ogre::ManualObject("MeshWaterChunk" + Ogre::StringConverter::toString(m_ChunkID));
	MeshChunk->setDynamic(true);
	MeshChunk->begin("WaterTest");

	for (int z = StartZ; z < CHUNK_SIZE + StartZ; ++z)
	{
		for (int y = StartY; y < CHUNK_SIZE + StartY; ++y)
		{
			for (int x = StartX; x < CHUNK_SIZE + StartX; ++x)
			{
				Block = GetBlock(x,y,z);
				if (Block != 5) continue;   //Only create water meshes


				BlockLight  = GetBlockLight(x, y, z) / 255.0f;
				BlockLight1 = BlockLight * 0.9f;
				BlockLight2 = BlockLight * 0.8f;


				V1 = 1.0f/5.0f * (float)(Block - 1);
				V2 = V1 + 1.0f/5.0f;

				//x-1
				Block1 = DefaultBlock;
				if (x > SX) Block1 = GetBlock(x-1,y,z);

				if (Block1 != 5)
				{
                                        //create face of block
					MeshChunk->position(x, y,   z+1); MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					MeshChunk->position(x, y+1, z+1); MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					MeshChunk->position(x, y+1, z);	  MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					MeshChunk->position(x, y,   z);	  MeshChunk->normal(-1,0,0);	MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight, BlockLight, BlockLight);

					MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					iVertex += 4;
                                }

				//x+1
				Block1 = DefaultBlock;
				if (x < SX + MaxSize - 1)
					Block1 = GetBlock(x+1,y,z);

				if (Block1 != 5)
				    {
					    MeshChunk->position(x+1, y,   z);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					    MeshChunk->position(x+1, y+1, z);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					    MeshChunk->position(x+1, y+1, z+1);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight, BlockLight, BlockLight);
					    MeshChunk->position(x+1, y,   z+1);	MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight, BlockLight, BlockLight);

					    MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					    MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					    iVertex += 4;
				    }

				//y-1
				Block1 = DefaultBlock;
				if (y > SY)
					Block1 = GetBlock(x,y-1,z);

				if (Block1 != 5)
				    {
					    MeshChunk->position(x,   y, z);		MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x+1, y, z);		MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x+1, y, z+1);	MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x,   y, z+1);	MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);

					    MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					    MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					    iVertex += 4;
				    }


				//y+1
				Block1 = DefaultBlock;
				if (y < SY + MaxSize - 1)
					Block1 = GetBlock(x,y+1,z);

				if (Block1 != 5)
				    {
					    MeshChunk->position(x,   y+1, z+1);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x+1, y+1, z+1);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x+1, y+1, z);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);
					    MeshChunk->position(x,   y+1, z);		MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight2, BlockLight2, BlockLight2);

					    MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					    MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					    iVertex += 4;
				    }

				//z-1
				Block1 = DefaultBlock;
				if (z > SZ)
					Block1 = GetBlock(x,y,z-1);

				if (Block1 != 5)
				    {
					    MeshChunk->position(x,   y+1, z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x+1, y+1, z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x+1, y,   z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x,   y,   z);		MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);

					    MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					    MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					    iVertex += 4;
				    }


				//z+1
				Block1 = DefaultBlock;
				if (z < SZ + MaxSize - 1)
					Block1 = GetBlock(x,y,z+1);

				if (Block1 != 5)
				    {
					    MeshChunk->position(x,   y,   z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V2); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x+1, y,   z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V2); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x+1, y+1, z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V1); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);
					    MeshChunk->position(x,   y+1, z+1);		MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V1); MeshChunk->colour(BlockLight1, BlockLight1, BlockLight1);

					    MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
					    MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

					    iVertex += 4;
				    }
			}
		}
	}
	MeshChunk->end();
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(MeshChunk);
	++m_ChunkID;

}
예제 #11
0
void AssetLoader::readModel(Ogre::SceneManager* sceneMgr, Ogre::SceneNode* scnNode, const aiScene* scene, aiNode* nd)
{
	for (size_t n = 0; n < nd->mNumChildren; n++) 
	{	
		aiNode* cnd = nd->mChildren[n];
		Ogre::SceneNode* cnode = createChildSceneNodeWithTransform(scnNode, cnd);

		for (size_t i = 0; i < cnd->mNumMeshes; i++) {
			aiMesh* m = scene->mMeshes[cnd->mMeshes[i]];	
			aiMaterial* mat = scene->mMaterials[m->mMaterialIndex];

			std::string nodeName = getFullPathName(cnd);
			Ogre::MaterialPtr omat = createMaterial(Ogre::String(nodeName), m->mMaterialIndex, mat);

			aiVector3D* vec  = m->mVertices;
			aiVector3D* norm = m->mNormals;
			aiVector3D* uv   = m->mTextureCoords[0];
			aiColor4D*  vcol = NULL;	
			if (m->HasVertexColors(0)) vcol = m->mColors[0];

			// 頂点情報の読み込み
			Ogre::AxisAlignedBox aab;
			Ogre::ManualObject* mobj = new Ogre::ManualObject(nodeName+"_MObj");
			mobj->begin(omat->getName());
			//mobj->begin("Ogre/Skin");
			for (size_t n = 0; n < m->mNumVertices; n ++) {
				Ogre::Vector3 position(vec->x, vec->y, vec->z);
				aab.merge(position);

				mobj->position(vec->x, vec->y, vec->z); 
				vec++;  

				mobj->normal(norm->x, norm->y, norm->z);
				norm++; 

				if (uv)   { 
					mobj->textureCoord(uv->x, uv->y);        
					uv++;   
				}
				if (vcol) { 
					mobj->colour(vcol->r, vcol->g, vcol->b, vcol->a); 
					vcol++;
				}
			}

			// ポリゴンの構築
			for (size_t n = 0; n < m->mNumFaces; n++) {
				aiFace* face = &m->mFaces[n];
				for (size_t k = 0; k < face->mNumIndices; k++) {
					mobj->index(face->mIndices[k]);
				}
			}
			mobj->end();
			mobj->setBoundingBox(aab);

			Ogre::String meshName(nodeName+"_Mesh");
			mobj->convertToMesh(meshName);
			delete mobj;

			Ogre::String entityName(nodeName+"_Entity");
			std::cout << "entity: " << entityName << std::endl;
			Ogre::Entity* ent = sceneMgr->createEntity(entityName, meshName);
			cnode->attachObject(ent);
		}

		readModel(sceneMgr, cnode, scene, cnd);
	}
}
예제 #12
0
void Oculus::setupOgreOculus( Ogre::SceneManager *sm, Ogre::RenderWindow* win, Ogre::Root* root )
{
	mSceneMgr = root->createSceneManager(Ogre::ST_GENERIC);
	mSceneMgr->setAmbientLight( Ogre::ColourValue( 0.5, 0.5, 0.5 ) );
	mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
	

	Ogre::SceneNode* meshNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();


	// Configure Render Textures:
	Sizei recommendedTex0Size = ovrHmd_GetFovTextureSize( mHMD, ovrEye_Left,
			mHMD->DefaultEyeFov[0], 1.0f );
	Sizei recommendedTex1Size = ovrHmd_GetFovTextureSize( mHMD, ovrEye_Right,
			mHMD->DefaultEyeFov[1], 1.0f );

	// Generate a texture for each eye, as a rendertarget:
	mLeftEyeRenderTexture = Ogre::TextureManager::getSingleton().createManual(
			"RiftRenderTextureLeft", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			Ogre::TEX_TYPE_2D, recommendedTex0Size.w, recommendedTex0Size.h, 0, Ogre::PF_X8B8G8R8,
			Ogre::TU_RENDERTARGET );
	mRightEyeRenderTexture = Ogre::TextureManager::getSingleton().createManual(
			"RiftRenderTextureRight", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			Ogre::TEX_TYPE_2D, recommendedTex1Size.w, recommendedTex1Size.h, 0, Ogre::PF_X8B8G8R8,
			Ogre::TU_RENDERTARGET );

	// Assign the textures to the eyes used later:
	mMatLeft = Ogre::MaterialManager::getSingleton().getByName( "Oculus/LeftEye" );
	mMatLeft->getTechnique(0)->getPass(0)->getTextureUnitState(0)->
		setTexture( mLeftEyeRenderTexture );
		
	mMatRight = Ogre::MaterialManager::getSingleton().getByName( "Oculus/RightEye" );
	mMatRight->getTechnique(0)->getPass(0)->getTextureUnitState(0)->
		setTexture( mRightEyeRenderTexture );
		
	ovrEyeRenderDesc eyeRenderDesc[2];

	eyeRenderDesc[0] = ovrHmd_GetRenderDesc( mHMD, ovrEye_Left, mHMD->DefaultEyeFov[0] );
	eyeRenderDesc[1] = ovrHmd_GetRenderDesc( mHMD, ovrEye_Right, mHMD->DefaultEyeFov[1] );

	ovrVector2f UVScaleOffset[2];
	ovrRecti viewports[2];
	viewports[0].Pos.x = 0;
	viewports[0].Pos.y = 0;
	viewports[0].Size.w = recommendedTex0Size.w;
	viewports[0].Size.h = recommendedTex0Size.h;
	viewports[1].Pos.x = recommendedTex0Size.w;
	viewports[1].Pos.y = 0;
	viewports[1].Size.w = recommendedTex1Size.w;
	viewports[1].Size.h = recommendedTex1Size.h;
	Ogre::ManualObject* manual;
	// Create the Distortion Meshes:
	for ( int eyeNum = 0; eyeNum < 2; eyeNum ++ )
	{
		ovrDistortionMesh meshData;
		ovrHmd_CreateDistortionMesh( mHMD,
				eyeRenderDesc[eyeNum].Eye,
				eyeRenderDesc[eyeNum].Fov,
				0,
				&meshData );

		Ogre::GpuProgramParametersSharedPtr params;

		if( eyeNum == 0 )
		{
			ovrHmd_GetRenderScaleAndOffset( eyeRenderDesc[eyeNum].Fov,
					recommendedTex0Size, viewports[eyeNum],
					UVScaleOffset);
			params = mMatLeft->getTechnique(0)->getPass(0)->getVertexProgramParameters();
		} else {
			ovrHmd_GetRenderScaleAndOffset( eyeRenderDesc[eyeNum].Fov,
					recommendedTex1Size, viewports[eyeNum],
					UVScaleOffset);
			params = mMatRight->getTechnique(0)->getPass(0)->getVertexProgramParameters();
		}

		params->setNamedConstant( "eyeToSourceUVScale",
				Ogre::Vector4( UVScaleOffset[0].x, UVScaleOffset[0].y,0,0 ) );
		params->setNamedConstant( "eyeToSourceUVOffset",
				Ogre::Vector4( UVScaleOffset[1].x, UVScaleOffset[1].y,0,0 ) );

		std::cout << "UVScaleOffset[0]: " << UVScaleOffset[0].x << ", " << UVScaleOffset[0].y << std::endl;
		std::cout << "UVScaleOffset[1]: " << UVScaleOffset[1].x << ", " << UVScaleOffset[1].y << std::endl;

		// create ManualObject
		// TODO: Destroy the manual objects!!
			
		if( eyeNum == 0 )
		{
			manual = mSceneMgr->createManualObject("RiftRenderObjectLeft");
			manual->begin("Oculus/LeftEye", Ogre::RenderOperation::OT_TRIANGLE_LIST);
			//manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
		}
		else
		{
			manual = mSceneMgr->createManualObject("RiftRenderObjectRight");
			manual->begin("Oculus/RightEye", Ogre::RenderOperation::OT_TRIANGLE_LIST);
			//manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
		}

		for( unsigned int i = 0; i < meshData.VertexCount; i++ )
		{
			ovrDistortionVertex v = meshData.pVertexData[i];
			manual->position( v.ScreenPosNDC.x,
					v.ScreenPosNDC.y, 0 );
			manual->textureCoord( v.TanEyeAnglesR.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x,
					v.TanEyeAnglesR.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y);
			manual->textureCoord( v.TanEyeAnglesG.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x,
					v.TanEyeAnglesG.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y);
			manual->textureCoord( v.TanEyeAnglesB.x,//*UVScaleOffset[0].x + UVScaleOffset[1].x,
					v.TanEyeAnglesB.y);//*UVScaleOffset[0].y + UVScaleOffset[1].y);
			//float vig = std::max( v.VignetteFactor, (float)0.0 );
			//manual->colour( vig, vig, vig, vig );
			manual->colour( 1, 1, 1, 1 );

		}
		for( unsigned int i = 0; i < meshData.IndexCount; i++ )
		{
			manual->index( meshData.pIndexData[i] );
		}

		// tell Ogre, your definition has finished
		manual->end();

		ovrHmd_DestroyDistortionMesh( &meshData );

		meshNode->attachObject( manual );
	}
	
	// Set up IPD in meters:
	mIPD = ovrHmd_GetFloat(mHMD, OVR_KEY_IPD,  0.064f);
	
	// Set a default value for interpupillary distance:
	mIPD = 0.064f;
	
	// Create a camera in the (new, external) scene so the mesh can be rendered onto it:
	mCamera = mSceneMgr->createCamera("OculusRiftExternalCamera");
	mCamera->setFarClipDistance(1000000.0f);
	mCamera->setNearClipDistance( 0.1f );
	mCamera->setProjectionType( Ogre::PT_ORTHOGRAPHIC );
	mCamera->setOrthoWindow(2 , 2);
	mCamera->lookAt( 0, 0, -1 );
	

	mSceneMgr->getRootSceneNode()->attachObject( mCamera );

	meshNode->setPosition( 0, 0, -1 );
	meshNode->setScale( 1, 1, -0.1f );

	mViewport = m_window->addViewport( mCamera);
	mViewport->setBackgroundColour(Ogre::ColourValue::Black);
	mViewport->setOverlaysEnabled(true);
}
예제 #13
0
void OgreRecast::update()
{
    // Fully rebuild static geometry after a reset (when tiles should be removed)
    if(m_rebuildSg) {
        m_sg->reset();

        // Add navmesh tiles (polys) to static geometry
        Ogre::SceneManager::MovableObjectIterator iterator = m_pSceneMgr->getMovableObjectIterator("Entity");
        while(iterator.hasMoreElements())
        {
            Ogre::Entity* ent = static_cast<Ogre::Entity*>(iterator.getNext());
            // Add all navmesh poly debug entities
            if(Ogre::StringUtil::startsWith(ent->getName(), "ent_recastmowalk_"))
                m_sg->addEntity(ent, Ogre::Vector3::ZERO);
        }
        m_sg->build();


        // Batch all lines together in one single manualObject (since we cannot use staticGeometry for lines)
        if(m_pSceneMgr->hasManualObject("AllNeighbourLines")) {
            m_pRecastSN->detachObject("AllNeighbourLines") ;
            m_pSceneMgr->destroyManualObject("AllNeighbourLines");
        }
        if(m_pSceneMgr->hasManualObject("AllBoundaryLines")) {
            m_pRecastSN->detachObject("AllBoundaryLines") ;
            m_pSceneMgr->destroyManualObject("AllBoundaryLines");
        }

        Ogre::ManualObject *allNeighbourLines = m_pSceneMgr->createManualObject("AllNeighbourLines");
        allNeighbourLines->begin("recastdebug", Ogre::RenderOperation::OT_LINE_LIST);
        allNeighbourLines->colour(m_navmeshNeighbourEdgeCol);

        Ogre::ManualObject *allBoundaryLines = m_pSceneMgr->createManualObject("AllBoundaryLines");
        allBoundaryLines->begin("recastdebug", Ogre::RenderOperation::OT_LINE_LIST);
        allBoundaryLines->colour(m_navmeshOuterEdgeCol);

        iterator = m_pSceneMgr->getMovableObjectIterator("ManualObject");
        while(iterator.hasMoreElements())
        {
            Ogre::ManualObject* man = static_cast<Ogre::ManualObject*>(iterator.getNext());

            if(Ogre::StringUtil::startsWith(man->getName(), "recastmoneighbour_")) {
                std::vector<Ogre::Vector3> verts = getManualObjectVertices(man);

                for(std::vector<Ogre::Vector3>::iterator iter = verts.begin(); iter != verts.end(); iter++) {
                    allNeighbourLines->position(*iter);
                }
            } else if(Ogre::StringUtil::startsWith(man->getName(), "recastmoboundary_")) {
                std::vector<Ogre::Vector3> verts = getManualObjectVertices(man);

                for(std::vector<Ogre::Vector3>::iterator iter = verts.begin(); iter != verts.end(); iter++) {
                    allBoundaryLines->position(*iter);
                }
            }
        }
        allNeighbourLines->end();
        allBoundaryLines->end();

        m_pRecastSN->attachObject(allNeighbourLines);
        m_pRecastSN->attachObject(allBoundaryLines);


        m_rebuildSg = false;
    }
}
예제 #14
0
void AwarenessVisualizer::createRecastPolyMesh(const std::string& name, const unsigned short *verts, const int nverts, const unsigned short *polys, const int npolys, const unsigned char *areas, const int maxpolys, const unsigned short *regions, const int nvp, const float cs, const float ch, const float *orig, bool colorRegions)
{

	// Demo specific parameters
	float m_navMeshOffsetFromGround = 0.2; //ch / 5;         // Distance above ground for drawing navmesh polygons
	float m_navMeshEdgesOffsetFromGround = 0.5; //ch / 3;    // Distance above ground for drawing edges of navmesh (should be slightly higher than navmesh polygons)
//	float m_pathOffsetFromGround = 1 + m_navMeshOffsetFromGround; // Distance above ground for drawing path debug lines relative to cellheight (should be higher than navmesh polygons)

	// Colors for navmesh debug drawing
	static Ogre::ColourValue m_navmeshNeighbourEdgeCol(0.9, 0.9, 0.9);   // Light Grey
	static Ogre::ColourValue m_navmeshOuterEdgeCol(0, 0, 0);         // Black
	static Ogre::ColourValue m_navmeshGroundPolygonCol(0, 0.7, 0);       // Green
	static Ogre::ColourValue m_navmeshOtherPolygonCol(0, 0.175, 0);     // Dark green
	static Ogre::ColourValue m_pathCol(1, 0, 0);         // Red

	// When drawing regions choose different random colors for each region
	Ogre::ColourValue* regionColors = NULL;
	if (colorRegions) {
		regionColors = new Ogre::ColourValue[maxpolys];
		for (int i = 0; i < maxpolys; ++i) {
			regionColors[i] = Ogre::ColourValue(Ogre::Math::RangeRandom(0, 1), Ogre::Math::RangeRandom(0, 1), Ogre::Math::RangeRandom(0, 1), 1);
		}
	}

	int nIndex = 0;

	if (npolys) {
		// start defining the manualObject with the navmesh planes
		Ogre::ManualObject* pRecastMOWalk;
		if (mSceneManager.hasManualObject("RecastMOWalk_" + name)) {
			pRecastMOWalk = mSceneManager.getManualObject("RecastMOWalk_" + name);
			pRecastMOWalk->clear();
		} else {
			pRecastMOWalk = mSceneManager.createManualObject("RecastMOWalk_" + name);
			//Remove from the overhead map.
			pRecastMOWalk->setVisibilityFlags(pRecastMOWalk->getVisibilityFlags() & ~Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
			mTileSceneNode->attachObject(pRecastMOWalk);
		}
		pRecastMOWalk->begin("/common/base/authoring/awareness", Ogre::RenderOperation::OT_TRIANGLE_LIST);
		for (int i = 0; i < npolys; ++i) {    // go through all polygons
			if (areas[i] == Navigation::POLYAREA_GROUND || areas[i] == DT_TILECACHE_WALKABLE_AREA) {
				const unsigned short* p = &polys[i * nvp * 2];

				unsigned short vi[3];
				for (int j = 2; j < nvp; ++j) // go through all verts in the polygon
						{
					if (p[j] == RC_MESH_NULL_IDX)
						break;
					vi[0] = p[0];
					vi[1] = p[j - 1];
					vi[2] = p[j];
					for (int k = 0; k < 3; ++k) // create a 3-vert triangle for each 3 verts in the polygon.
							{
						const unsigned short* v = &verts[vi[k] * 3];
						const float x = orig[0] + v[0] * cs;
						const float y = orig[1] + (v[1]/*+1*/) * ch;
						const float z = -orig[2] - v[2] * cs;

						pRecastMOWalk->position(x, y + m_navMeshOffsetFromGround, z);

						if (colorRegions) {
							pRecastMOWalk->colour(regionColors[regions[i]]);  // Assign vertex color
						} else {
							if (areas[i] == Navigation::POLYAREA_GROUND)
								pRecastMOWalk->colour(m_navmeshGroundPolygonCol);
							else
								pRecastMOWalk->colour(m_navmeshOtherPolygonCol);
						}

					}
					pRecastMOWalk->triangle(nIndex, nIndex + 2, nIndex + 1);
					nIndex += 3;
				}
			}
		}
		pRecastMOWalk->end();

		// Define manualObject with the navmesh edges between neighbouring polygons
		Ogre::ManualObject* pRecastMONeighbour;
		if (mSceneManager.hasManualObject("RecastMONeighbour_" + name)) {
			pRecastMONeighbour = mSceneManager.getManualObject("RecastMONeighbour_" + name);
			pRecastMONeighbour->clear();
		} else {
			pRecastMONeighbour = mSceneManager.createManualObject("RecastMONeighbour_" + name);
			//Remove from the overhead map.
			pRecastMONeighbour->setVisibilityFlags(pRecastMONeighbour->getVisibilityFlags() & ~Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
			mTileSceneNode->attachObject(pRecastMONeighbour);
		}

		pRecastMONeighbour->begin("/common/base/authoring/awareness", Ogre::RenderOperation::OT_LINE_LIST);

		for (int i = 0; i < npolys; ++i) {
			const unsigned short* p = &polys[i * nvp * 2];
			for (int j = 0; j < nvp; ++j) {
				if (p[j] == RC_MESH_NULL_IDX)
					break;
				if (p[nvp + j] == RC_MESH_NULL_IDX)
					continue;
				int vi[2];
				vi[0] = p[j];
				if (j + 1 >= nvp || p[j + 1] == RC_MESH_NULL_IDX)
					vi[1] = p[0];
				else
					vi[1] = p[j + 1];
				for (int k = 0; k < 2; ++k) {
					const unsigned short* v = &verts[vi[k] * 3];
					const float x = orig[0] + v[0] * cs;
					const float y = orig[1] + (v[1]/*+1*/) * ch /*+ 0.1f*/;
					const float z = -orig[2] - v[2] * cs;
					//dd->vertex(x, y, z, coln);
					pRecastMONeighbour->position(x, y + m_navMeshEdgesOffsetFromGround, z);
					pRecastMONeighbour->colour(m_navmeshNeighbourEdgeCol);

				}
			}
		}

		pRecastMONeighbour->end();

		// Define manualObject with navmesh outer edges (boundaries)
		Ogre::ManualObject* pRecastMOBoundary;
		if (mSceneManager.hasManualObject("RecastMOBoundary_" + name)) {
			pRecastMOBoundary = mSceneManager.getManualObject("RecastMOBoundary_" + name);

			pRecastMOBoundary->clear();
		} else {
			pRecastMOBoundary = mSceneManager.createManualObject("RecastMOBoundary_" + name);
			//Remove from the overhead map.
			pRecastMOBoundary->setVisibilityFlags(pRecastMOBoundary->getVisibilityFlags() & ~Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
			mTileSceneNode->attachObject(pRecastMOBoundary);
		}

		pRecastMOBoundary->begin("/common/base/authoring/awareness", Ogre::RenderOperation::OT_LINE_LIST);

		for (int i = 0; i < npolys; ++i) {
			const unsigned short* p = &polys[i * nvp * 2];
			for (int j = 0; j < nvp; ++j) {
				if (p[j] == RC_MESH_NULL_IDX)
					break;
				if (p[nvp + j] != RC_MESH_NULL_IDX)
					continue;
				int vi[2];
				vi[0] = p[j];
				if (j + 1 >= nvp || p[j + 1] == RC_MESH_NULL_IDX)
					vi[1] = p[0];
				else
					vi[1] = p[j + 1];
				for (int k = 0; k < 2; ++k) {
					const unsigned short* v = &verts[vi[k] * 3];
					const float x = orig[0] + v[0] * cs;
					const float y = orig[1] + (v[1]/*+1*/) * ch /*+ 0.1f*/;
					const float z = -orig[2] - v[2] * cs;
					//dd->vertex(x, y, z, colb);

					pRecastMOBoundary->position(x, y + m_navMeshEdgesOffsetFromGround, z);
					pRecastMOBoundary->colour(m_navmeshOuterEdgeCol);
				}
			}
		}

		pRecastMOBoundary->end();

//		if (STATIC_GEOM_DEBUG) {
//			// Render navmesh tiles more efficiently using staticGeometry
//
//			// Early out if empty meshes drawn
//			if (m_pRecastMOWalk->getNumSections() == 0)
//				return;
//
//			if (!m_sg) {
//				m_sg = m_pSceneMgr->createStaticGeometry("NavmeshDebugStaticGeom");
//				Ogre::Vector3 bmin;
//				Ogre::Vector3 bmax;
//				Ogre::Vector3 bsize;
//				FloatAToOgreVect3(m_cfg.bmin, bmin);
//				FloatAToOgreVect3(m_cfg.bmax, bmax);
//				bsize = bmax - bmin;
//				m_sg->setRegionDimensions(bsize);
//				m_sg->setOrigin(bmin);
//			}
//
//			m_pRecastMOWalk->convertToMesh("mesh_" + m_pRecastMOWalk->getName());
//			Ogre::Entity *walkEnt = m_pSceneMgr->createEntity("ent_" + m_pRecastMOWalk->getName(), "mesh_" + m_pRecastMOWalk->getName());
//			m_sg->addEntity(walkEnt, Ogre::Vector3::ZERO);
//
//// TODO line drawing does not work with staticGeometry
//			if (false && m_pRecastMONeighbour->getNumSections() > 0) {
//				m_pRecastMONeighbour->convertToMesh("mesh_" + m_pRecastMONeighbour->getName());     // Creating meshes from manualobjects without polygons is not a good idea!
//				Ogre::Entity *neighbourEnt = m_pSceneMgr->createEntity("ent_" + m_pRecastMONeighbour->getName(), "mesh_" + m_pRecastMONeighbour->getName());
//				m_sg->addEntity(neighbourEnt, Ogre::Vector3::ZERO);
//			}
//
//			if (false && m_pRecastMOBoundary->getNumSections() > 0) {
//				m_pRecastMOBoundary->convertToMesh("mesh_" + m_pRecastMOBoundary->getName());
//				Ogre::Entity *boundaryEnt = m_pSceneMgr->createEntity("ent_" + m_pRecastMOBoundary->getName(), "mesh_" + m_pRecastMOBoundary->getName());
//				m_sg->addEntity(boundaryEnt, Ogre::Vector3::ZERO);
//			}
//
//			// Set dirty flag of solid geometry so it will be rebuilt next update()
//			m_rebuildSg = true;
//		} else {
		// Add manualobjects directly to scene (can be slow for lots of tiles)
//		}

	}     // end areacount

	delete[] regionColors;

}
void ParticleFactory::CreateThrusterParticleGeometry(Ogre::String object_name, int num_particles, float loop_radius, float circle_radius){

	//try {
		/* Retrieve scene manager and root scene node */
       // Ogre::SceneManager* scene_manager = ogre_root_->getSceneManager("MySceneManager");
        Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode();

        /* Create the 3D object */
        Ogre::ManualObject* object = NULL;
        object = scene_manager->createManualObject(object_name);
        object->setDynamic(false);
/*
        /* Create point list for the object */
		object->begin("", Ogre::RenderOperation::OT_POINT_LIST);

		/* Initialize random numbers */
		std::srand(std::time(0));

		/* Create a set of points which will be the particles */
		/* This is similar to drawing a torus: we will sample points on the surface of the torus */

		
		float maxspray = 1.5; // This is how much we allow the points to wander around
		float u, v, w, theta, phi, spray; // Work variables
		for (int i = 0; i < num_particles; i++){
			
			// Randomly select two numbers to define a point on the torus
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
            
			// Use u and v to define the point on the torus
            theta = u * Ogre::Math::TWO_PI;
			phi = v * Ogre::Math::TWO_PI;
			Ogre::Vector3 center = Ogre::Vector3(loop_radius*cos(theta), loop_radius*sin(theta), 0.0);
            Ogre::Vector3 normal = Ogre::Vector3(cos(theta)*cos(phi), sin(theta)*cos(phi), sin(phi));
			object->position(center + normal*circle_radius); // Position of the point
			object->colour(Ogre::ColourValue(((float) i)/((float) num_particles), 0.0, 1.0 - (((float) i)/((float) num_particles))));
			object->textureCoord(Ogre::Vector2(0.0, 0.0));

			// Now sample a point on a sphere to define a direction for points to wander around
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
			w = ((double) rand() / (RAND_MAX));
			
			theta = u * Ogre::Math::TWO_PI;
			phi = acos(2.0*v * -1.0);
			spray = maxspray*pow((float) w, (float) (1.0/4.0)); // Cubic root
			Ogre::Vector3 wander = Ogre::Vector3(spray*cos(theta)*cos(phi), spray*cos(theta)*sin(phi), sin(phi)*-2);

			object->normal(wander);
		}

		object->position(Ogre::Vector3(0.0f, 0.0f, -30.0f));
		object->colour(Ogre::ColourValue(0.0f, 0.0f, 0.0f));
		object->textureCoord(Ogre::Vector2(0.0f, 0.0f));
		object->normal(Ogre::Vector3(0.0f, 0.0f, -30.0f));

        object->end();
		
		
		
        /* Convert triangle list to a mesh */
        object->convertToMesh(object_name);
  /*  }
    catch (Ogre::Exception &e){
        throw(OgreAppException(std::string("Ogre::Exception: ") + std::string(e.what())));
    }
    catch(std::exception &e){
        throw(OgreAppException(std::string("std::Exception: ") + std::string(e.what())));
    }*/
}
void  ParticleFactory::CreateSplineControlPoints(Ogre::String control_points_name, int num_control_points, Ogre::String material_name){

		// Control points for the spline
		Ogre::Vector3 *control_point;

		/* Allocate memory for control points */
		control_point = new Ogre::Vector3[num_control_points];

		/* Create control points of a piecewise spline */
		/* We store the control points in groups of 4 */
		/* Each group represents the control points (p0, p1, p2, p3) of a cubic Bezier curve */
		/* To ensure C1 continuity, we constrain the first and second point of each curve according to the previous curve */
        
		// Initialize the first two control points to fixed values */
		control_point[0] = Ogre::Vector3(-20.0, 0.0, 0.0);
		control_point[1] = Ogre::Vector3(20.0, 0.0, 0.0);

		// Create remaining points
		for (int i = 2; i < num_control_points; i++){
			// Check if we have the first or second point of a curve
			// Then we need to constrain the points
			if (i % 4 == 0){
				// Constrain the first point of the curve
				// p3 = q0, where the previous curve is (p0, p1, p2, p3) and the current curve is (q0, q1, q2, q3)
				// p3 is at position -1 from the current point q0
				control_point[i] = control_point[i - 1];
			} else if (i % 4 == 1){
				// Constrain the second point of the curve
				// q1 = 2*p3 – p2
				// p3 is at position -1 and we add another -1 since we are at i%4 == 1 (not i%4 == 0)
				// p2 is at position -2 and we add another -1 since we are at i%4 == 1 (not i%4 == 0)
				control_point[i] = 2.0*control_point[i -2] - control_point[i - 3];
			} else {
				// Other points: we can freely assign random values to them
				// Get 3 random numbers
				float u, v, w;
				//u = ((double) rand() / (RAND_MAX));
				//v = ((double) rand() / (RAND_MAX));
				//w = ((double) rand() / (RAND_MAX));
				// Define control points based on u, v, and w and scale by the control point index
				//control_point[i] = Ogre::Vector3(u*3.0*(i/4 + 1), v*3.0*(i/4+1), w*3.0*(i/4+1));
				//control_point[i] = Ogre::Vector3(u*3.0*(i/4 + 1), v*3.0*(i/4+1), 0.0); // Easier to visualize with the control points on the screen

				//x = cx + r * cos(a)
				//y = cy + r * sin(a)
			
				u = 20 * cos(Ogre::Math::RangeRandom(-25,25));
				v = 20 * sin(Ogre::Math::RangeRandom(-50,50));
				w = (Ogre::Math::RangeRandom(-15,15));
				control_point[i] = Ogre::Vector3(u, w, v);

			}
		}

		/* Add control points to the material's shader */
		/* Translate the array of Ogre::Vector3 to an accepted format */
		float *shader_data;
		shader_data = new float[num_control_points*4];
		for (int i = 0; i < num_control_points; i++){
			shader_data[i*4] = control_point[i].x;
			shader_data[i*4 + 1] = control_point[i].y;
			shader_data[i*4 + 2] = control_point[i].z;
			shader_data[i*4 + 3] = 0.0;
		}

		/* Add array as a parameter to the shader of the specified material */
		Ogre::MaterialPtr mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(material_name));
		mat->getBestTechnique()->getPass(0)->getVertexProgramParameters()->setNamedConstant("control_point", shader_data, num_control_points, 4);

		/* Also create a mesh out of the control points, so that we can render them, if needed */
		
        Ogre::ManualObject* object = NULL;
        object = scene_manager->createManualObject(control_points_name);
        object->setDynamic(false);
		object->begin("", Ogre::RenderOperation::OT_POINT_LIST);
		for (int i = 0; i < num_control_points; i++){
			object->position(control_point[i]);
			// Color allows us to keep track of control point ordering
			object->colour(1.0 - ((float) i)/((float)num_control_points), 0.0, ((float) i)/((float)num_control_points));
		}
		object->end();
        object->convertToMesh(control_points_name);

		/* Free memory we used to store control points temporarily */
		delete [] control_point;
		
}
void  ParticleFactory::CreateSplineParticleGeometry(Ogre::String object_name, int num_particles, float loop_radius, float circle_radius){

		/* Retrieve scene manager and root scene node */
        Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode();

        /* Create the 3D object */
        Ogre::ManualObject* object = NULL;
        object = scene_manager->createManualObject(object_name);
        object->setDynamic(false);
        
		/* Create point list for the object */
		object->begin("", Ogre::RenderOperation::OT_POINT_LIST);

		/* Initialize random numbers */
		std::srand(std::time(0));

		/* Create a set of points which will be the particles */
		/* This is similar to drawing a torus: we will sample points on a torus, but will allow the points to also
		   deviate a bit from the torus along the direction of a random vector */
        float maxspray = 0.5; // This is how much we allow the points to deviate along a normalized vector
		float u, v, w, theta, phi, spray; // Work variables
		for (int i = 0; i < num_particles; i++){
			
			// Get two random numbers
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
            
			// Use u and v to define a point on the torus with angles theta and phi
            theta = u * Ogre::Math::TWO_PI;
			phi = v * Ogre::Math::TWO_PI;

			// Get center of loop and point's normal on the torus
			Ogre::Vector3 center = Ogre::Vector3(loop_radius*cos(theta), loop_radius*sin(theta), 0.0);
            Ogre::Vector3 normal = Ogre::Vector3(cos(theta)*cos(phi), sin(theta)*cos(phi), sin(phi));

			// Next, we want to let the points deviate along the direction of a random vector
			// To obtain a random vector, we sample a point on the sphere
			// The point on the sphere minus the origin (0, 0) is the random vector

			// Randomly select two numbers to define a point in spherical coordinates
			u = ((double) rand() / (RAND_MAX));
            v = ((double) rand() / (RAND_MAX));
			
			// Use u to define the angle theta along one direction of a sphere
			theta = u * Ogre::Math::TWO_PI;
			// Use v to define the angle phi along the other direction of the sphere
			phi = acos(2.0*v - 1.0);
			// Get the point on the sphere (equivalent to a normalized direction vector since the origin is zero)
			Ogre::Vector3 direct = Ogre::Vector3(cos(theta)*sin(phi), sin(theta)*sin(phi), -cos(phi));
			// We need z = -cos(phi) to make sure that the z coordinate runs from -1 to 1 as phi runs from 0 to pi

			// Now, multiply a random amount of deviation by this vector, which is the deviation we will add to the point on the torus
			w = ((double) rand() / (RAND_MAX));
			spray = maxspray*pow((float) w, (float) (1.0/3.0)); // cbrt(w);
			Ogre::Vector3 wander = Ogre::Vector3(spray*direct.x, spray*direct.y, direct.z);
				
			// Add computed quantities to the object
			object->position(center + normal*circle_radius);
			object->normal(wander);
			object->colour(Ogre::ColourValue(((float) i)/((float) num_particles), 0.0, 0.0)); // Store particle id in the red channel as a float
			object->textureCoord(Ogre::Vector2(0.0, 0.0));
		}
		
		/* We finished the object */
        object->end();
		
        /* Convert triangle list to a mesh */
        object->convertToMesh(object_name);
   
}
예제 #18
0
void Client::initScene() {
	Ogre::Vector3 lightPosition = Ogre::Vector3(0,10,50);
	
	// Set the scene's ambient light
	mSceneMgr->setAmbientLight(Ogre::ColourValue(.1f, .1f, .1f));
	Ogre::Light* pointLight = mSceneMgr->createLight("pointLight");
	pointLight->setType(Ogre::Light::LT_POINT);
	pointLight->setPosition(lightPosition);
	// create a marker where the light is
	Ogre::Entity* ogreHead2 = mSceneMgr->createEntity( "Head2", "ogrehead.mesh" );
	Ogre::SceneNode* headNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "HeadNode2", lightPosition );
	headNode2->attachObject( ogreHead2 );
	headNode2->scale( .5, .5, .5 );
	
	// make a quad
	Ogre::ManualObject* lManualObject = NULL;
	Ogre::String lNameOfTheMesh = "TestQuad";
	{
		// params
		Ogre::String lManualObjectName = "TestQuad";
		bool lDoIWantToUpdateItLater = false;
		// code
		lManualObject = mSceneMgr->createManualObject(lManualObjectName);
		lManualObject->setDynamic(lDoIWantToUpdateItLater);
		lManualObject->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
		{	// Specify Vertices
			float xmin = 0.0f, xmax = 100.0f, zmin = -100.0f, zmax = 0.0f, ymin = -50.0f, ymax = 0.0f;
			
			lManualObject->position(xmin, ymin, zmin);// a vertex
			lManualObject->colour(Ogre::ColourValue::Red);
			lManualObject->textureCoord(0.0,0.0);
			
			lManualObject->position(xmax, ymin, zmin);// a vertex
			lManualObject->colour(Ogre::ColourValue::Green);
			lManualObject->textureCoord(1.0,0.0);
			
			lManualObject->position(xmin, ymin, zmax);// a vertex
			lManualObject->colour(Ogre::ColourValue::Blue);
			lManualObject->textureCoord(0.0,1.0);
			
			lManualObject->position(xmax, ymin, zmax);// a vertex
			lManualObject->colour(Ogre::ColourValue::Blue);
			lManualObject->textureCoord(1.0,1.0);
		}
		{	// specify geometry
			lManualObject->triangle(0,2,1);
			lManualObject->triangle(3,1,2);
		}
		lManualObject->end();
		lManualObject->convertToMesh(lNameOfTheMesh);
	}
	Ogre::Entity* lEntity = mSceneMgr->createEntity(lNameOfTheMesh);
	Ogre::SceneNode* lNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	lNode->attachObject(lEntity);
	Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
	// Create a SceneNode and attach the Entity to it
	Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HeadNode",Ogre::Vector3(0,-20,0));
	headNode->attachObject(ogreHead);
	ogreHead->setMaterialName("Hatching");
	
	lEntity->setMaterialName("Hatching");
	// postprocessing effects
	//Ogre::CompositorManager::getSingleton().addCompositor(mViewport,"Sobel" );
	//Ogre::CompositorManager::getSingleton().setCompositorEnabled(mCamera->getViewport(), "Sobel", true);
	//Ogre::CompositorManager::getSingleton().addCompositor(mViewport,"CelShading" );
	//Ogre::CompositorManager::getSingleton().setCompositorEnabled(mCamera->getViewport(), "CelShading", true);
}
//-------------------------------------------------------------------------------------
Ogre::ManualObject* const DigitalForensicsVisualisation::cylinder(ColorMap cm)
{
	Ogre::ColourValue cv;
	cv.r = cm.r; cv.g = cm.g; cv.b = cm.b; cv.a = 0.65;




	
	
	char* name = (char*) malloc (32);
	sprintf(name, "cylinder%d", app.cylinderCount++);
	Ogre::ManualObject* cylinder = mSceneMgr->createManualObject(name);

	cylinder->begin("MyMaterial1", Ogre::RenderOperation::OT_TRIANGLE_LIST);
	const float accuracy = 20;
	const float radius = 50;
	unsigned int index = 2;
	
	
	cylinder->position(50,0,-50);
	cylinder->colour(cv);
	cylinder->normal(50,90,-50);

	cylinder->position(50,-90,-50);
	cylinder->colour(cv);
	cylinder->normal(50,-91,-50);


	for (float theta = 0; theta <= Ogre::Math::PI * 2; theta += Ogre::Math::PI / (accuracy)) 
	{
		// TL: top-left, BR: bottom-right
 /*TL*/ cylinder->position(radius * cos(theta) + 50, 0, radius * sin(theta) - 50);
		cylinder->colour(cv); 
		cylinder->normal(radius * cos(theta) + 50, 90, radius * sin(theta) - 50); 
 /*TR*/ cylinder->position(radius * cos(theta - Ogre::Math::PI / accuracy) + 50, 0, radius * sin(theta - Ogre::Math::PI / accuracy) - 50);
		cylinder->colour(cv);
		cylinder->normal(radius * cos(theta - Ogre::Math::PI / accuracy) + 50, 90, radius * sin(theta - Ogre::Math::PI / accuracy) - 50);
	
 /*TL*/ cylinder->position(radius * cos(theta) + 50, -90, radius * sin(theta) - 50); 
		cylinder->colour(cv);
		cylinder->normal(radius * cos(theta) + 50, -91, radius * sin(theta) - 50); 
 /*TR*/ cylinder->position(radius * cos(theta - Ogre::Math::PI / accuracy) + 50, -90, radius * sin(theta - Ogre::Math::PI / accuracy) - 50);
		cylinder->colour(cv);
		cylinder->normal(radius * cos(theta - Ogre::Math::PI / accuracy) + 50, -91, radius * sin(theta - Ogre::Math::PI / accuracy) - 50);

		
		cylinder->triangle(index, index + 1, 0);
		cylinder->triangle(1, index + 3, index + 2);
		cylinder->triangle(index, index + 2, index + 3);
		cylinder->triangle(index + 3, index + 1, index);

		index += 4;

	}

	cylinder->end();
	
	free(name);
	return cylinder;



}
예제 #20
0
파일: main.cpp 프로젝트: Isaj7/finalOgre
			// 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);


			}
//-------------------------------------------------------------------------------------
Ogre::ManualObject* const DigitalForensicsVisualisation::cube (bool isFrustum, ColorMap cm)
{
	Ogre::ColourValue cv;
	cv.r = cm.r; cv.g = cm.g; cv.b = cm.b; cv.a = 0.65;


	char* name = (char*) malloc (32);
	sprintf(name, "cube%d", app.cubeCount++);
	Ogre::ManualObject* cube = mSceneMgr->createManualObject(name);

	cube->begin("MyMaterial1", Ogre::RenderOperation::OT_TRIANGLE_LIST);



	Ogre::Vector3 centre(50, 50, 50);
	Ogre::Vector3 position;
	//bottom points
	//0
	position.z = position. y = 0; 
	position.x = 0;
	Ogre::Vector3 normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(0,1,1);
	cube->colour(cv);
	cube->normal(normal);
	//1
	position.x = 100; // 100, 0, 0
	normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(1,0,1);
	cube->colour(cv);
	cube->normal(normal);
	//2
	position.z = 100; position.x = 0; 
	normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(1,1,1);
	cube->colour(cv);
	cube->normal(normal);
	////3
	position.x = 100;
	normal = (position - centre); normal.normalise();
	cube->position(position);
	cube->textureCoord(0,0,1);
	cube->colour(cv);
	cube->normal(normal);
	////top points
	////4
	position.y = 100;
	position.x = isFrustum ? 25 : 0;
	position.z = isFrustum ? 25 : 0; 
	normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(0,1,0);
	cube->colour(cv);
	cube->normal(normal);
	////5
	position.x = isFrustum ? 75 : 100;
	normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(1,0,0);
	cube->colour(cv);
	cube->normal(normal);
	////6
	position.x = isFrustum ? 25 : 0; position.z = isFrustum ? 75 : 100;
	normal = (position - centre);	normal.normalise();
	cube->position(position);
	cube->textureCoord(1,1,0);
	cube->colour(cv);
	cube->normal(normal);
	////7
	position.x = isFrustum ? 75 : 100;
	normal = (position - centre); normal.normalise();
	cube->position(position);
	cube->textureCoord(0,0,0);
	cube->colour(cv);
	cube->normal(normal);

	
	cube->triangle(0,1,2);//NEGATIVE
	cube->triangle(3,2,1);

	cube->triangle(6,5,4);//POSITIVE
	cube->triangle(5,6,7);

	cube->triangle(0,2,4);
	cube->triangle(6,4,2);
	
	cube->triangle(5,3,1); 
	cube->triangle(3,5,7);
	
	cube->triangle(2,3,6);
	cube->triangle(7,6,3);
	
	cube->triangle(4,1,0);
	cube->triangle(1,4,5);


	cube->end();
	free (name);

	return cube;


}
//-------------------------------------------------------------------------------------
Ogre::ManualObject* const DigitalForensicsVisualisation::pyramid(ColorMap cm)
{
	Ogre::ColourValue cv;
	cv.r = cm.r; cv.g = cm.g; cv.b = cm.b; cv.a = 0.65;
	

	char* name = (char*) malloc (32);
	sprintf(name, "pyramid%d", app.pyramidCount++);
	Ogre::ManualObject* pyramid = mSceneMgr->createManualObject(name);

	pyramid->begin("MyMaterial1", Ogre::RenderOperation::OT_TRIANGLE_LIST);

	Ogre::Vector3 normal;

	pyramid->position(0,0,0);    // 0
	pyramid->colour(cv);
	normal.x = normal.y = normal.z = -50;
	normal.normalise();
	pyramid->normal(normal);

	pyramid->position(100,0,0);  // 1
	pyramid->colour(cv);
	normal.x = 50; normal.y = normal.z = -50; 
	normal.normalise();
	pyramid->normal(normal);

	pyramid->position(50,0,100); // 2
	pyramid->colour(cv);
	normal.x = 0; normal.y = -50; normal.z = 50;
	normal.normalise();
	pyramid->normal(normal);

	pyramid->position(0,100,0);  // 3
	pyramid->colour(cv);
	normal.x = normal.z = -50;
	normal.y = 50;
	normal.normalise();
	pyramid->normal(normal);

	pyramid->position(100,100,0);  // 4
	pyramid->colour(cv);
	normal.x = normal.y = 50; normal.z = -50; 
	normal.normalise();
	pyramid->normal(normal);

	pyramid->position(50,100,100); // 5
	pyramid->colour(cv);
	normal.x = 0; normal.y = normal.z = 50;
	normal.normalise();
	pyramid->normal(normal);

	pyramid->triangle(0,1,2);
	pyramid->triangle(5,4,3);
	
	pyramid->triangle(3,1,0);
	pyramid->triangle(1,3,4);

	pyramid->triangle(0,2,3);
	pyramid->triangle(5,3,2);

	pyramid->triangle(4,2,1);
	pyramid->triangle(2,4,5);

	

	pyramid->end();
	free (name);
	return pyramid;




}
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;
}
예제 #24
0
void TerrainObjectManager::loadObjectConfigFile(Ogre::String odefname)
{
	proceduralManager = new ProceduralManager();

	objcounter = 0;
	free_localizer = 0;

	ProceduralObject po;
	po.loadingState = -1;
	int r2oldmode = 0;
	int lastprogress = -1;
	bool proroad = false;

	DataStreamPtr ds;
	try
	{
		ds = ResourceGroupManager::getSingleton().openResource(odefname, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
	}
	catch(...)
	{
		LOG("Error opening object configuration: " + odefname);
		return;
	}

	int mapsizex = terrainManager->getGeometryManager()->getMaxTerrainSize().x;
	int mapsizez = terrainManager->getGeometryManager()->getMaxTerrainSize().z;

	Vector3 r2lastpos=Vector3::ZERO;
	Quaternion r2lastrot=Quaternion::IDENTITY;
	int r2counter=0;

	//long line = 0;
	char line[4096] = "";

	while (!ds->eof())
	{
		int progress = ((float)(ds->tell()) / (float)(ds->size())) * 100.0f;
		if (progress-lastprogress > 20)
		{
#ifdef USE_MYGUI
			LoadingWindow::getSingleton().setProgress(progress, _L("Loading Terrain Objects"));
#endif //MYGUI
			lastprogress = progress;
		}

		char oname[1024] = {};
		char type[256] = {};
		char name[256] = {};
		Vector3 pos(Vector3::ZERO);
		Vector3 rot(Vector3::ZERO);

		size_t ll = ds->readLine(line, 1023);
		if (line[0]=='/' || line[0]==';' || ll==0) continue; //comments
		if (!strcmp("end",line)) break;

		if (!strncmp(line,"collision-tris", 14))
		{
			long amount = Collisions::MAX_COLLISION_TRIS;
			sscanf(line, "collision-tris %ld", &amount);
			gEnv->collisions->resizeMemory(amount);
		}

		if (!strncmp(line,"grid", 4))
		{
			sscanf(line, "grid %f, %f, %f", &pos.x, &pos.y, &pos.z);

			Ogre::ColourValue BackgroundColour = Ogre::ColourValue::White;//Ogre::ColourValue(0.1337f, 0.1337f, 0.1337f, 1.0f);
			Ogre::ColourValue GridColour = Ogre::ColourValue(0.2f, 0.2f, 0.2f, 1.0f);

			Ogre::ManualObject *mReferenceObject = new Ogre::ManualObject("ReferenceGrid");

			mReferenceObject->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);

			Ogre::Real step = 1.0f;
			unsigned int count = 50;
			unsigned int halfCount = count / 2;
			Ogre::Real full = (step * count);
			Ogre::Real half = full / 2;
			Ogre::Real y = 0;
			Ogre::ColourValue c;
			for (unsigned i=0;i < count+1;i++)
			{
				if (i == halfCount)
					c = Ogre::ColourValue(1,0,0,1.0f);
				else
					c = GridColour;

				mReferenceObject->position(-half,y,-half+(step*i));
				mReferenceObject->colour(BackgroundColour);
				mReferenceObject->position(0,y,-half+(step*i));
				mReferenceObject->colour(c);
				mReferenceObject->position(0,y,-half+(step*i));
				mReferenceObject->colour(c);
				mReferenceObject->position(half,y,-half+(step*i));
				mReferenceObject->colour(BackgroundColour);

				if (i == halfCount)
					c = Ogre::ColourValue(0,0,1,1.0f);
				else
					c = GridColour;

				mReferenceObject->position(-half+(step*i),y,-half);
				mReferenceObject->colour(BackgroundColour);
				mReferenceObject->position(-half+(step*i),y,0);
				mReferenceObject->colour(c);
				mReferenceObject->position(-half+(step*i),y,0);
				mReferenceObject->colour(c);
				mReferenceObject->position(-half+(step*i),y, half);
				mReferenceObject->colour(BackgroundColour);
			}

			mReferenceObject->end();
			mReferenceObject->setCastShadows(false);
			
			SceneNode *n = gEnv->sceneManager->getRootSceneNode()->createChildSceneNode();
			n->setPosition(pos);
			n->attachObject(mReferenceObject);
			n->setVisible(true);
		}
#ifdef USE_PAGED
		//ugly stuff to parse trees :)
		if (!strncmp("trees", line, 5))
		{
			if (terrainManager->getPagedMode() == 0) continue;
			char ColorMap[256] = {};
			char DensityMap[256] = {};
			char treemesh[256] = {};
			char treeCollmesh[256] = {};
			float gridspacing = 0.0f;
			float yawfrom = 0.0f, yawto = 0.0f;
			float scalefrom = 0.0f, scaleto = 0.0f;
			float highdens = 1.0f;
			int minDist = 90, maxDist = 700;
			sscanf(line, "trees %f, %f, %f, %f, %f, %d, %d, %s %s %s %f %s", &yawfrom, &yawto, &scalefrom, &scaleto, &highdens, &minDist, &maxDist, treemesh, ColorMap, DensityMap, &gridspacing, treeCollmesh);
			if (strnlen(ColorMap, 3) == 0)
			{
				LOG("tree ColorMap map zero!");
				continue;
			}
			if (strnlen(DensityMap, 3) == 0)
			{
				LOG("tree DensityMap zero!");
				continue;
			}
			Forests::DensityMap *densityMap = Forests::DensityMap::load(DensityMap, Forests::CHANNEL_COLOR);
			if (!densityMap)
			{
				LOG("could not load densityMap: "+String(DensityMap));
				continue;
			}
			densityMap->setFilter(Forests::MAPFILTER_BILINEAR);
			//densityMap->setMapBounds(TRect(0, 0, mapsizex, mapsizez));

			paged_geometry_t paged;
			paged.geom = new PagedGeometry();
			paged.geom->setTempDir(SSETTING("User Path", "") + "cache" + SSETTING("dirsep", "\\"));
			paged.geom->setCamera(gEnv->mainCamera);
			paged.geom->setPageSize(50);
			paged.geom->setInfinite();
			Ogre::TRect<Ogre::Real> bounds = TBounds(0, 0, mapsizex, mapsizez);
			paged.geom->setBounds(bounds);

			//Set up LODs
			//trees->addDetailLevel<EntityPage>(50);
			float min = minDist * terrainManager->getPagedDetailFactor();
			if (min<10) min = 10;
			paged.geom->addDetailLevel<BatchPage>(min, min/2);
			float max = maxDist * terrainManager->getPagedDetailFactor();
			if (max<10) max = 10;
			paged.geom->addDetailLevel<ImpostorPage>(max, max/10);
			TreeLoader2D *treeLoader = new TreeLoader2D(paged.geom, TBounds(0, 0, mapsizex, mapsizez));
			paged.geom->setPageLoader(treeLoader);
			treeLoader->setHeightFunction(&getTerrainHeight);
			if (String(ColorMap) != "none")
			{
				treeLoader->setColorMap(ColorMap);
			}

			Entity *curTree = gEnv->sceneManager->createEntity(String("paged_")+treemesh+TOSTRING(pagedGeometry.size()), treemesh);

			if (gridspacing > 0)
			{
				// grid style
				for (float x=0; x < mapsizex; x += gridspacing)
				{
					for (float z=0; z < mapsizez; z += gridspacing)
					{
						float density = densityMap->_getDensityAt_Unfiltered(x, z, bounds);
						if (density < 0.8f) continue;
						float nx = x + gridspacing * 0.5f;
						float nz = z + gridspacing * 0.5f;
						float yaw = Math::RangeRandom(yawfrom, yawto);
						float scale = Math::RangeRandom(scalefrom, scaleto);
						Vector3 pos = Vector3(nx, 0, nz);
						treeLoader->addTree(curTree, pos, Degree(yaw), (Ogre::Real)scale);
						if (strlen(treeCollmesh))
						{
							pos.y = gEnv->terrainManager->getHeightFinder()->getHeightAt(pos.x, pos.z);
							scale *= 0.1f;
							gEnv->collisions->addCollisionMesh(String(treeCollmesh), pos, Quaternion(Degree(yaw), Vector3::UNIT_Y), Vector3(scale, scale, scale));
						}
					}
				}

			} else
			{
				float gridsize = 10;
				if (gridspacing < 0 && gridspacing != 0)
				{
					gridsize = -gridspacing;
				}
				float hd = highdens;
				// normal style, random
				for (float x=0; x < mapsizex; x += gridsize)
				{
					for (float z=0; z < mapsizez; z += gridsize)
					{
						if (highdens < 0) hd = Math::RangeRandom(0, -highdens);
						float density = densityMap->_getDensityAt_Unfiltered(x, z, bounds);
						int numTreesToPlace = (int)((float)(hd) * density * terrainManager->getPagedDetailFactor());
						float nx=0, nz=0;
						while(numTreesToPlace-->0)
						{
							nx = Math::RangeRandom(x, x + gridsize);
							nz = Math::RangeRandom(z, z + gridsize);
							float yaw = Math::RangeRandom(yawfrom, yawto);
							float scale = Math::RangeRandom(scalefrom, scaleto);
							Vector3 pos = Vector3(nx, 0, nz);
							treeLoader->addTree(curTree, pos, Degree(yaw), (Ogre::Real)scale);
							if (strlen(treeCollmesh))
							{
								pos.y = gEnv->terrainManager->getHeightFinder()->getHeightAt(pos.x, pos.z);
								gEnv->collisions->addCollisionMesh(String(treeCollmesh),pos, Quaternion(Degree(yaw), Vector3::UNIT_Y), Vector3(scale, scale, scale));
							}
						}
					}
				}
			}
			paged.loader = (void*)treeLoader;
			pagedGeometry.push_back(paged);
		}

		//ugly stuff to parse grass :)
		if (!strncmp("grass", line, 5) || !strncmp("grass2", line, 6))
		{
			// is paged geometry disabled by configuration?
			if (terrainManager->getPagedMode() == 0) continue;
			int range = 80;
			float SwaySpeed=0.5, SwayLength=0.05, SwayDistribution=10.0, minx=0.2, miny=0.2, maxx=1, maxy=0.6, Density=0.6, minH=-9999, maxH=9999;
			char grassmat[256]="";
			char colorMapFilename[256]="";
			char densityMapFilename[256]="";
			int growtechnique = 0;
			int techn = GRASSTECH_CROSSQUADS;
			if (!strncmp("grass2", line, 6))
				sscanf(line, "grass2 %d, %f, %f, %f, %f, %f, %f, %f, %f, %d, %f, %f, %d, %s %s %s", &range, &SwaySpeed, &SwayLength, &SwayDistribution, &Density, &minx, &miny, &maxx, &maxy, &growtechnique, &minH, &maxH, &techn, grassmat, colorMapFilename, densityMapFilename);
			else if (!strncmp("grass", line, 5))
				sscanf(line, "grass %d, %f, %f, %f, %f, %f, %f, %f, %f, %d, %f, %f, %s %s %s", &range, &SwaySpeed, &SwayLength, &SwayDistribution, &Density, &minx, &miny, &maxx, &maxy, &growtechnique, &minH, &maxH, grassmat, colorMapFilename, densityMapFilename);

			//Initialize the PagedGeometry engine
			try
			{
				paged_geometry_t paged;
				PagedGeometry *grass = new PagedGeometry(gEnv->mainCamera, 30);
				//Set up LODs

				grass->addDetailLevel<GrassPage>(range * terrainManager->getPagedDetailFactor()); // original value: 80

				//Set up a GrassLoader for easy use
				GrassLoader *grassLoader = new GrassLoader(grass);
				grass->setPageLoader(grassLoader);
				grassLoader->setHeightFunction(&getTerrainHeight);

				// render grass at first
				grassLoader->setRenderQueueGroup(RENDER_QUEUE_MAIN-1);

				GrassLayer* grassLayer = grassLoader->addLayer(grassmat);
				grassLayer->setHeightRange(minH, maxH);
				grassLayer->setLightingEnabled(true);

				grassLayer->setAnimationEnabled((SwaySpeed>0));
				grassLayer->setSwaySpeed(SwaySpeed);
				grassLayer->setSwayLength(SwayLength);
				grassLayer->setSwayDistribution(SwayDistribution);

				//String grassdensityTextureFilename = String(DensityMap);

				grassLayer->setDensity(Density * terrainManager->getPagedDetailFactor());
				if (techn>10)
					grassLayer->setRenderTechnique(static_cast<GrassTechnique>(techn-10), true);
				else
					grassLayer->setRenderTechnique(static_cast<GrassTechnique>(techn), false);

				grassLayer->setMapBounds(TBounds(0, 0, mapsizex, mapsizez));

				if (strcmp(colorMapFilename,"none") != 0)
				{
					grassLayer->setColorMap(colorMapFilename);
					grassLayer->setColorMapFilter(MAPFILTER_BILINEAR);
				}

				if (strcmp(densityMapFilename,"none") != 0)
				{
					grassLayer->setDensityMap(densityMapFilename);
					grassLayer->setDensityMapFilter(MAPFILTER_BILINEAR);
				}

				//grassLayer->setMinimumSize(0.5,0.5);
				//grassLayer->setMaximumSize(1.0, 1.0);

				grassLayer->setMinimumSize(minx, miny);
				grassLayer->setMaximumSize(maxx, maxy);

				// growtechnique
				if (growtechnique == 0)
					grassLayer->setFadeTechnique(FADETECH_GROW);
				else if (growtechnique == 1)
					grassLayer->setFadeTechnique(FADETECH_ALPHAGROW);
				else if (growtechnique == 2)
					grassLayer->setFadeTechnique(FADETECH_ALPHA);
				paged.geom = grass;
				paged.loader = (void*)grassLoader;
				pagedGeometry.push_back(paged);
			} catch(...)
			{
				LOG("error loading grass!");
			}

			continue;
		}
#endif //USE_PAGED

		{ // ugly stuff to parse procedural roads
			if (!strncmp("begin_procedural_roads", line, 22))
			{
				po = ProceduralObject();
				po.loadingState = 1;
				r2oldmode = 1;
				proroad = true;
				continue;
			}
			if (!strncmp("end_procedural_roads", line, 20))
			{
				if (r2oldmode)
				{
					if (proceduralManager) proceduralManager->addObject(po);
					po = ProceduralObject();
				}
				proroad = false;
				continue;
			}
			if (proroad)
			{
				float rwidth, bwidth, bheight;
				//position x,y,z rotation rx,ry,rz, width, border width, border height, type
				int r = sscanf(line, "%f, %f, %f, %f, %f, %f, %f, %f, %f, %s",&pos.x,&pos.y,&pos.z, &rot.x, &rot.y, &rot.z, &rwidth, &bwidth, &bheight, oname);
				Quaternion rotation = Quaternion(Degree(rot.x), Vector3::UNIT_X)*Quaternion(Degree(rot.y), Vector3::UNIT_Y)*Quaternion(Degree(rot.z), Vector3::UNIT_Z);
				int roadtype=Road2::ROAD_AUTOMATIC;
				int pillartype = 0;
				if (!strcmp(oname, "flat")) roadtype=Road2::ROAD_FLAT;
				if (!strcmp(oname, "left")) roadtype=Road2::ROAD_LEFT;
				if (!strcmp(oname, "right")) roadtype=Road2::ROAD_RIGHT;
				if (!strcmp(oname, "both")) roadtype=Road2::ROAD_BOTH;
				if (!strcmp(oname, "bridge")) {roadtype=Road2::ROAD_BRIDGE;pillartype=1;}
				if (!strcmp(oname, "monorail")) {roadtype=Road2::ROAD_MONORAIL;pillartype=2;}
				if (!strcmp(oname, "monorail2")) {roadtype=Road2::ROAD_MONORAIL;pillartype=0;}
				if (!strcmp(oname, "bridge_no_pillars")) {roadtype=Road2::ROAD_BRIDGE;pillartype=0;}

				if (r2oldmode)
				{
					//fill object
					ProceduralPoint pp;
					pp.bheight = bheight;
					pp.bwidth = bwidth;
					pp.pillartype = pillartype;
					pp.position = pos;
					pp.rotation = rotation;
					pp.type = roadtype;
					pp.width = rwidth;

					po.points.push_back(pp);
				}
				continue;
			}
		} //end of the ugly (somewhat)

		strcpy(name, "generic");
		memset(oname, 0, 255);
		memset(type, 0, 255);
		memset(name, 0, 255);
		int r = sscanf(line, "%f, %f, %f, %f, %f, %f, %s %s %s",&pos.x,&pos.y,&pos.z, &rot.x, &rot.y, &rot.z, oname, type, name);
		if (r < 6) continue;
		if ((!strcmp(oname, "truck")) || (!strcmp(oname, "load") || (!strcmp(oname, "machine")) || (!strcmp(oname, "boat")) || (!strcmp(oname, "truck2")) ))
		{
			if (!strcmp(oname, "boat") && !terrainManager->getWater())
			{
				// no water so do not load boats!
				continue;
			}
			String group = "";
			String truckname(type);

			if (!RoR::Application::GetCacheSystem()->checkResourceLoaded(truckname, group))
			{
				LOG("Error while loading Terrain: truck " + String(type) + " not found. ignoring.");
				continue;
			}

			truck_prepare_t tempTruckPreload;
			//this is a truck or load declaration
			tempTruckPreload.px = pos.x;
			tempTruckPreload.py = pos.y;
			tempTruckPreload.pz = pos.z;
			tempTruckPreload.freePosition = (!strcmp(oname, "truck2"));
			tempTruckPreload.ismachine = (!strcmp(oname, "machine"));
			tempTruckPreload.rotation = Quaternion(Degree(rot.x), Vector3::UNIT_X)*Quaternion(Degree(rot.y), Vector3::UNIT_Y)*Quaternion(Degree(rot.z), Vector3::UNIT_Z);
			strcpy(tempTruckPreload.name, truckname.c_str());
			truck_preload.push_back(tempTruckPreload);

			continue;
		}
		if (   !strcmp(oname, "road")
			|| !strcmp(oname, "roadborderleft")
			|| !strcmp(oname, "roadborderright")
			|| !strcmp(oname, "roadborderboth")
			|| !strcmp(oname, "roadbridgenopillar")
			|| !strcmp(oname, "roadbridge"))
		{
			int pillartype = !(strcmp(oname, "roadbridgenopillar") == 0);
			// okay, this is a job for roads2
			int roadtype=Road2::ROAD_AUTOMATIC;
			if (!strcmp(oname, "road")) roadtype=Road2::ROAD_FLAT;
			Quaternion rotation;
			rotation = Quaternion(Degree(rot.x), Vector3::UNIT_X)*Quaternion(Degree(rot.y), Vector3::UNIT_Y)*Quaternion(Degree(rot.z), Vector3::UNIT_Z);
			if (pos.distance(r2lastpos) > 20.0f)
			{
				// break the road
				if (r2oldmode != 0)
				{
					// fill object
					ProceduralPoint pp;
					pp.bheight = 0.2;
					pp.bwidth = 1.4;
					pp.pillartype = pillartype;
					pp.position = r2lastpos + r2lastrot * Vector3(10.0f, 0.0f, 0.9f);
					pp.rotation = r2lastrot;
					pp.type = roadtype;
					pp.width = 8;
					po.points.push_back(pp);

					// finish it and start new object
					if (proceduralManager) proceduralManager->addObject(po);
					po = ProceduralObject();
					r2oldmode = 1;
				}
				r2oldmode = 1;
				// beginning of new
				ProceduralPoint pp;
				pp.bheight = 0.2;
				pp.bwidth = 1.4;
				pp.pillartype = pillartype;
				pp.position = pos;
				pp.rotation = rotation;
				pp.type = roadtype;
				pp.width = 8;
				po.points.push_back(pp);
			} else
			{
				// fill object
				ProceduralPoint pp;
				pp.bheight = 0.2;
				pp.bwidth = 1.4;
				pp.pillartype = pillartype;
				pp.position = pos;
				pp.rotation = rotation;
				pp.type = roadtype;
				pp.width = 8;
				po.points.push_back(pp);
			}
			r2lastpos=pos;
			r2lastrot=rotation;

			continue;
		}
		loadObject(oname, pos, rot, bakeNode, name, type);
	}

	// ds closes automatically, so do not close it explicitly here: ds->close();

	// finish the last road
	if (r2oldmode != 0)
	{
		// fill object
		ProceduralPoint pp;
		pp.bheight = 0.2;
		pp.bwidth = 1.4;
		pp.pillartype = 1;
		pp.position = r2lastpos+r2lastrot*Vector3(10.0,0,0);
		pp.rotation = r2lastrot;
		pp.type = Road2::ROAD_AUTOMATIC;
		pp.width = 8;
		po.points.push_back(pp);

		// finish it and start new object
		if (proceduralManager) proceduralManager->addObject(po);
	}
}