Ejemplo n.º 1
0
        void rebuildMatrices()
        {
            if (!needsRebuild)
            {
                return;
            }
            needsRebuild = false;

            warp_Vector forward, up, right;

            forward = warp_Vector.sub(lookat, pos);
            up      = new warp_Vector(0f, 1f, 0f);
            right   = warp_Vector.getNormal(up, forward);
            up      = warp_Vector.getNormal(forward, right);

            forward.normalize();
            up.normalize();
            right.normalize();

            normalmatrix = new warp_Matrix(right, up, forward);
            normalmatrix.rotate(0, 0, rollfactor);
            matrix = normalmatrix.getClone();
            matrix.shift(pos.x, pos.y, pos.z);
            normalmatrix = normalmatrix.inverse();
            matrix       = matrix.inverse();
        }
 public static float angle(warp_Vector a, warp_Vector b)
 // returns the angle between 2 vectors
 {
     a.normalize();
     b.normalize();
     return(a.x * b.x + a.y * b.y + a.z * b.z);
 }
Ejemplo n.º 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);

            float fact;

            if (camera.isOrthographic)
            {
                x = (int)(pos2.x * (camera.screenscale / camera.orthoViewWidth) + (camera.screenwidth >> 1));
                y = (int)(-pos2.y * (camera.screenscale / camera.orthoViewHeight) + (camera.screenheight >> 1));
            }
            else
            {
                fact = camera.screenscale / camera.fovfact / ((pos2.z > 0.1) ? pos2.z : 0.1f);
                x    = (int)(pos2.x * fact + (camera.screenwidth >> 1));
                y    = (int)(-pos2.y * fact + (camera.screenheight >> 1));
            }

            z  = (int)(65536f * pos2.z);
            sw = -(pos2.z);
            nx = (int)(n2.x * 127 + 127);
            ny = (int)(n2.y * 127 + 127);
            if (parent.material == null)
            {
                return;
            }
            if (parent.material.texture == null)
            {
                return;
            }
            tx = (int)((float)parent.material.texture.width * u);
            ty = (int)((float)parent.material.texture.height * v);
        }
Ejemplo n.º 4
0
 public warp_Vertex(warp_Vector ppos, warp_Vector norm, float u, float v)
 {
     pos    = ppos;
     n      = norm;
     this.u = u;
     this.v = v;
 }
        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));
        }
        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));
        }
Ejemplo n.º 7
0
        public static warp_Vector scale(float f, warp_Vector a)
        // substracts 2 vectors
        {
            a.x *= f;
            a.y *= f;
            a.z *= f;

            return(a);               // maybe should return a new vector?
        }
        public static warp_Vector add(warp_Vector a, warp_Vector b)
        // adds 2 vectors
        {
            a.x += b.x;
            a.y += b.y;
            a.z += b.z;

            return(a);
        }
Ejemplo n.º 9
0
        public static warp_Vector add(warp_Vector a, warp_Vector b)
        // adds 2 vectors
        {
            a.x += b.x;
            a.y += b.y;
            a.z += b.z;

            return(a);               // maybe should return a new vector?
        }
Ejemplo n.º 10
0
        public static warp_Vector scale(float f, warp_Vector a)
        // substracts 2 vectors
        {
            a.x *= f;
            a.y *= f;
            a.z *= f;

            return(a);
        }
Ejemplo n.º 11
0
        public static warp_Vector sub(warp_Vector a, warp_Vector b)
        // substracts 2 vectors
        {
            a.x -= b.x;
            a.y -= b.y;
            a.z -= b.z;

            return(a);               // maybe should return a new vector?
        }
Ejemplo n.º 12
0
        public static warp_Vector sub(warp_Vector a, warp_Vector b)
        // substracts 2 vectors
        {
            a.x -= b.x;
            a.y -= b.y;
            a.z -= b.z;

            return(a);
        }
        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));
        }
Ejemplo n.º 14
0
        public static warp_Vector vectorProduct(warp_Vector a, warp_Vector b, warp_Vector c)
        // returns (b-a) x (c-a)
        {
            float ax = b.x - a.x;
            float ay = b.y - a.y;
            float az = b.z - a.z;

            float bx = c.x - a.x;
            float by = c.y - a.y;
            float bz = c.z - a.z;

            return(new warp_Vector(ay * bz - by * az, az * bx - bz * ax, ax * by - bx * ay));
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        public void regenerateNormal()
        {
            warp_Vector wn;
            float       rgnx = 0f;
            float       rgny = 0f;
            float       rgnz = 0f;

            for (int i = 0; i < neighbor.Count; i++)
            {
                wn    = neighbor [i].getWeightedNormal();
                rgnx += wn.x;
                rgny += wn.y;
                rgnz += wn.z;
            }

            n = new warp_Vector(rgnx, rgny, rgnz).normalize();
        }
        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));
        }
Ejemplo n.º 18
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();
        }
        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));
        }
        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));
        }
Ejemplo n.º 21
0
 public void rotate(warp_Vector v)
 {
     rotate(v.x, v.y, v.z);
 }
Ejemplo n.º 22
0
 public void rotate(float dx, float dy, float dz)
 {
     pos          = pos.transform(warp_Matrix.rotateMatrix(dx, dy, dz));
     needsRebuild = true;
 }
Ejemplo n.º 23
0
 public void shift(warp_Vector v)
 {
     shift(v.x, v.y, v.z);
 }
Ejemplo n.º 24
0
 public void shift(float dx, float dy, float dz)
 {
     pos          = pos.transform(warp_Matrix.shiftMatrix(dx, dy, dz));
     lookat       = lookat.transform(warp_Matrix.shiftMatrix(dx, dy, dz));
     needsRebuild = true;
 }
Ejemplo n.º 25
0
 public void lookAt(warp_Vector p)
 {
     lookat       = p;
     needsRebuild = true;
 }
Ejemplo n.º 26
0
 public void lookAt(float px, float py, float pz)
 {
     lookat       = new warp_Vector(px, py, pz);
     needsRebuild = true;
 }
Ejemplo n.º 27
0
 public void setPos(warp_Vector p)
 {
     pos          = p;
     needsRebuild = true;
 }
Ejemplo n.º 28
0
 public void setPos(float px, float py, float pz)
 {
     pos          = new warp_Vector(px, py, pz);
     needsRebuild = true;
 }
 public void setPos(warp_Vector pos)
 {
     flareObject.fastvertex [0].pos = pos;
 }
Ejemplo n.º 30
0
 public static warp_Vector vectorProduct(warp_Vector a, warp_Vector b)
 // returns a x b
 {
     return(new warp_Vector(a.y * b.z - b.y * a.z, a.z * b.x - b.z * a.x, a.x * b.y - b.x * a.y));
 }