Beispiel #1
0
        protected override void CreateScene()
        {
            mLog = LogManager.Singleton.createLog("DemoGrass.log", false, true);
            mLog.LogMessage(string.Format("DemoGrass log {0}", System.DateTime.Now));

            //Init waveGrass varibles
            xinc     = OgreMath.PI * 0.4f;
            zinc     = OgreMath.PI * 0.55f;
            xpos     = OgreMath.RangeRandom(-OgreDotNet.OgreMath.PI, OgreDotNet.OgreMath.PI);
            zpos     = OgreMath.RangeRandom(-OgreDotNet.OgreMath.PI, OgreDotNet.OgreMath.PI);
            xxoffset = new Math3D.Vector4(0.0f, 0.0f, 0.0f, 0.0f);


            mSceneManager.SetSkyBox(true, "Examples/SpaceSkyBox");

            setupLighting();
            mSceneManager.AmbientLightColor = Color.FromArgb(125, 125, 125, 125);


            //create a ground plain
            mLog.LogMessage("Point 1");
            Plane plane = new Plane();

            plane.Normal.x = 0;
            plane.Normal.y = 1;
            plane.Normal.z = 0;
            plane.D        = 0;
            MeshManager.GetSingleton().CreatePlane("Myplane", "General", plane,
                                                   14500, 14500, 10, 10, true, 1, 50, 50, Vector3.UnitZ);
            Entity pPlaneEnt = mSceneManager.CreateEntity("plane", "Myplane");

            pPlaneEnt.SetMaterialName("Examples/GrassFloor");
            pPlaneEnt.SetCastShadows(false);
            mSceneManager.GetRootSceneNode().CreateChildSceneNode().AttachObject(pPlaneEnt);


            //create the grass mesh
            mLog.LogMessage("Point 2");
            createGrassMesh2();
            Entity e = null;

            e = mSceneManager.CreateEntity("1", GRASS_MESH_NAME);


            //close the the grass mesh in a region
            StaticGeometry s = mSceneManager.CreateStaticGeometry("bing");

            s.setRegionDimensions(new Vector3(1000, 1000, 1000));
            // Set the region origin so the centre is at 0 world
            s.setOrigin(new Vector3(-500, 500, -500));
            mLog.LogMessage("Point 3");
            for (int x = -1950; x < 1950; x += 150)                     //1950
            {
                for (int z = -1950; z < 1950; z += 150)
                {
                    Vector3 pos;
                    pos.x = x + OgreMath.RangeRandom(-25, 25);
                    pos.y = 0;
                    pos.z = z + OgreMath.RangeRandom(-25, 25);
                    Quaternion orientation = Quaternion.FromAngleAxis(
                        new Degree(OgreMath.RangeRandom(0, 359)).ValueDegrees(), Vector3.UnitY);
                    Vector3 scale = new Vector3(1, OgreMath.RangeRandom(0.85f, 1.15f), 1);
                    s.addEntity(e, pos, orientation, scale);
                }
            }
            mLog.LogMessage("Point 4");
            s.build();
            mStaticGeom = s;
            //mStaticGeom.dump("Grass.SG.Dump.txt");



            //Put an Ogre head in the middle
            mLog.LogMessage("Point 5");
            OgreDotNet.MeshPtr m = MeshManager.GetSingleton().Load("ogrehead.mesh", "General");
            Mesh   mm = m.Get();
            UInt16 src = 0, dest = 0;

            if (!mm.SuggestTangentVectorBuildParams(ref src, ref dest))
            {
                mLog.LogMessage("got from SuggestTangentVectorBuildParams src=" + src + " dest=" + dest);
                mm.BuildTangentVectors(src, dest);
            }
            e = mSceneManager.CreateEntity("head", "ogrehead.mesh");
            e.SetMaterialName("Examples/OffsetMapping/Specular");
            SceneNode headNode = mSceneManager.GetRootSceneNode().CreateChildSceneNode();

            headNode.AttachObject(e);
            headNode.SetScale(7, 7, 7);
            headNode.SetPosition(0, 200, 0);
            e.SetNormaliseNormals(true);


            mLog.LogMessage("Point 6");
            //setup camera position
            mCamera.Move(new Vector3(0, 350, 800));
            mCamera.LookAt = new Vector3(0, 200, 0);
            mLog.LogMessage("Point end");
        }