Beispiel #1
0
    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();
    }
Beispiel #2
0
    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()
    {
        //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);
    }
Beispiel #4
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);
    }
Beispiel #5
0
    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();
        }
    }
    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();
        }
    }
    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);
    }
    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();
    }
    // Start is called before the first frame update
    void Start()
    {
        angle = angle * Mathf.Deg2Rad;
        foreach (GameObject p in points)
        {
            Coords position = new Coords(p.transform.position, 1);
            p.transform.position = HolisticMath.Rotate(position, angle.x, true, angle.y, true, angle.z, true).ToVector();
        }

        Matrix rot      = HolisticMath.GetRotationMatrix(angle.x, true, angle.y, true, angle.z, true);
        float  rotAngle = HolisticMath.GetRotationAxisAngle(rot);
        Coords rotAxis  = HolisticMath.GetRotationAxis(rot, rotAngle);

        Debug.Log(rotAngle * Mathf.Rad2Deg + " about " + rotAxis.ToString());
        Coords.DrawLine(new Coords(0, 0, 0), rotAxis * 5, 0.1f, Color.yellow);
    }
Beispiel #10
0
    // Start is called before the first frame update
    void Start()
    {
        angle = angle * Mathf.Deg2Rad;
        foreach (var point in points)
        {
            Coords position = new Coords(point.transform.position, 1);
            point.transform.position = HolisticMath.Rotate(position, new HolisticMath.Rotation(angle.x), new HolisticMath.Rotation(angle.y), new HolisticMath.Rotation(angle.z)).ToVector();
        }

        Matrix rotation = HolisticMath.GetRotationMatrix(new HolisticMath.Rotation(angle.x), new HolisticMath.Rotation(angle.y), new HolisticMath.Rotation(angle.z));
        float  rotAngle = HolisticMath.GetRotationAngle(rotation);
        var    axis     = HolisticMath.GetRotationAxis(rotation, rotAngle);

        Debug.Log(rotAngle * Mathf.Rad2Deg + " about " + axis.ToString());

        Coords.DrawLine(new Coords(0, 0, 0), axis * 5, 0.1f, Color.yellow);
    }
Beispiel #11
0
    // Start is called before the first frame update
    void Start()
    {
        angle = angle * Mathf.Deg2Rad;
        foreach (GameObject point in points)
        {
            Coords position = new Coords(point.transform.position, 1);
            Coords axis     = new Coords(rotaionAxis, 0);
            // rotaion is applied to the position.
            point.transform.position = HolisticMath.Rotate(position, angle.x, true, angle.y, true, angle.z, true).ToVector();
        }
        Matrix rot       = HolisticMath.GetRotaionMatrix(angle.x, true, angle.y, true, angle.z, true);
        float  angle2    = HolisticMath.GetRotaionAxisAngle(rot);
        Coords angleAxis = HolisticMath.GetRotationAxis(rot, angle2);

        Coords.DrawLine(new Coords(Vector3.zero), (angleAxis) * 3, 0.1f, Color.yellow);
        Debug.Log("Axis" + angleAxis.ToString());
        Debug.Log("Angle" + angle2);
    }
    // Start is called before the first frame update
    void Start()
    {
        Vector3 c = new Vector3(center.transform.position.x, center.transform.position.y, center.transform.position.z);

        foreach (GameObject point in points)
        {
            Coords pos = new Coords(point.transform.position, 1);
            pos = HolisticMath.Translate(pos, new Coords(new Vector3(-c.x, -c.y, -c.z), 0));
            pos = HolisticMath.Rotate(pos, angle.x, true, angle.y, true, angle.z, true);
            point.transform.position = HolisticMath.Translate(pos,
                                                              new Coords(new Vector3(c.x, c.y, c.z), 0)).ToVector();

            // point.transform.position = HolisticMath.Translate(pos,
            // new Coords(new Vector3(translation.x,translation.y,translation.z),0)).ToVector();
            // pos = HolisticMath.ScaleTransForm(pos,scale.x,scale.y,scale.z);
            // point.transform.position = HolisticMath.Translate(pos,
            // new Coords(new Vector3(c.x,c.y,c.z),0)).ToVector();
        }
    }
Beispiel #13
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));
    }