public void LoadNewTree(string profileName, int seed = -1, bool displayBranch = true, bool wind = true) { TreeProfile profile = Content.Load <TreeProfile>(profileName); if (seed == -1) { tree = profile.GenerateSimpleTree(); } else { Random rand = new Random(seed); tree = profile.GenerateSimpleTree(rand); } useTree = true; treeUseBranches = displayBranch; treeUseWind = wind; // Wind treeWind = new LTreesLibrary.Trees.Wind.WindStrengthSin(); treeAnimator = new LTreesLibrary.Trees.Wind.TreeWindAnimator(treeWind); // Scale ChangeCameraZoom(0); float BoundingSphereRadius = (float)(new Ray(Vector3.Zero, Vector3.Up)).Intersects(camera._frustum.Top); treeScale = BoundingSphereRadius / tree.TrunkMesh.BoundingSphere.Radius; treeMatrices = new Matrix[2]; treeMatrices[0] = Matrix.CreateScale(treeScale); treeMatrices[1] = Matrix.CreateTranslation(new Vector3(0, -BoundingSphereRadius / 2, 0)); }
protected override void LoadBatchInfo(GraphicFactory factory, out BatchInformation[][] BatchInformations) { TreeProfile t = factory.GetAsset <TreeProfile>(profileName); if (!String.IsNullOrEmpty(LeaftextureName)) { t.LeafTexture = factory.GetAsset <Texture2D>(LeaftextureName); } if (!String.IsNullOrEmpty(trunktextureName)) { t.TrunkTexture = factory.GetAsset <Texture2D>(trunktextureName); } tree = t.GenerateSimpleTree(StaticRandom.RandomInstance); BatchInformations = new BatchInformation[2][]; vertexBufferS = new VertexBuffer[2]; indexBufferS = new IndexBuffer[2]; indexBufferS[0] = tree.TrunkMesh.IndexBuffer; vertexBufferS[0] = tree.TrunkMesh.VertexBuffer; BatchInformation bi0 = new BatchInformation(0, tree.TrunkMesh.NumberOfVertices, tree.TrunkMesh.NumberOfTriangles, 0, 0, tree.TrunkMesh.Vdeclaration, TreeVertex.SizeInBytes); BatchInformations[0] = new BatchInformation[1]; BatchInformations[0][0] = bi0; indexBufferS[1] = tree.LeafCloud.Ibuffer; vertexBufferS[1] = tree.LeafCloud.Vbuffer; BatchInformation bi1 = new BatchInformation(0, tree.LeafCloud.Numleaves * 4, tree.LeafCloud.Numleaves * 2, 0, 0, tree.LeafCloud.Vdeclaration, LeafVertex.SizeInBytes); BatchInformations[1] = new BatchInformation[1]; BatchInformations[1][0] = bi1; }
public override void Initialize() { _treeProfile = Content.Load <TreeProfile>("Trees/Graywood"); _tree = new SunlitSimpleTree(_treeProfile.GenerateSimpleTree()); _tree.Lighting = _sky; // Scale tree down to a desired height const int desiredHeight = 6; float treeModelHeight = _tree.TrunkMesh.BoundingSphere.Radius * 2; _scale = Matrix.CreateScale(desiredHeight / treeModelHeight); Position = _position; _wind = new WindStrengthSin(); _animator = new TreeWindAnimator(_wind); base.Initialize(); }
public override void Initialise(GraphicsDevice device, ContentManager content) { m_content = content; m_camera_position = new Vector3(600, 2, -500); m_camera_target = new Vector3(0, 2, 0); m_rand = new Random(); m_trunk = content.Load <Effect>("Trunk"); m_leaves = content.Load <Effect>("Leaves"); m_trunk_texture = content.Load <Texture2D>(@"Trees\PineBark"); m_leaves_texture = content.Load <Texture2D>(@"Trees\PineLeaf"); m_generator = TreeGenerator.CreateFromXml(@"Data\Trees\Pine.xml"); m_profile = new TreeProfile(device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves); m_tree = m_profile.GenerateSimpleTree(m_rand); m_projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), device.Viewport.AspectRatio, 0.5f, 20000.0f); m_world = Matrix.CreateScale(0.1f); // Matrix.CreateTranslation(Vector3.Zero); m_view = Matrix.CreateLookAt(m_camera_position, m_camera_target, Vector3.Up); m_device = device; }
public override void Update(float dt) { angle += MathHelper.ToRadians(10) * dt; m_world = Matrix.CreateScale(0.1f) * Matrix.CreateRotationY(angle); if ((Game1.Instance.last_mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) && (Game1.Instance.current_mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)) { for (int i = 0; i < Buttons.Length; i++) { if (Buttons[i].Contains(Game1.Instance.current_mouse_state.X, Game1.Instance.current_mouse_state.Y)) { switch (i) { case 0: { m_trunk_texture = m_content.Load <Texture2D>(@"Trees\PineBark"); m_leaves_texture = m_content.Load <Texture2D>(@"Trees\PineLeaf"); m_generator = TreeGenerator.CreateFromXml(@"Data\Trees\Pine.xml"); m_profile = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves); m_tree = m_profile.GenerateSimpleTree(m_rand); } break; case 1: { m_trunk_texture = m_content.Load <Texture2D>(@"Trees\BirchBark"); m_leaves_texture = m_content.Load <Texture2D>(@"Trees\BirchLeaf"); m_generator = TreeGenerator.CreateFromXml(@"Data\Trees\Birch.xml"); m_profile = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves); m_tree = m_profile.GenerateSimpleTree(m_rand); } break; case 2: { m_trunk_texture = m_content.Load <Texture2D>(@"Trees\wood_dark"); m_leaves_texture = m_content.Load <Texture2D>(@"Trees\WillowLeaf"); m_generator = TreeGenerator.CreateFromXml(@"Data\Trees\Willow.xml"); m_profile = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves); m_tree = m_profile.GenerateSimpleTree(m_rand); } break; case 3: { m_trunk_texture = m_content.Load <Texture2D>(@"Trees\GrayBark"); m_leaves_texture = m_content.Load <Texture2D>(@"Trees\GraywoodLeaf"); m_generator = TreeGenerator.CreateFromXml(@"Data\Trees\Graywood.xml"); m_profile = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves); m_tree = m_profile.GenerateSimpleTree(m_rand); } break; case 4: { m_trunk_texture = m_content.Load <Texture2D>(@"Trees\wood_dark"); m_leaves_texture = m_content.Load <Texture2D>(@"Trees\OakLeaf"); m_generator = TreeGenerator.CreateFromXml(@"Data\Trees\Gardenwood.xml"); m_profile = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves); m_tree = m_profile.GenerateSimpleTree(m_rand); } break; case 5: { m_trunk_texture = m_content.Load <Texture2D>(@"Trees\PineBark"); m_leaves_texture = m_content.Load <Texture2D>(@"Trees\WillowLeaf"); m_generator = TreeGenerator.CreateFromXml(@"Data\Trees\Rug.xml"); m_profile = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves); m_tree = m_profile.GenerateSimpleTree(m_rand); } break; } } } } }