Exemple #1
0
        protected Point3D Smooth(int index, ScanLine prev, ScanLine current, ScanLine next)
        {
            //http://paulbourke.net/geometry/polygonmesh/
            Point3DList nearPoints = new Point3DList();

            if (index > 0)
            {
                Point3D prevP = current[index - 1];
                nearPoints.Add(prevP);
                nearPoints.Add(prev.GetInterpolateByY(prevP.Position.Y));
                nearPoints.Add(next.GetInterpolateByY(prevP.Position.Y));
            }
            Point3D pt = current[index];

            nearPoints.Add(pt);
            nearPoints.Add(prev.GetInterpolateByY(pt.Position.Y));
            nearPoints.Add(next.GetInterpolateByY(pt.Position.Y));

            if (index < current.Count - 1)
            {
                Point3D nextP = current[index + 1];
                nearPoints.Add(nextP);
                nearPoints.Add(prev.GetInterpolateByY(nextP.Position.Y));
                nearPoints.Add(next.GetInterpolateByY(nextP.Position.Y));
            }


            Point3D ret = Smooth(current[index], nearPoints);

            return(ret);
        }
Exemple #2
0
        public override void DoDamageBoat(BaseGalleon galleon)
        {
            if (galleon == null)
            {
                return;
            }

            m_HasPushed = false;
            IPoint2D pnt = galleon;

            if (Combatant != null && galleon.Contains(Combatant))
            {
                pnt = Combatant;
            }

            Direction   dir  = Utility.GetDirection(this, pnt);
            Point3DList path = new Point3DList();

            for (int i = 0; i < DamageRange; i++)
            {
                int x = 0, y = 0;
                switch ((int)dir)
                {
                case (int)Direction.Running:
                case (int)Direction.North: { y -= i; break; }

                case 129:
                case (int)Direction.Right: { y -= i; x += i; break; }

                case 130:
                case (int)Direction.East: { x += i; break; }

                case 131:
                case (int)Direction.Down: { x += i; y += i; break; }

                case 132:
                case (int)Direction.South: { y += i; break; }

                case 133:
                case (int)Direction.Left: { y += i; x -= i; break; }

                case 134:
                case (int)Direction.West: { x -= i; break; }

                case (int)Direction.ValueMask:
                case (int)Direction.Up: { x -= i; y -= i; break; }
                }

                path.Add(this.X + x, this.Y + y, this.Z);
            }

            new EffectsTimer(this, path, dir, DamageRange);
        }
        /** Lookup the 3D points for each pixel location */
        public Point3DList MapPoints(List <PointF> laserLocations, Bitmap image, Color defColor)
        {
            double MAX_DIST_Y     = TableSize.Height * 2;
            double MAX_DIST_XZ_SQ = (TableSize.Width / 2) * (TableSize.Width / 2);

            Point3DList points = new Point3DList(laserLocations.Count);

            int numIntersectionFails = 0;
            int numDistanceFails     = 0;

            Ray  ray;
            bool haveImage = image != null;

            // Initialize our output variable
            for (int iLoc = 0; iLoc < laserLocations.Count; iLoc++)
            {
                // Compute the back projection ray
                ray = CalculateCameraRay(laserLocations[iLoc]);

                // Intersect the laser plane and populate the XYZ
                Point3D point = new Point3D();
                if (IntersectLaserPlane(ray, ref point, laserLocations[iLoc]))
                {
                    // The point must be above the turn table and less than the max distance from the center of the turn table
                    double distXZSq = point.Position.X * point.Position.X + point.Position.Z * point.Position.Z;

                    if (point.Position.Y >= 0.0 && distXZSq < MAX_DIST_XZ_SQ && point.Position.Y < MAX_DIST_Y)
                    {
                        // Set the color
                        if (haveImage)
                        {
                            point.Color = image.GetPixel(Utils.ROUND(laserLocations[iLoc].X), Utils.ROUND(laserLocations[iLoc].Y));
                        }
                        else
                        {
                            point.Color = defColor;
                        }

                        // Make sure we have the correct laser location
                        laserLocations[points.Count] = laserLocations[iLoc];
                        points.Add(point);
                    }
                    else
                    {
                        numDistanceFails++;
                    }
                }
                else
                {
                    numIntersectionFails++;
                }
            }

            if (numIntersectionFails > 0)
            {
                Debug.WriteLine("!! " + numIntersectionFails + " laser plane intersection failures.");
            }

            if (numDistanceFails > 0)
            {
                Debug.WriteLine("!! " + numDistanceFails + " object bounds failures. ");
            }
            return(points);
        }
		/** Lookup the 3D points for each pixel location */
        public Point3DList MapPoints(List<PointF> laserLocations, Bitmap image, Color defColor)
		{
			double MAX_DIST_Y = TableSize.Height * 2;
			double MAX_DIST_XZ_SQ = (TableSize.Width / 2) * (TableSize.Width / 2);

			Point3DList points = new Point3DList(laserLocations.Count);

			int numIntersectionFails = 0;
			int numDistanceFails = 0;

			Ray ray;
			bool haveImage = image != null;

			// Initialize our output variable
			for (int iLoc = 0; iLoc < laserLocations.Count; iLoc++)
			{
				// Compute the back projection ray
				ray = CalculateCameraRay(laserLocations[iLoc]);

				// Intersect the laser plane and populate the XYZ
				Point3D point = new Point3D();
				if (IntersectLaserPlane(ray, ref point, laserLocations[iLoc]))
				{
					// The point must be above the turn table and less than the max distance from the center of the turn table
					double distXZSq = point.Position.X * point.Position.X + point.Position.Z * point.Position.Z;

					if (point.Position.Y >= 0.0 && distXZSq < MAX_DIST_XZ_SQ && point.Position.Y < MAX_DIST_Y)
					{
						// Set the color
						if (haveImage)
						{
							point.Color = image.GetPixel(Utils.ROUND(laserLocations[iLoc].X), Utils.ROUND(laserLocations[iLoc].Y));
						}
						else
							point.Color = defColor;

						// Make sure we have the correct laser location
						laserLocations[points.Count] = laserLocations[iLoc];
						points.Add(point);
					}
					else
					{
						numDistanceFails++;
					}
				}
				else
				{
					numIntersectionFails++;
				}
			}

			if (numIntersectionFails > 0)
			{
				Debug.WriteLine("!! " + numIntersectionFails + " laser plane intersection failures.");
			}

			if (numDistanceFails > 0)
			{
				Debug.WriteLine("!! " + numDistanceFails + " object bounds failures. ");
			}
			return points;
		}
		protected Point3D Smooth(int index, ScanLine prev, ScanLine current, ScanLine next)
		{
			//http://paulbourke.net/geometry/polygonmesh/
			Point3DList nearPoints = new Point3DList();
			if (index > 0)
			{
				Point3D prevP = current[index - 1];
				nearPoints.Add(prevP);
				nearPoints.Add(prev.GetInterpolateByY(prevP.Position.Y));
				nearPoints.Add(next.GetInterpolateByY(prevP.Position.Y));
			}
			Point3D pt = current[index];
			nearPoints.Add(pt);
			nearPoints.Add(prev.GetInterpolateByY(pt.Position.Y));
			nearPoints.Add(next.GetInterpolateByY(pt.Position.Y));

			if (index <current.Count-1)
			{
				Point3D nextP = current[index + 1];
				nearPoints.Add(nextP);
				nearPoints.Add(prev.GetInterpolateByY(nextP.Position.Y));
				nearPoints.Add(next.GetInterpolateByY(nextP.Position.Y));
			}


			Point3D ret = Smooth(current[index], nearPoints);
			return ret;
		}
        Point3DList FindDrawingPoints(int curveIndex)
        {
            Point3DList pointList = new Point3DList();

            Point3D left = CalculateBezierPoint(curveIndex, 0);
            Point3D right = CalculateBezierPoint(curveIndex, 1);

            pointList.Add(left);
            pointList.Add(right);

            FindDrawingPoints(curveIndex, 0, 1, pointList, 1);

            return pointList;
        }
        /**
            Gets the drawing points. This implementation simply calculates a certain number
            of points per curve.

            This is a lsightly different inplementation from the one above.
        */
        public Point3DList GetDrawingPoints1()
        {
            Point3DList drawingPoints = new Point3DList();

            for (int i = 0; i < controlPoints.Count - 3; i += 3)
            {
                Point3D p0 = controlPoints[i];
                Point3D p1 = controlPoints[i + 1];
                Point3D p2 = controlPoints[i + 2];
                Point3D p3 = controlPoints[i + 3];

                if (i == 0) //only do this for the first end point. When i != 0, this coincides with the end point of the previous segment,
                {
                    drawingPoints.Add(CalculateBezierPoint(0, p0, p1, p2, p3));
                }

                for (int j = 1; j <= SEGMENTS_PER_CURVE; j++)
                {
                    double t = j / (double)SEGMENTS_PER_CURVE;
                    drawingPoints.Add(CalculateBezierPoint(t, p0, p1, p2, p3));
                }
            }

            return drawingPoints;
        }
        /**
            Gets the drawing points. This implementation simply calculates a certain number
            of points per curve.
        */
        public Point3DList GetDrawingPoints0()
        {
            Point3DList drawingPoints = new Point3DList();

            for (int curveIndex = 0; curveIndex < curveCount; curveIndex++)
            {
                if (curveIndex == 0) //Only do this for the first end point. 
                //When i != 0, this coincides with the 
                //end point of the previous segment,
                {
                    drawingPoints.Add(CalculateBezierPoint(curveIndex, 0));
                }

                for (int j = 1; j <= SEGMENTS_PER_CURVE; j++)
                {
                    double t = j / (double)SEGMENTS_PER_CURVE;
                    drawingPoints.Add(CalculateBezierPoint(curveIndex, t));
                }
            }

            return drawingPoints;
        }