Files Classes Functions Hierarchy
00001 #include <boxcollision.h> 00002 00003 00004 // 00005 // Crap code to do specific job. 00006 // If I were not so flat this would be generalized to 00007 // reflect of an arbitary line, reducing the size of code. 00008 // 00009 // Also in this case the rectangular coordinates are the natural 00010 // solution, the first method may take much more computing. 00011 00012 // 00013 // The important stuff is the condition and solution 00014 // x0+r<x then ok, else step back and solve intersection. 00015 // x + t1.v = x0+r 00016 // 00017 boolc boxcollision::left( particle & p, doublec h ) const 00018 { 00019 assert(h>0.0); 00020 00021 if ( x0 < p.pos[0]-p.radius ) 00022 return false; 00023 00024 p.step(-h); 00025 00026 assert(p.vel[0]!=0.0); 00027 doublec t1 = 00028 (x0+p.radius-p.pos[0])/p.vel[0]; 00029 doublec t2 = h-t1; 00030 00031 p.step(t1-h); 00032 00033 p.vel[0]*=-1.0; 00034 p.step(t2); 00035 00036 return true; 00037 } 00038 00039 boolc boxcollision::right( particle & p, doublec h ) const 00040 { 00041 assert(h>0.0); 00042 00043 if ( p.pos[0] < x1-p.radius ) 00044 return false; 00045 00046 p.step(-h); 00047 00048 assert(p.vel[0]!=0.0); 00049 doublec t1 = 00050 (x1-p.radius-p.pos[0])/p.vel[0]; 00051 doublec t2 = h-t1; 00052 00053 p.step(t1-h); 00054 00055 p.vel[0]*=-1.0; 00056 p.step(t2); 00057 00058 return true; 00059 } 00060 00061 boolc boxcollision::up( particle & p, doublec h ) const 00062 { 00063 assert(h>0.0); 00064 00065 if ( p.pos[1] < y1-p.radius ) 00066 return false; 00067 00068 p.step(-h); 00069 00070 assert(p.vel[1]!=0.0); 00071 doublec t1 = 00072 (y1-p.radius-p.pos[1])/p.vel[1]; 00073 doublec t2 = h-t1; 00074 00075 p.step(t1-h); 00076 00077 p.vel[1]*=-1.0; 00078 p.step(t2); 00079 00080 return true; 00081 } 00082 00083 boolc boxcollision::down( particle & p, doublec h ) const 00084 { 00085 assert(h>0.0); 00086 00087 if ( y0+p.radius < p.pos[1] ) 00088 return false; 00089 00090 p.step(-h); 00091 00092 assert(p.vel[1]!=0.0); 00093 doublec t1 = 00094 (y0+p.radius-p.pos[1])/p.vel[1]; 00095 doublec t2 = h-t1; 00096 00097 #ifdef DEGUG_BOX 00098 if ((t1>0.0)==false) 00099 { 00100 cout << SHOW(t1) << " " << SHOW(t2) << " " << SHOW(h) << endl; 00101 } 00102 #endif 00103 00104 p.step(t1-h); 00105 00106 p.vel[1]*=-1.0; 00107 p.step(t2); 00108 00109 return true; 00110 } 00111 00112 ostream & operator << 00113 ( 00114 ostream & os, 00115 boxcollision const & b 00116 ) 00117 { 00118 return b.print(os); 00119 } 00120 00121 00122
1.5.8