Ejemplo n.º 1
0
        private void EdytujTorus(int iloscWarstw, int iloscOkregow, float R, float r, int CurrentObiekt)
        {
            float t, u;

            obiekty[CurrentObiekt].Vertices.Clear();
            obiekty[CurrentObiekt].Dependences.Clear();
            obiekty[CurrentObiekt].duzyPromien = (float)R;
            obiekty[CurrentObiekt].malyPromien = (float)r;

            for (int w = 0; w < iloscWarstw; w++)
            {
                u = (float)(w * ((2.0f * Math.PI) / iloscWarstw));

                for (int i = 0; i < iloscOkregow; i++)
                {
                    t = (float)(i * ((2.0f * Math.PI) / iloscOkregow));
                    VectorPoint tmpPoint = new VectorPoint();
                    tmpPoint.X = torusXparametr(t, R, r, u);
                    tmpPoint.Y = torusYparametr(t, R, r, u);
                    tmpPoint.Z = torusZparametr(t, R, r, u);
                    tmpPoint.W = 1.0f;

                    obiekty[CurrentObiekt].Vertices.Add(tmpPoint);
                }
            }

            //poziomo
            for (int i = 0; i < iloscWarstw; i++)
            {
                for (int j = 0; j < iloscOkregow; j++)
                {
                    if (j == iloscOkregow - 1)
                    {
                        obiekty[CurrentObiekt].Dependences.Add(new System.Windows.Point(i * iloscOkregow + j, i * iloscOkregow));
                    }
                    else
                    {
                        obiekty[CurrentObiekt].Dependences.Add(new System.Windows.Point(i * iloscOkregow + j, i * iloscOkregow + j + 1));
                    }
                }
            }

            //pionowo
            for (int j = 0; j < iloscOkregow; j++)
            {
                for (int i = 0; i < iloscWarstw; i++)
                {
                    if (i == iloscWarstw - 1)
                    {
                        obiekty[CurrentObiekt].Dependences.Add(new System.Windows.Point(j + (i * iloscOkregow), j));
                    }
                    else
                    {
                        obiekty[CurrentObiekt].Dependences.Add(new System.Windows.Point(j + (i * iloscOkregow), j + (i * iloscOkregow) + iloscOkregow));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public VectorPoint mnozeniePunkt(VectorPoint point, float[,] Mmatrix)
        {
            float[]     tmp    = { (float)point.X, (float)point.Y, (float)point.Z, (float)point.W };
            VectorPoint result = new VectorPoint();

            result.X = Mmatrix[0, 0] * tmp[0] + Mmatrix[0, 1] * tmp[1] + Mmatrix[0, 2] * tmp[2] + Mmatrix[0, 3] * tmp[3];
            result.Y = Mmatrix[1, 0] * tmp[0] + Mmatrix[1, 1] * tmp[1] + Mmatrix[1, 2] * tmp[2] + Mmatrix[1, 3] * tmp[3];
            result.Z = Mmatrix[2, 0] * tmp[0] + Mmatrix[2, 1] * tmp[1] + Mmatrix[2, 2] * tmp[2] + Mmatrix[2, 3] * tmp[3];
            result.W = Mmatrix[3, 0] * tmp[0] + Mmatrix[3, 1] * tmp[1] + Mmatrix[3, 2] * tmp[2] + Mmatrix[3, 3] * tmp[3];

            return(result);
        }
Ejemplo n.º 3
0
        public void drawLines()
        {
            float fov = (float)(1.0f / Math.Tan(((90.0f / 360.0f) * 2.0f * Math.PI) / 2.0f));
            int   far = 1000, near = 100;

            float[,] ClipMatrix =
            {
                { (float)(fov * ((float)CurrentImage.ActualWidth / (float)CurrentImage.ActualHeight)), 0.0f,                                 0.0f,                                     0.0f },
                {                                                                                0.0f, fov,                                  0.0f,                                     0.0f },
                {                                                                                0.0f, 0.0f, (float)((far + near) / (far - near)), (float)((2 * far * near) / (near - far)) },
                {                                                                                0.0f, 0.0f,                                 1.0f,                                     0.0f }
            };
            //tu czeba jakos mnozyc maciory
            using (Bitmap WorkspaceMapa = new Bitmap(CleanMapa))
            {
                System.Drawing.Pen blackPen = new System.Drawing.Pen(System.Drawing.Color.Black, 1);

                for (int i = 0; i < obiekty.Count; i++)
                {
                    float[,] matrix =
                    {
                        { 1.0f, 0.0f, 0.0f, 0.0f },
                        { 0.0f, 1.0f, 0.0f, 0.0f },
                        { 0.0f, 0.0f, 1.0f, 0.0f },
                        { 0.0f, 0.0f, 0.0f, 1.0f }
                    };
                    //wmord/model
                    matrix = wymnozMacierze(i);
                    matrix = mnozenieMacierzy(matrix, ClipMatrix);
                    matrix = mnozenieMacierzy(matrix, projectionMatrix);
                    //mnozymy jeszcze przez projekcje i view o.0

                    for (int j = 0; j < obiekty[i].Dependences.Count; j++)
                    {
                        VectorPoint point1 = obiekty[i].Vertices[(int)obiekty[i].Dependences[j].X];
                        VectorPoint point2 = obiekty[i].Vertices[(int)obiekty[i].Dependences[j].Y];

                        point1 = mnozeniePunkt(point1, matrix);
                        point2 = mnozeniePunkt(point2, matrix);

                        float w1 = 1.0f;
                        if (point1.W != 0)
                        {
                            w1 = point1.W;
                        }

                        float w2 = 1.0f;
                        if (point2.W != 0)
                        {
                            w2 = point2.W;
                        }

                        int newX1 = (int)((point1.X * CurrentImage.ActualWidth) / (2.0f * w1) + (CurrentImage.ActualWidth / 2.0f));
                        int newY1 = (int)((point1.Y * CurrentImage.ActualHeight) / (2.0f * w1) + (CurrentImage.ActualHeight / 2.0f));
                        int newX2 = (int)((point2.X * CurrentImage.ActualWidth) / (2.0f * w2) + (CurrentImage.ActualWidth / 2.0f));
                        int newY2 = (int)((point2.Y * CurrentImage.ActualHeight) / (2.0f * w2) + (CurrentImage.ActualHeight / 2.0f));

                        using (var graphics = Graphics.FromImage(WorkspaceMapa))
                        {
                            graphics.DrawLine(blackPen, newX1, newY1, newX2, newY2);
                        }
                    }
                }
                mapa = WorkspaceMapa;
                CurrentImage.Source = ToBitmapSource(mapa);
            }
        }
Ejemplo n.º 4
0
        private void InicjalizujTorus(int iloscWarstw, int iloscOkregow, float R, float r)
        {
            float t, u;

            List <VectorPoint>          torusPoints = new List <VectorPoint>();
            List <System.Windows.Point> torusVertex = new List <System.Windows.Point>();

            for (int w = 0; w < iloscWarstw; w++)
            {
                u = (float)(w * ((2.0f * Math.PI) / iloscWarstw));

                for (int i = 0; i < iloscOkregow; i++)
                {
                    t = (float)(i * ((2.0f * Math.PI) / iloscOkregow));
                    VectorPoint tmpPoint = new VectorPoint();
                    tmpPoint.X = torusXparametr(t, R, r, u);
                    tmpPoint.Y = torusYparametr(t, R, r, u);
                    tmpPoint.Z = torusZparametr(t, R, r, u);
                    tmpPoint.W = 1.0f;

                    torusPoints.Add(tmpPoint);
                }
            }

            //poziomo
            for (int i = 0; i < iloscWarstw; i++)
            {
                for (int j = 0; j < iloscOkregow; j++)
                {
                    if (j == iloscOkregow - 1)
                    {
                        torusVertex.Add(new System.Windows.Point(i * iloscOkregow + j, i * iloscOkregow));
                    }
                    else
                    {
                        torusVertex.Add(new System.Windows.Point(i * iloscOkregow + j, i * iloscOkregow + j + 1));
                    }
                }
            }

            //pionowo
            for (int j = 0; j < iloscOkregow; j++)
            {
                for (int i = 0; i < iloscWarstw; i++)
                {
                    if (i == iloscWarstw - 1)
                    {
                        torusVertex.Add(new System.Windows.Point(j + (i * iloscOkregow), j));
                    }
                    else
                    {
                        torusVertex.Add(new System.Windows.Point(j + (i * iloscOkregow), j + (i * iloscOkregow) + iloscOkregow));
                    }
                }
            }

            Object3D torus = new Object3D(torusVertex, torusPoints);

            torus.Tag = index;

            obiekty.Add(torus);
            rotateObject(0, 0, 0, obiekty.Count - 1);
            moveObject(0, 0, 50, obiekty.Count - 1);
        }