Beispiel #1
0
    public Brush PerceivedColor(LightSource light, _Point CamPosition)
    {
        _Point     LightVector = VectMath.Subtract(this.Position, light.Position);
        _Point     PercVector  = this.Position;
        _Point     Rvector     = VectMath.RotateByAngle(VectMath.Negate(LightVector), Normal, 180);
        double     whitefactor = Math.Abs(.5 * Math.Sin(VectMath.AngleBetween(Normal, LightVector)) + .5);
        double     colorfactor = Math.Abs(Math.Cos(VectMath.AngleBetween(Normal, LightVector)));
        double     Total       = Math.Pow(Math.Sin(VectMath.AngleBetween(PercVector, Rvector)), 2);
        SolidBrush brush       = new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * Total * colorfactor * whitefactor), Convert.ToInt32(255 * Total * whitefactor), Convert.ToInt32(255 * Total * whitefactor)));

        return(brush);
    }
Beispiel #2
0
        public void DrawPlane(Plane plane)
        {
            if (VectMath.AngleBetween(VectMath.Subtract(plane.Position, new _Point(0, 0, 0)), plane.Normal) > Math.PI / 2)
            {
                PointF[] pf = new PointF[plane.Points.Count];

                for (int i = 0; i < pf.Length; i++)
                {
                    Point p = convert2D(plane.Points[i]);
                    pf[i] = new PointF(p.X, p.Y);
                }
                graphics.FillPolygon(plane.PerceivedColor(Sun, new _Point(0, 0, 0)), pf);
                pictureBox1.Image = bm;
                // Globals.PlanePointsToClear.Add(pf);
            }
            // MessageBox.Show(VectMath.AngleBetween(VectMath.Subtract(plane.Position, new _Point(0, 0, 0)), plane.Normal).ToString());
        }
Beispiel #3
0
        public Point convert2D(_Point p)
        {
            if (Camera1.NormalAxis != Axes.Z)
            {
                //IO.Point(p);
                p = VectMath.RotateByAngle(p, VectMath.Cross(Axes.Z, Camera1.NormalAxis), 180 * (VectMath.AngleBetween(new _Point(0, 0, 1), Camera1.NormalAxis)) / Math.PI);
                //IO.Point(p);
            }
            //if( Camera1.VerticalAxis != Axes.Y)
            // {
            //     p = VectMath.RotateByAngle(p, Camera1.NormalAxis, 180*(VectMath.AngleBetween(new _Point(0, 1, 0), Camera1.VerticalAxis))/Math.PI);
            // }
            if (p.z <= 0)
            {
                return(new Point(0, 0));
            }
            int Xcoord = Convert.ToInt32((p.x * Globals.BMSize.Width / 2) / (p.z * Math.Tan(45))) + Globals.BMSize.Width / 2;
            int Ycoord = Convert.ToInt32((-p.y * Globals.BMSize.Height / 2) / (p.z * Math.Tan(45))) + Globals.BMSize.Height / 2;

            p.PF = new PointF(Xcoord, Ycoord);

            return(new Point(Xcoord, Ycoord));
        }