Verlet integration  Collision Handling  C++
I am currently developing a simple 2d engine in C++, based on verlet integration. I desided not to hardcore every geometrical shape in the engine, and insted build every object from vertices connected by constraints. Now i have come to the point where i would like to implement collision detection and handling. I found some good mathematical tutorials on how to implement collision detection, and this is working now. So for every pair of constraints, i check if they are colliding, and if, then in which coordinate.
Now i just need to figure out what to do when i have this point of collision and i know they are colliding. The only way of influence i have on the constraints is the possibility to affect the coordinates of the vertices in both ends.
Here is the part of my code which does the collision detection, and i've commented where i would think the collision handling should be. Can somebody in here give a hint on how to handle this?
Now i just need to figure out what to do when i have this point of collision and i know they are colliding. The only way of influence i have on the constraints is the possibility to affect the coordinates of the vertices in both ends.
Here is the part of my code which does the collision detection, and i've commented where i would think the collision handling should be. Can somebody in here give a hint on how to handle this?
Code:
class LineSegment
{
public:
Vector2d begin,end;
LineSegment(const Vector2d& begin, const Vector2d& end)
: begin(begin), end(end) {}
enum IntersectResult { PARALLEL, COINCIDENT, NOT_INTERESECTING, INTERESECTING };
IntersectResult Intersect(const LineSegment& other_line, Vector2d& intersection)
{
float denom = ((other_line.end.y  other_line.begin.y)*(end.x  begin.x)) 
((other_line.end.x  other_line.begin.x)*(end.y  begin.y));
float nume_a = ((other_line.end.x  other_line.begin.x)*(begin.y  other_line.begin.y)) 
((other_line.end.y  other_line.begin.y)*(begin.x  other_line.begin.x));
float nume_b = ((end.x  begin.x)*(begin.y  other_line.begin.y)) 
((end.y  begin.y)*(begin.x  other_line.begin.x));
if(denom == 0.0f)
{
if(nume_a == 0.0f && nume_b == 0.0f)
{
return COINCIDENT;
}
return PARALLEL;
}
float ua = nume_a / denom;
float ub = nume_b / denom;
if(ua >= 0.0f && ua <= 1.0f && ub >= 0.0f && ub <= 1.0f)
{
// Get the intersection point.
intersection.x = begin.x + ua*(end.x  begin.x);
intersection.y = begin.y + ua*(end.y  begin.y);
return INTERESECTING;
}
return NOT_INTERESECTING;
}
};
void DoLineSegmentIntersection(const Vector2d& p0, const Vector2d& p1, const Vector2d& p2, const Vector2d& p3, int i, int j)
{
LineSegment linesegment0(p0, p1);
LineSegment linesegment1(p2, p3);
Vector2d ints;
switch(linesegment0.Intersect(linesegment1, ints))
{
case LineSegment::INTERESECTING:
Vector2d intersectionvector;
// Make sure it's actually colliding, not just touching
if((ints.x == p0.x && ints.y == p0.y)  (ints.x == p1.x && ints.y == p1.y)  (ints.x == p2.x && ints.y == p2.y)  (ints.x == p3.x && ints.y == p3.y)) {
} else {
// Here i need some collision handling
}
}
}
void CollisionDetection() {
for(int i=0; i<constraints_count; i++) {
for(int j=i+1; j<constraints_count;j++) {
Vector2d a, b, c, d;
a.x = vertices[constraints[i].point1].posx;
a.y = vertices[constraints[i].point1].posy;
b.x = vertices[constraints[i].point2].posx;
b.y = vertices[constraints[i].point2].posy;
c.x = vertices[constraints[j].point1].posx;
c.y = vertices[constraints[j].point1].posy;
d.x = vertices[constraints[j].point2].posx;
d.y = vertices[constraints[j].point2].posy;
DoLineSegmentIntersection(a, b, c, d, i, j);
}
}
}
How to do collision response between 2 segments is not clear.
I think for a shape made out of lines, for every line you should define which is the "full" side of that line (i.e. the side where the object "matter" is), that way you can push the other shapeline "out" of it.
I think for a shape made out of lines, for every line you should define which is the "full" side of that line (i.e. the side where the object "matter" is), that way you can push the other shapeline "out" of it.
Â©hâ‚¬ck Ã¸ut Âµy stuÆ’Æ’ Ã¥t ragdollsoft.com
New game in development Rubber Ninjas  Mac Games Downloads
Najdorf Wrote:How to do collision response between 2 segments is not clear.
I think for a shape made out of lines, for every line you should define which is the "full" side of that line (i.e. the side where the object "matter" is), that way you can push the other shapeline "out" of it.
Well then i wouldn't be able to make for example a rope, which would just be made of constraints, and have no real volume.
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Verlet Integration + Basic Stick Constraints. Now What?  megabassjosh  7  6,508 
Aug 31, 2005 10:51 PM Last Post: Skorche 

My craptacular interpretation of Jakobsen's verlet paper  Leisure Suit Lurie  6  5,478 
Aug 8, 2005 02:20 PM Last Post: reubert 

What collision handling code to use  Tasnu Arakun  5  4,403 
Sep 25, 2004 08:59 AM Last Post: FCCovett 

Collision Handling  Nick  18  8,624 
Aug 18, 2004 05:23 PM Last Post: Nick 

Verlet Integration Demo  Jake  15  9,696 
Aug 11, 2004 08:15 AM Last Post: aarku 