Example #1
0
        ///<summary>贝塞尔平滑插点计算,X方向</summary>
        private Point3D[,] insertXPoint(Point3D[,] allpoint, int insertcount) //x方向插点
        {
            // bezier平滑插值
            Point[] ap, cp1, cp2;
            Point   calpoint;

            Point3D[,] resultpoint = new Point3D[(allpoint.GetLength(0) - 1) * (insertcount + 1) + 1, allpoint.GetLength(1)];
            Point[] cp = new Point[4];
            for (int i = 0; i < allpoint.GetLength(1); i++)
            {
                ap = new Point[allpoint.GetLength(0)];
                for (int j = 0; j < allpoint.GetLength(0); j++)
                {
                    ap[j].X = allpoint[j, i].X;
                    ap[j].Y = allpoint[j, i].Y;
                }
                MyGeometryHelper.GetCurveControlPoints(ap, out cp1, out cp2);
                for (int j = 0; j < allpoint.GetLength(0) - 1; j++)
                {
                    resultpoint[j * (insertcount + 1), i] = allpoint[j, i]; //原有的点
                    cp[0] = ap[j]; cp[1] = cp1[j]; cp[2] = cp2[j]; cp[3] = ap[j + 1];
                    for (int k = 0; k < insertcount; k++)
                    {
                        calpoint = MyGeometryHelper.PointOnBezier(cp, 1.0 / (insertcount + 1) * (k + 1));
                        resultpoint[j * (insertcount + 1) + 1 + k, i] = new Point3D(calpoint.X, calpoint.Y, allpoint[j, i].Z); //插入的点
                    }
                }
                resultpoint[(allpoint.GetLength(0) - 1) * (insertcount + 1), i] = allpoint[allpoint.GetLength(0) - 1, i]; //原有的终点
            }
            return(resultpoint);
        }
Example #2
0
 public MyModel(Game game, int id, Model model, Vector3 position, MyCamera camera) : base(game)
 {
     this.Id             = id;
     this.model          = model;
     this.Position       = position;
     this.changeMatrix   = Matrix.Identity;
     this.Rotation       = Vector3.Zero;
     this.Scale          = Vector3.One;
     this.camera         = camera;
     this.boundingSphere = MyGeometryHelper.GetBoundingSphere(model);
 }
        /// <summary>
        /// 绘图方法
        /// </summary>
        /// <param name="gameTime">时间</param>
        public override void Draw(GameTime gameTime)
        {
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                this.Game.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, lineData, 0, lineData.Length / 2, VertexPositionColor.VertexDeclaration);

                if (roadData != null && roadData.Length != 0)
                {
                    this.Game.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, roadData, 0, roadData.Length / 3, VertexPositionColor.VertexDeclaration);
                }
                if (wallData != null && wallData.Length != 0)
                {
                    this.Game.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, wallData, 0, wallData.Length / 3, VertexPositionColor.VertexDeclaration);
                }
                MyGeometryHelper.FillRect(this.Game, graphics, new Vector2(start.X * 10, start.Y * 10), new Vector2(10, 10), Color.Green);
                MyGeometryHelper.FillRect(this.Game, graphics, new Vector2(end.X * 10, end.Y * 10), new Vector2(10, 10), Color.Orange);
            }
            base.Draw(gameTime);
        }