示例#1
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");
        }
示例#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 * 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);
        }
示例#3
0
        public override void CreateScene()
        {
            // Newton initialization
            m_World = new World();
            MogreNewt.Debugger.Instance.Init(sceneMgr);


            // sky box.
            sceneMgr.SetSkyBox(true, "Examples/CloudyNoonSkyBox");

            // shadows on!
            sceneMgr.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_ADDITIVE;

            // floor object!
            Entity    floor;
            SceneNode floornode;

            floor     = sceneMgr.CreateEntity("Floor", "simple_terrain.mesh");
            floornode = sceneMgr.RootSceneNode.CreateChildSceneNode("FloorNode");
            floornode.AttachObject(floor);
            floor.SetMaterialName("Simple/BeachStones");

            floor.CastShadows = false;

            //-------------------------------------------------------------
            // add some other objects.
            Entity    floor2;
            SceneNode floornode2;

            floor2     = sceneMgr.CreateEntity("Floor2", "simple_terrain.mesh");
            floornode2 = floornode.CreateChildSceneNode("FloorNode2");
            floornode2.AttachObject(floor2);
            floor2.SetMaterialName("Simple/BeachStones");
            floor2.CastShadows = false;
            floornode2.SetPosition(80.0f, 0.0f, 0.0f);

            Entity    floor3;
            SceneNode floornode3;

            floor3     = sceneMgr.CreateEntity("Floor3", "simple_terrain.mesh");
            floornode3 = floornode.CreateChildSceneNode("FloorNode3");
            floornode3.AttachObject(floor3);
            floor3.SetMaterialName("Simple/BeachStones");
            floor3.CastShadows = false;
            floornode3.SetPosition(-80.0f, -5.0f, 0.0f);
            floornode3.Orientation = new Quaternion(new Degree(15.0f), Vector3.UNIT_Z);
            //-------------------------------------------------------------

            // using the new "SceneParser" TreeCollision primitive.  this will automatically parse an entire tree of
            // SceneNodes (parsing all children), and add collision for all meshes in the tree.
            MogreNewt.CollisionPrimitives.TreeCollisionSceneParser stat_col = new MogreNewt.CollisionPrimitives.TreeCollisionSceneParser(m_World);
            stat_col.ParseScene(floornode, true);
            MogreNewt.Body bod = new MogreNewt.Body(m_World, stat_col);
            stat_col.Dispose();

            bod.AttachNode(floornode);
            bod.SetPositionOrientation(new Vector3(0.0f, -20.0f, 0.0f), Quaternion.IDENTITY);


            // position camera
            camera.SetPosition(0.0f, -3.0f, 20.0f);

            //make a light
            Light light;

            light      = sceneMgr.CreateLight("Light1");
            light.Type = Light.LightTypes.LT_POINT;
            light.SetPosition(0.0f, 100.0f, 100.0f);
        }