std::string createMaterialIfNotExists(const float r, const float g, const float b, const float a) { char buf[128]; sprintf(buf, "ShapeColor%f;%f;%f;%f",r,g,b,a); if(!Ogre::MaterialManager::getSingleton().getByName(buf, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME).isNull()) return buf; Ogre::ColourValue color( r,g,b,a ); Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create( buf, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); mat->setAmbient(color * 0.01f); mat->setDiffuse(color); mat->setLightingEnabled(true); mat->setReceiveShadows(true); mat->setCullingMode(Ogre::CULL_NONE); return buf; }
void ImageSelectionToolCustom::onInitialize() { move_tool_->initialize( context_ ); // Create our highlight rectangle Ogre::SceneManager* scene_manager = context_->getSceneManager(); highlight_node_ = scene_manager->getRootSceneNode()->createChildSceneNode(); std::stringstream ss; static int count = 0; ss << "ImageSelectionRect" << count++; highlight_rectangle_ = new Ogre::Rectangle2D(true); const static uint32_t texture_data[1] = { 0xffff0070 }; Ogre::DataStreamPtr pixel_stream; pixel_stream.bind(new Ogre::MemoryDataStream( (void*)&texture_data[0], 4 )); Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().loadRawData(ss.str() + "Texture", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, pixel_stream, 1, 1, Ogre::PF_R8G8B8A8, Ogre::TEX_TYPE_2D, 0); Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); material->setLightingEnabled(false); //material->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_WIREFRAME); highlight_rectangle_->setMaterial(material->getName()); Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); highlight_rectangle_->setBoundingBox(aabInf); highlight_rectangle_->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY + 4); material->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); material->setCullingMode(Ogre::CULL_NONE); Ogre::TextureUnitState* tex_unit = material->getTechnique(0)->getPass(0)->createTextureUnitState(); tex_unit->setTextureName(tex->getName()); tex_unit->setTextureFiltering( Ogre::TFO_NONE ); highlight_node_->attachObject(highlight_rectangle_); }
//-------------------------------------------------------------------------------------------------- bool DiscoApplication::frameStarted( const Ogre::FrameEvent& evt ) { static Ogre::Timer a; static uint32_t lastTimeMS; static uint32_t curTimeMS; curTimeMS = a.getMilliseconds(); uint32_t timeDiffMS = curTimeMS - lastTimeMS; if ( timeDiffMS > 0 ) { //printf( "FPS = %f\n", 1000.0/(float)timeDiffMS );//1.0/((float)timeDiffMS/1000.0) ); } lastTimeMS = curTimeMS; const int32_t MAX_DEPTH_MM = 10000; const float FOCAL_LENGTH = 0.525f; // Focal length in metres const float FADE_START_XZ_DISTANCE = 0.5f; const float FADE_MAX_XZ_DISTANCE = 6.0f; xn::SceneMetaData sceneMD; xn::DepthMetaData depthMD; mpKinectController->getContext().WaitAndUpdateAll(); mpKinectController->getDepthGenerator().GetMetaData( depthMD ); mpKinectController->getUserGenerator().GetUserPixels( 0, sceneMD ); XnUserID userIdx[15]; XnUInt16 numUsers = 15; mpKinectController->getUserGenerator().GetUsers( userIdx, numUsers ); if ( 0 == numUsers ) { // Restart the time if there are no users to record mRecordingGapTimer.reset(); } else { for ( uint32_t i = 0; i < numUsers; i++ ) { if ( tryToAttachParticleToUser( userIdx[ i ] ) ) { break; } } } // Start recording if we see a person if ( numUsers > 0 && !mbRecording && mRecordingGapTimer.getMilliseconds() > TIME_BETWEEN_RECORDINGS_MS ) { mbRecording = true; memset( mpImageData, 0, RECORDED_DATA_SIZE ); mRecordingFrameIdx = 0; } // Build an accumulative histogram to work out the colour for each point uint32_t depthHist[ MAX_DEPTH_MM ]; memset( depthHist, 0, sizeof( depthHist ) ); uint32_t numPoints = 0; const XnDepthPixel* pDepth = depthMD.Data(); int32_t recordingPixelStepX = depthMD.XRes() / SMALL_FRAME_WIDTH; int32_t recordingPixelStepY = depthMD.YRes() / SMALL_FRAME_HEIGHT; if ( recordingPixelStepX <= 0 ) recordingPixelStepX = 1; if ( recordingPixelStepY <= 0 ) recordingPixelStepY = 1; for ( uint32_t y = 0; y < depthMD.YRes(); y++ ) { for ( uint32_t x = 0; x < depthMD.XRes(); x++ ) { XnUInt16 value = *pDepth; if ( 0 != value ) { depthHist[ value ]++; numPoints++; } pDepth++; } } for ( uint32_t i = 1; i < MAX_DEPTH_MM; i++ ) { depthHist[ i ] += depthHist[ i - 1 ]; } if ( numPoints > 0 ) { for ( uint32_t i = 1; i < MAX_DEPTH_MM; i++ ) { depthHist[ i ] = (unsigned int)(256 * (1.0f - ((float)depthHist[ i ] / numPoints))); } } // Update the point cloud to reflect the depth data const float COLOURS[][3] = { {0,1,1}, {0,0,1}, {0,1,0}, {1,1,0}, {1,0,0}, {1,.5,0}, {.5,1,0}, {0,.5,1}, {.5,0,1}, {1,1,.5}, {1,1,1} }; const uint32_t NUM_COLOURS = 10; pDepth = depthMD.Data(); const XnLabel* pLabels = sceneMD.Data(); mpRosPointCloud->clear(); ogre_tools::PointCloud::Point* pPoints = new ogre_tools::PointCloud::Point[ numPoints ]; int32_t pointIdx = 0; int32_t width = depthMD.XRes(); int32_t height = depthMD.YRes(); int32_t halfWidth = width / 2; int32_t halfHeight = height / 2; for ( int32_t y = 0; y < height; y++ ) { for ( int32_t x = 0; x < width; x++ ) { XnUInt16 value = *pDepth; XnLabel label = *pLabels; XnUInt32 colorId = label % NUM_COLOURS; float fade = 1.0; if (label == 0) { // Ignore background colorId = NUM_COLOURS; } { float worldZ = (float)(*pDepth)/1000.0; // Convert from mm to m float worldX = (((float)(x-halfWidth)/1000.0)*worldZ) / FOCAL_LENGTH; float distanceXZ = sqrtf( worldX*worldX + worldZ*worldZ ); if ( distanceXZ > FADE_MAX_XZ_DISTANCE ) { fade = 0.0f; } else if ( distanceXZ > FADE_START_XZ_DISTANCE ) { fade = 1.0 - (distanceXZ - FADE_START_XZ_DISTANCE)/(FADE_MAX_XZ_DISTANCE - FADE_START_XZ_DISTANCE); } } if ( //mbRecording 0 != value && fade > 0.0 && ( SHOW_BACKGROUND || label != 0 ) ) { float worldZ = (float)(*pDepth)/1000.0; // Convert from mm to m float worldX = (((float)(x-halfWidth)/1000.0)*worldZ) / FOCAL_LENGTH; float worldY = (((float)(y-halfHeight)/1000.0)*worldZ) / FOCAL_LENGTH; //float worldY = (((float)(((height-1)-y)-halfHeight)/1000.0)*worldZ) / FOCAL_LENGTH; float histValue = (float)depthHist[ value ]/255.0; pPoints[ pointIdx ].setColor( fade * histValue * COLOURS[ colorId ][ 0 ], fade * histValue * COLOURS[ colorId ][ 1 ], fade * histValue * COLOURS[ colorId ][ 2 ] ); pPoints[ pointIdx ].x = worldX; pPoints[ pointIdx ].y = worldY; pPoints[ pointIdx ].z = worldZ; pointIdx++; if ( mbRecording && label != 0 && x%recordingPixelStepX == 0 && y%recordingPixelStepY == 0 ) { int32_t smallFrameX = x / recordingPixelStepX; int32_t smallFrameY = y / recordingPixelStepY; int32_t smallPixelIdx = mRecordingFrameIdx*SMALL_FRAME_WIDTH*SMALL_FRAME_HEIGHT + smallFrameY*SMALL_FRAME_WIDTH + smallFrameX; //((uint16_t*)mpImageData)[ smallPixelIdx ] = 0xFFFF; //((uint32_t*)mpImageData)[ smallPixelIdx ] = 0xFFFFFFFF; mpImageData[ smallPixelIdx ] = 0xFF; // 255; //(uint8_t)(fade * histValue * 255.0); //printf( "recorded %i to pixel %i\n", mpImageData[ smallPixelIdx ], smallPixelIdx ); } } pDepth++; pLabels++; } } mpRosPointCloud->addPoints( pPoints, pointIdx ); //printf( "Added %i points\n", pointIdx ); delete [] pPoints; // Draw the crowd uint32_t numCrowdMembers = mCrowdMembers.size(); mpCrowdObject->clear(); mpCrowdObject->estimateVertexCount( numCrowdMembers*4 ); mpCrowdObject->estimateIndexCount( numCrowdMembers*12 ); for ( uint32_t personIdx = 0; personIdx < numCrowdMembers; personIdx++ ) { CrowdMember& crowdMember = mCrowdMembers[ personIdx ]; float startV = (float)crowdMember.mFrameIdx/(float)NUM_FRAMES_TO_RECORD; float endV = (float)(crowdMember.mFrameIdx+1)/(float)NUM_FRAMES_TO_RECORD; mpCrowdObject->begin( crowdMember.mMaterialName, Ogre::RenderOperation::OT_TRIANGLE_LIST ); //float startV = 0.0; //(float)crowdMember.mFrameIdx/(float)NUM_FRAMES_TO_RECORD; //float endV = 1.0;// (float)(crowdMember.mFrameIdx+1)/(float)NUM_FRAMES_TO_RECORD; //mpCrowdObject->begin( "Template/CutOut", Ogre::RenderOperation::OT_TRIANGLE_LIST ); mpCrowdObject->position( crowdMember.mPos + Ogre::Vector3( -0.5f, -0.375f, 0.0f ) ); mpCrowdObject->textureCoord( 0.0, startV ); mpCrowdObject->colour( COLOURS[ crowdMember.mColourIdx ][ 0 ], COLOURS[ crowdMember.mColourIdx ][ 1 ], COLOURS[ crowdMember.mColourIdx ][ 2 ], 1.0 ); mpCrowdObject->position( crowdMember.mPos + Ogre::Vector3( 0.5f, -0.375f, 0.0f ) ); mpCrowdObject->textureCoord( 1.0, startV ); mpCrowdObject->position( crowdMember.mPos + Ogre::Vector3( 0.5f, 0.375f, 0.0f ) ); mpCrowdObject->textureCoord( 1.0, endV ); mpCrowdObject->position( crowdMember.mPos + Ogre::Vector3( -0.5f, 0.375f, 0.0f ) ); mpCrowdObject->textureCoord( 0.0, endV ); //mpCrowdObject->quad( 0, 1, 2, 3 ); mpCrowdObject->quad( 3, 2, 1, 0 ); mpCrowdObject->end(); // Move to the next frame if ( crowdMember.mbReversing ) { crowdMember.mFrameIdx--; if ( crowdMember.mFrameIdx < 0 ) { crowdMember.mFrameIdx = 1; crowdMember.mbReversing = false; } } else { crowdMember.mFrameIdx++; if ( crowdMember.mFrameIdx >= NUM_FRAMES_TO_RECORD ) { crowdMember.mFrameIdx = NUM_FRAMES_TO_RECORD-1; crowdMember.mbReversing = true; } } } // Check to see if we can stop recording if ( mbRecording ) { mRecordingFrameIdx++; if ( mRecordingFrameIdx >= NUM_FRAMES_TO_RECORD ) { // Create a new crowd member Ogre::Image image; image.loadDynamicImage( mpImageData, SMALL_FRAME_WIDTH, NUM_FRAMES_TO_RECORD*SMALL_FRAME_HEIGHT, 1, Ogre::PF_A4L4 ); std::stringstream ss; ss << "RecordedSequenceTex_" << numCrowdMembers; Ogre::String texName = ss.str(); Ogre::TextureManager* pTextureMgr = Ogre::TextureManager::getSingletonPtr(); Ogre::TexturePtr pTexture = pTextureMgr->loadImage( texName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, image ); ss.clear(); ss << "RecordedSequenceMat_" << numCrowdMembers; Ogre::String matName = ss.str(); Ogre::MaterialManager* pMatMgr = Ogre::MaterialManager::getSingletonPtr(); Ogre::MaterialPtr pSrcMat = (Ogre::MaterialPtr)pMatMgr->getByName( "Template/CutOut", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); Ogre::MaterialPtr pMat = pSrcMat->clone( matName ); // (Ogre::MaterialPtr)pMatMgr->create( matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); pMat->getTechnique( 0 )->getPass( 0 )->removeAllTextureUnitStates(); Ogre::TextureUnitState* pTex = pMat->getTechnique( 0 )->getPass( 0 )->createTextureUnitState( texName, 0 ); pMat->getTechnique( 0 )->getPass( 0 )->addTextureUnitState( pTex ); /*Ogre::Technique* pTech = pMat->getTechnique( 0 ); pTech->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA ); Ogre::Pass *pPass = pTech->createPass(); pPass->setLightingEnabled( false ); pPass->setAmbient( 1.0, 1.0, 1.0 ); pPass->setDiffuse( 1.0, 1.0, 1.0, 1.0 ); pPass->setSpecular( 0.0, 0.0, 0.0, 0.0 ); Ogre::ColourValue val(0.0f, 0.0f, 0.0f, 1.0f); pPass->setSelfIllumination(val); //pPass->setE ( 0.0, 0.0, 0.0, 0.0 ); pPass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA ); pPass->setDepthWriteEnabled( false ); Ogre::TextureUnitState* pTex = pPass->createTextureUnitState( texName, 0 ); pPass->addTextureUnitState( pTex ); pTex->setColourOperation( Ogre::LBO_MODULATE );*/ pMat->setCullingMode( Ogre::CULL_NONE ); pMat->compile(); CrowdMember crowdMember; crowdMember.mMaterialName = matName; crowdMember.mFrameIdx = 0; crowdMember.mColourIdx = rand()%NUM_COLOURS; crowdMember.mbReversing = false; int32_t rowIdx = rand()%NUM_ROWS; float angle = MIN_CROWD_ANGLE + ((float)rand()/(float)RAND_MAX)*(MAX_CROWD_ANGLE-MIN_CROWD_ANGLE); float x = ROW_DEPTHS[ rowIdx ]*sin( angle ); float z = ROW_DEPTHS[ rowIdx ]*cos( angle ); crowdMember.mPos = Ogre::Vector3( x, ROW_HEIGHTS[ rowIdx ], z ); mCrowdMembers.push_back( crowdMember ); mbRecording = false; mRecordingGapTimer.reset(); // Reset time so that there's a gap between recording printf( "Got frame\n" ); } } return true; }
void gkMaterialLoader::loadSubMeshMaterial(gkSubMesh* mesh, const gkString& group) { using namespace Ogre; gkMaterialProperties& gma = mesh->getMaterial(); if (gma.m_name.empty()) gma.m_name = "<gkBuiltin/DefaultMaterial>"; Ogre::MaterialPtr oma = Ogre::MaterialManager::getSingleton().getByName(gma.m_name.c_str(), group); if (!oma.isNull()) return; oma = Ogre::MaterialManager::getSingleton().create(gma.m_name, group); if (gma.m_mode & gkMaterialProperties::MA_INVISIBLE) { // disable writing to this material oma->setReceiveShadows(false); oma->setColourWriteEnabled(false); oma->setDepthWriteEnabled(false); oma->setDepthCheckEnabled(false); oma->setLightingEnabled(false); return; } if (gma.m_mode & gkMaterialProperties::MA_TWOSIDE) { oma->setCullingMode(Ogre::CULL_NONE); oma->setManualCullingMode(Ogre::MANUAL_CULL_NONE); } // apply lighting params bool enableLights = (gma.m_mode & gkMaterialProperties::MA_LIGHTINGENABLED) != 0; oma->setReceiveShadows((gma.m_mode & gkMaterialProperties::MA_RECEIVESHADOWS) != 0); oma->setLightingEnabled(enableLights); if (enableLights) { gkColor emissive, ambient, specular, diffuse; emissive = gma.m_diffuse * gma.m_emissive; ambient = gma.m_diffuse * gma.m_ambient; specular = gma.m_specular * gma.m_spec; diffuse = gma.m_diffuse * (gma.m_emissive + gma.m_refraction); emissive.a = ambient.a = specular.a = 1.f; oma->setSelfIllumination(emissive); oma->setAmbient(ambient); oma->setSpecular(specular); oma->setDiffuse(diffuse); oma->setShininess(gma.m_hardness); } Ogre::Pass* pass = oma->getTechnique(0)->getPass(0); bool matBlending = gkEngine::getSingleton().getUserDefs().matblending; if (matBlending && (gma.m_mode & gkMaterialProperties::MA_HASRAMPBLEND)) { switch (gma.m_rblend) { case GK_BT_MULTIPLY: pass->setSceneBlending(SBT_MODULATE); break; case GK_BT_SUBTRACT: pass->setSceneBlending(SBF_ONE_MINUS_SOURCE_COLOUR, SBF_ONE); break; case GK_BT_DARKEN: pass->setSceneBlendingOperation(SBO_MIN); pass->setSceneBlending(SBF_ONE, SBF_ONE); break; case GK_BT_LIGHTEN: pass->setSceneBlendingOperation(SBO_MAX); pass->setSceneBlending(SBF_ONE, SBF_ONE); break; case GK_BT_SCREEN: pass->setSceneBlending(SBF_ONE_MINUS_DEST_COLOUR, SBF_ONE); break; case GK_BT_ADDITIVE: pass->setSceneBlending(SBT_ADD); break; case GK_BT_MIXTURE: default: pass->setSceneBlending(SBF_ONE, SBF_ZERO); break; } } bool hasNormap = false; bool rtss = gkEngine::getSingleton().getUserDefs().rtss; for (int i = 0; i < gma.m_totaltex; ++i) { gkTextureProperties& gte = gma.m_textures[i]; #ifdef OGREKIT_USE_RTSHADER_SYSTEM if (gte.m_mode & gkTextureProperties::TM_NORMAL) { hasNormap = true; continue; } #endif Ogre::TextureUnitState* otus = pass->createTextureUnitState(gte.m_name, gte.m_layer); LayerBlendOperationEx op = LBX_MODULATE; switch (gte.m_blend) { case GK_BT_ADDITIVE: op = LBX_ADD; break; case GK_BT_SUBTRACT: op = LBX_SUBTRACT; break; case GK_BT_DARKEN: case GK_BT_LIGHTEN: case GK_BT_SCREEN: case GK_BT_COLOR: //break; TODO: support more mode case GK_BT_MULTIPLY: case GK_BT_MIXTURE: default: op = LBX_MODULATE; break; } if (i == 0) otus->setColourOperationEx(op, LBS_DIFFUSE, LBS_TEXTURE); else otus->setColourOperationEx(op); otus->setTextureScale(gte.m_scale[0],gte.m_scale[1]); } if (gma.m_mode & gkMaterialProperties::MA_ALPHABLEND) { pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); pass->setDepthWriteEnabled(false); } if (gma.m_mode & gkMaterialProperties::MA_ALPHACLIP) { pass->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 254); } #ifdef OGREKIT_USE_RTSHADER_SYSTEM if (rtss) { //pass->setSpecular(ColourValue::Black); //pass->setShininess(0.0); RTShader::RenderState* rs = 0; RTShader::ShaderGenerator* sg = Ogre::RTShader::ShaderGenerator::getSingletonPtr(); bool ok = sg->createShaderBasedTechnique(gma.m_name, group, Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME); if (ok && hasNormap) { rs = sg->getRenderState(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, gma.m_name, 0); rs->reset(); for (int i = 0; i < gma.m_totaltex; ++i) { gkTextureProperties& gte = gma.m_textures[i]; if (gte.m_mode & gkTextureProperties::TM_NORMAL) { GK_ASSERT(rs); RTShader::SubRenderState* srs= sg->createSubRenderState(RTShader::NormalMapLighting::Type); RTShader::NormalMapLighting* nsrs = static_cast<RTShader::NormalMapLighting*>(srs); if (gte.m_texmode & gkTextureProperties::TX_OBJ_SPACE) nsrs->setNormalMapSpace(RTShader::NormalMapLighting::NMS_OBJECT); else nsrs->setNormalMapSpace(RTShader::NormalMapLighting::NMS_TANGENT); nsrs->setNormalMapTextureName(gte.m_name); nsrs->setTexCoordIndex(gte.m_layer); rs->addTemplateSubRenderState(srs); } } sg->invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, gma.m_name); } } #endif }
void AerialMapDisplay::assembleScene() { if (!dirty_) { return; // nothing to update } dirty_ = false; if (!loader_) { return; // no tiles loaded, don't do anything } // get rid of old geometry, we will re-build this clearGeometry(); // iterate over all tiles and create an object for each of them const double resolution = loader_->resolution(); const std::vector<TileLoader::MapTile> &tiles = loader_->tiles(); for (const TileLoader::MapTile &tile : tiles) { const int w = tile.image().width(); const int h = tile.image().height(); // we here assume that the tiles are uniformly sized... const double tileW = w * resolution; const double tileH = h * resolution; const double origin_x = -loader_->originX() * tileW; const double origin_y = -(1 - loader_->originY()) * tileH; // determine location of this tile const double x = (tile.x() - loader_->tileX()) * tileW + origin_x; const double y = -(tile.y() - loader_->tileY()) * tileH + origin_y; // don't re-use any ids const std::string name_suffix = std::to_string(tile.x()) + "_" + std::to_string(tile.y()) + "_" + std::to_string(map_id_) + "_" + std::to_string(scene_id_); Ogre::TexturePtr tex; if (tile.hasImage()) { // one material per texture std::string matName = "material_" + name_suffix; Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create( matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); material->setReceiveShadows(false); material->getTechnique(0)->setLightingEnabled(false); material->setDepthBias(-16.0f, 0.0f); /// @todo: what the f**k does this do? material->setCullingMode(Ogre::CULL_NONE); material->setDepthWriteEnabled(false); // create textureing unit Ogre::Pass *pass = material->getTechnique(0)->getPass(0); Ogre::TextureUnitState *tex_unit = NULL; if (pass->getNumTextureUnitStates() > 0) { tex_unit = pass->getTextureUnitState(0); } else { tex_unit = pass->createTextureUnitState(); } // only add if we have a texture for it tex = textureFromImage(tile.image(), "texture_" + name_suffix); ROS_INFO("Rendering with texture: %s", tex->getName().c_str()); tex_unit->setTextureName(tex->getName()); tex_unit->setTextureFiltering(Ogre::TFO_BILINEAR); // create an object const std::string obj_name = "object_" + name_suffix; Ogre::ManualObject *obj = scene_manager_->createManualObject(obj_name); scene_node_->attachObject(obj); // configure depth & alpha properties if (alpha_ >= 0.9998) { material->setDepthWriteEnabled(!draw_under_); material->setSceneBlending(Ogre::SBT_REPLACE); } else { material->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); material->setDepthWriteEnabled(false); } if (draw_under_) { obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_4); } else { obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN); } tex_unit->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, alpha_); // create a quad for this tile obj->begin(material->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST); // bottom left obj->position(x, y, 0.0f); obj->textureCoord(0.0f, 0.0f); obj->normal(0.0f, 0.0f, 1.0f); // top right obj->position(x + tileW, y + tileH, 0.0f); obj->textureCoord(1.0f, 1.0f); obj->normal(0.0f, 0.0f, 1.0f); // top left obj->position(x, y + tileH, 0.0f); obj->textureCoord(0.0f, 1.0f); obj->normal(0.0f, 0.0f, 1.0f); // bottom left obj->position(x, y, 0.0f); obj->textureCoord(0.0f, 0.0f); obj->normal(0.0f, 0.0f, 1.0f); // bottom right obj->position(x + tileW, y, 0.0f); obj->textureCoord(1.0f, 0.0f); obj->normal(0.0f, 0.0f, 1.0f); // top right obj->position(x + tileW, y + tileH, 0.0f); obj->textureCoord(1.0f, 1.0f); obj->normal(0.0f, 0.0f, 1.0f); obj->end(); if (draw_under_property_->getValue().toBool()) { // render under everything else obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_4); } MapObject object; object.object = obj; object.texture = tex; object.material = material; objects_.push_back(object); } } scene_id_++; }
void OgreCPP::createNewCrowdMember( float animationTime ) { char buffer[ 512 ]; uint32_t numCrowdMembers = mCrowdMembers.size(); // Create a new crowd member Ogre::TextureManager* pTextureMgr = Ogre::TextureManager::getSingletonPtr(); Ogre::String frameTexNames[ 2*NUM_FRAMES_TO_RECORD ]; Ogre::String lowResFrameTexNames[ 2*NUM_FRAMES_TO_RECORD ]; for ( uint32_t frameIdx = 0; frameIdx < NUM_FRAMES_TO_RECORD; frameIdx++ ) { Ogre::Image image; image.loadDynamicImage( mpImageData + frameIdx*SMALL_FRAME_WIDTH*SMALL_FRAME_HEIGHT, SMALL_FRAME_WIDTH, SMALL_FRAME_HEIGHT, 1, Ogre::PF_A4L4 ); sprintf( buffer, "RecordedSequenceTex_%i_%i", numCrowdMembers, frameIdx ); frameTexNames[ frameIdx ] = buffer; Ogre::TexturePtr pTexture = pTextureMgr->loadImage( frameTexNames[ frameIdx ], Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, image ); sprintf( buffer, "LowResRecordedSequenceTex_%i_%i", numCrowdMembers, frameIdx ); lowResFrameTexNames[ frameIdx ] = buffer; Ogre::Image lowResImage; lowResImage.loadDynamicImage( mpLowResImageData + frameIdx*LOW_RES_SMALL_FRAME_WIDTH*LOW_RES_SMALL_FRAME_HEIGHT, LOW_RES_SMALL_FRAME_WIDTH, LOW_RES_SMALL_FRAME_HEIGHT, 1, Ogre::PF_A4L4 ); pTextureMgr->loadImage( lowResFrameTexNames[ frameIdx ], Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, lowResImage ); } for ( uint32_t frameIdx = 0; frameIdx < NUM_FRAMES_TO_RECORD; frameIdx++ ) { frameTexNames[ (2*NUM_FRAMES_TO_RECORD - 1) - frameIdx ] = frameTexNames[ frameIdx ]; lowResFrameTexNames[ (2*NUM_FRAMES_TO_RECORD - 1) - frameIdx ] = lowResFrameTexNames[ frameIdx ]; } // Create materials for the crowd member sprintf( buffer, "RecordedSequenceMat_%i", numCrowdMembers ); Ogre::String matName = buffer; Ogre::MaterialManager* pMatMgr = Ogre::MaterialManager::getSingletonPtr(); Ogre::MaterialPtr pSrcMat = (Ogre::MaterialPtr)pMatMgr->getByName( "Template/CutOut", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); Ogre::MaterialPtr pMat = pSrcMat->clone( matName ); pMat->getTechnique( 0 )->getPass( 0 )->removeAllTextureUnitStates(); Ogre::TextureUnitState* pTex = pMat->getTechnique( 0 )->getPass( 0 )->createTextureUnitState(); pMat->getTechnique( 0 )->getPass( 0 )->addTextureUnitState( pTex ); pTex->setAnimatedTextureName( frameTexNames, 2*NUM_FRAMES_TO_RECORD, 2.0*animationTime ); pMat->setCullingMode( Ogre::CULL_NONE ); pMat->compile(); sprintf( buffer, "LowResRecordedSequenceMat_%i", numCrowdMembers ); Ogre::String lowResMatName = buffer; pMat = pSrcMat->clone( lowResMatName ); pMat->getTechnique( 0 )->getPass( 0 )->removeAllTextureUnitStates(); pTex = pMat->getTechnique( 0 )->getPass( 0 )->createTextureUnitState(); pMat->getTechnique( 0 )->getPass( 0 )->addTextureUnitState( pTex ); pTex->setAnimatedTextureName( lowResFrameTexNames, 2*NUM_FRAMES_TO_RECORD, 2.0*animationTime ); pMat->setCullingMode( Ogre::CULL_NONE ); pMat->compile(); CrowdMember newCrowdMember; newCrowdMember.mMaterialName = matName; newCrowdMember.mLowResMaterialName = lowResMatName; newCrowdMember.mFrameIdx = 0; newCrowdMember.mColourIdx = rand()%NUM_COLOURS; newCrowdMember.mbReversing = false; num = mCrowdMembers.size()%11; /** POSITION CROWD MEMBER HERE **/ float x = (num*(5.0/11.0))-2.25; float y = 1.5; /* centre is 0,0, extremes are -3,+3 */ newCrowdMember.mPos = Ogre::Vector3( x, y, 5.0 ); newCrowdMember.mRow = 0; newCrowdMember.mpBillboard = OGRE_NEW PersonBillboard(); newCrowdMember.mpBillboard->setMaterial( newCrowdMember.mMaterialName ); newCrowdMember.mpBillboard->setCorners( Ogre::Vector3( -0.5f, -0.375f, 0.0f ), Ogre::Vector3( 0.5f, -0.375f, 0.0f ), Ogre::Vector3( -0.5f, 0.375f, 0.0f ), Ogre::Vector3( 0.5f, 0.375f, 0.0f ) ); // Make sure that the front row is drawn in front of everything else newCrowdMember.mpBillboard->setRenderQueueGroup( CROWD_FRONT_RENDER_QUEUE ); newCrowdMember.mpSceneNode = mpDiscoNode->createChildSceneNode( newCrowdMember.mPos, Ogre::Quaternion::IDENTITY ); newCrowdMember.mpSceneNode->attachObject( newCrowdMember.mpBillboard ); mCrowdMembers.push_back( newCrowdMember ); /* PLACING RT USER IN CROWD HERE */ if(USER_IN_CROWD){ float userX = (((num+1)%CROWD_WIDTH)*(12.0/(float)CROWD_WIDTH))-5.5; mUserNode->setPosition(userX,3.45,9.5); } /** PUSH ROW UP **/ if (num >= CROWD_WIDTH-1) { // push last row up for(int j = 0; j < mCrowdMembers.size(); j++) { mCrowdMembers[j].mPos.z += CROWD_PUSH_BACK; mCrowdMembers[j].mPos.y += CROWD_PUSH_UP; mCrowdMembers[j].mpSceneNode->setPosition( mCrowdMembers[j].mPos ); mCrowdMembers[j].mRow++; if ( FIRST_LOW_RES_ROW_IDX == mCrowdMembers[j].mRow ) { mCrowdMembers[j].mpBillboard->setMaterial( mCrowdMembers[j].mLowResMaterialName ); } if ( mCrowdMembers[j].mRow > MAX_VISIBLE_ROW_IDX ) { mCrowdMembers[j].mpBillboard->setVisible( false ); mCrowdMembers[j].mpBillboard->setMaterial( "BaseWhiteNoLighting" ); } else { mCrowdMembers[j].mpBillboard->setRenderQueueGroup( CROWD_FRONT_RENDER_QUEUE - mCrowdMembers[j].mRow ); } } } }