Пример #1
0
 public void DisplayTimeEvent(object source, ElapsedEventArgs e)
 {
     if (rotate == true)
     {
         lock (Form1.syncLock)
         {
             for (int i = 0; i < pointList.Count; i++)
             {
                 pointList[i]._currentCoords = Graphic3D.MultiplyV4(MModel, pointList[i].realCoords);
                 pointList[i].normal         = Graphic3D.MultiplyV4(MModel, pointList[i]._normal);
             }
             MModel = new Matrix4x4((float)Math.Cos(t), (float)(-Math.Sin(t)), 0, (float)(2 * Math.Sin(t)),
                                    (float)Math.Sin(t), (float)Math.Cos(t), 0, (float)(2 * Math.Cos(t)),
                                    0, 0, 1, 0,
                                    0, 0, 0, 1);
             //MModel = new Matrix4x4((float)Math.Cos(t), (float)(-Math.Sin(t)), 0, (float)(2 * Math.Sin(t)),
             //(float)Math.Sin(t), (float)Math.Cos(t), 0, (float)(2 * Math.Cos(t)),
             //0, 0, 1, 0,
             //0, 0, 0, 1);
             t += 0.05;
         }
     }
 }
Пример #2
0
        private void PictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = Graphics.FromImage(pictureBox1.Image);

            zindex = new float[pictureBox1.Width, pictureBox1.Height];

            tmpBtmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            using (Graphics gfx = Graphics.FromImage(tmpBtmp))
                using (SolidBrush brush = new SolidBrush(Color.Black))
                {
                    gfx.FillRectangle(brush, 0, 0, pictureBox1.Width, pictureBox1.Height);
                }
            lbm = new LockBitmap(tmpBtmp);
            for (int k = 0; k < pictureBox1.Width; k++)
            {
                for (int j = 0; j < pictureBox1.Height; j++)
                {
                    zindex[k, j] = float.MaxValue;
                }
            }
            lbm.LockBits();
            lock (syncLock)
            {
                if (radioButton2.Checked == true)
                {
                    cameraPos       = new Vector4(3.0f, 0.5f, 0.5f, 1);
                    Graphic3D.Mview = Graphic3D.CreateViewAt(3.0, 0.5, 0.5, objects[1].pointList[5]._currentCoords.X, objects[1].pointList[5]._currentCoords.Y, objects[1].pointList[5]._currentCoords.Z, 0, 0, 1);
                }
                if (radioButton3.Checked == true)
                {
                    cameraPos       = new Vector4(objects[1].pointList[5]._currentCoords.X + 2, objects[1].pointList[5]._currentCoords.Y + 2, objects[1].pointList[5]._currentCoords.Z + 2, 1);
                    Graphic3D.Mview = Graphic3D.CreateViewAt(objects[1].pointList[5]._currentCoords.X + 2, objects[1].pointList[5]._currentCoords.Y + 2, objects[1].pointList[5]._currentCoords.Z + 2, objects[1].pointList[5]._currentCoords.X, objects[1].pointList[5]._currentCoords.Y,
                                                             objects[1].pointList[5]._currentCoords.Z, 0, 0, 1);
                }
                int k = 0;
                foreach (Object3D c in objects)
                {
                    //if (k++ == 0) continue;
                    Parallel.ForEach(c.triangleList, poly =>
                    {
                        {
                            float R = 0.0f, G = 0.0f, B = 0.0f;
                            if (k == 0)
                            {
                                R = 1.0f;
                                G = 0.549019608f;
                                B = 0.0f;
                            }
                            else if (k == 1)
                            {
                                R = 0.0f;
                                B = 1.0f;
                                G = 0.0f;
                            }
                            var p1 = c.pointList[poly.p1];
                            var p2 = c.pointList[poly.p2];
                            var p3 = c.pointList[poly.p3];


                            DrawTriangle(p1, p2, p3, new Vector4(R, G, B, 1.0f));
                        }
                    });
                    k++;
                }
            }
            lbm.UnlockBits();
            pictureBox1.Image = tmpBtmp;
        }
Пример #3
0
 private void radioButton1_CheckedChanged(object sender, EventArgs e)
 {
     cameraPos       = new Vector4(3.0f, 0.5f, 0.5f, 1);
     Graphic3D.Mview = Graphic3D.CreateViewAt(3.0, 0.5, 0.5, 0, 0.5, 0.5, 0, 0, 1);
 }