*
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class ConstantForce : MonoBehaviour {
|
||||
|
||||
public Vector3 force;
|
||||
public Rigidbody body;
|
||||
public float maxSpeed = 1000;
|
||||
public bool localSpace = true;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate () {
|
||||
if (body != null) {
|
||||
var vel = body.velocity.magnitude;
|
||||
if(vel < maxSpeed) {
|
||||
if(localSpace) {
|
||||
var f = transform.TransformDirection(force);
|
||||
body.AddForce(f);
|
||||
} else {
|
||||
body.AddForce(force);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3052e159dd821b343b26054f95fee9fd
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class ConstantVelocity : MonoBehaviour {
|
||||
public Rigidbody target;
|
||||
public Vector3 velocity = Vector3.forward;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
if (target != null) {
|
||||
target.velocity = velocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2447c867112e08944a68a1b2a72389f4
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -100
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
|
||||
public class DebugSpeedometer : MonoBehaviour
|
||||
{
|
||||
public WheelPhysics[] wheels;
|
||||
public Rigidbody car;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
float speed_ms = 0;
|
||||
if (wheels != null)
|
||||
{
|
||||
speed_ms = Mathf.Abs((float)wheels.Select(v => v.angularVelocity*v.TotalWheelRadius).Sum() / wheels.Length);
|
||||
}
|
||||
|
||||
var speed_kmph = (speed_ms*60.0f*60.0f)/1000.0f;
|
||||
var car_speed = car.velocity.magnitude*3.6f;
|
||||
|
||||
|
||||
GUI.Label(new Rect(20, 100, 200, 40), "Wheels speed [km/h]: " + speed_kmph);
|
||||
GUI.Label(new Rect(20, 140, 200, 40), "Real speed [km/h]: " + car_speed);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f076152b0f182a946abb77db1b200bbb
|
||||
timeCreated: 1453672668
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class GetPhysicsDeltaTime : MonoBehaviour {
|
||||
public Rigidbody source;
|
||||
private Vector3 lastPos;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
lastPos = source.position;
|
||||
source.velocity = Vector3.forward;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
var currentPos = source.position;
|
||||
var delta = currentPos - lastPos;
|
||||
var distance = delta.magnitude;
|
||||
lastPos = currentPos;
|
||||
|
||||
Debug.Log("Delta time = " + distance+ " Fixed delta: " + Time.fixedDeltaTime);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37b12b0ffde576c48976e47fb0d4ec9f
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public static class Label3D {
|
||||
/*
|
||||
public static void AtWorldPosition(Vector3 position, string text) {
|
||||
var screenPosition = Camera.main.WorldToScreenPoint(position);
|
||||
screenPosition.y = Camera.main.pixelHeight - screenPosition.y;
|
||||
|
||||
var labelContent = new GUIContent(text);
|
||||
var size = GUI.skin.label.CalcSize(new GUIContent(text));
|
||||
var labelRect = new Rect(screenPosition.x, screenPosition.y, size.x, size.y);
|
||||
Tools.DrawRectangle(labelRect, new Color(0,0,0,0.5f));
|
||||
GUI.Label(labelRect, labelContent);
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43b38c3c19f944d4b8c5fed125847963
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
public class Plot2DVariableFunction : Plot2DFunction
|
||||
{
|
||||
public GameObject target;
|
||||
public string variable;
|
||||
|
||||
// Use this for initialization
|
||||
void Start ()
|
||||
{
|
||||
ReadValue();
|
||||
|
||||
}
|
||||
|
||||
public override float f(float x)
|
||||
{
|
||||
return ReadValue();
|
||||
}
|
||||
|
||||
float ReadValue()
|
||||
{
|
||||
if (target != null) {
|
||||
var pathBlocks = variable.Split('.');
|
||||
var c = target.GetComponent(pathBlocks[0]);
|
||||
|
||||
if (c == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
//find target
|
||||
int depth = 1;
|
||||
object o = c;
|
||||
System.Reflection.FieldInfo field = null ;
|
||||
|
||||
while (depth < pathBlocks.Length) {
|
||||
var t = o.GetType();
|
||||
field = t.GetField(pathBlocks[depth], System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
|
||||
if (field == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
o = field.GetValue(o);
|
||||
depth++;
|
||||
}
|
||||
try
|
||||
{
|
||||
float val = Convert.ToSingle(o);
|
||||
return val;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.LogFormat("Failed to convert property {0} to float type!", field.Name);
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 477c3138005e6c64da3d6bc84e51dec9
|
||||
timeCreated: 1454231920
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,117 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68fb46041ea99004b9edd5d7fc9133da
|
||||
timeCreated: 1453127428
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user