本文整理汇总了C++中ogre::ManualObject::colour方法的典型用法代码示例。如果您正苦于以下问题:C++ ManualObject::colour方法的具体用法?C++ ManualObject::colour怎么用?C++ ManualObject::colour使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::ManualObject
的用法示例。
在下文中一共展示了ManualObject::colour方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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: CreateRegion
//-------------------------------------------------------
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));
}
示例3: indicator
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: BuildCellLines
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);
}
示例5: CreateExplosionParticleGeometry
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: createTriangleScene
/**
* 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: addAxesLines
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);
}
示例8: chartToScreen
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));
//.........这里部分代码省略.........
示例9: readModel
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);
}
}
示例10: setupOgreOculus
//.........这里部分代码省略.........
{
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);
}
示例11: update
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;
}
}
示例12: createRecastPolyMesh
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];
//.........这里部分代码省略.........
示例13: CreateThrusterParticleGeometry
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())));
}*/
}
示例14: CreateSplineControlPoints
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;
}
示例15: CreateSplineParticleGeometry
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);
}