GLUT Shapes Demo
Enviado por painnagato • 23 de Junio de 2014 • Examen • 737 Palabras (3 Páginas) • 400 Visitas
/*
* GLUT Shapes Demo
*
* Written by Nigel Stewart November 2003
*
* This program is test harness for the sphere, cone
* and torus shapes in GLUT.
*
* Spinning wireframe and smooth shaded shapes are
* displayed until the ESC or q key is pressed. The
* number of geometry stacks and slices can be adjusted
* using the + and - keys.
*/
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#define pantx 0.015625f
#define panty 0.020834f
#include <Math.h>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
int ind=-1;
static int slices = 16;
static int stacks = 16;
int w=640, h=480;
int ncontrol=0;
int npts=0;
char* men="Punto: Activo. Puedes arrastrar los puntos";
float controles[100][3];/*={
{ -4.0, -4.0, 0.0},
{ -2.0, 4.0, 0.0},
{2.0, -4.0, 0.0}, {4.0, 4.0, 0.0}, {-4.0, 4.0, 0.0}};
*/
float mat[4][4] = { {-1,3,-3,1},
{ 3,-6,3,0},
{ -3,0,3,0},
{ 1,4,1,0}
};
float x=0, y=0;
bool act=true, mos=false;
float CalcularPuntos(float u){
float sum;
float sx=0, sy=0;
for(int j=0; j<npts-3;j++){
for(int i=0; i<4;i++){
sum=mat[0][i]*pow(u,3)+mat[1][i]*pow(u,2)+mat[2][i]*u+mat[3][i];
sx+=sum*controles[i+j][0];
sy+=sum*controles[i+j][1];
}
x=sx/6;
y=sy/6;}
}
void BSpline(){
glBegin(GL_LINE_STRIP);
float u;
for(u=0; u<=1;u+=0.01){
CalcularPuntos(u);
glVertex2f(x,y);
}
glEnd();
}
void dibujarControles(){
glPointSize(4.0);
glBegin(GL_POINTS);
for(int i=0; i<ncontrol;i++)
glVertex2f(controles[i][0],controles[i][1]);
glEnd();
glPointSize(1.0);
}
static void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5.0,5.0,-5.0,5.0,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
static void display(void)
{
...