Index: orxonox/branches/chris/core/collision.cc
===================================================================
--- orxonox/branches/chris/core/collision.cc	(revision 1972)
+++ orxonox/branches/chris/core/collision.cc	(revision 1975)
@@ -74,7 +74,10 @@
 }
 
-bool check_trace (const Placement& pa, const CollisionCluster& a, unsigned long* ahitflags, const Line& trace, Vector* impactpoint)
-{
-  return false;
+bool check_trace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint)
+{
+	CC_Tree* t;
+	if( (t = a->root) == NULL) return false;
+	
+  return cctree_trace( pa, t, ahitflags, trace, impactpoint);
 }
 
@@ -94,7 +97,29 @@
 }
 
-bool trace_sphere_collision( Vector m, float r, Line& l, Vector* impactpoint)
-{
-  return false;
+bool trace_sphere_collision( Vector m, float r, const Line* l, Vector* impactpoint)
+{
+  float A, B, C, D, t[2];
+  Vector d = l->r - m;
+  int i;
+  
+  A = l->a * l->a;
+  B = 2 * (l->a * d);
+  C = (d*d) - r*r;
+  D = B*B - 4*A*C;
+  
+  if (D < 0) return false;
+  
+  t[0] = (-B+sqrt(D))/(2*A);
+  t[1] = (-B-sqrt(D))/(2*A);
+  
+  if( (t[0] > 1 || t[0] < 0) && (t[1] < 0 || t[1] > 1)) return false;
+  if( t[0] > t[1]) i = 0;
+  else i = 1;
+
+  impactpoint->x = (l->r + (l->a * t[i])).x;
+  impactpoint->y = (l->r + (l->a * t[i])).y;
+  impactpoint->z = (l->r + (l->a * t[i])).z;
+  
+  return true;
 }
 
@@ -237,2 +262,54 @@
   return 0;
 }
+
+bool cctree_trace( const Placement* p, CC_Tree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint)
+{
+  bool r = false;
+  int i;
+  Vector mr = p->r + rotate_vector( t->m, p->w);
+  CC_Tree* use_t;
+  Vector* ips;
+  unsigned long* hfs;
+  
+  if( trace_sphere_collision (mr, t->r, trace, impactpoint))
+  {
+  	if( t->n == 0)
+  	{
+  		setflag (hitflags, t->data.ID);
+  		return true;
+  	}
+  	else
+  	{
+  		ips = new Vector[t->n];
+  		hfs = new unsigned long[t->n];
+  		for (i = 0; i < t->n; i++) hfs[i] = 0;
+  		for (i = 0; i < t->n; i++)
+  		{
+  			r = r || cctree_trace (p, t->data.b[i], &(hfs[i]), trace, &(ips[i]));
+  		}
+  		if( r)
+  		{
+  			float kl = 0.0;
+  			float l = 0.0;
+  			int k = 0;
+  			for (i = 0; i < t->n; i++)
+  			{
+  				if( (kl = (trace->r - ips[i]).len()) > l)
+  				{
+  					l = kl;
+  					k = i;
+  				}
+  			}
+  			impactpoint->x = ips[k].x;
+  			impactpoint->y = ips[k].y;
+  			impactpoint->z = ips[k].z;
+  			*hitflags = hfs[k];
+  		}
+  		delete ips;
+  		delete hfs;
+  	}
+  	return r;
+  }
+  
+  return false;
+}
Index: orxonox/branches/chris/core/collision.h
===================================================================
--- orxonox/branches/chris/core/collision.h	(revision 1972)
+++ orxonox/branches/chris/core/collision.h	(revision 1975)
@@ -3,5 +3,9 @@
 #define COLLISION_H
 
-#include "stdincl.h"
+#include "vector.h"
+#include "coordinates.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <strings.h>
 
 typedef struct CC_Tree
@@ -29,11 +33,12 @@
   int store (char* filename);
   
+  friend bool cctree_trace( const Placement* p, CC_Tree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint);
   friend bool cctree_iterate(const Placement* pa, CC_Tree* ta, unsigned long* ahitflags, const Placement* pb, CC_Tree* tb, unsigned long* bhitflags);
-  friend bool check_trace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line& trace, Vector* impactpoint);
+  friend bool check_trace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint);
   friend bool check_collision (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Placement* pb, const CollisionCluster* b, unsigned long* bhitflags);
 };
 
 bool sphere_sphere_collision( Vector m1, float r1, Vector m2, float r2);
-bool trace_sphere_collision( Vector m, float r, Line& l, Vector* impactpoint);
+bool trace_sphere_collision( Vector m, float r, const Line* l, Vector* impactpoint);
 
 void setflag( unsigned long* flags, unsigned long ID);
