Raydium 3D Game Engine

Official forum for everything about Raydium, ManiaDrive, MeMak, ...
It is currently Thu Mar 28, 2024 5:11 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: raydium_ode_element_fix
PostPosted: Wed Jul 23, 2008 5:52 pm 
Offline

Joined: Tue Jul 22, 2008 1:52 pm
Posts: 82
Bonjour
je ne parvient pas a relier plusieur object

Code:
int roues[10];
int a;

a=raydium_ode_object_create("BUGGY");

roues[0]=raydium_ode_object_box_add("arg_pneu08",a,1,1,1,1,RAYDIUM_ODE_STANDARD,0,"");
roues[1]=raydium_ode_object_box_add("arg_pneu09",a,1,1,1,1,RAYDIUM_ODE_STANDARD,0,"");
   
raydium_ode_element_fix("fixation",roues,2,0);


si je fait sa la programme plante

Code:
dMassCheck() File mass.cpp Line 39

ODE Message 2: mass must be > 0 in dMassCheck() File mass.cpp Line 39

ODE INTERNAL ERROR 1: assertion "dMassCheck(mass)" failed in dBodySetMass() [ode.cpp]


qu'elle qu'un peut me dire se que je fait de faut


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 3:23 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
I don't know french, but, raydium_ode_element_fix is experimental code, so maybe it doesn't work yet.

Anyway, what are you trying to do with that code?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 6:38 pm 
Offline

Joined: Tue Jul 22, 2008 1:52 pm
Posts: 82
thank you

I speak English very trunk has an automatic translation

you know or is developing
(one can expect a working version in
next day week month?)

and there is another way to connect to handle sets
object
raydium_ode_joint_attach_fixed does not work well and
documentation advises to use



merci

je parle très malle anglais s'est une traduction automatique

tu sait ou en est le développement
(on peut attendre une version fonctionnelle dans les
prochain jour semaine mois ??)

et il y a un autre moyen pour relier de manier fixe des
objet


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 11:04 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
sifourquier wrote:
you know or is developing
(one can expect a working version in
next day week month?)

No, sorry. I'm not working on that area of Raydium. Maybe you will have to wait more than a few weeks.

sifourquier wrote:
and there is another way to connect to handle sets
object
raydium_ode_joint_attach_fixed does not work well and
documentation advises to use

I'm not sure what are you trying to do. Do you want to have a few pieces be treated like just one?

Can you post here your full code? In that way we can guess what are you trying to do and what's failing.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 25, 2008 11:28 am 
Offline

Joined: Tue Jul 22, 2008 1:52 pm
Posts: 82
the code is almost the same as the tutorial but I would like to simply materialize body in a more realistic one cube

le code est presque le même que celui du tutoriel mais je voudrait simplement matérialiser la carrosserie de manière plus réaliste qu'un seul cube


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 25, 2008 4:39 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Ok, i guess you are trying to do something like:
An application that creates 1 object compound of 4 (for example) different elements. The elements must be linked each other, and so be treat like just 1 big element.
That's what you want to do?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 25, 2008 5:13 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Well, i have done a test and the function is not working :(
Go to give it a look...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 25, 2008 5:58 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Here again.
Well, I have got it running at last. But it's a bit tricky.
You can follow this steps:
  • First: Modify the raydium_ode_element_fix function
    You have to edit the ode file in the raydium folder. The file will be in a path like this:
    /yourpath/raydium/trunk/raydium/ode.c

    Then search the function raydium_ode_element_fix. You have to change that function with this one:
    Code:
    int raydium_ode_element_fix(char *name, int *elem, int nelems, signed char keepgeoms)
    {
    dReal aabb[6];
    dReal aabbR[6];
    dReal bounding[3];
    dReal position[3];
    int group;
    int elemN;
    int i,j;
    int done;
    dReal *data;
    dMass m;
    dReal mass;


    if(keepgeoms)
        raydium_log("ODE: element_fix: keepgeoms not implemented yet !");

    if(raydium_ode_element_find(name)>=0)
        {
        raydium_log("ODE: Error: Cannot fix elements as \"%s\": name already exists",name);
        return -1;
        }

    if(nelems<1)
        {
        raydium_log("ODE: Error: Must fix at least one element");
        return -1;   
        }

    for(i=0;i<nelems;i++)
     if(!raydium_ode_element_isvalid(elem[i]))
        {
        raydium_log("ODE: Error: Cannot fix elements: one element is not valid");
        return -1;
        }

    for(i=0;i<nelems;i++)
     if(raydium_ode_element[elem[i]].state!=RAYDIUM_ODE_STANDARD)
        {
        raydium_log("ODE: Error: Cannot fix non standard elements");
        return -1;
        }


    group=raydium_ode_element[elem[0]].object;
    for(i=0;i<nelems;i++)
     if(raydium_ode_element[elem[i]].object!=group)
        {
        raydium_log("ODE: Error: Cannot fix elements: not owned by the same object");
        return -1;
        }
    raydium_log("Step 1");
    // 2 - create new element (using AABB from elements)
    dGeomGetAABB(raydium_ode_element[elem[0]].geom,aabbR);
    raydium_log("Step 2");   
    for(i=0;i<nelems;i++)
        {
        dGeomGetAABB(raydium_ode_element[elem[i]].geom,aabb);
        for(j=0;j<6;j+=2)
            {
            aabbR[j  ]=raydium_trigo_min(aabb[j  ],aabbR[j  ]);
            aabbR[j+1]=raydium_trigo_max(aabb[j+1],aabbR[j+1]);
            }
        }
    raydium_log("Step 3");
    bounding[0]=aabbR[1]-aabbR[0];
    bounding[1]=aabbR[3]-aabbR[2];
    bounding[2]=aabbR[5]-aabbR[4];

    position[0]=aabbR[0]+(bounding[0]/2.f);
    position[1]=aabbR[2]+(bounding[1]/2.f);
    position[2]=aabbR[4]+(bounding[2]/2.f);

    // Now, we can create an new box element with some dummy values:
    elemN=raydium_ode_object_box_add(name,group,0.1f,bounding[0],bounding[1],bounding[2],RAYDIUM_ODE_STANDARD,0,"");
    raydium_ode_element[elemN].state=RAYDIUM_ODE_FIXING;
    raydium_ode_element_move(elemN,position);
    raydium_log("Step 4");
    // 3 - save elements to new element
    done=0;
    mass=0;
    for(i=0;i<nelems;i++)
     for(j=0;j<RAYDIUM_ODE_ELEMENT_MAX_FIXING;j++)
        if(raydium_ode_element[elemN].fixed_elements[j]==NULL)
            {
            raydium_ode_element[elemN].fixed_elements[j]=malloc(sizeof(raydium_ode_ElementInternalSave));
            strcpy(raydium_ode_element[elemN].fixed_elements[j]->name,raydium_ode_element[elem[i]].name);
            raydium_ode_element[elemN].fixed_elements[j]->type=dGeomGetClass(raydium_ode_element[elem[i]].geom);
            dGeomBoxGetLengths(raydium_ode_element[elem[i]].geom,raydium_ode_element[elemN].fixed_elements[j]->box_sizes);
            //raydium_ode_element[elemN].fixed_elements[j]->sphere_radius=dGeomSphereGetRadius(raydium_ode_element[elem[i]].geom);
            dBodyGetMass(raydium_ode_element[elem[i]].body,&m);
            raydium_ode_element[elemN].fixed_elements[j]->mass=m.mass;
            raydium_ode_element[elemN].fixed_elements[j]->object=raydium_ode_element[elem[i]].object;
            raydium_ode_element[elemN].fixed_elements[j]->mesh=raydium_ode_element[elem[i]].mesh;
            raydium_ode_element[elemN].fixed_elements[j]->slip=raydium_ode_element[elem[i]].slip;
            raydium_ode_element[elemN].fixed_elements[j]->cfm=raydium_ode_element[elem[i]].cfm;
            raydium_ode_element[elemN].fixed_elements[j]->erp=raydium_ode_element[elem[i]].erp;

            data=(dReal *)dGeomGetPosition(raydium_ode_element[elem[i]].geom);
            memcpy(raydium_ode_element[elemN].fixed_elements[j]->rel_pos,data,sizeof(dReal)*3);
            raydium_ode_element[elemN].fixed_elements[j]->rel_pos[0]-=position[0];
            raydium_ode_element[elemN].fixed_elements[j]->rel_pos[1]-=position[1];
            raydium_ode_element[elemN].fixed_elements[j]->rel_pos[2]-=position[2];
            dGeomGetQuaternion(raydium_ode_element[elem[i]].geom,raydium_ode_element[elemN].fixed_elements[j]->rel_rot);
            raydium_ode_element[elemN].fixed_elements[j]->user_data=raydium_ode_element[elem[i]].user_data;
            raydium_ode_element[elemN].fixed_elements[j]->user_tag=raydium_ode_element[elem[i]].user_tag;
            dBodyGetMass(raydium_ode_element[elem[i]].body,&m);
            raydium_ode_element[elemN].fixed_elements[j]->OnBlow=raydium_ode_element[elem[i]].OnBlow;
            raydium_ode_element[elemN].fixed_elements[j]->OnDelete=raydium_ode_element[elem[i]].OnDelete;
            mass+=m.mass;
            done++;
            j=RAYDIUM_ODE_ELEMENT_MAX_FIXING; // jump to next element to save
            }
    raydium_log("Step 5");
    if(done!=nelems)
        raydium_log("ODE: Error: only %i/%i elems were fixed to %s ! Continue anyway...",done,nelems,name);

    // 4 - delete elements
    for(i=0;i<nelems;i++)
        raydium_ode_element_delete(elem[i],1); // delete joints, too /!\ (must fix this)

    // 5 - compute new mass
    dMassSetBox(&m,1,bounding[0],bounding[1],bounding[2]);
    dMassAdjust(&m,mass);
    dBodySetMass(raydium_ode_element[elemN].body,&m);

    return elemN;
    }
  • Second: Create a testing file
    Now, create a new file with name, for example, joinelements.c. Put this content in the file:
    Code:
    /*
        Raydium - CQFD Corp.
        http://raydium.org/
        Released under both BSD license and Lesser GPL library license.
        See "license.txt" file.
    */

    // This file is a default skeleton. Replace all [ ... ] sections with yours.
    // Have fun !

    #include "raydium/index.c"
    int debug=1;

    void createbigone()
    {
       int a;
       int b[4];
       a=raydium_ode_object_create("thebigoneobject");
       
       b[0]=raydium_ode_object_box_add("element1",a,1,RAYDIUM_ODE_AUTODETECT,0,0,RAYDIUM_ODE_STANDARD,0,"crate.tri");
       raydium_ode_element_move_3f(b[0],1,1,2);
       
       b[1]=raydium_ode_object_box_add("element2",a,1,RAYDIUM_ODE_AUTODETECT,0,0,RAYDIUM_ODE_STANDARD,0,"crate.tri");
       raydium_ode_element_move_3f(b[1],-1,1,2);
       
       b[2]=raydium_ode_object_box_add("element3",a,1,RAYDIUM_ODE_AUTODETECT,0,0,RAYDIUM_ODE_STANDARD,0,"crate.tri");
       raydium_ode_element_move_3f(b[2],-1,2,3);
       
       b[3]=raydium_ode_object_box_add("element4",a,1,RAYDIUM_ODE_AUTODETECT,0,0,RAYDIUM_ODE_STANDARD,0,"crate.tri");
       raydium_ode_element_move_3f(b[3],1,3,4);

       //joining the four elements
       raydium_ode_element_fix("bigelement",b,4,0);
    }


    void display(void)
    {
    raydium_joy_key_emul();

    if(raydium_key_last==1027)
        exit(0);
       
    if(raydium_key_last==1000+'c')
       createbigone();
       
    if(raydium_key_last==1000+'d')
            debug=debug?0:1;

    raydium_clear_frame();
    /* [ place your camera here ] */ raydium_camera_look_at(10,-2,2,0,0,0);
    /* [ draw here ] */ raydium_ode_draw_all(0);

    if(debug)
       raydium_ode_draw_all(RAYDIUM_ODE_DRAW_DEBUG);
       
    raydium_rendering_finish();

    }


    int main(int argc, char **argv)
    {
    raydium_init_args(argc,argv);
    raydium_window_create(640,480,RAYDIUM_RENDERING_WINDOW,"My app");

    raydium_texture_filter_change(RAYDIUM_TEXTURE_FILTER_TRILINEAR);
    raydium_window_view_perspective(60,0.01,2500); // fov 60 + near and far planes

    raydium_fog_disable();   
    raydium_light_enable();
    raydium_light_on(0);

    raydium_light_conf_7f(0,50,150,200,1000000,1,0.9,0.7); // id, pos, intensity and color (RGB)
    raydium_background_color_change(1,0.9,0.7,1);

    raydium_sky_box_cache();

    /* [ place base scene here ] */ raydium_ode_ground_set_name("cocorobix.tri");

    raydium_callback(&display);
    return(0);
    }

    // EOF

  • Third: Try it
    Now the easy part. Just launch the test file with:
    Code:
    ./odyncomp.sh joinelements.c

    Press 'c' key to create the joint object. Press 'd' key to toogle the debug mode.

That's all. Tell me if it worked for you


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 26, 2008 4:48 pm 
Offline

Joined: Tue Jul 22, 2008 1:52 pm
Posts: 82
thank you very much
I can not test right away but I would tell you if everything works well


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 26, 2008 10:52 pm 
Offline

Joined: Tue Jul 22, 2008 1:52 pm
Posts: 82
I test and was not exactly what I wanted but it will serve me
I want what was done in a form other than a cube or a sphere

but I think its is not possible or complicate

j'ai tester et s'est pas exactement se que je voulait mais sa me sera utile
se que je voudrai s'est faire une autre forme que un cube ou une sphère

mais je pense que sa n'est pas possible ou compliquer


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 26, 2008 11:56 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Well, the collision bodies (not the rendered bodies) usually are boxes or shpehres cause it's quite faster for the computer calculate collision with them.

If you want a "custom body" you will have to join the different elements with usual raydium joints. It's a bit tricky but maybe it will works for you.


Top
 Profile  
 
 Post subject: Fix element
PostPosted: Mon Jul 28, 2008 6:12 pm 
Offline

Joined: Sun Oct 09, 2005 10:46 pm
Posts: 759
Hello,

I'll have a look in september, hope you can wait t'ill there.

Je regarderais le probleme en septembre. J'espere que vous pourrez patienter jusque la.

Bonne journée
Ouille.


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

All times are UTC


Who is online

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