예제 #1
0
        public Sfera(float radius, uint subdivisions, Vec4 color)
        {
            Mesh        ico20 = BuildIcosahedron(radius, color);
            Queue <Tri> tris  = new Queue <Tri>();

            foreach (var item in ico20)
            {
                tris.Enqueue(item);
            }

            uint j = 0;

            while (subdivisions > j)
            {
                for (int i = 0; i < 20 * Math.Pow(4, j); i++)
                {
                    Tri         t     = tris.Dequeue();
                    Wierzcholek newV0 = ComputeHalfVertex(t.W0, t.W1, radius);
                    Wierzcholek newV1 = ComputeHalfVertex(t.W1, t.W2, radius);
                    Wierzcholek newV2 = ComputeHalfVertex(t.W2, t.W0, radius);

                    tris.Enqueue(new Tri(t.W0, newV0, newV2, t.KS, t.KD, t.N));
                    tris.Enqueue(new Tri(t.W1, newV1, newV0, t.KS, t.KD, t.N));
                    tris.Enqueue(new Tri(t.W2, newV2, newV1, t.KS, t.KD, t.N));
                    tris.Enqueue(new Tri(newV0, newV1, newV2, t.KS, t.KD, t.N));
                }
                j++;
            }
            foreach (var item in tris)
            {
                Trojkaty.Add(item);
            }
        }
예제 #2
0
        private Wierzcholek ComputeHalfVertex(Wierzcholek v1, Wierzcholek v2, float radius)
        {
            Vec3  newV  = v1.Position + v2.Position;
            float scale = radius / (float)Math.Sqrt(newV.X * newV.X + newV.Y * newV.Y + newV.Z * newV.Z);

            newV *= scale;
            return(new Wierzcholek(newV, (v1.Color + v2.Color) / 2));
        }
        private Wierzcholek Linia(Vec3 planePoint, Vec3 planeNormal, Wierzcholek lineStart, Wierzcholek lineEnd)
        {
            planeNormal = planeNormal.Normal();

            float plane_d          = -planeNormal.Dot(planePoint);
            float ad               = lineStart.Position.Dot(planeNormal);
            float bd               = lineEnd.Position.Dot(planeNormal);
            float t                = (-plane_d - ad) / (bd - ad);
            Vec3  lineStartToEnd   = lineEnd.Position - lineStart.Position;
            Vec4  colorStartToEnd  = lineEnd.Color - lineStart.Color;
            Vec3  lineToIntersect  = lineStartToEnd * t;
            Vec4  colorToIntersect = colorStartToEnd * t;

            return(new Wierzcholek(lineStart.Position + lineToIntersect, lineStart.Color + colorToIntersect));
        }
예제 #4
0
        public Bryly()
        {
            //wektory szescianu
            Vec3 v00 = new Vec3(0, 0, 0);
            Vec3 v01 = new Vec3(0, 0, 1);
            Vec3 v02 = new Vec3(0, 1, 0);
            Vec3 v03 = new Vec3(0, 1, 1);
            Vec3 v04 = new Vec3(1, 0, 0);
            Vec3 v05 = new Vec3(1, 0, 1);
            Vec3 v06 = new Vec3(1, 1, 0);
            Vec3 v07 = new Vec3(1, 1, 1);
            Vec3 v10 = new Vec3(0, 0, 0);
            Vec3 v11 = new Vec3(0, 0, 1);
            //wektory kolumny
            Vec3 v12 = new Vec3(0, 10, 0);
            Vec3 v13 = new Vec3(0, 10, 1);
            Vec3 v14 = new Vec3(1, 0, 0);
            Vec3 v15 = new Vec3(1, 0, 1);
            Vec3 v16 = new Vec3(1, 10, 0);
            Vec3 v17 = new Vec3(1, 10, 1);


            Wierzcholek w1      = new Wierzcholek(v00, (Vec4)(Color.Blue + Color.Green));
            Wierzcholek w2      = new Wierzcholek(v01, (Vec4)(Color.Blue + Color.Green));
            Wierzcholek w3      = new Wierzcholek(v02, (Vec4)(Color.Blue + Color.Green));
            Wierzcholek w4      = new Wierzcholek(v03, (Vec4)(Color.Blue + Color.Green));
            Wierzcholek w5      = new Wierzcholek(v04, (Vec4)(Color.Blue + Color.Green));
            Wierzcholek w6      = new Wierzcholek(v05, (Vec4)(Color.Blue + Color.Green));
            Wierzcholek w7      = new Wierzcholek(v06, (Vec4)(Color.Blue + Color.Green));
            Wierzcholek w8      = new Wierzcholek(v07, (Vec4)(Color.Blue + Color.Green));
            Mesh        kolumna = new Mesh()
            {
                new Tri(v10, v12, v16, (Vec4)Color.White),
                new Tri(v10, v16, v14, (Vec4)Color.White),
                new Tri(v14, v16, v17, (Vec4)Color.White),
                new Tri(v14, v17, v15, (Vec4)Color.White),
                new Tri(v15, v17, v13, (Vec4)Color.White),
                new Tri(v15, v13, v11, (Vec4)Color.White),
                new Tri(v11, v13, v12, (Vec4)Color.White),
                new Tri(v11, v12, v10, (Vec4)Color.White),
                new Tri(v12, v13, v17, (Vec4)Color.White),
                new Tri(v12, v17, v16, (Vec4)Color.White),
                new Tri(v15, v11, v10, (Vec4)Color.White),
                new Tri(v15, v10, v15, (Vec4)Color.White)
            };
            Mesh szescian = new Mesh()
            {
                new Tri(w1, w3, w7),
                new Tri(w1, w7, w5),
                new Tri(w5, w7, w8),
                new Tri(w5, w8, w6),
                new Tri(w6, w8, w4),
                new Tri(w6, w4, w2),
                new Tri(w2, w4, w3),
                new Tri(w2, w3, w1),
                new Tri(w3, w4, w8),
                new Tri(w3, w8, w7),
                new Tri(w6, w2, w1),
                new Tri(w6, w1, w5),
            };

            kolumna.Origin  = new Vec3(0, 0, 0);
            szescian.Origin = new Vec3(0, 0, 0);
            Vec3 przenies = new Vec3(-1, 0, -1);

            szescian.Position = przenies;
            kolumna.Position  = new Vec3(1, 0.5f, 1);
            szescian.Scale    = new Vec3(5, 3, 5);
            //ps5
            Mesh lewastrona = new Mesh()
            {
                new Tri(v10, v12, v16, (Vec4)Color.White),
                new Tri(v10, v16, v14, (Vec4)Color.White),
                new Tri(v14, v16, v17, (Vec4)Color.White),
                new Tri(v14, v17, v15, (Vec4)Color.White),
                new Tri(v15, v17, v13, (Vec4)Color.White),
                new Tri(v15, v13, v11, (Vec4)Color.White),
                new Tri(v11, v13, v12, (Vec4)Color.White),
                new Tri(v11, v12, v10, (Vec4)Color.White),
                new Tri(v12, v13, v17, (Vec4)Color.White),
                new Tri(v12, v17, v16, (Vec4)Color.White),
                new Tri(v15, v11, v10, (Vec4)Color.White),
                new Tri(v15, v10, v15, (Vec4)Color.White)
            };

            lewastrona.Origin   = new Vec3(0, 0, 0);
            lewastrona.Position = new Vec3(10.7f, 0, 10);
            lewastrona.Scale    = new Vec3(0.3f, 1, 5);
            Mesh prawastrona = new Mesh()
            {
                new Tri(v10, v12, v16, (Vec4)Color.White),
                new Tri(v10, v16, v14, (Vec4)Color.White),
                new Tri(v14, v16, v17, (Vec4)Color.White),
                new Tri(v14, v17, v15, (Vec4)Color.White),
                new Tri(v15, v17, v13, (Vec4)Color.White),
                new Tri(v15, v13, v11, (Vec4)Color.White),
                new Tri(v11, v13, v12, (Vec4)Color.White),
                new Tri(v11, v12, v10, (Vec4)Color.White),
                new Tri(v12, v13, v17, (Vec4)Color.White),
                new Tri(v12, v17, v16, (Vec4)Color.White),
                new Tri(v15, v11, v10, (Vec4)Color.White),
                new Tri(v15, v10, v15, (Vec4)Color.White)
            };

            prawastrona.Origin   = new Vec3(0, 0, 0);
            prawastrona.Position = new Vec3(12, 0, 10);
            prawastrona.Scale    = new Vec3(0.3f, 1, 5);
            Color szary  = new Color(20, 20, 20);
            Mesh  srodek = new Mesh()
            {
                new Tri(v10, v12, v16, (Vec4)szary),
                new Tri(v10, v16, v14, (Vec4)szary),
                new Tri(v14, v16, v17, (Vec4)szary),
                new Tri(v14, v17, v15, (Vec4)szary),
                new Tri(v15, v17, v13, (Vec4)szary),
                new Tri(v15, v13, v11, (Vec4)szary),
                new Tri(v11, v13, v12, (Vec4)szary),
                new Tri(v11, v12, v10, (Vec4)szary),
                new Tri(v12, v13, v17, (Vec4)szary),
                new Tri(v12, v17, v16, (Vec4)szary),
                new Tri(v15, v11, v10, (Vec4)szary),
                new Tri(v15, v10, v15, (Vec4)szary)
            };

            srodek.Origin   = new Vec3(0, 0, -0.2f);
            srodek.Position = new Vec3(11, 0, 10);
            srodek.Scale    = new Vec3(1, 0.99f, 4f);

            //sfera
            Sfera sfera = new Sfera(1, 3, (Vec4)Color.Red);

            sfera.Origin   = new Vec3(0, 0, 0);
            sfera.Position = new Vec3(1.5f, 10, 1.5f);
            sfera.Scale    = new Vec3(2, 2, 2);

            //rysuj figury
            drawables.Add(szescian);
            drawables.Add(sfera);
            drawables.Add(kolumna);
            drawables.Add(lewastrona);
            drawables.Add(prawastrona);
            drawables.Add(srodek);
            //dodaj swiatlko
            Lampy.Add(new ZrodloSwiatla()
            {
                Position = new Vec3(-5, 10, -5), Intensywnosc = 2f
            });
            Lampy.Add(new ZrodloSwiatla()
            {
                Position = new Vec3(5, -3, 5), Intensywnosc = 1f
            });
            mainCamera.Position = new Vec3(-5, 0, -5);
        }
        private List <Tri> Clipowanie(Vec3 planePoint, Vec3 planeNormal, Tri tri)
        {
            planeNormal = planeNormal.Normal();

            float dist(Vec3 point)
            {
                return(planeNormal.Dot(point) - planeNormal.Dot(planePoint));
            }

            Wierzcholek[] insidePoints = new Wierzcholek[3]; int nInsidePointCount = 0;
            Wierzcholek[] outsidePoints = new Wierzcholek[3]; int nOutsidePointCount = 0;

            float d0 = dist(tri[0].Position);
            float d1 = dist(tri[1].Position);
            float d2 = dist(tri[2].Position);

            if (d0 >= 0)
            {
                insidePoints[nInsidePointCount++] = tri[0];
            }
            else
            {
                outsidePoints[nOutsidePointCount++] = tri[0];
            }
            if (d1 >= 0)
            {
                insidePoints[nInsidePointCount++] = tri[1];
            }
            else
            {
                outsidePoints[nOutsidePointCount++] = tri[1];
            }
            if (d2 >= 0)
            {
                insidePoints[nInsidePointCount++] = tri[2];
            }
            else
            {
                outsidePoints[nOutsidePointCount++] = tri[2];
            }

            if (nInsidePointCount == 0)
            {
                return(new List <Tri>());
            }
            if (nInsidePointCount == 1 && nOutsidePointCount == 2)
            {
                Wierzcholek v0 = insidePoints[0];
                Wierzcholek v1 = Linia(planePoint, planeNormal, v0, outsidePoints[0]);
                Wierzcholek v2 = Linia(planePoint, planeNormal, v0, outsidePoints[1]);

                Tri t = new Tri(tri)
                {
                    W0 = v0, W1 = v1, W2 = v2
                };
                if (tri.NormalVector.Z * t.NormalVector.Z < 0)
                {
                    Wierzcholek tmp = t[1];
                    t[1] = t[2];
                    t[2] = tmp;
                }
                return(new List <Tri>
                {
                    t,
                });
            }
            if (nInsidePointCount == 2 && nOutsidePointCount == 1)
            {
                Wierzcholek v00 = insidePoints[0];
                Wierzcholek v01 = insidePoints[1];
                Wierzcholek v02 = Linia(planePoint, planeNormal, v00, outsidePoints[0]);

                Wierzcholek v10 = insidePoints[1];
                Wierzcholek v11 = v02;
                Wierzcholek v12 = Linia(planePoint, planeNormal, v10, outsidePoints[0]);

                Tri t1 = new Tri(tri)
                {
                    W0 = v00, W1 = v01, W2 = v02
                };
                Tri t2 = new Tri(tri)
                {
                    W0 = v10, W1 = v11, W2 = v12
                };
                if (tri.NormalVector.Z * t1.NormalVector.Z < 0)
                {
                    Wierzcholek tmp = t1[1];
                    t1[1] = t1[2];
                    t1[2] = tmp;
                }
                if (tri.NormalVector.Z * t2.NormalVector.Z < 0)
                {
                    Wierzcholek tmp = t2[1];
                    t2[1] = t2[2];
                    t2[2] = tmp;
                }
                return(new List <Tri>
                {
                    t1,
                    t2,
                });
            }
            if (nInsidePointCount == 3)
            {
                return(new List <Tri>
                {
                    tri,
                });
            }
            return(new List <Tri>());
        }
        private void RysujTrojkat(Tri triangle, PrimitiveType primitiveType)
        {
            if (primitiveType == PrimitiveType.Triangles)
            {
                void uzupelnijdol(Wierzcholek v1, Wierzcholek v2, Wierzcholek v3)
                {
                    float invslope1 = (v2.Position.X - v1.Position.X) / (v2.Position.Y - v1.Position.Y);
                    float invslope2 = (v3.Position.X - v1.Position.X) / (v3.Position.Y - v1.Position.Y);

                    float curx1 = v1.Position.X;
                    float curx2 = v1.Position.X;

                    for (int scanlineY = (int)v1.Position.Y; scanlineY <= v2.Position.Y; scanlineY++)
                    {
                        float z1   = v1.Position.Z + ((float)(scanlineY - v1.Position.Y) / (float)(v2.Position.Y - v1.Position.Y)) * (v2.Position.Z - v1.Position.Z);
                        float z2   = v1.Position.Z + ((float)(scanlineY - v1.Position.Y) / (float)(v3.Position.Y - v1.Position.Y)) * (v3.Position.Z - v1.Position.Z);
                        Vec4  c1   = v1.Color + ((float)(scanlineY - v1.Position.Y) / (float)(v2.Position.Y - v1.Position.Y)) * (v2.Color - v1.Color);
                        Vec4  c2   = v1.Color + ((float)(scanlineY - v1.Position.Y) / (float)(v3.Position.Y - v1.Position.Y)) * (v3.Color - v1.Color);
                        Vec3  from = new Vec3((float)Math.Round(curx1), scanlineY, z1);
                        Vec3  to   = new Vec3((float)Math.Round(curx2), scanlineY, z2);
                        UstawLinie(from.X, from.Z, c1, to.X, to.Z, c2, scanlineY);
                        curx1 += invslope1;
                        curx2 += invslope2;
                    }
                }

                void uzupelnijgore(Wierzcholek v1, Wierzcholek v2, Wierzcholek v3)
                {
                    float invslope1 = (v3.Position.X - v1.Position.X) / (v3.Position.Y - v1.Position.Y);
                    float invslope2 = (v3.Position.X - v2.Position.X) / (v3.Position.Y - v2.Position.Y);

                    float curx1 = v3.Position.X;
                    float curx2 = v3.Position.X;

                    for (int scanlineY = (int)v3.Position.Y; scanlineY > v1.Position.Y; scanlineY--)
                    {
                        float z1   = v3.Position.Z + ((float)(scanlineY - v3.Position.Y) / (float)(v1.Position.Y - v3.Position.Y)) * (v1.Position.Z - v3.Position.Z);
                        float z2   = v3.Position.Z + ((float)(scanlineY - v3.Position.Y) / (float)(v2.Position.Y - v3.Position.Y)) * (v2.Position.Z - v3.Position.Z);
                        Vec3  from = new Vec3((float)Math.Round(curx1), scanlineY, z1);
                        Vec3  to   = new Vec3((float)Math.Round(curx2), scanlineY, z2);
                        Vec4  c1   = v3.Color + ((float)(scanlineY - v3.Position.Y) / (float)(v1.Position.Y - v3.Position.Y)) * (v1.Color - v3.Color);
                        Vec4  c2   = v3.Color + ((float)(scanlineY - v3.Position.Y) / (float)(v2.Position.Y - v3.Position.Y)) * (v2.Color - v3.Color);
                        UstawLinie(from.X, from.Z, c1, to.X, to.Z, c2, scanlineY);
                        curx1 -= invslope1;
                        curx2 -= invslope2;
                    }
                }

                List <Wierzcholek> sortedVecs = new List <Wierzcholek>
                {
                    triangle[0],
                    triangle[1],
                    triangle[2],
                };
                sortedVecs = sortedVecs.OrderBy(i => i.Position.Y).ToList();
                Wierzcholek A = sortedVecs[0];
                Wierzcholek B = sortedVecs[1];
                Wierzcholek C = sortedVecs[2];
                A.Position = new Vec3((int)A.Position.X, (int)A.Position.Y, A.Position.Z);
                B.Position = new Vec3((int)B.Position.X, (int)B.Position.Y, B.Position.Z);
                C.Position = new Vec3((int)C.Position.X, (int)C.Position.Y, C.Position.Z);

                if (B.Position.Y == C.Position.Y)
                {
                    uzupelnijdol(A, B, C);
                }
                else if (A.Position.Y == B.Position.Y)
                {
                    uzupelnijgore(A, B, C);
                }
                else
                {
                    float z  = A.Position.Z + ((float)(B.Position.Y - A.Position.Y) / (float)(C.Position.Y - A.Position.Y)) * (C.Position.Z - A.Position.Z);
                    Vec4  c  = A.Color + ((float)(B.Position.Y - A.Position.Y) / (float)(C.Position.Y - A.Position.Y)) * (C.Color - A.Color);
                    Vec3  v4 = new Vec3(
                        (int)(A.Position.X + ((float)(B.Position.Y - A.Position.Y) / (float)(C.Position.Y - A.Position.Y)) * (C.Position.X - A.Position.X)),
                        B.Position.Y,
                        z
                        );
                    Wierzcholek v = new Wierzcholek(v4, c);

                    uzupelnijdol(A, B, v);
                    uzupelnijgore(B, v, C);
                }
            }
        }
        //rysowanie trojkatow skierowanych do mnie z cieniem i przycieciem
        public void RenderowanieSceny(Scena scene, RenderTarget target, RenderStates states)
        {
            uint width  = target.Size.X;
            uint height = target.Size.Y;

            Buffer = new float[width, height];
            Bitmap = new Color[width, height];

            Transformacja cameraInvMatrixAndWorld = scene.mainCamera.InverseTransform * scene.worldTransform;
            Transformacja matView = Transformacja.Identity.Translate(new Vec3(1, 1, 0)).Scale(new Vec3(width / 2, height / 2, 1));

            float fAspectRatio = height / (float)width;
            float fFovRad      = 1.0f / (float)Math.Tan(scene.mainCamera.Fov * 0.5f / 180.0f * Math.PI);

            float[,] m = new float[4, 4];
            m[0, 0]    = fAspectRatio * fFovRad;
            m[1, 1]    = fFovRad;
            m[2, 2]    = scene.mainCamera.Daleko / (scene.mainCamera.Daleko - scene.mainCamera.Blisko);
            m[3, 2]    = (-scene.mainCamera.Daleko * scene.mainCamera.Blisko) / (scene.mainCamera.Daleko - scene.mainCamera.Blisko);
            m[2, 3]    = 1.0f;
            m[3, 3]    = 0.0f;
            Transformacja matProj = new Transformacja(m);

            Transformacja matProjAndView = matView * matProj;

            Queue <Tri> sceneTriangles = new Queue <Tri>();

            foreach (Rysowalne drawable in scene.drawables)
            {
                Mesh mesh = drawable.GetMesh();
                foreach (Tri tri in mesh)
                {
                    sceneTriangles.Enqueue(mesh.Transform * tri);
                }
            }
            int c = sceneTriangles.Count;

            for (int i = 0; i < c; i++)
            {
                Tri t = sceneTriangles.Dequeue();
                sceneTriangles.Enqueue(cameraInvMatrixAndWorld * t);
            }
            for (int i = 0; i < c; i++)
            {
                Tri        t   = sceneTriangles.Dequeue();
                List <Tri> clt = Clipowanie(new Vec3(0, 0, scene.mainCamera.Blisko), new Vec3(0, 0, 1), t);
                foreach (var clippedTriangle in clt)
                {
                    sceneTriangles.Enqueue(clippedTriangle);
                }
            }
            c = sceneTriangles.Count;
            for (int i = 0; i < c; i++)
            {
                Tri t = sceneTriangles.Dequeue();
                if (t.NormalVector.Dot(t[0].Position) < 0)
                {
                    sceneTriangles.Enqueue(t);
                }
            }
            c = sceneTriangles.Count;
            for (int i = 0; i < c; i++)
            {
                Tri     t  = sceneTriangles.Dequeue();
                float[] Is = new float[3] {
                    0, 0, 0
                };
                Vec3  N  = t.NormalVector;
                float kd = t.KD;
                float ks = t.KS;
                float n  = t.N;
                foreach (ZrodloSwiatla lsrc in scene.Lampy)
                {
                    Vec3 lightPos = cameraInvMatrixAndWorld * lsrc.Position;
                    for (int j = 0; j < 3; j++)
                    {
                        Vec3  V     = (-t[j].Position).Normal();
                        Vec3  L     = (lightPos - t[j].Position).Normal();
                        Vec3  R     = (-L - 2 * N.Dot(-L) * N).Normal();
                        float minus = (V.Dot(R) < 0) ? -1 : 1;
                        float I     = lsrc.Intensywnosc * (kd * N.Dot(L) + ks * minus * (float)Math.Pow(V.Dot(R), n));
                        Math.Max(I, 0);
                        Is[j] += I;
                    }
                }
                for (int j = 0; j < 3; j++)
                {
                    Is[j] = Math.Max(Is[j], 0.2f);
                }
                Vec4 color0 = new Vec4(t[0].Color.R * Is[0], t[0].Color.G * Is[0], t[0].Color.B * Is[0], t[0].Color.A);
                Vec4 color1 = new Vec4(t[1].Color.R * Is[1], t[1].Color.G * Is[1], t[1].Color.B * Is[1], t[1].Color.A);
                Vec4 color2 = new Vec4(t[2].Color.R * Is[2], t[2].Color.G * Is[2], t[2].Color.B * Is[2], t[2].Color.A);

                Wierzcholek vert0 = new Wierzcholek(t[0].Position, color0);
                Wierzcholek vert1 = new Wierzcholek(t[1].Position, color1);
                Wierzcholek vert2 = new Wierzcholek(t[2].Position, color2);
                sceneTriangles.Enqueue(new Tri(vert0, vert1, vert2, t.KS, t.KD, t.N));
            }
            for (int i = 0; i < c; i++)
            {
                Tri t = sceneTriangles.Dequeue();
                sceneTriangles.Enqueue(matProjAndView * t);
            }
            for (int i = 0; i < c; i++)
            {
                Tri         t     = sceneTriangles.Dequeue();
                Queue <Tri> qTris = new Queue <Tri>();
                qTris.Enqueue(t);
                int nNewTriangles = 1;

                for (int p = 0; p < 4; p++)
                {
                    while (nNewTriangles > 0)
                    {
                        Tri t2 = qTris.Dequeue();
                        nNewTriangles--;

                        List <Tri> clippedTriangles = new List <Tri>();
                        switch (p)
                        {
                        case 0:
                            clippedTriangles = Clipowanie(new Vec3(), new Vec3(0, 1, 0), t2);
                            break;

                        case 1:
                            clippedTriangles = Clipowanie(new Vec3(0, height - 1, 0), new Vec3(0, -1, 0), t2);
                            break;

                        case 2:
                            clippedTriangles = Clipowanie(new Vec3(), new Vec3(1, 0, 0), t2);
                            break;

                        case 3:
                            clippedTriangles = Clipowanie(new Vec3(width - 1, 0, 0), new Vec3(-1, 0, 0), t2);
                            break;
                        }
                        foreach (var item in clippedTriangles)
                        {
                            qTris.Enqueue(item);
                        }
                    }
                    nNewTriangles = qTris.Count;
                }
                foreach (var item in qTris)
                {
                    sceneTriangles.Enqueue(item);
                }
            }
            while (sceneTriangles.Count > 0)
            {
                Tri t = sceneTriangles.Dequeue();
                RysujTrojkat(t, PrimitiveType.Triangles);
            }
            foreach (ZrodloSwiatla light in scene.Lampy)
            {
                Vec3 lpos = cameraInvMatrixAndWorld * light.Position;
                if (lpos.Z > 0)
                {
                    Vec3 lPosOnScreen = matProjAndView * lpos;
                    UstawPixel(lPosOnScreen, (Vec4)Color.White);
                    UstawPixel(lPosOnScreen + new Vec3(0, 1), (Vec4)Color.White);
                    UstawPixel(lPosOnScreen + new Vec3(1, 0), (Vec4)Color.White);
                    UstawPixel(lPosOnScreen + new Vec3(1, 1), (Vec4)Color.White);
                }
            }
            Image   img     = new Image(Bitmap);
            Texture texture = new Texture(img);
            Sprite  s       = new Sprite(texture);

            target.Draw(s, states);
            s.Dispose();
            texture.Dispose();
            img.Dispose();
        }