Esempio n. 1
0
        /// <summary>
        /// Spread flora over intersection of road.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        public override bool NewFan(
            Road.Intersection isect,
            Road.Section first,
            Road.Section second,
            List <Road.RenderObj> fans)
        {
            FBXModel model = EndModel;

            if (model != null)
            {
                RoadFBXRenderObj ro = new RoadFBXRenderObj();

                ro.Model    = model;
                ro.Animator = EndAnim;

                Matrix  localToWorld = Matrix.Identity;
                Vector3 position     = isect.Node.Position;
                position.Z = Terrain.GetTerrainHeightFlat(position) + isect.Node.Height;
                localToWorld.Translation = position;
                RandomizeAngle(ref localToWorld);
                ro.LocalToWorld = localToWorld;

                fans.Add(ro);
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Put down a tree at the intersection.
        /// </summary>
        public override bool NewFan(
            Road.Intersection isect,
            Road.Section first,
            Road.Section second,
            List <Road.RenderObj> fans)
        {
            FBXModel model = EndModel;

            if (model != null)
            {
                RoadMultiRenderObj multiRo = new RoadMultiRenderObj();

                Vector2 center = isect.Node.Position2d;

                float area = width * width * (float)Math.PI;

                int count = (int)Math.Ceiling(area * density);

                for (int i = 0; i < count; ++i)
                {
                    double rndAng = BokuGame.bokuGame.rnd.NextDouble() * Math.PI * 2.0;
                    float  rndOut = (float)(BokuGame.bokuGame.rnd.NextDouble() * 2.0 - 1.0);

                    float cos = (float)Math.Cos(rndAng);
                    float sin = (float)Math.Sin(rndAng);

                    Vector2 rndPos = center;
                    rndPos.X += cos * rndOut;
                    rndPos.Y += sin * rndOut;
                    float height = Terrain.GetTerrainHeightFlat(rndPos);

                    Matrix localToWorld = Matrix.CreateTranslation(rndPos.X, rndPos.Y, height);

                    RoadFBXRenderObj ro = new RoadFBXRenderObj();
                    ro.Model        = model;
                    ro.Animator     = EndAnim;
                    ro.LocalToWorld = localToWorld;

                    multiRo.RenderObjList.Add(ro);
                }

                fans.Add(multiRo);

                return(count > 0);
            }
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Spread flora over new section of road.
        /// </summary>
        /// <param name="section"></param>
        public override void NewSection(Road.Section section)
        {
            RoadMultiRenderObj multiRo = null;
            FBXModel           model   = Model;

            if (model != null)
            {
                multiRo = new RoadMultiRenderObj();

                Vector2 start = section.Edge.Node0.Position2d;
                Vector2 end   = section.Edge.Node1.Position2d;
                Vector2 axis  = end - start;
                Vector2 norm  = new Vector2(-axis.Y, axis.X);
                norm = Vector2.Normalize(norm) * width;

                float area = axis.Length() * width * 2.0f;

                int count = (int)Math.Ceiling(area * density);

                for (int i = 0; i < count; ++i)
                {
                    float rndTo  = (float)BokuGame.bokuGame.rnd.NextDouble();
                    float rndOut = (float)(BokuGame.bokuGame.rnd.NextDouble() * 2.0 - 1.0);

                    Vector2 rndPos = start + rndTo * axis + rndOut * norm;
                    float   height = Terrain.GetTerrainHeightFlat(rndPos);

                    height += section.Edge.Node0.Height + rndTo * (section.Edge.Node1.Height - section.Edge.Node0.Height);

                    Matrix localToWorld = Matrix.CreateTranslation(rndPos.X, rndPos.Y, height);

                    RandomizeAngle(ref localToWorld);

                    RoadFBXRenderObj ro = new RoadFBXRenderObj();
                    ro.Model        = model;
                    ro.LocalToWorld = localToWorld;
                    ro.Animator     = Anim;

                    multiRo.RenderObjList.Add(ro);
                }
            }
            section.RenderObj = multiRo;
        }
Esempio n. 4
0
        /// <summary>
        /// Generate a castle as an intersection.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        public override bool NewFan(
            Road.Intersection isect,
            Road.Section first,
            Road.Section second,
            List <Road.RenderObj> fans)
        {
            bool didBase = base.NewFan(isect, first, second, fans);

            WayPoint.Node node = isect.Node;

            /*
             * centerheight
             * 4.4
             * height
             * 4.3, 2.0, 2.3, 2.3, -1.0
             * width
             * 0.05, 0.2, 0.2, 0.3, 0.3
             * */
            RoadFBXRenderObj ro    = null;
            FBXModel         model = ActorManager.GetActor("Castle").Model;

            if (model != null)
            {
                ro = new RoadFBXRenderObj();

                ro.Model = model;

                Matrix  localToWorld = Matrix.Identity;
                Vector3 position     = node.Position;
                localToWorld.Translation = position;
                ro.LocalToWorld          = localToWorld;

                fans.Add(ro);

                return(true);
            }
            return(didBase);
        }