Commit 02456aa4 authored by Chae Ho Shin's avatar Chae Ho Shin

Added wasd key acceleration movement

parent d5275c60
fileFormatVersion: 2
guid: 4ed3ccfedffc65c479bbf334b135ff23
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 06fdc036819968c4b9fad31b0a9bd2fb
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
...@@ -4,7 +4,8 @@ using UnityEngine; ...@@ -4,7 +4,8 @@ using UnityEngine;
public class BackgroundMovement : MonoBehaviour public class BackgroundMovement : MonoBehaviour
{ {
bool toggle = false; [SerializeField]
GameObject Cone;
bool grabbed = false; bool grabbed = false;
int cnt = 0; int cnt = 0;
double beta = 0.5f; // v/c double beta = 0.5f; // v/c
...@@ -15,15 +16,44 @@ public class BackgroundMovement : MonoBehaviour ...@@ -15,15 +16,44 @@ public class BackgroundMovement : MonoBehaviour
public double gamma = 1.0f; public double gamma = 1.0f;
Vector3 orientation; Vector3 orientation;
bool toggle = false;
public bool Toggle
{
get
{
return toggle;
}
set
{
if(value)
transform.parent = Cone.transform;
else
{
transform.parent = null;
v = Levelmanager.player.v;
}
toggle = value;
}
}
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
toggle = false;
v = new Vector3(0, 0, 0);
} }
// Update is called once per frame void FixedUpdate()
void Update()
{ {
if(!toggle)
{
transform.localPosition = new Vector3(0, 0, 0);
}
else
{
transform.Translate((float)Constants.c * Vector3.up * Time.fixedDeltaTime * (float)Levelmanager.player.gamma, Space.World); // move up by 1 second
transform.Translate(v * Time.fixedDeltaTime * (float)Levelmanager.player.gamma, Space.World);
}
} }
} }
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
public static class Constants public static class Constants
{ {
public static double c => 5; // speed of light. public static double c => 5; // speed of light.
public static double Gamma(double v) public static double Gamma(double v)
{ {
return 1.0f / Mathf.Sqrt((1 - (float)((v / c) * (v / c)))); return 1.0f / Mathf.Sqrt((float)(1 - ((v / c) * (v / c))));
} }
public static double RadianToDegree(double r) public static double RadianToDegree(double r)
{ {
return r * 180 / Mathf.PI; return r * 180 / Mathf.PI;
} }
public static Matrix<double> BoostMatrix(Vector3 velocity)
{
var vmag = velocity.magnitude;
var gamma = Constants.Gamma(vmag);
var beta = vmag / Constants.c;
var betax = velocity.x / Constants.c;
var betay = velocity.z / Constants.c;
double[,] tmp = { { gamma, -gamma * betax, -gamma * betay},
{ -gamma * betax, 1.0+(gamma - 1.0)*(betax*betax)/(beta*beta) , (gamma - 1.0) * (betax*betay)/(beta*beta)},
{ -gamma * betay, (gamma - 1.0) * (betay*betax)/(beta*beta), 1.0+(gamma - 1.0)*(betay*betay)/(beta*beta)} };
var M = Matrix<double>.Build;
var result = M.DenseOfArray(tmp);
return result;
}
} }
...@@ -16,7 +16,7 @@ public class PathRenderer : MonoBehaviour ...@@ -16,7 +16,7 @@ public class PathRenderer : MonoBehaviour
[SerializeField] [SerializeField]
LevelManager levelManager; LevelManager levelManager;
[SerializeField] [SerializeField]
GameObject background; BackgroundMovement background;
[SerializeField] [SerializeField]
LogScaleSlider velocityslider; LogScaleSlider velocityslider;
......
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
public class Planemovement : MonoBehaviour public class Planemovement : MonoBehaviour
{ {
...@@ -22,6 +24,9 @@ public class Planemovement : MonoBehaviour ...@@ -22,6 +24,9 @@ public class Planemovement : MonoBehaviour
public Planemovement otherclock; public Planemovement otherclock;
MatrixBuilder<double> M = Matrix<double>.Build;
VectorBuilder<double> V = Vector<double>.Build;
void Start() void Start()
{ {
...@@ -50,19 +55,37 @@ public class Planemovement : MonoBehaviour ...@@ -50,19 +55,37 @@ public class Planemovement : MonoBehaviour
{ {
cnt = 0; cnt = 0;
} }
//transform.Translate(Vector3.forward * Time.fixedDeltaTime, Space.World); if (alpha.magnitude > 0.0f)
//transform.Translate(0.5f*Vector3.forward * Mathf.Cos(2*Mathf.PI*cnt/480) * Time.fixedDeltaTime, Space.World); {
//transform.Translate(0.5f*Vector3.left * Mathf.Sin(2 * Mathf.PI * cnt / 480) * Time.fixedDeltaTime, Space.World);
var atmp = alpha.magnitude * Time.fixedDeltaTime;
double[] vtmp = { (atmp * (alpha.x / alpha.magnitude)), 0.0, (atmp * (alpha.z / alpha.magnitude)) };
var deltavnaive = V.DenseOfArray(vtmp);
double[] tmp = {Constants.c * Constants.Gamma(deltavnaive.L2Norm()),
deltavnaive[0] * Constants.Gamma(deltavnaive.L2Norm()),
deltavnaive[2] * Constants.Gamma(deltavnaive.L2Norm())};
//orientation = (float)beta * Vector3.forward * Mathf.Cos(2 * Mathf.PI * cnt / 480) + (float)beta * Vector3.left * Mathf.Sin(2 * Mathf.PI * cnt / 480); var deltav = V.DenseOfArray(tmp);
//v = (float)beta * Vector3.forward * Mathf.Cos(2 * Mathf.PI * cnt / 480) + (float)beta * Vector3.left * Mathf.Sin(2 * Mathf.PI * cnt / 480);
//v = alpha.normalized * (alpha.magnitude * Time.time / Mathf.Sqrt(1.0f+(alpha.magnitude * Time.time)*(alpha.magnitude * Time.time))); if (v.magnitude > 0.0f)
{
deltav = Constants.BoostMatrix(-v) * deltav;
}
var tt = deltav[0] / Constants.c;
//v = new Vector3(0, 0, 0); Vector3 finaldeltav = new Vector3((float)(deltav[1] / tt), 0.0f, (float)(deltav[2] / tt));
var hmm = finaldeltav - v;
v = finaldeltav;
}
if((Levelmanager.player.transform.position - transform.position).magnitude < 0.5f) if ((Levelmanager.player.transform.position - transform.position).magnitude < 1f)
{ {
toggle = true; toggle = true;
} }
......
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
public class PlayerMovement : MonoBehaviour public class PlayerMovement : MonoBehaviour
{ {
//int cnt = 0; //int cnt = 0;
double beta = 0.5f; // v/c double beta = 0.5f; // v/c
public Vector3 alpha = new Vector3(0.1f, 0.0f, 0.0f); // proper acceleration public Vector3 alpha = new Vector3(0.0f, 0.0f, 0.0f); // proper acceleration
public Vector3 v = new Vector3(0.0f, 0.0f, 0.0f); public Vector3 v = new Vector3(0.0f, 0.0f, 0.0f);
public double gamma = 1.0f; public double gamma = 1.0f;
public GameObject theobject; public GameObject theobject;
public Vector3 orientation = new Vector3(0.0f, 0.0f, 0.0f); public Vector3 orientation = new Vector3(0.0f, 0.0f, 0.0f);
public double time = 0.0f; public double time = 0.0f;
MatrixBuilder<double> M = Matrix<double>.Build;
VectorBuilder<double> V = Vector<double>.Build;
bool isinertial = true; bool isinertial = true;
...@@ -25,6 +29,7 @@ public class PlayerMovement : MonoBehaviour ...@@ -25,6 +29,7 @@ public class PlayerMovement : MonoBehaviour
orientation = new Vector3(0.0f, 0.0f, 1.0f); orientation = new Vector3(0.0f, 0.0f, 1.0f);
time = 0.0f; time = 0.0f;
isinertial = true; isinertial = true;
alpha = new Vector3(0.0f, 0.0f, 0.0f);
} }
// Update is called once per frame // Update is called once per frame
...@@ -46,10 +51,43 @@ public class PlayerMovement : MonoBehaviour ...@@ -46,10 +51,43 @@ public class PlayerMovement : MonoBehaviour
//v = (float)beta * Vector3.forward * Mathf.Cos(2 * Mathf.PI * cnt / 480) + (float)beta * Vector3.left * Mathf.Sin(2 * Mathf.PI * cnt / 480); //v = (float)beta * Vector3.forward * Mathf.Cos(2 * Mathf.PI * cnt / 480) + (float)beta * Vector3.left * Mathf.Sin(2 * Mathf.PI * cnt / 480);
//v = alpha.normalized * (alpha.magnitude * Time.time / Mathf.Sqrt(1.0f + (alpha.magnitude * Time.time) * (alpha.magnitude * Time.time))); //v = alpha.normalized * (alpha.magnitude * Time.time / Mathf.Sqrt(1.0f + (alpha.magnitude * Time.time) * (alpha.magnitude * Time.time)));
//v = new Vector3(0.7f, 0.0f, 0.0f); //v = new Vector3(0.7f, 0.0f, 0.0f);
if (alpha.magnitude > 0.0f)
{
var atmp = alpha.magnitude * Time.fixedDeltaTime;
double[] vtmp = { (atmp * (alpha.x / alpha.magnitude)), 0.0,(atmp * (alpha.z / alpha.magnitude)) };
var deltavnaive = V.DenseOfArray(vtmp);
double[] tmp = {Constants.c * Constants.Gamma(deltavnaive.L2Norm()),
deltavnaive[0] * Constants.Gamma(deltavnaive.L2Norm()),
deltavnaive[2] * Constants.Gamma(deltavnaive.L2Norm())};
var deltav = V.DenseOfArray(tmp);
if (v.magnitude > 0.0f)
{
deltav = Constants.BoostMatrix(-v) * deltav;
}
var tt = deltav[0] / Constants.c;
Vector3 finaldeltav = new Vector3((float)(deltav[1]/tt), 0.0f, (float)(deltav[2]/tt));
var hmm = finaldeltav - v;
v = finaldeltav;
}
beta = v.magnitude / (float)Constants.c; beta = v.magnitude / (float)Constants.c;
gamma = Constants.Gamma(v.magnitude); gamma = Constants.Gamma(v.magnitude);
transform.Translate(v * Time.fixedDeltaTime * (float)gamma, Space.World); transform.Translate(v * Time.fixedDeltaTime * (float)gamma, Space.World);
var vt = v + (float)Constants.c * Vector3.up; var vt = v + (float)Constants.c * Vector3.up;
......
...@@ -26,7 +26,7 @@ public class Square : FlatLandObject ...@@ -26,7 +26,7 @@ public class Square : FlatLandObject
return pathList[n+1]; return pathList[n+1];
} }
public float GetPathVeclocity(int n) public float GetPathVelocity(int n)
{ {
return pathVelocity[n + 1]; return pathVelocity[n + 1];
} }
......
...@@ -14,6 +14,9 @@ public class UIManager : MonoBehaviour ...@@ -14,6 +14,9 @@ public class UIManager : MonoBehaviour
Camera playercamera; Camera playercamera;
[SerializeField] [SerializeField]
LogScaleSlider velocityslider; LogScaleSlider velocityslider;
[SerializeField]
LogScaleSlider accelslider;
public Canvas canvas; public Canvas canvas;
public Text mytime; public Text mytime;
...@@ -27,7 +30,7 @@ public class UIManager : MonoBehaviour ...@@ -27,7 +30,7 @@ public class UIManager : MonoBehaviour
private int prevSelectPathNum = -1; private int prevSelectPathNum = -1;
private Text pathName; private Text pathName;
private Text pathVeclocity; private Text pathVelocity;
private Vector3 middlePoint; private Vector3 middlePoint;
private Vector3 canvasSize; private Vector3 canvasSize;
private int sliderflag = 0; private int sliderflag = 0;
...@@ -40,7 +43,7 @@ public class UIManager : MonoBehaviour ...@@ -40,7 +43,7 @@ public class UIManager : MonoBehaviour
{ {
_pathUI.SetActive(false); _pathUI.SetActive(false);
pathName = _pathUI.transform.Find("Name").GetComponent<Text>(); pathName = _pathUI.transform.Find("Name").GetComponent<Text>();
pathVeclocity = _pathUI.transform.Find("Velocity").GetComponent<Text>(); pathVelocity = _pathUI.transform.Find("Velocity").GetComponent<Text>();
middlePoint = _pathUI.transform.position; middlePoint = _pathUI.transform.position;
canvasSize = new Vector3(Screen.width, Screen.height, 0); canvasSize = new Vector3(Screen.width, Screen.height, 0);
...@@ -73,7 +76,7 @@ public class UIManager : MonoBehaviour ...@@ -73,7 +76,7 @@ public class UIManager : MonoBehaviour
if (_pathUI.activeSelf == true && prevSelectPathNum != -1) if (_pathUI.activeSelf == true && prevSelectPathNum != -1)
{ {
square.pathVelocity[prevSelectPathNum + 1] = velocityslider.GetLogScaleValue(); square.pathVelocity[prevSelectPathNum + 1] = velocityslider.GetLogScaleValue();
pathVeclocity.text = "Velocity: " + square.GetPathVeclocity(prevSelectPathNum).ToString() + "c"; pathVelocity.text = "Velocity: " + square.GetPathVelocity(prevSelectPathNum).ToString() + "c";
} }
} }
} }
...@@ -129,7 +132,7 @@ public class UIManager : MonoBehaviour ...@@ -129,7 +132,7 @@ public class UIManager : MonoBehaviour
if (_pathUI.activeSelf == true && prevSelectPathNum != -1) if (_pathUI.activeSelf == true && prevSelectPathNum != -1)
{ {
square.pathVelocity[prevSelectPathNum + 1] = velocityslider.GetLogScaleValue(); square.pathVelocity[prevSelectPathNum + 1] = velocityslider.GetLogScaleValue();
pathVeclocity.text = "Velocity: " + square.GetPathVeclocity(prevSelectPathNum).ToString() + "c"; pathVelocity.text = "Velocity: " + square.GetPathVelocity(prevSelectPathNum).ToString() + "c";
} }
} }
else if (Input.GetMouseButtonDown(1)) else if (Input.GetMouseButtonDown(1))
...@@ -138,6 +141,44 @@ public class UIManager : MonoBehaviour ...@@ -138,6 +141,44 @@ public class UIManager : MonoBehaviour
prevSelectPathNum = -1; prevSelectPathNum = -1;
sliderflag = 0; sliderflag = 0;
} }
if(Input.GetKeyDown("w"))
{
var tmp = accelslider.GetLogScaleValue();
Levelmanager.player.alpha += new Vector3(0, 0, tmp);
}
else if(Input.GetKeyDown("a"))
{
var tmp = accelslider.GetLogScaleValue();
Levelmanager.player.alpha += new Vector3(-tmp, 0, 0);
}
else if(Input.GetKeyDown("s"))
{
var tmp = accelslider.GetLogScaleValue();
Levelmanager.player.alpha += new Vector3(0, 0, -tmp);
}
else if(Input.GetKeyDown("d"))
{
var tmp = accelslider.GetLogScaleValue();
Levelmanager.player.alpha += new Vector3(tmp, 0, 0);
}
if (Input.GetKeyUp("w"))
{
Levelmanager.player.alpha -= new Vector3(0, 0, Levelmanager.player.alpha.z);
}
else if (Input.GetKeyUp("a"))
{
Levelmanager.player.alpha -= new Vector3(Levelmanager.player.alpha.x, 0, 0);
}
else if (Input.GetKeyUp("s"))
{
Levelmanager.player.alpha -= new Vector3(0, 0, Levelmanager.player.alpha.z);
}
else if (Input.GetKeyUp("d"))
{
Levelmanager.player.alpha -= new Vector3(Levelmanager.player.alpha.x, 0, 0);
}
} }
private Vector3 getMouseClickPosition(RaycastHit hit) private Vector3 getMouseClickPosition(RaycastHit hit)
...@@ -158,7 +199,8 @@ public class UIManager : MonoBehaviour ...@@ -158,7 +199,8 @@ public class UIManager : MonoBehaviour
private void updatePathInfo(GameObject obj, int pathNum) private void updatePathInfo(GameObject obj, int pathNum)
{ {
pathName.text = obj.name; pathName.text = obj.name;
pathVeclocity.text = "Velocity: " + square.GetPathVeclocity(pathNum).ToString() + "c"; pathVelocity.text = "Velocity: " + square.GetPathVelocity(pathNum).ToString() + "c";
velocityslider.UpdateValuebyVelocity(square.GetPathVeclocity(pathNum)); velocityslider.UpdateValuebyVelocity(square.GetPathVelocity(pathNum));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment