int HOO::allocateEntityToNode(Ogre::SceneManager *& SceneManager, Ogre::SceneNode *& node, Ogre::Entity*& Ent , const Ogre::String& entityName, const Ogre::String& meshName, HOO::entityVector * debugEntityVector){ try{ Ent = SceneManager->createEntity( entityName, meshName ); node->attachObject(Ent); } catch( Ogre::Exception & e ){ Ent = SceneManager->createEntity( entityName, "cube.mesh"); debugEntityVector->push_back(Ent); Ogre::String message = "WARNING ! Failed to load the following mesh : "; message += meshName; Ogre::LogManager::getSingletonPtr()->logMessage( message); node->attachObject(Ent); float scale=0.2f; node->setScale(scale,scale,scale); Ogre::String txtName = "ErrorTxtObject_n"; txtName += debugEntityVector->size(); Ogre::MovableText* msg = new Ogre::MovableText(txtName, message ,"BlueHighway-8",int(2/scale),Ogre::ColourValue::Green); msg->setTextAlignment(Ogre::MovableText::H_CENTER, Ogre::MovableText::V_CENTER); // Center horizontally and display above the node Ogre::AxisAlignedBox AABB =Ent->getWorldBoundingBox(true); msg->setLocalTranslation(Ogre::Vector3(0.0f,AABB.getHalfSize()[2]+0.1f,0.0f)); node->attachObject(msg); return HOO::ALLOCATEFAIL; } return HOO::SUCCESS; }
void SelectionHandler::updateTrackedBoxes() { M_HandleToBox::iterator it = boxes_.begin(); M_HandleToBox::iterator end = boxes_.end(); for (; it != end; ++it) { V_AABB aabbs; Picked p(it->first.first); p.extra_handles.insert(it->first.second); getAABBs(Picked(it->first.first), aabbs); if (!aabbs.empty()) { Ogre::AxisAlignedBox combined; V_AABB::iterator aabb_it = aabbs.begin(); V_AABB::iterator aabb_end = aabbs.end(); for (; aabb_it != aabb_end; ++aabb_it) { combined.merge(*aabb_it); } createBox(std::make_pair(p.handle, it->first.second), combined, "RVIZ/Cyan"); } } }
void ProjectManager::initializeSceneManager() { assert(QThread::currentThread() == thread()); Ogre::Root& root = Ogre::Root::getSingleton(); Ogre::SceneManager* mgr = NULL; if(root.hasSceneManager(Application::sSceneManagerName)) { mgr = root.getSceneManager(Application::sSceneManagerName); root.destroySceneManager(mgr); } mgr = root.createSceneManager(Ogre::ST_GENERIC, Application::sSceneManagerName); mgr->setShadowTechnique(Ogre::SHADOWTYPE_NONE); mgr->setAmbientLight(Ogre::ColourValue(1, 1, 1)); mgr->setShadowCasterRenderBackFaces(false); mgr->setCameraRelativeRendering(true); mgr->setShowDebugShadows(true); // This fixes some issues with ray casting when using shallow terrain. Ogre::AxisAlignedBox box; Ogre::Vector3 max(100000, 100000, 100000); box.setExtents(-max, max); mgr->setOption("Size", &box); }
//------------------------------------------------------------------------------------- bool BaseApplication::setup(void) { mRoot = new Ogre::Root(mPluginsCfg); setupResources(); bool carryOn = configure(); if (!carryOn) return false; chooseSceneManager(); createCamera(); createViewports(); // Set default mipmap level (NB some APIs ignore this) Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); // Create background material Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("Background", "General"); material->getTechnique(0)->getPass(0)->createTextureUnitState("space.jpg"); material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); material->getTechnique(0)->getPass(0)->setLightingEnabled(false); // Create background rectangle covering the whole screen rect = new Ogre::Rectangle2D(true); rect->setCorners(-1.0, 1.0, 1.0, -1.0); rect->setMaterial("Background"); // Render the background before everything else rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND); // Use infinite AAB to always stay visible Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); rect->setBoundingBox(aabInf); // Attach background to the scene Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background"); node->attachObject(rect); // Example of background scrolling material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setScrollAnimation(-0.10, 0.0); // Don't forget to delete the Rectangle2D in the destructor of your application: // Create any resource listeners (for loading screens) createResourceListener(); // Load resources loadResources(); // Create the scene createScene(); createFrameListener(); return true; };
void CSceneEditorView::OnEditsceneAddentity() { CEntityCreatorDlg EntityCreatorDlg; if (IDOK == EntityCreatorDlg.DoModal()) { HTREEITEM Selected = m_SceneManagerDlg->m_SceneTree.GetSelectedItem(); m_SceneManagerDlg->m_SceneTree.InsertItem(EntityCreatorDlg.m_EntityName, Selected); Ogre::String SceneNodeName = m_SceneManagerDlg->m_SceneTree.GetItemText(Selected); Ogre::Entity *Entity = m_SceneManager->createEntity(Ogre::String(EntityCreatorDlg.m_EntityName), Ogre::String(EntityCreatorDlg.m_MeshName)); Ogre::SceneNode *SceneNode = m_SceneManager->getSceneNode(SceneNodeName); SceneNode->attachObject(Entity); Ogre::AxisAlignedBox Box = Entity->getBoundingBox(); Ogre::Vector3 Center = Box.getCenter(); m_Camera->lookAt(Center); m_SceneManagerDlg->m_SceneTree.Expand(Selected, TVE_EXPAND); if (m_Root != NULL) { m_Root->renderOneFrame(); } } }
Ogre::AxisAlignedBox GPUBillboardSet::calculateBillboardsBoundingBox(const std::vector<PhotoSynth::Vertex>& vertices) { Ogre::AxisAlignedBox box; for (std::size_t i=0; i<vertices.size(); ++i) box.merge(vertices[i].position); return box; }
void MergeBounds(Ogre::SceneNode* node, Ogre::SceneNode* rootNode, const Ogre::Matrix4& parentTransform, Ogre::AxisAlignedBox& aabb) { // Get this nodes current transform Ogre::Matrix4 currentTransform = parentTransform; if (node != rootNode) { Ogre::Matrix4 localTransform(node->getOrientation()); localTransform.setTrans(node->getPosition()); currentTransform = currentTransform * localTransform; } // Merge this nodes objects Ogre::SceneNode::ObjectIterator object = node->getAttachedObjectIterator(); while (object.hasMoreElements()) { Ogre::AxisAlignedBox localAABB = object.getNext()->getBoundingBox(); localAABB.transform(currentTransform); aabb.merge(localAABB); } // Iterate through all children and call this function on them Ogre::SceneNode::ChildNodeIterator child = node->getChildIterator(); while (child.hasMoreElements()) { MergeBounds(static_cast<Ogre::SceneNode*>(child.getNext()), rootNode, currentTransform, aabb); } }
void AIRayPathFinderStrategy::Init() { AIPathFinderStrategy::Init(); //if (Inited) // return; Inited=true; if (Lines) delete [] Lines; Lines = new Ogre::Ray[LinesNumber]; IScenable *scen = Parent->GetScenable(); assert(scen); Ogre::AxisAlignedBox OurBox = scen->GetBoundingBox(false); Vector3 extent = OurBox.getSize(); float HalfSide = extent.z/2, Side=HalfSide*2; LineOrigins[0]=Vector3(-HalfSide,-HalfSide,0); LineOrigins[1]=Vector3(-HalfSide,HalfSide,0); LineOrigins[2]=Vector3(HalfSide,HalfSide,0); LineOrigins[3]=Vector3(HalfSide,-HalfSide,0); LineOrigins[4]=Vector3(0,-HalfSide,0); LineOrigins[5]=Vector3(-HalfSide,0,0); LineOrigins[6]=Vector3(0,HalfSide,0); LineOrigins[7]=Vector3(HalfSide,0,0); }
ConvexVolume::ConvexVolume(Ogre::AxisAlignedBox boundingBox, float offset) { Ogre::Vector3 max = boundingBox.getMaximum(); Ogre::Vector3 min = boundingBox.getMinimum(); // Offset bounding box (except height) if(offset > 0.01f) { max = max + offset*Ogre::Vector3(1,0,1); min = min - offset*Ogre::Vector3(1,0,1); } // Create box verts (in clockwise fashion!!) verts[0]= min.x; verts[1]= min.y; verts[2]= max.z; verts[3]= max.x; verts[4]= max.y; verts[5]= max.z; verts[6]= max.x; verts[7]= max.y; verts[8]= min.z; verts[9]= min.x; verts[10]= min.y; verts[11]= min.z; nverts = 4; // For rcMarkConvexPoly the verts of the shape need to be in clockwise order // Set bounding box limits OgreRecast::OgreVect3ToFloatA(min, bmin); OgreRecast::OgreVect3ToFloatA(max, bmax); // Set height limits hmin = min.y; hmax = max.y; area = SAMPLE_POLYAREA_DOOR; // You can choose whatever flag you assing to the poly area }
void EditorApplication::createSkybox(string skybox_name) { LibGens::Model *skybox_model=current_level->getModelLibrary()->getModel(skybox_name); if (skybox_model) { Ogre::SceneNode *scene_node = scene_manager->getRootSceneNode()->createChildSceneNode(); buildModel(scene_node, skybox_model, skybox_model->getName(), "", scene_manager, current_level->getMaterialLibrary(), 0, GENERAL_MESH_GROUP, false); unsigned short attached_objects=scene_node->numAttachedObjects(); for (unsigned short i=0; i<attached_objects; i++) { Ogre::Entity *entity=static_cast<Ogre::Entity *>(scene_node->getAttachedObject(i)); entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_SKIES_EARLY); unsigned int attached_entities=entity->getNumSubEntities(); Ogre::AxisAlignedBox aabb; aabb.setInfinite(); entity->getMesh()->_setBounds(aabb, false); for (unsigned int j=0; j<attached_entities; j++) { Ogre::SubEntity *sub_entity=entity->getSubEntity(j); Ogre::MaterialPtr material=sub_entity->getMaterial(); Ogre::Pass *pass=material->getTechnique(0)->getPass(0); pass->setDepthWriteEnabled(false); } } } }
Ogre::Real LuaScriptUtilities::GetRadius(Ogre::SceneNode* const sceneNode) { sceneNode->_updateBounds(); const Ogre::AxisAlignedBox aabb = sceneNode->_getWorldAABB(); return aabb.getHalfSize().length(); }
const Ogre::AxisAlignedBox& Canvas::getBoundingBox() const { static Ogre::AxisAlignedBox box; box.setInfinite(); return box; }
InputGeometry::InputGeometry(std::vector<Ogre::Entity*> sourceMeshes,const Ogre::AxisAlignedBox& tileBounds) : _sourceMeshes(sourceMeshes), _numVertices(0), _numTriangles(0), _referenceNode(0), _boundMin(0), _boundMax(0), _normals(0), _vertices(0), _triangles(0) { if(sourceMeshes.empty()) { return; } Ogre::Entity* ent = sourceMeshes[0]; _referenceNode = ent->getParentSceneNode()->getCreator()->getRootSceneNode(); _boundMin = new float[3]; _boundMax = new float[3]; Utility::vector3_toFloatPtr(tileBounds.getMinimum(),_boundMin); Utility::vector3_toFloatPtr(tileBounds.getMaximum(),_boundMax); _convertOgreEntities(tileBounds); //eventually add _buildChunkyTriMesh() }
LoadingScreen::LoadingScreen(Ogre::SceneManager* sceneMgr, Ogre::RenderWindow* rw) : mSceneMgr(sceneMgr) , mWindow(rw) , WindowBase("openmw_loading_screen.layout") , mLastRenderTime(0.f) , mLastWallpaperChangeTime(0.f) , mFirstLoad(true) , mProgress(0) , mVSyncWasEnabled(false) { getWidget(mLoadingText, "LoadingText"); getWidget(mProgressBar, "ProgressBar"); getWidget(mBackgroundImage, "BackgroundImage"); mProgressBar->setScrollViewPage(1); mBackgroundMaterial = Ogre::MaterialManager::getSingleton().create("BackgroundMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); mBackgroundMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false); mBackgroundMaterial->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); mBackgroundMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(""); mRectangle = new Ogre::Rectangle2D(true); mRectangle->setCorners(-1.0, 1.0, 1.0, -1.0); mRectangle->setMaterial("BackgroundMaterial"); // Render the background before everything else mRectangle->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY-1); // Use infinite AAB to always stay visible Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); mRectangle->setBoundingBox(aabInf); // Attach background to the scene Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); node->attachObject(mRectangle); mRectangle->setVisible(false); }
Fader::Fader(Ogre::SceneManager* sceneMgr) : mSceneMgr(sceneMgr) , mMode(FadingMode_In) , mRemainingTime(0.f) , mTargetTime(0.f) , mTargetAlpha(0.f) , mCurrentAlpha(0.f) , mStartAlpha(0.f) , mFactor(1.f) { // Create the fading material MaterialPtr material = MaterialManager::getSingleton().create("FadeInOutMaterial", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); Pass* pass = material->getTechnique(0)->getPass(0); pass->setSceneBlending(SBT_TRANSPARENT_ALPHA); pass->setDepthWriteEnabled (false); mFadeTextureUnit = pass->createTextureUnitState("black.png"); mFadeTextureUnit->setColourOperationEx(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, ColourValue(0.f, 0.f, 0.f)); // always black colour mRectangle = new Ogre::Rectangle2D(true); mRectangle->setCorners(-1.0, 1.0, 1.0, -1.0); mRectangle->setMaterial("FadeInOutMaterial"); mRectangle->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY-1); // Use infinite AAB to always stay visible Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); mRectangle->setBoundingBox(aabInf); // Attach background to the scene Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); node->attachObject(mRectangle); mRectangle->setVisible(false); mRectangle->setVisibilityFlags (2048); }
Ogre::AxisAlignedBox OgreDetourTileCache::getWorldSpaceBounds() { Ogre::AxisAlignedBox result; result.setMinimum(m_cfg.bmin[0], m_cfg.bmin[1], m_cfg.bmin[2]); result.setMaximum(m_cfg.bmax[0], m_cfg.bmax[1], m_cfg.bmax[2]); return result; }
bool Panel::injectMouseMoved(const Ogre::Ray& ray) { Ogre::Matrix4 transform; transform.makeTransform(mNode->getPosition(), mNode->getScale(), mNode->getOrientation()); Ogre::AxisAlignedBox aabb = mScreenRenderable->getBoundingBox(); aabb.transform(transform); pair<bool, Ogre::Real> result = Ogre::Math::intersects(ray, aabb); if (result.first == false) { unOverAllElements(); return false; } Ogre::Vector3 a,b,c,d; Ogre::Vector2 halfSize = (mSize/100) * 0.5f; a = transform * Ogre::Vector3(-halfSize.x,-halfSize.y,0); b = transform * Ogre::Vector3( halfSize.x,-halfSize.y,0); c = transform * Ogre::Vector3(-halfSize.x, halfSize.y,0); d = transform * Ogre::Vector3( halfSize.x, halfSize.y,0); result = Ogre::Math::intersects(ray, c, b, a); if (result.first == false) result = Ogre::Math::intersects(ray, c, d, b); if (result.first == false) { unOverAllElements(); return false; } if (result.second > mDistanceFromPanelToInteractWith) { unOverAllElements(); return false; } Ogre::Vector3 hitPos = (ray.getOrigin() + (ray.getDirection() * result.second)); Ogre::Vector3 localPos = transform.inverse() * hitPos; localPos.x += halfSize.x; localPos.y -= halfSize.y; localPos.x *= 100; localPos.y *= 100; // Cursor clip localPos.x = Ogre::Math::Clamp<Ogre::Real>(localPos.x, 0, mSize.x - 10); localPos.y = Ogre::Math::Clamp<Ogre::Real>(-localPos.y, 0, mSize.y - 18); mInternalMousePos = Ogre::Vector2(localPos.x, localPos.y); mMousePointer->position(mInternalMousePos); // Let's actualize the "over" for each elements for (size_t i=0; i < mPanelElements.size(); i++) mPanelElements[i]->isOver(mInternalMousePos); return true; }
void RenderedCompassImpl::_setCompass(Compass* compass) { Ogre::MaterialPtr originalMaterial = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(mMaterialName)); if (originalMaterial) { originalMaterial->load(); mCompassMaterial = originalMaterial->clone(OgreInfo::createUniqueResourceName(originalMaterial->getName())); if (Ogre::Technique* tech = mCompassMaterial->getBestTechnique()) { Ogre::Pass* pass = nullptr; if (tech->getNumPasses() && (pass = tech->getPass(0))) { mCompassMaterialMapTUS = pass->getTextureUnitState("Background"); if (mCompassMaterialMapTUS) { //Make sure that the compass material is using the map texture for the base rendering mCompassMaterialMapTUS->setTexture(mMap->getTexture()); mTexture = Ogre::TextureManager::getSingleton().createManual("RenderedCompass", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 128, 128, 1, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET); mRenderTexture = mTexture->getBuffer()->getRenderTarget(); mRenderTexture->removeAllViewports(); mRenderTexture->setAutoUpdated(false); mRenderTexture->setActive(true); mCamera = mSceneManager->createCamera("RenderedCompassCamera"); mViewport = mRenderTexture->addViewport(mCamera); mViewport->setOverlaysEnabled(false); mViewport->setShadowsEnabled(false); mViewport->setSkiesEnabled(false); mViewport->setClearEveryFrame(true); mViewport->setBackgroundColour(Ogre::ColourValue::ZERO); mMapRectangle = OGRE_NEW Ogre::Rectangle2D(true); auto mapMaterialPtr = Ogre::MaterialManager::getSingleton().getByName(mCompassMaterial->getName(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); if (mapMaterialPtr) { mMapRectangle->setMaterial(mapMaterialPtr); } //We need to maximise the rendered texture to cover the whole screen Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem(); Ogre::Real hOffset = rs->getHorizontalTexelOffset() / (0.5 * mViewport->getActualWidth()); Ogre::Real vOffset = rs->getVerticalTexelOffset() / (0.5 * mViewport->getActualHeight()); mMapRectangle->setCorners(-1 + hOffset, 1 - vOffset, 1 + hOffset, -1 - vOffset); //Since a Rectangle2D instance is a moveable object it won't be rendered unless it's in the frustrum. If we set the axis aligned box to be "infinite" it will always be rendered. Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); mMapRectangle->setBoundingBox(aabInf); //We can't attach something to the root node, so we'll attach it to a newly created node. We won't keep a reference to this node since it will be destroyed along with the scene manager when we ourselves are destroyed. mSceneManager->getRootSceneNode()->createChildSceneNode()->attachObject(mMapRectangle); //Return early since everything is good. return; } } } } S_LOG_WARNING("Could not load material '" << mMaterialName << "' for the compass."); }
void ImageDisplay::onInitialize() { ImageDisplayBase::onInitialize(); { static uint32_t count = 0; std::stringstream ss; ss << "ImageDisplay" << count++; img_scene_manager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, ss.str()); } img_scene_node_ = img_scene_manager_->getRootSceneNode()->createChildSceneNode(); { static int count = 0; std::stringstream ss; ss << "ImageDisplayObject" << count++; screen_rect_ = new Ogre::Rectangle2D(true); screen_rect_->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1); screen_rect_->setCorners(-1.0f, 1.0f, 1.0f, -1.0f); ss << "Material"; material_ = Ogre::MaterialManager::getSingleton().create( ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); material_->setSceneBlending( Ogre::SBT_REPLACE ); material_->setDepthWriteEnabled(false); material_->setReceiveShadows(false); material_->setDepthCheckEnabled(false); material_->getTechnique(0)->setLightingEnabled(false); Ogre::TextureUnitState* tu = material_->getTechnique(0)->getPass(0)->createTextureUnitState(); tu->setTextureName(texture_.getTexture()->getName()); tu->setTextureFiltering( Ogre::TFO_NONE ); material_->setCullingMode(Ogre::CULL_NONE); Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); screen_rect_->setBoundingBox(aabInf); screen_rect_->setMaterial(material_->getName()); img_scene_node_->attachObject(screen_rect_); } render_panel_ = new RenderPanel(); render_panel_->getRenderWindow()->setAutoUpdated(false); render_panel_->getRenderWindow()->setActive( false ); render_panel_->resize( 640, 480 ); render_panel_->initialize(img_scene_manager_, context_); setAssociatedWidget( render_panel_ ); render_panel_->setAutoRender(false); render_panel_->setOverlaysEnabled(false); render_panel_->getCamera()->setNearClipDistance( 0.01f ); updateNormalizeOptions(); }
/////////////////////////////////////////////////////////////// // collides with any other bounding boxes? bool Agent::intersects(Ogre::Entity* e) { if (e == NULL) { return false; } Ogre::AxisAlignedBox mBox = mBodyEntity->getWorldBoundingBox(); Ogre::AxisAlignedBox eBox = e->getWorldBoundingBox(); return mBox.intersects(eBox); }
bool DefaultCameraManager::canSee(RenderedObject* obj) { Ogre::AxisAlignedBox aabb = obj->getEntity()->getBoundingBox(); Ogre::Matrix4 mat4 = Ogre::Matrix4::IDENTITY; mat4.setTrans(obj->getPosition()); aabb.transform(mat4); return mCamera->isVisible(aabb); //Ogre::AxisAlignedBox aabb = obj-> //if(mCamera->isVisible( }
void GPUBillboardSet::updateBoundingBoxAndSphereFromBillboards(const std::vector<PhotoSynth::Vertex>& vertices) { Ogre::AxisAlignedBox box = calculateBillboardsBoundingBox(vertices); setBoundingBox(box); Ogre::Vector3 vmax = box.getMaximum(); Ogre::Vector3 vmin = box.getMinimum(); Ogre::Real sqLen = std::max(vmax.squaredLength(), vmin.squaredLength()); mBBRadius = Ogre::Math::Sqrt(sqLen); }
Ogre::Vector2 Mesh::getGridPosition(const Ogre::Vector2 &Position) { if (mOptions.MeshSize.Width == 0 && mOptions.MeshSize.Height == 0) { return Position; } if (!isPointInGrid(Position)) { return Ogre::Vector2(-1,-1); } Ogre::AxisAlignedBox WordMeshBox = mEntity->getWorldBoundingBox(); // Get our mesh grid rectangle: (Only a,b,c corners) // c // | // | // | // a-----------b Ogre::Vector3 a = WordMeshBox.getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM), b = WordMeshBox.getCorner(Ogre::AxisAlignedBox::FAR_RIGHT_BOTTOM), c = WordMeshBox.getCorner(Ogre::AxisAlignedBox::NEAR_LEFT_BOTTOM); // Transform all corners to Ogre::Vector2 array Ogre::Vector2 Corners2D[3] = {Ogre::Vector2(a.x, a.z), Ogre::Vector2(b.x, b.z), Ogre::Vector2(c.x, c.z)}; // Get segments AB and AC Ogre::Vector2 AB = Corners2D[1]-Corners2D[0], AC = Corners2D[2]-Corners2D[0]; // Find the X/Y position projecting the Position point to AB and AC segments. Ogre::Vector2 XProjectedPoint = Position-AC, YProjectedPoint = Position-AB; // Fint the intersections points Ogre::Vector2 XPoint = Math::intersectionOfTwoLines(Corners2D[0],Corners2D[1],Position,XProjectedPoint), YPoint = Math::intersectionOfTwoLines(Corners2D[0],Corners2D[2],Position,YProjectedPoint); // Find lengths Ogre::Real ABLength = AB.length(), ACLength = AC.length(), XLength = (XPoint-Corners2D[0]).length(), YLength = (YPoint-Corners2D[0]).length(); // Find final x/y grid positions in [0,1] range Ogre::Real XFinal = XLength / ABLength, YFinal = YLength / ACLength; return Ogre::Vector2(XFinal,YFinal); }
ModelBlock::ModelBlock(Ogre::SceneNode* baseNode,const Carpenter::BuildingBlock* buildingBlock, Model::Model* model, Construction* construction) : mBuildingBlock(buildingBlock) , mModel(model) , mModelNode(0) , mConstruction(construction) { mNode = baseNode->createChildSceneNode(Convert::toOgre(buildingBlock->getPosition()), Convert::toOgre(buildingBlock->getOrientation())); mPointBillBoardSet = mNode->getCreator()->createBillboardSet( std::string("__construction_") + construction->getBluePrint()->getName() + "_" + buildingBlock->getName() + "_billboardset__" + mNode->getName()); mPointBillBoardSet->setDefaultDimensions(1, 1); mPointBillBoardSet->setMaterialName("carpenter/flare"); mPointBillBoardSet->setVisible(false); // Ogre::SceneNode* aNode = EmberOgre::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(); mNode->attachObject(mPointBillBoardSet); if (model) { JesusPickerObject* pickerObject = new JesusPickerObject(this, 0); model->setUserObject(pickerObject); mModelNode = mNode->createChildSceneNode(); mModelNode->attachObject(model); model->setQueryFlags(Jesus::CM_MODELBLOCK); //only autoscale the model if we've not set the scale in the modeldefinition //TODO: it would of course be best if all models were correctly scaled and this code could be removed if (model->getDefinition()->getScale() == 0) { const Ogre::AxisAlignedBox ogreBoundingBox = model->getBoundingBox(); const Ogre::Vector3 ogreMax = ogreBoundingBox.getMaximum(); const Ogre::Vector3 ogreMin = ogreBoundingBox.getMinimum(); const WFMath::AxisBox<3> wfBoundingBox = buildingBlock->getBuildingBlockSpec()->getBlockSpec()->getBoundingBox(); const WFMath::Point<3> wfMax = wfBoundingBox.highCorner(); const WFMath::Point<3> wfMin = wfBoundingBox.lowCorner(); Ogre::Real scaleX; Ogre::Real scaleY; Ogre::Real scaleZ; scaleX = fabs((wfMax.x() - wfMin.x()) / (ogreMax.x - ogreMin.x)); scaleY = fabs((wfMax.z() - wfMin.z()) / (ogreMax.y - ogreMin.y)); scaleZ = fabs((wfMax.y() - wfMin.y()) / (ogreMax.z - ogreMin.z)); mModelNode->setScale(scaleX, scaleY, scaleZ); } } }
Button* check(const Ogre::Ray& ray, bool& isOver) { isOver = false; Ogre::Matrix4 transform; transform.makeTransform(mNode->getPosition(), mNode->getScale(), mNode->getOrientation()); Ogre::AxisAlignedBox aabb = mScreen->getBoundingBox(); aabb.transform(transform); std::pair<bool, Ogre::Real> result = Ogre::Math::intersects(ray, aabb); if (result.first == false) return 0; Ogre::Vector3 a,b,c,d; Ogre::Vector2 halfSize = mSize * 0.5f; a = transform * Ogre::Vector3(-halfSize.x,-halfSize.y,0); b = transform * Ogre::Vector3( halfSize.x,-halfSize.y,0); c = transform * Ogre::Vector3(-halfSize.x, halfSize.y,0); d = transform * Ogre::Vector3( halfSize.x, halfSize.y,0); result = Ogre::Math::intersects(ray, c, b, a); if (result.first == false) result = Ogre::Math::intersects(ray, c, d, b); if (result.first == false) return 0; if (result.second > 6.0f) return 0; isOver = true; Ogre::Vector3 hitPos = ( ray.getOrigin() + (ray.getDirection() * result.second) ); Ogre::Vector3 localPos = transform.inverse() * hitPos; localPos.x += halfSize.x; localPos.y -= halfSize.y; localPos.x *= 100; localPos.y *= 100; // Cursor clip localPos.x = Ogre::Math::Clamp<Ogre::Real>(localPos.x, 0, (mSize.x * 100) - 10); localPos.y = Ogre::Math::Clamp<Ogre::Real>(-localPos.y, 0, (mSize.y * 100) - 18); mMousePointer->position(localPos.x, localPos.y); for (size_t i=0;i < mButtons.size();i++) { if (mButtons[i]->isOver(mMousePointer->position())) return mButtons[i]; } return 0; }
bool Agent::intersectsSphere(Ogre::Entity* e) { if (e == NULL) { return false; } Ogre::AxisAlignedBox mBox = mBodyEntity->getWorldBoundingBox(); //Ogre::Real radius= e->getBoundingRadius(); Ogre::AxisAlignedBox eBox = e->getBoundingBox(); //e->getWorldBoundingSphere e->getBoundingBox(); return mBox.intersects(eBox); }
Ogre::AxisAlignedBox AACamera::GetBoundingBox(bool transformed) const { Ogre::AxisAlignedBox box = Box; if (!transformed) return box; Ogre::Matrix4 transforms; //Node->getWorldTransforms(&transforms); transforms.makeTransform(Node->getPosition(),Node->getScale(),Node->getOrientation()); box.transform(transforms); return box; }
bool ignoreNode(l2p::UModel *m, l2p::BSPNode &n, l2p::BSPSurface &s) { l2p::Package &p = *m->package; for (int i = 0; i < n.num_verticies; ++i) { Ogre::Vector3 loc = ogre_cast(m->points[m->vertexes[n.vert_pool + i].vertex]); Ogre::AxisAlignedBox box = ogre_cast(m->getRegionAABB()); if (!box.contains(loc)) return true; } if (s.flags & l2p::PF_WeDontCareAbout || !s.material.index) return true; return false; }
bool Mesh::isPointInGrid(const Ogre::Vector2 &Position) { Ogre::AxisAlignedBox WordMeshBox = mEntity->getWorldBoundingBox(); // Get our mesh grid rectangle: // c-----------d // | | // | | // | | // a-----------b Ogre::Vector3 a = WordMeshBox.getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM), b = WordMeshBox.getCorner(Ogre::AxisAlignedBox::FAR_RIGHT_BOTTOM), c = WordMeshBox.getCorner(Ogre::AxisAlignedBox::NEAR_RIGHT_BOTTOM), d = WordMeshBox.getCorner(Ogre::AxisAlignedBox::NEAR_LEFT_BOTTOM); // Transform all corners to Ogre::Vector2 array Ogre::Vector2 Corners2D[4] = {Ogre::Vector2(a.x, a.z), Ogre::Vector2(b.x, b.z), Ogre::Vector2(c.x, c.z), Ogre::Vector2(d.x, d.z)}; // Determinate if Position is into our rectangle, we use a line intersection detection // because our mesh rectangle can be rotated, if the number of collisions with the four // segments AB, BC, CD, DA is one, the Position point is into the rectangle, else(if number // of collisions are 0 or 2, the Position point is outside the rectangle. int NumberOfCollisions = 0; // Find a point wich isn't be inside the rectangle Ogre::Vector2 DestPoint = Corners2D[0] + (Corners2D[1]-Corners2D[0])*2; for (int k = 0; k < 3; k++) { if (Math::intersectionOfTwoLines(Corners2D[k], Corners2D[k+1], Position, DestPoint) != Ogre::Vector2::ZERO) { NumberOfCollisions ++; } if (k == 2) { if (Math::intersectionOfTwoLines(Corners2D[3], Corners2D[0], Position, DestPoint) != Ogre::Vector2::ZERO) { NumberOfCollisions ++; } } } if (NumberOfCollisions == 1) { return true; } return false; }
void BoxCenterMovable::getBoundingBoxCenter() { if(object.lock()->hasProperty("bounding box") && object.lock()->hasProperty("position")) { Ogre::AxisAlignedBox aabb = VariantCast<Ogre::AxisAlignedBox>(object.lock()->getProperty("bounding box")); /*Ogre::Vector3 position = VariantCast<Ogre::Vector3>(object.lock()->getProperty("position")); Ogre::Matrix4 matTrans; matTrans.makeTrans( position ); aabb.transformAffine(matTrans);*/ Ogre::Matrix4 transform = Ogre::Matrix4::IDENTITY; Ogre::Matrix3 rot3x3; if (object.lock()->hasProperty("orientation")) { Ogre::Quaternion orientation = VariantCast<Ogre::Quaternion>(object.lock()->getProperty("orientation")); orientation.ToRotationMatrix(rot3x3); } else { rot3x3 = Ogre::Matrix3::IDENTITY; } Ogre::Matrix3 scale3x3; if (object.lock()->hasProperty("scale")) { Ogre::Vector3 scale = VariantCast<Ogre::Vector3>(object.lock()->getProperty("scale")); scale3x3 = Ogre::Matrix3::ZERO; scale3x3[0][0] = scale.x; scale3x3[1][1] = scale.y; scale3x3[2][2] = scale.z; } else { scale3x3 = Ogre::Matrix3::IDENTITY; } transform = rot3x3 * scale3x3; if (object.lock()->hasProperty("position")) { Ogre::Vector3 position = VariantCast<Ogre::Vector3>(object.lock()->getProperty("position")); transform.setTrans(position); } aabb.transformAffine(transform); mCenterPosWC = aabb.getCenter(); } }