// Start is called before the first frame update void Start() { //fuel.GetComponent<OtherFuelManager>().objectPosition; direction = fuelManager.GetComponent <OtherFuelManager>().objectPosition - this.transform.position; //normal vector section NormalCoordinates directionNormal = HolisticMath.GetNormal(new NormalCoordinates(direction)); direction = directionNormal.ToVector(); //Coordinates v = new Coordinates(direction.x,direction.y,direction.z); //float angle = HolisticMath.Angle(new NormalCoordinates(0,1,0),new NormalCoordinates(direction)) * 180.0f / Mathf.PI; //ANGLE RADIANS TO DEGRESS //Debug.Log("Angle from Tank to Fuel: " + angle); //Rotate dirtection //float angle = HolisticMath.Angle(new NormalCoordinates(0,1,0),new NormalCoordinates(direction)); float angle = HolisticMath.Angle(new NormalCoordinates(this.transform.up), new NormalCoordinates(direction)); bool clockwise = false; if (HolisticMath.Cross(new NormalCoordinates(this.transform.up), directionNormal).z < 0) { clockwise = true; } //NormalCoordinates newRotationDirection = HolisticMath.Rotate(new NormalCoordinates(0,1,0),angle); NormalCoordinates newRotationDirection = HolisticMath.Rotate(new NormalCoordinates(this.transform.up), angle, clockwise); this.transform.up = new Vector3(newRotationDirection.x, newRotationDirection.y, newRotationDirection.z); }
// Start is called before the first frame update //void Start() //{ //} //// Update is called once per frame //void Update() //{ //} //** Dot product section static public float Dot(NormalCoordinates vector1, NormalCoordinates vector2) { //float dotProduct = (vector1.x * vector2.x) + (vector1.y * vector2.y); //return dotProduct; return(vector1.x * vector2.x + vector1.y * vector2.y + vector1.z * vector2.z); }
static public NormalCoordinates Cross(NormalCoordinates vector1, NormalCoordinates vector2) { float xCrossValue = vector1.y * vector2.z - vector1.z * vector2.y; float yCrossValue = vector1.z * vector2.x - vector1.x * vector2.z; float zCrossValue = vector1.x * vector2.y - vector1.y * vector2.x; NormalCoordinates crossProduct = new NormalCoordinates(xCrossValue, yCrossValue, zCrossValue); return(crossProduct); }
static public NormalCoordinates GetNormal(NormalCoordinates vector) { float length = GetDistance(new NormalCoordinates(0, 0, 0), vector); vector.x /= length; vector.y /= length; vector.z /= length; return(vector); }
public static void DrawLine(NormalCoordinates startPosition, NormalCoordinates endPosition, float width, Color color) { GameObject line = new GameObject("Line: " + startPosition.ToString() + " _ " + endPosition.ToString()); LineRenderer linerenderer = line.AddComponent <LineRenderer>(); linerenderer.material = new Material(Shader.Find("Unlit/Color")); linerenderer.material.color = color; linerenderer.SetPosition(0, new Vector3(startPosition.x, startPosition.y, startPosition.z)); linerenderer.SetPosition(1, new Vector3(endPosition.x, endPosition.y, endPosition.z)); linerenderer.startWidth = width; linerenderer.endWidth = width; }
public static void DrawPoint(NormalCoordinates position, float width, Color color) { GameObject point = new GameObject("Point: " + position.ToString()); LineRenderer line = point.AddComponent <LineRenderer>(); line.material = new Material(Shader.Find("Unlit/Color")); line.material.color = color; line.SetPosition(0, new Vector3(position.x - width / 3.0f, position.y - width / 3.0f, position.z)); line.SetPosition(1, new Vector3(position.x + width / 3.0f, position.y + width / 3.0f, position.z)); line.startWidth = width; line.endWidth = width; }
// private void Start() { Vector3 position = transform.position; int x = Mathf.FloorToInt(position.x / 0.866f); int z = Mathf.FloorToInt(position.z) - (x - (x & 1)) / 2; int y = -x - z; normalCoordinates = new NormalCoordinates(x, Mathf.FloorToInt(position.z)); cubeCoordinates = new CubeCoordinates(x, y, z); indexInGrid = transform.GetSiblingIndex(); modelHeight = GetComponent <MeshRenderer>().bounds.size.y; }
static public NormalCoordinates Rotate(NormalCoordinates vector, float angle, bool clockwise) //angle in radians { if (clockwise) { angle = 2 * Mathf.PI - angle; // this method works in radians and 2 * Math.PI is equal to 360 degress of a circle } float xValue = vector.x * Mathf.Cos(angle) - vector.y * Mathf.Sin(angle); float yValue = vector.x * Mathf.Sin(angle) + vector.y * Mathf.Cos(angle); return(new NormalCoordinates(xValue, yValue, 0)); }
static public float GetDistance(NormalCoordinates point1, NormalCoordinates point2) { //float distance = Vector3.Distance(point1.ToVector(), point2.ToVector()); //return distance; float differenceSquare = Square(point1.x - point2.x) + Square(point1.y - point2.y) + Square(point1.z - point2.z); float squareRoot = Mathf.Sqrt(differenceSquare); return(squareRoot); }
static public float Angle(NormalCoordinates vector1, NormalCoordinates vector2) { float dotDivide = Dot(vector1, vector2) / (GetDistance(new NormalCoordinates(0, 0, 0), vector1) * GetDistance(new NormalCoordinates(0, 0, 0), vector2)); return(Mathf.Acos(dotDivide)); //radians //for degrees multiply * 180 / Mathf.PI; }