Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 10 July 2008 - 09:17 AM
Posted 10 July 2008 - 04:11 PM
Posted 11 July 2008 - 03:00 AM
Posted 11 July 2008 - 04:42 AM
Quote:
Original post by Taturana
Ok, sorry if I don't explained clearly.
* I'll see the code in .rar file, thanks for reply
My problem is: When there are fast moving objects, I know if the object will collide or not in the forward time, so what I'll do with this information? If I know it'll collide forward in time, what do I need to do?
Quote:
Thanks
*EDIT I really can't understand this function separatedByAxis_swept(). I know what's the d0, d1, axis etc are, but I can't understand what's t0 and t1, why swap the values, etc, can someone explain me?
Posted 11 July 2008 - 07:16 PM
bool CollisionBody::SeparatedByAxisLinePolygon(const Vector2D &axis, const CollisionBody *bodyToCheck, CollisionInfo &colInf)
{
double LineProjMin, LineProjMax, minB, maxB;
LineProjMin = LineProjMax = Vector2D(GetVerticePosition(1)).GetProjectedVectorOnto(axis);
{
Vector2D v0J = GetVerticePosition(2);
double length = v0J.GetProjectedVectorOnto(axis);
if(length > LineProjMax)
LineProjMax = length;
else if(length < LineProjMin)
LineProjMin = length;
}
minB = maxB = Vector2D(bodyToCheck->GetVerticePosition(1)).GetProjectedVectorOnto(axis);
for(int j = 2; j <= bodyToCheck->GetVerticesCount(); j++)
{
Vector2D v0J = bodyToCheck->GetVerticePosition(j);
double length = v0J.GetProjectedVectorOnto(axis);
if(length > maxB)
maxB = length;
else if(length < minB)
minB = length;
}
//Testing the distance of the intervals
float D0 = (maxB - LineProjMin);
float D1 = (minB - LineProjMax);
double overlapDepth;
std::stringstream ss;
float ProjectedVelocity = fabs(Vector2D(bodyToCheck->GetLinearVelocity() - GetLinearVelocity()).GetProjectedVectorOnto(axis));
if (ProjectedVelocity > 0.0000001f)
{
float t0 = D0 / ProjectedVelocity; // time of impact to d0 reaches 0
float t1 = D1 / ProjectedVelocity; // time of impact to d0 reaches 1
if (t0 > t1) { float temp = t0; t0 = t1; t1 = temp; }
overlapDepth = (t0 > 0.0f)? t0 : t1;
}
if(D0 > 0.0f && D1 < 0.0f)
{
overlapDepth += (D0 < -D1)? D0 : D1;
}
else
{
if (overlapDepth < 0.0f)
return true;
}
Vector2D currentMtd = axis.GetNormalized() * overlapDepth;
double mtdLength = currentMtd.GetLength();
if(mtdLength < colInf.length || colInf.length < 0.0f)
{
colInf.MTD = currentMtd;
colInf.length = mtdLength;
}
return false;
}
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.