public Tree(TreeGroup group, SpeedTreeWrapper speedTree, Vector3 location) { this.group = group; this.location = location; this.speedTree = speedTree; billboard0 = new float[20]; billboard1 = new float[20]; // set location for the instance speedTree.TreePosition = SpeedTreeUtil.ToSpeedTree(location); // set bounding box AxisAlignedBox stbox = SpeedTreeUtil.FromSpeedTree(speedTree.BoundingBox); this.bounds = new AxisAlignedBox(stbox.Minimum + location, stbox.Maximum + location); }
public void PerFrameProcessing(float time, Camera camera) { Debug.Assert(inBoundary); bool updateVisibility = false; if (pendingTreeTypes != null) { ProcessTreeTypes(); TerrainManager.Instance.RecreateCollisionTiles(); updateVisibility = true; } SpeedTreeWrapper.Time = time; if (bounds != null && camera.IsObjectVisible(bounds)) { // this stuff only needs to be done if the forest is visible // process wind speedWind.Advance(time, windStrength, SpeedTreeUtil.ToSpeedTree(windDirection)); // determine whether the camera changed direction or location since the last frame if (camera.Direction != lastCameraDirection || camera.Position != lastCameraLocation) { updateVisibility = true; lastCameraLocation = camera.Position; lastCameraDirection = camera.Direction; } // if the camera changed position or direction, or new trees were added, then recompute the visibility of this tree if (updateVisibility) { foreach (TreeGroup group in groups) { group.CameraChange(camera); } } foreach (TreeGroup group in groups) { group.UpdateMaterials(); } } }