public App(int width, int height) { WorldSize = new Vector3(200, 200, 200); lastTime = 0; SceneRoot = new GameObject("SceneRoot", this); Shaders = new Dictionary <string, Shader>(); Materials = new Dictionary <string, Material>(); destroyed = new List <DestructableObject>(); DefaultBlendFactorSrc = BlendingFactorSrc.SrcAlpha; DefaultBlendFactorDest = BlendingFactorDest.OneMinusSrcAlpha; Window = new GameWindow(width, height, new GraphicsMode(32, 24, 0, 0)); Window.Load += OnLoadInternal; Window.Resize += OnResizeInternal; Window.Closing += Window_Closing; Window.UpdateFrame += OnUpdateInternal; Window.RenderFrame += OnRenderInternal; SceneRenderer = new SceneRenderer(this); SetupGL(); var cameraContainer = CreateGameObject("Camera"); ActiveCamera = cameraContainer.AddComponent <Camera>(); stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); time = new System.Diagnostics.Stopwatch(); time.Start(); Shaders.Add("unlit", new Shader("Shaders/unlit.glsl", "vertex", null, "fragment")); Shaders.Add("screen", new Shader("Shaders/screen.glsl", "vertex", null, "fragment")); Shaders.Add("screenCA", new Shader("Shaders/chromaticAbberation.glsl", "vertex", null, "fragment")); Shaders.Add("text", new Shader("Shaders/text.glsl", "vertex", null, "fragment")); Shaders.Add("gol", new Shader("Shaders/gol.glsl", "vertex", null, "fragment")); Shaders.Add("lit", new Shader("Shaders/lit.glsl", "vertex", null, "fragment")); Materials.Add("unlit", new Material(Shaders["unlit"], RenderMode.Opaque)); Materials.Add("lit", new Material(Shaders["lit"], RenderMode.Opaque)); GameObjectFactory = new GameObjectFactory(this); PrimitiveFactory = new PrimitiveFactory(); //var cs = new Jitter.Collision.CollisionSystemPersistentSAP(); //PhysicsWorld = new Jitter.World(cs); //PhysicsWorld.Gravity = new Jitter.LinearMath.JVector(0, -9.81f, 0); var collisionConfig = new BulletSharp.DefaultCollisionConfiguration(); PhysicsWorld = new BulletSharp.DiscreteDynamicsWorld( new BulletSharp.CollisionDispatcher(collisionConfig), new BulletSharp.DbvtBroadphase(), new BulletSharp.SequentialImpulseConstraintSolver(), collisionConfig); Ray.Init(this); Window.Run(60.0); }
public void InitializeWorld() { mGameObjects = new List <NetGameObject>(); //mWorldMap = new WorldMap(); #if _USE_BEPU_PHYSICS space = new BEPUphysics.Space(); space.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, -9.81f, 0); #elif _USE_BULLET_SHARP Broadphase = new BulletSharp.AxisSweep3(new BulletSharp.Math.Vector3(-1000, -1000, -1000), new BulletSharp.Math.Vector3(1000, 1000, 1000)); var conf = new BulletSharp.DefaultCollisionConfiguration(); var dispatcher = new BulletSharp.CollisionDispatcher(conf); world = new BulletSharp.MultiBodyDynamicsWorld(dispatcher, Broadphase, new BulletSharp.MultiBodyConstraintSolver(), conf); world.Gravity = new BulletSharp.Math.Vector3(0, -9.81f, 0); var box = new BulletSharp.BoxShape(50f, 1f, 50f); //box.Margin = 0f; floor = new BulletSharp.RigidBody(new BulletSharp.RigidBodyConstructionInfo(0f, new BulletSharp.DefaultMotionState(), box, new BulletSharp.Math.Vector3(0, -2f, 0))); floor.CollisionFlags = BulletSharp.CollisionFlags.KinematicObject; BulletSharp.Math.Matrix worldTrans = new BulletSharp.Math.Matrix(); worldTrans.M41 = 0f; worldTrans.M42 = -2f; worldTrans.M43 = 0; floor.WorldTransform = worldTrans; //floor.Friction = 0.5f; world.AddRigidBody(floor, BulletSharp.CollisionFilterGroups.DefaultFilter, //BulletSharp.CollisionFilterGroups.Everything); (BulletSharp.CollisionFilterGroups.DefaultFilter | BulletSharp.CollisionFilterGroups.StaticFilter | BulletSharp.CollisionFilterGroups.KinematicFilter | BulletSharp.CollisionFilterGroups.DebrisFilter | BulletSharp.CollisionFilterGroups.SensorTrigger | BulletSharp.CollisionFilterGroups.CharacterFilter ) ); #elif _USE_BEPU_PHYSICS_V2 characters = new BepuPhysics.CharacterControllers(BufferPool); Simulation = Simulation.Create(BufferPool, new BepuPhysics.CharacterNarrowphaseCallbacks(characters), new DemoPoseIntegratorCallbacks(new System.Numerics.Vector3(0, -10, 0))); Simulation.Statics.Add(new StaticDescription(new System.Numerics.Vector3(0, 0, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(50, 1, 50)), 0.1f))); #endif }
private void LoadPhysics() { var defaultCollisionConfiguration = new BulletSharp.DefaultCollisionConfiguration(); var collisionDispatcher = new BulletSharp.CollisionDispatcher(); var worldAabbMin = new Vector3(-1000, -1000, -1000); var worldAabbMax = new Vector3(1000, 1000, 1000); var broadphase = new BulletSharp.AxisSweep3(worldAabbMin, worldAabbMax); this.collisionWorld = new BulletSharp.CollisionWorld(collisionDispatcher, broadphase, defaultCollisionConfiguration); this.collisionWorld.DebugDrawer = new BulletDebugDrawer(this.viewscreenProgram); foreach (var collisionObject in mousePole.ContactObjects) { collisionWorld.AddCollisionObject(collisionObject); } }