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 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! this time we'll scale it slightly to make it more vehicle-friendly :P
            Vector3   size = new Vector3(2.0f, 0.5f, 2.0f);
            Entity    floor;
            SceneNode floornode;

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

            collisionNode = floornode;

            floor.CastShadows = false;

            //Vector3 siz(100.0, 10.0, 100.0);
            MogreNewt.Collision col = new MogreNewt.CollisionPrimitives.TreeCollision(m_World, floornode, false);
            MogreNewt.Body      bod = new MogreNewt.Body(m_World, col);
            col.Dispose();

            bod.AttachToNode(floornode);
            bod.SetPositionOrientation(new Vector3(0, -2.0f, 0.0f), Quaternion.IDENTITY);

            // here's where we make the simple vehicle.  everything is taken care of in the constuctor.
            mCar = new SimpleVehicle(sceneMgr, m_World, new Vector3(0, -0.5f, 0), Quaternion.IDENTITY);



            // position camera
            camera.SetPosition(0.0f, 1.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);
        }
示例#3
0
        public ForceBall(SceneManager sceneManager, MogreNewt.World physicsWorld, float tempSize, int own)
        {
            MogreNewt.ConvexCollision col;
            Mogre.Vector3 offset;
            Mogre.Vector3 inertia;

            unique++;

            // Create the visible mesh (no physics)
            ent = sceneManager.CreateEntity("forceball" + unique, "Sph.mesh");
            sn = sceneManager.RootSceneNode.CreateChildSceneNode();
            sn.AttachObject(ent);
            Console.WriteLine("end ball create");
            size = tempSize;

            sn.SetScale(size, size, size);

            // Create the collision hull
            col = new MogreNewt.CollisionPrimitives.ConvexHull(physicsWorld, sn);
            col.calculateInertialMatrix(out inertia, out offset);

            // Create the physics body. This body is what you manipulate. The graphical Ogre scenenode is automatically synced with the physics body
            body = new MogreNewt.Body(physicsWorld, col);
            col.Dispose();

            //body.setPositionOrientation(new Vector3(0, 10, 0), Quaternion.IDENTITY);

            body.attachToNode(sn);
            body.setContinuousCollisionMode(1);
            body.setMassMatrix(mass, mass * inertia);
            body.IsGravityEnabled = true;
            body.setUserData(this);

            trail = sceneManager.CreateParticleSystem("awesome" + StringConverter.ToString(unique), "Char/Smoke");
            trail.CastShadows = true;
            trail.GetEmitter(0).EmissionRate = 100;
            sn.AttachObject(trail);

            Console.WriteLine("player stuff");

            owner = own;
            Player tempP = (Player)Program.p1;
            colour = tempP.cv;
        }
示例#4
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");
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
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);
        }