Thread: [Plib-users] triangles from branches
Brought to you by:
sjbaker
From: Paolo S. <ax...@ti...> - 2004-10-25 15:25:04
|
Hi, I'm new to this mailing list. I'm trying to use plib together with ode (www.ode.org) dynamics engine, did anyone have some experience with it? My main problem is that I need to access the triangle data for a given object (ie a branch entity, which contains data loaded from a model in .ac format) to create the geometric rapresentation for the ode's collision detection system. Is there a simple way to reach these informations using plib api? I couldn't figure out from the docs. TIA. -- Paolo Sacconier |
From: Wolfram K. <w_...@rz...> - 2004-10-25 19:29:16
|
Hi! >I'm new to this mailing list. I'm trying to use plib together with ode=20 >(www.ode.org) dynamics engine, did anyone have some experience with it? I heard of it, but have not used it myself yet. >My main problem is that I need to access the triangle data for a given=20 >object (ie a branch entity, which contains data loaded from a model in=20 >.ac format) to create the geometric rapresentation for the ode's=20 >collision detection system. Is there a simple way to reach these=20 >informations using plib api? I couldn't figure out from the docs. One way would be to recursively go down the tree and use getTriangle and getVertex. This returns the data in a very simple format (all triangulated, all vertices unique etc), but can be used on any leaf node, so code usin it is very short. Have a look at ssgSaveTri.cxx for example code. >TIA. Bye bye, Wolfram. |
From: Steve B. <sjb...@ai...> - 2004-10-26 00:35:21
|
Paolo Sacconier wrote: > Hi, > I'm new to this mailing list. I'm trying to use plib together with ode > (www.ode.org) dynamics engine, did anyone have some experience with it? Take a look at the TORCS project - it uses PLIB and ODE. > My main problem is that I need to access the triangle data for a given > object (ie a branch entity, which contains data loaded from a model in > .ac format) to create the geometric rapresentation for the ode's > collision detection system. Is there a simple way to reach these > informations using plib api? I couldn't figure out from the docs. Well, you need to walk the tree structure of the model using things like getNumKids() and getKid(n) at each node and using isAKindOf to recognise whether you have a leaf node or a branch node...for example: void processObj ( ssgEntity *n ) { if ( n == NULL ) return ; if ( n -> isAKindOf ( ssgTypeLeaf() ) ) { ssgLeaf *l = (ssgLeaf *) n ; ....DO SOMETHING WITH THE TRIANGLES... return ; } ssgBranch *b = (ssgBranch *) n ; for ( int i = 0 ; i < b -> getNumKids () ; i++ ) processObj ( b -> getKid ( i ) ) ; } ssgLeaf nodes contain the triangles - there are member functions to get the indices of the three vertices of the N'th triangle (getTriangle) and to retrieve the vertex, colour, normal and texture coordinate given a vertex index: getVertex()/getColour()/ getNormal()/getTexCoord(). ---------------------------- Steve Baker ------------------------- HomeEmail: <sjb...@ai...> WorkEmail: <sj...@li...> HomePage : http://www.sjbaker.org Projects : http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net -----BEGIN GEEK CODE BLOCK----- GCS d-- s:+ a+ C++++$ UL+++$ P--- L++++$ E--- W+++ N o+ K? w--- !O M- V-- PS++ PE- Y-- PGP-- t+ 5 X R+++ tv b++ DI++ D G+ e++ h--(-) r+++ y++++ -----END GEEK CODE BLOCK----- |
From: Paolo S. <ax...@ti...> - 2004-10-26 08:53:59
|
Steve Baker wrote: ... > Take a look at the TORCS project - it uses PLIB and ODE. I will. Until now I saw the nick's solution and I tried to implement it, since it doesn't need to access the triangle data. ... > Well, you need to walk the tree structure of the model using things > like getNumKids() and getKid(n) at each node and using isAKindOf to > recognise whether you have a leaf node or a branch node...for example: > > > void processObj ( ssgEntity *n ) > { > if ( n == NULL ) return ; > > if ( n -> isAKindOf ( ssgTypeLeaf() ) ) > { > ssgLeaf *l = (ssgLeaf *) n ; > ....DO SOMETHING WITH THE TRIANGLES... > return ; > } > > ssgBranch *b = (ssgBranch *) n ; > > for ( int i = 0 ; i < b -> getNumKids () ; i++ ) > processObj ( b -> getKid ( i ) ) ; > } > > ssgLeaf nodes contain the triangles - there are member functions > to get the indices of the three vertices of the N'th triangle > (getTriangle) and to retrieve the vertex, colour, normal and > texture coordinate given a vertex index: getVertex()/getColour()/ > getNormal()/getTexCoord(). I wrote a function that uses the algorithm that you and Wolfram suggest: static void getTriangleData( ssgEntity * ent, dReal * vertices, int * indices, int *vert_offset, int *ind_offset ) { int i,j; if (ent->getNumKids() == 0){ ssgLeaf * le = (ssgLeaf *) ent; int ind_start = *ind_offset; int ind_max = 0; for (i=0; i<le->getNumTriangles(); i++) { short int ind[3]; le->getTriangle(i, &ind[0], &ind[1], &ind[2]); for (j=0; j<3; j++){ indices[*ind_offset+j] = ind[j]; if (indices[*ind_offset+j]>ind_max) ind_max=indices[*ind_offset+j]; indices[*ind_offset+j] += ind_start; } (*ind_offset)+=3; } for (i = 0; i < ind_max; i++) { float *vert; vert = le->getVertex(i); for (j=0; j<3; j++){ vertices[*vert_offset+i*3+j] = (dReal) vert[j]; } (*vert_offset)+=3; } } else { ssgBranch * br = (ssgBranch *) ent; for (i=0; i<br->getNumKids(); i++){ getTriangleData(br->getKid(i), vertices, indices, vert_offset, ind_offset); } } } but I fear that I have to handle also the transformation nodes to get right vertices positions. And I have no idea how to calculate the exact dimensions of the arrays I should pass to this function. Just for the indices I used: static int getNumIndices(ssgEntity * ent) { int i, num = 0; if (ent->getNumKids() == 0){ ssgLeaf * le = (ssgLeaf *) ent; return (le->getNumTriangles())*3; } else { ssgBranch * br = (ssgBranch *) ent; for (i=0; i<br->getNumKids(); i++){ num += getNumIndices(br->getKid(i)); } return num; } } Since I didn't find any simple way to check if the triangle data I get with this method are correct (of course when I use this data I get wreid collisions :)) I gave up... Maybe torcs people have found a solution. -- Paolo Sacconier |
From: torcs <to...@fr...> - 2004-10-26 17:50:06
|
Steve Baker wrote: > Paolo Sacconier wrote: > >> Hi, >> I'm new to this mailing list. I'm trying to use plib together with ode >> (www.ode.org) dynamics engine, did anyone have some experience with it? > > > Take a look at the TORCS project - it uses PLIB and ODE. > Well, in fact ODE is not used for TORCS, the collisions are managed by SOLID (http://sourceforge.net/projects/freesolid), but the objects and the transformations have to be duplicated between PLIB and SOLID :-( Eric. -- =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= TORCS - http://torcs.org The Open Racing Car Simulator AKA The Other Release Coming Soon (Skin'r) How soon is soon ? (RaceBlizter) =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= |