/* * public Model * BloomViewboard, * BloomViewboard2, * CompositeViewboard, * AoViewboard, * AoBlrViewboard; */ public Scene(OpenTkProjectWindow mGameWindow) { //prepare list of world textures int texCount = Enum.GetValues(typeof(Material.WorldTexture)).Length; if (worldTextures == null) { worldTextures = new Texture[texCount]; } this.gameWindow = mGameWindow; Scene = this; //sunLight.pointingDirection = Vector3.Normalize(new Vector3(674, 674, 1024)); // creating a new collision system and adding it to the new world CollisionSystem collisionSystem = new CollisionSystemSAP(); world = new World(collisionSystem); // Create the groundShape and the body. Shape groundShape = new BoxShape(new JVector(100, waterLevel * 2, 100)); RigidBody groundBody = new RigidBody(groundShape); // make the body static, so it can't be moved groundBody.IsStatic = true; // add the ground to the world. world.AddBody(groundBody); }
/// <summary> /// Initializes a new instance of the <see cref="FreezingArcher.Core.PhysicsManager"/> class. /// </summary> /// <param name="collisionSystem">Collision system.</param> public PhysicsManager(MessageProvider prov, CollisionSystem collisionSystem = CollisionSystem.SweepAndPrune) { this.collisionSystem = collisionSystem; MessageProvider = prov; Jitter.Collision.CollisionSystem system; switch (collisionSystem) { case CollisionSystem.Brute: system = new CollisionSystemBrute(); break; case CollisionSystem.PersistentSweepAndPrune: system = new CollisionSystemPersistentSAP(); break; default: system = new CollisionSystemSAP(); break; } MessageProvider += this; World = new World(system); World.CollisionSystem.CollisionDetected += (Jitter.Dynamics.RigidBody body1, Jitter.Dynamics.RigidBody body2, Jitter.LinearMath.JVector point1, Jitter.LinearMath.JVector point2, Jitter.LinearMath.JVector normal, float penetration) => { if(MessageCreated != null) MessageCreated(new CollisionDetectedMessage(body1, body2)); }; Start(); }
// temp function! public static void CreatePhysicsWorld() { // initialize physics world var collisionSystem = new CollisionSystemSAP(); _physicsWorld = new World(collisionSystem); }
/* public Model BloomViewboard, BloomViewboard2, CompositeViewboard, AoViewboard, AoBlrViewboard; */ public Scene(OpenTkProjectWindow mGameWindow) { //prepare list of world textures int texCount = Enum.GetValues(typeof(Material.WorldTexture)).Length; if (worldTextures == null) worldTextures = new Texture[texCount]; this.gameWindow = mGameWindow; Scene = this; //sunLight.pointingDirection = Vector3.Normalize(new Vector3(674, 674, 1024)); // creating a new collision system and adding it to the new world CollisionSystem collisionSystem = new CollisionSystemSAP(); world = new World(collisionSystem); // Create the groundShape and the body. Shape groundShape = new BoxShape(new JVector(100, waterLevel * 2, 100)); RigidBody groundBody = new RigidBody(groundShape); // make the body static, so it can't be moved groundBody.IsStatic = true; // add the ground to the world. world.AddBody(groundBody); }
/// <summary> /// Creates an instance of WorldSimulation class. /// </summary> /// <param name="map">The map to use as physic base.</param> public WorldSimulation(Map.Map map) { CollisionSystem collisionSystem = new CollisionSystemSAP(); collisionSystem.UseTriangleMeshNormal = false; world = new World(collisionSystem); world.Gravity = new Jitter.LinearMath.JVector(0, 0, -10); Initialize(map); }
public JitterPhysics() { collisionSystem = new CollisionSystemSAP(); jitterWorld = new World(collisionSystem) { AllowDeactivation = true }; jitterWorld.SetIterations(100, 100); jitterWorld.SetDampingFactors(0.95f, 0.95f); jitterWorld.SetInactivityThreshold(0.005f, 0.005f, 10); jitterWorld.Gravity = JitterDatatypesMapping.ConvertSlow(DefaultGravity); jitterWorld.Events.BodiesBeginCollide += BeginCollision; jitterWorld.Events.BodiesEndCollide += EndCollision; CreateGroundBody(); }
/// <summary> /// Default constructor /// </summary> public JitterPhysicsHandler(Vector3 gravity) { Jitter.Collision.CollisionSystem collision = new CollisionSystemSAP(); world = new Jitter.World(collision); world.AllowDeactivation = true; world.Gravity = new Jitter.LinearMath.JVector(gravity.X, gravity.Y, gravity.Z); RigidBodies = new JitterRigidBodyHandler(world) { PhysicsHandler = this }; }
public Game1() { this.IsMouseVisible = true; graphics = new GraphicsDeviceManager(this); // creating a new collision system and adding it to the new world CollisionSystem collisionSystem = new CollisionSystemSAP(); world = new World(collisionSystem); // build our basic scene BuildScene(); Content.RootDirectory = "Content"; }
internal static void Init() { CollisionSystem = new CollisionSystemSAP(); JWorld = new JWorld(CollisionSystem); CoreECS.SubscribeComponentAdded <RigidBody>(AddRigidBody); CoreECS.SubscribeComponentEnabled <RigidBody>(AddRigidBody); CoreECS.SubscribeComponentRemoved <RigidBody>(RemoveRigidBody); CoreECS.SubscribeComponentDisabled <RigidBody>(RemoveRigidBody); CoreECS.SubscribeComponentAdded <EmptyRigidBody>(AddEmptyRigidBody); CoreECS.SubscribeComponentEnabled <EmptyRigidBody>(AddEmptyRigidBody); CoreECS.SubscribeComponentRemoved <EmptyRigidBody>(RemoveEmptyRigidBody); CoreECS.SubscribeComponentDisabled <EmptyRigidBody>(RemoveEmptyRigidBody); CollisionSystem.CollisionDetected += CollisionDetected; }
public JitterPhysicsGame() { graphics = new GraphicsDeviceManager(this); graphics.PreferMultiSampling = true; graphics.PreferredBackBufferWidth = (int)PreferredSize.X; graphics.PreferredBackBufferHeight = (int)PreferredSize.Y; Content.RootDirectory = "Content"; // Choose a collision system and create a new world instance. var collision = new CollisionSystemSAP(); world = new World(collision); // Call this method which adds some boxes to the // empty world. CreateInitialScene(); }
public DemoGame() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 480; graphics.PreferredBackBufferHeight = 800; Content.RootDirectory = "Content"; TargetElapsedTime = TimeSpan.FromTicks(333333); // Choose a collision system and create a new world instance. CollisionSystemSAP collision = new CollisionSystemSAP(); world = new World(collision); // Call this method which adds some boxes to the // emtpy world. CreateInitialScene(); }
public void RunSimulation() { CollisionSystem collision = new CollisionSystemSAP(); JitterWorld world = new JitterWorld(collision); world.Gravity = new JVector(0, -10, -0); Shape shape = new BoxShape(20.0f, 1.0f, 20.0f); RigidBody floor = new RigidBody(shape); floor.IsStatic = true; floor.Position = new JVector(0.0f, -15.0f, 0.0f); shape = new SphereShape(0.5f); RigidBody body = new RigidBody(shape); body.Position = new JVector(0.0f, 3.0f, 0.0f); body.Material.Restitution = 0.8f; world.AddBody(floor); world.AddBody(body); for (int i = 0; i < 600; i++) { world.Step(1.0f / 30.0f, true); SunflowAPI sunflow = new SunflowAPI(); SetupSunflow(sunflow); sunflow.geometry("sphere", "sphere"); //Instancing the big metal sphere. JVector v = body.Position; sunflow.parameter("transform", Matrix4.translation(v.X, v.Y, v.Z).multiply(Matrix4.scale(1))); sunflow.parameter("shaders", "metal"); sunflow.instance("sphere.instance", "sphere"); sunflow.render(SunflowAPI.DEFAULT_OPTIONS, new FileDisplay("spherecube" + i + ".png")); // do other stuff, like drawing } }
public JitterDemo() { this.IsMouseVisible = true; graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; this.IsFixedTimeStep = false; this.graphics.SynchronizeWithVerticalRetrace = false; CollisionSystem collision = new CollisionSystemSAP(); world = new World(collision); world.AllowDeactivation = false; codeForm = new CodeForm(world); RigidBody ground = new RigidBody(new BoxShape(new JVector(1000, 10, 1000))); ground.Position = new JVector(0, -5, 0); ground.Tag = true; ground.IsStatic = true; world.AddBody(ground); this.Window.Title = "Jitter Demo (Preview) - Jitter © by Thorben Linneweber"; }
void CreateWorld() { CollisionSystem collision = null; switch (settings.CollisionSystem.CollisionSystem) { case JSettings.CollisionSystemEnum.SAP: collision = new CollisionSystemSAP(); break; case JSettings.CollisionSystemEnum.PersistentSAP: collision = new CollisionSystemPersistentSAP(); break; case JSettings.CollisionSystemEnum.Brute: collision = new CollisionSystemBrute(); break; } collision.EnableSpeculativeContacts = settings.CollisionSystem.EnableSpeculativeContacts; World = new World(collision); World.SetInactivityThreshold(settings.InactivityThreshold.MinAngularVelocity, settings.InactivityThreshold.MinLinearVelocity, settings.InactivityThreshold.MinSleepingTime); World.AllowDeactivation = settings.World.AllowDeactivation; Multithread = settings.Multithread.Mode; ThreadManager.ThreadsPerProcessor = settings.Multithread.ThreadsPerProcessor; timestep = settings.World.Timestep; JRigidbody.LerpFactor = settings.Rigidbody.LerpFactor; }
protected override void Initialise() { // initialize physics simulation CollisionSystemSAP collision = new CollisionSystemSAP(); world = new World(collision); //setup the view camera first //-------------------------------------- viewCamera = new Xen.Camera.FirstPersonControlledCamera3D(this.UpdateManager); viewCamera.Projection.FieldOfView *= 0.80f; viewCamera.MovementSensitivity *= 0.05f; viewCamera.LookAt(new Vector3(-3, 4, 2), new Vector3(6, 40, 2), new Vector3(0, 1, 0)); viewCamera.Projection.NearClip = 0.1f; //shadow map setup: //-------------------------------------- const float shadowArea = 4; const int shadowMapResolution = 1024; //setup the shadow map rendering camera shadowCamera = new Camera3D(); //setup the shadow map projection to roughly cover the character shadowCamera.Projection.Orthographic = true; shadowCamera.Projection.NearClip = shadowArea * 2; shadowCamera.Projection.FarClip = -shadowArea * 2; shadowCamera.Projection.Region = new Vector4(1, -1.8f, -1, 0.2f) * shadowArea; //setup the shadow map draw target //create the shadow map shadowMap = new DrawTargetTexture2D(shadowCamera, shadowMapResolution, shadowMapResolution, SurfaceFormat.HalfSingle, DepthFormat.Depth24); shadowMap.ClearBuffer.ClearColour = Color.White; //setup the shadow map drawer.. shadowDrawer = new ShadowMapDrawer(null, new ShadowOutputShaderProvider()); this.shadowMap.Add(shadowDrawer); //create the main draw targets. //-------------------------------------- drawToScreen = new DrawTargetScreen(new Camera2D()); drawToScreen.ClearBuffer.ClearColourEnabled = false; drawToRenderTarget = new DrawTargetTexture2D(viewCamera, this.WindowWidth, this.WindowHeight, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, false, PreferredMultiSampleLevel.FourSamples, RenderTargetUsage.PlatformContents); drawToRenderTarget.ClearBuffer.ClearColourEnabled = false; //setup the bloom draw targets //-------------------------------------- //scale to reduce the size of the bloom target, compared to main render target const int bloomDownsample = 8; //eight times smaller bloomRenderTarget = new DrawTargetTexture2D(new Camera2D(), Math.Max(1, drawToRenderTarget.Width / bloomDownsample), Math.Max(1, drawToRenderTarget.Height / bloomDownsample), SurfaceFormat.Color, DepthFormat.None); bloomRenderTarget.ClearBuffer.ClearColourEnabled = false; bloomIntermediateRenderTarget = null; //the bloom intermediate target is not needed on the xbox, as the full bloom target fits in EDRAM bloomIntermediateRenderTarget = new DrawTargetTexture2D(viewCamera, bloomRenderTarget.Width, bloomRenderTarget.Height, SurfaceFormat.Color, DepthFormat.None); bloomIntermediateRenderTarget.ClearBuffer.ClearColourEnabled = false; //setup the blur filter, with a large 31 sample radius. bloomBlurPass = new Xen.Ex.Filters.BlurFilter(Xen.Ex.Filters.BlurFilterFormat.ThirtyOneSampleBlur_FilteredTextureFormat, 1.0f, bloomRenderTarget, bloomIntermediateRenderTarget); //setup the character model this.model = new ModelInstance(); //(the model is setup in LoadContent) this.modelRotation = new DrawRotated(model); this.modelRotation.RotationAngle = 3; this.modelPhysics = new DrawCharacter(model); //add the model to be drawn //drawToRenderTarget.Add(modelRotation); //drawToRenderTarget.Add(model); drawToRenderTarget.Add(modelPhysics); // setup simple terrain simpleTerrain = new SimpleTerrain(this.Content, Vector3.Zero, @"TerrainTest/terrain_desert"); drawToRenderTarget.Add(simpleTerrain); drawToRenderTarget.Add(simpleTerrain.PickingDrawer); // preview picking //setup the shaders this.characterRenderShader = new Shaders.Character(); //setup the output and bloom shaders outputShader = new Shaders.RgbmDecode(); drawToScreen.Add(new ShaderElement(outputShader, new Vector2(1, 1), true)); bloomPassShader = new Shaders.RgbmDecodeBloomPass(); bloomRenderTarget.Add(new ShaderElement(bloomPassShader, new Vector2(1, 1), true)); //add a background to be drawn drawToRenderTarget.Add(new BackgroundDrawer()); //setup the debug image displays //-------------------------------------- this.rgmbTextureAlphaShader = new Shaders.AlphaWrite(); this.bloomTextureDisplay = new TexturedElement(this.bloomRenderTarget, new Vector2(0.2f, 0.2f), true); this.rgbmTextureDisplay = new TexturedElement(this.drawToRenderTarget, new Vector2(0.2f, 0.2f), true); this.rgbmTextureAlphaDisplay = new ShaderElement(this.rgmbTextureAlphaShader, new Vector2(0.2f, 0.2f), true); this.rgbmTextureAlphaDisplay.Position = new Vector2(0.7f, 0.2f); this.rgbmTextureDisplay.Position = new Vector2(0.7f, 0.4f); this.bloomTextureDisplay.Position = new Vector2(0.7f, 0.6f); this.drawToScreen.Add(this.rgbmTextureDisplay); this.drawToScreen.Add(this.rgbmTextureAlphaDisplay); this.drawToScreen.Add(this.bloomTextureDisplay); //setup the render config this.configEditor = new RenderConfigEditor(this.Content); this.drawToScreen.Add(configEditor); this.UpdateManager.Add(configEditor); //add a statistics overlay. drawStats = new Xen.Ex.Graphics2D.Statistics.DrawStatisticsDisplay(this.UpdateManager); drawToScreen.Add(drawStats); }
/* public Model BloomViewboard, BloomViewboard2, CompositeViewboard, AoViewboard, AoBlrViewboard; */ public Scene(OpenTkProjectWindow mGameWindow) { this.gameWindow = mGameWindow; Scene = this; sunLight = new LightSun(new Vector3(0.1f, 0.125f, 0.2f) * 3f, this); sunLight.lightAmbient = new Vector3(0.1f, 0.125f, 0.2f) * 0.5f;//new Vector3(0.2f, 0.125f, 0.1f);//new Vector3(0.1f, 0.14f, 0.3f); sunLight.PointingDirection = Vector3.Normalize(new Vector3(674, -674, 1024)); sunFrameBuffer = gameWindow.framebufferCreator.createFrameBuffer("shadowFramebuffer", shadowRes * 2, shadowRes * 2, PixelInternalFormat.Rgba8, false); sunInnerFrameBuffer = gameWindow.framebufferCreator.createFrameBuffer("shadowFramebuffer", shadowRes * 2, shadowRes * 2, PixelInternalFormat.Rgba8, false); //sunLight.pointingDirection = Vector3.Normalize(new Vector3(674, 674, 1024)); // creating a new collision system and adding it to the new world CollisionSystem collisionSystem = new CollisionSystemSAP(); world = new World(collisionSystem); // Create the groundShape and the body. Shape groundShape = new BoxShape(new JVector(100, waterLevel * 2, 100)); RigidBody groundBody = new RigidBody(groundShape); // make the body static, so it can't be moved groundBody.IsStatic = true; // add the ground to the world. world.AddBody(groundBody); }
public override void Initialize() { CollisionSystem system = new CollisionSystemSAP(); system.UseTriangleMeshNormal = true; // TODO: Should damping factors be left in their default states? (they were changed while adding kinematic bodies) world = new World(system); world.Gravity = new JVector(0, -PhysicsConstants.Gravity, 0); world.SetDampingFactors(1, 1); world.Events.ContactCreated += OnContact; space = new Space(); scene = new Scene { Camera = camera, Canvas = canvas, Space = space, World = world }; var stats = new StatisticsDisplay(); stats.Anchor = Alignments.Left | Alignments.Top; stats.Offset = new ivec2(10); stats.IsVisible = false; canvas.Clear(); canvas.Load("Canvas.json"); canvas.Add(stats); //canvas.Add(new RopeTester()); spawnHelper = new SpawnHelper(scene); // TODO: Load settings from a file. ControlSettings settings = new ControlSettings(); settings.MouseSensitivity = 50; // TODO: Set player position from a save slot. PlayerCharacter player = new PlayerCharacter(settings); player.Equip(new Sword(player)); player.Unlock(PlayerSkills.Grab); player.Unlock(PlayerSkills.Jump); player.Unlock(PlayerSkills.DoubleJump); player.Unlock(PlayerSkills.WallJump); //player.Unlock(PlayerSkills.Ascend); player.Unlock(PlayerSkills.Block); player.Unlock(PlayerSkills.Parry); player.Equip(new Sword(player)); // TODO: Load fragments from a save slot. scene.Add(player); var fragment = scene.LoadFragment("Demo.json"); //var fragment = scene.LoadFragment("Windmill.json"); player.Position = fragment.Origin + fragment.Spawn; CreateDebugCubes(); camera.Attach(new FollowView(camera, player, settings)); // TODO: Initialize renderer settings from a configuration file (based on user settings). // TODO: Set light color and direction based on time of day and weather. var renderer = scene.Renderer; renderer.Light.Direction = Utilities.Normalize(new vec3(-2, -0.75f, 2)); renderTargetUsers3D.Add(renderer); // Create visualizers. spaceVisualizer = new SpaceVisualizer(camera, space); jitterVisualizer = new JitterVisualizer(camera, world); jitterVisualizer.IsEnabled = true; MessageSystem.Subscribe(this, CoreMessageTypes.Keyboard, (messageType, data, dt) => { ProcessKeyboard((KeyboardData)data); }); }