Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
// function CL_Intersect(argument0, arugment1) { x0 = argument0.tempx; y0 = argument0.tempy; x1 = argument1.x1; y1 = argument1.y1; x2 = argument1.x2; y2 = argument1.y2; n = abs((x2-x1)*(y1-y0)-(x1-x0)*(y2-y1)); d = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); dist = n/d; if(dist > argument0.radius) return false; d1 = sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1)); if((d1-argument0.radius) > d) return false; d2 = sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2)); if((d2-argument0.radius) > d) return false; return true; } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
// function CL_Reaction(argument0, argument1) { dx = 0; dy = 0; px = 0; py = 0; pen = 0; xx = argument0.tempx; yy = argument0.tempy; r = argument0.radius; x0 = argument1.x1; y0 = argument1.y1; x1 = argument1.x2; y1 = argument1.y2; lx = x1 - x0; //lx,ly is a vector parallel to the line ly = y1 - y0; len = sqrt(lx*lx + ly*ly); if(len == 0) { return 0; } rx = lx/len; //rx,ry is the unit direction vector of the lineseg ry = ly/len; nx = -ry; //nx,ny is a vector perpendicular to the line ny = rx; dx = (xx - x0); //dx,dy is the vector from x0,y0 to the circle dy = (yy - y0); dpPerp = dx*rx + dy*ry; //length of dx,dy projected onto the lineseg's direction if(dpPerp < 0) { //circle is closer to the endpoint x0,y0 than the line, project out of point x0,y0 len = sqrt(dx*dx + dy*dy); pen = r - len; if(0 < pen) { //project out of the endpoint dx /= len; dy /= len; px = dx*pen; py = dy*pen; } } else { if(len < dpPerp) { //circle is closer to the endpoint x1,y1 than the line, project out of point x1,y1 dx -= lx; //dx,dy is now the vector from x1,y1 to the circle dy -= ly; len = sqrt(dx*dx + dy*dy); pen = r - len; if(0 < pen) { //project out of the endpoint dx /= len; dy /= len; px = dx*pen; py = dy*pen; } } else { //circle is closer to the lineseg; project out of it dp = dx*nx + dy*ny;//dp is length of dx,dy when measured/projected onto the line's normal pen = abs(dp) - r; if(pen < 0) { //circle is inside the line; project it out along the normal if(0 < dp) { //circle is on the RHside of the line, should be projected out the +ve normal pen *= -1; } px = nx*pen;//px,py is the penetration vector which pushes the circle out of the line py = ny*pen; } } } argument0.vel_x += px; argument0.vel_y += py; } |
Werbeanzeige