예제 #1
0
파일: Part.cs 프로젝트: ext0/Flex
        protected override void LoadPhysicsInstance()
        {
            _shape = new MogreNewt.CollisionPrimitives.Box(PhysicsEngine.World, new Mogre.Vector3(_size.x, _size.y, _size.z), 0);

            if (_rigidBody != null)
            {
                _rigidBody.AttachNode(null);
                _rigidBody.Dispose();
            }

            _rigidBody = new Body(PhysicsEngine.World, _shape);
            _rigidBody.SetPositionOrientation(new Mogre.Vector3(position.x + (size.x / 2), position.y + (size.y / 2), position.z + (size.z / 2)), _sceneNode.Orientation);
            _rigidBody.AttachNode(_sceneNode);

            if (!_anchored)
            {
                Mogre.Vector3 intertia;
                Mogre.Vector3 offset;
                _shape.CalculateInertialMatrix(out intertia, out offset);
                float mass = _size.x * _size.y * _size.z;
                _rigidBody.SetMassMatrix(mass, intertia);
            }

            _rigidBody.IsFreezed = anchored;

            //_rigidBody.IsGravityEnabled = true;

            _rigidBody.ForceCallback += _rigidBody_ForceCallback;
        }
예제 #2
0
        Body MakeSimpleBox(Vector3 size, Vector3 pos, Quaternion orient)
        {
            // base mass on the size of the object.
            float mass = size.x * size.y * size.z * 100.0f;

            // calculate the inertia based on box formula and mass
            Vector3 inertia = MogreNewt.MomentOfInertia.CalcBoxSolid(mass, size);


            Entity    box1;
            SceneNode box1node;

            box1     = mSceneMgr.CreateEntity("Entity" + (mEntityCount++), "box.mesh");
            box1node = mSceneMgr.RootSceneNode.CreateChildSceneNode();
            box1node.AttachObject(box1);
            box1node.SetScale(size);
            box1.NormaliseNormals = true;

            MogreNewt.Collision col = new MogreNewt.CollisionPrimitives.Box(mWorld, size);
            MogreNewt.Body      bod = new MogreNewt.Body(mWorld, col);
            col.Dispose();

            bod.AttachToNode(box1node);
            bod.SetMassMatrix(mass, inertia);
            bod.IsGravityEnabled = true;

            box1.SetMaterialName("Simple/BumpyMetal");


            bod.SetPositionOrientation(pos, orient);

            return(bod);
        }
 public void AddBoxPart(Vector3 offset, Quaternion _orientation, Vector3 size)
 {
     ConvexCollision collision = new MogreNewt.CollisionPrimitives.Box(
       Engine.Singleton.NewtonWorld,
       size,
       _orientation,
       offset,
       Engine.Singleton.GetUniqueBodyId());
     CompoundParts.Add(collision);
 }
        public void AddBoxPart(Vector3 offset, Quaternion _orientation, Vector3 size)
        {
            ConvexCollision collision = new MogreNewt.CollisionPrimitives.Box(
                Engine.Singleton.NewtonWorld,
                size,
                _orientation,
                offset,
                Engine.Singleton.GetUniqueBodyId());

            CompoundParts.Add(collision);
        }
예제 #5
0
파일: Missile.cs 프로젝트: andyhebear/ymfas
        public Missile(World _w, int _id, Vector3 _position, Quaternion _orientation, Ship _target)
        {
            id = _id;
            target = _target;

            MogreNewt.CollisionPrimitives.Box bodyBox =
                new MogreNewt.CollisionPrimitives.Box(_w, new Vector3(1.0f, 1.0f, 1.0f));
            body = new Body(_w, bodyBox);

            float mass;
            Vector3 inertia;
            body.getMassMatrix(out mass, out inertia);

               	body.setMassMatrix(1.0f, new Vector3(1.0f, 1.0f, 1.0f));

            body.setPositionOrientation(_position, _orientation);
            body.IsGravityEnabled = false;
            body.ForceCallback += new ForceCallbackHandler(ForceTorqueCallback);
            body.setAutoFreeze(0);
            body.setLinearDamping(0.0f);
            body.setAngularDamping(new Vector3(0.0f));
        }
예제 #6
0
        public Missile(World _w, int _id, Vector3 _position, Quaternion _orientation, Ship _target)
        {
            id     = _id;
            target = _target;

            MogreNewt.CollisionPrimitives.Box bodyBox =
                new MogreNewt.CollisionPrimitives.Box(_w, new Vector3(1.0f, 1.0f, 1.0f));
            body = new Body(_w, bodyBox);

            float   mass;
            Vector3 inertia;

            body.getMassMatrix(out mass, out inertia);

            body.setMassMatrix(1.0f, new Vector3(1.0f, 1.0f, 1.0f));

            body.setPositionOrientation(_position, _orientation);
            body.IsGravityEnabled = false;
            body.ForceCallback   += new ForceCallbackHandler(ForceTorqueCallback);
            body.setAutoFreeze(0);
            body.setLinearDamping(0.0f);
            body.setAngularDamping(new Vector3(0.0f));
        }
예제 #7
0
        Body MakeSimpleBox(Vector3 size, Vector3 pos, Quaternion orient)
        {
            // base mass on the size of the object.
            float mass = size.x * size.y * size.z * 2.5f;

            // calculate the inertia based on box formula and mass
            Vector3 inertia;
            Vector3 offset;


            Entity    box1;
            SceneNode box1node;

            box1     = sceneMgr.CreateEntity("Entity" + (mEntityCount++), "box.mesh");
            box1node = sceneMgr.RootSceneNode.CreateChildSceneNode();
            box1node.AttachObject(box1);
            box1node.SetScale(size);
            box1.NormaliseNormals = true;

            MogreNewt.ConvexCollision col = new MogreNewt.CollisionPrimitives.Box(m_World, size);
            col.CalculateInertialMatrix(out inertia, out offset);
            inertia = inertia * mass;
            MogreNewt.Body bod = new MogreNewt.Body(m_World, col);
            col.Dispose();

            bod.AttachNode(box1node);
            bod.SetMassMatrix(mass, inertia);
            bod.IsGravityEnabled = true;

            box1.SetMaterialName("Examples/10PointBlock");


            bod.SetPositionOrientation(pos, orient);

            return(bod);
        }
예제 #8
0
        public void SetPhysics(Mogre.Entity entity, Mogre.SceneNode node, float mass)
        {
            MogreNewt.ConvexCollision collision = new MogreNewt.CollisionPrimitives.Box(
                Core.Singleton.NewtonWorld,
                Core.Singleton.PhysicsManager.getCollisionBoxSize(entity, node),
               // Core.Singleton.PhysicsManager.getCollisionCylinderRadius(entity, node),
               // Core.Singleton.PhysicsManager.getCollisionCylinderHeight(entity, node),
               // new Mogre.Quaternion(new Mogre.Radian(1.57f), new Mogre.Vector3(0f, 0f, 1f)),
                Core.Singleton.GetUniqueBodyId()
                );

            Mogre.Vector3 inertia, offset;
            collision.CalculateInertialMatrix(out inertia, out offset);
            inertia *= mass;

            m_Body = new MogreNewt.Body(Core.Singleton.NewtonWorld, collision, true);
            m_Body.AttachNode(node);
            m_Body.SetMassMatrix(mass, inertia);
            m_Body.SetPositionOrientation( node.Position + new Vector3(0,1,0) , node.Orientation);
            m_Body.MaterialGroupID = Core.Singleton.PhysicsManager.getMaterialID("Ground");
        }