92 lines
2.7 KiB
C++
92 lines
2.7 KiB
C++
#include "scene.h"
|
|
#include <GL/glu.h>
|
|
#include <stack>
|
|
|
|
using namespace std;
|
|
|
|
|
|
Scene::Scene()
|
|
:volant(.2, .55, 8, Color(.522, .816, 1)),
|
|
axe_volant(.6, .06, 6, Color(.522*.5, .816*.5, 1.5)),
|
|
manivelle(.2, .115, 8, Color(.078, .718, .078)),
|
|
axe_manivelle(.35, .06, 6, Color(.078*.5, .718*.5, .078*.5)),
|
|
bague_bielle(.2, .14, 8, Color(.078, .718, .078)),
|
|
bague_piston(.2, .115, 8, Color(.69, .11, .69)),
|
|
axe_bielle_piston(.36, .06, 6, Color(.69*.5, .11*.5, .69*.5)),
|
|
bielle(1.5, .05, 6, Color(.173, .824, .173)),
|
|
piston(1.1, .065, 6, Color(.847, .318, .847)),
|
|
cylindre(1.2, .15, 8, Color(.702, .424, .286)) {}
|
|
|
|
|
|
void Scene::draw(QOpenGLFunctions &f, QOpenGLShaderProgram *prog, int mat_uni,
|
|
float alpha, QMatrix4x4 &matrix, int pos, int col)
|
|
{
|
|
float gh = .45;
|
|
float xh = gh*cos(alpha);
|
|
float yh = gh*sin(alpha);
|
|
|
|
QMatrix4x4 m, m2;
|
|
|
|
/* Volant */
|
|
m = matrix;
|
|
matrix.rotate(alpha*360/(2*M_PI), 0, 0, 1);
|
|
prog->setUniformValue(mat_uni, matrix);
|
|
volant.draw(f, pos, col);
|
|
m2 = matrix;
|
|
matrix.translate(0, 0, -axe_volant.ep/2 + .125);
|
|
prog->setUniformValue(mat_uni, matrix);
|
|
axe_volant.draw(f, pos, col);
|
|
matrix = m2;
|
|
matrix.translate(gh, 0, axe_manivelle.ep/2);
|
|
prog->setUniformValue(mat_uni, matrix);
|
|
axe_manivelle.draw(f, pos, col);
|
|
matrix = m;
|
|
|
|
/* Manivelle */
|
|
m = matrix;
|
|
matrix.translate(xh, yh, volant.ep/2+manivelle.ep/2);
|
|
prog->setUniformValue(mat_uni, matrix);
|
|
manivelle.draw(f, pos, col);
|
|
matrix = m;
|
|
|
|
float hj = bielle.ep;
|
|
float xj = xh - sqrtf(hj*hj - powf(gh*sin(alpha), 2));
|
|
float b = atanf(yh / (xj-xh < 0 ? xj-xh : -xj+xh));
|
|
m = matrix;
|
|
matrix.translate(xj, 0, volant.ep/2+manivelle.ep/2);
|
|
prog->setUniformValue(mat_uni, matrix);
|
|
bague_bielle.draw(f, pos, col);
|
|
/* Bielle */
|
|
m2 = matrix;
|
|
matrix.rotate(90, 0, 1, 0);
|
|
matrix.rotate(b*360/(2*M_PI), 1, 0, 0);
|
|
matrix.translate(0, 0, bielle.ep/2);
|
|
prog->setUniformValue(mat_uni, matrix);
|
|
bielle.draw(f, pos, col);
|
|
matrix = m2;
|
|
/* Piston */
|
|
m2 = matrix;
|
|
matrix.translate(0, 0, axe_bielle_piston.ep/2);
|
|
prog->setUniformValue(mat_uni, matrix);
|
|
axe_bielle_piston.draw(f, pos, col);
|
|
matrix.translate(0, 0, axe_bielle_piston.ep/2 - .15);
|
|
prog->setUniformValue(mat_uni, matrix);
|
|
bague_piston.draw(f, pos, col);
|
|
matrix.rotate(90, 0, 1, 0);
|
|
matrix.translate(0, 0, -piston.ep/2);
|
|
prog->setUniformValue(mat_uni, matrix);
|
|
piston.draw(f, pos, col);
|
|
matrix = m2;
|
|
matrix = m;
|
|
|
|
/* Cylindre */
|
|
m = matrix;
|
|
matrix.translate(-gh-bielle.ep - piston.ep + .3, 0, volant.ep/2
|
|
+ bague_bielle.ep
|
|
+ bague_piston.ep/2);
|
|
matrix.rotate(90, 0, 1, 0);
|
|
prog->setUniformValue(mat_uni, matrix);
|
|
cylindre.draw(f, pos, col);
|
|
matrix = m;
|
|
}
|