#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#include "glig.h"
#define PI 3.1415926535897932
#define ALFA (0.5-v)*PI
#define BETA 2*PI*u
float
xSuperQuadric (
float
u,
float
v,
float
R,
float
s1,
float
s2)
{
float
cosalfa, cosbeta, powcosalfa, powcosbeta;
cosalfa = (
float
)
cos
(ALFA);
cosbeta = (
float
)
cos
(BETA);
if
(cosalfa > 0.0)
powcosalfa = (
float
)
pow
(cosalfa,s1);
else
powcosalfa =(
float
) -
pow
(- cosalfa,s1);
if
(cosbeta > 0.0)
powcosbeta = (
float
)
pow
(cosbeta,s2);
else
powcosbeta = (
float
) -
pow
(- cosbeta,s2);
return
(R*powcosalfa*powcosbeta);
}
float
ySuperQuadric (
float
u,
float
v,
float
R,
float
s1,
float
s2)
{
float
sinalfa, powsinalfa;
sinalfa = (
float
)
sin
(ALFA);
if
(sinalfa > 0.0)
powsinalfa = (
float
)
pow
(sinalfa,s1);
else
powsinalfa = (
float
)-
pow
(- sinalfa,s1);
return
(R*powsinalfa);
}
float
zSuperQuadric(
float
u,
float
v,
float
R,
float
s1,
float
s2)
{
float
cosalfa, sinbeta, powcosalfa, powsinbeta;
cosalfa = (
float
)
cos
(ALFA);
sinbeta=(
float
)
sin
(BETA);
if
(cosalfa > 0.0)
powcosalfa = (
float
)
pow
(cosalfa,s1);
else
powcosalfa=(
float
) -
pow
(- cosalfa,s1);
if
(sinbeta > 0.0)
powsinbeta = (
float
)
pow
(sinbeta,s2);
else
powsinbeta = (
float
) -
pow
(- sinbeta,s2);
return
(R*powcosalfa*powsinbeta);
}
void
igCreateQuadricObject (
int
pu,
int
pv,
float
uMax,
float
vMax,
float
R,
float
s1,
float
s2)
{
float
u, v;
float
iniu,iniv;
float
inc_u;
float
inc_v;
float
x, y, z;
int
i,j;
v= uMax;
u =vMax;
iniu=u;
iniv=v;
inc_u= (1.0f-u)/pu;
inc_v= (1.0f-v)/pv;
for
(j=0;j<pv;j++)
{
glBegin (GL_LINE_LOOP);
for
(i= 0; i<= pu; i++)
{
x= xSuperQuadric (u, v, R, s1, s2);
y= ySuperQuadric (u, v, R, s1, s2);
z= zSuperQuadric (u, v, R, s1, s2);
glVertex3f (x, y, z);
u= u+ inc_u;
if
(u>1){u=iniu;}
}
glEnd();
v+=inc_v;
}
u=iniu;
v=iniv;
for
(j=0;j<pu;j++)
{
glBegin(GL_LINE_STRIP);
v=iniv;
for
(i=0;i<=pv;i++)
{
x= xSuperQuadric (u, v, R, s1, s2);
y= ySuperQuadric (u, v, R, s1, s2);
z= zSuperQuadric (u, v, R, s1, s2);
glVertex3f (x, y, z);
v+=inc_v;
}
glEnd();
u+=inc_u;
}
}
void
igWireSphere (
int
pu,
int
pv)
{
igCreateQuadricObject(pu,pv,0,0,1.0, 1, 1);
}
void
igWireRulo (
int
pu,
int
pv)
{
igCreateQuadricObject(pu,pv,0,0,1.0, 0.5, 1);
}
void
igWireDado (
int
pu,
int
pv)
{
igCreateQuadricObject(pu,pv,0,0,1.0, 0.5, 0.5);
}
void
igWireSemiSphere (
int
pu,
int
pv)
{
igCreateQuadricObject(pu,pv,0,0.5,1.0, 1, 1);
}
void
igWireCubo (
void
)
{
glBegin (GL_LINE_LOOP);
glVertex3f(-0.5,-0.5,-0.5);
glVertex3f(0.5, -0.5, -0.5);
glVertex3f(0.5,0.5,-0.5);
glVertex3f(-0.5,0.5,-0.5);
glVertex3f(-0.5,-0.5,-0.5);
glVertex3f(-0.5,-0.5,0.5);
glVertex3f(-0.5,0.5,0.5);
glVertex3f(0.5,0.5,0.5);
glVertex3f(0.5,-0.5,0.5);
glVertex3f(-0.5,-0.5,0.5);
glVertex3f(-0.5,-0.5,-0.5);
glVertex3f(-0.5,-0.5,0.5);
glVertex3f(-0.5,0.5,0.5);
glVertex3f(-0.5,0.5,-0.5);
glVertex3f(0.5,0.5,-0.5);
glVertex3f(0.5,0.5,0.5);
glVertex3f(0.5,-0.5,0.5);
glVertex3f(0.5,-0.5,-0.5);
glEnd ();
}
void
igWireCone (
int
pu,
int
pv)
{
igCreateQuadricObject(pu, pv, 0.5, 0, 1, 2.0, 1.0);
}
void
CreaAbetoPush(
void
)
{
if
(abetoPush != 0)
{
glNewList( abetoPush, GL_COMPILE);
glColor3f(1,0,0);
glPushMatrix();
glRotated(180,0,0,1);
glScalef(0.75, 1, 0.75);
igWireCone(20, 20);
glPopMatrix();
glPushMatrix();
glTranslatef(0,0.25, 0);
glRotated(180,0,0,1);
glScalef(0.75, 1, 0.75);
glScalef(0.75, 1, 0.75);
igWireCone(20, 20);
glPopMatrix();
glPushMatrix();
glTranslatef(0, 0.5, 0);
glRotated(180,0,0,1);
glScalef(0.75, 1, 0.75);
glScalef(0.75, 1, 0.75);
glScalef(0.75, 1, 0.75);
igWireCone(20, 20);
glPopMatrix();
glPushMatrix();
glRotated(180,0,0,1);
glScalef(0.75, 1, 0.75);
glScalef(0.75, 1, 0.75);
glScalef(0.75, 1, 0.75);
glScalef(0.5, 1, 0.5);
igWireRulo(15, 5);
glPopMatrix();
glEndList();
}
else
{
printf
("Error al crear abetoPush\n");
}
}
void
CreaAbeto (
void
)
{
if
(abeto != 0)
{
glNewList (abeto, GL_COMPILE);
glColor3f(0,1,0);
glRotated(180,0,0,1);
glScalef(0.75,1,0.75);
igWireCone(20, 20);
glScalef(0.75,1,0.75);
glTranslatef(0,-0.25,0);
igWireCone(20, 20);
glScalef(0.75,1,0.75);
glTranslatef(0,-0.25,0);
igWireCone(20, 20);
glTranslatef(0, 0.5, 0);
glScalef(0.5, 1, 0.5);
igWireRulo(15, 5);
glEndList ();
}
}
void
CreaEscalera(
void
)
{
int
x;
glNewList(escalera, GL_COMPILE);
printf
("mierda\n");
escalon();
for
(x=0;x<100;x++)
{
glPushMatrix();
glRotated(90,1,0,0);
glScalef(0.5, 0.5, 0.1);
glTranslatef(0, 0,-x*(0.2));
glRotated((360/50)*x,0,0,1);
escalon();
glPopMatrix();
}
glEndList();
}
void
escalon(
void
)
{
glBegin (GL_LINE_LOOP);
glVertex3f(-0.1,0,-0.1);
glVertex3f(0.1,0,-0.1);
glVertex3f(0.1,0,0.1);
glVertex3f(-0.1,0,0.1);
glVertex3f(-0.1,0,-0.1);
glVertex3f(-0.1,2,-0.1);
glVertex3f(0.1,2,-0.1);
glVertex3f(0.1,0,-0.1);
glVertex3f(0.1,2,-0.1);
glVertex3f(0.1,2,0.1);
glVertex3f(0.1,0,0.1);
glVertex3f(0.1,2,0.1);
glVertex3f(-0.1,2,0.1);
glVertex3f(-0.1,0,0.1);
glVertex3f(-0.1,2,0.1);
glVertex3f(-0.1,2,-0.1);
glEnd();
}
void
CreaPatio(
void
)
{
int
x;
glNewList( patio , GL_COMPILE);
for
(x=0;x<12;x++)
{
glPushMatrix();
glScalef(0.2, 0.2, 0.2);
glRotated(30*x, 0, 1, 0);
glTranslatef(0, 0, -4);
arco();
glPopMatrix();
}
glEndList();
}
void
arco(
void
)
{
glPushMatrix();
glTranslatef(-0.75, 0, 0);
columna();
glPopMatrix();
glPushMatrix();
glTranslatef(0.75, 0, 0);
columna();
glPopMatrix();
glPushMatrix();
glRotated(270, 0, 0, 1);
glTranslatef(-1.75, -1, 0);
columna();
glPopMatrix();
}
void
columna(
void
)
{
glBegin (GL_LINE_LOOP);
glVertex3f(-0.25,0,-0.25);
glVertex3f(0.25,0,-0.25);
glVertex3f(0.25,0,0.25);
glVertex3f(-0.25,0,0.25);
glVertex3f(-0.25,0,-0.25);
glVertex3f(-0.25,2,-0.25);
glVertex3f(0.25,2,-0.25);
glVertex3f(0.25,0,-0.25);
glVertex3f(0.25,2,-0.25);
glVertex3f(0.25,2,0.25);
glVertex3f(0.25,0,0.25);
glVertex3f(0.25,2,0.25);
glVertex3f(-0.25,2,0.25);
glVertex3f(-0.25,0,0.25);
glVertex3f(-0.25,2,0.25);
glVertex3f(-0.25,2,-0.25);
glEnd();
}