Horde3D

Next-Generation Graphics Engine
It is currently 28.03.2024, 09:48

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 03.12.2009, 21:05 
Offline

Joined: 23.10.2009, 19:35
Posts: 23
I'm looking at possibly using GameEngine for my little game. I have looked at the samples but I'm missing some more advanced sample of how to actually use the GameEngine, particularly in code.
For example what I have learned so far is that events are a central piece (for triggering actions) but I have not yet figured out how to use these in my own game logic... for starters I want to listen/catch an event when a gameentity collides with some other gameentity (through bullet physics).
Are there any more advanced examples of how to do this, or could someone provide some code snippet of how to accomplish this?
Thanks in advance.


Top
 Profile  
Reply with quote  
PostPosted: 04.12.2009, 08:14 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
I can't offer you a out of the box sample right now, but in the BulletPhyiscs Component there is a GameEvent:E_COLLISION that will be sent for every colliding object. You may have a look at Physics.cpp line 142. So if you create a new e.g. collision component for the GameEngine you can register that component for E_COLLISION events and implement some reaction when an E_COLLISION event was sent by the bullet component.

Something like this:

Code:
GameComponent* CollisionComponent::createComponent( GameEntity* owner )
{
   return new CollisionComponent( owner );
}

CollisionComponent::CollisionComponent(GameEntity *owner) : GameComponent(owner, "CollisionHandler")
{
   owner->addListener(GameEvent::E_COLLISION, this);
   CollisionManager::instance()->addComponent(this);   
}

CollisionComponent::~CollisionComponent()
{
   CollisionManager::instance()->removeComponent(this);
}

void CollisionComponent::executeEvent(GameEvent *event)
{
   if( event->id() == GameEvent::E_COLLISION )
   {
      // DO SOMETHING
   }
}



Top
 Profile  
Reply with quote  
PostPosted: 06.12.2009, 21:19 
Offline

Joined: 23.10.2009, 19:35
Posts: 23
Thanks for the answer.
I saw that there already is a CollisionComponent in the GameEngine. I guess that I can use it (and it's two methods: numCollisions() and collision() in my render loop)?

If someone has a more complete example of how to use the GameEngine this is very much welcome :-)
(For example how a game entity/character can pick up an object and walk around with it and then drop it.)


Top
 Profile  
Reply with quote  
PostPosted: 09.12.2009, 00:27 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
Okay ...

I would likely do it with two new components (probably tied to a single manager and in a single dll), InventoryComponent and ItemComponent. Whatever has an item component would have a physics component as well as the item will listen to collision events. When the item receives an event it would do checkEvent to the other entity for some new event type (e.g. PickupItemEvent), the checkEvent handler of the other entity in the InventoryComponent would see if it's allowed to pick the item up. If the item finds out that it's accepted than it will executeEvent on the other entity. Assumably the inventory component would receive a pointer to the item or increment an ammo counter or something, after which the item would disable its physics and graphic components (it'll only need to worry about them when responding to a DropItem event.

Dropping the item is more complicated.

Recap step-by-step:

    - 2 new components (both of which should be made to be useable for all sorts of item 'types', so you can have an inventory for a character, a crate, etc)
    - new events and event data classes
    - Process
      - checkEvent on the entity who may have an InventoryComponent on collision
      - if ok then executeEvent on the entity who has the InventoryComponent, and disable graphics and physics for the pickup item

Obviously this is kind of cumbersome for simple cases (e.g. ammo counts), but its flexible, though I implemented a PropertyMap (binds existing variables) and DynamicDataSet (on the fly data) for the simple cases where you just need to do a "Does the entity have? Ok, set it to ____." At some point in the not so distant future I'll end up pushing out all my changes, too busy on tool dev to do the necessary initial-debugging.

NOTE: Just use the BulletPhysics component, the collision component doesn't really do too much.


Top
 Profile  
Reply with quote  
PostPosted: 09.12.2009, 10:21 
Offline

Joined: 23.10.2009, 19:35
Posts: 23
Thanks for the suggestions.
But how would I do if I for example want a character to pick up a crate and walk around with it and then drop it (the crate being visible the whole time)?
... to let the crate "attach to" and "follow" the character and still have the physics for the crate (for collision detection)?


Top
 Profile  
Reply with quote  
PostPosted: 10.12.2009, 00:44 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
That's more complicated.

In that case you don't need to disable anything. Attach as normal, and add the ability to turn a dynamic physics object into a kinematic physics object and vice-versa.

Both entities will need to make sure that their physics primitives are ignoring collisions with the other entity (else inter-penetration could get violent), not too difficult.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 44 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group