示例#1
0
        void rebuildMatrices()
        {
            if (!needsRebuild)
            {
                return;
            }
            needsRebuild = false;

            warp_Vector forward, up, right;

            forward = warp_Vector.sub(lookat, pos);
            if (Math.Abs(forward.x) < 0.001f && Math.Abs(forward.z) < 0.001f)
            {
                right = new warp_Vector(1f, 0f, 0f);
                if (forward.y < 0)
                {
                    up = new warp_Vector(0f, 0f, 1f);
                }
                else
                {
                    up = new warp_Vector(0f, 0f, -1f);
                }
            }
            else
            {
                up    = new warp_Vector(0f, 1f, 0f);
                right = warp_Vector.getNormal(up, forward);
                up    = warp_Vector.getNormal(forward, right);
            }

            forward.normalize();
            normalmatrix = new warp_Matrix(right, up, forward);
            if (rollfactor != 0)
            {
                normalmatrix.rotate(0, 0, rollfactor);
            }
            matrix = normalmatrix.getClone();
            matrix.shift(pos.x, pos.y, pos.z);
            matrix = matrix.inverse();

            normalmatrix = normalmatrix.inverse();
            if (isOrthographic)
            {
                projmatrix.m00 = screenwidth / orthoViewWidth;
                projmatrix.m03 = halfscreenwidth;
                projmatrix.m11 = -screenheight / orthoViewHeight;
                projmatrix.m13 = halfscreenheight;
                projmatrix.m22 = 1.0f;
            }
            else
            {
                float screenscale = (screenwidth < screenheight) ? screenwidth : screenheight;
                projmatrix.m00 = screenscale / fovfact;
                projmatrix.m03 = 0;
                projmatrix.m11 = -screenscale / fovfact;
                projmatrix.m13 = 0;
                projmatrix.m22 = 1.0f;
            }
            matrix = warp_Matrix.multiply(projmatrix, matrix);
        }
示例#2
0
 public warp_Vertex(warp_Vector ppos, warp_Vector norm, float u, float v)
 {
     pos    = ppos.getClone();
     n      = norm.getClone();
     this.u = u;
     this.v = v;
 }
示例#3
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;
        }
示例#4
0
        public warp_Vector getDimension()
        // Returns the x,y,z - Dimension of this object
        {
            warp_Vector max = maximum();
            warp_Vector min = minimum();

            return(new warp_Vector(max.x - min.x, max.y - min.y, max.z - min.z));
        }
示例#5
0
        public warp_Vector getCenter()
        // Returns the center of this object
        {
            warp_Vector max = maximum();
            warp_Vector min = minimum();

            return(new warp_Vector((max.x + min.x) / 2, (max.y + min.y) / 2, (max.z + min.z) / 2));
        }
示例#6
0
 public warp_Light(warp_Vector direction, int diffuse, int specular, int highlightSheen, int highlightSpread)
 {
     v = direction.getClone();
     v.normalize();
     this.diffuse         = diffuse;
     this.specular        = specular;
     this.highlightSheen  = highlightSheen;
     this.highlightSpread = highlightSpread;
 }
示例#7
0
        public static warp_Object CONE(float height, float radius, int segments)
        {
            warp_Vector[] path = new warp_Vector[4];
            float         h    = height / 2;

            path[0] = new warp_Vector(0, h, 0);
            path[1] = new warp_Vector(radius, -h, 0);
            path[2] = new warp_Vector(radius, -h, 0);
            path[3] = new warp_Vector(0, -h, 0);

            return(ROTATIONOBJECT(path, segments));
        }
示例#8
0
 public warp_Matrix(warp_Vector right, warp_Vector up, warp_Vector forward)
 {
     m00 = right.x;
     m10 = right.y;
     m20 = right.z;
     m01 = up.x;
     m11 = up.y;
     m21 = up.z;
     m02 = forward.x;
     m12 = forward.y;
     m22 = forward.z;
 }
示例#9
0
        public static void projectCylindric(warp_Object obj)
        {
            obj.rebuild();
            warp_Vector min = obj.minimum();
            warp_Vector max = obj.maximum();
            float       dz  = 1 / (max.z - min.z);

            for (int i = 0; i < obj.vertices; i++)
            {
                obj.fastvertex[i].pos.buildCylindric();
                obj.fastvertex[i].u = obj.fastvertex[i].pos.theta / (2 * 3.14159265f);
                obj.fastvertex[i].v = (obj.fastvertex[i].pos.z - min.z) * dz;
            }
        }
示例#10
0
        public static void projectFrontal(warp_Object obj)
        {
            obj.rebuild();
            warp_Vector min = obj.minimum();
            warp_Vector max = obj.maximum();
            float       du  = 1 / (max.x - min.x);
            float       dv  = 1 / (max.y - min.y);

            for (int i = 0; i < obj.vertices; i++)
            {
                obj.fastvertex[i].u = (obj.fastvertex[i].pos.x - min.x) * du;
                obj.fastvertex[i].v = 1 - (obj.fastvertex[i].pos.y - min.y) * dv;
            }
        }
示例#11
0
        public static warp_Object TORUSKNOT(float p, float q, float r_tube, float r_out, float r_in, float h, int segments, int steps)
        {
            float x, y, z, r, t, theta;

            warp_Vector[] path = new warp_Vector[segments + 1];
            for (int i = 0; i < segments + 1; i++)
            {
                t       = 2 * 3.14159265f * i / (float)segments;
                r       = r_out + r_in * warp_Math.cos(p * t);
                z       = h * warp_Math.sin(p * t);
                theta   = q * t;
                x       = r * warp_Math.cos(theta);
                y       = r * warp_Math.sin(theta);
                path[i] = new warp_Vector(x, y, z);
            }
            return(TUBE(path, r_tube, steps, true));
        }
示例#12
0
        public void detach()
        // Centers the object in its coordinate system
        // The offset from origin to object center will be transfered to the matrix,
        // so your object actually does not move.
        // Usefull if you want prepare objects for self rotation.
        {
            warp_Vector center = getCenter();

            for (int i = 0; i < vertices; i++)
            {
                fastvertex[i].pos.x -= center.x;
                fastvertex[i].pos.y -= center.y;
                fastvertex[i].pos.z -= center.z;
            }

            shift(center);
        }
示例#13
0
        public void DisplayDefaultScene()
        {
            _scene = new warp_Scene(512, 512);

            warp_Material crystal = new warp_Material(warp_TextureFactory.MARBLE(128, 128, .15f));

            _scene.addMaterial("crystal", crystal);

            warp_Material c = (warp_Material)_scene.materialData["crystal"];

            c.setReflectivity(255);
            c.setTransparency(100);

            _scene.environment.setBackground(warp_TextureFactory.CHECKERBOARD(128, 128, 3, 0x000000, 0x999999));

            _scene.addLight("light1", new warp_Light(new warp_Vector(0.2f, 0.2f, 1f), 0xFFFFFF, 320, 80));
            _scene.addLight("light2", new warp_Light(new warp_Vector(-1f, -1f, 1f), 0xffffff, 100, 40));

            warp_Vector[] path = new warp_Vector[15];

            path[0]  = new warp_Vector(0.0f, 0.2f, 0);
            path[1]  = new warp_Vector(0.13f, 0.25f, 0);
            path[2]  = new warp_Vector(0.33f, 0.3f, 0);
            path[3]  = new warp_Vector(0.43f, 0.6f, 0);
            path[4]  = new warp_Vector(0.48f, 0.9f, 0);
            path[5]  = new warp_Vector(0.5f, 0.9f, 0);
            path[6]  = new warp_Vector(0.45f, 0.6f, 0);
            path[7]  = new warp_Vector(0.35f, 0.3f, 0);
            path[8]  = new warp_Vector(0.25f, 0.2f, 0);
            path[9]  = new warp_Vector(0.1f, 0.15f, 0);
            path[10] = new warp_Vector(0.1f, 0.0f, 0);
            path[11] = new warp_Vector(0.1f, -0.5f, 0);
            path[12] = new warp_Vector(0.35f, -0.55f, 0);
            path[13] = new warp_Vector(0.4f, -0.6f, 0);
            path[14] = new warp_Vector(0.0f, -0.6f, 0);

            _scene.addObject("wineglass", warp_ObjectFactory.ROTATIONOBJECT(path, 32));
            _scene.sceneobject("wineglass").setMaterial(_scene.material("crystal"));

            _scene.sceneobject("wineglass").scale(0.8f, 0.8f, 0.8f);
            _scene.sceneobject("wineglass").rotate(0.5f, 0f, 0f);

            _scene.render();

            //Refresh();
        }
示例#14
0
        public void regenerateNormal()
        {
            float nx = 0;
            float ny = 0;
            float nz = 0;

            for (int i = 0; i < neighbor.Count; ++i)
            {
                warp_Triangle tri = neighbor[i];
                warp_Vector   wn  = tri.rawNorm;
                nx += wn.x;
                ny += wn.y;
                nz += wn.z;
            }

            n = new warp_Vector(nx, ny, nz).normalize();
        }
示例#15
0
        public static warp_Object SPIRAL(float h, float r_out, float r_in,
                                         float r_tube, float w, float f,
                                         int segments, int steps)
        {
            float x, y, z, r, t, theta;

            warp_Vector[] path = new warp_Vector[segments + 1];
            for (int i = 0; i < segments + 1; i++)
            {
                t       = (float)i / (float)segments;
                r       = r_out + r_in * warp_Math.sin(2 * 3.14159265f * f * t);
                z       = (h / 2) + h * t;
                theta   = 2 * 3.14159265f * w * t;
                x       = r * warp_Math.cos(theta);
                y       = r * warp_Math.sin(theta);
                path[i] = new warp_Vector(x, y, z);
            }
            return(TUBE(path, r_tube, steps, false));
        }
示例#16
0
        public static warp_Object SPHERE(float radius, int segments)
        {
            warp_Vector[] path = new warp_Vector[segments];

            float x, y, angle;

            path[0]            = new warp_Vector(0, radius, 0);
            path[segments - 1] = new warp_Vector(0, -radius, 0);

            for (int i = 1; i < segments - 1; i++)
            {
                angle = -(((float)i / (float)(segments - 2)) - 0.5f) *
                        3.14159265f;
                x       = (float)Math.Cos(angle) * radius;
                y       = (float)Math.Sin(angle) * radius;
                path[i] = new warp_Vector(x, y, 0);
            }

            return(ROTATIONOBJECT(path, segments));
        }
示例#17
0
 public static warp_Vector getNormal(warp_Vector a, warp_Vector b, warp_Vector c)
 // returns the normal vector of the plane defined by the two vectors
 {
     return(vectorProduct(a, b, c).normalize());
 }
示例#18
0
 public void rotate(warp_Vector v)
 {
     rotate(v.x, v.y, v.z);
 }
示例#19
0
 public void rotate(float dx, float dy, float dz)
 {
     pos          = pos.transform(warp_Matrix.rotateMatrix(dx, dy, dz));
     needsRebuild = true;
 }
示例#20
0
 public void shift(warp_Vector v)
 {
     shift(v.x, v.y, v.z);
 }
示例#21
0
 public void lookAt(warp_Vector p)
 {
     lookat       = p;
     needsRebuild = true;
 }
示例#22
0
 public void lookAt(float px, float py, float pz)
 {
     lookat       = new warp_Vector(px, py, pz);
     needsRebuild = true;
 }