예제 #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 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
        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);
        }