Ejemplo n.º 1
0
        public void project(warp_Matrix vertexProjection, warp_Matrix normalProjection, warp_Camera camera)
        // Projects this vertex into camera space
        {
            pos2 = pos.transform(vertexProjection);
            n2   = n.transform(normalProjection);

            if (pos2.z < 0.001f && pos2.z > -0.0001f)
            {
                pos2.z = 0.001f;
            }

            if (camera.isOrthographic)
            {
                x    = (int)pos2.x;
                y    = (int)pos2.y;
                invZ = -1.0f;
                tx   = -u;
                ty   = -v;
            }
            else
            {
                invZ = 1.0f / pos2.z;
                x    = (int)(pos2.x * invZ + camera.halfscreenwidth);
                y    = (int)(pos2.y * invZ + camera.halfscreenheight);
                invZ = -invZ;
                tx   = u * invZ;
                ty   = v * invZ;
            }

            z  = (int)(65536f * pos2.z);
            nx = ((int)(n2.x * 127 + 127)) << 16;
            ny = ((int)(n2.y * 127 + 127)) << 16;
        }
Ejemplo n.º 2
0
 public void rotate(float dx, float dy, float dz)
 {
     pos          = pos.transform(warp_Matrix.rotateMatrix(dx, dy, dz));
     needsRebuild = true;
 }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
 public void project(warp_Matrix normalProjection)
 {
     n2    = n.transform(normalProjection);
     distZ = getDistZ();
 }
Ejemplo n.º 5
0
 public void project(warp_Matrix m)
 {
     matrix2 = m.getClone();
     matrix2.transform(m);
     v2 = v.transform(matrix2);
 }