Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu May 03, 2012 8:58 am 
Offline

Joined: Thu May 03, 2012 8:47 am
Posts: 14
Hi everyone,
I've been playing around with bullet for a few weeks now. I must say that it looks pretty damn good - both easy to use, and seems very powerful and high-performing.

Anyway, I'm still in technical demo stage. I'd like to consult on what's the best way to handle bullets (like: gun's bullets, now Bullet Physics Engine :). I can think of two alternatives:
1. Use rayTrace() (or some other equivalent)
This has the advantage of not needing to add an object to the world, and the high speed of a bullet fired into the air won't confuse Bullet engine
However, I'm not sure how (and if possible) to retrieve the relative position of the hit in the object (to know if it was a headshot, for instance)
2. Add a bullet object to the world and listen to collision events
This is the advantage of being able to know where the object was hit, and to be able to move dynamic objects as a result of the hit (like boxes, etc)
However, I'm not sure if Bullet Engine is supposed to handle such quick (and small) objects moving around the world. Is it?

Thanks a lot!
Mike


Top
 Profile  
 
PostPosted: Thu May 03, 2012 12:14 pm 
Offline
User avatar

Joined: Fri Nov 04, 2005 2:22 pm
Posts: 34
Hi mike!
I currently use RayTest
In this video, after the first 40 seconds, you can see how it is fast.
Here I do not use a real bullet, but if I were to do that, then I just have to calculate
the final position of the impact and then call the function raytest ()


Top
 Profile  
 
PostPosted: Thu May 03, 2012 12:43 pm 
Offline

Joined: Thu May 03, 2012 8:47 am
Posts: 14
if you're not using a real bullet - how do you calculate the impact position?
are you applying a force to that position to simulate a bullet hitting it?

Thanks!

*EDIT*
btw, is that video showing open source project? can you by any chance send me the sources so I can learn how to do these cool things?


Top
 Profile  
 
PostPosted: Thu May 03, 2012 1:43 pm 
Offline
User avatar

Joined: Fri Nov 04, 2005 2:22 pm
Posts: 34
I have a starting point and an ending point. then a line.
Objects that are "holed" from this line, I give a impulse and a force(kickback)

The engine is entirely in C + +. follows the concept of the family quake,
but is not quake, or like doom3. but give you a piece of code is not a problem.

I hope can help you! ;)

Code:
BOOL BTPhysics::PhysRayCast (Vec3 start, Vec3 end, float kick)
{
   BOOL hit = false;
   var st = btVector3(start[0], start[1], start[2]), en = btVector3(end[0], end[1], end[2]);
   btCollisionWorld::AllHitsRayResultCallback callback(st, en);
   physicsWorld->rayTest(st, en, callback);

   for (int i = 0; i < callback.m_collisionObjects.size(); i++)
   {
      btCollisionObject *obj = callback.m_collisionObjects[i];

      if (!obj->isStaticOrKinematicObject())
      {
         var y = ((btRigidBody*)obj)->getCenterOfMassPosition() - callback.m_hitPointWorld[i];

         y.normalize(); y *= kick;

         obj->activate(true);

         var rigd = ((RigidBody*)obj);
         var gamebody = static_cast<gamebody *>(rigd->getUserPointer());

         if (static_cast<gamebody *>(rigd->getUserPointer())->type & TYPES_RAGDOLL)
         {
            RagDoll *rag = (RagDoll*)gamebody->model;
            rag->DestroyBodyPart(rigd);
         }
         else
            rigd->applyCentralImpulse(y);
         hit = true;
      }
   }
   return hit;
}


Top
 Profile  
 
PostPosted: Fri May 04, 2012 5:34 pm 
Offline

Joined: Thu May 03, 2012 8:47 am
Posts: 14
thanks a lot for the code snippet!
now i see that you can extract the hit point from the rayTrace callback.

i'll dig in further, but some basic testing i made look very promising. thanks!


Top
 Profile  
 
PostPosted: Fri May 04, 2012 7:55 pm 
Offline
User avatar

Joined: Fri Nov 04, 2005 2:22 pm
Posts: 34
;)

Here a demonstration without..... bullets...with...Bullet :mrgreen:
sorry for quality - captured with Olympus camera - Fraps sucks
music "Typh - 2012 Prophecy"


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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:  
Powered by phpBB® Forum Software © phpBB Group