예제 #1
0
        public box(Vector3 _position, Vector3 _dimensions, int _color, Quaternion _rotation, float _absorption = 1, float _refraction = 0)
        {
            position   = _position;
            dimensions = _dimensions / 2;
            color      = _color;
            rotation   = _rotation;
            rotation.Normalize();
            absorption = _absorption;
            refraction = _refraction;

            Vector3 right   = rotation * Vector3.UnitX;
            Vector3 up      = rotation * Vector3.UnitY;
            Vector3 forward = rotation * Vector3.UnitZ;

            //Create vertices
            vertices    = new Vector3[8];
            vertices[0] = position - forward * dimensions.Z + up * dimensions.Y - right * dimensions.X;
            vertices[1] = position - forward * dimensions.Z + up * dimensions.Y + right * dimensions.X;
            vertices[2] = position - forward * dimensions.Z - up * dimensions.Y - right * dimensions.X;
            vertices[3] = position - forward * dimensions.Z - up * dimensions.Y + right * dimensions.X;
            vertices[4] = position + forward * dimensions.Z + up * dimensions.Y - right * dimensions.X;
            vertices[5] = position + forward * dimensions.Z + up * dimensions.Y + right * dimensions.X;
            vertices[6] = position + forward * dimensions.Z - up * dimensions.Y - right * dimensions.X;
            vertices[7] = position + forward * dimensions.Z - up * dimensions.Y + right * dimensions.X;

            //Create triangles based on vertices
            shape     = new triangle[12];
            shape[0]  = new triangle(0, 2, 1, _color, _absorption);
            shape[1]  = new triangle(1, 2, 3, _color, _absorption);
            shape[2]  = new triangle(0, 1, 4, _color, _absorption);
            shape[3]  = new triangle(1, 5, 4, _color, _absorption);
            shape[4]  = new triangle(1, 7, 5, _color, _absorption);
            shape[5]  = new triangle(1, 3, 7, _color, _absorption);
            shape[6]  = new triangle(2, 6, 3, _color, _absorption);
            shape[7]  = new triangle(6, 7, 3, _color, _absorption);
            shape[8]  = new triangle(0, 4, 6, _color, _absorption);
            shape[9]  = new triangle(0, 6, 2, _color, _absorption);
            shape[10] = new triangle(4, 5, 6, _color, _absorption);
            shape[11] = new triangle(6, 5, 7, _color, _absorption);
        }
예제 #2
0
        // initialize
        public void Init()
        {
            //load texture and find the colors for every pixel
            map = new Surface("../../assets/dark.png");
            c   = new float[640, 640][];
            texture(floatbuffer, c, map);

            //lights startvalues: x,y,r,g,b
            lightbuffer[0]  = TX(-1.5f);
            lightbuffer[1]  = TY(1.5f);
            lightbuffer[2]  = 0f;
            lightbuffer[3]  = 15f;
            lightbuffer[4]  = 15f;
            lightbuffer[5]  = TX(1.5f);
            lightbuffer[6]  = TY(-1.5f);
            lightbuffer[7]  = 15f;
            lightbuffer[8]  = 15f;
            lightbuffer[9]  = 0f;
            lightbuffer[10] = TX(1.5f);
            lightbuffer[11] = TY(1.5f);
            lightbuffer[12] = 15f;
            lightbuffer[13] = 0f;
            lightbuffer[14] = 15f;
            lightbuffer[15] = TX(-1.5f);
            lightbuffer[16] = TY(-1.5f);
            lightbuffer[17] = 15f;
            lightbuffer[18] = 0f;
            lightbuffer[19] = 0f;

            //box declaration, top-left align
            box b1 = new box();

            b1.X    = -1.1f;
            b1.Y    = -0.6f;
            b1.W    = 0.2f;
            b1.H    = 0.2f;
            b1.X2   = b1.X + b1.W;
            b1.Y2   = b1.Y + b1.H;
            b1.C    = MixColor(1, 1, 0);
            b1.TYPE = "box";
            box b2 = new box();

            b2.X    = -0.7f;
            b2.Y    = -1f;
            b2.W    = 0.6f;
            b2.H    = 0.2f;
            b2.X2   = b2.X + b2.W;
            b2.Y2   = b2.Y + b2.H;
            b2.C    = MixColor(1, 1, 0);
            b2.TYPE = "box";
            box b3 = new box();

            b3.X    = 0.1f;
            b3.Y    = -1f;
            b3.W    = 0.6f;
            b3.H    = 0.2f;
            b3.X2   = b3.X + b3.W;
            b3.Y2   = b3.Y + b3.H;
            b3.C    = MixColor(1, 1, 0);
            b3.TYPE = "box";
            box b4 = new box();

            b4.X    = 0.9f;
            b4.Y    = -0.6f;
            b4.W    = 0.2f;
            b4.H    = 0.2f;
            b4.X2   = b4.X + b4.W;
            b4.Y2   = b4.Y + b4.H;
            b4.C    = MixColor(1, 1, 0);
            b4.TYPE = "box";

            //triangle declaration, top-left bounding box align
            triangle tr1 = new triangle();

            tr1.X    = -0.3f;
            tr1.Y    = 0.2f;
            tr1.W    = 0.6f;
            tr1.H    = 0.4f;
            tr1.XT   = tr1.X + (tr1.W / 2);
            tr1.C    = MixColor(0.8f, 0.2f, 0.2f);
            tr1.TYPE = "triangle";

            //circle declaration, center align
            circle circ1 = new circle();

            circ1.X    = -0.6f;
            circ1.Y    = 0.8f;
            circ1.W    = 0.5f;
            circ1.H    = circ1.W;
            circ1.POS  = new Vector2(circ1.X, circ1.Y);
            circ1.R    = circ1.W / 2;
            circ1.C    = MixColor(1, 0.5f, 0.5f);
            circ1.TYPE = "circle";

            circle circ2 = new circle();

            circ2.X    = 0.6f;
            circ2.Y    = 0.8f;
            circ2.W    = 0.5f;
            circ2.H    = circ1.W;
            circ2.POS  = new Vector2(circ2.X, circ2.Y);
            circ2.R    = circ1.W / 2;
            circ2.C    = MixColor(1, 0.5f, 0.5f);
            circ2.TYPE = "circle";

            //add primitives to List
            prim.Add(b1);
            prim.Add(b2);
            prim.Add(b3);
            prim.Add(b4);
            prim.Add(tr1);
            prim.Add(circ1);
            prim.Add(circ2);
        }