public void scale(float d)
 {
     matrix.scale(d);
 }
Beispiel #2
0
        public float EstimateBoxProjectedArea(warp_Vector pos, warp_Vector size, warp_Matrix rotation)
        {
            warp_Matrix om = new warp_Matrix();

            om.scale(size.x, size.y, size.z);
            om.transform(rotation);

            float xmax;
            float ymax;

            /*
             * if (defaultCamera.isOrthographic)
             * {
             *  xmax = Math.Abs(om.m00);
             *  ymax = Math.Abs(om.m22);
             *  if (xmax < 1f || ymax < 1f)
             *      return -1;
             *  return xmax * ymax / (width * height);
             * }
             */
            om.m03 = pos.x;
            om.m13 = pos.y;
            om.m23 = pos.z;
            warp_Vector side;
            warp_Vector v;
            float       xmin;
            float       ymin;

            warp_Matrix m = warp_Matrix.multiply(defaultCamera.getMatrix(), matrix);

            om.transform(m);

            float zmin;

            side = new warp_Vector(-1f, -1f, -1f);
            v    = side.transform(om);
            xmin = v.x;
            xmax = xmin;
            ymin = v.y;
            ymax = ymin;
            zmin = v.z;

            side.x = 1f;
            v      = side.transform(om);
            if (xmin > v.x)
            {
                xmin = v.x;
            }
            else if (xmax < v.x)
            {
                xmax = v.x;
            }
            if (ymin > v.y)
            {
                ymin = v.y;
            }
            else if (ymax < v.y)
            {
                ymax = v.y;
            }
            if (zmin > v.z)
            {
                zmin = v.z;
            }

            side.x = -1f;
            side.y = 1f;
            v      = side.transform(om);
            if (xmin > v.x)
            {
                xmin = v.x;
            }
            else if (xmax < v.x)
            {
                xmax = v.x;
            }
            if (ymin > v.y)
            {
                ymin = v.y;
            }
            else if (ymax < v.y)
            {
                ymax = v.y;
            }
            if (zmin > v.z)
            {
                zmin = v.z;
            }

            side.x = 1f;
            v      = side.transform(om);
            if (xmin > v.x)
            {
                xmin = v.x;
            }
            else if (xmax < v.x)
            {
                xmax = v.x;
            }
            if (ymin > v.y)
            {
                ymin = v.y;
            }
            else if (ymax < v.y)
            {
                ymax = v.y;
            }
            if (zmin > v.z)
            {
                zmin = v.z;
            }

            side.x = -1f;
            side.y = -1f;
            side.z = 1f;
            v      = side.transform(om);
            if (xmin > v.x)
            {
                xmin = v.x;
            }
            else if (xmax < v.x)
            {
                xmax = v.x;
            }
            if (ymin > v.y)
            {
                ymin = v.y;
            }
            else if (ymax < v.y)
            {
                ymax = v.y;
            }
            if (zmin > v.z)
            {
                zmin = v.z;
            }

            side.x = 1f;
            v      = side.transform(om);
            if (xmin > v.x)
            {
                xmin = v.x;
            }
            else if (xmax < v.x)
            {
                xmax = v.x;
            }
            if (ymin > v.y)
            {
                ymin = v.y;
            }
            else if (ymax < v.y)
            {
                ymax = v.y;
            }
            if (zmin > v.z)
            {
                zmin = v.z;
            }

            side.x = -1f;
            side.y = 1f;
            v      = side.transform(om);
            if (xmin > v.x)
            {
                xmin = v.x;
            }
            else if (xmax < v.x)
            {
                xmax = v.x;
            }
            if (ymin > v.y)
            {
                ymin = v.y;
            }
            else if (ymax < v.y)
            {
                ymax = v.y;
            }
            if (zmin > v.z)
            {
                zmin = v.z;
            }

            side.x = 1f;
            v      = side.transform(om);
            if (xmin > v.x)
            {
                xmin = v.x;
            }
            else if (xmax < v.x)
            {
                xmax = v.x;
            }
            if (ymin > v.y)
            {
                ymin = v.y;
            }
            else if (ymax < v.y)
            {
                ymax = v.y;
            }
            if (zmin > v.z)
            {
                zmin = v.z;
            }


            xmax -= xmin;
            ymax -= ymin;

            if (xmax < 1f || ymax < 1f)
            {
                return(-1);
            }
            return(xmax * ymax / (width * height));
        }