Ejemplo n.º 1
0
 public SolarViewerView(OpenGLControlWrapper w, Shape center, float fov = 4f)
     : base(w, center)
 {
     Azimuth     = 157.657f;
     Elevation   = -0.109f;
     FieldOfView = fov;
 }
Ejemplo n.º 2
0
        public override void DragStart(OpenGLControlWrapper w, MouseEventArgs e)
        {
            _lastLocation  = e.Location;
            _startPosition = _eye - _lookat;
            var circleDistance = 0.4d * Math.Min(w.Width, w.Height);
            var dx             = e.X - w.Width / 2;
            var dy             = e.Y - w.Height / 2;
            var d = Math.Sqrt(dx * dx + dy * dy);

            if (d > circleDistance)
            {
                _dragging = DragState.RotatingUp;
            }
            else
            {
                switch (e.Button)
                {
                case MouseButtons.Left:
                    _dragging = DragState.ArcBalling;
                    break;

                case MouseButtons.Right:
                    _dragging = DragState.Scaling;
                    break;

                default:
                    _dragging = DragState.Idle;
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public override void PaintInternal(OpenGLControlWrapper w)
        {
            base.PaintInternal(w);

            GL.Disable(EnableCap.Lighting);

            GL.MatrixMode(MatrixMode.Modelview);  // This worked with the lookat in s/c frame
            GL.LoadIdentity();
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            var width       = w.Width;
            var height      = w.Height;
            var aspectRatio = width / (float)height;

            GL.Ortho(-aspectRatio, aspectRatio, -1.0, 1.0, 0.0, 4.0);
            GL.Viewport(0, 0, width, height);

            const double solarViewerFOVRadius = 0.5d;
            var          radius    = solarViewerFOVRadius * (2f / FieldOfView);
            const int    numPoints = 32;
            const double frac      = (2d * Math.PI) / numPoints;

            GL.Color3(Color.Yellow);
            GL.Begin(BeginMode.LineStrip);
            for (var i = 0; i <= numPoints; i++)
            {
                var px = radius * Math.Cos(i * frac);
                var py = radius * Math.Sin(i * frac);
                GL.Vertex2(px, py);
            }
            GL.End();

            GL.Enable(EnableCap.Lighting);
        }
Ejemplo n.º 4
0
 public TelescopeView(OpenGLControlWrapper w, Shape center, float fov = 4f)
     : base(w, center)
 {
     Azimuth     = 170.1f;
     Elevation   = 0f;
     FieldOfView = fov;
 }
Ejemplo n.º 5
0
        private void MainView_Load(object sender, EventArgs e)
        {
            Console.WriteLine(@"in load");
            Toolkit.Init();

            OpenGLWindow = new OpenGLControlWrapper {
                Dock = DockStyle.Fill
            };
            tabMap.Controls.Add(OpenGLWindow);
            OpenGLWindow.Loaded = true;

            GL.ClearColor(Color.Black);

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

            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)

            OpenGLWindow.CameraMode = new ArcBall(OpenGLWindow, OpenGLWindow.TheWorld.ViewTarget)
            {
                RelativePosition = new Vector3d(0d, 10000 * Kilometers, 0d)
            };
            //OGLDelegate.CameraMode = new JoystickCamera(OGLDelegate, OGLDelegate.TheWorld.ViewTarget) { Eye = new Vector3d(10f, 10f, 10f)};

            OpenGLWindow.TheWorld.Tick();
        }
Ejemplo n.º 6
0
        public JoystickCamera(OpenGLControlWrapper w, Shape t)
            : base(w, t)
        {
            Wrapper = w;

            //_eye = new Vector3d(10d, 10d, 5d);
            // _lookat = new Vector3d(0.0d, 0.0d, 0.0d);
        }
Ejemplo n.º 7
0
 internal void PaintScene(OpenGLControlWrapper w, Vector3d eye)
 {
     MakeCurrent();
     for (var i = 0; i < w.TheWorld.FarShapes.Count; i++)
     {
         w.TheWorld.FarShapes[i].Draw(false, eye);  // modified
     }
 }
Ejemplo n.º 8
0
        public virtual void PaintInternal(OpenGLControlWrapper w)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            //w.SetupViewport(FieldOfView, 1000f, 2000000f);
            //w.DrawStars();
            w.SetupViewport(FieldOfView, 0.001f, 800f);

            //w.SetupViewport(FieldOfView, 0.001f, 1000f);
            w.PaintScene(w, Eye);
        }
Ejemplo n.º 9
0
        private int _state;  // 1 means relaxing lookat, 2 means relaxing eye, 0 means idle

        public ZoomTo(OpenGLControlWrapper w, Shape t, double distanceFrom, double threshold, Camera next)
            : base(w, t)
        {
            Wrapper       = w;
            _eye          = w.CameraMode.Eye;
            _lookat       = w.CameraMode.Lookat;
            Target        = t;
            Next          = next;
            ZoomThreshold = threshold;

            _eye2 = (t.Position - _eye);
            _eye2.NormalizeFast();
            _eye2 = _eye2 * -distanceFrom + t.Position;

            _state = 1;
        }
Ejemplo n.º 10
0
        public virtual void Paint(OpenGLControlWrapper w)
        {
            var eye    = new Vector3(0f, 0f, 0f);
            var target = (Lookat - Eye).ToNear();
            var up     = new Vector3(Up.ToFloat());

            ViewMatrix = Matrix4.LookAt(eye, target, up);

            //todo
            //Console.WriteLine(ViewMatrix);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref ViewMatrix);

            PaintInternal(w);

            w.SwapBuffers();
        }
Ejemplo n.º 11
0
        public override void Paint(OpenGLControlWrapper w)
        {
            var e      = MathHelper.DegreesToRadians(Elevation);
            var a      = MathHelper.DegreesToRadians(Azimuth);
            var z      = (float)Math.Sin(e);
            var d      = Math.Cos(e);
            var x      = (float)(Math.Cos(a) * d);
            var y      = (float)(Math.Sin(a) * d);
            var target = new Vector3(x, y, z);

            var eye = new Vector3(0f, 0f, 0f);
            var up  = new Vector3(0f, 0f, 1f);

            ViewMatrix = Matrix4.LookAt(eye, target, up);

            GL.MatrixMode(MatrixMode.Modelview);  // This worked with the lookat in s/c frame
            GL.LoadMatrix(ref ViewMatrix);
            Satellite.Attitude.ToAxisAngle(out Vector3 axis, out float angle);
            GL.Rotate(angle * 180.0f / 3.141593f, axis);

            PaintInternal(w);

            w.SwapBuffers();
        }
Ejemplo n.º 12
0
 public virtual void DragStop(OpenGLControlWrapper w, MouseEventArgs e)
 {
 }
Ejemplo n.º 13
0
 public ArcBall(OpenGLControlWrapper w, Shape t)
     : base(w, t)
 {
     _lookat = new Vector3d(0d, 0d, 0d);
     _eye    = new Vector3d(10d, 0d, 0d);
 }
Ejemplo n.º 14
0
        public override void Drag(OpenGLControlWrapper w, MouseEventArgs e)
        {
            if (_dragging == DragState.Idle)
            {
                return;
            }
            Lookat = Target.Position;
            switch (_dragging)
            {
            case DragState.ArcBalling:     // moving
            {
                var relativePosition = _eye - _lookat;
                var lookToward       = new Vector3d(-relativePosition);
                lookToward.Normalize();
                var right       = Vector3d.Cross(lookToward, Up);
                var yaw         = YawGain * (e.Location.X - _lastLocation.X);
                var yawMatrix   = Matrix4d.CreateFromAxisAngle(Up, yaw);
                var pitch       = PitchGain * (e.Location.Y - _lastLocation.Y);
                var pitchMatrix = Matrix4d.CreateFromAxisAngle(right, pitch);
                var distance    = relativePosition.Length;
                relativePosition = Vector3d.TransformVector(relativePosition, yawMatrix * pitchMatrix);
                relativePosition.Normalize();
                relativePosition = relativePosition * distance;

                _eye = _lookat + relativePosition;
                relativePosition.Normalize();
                Up = Vector3d.Cross(relativePosition, right);
                Up.Normalize();
                _lastLocation = e.Location;
            }
            break;

            case DragState.Scaling:     // scaling
            {
                var d    = ZoomGain * (e.Location.Y - _lastLocation.Y);
                var zoom = Math.Exp(d);
                var rp   = _startPosition * (ZoomFactor * zoom);
                _eye = _lookat + rp;
            }
            break;

            case DragState.RotatingUp:
            {
                var centerX = w.Width / 2;
                var centerY = w.Height / 2;
                var v1      = new Vector3d(_lastLocation.X - centerX, _lastLocation.Y - centerY, 0d);
                var v2      = new Vector3d(e.Location.X - centerX, e.Location.Y - centerY, 0d);
                var v3      = Vector3d.Cross(v1, v2);
                var v3Mag   = v3[2];
                var angDeg  = Math.Asin(v3Mag / (v1.Length * v2.Length));         //*180d/Math.PI
                var axis    = _lookat - _eye;
                axis.Normalize();
                var mat = Matrix4d.CreateFromAxisAngle(axis, -angDeg);
                Up = Vector3d.TransformVector(Up, mat); // was _startUp
                Up.Normalize();
                _lastLocation = e.Location;             // not sure about this
            }
            break;
            }
            Dirty = true;
            w.Invalidate();
        }
Ejemplo n.º 15
0
 public Camera(OpenGLControlWrapper w, Shape t)
 {
     Wrapper = w;
     Target  = t;
 }
Ejemplo n.º 16
0
 public override void DragStop(OpenGLControlWrapper w, MouseEventArgs e)
 {
     _dragging = DragState.Idle;
 }
Ejemplo n.º 17
0
 public InstrumentView(OpenGLControlWrapper w, Shape t)
     : base(w, t)
 {
     Satellite = t;
 }
Ejemplo n.º 18
0
        private void NearFieldVisualization_Load(object sender, EventArgs e)
        {
            Toolkit.Init();
            OpenGLWindow = new OpenGLControlWrapper {
                Dock = DockStyle.Fill
            };

            OpenGLWindow.MouseDown += OnMouseDownHandler;
            OpenGLWindow.MouseMove += OnMouseMoveHandler;
            OpenGLWindow.MouseUp   += OnMouseUpHandler;
            OpenGLWindow.Paint     += ogl_Paint;

            Controls.Add(OpenGLWindow);
            OpenGLWindow.Loaded = true;

            LoadObjects();

            var world = OpenGLWindow.TheWorld;

            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, new Vector4(world.Sun.Position.ToFloat(), 1f));

            const float ambient = 0.4f;
            const float diffuse = 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[] { diffuse, diffuse, diffuse, 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);

            //world.Fetcher.Frame = LadeeStateFetcher.StateFrame.MoonFixed;

            //var t = TimeUtilities.DateTimeToTime42(new DateTime(2014, 1, 1));
            //UpdateToTime(t);

            OpenGLWindow.CameraMode = new ArcBall(OpenGLWindow, OpenGLWindow.TheWorld.ViewTarget)
            {
                RelativePosition = new Vector3d(0d, 10000 * Kilometers, 0d)
            };
            //OGLDelegate.CameraMode = new JoystickCamera(OGLDelegate, OGLDelegate.TheWorld.ViewTarget) { Eye = new Vector3d(10f, 10f, 10f)};

            OpenGLWindow.TheWorld.Tick();
        }