error on callback function

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

error on callback function

Postby xtravanta » Wed Nov 17, 2010 12:41 pm

Hi,

iam new to newton :)

and for as far as i know you need to use the callback function to at gravity

but when i do that ill get a error:

invalid conversion from `void (*)(const NewtonBody*)' to `void (*)(const NewtonBody*, float, int)


here is my complete code its just a simple box.. :)

Code: Select all
#include <irrlicht/Irrlicht.h>
#include <Newton.h>
#include <iostream>


using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

static NewtonWorld* nWorld;
static NewtonBody* body;


IVideoDriver* driver = 0;
IrrlichtDevice *device = 0;
ISceneManager* smgr = 0;

ISceneNode *boxNode = 0;
ISceneNode *cam = 0;
unsigned int lasttick;

#define NEWTON_GRAVITY -1

void _cdecl ApplyForceAndTorqueEvent (const NewtonBody* body)
{
    printf("test\n");
   float mass;
   float Ixx;
   float Iyy;
   float Izz;
   float force[3];
   float torque[3];

   NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);

   force[0] = 0.0f;
   force[1] = NEWTON_GRAVITY * mass;
   force[2] = 0.0f;

   torque[0] = 0.0f;
   torque[1] = 0.0f;
   torque[2] = 0.0f;

   NewtonBodyAddForce (body, force);
   NewtonBodyAddTorque (body, torque);
}

void InitScene()
{
    device = createDevice(EDT_OPENGL, dimension2d<u32>(640,480), 32, false);

    driver = device->getVideoDriver();
    smgr = device->getSceneManager();

    nWorld = NewtonCreate();

    boxNode = smgr->addAnimatedMeshSceneNode(smgr->getMesh("data/smallcube.3ds"));

    boxNode->setMaterialTexture(0, driver->getTexture("data/crate.jpg"));
    boxNode->setMaterialFlag(EMF_LIGHTING, false);

    NewtonCollision *collision;
    collision = NewtonCreateBox(nWorld, 0, 0, 0, 0, NULL);

    body = NewtonCreateBody (nWorld, collision);

    NewtonReleaseCollision (nWorld, collision);
    NewtonBodySetUserData(body, boxNode);

    NewtonBodySetMassMatrix (body, 100.0f, 1.0f, 1.0f, 1.0f);

    matrix4 mat;
    mat.setTranslation(vector3df(0,0,0));
    NewtonBodySetMatrix(body, &mat.pointer()[0]);

    float omega[3] = {1.0f, 2.0f, 1.0f};
    NewtonBodySetOmega (body, &omega[0]);

    NewtonBodySetForceAndTorqueCallback(body, ApplyForceAndTorqueEvent);

    cam = smgr->addCameraSceneNodeFPS();
   cam->setPosition(vector3df(0, 300, 0));
}

void DrawScene()
{
    if (device->getTimer()->getTime() > lasttick + 10) {
        lasttick = device->getTimer()->getTime();
        NewtonUpdate(nWorld, 0.01f);
    }

    float matrix[4][4];
    NewtonBodyGetMatrix(body, &matrix[0][0]);

    matrix4 mat;
    memcpy(mat.pointer(), matrix, sizeof(float)*16);
    boxNode->setPosition(mat.getTranslation());
    boxNode->setRotation(mat.getRotationDegrees());
}


int main()
{

    InitScene();


    while(device->run())
    {
        DrawScene();

        printf("y: %f\n", boxNode->getPosition().Y);


        driver->beginScene(true, true, video::SColor(0,0,0,0));

        smgr->drawAll();

        driver->endScene();
    }
    NewtonDestroy(nWorld);

    device->drop();

    return 0;
}
xtravanta
 
Posts: 5
Joined: Tue Nov 16, 2010 10:48 am

Re: error on callback function

Postby Julio Jerez » Wed Nov 17, 2010 1:11 pm

the prototype of force an dtorque callback is this

void PhysicsApplyGravityForce (const NewtonBody* body, dFloat timestep, int threadIndex)
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: error on callback function

Postby xtravanta » Wed Nov 17, 2010 1:43 pm

oke.. but how do i put that toghter because every where i look ( tutorials ) they create functions like this..

Code: Select all
void _cdecl ApplyForceAndTorqueEvent (const NewtonBody* body)
{
    printf("test\n");
   float mass;
   float Ixx;
   float Iyy;
   float Izz;
   float force[3];
   float torque[3];

   NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);

   force[0] = 0.0f;
   force[1] = NEWTON_GRAVITY * mass;
   force[2] = 0.0f;

   torque[0] = 0.0f;
   torque[1] = 0.0f;
   torque[2] = 0.0f;

   NewtonBodyAddForce (body, force);
   NewtonBodyAddTorque (body, torque);
}
xtravanta
 
Posts: 5
Joined: Tue Nov 16, 2010 10:48 am

Re: error on callback function

Postby Julio Jerez » Wed Nov 17, 2010 2:46 pm

I guess like this

Code: Select all
void _cdecl ApplyForceAndTorqueEvent (const NewtonBody* body, dFloat timestep, int threadIndex)
{
    printf("test\n");
   float mass;
   float Ixx;
   float Iyy;
   float Izz;
   float force[3];
   float torque[3];

   NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);

   force[0] = 0.0f;
   force[1] = NEWTON_GRAVITY * mass;
   force[2] = 0.0f;

   torque[0] = 0.0f;
   torque[1] = 0.0f;
   torque[2] = 0.0f;

   NewtonBodyAddForce (body, force);
   NewtonBodyAddTorque (body, torque);
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron