forked from chrisyeshi/VolRen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raycastcube.cpp
59 lines (45 loc) · 1.08 KB
/
raycastcube.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "raycastcube.h"
#include <cassert>
#include "shape.h"
namespace yy {
namespace volren {
RaycastCube::RaycastCube()
: width(1), height(1), depth(1)
{
}
RaycastCube::~RaycastCube()
{
}
void RaycastCube::initializeGL()
{
painter.initializeGL(yy::Shape::cube(), ":/volren/shaders/raycastcube.vert", ":/volren/shaders/raycastcube.frag");
}
void RaycastCube::setSize(int w, int h, int d)
{
width = w;
height = h;
depth = d;
}
void RaycastCube::render(const QMatrix4x4& vp, GLenum face)
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(face);
glEnable(GL_DEPTH_TEST);
painter.paint("mvp", vp * matrix(),
"volDim", QVector3D(width, height, depth));
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
}
const QMatrix4x4 &RaycastCube::matrix()
{
static QMatrix4x4 mat;
mat.setToIdentity();
// mat.translate(0.5f, 0.5f, 0.5f);
// mat.scale(width - 1, height - 1, depth - 1);
mat.scale(width, height, depth);
return mat;
}
} // namespace volren
} // namespace yy