// Separate from this function, but so you know how it works
pMesh[0].vR.x += (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[0].vR.x -=(*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
//where turning is done
// Collision response code below:
// Calculate the Difference in Location (X&Z) Axis Only
fXDiff = pMesh[iD2].vLoc.x - pMesh[iD].vLoc.x;
fZDiff = pMesh[iD2].vLoc.z - pMesh[iD].vLoc.z;
// Optimization of not using Sqrt Function
fLocDist = (float)fabs((fXDiff*fXDiff)+(fZDiff*fZDiff));
// Compute / Test if Location Distance is Less than Radius Distance
if (fLocDist <= pMesh[iD2].vRadius.x || fLocDist <= pMesh[iD2].vRadius.z)
{
// Mesh<->Mesh Collision Detection Algorithm (Reaction)
//UpdateParticle();
// Mesh is on left side of Object it is colliding with
// Mesh is of less depth than Object
if ( (fXDiff > 0.0f) && (fZDiff > 0.0f) )
{
if ( pMesh[iD].fAccel > 0.0f )
{
pMesh[iD].vR.x += (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x -= pMesh[iD].fAccel;
}
else
{
pMesh[iD].vR.x += (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x += pMesh[iD].fAccel;
}
}
// Mesh is on left side of Object it is colliding with
// Mesh is of greater depth than Object
else if ( (fXDiff > 0.0f) && (fZDiff < 0.0f) )
{
if ( pMesh[iD].fAccel > 0.0f )
{
pMesh[iD].vR.x -= (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x -= pMesh[iD].fAccel;
}
else
{
pMesh[iD].vR.x -= (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x += pMesh[iD].fAccel;
}
}
// Mesh is on right side of Object it is colliding with
// Mesh is of less depth than Object
else if ( (fXDiff < 0.0f) && (fZDiff > 0.0f) )
{
if ( pMesh[iD].fAccel > 0.0f )
{
pMesh[iD].vR.x -= (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x += pMesh[iD].fAccel;
//pMesh[iD].fAccel -= pMesh[iD].fAccel;
}
else
{
pMesh[iD].vR.x -= (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x -= pMesh[iD].fAccel;
}
}
// Mesh is on right side of Object it is colliding with
// Mesh is of greater depth than Object
else if ( (fXDiff < 0.0f) && (fZDiff < 0.0f) )
{
if ( pMesh[iD].fAccel > 0.0f )
{
pMesh[iD].vR.x += (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x += pMesh[iD].fAccel;
}
else
{
pMesh[iD].vR.x += (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x -= pMesh[iD].fAccel;
}
}
}
If you have any suggestions or comments please let me know, I''ve been trying to figure out a way of doing this, just can''t quite get it! =)
.:Carandiru:.
Collision Reaction
Well I have the collision detecting working flawlessy, box-box method where the vehicle is inside a bounding box and the object the vehicle is colliding with is also inside a bounding box. Collision detection works great, but I''m trying to implement collision reaction in which a car collides "realistically" with a wall. For the right side or left side depending on the depth of the vehicle in comparison to the depth of the object it is colliding with, the vehicle location in relation to its local x axis is modified in relation to which side it is next to the "object". The angle is also modified so it "slides" against the wall as a car would at *certain angles*. Certain angles is my problem, the way the rotation of my vehicle is set up as a decrement of time for turning right and a increment of time for turning left in relation to accelation. So having values that are negative or positive to determine the angle is out of the question. But the method I have described above works. The problem I am having though is, if the *certain angle* is for sakes of simplicity "head on" the vehicle will rotate back and forth as expected. Instead in this case, the vehicle will "bounce" back! But how do I determine this, if I do not have any capability of referencing the angle of rotation for the vehicle itself. For clarification purposes, here''s a snippet of the code I have implemented thus far:
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement