void Update() { float translation = Input.GetAxis("Vertical") * speed; float rotation = Input.GetAxis("Horizontal") * rotationSpeed; translation *= Time.deltaTime; rotation *= Time.deltaTime; // transform.Translate(0, translation, 0); //move towards world up. //need to convert to local space. Vector3 direction = new Vector3(0, translation, 0); Vector3 facingDirection = transform.up; // what is the move direction of the tank Vector3 currentPos = transform.position; transform.position = HolisticMath.Translate(new Coords(0, translation, 0), new Coords(currentPos.x, currentPos.y, currentPos.z), new Coords(facingDirection.x, facingDirection.y, facingDirection.z)).ToVector(); // transform.Rotate(0, 0, -rotation); Vector3 temp = transform.up; float angleInRadians = rotation * Mathf.Deg2Rad; transform.up = HolisticMath.Rotate(new Coords(temp.x, temp.y, temp.z), angleInRadians, true).ToVector(); }
// Start is called before the first frame update void Start() { direction = fuel.transform.position - this.transform.position; Coords dirNormal = HolisticMath.GetNormal(new Coords(direction)); direction = dirNormal.ToVector(); this.transform.up = HolisticMath.LookAt2D(new Coords(this.transform.up), new Coords(this.transform.position), new Coords(fuel.transform.position)).ToVector(); /*direction = fuel.transform.position - this.transform.position; * Coords dirNormal = HolisticMath.GetNormal(new Coords(direction)); * direction = dirNormal.ToVector(); * // Coords(0,1,0) - facing of the tank * float angle = HolisticMath.Angle(new Coords(this.transform.up), new Coords(direction)); //* 180.0f/Mathf.PI; * * bool clockwise = false; * if(HolisticMath.Cross(new Coords(this.transform.up), dirNormal).Z < 0) * { * clockwise = true; * } * * Coords newDir = HolisticMath.Rotate(new Coords(0, 1, 0), angle, clockwise); * this.transform.up = new Vector3(newDir.X, newDir.Y, newDir.Z); */ }
public float IntersectsAt(Line l) { Coords c = l.A - this.A; float t = HolisticMath.Dot(Coords.Perp(l.v), c) / HolisticMath.Dot(Coords.Perp(l.v), v); return(t); }
void Update() { forwardVector = transform.up; float translation = Input.GetAxis("Vertical") * speed; float rotation = Input.GetAxis("Horizontal") * rotationSpeed; translation *= Time.deltaTime; rotation *= Time.deltaTime; //transform.Translate(0, translation, 0); transform.position = HolisticMath.Translate(transform.position, forwardVector, translation); //transform.Rotate(0, 0, -rotation); bool clockwise = false; if (rotation > 0) { clockwise = true; } // Always try to be sure if you are working with degrees or radians. // Dont just divide the rotationSpeed by something. // In this case, Rotate recieves angle in radians, so the conversion is necessary. transform.up = HolisticMath.Rotate(new Coords(forwardVector), Mathf.Abs(rotation) * Mathf.Deg2Rad, clockwise).ToVector(); }
// 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); }
// Update is called once per frame void Update() { //this.transform.position = line.Lerp(Time.time * 0.1f).ToVector(); this.transform.position = HolisticMath.Lerp(new Coords(start.position), new Coords(end.position), Time.time * 0.1f).ToVector(); }
public float IntersectsAt(Line l) { var normal = HolisticMath.GetNormal(HolisticMath.Cross(u, v)); var t = HolisticMath.Dot(-normal, l.A - B) / HolisticMath.Dot(normal, l.v); return(t); }
void Start() { Coords position = new Coords(point.transform.position, 1); point.transform.position = HolisticMath.Translate(position, new Coords(new Vector3(translation.x, translation.y, translation.z), 0)).ToVector(); }
public Coords Reflection(Coords hitVector) { Coords hitNormal = Coords.GetNormal(hitVector); Coords normalV = Coords.GetNormal(this.v); float dotTemp = HolisticMath.Dot(normalV, hitNormal); return(new Coords((normalV - (hitNormal * (2 * dotTemp))).ToVector())); }
void Update() { if (HolisticMath.Distance(new Coords(this.transform.position), new Coords(fuel.transform.position)) > stopping) { this.transform.position += direction * speed * Time.deltaTime; } }
public Coords Reflect(Coords normal) { Coords normalNormalized = normal.Normalize(); Coords vNormalized = v.Normalize(); var r = vNormalized - ((2 * HolisticMath.Dot(vNormalized, normalNormalized)) * normalNormalized); return(r); }
void Start() { rotaionMatrix = HolisticMath.GetRotaionMatrix(eulerAngles.x * Mathf.Deg2Rad, false, eulerAngles.y * Mathf.Deg2Rad, false, eulerAngles.z * Mathf.Deg2Rad, false); angle = HolisticMath.GetRotaionAxisAngle(rotaionMatrix); axis = HolisticMath.GetRotationAxis(rotaionMatrix, angle); }
static public Coords LookAt(Coords forward, Coords position, Coords target) { var diff = target - position; float a = HolisticMath.Angle(forward, diff); Coords cross = HolisticMath.Cross(forward, diff); Coords rotate = HolisticMath.Rotate(forward, a, cross.z < 0); return(rotate); }
// Update is called once per frame void Update() { /* transform.forward = HolisticMath.QRotate(new Coords(transform.forward, 1), new Coords(transform.forward), 1).ToVector(); * transform.rotation = HolisticMath.QRotate().ToMatrix(); */ Coords coords = HolisticMath.Quaternion(axis, angle * Mathf.Rad2Deg); Vector4 quaternion = new Vector4(coords.x, coords.y, coords.z, coords.w); transform.rotation *= new Quaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w); }
public void SetAngle(string amt) { float n; if (float.TryParse(amt, out n)) { n *= Mathf.PI / 180.0f; tank.transform.up = HolisticMath.Rotate(new Coords(tank.transform.up), n, false).ToVector(); } }
// Update is called once per frame void Update() { Coords quaternion = HolisticMath.Quaternion(axis, angle); transform.rotation *= new Quaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w); // transform.forward = HolisticMath.Rotate(new Coords(this.transform.forward,0), // 1 * Mathf.Deg2Rad,false, // 1 * Mathf.Deg2Rad,false, // 1 * Mathf.Deg2Rad,false).ToVector(); }
static public Coords GetNormal(Coords vector) { float length = HolisticMath.Distance(new Coords(0, 0, 0), vector); vector.x /= length; vector.y /= length; vector.z /= length; return(vector); }
void Start() { Vector3 rotationInRad = eulerAngles * Mathf.Deg2Rad; rotationMatrix = HolisticMath.GetRotationMatrix( new HolisticMath.Rotation(rotationInRad.x, false), new HolisticMath.Rotation(rotationInRad.y, false), new HolisticMath.Rotation(rotationInRad.z, false)); angle = HolisticMath.GetRotationAngle(rotationMatrix); axis = HolisticMath.GetRotationAxis(rotationMatrix, angle); }
public void SetAngle(string amount) { float n; if (float.TryParse(amount, out n)) { n *= Mathf.PI / 180.0f; //n *= Mathf.Deg2Rad; tank.transform.up = HolisticMath.Rotate(new NormalCoordinates(tank.transform.up), n, false).ToVector(); } }
// Update is called once per frame void Update() { if (Time.time <= 1) { ball.transform.position = trajectory.Lerp(Time.time).ToVector(); } else { ball.transform.position += trajectory.Reflect(HolisticMath.Cross(wall.v, wall.u)).ToVector() * Time.deltaTime * 2; } }
// Start is called before the first frame update void Start() { foreach (GameObject p in points) { Coords position = new Coords(p.transform.position, 1); Coords ax = new Coords(axis, 0); p.transform.position = HolisticMath.QRotate(position, ax, angle).ToVector(); } Coords.DrawLine(new Coords(0, 0, 0), new Coords(axis) * 3, 0.1f, Color.yellow); }
public Coords Reflect(Coords normal) { Coords norm = normal.GetNormal(); Coords vnorm = v.GetNormal(); float d = HolisticMath.Dot(norm, vnorm); float vn2 = d * 2; Coords r = vnorm - norm * vn2; return(r); }
public float IntersectsAt(Plane p) { var normal = HolisticMath.GetNormal(HolisticMath.Cross(p.u, p.v)); if (HolisticMath.Dot(normal, p.v) == 0) { return(float.NaN); } var t = HolisticMath.Dot(-normal, p.A - A) / HolisticMath.Dot(normal, v); return(t); }
public float IntersectsAt(Plane p) { Coords normal = HolisticMath.Cross(p.u, p.v); if (HolisticMath.Dot(normal, v) == 0) { return(float.NaN); } float t = HolisticMath.Dot(normal, p.A - A) / HolisticMath.Dot(normal, v); return(t); }
public float IntersectsAt(Plane plane) { Coords normal = HolisticMath.CrossProduct(plane.u, plane.v); if (HolisticMath.Dot(normal, V) == 0) { return(float.NaN); } float t = HolisticMath.Dot(normal, plane.A - A) / HolisticMath.Dot(normal, V); return(t); }
static public Coords Translate(Coords up, Coords position, Coords vector) { if (Distance(new Coords(0, 0, 0), vector) == 0) { return(position); } var worldup = new Coords(0, 1, 0); float worldAngle = HolisticMath.Angle(vector, worldup); float angle = Angle(vector, up); var rotate = Rotate(vector, angle + worldAngle, HolisticMath.Cross(vector, up).z < 0); return(position + rotate); }
void Update() { float translation = Input.GetAxis("Vertical") * speed; float rotation = Input.GetAxis("Horizontal") * rotationSpeed; translation *= Time.deltaTime; rotation *= Time.deltaTime; transform.position = HolisticMath.Translate(new Coords(transform.position), new Coords(transform.up), new Coords(0, translation, 0)).ToVector(); transform.up = HolisticMath.Rotate(new Coords(transform.up), rotation * Mathf.Deg2Rad, true).ToVector(); }
static public Coords LookAt2D(Coords forwardVector, Coords position, Coords focusPoint) { Coords direction = new Coords(focusPoint.X - position.X, focusPoint.Y - position.Y, position.Z); float angle = HolisticMath.Angle(forwardVector, direction); bool clockwise = false; if (HolisticMath.Cross(forwardVector, direction).Z < 0) { clockwise = true; } Coords newDir = HolisticMath.Rotate(forwardVector, angle, clockwise); return(newDir); }
public float IntersectsAt(Plane p, out bool found) { found = false; var normal = HolisticMath.GetNormal(HolisticMath.Cross(p.u, p.v)); if (HolisticMath.Dot(normal, p.v) == 0) { found = true; return(float.NaN); } var t = HolisticMath.Dot(-normal, p.A - A) / HolisticMath.Dot(normal, v); return(t); }
public float IntersectsAt(Line l) { if (HolisticMath.Dot(Coords.Perp(l.v), v) == 0) { return(float.NaN); } Coords c = l.A - this.A; float t = HolisticMath.Dot(Coords.Perp(l.v), c) / HolisticMath.Dot(Coords.Perp(l.v), v); if ((t < 0 || t > 1) && type == LINETYPE.SEGMENT) { return(float.NaN); } return(t); }