TriggerVolume not working, core 300

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

TriggerVolume not working, core 300

Postby Madman07 » Fri Apr 12, 2013 7:50 am

Hi.

I have problems with trigger volumes. When collision (attached to some body) is setted as trigger, it still collide with anything else in the scene. I did something wrong, or they doesn't work yet?? I'm using core 300, compiled around half hear ago.

This is how i setted them up:

Code: Select all
   NewtonCollision *coll = NewtonCreateBox (mPhys, 40,-1,40, 10,0);
   NewtonCollisionSetAsTriggerVolume(coll, 1);
   NewtMgr::getSingleton()->DebugCollision(coll, mat); // custom debug

   NewtonBody *body = NewtonCreateBody(mPhys, coll, &mat[0][0]);
   NewtonBodySetMaterialGroupID(body, NewtMgr::getSingleton()->getMatIDTrigger());
   NewtonDestroyCollision(coll);
Madman07
 
Posts: 15
Joined: Thu Jul 19, 2012 1:40 pm

Re: TriggerVolume not working, core 300

Postby Julio Jerez » Fri Apr 12, 2013 9:33 pm

NewtonCollisionSetAsTriggerVolume is not a function of core 300, instead wioth have a more general compsect of Static and dynamic bodies.
Trigger are just a special usage of static bodies.
you can just add static bodies to the scene oe you can use the new pre/post listener functionality of core 300 to manage triggers.
ther is one sub system in teh joint library called engine extensions.

Bascially you subclass one or more controller manager, and you add controller to teh scene.
controller manage have function cllnack tha get call when object enter, statein and exit a controller volume
look at advancePlayer controller for an example


here is a sample hwo to make a trigget controller manager

Code: Select all
#include "CustomTriggerManager.h"


class TriggerManager: public CustomTriggerManager
{
   public:
   TriggerManager(NewtonWorld* const world, AdvancePlayerControllerManager* const playerManager)
      :CustomTriggerManager(world)
      ,m_playerManager(playerManager)
   {
   }

   virtual void EventCallback (const CustomTriggerController* const me, TriggerEventType event, NewtonBody* const visitor) const
   {
      // send this message to the entity
      DemoEntity* const entity = (DemoEntity*) NewtonBodyGetUserData(visitor);
      if (entity) {
         // map the event massage
         int message = -1;
         switch (event) {
            case m_enterTrigger:
               message = ENTER_TRIGGER;
               break;
            case m_exitTrigger:
               message = EXIT_TRIGGER;
               break;

            case m_inTrigger:
               message = INSIDE_TRIGGER;
               break;
         }
            
         // pass the controller pointer as the user data of this massage
         entity->MessageHandler(me->GetBody(), message, (void*)me);
      }
   }
   AdvancePlayerControllerManager* m_playerManager;
};


a control is like a factory that make controller of one type.
you cana keep y in yor main scene togethe wit teh pointer to teh world
then from a makeger you make a controller like this

CustomTriggerController* const controller = triggerManager->CreateTrigger(matrix, collision, NULL);

Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: TriggerVolume not working, core 300

Postby Madman07 » Sat Apr 13, 2013 5:59 am

Newton appears to be harder than I thought.

I assumed I need to compile packages. I went to packages, opened sollution (error during loading physics project), and compiled dJoints using dynamic linking. There were few errors, 1 build failed (for both debug and release). After copying files (dll, lib, includes) to my project, i always get missing dJointLibrary_d.dll (and dJointLibrary.dll), but they are in place.

I'm sure I did something wrong, so what's the exact order of compiling those packages, and what includes I need to add to my project later?? I'm kinda noob from PC programming (I prefer embedded systems...).
Madman07
 
Posts: 15
Joined: Thu Jul 19, 2012 1:40 pm

Re: TriggerVolume not working, core 300

Postby Julio Jerez » Sat Apr 13, 2013 9:14 am

were you able to compile the sandbox project?
That project use all of the libraries that the engine uses

if you do no want to use the sandbox, you can open project
C:\Users\Julio\Desktop\newton-dynamics\packages\projects\visualStudio_2008
or
C:\Users\Julio\Desktop\newton-dynamics\packages\projects\visualStudio_2010
those two solutions contain all of the subproject that you need.

here are all of the subproject with a strong dependency graph:
project: dependency
pthread
core dependency(pthread)
physics dependency(pthread, core)
ai dependency(pthread, core, physics)
newton dependency(pthread, core, physics, ai)
dMath dependency(pthread, core, physics, ai, newton)
dContainers dependency(pthread, core, physics, ai, newton, dMath)
djointLibrary dependency(pthread, core, physics, ai, newton, dMath, dContainers)
dAnimation dependency(pthread, core, physics, ai, newton, dMath, dContainers, djointLibrary)
dScene dependency(pthread, core, physics, ai, newton, dMath, dContainers, djointLibrary, dAnimation)


sync again I just made sure that all the dependencies are in the right order.
if you are usin VS2010 or later, you do no even have to worry about setting dependencies, VS figure it out automatically.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: TriggerVolume not working, core 300

Postby Madman07 » Sat Apr 13, 2013 11:52 am

I was using "packages\projects\visualStudio_2008" but I did selective compiling (eg. just selected dJoints). Joints require so much dependencies. I would prob. compile it all, hovewer I don't need (in that game project) anything more than basic Newton propeties (collisions and materials), and (im minimalistic perso) I don't want to have unused things here. Is there any simpler way to create triggers? I know I can disable collisions between two materials, but is there any way to force them to create some callback (when they supposed to collide) ? If not, then I'm simply gonna write something by hand, since I need just box and plane triggers ;)
Madman07
 
Posts: 15
Joined: Thu Jul 19, 2012 1:40 pm

Re: TriggerVolume not working, core 300

Postby Julio Jerez » Sat Apr 13, 2013 12:06 pm

but if you build the libraries, the linked does no add anything that is not linked to by youy code.

if you do not want to build the libraries you, like I said, triggers inb core 300 are kinematic bodies, you can look at the code that implement a trigger manager
all I does Is that it create one of those, the afte that you can eieth use the material callback, or iterate over the contacts joint that connect the trigget to any oteh dynamics body

Code: Select all
void CustomTriggerController::Init (NewtonCollision* const convexShape, const dMatrix& matrix, void* const userData)
{
   NewtonWorld* const world = GetManager()->GetWorld();

   // create a trigger body and place in the scene
   NewtonBody* const body = NewtonCreateKinematicBody(world, convexShape, &matrix[0][0]);
   SetBody (body);
   
   // set this shape do not collide with other bodies
   NewtonCollision* const collision = NewtonBodyGetCollision (body);
   NewtonCollisionSetCollisonMode(collision, 0);
}


void CustomTriggerController::PreUpdate(dFloat timestep, int threadIndex)
{
   CustomTriggerManager* const manager = (CustomTriggerManager*)GetManager();

   unsigned lru = manager->m_lru;

   NewtonBody* const triggerBody = GetBody();
   for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint (triggerBody); joint; joint = NewtonBodyGetNextContactJoint (triggerBody, joint)) {
      NewtonBody* const body0 = NewtonJointGetBody0(joint);
      NewtonBody* const body1 = NewtonJointGetBody1(joint);
      NewtonBody* const passangerBody = (body0 != triggerBody) ? body0 : body1;
      PassangerManifest::dTreeNode* node = m_manifest.Find (passangerBody);
      if (!node) {
         node = m_manifest.Insert (passangerBody);
         manager->EventCallback (this, CustomTriggerManager::m_enterTrigger, passangerBody);
      } else {
         manager->EventCallback (this, CustomTriggerManager::m_inTrigger, passangerBody);
      }
      node->GetInfo() = lru;
   }
   
   PassangerManifest::Iterator iter (m_manifest);
   for (iter.Begin(); iter; ) {
      PassangerManifest::dTreeNode* const node = iter.GetNode();
      iter ++;
      if (node->GetInfo() != lru) {
         manager->EventCallback (this, CustomTriggerManager::m_exitTrigger, node->GetKey());         
         m_manifest.Remove(node);
      }
   }
}


the only thing different in the manage is that is uses the pre and post listener feature on the engine. you can make you own listeners with using any of the joint libraries
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: TriggerVolume not working, core 300

Postby Madman07 » Sat Apr 13, 2013 12:17 pm

I don't have NewtonCreateKinematicBody, or NewtonCollisionSetCollisonMode in my Newton.h file. Seems my version is a lot out of date. I'm gonna download new version and compile it asap!

Much thanks for help! ;)
Madman07
 
Posts: 15
Joined: Thu Jul 19, 2012 1:40 pm

Re: TriggerVolume not working, core 300

Postby Madman07 » Sun Apr 14, 2013 4:50 pm

I compiled 3.04 version and I have to say, that physics is working a bit better, than in 3.00 ver. Also, triggers are really nice ;))

Hovewer, I have problem with NewtonBodyAddBuoyancyForce. It doesn't work. I wasted one day till I looked into source, and I see you've disabled it. So I went to dgDynamicBody and have enabled it there (replaced Min Max with if-statements). It still doesn't work ;(

So, how I can manually calculate force needed to push body out of water? Is that formula correct? :

- calculate body volume under water plane (how to do that, when I have water plane equantion?)
- calculate weight of displaced water = calculated volume * water density
- apply force = weight of displaced water * gravity + gravity pull down
Madman07
 
Posts: 15
Joined: Thu Jul 19, 2012 1:40 pm

Re: TriggerVolume not working, core 300

Postby Julio Jerez » Sun Apr 14, 2013 6:01 pm

the buoyance function is broken. this is because of the changes to the collision system.
I see if I can re enable it this week.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: TriggerVolume not working, core 300

Postby carli2 » Wed Apr 17, 2013 6:18 am

Julio Jerez wrote:the buoyance function is broken. this is because of the changes to the collision system.
I see if I can re enable it this week.


Very good.

That's also my issue in the moment.
carli2
 
Posts: 157
Joined: Thu Nov 10, 2011 1:53 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest