public Asteroid(Game game, Vector3 pos, string id) : this(game) { physicsObject = new BEPUphysics.Entities.Prefabs.Box(MathConverter.Convert(pos), 1, 1, 1); physicsObject.AngularDamping = 0f; physicsObject.LinearDamping = 0f; //physicsObject.CollisionInformation.Events.InitialCollisionDetected += Events_InitialCollisionDetected; physicsObject.Tag = id; Game.Services.GetService <Space>().Add(physicsObject); }
//-------------------------------------------------------------------------- #region Making primitives public IPhysical MakeBox(double xsize, double ysize, double zsize) { var body = new BEPUphysics.Entities.Prefabs.Box(new Vector3(0, 0, 0), BepuConverter.ToSimUnits((float)xsize), BepuConverter.ToSimUnits((float)ysize), BepuConverter.ToSimUnits((float)zsize), 1); // в мир сразу не добавляем return(new BepuBody(body)); }
} // UpdateTasks #endregion #region Helper Methods /// <summary> /// Makes a box that is affected by physics. /// </summary> private static GameObject3D MakeBox(Vector3 position, float width, float height, float depth, float mass, Material mat) { var cubeEntity = new Box(position, width, height, depth, mass); var gameObject = new GameObject3D(new XNAFinalEngine.Assets.Box(width, height, depth), mat); var rigidBody = (RigidBody)gameObject.AddComponent <RigidBody>(); rigidBody.Entity = cubeEntity; return(gameObject); } // MakeBox
public Goal(Vector3 pos, bool sideways) { Ent = new BEPUphysics.Entities.Prefabs.Box(pos, 0.1f, 9, 9f); BlackSquare = new BEPUphysics.Entities.Prefabs.Box(pos - new Vector3(2f, 0, 0), 0.1f, 9, 9f); Ent.CollisionInformation.Events.InitialCollisionDetected += OnCollision; BlackSquare.CollisionInformation.CollisionRules.Group = BaseModel.noSolverGroupL; BlackSquare.CollisionInformation.Events.InitialCollisionDetected += onBlackCollision; CatcherColor = col = Color.White; size = 6; this.sideways = sideways; this.pos = pos; onGDMCreation(); OnGDMReset += onGDMCreation; }
internal override void OnCreated() { var renderer = gameObject.GetComponent <MeshRenderer>(); if (renderer) { center = renderer.mesh.bounds.center; size = renderer.mesh.bounds.extents; representsMeshBounds = true; } var s = size * transform.scale; collisionEntity = new BEPUphysics.Entities.Prefabs.Box(transform.position + center.RotateBy(transform.rotation), s.X, s.Y, s.Z); gameObject.OnChanged += OnChanged; gameObject.RaiseOnChanged(ChangedFlags.All); }
public Goal(Vector3 pos, Color col) { Ent = new BEPUphysics.Entities.Prefabs.Box(pos, 7, 7, 0.1f); BlackSquare = new BEPUphysics.Entities.Prefabs.Box(pos + new Vector3(0, 0, 2f), 7, 7, 0.1f); BlackSquare.CollisionInformation.Events.InitialCollisionDetected += onBlackCollision; BlackSquare.CollisionInformation.CollisionRules.Group = BaseModel.noSolverGroupL; Ent.CollisionInformation.Events.InitialCollisionDetected += OnCollision; CatcherColor = col; this.pos = pos; this.col = col; size = 3; if(col != Color.White) size++; onGDMCreation(); OnGDMReset += onGDMCreation; }
//-------------------------------------------------------------------------- #region Making primitives public IPhysical MakeBox(double xsize, double ysize, double zsize) { var body = new BEPUphysics.Entities.Prefabs.Box(new Vector3(0, 0, 0), BepuConverter.ToSimUnits((float)xsize), BepuConverter.ToSimUnits((float)ysize), BepuConverter.ToSimUnits((float)zsize), 1); // в мир сразу не добавляем return new BepuBody(body); }
public static void BoundPlayerOnScreen(Vector3 center) { if (!isBound) { savedIndex = spawnLaneIndex; CameraQB c = Stage.ActiveStage.GetQB<CameraQB>(); PlayerCamera p = (c.ActiveCamera as PlayerCamera); float halfFov = (float)((Math.PI / 2 - Math.Atan(p.ProjectionMatrix.M22))); float aspect = p.ProjectionMatrix.M22 / p.ProjectionMatrix.M11; float offset; BEPUphysics.Entities.Prefabs.Box box1, box2; if (MoveDirection == PlayerDirection.Right || MoveDirection == PlayerDirection.Left) { offset = aspect * Math.Abs(PlayerAgent.Player.PhysicsObject.Position.Z - p.DesiredPosition.Z) * (float)Math.Tan(halfFov); Vector3 box1Center = new Vector3(center.X - offset, center.Y, center.Z); Vector3 box2Center = new Vector3(center.X + offset, center.Y, center.Z); box1 = new BEPUphysics.Entities.Prefabs.Box(box1Center, boundBoxThickness, 50.0f, 20.0f); box2 = new BEPUphysics.Entities.Prefabs.Box(box2Center, boundBoxThickness, 50.0f, 20.0f); } else { offset = aspect * Math.Abs(PlayerAgent.Player.PhysicsObject.Position.X - p.DesiredPosition.X) * (float)Math.Tan(halfFov); Vector3 box1Center = new Vector3(center.X, center.Y, center.Z - offset); Vector3 box2Center = new Vector3(center.X, center.Y, center.Z + offset); box1 = new BEPUphysics.Entities.Prefabs.Box(box1Center, 20.0f, 50.0f, boundBoxThickness); box2 = new BEPUphysics.Entities.Prefabs.Box(box2Center, 20.0f, 50.0f, boundBoxThickness); } box1.CollisionInformation.CollisionRules.Group = PhysicsQB.wallGroup; box2.CollisionInformation.CollisionRules.Group = PhysicsQB.wallGroup; playerBoundingBoxes.Add(box1); playerBoundingBoxes.Add(box2); PhysicsQB physicsQB = Stage.ActiveStage.GetQB<PhysicsQB>(); physicsQB.AddToSpace(box1); physicsQB.AddToSpace(box2); PlayerAgent.Player.GetAgent<PlayerAgent>().ReachedStopZone(); PlayerAgent.Player.GetAgent<GameLib.Engine.AttackSystem.RockMeter>().RockLevelLocked = false; isBound = true; } }
/// <summary> /// Load the resources. /// </summary> protected override void LoadContent() { hitMaterial = new BlinnPhong { DiffuseColor = new Color(0.10f, 0.10f, 0.85f) }; mat1 = new BlinnPhong { DiffuseColor = new Color(0.85f, 0.65f, 0f) }; mat2 = new BlinnPhong { DiffuseColor = new Color(0.5f, 0.9f, 0.5f) }; #region Physics Simulation Settings // Setup gravity. PhysicsManager.Gravity = new Vector3(0, -9.81f, 0); #endregion #region Camera camera = new GameObject3D(); camera.AddComponent <Camera>(); camera.AddComponent <SoundListener>(); camera.Transform.LookAt(Vector3.Zero, Vector3.Forward, Vector3.Up); var script = (ScriptCustomCameraScript)camera.AddComponent <ScriptCustomCameraScript>(); script.SetPosition(new Vector3(0, 15, 45), new Vector3(0, 5, 0)); camera.Camera.RenderTargetSize = Size.FullScreen; camera.Camera.FarPlane = 500; camera.Camera.NearPlane = 1f; camera.Camera.ClearColor = Color.Black; camera.Camera.FieldOfView = 180f / 7f; camera.Camera.PostProcess = new PostProcess(); camera.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU; camera.Camera.PostProcess.ToneMapping.AutoExposureEnabled = false; camera.Camera.PostProcess.ToneMapping.LensExposure = 0f; camera.Camera.PostProcess.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Both; camera.Camera.PostProcess.MLAA.Enabled = false; camera.Camera.PostProcess.Bloom.Threshold = 2; camera.Camera.PostProcess.FilmGrain.Enabled = true; camera.Camera.PostProcess.FilmGrain.Strength = 0.03f; camera.Camera.PostProcess.AnamorphicLensFlare.Enabled = false; camera.Camera.AmbientLight = new AmbientLight { Color = new Color(20, 20, 25), Intensity = 0.5f, AmbientOcclusionStrength = 1f }; #endregion #region Models and Physics // Make the floor (Kinematic) // // First, we create a bepu box entity that we will be used in our rigidbody component. // Notice that we don't specify the mass, so we are creating a kinematic entity. // Kinematic rigidbodies are moved through the transform component of the gameobject which it belongs. // Kinematic rigidbodies don't respond to collisions and can't collide with other kinematic rigidbodies. However, they can // collide with dynamic rigidbodies affecting them. var bepuGround = new Box(Vector3.Zero, 50, 1, 50); // Now, we create the game object and we add a rigidbody component to it. floor = new GameObject3D(new XNAFinalEngine.Assets.Box(50, 1, 50), new BlinnPhong { SpecularIntensity = 0.3f, SpecularPower = 200 }); var floorRb = (RigidBody)floor.AddComponent <RigidBody>(); // Finally, we set the entity created previously to the rigidbody component floorRb.Entity = bepuGround; // Make a Cube (Dynamic) // // Now, we create a 1x1x1 bepu box entity that will appear 20 units above the floor. // Notice that this time we specify the entity's mass in order to create a dynamic entity. // Dynamic rigidbodies are affected by gravity and respond to collisions with other rigidbodies. // Dynamic rigidbodies are under the control of physics so they don't have to be moved or rotated through the transform component. var bepuCube = new Box(new Vector3(0, 20, 2), 1, 1, 1, 1); cube = new GameObject3D(new XNAFinalEngine.Assets.Box(1, 1, 1), new BlinnPhong { DiffuseColor = new Color(0.8f, 0.8f, 0.85f) }); var cubeRb = (RigidBody)cube.AddComponent <RigidBody>(); cubeRb.Entity = bepuCube; // Create a script for test collisions var crt = (CollisionResponseTestScript)cube.AddComponent <CollisionResponseTestScript>(); GameObject2D debugGo = new GameObject2D(); debugGo.Transform.Position = new Vector3(15f, Screen.Height - 90, 0f); crt.DebugText = (HudText)debugGo.AddComponent <HudText>(); // Make an obstacle (Kinematic) // var bepuObstacle = new Box(new Vector3(0.5f, 1f, 0.5f), 4, 1, 1.5f); obstacle = new GameObject3D(new XNAFinalEngine.Assets.Box(4, 1, 1.5f), new BlinnPhong { DiffuseColor = new Color(0.9f, 0.2f, 0.15f), SpecularPower = 20 }); obstacle.Transform.Position = new Vector3(0.5f, 1f, 0.5f); var obstacleRb = (RigidBody)obstacle.AddComponent <RigidBody>(); obstacleRb.Entity = bepuObstacle; // Make a wall of boxes // MakeWall(6, 9); // Make a sphere obstacle (Dynamic) // // The sphere model is not center in its model space, instead is displaced 10 units on Z. GameObject3D sphere; // First we creates this sphere with no physics representation. //sphere = new GameObject3D(new FileModel("SphereTransformed"), new BlinnPhong { DiffuseColor = new Color(1f, 0f, 0f), SpecularPower = 20 }); // Then we creates the same sphere and asign a dynamic physic object representation. sphere = new GameObject3D(new FileModel("SphereTransformed"), new BlinnPhong { DiffuseColor = new Color(0.79f, 0.75f, 0.2f), SpecularPower = 20 }); // The initial motion state place the sphere just a little above. MotionState motionState = new MotionState { Position = new Vector3(0f, 10f, 0f), Orientation = Quaternion.Identity }; // We create the physic object. The offset that creates Bepu is hide transparently. // Moreover the initial motion state takes in consideration this offset and places the sphere in the same x, z coordinates as the other sphere. ((RigidBody)sphere.AddComponent <RigidBody>()).CreateDynamicEntityFromModelFilter(motionState, 1); // Static mesh. var lamboBody = new GameObject3D(new FileModel("LamborghiniMurcielago\\Murcielago-Body" #if XBOX + "Xbox" #endif ), new BlinnPhong { DiffuseColor = Color.Gray }); lamboBody.Transform.Position = new Vector3(-3, 3, 3); ((StaticCollider)lamboBody.AddComponent <StaticCollider>()).CreateStaticCollidableFromModelFilter(); // Very Simple Crosshair // GameObject2D crosshair = new GameObject2D(); crosshair.Transform.Position = new Vector3(Screen.Width / 2f, Screen.Height / 2f, 0f); var crossText = (HudText)crosshair.AddComponent <HudText>(); crossText.Text.Append("+"); #endregion #region Shadows and Lights Shadow.DistributeShadowCalculationsBetweenFrames = true; var pointLight = new GameObject3D(); pointLight.AddComponent <PointLight>(); pointLight.PointLight.Color = new Color(180, 200, 250); pointLight.PointLight.Intensity = 4f; pointLight.PointLight.Range = 60; pointLight.Transform.Position = new Vector3(4.8f, 10f, 10); pointLight.PointLight.Shadow = new CubeShadow { LightDepthTextureSize = 1024 }; var pointLight2 = new GameObject3D(); pointLight2.AddComponent <PointLight>(); pointLight2.PointLight.Color = new Color(100, 110, 170); pointLight2.PointLight.Intensity = 1f; pointLight2.PointLight.Range = 30; pointLight2.Transform.Position = new Vector3(-12f, 10, -3); #endregion #region Demo Legend #region Legend Background Texture2D bg = new Texture2D(EngineManager.Device, 1, 1, false, SurfaceFormat.Color); Color[] bgColor = new Color[] { new Color(0f, 0f, 0f, 0.55f) }; bg.SetData(bgColor); var bgTexture = new XNAFinalEngine.Assets.Texture(bg); var backgroundLegend = new GameObject2D(); backgroundLegend.Transform.Position = new Vector3(0f, 0f, 1f); var bgHudTex = (HudTexture)backgroundLegend.AddComponent <HudTexture>(); bgHudTex.Texture = bgTexture; bgHudTex.DestinationRectangle = new Rectangle(0, Screen.Height - 115, Screen.Width, Screen.Height); #endregion var demoLegend = new GameObject2D(); demoLegend.Transform.Position = new Vector3(Screen.Width - 380f, Screen.Height - 105f, 0f); var legend = (HudText)demoLegend.AddComponent <HudText>(); legend.Color = new Color(1f, 1f, 1f, 1f); legend.Text.Append(" Controls\n"); legend.Text.Append("\n"); legend.Text.Append("- Press Left Ctrl to fire a Blue box.\n"); legend.Text.Append("- Press Space to apply an Up impulse to the white box.\n"); legend.Text.Append("- Press Left Shift to cast a ray that paints yellow and \n"); legend.Text.Append(" applies an Up impulse to the GO that hits.\n"); legend.Text.Append("- Press keys A, S, W, D, Q, E to move and rotate the red box"); #endregion } // LoadContent