/// <summary> /// Fires a coloured cube from player's position into world. /// </summary> private void FireCube(Vector4[] colors) { float size = 1.5f; // Get next colour for cube Vector4 cubeColor = colors[colorIndex++]; Color lightColor = new Color(cubeColor.X, cubeColor.Y, cubeColor.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 * size; // Create cube entity DynamicEntity cubeEntity = new DynamicEntity(core.ActiveScene); cubeEntity.Matrix = Matrix.CreateTranslation(position); // Attach cube geometry GeometricPrimitiveComponent cubeGeometry = new GeometricPrimitiveComponent(core); cubeGeometry.MakeCube(size); cubeGeometry.Color = cubeColor; cubeEntity.Components.Add(cubeGeometry); // Attach cube physics PhysicsColliderComponent cubePhysics = new PhysicsColliderComponent(core, core.ActiveScene, cubeEntity.Matrix, size, size, size, 1f); cubePhysics.PhysicsEntity.LinearVelocity = cameraFacing * 15f; cubePhysics.PhysicsEntity.Material.Bounciness = 0.0f; cubeEntity.Components.Add(cubePhysics); // Attach cube light if (cubeColor.W > 0.5f) { LightComponent cubeLight = new LightComponent(core, Vector3.Zero, size * 2.5f, lightColor, 2.0f); cubeEntity.Components.Add(cubeLight); } // Set entity to expire after 5 minutes cubeEntity.Components.Add(new ReaperComponent(core, cubeEntity, 300000)); }
/// <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); }