예제 #1
0
        private void glControl1_Load(object sender, EventArgs e)
        {
            glControl1.Loaded = true;

            CreateShaders();

            glControl1.MakeCurrent();

            //WavefrontShape.MakeCone(20);
            STKModel.MakeCone(20);

            glControl1.TheWorld = TheWorld;

            LoadObjects();

            GL.ClearColor(Color.Black);
            //SetupViewport();

            GL.Enable(EnableCap.Lighting);   // Turn off lighting to get color
            GL.Enable(EnableCap.Light0);

            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);  //??
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            GL.ShadeModel(ShadingModel.Smooth);

            // Enable Light 0 and set its parameters.
            //GL.Light(LightName.Light0, LightParameter.Position, SunPosition);

            const float ambient = 0.1f;

            GL.Light(LightName.Light0, LightParameter.Ambient, new[] { ambient, ambient, ambient, 1.0f });
            //GL.Light(LightName.Light0, LightParameter.Ambient, new[] { 0.6f, 0.6f, 0.6f, 1.0f });
            GL.Light(LightName.Light0, LightParameter.Diffuse, new[] { 1.0f, 1.0f, 1.0f, 1.0f });
            GL.Light(LightName.Light0, LightParameter.Specular, new[] { 1f, 1f, 1f, 1.0f });
            GL.Light(LightName.Light0, LightParameter.SpotExponent, new[] { 1.0f, 1.0f, 1.0f, 1.0f });
            GL.LightModel(LightModelParameter.LightModelAmbient, new[] { 0f, 0f, 0f, 1.0f });
            GL.LightModel(LightModelParameter.LightModelLocalViewer, 0);
            GL.LightModel(LightModelParameter.LightModelTwoSide, 0);

            //GL.Material(MaterialFace.Front, MaterialParameter.Ambient, new float[] { 0.3f, 0.3f, 0.3f, 1.0f });
            //GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
            //GL.Material(MaterialFace.Front, MaterialParameter.Specular, new float[] { 0.5f, 0.5f, 0.5f, 1.0f });
            //GL.Material(MaterialFace.Front, MaterialParameter.Emission, new float[] { 0.0f, 0.0f, 0.0f, 1.0f });

            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.ColorMaterial);  // lets me use colors rather than changing materials
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.Normalize);      // Do I need this?  (this make a difference, although I don't know why)

            GL.PointSize(5f);
            GL.Enable(EnableCap.PointSmooth);
            GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);

            var start = TheWorld.Fetcher.SpiceStartDate.AddDays(0);

            SetScenarioTimes(LadeeStateFetcher.StateFrame.MoonFixed, start, TheWorld.Fetcher.SpiceStartDate.AddDays(70));

            var t = TimeUtilities.DateTimeToTime42(start);

            UpdateToTime(t);

            glControl1.CameraMode = new ArcBall(glControl1, TheWorld.LADEE)
            {
                RelativePosition = new Vector3d(0d, 100 * Meters, 0d)
            };
            TheWorld.Tick();
        }
예제 #2
0
        private void LoadObjects()
        {
            TheWorld.Trajectory = new TrajectoryShape(TheWorld);

            TheWorld.LADEE          = STKModel.Load("ladee_new.mdl");
            TheWorld.LADEE.ShowAxes = true;
            TheWorld.NearShapes.Add(TheWorld.LADEE);

            if (false)
            {
                for (var azimuth = 0d; azimuth < MathHelper.TwoPi; azimuth += MathHelper.DegreesToRadians(5))
                {
                    for (var elevation = MathHelper.DegreesToRadians(-60d); elevation < MathHelper.DegreesToRadians(60d); elevation += MathHelper.DegreesToRadians(5))
                    {
                        const double d    = 100000d;
                        var          w    = Math.Cos(elevation) * d;
                        var          z    = Math.Sin(elevation) * d;
                        var          x    = Math.Cos(azimuth) * w;
                        var          y    = Math.Sin(azimuth) * w;
                        var          cube = new CubeShape()
                        {
                            Scale = 0.1f, Position = new Vector3d(x, y, z)
                        };
                        TheWorld.FarShapes.Add(cube);
                    }
                }
            }

            //var cube = new CubeShape() { Scale = 1.5f, Position = new Vector3d(1000d,0d,0d) };
            //TheWorld.FarShapes.Add(cube);

            /*
             * _ladee = new WavefrontShape
             *  {
             *      Name = "LADEE",
             *      WavefrontFilename = "0a-003-ladee_simplified2.obj",
             *      Position = new Vector3d(386400 * Kilometers, 0000 * Kilometers, 0d),
             *      ShowAxes = true,
             *      AxisScale = 40f,
             *      ShowModel = true
             *  };
             * _ladee.Load();
             * //glControl1.NearShapes.Add(_ladee);
             */

            //foreach (var c in _stkModel.Components)
            //    foreach (var m in c.Meshes)
            //        Console.WriteLine("VBO {0}", m.Handle.VboID);
            //Console.WriteLine("VBO for Wavefront = {0}", _ladee._vboid);

            /*
             * _moon = new MoonHeightField { Name = "Moon", Position = new Vector4d(384400 * Kilometers, 0d, 0d, 1d), TextureFilename = "moon_8k_color_brim16.jpg", Radius = (float)(1734.4 * Kilometers)};
             * _moon.Load();
             * _moon.LoadTexture();
             * glControl1.FarShapes.Add(_moon);
             */

            if (true)
            {
                TheWorld.Moon = new MoonDEM()
                {
                    Name            = "Moon",
                    Position        = new Vector3d(384400 * Kilometers, 0d, 0d),
                    TextureFilename = "moon_8k_color_brim16.jpg",
                    ShowAxes        = true,
                    AxisScale       = 4f
                };
                ((MoonDEM)TheWorld.Moon).Load();
                TheWorld.FarShapes.Add(TheWorld.Moon);
            }
            else
            {
                TheWorld.Moon = new MoonHeightField
                {
                    Name            = "Moon",
                    Position        = new Vector3d(384400 * Kilometers, 0d, 0d),
                    TextureFilename = "moon_8k_color_brim16.jpg",
                    Radius          = (float)(1734.4 * Kilometers),
                    XSize           = 96,
                    YSize           = 48,
                    ShowAxes        = true,
                    AxisScale       = 4f
                };
                ((MoonHeightField)TheWorld.Moon).Load();
                ((MoonHeightField)TheWorld.Moon).LoadTexture();
                TheWorld.FarShapes.Add(TheWorld.Moon);
            }

            // earth_800x400.jpg
            // land_shallow_topo_2011_8192.jpg
            TheWorld.Earth = new TexturedBall
            {
                Name            = "Earth",
                Position        = new Vector3d(0d, 0d, 0d),
                TextureFilename = "earth_800x400.jpg",
                Radius          = (float)(6371 * Kilometers),
                XSize           = 48,
                YSize           = 24,
                ShowAxes        = true,
                AxisScale       = 10f,
                Specularity     = new float[] { 1f, 1f, 1f },
                Shininess       = 1f
            };
            TheWorld.Earth.Shader = glControl1.EarthShaderProgram;
            TheWorld.Earth.Load();
            TheWorld.Earth.LoadTexture();
            TheWorld.FarShapes.Add(TheWorld.Earth);

            // earth_800x400.jpg
            // land_shallow_topo_2011_8192.jpg
            TheWorld.Sun = new TexturedBall
            {
                Name            = "Sun",
                Position        = new Vector3d(0d, 0d, 0d),
                TextureFilename = "sun.png",
                Color           = Color.Yellow,
                Radius          = (float)(695500 * Kilometers),
                XSize           = 32,
                YSize           = 16,
                ShowAxes        = false,
                AxisScale       = 10f
            };
            TheWorld.Sun.Load();
            TheWorld.Sun.LoadTexture();

            TheWorld.Stars = new StarBackground();
            TheWorld.Stars.Load();
        }