/// <summary> /// Default constructor. /// </summary> public Camera(Scene scene) { _scene = scene; // set default positioning _position = new Vector(0.0, 0.0, 9.0); _upVec = new Vector(0.0, 1.0, 0.0); _center = new Vector(); // set default field of view fov = new Angle(); fov["deg"] = 28.0; // set default interaction factors dollyFactor = 0.15; panFactor = 0.05; lastDirection = ViewDirection.Front; Frustum = new FrustumDef(); DefaultAnimationOptions.Duration = 4.0; DefaultAnimationOptions.EaseType = EaseType.Quadratic; UseInertia = true; InertiaAnimationOptions = new AnimationOptions() { Duration = 6.0, EaseType = EaseType.Linear }; InertiaType = InteractionType.None; }
/// <summary> /// Configures the viewport based on its width and height. /// </summary> public virtual void Configure() { // initialize the projection matrix gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); // set the viewport var width = _scene.Width; var height = _scene.Height; if (height == 0) // prevent divide by zero height = 1; double ar = width / height; if (projection == Projection.Perspective) { // store the frustum Frustum = new FrustumDef(fov, 0.0001*Distance, 1000*Distance, ar); // set the perspective projection matrix glu.gluPerspective((float)fov["deg"], (float)Frustum.AR, (float)Frustum.NearDist, (float)Frustum.FarDist); } else // parallel { // determine the size of the viewing box double h = (fov*0.5).Tan() * Distance; gl.glOrtho(-ar*h, ar*h, -h, h, 0.001*Distance, 100*Distance); } // store the projection matrix for later setup gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, projectionMatrix); // store the viewport size //gl.glGetIntegerv(gl.GL_VIEWPORT, viewportSize); viewportSize = new int[] {0, 0, (int)width, (int)height}; }