-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawer.h
47 lines (35 loc) · 967 Bytes
/
drawer.h
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
#ifndef DRAWER_H
#define DRAWER_H
#include <vector>
#include "scenegraph.h"
#include "asstcommon.h"
class Drawer : public SgNodeVisitor {
protected:
std::vector<RigTForm> rbtStack_;
const ShaderState& curSS_;
public:
Drawer(const RigTForm& initialRbt, const ShaderState& curSS)
: rbtStack_(1, initialRbt)
, curSS_(curSS) {}
virtual bool visit(SgTransformNode& node) {
rbtStack_.push_back(rbtStack_.back() * node.getRbt());
return true;
}
virtual bool postVisit(SgTransformNode& node) {
rbtStack_.pop_back();
return true;
}
virtual bool visit(SgShapeNode& shapeNode) {
const Matrix4 MVM = rigTFormToMatrix(rbtStack_.back()) * shapeNode.getAffineMatrix();
sendModelViewNormalMatrix(curSS_, MVM, normalMatrix(MVM));
shapeNode.draw(curSS_);
return true;
}
virtual bool postVisit(SgShapeNode& shapeNode) {
return true;
}
const ShaderState& getCurSS() const {
return curSS_;
}
};
#endif