[ODE] [Where m I ]always simulating spring.
elekis
elekis at gmail.com
Thu Mar 8 01:41:37 MST 2007
hi,
always trying simulate a spring, this is where I m (see below for trouble)
int main(){
//Create a dynamics world.
World = dWorldCreate();
dWorldSetERP (World, ERP);
//Create bodies in the dynamics world.
Box1 = dBodyCreate (World);
Box2 = dBodyCreate (World);
Box3 = dBodyCreate (World);
dBodySetPosition (Box1, 0.0, 0.0, 0.0);
dBodySetPosition (Box2, 10, 10, 10);
dBodySetPosition (Box3, 20, 20, 0);
joint12 = dJointCreateSlider (World ,0);
dJointAttach (joint12, Box1, Box2);
joint23 = dJointCreateSlider (World ,0);
dJointAttach (joint23, Box2, Box3);
osgProducer::Viewer viewer;
viewer.setUpViewer (osgProducer::Viewer::STANDARD_SETTINGS);
CreateOSGWorld();
viewer.setSceneData (root.get());
UpdateOSGWorld();
viewer.realize();
osg::Timer_t prevTime = osg::Timer::instance()->tick();
while (!viewer.done())
{
viewer.sync();
viewer.update();
viewer.frame();
const double MAX_STEP = 0.01;
const osg::Timer_t now = osg::Timer::instance()->tick();
double deltaSecs = osg::Timer::instance()->delta_s (prevTime, now);
prevTime = now;
while (deltaSecs > 0.0)
{
const double step = std::min (MAX_STEP, deltaSecs);
deltaSecs -= MAX_STEP;
static dReal kp12 = 10; // spring constant
static dReal kp23 = 20; // spring constant
dReal tmp12 = dJointGetSliderPosition(joint12);
dReal tmp23 = dJointGetSliderPosition(joint23);
dReal f12 = - kp12 * tmp12;
dJointAddSliderForce(joint12, f12);
dReal f23 = - kp23 * tmp23;
dJointAddSliderForce(joint23, f23);
dWorldStep (World, step);
}
UpdateOSGWorld();
}
dWorldDestroy (World);
// viewer.sync();
}
to be simple there are two box 1 and 3 who doesnt' move, and box 2 who has
to move attached by springs.
I have two trouble, the first is, That doesnt' move like I want, the box 2
move in the 1-3 axis and not in up-down axis (like a real spring)
the second thing is box 1 and 3 have to be immuable.
in faq you say
" he answer is to create a geom only, without the corresponding rigid body
object ... Then in the contact callback"
but I don't need collision world so how to do that.
thanks a lot for all
a++
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mooshika.org/pipermail/ode/attachments/20070308/6e689992/attachment.htm
More information about the ODE
mailing list