Vehicle ContactPoint & Skiding

Please don't post Bullet support questions here, use the above forums instead.
Towelie
Posts: 9
Joined: Mon Sep 20, 2010 10:07 am

Vehicle ContactPoint & Skiding

Post by Towelie »

Hi, I wanna show skid mark with Ogre::ManualObject ( i using Ogre3d), there are some problems:
1)When the car has been just added this is true

Code: Select all

wInfo.m_raycastInfo.m_groundObject != NULL && wInfo.m_skidInfo < 1.
then i add the inspection wInfo.m_skidInfo > 0.0 . but this is wrang way, i think.
2)When the car touches the surface, m_contactPointWS y axis == 4.xxe-8 and sometimes -4.xxe-8, why? How can i correct it?
3)I realy cant understand how i can build a rectangle around the contactpoint that will be perpendicular to m_contactNormalWS and the 2 sides will be parallel to the wheel forward vector, now i'm doing it this way

Code: Select all

btWheelInfo& wInfo = vehicle->getWheelInfo(i);
		btVector3 wCP = wInfo.m_raycastInfo.m_contactPointWS;
		if(wInfo.m_raycastInfo.m_groundObject != NULL && wInfo.m_skidInfo < 1. && wInfo.m_skidInfo > 0.0)
		{
			
			//if(oldChains[i].back()->getChainElement(0, oldChains[i].back()->getMaxChainElements() - 1).position.distance(pos) >= 0.1 && !haveInterupt[i])
			//{			
			btVector3 orig = vehicle->getForwardVector().rotate(wInfo.m_raycastInfo.m_contactNormalWS, wInfo.m_steering);	
			orig.setY(wInfo.m_raycastInfo.m_contactPointWS.getY());
			orig.normalize();

			btVector3 perp = wInfo.m_raycastInfo.m_contactNormalWS.cross(wCP).normalize();
			
			ManualObject* newObj = new ManualObject("TierTracksChains_" + StringConverter::toString(i) + "_" + StringConverter::toString(++totalCount[i]));

			newObj->begin("CarTierStrip", RenderOperation::OT_TRIANGLE_STRIP);

			newObj->setCastShadows(false);
			
			newObj->position(cvt(wCP + orig - perp));
			newObj->position(cvt(wCP - orig - perp));
			newObj->position(cvt(wCP - orig + perp));
			newObj->position(cvt(wCP + orig + perp));
		
			newObj->index(0);
			newObj->index(1);
			newObj->index(2);
			newObj->index(3);
			newObj->index(0);

			newObj->end();

			//newObj->colour(1., 1., 1., 1. - wInfo.m_frictionSlip * wInfo.m_frictionSlip);

			mSceneManager->getRootSceneNode()->attachObject(newObj);				
		}
Plz, help
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: Vehicle ContactPoint & Skiding

Post by bone »

1) I don't know.

2) Looks like minor floating point round off. Depending on how you draw the skids, you probably want them to be slightly offset from the surface anyway (slightly above so there's no z-buffer artifacts).

3) Instead of using the wheel's forward vector, I would recommend using its normalized velocity. This will handle lateral sliding better. Second, in order to output a continuous skidmark over several frames, you'll need to store the previous frame's information.

In other words:
a) at each frame, create two points and one skid alpha value, something like this pseudocode:

Code: Select all

  offset = CrossProduct( contactNormal, wheelVelocity );
  offset.normalize();
  offset *= approximate_half_tire_width;
  leftOffset = contactPoint - offset;
  rightOffset = contactPoint + offset;
  skidAlpha = howSevereAmISkidding; // you'll have to figure out the criteria ... perhaps speed of skid, etc. - but it should ramp to transparent when you're not skidding
b) then, using the two points from this frame and the previous frame, you've got your 4 points for a rectangle, along with a smooth gradient of skidAlpha

Code: Select all

  rectanglePoint[0].xyz = prevLeftOffset; rectanglePoint[0].alpha = prevSkidAlpha;
  rectanglePoint[1].xyz = prevRightOffset; rectanglePoint[0].alpha = prevSkidAlpha;
  rectanglePoint[2].xyz = leftOffset; rectanglePoint[0].alpha = skidAlpha;
  rectanglePoint[3].xyz = rightOffset; rectanglePoint[0].alpha = skidAlpha;
(Obviously no need to draw the rectangle if both the current and previous alphas are perfectly transparent).

With this method, since every frame of information is used twice, the skids are continuous and smooth-looking.

Hope this helps.