예제 #1
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);
        }
예제 #2
0
        public void SetPhysics(Mogre.Entity entity, Mogre.SceneNode node, float mass)
        {
            MogreNewt.ConvexCollision collision = new MogreNewt.CollisionPrimitives.Cylinder(
                Core.Singleton.NewtonWorld,

                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("Metal");
        }
예제 #3
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);
        }
예제 #4
0
        bool Scene_FrameStarted(FrameEvent evt)
        {
            inputKeyboard.Capture();


            if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_SPACE))
            {
                if (timer <= 0.0)
                {
                    Vector3    dir, vec;
                    Quaternion camorient = camera.Orientation;
                    vec = new Vector3(0, 0, -1);

                    dir = camorient * vec;

                    Entity    ent;
                    SceneNode node;
                    String    name;
                    Vector3   pos = camera.Position;

                    name = "Body " + (mEntityCount++);

                    ent  = sceneMgr.CreateEntity(name, "ellipsoid.mesh");
                    node = sceneMgr.RootSceneNode.CreateChildSceneNode(name);
                    node.AttachObject(ent);

                    ent.SetMaterialName("Simple/dirt01");

                    MogreNewt.Collision col  = new MogreNewt.CollisionPrimitives.Ellipsoid(m_World, new Vector3(1, 1, 1));
                    MogreNewt.Body      body = new MogreNewt.Body(m_World, col);

                    Vector3 inertia = MogreNewt.MomentOfInertia.CalcSphereSolid(10.0f, 1.0f);
                    body.SetMassMatrix(10.0f, inertia);
                    body.AttachToNode(node);
                    body.IsGravityEnabled = true;
                    body.SetPositionOrientation(pos, camorient);
                    body.Velocity = dir * 15.0f;

                    timer = 0.2f;
                }
            }

            timer -= evt.timeSinceLastFrame;

            // ---------------------------------------------------------
            // -- VEHICLE CONTORLS
            // ---------------------------------------------------------
            float  torque   = 0.0f;
            Degree steering = new Degree(0);

            if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_I))
            {
                torque += 600.0f;
            }

            if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_K))
            {
                torque -= 600.0f;
            }

            if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_J))
            {
                steering += new Degree(30);
            }

            if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_L))
            {
                steering -= new Degree(30);
            }

            //update the vehicle!
            mCar.setTorqueSteering(torque, steering);

            if ((inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_Q)) && (!mR))
            {
                mR = true;
                // rebuild the vehicle
                if (mCar != null)
                {
                    mCar.Dispose();
                    mCar = new SimpleVehicle(sceneMgr, m_World, new Vector3(0, (float)new Random().NextDouble() * 10.0f, 0), Quaternion.IDENTITY);
                }
            }
            if (!inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_Q))
            {
                mR = false;
            }

            return(true);
        }