[ODE] What NearCallback must be like? I cannot place it inside
odelist@sunshinefeelsgood.com
odelist at sunshinefeelsgood.com
Thu Jul 27 18:28:35 MST 2006
If you declared your NearCallback function in your class as "static", then inside
that function, you're not allowed to access non-static member variables directly.
Two options:
1) make the member variables you need in that function static (makes sense if you
only have one instance ever of PhysicsBasic, bad if you have more than one
world/space/etc.)
2) like Alex was saying, pass in an instance of your basic class as the "data"
argument of Collide, then you can access that particular instance's
world/space/etc. For example:
// somewhere in code...
PhysicsBasic *physicsBasicInstance;
dSpaceCollide(physicsBasicInstance->space, physicsBasicInstance /* this is the
'data' */, PhysicsBasic::NearCallback);
// then in your static member function...
void PhysicsBasic::NearCallback (void *data, dGeomID o1, dGeomID o2)
{
PhysicsBasic *physicsBasicInstance = static_cast<PhysicsBasic*>(data);
...
// now this is accessible
physicsBasicInstance->world
}
-Elijah
On Thu Jul 27 3:28 , michael kapelko <kornerr at gmail.com> sent:
>Now it says:
>main.cpp:236: error: invalid conversion from `void (*)(PhysicsBasic*,
>dxGeom*,
> dxGeom*)' to `void (*)(void*, dxGeom*, dxGeom*)'
>I tried to set it static, keep void*, set world, space as static. Object
>files were compiled ok.
>But compiler cannot link them. Looks like it can't see my static world,
>space anymore:
>physics/.obj/basic.o(.text+0x1ad): In function
>`PhysicsBasic::NearCallback(void*, dxGeom*, dxGeom*)':
>: undefined reference to `PhysicsBasic::contact_group'
>physics/.obj/basic.o(.text+0x1b3): In function
>`PhysicsBasic::NearCallback(void*, dxGeom*, dxGeom*)':
>: undefined reference to `PhysicsBasic::world'
>physics/.obj/basic.o(.text+0x244): In function
>`PhysicsBasic::CreateWorld()':
>: undefined reference to `PhysicsBasic::world'
>physics/.obj/basic.o(.text+0x256): In function
>`PhysicsBasic::CreateWorld()':
>: undefined reference to `PhysicsBasic::space'
>physics/.obj/basic.o(.text+0x268): In function
>`PhysicsBasic::CreateWorld()':
>: undefined reference to `PhysicsBasic::contact_group'
>physics/.obj/basic.o(.text+0x280): In function
>`PhysicsBasic::CreateWorld()':
>: undefined reference to `PhysicsBasic::world'
>physics/.obj/basic.o(.text+0x299): In function
>`PhysicsBasic::DestroyWorld()':
>: undefined reference to `PhysicsBasic::contact_group'
>physics/.obj/basic.o(.text+0x2aa): In function
>`PhysicsBasic::DestroyWorld()':
>: undefined reference to `PhysicsBasic::space'
>physics/.obj/basic.o(.text+0x2bb): In function
>`PhysicsBasic::DestroyWorld()':
>: undefined reference to `PhysicsBasic::world'
>.obj/main.o(.text+0x148): In function `Simulate(bool)':
>: undefined reference to `PhysicsBasic::space'
>.obj/main.o(.text+0x15b): In function `Simulate(bool)':
>: undefined reference to `PhysicsBasic::world'
>.obj/main.o(.text+0x172): In function `Simulate(bool)':
>: undefined reference to `PhysicsBasic::world'
>.obj/main.o(.text+0x183): In function `Simulate(bool)':
>: undefined reference to `PhysicsBasic::contact_group'
>.obj/main.o(.text+0x462): In function `main':
>: undefined reference to `PhysicsBasic::space'
>collect2: ld returned 1 exit status
>make: *** [test] Error 1
>
>callback function:
>
>void PhysicsBasic::NearCallback (void *data, dGeomID o1, dGeomID o2) {
> dBodyID b1 = dGeomGetBody (o1);
> dBodyID b2 = dGeomGetBody (o2);
> // If bodies are connected with a joint, then no collision
>detection needed
> if (b1 && b2 && dAreConnected (b1, b2))
> return;
>
> // Maximum possible contacts
> const int N = 4;
> dContact contact[N];
> // How much contacts do we actually have?
> int n = dCollide (o1, o2, N, &contact[0].geom, sizeof (dContact));
> if (n > 0)
> for (int i = 0; i
> // What these parameters mean, you can read in ODE Manual
> contact[i].surface.mode = dContactSlip1 | dContactSlip2 |
> dContactSoftERP | dContactSoftCFM | dContactApprox1;
> contact[i].surface.mu = dInfinity;
> contact[i].surface.slip1 = 0.1;
> contact[i].surface.slip2 = 0.1;
> contact[i].surface.soft_erp = 0.2;
> contact[i].surface.soft_cfm = 0.2;
> dJointID c = dJointCreateContact (world, contact_group,
> &contact[i]);
> dJointAttach (c, dGeomGetBody (contact[i].geom.g1),
> dGeomGetBody (contact[i].geom.g2));
> }
>}
>_______________________________________________
>ODE mailing list
>ODE at q12.org
>http://q12.org/mailman/listinfo/ode
>
More information about the ODE
mailing list