Example #1
0
 public virtual TColor Result(TVec3 r, TVec3 n, TColor diffuse)
 {
     var c = Ambient;
     foreach (var source in ParallelBeams)
     {
         double num1 = n * source.O;
         if (num1 >= 0.0)
         {
             double num2 = num1 * num1 / (n * n * source.O * source.O);
             c += num2 * source.C;
         }
     }
     foreach (var source in NearSources)
     {
         var tvec3 = source.O - r;
         double num1 = n * tvec3;
         double num2 = tvec3 * tvec3;
         if (num1 >= 0.0)
         {
             double num3 = num1 * num1 / (n * n * num2 * num2);
             c += num3 * source.C;
         }
     }
     return diffuse * c;
 }
Example #2
0
 public virtual TColor Result(TVec3 r, TVec3 n, TColor diffuse)
 {
     TColor tcolor = this.Ambient;
     foreach (TLight.TSource tsource in this.ParallelBeams)
     {
         double num1 = n * tsource.o;
         if (num1 >= 0.0)
         {
             double num2 = num1 * num1 / (n * n * tsource.o * tsource.o);
             tcolor += num2 * tsource.c;
         }
     }
     foreach (TLight.TSource tsource in this.NearSources)
     {
         TVec3 tvec3 = tsource.o - r;
         double num1 = n * tvec3;
         double num2 = tvec3 * tvec3;
         if (num1 >= 0.0)
         {
             double num3 = num1 * num1 / (n * n * num2 * num2);
             tcolor += num3 * tsource.c;
         }
     }
     return diffuse * tcolor;
 }
Example #3
0
        public unsafe void Paint(Pad Pad)
        {
            TView tview = TView.View(Pad);

            this.Left  = tview.Left;
            this.Top   = tview.Top;
            this.W     = tview.H;
            this.H     = tview.H;
            this.o     = tview.O - new TVec3((double)this.Left, (double)this.Top, 0.0);
            this.Lx    = tview.Lx;
            this.Ly    = tview.Ly;
            this.Lz    = tview.Lz;
            this.Light = tview.Light;
            if (this.Look == EChartLook.SurfaceOnly)
            {
                this.BitmapWriteOnly = false;
            }
            Bitmap bm = new Bitmap(this.W, this.H, PixelFormat.Format32bppRgb);

            this.BackgroundIntoBitmapIfNeeded(Pad, bm);
            Rectangle  rect       = new Rectangle(0, 0, this.W, this.H);
            BitmapData bitmapdata = bm.LockBits(rect, this.BitmapWriteOnly ? ImageLockMode.WriteOnly : ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);

            this.PaintBuffer((int *)bitmapdata.Scan0.ToPointer());
            bm.UnlockBits(bitmapdata);
            Color transparentColor = Color.FromArgb((int)byte.MaxValue, 0, 0, 0);

            bm.MakeTransparent(transparentColor);
            Pad.Graphics.DrawImage((Image)bm, this.Left, this.Top);
        }
Example #4
0
        public virtual TColor Result(TVec3 r, TVec3 n, TColor diffuse)
        {
            var c = Ambient;

            foreach (var source in ParallelBeams)
            {
                double num1 = n * source.O;
                if (num1 >= 0.0)
                {
                    double num2 = num1 * num1 / (n * n * source.O * source.O);
                    c += num2 * source.C;
                }
            }
            foreach (var source in NearSources)
            {
                var    tvec3 = source.O - r;
                double num1  = n * tvec3;
                double num2  = tvec3 * tvec3;
                if (num1 >= 0.0)
                {
                    double num3 = num1 * num1 / (n * n * num2 * num2);
                    c += num3 * source.C;
                }
            }
            return(diffuse * c);
        }
Example #5
0
        public virtual TColor Result(TVec3 r, TVec3 n, TColor diffuse)
        {
            TColor tcolor = this.Ambient;

            foreach (TLight.TSource tsource in this.ParallelBeams)
            {
                double num1 = n * tsource.o;
                if (num1 >= 0.0)
                {
                    double num2 = num1 * num1 / (n * n * tsource.o * tsource.o);
                    tcolor += num2 * tsource.c;
                }
            }
            foreach (TLight.TSource tsource in this.NearSources)
            {
                TVec3  tvec3 = tsource.o - r;
                double num1  = n * tvec3;
                double num2  = tvec3 * tvec3;
                if (num1 >= 0.0)
                {
                    double num3 = num1 * num1 / (n * n * num2 * num2);
                    tcolor += num3 * tsource.c;
                }
            }
            return(diffuse * tcolor);
        }
Example #6
0
        public TAxisCalc(TVec3 origin, TVec3 end, double valO, double valEnd, int nTicks)
        {
            this.origin = origin;
            this.end    = end;
            this.valO   = valO;
            this.valEnd = valEnd;
            this.n      = nTicks;
            SetTicks();

            // Set tick positions
            Parallel.ForEach(this.ticks, t => t.Position = this.origin + (this.end - this.origin) * (t.Value - this.valO) / (this.valEnd - this.valO));
        }
Example #7
0
        public TAxisCalc(TVec3 origin, TVec3 end, double valO, double valEnd, int nTicks)
        {
            this.origin = origin;
            this.end = end;
            this.valO = valO;
            this.valEnd = valEnd;
            this.n = nTicks;
            SetTicks();

            // Set tick positions
            Parallel.ForEach(this.ticks, t => t.Position =  this.origin + (this.end - this.origin) * (t.Value - this.valO) / (this.valEnd - this.valO));
        }
Example #8
0
        public static TVec3 operator *(TVec3 v, TMat3x3 m)
        {
            var r = new TVec3();

            for (var i = 0; i < 3; ++i)
            {
                for (var j = 0; j < 3; ++j)
                {
                    r[j] += v[i] * m[i, j];
                }
            }
            return(r);
        }
Example #9
0
        public static TVec3 operator *(TMat3x3 m, TVec3 v)
        {
            var r = new TVec3();

            for (var i = 0; i < 3; ++i)
            {
                for (var j = 0; j < 3; ++j)
                {
                    r[i] += m[i, j] * v[j];
                }
            }
            return(r);
        }
Example #10
0
        public TAxisCalc(TVec3 origin, TVec3 end, double valO, double valEnd, int nTicks)
        {
            this.origin = origin;
            this.end    = end;
            this.valO   = valO;
            this.valEnd = valEnd;
            n           = nTicks;
            SetTicks();

            // Set tick positions
            for (var i = 0; i < ticks.Length; i++)
            {
                var t = ticks[i];
                t.Position = this.origin + (this.end - this.origin) * (t.Value - this.valO) / (this.valEnd - this.valO);
            }
        }
Example #11
0
        public TAxisCalc(TVec3 origin, TVec3 end, double valO, double valEnd, int nTicks)
        {
            this.origin = origin;
            this.end = end;
            this.valO = valO;
            this.valEnd = valEnd;
            n = nTicks;
            SetTicks();

            // Set tick positions
            for (var i = 0; i < ticks.Length; i++)
            {
                var t = ticks[i];
                t.Position = this.origin + (this.end - this.origin)*(t.Value - this.valO)/(this.valEnd - this.valO);
            }
        }
Example #12
0
        public void CalculateAxes(Pad pad, int left, int top, int h)
        {
            this.fLeft = left;
            this.fTop  = top;
            this.fH    = h;
            this.fo    = new TVec3((double)(left + h / 2), (double)(top + 3 * h / 4), 0.0);
            if (this.ScaleZ < 1.0)
            {
                this.fo.y -= (1.0 - this.ScaleZ) * 0.25 * (double)h;
            }
            double num = 0.7 * (double)h;
            double Z   = 0.5 * this.ScaleZ * (double)h;

            this.fLx = new TVec3(num, 0.0, 0.0);
            this.fLy = new TVec3(0.0, num, 0.0);
            this.fLz = new TVec3(0.0, 0.0, Z);
            this.fLx = this.ms * this.Lx;
            this.fLy = this.ms * this.Ly;
            this.fLz = this.ms * this.Lz;
        }
Example #13
0
 public unsafe void Paint(Pad Pad)
 {
     TView tview = TView.View(Pad);
     this.Left = tview.Left;
     this.Top = tview.Top;
     this.W = tview.H;
     this.H = tview.H;
     this.o = tview.O - new TVec3((double) this.Left, (double) this.Top, 0.0);
     this.Lx = tview.Lx;
     this.Ly = tview.Ly;
     this.Lz = tview.Lz;
     this.Light = tview.Light;
     if (this.Look == EChartLook.SurfaceOnly)
         this.BitmapWriteOnly = false;
     Bitmap bm = new Bitmap(this.W, this.H, PixelFormat.Format32bppRgb);
     this.BackgroundIntoBitmapIfNeeded(Pad, bm);
     Rectangle rect = new Rectangle(0, 0, this.W, this.H);
     BitmapData bitmapdata = bm.LockBits(rect, this.BitmapWriteOnly ? ImageLockMode.WriteOnly : ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
     this.PaintBuffer((int*) bitmapdata.Scan0.ToPointer());
     bm.UnlockBits(bitmapdata);
     Color transparentColor = Color.FromArgb((int) byte.MaxValue, 0, 0, 0);
     bm.MakeTransparent(transparentColor);
     Pad.Graphics.DrawImage((Image) bm, this.Left, this.Top);
 }
Example #14
0
 public static TVec3 operator *(TVec3 v, TMat3x3 m)
 {
     var r = new TVec3();
     for (var i = 0; i < 3; ++i)
         for (var j = 0; j < 3; ++j)
             r[j] += v[i] * m[i, j];
     return r;
 }
Example #15
0
 public TSource(TVec3 o, TColor c)
 {
     O = o;
     C = c;
 }
Example #16
0
 public TSource(TVec3 o, TColor c)
 {
     this.o = o;
     this.c = c;
 }
Example #17
0
        private TColor color(double x, double y, double dx, double dy, TColor Diffuse)
        {
            TVec3 n = new TVec3(dx, 0.0, this.f(x + dx, y) - this.f(x, y)) ^ new TVec3(0.0, dy, this.f(x, y + dy) - this.f(x, y));

            return(this.Light.Result(new TVec3(x, y, this.f(x, y)), n, Diffuse));
        }
Example #18
0
        private unsafe void PaintBuffer(int *b)
        {
            int[,] numArray = new int[this.W, this.H];
            if (!this.BitmapWriteOnly)
            {
                int *numPtr = b;
                for (int index1 = 0; index1 < this.H; ++index1)
                {
                    for (int index2 = 0; index2 < this.W; ++index2)
                    {
                        numArray[index2, index1] = *numPtr++;
                    }
                }
            }
            double normInf1 = this.Lx.NormInf;
            double normInf2 = this.Ly.NormInf;
            TVec3  Origin   = this.o - 0.5 * this.Lx - 0.5 * this.Ly;
            TVec3  tvec3_1  = this.Lx / normInf1;
            TVec3  tvec3_2  = this.Ly / normInf2;
            double num1     = (this.MaxX - this.MinX) / normInf1;
            double num2     = (this.MaxY - this.MinY) / normInf2;
            double dx       = num1;
            double dy       = num2;

            if ((double)(2 * this.nx) >= normInf1 && (double)(2 * this.ny) >= normInf2)
            {
                dx = (this.MaxX - this.MinX) / (double)this.nx;
                dy = (this.MaxY - this.MinY) / (double)this.ny;
            }
            double ValO1   = this.MinX + 0.01 * dx;
            double ValO2   = this.MinY + 0.01 * dy;
            TVec3  tvec3_3 = this.Lx;
            TVec3  tvec3_4 = this.Ly;

            if (this.Lx.z > 0.0)
            {
                ValO1   = this.MaxX - 0.99 * dx;
                num1    = -num1;
                dx      = -dx;
                Origin += this.Lx;
                tvec3_3 = -this.Lx;
                tvec3_1 = -tvec3_1;
            }
            if (this.Ly.z > 0.0)
            {
                ValO2   = this.MaxY - 0.99 * dy;
                num2    = -num2;
                dy      = -dy;
                Origin += this.Ly;
                tvec3_4 = -this.Ly;
                tvec3_2 = -tvec3_2;
            }
            int num3 = (int)normInf1;
            int num4 = (int)normInf2;
            int num5 = (int)this.Lz.NormInf;

            bool[] flagArray1 = new bool[num3 + 2];
            bool[] flagArray2 = new bool[num4 + 2];
            bool[] flagArray3 = new bool[num5 + 2];
            if (this.Grid)
            {
                TAxisCalc taxisCalc1 = new TAxisCalc(Origin, Origin + tvec3_3, ValO1, ValO1 + normInf1 * num1, 10);
                TAxisCalc taxisCalc2 = new TAxisCalc(Origin, Origin + tvec3_4, ValO2, ValO2 + normInf2 * num2, 10);
                double    Val1       = ValO1;
                int       index1     = 0;
                while (index1 <= num3)
                {
                    if (taxisCalc1.TickPassed(Val1))
                    {
                        flagArray1[index1] = true;
                    }
                    ++index1;
                    Val1 += num1;
                }
                double Val2   = ValO2;
                int    index2 = 0;
                while (index2 <= num4)
                {
                    if (taxisCalc2.TickPassed(Val2))
                    {
                        flagArray2[index2] = true;
                    }
                    ++index2;
                    Val2 += num2;
                }
            }
            if (this.LevelLines)
            {
                for (int index = 0; index < num5; ++index)
                {
                    flagArray3[index] = (index & 4) != 0;
                }
            }
            switch (this.Look)
            {
            case EChartLook.FromZeroToSurface:
                double x1     = ValO1;
                int    index3 = 0;
                while (index3 <= num3)
                {
                    bool   flag    = flagArray1[index3];
                    TVec3  tvec3_5 = Origin;
                    double y       = ValO2;
                    int    index1  = 0;
                    while (index1 <= num4)
                    {
                        double num6 = this.f(x1, y);
                        if (num6 > 0.0)
                        {
                            int num7 = (int)tvec3_5.y;
                            int num8 = (int)(tvec3_5.y - num6);
                            if (num8 < 0)
                            {
                                num8 = 0;
                            }
                            TColor Diffuse = this.color0(x1, y);
                            if (this.Grid && (flag || flagArray2[index1]))
                            {
                                Diffuse = this.Surface.GridDiffuse;
                            }
                            Diffuse = this.color(x1, y, dx, dy, Diffuse);
                            Diffuse.Clip();
                            int num9   = Diffuse.Get888();
                            int index2 = (int)tvec3_5.x;
                            if (this.LevelLines)
                            {
                                TColor tcolor = 0.81 * Diffuse;
                                tcolor.Clip();
                                int num10 = tcolor.Get888();
                                for (int index4 = num7; index4 >= num8; --index4)
                                {
                                    numArray[index2, index4] = flagArray3[num7 - index4] ? num10 : num9;
                                }
                            }
                            else
                            {
                                for (int index4 = num7; index4 >= num8; --index4)
                                {
                                    numArray[index2, index4] = num9;
                                }
                            }
                        }
                        ++index1;
                        y       += num2;
                        tvec3_5 += tvec3_2;
                    }
                    ++index3;
                    x1     += num1;
                    Origin += tvec3_1;
                }
                break;

            case EChartLook.SurfaceOnly:
                double x2     = ValO1;
                int    index5 = 0;
                while (index5 < num3)
                {
                    bool   flag    = flagArray1[index5];
                    TVec3  tvec3_5 = Origin;
                    double y       = ValO2;
                    int    index1  = 0;
                    while (index1 < num4)
                    {
                        double num6  = this.f(x2, y);
                        double num7  = this.f(x2 + num1, y);
                        double num8  = this.f(x2, y + num2);
                        double num9  = this.f(x2 + num1, y + num2);
                        double num10 = num6;
                        double num11 = num6;
                        if (num7 < num10)
                        {
                            num10 = num7;
                        }
                        if (num8 < num10)
                        {
                            num10 = num8;
                        }
                        if (num9 < num10)
                        {
                            num10 = num9;
                        }
                        if (num7 > num11)
                        {
                            num11 = num7;
                        }
                        if (num8 > num11)
                        {
                            num11 = num8;
                        }
                        if (num9 > num11)
                        {
                            num11 = num9;
                        }
                        int num12 = (int)tvec3_5.y;
                        int num13 = (int)(tvec3_5.y - num10 + 1.0);
                        int num14 = (int)(tvec3_5.y - num11);
                        if (num13 < this.H && num13 >= 0 && (num14 < this.H && num14 >= 0))
                        {
                            TColor Diffuse = this.color0(x2, y);
                            if (this.Grid && (flag || flagArray2[index1]))
                            {
                                Diffuse = this.Surface.GridDiffuse;
                            }
                            Diffuse = this.color(x2, y, dx, dy, Diffuse);
                            Diffuse.Clip();
                            int num15  = Diffuse.Get888();
                            int index2 = (int)tvec3_5.x;
                            if (this.LevelLines)
                            {
                                TColor tcolor = 0.81 * Diffuse;
                                tcolor.Clip();
                                int num16 = tcolor.Get888();
                                for (int index4 = num13; index4 >= num14; --index4)
                                {
                                    if (num10 > 0.0 || numArray[index2, index4] >= 0 || numArray[index2, index4] == -1)
                                    {
                                        numArray[index2, index4] = (num12 - index4 & 4) != 0 ? num16 : num15;
                                    }
                                }
                            }
                            else
                            {
                                for (int index4 = num13; index4 >= num14; --index4)
                                {
                                    if (num10 > 0.0 || numArray[index2, index4] >= 0 || numArray[index2, index4] == -1)
                                    {
                                        numArray[index2, index4] = num15;
                                    }
                                }
                            }
                        }
                        ++index1;
                        y       += num2;
                        tvec3_5 += tvec3_2;
                    }
                    ++index5;
                    x2     += num1;
                    Origin += tvec3_1;
                }
                break;
            }
            for (int index1 = 0; index1 < this.H; ++index1)
            {
                for (int index2 = 0; index2 < this.W; ++index2)
                {
                    *b++ = numArray[index2, index1];
                }
            }
        }
Example #19
0
        public void PaintAxisGridAndTicks(Graphics g, Axis a, bool marks, TVec3 o, TVec3 o_, TVec3 L)
        {
            a.MinorGridEnabled  = false;
            a.MinorTicksEnabled = false;
            int nTicks = (int)(L.NormInf / 10.0);

            if (nTicks < 3)
            {
                nTicks = 3;
            }
            if (nTicks > 10)
            {
                nTicks = 10;
            }
            TAxisCalc taxisCalc = new TAxisCalc(o, o + L, a.Min, a.Max, nTicks);
            TVec3     tvec3_1   = o_ - o;
            TVec3     tvec3_2   = TVec3.O;
            TVec3     tvec3_3   = -0.04 * tvec3_1;

            if (o_.y > o.y)
            {
                tvec3_2 = tvec3_1;
                tvec3_3 = -tvec3_3;
            }
            TVec3 tvec3_4 = tvec3_2 + 1.04 * tvec3_3;

            if (a.GridEnabled)
            {
                Pen pen = new Pen(a.GridColor, a.GridWidth);
                for (int i = 0; i < taxisCalc.nTicks; ++i)
                {
                    g.DrawLine(pen, (Point)taxisCalc.TickPos(i), (Point)(taxisCalc.TickPos(i) + tvec3_1));
                }
            }
            if (a.Position == EAxisPosition.Right && tvec3_3.x <= 0.0)
            {
                marks = false;
            }
            if (!marks)
            {
                return;
            }
            int   num1 = a.Position == EAxisPosition.Bottom ? 0 : 1;
            int   num2 = a.Position == EAxisPosition.Bottom ? taxisCalc.nTicks - 1 : taxisCalc.nTicks;
            float num3 = 0.0f;

            if (a.MajorTicksEnabled)
            {
                Pen pen = new Pen(a.GridColor, a.GridWidth);
                for (int i = num1; i < num2; ++i)
                {
                    g.DrawLine(pen, (Point)(taxisCalc.TickPos(i) + tvec3_2), (Point)(taxisCalc.TickPos(i) + tvec3_2 + tvec3_3));
                }
            }
            if (a.LabelEnabled)
            {
                Font         labelFont  = a.LabelFont;
                float        height     = labelFont.GetHeight(g);
                SolidBrush   solidBrush = new SolidBrush(a.LabelColor);
                StringFormat format     = new StringFormat();
                float        num4;
                if (a.Position == EAxisPosition.Bottom)
                {
                    format.FormatFlags = StringFormatFlags.DirectionVertical;
                    num4 = (float)Math.Abs(taxisCalc.TickPos(1).x - taxisCalc.TickPos(0).x);
                }
                else
                {
                    tvec3_4.y -= 0.5 * (double)a.LabelFont.GetHeight();
                    num4       = (float)Math.Abs(taxisCalc.TickPos(1).y - taxisCalc.TickPos(0).y);
                }
                if (tvec3_3.x < 0.0)
                {
                    tvec3_4.x -= (double)a.LabelFont.GetHeight();
                }
                if ((double)num4 > 0.0)
                {
                    int num5 = (int)((double)height / (double)num4 + 1.0);
                    if (num1 + num5 < num2)
                    {
                        int i = num1;
                        while (i < num2)
                        {
                            if (i + num5 >= num2)
                            {
                                i = num2 - 1;
                            }
                            TVec3  tvec3_5 = taxisCalc.TickPos(i) + tvec3_4;
                            string str     = taxisCalc.TickVal(i).ToString();
                            g.DrawString(str, labelFont, (Brush)solidBrush, (PointF)tvec3_5, format);
                            SizeF sizeF = g.MeasureString(str, labelFont);
                            if ((double)sizeF.Width > (double)num3)
                            {
                                num3 = sizeF.Width;
                            }
                            i += num5;
                        }
                    }
                    else if (num2 > 0)
                    {
                        int    i       = num2 - 1;
                        TVec3  tvec3_5 = taxisCalc.TickPos(i) + tvec3_4;
                        string str     = taxisCalc.TickVal(i).ToString();
                        g.DrawString(str, labelFont, (Brush)solidBrush, (PointF)tvec3_5, format);
                        num3 = g.MeasureString(str, labelFont).Width;
                    }
                }
            }
            if (!a.TitleEnabled)
            {
                return;
            }
            SizeF  sizeF1 = g.MeasureString(a.Title, a.TitleFont);
            PointF point1;
            PointF point2;
            float  angle;

            if (a.Position == EAxisPosition.Bottom)
            {
                if (tvec3_3.x < 0.0)
                {
                    point1    = taxisCalc.TickPos(0).x > taxisCalc.TickPos(1).x ? (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4) : (PointF)(taxisCalc.TickPos(0) + tvec3_4);
                    point1.Y += num3;
                    point2    = point1;
                    angle     = (float)(Math.Atan2(Math.Abs(L.y), Math.Abs(L.x)) * 180.0 / Math.PI);
                }
                else
                {
                    point1    = taxisCalc.TickPos(0).x > taxisCalc.TickPos(1).x ? (PointF)(taxisCalc.TickPos(0) + tvec3_4) : (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4);
                    point1.X += a.LabelFont.GetHeight(g);
                    point1.Y += num3;
                    point2    = point1;
                    point2.X -= sizeF1.Width;
                    angle     = (float)(-Math.Atan2(Math.Abs(L.y), Math.Abs(L.x)) * 180.0 / Math.PI);
                }
            }
            else
            {
                point1    = taxisCalc.TickPos(0).z > taxisCalc.TickPos(1).z ? (PointF)(taxisCalc.TickPos(0) + tvec3_4) : (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4);
                point1.X += num3;
                point2    = point1;
                point2.X -= sizeF1.Width;
                angle     = -90f;
            }
            Matrix matrix = new Matrix();

            matrix.RotateAt(angle, point1, MatrixOrder.Append);
            g.Transform = matrix;
            g.DrawString(a.Title, a.LabelFont, (Brush) new SolidBrush(a.LabelColor), point2);
            matrix.Reset();
            g.Transform = matrix;
        }
Example #20
0
 public TSource(TVec3 o, TColor c)
 {
     this.o = o;
     this.c = c;
 }
Example #21
0
        public void PaintAxes(Pad pad, int left, int top, int h)
        {
            CalculateAxes(pad, left, top, h);
            var v = new TVec3[]
            {
                this.O - 0.5 * Lx - 0.5 * Ly,
                this.O + 0.5 * Lx - 0.5 * Ly,
                this.O + 0.5 * Lx + 0.5 * Ly,
                this.O - 0.5 * Lx + 0.5 * Ly
            };
            double num1 = -1.0;
            int    num2 = -1;

            for (int index = 0; index < v.Length; ++index)
            {
                if (v[index].y > num1)
                {
                    num1 = v[index].y;
                    num2 = index;
                }
            }
            int index1 = 0;
            int index2 = 0;
            int index3 = 0;

            switch (num2)
            {
            case 0:
                index1 = 1;
                index2 = 2;
                index3 = 3;
                break;

            case 1:
                index1 = 2;
                index2 = 3;
                index3 = 0;
                break;

            case 2:
                index1 = 3;
                index2 = 0;
                index3 = 1;
                break;

            case 3:
                index1 = 0;
                index2 = 1;
                index3 = 2;
                break;
            }
            var points1 = TVec3.PointArray(v);
            var points2 = new Point[]
            {
                v[index1],
                v[index2],
                v[index2] + this.Lz,
                v[index1] + this.Lz
            };
            var points3 = new Point[]
            {
                v[index2],
                v[index3],
                v[index3] + Lz,
                v[index2] + Lz
            };
            var graphics = pad.Graphics;

            graphics.Clip = new Region(new Rectangle(pad.X1, pad.Y1, pad.Width + 1, pad.Height + 1));
            var   pen   = new Pen(Color.Black, 1f);
            Brush brush = new SolidBrush(Color.White);

            graphics.FillPolygon(brush, points1);
            graphics.FillPolygon(brush, points2);
            graphics.FillPolygon(brush, points3);
            graphics.DrawPolygon(pen, points1);
            graphics.DrawPolygon(pen, points2);
            graphics.DrawPolygon(pen, points3);
            TView.SetAxesPropertiesFor3D(pad);
            pad.AxisX3D.Position = EAxisPosition.Bottom;
            pad.AxisY3D.Position = EAxisPosition.Bottom;
            pad.AxisZ3D.Position = EAxisPosition.Right;
            PaintAxisGridAndTicks(graphics, pad.AxisX3D, true, v[0], v[0] + Ly, Lx);
            PaintAxisGridAndTicks(graphics, pad.AxisY3D, true, v[0], v[0] + Lx, Ly);
            PaintAxisGridAndTicks(graphics, pad.AxisX3D, false, v[index2], v[index2] + Lz, Lx);
            PaintAxisGridAndTicks(graphics, pad.AxisY3D, false, v[index2], v[index2] + Lz, Ly);
            PaintAxisGridAndTicks(graphics, pad.AxisZ3D, true, v[index2], v[index2] + Lx, Lz);
            PaintAxisGridAndTicks(graphics, pad.AxisZ3D, true, v[index2], v[index2] + Ly, Lz);
        }
Example #22
0
 public void CalculateAxes(Pad pad, int left, int top, int h)
 {
     this.fLeft = left;
     this.fTop = top;
     this.fH = h;
     this.fo = new TVec3((double)(left + h / 2), (double)(top + 3 * h / 4), 0.0);
     if (this.ScaleZ < 1.0)
         this.fo.y -= (1.0 - this.ScaleZ) * 0.25 * (double)h;
     double num = 0.7 * (double)h;
     double Z = 0.5 * this.ScaleZ * (double)h;
     this.fLx = new TVec3(num, 0.0, 0.0);
     this.fLy = new TVec3(0.0, num, 0.0);
     this.fLz = new TVec3(0.0, 0.0, Z);
     this.fLx = this.ms * this.Lx;
     this.fLy = this.ms * this.Ly;
     this.fLz = this.ms * this.Lz;
 }
Example #23
0
 public void PaintAxes(Pad pad, int left, int top, int h)
 {
     CalculateAxes(pad, left, top, h);
     var v = new TVec3[]
     {
         this.O - 0.5 * Lx - 0.5 * Ly,
         this.O + 0.5 * Lx - 0.5 * Ly,
         this.O + 0.5 * Lx + 0.5 * Ly,
         this.O - 0.5 * Lx + 0.5 * Ly
     };
     double num1 = -1.0;
     int num2 = -1;
     for (int index = 0; index < v.Length; ++index)
     {
         if (v[index].y > num1)
         {
             num1 = v[index].y;
             num2 = index;
         }
     }
     int index1 = 0;
     int index2 = 0;
     int index3 = 0;
     switch (num2)
     {
         case 0:
             index1 = 1;
             index2 = 2;
             index3 = 3;
             break;
         case 1:
             index1 = 2;
             index2 = 3;
             index3 = 0;
             break;
         case 2:
             index1 = 3;
             index2 = 0;
             index3 = 1;
             break;
         case 3:
             index1 = 0;
             index2 = 1;
             index3 = 2;
             break;
     }
     var points1 = TVec3.PointArray(v);
     var points2 = new Point[]
     {
         v[index1],
         v[index2],
         v[index2] + this.Lz,
         v[index1] + this.Lz
     };
     var points3 = new Point[]
     {
         v[index2],
         v[index3],
         v[index3] + Lz,
         v[index2] + Lz
     };
     var graphics = pad.Graphics;
     graphics.Clip = new Region(new Rectangle(pad.X1, pad.Y1, pad.Width + 1, pad.Height + 1));
     var pen = new Pen(Color.Black, 1f);
     Brush brush = new SolidBrush(Color.White);
     graphics.FillPolygon(brush, points1);
     graphics.FillPolygon(brush, points2);
     graphics.FillPolygon(brush, points3);
     graphics.DrawPolygon(pen, points1);
     graphics.DrawPolygon(pen, points2);
     graphics.DrawPolygon(pen, points3);
     TView.SetAxesPropertiesFor3D(pad);
     pad.AxisX3D.Position = EAxisPosition.Bottom;
     pad.AxisY3D.Position = EAxisPosition.Bottom;
     pad.AxisZ3D.Position = EAxisPosition.Right;
     PaintAxisGridAndTicks(graphics, pad.AxisX3D, true, v[0], v[0] + Ly, Lx);
     PaintAxisGridAndTicks(graphics, pad.AxisY3D, true, v[0], v[0] + Lx, Ly);
     PaintAxisGridAndTicks(graphics, pad.AxisX3D, false, v[index2], v[index2] + Lz, Lx);
     PaintAxisGridAndTicks(graphics, pad.AxisY3D, false, v[index2], v[index2] + Lz, Ly);
     PaintAxisGridAndTicks(graphics, pad.AxisZ3D, true, v[index2], v[index2] + Lx, Lz);
     PaintAxisGridAndTicks(graphics, pad.AxisZ3D, true, v[index2], v[index2] + Ly, Lz);
 }
Example #24
0
 public TSource(TVec3 o, TColor c)
 {
     O = o;
     C = c;
 }
Example #25
0
 public static TVec3 operator *(TMat3x3 m, TVec3 v)
 {
     var r = new TVec3();
     for (var i = 0; i < 3; ++i)
         for (var j = 0; j < 3; ++j)
             r[i] += m[i, j] * v[j];
     return r;
 }
Example #26
0
 public void PaintAxisGridAndTicks(Graphics g, Axis a, bool marks, TVec3 o, TVec3 o_, TVec3 L)
 {
     a.MinorGridEnabled = false;
     a.MinorTicksEnabled = false;
     int nTicks = (int)(L.NormInf / 10.0);
     if (nTicks < 3)
         nTicks = 3;
     if (nTicks > 10)
         nTicks = 10;
     TAxisCalc taxisCalc = new TAxisCalc(o, o + L, a.Min, a.Max, nTicks);
     TVec3 tvec3_1 = o_ - o;
     TVec3 tvec3_2 = TVec3.O;
     TVec3 tvec3_3 = -0.04 * tvec3_1;
     if (o_.y > o.y)
     {
         tvec3_2 = tvec3_1;
         tvec3_3 = -tvec3_3;
     }
     TVec3 tvec3_4 = tvec3_2 + 1.04 * tvec3_3;
     if (a.GridEnabled)
     {
         Pen pen = new Pen(a.GridColor, a.GridWidth);
         for (int i = 0; i < taxisCalc.nTicks; ++i)
             g.DrawLine(pen, (Point)taxisCalc.TickPos(i), (Point)(taxisCalc.TickPos(i) + tvec3_1));
     }
     if (a.Position == EAxisPosition.Right && tvec3_3.x <= 0.0)
         marks = false;
     if (!marks)
         return;
     int num1 = a.Position == EAxisPosition.Bottom ? 0 : 1;
     int num2 = a.Position == EAxisPosition.Bottom ? taxisCalc.nTicks - 1 : taxisCalc.nTicks;
     float num3 = 0.0f;
     if (a.MajorTicksEnabled)
     {
         Pen pen = new Pen(a.GridColor, a.GridWidth);
         for (int i = num1; i < num2; ++i)
             g.DrawLine(pen, (Point)(taxisCalc.TickPos(i) + tvec3_2), (Point)(taxisCalc.TickPos(i) + tvec3_2 + tvec3_3));
     }
     if (a.LabelEnabled)
     {
         Font labelFont = a.LabelFont;
         float height = labelFont.GetHeight(g);
         SolidBrush solidBrush = new SolidBrush(a.LabelColor);
         StringFormat format = new StringFormat();
         float num4;
         if (a.Position == EAxisPosition.Bottom)
         {
             format.FormatFlags = StringFormatFlags.DirectionVertical;
             num4 = (float)Math.Abs(taxisCalc.TickPos(1).x - taxisCalc.TickPos(0).x);
         }
         else
         {
             tvec3_4.y -= 0.5 * (double)a.LabelFont.GetHeight();
             num4 = (float)Math.Abs(taxisCalc.TickPos(1).y - taxisCalc.TickPos(0).y);
         }
         if (tvec3_3.x < 0.0)
             tvec3_4.x -= (double)a.LabelFont.GetHeight();
         if ((double)num4 > 0.0)
         {
             int num5 = (int)((double)height / (double)num4 + 1.0);
             if (num1 + num5 < num2)
             {
                 int i = num1;
                 while (i < num2)
                 {
                     if (i + num5 >= num2)
                         i = num2 - 1;
                     TVec3 tvec3_5 = taxisCalc.TickPos(i) + tvec3_4;
                     string str = taxisCalc.TickVal(i).ToString();
                     g.DrawString(str, labelFont, (Brush)solidBrush, (PointF)tvec3_5, format);
                     SizeF sizeF = g.MeasureString(str, labelFont);
                     if ((double)sizeF.Width > (double)num3)
                         num3 = sizeF.Width;
                     i += num5;
                 }
             }
             else if (num2 > 0)
             {
                 int i = num2 - 1;
                 TVec3 tvec3_5 = taxisCalc.TickPos(i) + tvec3_4;
                 string str = taxisCalc.TickVal(i).ToString();
                 g.DrawString(str, labelFont, (Brush)solidBrush, (PointF)tvec3_5, format);
                 num3 = g.MeasureString(str, labelFont).Width;
             }
         }
     }
     if (!a.TitleEnabled)
         return;
     SizeF sizeF1 = g.MeasureString(a.Title, a.TitleFont);
     PointF point1;
     PointF point2;
     float angle;
     if (a.Position == EAxisPosition.Bottom)
     {
         if (tvec3_3.x < 0.0)
         {
             point1 = taxisCalc.TickPos(0).x > taxisCalc.TickPos(1).x ? (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4) : (PointF)(taxisCalc.TickPos(0) + tvec3_4);
             point1.Y += num3;
             point2 = point1;
             angle = (float)(Math.Atan2(Math.Abs(L.y), Math.Abs(L.x)) * 180.0 / Math.PI);
         }
         else
         {
             point1 = taxisCalc.TickPos(0).x > taxisCalc.TickPos(1).x ? (PointF)(taxisCalc.TickPos(0) + tvec3_4) : (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4);
             point1.X += a.LabelFont.GetHeight(g);
             point1.Y += num3;
             point2 = point1;
             point2.X -= sizeF1.Width;
             angle = (float)(-Math.Atan2(Math.Abs(L.y), Math.Abs(L.x)) * 180.0 / Math.PI);
         }
     }
     else
     {
         point1 = taxisCalc.TickPos(0).z > taxisCalc.TickPos(1).z ? (PointF)(taxisCalc.TickPos(0) + tvec3_4) : (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4);
         point1.X += num3;
         point2 = point1;
         point2.X -= sizeF1.Width;
         angle = -90f;
     }
     Matrix matrix = new Matrix();
     matrix.RotateAt(angle, point1, MatrixOrder.Append);
     g.Transform = matrix;
     g.DrawString(a.Title, a.LabelFont, (Brush)new SolidBrush(a.LabelColor), point2);
     matrix.Reset();
     g.Transform = matrix;
 }
Example #27
0
 public static Point[] PointArray(TVec3[] v) => v.Select(i => (Point) i).ToArray();
Example #28
0
 public TVec3(TVec3 v) : this(v.x, v.y, v.z)
 {
 }
Example #29
0
 public static Point[] PointArray(TVec3[] v)
 {
     var points = new Point[v.Length];
     Parallel.For(0, v.Length, i => points[i] = v[i]);
     return points;
 }
Example #30
0
 private TColor color(double x, double y, double dx, double dy, TColor Diffuse)
 {
     TVec3 n = new TVec3(dx, 0.0, this.f(x + dx, y) - this.f(x, y)) ^ new TVec3(0.0, dy, this.f(x, y + dy) - this.f(x, y));
     return this.Light.Result(new TVec3(x, y, this.f(x, y)), n, Diffuse);
 }
Example #31
0
 public TVec3(TVec3 v)
     : this(v.x, v.y, v.z)
 {
 }