Exemplo n.º 1
0
        /// <summary>
        /// The main setup point for the initial scene graph and tools
        /// </summary>
        public void SetupInitialObjects()
        {
            Root = new MObject(MObject.EType.Null, "Root");
            //Root.Deletable = false;

            TemplateRoot = new MObject(MObject.EType.Null, "TemplateRoot");
            Root.Add(TemplateRoot);
            TemplateRoot.Enabled = false; //disable updates

            SelectionRoot = new MObject(MObject.EType.Null, "Selection");
            Root.Add(SelectionRoot);

            UtilityRoot           = new MObject(MObject.EType.Null, "Utility");
            UtilityRoot.Deletable = false;
            Root.Add(UtilityRoot);
            time = new Time();
            UtilityRoot.Add(time);

            LightRoot = new MObject(MObject.EType.Null, "LightRoot");
            Root.Add(LightRoot);

            Climate = new MClimate();
            UtilityRoot.Add(Climate);

            Globals.ScriptHost = new MScriptHost();
            UtilityRoot.Add(Globals.ScriptHost);
            MSystemScript sc = new MSystemScript("Massive.Main", Root);

            sc.SetActivator(Globals.ScriptHost.GetMainActivator());
            Root.Add(sc);

            Globals.TexturePool = new TexturePool();
            UtilityRoot.Add(Globals.TexturePool);

            Renderer = new MRenderer();
            UtilityRoot.Add(Renderer);

            DefaultShader = new MShader(MShader.DEFAULT_SHADER);
            DefaultShader.Load("default_v.glsl",
                               "default_f.glsl",
                               "Terrain\\eval.glsl", "Terrain\\control.glsl");
            DefaultShader.Bind();
            DefaultShader.SetInt("material.diffuse", MShader.LOCATION_DIFFUSE);
            DefaultShader.SetInt("material.specular", MShader.LOCATION_SPECULAR);
            DefaultShader.SetInt("material.multitex", MShader.LOCATION_MULTITEX);
            DefaultShader.SetInt("material.normalmap", MShader.LOCATION_NORMALMAP);
            DefaultShader.SetInt("material.shadowMap", MShader.LOCATION_SHADOWMAP);
            //DefaultShader.Deletable = false;
            Helper.CheckGLError(this, "TestPoint 1");

            // MShader GUIShader = new MShader("DefaultGUIShader");
            // GUIShader.Load("gui_v.glsl", "gui_f.glsl");
            //GUIShader.Bind();
            //GUIShader.Deletable = false;

            MaterialRoot = new MObject(MObject.EType.Null, "MaterialRoot");
            //MaterialRoot.Deletable = false;
            Root.Add(MaterialRoot);
            Helper.CheckGLError(this);
            if (Physics != null)
            {
                Physics.Dispose();
            }
            Physics = new MPhysics();
            Physics.Setup(); //only need to do this once
            //Physics.Deletable = false;
            UtilityRoot.Add(Physics);
            Helper.CheckGLError(this, "TestPoint 2");
            //UtilityRoot.Add(Globals.Network);
            //Globals.Network.Deletable = false;

            DistanceClipper = new MDistanceClipper();
            UtilityRoot.Add(DistanceClipper);
            FrustrumCuller = new MFrustrumCuller();
            UtilityRoot.Add(FrustrumCuller);

            Globals.Avatar = new MAvatar("Player1");
            UtilityRoot.Add(Globals.Avatar);

            Background = new MObject(MObject.EType.Null, "Background");
            Root.Add(Background);
            Background2 = new MObject(MObject.EType.Null, "Background2");
            Root.Add(Background2);

            ModelRoot = new MObject(MObject.EType.Null, "ModelRoot");
            Root.Add(ModelRoot);
            ModelRoot.Deletable = false;

            AstroRoot = new MObject(MObject.EType.Null, "AstroRoot");
            //ModelRoot.Add(AstroRoot);
            UtilityRoot.Add(AstroRoot);
            AstroRoot.Deletable = false;

            if (Settings.DrawPlanets == true)
            {
                MPlanetHandler mpi = new MPlanetHandler();
                UtilityRoot.Add(mpi);
                MGrass grass = new MGrass();
                Background2.Add(grass);
            }

            Priority1 = new MObject(MObject.EType.Null, "Priority1");
            ModelRoot.Add(Priority1);
            Priority2 = new MObject(MObject.EType.Null, "Priority2");
            ModelRoot.Add(Priority2);
            Overlay = new MObject(MObject.EType.Null, "Overlay");
            //ModelRoot.Add(Overlay); //manually drawn in render


            if (Settings.DrawBackdrop == true)
            {
                AddBackdrop();
            }

            Fog = new MFog();
            UtilityRoot.Add(Fog);

            DefaultMaterial           = new MMaterial(MMaterial.DEFAULT_MATERIAL);
            DefaultMaterial.Deletable = false;
            DefaultMaterial.AddShader(DefaultShader);
            //DefaultMaterial.SetDiffuseTexture(Globals.TexturePool.GetTexture("Textures\\default.jpg"));
            MaterialRoot.Add(DefaultMaterial);

            MTexture DefaultTexture = new MTexture(MTexture.DEFAULT_TEXTURE);

            DefaultTexture.LoadTextureData(MFileSystem.ProjectPath + "Assets\\Textures\\default.jpg");
            DefaultTexture.DoAssign = true;
            DefaultMaterial.SetDiffuseTexture(DefaultTexture);


            MMaterial GUIMat = new MMaterial("DefaultGUIMaterial");
            //GUIMat.Deletable = false;
            //GUIMat.AddShader(GUIShader);
            //GUIMat.SetDiffuseTexture(Globals.TexturePool.GetTexture("Textures\\unwrap_helper_1024.jpg"));
            //MaterialRoot.Add(GUIMat);

            MMaterial DepthMaterial = new MMaterial("Depth");

            DepthMaterial.Deletable = false;
            simpleDepthShader       = new MShader("simpleDepthShader");
            simpleDepthShader.Load("shadow_mapping_depth_v.glsl",
                                   "shadow_mapping_depth_f.glsl",
                                   "", "")
            ;
            DepthMaterial.shader = simpleDepthShader;
            DepthMaterial.Add(simpleDepthShader);
            MaterialRoot.Add(DepthMaterial);
            Helper.CheckGLError(this, "TestPoint 5");


            //UtilityRoot.Add(audioListener);
            //audioListener.Deletable = false;

            Camera                    = new MCamera("MainCam");
            Camera.OwnerID            = MObject.OWNER_SYSTEM;
            Camera.transform.Position = new Vector3d(9, 5, 9);
            UtilityRoot.Add(Camera);
            audioListener = new MAudioListener();
            Camera.Add(audioListener);
            // Camera.Deletable = false;

            light                    = new MLight("DirLight");
            light.OwnerID            = MObject.OWNER_SYSTEM;
            light.transform.Position = new Vector3d(-10, 20.0f, -10.0f);
            UtilityRoot.Add(light);
            //light.Deletable = false;

            ScreenPick = new MScreenPick();
            // ScreenPick.Setup();
            UtilityRoot.Add(ScreenPick);
            // ScreenPick.Deletable = false;

            MShader debugDepthQuad = new MShader("debugDepthQuad");

            debugDepthQuad.Load("debug_quad_v.glsl",
                                "debug_quad_f.glsl",
                                "Terrain\\eval.glsl", "Terrain\\control.glsl");
            debugDepthQuad.Bind();
            debugDepthQuad.SetInt("depthMap", 0);
            //debugDepthQuad.SetFloat("near_plane", light.NearPlane);
            //debugDepthQuad.SetFloat("far_plane", light.FarPlane);
            UtilityRoot.Add(debugDepthQuad);
            debugDepthQuad.Deletable = false;

            MMaterial debugmat = new MMaterial("DEBUG");

            debugmat.shader = debugDepthQuad;
            //debugmat.Deletable = false;
            debugQuad          = new DebugQuad("DEBUGQUAD");
            debugQuad.material = debugmat;
            UtilityRoot.Add(debugQuad);
            debugQuad.Deletable = false;

            GUIRoot = new MGUI();
            Root.Add(GUIRoot);
            Helper.CheckGLError(this, "TestPoint 6");
        }
Exemplo n.º 2
0
        public void PlantTrees(MAstroBody planet, MTerrainTile tile)
        {
            //DistanceThreshold = tile.DistanceThreshold;
            Tile = tile;
            if (tile.material == null)
            {
                return;
            }
            MTexture tex = Tile.Biome;

            if (tex == null)
            {
                return;
            }

            this.transform.Position = tile.transform.Position;

            Random ran = new Random(1234);

            Matrix4d TreeRotation = Matrix4d.CreateFromQuaternion(Globals.LocalUpRotation());

            int i = 0;

            for (int z = 0; z < tile.z_res - 1; z++)
            {
                for (int x = 0; x < tile.x_res - 1; x++)
                {
                    float[] c = tex.GetPixel(x, z);
                    float   r = c[0];
                    float   g = c[1];
                    float   b = c[2];
                    float   a = c[3];

                    float t = 0;
                    //if ((b > r) && (b > g)) t = g;
                    if ((r < 0.05) && (g > 0.1) && (b < 0.05))
                    {
                        t = g;
                    }
                    else
                    {
                        continue;
                    }

                    if (ran.NextDouble() > Settings.TreeDensity)
                    {
                        continue;
                    }

                    //if (g < 0.7) continue;
                    //Console.WriteLine(c[0] + " " + c[1] + " " + c[2] + " " + c[3]);
                    if (i >= Settings.MaxTreesPerTerrain)
                    {
                        break;
                    }
                    Vector3d Treepos = new Vector3d(x,
                                                    0,
                                                    z);
                    //Vector3d PlantingPos = planet.GetNearestPointOnSphere(Treepos, 0);
                    Matrix4d TreeScale    = Matrix4d.Scale(1 + ran.NextDouble(), 1 + ran.NextDouble() * 2, 1 + ran.NextDouble());
                    Vector3d PlantingPos  = Tile.GetPointOnSurfaceFromGrid(Treepos); //; + new Vector3d(r.NextDouble()*5, r.NextDouble() * 5, r.NextDouble()*5);
                    Matrix4d TreePosition = Matrix4d.CreateTranslation(PlantingPos);
                    //find point at y with raycast
                    Matrix4 final = MTransform.GetFloatMatrix(TreeScale * TreeRotation * TreePosition);
                    mats[i] = final;
                    i++;
                }
            }

            TotalInstances = i;

            for (int j = TotalInstances; j < Settings.MaxTreesPerTerrain; j++)
            {
                Matrix4 final = Matrix4.CreateTranslation(j, 0, 0);
                mats[j] = final;
            }

            //Setup();
            //UploadBuffer();
            Planted = false;
        }
Exemplo n.º 3
0
        public void PlantGrass(MAstroBody planet, MTerrainTile tile)
        {
            // if (Planted == true) return;
            //DistanceThreshold = tile.DistanceThreshold;
            Tile = tile;
            if (tile.material == null)
            {
                return;
            }
            MTexture tex = Tile.Biome;

            if (tex == null)
            {
                return;
            }

            this.transform.Position = tile.transform.Position;

            //Random ran = new Random(1234);

            Matrix4d TreeRotation = Matrix4d.CreateFromQuaternion(Globals.LocalUpRotation());

            //int i = 0;
            TotalInstances = 0;

            Vector3d AP = Globals.Avatar.GetPosition();
            // Console.WriteLine(AP);

            Barycentric bary = new Barycentric(Tile.Boundary.TL, Tile.Boundary.BR, Tile.Boundary.TR, AP);

            PlantPatch(bary, 64 * 64, 2, 0.8);
            //PlantPatch(bary, 32 * 32, 8, 0.3);

            // Console.WriteLine(bary.ToString());

            /*
             * double sq = 64 * 64;
             * double sq2 = Math.Sqrt(sq);
             *
             * Matrix4d TreePosition;
             * Matrix4 final;
             * Matrix4d TreeScale;
             * Vector3d PlantingPos = new Vector3d();
             * for (int x = (int)-sq2; x < sq2; x++)
             * for (int z = (int)-sq2; z < sq2; z++)
             * {
             *  PlantingPos.X = (int)(Tile.x_res * (1 - bary.u)) - x * 0.05;
             *  PlantingPos.Y = 0;
             *  PlantingPos.Z = (int)(Tile.z_res * (bary.v)) - z * 0.05;
             *
             *  double yv =
             *    (MPerlin.Noise(PlantingPos.X, PlantingPos.Z) * 0.4)
             + (MPerlin.Noise(PlantingPos.X * 1.1, PlantingPos.Z * 1.1) * 0.4)
             +    ;
             +  if (yv < 0.1) continue;
             +
             +  TreeScale = Matrix4d.Scale(0.03+0.04 * yv,  0.01 + yv * 0.14 , 0.03+0.04* yv);
             +
             +  PlantingPos.X += MPerlin.Noise(PlantingPos.X * 4.0, PlantingPos.Z * 4.1) * 1.1;
             +  PlantingPos.Z += MPerlin.Noise(PlantingPos.X * 3.8, PlantingPos.Z * 4.2) * 1.1;
             +  PlantingPos = Tile.GetInterpolatedPointOnSurfaceFromGrid2(PlantingPos);
             +
             +  TreePosition = Matrix4d.CreateTranslation(PlantingPos);
             +  final = MTransform.GetFloatMatrix(TreeScale * TreeRotation * TreePosition);
             +  if (i < Settings.MaxGrassPerTerrain)
             +  {
             +    mats[i] = final;
             +    i++;
             +  }
             + }
             +
             + TotalInstances = i;
             */

            for (int j = TotalInstances; j < Settings.MaxGrassPerTerrain; j++)
            {
                Matrix4 final = Matrix4.CreateTranslation(9999999999, 0, 0);
                mats[j] = final;
            }


            //Setup();
            //UploadBuffer();
            Planted = true;
        }