My objects don't collide each other?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

My objects don't collide each other?

Postby jiandingzhe » Sun Nov 27, 2011 12:33 am

I made a simple test scene: a moving body (affected by gravity) fall down to an floor. However, they don't collide each other: the moving body just drop through the floor. I tried to bind an collision callback, but it's never get called.

What error might cause this kind of consequence? Thanks a lot!

This is part of my code:
Code: Select all
void t_PhysicObject::initCustom()
{
    ......
    //
    // physic system
    //
    nWorld = NewtonCreate();
    Ogre::Real minWorld[4] = {-1000,-1000,-1000,0};
    Ogre::Real maxWorld[4] = {1000,1000,1000,0};
    NewtonSetWorldSize(nWorld,minWorld,maxWorld);
   
    int something_mat = NewtonMaterialCreateGroupID(nWorld);
    int floor_mat     = NewtonMaterialCreateGroupID(nWorld);
    NewtonMaterialSetCollisionCallback(nWorld,something_mat,floor_mat,NULL,NULL,&t_PhysicObject::GenericContactProcess);
   
    //
    // create two objects
    //
   
    Ogre::Real iden_mat[16] = {
        1, 0, 0, 0,
        0, 1, 0, 0,
        0, 0, 1, 0,
        0, 0, 0, 1
    };
    Ogre::Matrix4 high_mat;
    high_mat.setTrans(Ogre::Vector3(0,10,0));
    Ogre::Real inertia[4];
    Ogre::Real origin[4];
   
    // moving object
    Ogre::Real somethingMass = 100;
    ArmorBodyPtr somethingArmor(ArmorBodyManager::getSingleton().getArmorBody("bridge.armor"));
    NewtonCollision* somethingCollision = somethingArmor->toNewtonCollision( nWorld, 0, iden_mat );
    NewtonBody* somethingBody = NewtonCreateBody(
        nWorld,
        somethingCollision,
        high_mat.transpose().operator[](0)
    );
   
    NewtonConvexCollisionCalculateInertialMatrix(somethingCollision, inertia, origin);
    NewtonBodySetMassMatrix(
        somethingBody,
        somethingMass,
        somethingMass * inertia[0],
        somethingMass * inertia[1],
        somethingMass * inertia[2]
    );
    NewtonBodySetCentreOfMass(somethingBody,origin);
    NewtonBodySetMaterialGroupID(somethingBody, something_mat);

    // static floor
    Ogre::Real floorMass = 100;
    ArmorBodyPtr floorArmor(ArmorBodyManager::getSingleton().getArmorBody("large_floor.armor"));
    NewtonCollision* floorCollision = floorArmor->toNewtonCollision(nWorld,1,iden_mat);
    NewtonBody* floorBody = NewtonCreateBody(nWorld,floorCollision,iden_mat);
   
    NewtonConvexCollisionCalculateInertialMatrix(floorCollision, inertia, origin);
    NewtonBodySetMassMatrix(
        floorBody,
        floorMass,
        floorMass*inertia[0],
        floorMass*inertia[1],
        floorMass*inertia[2]
    );
    NewtonBodySetCentreOfMass(floorBody,origin);
    NewtonBodySetMaterialGroupID(floorBody,floor_mat);
}
User avatar
jiandingzhe
 
Posts: 48
Joined: Fri Jul 08, 2011 11:21 am
Location: Beijing

Re: My objects don't collide each other?

Postby JernejL » Sun Nov 27, 2011 1:04 am

there is no forcetorque callback & newtonupdate call to make it move?
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: My objects don't collide each other?

Postby Sweenie » Sun Nov 27, 2011 2:17 am

What kind of collider does the toNewtonCollision function create and what does the second parameter of that function mean?
Also, you give the static floor a mass of 100 and calculates inertia for it which is not necessary if it's supposed to be static. Just set the mass to 0 and skip the inertia stuff in that case.
If it has a non-zero mass and a simple convex collider it would fall down as well along with the other body unless it's using a tree collider which would make it a static body automatically.
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: My objects don't collide each other?

Postby jiandingzhe » Sun Nov 27, 2011 2:40 am

JernejL wrote:there is no forcetorque callback & newtonupdate call to make it move?

I did not show them. I'm sure there has force&torque callback, and has world updated at every step. I can see the object drop down through floor.
User avatar
jiandingzhe
 
Posts: 48
Joined: Fri Jul 08, 2011 11:21 am
Location: Beijing

Re: My objects don't collide each other?

Postby jiandingzhe » Sun Nov 27, 2011 2:43 am

Sweenie wrote:What kind of collider does the toNewtonCollision function create and what does the second parameter of that function mean?
Also, you give the static floor a mass of 100 and calculates inertia for it which is not necessary if it's supposed to be static. Just set the mass to 0 and skip the inertia stuff in that case.
If it has a non-zero mass and a simple convex collider it would fall down as well along with the other body unless it's using a tree collider which would make it a static body automatically.

This is the function that creates an newton convex hull collision from my "ArmorBody" class:
Code: Select all
NewtonCollision* ArmorBody::toNewtonCollision(const NewtonWorld* const world, int id, const Ogre::Real* const offsetMatrix)
{
    // store vertex data in one array
    vector<Ogre::Real> vertex_tmp;
    for (vector<Ogre::Vector3>::iterator it = vertices.begin(); it != vertices.end(); it++) {
        vertex_tmp.push_back(it->x);
        vertex_tmp.push_back(it->y);
        vertex_tmp.push_back(it->z);
    }
   
    return NewtonCreateConvexHull( world,
                                   vertices.size(),
                                   vertex_tmp.data(),
                                   sizeof(Ogre::Real)*3,
                                   0,
                                   id,
                                   offsetMatrix
                                 );
}

So it's possible that the armor body is created with no vertex loaded. I'll check that out.
I checked. The vertices are properly loaded into vertex_tmp, which is provided as vertex cloud for ConvexHull construction.
Last edited by jiandingzhe on Sun Nov 27, 2011 3:02 am, edited 1 time in total.
User avatar
jiandingzhe
 
Posts: 48
Joined: Fri Jul 08, 2011 11:21 am
Location: Beijing

Re: My objects don't collide each other?

Postby jiandingzhe » Sun Nov 27, 2011 2:48 am

Sweenie wrote:What kind of collider does the toNewtonCollision function create and what does the second parameter of that function mean?
Also, you give the static floor a mass of 100 and calculates inertia for it which is not necessary if it's supposed to be static. Just set the mass to 0 and skip the inertia stuff in that case.
If it has a non-zero mass and a simple convex collider it would fall down as well along with the other body unless it's using a tree collider which would make it a static body automatically.

I did not applied force on the floor object. So it should keep static until the moving thing collides on it.
User avatar
jiandingzhe
 
Posts: 48
Joined: Fri Jul 08, 2011 11:21 am
Location: Beijing

Re: My objects don't collide each other?

Postby Sweenie » Sun Nov 27, 2011 3:11 am

Hmm, well it looks ok.
Have you implemented any debug rendering to verify that the collider is correct?
Try commenting out the ConvexHull code temporarily and return a simple Box or Sphere Collider instead, just to see if there is any collision.
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: My objects don't collide each other?

Postby jiandingzhe » Sun Nov 27, 2011 3:33 am

Sweenie wrote:Hmm, well it looks ok.
Have you implemented any debug rendering to verify that the collider is correct?
Try commenting out the ConvexHull code temporarily and return a simple Box or Sphere Collider instead, just to see if there is any collision.

I did these things
1: make the mass of floor to zero, so it become static.
2: make the object locates at (3,20,3) initially, so it may roll down.
3: use sphere collider for both floor and the other object:
Code: Select all
NewtonCollision* somethingCollision = NewtonCreateSphere(nWorld,5,5,5,0,iden_mat);
......
NewtonCollision* floorCollision = NewtonCreateSphere(nWorld,5,5,5,0,iden_mat);

The object collides with the static floor, and roll down properly.

Then I use convex hull as collision for the moving object again. When the collide happens, the whole program can have the collide calback called, but it then got stuck! No error was throwed, it just halt there and do not refreshing screen, until I terminate it using Ctrl-C.
User avatar
jiandingzhe
 
Posts: 48
Joined: Fri Jul 08, 2011 11:21 am
Location: Beijing

Re: My objects don't collide each other?

Postby jiandingzhe » Mon Nov 28, 2011 6:29 am

Sweenie wrote:Hmm, well it looks ok.
Have you implemented any debug rendering to verify that the collider is correct?
Try commenting out the ConvexHull code temporarily and return a simple Box or Sphere Collider instead, just to see if there is any collision.

I then tried to create an convex hull directly. It still has the same problem.
Code: Select all
    Ogre::Real test_rect[] = {
        1,1,1,
        1,1,-1,
        -1,1,-1,
        -1,1,1,
        1,-1,1,
        1,-1,-1,
        -1,-1,-1,
        -1,-1,1
    };
    NewtonCollision* somethingCollision = NewtonCreateConvexHull(nWorld,8,test_rect,3*sizeof(Ogre::Real),0,0,iden_mat);
User avatar
jiandingzhe
 
Posts: 48
Joined: Fri Jul 08, 2011 11:21 am
Location: Beijing

Re: My objects don't collide each other?

Postby jiandingzhe » Mon Nov 28, 2011 6:30 am

jiandingzhe wrote:
Sweenie wrote:Hmm, well it looks ok.
Have you implemented any debug rendering to verify that the collider is correct?
Try commenting out the ConvexHull code temporarily and return a simple Box or Sphere Collider instead, just to see if there is any collision.

I then tried to create an convex hull directly. The program still stucks when collision happens.
Code: Select all
    Ogre::Real test_rect[] = {
        1,1,1,
        1,1,-1,
        -1,1,-1,
        -1,1,1,
        1,-1,1,
        1,-1,-1,
        -1,-1,-1,
        -1,-1,1
    };
    NewtonCollision* somethingCollision = NewtonCreateConvexHull(nWorld,8,test_rect,3*sizeof(Ogre::Real),0,0,iden_mat);
User avatar
jiandingzhe
 
Posts: 48
Joined: Fri Jul 08, 2011 11:21 am
Location: Beijing

Re: My objects don't collide each other?

Postby Sweenie » Mon Nov 28, 2011 11:12 am

Probably not the problem but is Ogre::Real a float or double?
Sweenie
 
Posts: 503
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Re: My objects don't collide each other?

Postby jiandingzhe » Mon Nov 28, 2011 9:19 pm

Sweenie wrote:Probably not the problem but is Ogre::Real a float or double?

Ogre::Real is a double, and I compiled Newton to use double, too.
I'm sure Ogre::Real is as same size of Newton's dFloat, otherwise the program would terminate at very early stage:
Code: Select all
int main (int argc, char** argv) {
    // float size compatiability test
    size_t float_sz_ogre = sizeof(Ogre::Real);
    size_t float_sz_newton = sizeof(dFloat);
   
    if (float_sz_ogre != float_sz_newton) {
        cerr<<"newton and ogre float size not equal: "<<float_sz_newton<<" and "<<float_sz_ogre<<endl;
        throw;
    }
    ......
}
User avatar
jiandingzhe
 
Posts: 48
Joined: Fri Jul 08, 2011 11:21 am
Location: Beijing


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron