Open twaritwaikar opened 5 years ago
i like to use constraints in another thread that checks and separates bodies std::thread physicsConstraintThread(&physics::runConstraints,Constraints); for like max of 5 to 10 times a fram so it wont be laggy while checking The only problem with my code is i havent written my vector mats yet so i need to use angles
void physics::constraints(collider& c1,collider& c2)
{
Vector2f moveAmount=Vector2f(0,0);
Vector2f direction = c2.location-c1.location;
float angle = atan(direction.y/direction.x);
if(angle>-1*c1.depth && angle<c1.depth)
{
if(mod(direction.y)<(c1.bounds.height/2 + c2.bounds.height/2)-1)
moveAmount.x= signum(c2.location.x-c1.location.x);
}
else
{
if(mod(direction.x)<(c1.bounds.width/2 + c2.bounds.width/2)-1)
moveAmount.y= 0.2*signum(c2.location.y-c1.location.y);
}
c2.move(Vector2f(c2.physicsStepRatio.x* /*(c2.velocity.x+0.00001)*/ moveAmount.x,c2.physicsStepRatio.y* /*(c2.velocity.y+0.00001)*/ moveAmount.y));
// c2.move(moveAmount);
c1.move(Vector2f(c1.physicsStepRatio.x* /*(c1.velocity.x+0.00001)*/ moveAmount.x*-1,c1.physicsStepRatio.y* /*(c1.velocity.y+0.00001)*/ moveAmount.y*-1));
//c1.move(Vector2f(moveAmount.x*-1,moveAmount.y*-1));
}
@BoldHonor Do you see any performance improvements by resolving constraints like this?
Is there a specific reason that you spawn only a single thread to check constraints?
Master: v3
OS version: Windows 10
Our 2D collision algorithms are homegrown and need testing regularly after every change.
Create tests for each type of 2D collision possible with our available colliders (circle, rectangle, line, plane)