Eigene Dateien/uni/visualisierung/vislu/bsp1/VisLu/VCamera.cpp

Go to the documentation of this file.
00001 #include "VCamera.h"
00002 #include <GL/glew.h>
00003 #include <GL/glut.h>
00004 #include "vmath.h"
00005 #include <math.h>
00006 #include <iostream>
00007 
00008 using namespace std;
00009 
00010 VCamera::VCamera(int * width, int * height, float distance)
00011 {
00012     this->winwidth = width;
00013     this->winheight = height;
00014         this->angleX = 0.0f;
00015         this->angleY = 0.0f;
00016         this->maxdistance = 8.0f;
00017         this->mindistance = 2.0f;
00018         this->setDistance(distance);
00019         this->deleteFromPoint();
00020 }
00021 
00022 VCamera::~VCamera()
00023 {
00024     
00025 }
00026 
00027 void VCamera::setCamera()
00028 {
00029         //cout << "set camera" << endl;
00030         //glTranslatef(0,0,this->distance);
00031         glTranslatef(0,0,-this->distance);
00032         glRotatef(-this->angleX, 1.0f, 0.0f, 0.0f );
00033         glRotatef(-this->angleY, 0.0f, 1.0f, 0.0f );
00034 }
00035 
00036 void VCamera::setRotation() {
00037         glRotatef(this->angleX, 1.0f, 0.0f, 0.0f );
00038         glRotatef(-this->angleY, 0.0f, 1.0f, 0.0f );
00039 }
00040 
00041 float VCamera::getDistance ()
00042 {
00043         return this->distance;
00044 }
00045 
00046 void VCamera::setAxisAlign(int axis) {
00047         switch(axis) {
00048                 case 0: this->angleX = 0.0f; this->angleY = -90.0f; break; //x
00049                 case 1: this->angleX = 90.0f; this->angleY = 0.0f; break; //y
00050                 case 2: this->angleX = 0.0f; this->angleY = 0.0f; break; //z
00051         }
00052 }
00053 
00054 void VCamera::setDistance (float cameraDistance)
00055 {
00056         if(cameraDistance <= this->maxdistance && cameraDistance >= this->mindistance) {
00057                 this->distance = cameraDistance;
00058         }
00059 }
00060 
00061 void VCamera::setFromPoint(int x,int y) {
00062         //cout << x << " " << y;
00063         this->fromPoint[0] = x;
00064         this->fromPoint[1] = y;
00065 }
00066 
00067 void VCamera::deleteFromPoint() {
00068         this->fromPoint[0] = 0;
00069         this->fromPoint[1] = 0;
00070 }
00071 
00072 void VCamera::changeDirection(int x, int y)
00073 {
00074         //cout << "changing direction" << endl;
00075         //cout << this->fromPoint[0] << " " << this->fromPoint[1] << endl;
00076     Vector2<float> toPoint(x,y);
00077         Vector2<float> diffPoint = toPoint - fromPoint;
00078 
00079         this->angleX += -(diffPoint[1]/ (*winheight) * 180);
00080         this->angleY += -(diffPoint[0]/ (*winwidth) * 180);
00081 
00082         fromPoint = toPoint;
00083 }
00084 
00085 void VCamera::changeDistance(int x, int y)
00086 {
00087     Vector2<float> toPoint(x,y);
00088         Vector2<float> diffPoint = toPoint - fromPoint;
00089 
00090         float maxlength = sqrt((float)(*winwidth)*(*winwidth)+(*winheight)*(*winheight));
00091         float newdistance = (diffPoint.length()/maxlength)*this->maxdistance;
00092 
00093         float sum = diffPoint[0] + diffPoint[1];
00094         if(sum >= 0) {
00095                 this->setDistance(this->distance + newdistance);
00096         } else {
00097                 this->setDistance(this->distance - newdistance);
00098         }
00099         //cout << diffPoint[0] << " " << diffPoint[1] << endl;
00100 
00101         fromPoint = toPoint;
00102 }

Generated on Wed Dec 6 11:07:59 2006 for VisLU by  doxygen 1.5.1-p1