public Intersection IsInside(BoundingBox box) { if (box.Max.X < Min.X || box.Min.X > Max.X || box.Max.Y < Min.Y || box.Min.Y > Max.Y || box.Max.Z < Min.Z || box.Min.Z > Max.Z) return Intersection.OUTSIDE; else if (box.Min.X < Min.X || box.Max.X > Max.X || box.Min.Y < Min.Y || box.Max.Y > Max.Y || box.Min.Z < Min.Z || box.Max.Z > Max.Z) return Intersection.INTERSECTS; else return Intersection.INSIDE; }
void CreateScene() { var cache = GetSubsystem<ResourceCache>(); scene = new Scene(); // Create the Octree component to the scene so that drawable objects can be rendered. Use default volume // (-1000, -1000, -1000) to (1000, 1000, 1000) scene.CreateComponent<Octree>(); scene.CreateComponent<DebugRenderer>(); // Create scene node & StaticModel component for showing a static plane var planeNode = scene.CreateChild("Plane"); planeNode.Scale = new Vector3(100, 1, 100); var planeObject = planeNode.CreateComponent<StaticModel>(); planeObject.Model = cache.Get<Model>("Models/Plane.mdl"); planeObject.SetMaterial(cache.Get<Material>("Materials/StoneTiled.xml")); // Create a Zone component for ambient lighting & fog control var zoneNode = scene.CreateChild("Zone"); var zone = zoneNode.CreateComponent<Zone>(); // Set same volume as the Octree, set a close bluish fog and some ambient light zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f)); zone.AmbientColor = new Color(0.15f, 0.15f, 0.15f); zone.FogColor = new Color(0.5f, 0.5f, 0.7f); zone.FogStart = 100; zone.FogEnd = 300; // Create a directional light to the world. Enable cascaded shadows on it var lightNode = scene.CreateChild("DirectionalLight"); lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f)); var light = lightNode.CreateComponent<Light>(); light.LightType = LightType.LIGHT_DIRECTIONAL; light.CastShadows = true; light.ShadowBias = new BiasParameters(0.00025f, 0.5f); // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance light.ShadowCascade = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f); // Create animated models const int numModels = 100; const float modelMoveSpeed = 2.0f; const float modelRotateSpeed = 100.0f; var bounds = new BoundingBox(new Vector3(-47.0f, 0.0f, -47.0f), new Vector3(47.0f, 0.0f, 47.0f)); for (var i = 0; i < numModels; ++i) { var modelNode = scene.CreateChild("Jack"); modelNode.Position = new Vector3(NextRandom(-45, 45), 0.0f, NextRandom(-45, 45)); modelNode.Rotation = new Quaternion(0, NextRandom(0, 360), 0); //var modelObject = modelNode.CreateComponent<AnimatedModel>(); var modelObject = new AnimatedModel(); modelNode.AddComponent(modelObject); modelObject.Model = cache.Get<Model>("Models/Jack.mdl"); //modelObject.Material = cache.GetMaterial("Materials/Jack.xml"); modelObject.CastShadows = true; // Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the // animation, The alternative would be to use an AnimationController component which updates the animation automatically, // but we need to update the model's position manually in any case var walkAnimation = cache.Get<Animation>("Models/Jack_Walk.ani"); var state = modelObject.AddAnimationState(walkAnimation); // The state would fail to create (return null) if the animation was not found if (state != null) { // Enable full blending weight and looping state.Weight = 1; state.Looped = true; } // Create our custom Mover component that will move & animate the model during each frame's update var mover = new Mover(modelMoveSpeed, modelRotateSpeed, bounds); modelNode.AddComponent(mover); } // Create the camera. Limit far clip distance to match the fog CameraNode = scene.CreateChild("Camera"); camera = CameraNode.CreateComponent<Camera>(); camera.FarClip = 300; // Set an initial position for the camera scene node above the plane CameraNode.Position = new Vector3(0.0f, 5.0f, 0.0f); }
public void Merge(BoundingBox box) { if (box.Min.X < Min.X) Min.X = box.Min.X; if (box.Min.Y < Min.Y) Min.Y = box.Min.Y; if (box.Min.Z < Min.Z) Min.Z = box.Min.Z; if (box.Max.X > Max.X) Max.X = box.Max.X; if (box.Max.Y > Max.Y) Max.Y = box.Max.Y; if (box.Max.Z > Max.Z) Max.Z = box.Max.Z; }
public Mover(float moveSpeed, float rotateSpeed, BoundingBox bounds) { MoveSpeed = moveSpeed; RotationSpeed = rotateSpeed; Bounds = bounds; }