/// <summary> /// Se crea una capsula a partir de un radio, altura, posicion, masa y si se dedea o no calcular /// la inercia. Esto es importante ya que sin inercia no se generan rotaciones que no se /// controlen en forma particular. /// </summary> /// <param name="radius">Radio de la Capsula</param> /// <param name="height">Altura de la Capsula</param> /// <param name="position">Posicion de la Capsula</param> /// <param name="mass">Masa de la Capsula</param> /// <param name="needInertia">Booleano para el momento de inercia de la Capsula</param> /// <returns>Rigid Body de una Capsula</returns> public static RigidBody CreateCapsule(float radius, float height, TGCVector3 position, float mass, bool needInertia) { //Creamos el shape de la Capsula a partir de un radio y una altura. var capsuleShape = new CapsuleShape(radius, height); //Armamos las transformaciones que luego formaran parte del cuerpo rigido de la capsula. var capsuleTransform = TGCMatrix.Identity; capsuleTransform.Origin = position; var capsuleMotionState = new DefaultMotionState(capsuleTransform.ToBsMatrix); RigidBodyConstructionInfo capsuleRigidBodyInfo; //Calculamos o no el momento de inercia dependiendo de que comportamiento //queremos que tenga la capsula. if (!needInertia) { capsuleRigidBodyInfo = new RigidBodyConstructionInfo(mass, capsuleMotionState, capsuleShape); } else { var capsuleInertia = capsuleShape.CalculateLocalInertia(mass); capsuleRigidBodyInfo = new RigidBodyConstructionInfo(mass, capsuleMotionState, capsuleShape, capsuleInertia); } var localCapsuleRigidBody = new RigidBody(capsuleRigidBodyInfo) { LinearFactor = TGCVector3.One.ToBsVector }; //Dado que hay muchos parametros a configurar el RigidBody lo ideal es que //cada caso se configure segun lo que se necesite. return(localCapsuleRigidBody); }
/// <summary> /// Starts the component. /// </summary> protected override void OnStart(GameTime time) { if (this.rigidBody == null) { var shape = this.Node.Components.Get <Shape>(); if (shape == null) { throw new NullReferenceException("Could not find a shape component for the rigid body."); } var constructionInfo = new RigidBodyConstructionInfo( this.Mass, new SceneNodeMotionState(this.Node), shape.GetShape()); this.rigidBody = new BulletSharp.RigidBody(constructionInfo); this.rigidBody.UserObject = this; this.IsKinematic = this.isKinematic; // Just make sure the body gets its correct rigid body state. } if (this.Node.Scene.PhysicsEnabled) { this.Node.Scene.World.AddRigidBody(this.rigidBody); } }
/// <summary> /// Crea una coleccion de triangulos para Bullet a partir de los triangulos generados por un heighmap /// o una coleccion de triangulos a partir de un Custom Vertex Buffer con vertices del tipo Position Texured. /// Se utilizo el codigo de un snippet de Bullet http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Code_Snippets /// </summary> /// <param name="triangleDataVB">Custom Vertex Buffer que puede ser de un Heightmap</param> /// <returns>Rigid Body del terreno</returns> public static RigidBody CreateSurfaceFromHeighMap(CustomVertex.PositionTextured[] triangleDataVB) { //Triangulos var triangleMesh = new TriangleMesh(); int i = 0; TGCVector3 vector0; TGCVector3 vector1; TGCVector3 vector2; while (i < triangleDataVB.Length) { var triangle = new Triangle(); vector0 = new TGCVector3(triangleDataVB[i].X, triangleDataVB[i].Y, triangleDataVB[i].Z); vector1 = new TGCVector3(triangleDataVB[i + 1].X, triangleDataVB[i + 1].Y, triangleDataVB[i + 1].Z); vector2 = new TGCVector3(triangleDataVB[i + 2].X, triangleDataVB[i + 2].Y, triangleDataVB[i + 2].Z); i = i + 3; triangleMesh.AddTriangle(vector0.ToBsVector, vector1.ToBsVector, vector2.ToBsVector, false); } CollisionShape meshCollisionShape = new BvhTriangleMeshShape(triangleMesh, true); var meshMotionState = new DefaultMotionState(); var meshRigidBodyInfo = new RigidBodyConstructionInfo(0, meshMotionState, meshCollisionShape); RigidBody meshRigidBody = new RigidBody(meshRigidBodyInfo); return(meshRigidBody); }
/// <summary> /// Se crea uncuerpo rigido a partir de un TgcMesh, pero no tiene masa /// por lo que va a ser estatico. /// </summary> /// <param name="mesh">TgcMesh</param> /// <returns>Cuerpo rigido de un Mesh</returns> public static RigidBody CreateRigidBodyFromTgcMesh(TgcMesh mesh) { var vertexCoords = mesh.getVertexPositions(); TriangleMesh triangleMesh = new TriangleMesh(); for (int i = 0; i < vertexCoords.Length; i = i + 3) { triangleMesh.AddTriangle(vertexCoords[i].ToBsVector, vertexCoords[i + 1].ToBsVector, vertexCoords[i + 2].ToBsVector); } var transformationMatrix = TGCMatrix.RotationYawPitchRoll(0, 0, 0).ToBsMatrix; DefaultMotionState motionState = new DefaultMotionState(transformationMatrix); var bulletShape = new BvhTriangleMeshShape(triangleMesh, false); var boxLocalInertia = bulletShape.CalculateLocalInertia(0); var bodyInfo = new RigidBodyConstructionInfo(0, motionState, bulletShape, boxLocalInertia); var rigidBody = new RigidBody(bodyInfo) { Friction = 0.4f, RollingFriction = 1, Restitution = 1f }; return(rigidBody); }
public static RigidBody CreateRigidBodyFromTgcMesh(TgcMesh mesh, TGCVector3 position, float mass, float friction) { var meshAxisRadius = mesh.BoundingBox.calculateAxisRadius().ToBsVector; var boxShape = new BoxShape(meshAxisRadius); var transformationMatrix = TGCMatrix.RotationYawPitchRoll(0, 0, 0).ToBsMatrix; transformationMatrix.Origin = position.ToBsVector; DefaultMotionState motionState = new DefaultMotionState(transformationMatrix); var boxLocalInertia = boxShape.CalculateLocalInertia(mass); var bodyInfo = new RigidBodyConstructionInfo(mass, motionState, boxShape, boxLocalInertia); var rigidBody = new RigidBody(bodyInfo) { LinearFactor = TGCVector3.One.ToBsVector, Friction = friction, RollingFriction = 1f, AngularFactor = new Vector3(1f, 0.2f, 1f), SpinningFriction = 0.7f }; return(rigidBody); }
public RigidBody LocalCreateRigidBody(float mass, Matrix startTransform, CollisionShape shape, bool isKinematic = false) { //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.0f); BulletSharp.Math.Vector3 localInertia = BulletSharp.Math.Vector3.Zero; if (isDynamic) { shape.CalculateLocalInertia(mass, out localInertia); } //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects DefaultMotionState myMotionState = new DefaultMotionState(startTransform); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia); RigidBody body = new RigidBody(rbInfo); if (isKinematic) { body.CollisionFlags = body.CollisionFlags | BulletSharp.CollisionFlags.KinematicObject; body.ActivationState = ActivationState.ActiveTag; } rbInfo.Dispose(); World.AddRigidBody(body); return(body); }
public Physics() { // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new DbvtBroadphase(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf); World.Gravity = new Vector3(0, -10, 0); // create the ground CollisionShape groundShape = new BoxShape(50, 1, 50); CollisionShapes.Add(groundShape); CollisionObject ground = LocalCreateRigidBody(0, Matrix.Identity, groundShape); ground.UserObject = "Ground"; // create a few dynamic rigidbodies float mass = 1.0f; CollisionShape colShape = new BoxShape(1); CollisionShapes.Add(colShape); Vector3 localInertia = colShape.CalculateLocalInertia(mass); float start_x = StartPosX - ArraySizeX / 2; float start_y = StartPosY; float start_z = StartPosZ - ArraySizeZ / 2; int k, i, j; for (k = 0; k < ArraySizeY; k++) { for (i = 0; i < ArraySizeX; i++) { for (j = 0; j < ArraySizeZ; j++) { Matrix startTransform = Matrix.Translation( 2 * i + start_x, 2 * k + start_y, 2 * j + start_z ); // using motionstate is recommended, it provides interpolation capabilities // and only synchronizes 'active' objects DefaultMotionState myMotionState = new DefaultMotionState(startTransform); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia); RigidBody body = new RigidBody(rbInfo); // make it drop from a height body.Translate(new Vector3(0, 20, 0)); World.AddRigidBody(body); } } } }
public void Init(TgcSimpleTerrain terrain) { collisionConfiguration = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(collisionConfiguration); GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher); constraintSolver = new SequentialImpulseConstraintSolver(); broadphaseInterface = new DbvtBroadphase(); dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadphaseInterface, constraintSolver, collisionConfiguration); dynamicsWorld.Gravity = gravity; var ballShape = new SphereShape(50); var ballTransform = TGCMatrix.Identity; ballTransform.Origin = initialPosition; var ballMotionState = new DefaultMotionState(ballTransform.ToBsMatrix); var ballInertia = ballShape.CalculateLocalInertia(1f); var ballInfo = new RigidBodyConstructionInfo(1, ballMotionState, ballShape, ballInertia); RigidCamera = new RigidBody(ballInfo); RigidCamera.SetDamping(0.9f, 0.9f); //esto es para que no le afecte la gravedad al inicio de la partida //RigidCamera.ActivationState = ActivationState.IslandSleeping; dynamicsWorld.AddRigidBody(RigidCamera); var heighmapRigid = BulletRigidBodyFactory.Instance.CreateSurfaceFromHeighMap(terrain.getData()); dynamicsWorld.AddRigidBody(heighmapRigid); }
public static RigidBody CreateBody(float mass, Matrix startTransform, CollisionShape shape, DynamicsWorld world) { // A body with zero mass is considered static if (mass == 0) { return(CreateStaticBody(startTransform, shape, world)); } // Using a motion state is recommended, // it provides interpolation capabilities and only synchronizes "active" objects var myMotionState = new DefaultMotionState(startTransform); Vector3 localInertia = shape.CalculateLocalInertia(mass); RigidBody body; using (var rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia)) { body = new RigidBody(rbInfo); } if (world != null) { world.AddRigidBody(body); } return(body); }
public void SetRigidBody(RigidBodyConstructionInfo info, Vector3 scale) { Body = new RigidBody(info); Body.UserObject = GameObject; Body.CollisionShape.LocalScaling = scale; GameObject.App.PhysicsWorld.AddRigidBody(Body); }
protected virtual void Initialize() { RigidBodyConstructionInfo info = new RigidBodyConstructionInfo(Mass, new DefaultMotionState(), new BoxShape(GetHalfExtents())); this._id = Guid.NewGuid().ToString(); Rigidbody = new OrakelRigidBody(info, Id); }
public PhysicsObject AddDynamicObject(float mass, Matrix4x4 transform, Collider col, Vector3?inertia = null) { if (mass < float.Epsilon) { throw new Exception("Mass must be non-zero"); } BM.Vector3 localInertia; if (inertia != null) { localInertia = inertia.Value.Cast(); } else { col.BtShape.CalculateLocalInertia(mass, out localInertia); } using (var rbInfo = new RigidBodyConstructionInfo(mass, new DefaultMotionState(transform.Cast()), col.BtShape, localInertia)) { var body = new RigidBody(rbInfo); body.SetDamping(0, 0); body.Restitution = 1f; var phys = new PhysicsObject(body, col) { Static = false }; phys.UpdateProperties(); body.UserObject = phys; btWorld.AddRigidBody(body); objects.Add(phys); dynamicObjects.Add(phys); return(phys); } }
public override RigidBody LocalCreateRigidBody(float mass, Matrix startTransform, CollisionShape shape) { //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.0f); Vector3 localInertia = Vector3.Zero; if (isDynamic) { shape.CalculateLocalInertia(mass, out localInertia); } //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, null, shape, localInertia); RigidBody body = new RigidBody(rbInfo); rbInfo.Dispose(); body.WorldTransform = startTransform; World.AddRigidBody(body, CollisionFilterGroups.DefaultFilter, CollisionFilterGroups.DefaultFilter | CollisionFilterGroups.StaticFilter); return(body); }
/// <summary> /// 剛体を作る /// </summary> /// <param name="collisionShape">剛体の形</param> /// <param name="world">剛体のワールド変換行列</param> /// <param name="rigidProperty">剛体の物性</param> /// <param name="superProperty">物理演算を超越した特性</param> /// <returns></returns> public RigidBody CreateRigidBody(CollisionShape collisionShape, Matrix world, RigidProperty rigidProperty, SuperProperty superProperty) { var mass = superProperty.kinematic ? 0 : rigidProperty.mass; collisionShapes.Add(collisionShape); Vector3 localInertia = new Vector3(0, 0, 0); if (mass != 0) { collisionShape.CalculateLocalInertia(mass, out localInertia); } DefaultMotionState motionState = new DefaultMotionState(world); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, motionState, collisionShape, localInertia); RigidBody body = new RigidBody(rbInfo); body.Restitution = rigidProperty.restitution; body.Friction = rigidProperty.friction; body.SetDamping(rigidProperty.linear_damp, rigidProperty.angular_damp); float linearDamp = body.LinearDamping; float angularDamp = body.AngularDamping; if (superProperty.kinematic) { body.CollisionFlags = body.CollisionFlags | CollisionFlags.KinematicObject; } body.ActivationState = ActivationState.DisableDeactivation; dynamicsWorld.AddRigidBody(body, superProperty.group, superProperty.mask); return(body); }
protected override void RebuildRigidBody() { lock (PhysicsSimulation.Locker) { World?.Physics.World.RemoveRigidBody(RigidBody); _capsuleShape?.Dispose(); RigidBody?.Dispose(); _capsuleShape = new CapsuleShape(_capsuleRadius, _capsuleHeight / 2); var mass = GetMass(); var intertia = _capsuleShape.CalculateLocalInertia(mass); var constructionInfo = new RigidBodyConstructionInfo(mass, _motionState, _capsuleShape, intertia); RigidBody = new RigidBody(constructionInfo) { AngularFactor = new BulletSharp.Math.Vector3(0, 0, 0), CollisionFlags = CollisionFlags.CharacterObject, ActivationState = ActivationState.DisableDeactivation, UserObject = this }; RigidBody.UpdateInertiaTensor(); World?.Physics.World.AddRigidBody(RigidBody); } }
private void CreateBoxes() { const float mass = 1.0f; var colShape = new BoxShape(1); CollisionShapes.Add(colShape); Vector3 localInertia = colShape.CalculateLocalInertia(mass); var rbInfo = new RigidBodyConstructionInfo(mass, null, colShape, localInertia); for (int y = 0; y < ArraySizeY; y++) { for (int x = 0; x < ArraySizeX; x++) { for (int z = 0; z < ArraySizeZ; z++) { Vector3 position = startPosition + 2 * new Vector3(x, y, z); // make it drop from a height position += new Vector3(0, 10, 0); // using MotionState is recommended, it provides interpolation capabilities // and only synchronizes 'active' objects rbInfo.MotionState = new DefaultMotionState(Matrix.Translation(position)); var body = new RigidBody(rbInfo); World.AddRigidBody(body); } } } rbInfo.Dispose(); }
static void Main(string[] args) { { var world = new DiscreteDynamicsWorld(); world.Gravity = new Vector3(0.0f, -10.0f, 0.0f); var info0 = new RigidBodyConstructionInfo(); info0.Mass = 1.0f; info0.CollisionShape = new BulletDotNet.Shapes.BoxShape(Vector3.One); info0.CenterOfMass = Vector3.Zero; var rb0 = new RigidBody(info0, OnGetTransform0, OnSetTransform0); var info1 = new RigidBodyConstructionInfo(); info1.Mass = 0.0f; info1.CollisionShape = new BulletDotNet.Shapes.BoxShape(Vector3.One); info1.CenterOfMass = Vector3.Zero; var rb1 = new RigidBody(info1, OnGetTransform1, OnSetTransform1); world.AddRigidBody(rb0); world.AddRigidBody(rb1); for (int i = 0; i < 100; i++) { rb0.Activate(); world.StepSimulation(1.0f / 60.0f); } world.RemoveRigidBody(rb0); world.RemoveRigidBody(rb1); } GC.Collect(); GC.WaitForPendingFinalizers(); }
protected RigidBody ResetRigidBody(RigidBody rb, float newMass, BulletSharp.Math.Vector3 newInertia, Matrix startTransform, CollisionShape shape, float friction = 0.5f, bool isKinematic = false) { // basically detroys a rigid body and re-initializes it efficiently // doesn't recalculate moment of inertia or re-create the gfx object //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects\ float mass = newMass; BulletSharp.Math.Vector3 localInertia = newInertia; DestroyRigidBody(rb); DefaultMotionState myMotionState = new DefaultMotionState(startTransform); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia); rbInfo.Friction = friction; RigidBody body = new RigidBody(rbInfo); if (isKinematic) { body.CollisionFlags = body.CollisionFlags | BulletSharp.CollisionFlags.KinematicObject; body.ActivationState = ActivationState.DisableDeactivation; } rbInfo.Dispose(); m_world.AddRigidBody(body); return(body); }
//---------------------------------------------------------------------------------------------- public RigidBody LocalCreateRigidBodyMultiWorld(float mass, ref IndexedMatrix startTransform, CollisionShape shape, DiscreteDynamicsWorld world) { Debug.Assert((shape == null || shape.GetShapeType() != BroadphaseNativeTypes.INVALID_SHAPE_PROXYTYPE)); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = !MathUtil.CompareFloat(mass, 0f); IndexedVector3 localInertia = IndexedVector3.Zero; if (isDynamic) { shape.CalculateLocalInertia(mass, out localInertia); } //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects //#define USE_MOTIONSTATE 1 //#ifdef USE_MOTIONSTATE DefaultMotionState myMotionState = new DefaultMotionState(startTransform, IndexedMatrix.Identity); RigidBodyConstructionInfo cInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia); RigidBody body = new RigidBody(cInfo); if (BulletGlobals.g_streamWriter != null && true) { BulletGlobals.g_streamWriter.WriteLine("localCreateRigidBody [{0}] startTransform", body.m_debugBodyId); MathUtil.PrintMatrix(BulletGlobals.g_streamWriter, startTransform); BulletGlobals.g_streamWriter.WriteLine(""); } world.AddRigidBody(body); return(body); }
private void CreateBoxes() { const float mass = 1.0f; var shape = new BoxShape(1); Vector3 localInertia = shape.CalculateLocalInertia(mass); var rbInfo = new RigidBodyConstructionInfo(mass, null, shape, localInertia); for (int y = 0; y < NumBoxesY; y++) { for (int x = 0; x < NumBoxesX; x++) { for (int z = 0; z < NumBoxesZ; z++) { Vector3 position = _startPosition + 3 * new Vector3(x, y, z); // using motionstate is recommended, it provides interpolation capabilities // and only synchronizes 'active' objects rbInfo.MotionState = new DefaultMotionState(Matrix.Translation(position)); var body = new RigidBody(rbInfo); World.AddRigidBody(body); } } } rbInfo.Dispose(); }
private RigidBody CreateRigidBody(float mass, Matrix4 startTransform, CollisionShape shape) { bool isDynamic = (mass != 0.0f); Vector3 localInertia = Vector3.Zero; if (isDynamic) { shape.CalculateLocalInertia(mass, out localInertia); } DefaultMotionState myMotionState = new DefaultMotionState(startTransform); RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia); RigidBody body = new RigidBody(rbInfo); body.SetSleepingThresholds(0, 0); body.ContactProcessingThreshold = 0; body.CcdMotionThreshold = 0; //World.AddRigidBody(body); return(body); }
public RigidBody LocalCreateRigidBody(float mass, Matrix startTransform, CollisionShape shape) { //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.0f); Vector3 localInertia = Vector3.Zero; if (isDynamic) { shape.CalculateLocalInertia(mass, out localInertia); } //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects DefaultMotionState myMotionState = new DefaultMotionState(startTransform); RigidBody body; using (var rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia)) { body = new RigidBody(rbInfo); } ownerWorld.AddRigidBody(body); return(body); }
void Start() { var rigged = Node.GetComponent <Animator>(); if (rigged) { head = rigged.BoneController.GetBone("頭"); head.FollowAnimation = false; } //create head ray collision object headBox = new SphereShape(0.35f); var rbInfo = new RigidBodyConstructionInfo(0, new DefaultMotionState(Matrix4.Identity.Convert()), headBox, BulletSharp.Math.Vector3.Zero); headBody = new RigidBody(rbInfo); CoreEngine.pEngine.World.AddRigidBody(headBody, (int)CollisionFilleters.Look, (int)CollisionFilleters.Look); //headBody.CollisionFlags |= CollisionFlags.KinematicObject; headBody.UserObject = new Action <SceneNode>(triggerSwitch); headBody.UserIndex = 1; targetAngle = new Vector2(thetaDef, phiDef); angle = targetAngle; angSpeed = Vector2.Zero; audio = Node.AddComponent <AudioSource>(); PrepareExpressions(rigged); PrepareSpeech(); }
public RigidBodyBone(RigidContainer rcon) { bodyContainer = rcon; CollisionShape shape = null; switch (rcon.PrimitiveType) { case PhysPrimitiveType.Box: shape = new BoxShape(rcon.Size.Convert()); break; case PhysPrimitiveType.Capsule: shape = new CapsuleShape(rcon.Size.X, rcon.Size.Y); break; case PhysPrimitiveType.Sphere: shape = new SphereShape(rcon.Size.X); break; } if (rcon.Phys == PhysType.FollowBone) { rcon.Mass = 0; } bool isDynamic = (rcon.Mass != 0.0f); Vector3 inertia = Vector3.Zero; if (isDynamic) { shape.CalculateLocalInertia(rcon.Mass, out inertia); } startTransform = Matrix.RotationYawPitchRoll(rcon.Rotation.Y, rcon.Rotation.X, rcon.Rotation.Z) * Matrix.Translation(rcon.Position.Convert()); //Convert left to right coordinates var reverce = Matrix.Scaling(new Vector3(1, 1, -1)); startTransform = reverce * startTransform * reverce; rbInfo = new RigidBodyConstructionInfo(rcon.Mass, new DefaultMotionState(startTransform), shape, inertia); Body = new RigidBody(rbInfo); Body.ActivationState = ActivationState.DisableDeactivation; Body.Friction = rcon.Friction; Body.SetDamping(rcon.MassAttenuation, rcon.RotationDamping); Body.Restitution = rcon.Restitution; if (rcon.Phys == PhysType.FollowBone) { //Body.SetCustomDebugColor(new Vector3(0, 1, 0)); Body.CollisionFlags = Body.CollisionFlags | CollisionFlags.KinematicObject; } /* * else if (rcon.Phys == PhysType.Gravity) * Body.SetCustomDebugColor(new Vector3(1, 0, 0)); * else if (rcon.Phys == PhysType.GravityBone) * Body.SetCustomDebugColor(new Vector3(0, 0, 1)); */ //Disabled debug color cause its freeze engine on 3rd model load }
static CustomVehicle() { var ci = new RigidBodyConstructionInfo(0, null, null); fixedBody = new RigidBody(ci); fixedBody.SetMassProps(0, Vector3.Zero); ci.Dispose(); }
/// <summary> /// Initializes the static RaycastRobot instance. /// </summary> static RaycastRobot() { using (var ci = new RigidBodyConstructionInfo(0, null, null)) { fixedBody = new RigidBody(ci); fixedBody.SetMassProps(0, Vector3.Zero); } }
static CustomVehicle() { using (var ci = new RigidBodyConstructionInfo(0, null, null)) { fixedBody = new RigidBody(ci); fixedBody.SetMassProps(0, Vector3.Zero); } }
public void AddGroundRigidBody() { CollisionShape groundShape = new StaticPlaneShape(new BulletSharp.Math.Vector3(0, 1, 0), 1); RigidBodyConstructionInfo groundRigidBodyCI = new RigidBodyConstructionInfo(0, new DefaultMotionState(), groundShape, BulletSharp.Math.Vector3.Zero); RigidBody groundRigidBody = new RigidBody(groundRigidBodyCI); dynamicsWorld.AddRigidBody(groundRigidBody); }
protected override void Initialize() { base.Initialize(); // collision configuration contains default setup for memory, collision setup CollisionConf = new DefaultCollisionConfiguration(); Dispatcher = new CollisionDispatcher(CollisionConf); Broadphase = new DbvtBroadphase(); World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf); World.Gravity = new Vector3(0, -10, 0); World.DebugDrawer = DebugDrawer; // create the ground _groundShape = new BoxShape(50, 1, 50); LoadModel("ground", _groundShape); CollisionShapes.Add(_groundShape); CollisionObject ground = LocalCreateRigidBody(0, Matrix.Identity, _groundShape); // create a few dynamic rigidbodies const float mass = 1.0f; _boxShape = new BoxShape(1); LoadModel("cube", _boxShape); CollisionShapes.Add(_boxShape); var rbInfo = new RigidBodyConstructionInfo(mass, null, _boxShape); rbInfo.LocalInertia = _boxShape.CalculateLocalInertia(mass); for (int k = 0; k < ArraySizeY; k++) { for (int i = 0; i < ArraySizeX; i++) { for (int j = 0; j < ArraySizeZ; j++) { Matrix startTransform = Matrix.CreateTranslation( _start + new Vector3(2 * i, 2 * k, 2 * j)); // using motionstate is recommended, it provides interpolation capabilities // and only synchronizes 'active' objects rbInfo.MotionState = new DefaultMotionState(startTransform); var body = new RigidBody(rbInfo); // make it drop from a height body.Translate(new Vector3(0, 20, 0)); World.AddRigidBody(body); } } } rbInfo.Dispose(); FreeLook.SetEyeTarget(ref _eye, ref _target); }
private void AddRoofRigidBody() { var roofShape = new StaticPlaneShape(TGCVector3.Down.ToBulletVector3(), -3580); var roofMotionState = new DefaultMotionState(); var roofInfo = new RigidBodyConstructionInfo(0, roofMotionState, roofShape); var roofBody = new RigidBody(roofInfo); PhysicalWorld.AddBodyToTheWorld(roofBody); }