Index: orxonox/trunk/src/camera.cc
===================================================================
--- orxonox/trunk/src/camera.cc	(revision 2190)
+++ orxonox/trunk/src/camera.cc	(revision 2551)
@@ -29,5 +29,20 @@
 Camera::Camera ()
 {
-	bound = NULL;
+  bound = NULL;
+  /* give it some physical live */
+  m = 10;
+  a = new Vector(0.0, 0.0, 0.0);
+  v = new Vector(0.0, 0.0, 0.0);
+  fs = new Vector(0.0, 0.0, 0.0);
+  cameraMode = NORMAL;
+
+  deltaTime = 3000.0;
+  cameraOffset = 1.0;
+  cameraOffsetZ = 10.0;
+  t = 0.0;
+
+  actual_place.r.x = 0.0;
+  actual_place.r.y = 10.0;
+  actual_place.r.z = -5.0;
 }
 
@@ -48,82 +63,193 @@
 void Camera::time_slice (Uint32 deltaT)
 {
-	update_desired_place ();
-	jump (NULL);
-}
-
-/**
-  \brief this calculates the location where the track wants the camera to be
-   
-	This refreshes the placement the camera should have according to the bound entity's position on the track.
+  if(t <= deltaTime)
+    {t += deltaT;}
+  //printf("time is: t=%f\n", t );
+  update_desired_place ();
+  jump (NULL);
+}
+
+/**
+   \brief this calculates the location where the track wants the camera to be
+   
+   This refreshes the placement the camera should have according to the 
+   bound entity's position on the track.
 */
 void Camera::update_desired_place ()
 {
-		Orxonox *orx = Orxonox::getInstance();
-		Location lookat;
+  switch(cameraMode)
+    {
+      
+    case ELLIPTICAL:
+      {
+	//r = actual_place.r 
+	Orxonox *orx = Orxonox::getInstance();
+	Location lookat;  
+	Placement plFocus;
+	if( bound != NULL)
+	  {
+	    bound->get_lookat (&lookat);
+	    orx->get_world()->calc_camera_pos (&lookat, &plFocus);
+	    Quaternion *fr;
+	    if(t < 20.0)
+	      {
+		Vector *start = new Vector(0.0, 1.0, 0.0);
+		//r = /*actual_place.r*/ *start - plFocus.r;
+		r = *(new Vector(0.0, 5.0, 0.0));
+
+		Vector up(0.0, 0.0, 1.0);
 		
-		if( bound != NULL)
-		{
-			bound->get_lookat (&lookat);
-			orx->get_world()->calc_camera_pos (&lookat, &desired_place);
-		}
-		else
-		{
-			desired_place.r = Vector (0,0,0);
-			desired_place.w = Quaternion (); 
-		}
-}
-
-/**
-  \brief initialize rendering perspective according to this camera
-   
-	This is called immediately before the a rendering cycle starts, it sets all global rendering options as
-	well as the GL_PROJECTION matrix according to the camera.
+		Vector op(1.0, 0.0, 0.0);
+		float angle = angle_deg(op, *start);
+		printf("angle is: %f\n", angle);
+
+		//if in one plane
+		from = new Quaternion(angle, up);
+
+		//from = new Quaternion(*start, *up);
+		//&from = &plFocus.w;
+		//fr = &plFocus.w; real quaternion use
+		
+
+
+		Vector vDirection(1.0, 0.0, 0.0);
+		//vDirection = plFocus.w.apply(vDirection);
+		to = new Quaternion(vDirection, *start);
+		res = new Quaternion();
+	      }
+	    //printf("vector r = %f, %f, %f\n",r.x, r.y, r.z );
+	    rAbs = r.len();
+	    if(t < 30.0) /* FIXME!!*/
+	      {
+		ka = rAbs / deltaTime*deltaTime;
+	      }
+	    /* this is the new length of the vector */
+	    //float len = ka * powf((deltaTime - t), 2);
+	    
+	    /* calc the rotation */
+	    /*
+	    Vector axis(0.0, 0.0, 1.0);
+	    if(t < 30.0)
+	      a0 = PI/4 - atanf(fabs(r.x) / fabs(r.y));
+	    printf("a0 = %f\n", a0);
+	    float angle = a0/deltaTime * (deltaTime - t);
+	    printf("angle is: %f\n", angle);
+	    Quaternion q(angle, axis);
+	    */
+	    //r = q.apply(r);
+	    //r = r * (len/r.len());
+	    
+	    //res->quatSlerp(from, to, t/deltaTime, res);
+	    res->quatSlerp(to, from, t/deltaTime, res);
+
+	    Vector ursp(0.0, 0.0, 0.0);
+	    desired_place.r = /*plFocus.r -*/ ursp - res->apply(r); 
+
+	    printf("desired place is: %f, %f, %f\n", desired_place.r.x, desired_place.r.y, desired_place.r.z);
+	    //plLastBPlace = *bound->get_placement();
+	  } 
+      }
+      break;
+    case SMOTH_FOLLOW:
+      {
+	Placement *plBound = bound->get_placement();
+	Location lcBound;
+	if(bound != null)
+	  {
+	    bound->get_lookat(&lcBound);
+	    Vector vDirection(0.0, 0.0, 1.0);
+	    vDirection = plBound->w.apply(vDirection);
+	    desired_place.r = (vDirection * ((lcBound.dist-10.0)/* / l*/)) + Vector(0,0,5.0);
+	  }
+	break;
+      }
+      /* this is a camera mode that tries just to follow the entity. */
+    case STICKY:
+      {
+	if(bound != null)
+	  {
+	    Placement *plBound = bound->get_placement();
+	    Vector vDirection(0.0, 0.0, 1.0);
+	    Vector eclipticOffset(0.0, 0.0, 5.0);
+	    vDirection = plBound->w.apply(vDirection);
+	    desired_place.r = plBound->r - vDirection*10 + eclipticOffset;
+	  }
+	break;
+      }
+      /* the camera is handled like an entity and rolls on the track */
+    case NORMAL:
+      Orxonox *orx = Orxonox::getInstance();
+      Location lookat;  
+      if( bound != NULL)
+	{
+	  bound->get_lookat (&lookat);
+	  orx->get_world()->calc_camera_pos (&lookat, &desired_place);
+	} 
+      else
+	{
+	  desired_place.r = Vector (0,0,0);
+	  desired_place.w = Quaternion (); 
+	}
+      break;
+    }
+}
+
+/**
+   \brief initialize rendering perspective according to this camera
+   
+   This is called immediately before the rendering cycle starts, it sets all global
+   rendering options as well as the GL_PROJECTION matrix according to the camera.
 */
 void Camera::apply ()
 {
-	glMatrixMode (GL_PROJECTION);
+  glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
-		// view
-		// TO DO: implement options for frustum generation
-	glFrustum( -1.0,1.0,-1.0,1.0,1.5,250.0);
-//Vector up(0,0,1);
-//Vector dir(1,0,0);
-//Quaternion q(dir,up);
-//float matrix[4][4];
-//q.conjugate().matrix (matrix);
-//glMultMatrixf ((float*)matrix);
-//glTranslatef (10,0,-5);
-//
-//dir = Vector(-1,-1,0);
-//q = Quaternion( dir, up);
-//glMatrixMode (GL_MODELVIEW);
-//glLoadIdentity ();
-//q.matrix (matrix);
-//glMultMatrixf ((float*)matrix);
-//glTranslatef (2,2,0);
-//
-//glBegin(GL_TRIANGLES);
-//glColor3f(1,0,0);
-//glVertex3f(0,0,0.5);
-//glColor3f(0,1,0);
-//glVertex3f(-0.5,0,-1);
-//glColor3f(0,0,1);
-//glVertex3f(0.5,0,-1);
-//glEnd();	
-
-  	// rotation
+  // view
+  // TO DO: implement options for frustum generation
+  glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 250.0);
+  //Vector up(0,0,1);
+  //Vector dir(1,0,0);
+  //Quaternion q(dir,up);
+  //float matrix[4][4];
+  //q.conjugate().matrix (matrix);
+  //glMultMatrixf ((float*)matrix);
+  //glTranslatef (10,0,-5);
+  //
+  //dir = Vector(-1,-1,0);
+  //q = Quaternion( dir, up);
+  //glMatrixMode (GL_MODELVIEW);
+  //glLoadIdentity ();
+  //q.matrix (matrix);
+  //glMultMatrixf ((float*)matrix);
+  //glTranslatef (2,2,0);
+  //
+  //glBegin(GL_TRIANGLES);
+  //glColor3f(1,0,0);
+  //glVertex3f(0,0,0.5);
+  //glColor3f(0,1,0);
+  //glVertex3f(-0.5,0,-1);
+  //glColor3f(0,0,1);
+  //glVertex3f(0.5,0,-1);
+  //glEnd();	
+
+  // ===== first camera control calculation option
+  // rotation
   float matrix[4][4];
   actual_place.w.conjugate().matrix (matrix);
+  /* orientation and */
   glMultMatrixf ((float*)matrix);
-  	// translation
+  /*  translation */
   glTranslatef (-actual_place.r.x, -actual_place.r.y,- actual_place.r.z);
-  
+  //Placement *plBound = bound->get_placement();
+
+  // ===== second camera control calculation option
+  /*
+    gluLookAt(actual_place.r.x, actual_place.r.y, actual_place.r.z, 
+              plBound->r.x, plBound->r.y, plBound->r.z,
+              0.0, 0.0, 1.0);
+  */
+
   glMatrixMode (GL_MODELVIEW);
   glLoadIdentity ();
-  
-  printf("Camera@%f/%f/%f\n",actual_place.r.x,actual_place.r.y,actual_place.r.z);
-  Vector unique(1,0,0);
-  Vector test = actual_place.w.apply (unique);
-  printf("Camera&%f/%f/%f\n", test.x, test.y, test.z);
 }
 
@@ -136,13 +262,14 @@
 void Camera::jump (Placement* plc = NULL)
 {
-	if( plc == NULL)
-	{
-		actual_place = desired_place;
-	}
-	else
-	{
-		desired_place = *plc;
-		actual_place = *plc;
-	}
+  if( plc == NULL)
+    {
+      actual_place = desired_place;
+      //printf("Camera|jump: camer@ %f, %f, %f\n\n", actual_place.r.x, actual_place.r.y, actual_place.r.z);
+    }
+  else
+    {
+      desired_place = *plc;
+      actual_place = *plc;
+    }
 }
 
@@ -157,8 +284,11 @@
 void Camera::bind (WorldEntity* entity)
 {
-	if( entity != NULL)
+  if( entity != NULL)
+    {
+      if( entity->isFree ()) printf("Cannot bind camera to free entity");
+      else 
 	{
-		if( entity->isFree ()) printf("Cannot bind camera to free entity");
-		else bound = entity;
-	} 
-}
+	  bound = entity;
+	}
+    } 
+}
