public World(Backend backend, ResourceManager resourceManager) { var collisionSystem = new Jitter.Collision.CollisionSystemPersistentSAP(); PhysicsWorld = new Jitter.World(collisionSystem); DebugDrawer = new DebugDrawer(backend, resourceManager); }
public JitterDemo() { this.IsMouseVisible = true; graphics = new GraphicsDeviceManager(this); graphics.GraphicsProfile = GraphicsProfile.HiDef; graphics.PreferMultiSampling = true; Content.RootDirectory = "Content"; graphics.PreferredBackBufferHeight = 600; graphics.PreferredBackBufferWidth = 800; this.IsFixedTimeStep = false; this.graphics.SynchronizeWithVerticalRetrace = false; CollisionSystem collision = new CollisionSystemPersistentSAP(); World = new World(collision); World.AllowDeactivation = true; this.Window.AllowUserResizing = true; this.Window.Title = "Jitter Physics Demo - Jitter " + Assembly.GetAssembly(typeof(Jitter.World)).GetName().Version.ToString(); wireframe = new RasterizerState(); wireframe.FillMode = FillMode.WireFrame; cullMode = new RasterizerState(); cullMode.CullMode = CullMode.None; normal = new RasterizerState(); }
/// <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(); }
protected override void shown() { try { root = new RootDisposable(); // video objects VideoTypes videoType; #if METRO VideoTypes createVideoTypes = VideoTypes.D3D11; #elif WIN32 VideoTypes createVideoTypes = VideoTypes.D3D11 | VideoTypes.D3D9 | VideoTypes.OpenGL; #elif XNA VideoTypes createVideoTypes = VideoTypes.XNA; #endif #if WIN32 || METRO video = Video.Init(createVideoTypes, out videoType, root, this, true); #elif XNA video = Video.Create(createVideoTypes, out videoType, root, this); #endif // shaders DiffuseTextureMaterial.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null); DiffuseTextureMaterial.ApplyInstanceConstantsCallback = applyDiffuseCallbackMethod; QuickDraw3ColorMaterial.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null); material = new QuickDraw3ColorMaterial(); texture = Texture2DAPI.New(video, "Data/Rocks.dds", null); qd = QuickDrawAPI.New(video, QuickDraw3ColorMaterial.BufferLayoutDesc); var frame = FrameSize; viewPort = ViewPortAPI.New(video, 0, 0, frame.Width, frame.Height); float camDis = 50; camera = new Camera(viewPort, new Vector3(0, 5, camDis), new Vector3(), new Vector3(0, 5+1, camDis)); // states rasterizerState = RasterizerStateAPI.New(video, RasterizerStateDescAPI.New(RasterizerStateTypes.Solid_CullCW)); samplerState = SamplerStateAPI.New(video, SamplerStateDescAPI.New(SamplerStateTypes.Linear_Wrap)); blendState = BlendStateAPI.New(video, BlendStateDescAPI.New(BlendStateTypes.None)); depthStencilState = DepthStencilStateAPI.New(video, DepthStencilStateDescAPI.New(DepthStencilStateTypes.ReadWrite_Less)); // models var materialTypes = new Dictionary<string,Type>(); materialTypes.Add("Material", typeof(DiffuseTextureMaterial)); var materialFieldTypes = new List<MaterialFieldBinder>(); materialFieldTypes.Add(new MaterialFieldBinder("Material", "Paint_dds", "Diffuse")); var extOverrides = new Dictionary<string,string>(); var emptyBinders = new List<MaterialFieldBinder>(); sphereModel = new Model(video, "Data/sphere.rm", "Data/", materialTypes, emptyBinders, emptyBinders, emptyBinders, emptyBinders, materialFieldTypes, extOverrides, 0, null); //capsuleModel = Model.Create(videoType, video, "Data/capsule.rm", "Data/", materialTypes, emptyBinders, emptyBinders, emptyBinders, emptyBinders, materialFieldTypes, extOverrides); boxModel = new Model(video, "Data/box.rm", "Data/", materialTypes, emptyBinders, emptyBinders, emptyBinders, emptyBinders, materialFieldTypes, extOverrides, 0, null); monkeyModel = new Model(video, "Data/monkeyFlat.rm", "Data/", materialTypes, emptyBinders, emptyBinders, emptyBinders, emptyBinders, materialFieldTypes, extOverrides, 0, null); // physics collisionSystem = new CollisionSystemPersistentSAP(); world = new World(collisionSystem); world.Gravity = new JVector(0, -9.81f, 0); spheres = new RigidBody[35]; for (int i = 0; i != spheres.Length; ++i) { spheres[i] = new RigidBody(new SphereShape(1)); spheres[i].Position = new JVector(spheres.Length/(float)(i+1), (i*3)+5, 0); world.AddBody(spheres[i]); } floorBox = new RigidBody(new BoxShape(30, 1, 30)); floorBox.Shape.TransformScale = new Vector3(30, 1, 30) * .5f; floorBox.Position = new JVector(0, -7, 0); floorBox.IsStatic = true; //floorBox.Orientation = JMatrix.CreateFromYawPitchRoll(0, -.25f, 0); world.AddBody(floorBox); triangleMesh = new TriangleMesh("Data/monkeyFlat.rtmm", loadTiangleMesh); loaded = true; } catch (Exception e) { Message.Show("Error", e.Message); dispose(); } }