/pr2/UFP.cpp
C++ | 858 lines | 637 code | 127 blank | 94 comment | 133 complexity | e435ed1d2a04cbe8372dc853e590d8c2 MD5 | raw file
- /* Práctica 1 de IGr
- *
- * Enrique López Ma?as - 70060945-R
- * Daniel Dionne González - 51454901-Z
- */
- //---------------------------------------------------------------------------
-
- #include <vcl.h>
- #pragma hdrstop
-
- #include "UFP.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
-
-
- TGLForm2D *GLForm2D;
- //---------------------------------------------------------------------------
- __fastcall TGLForm2D::TGLForm2D(TComponent* Owner)
- : TForm(Owner)
- {
- }
-
- //---------------------------------------------------------------------------
- void __fastcall TGLForm2D::FormCreate(TObject *Sender)
- {
- scene = new Scene();
- running = true;
- RatioViewPort = 1.0;
- hdc = GetDC(Handle);
- SetPixelFormatDescriptor();
- hrc = wglCreateContext(hdc);
-
- if(hrc == NULL)
- ShowMessage(":-)~ hrc == NULL");
- if(wglMakeCurrent(hdc, hrc) == false)
- ShowMessage("Could not MakeCurrent");
-
- //Color de fondo de la ventana
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
-
- // Inicializacion del volumen de vista
- scene->setLimits(-300,300,300,-300);
- //Radio del volumen de vista == 1
-
- // Inicializacion del puerto de vista
- //ClientWidth=400;
- //ClientHeight=400;
-
-
- // Inicializacion de las variables del programa
- traslX = traslY = 0;
-
- formDebug = new TFormDebug(this);
- formPaleta = new TformPaleta(this);
-
- zoomVel = 0;
- maxZoomVel = 200;
- xVel = 0;
- yVel = 0;
- maxVel = 200;
- pointInit.setX(0);
- pointInit.setY(0);
-
- option = unSelected;
-
- formPaleta->editLados->Text = "5";
- }
- //---------------------------------------------------------------------------
- void __fastcall TGLForm2D::SetPixelFormatDescriptor()
- {
- PIXELFORMATDESCRIPTOR pfd = {
- sizeof(PIXELFORMATDESCRIPTOR),
- 1,
- PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
- PFD_TYPE_RGBA,
- 32,
- 0,0,0,0,0,0,
- 0,0,
- 0,0,0,0,0,
- 32,
- 0,
- 0,
- PFD_MAIN_PLANE,
- 0,
- 0,0,0
- };
- int PixelFormat = ChoosePixelFormat(hdc, &pfd);
- SetPixelFormat(hdc, PixelFormat, &pfd);
- }
- //---------------------------------------------------------------------
- void __fastcall TGLForm2D::FormResize(TObject *Sender)
- {
- if (scene!=NULL) {
- //se actualiza puerto de vista y su radio
- if ((ClientWidth<=1)||(ClientHeight<=1)){
- ClientWidth=400;
- ClientHeight=400;
- RatioViewPort=1.0;
- }
- else RatioViewPort= (float)ClientWidth/(float)ClientHeight;
-
- glViewport(0,0,ClientWidth,ClientHeight);
-
- // se actualiza el volumen de vista
- // para que su radio coincida con ratioViewPort
- if (scene->getYTop() == 0) scene->setYTop(1);
- GLfloat RatioVolVista=scene->getXRight()/scene->getYTop();
-
- if (RatioVolVista>=RatioViewPort) {
- //Aumentamos yTop-yBot
- scene->setYTop(scene->getXRight()/RatioViewPort);
- scene->setYBot(-scene->getYTop());
- } else {
- //Aumentamos xRight-xLeft
- scene->setXRight(RatioViewPort*scene->getYTop());
- scene->setXLeft(-scene->getXRight());
- }
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- gluOrtho2D(scene->getXLeft() + traslX,
- scene->getXRight() + traslX,
- scene->getYBot() + traslY,
- scene->getYTop() + traslY);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- GLScene();
-
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TGLForm2D::GLScene()
- {
- if (running) {
- if (divisions<1) divisions=1;
- glClear(GL_COLOR_BUFFER_BIT);
-
- // draw scene
- for (int i=0; i<scene->getNumberOfLines(); i++) {
- LineDrawing *ld = scene->getLineDrawing(i);
- glBegin(GL_LINES);
- ld->savePosition();
- ld->iniciar();
- glColor3f(1.0f, 1.0f, 1.0f);
- for (int j=0; j<ld->getNumberOfPoints(); j++) {
- if (ld==selectedld) {
- glColor3f(1.0f, 0.0f, 0.0f);
- }
- glVertex3f(ld->getPoint1().getX(), ld->getPoint1().getY(), 1.0f);
- glVertex3f(ld->getPoint2().getX(), ld->getPoint2().getY(), 1.0f);
- ld->avanzar();
- }
- glEnd();
- ld->iniciar();
- glPointSize(3.0f);
- glBegin(GL_POINTS);
- glVertex2f(ld->getPoint1().getX(), ld->getPoint1().getY());
- glEnd();
- for (int j=0; j<ld->getNumberOfPoints(); j++) {
- if ((ld==hoveredld ||ld==selectedld) && option == seleccionar) {
- glPointSize(5.0f);
- glColor3f(1.0f, 0.0f, 0.0f);
- }
- else
-
- glColor3f(0.0f, 0.0f, 1.0f);
- glBegin(GL_POINTS);
- glPointSize(3.0f);
- glVertex2f(ld->getPoint2().getX(), ld->getPoint2().getY());
- ld->avanzar();
- glEnd();
- }
- ld->restorePosition();
-
- }
-
- // si estoy pintando el rectángulo del algoritmo de recorte, pintarlo
- if (option == recortar2) {
- glColor3f(0.0f, 1.0f, 1.0f);
- glBegin(GL_LINES);
- glVertex2f(pointInit.getX(), pointInit.getY());
- glVertex2f(pointMouse.getX(), pointInit.getY());
-
- glVertex2f(pointMouse.getX(), pointInit.getY());
- glVertex2f(pointMouse.getX(), pointMouse.getY());
-
- glVertex2f(pointMouse.getX(), pointMouse.getY());
- glVertex2f(pointInit.getX(), pointMouse.getY());
-
- glVertex2f(pointInit.getX(), pointMouse.getY());
- glVertex2f(pointInit.getX(), pointInit.getY());
- glEnd();
- }
- glFlush();
- SwapBuffers(hdc);
- }
- }
-
-
-
- //---------------------------------------------------------------------------
- void __fastcall TGLForm2D::FormPaint(TObject *Sender)
- {
- GLScene();
- }
- //---------------------------------------------------------------------------
- void TGLForm2D::drawSceneCenter() {
- glPointSize(3.0f);
- glBegin(GL_POINTS);
- glColor3f(1.0f, 1.0f, 0);
- glVertex2i(traslX,traslY);
- glEnd();
- }
-
- void __fastcall TGLForm2D::FormDestroy(TObject *Sender)
- {
- ReleaseDC(Handle,hdc);
- wglMakeCurrent(NULL, NULL);
- wglDeleteContext(hrc);
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::FormKeyDown(TObject *Sender, WORD &Key,
- TShiftState Shift)
- {
- key = Key;
- //Key up
- if ( key==37 ) {
- traslX++;
- } else if ( key==38 ) {
- traslY--;
- } else if ( key==39 ) {
- traslX--;
- } else if ( key==40 ) {
- traslY++;
- } else if ( key==46 ){
- scene->elimina(selectedld);
- }
- Resize();
- }
- //---------------------------------------------------------------------------
- void __fastcall TGLForm2D::Dep1Click(TObject *Sender)
- {
- formDebug->Visible = !formDebug->Visible;
- }
- //---------------------------------------------------------------------------
-
-
- void __fastcall TGLForm2D::RedrawTimerTimer(TObject *Sender)
- {
- //if (running) {
- // Key -
- if (key==109) {
- if (zoomVel<maxZoomVel) zoomVel++;
- }
- // Key +
- else if (key==107) {
- if (zoomVel>-maxZoomVel) zoomVel--;
- }
- // Key up
- else if (key==38) {
- if (maxVel>yVel) yVel++;
- }
- // Key down
- else if (key==40) {
- if (maxVel>-yVel) yVel--;
- }
- // Key left
- else if (key==37) {
- if (maxVel>-xVel) xVel--;
- }
- // Key right
- else if (key==39) {
- if (maxVel>xVel) xVel++;
- }
-
- if (scene!=NULL) {
- // Modificar límites de la parte visible de la escena
- // Límite para que la imagen no se invierta
- // (xRight debe ser siempre positivo, y mejor
- // si no llega 0, porque pasan cosas raras)
- float xRight = scene->getXRight();
- if (xRight+zoomVel>10) {
- traslY+=yVel;
- traslX+=xVel;
- float ratio = scene->getRatio();
- xRight = xRight+zoomVel;
- scene->setXRight(xRight);
- scene->setXLeft(-xRight);
- scene->setYTop(xRight/ratio);
- scene->setYBot(-scene->getYTop());
- // Modificar matriz de proyeccion
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(scene->getXLeft() + traslX,
- scene->getXRight() + traslX,
- scene->getYBot() + traslY,
- scene->getYTop() + traslY);
-
- // Dibujar
- GLScene();
-
- } }
- // }
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::FormKeyUp(TObject *Sender, WORD &Key,
- TShiftState Shift)
- {
- key = 0;
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::BrakeTimerTimer(TObject *Sender)
- {
- if (key!=107 && key!=109) {
- // Reset zoomVel
- if (zoomVel>0) zoomVel--;
- else if (zoomVel<0) zoomVel++;
- }
- if (key!=38 && key!=40) {
- // Reset yVel
- if (yVel>0) yVel--;
- else if (yVel<0) yVel++;
- }
- if (key!=37 && key!=49) {
- // Reset xVel
- if (xVel>0) xVel--;
- else if (xVel<0) xVel++;
- }
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::Paleta1Click(TObject *Sender)
- {
- formPaleta->Visible = !formPaleta->Visible; Resize();
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::FormMouseDown(TObject *Sender,
- TMouseButton Button, TShiftState Shift, int X, int Y)
- {
- // Get clicked point
- float width = scene->getXRight() - scene->getXLeft();
- float ratio = width/ClientWidth;
- float x = (X - ClientWidth/2) * ratio + traslX; // horizontal
- float y = (ClientHeight/2 - Y) * ratio + traslY; // vertical
-
- switch (option) {
- case (spiral): {
- drawSpiral(50,0,10,1,5,*new GLPoint(x,y));
- break;
- }
- case (polygon): {
- drawPolygon(StrToInt(formPaleta->editLados->Text),100,*new GLPoint(x,y));
- break;
- }
- case (startPolilines): {
- scene->startNewDrawing(*new GLPoint(x,y));
- option = polilines;
- break;
- }
- case (polilines): {
- Pen p = *new Pen(scene);
- p.moveTo(x,y,true);
- break;
- }
- case (seleccionar) : {
- selectedld = scene->getLineDrawing(*new GLPoint(x,y), 5*ratio);
- break;
- }
- case (recortar1) :
- {
- pointInit = *new GLPoint(pointMouse.getX(),pointMouse.getY());
- option = recortar2;
- break;
- }
- case (recortar2) : {
- for (int i=0; i<scene->getNumberOfLines(); i++) {
- LineDrawing *ld = scene->getLineDrawing(i);
- glBegin(GL_LINES);
- ld->iniciar();
- glColor3f(1.0f, 1.0f, 1.0f);
- for (int j=0; j<ld->getNumberOfPoints(); j++) {
- if (scene->getNumberOfLines()>0) {
- GLPoint a = *new GLPoint(ld->getPoint1().getX(), ld->getPoint1().getY());
- GLPoint b = *new GLPoint(ld->getPoint2().getX(), ld->getPoint2().getY());
- if (recortar(a,b)) {
- ld->setPoint1(a);
- ld->setPoint2(b);
- ld->avanzar();
- } else {
- ld->deleteSegment();
- j--;
- // Si el dibujo queda vacio, borrarlo
- if (ld->getNumberOfPoints()==0)
- scene->deleteLineDrawing();
- }
- }
- }
- }
- option = unSelected;
- break;
- }
- case (koch1) :
- {
- pointInit = *new GLPoint(pointMouse.getX(),pointMouse.getY());
- option = recortar2;
- break;
- }
- case (koch2) :
- {
- pointInit = *new GLPoint(pointMouse.getX(),pointMouse.getY());
- option = recortar2;
- break;
- }
- case (dragon) :
- {
- pointInit = *new GLPoint(pointMouse.getX(),pointMouse.getY());
- option = recortar2;
- break;
- }
- }
- }
- //---------------------------------------------------------------------------
-
-
-
- void __fastcall TGLForm2D::FormMouseMove(TObject *Sender,
- TShiftState Shift, int X, int Y)
- {
- float width = scene->getXRight() - scene->getXLeft();
- float ratio = width/ClientWidth;
- float x = (X - ClientWidth/2) * ratio + traslX; // horizontal
- float y = (ClientHeight/2 - Y) * ratio + traslY; // vertical
-
- pointMouse = *new GLPoint(x,y);
- hoveredld = scene->getLineDrawing(*new GLPoint(x,y), 5*ratio);
-
-
- }
- //---------------------------------------------------------------------------
-
- void TGLForm2D::drawPolygon(int sides, float radius, GLPoint center) {
- Pen *p = new Pen(scene);
- // Start to the right and turn left
- GLPoint origin = *new GLPoint(center.getX() + radius, center.getY());
- p->moveTo(origin, false);
- float alpha = 2*M_PI/sides;
- float beta = (M_PI-alpha);
- float side = 2*cos(beta/2)*radius;
- p->turn(M_PI-beta/2);
- scene->startNewDrawing(p->getPosition());
- for (int i=0; i<sides-1; i++) {
- p->move(side, true);
- p->turn(M_PI-beta);
- }
- p->moveTo(origin, true);
- delete p;
- };
-
- void TGLForm2D::drawSpiral(int sides, float direction, float side, float dir_inc, float side_inc, GLPoint start) {
- Pen *p = new Pen(scene, start, direction);
- scene->startNewDrawing(start);
- for (int i=0; i<sides; i++) {
- p->move(side, true);
- p->turn(dir_inc);
- side += side_inc;
- }
-
-
- delete p;
- };
-
- void __fastcall TGLForm2D::Lneas1Click(TObject *Sender)
- {
- option = startPolilines;
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::Polgono1Click(TObject *Sender)
- {
- option = polygon;
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::Espiral1Click(TObject *Sender)
- {
- option = spiral;
- }
- //---------------------------------------------------------------------------
-
-
-
-
- void __fastcall TGLForm2D::zoomMasClick(TObject *Sender)
- {
- if (zoomVel>-maxZoomVel) zoomVel-=5;
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::zoomMinusClick(TObject *Sender)
- {
- if (zoomVel<maxZoomVel) zoomVel+=5;
- }
- //---------------------------------------------------------------------------
-
-
- void __fastcall TGLForm2D::Button1Click(TObject *Sender)
- {
- if (maxVel>yVel) yVel+=5;
- }
- //---------------------------------------------------------------------------
-
-
- void __fastcall TGLForm2D::Button3Click(TObject *Sender)
- {
- if (maxVel>-yVel) yVel-=5;
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::Button2Click(TObject *Sender)
- {
- if (maxVel>-xVel) xVel-=5;
- }
- //---------------------------------------------------------------------------
-
-
- void __fastcall TGLForm2D::Button4Click(TObject *Sender)
- {
- if (maxVel>-xVel) xVel+=5;
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::Nuevo1Click(TObject *Sender)
- {
- running = false;
- delete scene;
- scene = new Scene();
- scene->setLimits(-300,300,300,-300);
- RatioViewPort = 1.0;
- SetPixelFormatDescriptor();
- traslX = traslY = 0;
- zoomVel = 0;
- maxZoomVel = 200;
- xVel = 0;
- yVel = 0;
- pointInit.setX(0);
- pointInit.setY(0);
-
- option = unSelected;
- Resize();
- running = true;
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::Cortar1Click(TObject *Sender)
- {
- option = recortar1;
-
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::Seleccionar1Click(TObject *Sender)
- {
- this->option = seleccionar;
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::Borrar1Click(TObject *Sender)
- {
- scene->elimina(selectedld);
- GLScene();
- }
- //---------------------------------------------------------------------------
-
-
- int TGLForm2D::recortar(GLPoint &a, GLPoint &b) {
-
- /*
- Tras ejecutar la función, las coordenadas se convierten en los puntos
- resultantes del recorte.
- Si la linea está fuera del recorte, la función devuelve FALSE;
- x1, y1: Coordenada de inicio
- x2, y2: Coordenada de fin
- */
-
- #define CLIPLEFT 1 // Binario 0001
- #define CLIPRIGHT 2 // 0010
- #define CLIPLOWER 4 // 0100
- #define CLIPUPPER 8 // 1000
- float YMin, YMax, XMin, XMax;
-
- if (pointInit.getY() < pointMouse.getY()) {
- YMin = pointInit.getY();
- YMax = pointMouse.getY();
- } else {
- YMax = pointInit.getY();
- YMin = pointMouse.getY();
- }
-
- if (pointInit.getX() < pointMouse.getX()) {
- XMin = pointInit.getX();
- XMax = pointMouse.getX();
- } else {
- XMax = pointInit.getX();
- XMin = pointMouse.getX();
- }
-
- /*
- Estas variables indican la posición de cada punto (izquierda, derecha, arriba y
- abajo) usando los flags declarados).
- */
- float x1,y1,x2,y2;
- x1 = a.getX();
- y1 = a.getY();
- x2 = b.getX();
- y2 = b.getY();
-
- int K1=0, K2=0;
- float dx, dy;
-
- dx = x2-x1;
- dy = y2-y1;
-
- if (y1<YMin) K1 =CLIPLOWER;
- if (y1>YMax) K1 =CLIPUPPER;
- if (x1<XMin) K1|=CLIPLEFT;
- if (x1>XMax) K1|=CLIPRIGHT;
-
- if (y2<YMin) K2 =CLIPLOWER;
- if (y2>YMax) K2 =CLIPUPPER;
- if (x2<XMin) K2|=CLIPLEFT;
- if (x2>XMax) K2|=CLIPRIGHT;
-
- while (K1 || K2) {
- if(K1 & K2)
- return FALSE;
-
- if(K1) {
- if(K1 & CLIPLEFT) {
- y1+=(XMin-x1)*dy/dx;
- x1=XMin;
- }
- else if(K1 & CLIPRIGHT) {
- y1+=(XMax-x1)*dy/dx;
- x1=XMax;
- }
- if(K1 & CLIPLOWER) {
- x1+=(YMin-y1)*dx/dy;
- y1=YMin;
- }
- else if(K1 & CLIPUPPER) {
- x1+=(YMax-y1)*dx/dy;
- y1=YMax;
- }
- K1 = 0;
-
- if(y1<YMin) K1 =CLIPLOWER;
- if(y1>YMax) K1 =CLIPUPPER;
- if(x1<XMin) K1|=CLIPLEFT;
- if(x1>XMax) K1|=CLIPRIGHT;
- }
-
- if(K1 & K2)
- return FALSE;
-
- if(K2) {
- if(K2 & CLIPLEFT) {
- y2+=(XMin-x2)*dy/dx;
- x2=XMin;
- }
- else if(K2 & CLIPRIGHT) {
- y2+=(XMax-x2)*dy/dx;
- x2=XMax;
- }
- if(K2 & CLIPLOWER) {
- x2+=(YMin-y2)*dx/dy;
- y2=YMin;
- }
- else if(K2 & CLIPUPPER) {
- x2+=(YMax-y2)*dx/dy;
- y2=YMax;
- }
- K2 = 0;
-
- if(y2<YMin) K2 =CLIPLOWER;
- if(y2>YMax) K2 =CLIPUPPER;
- if(x2<XMin) K2|=CLIPLEFT;
- if(x2>XMax) K2|=CLIPRIGHT;
- }
- }
-
- a = *new GLPoint(x1,y1);
- b = *new GLPoint(x2,y2);
- return TRUE;
- };
-
- void TGLForm2D::applyTransformation (int algorithm) {
-
- Lista<Segment>* auxSegmentList=new Lista<Segment>();
- GLPoint pointAux;
- //Para cada uno de los miembros de la escena...
-
- for (int i=0; i<scene->getNumberOfLines(); i++) {
- //Guardamos en ld la escena i...
- LineDrawing *ld = scene->getLineDrawing(i);
- //Puntero al principio...
- ld->iniciar();
- //Si es la ListDrawing que queremos...
- if (ld==selectedld) {
-
- //Para cada uno de sus puntos...
- for (int j=0; j<ld->getNumberOfPoints(); j++) {
-
- //Almacenamos la información de sus puntos para trabajar con ellos
- GLfloat ox= ld->getPoint1().getX();
- GLfloat oy= ld->getPoint1().getY();
-
- GLfloat dx= ld->getPoint2().getX();
- GLfloat dy= ld->getPoint2().getY();
-
- //Cálculo de la longitud total del segmento
- GLfloat longitud= sqrt ((dx - ox)*(dx - ox)+ (dy - oy)*(dy - oy));
- if (longitud != 0) {
- switch (algorithm) {
- case 1:
- j+=Koch1(ld,ox,oy,dx,dy,longitud);
- break;
- case 2:
- j+=Koch2(ld,ox,oy,dx,dy,longitud);
- break;
- case 3:
- j+=Dragon(ld,ox,oy,dx,dy,longitud);
- break;
- }
- } else
- ld->avanzar();
- }
- }
- }
- }
-
- int TGLForm2D::Koch1(LineDrawing *ld, float ox, float oy, float dx, float dy, float longitud) {
- GLfloat cosAlfa= (dx-ox) / longitud;
- GLfloat sinAlfa = (dy-oy) / longitud;
- GLfloat alfaRad = acos(cosAlfa);
- if (dy < oy) alfaRad = - alfaRad;
-
- GLPoint auxA = *new GLPoint(longitud/(3.0)*cosAlfa+ox, longitud/(3.0)*sinAlfa+oy );
- GLPoint auxC = *new GLPoint(longitud*(2.0/3.0)*cosAlfa+ox, longitud*(2.0/3.0)*sinAlfa+oy );
- GLPoint auxD = *new GLPoint(dx,dy );
-
- ld->setPoint2( auxA );
-
- alfaRad += 2/6*M_PI; // Sumar 60?
- float cosAlfa2 = cos(alfaRad);
- float sinAlfa2 = sin(alfaRad);
- GLPoint auxB = *new GLPoint(longitud/3.0*cosAlfa2+auxA.getX(), longitud/3.0*sinAlfa2+auxA.getY());
-
- ld->insertaDespues( new Segment(auxA, auxB) );
- ld->insertaDespues( new Segment(auxB, auxC) );
- ld->insertaDespues( new Segment(auxC, auxD) );
- ld->avanzar();
- return 3;
- }
-
- int TGLForm2D::Koch2(LineDrawing *ld, float ox, float oy, float dx, float dy, float longitud) {
- GLfloat cosAlfa= (dx-ox) / longitud;
- GLfloat sinAlfa = (dy-oy) / longitud;
- GLfloat alfaRad = acos(cosAlfa);
- if (dy < oy) alfaRad = - alfaRad;
- GLfloat beta = 90+alfaRad*180/M_PI;
- GLfloat betaRad = beta*M_PI/180;
- GLfloat cosBeta = cos(betaRad);
- GLfloat sinBeta = sin(betaRad);
-
- GLPoint auxA = *new GLPoint(longitud/4.0*cosAlfa+ox, longitud/4.0*sinAlfa+oy );
- GLPoint auxB = *new GLPoint(longitud/4.0*cosBeta+auxA.getX(), longitud/4.0*sinBeta+auxA.getY());
- GLPoint auxC = *new GLPoint(longitud/4.0*cosAlfa+auxB.getX(), longitud/4.0*sinAlfa+auxB.getY());
- GLPoint auxD = *new GLPoint(-longitud/2.0*cosBeta+auxC.getX(), -longitud/2.0*sinBeta+auxC.getY());
- GLPoint auxE = *new GLPoint(longitud/4.0*cosAlfa+auxD.getX(), longitud/4.0*sinAlfa+auxD.getY());
- GLPoint auxF = *new GLPoint(longitud/4.0*cosBeta+auxE.getX(), longitud/4.0*sinBeta+auxE.getY());
- GLPoint auxG = *new GLPoint(dx,dy);
-
-
- ld->setPoint2( auxA );
-
- ld->insertaDespues( new Segment(auxA, auxB) );
- ld->insertaDespues( new Segment(auxB, auxC) );
- ld->insertaDespues( new Segment(auxC, auxD) );
- ld->insertaDespues( new Segment(auxD, auxE) );
- ld->insertaDespues( new Segment(auxE, auxF) );
- ld->insertaDespues( new Segment(auxF, auxG) );
-
- ld->avanzar();
- return 6;
- }
-
- int TGLForm2D::Dragon(LineDrawing *ld, float ox, float oy, float dx, float dy, float longitud) {
- GLfloat cosAlfa= (dx-ox) / longitud;
- GLfloat alfaRad = acos(cosAlfa);
- if (dy < oy) alfaRad = - alfaRad;
- alfaRad += M_PI/4; // Sumar 45?;
-
- float cosAlfa2 = cos(alfaRad);
- float sinAlfa2 = sin(alfaRad);
-
- float longLado = longitud/(2*cos(M_PI/4));
-
- GLPoint auxA = *new GLPoint(longLado*cosAlfa2+ox, longLado*sinAlfa2+oy );
- ld->setPoint2( auxA );
-
- GLPoint auxB = *new GLPoint(dx,dy);
-
- ld->insertaDespues( new Segment(auxA, auxB) );
- ld->avanzar();
- return 1;
- }
-
-
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::FormClose(TObject *Sender, TCloseAction &Action)
- {
- running = false;
- delete scene;
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::Koch11Click(TObject *Sender)
- {
- if ( option == seleccionar )
- applyTransformation(1);
- }
-
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::Koch21Click(TObject *Sender)
- {
- if ( option == seleccionar )
- applyTransformation(2);
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TGLForm2D::Dragn1Click(TObject *Sender)
- {
- if ( option == seleccionar )
- applyTransformation(3);
- }
- //---------------------------------------------------------------------------