The simplest ogre Series 4-sphere scenario Query

Source: Internet
Author: User

Ogre integrates a simple collision detection query. Only the AABB and sphere scenarios are involved in the query of the volume. There is no concept of a layered volume and can be used as the most basic and simple collision detection. The following is the code I implemented. The baseapplication can be found in the previous blog. Both Sinbad and sphere model resources are provided by ogre.

#ifndef __Ogre_Rigid_Simple__H__#define __Ogre_Rigid_Simple__H__#include "BaseApplication.h"class Ogre_Rigid_Simple : public BaseApplication{public:Ogre_Rigid_Simple(void);virtual ~Ogre_Rigid_Simple(void);protected:virtual void createScene(void);virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);void SceneQueryBySphere();private:Ogre::SceneNode* mStaticNode;Ogre::SceneNode* mDynamicNode;Ogre::Entity* mStaticModel; Ogre::Entity* mDynamicModel;};#endif // __Ogre_Rigid_Simple__H__

#include "Ogre_Rigid_Simple.h"#include <windows.h>//-------------------------------------------------------------------------------------Ogre_Rigid_Simple::Ogre_Rigid_Simple(void){}//-------------------------------------------------------------------------------------Ogre_Rigid_Simple::~Ogre_Rigid_Simple(void){}//-------------------------------------------------------------------------------------void Ogre_Rigid_Simple::createScene(void){// Setup some basic lighting for our scenemSceneMgr->setAmbientLight(Ogre::ColourValue(0.4f, 0.4f, 0.4f));mSceneMgr->createLight()->setPosition(0, 0, 300);// Create the static node and modelmStaticNode  = mSceneMgr->getRootSceneNode()->createChildSceneNode("StaticNode");mStaticModel = mSceneMgr->createEntity("StaticModel", "Sinbad.mesh");    mStaticNode->attachObject(mStaticModel);mStaticNode->scale(10.0f, 10.0f, 10.0f);// Create the dynamic node and modelmDynamicNode  = mSceneMgr->getRootSceneNode()->createChildSceneNode("DynamicNode");mDynamicModel = mSceneMgr->createEntity("DynamicModel", "Sphere.mesh");mDynamicModel->setMaterialName("Sphere");    mDynamicNode->attachObject(mDynamicModel);mDynamicNode->scale(0.03f, 0.03f, 0.03f);mDynamicNode->setPosition(0.0f,0.0f,20.0f);// Setup cameramCameraMan->setStyle(OgreBites::CS_ORBIT);mCamera->getViewport()->setBackgroundColour(Ogre::ColourValue(0.5f,0.5f,1.0f,1.0f));}//-------------------------------------------------------------------------------------bool Ogre_Rigid_Simple::frameRenderingQueued(const Ogre::FrameEvent& evt){// Scene QuerySceneQueryBySphere();return BaseApplication::frameRenderingQueued(evt);}//-------------------------------------------------------------------------------------void Ogre_Rigid_Simple::SceneQueryBySphere(){// Setup sphere scene query for the dynamic nodeOgre::SphereSceneQuery * pQuery=mSceneMgr->createSphereQuery(Ogre::Sphere(mDynamicNode->getPosition(),100));// Execute this queryOgre::SceneQueryResult QResult=pQuery->execute();// Iterate objects in the query resultfor (Ogre::SceneQueryResultMovableList::iterator iter = QResult.movables.begin(); iter != QResult.movables.end();++iter){Ogre::MovableObject* pObject=static_cast<Ogre::MovableObject*>(*iter);if(pObject){if(pObject->getMovableType()=="Entity"){Ogre::Entity* ent = static_cast<Ogre::Entity*>(pObject);if(ent->getName()=="StaticModel"){// Scale the dynamic node if the name of the entity is "StaticModel"mDynamicNode->scale(1.0001f,1.0001f,1.0001f);break;}}}}}//-------------------------------------------------------------------------------------int main(int argc, char **argv){Ogre_Rigid_Simple app;    try {app.go();}catch(Ogre::Exception& e){std::cerr << "An exception has occured: " << e.getFullDescription();  }    return 0;}

Is the status of the ball at the beginning:

This is the status of the ball after a period of Collision Detection and query.

Update1: 2012-06-14

Today, I saw a blog about ogre 1.8 written by Liu Jingyang. The subclasses of scenequery include regionscenequery and rayscenequery. Regionscenequery includes axisalignedboxscenequery, spherescenequery, and planeboundedvolumelistscenequery. Axisalignedboxscenequery and rayscenequery are more precise than spherescenequery, and these two types of query will be implemented in sequence.

Update2: 2012-06-14

AABB scenario query has been implemented.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.