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

Go to the documentation of this file.
00001 #include "VAxisAlignElement.h"
00002 #include <iostream>
00003 #include "V2Ddraw.h"
00004 #include "corona.h"
00005 #include "VCamera.h"
00006 #include <GL/glew.h>
00007 #include <GL/glut.h>
00008 #include <math.h>
00009 
00010 using namespace std;
00011 
00012 VAxisAlignElement::VAxisAlignElement(int* width, int* height, unsigned int* fps, VCamera * cam):
00013         GUIelement(width,height,fps)
00014 {
00015         this->offset = 40;
00016         this->x = offset+20; //(int)*(this->wwidth)*0.02;
00017         this->y = (int)*(this->wheight)-(offset+20); //*0.75;
00018         this->active = true;
00019         this->camera = cam;
00020         this->dragging = false;
00021 }
00022 
00023 VAxisAlignElement::~VAxisAlignElement(void)
00024 {
00025 
00026 }
00027 
00028 void VAxisAlignElement::render() {
00029         glLineWidth(4);
00030         glEnable(GL_LINE_SMOOTH);
00031         glPushMatrix();
00032         
00033         glTranslatef(this->x,this->y,0.0f);
00034         
00035         camera->setRotation();
00036 
00037         glBegin(GL_LINES);
00038         //x
00039         glColor4f(1,0,0,1);
00040         glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
00041         glVertex3f(offset, 0.0f, 0.0f); // end point of the line
00042 
00043         //y
00044         glColor4f(0,1,0,1);
00045         glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
00046         glVertex3f(0.0f, -offset, 0.0f); // end point of the line
00047 
00048         //z
00049         glColor4f(0,0,1,1);
00050         glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
00051         glVertex3f(0.0f, 0.0f, offset); // end point of the line
00052 
00053         glEnd( );
00054         glPopMatrix();
00055         glDisable(GL_LINE_SMOOTH);
00056         glLineWidth(1);
00057 }
00058 
00059 void VAxisAlignElement::released(int x, int y) {
00060         if(!this->dragging) { //click
00061                 //cout << "click" << endl;
00062                 float pixels[3];
00063                 GLint viewport[4];
00064                 glGetIntegerv(GL_VIEWPORT,viewport);
00065                 glReadPixels(x,viewport[3]-y,1,1,GL_RGB,GL_FLOAT,pixels);
00066                 if(pixels[0] == 1.0 && pixels[1] == 0.0 && pixels[2] == 0.0) {
00067                         //cout << "red" << endl;
00068                         this->camera->setAxisAlign(0);
00069                 } else if(pixels[0] == 0.0 && pixels[1] == 1.0 && pixels[2] == 0.0) {
00070                         //cout << "green" << endl;
00071                         this->camera->setAxisAlign(1);
00072                 } else if(pixels[0] == 0.0 && pixels[1] == 0.0 && pixels[2] == 1.0) {
00073                         //cout << "blue" << endl;
00074                         this->camera->setAxisAlign(2);
00075                 }
00076         }
00077         this->dragging = false;
00078 }
00079 
00080 void VAxisAlignElement::drag(int,int) {
00081         this->dragging = true;
00082 }
00083 
00084 bool VAxisAlignElement::isInside(int xm, int ym) {
00085         return sqrt(pow((double)ym-this->y,2)+pow((double)xm-this->x,2)) < this->offset;
00086 }

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