/// <summary> /// Fires an octahedron. /// </summary> private void FireOctahedron() { // Get model DaggerfallModelComponent model = new DaggerfallModelComponent(core, (int)PhysicsObjects.Octahedron); // Get camera facing Vector3 cameraFacing = core.ActiveScene.Camera.TransformedReference; // Get start position Vector3 position = core.ActiveScene.Camera.Position; position += cameraFacing * (model.BoundingSphere.Radius * 3); // Create entity DynamicEntity entity = new DynamicEntity(core.ActiveScene); entity.Matrix = Matrix.CreateRotationY(MathHelper.ToRadians(scene.Camera.Yaw)) * Matrix.CreateTranslation(position); // Attach geometry entity.Components.Add(model); // Attach physics PhysicsColliderComponent physics = new PhysicsColliderComponent(core, core.ActiveScene, entity.Matrix, model.ModelData.GetPointList(), 2f); //physics.PhysicsEntity.LinearVelocity = cameraFacing * 15f; physics.PhysicsEntity.AngularMomentum = new Vector3(0.0001f, 10, 0.0001f); physics.PhysicsEntity.Material.Bounciness = 0.1f; entity.Components.Add(physics); // Set entity to expire after 5 minutes entity.Components.Add(new ReaperComponent(core, entity, 300000)); }
public PhysicsElementInfo(PhysicsColliderComponent component) { shape = component.ColliderShape; var rigidbodyComponent = component as RigidbodyComponent; isKinematic = rigidbodyComponent != null && rigidbodyComponent.IsKinematic; colliderShapes = component.ColliderShapes != null?CloneDescs(component.ColliderShapes) : null; var triggerBase = component as StaticColliderComponent; isTrigger = triggerBase != null && triggerBase.GenerateOverlapEvents; }
/// <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> /// 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)); }
public bool HasChanged(PhysicsColliderComponent component) { var triggerBase = component as StaticColliderComponent; var rb = component as RigidbodyComponent; return(shape != component.ColliderShape || (colliderShapes == null && component.ColliderShapes != null) || (colliderShapes != null && component.ColliderShapes == null) || DescsAreDifferent(colliderShapes, component.ColliderShapes) || component.ColliderShapeChanged || (rb != null && isKinematic != rb.IsKinematic) || triggerBase != null && triggerBase.GenerateOverlapEvents != isTrigger || shape != null && component.DebugEntity == null); }
/// <summary> /// Fires an arrow projectile. /// </summary> private void FireArrow() { // Get arrow model DaggerfallModelComponent arrowModel = new DaggerfallModelComponent(core, (int)PhysicsObjects.Arrow); arrowModel.Matrix = Matrix.CreateScale(1.0f); // Get camera facing Vector3 cameraFacing = core.ActiveScene.Camera.TransformedReference; // Get start position Vector3 position = core.ActiveScene.Camera.Position; position += cameraFacing * (arrowModel.BoundingSphere.Radius * 2); // Create arrow entity DynamicEntity arrowEntity = new DynamicEntity(core.ActiveScene); arrowEntity.Matrix = Matrix.CreateFromYawPitchRoll( MathHelper.ToRadians(scene.Camera.Yaw), MathHelper.ToRadians(scene.Camera.Pitch), 0) * Matrix.CreateTranslation(position); // Attach arrow geometry arrowEntity.Components.Add(arrowModel); // Attach arrow physics BoundingBox box = arrowModel.BoundingBox; float width = box.Max.X - box.Min.X; float height = box.Max.Y - box.Min.Y; float depth = box.Max.Z - box.Min.Z; PhysicsColliderComponent arrowPhysics = new PhysicsColliderComponent(core, core.ActiveScene, arrowEntity.Matrix, width, height, depth, 1f); arrowPhysics.PhysicsEntity.LinearVelocity = cameraFacing * 30f; arrowPhysics.PhysicsEntity.Material.Bounciness = 0.2f; arrowEntity.Components.Add(arrowPhysics); // Set entity to expire after 2 seconds arrowEntity.Components.Add(new ReaperComponent(core, arrowEntity, 2000)); }
/// <summary> /// Drops a heavy anvil. /// </summary> private void FireAnvil() { // Get anvil model DaggerfallModelComponent anvilModel = new DaggerfallModelComponent(core, (int)PhysicsObjects.Anvil); anvilModel.Matrix = Matrix.CreateScale(0.04f); // Get camera facing Vector3 cameraFacing = core.ActiveScene.Camera.TransformedReference; // Get start position Vector3 position = core.ActiveScene.Camera.Position; position += cameraFacing * (anvilModel.BoundingSphere.Radius * 2); // Create anvil entity DynamicEntity anvilEntity = new DynamicEntity(core.ActiveScene); anvilEntity.Matrix = Matrix.CreateRotationY(MathHelper.ToRadians(scene.Camera.Yaw)) * Matrix.CreateTranslation(position); // Attach anvil geometry anvilEntity.Components.Add(anvilModel); // Attach anvil physics BoundingBox box = anvilModel.BoundingBox; float width = box.Max.X - box.Min.X; float height = box.Max.Y - box.Min.Y; float depth = box.Max.Z - box.Min.Z; PhysicsColliderComponent anvilPhysics = new PhysicsColliderComponent(core, core.ActiveScene, anvilEntity.Matrix, width, height, depth, 200f); anvilPhysics.PhysicsEntity.Material.Bounciness = 0.0f; anvilEntity.Components.Add(anvilPhysics); // Set entity to expire after 5 minutes anvilEntity.Components.Add(new ReaperComponent(core, anvilEntity, 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); }