代码拉取完成,页面将自动刷新
#include "../include/simulation_object.h"
#include "../include/piston.h"
#include "../include/cylinder_bank.h"
#include "../include/engine_sim_application.h"
SimulationObject::SimulationObject() {
m_app = nullptr;
}
SimulationObject::~SimulationObject() {
/* void */
}
void SimulationObject::initialize(EngineSimApplication *app) {
m_app = app;
}
void SimulationObject::generateGeometry() {
/* void */
}
void SimulationObject::render(const ViewParameters *settings) {
/* void */
}
void SimulationObject::process(float dt) {
/* void */
}
void SimulationObject::destroy() {
/* void */
}
Piston *SimulationObject::getForemostPiston(CylinderBank *bank, int layer) {
Engine *engine = m_app->getSimulator()->getEngine();
Piston *frontmostPiston = nullptr;
const int cylinderCount = engine->getCylinderCount();
for (int i = 0; i < cylinderCount; ++i) {
Piston *piston = engine->getPiston(i);
if (piston->getCylinderBank() == bank) {
if (piston->getRod()->getJournal() >= layer) {
if (frontmostPiston == nullptr
|| piston->getRod()->getJournal() < frontmostPiston->getRod()->getJournal()) {
frontmostPiston = piston;
}
}
}
}
return frontmostPiston;
}
void SimulationObject::resetShader() {
m_app->getShaders()->ResetBaseColor();
m_app->getShaders()->SetObjectTransform(ysMath::LoadIdentity());
}
void SimulationObject::setTransform(
atg_scs::RigidBody *rigidBody,
float scale,
float lx,
float ly,
float angle,
float z)
{
double p_x, p_y;
rigidBody->localToWorld(lx, ly, &p_x, &p_y);
const ysMatrix rot = ysMath::RotationTransform(
ysMath::Constants::ZAxis,
(float)rigidBody->theta + angle);
const ysMatrix trans = ysMath::TranslationTransform(
ysMath::LoadVector((float)p_x, (float)p_y, z));
const ysMatrix scaleTransform = ysMath::ScaleTransform(ysMath::LoadScalar(scale));
m_app->getShaders()->SetObjectTransform(
ysMath::MatMult(ysMath::MatMult(trans, rot), scaleTransform));
}
ysVector SimulationObject::tintByLayer(const ysVector &col, int layers) const {
ysVector result = col;
for (int i = 0; i < layers; ++i) {
result = ysMath::Add(
ysMath::Mul(result, ysMath::LoadScalar(0.3f)),
ysMath::Mul(m_app->getBackgroundColor(), ysMath::LoadScalar(0.7f))
);
}
return result;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。