public override void Update() { if (DebugHook.enabled) { DebugHook.SendSceneData(sceneObjects.ToArray(), materials.ToArray(), sceneProperties); } }
void CallHook(DebugHook hook) { var func = _hook[(int)hook]; if (func != null) { _state = State.Breaking; func(this); _state = State.Running; } }
public void Update(SceneProperties sceneProperties) { DebugHook.ClearDebugData(); delta = (float)Time.lastFrameTime / 20; // Acceleration if (InputHandler.GetStatus().keyboardKeys[OpenTK.Input.Key.W]) { userRpm += data.engineIncr; } else if (rpm > 0) { userRpm -= data.engineDecr; } else if (rpm != 0) { userRpm = 0; } rpm = userRpm * data.gearRatios[gear] * data.differentialRatio * data.transmissionEfficiency; rpm = Math.Min(rpm, 6400); Vector3 drag = -data.drag * velocity * velocity.Length; Vector3 rollingResistance = -data.rollingResistance * velocity; // Braking if (InputHandler.GetStatus().keyboardKeys[OpenTK.Input.Key.Space] && velocity.LengthWithSign() > 0) { velocity = -forward * data.brake; } if (velocity.Length < 0) { velocity = Vector3.Zero; // TODO: reverse } Vector3 traction = forward * GetTorqueCurve() * data.gearRatios[gear] * data.differentialRatio * data.transmissionEfficiency * MULT_CONST; Vector3 longitudinalForce = traction + drag + rollingResistance; Vector3 acceleration = longitudinalForce / data.mass; velocity = velocity + (delta * acceleration); if (rpm > data.gearChangeUpperThreshold && gear < 4) { rpmAtGearChanges += gear + " -> " + (gear + 1) + " @ " + rpm + "\n"; gear++; } else if (rpm < data.gearChangeLowerThreshold && gear > 0) { rpmAtGearChanges += gear + " -> " + (gear - 1) + " @ " + rpm + "\n"; gear--; } //var enginePitch = Math.Min(Math.Max(0.2f + (Math.Min(rpm / 6400, 0.8f)), 0.5f), 1.0f); //engineSound.SetPitch(enginePitch); Dictionary <string, Any> debugData = new Dictionary <string, Any>() { { "= = = = Transform properties", "= = =" }, { "Velocity", velocity }, { "Position", position }, { "= = = = Engine Logic", "= = =" }, { "Traction", traction }, { "Drag", drag }, { "Rolling resistance", rollingResistance }, { "Longitudinal force", longitudinalForce }, { "Acceleration", acceleration }, { "= = = = Car Logic", "= = =" }, { "Gear", gear }, { "Current gear ratio", data.gearRatios[gear] }, { "Current torque", GetTorqueCurve() }, { "RPM", rpm }, { "Input RPM", userRpm }, { "Gear change @ RPM", rpmAtGearChanges }, { "Speed (MPH)", (velocity.Length / 100) * MPH_CONST }, { "= = = = Constants", "= = =" }, { "Car name", data.name }, { "Constant drag", data.drag }, { "Constant rolling resistance", data.rollingResistance }, { "Constant mass", data.mass }, { "Transmission efficiency", data.transmissionEfficiency }, { "Differential ratio", data.differentialRatio } }; foreach (KeyValuePair <string, Any> a in debugData) { DebugHook.PushDebugData(a.Key, a.Value); } position = position + (delta * velocity); Render3D.sceneCamera.position = new Vector3(6, 2, 0); Render3D.sceneCamera.vAngle = -currentEuler.Y; Render3D.sceneCamera.worldPosition = position; Render3D.sceneCamera.fieldOfView = 55; }
public void SetHook(DebugHook hook, Action <VMachine> callback) { _hook[(int)hook] = callback; }