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); }
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 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"; }
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 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 void AddToWorld(World Target) { Target.AddBody(this.PhysicsElement); }
/* 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); }
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 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 void AddToWorld(World Target) { Target.AddBody(PhysicsObject); }