Beispiel #1
0
        public Vector3 rotate(Common.Rotation rotation)
        {
            double tmp;

            switch (rotation)
            {
            case Common.Rotation.ROTATION_NONE:
            case Common.Rotation.ROTATION_MAX:
                return(this);

            case Common.Rotation.ROTATION_YAW_45:
            {
                tmp = HALF_SQRT_2 * (x - y);
                y   = HALF_SQRT_2 * (x + y);
                x   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_YAW_90:
            {
                tmp = x;
                x   = -y;
                y   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_YAW_135:
            {
                tmp = -HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (x - y);
                x   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_YAW_180:
                x = -x;
                y = -y;
                return(this);

            case Common.Rotation.ROTATION_YAW_225:
            {
                tmp = HALF_SQRT_2 * (y - x);
                y   = -HALF_SQRT_2 * (x + y);
                x   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_YAW_270:
            {
                tmp = x;
                x   = y;
                y   = -tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_YAW_315:
            {
                tmp = HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (y - x);
                x   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_180:
            {
                y = -y;
                z = -z;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_45:
            {
                tmp = HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (x - y);
                x   = tmp;
                z   = -z;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_90:
            {
                tmp = x;
                x   = y;
                y   = tmp;
                z   = -z;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_135:
            {
                tmp = HALF_SQRT_2 * (y - x);
                y   = HALF_SQRT_2 * (y + x);
                x   = tmp;
                z   = -z;
                return(this);
            }

            case Common.Rotation.ROTATION_PITCH_180:
            {
                x = -x;
                z = -z;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_225:
            {
                tmp = -HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (y - x);
                x   = tmp;
                z   = -z;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_270:
            {
                tmp = x;
                x   = -y;
                y   = -tmp;
                z   = -z;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_315:
            {
                tmp = HALF_SQRT_2 * (x - y);
                y   = -HALF_SQRT_2 * (x + y);
                x   = tmp;
                z   = -z;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_90:
            {
                tmp = z;
                z   = y;
                y   = -tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_90_YAW_45:
            {
                tmp = z;
                z   = y;
                y   = -tmp;
                tmp = HALF_SQRT_2 * (x - y);
                y   = HALF_SQRT_2 * (x + y);
                x   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_90_YAW_90:
            {
                tmp = z;
                z   = y;
                y   = -tmp;
                tmp = x;
                x   = -y;
                y   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_90_YAW_135:
            {
                tmp = z;
                z   = y;
                y   = -tmp;
                tmp = -HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (x - y);
                x   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_270:
            {
                tmp = z;
                z   = -y;
                y   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_270_YAW_45:
            {
                tmp = z;
                z   = -y;
                y   = tmp;
                tmp = HALF_SQRT_2 * (x - y);
                y   = HALF_SQRT_2 * (x + y);
                x   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_270_YAW_90:
            {
                tmp = z;
                z   = -y;
                y   = tmp;
                tmp = x;
                x   = -y;
                y   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_ROLL_270_YAW_135:
            {
                tmp = z;
                z   = -y;
                y   = tmp;
                tmp = -HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (x - y);
                x   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_PITCH_90:
            {
                tmp = z;
                z   = -x;
                x   = tmp;
                return(this);
            }

            case Common.Rotation.ROTATION_PITCH_270:
            {
                tmp = z;
                z   = x;
                x   = -tmp;
                return(this);
            }
            }
            throw new Exception("Invalid Rotation");
            //return this;
        }
Beispiel #2
0
        void rotate(Common.Rotation rotation)
        {
            double tmp;

            switch (rotation)
            {
            case Common.Rotation.ROTATION_NONE:
            case Common.Rotation.ROTATION_MAX:
                return;

            case Common.Rotation.ROTATION_YAW_45:
            {
                tmp = HALF_SQRT_2 * (x - y);
                y   = HALF_SQRT_2 * (x + y);
                x   = tmp;
                return;
            }

            case Common.Rotation.ROTATION_YAW_90:
            {
                tmp = x; x = -y; y = tmp;
                return;
            }

            case Common.Rotation.ROTATION_YAW_135:
            {
                tmp = -HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (x - y);
                x   = tmp;
                return;
            }

            case Common.Rotation.ROTATION_YAW_180:
                x = -x; y = -y;
                return;

            case Common.Rotation.ROTATION_YAW_225:
            {
                tmp = HALF_SQRT_2 * (y - x);
                y   = -HALF_SQRT_2 * (x + y);
                x   = tmp;
                return;
            }

            case Common.Rotation.ROTATION_YAW_270:
            {
                tmp = x; x = y; y = -tmp;
                return;
            }

            case Common.Rotation.ROTATION_YAW_315:
            {
                tmp = HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (y - x);
                x   = tmp;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_180:
            {
                y = -y; z = -z;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_45:
            {
                tmp = HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (x - y);
                x   = tmp; z = -z;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_90:
            {
                tmp = x; x = y; y = tmp; z = -z;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_135:
            {
                tmp = HALF_SQRT_2 * (y - x);
                y   = HALF_SQRT_2 * (y + x);
                x   = tmp; z = -z;
                return;
            }

            case Common.Rotation.ROTATION_PITCH_180:
            {
                x = -x; z = -z;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_225:
            {
                tmp = -HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (y - x);
                x   = tmp; z = -z;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_270:
            {
                tmp = x; x = -y; y = -tmp; z = -z;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_180_YAW_315:
            {
                tmp = HALF_SQRT_2 * (x - y);
                y   = -HALF_SQRT_2 * (x + y);
                x   = tmp; z = -z;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_90:
            {
                tmp = z; z = y; y = -tmp;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_90_YAW_45:
            {
                tmp = z; z = y; y = -tmp;
                tmp = HALF_SQRT_2 * (x - y);
                y   = HALF_SQRT_2 * (x + y);
                x   = tmp;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_90_YAW_90:
            {
                tmp = z; z = y; y = -tmp;
                tmp = x; x = -y; y = tmp;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_90_YAW_135:
            {
                tmp = z; z = y; y = -tmp;
                tmp = -HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (x - y);
                x   = tmp;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_270:
            {
                tmp = z; z = -y; y = tmp;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_270_YAW_45:
            {
                tmp = z; z = -y; y = tmp;
                tmp = HALF_SQRT_2 * (x - y);
                y   = HALF_SQRT_2 * (x + y);
                x   = tmp;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_270_YAW_90:
            {
                tmp = z; z = -y; y = tmp;
                tmp = x; x = -y; y = tmp;
                return;
            }

            case Common.Rotation.ROTATION_ROLL_270_YAW_135:
            {
                tmp = z; z = -y; y = tmp;
                tmp = -HALF_SQRT_2 * (x + y);
                y   = HALF_SQRT_2 * (x - y);
                x   = tmp;
                return;
            }

            case Common.Rotation.ROTATION_PITCH_90:
            {
                tmp = z; z = -x; x = tmp;
                return;
            }

            case Common.Rotation.ROTATION_PITCH_270:
            {
                tmp = z; z = x; x = -tmp;
                return;
            }
            }
        }