- Timestamp:
- Jun 18, 2004, 7:56:18 AM (20 years ago)
- Location:
- orxonox/branches/chris/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/chris/core/collision.cc
r1966 r1975 74 74 } 75 75 76 bool check_trace (const Placement& pa, const CollisionCluster& a, unsigned long* ahitflags, const Line& trace, Vector* impactpoint) 77 { 78 return false; 76 bool check_trace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint) 77 { 78 CC_Tree* t; 79 if( (t = a->root) == NULL) return false; 80 81 return cctree_trace( pa, t, ahitflags, trace, impactpoint); 79 82 } 80 83 … … 94 97 } 95 98 96 bool trace_sphere_collision( Vector m, float r, Line& l, Vector* impactpoint) 97 { 98 return false; 99 bool trace_sphere_collision( Vector m, float r, const Line* l, Vector* impactpoint) 100 { 101 float A, B, C, D, t[2]; 102 Vector d = l->r - m; 103 int i; 104 105 A = l->a * l->a; 106 B = 2 * (l->a * d); 107 C = (d*d) - r*r; 108 D = B*B - 4*A*C; 109 110 if (D < 0) return false; 111 112 t[0] = (-B+sqrt(D))/(2*A); 113 t[1] = (-B-sqrt(D))/(2*A); 114 115 if( (t[0] > 1 || t[0] < 0) && (t[1] < 0 || t[1] > 1)) return false; 116 if( t[0] > t[1]) i = 0; 117 else i = 1; 118 119 impactpoint->x = (l->r + (l->a * t[i])).x; 120 impactpoint->y = (l->r + (l->a * t[i])).y; 121 impactpoint->z = (l->r + (l->a * t[i])).z; 122 123 return true; 99 124 } 100 125 … … 237 262 return 0; 238 263 } 264 265 bool cctree_trace( const Placement* p, CC_Tree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint) 266 { 267 bool r = false; 268 int i; 269 Vector mr = p->r + rotate_vector( t->m, p->w); 270 CC_Tree* use_t; 271 Vector* ips; 272 unsigned long* hfs; 273 274 if( trace_sphere_collision (mr, t->r, trace, impactpoint)) 275 { 276 if( t->n == 0) 277 { 278 setflag (hitflags, t->data.ID); 279 return true; 280 } 281 else 282 { 283 ips = new Vector[t->n]; 284 hfs = new unsigned long[t->n]; 285 for (i = 0; i < t->n; i++) hfs[i] = 0; 286 for (i = 0; i < t->n; i++) 287 { 288 r = r || cctree_trace (p, t->data.b[i], &(hfs[i]), trace, &(ips[i])); 289 } 290 if( r) 291 { 292 float kl = 0.0; 293 float l = 0.0; 294 int k = 0; 295 for (i = 0; i < t->n; i++) 296 { 297 if( (kl = (trace->r - ips[i]).len()) > l) 298 { 299 l = kl; 300 k = i; 301 } 302 } 303 impactpoint->x = ips[k].x; 304 impactpoint->y = ips[k].y; 305 impactpoint->z = ips[k].z; 306 *hitflags = hfs[k]; 307 } 308 delete ips; 309 delete hfs; 310 } 311 return r; 312 } 313 314 return false; 315 } -
orxonox/branches/chris/core/collision.h
r1966 r1975 3 3 #define COLLISION_H 4 4 5 #include "stdincl.h" 5 #include "vector.h" 6 #include "coordinates.h" 7 #include <stdlib.h> 8 #include <stdio.h> 9 #include <strings.h> 6 10 7 11 typedef struct CC_Tree … … 29 33 int store (char* filename); 30 34 35 friend bool cctree_trace( const Placement* p, CC_Tree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint); 31 36 friend bool cctree_iterate(const Placement* pa, CC_Tree* ta, unsigned long* ahitflags, const Placement* pb, CC_Tree* tb, unsigned long* bhitflags); 32 friend bool check_trace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line &trace, Vector* impactpoint);37 friend bool check_trace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint); 33 38 friend bool check_collision (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Placement* pb, const CollisionCluster* b, unsigned long* bhitflags); 34 39 }; 35 40 36 41 bool sphere_sphere_collision( Vector m1, float r1, Vector m2, float r2); 37 bool trace_sphere_collision( Vector m, float r, Line&l, Vector* impactpoint);42 bool trace_sphere_collision( Vector m, float r, const Line* l, Vector* impactpoint); 38 43 39 44 void setflag( unsigned long* flags, unsigned long ID);
Note: See TracChangeset
for help on using the changeset viewer.