forked from bobsayshilol/engine-sim
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpiston_object.cpp
More file actions
59 lines (47 loc) · 1.76 KB
/
piston_object.cpp
File metadata and controls
59 lines (47 loc) · 1.76 KB
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
58
59
#include "../include/piston_object.h"
#include "../include/cylinder_bank.h"
#include "../include/engine_sim_application.h"
PistonObject::PistonObject() {
m_piston = nullptr;
m_wristPinHole = {};
}
PistonObject::~PistonObject() {
/* void */
}
void PistonObject::generateGeometry() {
GeometryGenerator *gen = m_app->getGeometryGenerator();
GeometryGenerator::Circle2dParameters circleParams;
circleParams.center_x = 0.0f;
circleParams.center_y = (float)m_piston->getWristPinLocation();
circleParams.maxEdgeLength = m_app->pixelsToUnits(5.0f);
circleParams.radius = (float)(m_piston->getCylinderBank()->getBore() / 10) * 0.75f;
gen->startShape();
gen->generateCircle2d(circleParams);
gen->endShape(&m_wristPinHole);
}
void PistonObject::render(const ViewParameters *view) {
const int layer = m_piston->getRod()->getJournal();
if (layer > view->Layer1 || layer < view->Layer0) return;
const ysVector col = tintByLayer(m_app->getWhite(), layer - view->Layer0);
const ysVector holeCol = tintByLayer(m_app->getBackgroundColor(), layer - view->Layer0);
resetShader();
setTransform(
&m_piston->m_body,
(float)(m_piston->getCylinderBank()->getBore() / 2),
0.0f,
(float)(-m_piston->getCompressionHeight() - m_piston->getWristPinLocation()));
m_app->getShaders()->SetBaseColor(col);
m_app->getEngine()->DrawModel(
m_app->getShaders()->GetRegularFlags(),
m_app->getAssetManager()->GetModelAsset("Piston"),
0x32 - layer);
setTransform(&m_piston->m_body);
m_app->getShaders()->SetBaseColor(holeCol);
m_app->drawGenerated(m_wristPinHole, 0x32 - layer);
}
void PistonObject::process(float dt) {
/* void */
}
void PistonObject::destroy() {
/* void */
}