- private void glControl1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- if (drawing == true)
- {
- // Compute current mouse position.
- mouse_current.X = glControl1.PointToClient(MousePosition).X;
- mouse_current.Y = glControl1.PointToClient(MousePosition).Y;
- // Compute moving distance depending on mouse speed.
- float dx = mouse_current.X - mouse_previous.X;
- dx *= mouse_speed;
- float dy = mouse_current.Y - mouse_previous.Y;
- dy *= mouse_speed;
- // Get angle in rad.
- this.theta += dx * Math.PI / 180.0;
- this.phi += dy * Math.PI / 180.0;
- // Set borders from 0 to 360°.
- if (this.theta > 2 * Math.PI)
- this.theta -= 2 * Math.PI;
- if (this.theta < 0)
- this.theta += 2 * Math.PI;
- // Set borders from 90 to -90°
- if (this.phi > Math.PI/2)
- this.phi = Math.PI/2;
- if (this.phi < -Math.PI/2)
- this.phi = -Math.PI/2;
- // Angle output.
- ThetaOutput.Text = "Theta: " + this.theta;
- PhiOutput.Text = "Phi: " + this.phi;
- // Compute position vector.
- Vector3d forward = new Vector3d(Math.Sin(this.theta) * Math.Cos(this.phi),
- -Math.Sin(this.phi),
- Math.Cos(this.theta) * Math.Cos(this.phi)
- );
- // Switch do model matrix.
- GL.MatrixMode(MatrixMode.Modelview);
- GL.LoadIdentity();
- // Compute new modelview matrix.
- Matrix4d modelview = Matrix4d.LookAt(Vector3d.Zero + forward * 0.1, Vector3d.Zero, Vector3d.UnitY);
- // Set new modelview matrix.
- GL.LoadMatrix(ref modelview);
- // Update mouse position.
- mouse_previous.X = mouse_current.X;
- mouse_previous.Y = mouse_current.Y;
- }
- }