Index: orxonox/branches/levelloader/src/camera.cc
===================================================================
--- orxonox/branches/levelloader/src/camera.cc	(revision 3605)
+++ orxonox/branches/levelloader/src/camera.cc	(revision 3746)
@@ -17,31 +17,28 @@
 
 #include "camera.h"
+
 #include "world.h"
 #include "world_entity.h"
+#include "vector.h"
 
 using namespace std;
 
+////////////
+// CAMERA //
+////////////
+
 /**
    \brief creates a Camera
-   
-   This standard constructor sets all parameters to zero
 */
-Camera::Camera (World* world)
+Camera::Camera(void)
 {
-  this->world = world;
-  this->bound = NULL;
-  /* give it some physical live */
-  this->m = 10;
-  this->a = new Vector(0.0, 0.0, 0.0);
-  this->v = new Vector(0.0, 0.0, 0.0);
-  this->fs = new Vector(0.0, 0.0, 0.0);
-  this->cameraMode = NORMAL;
-  this->deltaTime = 3000.0;
-  this->cameraOffset = 1.0;
-  this->cameraOffsetZ = 10.0;
-  this->t = 0.0;
+  this->setClassName("Camera");
+  this->target = new CameraTarget();
 
+  this->setFovy(90);
+  this->setAspectRatio(1.2f);
+  this->setClipRegion(.1, 2000);
 
-  this->setDrawable (false);
+  this->setViewMode(VIEW_NORMAL);
 }
 
@@ -49,142 +46,105 @@
    \brief default destructor
 */
-Camera::~Camera ()
+Camera::~Camera(void)
 {
-  this->bound = NULL;
-  this->world = NULL;
-
 }
 
 /**
-   \brief time based actualisation of camera parameters
-   \param deltaT: The amount of time that has passed in milliseconds
-   
-   This is called by the World in every time_slice, use it to do fancy time dependant effects (such 
-   as smooth camera movement or swaying).
+   \brief focuses the Camera onto a Target
+   \param target the new PNode the Camera should look at.
 */
-void Camera::tick (Uint32 deltaT)
+void Camera::lookAt(PNode* target)
 {
-  if( this->t <= deltaTime)
-    {this->t += deltaT;}
-  //printf("time is: t=%f\n", t );
-  updateDesiredPlace();
-  //jump(NULL);
+  this->target->setParent(target);
 }
 
 /**
-   \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.
+   \returns The PNode of the Target (from there you can get position and so on
 */
-void Camera::updateDesiredPlace ()
+PNode* Camera::getTarget(void)
 {
-  switch(cameraMode)
-    {
-      
-    case ELLIPTICAL:
-      {
-	/*
-	//r = actual_place.r 
-	Orxonox *orx = Orxonox::getInstance();
-	Location lookat;  
-	Placement plFocus;
-	if( bound != NULL)
-	  {
-	    bound->getLookat (&lookat);
-	    orx->getWorld()->calcCameraPos (&lookat, &plFocus);
-	    Quaternion *fr;
-	    if(t < 20.0)
-	      {
-		Vector *start = new Vector(0.0, 1.0, 0.0);
-		r = *(new Vector(0.0, 5.0, 0.0));
-
-		Vector up(0.0, 0.0, 1.0);
-		
-		Vector op(1.0, 0.0, 0.0);
-		float angle = angleDeg(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
-		
+  return (PNode*)this->target;
+}
 
 
-		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)
-	      {
-		ka = rAbs / deltaTime*deltaTime;
-	      }
+/**
+   \brief sets a new AspectRatio
+   \param aspectRatio the new aspect ratio to set (width / height)
+*/
+void Camera::setAspectRatio(float aspectRatio)
+{
+  this->aspectRatio = aspectRatio;
+}
 
-	    res->quatSlerp(to, from, t/deltaTime, res);
+/**
+   \brief sets the Field of View to fofy
+   \param fovy new field of view factor (in degrees)
+*/
+void Camera::setFovy(float fovy)
+{
+  this->fovy = fovy;
+}
 
-	    Vector ursp(0.0, 0.0, 0.0);
-	    desiredPlace.r =  ursp - res->apply(r); 
+/**
+  \brief Sets a new clipping region
+  \param nearClip The near clip plane
+  \param farClip The far clip plane
+*/
+void Camera::setClipRegion(float nearClip, float farClip)
+{
+  this->nearClip = nearClip;
+  this->farClip = farClip;
+}
 
-	    printf("desired place is: %f, %f, %f\n", desiredPlace.r.x, desiredPlace.r.y, desiredPlace.r.z);
-	    //plLastBPlace = *bound->get_placement();
-	    
-	  } 
-      */
-      }
+void Camera::setViewMode(ViewMode mode)
+{
+  switch (mode)
+    {
+    default:
+    case VIEW_NORMAL:
+      this->toFovy = 60.0;
+      this->toRelCoor = Vector(-10, 5, 0);
       break;
-    case SMOTH_FOLLOW:
-      {
-	/*
-	Placement *plBound = bound->getPlacement();
-	Location lcBound;
-	if(bound != null)
-	  {
-	    bound->getLookat(&lcBound);
-	    Vector vDirection(0.0, 0.0, 1.0);
-	    vDirection = plBound->w.apply(vDirection);
-	    desiredPlace.r = (vDirection * ((lcBound.dist-10.0))) + 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->getPlacement();
-	    Vector vDirection(0.0, 0.0, 1.0);
-	    Vector eclipticOffset(0.0, 0.0, 5.0);
-	    vDirection = plBound->w.apply(vDirection);
-	    desiredPlace.r = plBound->r - vDirection*10 + eclipticOffset;
-	  }
-	*/
-	break;
-      }
-      /* the camera is handled like an entity and rolls on the track */
-    case NORMAL:
-      if( bound != NULL && world != NULL )
-	{
-	  //FIXME: camera should be made via relative coordinates
-	  Vector* cameraOffset = new Vector (-10, 5, 0);
-	  this->setRelCoor (cameraOffset);
-	} 
-      else
-	{
-	  /*
-	  desiredPlace.r = Vector (0,0,0);
-	  desiredPlace.w = Quaternion (); 
-	  */
-	}
+    case VIEW_BEHIND:
+      this->toFovy = 120.0;
+      this->toRelCoor = Vector(-7, 0, 0);
       break;
+    case VIEW_FRONT:
+      this->toFovy = 95.0;
+      this->toRelCoor = Vector(12, 5, 0);
+      break;
+    case VIEW_LEFT: 
+      this->toFovy = 90;
+      this->toRelCoor = Vector(0, 2, -10);
+      break;
+    case VIEW_RIGHT:
+      this->toFovy = 90;
+      this->toRelCoor = Vector(0, 2, 10);
+      break;
+    case VIEW_TOP:
+      this->toFovy= 120;
+      this->toRelCoor = Vector(0, 4, 0);
     }
 }
+
+
+/**
+   \brief Updates the position of the camera.
+   \param dt The time that elapsed.
+*/
+void Camera::tick(float dt)
+{
+  dt /= 500;
+  float tmpFovy = (this->toFovy - this->fovy) * dt;
+  if (tmpFovy > .001)
+    this->fovy += (this->toFovy - this->fovy) * dt;
+  Vector tmpPos = (this->toRelCoor - *this->getRelCoor()) * dt;
+  if (tmpPos.len() >= .001)
+    {
+      tmpPos = tmpPos + *this->getRelCoor();
+      this->setRelCoor(&tmpPos);
+    }
+}
+
 
 /**
@@ -196,85 +156,44 @@
 void Camera::apply ()
 {
+  // switching to Projection Matrix
   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);
-  gluPerspective(60, 1.2f, 0.1, 2000);
-  
-  //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];
-  //this->absDirection.conjugate().matrix (matrix);
-  /* orientation and */
-  //glMultMatrixf ((float*)matrix);
+  // setting up the perspective
+  gluPerspective(this->fovy,
+		 this->aspectRatio,
+		 this->nearClip,
+		 this->farClip);
 
-  /*  translation */
-  //glTranslatef (this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z );
+  // speed-up feature
+  Vector cameraPosition = this->getAbsCoor();
+  Vector targetPosition = this->target->getAbsCoor();
+  Vector up = Vector(0, 1, 0);
+  up = this->getAbsDir().apply(up);
 
+  // Setting the Camera Eye, lookAt and up Vectors
+  gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z,
+	    targetPosition.x, targetPosition.y, targetPosition.z,
+	    up.x, up.y, up.z);
 
-  // ===== second camera control calculation option
-  
-  gluLookAt(this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z, 
-	    this->parent->getAbsCoor ().x, this->parent->getAbsCoor ().y, this->parent->getAbsCoor ().z,
-	    0.0, 1.0, 0.0);
-  
-
+  // switching back to Modeling Matrix
   glMatrixMode (GL_MODELVIEW);
-  glLoadIdentity ();
 }
 
 
 
-/**
-  \brief bind the camera to an entity
-  \param entity: The enitity to bind the camera to
-	
-  This sets the focus of the camera to the given entity. This means that it will use the given WorldEntity's
-  Location and get_lookat() to determine the viewpoint the camera will render from.
-  Note that you cannot bind a camera to a free entity.
-*/
-void Camera::bind (WorldEntity* entity)
+///////////////////
+// CAMERA-TARGET //
+///////////////////
+
+
+CameraTarget::CameraTarget()
 {
-  if( entity != NULL)
-    {
-      if( entity->isFree()) printf("Cannot bind camera to free entity");
-      else 
-	{
-	  this->bound = entity;
-	}
-    } 
+  this->setClassName("CameraTarget");
+  this->setMode(PNODE_MOVEMENT);
 }
 
+CameraTarget::~CameraTarget()
+{
 
-void Camera::setWorld(World* world)
-{
-  this->world = world;
 }
-
-
