/* 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(); }
/// <summary> /// The main game constructor. /// </summary> public JDBaconTheGame() { Content.RootDirectory = "Content"; this.IsFixedTimeStep = false; this.Window.AllowUserResizing = true; graphics = new GraphicsDeviceManager(this); graphics.GraphicsProfile = GraphicsProfile.HiDef; graphics.SynchronizeWithVerticalRetrace = false; graphics.PreferMultiSampling = true; graphics.PreferredBackBufferWidth = 840; graphics.PreferredBackBufferHeight = 480; // Establishing JDBTG object instances. JDBTG.MusicManager = new EasyXnaAudioComponent(this, "Assets/Audio"); // Create the screen manager component. screenManager = new ScreenManager(this); // Activate the first screens. screenManager.AddScreen(new BackgroundScreen(), null); screenManager.AddScreen(new MainMenuScreen(), null); Collision = new CollisionSystemPersistentSAP(); World = new World(Collision); World.AllowDeactivation = true; World.Gravity = new JVector(0, -10, 0); cullMode = new RasterizerState(); cullMode.CullMode = CullMode.None; normal = new RasterizerState(); Components.Add(screenManager); }
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> /// 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 PhysicsService() { trigger = c => c is PhysicsComponent; World = new World(new CollisionSystemSAP{UseTriangleMeshNormal = false}) { Gravity = new JVector(0, 0, -9.81f) }; World.ContactSettings.MaterialCoefficientMixing = ContactSettings.MaterialCoefficientMixingType.TakeMinimum; World.CollisionSystem.PassedBroadphase += CheckBroadphase; }
public void AttachToWorld(World world) { this.CollisionShape = PhysicsUtils.CollisionShapeForModel(this.CollisionShapeType, this.Model, this.Scale); this.RigidBody = new RigidBody(this.CollisionShape); this.RigidBody.IsStatic = this.IsStatic; this.RigidBody.Position = PhysicsUtils.XNAToJitterVector(this.Position); world.AddBody(this.RigidBody); }
protected override void OnOwnerSet() { if (m_World != null) m_World.Clear(); m_World = new World(new CollisionSystemPersistentSAP()) { Gravity = new JVector() { Y = -9.8f } }; base.OnOwnerSet(); }
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(); }
public Ball(World physicsWorld,PrehenderGame game,Vector3 pLocation, Vector3 pVelocity, double pRadius = 3) { _Location = pLocation; _Velocity = pVelocity; _Radius = pRadius; rb = new RigidBody(new SphereShape((float)_Radius)); rb.Position = new JVector(pLocation.X, pLocation.Y, pLocation.Z); rb.LinearVelocity = new JVector(pVelocity.X, pVelocity.Y, pVelocity.Z); rb.Mass = 50; rb.Tag = this; physicsWorld.AddBody(rb); }
public CharacterController(World world, RigidBody body) : base(body, null) { this.world = world; JMatrix orient = body.Orientation; JVector down = JVector.Forward, ray; JVector.TransposedTransform(ref down, ref orient, out down); body.Shape.SupportMapping(ref down, out ray); FeetPosition = ray * down; JumpVelocity = 5f; FallVelocity = 5f; ClimbVelocity = 1f; }
public Program() : base(800, 600) { world = new World(new CollisionSystemSAP()); world.Gravity = new JVector(0, 0, -10); dsSetSphereQuality(2); this.VSync = OpenTK.VSyncMode.Off; this.Title = title; Keyboard.KeyDown += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyDown); BuildScene(); }
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"; }
/// <summary> /// Initializes a new instance of the <see cref="SceneGraph" /> class. /// </summary> public SceneGraph() { this.root = new SceneNode(); this.collisionSystem = new CollisionSystemSAP(); this.world = new World(this.collisionSystem); this.world.Gravity = new JVector(0f, -12f, 0f); this.directionalLights = new List<DirectionalLight>(); this.spotLights = new List<SpotLight>(); this.pointLights = new List<PointLight>(); this.renderableObjects = new List<RenderableObject>(); this.camera = new Camera(this.engine); }
/// <summary> /// Creates a new instance of the Wheel class. /// </summary> /// <param name="world">The world.</param> /// <param name="car">The RigidBody on which to apply the wheel forces.</param> /// <param name="position">The position of the wheel on the body (in body space).</param> /// <param name="radius">The wheel radius.</param> public Wheel(World world,RigidBody car,JVector position,float radius) { this.world = world; this.car = car; this.Position = position; raycast = new RaycastCallback(RaycastCallback); // set some default values. this.SideFriction = 1.5f; this.ForwardFriction = 1f; this.Radius = radius; this.Inertia = 1.0f; this.WheelTravel = 0.2f; this.MaximumAngularVelocity = 200; this.NumberOfRays = 5; }
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 void AttachToWorld(World world) { // Create rigid body this.RigidBody = new RigidBody(this.CollisionShape); this.RigidBody.IsStatic = false; this.RigidBody.Position = PhysicsUtils.XNAToJitterVector(this.Position); // Create constraints this.FixedAngleConstraint = new FixedAngle(this.RigidBody); this.ImpulseConstraint = new ImpulseConstraint(world, this.RigidBody); // Add constraints to world world.AddConstraint(this.FixedAngleConstraint); world.AddConstraint(this.ImpulseConstraint); // Add rigid body to world world.AddBody(this.RigidBody); }
public ImpulseConstraint(World world, RigidBody body) : base(body, null) { this.World = world; // determine the position of the feets of the character // this can be done by supportmapping in the down direction. // (furthest point away in the down direction) JVector vec = JVector.Down; JVector result = JVector.Zero; // Note: the following works just for normal shapes, for multishapes (compound for example) // you have to loop through all sub-shapes -> easy. body.Shape.SupportMapping(ref vec, out result); // feet position is now the distance between body.Position and the feets // Note: the following '*' is the dot product. this.feetPosition = result * JVector.Down; }
//World.WorldStep postStep; /// <summary> /// Initializes a new instance of the DefaultCar class. /// </summary> /// <param name="world">The world the car should be in.</param> /// <param name="shape">The shape of the car. Recommend is a box shape.</param> public DefaultCar(World world,Shape shape) : base(shape) { this.world = world; //postStep = new World.WorldStep(world_PostStep); //world.Events.PostStep += postStep; // set some default values this.AccelerationRate = 5.0f; this.SteerAngle = 20.0f; this.DriveTorque = 50.0f; this.SteerRate = 5.0f; // create default wheels wheels[(int)WheelPosition.FrontLeft] = new Wheel(world, this, JVector.Left + 1.8f * JVector.Forward + 0.8f * JVector.Down,0.4f); wheels[(int)WheelPosition.FrontRight] = new Wheel(world, this, JVector.Right + 1.8f * JVector.Forward + 0.8f * JVector.Down, 0.4f); wheels[(int)WheelPosition.BackLeft] = new Wheel(world, this, JVector.Left + 1.8f * JVector.Backward + 0.8f * JVector.Down, 0.4f); wheels[(int)WheelPosition.BackRight] = new Wheel(world, this, JVector.Right + 1.8f * JVector.Backward + 0.8f * JVector.Down, 0.4f); AdjustWheelValues(); }
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"; }
public void AddToWorld(World Target) { Target.AddBody(this.PhysicsElement); }
public PedestrianController(World world, RigidBody body) : base(body, null) { }
public PhysicsWorld(PhysicsDebugDraw debugDraw) { collisionSystem.UseTriangleMeshNormal = true; world = new World(collisionSystem); this.debugDraw = debugDraw; }
/* 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 Event(Game game,World world) { this.game = game; this.world = world; }
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(); } }
public PhysicsSystem() : base(TimeSpan.FromSeconds(TICKS_PER_SECOND), Aspect.All(typeof(ECS.Components.PhysicsBody))) { collisionSystem = new CollisionSystemSAP(); world = new World(collisionSystem); }
public void RemoveFromWorld(World Target) { Target.RemoveBody(PhysicsElement); }
public void BuildRagdoll(World world, JVector position) { // the torso RigidBody torso = new RigidBody(new BoxShape(1.5f, 3, 0.5f)); torso.Position = position; // the head RigidBody head = new RigidBody(new SphereShape(0.5f)); head.Position = position + new JVector(0, 2.1f, 0); // connect head and torso PointPointDistance headTorso = new PointPointDistance(head, torso, position + new JVector(0, 1.6f, 0), position + new JVector(0, 1.5f, 0)); RigidBody arm1 = new RigidBody(new CapsuleShape(0.8f, 0.2f)); arm1.Position = position + new JVector(1.0f, 0.75f, 0); RigidBody arm2 = new RigidBody(new CapsuleShape(0.8f, 0.2f)); arm2.Position = position + new JVector(-1.0f, 0.75f, 0); RigidBody lowerarm1 = new RigidBody(new CapsuleShape(0.6f, 0.2f)); lowerarm1.Position = position + new JVector(1.0f, -0.45f, 0); RigidBody lowerarm2 = new RigidBody(new CapsuleShape(0.6f, 0.2f)); lowerarm2.Position = position + new JVector(-1.0f, -0.45f, 0); PointOnPoint arm1torso = new PointOnPoint(arm1, torso, position + new JVector(0.9f, 1.4f, 0)); PointOnPoint arm2torso = new PointOnPoint(arm2, torso, position + new JVector(-0.9f, 1.4f, 0)); HingeJoint arm1Hinge = new HingeJoint(world, arm1, lowerarm1, position + new JVector(1.0f, 0.05f, 0), JVector.Right); HingeJoint arm2Hinge = new HingeJoint(world, arm2, lowerarm2, position + new JVector(-1.0f, 0.05f, 0), JVector.Right); RigidBody leg1 = new RigidBody(new CapsuleShape(1.0f, 0.3f)); leg1.Position = position + new JVector(-0.5f, -2.4f, 0); RigidBody leg2 = new RigidBody(new CapsuleShape(1.0f, 0.3f)); leg2.Position = position + new JVector(0.5f, -2.4f, 0); PointOnPoint leg1torso = new PointOnPoint(leg1, torso, position + new JVector(-0.5f, -1.6f, 0)); PointOnPoint leg2torso = new PointOnPoint(leg2, torso, position + new JVector(+0.5f, -1.6f, 0)); RigidBody lowerleg1 = new RigidBody(new CapsuleShape(0.8f, 0.3f)); lowerleg1.Position = position + new JVector(-0.5f, -4.0f, 0); RigidBody lowerleg2 = new RigidBody(new CapsuleShape(0.8f, 0.3f)); lowerleg2.Position = position + new JVector(+0.5f, -4.0f, 0); HingeJoint leg1Hinge = new HingeJoint(world, leg1, lowerleg1, position + new JVector(-0.5f, -3.35f, 0), JVector.Right); HingeJoint leg2Hinge = new HingeJoint(world, leg2, lowerleg2, position + new JVector(0.5f, -3.35f, 0), JVector.Right); lowerleg1.IsActive = false; lowerleg2.IsActive = false; leg1.IsActive = false; leg2.IsActive = false; head.IsActive = false; torso.IsActive = false; arm1.IsActive = false; arm2.IsActive = false; lowerarm1.IsActive = false; lowerarm2.IsActive = false; world.AddBody(head); world.AddBody(torso); world.AddBody(arm1); world.AddBody(arm2); world.AddBody(lowerarm1); world.AddBody(lowerarm2); world.AddBody(leg1); world.AddBody(leg2); world.AddBody(lowerleg1); world.AddBody(lowerleg2); arm1Hinge.Activate(); arm2Hinge.Activate(); leg1Hinge.Activate(); leg2Hinge.Activate(); world.AddConstraint(headTorso); world.AddConstraint(arm1torso); world.AddConstraint(arm2torso); world.AddConstraint(leg1torso); world.AddConstraint(leg2torso); }
public Scenes(World world){ this.world = world;}