Vous êtes sur la page 1sur 4

Carrasco Domínguez Yazmín

Computación Gráfica
/**Código C Algoritmo Cyrus-Beck****/

#include <windows.h>
#include <gl/Gl.h>
#include <gl/glut.h>

struct GLintPoint
{ GLint x,y;
};

struct GLfloatPoint
{ GLfloat x,y;
};

void RecorteCB (GLfloatPoint p1, GLfloatPoint p2, Normals n,


GLfloatPointArray p,bool & visible, GLfloatPoint & rp, GLfloatPoint & q)

float t1,t2,t,numer,den;
GLfloatPoint dirV,F; // vectores
int i;

t1 = 0.0;
t2 = 1.0;
// calcula la dirección del vector
dirV.x = p2.x - p1.x;
dirV.y = p2.y - p1.y;

visible = true;
i = 0;
while ( (i < p.num) && visible)
{ F.x = p1.x - p.pt[i].x;
F.y = p1.y - p.pt[i].y;
numer = DotProduct (n[i],F);
den = DotProduct (n[i],dirV);

if (den == 0.0)
{
if (numer > 0.0)
visible = false;
}
else
{ t = -(numer/den);
if (den < 0.0) // entrada
{ if (t <= 1.0)
if (t > t1)
t1 = t;
}
else if ( t >= 0.0) //salida
{ if (t < t2)
t2 = t;
}
}
i++;
}
if ( t1 <= t2)
{ rp.x = p1.x + t1*dirV.x;
rp.y = p1.y + t1*dirV.y;
q.x = p1.x + t2*dirV.x;
q.y = p1.y + t2*dirV.y;
}
else
visible = false;
}

void main(int argc, char** argv)


{
.

Vous aimerez peut-être aussi