コード例 #1
0
ファイル: Model.cs プロジェクト: MattVitelli/IslandAdventure
 public override void OnAdd(Scene scene)
 {
     base.OnAdd(scene);
     if (false == true && mesh.GetCollisionMesh() != null)
     {
         Matrix currOrientation = Transformation.GetTransform();
         currOrientation.Translation = Vector3.Zero;
         Vector3 currPosition = Transformation.GetPosition();
         collisionTransform = new JigLibX.Math.Transform(currPosition, currOrientation);
         collision = new CollisionSkin(null);
         collision.AddPrimitive(mesh.GetCollisionMesh(), (int)MaterialTable.MaterialID.NotBouncyRough);
         scene.GetPhysicsEngine().CollisionSystem.AddCollisionSkin(collision);
         collision.SetNewTransform(ref collisionTransform);
     }
 }
コード例 #2
0
ファイル: Actor.cs プロジェクト: MattVitelli/IslandAdventure
        public override void OnAdd(Scene scene)
        {
            base.OnAdd(scene);

            scene.AddActor(this);

            PhysicsSystem world = scene.GetPhysicsEngine();

            Vector3 pos = Vector3.Up * 256 + 15*(new Vector3((float)RandomHelper.RandomGen.NextDouble(), (float)RandomHelper.RandomGen.NextDouble(), (float)RandomHelper.RandomGen.NextDouble())*2-Vector3.One);
            //pos.X += (scene.MainTerrain as TerrainHeightmap).GetWidth()*0.5f;
            //pos.Z += (scene.MainTerrain as TerrainHeightmap).GetDepth() * 0.5f;
            Vector3 normal = Vector3.Up;
            //scene.MainTerrain.GenerateRandomTransform(RandomHelper.RandomGen, out pos, out normal);
            //pos = pos + Vector3.Up * 5;

            body = new CharacterBody();
            collision = new CollisionSkin(body);

            standCapsule = new Capsule(Vector3.Zero, Matrix.CreateRotationX(MathHelper.PiOver2), 1.0f, 1.778f);
            crouchCapsule = new Capsule(Vector3.Zero, Matrix.CreateRotationX(MathHelper.PiOver2), 1.0f, 1.0f);
            SetupPosture(false);
            collision.AddPrimitive(standCapsule, (int)MaterialTable.MaterialID.NormalRough);
            body.CollisionSkin = collision;
            Vector3 com = PhysicsHelper.SetMass(75.0f, body, collision);

            body.MoveTo(pos + com, Matrix.Identity);
            collision.ApplyLocalTransform(new JigLibX.Math.Transform(-com, Matrix.Identity));

            body.SetBodyInvInertia(0.0f, 0.0f, 0.0f);

            body.AllowFreezing = false;
            body.EnableBody();
            Transformation = new Transform(body);

            ResetState();
        }