53 m_node_back = tnodeback;
54 m_node_front = tnodefront;
55 m_node_ref = tnoderef;
60 m_afterburner_active =
false;
65 m_area = 2 * 3.14159 * m_radius * 0.6 * m_radius * 0.6;
66 m_exhaust_velocity = 0;
67 m_axis = m_actor->ar_nodes[m_node_front].RelPosition - m_actor->ar_nodes[m_node_back].RelPosition;
68 m_reflen = m_axis.length();
69 m_axis = m_axis / m_reflen;
73 void TurbojetVisual::SetupVisuals(
RigDef::Turbojet & def,
int num, std::string
const& propname, Ogre::Entity* nozzle, Ogre::Entity* afterburner_flame)
78 m_nozzle_entity = nozzle;
80 m_nozzle_scenenode->attachObject(m_nozzle_entity);
83 if (afterburner_flame !=
nullptr)
85 m_flame_entity = afterburner_flame;
87 m_flame_scenenode->attachObject(m_flame_entity);
89 m_flame_scenenode->setVisible(
false);
98 m_smoke_scenenode->attachObject(m_smoke_particle);
99 m_smoke_particle->setCastShadows(
false);
109 m_node_front = front;
114 Turbojet::~Turbojet()
124 TurbojetVisual::~TurbojetVisual()
126 if (m_flame_entity !=
nullptr)
128 m_flame_entity->setVisible(
false);
131 if (m_nozzle_entity !=
nullptr)
133 m_nozzle_entity->setVisible(
false);
136 if (m_smoke_particle !=
nullptr)
138 m_smoke_particle->removeAllEmitters();
144 if (this->tjet_visual.IsVisible())
145 this->tjet_visual.UpdateVisuals(gfx_actor);
148 void Turbojet::setVisible(
bool visible)
150 this->tjet_visual.SetVisible(visible);
160 m_nozzle_scenenode->setPosition(node_buf[m_node_back].AbsPosition);
164 Vector3 paxis = Plane(laxis, 0).projectVector(node_buf[m_node_ref].AbsPosition - node_buf[m_node_back].AbsPosition);
166 Vector3 taxis = laxis.crossProduct(paxis);
167 Quaternion dir = Quaternion(laxis, paxis, taxis);
168 m_nozzle_scenenode->setOrientation(dir);
172 m_flame_scenenode->setVisible(
true);
174 flamelength = flamelength * (1.0 + (((Real)rand() / (Real)RAND_MAX) - 0.5) / 10.0);
175 m_flame_scenenode->setScale(flamelength, m_radius * 2.0, m_radius * 2.0);
176 m_flame_scenenode->setPosition(node_buf[m_node_back].AbsPosition + dir * Vector3(-0.2, 0.0, 0.0));
177 m_flame_scenenode->setOrientation(dir);
180 m_flame_scenenode->setVisible(
false);
183 if (m_smoke_particle &&
186 m_smoke_scenenode->setPosition(node_buf[m_node_back].AbsPosition);
187 ParticleEmitter* emit = m_smoke_particle->getEmitter(0);
188 emit->setDirection(-laxis);
194 emit->setEnabled(
true);
200 emit->setEnabled(
false);
205 emit->setDirection(Vector3(0, 1, 0));
206 emit->setParticleVelocity(7.0);
207 emit->setEnabled(
true);
208 emit->setColour(ColourValue(0.0, 0.0, 0.0, 0.1));
209 emit->setTimeToLive(0.1 / 0.1);
214 void TurbojetVisual::SetVisible(
bool visible)
217 m_smoke_particle->setVisible(visible);
218 m_nozzle_scenenode->setVisible(visible);
222 m_flame_scenenode->setVisible(
false);
226 void Turbojet::updateForces(
float dt,
int doUpdate)
233 m_axis = m_actor->ar_nodes[m_node_front].RelPosition - m_actor->ar_nodes[m_node_back].RelPosition;
234 float axlen = m_axis.length();
235 m_axis = m_axis / axlen;
236 if (fabs(m_reflen - axlen) > 0.1)
242 float warmupfactor = 1.0;
245 warmupfactor = (m_timer - m_warmup_start) / m_warmup_time;
246 if (warmupfactor >= 1.0)
252 if (m_rpm_percent < 0)
254 float torque = -m_rpm_percent / 100.0;
256 if (m_rpm_percent < 100.0 && !m_is_failed && m_ignition)
257 torque += ((0.2 + m_throtle * 0.8) * warmupfactor);
259 m_rpm_percent += (double)dt * torque * 30.0;
261 float enginethrust = 0;
262 if (!m_is_failed && m_ignition)
264 enginethrust = m_max_dry_thrust * m_rpm_percent / 100.0;
265 m_afterburner_active = (tjet_afterburnable && m_throtle > 0.95 && m_rpm_percent > 80);
266 if (m_afterburner_active)
267 enginethrust += (m_afterburn_thrust - m_max_dry_thrust);
270 m_afterburner_active =
false;
272 if (m_afterburner_active)
278 m_actor->ar_nodes[m_node_back].Forces -= (enginethrust * 1000.0) * m_axis;
280 m_actor->ar_nodes[m_node_back].Forces += (enginethrust * 1000.0) * m_axis;
282 m_exhaust_velocity = enginethrust * 5.6 / m_area;
285 void Turbojet::setThrottle(
float val)
297 float Turbojet::getThrottle()
302 void Turbojet::setRPM(
float _rpm)
304 m_rpm_percent = _rpm;
307 void Turbojet::reset()
317 void Turbojet::toggleReverse()
322 m_reverse = !m_reverse;
325 void Turbojet::setReverse(
bool val)
330 void Turbojet::flipStart()
332 if (m_timer - m_last_flip < 0.3)
334 m_ignition = !m_ignition;
335 if (m_ignition && !m_is_failed)
338 m_warmup_start = m_timer;
346 m_last_flip = m_timer;