/// <summary> /// Constructor. /// </summary> /// <param name="scene">Scene to attach entity.</param> public Firefly(Scene scene) : base(scene) { // Create sphere sphere = new GeometricPrimitiveComponent(scene.Core); sphere.MakeSphere(0.03125f, 4); Components.Add(sphere); // Create light light = new LightComponent(scene.Core, Vector3.Zero, 1.5f, color, 0.5f); Components.Add(light); // Start random generator rnd = new Random((int)scene.Core.Stopwatch.ElapsedTicks); // Random start alive or resting if (1 == ((int)(rnd.NextDouble() * 10) & 1)) { alive = true; } else { alive = false; restCounterStart = scene.Core.Stopwatch.ElapsedMilliseconds; timeToRest = (long)(maxTimeToRest * rnd.NextDouble()); } // Start firefly StartFirefly(); }
/// <summary> /// Fires a coloured sphere from player's position into world. /// </summary> public void FireSphere() { float radius = 0.70f; // Get next colour for ball Vector4 sphereColor = colors[colorIndex++]; Color lightColor = new Color(sphereColor.X, sphereColor.Y, sphereColor.Z); if (colorIndex >= colors.Length) { colorIndex = 0; } // Get camera facing Vector3 cameraFacing = core.ActiveScene.Camera.TransformedReference; // Get start position Vector3 position = core.ActiveScene.Camera.Position; position += cameraFacing * radius; // Create sphere entity DynamicEntity sphereEntity = new DynamicEntity(core.ActiveScene); sphereEntity.Matrix = Matrix.CreateTranslation(position); // Attach sphere geometry GeometricPrimitiveComponent sphereGeometry = new GeometricPrimitiveComponent(core); sphereGeometry.MakeSphere(radius, 16); sphereGeometry.Color = sphereColor; sphereEntity.Components.Add(sphereGeometry); // Attach sphere physics PhysicsColliderComponent spherePhysics = new PhysicsColliderComponent(core, core.ActiveScene, sphereEntity.Matrix, radius, 1f); spherePhysics.PhysicsEntity.LinearVelocity = cameraFacing * 15f; spherePhysics.PhysicsEntity.Material.Bounciness = 0.2f; sphereEntity.Components.Add(spherePhysics); // Attach sphere light LightComponent sphereLight = new LightComponent(core, Vector3.Zero, radius * 2.5f, lightColor, 2.0f); sphereEntity.Components.Add(sphereLight); // Set entity to expire after 5 minutes sphereEntity.Components.Add(new ReaperComponent(core, sphereEntity, 300000)); soundIndex = 16; LoadSound(); PlaySound(); }
/// <summary> /// Loads a simple physics test scene. /// </summary> private void LoadPhysicsScene() { // Set camera position core.ActiveScene.Camera.Position = new Vector3(-100, -300, 800); // Create cube entity DynamicEntity cubeEntity = new DynamicEntity(core.ActiveScene); cubeEntity.Matrix = Matrix.CreateTranslation(-555, -1024, 0); // Create torus entity DynamicEntity torusEntity = new DynamicEntity(core.ActiveScene); // Create sphere entity DynamicEntity sphereEntity = new DynamicEntity(core.ActiveScene); sphereEntity.Matrix = Matrix.CreateTranslation(-555, 0, 0); // Attach cube geometry GeometricPrimitiveComponent cubeGeometry = new GeometricPrimitiveComponent(core); cubeGeometry.MakeCube(1024f); cubeGeometry.Color = Vector4.One; cubeEntity.Components.Add(cubeGeometry); // Attach cube physics and a directional light PhysicsColliderComponent cubePhysics = new PhysicsColliderComponent(core, core.ActiveScene, cubeEntity.Matrix, 1024f, 1024f, 1024f); LightComponent cubeLight = new LightComponent(core, Vector3.Right, Color.White, 0.5f); cubeEntity.Components.Add(cubePhysics); cubeEntity.Components.Add(cubeLight); // Attach torus geometry GeometricPrimitiveComponent torusGeometry = new GeometricPrimitiveComponent(core); torusGeometry.MakeTorus(64f, 64f, 16); torusGeometry.Color = new Vector4(Color.Red.ToVector3(), 1); torusEntity.Components.Add(torusGeometry); // Attach torus physics and a point light PhysicsColliderComponent torusPhysics = new PhysicsColliderComponent(core, core.ActiveScene, torusEntity.Matrix, 128f, 64f, 128f, 1f); LightComponent torusLight = new LightComponent(core, Vector3.Zero, 512f, Color.Red, 1f); torusEntity.Components.Add(torusPhysics); torusEntity.Components.Add(torusLight); // Attach sphere geometry GeometricPrimitiveComponent sphereGeometry = new GeometricPrimitiveComponent(core); sphereGeometry.MakeSphere(64f, 16); sphereGeometry.Color = new Vector4(Color.Red.ToVector3(), 1); sphereEntity.Components.Add(sphereGeometry); // Attach sphere physics PhysicsColliderComponent spherePhysics = new PhysicsColliderComponent(core, core.ActiveScene, sphereEntity.Matrix, 64f, 1f); spherePhysics.PhysicsEntity.Material.Bounciness = 0.0f; sphereEntity.Components.Add(spherePhysics); // Share torus light with sphere sphereEntity.Components.Add(torusLight); }