archivage initial
This commit is contained in:
69
cylinder.h
Normal file
69
cylinder.h
Normal file
@ -0,0 +1,69 @@
|
||||
#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
|
Reference in New Issue
Block a user