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();
        }
        public ctl3DView()
        {
            InitializeComponent();
            //Visible = false;
            //SetupSceneTree();
            m_modelAnimTmr = null;
            m_camera       = new GLCamera();
            m_axisCam      = new GLCamera();
            ResetCameraView();
            m_isectnormal = new Engine3D.Vector3d();

            mainViewSplitContainer.Panel1Collapsed = true;

            UVDLPApp.Instance().m_undoer.AsociateUndoButton(buttUndo);
            UVDLPApp.Instance().m_undoer.AsociateRedoButton(buttRedo);

            //glControl1. = new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, 8);
            gr2d                    = UVDLPApp.Instance().m_2d_graphics;
            ctlBgndList             = new List <ctlBgnd>();
            guiconf                 = UVDLPApp.Instance().m_gui_config; // set from the main program GUIConfig
            guiconf.TopLevelControl = mainViewSplitContainer.Panel2;
            UpdateButtonList();
            RearrangeGui(); // once the GUIConfig is loaded from the plugins and from the main GUIConfig, the screen is re-arranged

            // toplevel controls must point to this

            glControl1.PaintCallback += new ctlGL.delPaint(DisplayFunc);

            m_sliceTex = -1;
            RegisterCallbacks();

            UVDLPApp.Instance().m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
            UVDLPApp.Instance().AppEvent += new AppEventDelegate(AppEventDel);
        }
        public FullScreenWindow(ref GLRenderer renderer, ref GLCamera camera,
                                ref AnimationController animationController,
                                ref GLControl control,
                                float fieldOfView, float nearPlane, float farPlane)
        {
            // Store references
            this.renderer            = renderer;
            this.camera              = camera;
            this.animationController = animationController;
            this.fieldOfView         = fieldOfView;
            this.nearPlane           = nearPlane;
            this.farPlane            = farPlane;
            this.mainGLControl       = control;

            InitializeComponent();

            //
            // Set up callbacks.
            //

            // GLControl Callbacks
            glControlMain.Load   += new EventHandler(GLControlMainOnLoad);
            glControlMain.Resize += new EventHandler(GLControlMainOnResize);
            glControlMain.Paint  += new PaintEventHandler(GLControlMainOnPaint);

            // Set mouse events
            glControlMain.MouseDown  += new MouseEventHandler(GLControlOnMouseDown);
            glControlMain.MouseUp    += new MouseEventHandler(GLControlOnMouseUp);
            glControlMain.MouseWheel += new MouseEventHandler(GLControlOnMouseWheel);
            glControlMain.MouseMove  += new MouseEventHandler(GLControlOnMouseMove);

            // Set keyboard events
            glControlMain.KeyDown += new KeyEventHandler(GLControlMainOnKeyDown);
            glControlMain.KeyUp   += new KeyEventHandler(GLControlMainOnKeyUp);
        }
        private void SetupEditorCamera()
        {
            m_pivot.transform.position = Vector3.zero;
            m_prevPivotPosition        = Vector3.zero;

            //Vector3 position = m_editorCamera.transform.position;
            //position.y = 0;
            //m_pivot.transform.position = position;

            m_gameView.IsOn = false;

            GLCamera glCamera = m_editorCamera.GetComponent <GLCamera>();

            glCamera.CullingMask = (int)RTLayer.SceneView;

            Component[] components = m_editorCamera.GetComponents <Component>();
            for (int i = 0; i < components.Length; ++i)
            {
                Component component = components[i];
                if (!(component is Camera || component is MouseOrbit || component is Transform || component is GLCamera))
                {
                    Destroy(component);
                }
            }

            m_gridRenderer.Target = m_pivot.transform;
            OnTopView();
        }
Example #5
0
        public static Matrix ProjectionMapping(
            int ref_camera,
            SCN0Node node,
            ModelPanelViewport v,
            float frame)
        {
            Matrix   projMtx = Matrix.Identity;
            Matrix   camMtx  = Matrix.Identity;
            GLCamera cam     = v.Camera;

            if (ref_camera >= 0 && node?.CameraGroup != null && ref_camera < node.CameraGroup.Children.Count)
            {
                // Set so that the image is projected from the specified camera.
                // Transform to the viewing coordinate system of the specified camera
                SCN0CameraNode camNode = (SCN0CameraNode)node.CameraGroup.Children[ref_camera];
                camNode.GetModelViewMatrix(frame, out Matrix cm, out Matrix cmInv);
                camMtx  = cm * cam._matrix;
                projMtx = (Matrix)ProjectionTexMtx(camNode, frame);
            }
            else
            {
                camMtx  = cam._matrix;
                projMtx = (Matrix)ProjectionTexMtx(cam);
            }

            return(projMtx * camMtx);
        }
Example #6
0
        public ctl3DView()
        {
            InitializeComponent();
            //Visible = false;
            //SetupSceneTree();
            m_modelAnimTmr = null;
            m_camera       = new GLCamera();
            m_axisCam      = new GLCamera();
            ResetCameraView();
            m_isectnormal = new Engine3D.Vector3d();

            mainViewSplitContainer.Panel1Collapsed = true;

            UVDLPApp.Instance().m_undoer.AsociateUndoButton(buttUndo);
            UVDLPApp.Instance().m_undoer.AsociateRedoButton(buttRedo);

            //glControl1. = new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, 8);
            gr2d                    = UVDLPApp.Instance().m_2d_graphics;
            ctlBgndList             = new List <ctlBgnd>();
            guiconf                 = UVDLPApp.Instance().m_gui_config;
            guiconf.TopLevelControl = mainViewSplitContainer.Panel2;
            UpdateButtonList();
            //guiconf.LoadConfiguration(global::UV_DLP_3D_Printer.Properties.Resources.GuiConfig);
            RearrangeGui();

            // toplevel controls must point to this

            glControl1.PaintCallback += new ctlGL.delPaint(DisplayFunc);

            m_sliceTex = -1;
            RegisterCallbacks();

            UVDLPApp.Instance().m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
            UVDLPApp.Instance().AppEvent += new AppEventDelegate(AppEventDel);
        }
        public FullScreenWindow(ref GLRenderer renderer, ref GLCamera camera,
            ref AnimationController animationController,
            ref GLControl control,
            float fieldOfView, float nearPlane, float farPlane)
        {
            // Store references
            this.renderer = renderer;
            this.camera = camera;
            this.animationController = animationController;
            this.fieldOfView = fieldOfView;
            this.nearPlane = nearPlane;
            this.farPlane = farPlane;
            this.mainGLControl = control;

            InitializeComponent();

            //
            // Set up callbacks.
            //

            // GLControl Callbacks
            glControlMain.Load += new EventHandler(GLControlMainOnLoad);
            glControlMain.Resize += new EventHandler(GLControlMainOnResize);
            glControlMain.Paint += new PaintEventHandler(GLControlMainOnPaint);

            // Set mouse events
            glControlMain.MouseDown += new MouseEventHandler(GLControlOnMouseDown);
            glControlMain.MouseUp += new MouseEventHandler(GLControlOnMouseUp);
            glControlMain.MouseWheel += new MouseEventHandler(GLControlOnMouseWheel);
            glControlMain.MouseMove += new MouseEventHandler(GLControlOnMouseMove);

            // Set keyboard events
            glControlMain.KeyDown += new KeyEventHandler(GLControlMainOnKeyDown);
            glControlMain.KeyUp += new KeyEventHandler(GLControlMainOnKeyUp);
        }
 public static void InitProjection(GLCamera cur, GLCamera prev, double t, Size viewportSize)
 {
     Gl.glMatrixMode(Gl.GL_PROJECTION);
     Gl.glLoadIdentity();
     cur.ApplyProjection(prev, t);
     Gl.glMatrixMode(Gl.GL_MODELVIEW);
     Gl.glLoadIdentity();
 }
Example #9
0
        public ModelPanel()
        {
            _camera = new GLCamera();

            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ModelPanel_MouseDown);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ModelPanel_MouseMove);
            this.MouseUp   += new System.Windows.Forms.MouseEventHandler(this.ModelPanel_MouseUp);
        }
        public ModelPanelViewport()
        {
            _text         = new ScreenTextHandler(this);
            _camera       = new GLCamera();
            LightPosition = new Vector4(100.0f, 45.0f, 45.0f, 1.0f);

#if DEBUG
            _textEnabled = true;
#endif
        }
Example #11
0
        private void Awake()
        {
            GameObject pivot = new GameObject();

            pivot.name = "ViewportPivot";

            GameObject camera = new GameObject();

            camera.transform.SetParent(pivot.transform, true);
            m_camera                 = camera.AddComponent <Camera>();
            m_camera.fieldOfView     = 50;
            m_camera.clearFlags      = CameraClearFlags.SolidColor;
            m_camera.backgroundColor = new Color32(0x4F, 0xC6, 0xFF, 0x00);

            GLCamera glCam = camera.AddComponent <GLCamera>();

            glCam.CullingMask = (int)RTLayer.GameView;

            GridRenderer gridRenderer = GetComponentInChildren <GridRenderer>(true);

            if (gridRenderer != null)
            {
                gridRenderer.Target      = pivot.transform;
                gridRenderer.CullingMask = glCam.CullingMask;
            }

            if (m_postrocessingProfile != null)
            {
                PostProcessingBehaviour postprocessing = camera.AddComponent <PostProcessingBehaviour>();
                postprocessing.profile = m_postrocessingProfile;

                m_camera.allowMSAA = false;
            }

            camera.AddComponent <CameraFogOfWar>();

            m_viewport = GetComponent <RectTransform>();

            Canvas canvas = m_viewport.GetComponentInParent <Canvas>();

            if (canvas == null)
            {
                gameObject.SetActive(false);
                return;
            }

            if (canvas.renderMode != RenderMode.ScreenSpaceCamera && canvas.renderMode != RenderMode.ScreenSpaceOverlay)
            {
                gameObject.SetActive(false);
                Debug.LogWarning("ViewportFitter requires canvas.renderMode -> RenderMode.ScreenSpaceOverlay or RenderMode.ScreenSpaceCamera");
                return;
            }

            m_camera.pixelRect = new Rect(new Vector2(0, 0), new Vector2(Screen.width, Screen.height));
        }
 public static float CamDistance(Vector3 v, GLCamera cam, float radius = _orbRadius)
 {
     if (!cam.Orthographic)
     {
         return(v.TrueDistance(cam.GetPoint()) / radius * (cam.VerticalFieldOfView / 45.0f) * 0.1f);
     }
     else
     {
         return(cam._scale._x * 80.0f);
     }
 }
Example #13
0
 private void DisableRuntimeEditing()
 {
     if (Camera != null)
     {
         GLCamera glCamera = Camera.GetComponent <GLCamera>();
         if (glCamera != null)
         {
             DestroyImmediate(glCamera);
         }
     }
 }
 public static void Enable()
 {
     Camera[] cameras = SceneView.GetAllSceneCameras();
     for (int i = 0; i < cameras.Length; ++i)
     {
         Camera   camera   = cameras[i];
         GLCamera glCamera = camera.GetComponent <GLCamera>();
         if (glCamera == null)
         {
             camera.gameObject.AddComponent <GLCamera>();
         }
     }
 }
Example #15
0
        public static Matrix EnvCamMap(int refCam, SCN0Node node, ModelPanelViewport v, float frame)
        {
            GLCamera cam = v.Camera;

            if (refCam >= 0 && node?.CameraGroup != null && refCam < node.CameraGroup.Children.Count)
            {
                SCN0CameraNode camNode = (SCN0CameraNode)node.CameraGroup.Children[refCam];
                camNode.GetModelViewMatrix(frame, out Matrix cm, out Matrix cmInv);
                return((Matrix)EnvironmentTexMtx() * cm.GetRotationMatrix());
            }

            return((Matrix)EnvironmentTexMtx() * v.Camera._matrix.GetRotationMatrix());
        }
Example #16
0
 private void DisableRuntimeEditing()
 {
     Camera[] allCameras = Camera.allCameras;
     for (int i = 0; i < allCameras.Length; ++i)
     {
         Camera   camera        = allCameras[i];
         GLCamera glLinesCamera = camera.GetComponent <GLCamera>();
         if (glLinesCamera != null)
         {
             DestroyImmediate(glLinesCamera);
         }
     }
 }
 public static void Disable()
 {
     Camera[] cameras = SceneView.GetAllSceneCameras();
     for (int i = 0; i < cameras.Length; ++i)
     {
         Camera   camera   = cameras[i];
         GLCamera glCamera = camera.GetComponent <GLCamera>();
         if (glCamera != null)
         {
             Object.DestroyImmediate(glCamera);
         }
     }
 }
        public static void DrawStringMultiLine(string str, Color color, PointF loc, GLCamera cam)
        {
            //split the string by newlines
            string[] strings = str.Split('\n');
            float    ypos    = loc.Y;

            foreach (string s in strings)
            {
                SetGLColor(color);
                Gl.glRasterPos3f(loc.X, ypos, .1f);
                glPrint(s);
                ypos -= (MeasureString(s, GLUtility.defFault).Height / 1.8f) / cam.scale;
            }
        }
Example #19
0
        private static Matrix34 ProjectionTexMtx(GLCamera c)
        {
            if (c.Orthographic)
            {
                return(LightMtxOrtho(
                           c._orthoDimensions[2],
                           c._orthoDimensions[3],
                           c._orthoDimensions[0],
                           c._orthoDimensions[1],
                           0.5f, -0.5f, 0.5f, 0.5f));
            }

            return(LightMtxPersp(
                       c._fovY, 1.0f,
                       0.5f, -0.5f, 0.5f, 0.5f));
        }
        public ctl3DView()
        {
            InitializeComponent();

            SetupSceneTree();
            m_modelAnimTmr = null;
            m_camera       = new GLCamera();
            ResetCameraView();

            ctlViewOptions.TreeViewHolder          = mainViewSplitContainer;
            ctlViewOptions.LayerNumberScroll       = numLayer;
            ctlViewOptions.ObjectInfoPanel         = objectInfoPanel;
            mainViewSplitContainer.Panel1Collapsed = true;

            UVDLPApp.Instance().m_undoer.AsociateUndoButton(buttUndo);
            UVDLPApp.Instance().m_undoer.AsociateRedoButton(buttRedo);
        }
Example #21
0
        private unsafe void btnExport_Click(object sender, EventArgs e)
        {
            //TODO: get this working

            int height = 512; //temporary - need to calculate width
            int width  = 512; //temporary - need to calculate height

            uint bufferHandle;
            uint colorTex;

            texCoordRenderer1.Capture();

            GL.GenTextures(1, out colorTex);
            GL.BindTexture(TextureTarget.Texture2D, colorTex);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, height, width, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);

            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.Ext.GenFramebuffers(1, out bufferHandle);
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, bufferHandle);
            GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, colorTex, 0);

            GL.DrawBuffer((DrawBufferMode)FramebufferAttachment.ColorAttachment0Ext);

            GL.PushAttrib(AttribMask.ViewportBit);
            GL.Viewport(0, 0, height, width);

            //TODO: Make a copy of the renderer camera here, but with no transformations
            GLCamera cam = new GLCamera()
            {
                _projectionMatrix  = texCoordRenderer1.CurrentViewport.Camera._projectionMatrix,
                _projectionInverse = texCoordRenderer1.CurrentViewport.Camera._projectionInverse,
                _matrix            = Matrix.Identity,
                _matrixInverse     = Matrix.Identity,
            };

            texCoordRenderer1.Render(cam, false);

            GL.PopAttrib();
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
            GL.DrawBuffer(DrawBufferMode.Back);
        }
Example #22
0
        //Slice m_curslice = null; // for previewing only

        //float ipx = 0.0f, ipy = 0.0f, ipz = 2.0f;
        public frmMain()
        {
            // following 2 lines removed from designer - SHS to eliminate autoscale
            //this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            //this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

            InitializeComponent();
            UVDLPApp.Instance().AppEvent += new AppEventDelegate(AppEventDel);
            UVDLPApp.Instance().Engine3D.UpdateGrid();
            //UVDLPApp.Instance().Engine3D.AddPlatCube();
            UVDLPApp.Instance().m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
            UVDLPApp.Instance().m_buildmgr.BuildStatus += new delBuildStatus(BuildStatus);
            UVDLPApp.Instance().m_buildmgr.PrintLayer += new delPrinterLayer(PrintLayer);
            DebugLogger.Instance().LoggerStatusEvent += new LoggerStatusHandler(LoggerStatusEvent);
            UVDLPApp.Instance().m_deviceinterface.StatusEvent += new DeviceInterface.DeviceInterfaceStatus(DeviceStatusEvent);
            UVDLPApp.Instance().m_supportgenerator.SupportEvent += new SupportGeneratorEvent(SupEvent);

            ctl3DView1.SetMessagePanelHolder(splitContainerMainWindow);
            ctl3DView1.Dock = DockStyle.Fill;
            ctl3DView1.Enable3dView(true);
            tabMain.Dock    = DockStyle.Fill;
            tabMain.Visible = false;

            m_frmdlp.HideDLPScreen();
            ctlSliceView1.Visible = false;
            ctlSliceView1.Dock    = DockStyle.Fill;
            ctlSliceView1.DlpForm = m_frmdlp;

            ctlGcodeView1.Visible = false;
            ctlGcodeView1.Dock    = DockStyle.Fill;

            //arcball = new ArcBall();
            m_camera = new GLCamera();
            ResetCameraView();

            lblTime.Text        = "";
            lblMainMessage.Text = "";

            SetButtonStatuses();
            //PopulateBuildProfilesMenu();

            Refresh();
        }
 public void ApplyProjection(GLCamera prevProj, double t)
 {
     if (t <= 0.0)
     {
         prevProj.ApplyProjection();
     }
     else if (t >= 1.0)
     {
         this.ApplyProjection();
         AdjustEffects();
     }
     else
     {
         double[] p = prevProj.GetProjMatrix();
         double[] c = this.GetProjMatrix();
         for (uint i = 0; i < 16; i++)
         {
             c[i] = c[i] * t + p[i] * (1.0 - t);
         }
         Gl.glMultMatrixd(c);
         AdjustEffects();
     }
 }
Example #24
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);
        }
 public static void InitScene(GLCamera cur, GLCamera prev, double t, Size viewportSize)
 {
     Gl.glViewport(0, 0, viewportSize.Width, viewportSize.Height);
     Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
     InitProjection(cur, prev, t, viewportSize);
 }
Example #26
0
 public void ApplyProjection(GLCamera prevProj, double t)
 {
     if (t <= 0.0) prevProj.ApplyProjection();
     else if (t >= 1.0)
     {
       this.ApplyProjection();
       AdjustEffects();
     }
     else
     {
       double[] p = prevProj.GetProjMatrix();
       double[] c = this.GetProjMatrix();
       for (uint i = 0; i < 16; i++)
     c[i] = c[i] * t + p[i] * (1.0 - t);
       Gl.glMultMatrixd(c);
         AdjustEffects();
     }
 }
Example #27
0
        /// <summary>
        /// This function returns a texture matrix
        /// that will aim the texture to the midpoint between the active camera
        /// and the given reference camera or light.
        /// </summary>
        public static Matrix EnvSpecMap(
            int refCam,
            int refLight,
            SCN0Node node,
            ModelPanelViewport v,
            float frame)
        {
            // Normal environmental map when neither the light nor the camera is specified.
            Matrix34 finalMtx = EnvironmentTexMtx();

            GLCamera cam = v.Camera;
            Vector3  vLook, camUp, camLook;
            Matrix   camMtx    = cam._matrixInverse;
            Matrix   invCamMtx = cam._matrix;

            Matrix34 m34 = (Matrix34)camMtx;

            camLook._x = -m34[8];
            camLook._y = -m34[9];
            camLook._z = -m34[10];

            if (refLight >= 0)
            {
                Vector3 lgtLook = GetLightLook(node, refLight, invCamMtx, v, frame, out bool specEnabled);

                // Specular light is already set as a vector taking the center position.
                if (!specEnabled)
                {
                    vLook = GetHalfAngle(camLook, lgtLook);
                }
                else
                {
                    vLook = -lgtLook;
                }

                if (Math.Abs(vLook._x) < 0.000001f &&
                    Math.Abs(vLook._z) < 0.000001f)
                {
                    camUp._x = camUp._y = 0.0f;
                    if (vLook._y <= 0.0f)
                    {
                        // Look straight down
                        camUp._z = -1.0f;
                    }
                    else
                    {
                        // Look straight up
                        camUp._z = 1.0f;
                    }
                }
                else
                {
                    camUp._x = camUp._z = 0.0f;
                    camUp._y = 1.0f;
                }
            }
            else if (refCam >= 0)
            {
                SCN0CameraNode camNode = null;

                if (node?.CameraGroup != null && refCam < node.CameraGroup.Children.Count)
                {
                    camNode = (SCN0CameraNode)node.CameraGroup.Children[refCam];
                }
                else
                {
                    camNode = new SCN0CameraNode();
                }

                camNode.GetModelViewMatrix(frame, out Matrix cM, out Matrix cMInv);

                // Map from the midpoint of the view camera and the specified camera.
                Matrix34 lgtCam = (Matrix34)cM;
                camUp._x = lgtCam[4];
                camUp._y = lgtCam[5];
                camUp._z = lgtCam[6];
                Vector3 lgtLook = new Vector3(-lgtCam[8], -lgtCam[9], -lgtCam[10]);

                vLook = GetHalfAngle(camLook, lgtLook);
            }
            else
            {
                return((Matrix)finalMtx);
            }

            vLook.Normalize();
            Vector3 vRight, vUp;

            vUp = (vRight = vLook.Cross(camUp).Normalize()).Cross(vLook);
            m34 = new Matrix34(
                vRight._x, vRight._y, vRight._z, 0.0f,
                vUp._x, vUp._y, vUp._z, 0.0f,
                vLook._x, vLook._y, vLook._z, 0.0f);

            m34     = (Matrix34)((Matrix)m34 * invCamMtx);
            m34[3]  = 0.0f;
            m34[7]  = 0.0f;
            m34[11] = 0.0f;

            return((Matrix)(finalMtx * m34));
        }
Example #28
0
 public static void DrawStringMultiLine(string str, Color color, PointF loc, GLCamera cam)
 {
     //split the string by newlines
     string[] strings = str.Split('\n');
     float ypos = loc.Y;
     foreach (string s in strings)
     {
         SetGLColor(color);
         Gl.glRasterPos3f(loc.X, ypos,.1f);
         glPrint(s);
         ypos -= (MeasureString(s, GLUtility.defFault).Height) / cam.scale;
     }
 }
Example #29
0
        public static Matrix EnvLightMap(int refLight, SCN0Node node, ModelPanelViewport v, float frame)
        {
            Matrix   m         = Matrix.Identity;
            GLCamera cam       = v.Camera;
            Matrix   camMtx    = cam._matrix;
            Matrix   invCamMtx = cam._matrixInverse;

            Matrix34 envMtx = new Matrix34(
                0.5f, 0.0f, 0.0f, 0.5f,
                0.0f, -0.5f, 0.0f, 0.5f,
                0.0f, 0.0f, 0.0f, 1.0f);

            //If no light is referenced, use the BrawlCrate built-in light
            if (refLight < 0 || node?.LightGroup != null && refLight >= node.LightGroup.Children.Count)
            {
                refLight = 0;
                node     = null;
            }

            // The light position and direction needs to be transformed with the camera's inverse matrix.
            Vector3 vLook, camUp, vRight, vUp;

            vLook = GetLightLook(node, refLight, invCamMtx, v, frame, out bool specEnabled).Normalize();

            // Calculate without using a target because the margin of error for calculations must be taken into account when the light is far away.
            // Take the absolute value as a measure against transformation margin.
            if (Math.Abs(vLook._x) < 0.000001f &&
                Math.Abs(vLook._z) < 0.000001f)
            {
                camUp._x = camUp._y = 0.0f;
                if (vLook._y <= 0.0f)
                {
                    // Look straight down
                    camUp._z = -1.0f;
                }
                else
                {
                    // Look straight up
                    camUp._z = 1.0f;
                }
            }
            else
            {
                camUp._x = camUp._z = 0.0f;
                camUp._y = 1.0f;
            }

            vUp = (vRight = vLook.Cross(camUp).Normalize()).Cross(vLook);

            Matrix34 m34 = new Matrix34(
                vRight._x, vRight._y, vRight._z, 0.0f,
                vUp._x, vUp._y, vUp._z, 0.0f,
                -vLook._x, -vLook._y, -vLook._z, 0.0f);

            m34 = (Matrix34)((Matrix)m34 * invCamMtx);

            m34[3]  = 0.0f;
            m34[7]  = 0.0f;
            m34[11] = 0.0f;

            return((Matrix)(envMtx * m34));

            //return (Matrix)envMtx * Matrix.RotationMatrix(new Vector3().LookatAngles((Vector3)v._posLight) * Maths._rad2degf);
        }
Example #30
0
 public static void InitProjection(GLCamera cur, GLCamera prev, double t, Size viewportSize)
 {
     Gl.glMatrixMode(Gl.GL_PROJECTION);
       Gl.glLoadIdentity();
       cur.ApplyProjection(prev, t);
       Gl.glMatrixMode(Gl.GL_MODELVIEW);
       Gl.glLoadIdentity();
 }
Example #31
0
 public static void InitScene(GLCamera cur, GLCamera prev, double t, Size viewportSize)
 {
     Gl.glViewport(0, 0, viewportSize.Width, viewportSize.Height);
       Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
       InitProjection(cur, prev, t, viewportSize);
 }
Example #32
0
        public MainWindow()
        {
            logger = new Logger(DEFAULT_LOG_FILE); // Not checking result.
            logger.Event("Program Start.");

            isGLLoaded = false;
            timer      = new Stopwatch();

            camera = new GLCamera();
            camera.SetViewParameters(new Vector3(0.0f, 0.0f, 2.0f), Vector3.Zero);
            renderer = new GLRenderer();

            // Set up the reader and initialize its root to the value in 'lolviewer.dat' if
            // the file exists.
            {
                reader = new LOLDirectoryReader();

                bool       isFileOpen = false;
                FileStream file       = null;
                try
                {
                    FileInfo fileInfo = new FileInfo(DEFAULT_DATA_FILE);
                    if (fileInfo.Exists == true)
                    {
                        file       = new FileStream(fileInfo.FullName, FileMode.Open);
                        isFileOpen = true;
                    }
                    else
                    {
                        logger.Warning("Failed to locate " + DEFAULT_DATA_FILE + ".");
                    }
                }
                catch
                {
                    logger.Warning("Failed to open " + DEFAULT_DATA_FILE + ".");
                }

                if (isFileOpen == true)
                {
                    BinaryReader fileReader = null;
                    if (file != null)
                    {
                        try
                        {
                            logger.Event("Reading " + DEFAULT_DATA_FILE + ".");

                            fileReader  = new BinaryReader(file);
                            reader.Root = fileReader.ReadString();
                            fileReader.Close();
                        }
                        catch
                        {
                            logger.Warning("Failed to read " + DEFAULT_DATA_FILE + ".");
                            file.Close();
                        }
                    }
                }
            }

            InitializeComponent();

            mainWindowProgressBar.Style = ProgressBarStyle.Marquee;
            mainWindowProgressBar.Value = 100;

            lastSearch          = String.Empty;
            currentSearchSubset = new List <String>();

            // Main window Callbacks
            this.Shown += new EventHandler(OnMainWindowShown);

            // GLControl Callbacks
            glControlMain.Load     += new EventHandler(GLControlMainOnLoad);
            glControlMain.Resize   += new EventHandler(GLControlMainOnResize);
            glControlMain.Paint    += new PaintEventHandler(GLControlMainOnPaint);
            glControlMain.Disposed += new EventHandler(GLControlMainOnDispose);

            // Set mouse events
            glControlMain.MouseDown  += new MouseEventHandler(GLControlOnMouseDown);
            glControlMain.MouseUp    += new MouseEventHandler(GLControlOnMouseUp);
            glControlMain.MouseWheel += new MouseEventHandler(GLControlOnMouseWheel);
            glControlMain.MouseMove  += new MouseEventHandler(GLControlOnMouseMove);

            // Set keyboard events
            glControlMain.KeyDown += new KeyEventHandler(GLControlMainOnKeyDown);
            glControlMain.KeyUp   += new KeyEventHandler(GLControlMainOnKeyUp);

            // Menu Callbacks
            exitToolStripMenuItem.Click          += new EventHandler(OnExit);
            aboutToolStripMenuItem.Click         += new EventHandler(OnAbout);
            readDirectoryMainMenuStripItem.Click += new EventHandler(OnReadModels);
            readMainMenuStripItem.Click          += new EventHandler(OnSetDirectory);

            // Model View Callbacks
            modelListBox.DoubleClick += new EventHandler(OnModelListDoubleClick);
            modelListBox.KeyPress    += new KeyPressEventHandler(OnModelListKeyPress);

            // Buttons
            resetCameraButton.Click     += new EventHandler(OnResetCameraButtonClick);
            backgroundColorButton.Click += new EventHandler(OnBackgroundColorButtonClick);
            fullscreenButton.Click      += new EventHandler(OnFullscreenButtonClick);

            //
            // Animation Controller
            //

            // TODO: Pass the references and callbacks into constructor instead of doing them out here.
            // Kind of ugly code. :(
            animationController = new AnimationController();

            // Set references
            animationController.enableAnimationButton    = enableAnimationButton;
            animationController.currentAnimationComboBox = currentAnimationComboBox;
            animationController.playAnimationButton      = playAnimationButton;
            animationController.glControlMain            = glControlMain;
            animationController.timelineTrackBar         = timelineTrackBar;
            animationController.mainWindowStatusLabel    = mainWindowStatusLabel;

            animationController.renderer = renderer;

            // Set callbacks.
            enableAnimationButton.Click += new EventHandler(animationController.OnEnableAnimationButtonClick);
            playAnimationButton.Click   += new EventHandler(animationController.OnPlayAnimationButtonClick);
            currentAnimationComboBox.SelectedIndexChanged += new EventHandler(animationController.OnCurrentAnimationComboBoxSelectedIndexChanged);
            timelineTrackBar.Scroll += new EventHandler(animationController.OnTimelineTrackBar);

            animationController.DisableAnimation();

            //
            // End Animation Controller
            //

            // Search Box
            modelSearchBox.TextChanged += new EventHandler(OnModelSearchBoxTextChanged);
            modelSearchBox.KeyPress    += new KeyPressEventHandler(OnModelSearchBoxKeyPress);
            modelSearchBox.KeyDown     += new KeyEventHandler(OnModelSearchBoxKeyDown);
        }
Example #33
0
        public MainWindow()
        {
            logger = new Logger(DEFAULT_LOG_FILE); // Not checking result.
            logger.Event("Program Start.");

            isGLLoaded = false;
            timer = new Stopwatch();

            camera = new GLCamera();
            camera.SetViewParameters(new Vector3(0.0f, 0.0f, 2.0f), Vector3.Zero);
            renderer = new GLRenderer();

            // Set up the reader and initialize its root to the value in 'lolviewer.dat' if
            // the file exists.
            {
                reader = new LOLDirectoryReader();

                bool isFileOpen = false;
                FileStream file = null;
                try
                {
                    FileInfo fileInfo = new FileInfo(DEFAULT_DATA_FILE);
                    if (fileInfo.Exists == true)
                    {
                        file = new FileStream(fileInfo.FullName, FileMode.Open);
                        isFileOpen = true;
                    }
                    else
                    {
                        logger.Warning("Failed to locate " + DEFAULT_DATA_FILE + ".");
                    }
                }
                catch
                {
                    logger.Warning("Failed to open " + DEFAULT_DATA_FILE + ".");
                }

                if (isFileOpen == true)
                {
                    BinaryReader fileReader = null;
                    if (file != null)
                    {
                        try
                        {
                            logger.Event("Reading " + DEFAULT_DATA_FILE + ".");

                            fileReader = new BinaryReader(file);
                            reader.Root = fileReader.ReadString();
                            fileReader.Close();
                        }
                        catch
                        {
                            logger.Warning("Failed to read " + DEFAULT_DATA_FILE + ".");
                            file.Close();
                        }
                    }
                }
            }

            InitializeComponent();

            mainWindowProgressBar.Style = ProgressBarStyle.Marquee;
            mainWindowProgressBar.Value = 100;

            lastSearch = String.Empty;
            currentSearchSubset = new List<String>();

            // Main window Callbacks
            this.Shown += new EventHandler(OnMainWindowShown);

            // GLControl Callbacks
            glControlMain.Load += new EventHandler(GLControlMainOnLoad);
            glControlMain.Resize += new EventHandler(GLControlMainOnResize);
            glControlMain.Paint += new PaintEventHandler(GLControlMainOnPaint);
            glControlMain.Disposed += new EventHandler(GLControlMainOnDispose);

            // Set mouse events
            glControlMain.MouseDown += new MouseEventHandler(GLControlOnMouseDown);
            glControlMain.MouseUp += new MouseEventHandler(GLControlOnMouseUp);
            glControlMain.MouseWheel += new MouseEventHandler(GLControlOnMouseWheel);
            glControlMain.MouseMove += new MouseEventHandler(GLControlOnMouseMove);

            // Set keyboard events
            glControlMain.KeyDown += new KeyEventHandler(GLControlMainOnKeyDown);
            glControlMain.KeyUp += new KeyEventHandler(GLControlMainOnKeyUp);

            // Menu Callbacks
            exitToolStripMenuItem.Click += new EventHandler(OnExit);
            aboutToolStripMenuItem.Click += new EventHandler(OnAbout);
            readDirectoryMainMenuStripItem.Click += new EventHandler(OnReadModels);
            readMainMenuStripItem.Click += new EventHandler(OnSetDirectory);

            // Model View Callbacks
            modelListBox.DoubleClick += new EventHandler(OnModelListDoubleClick);
            modelListBox.KeyPress += new KeyPressEventHandler(OnModelListKeyPress);

            // Buttons
            resetCameraButton.Click += new EventHandler(OnResetCameraButtonClick);
            backgroundColorButton.Click += new EventHandler(OnBackgroundColorButtonClick);
            fullscreenButton.Click += new EventHandler(OnFullscreenButtonClick);

            //
            // Animation Controller
            //

            // TODO: Pass the references and callbacks into constructor instead of doing them out here.
            // Kind of ugly code. :(
            animationController = new AnimationController();

            // Set references
            animationController.enableAnimationButton = enableAnimationButton;
            animationController.currentAnimationComboBox = currentAnimationComboBox;
            animationController.playAnimationButton = playAnimationButton;
            animationController.glControlMain = glControlMain;
            animationController.timelineTrackBar = timelineTrackBar;
            animationController.mainWindowStatusLabel = mainWindowStatusLabel;

            animationController.renderer = renderer;

            // Set callbacks.
            enableAnimationButton.Click += new EventHandler(animationController.OnEnableAnimationButtonClick);
            playAnimationButton.Click += new EventHandler(animationController.OnPlayAnimationButtonClick);
            currentAnimationComboBox.SelectedIndexChanged += new EventHandler(animationController.OnCurrentAnimationComboBoxSelectedIndexChanged);
            timelineTrackBar.Scroll += new EventHandler(animationController.OnTimelineTrackBar);

            animationController.DisableAnimation();

            //
            // End Animation Controller
            //

            // Search Box
            modelSearchBox.TextChanged += new EventHandler(OnModelSearchBoxTextChanged);
            modelSearchBox.KeyPress += new KeyPressEventHandler(OnModelSearchBoxKeyPress);
            modelSearchBox.KeyDown += new KeyEventHandler(OnModelSearchBoxKeyDown);
        }
 public static Vector3 CamLoc(GLCamera cam)
 {
     return(cam == null ? new Vector3() : cam.GetPoint());
 }
Example #35
0
        public void ApplyBillboard(GLCamera camera)
        {
            if (BillboardSetting == BillboardFlags.Off)
            {
                return;
            }

            Vector3 camPoint = camera.GetPoint();
            Vector3 camRot   = camera._rotation;

            FrameState worldState = _frameMatrix.Derive();

            Matrix m = Matrix.Identity, mInv = Matrix.Identity;

            Vector3 rot = ((int)BillboardSetting & 1) == 0 ?                              //If perspective
                          worldState.Translate.LookatAngles(camPoint) * Maths._rad2degf : //Point at camera position
                          camRot;                                                         //Set parallel to the camera

            switch (BillboardSetting)
            {
            case BillboardFlags.Standard:
            case BillboardFlags.StandardPerspective:

                //Is affected by parent rotation
                m    = Matrix.RotationMatrix(worldState.Rotate);
                mInv = Matrix.ReverseRotationMatrix(worldState.Rotate);

                //No restrictions to apply
                break;

            case BillboardFlags.Rotation:
            case BillboardFlags.RotationPerspective:

                //Is not affected by parent rotation
                m    = Matrix.RotationMatrix(_frameState.Rotate);
                mInv = Matrix.ReverseRotationMatrix(_frameState.Rotate);

                //TODO: apply restrictions?
                break;

            case BillboardFlags.Y:
            case BillboardFlags.YPerspective:

                //Is affected by parent rotation
                m    = Matrix.RotationMatrix(worldState.Rotate);
                mInv = Matrix.ReverseRotationMatrix(worldState.Rotate);

                //Only Y is allowed to rotate automatically
                rot._x = 0;
                rot._z = 0;

                break;

            default:     //Not a valid billboard type
                return;
            }

            worldState.Rotate = rot;

            _frameMatrix        = worldState._transform * m;
            _inverseFrameMatrix = worldState._iTransform * mInv;
        }
Example #36
0
 public ModelPanel()
 {
     ColorChanged += OnBackColorChanged;
     ImageChanged += OnBgImageChanged;
     _camera       = new GLCamera();
 }