Bringing a mesh to move

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Bringing a mesh to move

Postby Mainclain » Fri Feb 27, 2009 5:10 pm

Hi
At first i have to say sorry for my bad english.
So now to my problem. I create a game with irrlicht3d and like to use newton for the physic.
So I found a week ago this tutorial:
http://irrlicht.sourceforge.net/phpBB2/ ... 73&start=0

So I create a class with the function from the tutorial (It’s create my Game-Character)
Now I have a problem with the movement of the mesh.
At first I set his position to 0,1000,0 – It’s flying and fall down.
If I press “w” It’s going back to 0,1000,0 – I have test it, the function is correct, but it’s only go back to 0,1000,0 if the mesh is still in the air. After it is landing on the ground, the mesh doesn’t move anymore.

Here my function to set the position.
Code: Select all
   void GameCharacter::setPosition(vector3df pos){
       // Set the position of the body:
       CMatrix4<float> mat;
       //matrix4 mat;
       mat.setTranslation(pos);
       NewtonBodySetMatrix(Character.body, mat.pointer());
    }

Code: Select all
void SetMeshTransformEvent(const NewtonBody* body, const float* matrix)
    {
    // Instantiate Irricht CMatrix4 template as float, copy the matrix into it:
    // ggb: Old tutorial used matrix4
    CMatrix4<float> mat;
    mat.setM(matrix);
    //memcpy(mat.pointer(), matrix, sizeof(float)*16);


    // Retreive the user data attached to the Newton body:
    ISceneNode *tmp = (ISceneNode *)NewtonBodyGetUserData(body);
    if (tmp)
        {
        // Position the node:
        tmp->setPosition(mat.getTranslation());      // set position
        tmp->setRotation(mat.getRotationDegrees());   // and rotation
        }
    }
Mainclain
 
Posts: 4
Joined: Fri Feb 27, 2009 11:14 am

Re: Bringing a mesh to move

Postby Mainclain » Mon Mar 02, 2009 8:58 am

Is my english so bad that no one understand my problem :P?
Mainclain
 
Posts: 4
Joined: Fri Feb 27, 2009 11:14 am

Re: Bringing a mesh to move

Postby agi_shi » Mon Mar 02, 2009 9:29 am

The problem is probably that your world size is too small, so when your object falls out of the limits it is frozen, and then when you try to move it back you need to unfreeze it. Use NewtonSetWorldSize()
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: Bringing a mesh to move

Postby Mainclain » Mon Mar 02, 2009 11:27 am

I had set it:

Code: Select all
        // Set the newton world size based on the bsp size:
        float boxP0[3];
        float boxP1[3];
        float matrix[4][4];
        NewtonBodyGetMatrix (g_newtonmapbody, &matrix[0][0]);
        NewtonCollisionCalculateAABB (g_newtonmap, &matrix[0][0],  &boxP0[0], &boxP1[0]);
        printf("min: %f,%f,%f  max: %f,%f,%f\n",boxP0[0],boxP0[1],boxP0[2],boxP1[0],
            boxP1[1],boxP1[2]);  //exposed the 'small world' problem...
        // You can pad the box here if you wish
        // ggb: I spent a lot of time figuring out the initial boxes were outside the
        //      Newton world bounded by the bsp size.  Just padded y by 1000 in both
        //      directions to snag them.
        boxP0[1] -= 1000.0f;  //boxP0.y
        boxP1[1] += 1000.0f;  //boxP1.y
        NewtonSetWorldSize (nWorld, (float*)boxP0, (float*)boxP1);

Do there are difference between bsp and 3ds?

Ah okay you were right, if I use NewtonBodySetAutoFreeze(Character.body, 0); there aren't Problems^^
Mainclain
 
Posts: 4
Joined: Fri Feb 27, 2009 11:14 am

Re: Bringing a mesh to move

Postby Mainclain » Tue Mar 03, 2009 4:27 am

Hello I have another problem. How can i move the mesh with collision? If I move it like in the function It goes throw walls etc.
Mainclain
 
Posts: 4
Joined: Fri Feb 27, 2009 11:14 am

Re: Bringing a mesh to move

Postby agi_shi » Tue Mar 03, 2009 5:36 pm

Use something like NewtonBodySetVelocity(), NewtonBodyAddImpulse(), or you can simply added more forces than just gravity in the force and torque callbaack.

Note that tree collision bodies (NewtonCreateTreeCollision()) cannot physically collide with other objects because they are static (but other objects can collide with them, of course).
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 21 guests

cron