public void Test_New() { var mat = new PhysicsMaterial (); Assert.AreEqual (1, mat.Restitution); Assert.AreEqual (0.5f, mat.Friction); Assert.AreEqual (0, mat.RollingFriction); Assert.AreEqual (0, mat.LinearDamping); Assert.AreEqual (0, mat.AngularDamping); }
/// <summary> /// コンストラクター /// </summary> /// <remarks> /// デフォルトはスタティック オブジェクト。 /// </remarks> public PhysicsBody() { var wld = Physics2D.GetInstance ().GetWorld () as FarseerPhysics.Dynamics.World; if (wld == null) { throw new InvalidOperationException ("Physics world is not created"); } this.mask = 0xffffffff; this.shape = null; this.mat = null; this.hash = -0x12345678; // 本当はアタッチされるタイミングで Box2D.World に追加したいが、 // 無理みたいなので・・・ this.body = new Body (wld, this); }
/// <summary> /// 剛体物理オブジェクトを作成するコンストラクター /// </summary> public RigidBody() { this.shapes = new List<CollisionShape> (); this.offsets = new List<Vector3> (); this.material = null; this.offset = new Vector3 (0, 0, 0); this.collideWith = -1; this.ignoreWith = 0; this.mass = 1; this.useGravity = true; this.useContactResponse = true; this.useCCD = true; this.linearFactor = new Vector3 (1, 1, 1); this.angularFactor = new Vector3 (1, 1, 1); this.rigidBody = new BulletSharp.RigidBody(new BulletSharp.RigidBodyConstructionInfo (mass, new DefaultMotionState (), new CompoundShape(true))); }
private static Node CreateFloor(string name, int x, int y, int width, int height, Quaternion rot) { var spr = new Sprite (width, height); spr.AddTexture (Resource.GetTexture ("media/Rectangle-160x40.png")); var col = new BoxCollision (spr.Width / 2, spr.Height / 2, 0); col.SetOffset (spr.Width / 2, spr.Height / 2, 0); var body = new PhysicsBody (); var mat = new PhysicsMaterial (); body.Shape = col; body.Material = mat; var node = new Node (name); node.SetTranslation (x, y, 0); node.SetRotation (rot); node.Attach (spr); node.Attach (col); node.Attach (body); return node; }
/// <summary> /// 物理特性の変更 /// </summary> /// <remarks> /// コリジョンの物理材質を変更します。 /// 値は次回 <see cref="OnPhysicsUpdate"/> が呼ばれたタイミングで物理エンジンに反映されます。 /// 物理特性に <c>null</c> に設定すると例外が発生します。 /// </remarks> /// <param name="mat">物理特性</param> public void SetMaterial(PhysicsMaterial mat) { if (mat == null) { throw new ArgumentNullException ("Material is null"); } this.mat = mat; }
public void Test_Sphere_to_Box() { var mat = new PhysicsMaterial (); mat.Restitution=1; var sph = new Node ("Sphere"); sph.Attach(new RigidBody ()); sph.RigidBody.Mass = 1; sph.RigidBody.Material = mat; sph.RigidBody.AddShape( new SphereShape (1)); var box = new Node ("Box"); box.Attach(new RigidBody ()); box.RigidBody.Mass = 0; box.RigidBody.Material = mat; box.RigidBody.AddShape(new BoxShape (1,1,1)); var wld = new World (""); wld.AddChild (sph); wld.AddChild (box); wld.PhysicsSimulator.SetGravity (0, -9.8f, 0); sph.Translate (0, 10, 0); for (var i = 0; i < 100; i++) { wld.PhysicsUpdate (33); Debug.WriteLine ("Sphere = {0}, Box = {1}", sph.Position, box.Position); } wld.Destroy (); }