?? ogreopcode.dox
字號:
@mainpage Index
@section intro_sec OgreOpcode 0.1
Welcome to OgreOpcode, version 0.1!
@section menu_sec Usage
- @ref collide_initialization
- @ref collide_handling_collisions
@section collide_initialization Initialization and Setup
- @ref collide_create_manager
- @ref collide_define_classes
- @ref collide_define_types
- @ref collide_create_context
- @ref collide_app_objects
@subsection collide_create_manager Create Collision Manager
The collision manager must be created prior to using the collision
detection system.
@code
new CollisionManager(mSceneMgr);
@endcode
@subsection collide_define_classes Define Collision Classes
A collision class doesn't need to correspond to an @c EntityType (or game
object type). The class is really like a category type for determining
collision relationships. So let's say we have @c "vehicle", @c "powerup"
and @c "bullet" classes.
@code
CollisionManager::getSingletonPtr()->beginCollClasses();
CollisionManager::getSingletonPtr()->addCollClass("vehicle");
CollisionManager::getSingletonPtr()->addCollClass("powerup");
CollisionManager::getSingletonPtr()->addCollClass("bullet");
CollisionManager::getSingletonPtr()->andCollClasses();
@endcode
@subsection collide_define_types Define Collision Types
Collision types define what happens when two classes collide. They tell
the collision system whether or not it should report a collision and
the amount of work that it should do in determining whether or not
a collision occurred.
Collision types are one of:
- COLLTYPE_IGNORE: Don't report collisions.
- COLLTYPE_QUICK: Do fast %sphere vs. %sphere checks.
- COLLTYPE_CONTACT: Report the first contact.
- COLLTYPE_EXACT: Report all contacts.
So using the example from the previous section, vehicles could bounce
off each other and requires exact hit, powerups can be picked up by
being around the right place, and bullets require exact. Powerups
ignore other powerups and bullets. Bullets ignore other bullets.
@code
CollisionManager::getSingletonPtr()->beginCollTypes()
CollisionManager::getSingletonPtr()->addCollType("vehicle", "vehicle", COLLTYPE_EXACT);
CollisionManager::getSingletonPtr()->addCollType("vehicle", "powerup", COLLTYPE_QUICK);
CollisionManager::getSingletonPtr()->addCollType("vehicle", "bullet", COLLTYPE_EXACT);
CollisionManager::getSingletonPtr()->addCollType("powerup", "powerup", COLLTYPE_IGNORE);
CollisionManager::getSingletonPtr()->addCollType("powerup", "bullet", COLLTYPE_IGNORE);
CollisionManager::getSingletonPtr()->addCollType("bullet", "bullet", COLLTYPE_IGNORE);
CollisionManager::getSingletonPtr()->endCollTypes()
@endcode
@subsection collide_create_context Create a Collision Context
A collision context is a space within which collisions occur. It is used
to minimize the set of objects that any given object can collide with (since
it can only collide with those in the same context). The default collision
context can be obtained by:
@code
CollisionContext *collideContext;
...
collideContext = CollisionManager::getSingletonPtr()->getDefaultContext();
@endcode
@subsection collide_app_objects Setting Up Application Objects
Once you have the collision system initialized and ready to go, it is
now time to add in your application's objects.
To do this, you need to do the following things:
- Create a CollisionShape
- Load the collision geometry
- Create a CollisionObject
- Add the collision object to the CollisionContext
@code
Entity* ogreCar = mSceneMgr->createEntity("Car", "car.mesh");
...
CollisionShape *collideShape = CollisionManager::getSingletonPtr()->newShape("fancycar");
collideShape->load(ogreCar);
collideObject = collideContext->newObject();
collideObject->setCollClass(CollisionManager::getSingletonPtr()->queryCollClass("vehicle"));
collideObject->setShape(collideShape);
collideContext->addObject(collideObject);
@endcode
@section collide_handling_collisions Handling and Responding to Collisions
Call CollisionContext::collide() in your game loop to compute contacts
between collision objects in context.
@code
bool frameStarted(const FrameEvent& evt)
{
...
collideContext->collide();
...
}
@endcode
You can retrieve the number of collisions and description of a contact
between two CollideObjects with the given CollisionObject by calling
CollisionContext::getCollissions():
@code
CollisionPair **collisionReport;
int num_collide = collideContext->getCollissions(collideObject, collisionReport);
if (num_collide)
{
CollisionObject* col1 = collisionReport->col1;
CollisionObject* col2 = collisionReport->col2;
}
@endcode
CollisionPair contains the information of collision like pointer to
CollisionObject, the object which is collided, time stamp, contact point and so on.
You can also retrieve the collision info from CollisionObject::GetCollissions():
@code
CollisionObject* collideObject = myEntity->getCollideObject();
CollisionPair *collisionPair;
int num_collide = collideObject->getNumCollissions();
if (collideObject && num_collide)
{
collideObject->getCollissions (collisionPair);
// other process
...
}
@endcode
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -