示例#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);
    }
    // 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); */
    }
示例#4
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);
    }
示例#5
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);
    }
示例#6
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);
    }