/// <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); }
/// <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; }