Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
elchtest mod :)
03-06-2010, 09:19 AM,
#48
 
@NaN:
I'm looking at your code. I guess you have to add some synchronization to the pose not only the velocities, too. Then you have to decide which one of them integrates the velocities.

Further there is some possible problem with the velocities:
You are getting the vdrift velocities after a timestep and bullet assumes constant velocities. I solved it by calculating the velocitiy from the distance the car moved/rotated.

So, what are your concrete problems?

For your information: Here is my code for the cylinder collision detection.
Code:
void CarPhysics::UpdateWheelContacts()
{
    double bumpwave = 1;
    double bumpamp= 0.0;
    double frict_no= 1.5;
    double frict_tread=0;
    double roll_res=0.;
    double roll_drag=0;
    SURFACE::CARSURFACETYPE surface = SURFACE::ASPHALT;

    //Update the wheels!
    UpdateBulletWheelsFromVdrift();

    // some possible helpers for orientation conversion
    btQuaternion bullet_ori = chassisBody->getWorldTransform().getRotation().inverse();
    btQuaternion vdrift_ori = ( getbtQuaternion( car_dynamics->GetOrientation()));
    btQuaternion convertRotation= vdrift_ori * bullet_ori;

        if (debugGeode)
            OSGroot->removeChild(debugGeode);
    debugGeode = new osg::Geode();

    OSGroot->addChild(debugGeode);

    for (int wheel = 0; wheel < WHEEL_POSITION_SIZE; ++wheel)
    {
        int contactNum=0;
        //For (optional) averaging
        btVector3 colPoint(0,0,0);
        btVector3 colNormal(0,0,0);
        double colDepth=0;

        double minLength=10000000000.;
        double maxLength= 0;

        ////////////////////////////
        btManifoldArray   manifoldArray;
        btBroadphasePairArray& pairArray = wheel_infos[wheel]->wheelGhost->getOverlappingPairCache()->getOverlappingPairArray();
//        int numPairs = pairArray.size();
        int numPairs=  wheel_infos[wheel]->wheelGhost->getNumOverlappingObjects();
        for (int i=0;i<numPairs;i++)
        {
            manifoldArray.clear();

            const btBroadphasePair& pair = pairArray[i];

            //unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache:
            btBroadphasePair* collisionPair = m_dynamics_world->getPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1);
            if (!collisionPair)
                continue;

            if (collisionPair->m_algorithm)
                collisionPair->m_algorithm->getAllContactManifolds(manifoldArray);

            for (int j=0;j<manifoldArray.size();j++)
            {
                btPersistentManifold* manifold = manifoldArray[j];
                btScalar directionSign = manifold->getBody0() ==  wheel_infos[wheel]->wheelGhost ? btScalar(-1.0) : btScalar(1.0);
                if (directionSign>0.){
                //    cout << " QQQQQQQQ "<< endl;
                    continue; // Punkte nur in eine Richtung holen
                }
                if (manifold->getBody0() == chassisBody)
                {
                    //cout << " DAMN "<< endl;
                    continue;
                }
                for (int p=0;p<manifold->getNumContacts();p++)
                {
                    const btManifoldPoint&pt = manifold->getContactPoint(p);
                    if (pt.getDistance()<0.f)
                    {
                        const btVector3& ptA = pt.getPositionWorldOnA();
                        const btVector3& ptB = pt.getPositionWorldOnB();
                        const btVector3& normalOnB = pt.m_normalWorldOnB;
                        const float depth=(ptA-ptB).length();
                        btVector3 wheelLocalHitPos= wheel_infos[wheel]->wheelRigidbody->getCenterOfMassPosition() -ptB;
                        colPoint+= ptA*depth;
                        colNormal+= normalOnB*depth;
                        colDepth+= depth;
                        contactNum++;
                    }
                }
            }
        }
        //////////////////////////////
        ///Process the result
        if (contactNum>0)
        {
//            cout << " anzahl der kontakte für reifen " << wheel << " : "<<contactNum << endl;
            ////average
            colPoint/=colDepth;
            colNormal/=colDepth;
            colDepth/=contactNum;
            btVector3 wheelLocalHitPos= wheel_infos[wheel]->wheelRigidbody->getCenterOfMassPosition() -colPoint;
// // Get the distance from rotation axis to col point (no good: car does bounce)
//            btVector3 test (0,0,1);
//            test.rotate(wheel_infos[wheel]->wheelRigidbody->getOrientation().getAxis(),wheel_infos[wheel]->wheelRigidbody->getOrientation().getAngle());
//            test.normalize();
//            double distanceFromWheelCenter = wheelLocalHitPos.dot(test)*contactNum;

            // Fake the depth to be the distance from wheel center to the collision point
            double distanceFromWheelCenter= wheelLocalHitPos.length() ;

            colNormal.normalize();
            car_dynamics->SetWheelContactProperties(WHEEL_POSITION(wheel),    (double)distanceFromWheelCenter  ,getMATHVECTOR(colPoint), getMATHVECTOR(colNormal),bumpwave, bumpamp, frict_no, frict_tread, roll_res, roll_drag, surface);

            std::cout << "ColPoint:  " << colPoint.getX() << " " << colPoint.getY() << " " << colPoint.getZ() <<endl;
            std::cout << " Collision normal: "<< colNormal.getX() << " " << colNormal.getY() << " " << colNormal.getZ() << std::endl;
            cout << " distance from wheel center: " << "  "<<car.GetTireRadius((WHEEL_POSITION)wheel)<<" "<< distanceFromWheelCenter<<"  "<<colDepth<<"  "<<endl;
        cout << "-----------------------------------"<<endl;

        }    else
        {

            car_dynamics->SetWheelContactProperties(WHEEL_POSITION(wheel),    (double)1000,
                    MATHVECTOR<double,3>(0), MATHVECTOR<double,3>(0,0,1),
                    bumpwave, bumpamp, frict_no, frict_tread, roll_res, roll_drag, surface);
        }
    }
}

It is a mess, but I am still experimenting with different versions (getting the deepest hit depth, or using different normals, etc.)
Wheels are modeled as GhostObjects and therefore don't collide themselves, but save collisions. In the new bullet version, there must be a instant Collision check, which is preferable, but I did not yet try it.

My ray cast version looks almost identical to yours.

Edit:
world.stepSimulation(dt, maxsubsteps, dt);
makes bullet use your timestep and not interpolate to dt (thats what I understood).

Your implementation differs from mine, because I use bullet to trigger the physics tick in vdrift (it is all done in the updateAction function).
One StepSimulation is all, you have to do then.
Execution looks like follows:
Code:
void CarPhysics::updateAction( btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
    double dt= (double) deltaTimeStep *2.; // FIXME ... why is vdrift slower than bullet?
    int num_repeats= dt/internal_dt+0.5;

    /// overwrite vdrift pose/velocities with bullets calculation to integrate collision results
    UpdateInternalFromBullet();
    // Init deltaAngularVelocity (contains sum over all delta Velocities in substeps)
    deltaAngularVelocity=getVector3d(car_dynamics->GetBody().GetAngularVelocity());
    oldPosition=GetPosition();

    double old_force= force_feedback;
    force_feedback=0;

    UpdateWheelContacts(); //TODO do this in every substep (needs collision from bullet 2.76)

    /// Apply several vdrift steps (cause frequency must be very high for a vehicle
    for (int i= 0; i< num_repeats; ++i )
    {
        ///Get the new engine and so on sounds
        car.UpdateSounds(internal_dt);

        ///Use the input vector to update internal car controls (inputs has to be set by setInputVector! )
        // Input Handling differs and adds things to handling in Vdrift
        car.HandleInputsTransparent(inputs, internal_dt);

        force_feedback+= car.GetFeedback();

        //Set forward the vdrift physics
        car.TickPhysics(internal_dt);

        deltaAngularVelocity+= getVector3d(car_dynamics->GetBody().GetAngularVelocity());
    }
    force_feedback/=num_repeats;

    deltaAngularVelocity= deltaAngularVelocity/((double)num_repeats+1);

    newPosition= GetPosition();
    double dt_inv= 1. / (num_repeats*internal_dt);
    deltaVelocity= (newPosition-oldPosition) * dt_inv;

    // Update the Bullet angular and linear Velocities: This is the only connection from Vdrift to bullet
    UpdateBulletVelocities();
}
Reply


Messages In This Thread
elchtest mod :) - by NaN - 02-04-2010, 12:04 PM
[No subject] - by NaN - 02-04-2010, 01:01 PM
[No subject] - by NaN - 02-04-2010, 02:16 PM
[No subject] - by nomoo - 02-04-2010, 02:41 PM
[No subject] - by joevenzon_phpbb2_import3 - 02-05-2010, 11:29 AM
[No subject] - by NaN - 02-05-2010, 11:39 AM
[No subject] - by NaN - 02-05-2010, 01:10 PM
[No subject] - by NaN - 02-05-2010, 04:15 PM
[No subject] - by joevenzon_phpbb2_import3 - 02-06-2010, 12:25 AM
[No subject] - by NaN - 02-10-2010, 08:37 AM
[No subject] - by NaN - 02-10-2010, 11:25 AM
[No subject] - by portets - 02-10-2010, 06:58 PM
[No subject] - by NaN - 02-10-2010, 07:36 PM
[No subject] - by portets - 02-10-2010, 08:19 PM
[No subject] - by NaN - 02-20-2010, 05:47 PM
[No subject] - by CrystalH - 02-21-2010, 12:52 PM
[No subject] - by NaN - 02-21-2010, 01:45 PM
[No subject] - by joevenzon_phpbb2_import3 - 02-22-2010, 02:01 AM
[No subject] - by sebiastisch - 02-22-2010, 10:45 AM
[No subject] - by joevenzon_phpbb2_import3 - 02-22-2010, 11:22 AM
[No subject] - by sebiastisch - 02-22-2010, 12:02 PM
[No subject] - by NaN - 02-22-2010, 12:56 PM
[No subject] - by sebiastisch - 02-22-2010, 01:00 PM
[No subject] - by NaN - 02-22-2010, 01:09 PM
[No subject] - by sebiastisch - 02-22-2010, 01:14 PM
[No subject] - by NaN - 02-23-2010, 03:38 AM
[No subject] - by joevenzon_phpbb2_import3 - 02-23-2010, 11:20 AM
[No subject] - by NaN - 02-25-2010, 03:47 PM
[No subject] - by NaN - 02-25-2010, 04:50 PM
[No subject] - by sebiastisch - 02-25-2010, 06:43 PM
[No subject] - by NaN - 02-27-2010, 03:24 PM
[No subject] - by sebiastisch - 02-28-2010, 08:24 AM
[No subject] - by joevenzon_phpbb2_import3 - 02-28-2010, 01:46 PM
[No subject] - by joevenzon_phpbb2_import3 - 02-28-2010, 01:56 PM
[No subject] - by NaN - 02-28-2010, 02:04 PM
[No subject] - by NaN - 02-28-2010, 05:57 PM
[No subject] - by sebiastisch - 02-28-2010, 07:20 PM
[No subject] - by sebiastisch - 03-03-2010, 10:10 AM
[No subject] - by joevenzon_phpbb2_import3 - 03-03-2010, 11:39 AM
[No subject] - by sebiastisch - 03-03-2010, 12:43 PM
[No subject] - by joevenzon_phpbb2_import3 - 03-03-2010, 11:29 PM
[No subject] - by sebiastisch - 03-04-2010, 05:08 AM
[No subject] - by joevenzon_phpbb2_import3 - 03-04-2010, 11:42 AM
[No subject] - by sebiastisch - 03-04-2010, 12:43 PM
[No subject] - by NaN - 03-05-2010, 09:17 AM
[No subject] - by NaN - 03-05-2010, 01:44 PM
[No subject] - by sebiastisch - 03-05-2010, 02:25 PM
[No subject] - by sebiastisch - 03-06-2010, 09:19 AM
[No subject] - by NaN - 03-08-2010, 11:28 AM
[No subject] - by joevenzon_phpbb2_import3 - 03-08-2010, 11:11 PM
[No subject] - by joevenzon_phpbb2_import3 - 03-08-2010, 11:24 PM
[No subject] - by sebiastisch - 03-09-2010, 06:55 AM
[No subject] - by joevenzon_phpbb2_import3 - 03-11-2010, 02:00 AM
[No subject] - by joevenzon_phpbb2_import3 - 03-11-2010, 02:05 AM
[No subject] - by sebiastisch - 03-11-2010, 09:43 AM
[No subject] - by sebiastisch - 03-11-2010, 09:45 AM
[No subject] - by NaN - 03-11-2010, 03:04 PM
[No subject] - by sebiastisch - 03-15-2010, 06:50 AM
[No subject] - by NaN - 03-15-2010, 03:26 PM
[No subject] - by sebiastisch - 03-16-2010, 08:13 AM
[No subject] - by NaN - 03-16-2010, 12:50 PM
[No subject] - by sebiastisch - 03-16-2010, 01:15 PM
[No subject] - by NaN - 03-16-2010, 01:30 PM
[No subject] - by sebiastisch - 03-20-2010, 07:38 AM
[No subject] - by joevenzon_phpbb2_import3 - 03-20-2010, 12:10 PM
[No subject] - by NaN - 03-22-2010, 12:19 PM
[No subject] - by sebiastisch - 03-30-2010, 10:37 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)