- //foot of a perpendicular: (1,0) to the line
- float footX1 = ( coefB*coefB - coefA*coefC) * inversedAABB;
- float footY1 = (-coefA*coefB - coefB*coefC) * inversedAABB;
- //foot of a perpendicular: (0,1) to the line
- float footX2 = (-coefA*coefB - coefA*coefC) * inversedAABB;
- float footY2 = ( coefA*coefA - coefB*coefC) * inversedAABB;
- saddleParam[1] = (footX1-footX2)*(footX1-footX2) + (footY1-footY2)*(footY1-footY2);
- translation = Vector2(-footX2,-footY2);
- }
- else
- {
- //distance from(1,0) to the line
- float distanceTopRight = fabsf(coefA+coefC) * inversedSqrtAABB;
- //distance from(0,1) to the line
- float distanceBottomLeft = fabsf(coefB+coefC) * inversedSqrtAABB;
- saddleA = std::max( distanceTopRight, distanceBottomLeft );
- //foot of a perpendicular: (0,0) to the line
- float footX3 = (-coefA*coefC) * inversedAABB;
- float footY3 = (-coefB*coefC) * inversedAABB;
- //foot of a perpendicular: (1.0,1.0) to the line
- float footX4 = ( coefB*coefB - coefA*coefB - coefA*coefC) * inversedAABB;
- float footY4 = (-coefA*coefB + coefA*coefA- coefB*coefC) * inversedAABB;
- saddleParam[1] = (footX3-footX4)*(footX3-footX4) + (footY3-footY4)*(footY3-footY4);
- translation = Vector2(-footX3, -footY3);
- }
+ if( (displacement.y * displacement.x < 0.0f) )
+ {
+ //distance from (0,0) to the line
+ float distanceTopLeft = fabsf(coefC) * inversedSqrtAABB;
+ //distance from (1, 1 ) to the line
+ float distanceBottomRight = fabsf(coefA+coefB+coefC) * inversedSqrtAABB;
+ saddleA = std::max( distanceTopLeft, distanceBottomRight );
+
+ //foot of a perpendicular: (1,0) to the line
+ float footX1 = ( coefB*coefB - coefA*coefC) * inversedAABB;
+ float footY1 = (-coefA*coefB - coefB*coefC) * inversedAABB;
+ //foot of a perpendicular: (0,1) to the line
+ float footX2 = (-coefA*coefB - coefA*coefC) * inversedAABB;
+ float footY2 = ( coefA*coefA - coefB*coefC) * inversedAABB;
+ saddleParam[1] = (footX1-footX2)*(footX1-footX2) + (footY1-footY2)*(footY1-footY2);
+ translation = Vector2(-footX2,-footY2);
+ }
+ else
+ {
+ //distance from(1,0) to the line
+ float distanceTopRight = fabsf(coefA+coefC) * inversedSqrtAABB;
+ //distance from(0,1) to the line
+ float distanceBottomLeft = fabsf(coefB+coefC) * inversedSqrtAABB;
+ saddleA = std::max( distanceTopRight, distanceBottomLeft );
+ //foot of a perpendicular: (0,0) to the line
+ float footX3 = (-coefA*coefC) * inversedAABB;
+ float footY3 = (-coefB*coefC) * inversedAABB;
+ //foot of a perpendicular: (1.0,1.0) to the line
+ float footX4 = ( coefB*coefB - coefA*coefB - coefA*coefC) * inversedAABB;
+ float footY4 = (-coefA*coefB + coefA*coefA- coefB*coefC) * inversedAABB;
+ saddleParam[1] = (footX3-footX4)*(footX3-footX4) + (footY3-footY4)*(footY3-footY4);
+ translation = Vector2(-footX3, -footY3);
+ }