   Problems with line-circle collision detection (part 1)
  Hi everybody.  I'm writing a very simple game as a semester project in my mobile programming class (I'm using OpenGL).  I'm to the point where I'm trying to implement collision detection with the walls of my world, and I'm running into some problems.  (Looks like I'm going to have to post this is chunks)Up front, I'm doing what I consider VERY simple collision detection.No BSP octrees for me ;)My algorithm came fromhttp://mathworld.wolfram.com/Circle-LineIntersection.html(I'm writing in C++)...I'll let my code do a little bit of the talking, and I'll try my best to explain it as I go.I load my coordinate data from a txt file (world.txt from NeHe's 10th tut)NUMPOLLIES 36// Floor 1-3.0  0.0 -3.0 0.0 6.0-3.0  0.0  3.0 0.0 0.0 3.0  0.0  3.0 6.0 0.0-3.0  0.0 -3.0 0.0 6.0 3.0  0.0 -3.0 6.0 6.0 3.0  0.0  3.0 6.0 0.0// Ceiling 1-3.0  1.0 -3.0 0.0 6.0-3.0  1.0  3.0 0.0 0.0 3.0  1.0  3.0 6.0 0.0-3.0  1.0 -3.0 0.0 6.0 3.0  1.0 -3.0 6.0 6.0 3.0  1.0  3.0 6.0 0.0// A1-2.0  1.0  -2.0 0.0 1.0-2.0  0.0  -2.0 0.0 0.0-0.5  0.0  -2.0 1.5 0.0-2.0  1.0  -2.0 0.0 1.0-0.5  1.0  -2.0 1.5 1.0-0.5  0.0  -2.0 1.5 0.0// A2 2.0  1.0  -2.0 2.0 1.0 2.0  0.0  -2.0 2.0 0.0 0.5  0.0  -2.0 0.5 0.0 2.0  1.0  -2.0 2.0 1.0 0.5  1.0  -2.0 0.5 1.0 0.5  0.0  -2.0 0.5 0.0// B1-2.0  1.0  2.0 2.0  1.0-2.0  0.0   2.0 2.0 0.0-0.5  0.0   2.0 0.5 0.0-2.0  1.0  2.0 2.0  1.0-0.5  1.0  2.0 0.5  1.0-0.5  0.0   2.0 0.5 0.0// B2 2.0  1.0  2.0 2.0  1.0 2.0  0.0   2.0 2.0 0.0 0.5  0.0   2.0 0.5 0.0 2.0  1.0  2.0 2.0  1.0 0.5  1.0  2.0 0.5  1.0 0.5  0.0   2.0 0.5 0.0// C1-2.0  1.0  -2.0 0.0  1.0-2.0  0.0   -2.0 0.0 0.0-2.0  0.0   -0.5 1.5 0.0-2.0  1.0  -2.0 0.0  1.0-2.0  1.0  -0.5 1.5  1.0-2.0  0.0   -0.5 1.5 0.0// C2-2.0  1.0   2.0 2.0 1.0-2.0  0.0   2.0 2.0 0.0-2.0  0.0   0.5 0.5 0.0-2.0  1.0  2.0 2.0 1.0-2.0  1.0  0.5 0.5 1.0-2.0  0.0   0.5 0.5 0.0// D12.0  1.0  -2.0 0.0 1.02.0  0.0   -2.0 0.0 0.02.0  0.0   -0.5 1.5 0.02.0  1.0  -2.0 0.0 1.02.0  1.0  -0.5 1.5 1.02.0  0.0   -0.5 1.5 0.0// D22.0  1.0  2.0 2.0 1.02.0  0.0   2.0 2.0 0.02.0  0.0   0.5 0.5 0.02.0  1.0  2.0 2.0 1.02.0  1.0  0.5 0.5 1.02.0  0.0   0.5 0.5 0.0// Upper hallway - L-0.5  1.0  -3.0 0.0 1.0-0.5  0.0   -3.0 0.0 0.0-0.5  0.0   -2.0 1.0 0.0-0.5  1.0  -3.0 0.0 1.0-0.5  1.0  -2.0 1.0 1.0-0.5  0.0   -2.0 1.0 0.0// Upper hallway - R0.5  1.0  -3.0 0.0 1.00.5  0.0   -3.0 0.0 0.00.5  0.0   -2.0 1.0 0.00.5  1.0  -3.0 0.0 1.00.5  1.0  -2.0 1.0 1.00.5  0.0   -2.0 1.0 0.0// Lower hallway - L-0.5  1.0  3.0 0.0 1.0-0.5  0.0   3.0 0.0 0.0-0.5  0.0   2.0 1.0 0.0-0.5  1.0  3.0 0.0 1.0-0.5  1.0  2.0 1.0 1.0-0.5  0.0   2.0 1.0 0.0// Lower hallway - R0.5  1.0  3.0 0.0 1.00.5  0.0   3.0 0.0 0.00.5  0.0   2.0 1.0 0.00.5  1.0  3.0 0.0 1.00.5  1.0  2.0 1.0 1.00.5  0.0   2.0 1.0 0.0// Left hallway - Lw-3.0  1.0  0.5 1.0 1.0-3.0  0.0   0.5 1.0 0.0-2.0  0.0   0.5 0.0 0.0-3.0  1.0  0.5 1.0 1.0-2.0  1.0  0.5 0.0 1.0-2.0  0.0   0.5 0.0 0.0// Left hallway - Hi-3.0  1.0  -0.5 1.0 1.0-3.0  0.0   -0.5 1.0 0.0-2.0  0.0   -0.5 0.0 0.0-3.0  1.0  -0.5 1.0 1.0-2.0  1.0  -0.5 0.0 1.0-2.0  0.0   -0.5 0.0 0.0// Right hallway - Lw3.0  1.0  0.5 1.0 1.03.0  0.0   0.5 1.0 0.02.0  0.0   0.5 0.0 0.03.0  1.0  0.5 1.0 1.02.0  1.0  0.5 0.0 1.02.0  0.0   0.5 0.0 0.0// Right hallway - Hi3.0  1.0  -0.5 1.0 1.03.0  0.0   -0.5 1.0 0.02.0  0.0   -0.5 0.0 0.03.0  1.0  -0.5 1.0 1.02.0  1.0 -0.5 0.0 1.02.0  0.0   -0.5 0.0 0.0into a sector struct(TWODPOINT and COLLISIONCIRCLE are used for collision detection)--------------typedef struct tagTWODPOINT{float x, z;} TWODPOINT;typedef struct tagCollisionCircle{TWODPOINT circleOrigin;floatradius;}COLLISIONCIRCLE;typedef struct tagWALL{TWODPOINT wallPoints[2];} WALL;typedef struct tagVERTEX{float x, y, z;//3d coordinatesfloat u, v;//texture coordinates} VERTEX;typedef struct tagTRIANGLE{VERTEX vertex[3];} TRIANGLE;typedef struct tagSECTOR{int numWalls;int numTriangles;TRIANGLE* triangle;  //pointer to array of TrianglesWALL* SectorWalls; //pointer to array of verticesWALL* ObjectWalls;} SECTOR;my global variables (the relevant ones)---------------Quote:floatxpos = 0.0f;floatzpos = 0.0f;SECTOR   sector1;