This repository has been archived on 2020-03-08. You can view files and clone it, but cannot push or open issues or pull requests.
pg-tp3/cylinder.h

70 lines
1001 B
C++

#ifndef CYLINDER_HPP
#define CYLINDER_HPP
#include <GL/glu.h>
#include <math.h>
#include <array>
#include <QOpenGLFunctions>
struct Color
{
float r;
float g;
float b;
Color(float r, float g, float b) :r(r), g(g), b(b) {};
};
struct VertexBuf
{
size_t i = 0;
size_t size;
GLfloat *vertices;
GLfloat *colors;
VertexBuf(size_t i)
:size(i*3),
vertices(new GLfloat[size]),
colors(new GLfloat[size]) {}
void push(GLfloat x, GLfloat y, GLfloat z, Color &c);
};
struct Cylinder
{
float ep;
float r;
unsigned nb_fac;
Color c;
float angle;
size_t face_size;
size_t side_size;
VertexBuf vb;
Cylinder(float ep, float r, unsigned nb_fac, Color c)
:ep(ep),
r(r),
nb_fac(nb_fac),
c(c),
angle(2*M_PI/nb_fac),
face_size(nb_fac*3),
side_size((nb_fac+1) * 2),
vb(2 * face_size + side_size)
{
build_faces();
build_side();
}
void build_face(float z);
void build_faces();
void build_side();
void draw(QOpenGLFunctions &f, int pos, int col);
};
#endif