118 lines
4.2 KiB
C#
118 lines
4.2 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System;
|
|
|
|
|
|
public class TyreCurvesView : MonoBehaviour
|
|
{
|
|
|
|
public OscilloscopeDisplay display;
|
|
public float Fz = 5000;
|
|
|
|
public bool autoVerticalScale = true;
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
|
|
}
|
|
|
|
private void OnDrawGizmosSelected()
|
|
{
|
|
if (display == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
var tyre = GetComponent<Tyre>();
|
|
|
|
if (display.plot.channels.Length < 4) {
|
|
Array.Resize(ref display.plot.channels, 4);
|
|
}
|
|
|
|
int samplesCount = 400;
|
|
|
|
|
|
Color[] channel_colors = new[] {Color.red, Color.green, Color.blue};
|
|
|
|
double r = 0.33;
|
|
double r0 = r;
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
{
|
|
var channel = display.plot.channels[i];
|
|
channel.ResizeBuffers(samplesCount);
|
|
channel.SampleBufferPosition = samplesCount - 1;
|
|
channel.color = channel_colors[i];
|
|
if (autoVerticalScale)
|
|
{
|
|
channel.cellValue = Fz / display.halfYCellCount;
|
|
}
|
|
|
|
channel.cellTime = 1.0f / display.halfXCellCount;
|
|
|
|
if (i == 0){
|
|
for (int j = 0; j < samplesCount; ++j) {
|
|
float k = ((1.0f / (float)(samplesCount - 1)) * j) * 2.0f - 1.0f;
|
|
var Vc = new Double3(10, 0, 0);
|
|
var forces = Pacejka.CalcPacejka(Vc, (Vc.x + Vc.x * k) / r, r0, r, Fz, 0, tyre.pacejkaParams._coeffs2, false);
|
|
channel.SetSample(j, k, (float)forces.x);
|
|
}
|
|
} else if (i == 1) {
|
|
for (int j = 0; j < samplesCount; ++j) {
|
|
float k = ((1.0f / (float)(samplesCount - 1)) * j) * 2.0f - 1.0f;
|
|
Vector3 angle_zero = new Vector3(10, 0, 0);
|
|
Vector3 angle_90 = new Vector3(0, 10, 0);
|
|
Vector3 Vc = (Vector3.Lerp(angle_zero, angle_90, Mathf.Abs(k))*Mathf.Sign(k)).normalized * 10;
|
|
var forces = Pacejka.CalcPacejka(new Double3(Vc.x, Vc.y, Vc.z), 10.0 / r, r0, r, Fz, 0, tyre.pacejkaParams._coeffs2, false);
|
|
channel.SetSample(j, k, (float)forces.y);
|
|
}
|
|
} else if (i == 2) {
|
|
for (int j = 0; j < samplesCount; ++j) {
|
|
float k = ((1.0f / (float)(samplesCount - 1)) * j) * 2.0f - 1.0f;
|
|
Vector3 angle_zero = new Vector3(10, 0, 0);
|
|
Vector3 angle_90 = new Vector3(0, 10, 0);
|
|
Vector3 Vc = (Vector3.Lerp(angle_zero, angle_90, Mathf.Abs(k))).normalized * 10;
|
|
Vc.y *= Mathf.Sign(k);
|
|
var forces = Pacejka.CalcPacejka(new Double3(Vc.x, Vc.y, Vc.z), 10.0 / r, r0, r, Fz, 0, tyre.pacejkaParams._coeffs2, false);
|
|
channel.SetSample(j, k, (float)forces.z);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//draw friction circle
|
|
var combined_channel = display.plot.channels[3];
|
|
combined_channel.ResizeBuffers(samplesCount);
|
|
combined_channel.SampleBufferPosition = samplesCount - 1;
|
|
combined_channel.color = Color.white;
|
|
combined_channel.cellValue = combined_channel.cellTime = 3000 / display.halfYCellCount;
|
|
|
|
for (int j = 0; j < samplesCount; ++j) {
|
|
float k = ((1.0f / (float)(samplesCount - 1)) * j) * 2.0f - 1.0f;
|
|
|
|
// float k = ((1.0f / (float)(samplesCount - 1)) * j);
|
|
/*float angle = Mathf.PI*2.0f*k;
|
|
var v = new Vector3(Mathf.Sin(angle), Mathf.Cos(angle), 0) * 1000;
|
|
combined_channel.SetSample(j, (float)v.x, (float)v.y);*/
|
|
|
|
Vector3 angle_zero = new Vector3(1, 0, 0);
|
|
Vector3 angle_90 = new Vector3(0, 1, 0);
|
|
|
|
|
|
Vector3 Vc = (Vector3.Lerp(angle_zero, angle_90, Mathf.Abs(k)) ).normalized * 10;
|
|
Vc.y *= Mathf.Sign(k);
|
|
var forces = Pacejka.CalcPacejka(new Double3(Vc.x, Vc.y, Vc.z), 8.0 / r, r0, r, Fz, 0, tyre.pacejkaParams._coeffs2, true);
|
|
|
|
combined_channel.SetSample(j, (float)forces.x, (float)forces.y);
|
|
// combined_channel.SetSample(j, k * 3000, (float)forces.x);
|
|
}
|
|
|
|
}
|
|
}
|