Ejemplo n.º 1
0
    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);
    }
    // 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);
    }
Ejemplo n.º 3
0
    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()
 {
     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;
     }
 }
Ejemplo n.º 5
0
    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);
    }
Ejemplo n.º 6
0
    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);
    }
Ejemplo n.º 7
0
    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);
    }
    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);
    }
Ejemplo n.º 9
0
    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);
    }
Ejemplo n.º 10
0
    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);

        /*    var direction = GetNormal(v1 + v2);
         * var angle = Angle(up, direction);
         * var rotate = Rotate(direction, angle, HolisticMath.Cross(up, direction).z < 0);
         * return v1 + (rotate); */
        float angle  = Angle(vector, up);
        var   rotate = Rotate(vector, angle + worldAngle, HolisticMath.Cross(vector, up).z < 0);

        return(position + rotate);
    }
Ejemplo n.º 11
0
    private void Start()
    {
        // If direction is declared here, the value of direction wont change each frame
        // this way, direction wont get smaller each frame and the Tank speed will be
        // constant and the tank is going to pass the fuel
        direction = fuel.transform.position - transform.position;
        Coords dirNormal = HolisticMath.GetNormal(new Coords(direction));

        direction = dirNormal.ToVector();
        float angle = HolisticMath.Angle(new Coords(transform.up), new Coords(direction)); //* 180.0f/Mathf.PI;

        //Debug.Log("Angle to fuel: " + angle);

        // green axis: transform.up
        // red axis: transform.right
        // blue axis: transform.forward

        Debug.Log("transform.up: " + transform.up);
        Debug.Log("dirNormal: " + dirNormal);

        bool clockwise = false;

        // If this cross product between transform.up and direction to goal is positive, by right hand rule
        // (going from first parameter to second parameter),
        // that indicates anti-clockwise rotation.
        // If this cross product between transform.up and direction to goal is negative, by right hand rule
        // (going from first parameter to second parameter),
        // that indicates clockwise rotation.
        if (HolisticMath.Cross(new Coords(transform.up), dirNormal).z < 0)
        {
            clockwise = true;
        }

        Coords newDir = HolisticMath.Rotate(new Coords(0, 1, 0), angle, clockwise);

        transform.up = new Vector3(newDir.x, newDir.y, newDir.z);
        Debug.Log(transform.up);
    }
    static public Coords Translate(Coords position, Coords facing, Coords vector)
    {
        if (HolisticMath.Distance(new Coords(0, 0, 0), vector) <= 0)
        {
            return(position);
        }
        float angle      = HolisticMath.Angle(vector, facing);
        float worldAngle = HolisticMath.Angle(vector, new Coords(0, 1, 0));
        bool  clockwise  = false;

        if (HolisticMath.Cross(vector, facing).z < 0)
        {
            clockwise = true;
        }

        vector = HolisticMath.Rotate(vector, angle + worldAngle, clockwise);

        float xVal = position.x + vector.x;
        float yVal = position.y + vector.y;
        float zVal = position.z + vector.z;

        return(new Coords(xVal, yVal, zVal));
    }
Ejemplo n.º 13
0
 public Coords Normal()
 {
     return(HolisticMath.Cross(v, u));
 }