Example #1
0
        public void SetCamWithBox(Vector3 min, Vector3 max)
        {
            GLCamera cam = CurrentViewport.Camera;

            //Get the position of the midpoint of the bounding box plane closer to the camera
            Vector3 frontMidPt = new Vector3((max._x + min._x) / 2.0f, (max._y + min._y) / 2.0f, max._z);
            float   tan = (float)Math.Tan(cam.VerticalFieldOfView / 2.0f * Maths._deg2radf), distX = 0, distY = 0;

            //The tangent value would only be 0 if the FOV was 0,
            //meaning nothing would be visible anyway
            if (tan != 0)
            {
                //Calculate lengths
                Vector3 extents     = max - min;
                Vector3 halfExtents = extents / 2.0f;
                if (halfExtents._y != 0.0f)
                {
                    float ratio = halfExtents._x / halfExtents._y;
                    distY = halfExtents._y / tan; //The camera's distance from the model's midpoint in respect to Y
                    distX = distY * ratio;
                }
            }

            cam.Reset();
            cam.Translate(frontMidPt._x, frontMidPt._y, Maths.Max(distX, distY, max._z) + 2.0f);
            Invalidate();
        }
Example #2
0
        // Button Handlers
        private void OnResetCameraButtonClick(object sender, EventArgs e)
        {
            camera.Reset();
            renderer.Reset();

            // Redraw.
            glControlMain.Invalidate();
        }
Example #3
0
        public void SetCamera(ModelPanelViewport v, float frame, bool retainAspect)
        {
            ViewportProjection proj = (ViewportProjection)(int)ProjectionType;

            if (v.ViewType != proj)
            {
                v.SetProjectionType(proj);
            }

            GLCamera             cam = v.Camera;
            CameraAnimationFrame f   = GetAnimFrame(frame);

            cam.Reset();
            cam.Translate(f.Pos);

            Vector3 rotate = f.GetRotation(Type);

            cam.Rotate(rotate);

            float aspect = retainAspect ? cam.Aspect : f.Aspect;

            cam.SetProjectionParams(aspect, f.FovY, f.FarZ, f.NearZ);
        }