本文整理汇总了C++中ogre::MaterialPtr::createTechnique方法的典型用法代码示例。如果您正苦于以下问题:C++ MaterialPtr::createTechnique方法的具体用法?C++ MaterialPtr::createTechnique怎么用?C++ MaterialPtr::createTechnique使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::MaterialPtr
的用法示例。
在下文中一共展示了MaterialPtr::createTechnique方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitHydrax
void MyTerrain::InitHydrax()
{
if(Global::UseHydrax)
{
m_pHydrax=new Hydrax::Hydrax(m_pSceneMgr,MyGameApp::GetSingleton().GetMainCamera(),MyGameApp::GetSingleton().GetRenderWindow()->getViewport(0));
Hydrax::Module::ProjectedGrid *mModule
= new Hydrax::Module::ProjectedGrid(
m_pHydrax,
new Hydrax::Noise::Perlin(/*Generic one*/),
Ogre::Plane(Ogre::Vector3(0,1,0), Ogre::Vector3(0,0,0)),
Hydrax::MaterialManager::NM_VERTEX,
Hydrax::Module::ProjectedGrid::Options(/*264 /*Generic one*/));
m_pHydrax->setModule(static_cast<Hydrax::Module::Module*>(mModule));
m_pHydrax->loadCfg("Hydrax.hdx");
auto ti=m_pTerrainGroup->getTerrainIterator();
while(ti.hasMoreElements())
{
Ogre::Terrain* t = ti.getNext()->instance;
Ogre::MaterialPtr pMat = t->getMaterial();
m_pHydrax->getMaterialManager()->addDepthTechnique(pMat->createTechnique());
}
m_pHydrax->create();
}
}
示例2: mCudaRoot
GPUSurfFeatureDetector::GPUSurfFeatureDetector(Ogre::Cuda::Root* root, int nbOctave, int nbFeatureMax)
: mCudaRoot(root)
{
mOgreIsAllocated = false;
mCudaIsAllocated = false;
mWidth = 0;
mHeight = 0;
mNbFeatureMax = nbFeatureMax;
mNbOctave = nbOctave;
mThreshold = 0.003f;
mNbFeatureFound = 0;
mGPGPURoot = new Ogre::GPGPU::Root;
mWebcamTexture = Ogre::TextureManager::getSingleton().createManual("WebcamVideoTexture", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 640, 480, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
//Create Webcam Material
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("WebcamVideoMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::Technique *technique = material->createTechnique();
technique->createPass();
material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
material->getTechnique(0)->getPass(0)->createTextureUnitState("WebcamVideoTexture");
}
示例3: compileMaterial
bool Simple::compileMaterial(Ogre::MaterialPtr material, std::set<std::string>& managedTextures) const
{
material->removeAllTechniques();
Ogre::Technique* technique = material->createTechnique();
if (!mTerrainPageSurfaces.empty()) {
//First add a base pass
auto surfaceLayer = mTerrainPageSurfaces.begin()->second;
Ogre::Pass* pass = technique->createPass();
pass->setLightingEnabled(false);
Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState();
textureUnitState->setTextureScale(1.0f / surfaceLayer->getScale(), 1.0f / surfaceLayer->getScale());
textureUnitState->setTextureName(surfaceLayer->getDiffuseTextureName());
textureUnitState->setTextureCoordSet(0);
for (auto& layer : mLayers) {
addPassToTechnique(*mGeometry, technique, layer, managedTextures);
}
}
if (mTerrainPageShadow) {
addShadow(technique, mTerrainPageShadow, material, managedTextures);
}
// addLightingPass(technique, managedTextures);
material->load();
if (material->getNumSupportedTechniques() == 0) {
S_LOG_WARNING("The material '" << material->getName() << "' has no supported techniques. The reason for this is: \n" << material->getUnsupportedTechniquesExplanation());
return false;
}
return true;
}
示例4: compileMaterial
bool Simple::compileMaterial(Ogre::MaterialPtr material)
{
material->removeAllTechniques();
Ogre::Technique* technique = material->createTechnique();
for (SurfaceLayerStore::const_iterator I = mTerrainPageSurfaces.begin(); I != mTerrainPageSurfaces.end(); ++I) {
const TerrainPageSurfaceLayer* surfaceLayer = I->second;
if (I == mTerrainPageSurfaces.begin()) {
Ogre::Pass* pass = technique->createPass();
pass->setLightingEnabled(false);
//add the first layer of the terrain, no alpha or anything
Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState();
textureUnitState->setTextureScale(1.0f / surfaceLayer->getScale(), 1.0f / surfaceLayer->getScale());
textureUnitState->setTextureName(surfaceLayer->getDiffuseTextureName());
textureUnitState->setTextureCoordSet(0);
} else {
if (surfaceLayer->intersects(*mGeometry)) {
addPassToTechnique(*mGeometry, technique, surfaceLayer);
}
}
}
if (mTerrainPageShadow) {
addShadow(technique, mTerrainPageShadow, material);
}
material->load();
if (material->getNumSupportedTechniques() == 0) {
S_LOG_WARNING("The material '" << material->getName() << "' has no supported techniques. The reason for this is: \n" << material->getUnsupportedTechniquesExplanation());
return false;
}
return true;
}
示例5: forceCreateFirstTexture
//-----------------------------------------------------------------------
Ogre::TextureUnitState* MaterialTab::forceCreateFirstTexture(const Ogre::String textureName)
{
// Ignore some materials because they result in a crash while unloading
wxString materialName = mMaterialListBox->GetStringSelection();
if (materialName == wxT("DefaultSettings"))
return 0;
Ogre::Technique* technique = 0;
Ogre::TextureUnitState* texture = 0;
Ogre::Pass* pass = getFirstPass();
if (pass)
{
// There is a pass, check for textures or create one
if (pass->getNumTextureUnitStates() > 0)
{
pass->removeAllTextureUnitStates();
}
texture = pass->createTextureUnitState(textureName);
}
else
{
// There is no pass
wxString materialName = mMaterialListBox->GetStringSelection();
Ogre::String name = wx2ogre(materialName);
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(name);
if (!material.isNull())
{
material->load();
if (material->getNumTechniques() > 0)
{
technique = material->getBestTechnique(); // Get the best technique
pass = technique->createPass();
texture = pass->createTextureUnitState(textureName);
}
else
{
// There is no technique, no pass and no textureunitstate
technique = material->createTechnique();
pass = technique->createPass();
texture = pass->createTextureUnitState(textureName);
}
}
}
return texture;
}
示例6: IComponent
EC_WidgetCanvas::EC_WidgetCanvas(Scene *scene) :
IComponent(scene),
widget_(0),
update_internals_(false),
mesh_hooked_(false),
refresh_timer_(0),
update_interval_msec_(0),
material_name_(""),
texture_name_("")
{
if (framework->IsHeadless())
return;
if (framework->Renderer())
{
// Create texture
texture_name_ = framework->Renderer()->GetUniqueObjectName("EC_3DCanvas_tex");
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual(
texture_name_, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, 1, 1, 0, Ogre::PF_A8R8G8B8,
Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
if (texture.isNull())
{
LogError("EC_WidgetCanvas: Could not create texture for usage!");
return;
}
// Create material: Make sure we have one tech with one pass with one texture unit.
// Don't use our lit textured templates here as emissive will not work there as it has vertex etc programs in it.
material_name_ = framework->Renderer()->GetUniqueObjectName("EC_3DCanvas_mat");
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(material_name_, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (material->getNumTechniques() == 0)
material->createTechnique();
if (material->getTechnique(0) &&
material->getTechnique(0)->getNumPasses() == 0)
material->getTechnique(0)->createPass();
if (material->getTechnique(0)->getPass(0) &&
material->getTechnique(0)->getPass(0)->getNumTextureUnitStates() == 0)
material->getTechnique(0)->getPass(0)->createTextureUnitState(texture_name_);
}
connect(this, SIGNAL(ParentEntitySet()), SLOT(ParentEntitySet()), Qt::UniqueConnection);
}
示例7: logic_error
Camera::Camera(Event::Lane& lane,
GameHandle cameraHandle,
Ogre::SceneNode* camNode,
Ogre::RenderTarget* renderTarget,
u32 width,
u32 height,
const v3& position,
const qv4& orientation,
GameHandle parent) :
mSubLane(lane.createSubLane()),
mCameraNode(camNode),
mRenderTarget(renderTarget),
mHandle(cameraHandle),
mNodeCreated(false),
mRenderTargetCreated(false)
{
Ogre::SceneManager* sceneMgr = Ogre::Root::getSingleton().getSceneManager(BFG_SCENEMANAGER);
if (mCameraNode == NULL) // Create SceneNode
{
if (sceneMgr->hasSceneNode(stringify(mHandle)))
{
mCameraNode = sceneMgr->getSceneNode(stringify(mHandle));
}
else
{
mCameraNode = sceneMgr->getRootSceneNode()->createChildSceneNode(stringify(mHandle));
mNodeCreated = true;
}
}
mCameraNode->setOrientation(toOgre(orientation));
mCameraNode->setPosition(toOgre(position));
v3 target = toBFG(mCameraNode->getOrientation().zAxis());
norm(target);
Ogre::Camera* cam;
cam = sceneMgr->createCamera(stringify(mHandle));
cam->setFOVy(Ogre::Degree(60.0f));
cam->setNearClipDistance(0.1f);
cam->setFarClipDistance(250000.0f);
cam->lookAt(toOgre(target)*10);
mCameraNode->attachObject(cam);
infolog << "Camera: " << stringify(mHandle) << " created.";
if (mRenderTarget == NULL)
{
// Create renderToTexture RenderTarget
if (width == 0 || height == 0)
{
throw std::logic_error("Too few information to create a render target.");
}
cam->setAspectRatio((f32)width / (f32)height);
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual
(
stringify(mHandle),
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D,
width,
height,
0,
Ogre::PF_R8G8B8,
Ogre::TU_RENDERTARGET
);
mRenderTarget = texture->getBuffer()->getRenderTarget();
prepareRenderTarget();
mRenderTarget->addViewport(cam);
mRenderTarget->getViewport(0)->setClearEveryFrame(true);
mRenderTarget->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black);
mRenderTarget->getViewport(0)->setOverlaysEnabled(false);
Ogre::MaterialPtr mat =
Ogre::MaterialManager::getSingleton().getByName(stringify(mHandle));
if (mat.isNull())
{
mat = Ogre::MaterialManager::getSingleton().create(
stringify(mHandle),
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
}
Ogre::Technique* tech = mat->getTechnique(0);
if (!tech)
{
tech = mat->createTechnique();
}
Ogre::Pass* pass = tech->getPass(0);
if (!pass)
{
pass = tech->createPass();
}
pass->setLightingEnabled(false);
if (pass->getNumTextureUnitStates() > 0)
//.........这里部分代码省略.........
示例8: setupScene
void Game::setupScene()
{
// Init stuff for render to texture - Minimap
// First the texture
rtt_texture_minimap = Ogre::TextureManager::getSingleton().createManual("RttTex",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
OgreFW::getSingletonPtr()->m_pRenderWnd->getWidth(),
OgreFW::getSingletonPtr()->m_pRenderWnd->getHeight(),
0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
// Then, get its render target
renderTextureTarget = rtt_texture_minimap->getBuffer()->getRenderTarget();
renderTextureTarget->addViewport(OgreFW::getSingletonPtr()->m_pCamera);
renderTextureTarget->getViewport(0)->setClearEveryFrame(true);
renderTextureTarget->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black);
renderTextureTarget->getViewport(0)->setOverlaysEnabled(false);
// Set it active!
renderTextureTarget->setActive(true);
// Last, the mini rectangle
mMiniScreen = new Ogre::Rectangle2D(true);
mMiniScreen->setCorners(0.75f, -0.75f, 1.0f, -1.0f);
mMiniScreen->setBoundingBox(Ogre::AxisAlignedBox(-100000.0f * Ogre::Vector3::UNIT_SCALE, 100000.0f * Ogre::Vector3::UNIT_SCALE));
// Scenenode, then add
mMiniScreenSN = OgreFW::getSingletonPtr()->m_pSceneMgr->getRootSceneNode()->createChildSceneNode("MiniScreenNode");
mMiniScreenSN->attachObject(mMiniScreen);
// The texture needs its material
Ogre::MaterialPtr renderMaterial = Ogre::MaterialManager::getSingleton().create("RttMat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::Technique* matTechnique = renderMaterial->createTechnique();
matTechnique->createPass();
renderMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);
renderMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
mMiniScreen->setMaterial("RttMat");
//Register this as a listener
renderTextureTarget->addListener(this);
// Init the CollisionHandler
GameCollisionHandler = new CollisionHandler(OgreFW::getSingletonPtr()->m_pSceneMgr);
// Init the first level
myLevel = myLevelFactory->create();
// Pass the LevelObjects to the collision_handler
std::vector<LevelBlock*> levobjs = myLevel->getLevelObjects();
for (std::vector<LevelBlock*>::iterator i = levobjs.begin(); i != levobjs.end(); ++i) {
GameCollisionHandler->addNewObject(*i);
}
// The skybox!
OgreFW::getSingletonPtr()->m_pSceneMgr->setSkyDome(true, "Examples/CloudySky");
// Activate shadows
OgreFW::getSingletonPtr()->m_pSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_MODULATIVE);
// Create Lights
// Set the ambient light
OgreFW::getSingletonPtr()->m_pSceneMgr->setAmbientLight(Ogre::ColourValue(0.15, 0.15, 0.15));
// Create a Directional light
Ogre::Light* lptr = OgreFW::getSingletonPtr()->m_pSceneMgr->createLight("dirLight");
lptr->setType(Ogre::Light::LT_DIRECTIONAL);
lptr->setDiffuseColour(Ogre::ColourValue(0.4, 0.4, 0));
lptr->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0));
lptr->setDirection(Ogre::Vector3( 0, -1, 0 ));
sceneLights.push_back(lptr);
// Create a Point Light
Ogre::Light* lptrpoint = OgreFW::getSingletonPtr()->m_pSceneMgr->createLight("pointLight");
lptrpoint->setType(Ogre::Light::LT_POINT);
lptrpoint->setPosition(Ogre::Vector3(0, OBJ_SIZE_Y * myLevel->getHeight() * 2, 0));
lptrpoint->setDiffuseColour(1.0, 0.0, 0.0);
lptrpoint->setSpecularColour(1.0, 0.0, 0.0);
sceneLights.push_back(lptrpoint);
// Camera settings - TODO
//OgreFW::getSingletonPtr()->moveCameraToPos(Ogre::Vector3( OBJ_SIZE_X, OBJ_SIZE_Y, OBJ_SIZE_Z));
OgreFW::getSingletonPtr()->moveCameraToPos(Ogre::Vector3( myLevel->getWidth() * OBJ_SIZE_X / 2, OBJ_SIZE_Y * myLevel->getHeight() / 2, OBJ_SIZE_Z * 5));
//OgreFW::getSingletonPtr()->setCameraLookAt(Ogre::Vector3(OBJ_SIZE_X * myLevel->getWidth() /2, OBJ_SIZE_Y, 0.0f));
OgreFW::getSingletonPtr()->setCameraLookAt(Ogre::Vector3( myLevel->getWidth() * OBJ_SIZE_X / 2, OBJ_SIZE_Y * (myLevel->getHeight() -1) / 2, 0.0f));
// Set the camerapos for rendering the minimap
cameraPosMap = Ogre::Vector3(OBJ_SIZE_X * myLevel->getWidth() / 2, OBJ_SIZE_Y * myLevel->getHeight() / 2, OBJ_SIZE_Z * 10);
// Request a sunEffect for creating the sun
EffectsFactory::getSingletonPtr()->createSunEffect(myLevel->getWidth() * myLevel->getObjectSide() / 2 , myLevel->getHeight() * myLevel->getObjectSide() / 2 , -60.0f);
// We move to the first game state
currentGameStage = MAIN_MENU_STATE;
// Load the GUI sheet
OgreFW::getSingletonPtr()->mGUIRootWindow = CEGUI::WindowManager::getSingleton().loadWindowLayout("myL2.layout");
//CEGUI::Window *guiRoot = CEGUI::WindowManager::getSingleton().getWindow(
CEGUI::System::getSingleton().setGUISheet(OgreFW::getSingletonPtr()->mGUIRootWindow);
CEGUI::Window* eventButton = OgreFW::getSingletonPtr()->mGUIRootWindow->getChild("MainMenuRoot/LocalGame");
if (eventButton) {
std::cout << "Yes I got it" << std::endl;
// Register handler
eventButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::SubscriberSlot(&Game::setupLocalGame, this));
//std::cout << "Text: " << eventButton->getText() << std::endl;
}
eventButton = OgreFW::getSingletonPtr()->mGUIRootWindow->getChild("MainMenuRoot/NetClient");
if (eventButton) {
//.........这里部分代码省略.........
示例9: createActions
//.........这里部分代码省略.........
mNodeEditor->addNode(mMaterialNode);
}
}
//****************************************************************************/
void EditorDockWidget::doTechniqueHToolbarAction(void)
{
// Add a technique node
Magus::QtNodeTechnique* techniqueNode = new Magus::QtNodeTechnique(NODE_TITLE_TECHNIQUE);
mNodeEditor->addNode(techniqueNode);
}
//****************************************************************************/
void EditorDockWidget::doPassHToolbarAction(void)
{
// Add a pass node
Magus::QtNodePass* passNode = new Magus::QtNodePass(NODE_TITLE_PASS);
mNodeEditor->addNode(passNode);
}
//****************************************************************************/
void EditorDockWidget::doTextureHToolbarAction(void)
{
// Add a texture unit node
Magus::QtNodeTextureUnit* textureUnitNode = new Magus::QtNodeTextureUnit(NODE_TITLE_TEXTURE_UNIT);
mNodeEditor->addNode(textureUnitNode);
}
//****************************************************************************/
void EditorDockWidget::doCogHToolbarAction(void)
{
if (!mMaterialNode)
return;
if (mMaterialNode->getMaterialName().isEmpty())
return;
// ---------------------------------------- Create a material ----------------------------------------
Ogre::LogManager* logManager = Ogre::LogManager::getSingletonPtr();
Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
Ogre::String materialName = mMaterialNode->getMaterialName().toStdString(); // Convert to std format
logManager->logMessage("SME: create Ogre material: " + materialName);
Ogre::MaterialPtr material = materialManager->create(materialName, "General");
// Remark: Sceneblending is done for each pass individually, although it is defined on material level
// ---------------------------------------- Add the technique ----------------------------------------
Magus::QtNode* node = mMaterialNode->getNodeConnectedToPort(PORT_TECHNIQUE_OUT);
if (!node)
{
logManager->logMessage("SME: No technique node available");
return;
}
Magus::QtNodeTechnique* techniqueNode = static_cast<Magus::QtNodeTechnique*>(node);
material->removeAllTechniques();
Ogre::Technique* technique = material->createTechnique();
technique->removeAllPasses();
logManager->logMessage("SME: Technique created" + Ogre::StringConverter::toString(material->getNumTechniques()));
// ---------------------------------------- Add the passes ----------------------------------------
Magus::QtNodePass* passNode;
Magus::QtNodeTextureUnit* textureUnitNode;
Ogre::Pass* pass;
Ogre::TextureUnitState* textureUnit;
for (unsigned int i = 1; i < 5; ++i)
{
node = techniqueNode->getNodeConnectedToPort(PORT_PASS_OUT, i); // node with the same name
if (node)
{
passNode = static_cast<Magus::QtNodePass*>(node);
pass = technique->createPass();
pass->removeAllTextureUnitStates();
logManager->logMessage("SME: Pass on port nr. " + Ogre::StringConverter::toString(i) + " created");
propagatePassNodeData(passNode, pass);
// ---------------------------------------- Add the texture units ----------------------------------------
for (unsigned int j = 1; j < 9; ++j)
{
node = passNode->getNodeConnectedToPort(PORT_TEXTURE_OUT, j);
if (node)
{
logManager->logMessage("SME: Texture unit on port nr. " +
Ogre::StringConverter::toString(j) +
" of Pass port nr. " +
Ogre::StringConverter::toString(i) +
" created");
textureUnitNode = static_cast<Magus::QtNodeTextureUnit*>(node);
textureUnit = pass->createTextureUnitState();
propagateTextureUnitNodeData(textureUnitNode, textureUnit);
}
}
}
}
// Assign the material to the ogrehead
material->compile();
material->load();
mParent->getOgreManager()->getOgreWidget(1)->mEntity->setMaterial(material);
}
示例10: initOgreAR
int initOgreAR(aruco::CameraParameters camParams, unsigned char* buffer, std::string resourcePath)
{
/// INIT OGRE FUNCTIONS
#ifdef _WIN32
root = new Ogre::Root(resourcePath + "plugins_win.cfg", resourcePath + "ogre_win.cfg");
#elif __x86_64__ || __ppc64__
root = new Ogre::Root(resourcePath + "plugins_x64.cfg", resourcePath + "ogre.cfg");
#else
root = new Ogre::Root(resourcePath + "plugins.cfg", resourcePath + "ogre.cfg");
#endif
if (!root->showConfigDialog()) return -1;
Ogre::SceneManager* smgr = root->createSceneManager(Ogre::ST_GENERIC);
/// CREATE WINDOW, CAMERA AND VIEWPORT
Ogre::RenderWindow* window = root->initialise(true);
Ogre::Camera *camera;
Ogre::SceneNode* cameraNode;
camera = smgr->createCamera("camera");
camera->setNearClipDistance(0.01f);
camera->setFarClipDistance(10.0f);
camera->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
camera->setPosition(0, 0, 0);
camera->lookAt(0, 0, 1);
double pMatrix[16];
camParams.OgreGetProjectionMatrix(camParams.CamSize,camParams.CamSize, pMatrix, 0.05,10, false);
Ogre::Matrix4 PM(pMatrix[0], pMatrix[1], pMatrix[2] , pMatrix[3],
pMatrix[4], pMatrix[5], pMatrix[6] , pMatrix[7],
pMatrix[8], pMatrix[9], pMatrix[10], pMatrix[11],
pMatrix[12], pMatrix[13], pMatrix[14], pMatrix[15]);
camera->setCustomProjectionMatrix(true, PM);
camera->setCustomViewMatrix(true, Ogre::Matrix4::IDENTITY);
window->addViewport(camera);
cameraNode = smgr->getRootSceneNode()->createChildSceneNode("cameraNode");
cameraNode->attachObject(camera);
/// CREATE BACKGROUND FROM CAMERA IMAGE
int width = camParams.CamSize.width;
int height = camParams.CamSize.height;
// create background camera image
mPixelBox = Ogre::PixelBox(width, height, 1, Ogre::PF_R8G8B8, buffer);
// Create Texture
mTexture = Ogre::TextureManager::getSingleton().createManual("CameraTexture",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D,width,height,0,Ogre::PF_R8G8B8,Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
//Create Camera Material
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("CameraMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::Technique *technique = material->createTechnique();
technique->createPass();
material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
material->getTechnique(0)->getPass(0)->createTextureUnitState("CameraTexture");
Ogre::Rectangle2D* rect = new Ogre::Rectangle2D(true);
rect->setCorners(-1.0, 1.0, 1.0, -1.0);
rect->setMaterial("CameraMaterial");
// Render the background before everything else
rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND);
// Hacky, but we need to set the bounding box to something big, use infinite AAB to always stay visible
Ogre::AxisAlignedBox aabInf;
aabInf.setInfinite();
rect->setBoundingBox(aabInf);
// Attach background to the scene
Ogre::SceneNode* node = smgr->getRootSceneNode()->createChildSceneNode("Background");
node->attachObject(rect);
/// CREATE SIMPLE OGRE SCENE
// add sinbad.mesh
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(resourcePath + "Sinbad.zip", "Zip", "Popular");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
for(int i=0; i<MAX_MARKERS; i++) {
Ogre::String entityName = "Marker_" + Ogre::StringConverter::toString(i);
Ogre::Entity* ogreEntity = smgr->createEntity(entityName, "Sinbad.mesh");
Ogre::Real offset = ogreEntity->getBoundingBox().getHalfSize().y;
ogreNode[i] = smgr->getRootSceneNode()->createChildSceneNode();
// add entity to a child node to correct position (this way, entity axis is on feet of sinbad)
Ogre::SceneNode *ogreNodeChild = ogreNode[i]->createChildSceneNode();
ogreNodeChild->attachObject(ogreEntity);
// Sinbad is placed along Y axis, we need to rotate to put it along Z axis so it stands up over the marker
// first rotate along X axis, then add offset in Z dir so it is over the marker and not in the middle of it
ogreNodeChild->rotate(Ogre::Vector3(1,0,0), Ogre::Radian(Ogre::Degree(90)));
ogreNodeChild->translate(0,0,offset,Ogre::Node::TS_PARENT);
// mesh is too big, rescale!
const float scale = 0.006675f;
ogreNode[i]->setScale(scale, scale, scale);
// Init animation
ogreEntity->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE);
if(i==0)
{
baseAnim[i] = ogreEntity->getAnimationState("HandsClosed");
topAnim[i] = ogreEntity->getAnimationState("HandsRelaxed");
}
else if(i==1)
{
//.........这里部分代码省略.........
示例11: createBackground
/*!
Create a color background to show the real scene.
\param I : This parameter is here only used to initialize a color background.
*/
void vpAROgre::createBackground(vpImage<vpRGBa> & /* I */)
{
// Create a rectangle to show the incoming images from the camera
mBackground = new Ogre::Rectangle2D(true); // true = textured
mBackground->setCorners(-1.0, 1.0, 1.0, -1.0); // Spread all over the window
mBackground->setBoundingBox(Ogre::AxisAlignedBox(-100000.0*Ogre::Vector3::UNIT_SCALE, 100000.0*Ogre::Vector3::UNIT_SCALE)); // To be shown everywhere
// Texture options
Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_NONE);
Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(1);
// Dynamic texture
// If we are using opengl we can boost a little bit performances with a dynamic texture
if(mRoot->getRenderSystem()->getName() == "OpenGL Rendering Subsystem") {
Ogre::TextureManager::getSingleton().createManual("BackgroundTexture",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D,
mBackgroundWidth,//width
mBackgroundHeight,//height
0, // num of mip maps
//Ogre::PF_BYTE_RGBA,
Ogre::PF_BYTE_BGRA,
Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
}
else{ // As that texture does not seem to work properly with direct3D we use a default texture
Ogre::TextureManager::getSingleton().createManual("BackgroundTexture",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D,
mBackgroundWidth,//width
mBackgroundHeight,//height
0, // num of mip maps
//Ogre::PF_BYTE_RGBA,
Ogre::PF_BYTE_BGRA,
Ogre::TU_DEFAULT);
}
// Pointer to the dynamic texture
Ogre::TexturePtr dynTexPtr =
Ogre::TextureManager::getSingleton().getByName("BackgroundTexture");
//#if ( OGRE_VERSION >= (1 << 16 | 9 << 8 | 0) )
// .dynamicCast<Ogre::Texture>();// Get the pixel buffer
//#else
// ;
//#endif
// Get the pixel buffer
mPixelBuffer = dynTexPtr->getBuffer();
// Material to apply the texture to the background
Ogre::MaterialPtr Backgroundmaterial
= Ogre::MaterialManager::getSingleton().create("BackgroundMaterial",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
//#if ( OGRE_VERSION >= (1 << 16 | 9 << 8 | 0) )
// .dynamicCast<Ogre::Material>();
//#else
// ;
//#endif
Ogre::Technique *Backgroundtechnique = Backgroundmaterial->createTechnique();
Backgroundtechnique->createPass();
Backgroundmaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);
Backgroundmaterial->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); // Background
Backgroundmaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); // Background
Backgroundmaterial->getTechnique(0)->getPass(0)->createTextureUnitState("BackgroundTexture");
mBackground->setMaterial("BackgroundMaterial"); // Attach the material to the rectangle
mBackground->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND); // To be rendered in Background
// Add the background to the Scene Graph so it will be rendered
Ogre::SceneNode *BackgroundNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("BackgoundNode");
BackgroundNode->attachObject(mBackground);
}