Esempio n. 1
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(5, 3, 4) * 0.2f;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)
            ;
            {
                var manipulater = new ArcBallManipulater(GLMouseButtons.Right);
                manipulater.Bind(camera, this.winGLCanvas1);
                manipulater.Rotated += manipulater_Rotated;
                var node = RaycastNode.Create();
                this.scene.RootNode = node;
                (new FormProperyGrid(node)).Show();
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene.RootNode);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            this.pickingAction = new Picking(scene);

            this.triangleTip = new LegacyTriangleNode();
            this.quadTip     = new LegacyQuadNode();
        }
Esempio n. 2
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            foreach (var item in Enum.GetNames(typeof(EnvironmentMappingNode.Ratio)))
            {
                this.cmbRatios.Items.Add(item);
            }

            var position = new vec3(8, 0, 4) * 3;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            string folder   = System.Windows.Forms.Application.StartupPath;
            var    totalBmp = new Bitmap(System.IO.Path.Combine(folder, @"cubemaps_skybox.png"));

            Bitmap[] bitmaps = GetBitmaps(totalBmp);
            this.skybox = SkyboxNode.Create(bitmaps); this.skybox.Scale *= 60;
            string       objFilename = System.IO.Path.Combine(folder, "nanosuit.obj_");
            var          parser      = new ObjVNFParser(false);
            ObjVNFResult result      = parser.Parse(objFilename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                var model = new ObjVNF(result.Mesh);
                var node  = EnvironmentMappingNode.Create(
                    this.skybox.SkyboxTexture,
                    model, ObjVNF.strPosition, ObjVNF.strNormal);
                node.ModelSize = model.GetSize();
                float max = node.ModelSize.max();
                node.Scale *= 20.0f / max;
                node.Children.Add(new LegacyBoundingBoxNode(node.ModelSize));
                this.environmentMappingNode = node;

                var group = new GroupNode(this.environmentMappingNode, this.skybox);

                this.scene = new Scene(camera, this.winGLCanvas1)
                {
                    RootElement = group,
                };

                var list            = new ActionList();
                var transformAction = new TransformAction(scene);
                list.Add(transformAction);
                var renderAction = new RenderAction(scene);
                list.Add(renderAction);
                this.actionList = list;

                var manipulater = new FirstPerspectiveManipulater();
                manipulater.Bind(camera, this.winGLCanvas1);

                this.pickingAction = new PickingAction(scene);

                this.triangleTip = new LegacyTriangleNode();
                this.quadTip     = new LegacyQuadNode();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Color coded picking.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void winGLCanvas1_MouseMove(object sender, MouseEventArgs e)
        {
            LegacyTriangleNode triangleTip = this.triangleTip;

            if (triangleTip == null)
            {
                return;
            }
            LegacyQuadNode quadTip = this.quadTip;

            if (quadTip == null)
            {
                return;
            }

            int            x = e.X;
            int            y = this.winGLCanvas1.Height - e.Y - 1;
            PickedGeometry pickedGeometry = this.pickingAction.Pick(x, y, PickingGeometryTypes.Triangle | PickingGeometryTypes.Quad, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            if (pickedGeometry != null)
            {
                switch (pickedGeometry.Type)
                {
                case GeometryType.Point:
                    throw new NotImplementedException();

                case GeometryType.Line:
                    throw new NotImplementedException();

                case GeometryType.Triangle:
                    triangleTip.Vertex0 = pickedGeometry.Positions[0];
                    triangleTip.Vertex1 = pickedGeometry.Positions[1];
                    triangleTip.Vertex2 = pickedGeometry.Positions[2];
                    triangleTip.Parent  = pickedGeometry.FromObject as SceneNodeBase;
                    quadTip.Parent      = null;
                    break;

                case GeometryType.Quad:
                    quadTip.Vertex0    = pickedGeometry.Positions[0];
                    quadTip.Vertex1    = pickedGeometry.Positions[1];
                    quadTip.Vertex2    = pickedGeometry.Positions[2];
                    quadTip.Vertex3    = pickedGeometry.Positions[3];
                    quadTip.Parent     = pickedGeometry.FromObject as SceneNodeBase;
                    triangleTip.Parent = null;
                    break;

                case GeometryType.Polygon:
                    throw new NotImplementedException();

                default:
                    throw new NotDealWithNewEnumItemException(typeof(GeometryType));
                }
            }
            else
            {
                triangleTip.Parent = null;
                quadTip.Parent     = null;
            }
        }
Esempio n. 4
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(5, 3, 4);
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)
            ;

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            this.pickingAction = new Picking(scene);

            this.triangleTip = new LegacyTriangleNode();
            this.quadTip     = new LegacyQuadNode();

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);

            //string folder = System.Windows.Forms.Application.StartupPath;
            //string filename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", "vnfHanoiTower.obj_");
            //var parser = new ObjVNFParser(false);
            //ObjVNFResult result = parser.Parse(filename);
            //if (result.Error != null)
            //{
            //    MessageBox.Show(result.Error.ToString());
            //}
            //else
            //{
            //    var model = new ObjVNF(result.Mesh);
            //    var node = OITNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
            //    float max = node.ModelSize.max();
            //    node.Scale *= 7.0f / max;
            //    node.WorldPosition = new vec3(0, 0, 0);
            //    var rootElement = this.scene.RootElement;
            //    this.scene.RootElement = node;
            //    if (rootElement != null) { rootElement.Dispose(); }
            //}
            // use teapot instead.
            var   model = new Teapot();
            var   node  = OITNode.Create(model, Teapot.strPosition, Teapot.strNormal, model.GetModelSize());
            float max   = node.ModelSize.max();

            node.Scale         *= 7.0F / max;
            node.WorldPosition  = new vec3(0, 0, 0);
            this.scene.RootNode = node;
        }
Esempio n. 5
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(5, 3, 4);
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)
            ;

            var list            = new ActionList();
            var transformAction = new TransformAction(scene.RootNode);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            this.pickingAction = new Picking(scene);

            this.triangleTip = new LegacyTriangleNode();
            this.quadTip     = new LegacyQuadNode();

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);

            string       folder   = System.Windows.Forms.Application.StartupPath;
            string       filename = System.IO.Path.Combine(folder, "nanosuit.obj_");
            var          parser   = new ObjVNFParser(false);
            ObjVNFResult result   = parser.Parse(filename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                var node = ObjVNFNode.Create(result.Mesh);
                node.Children.Add(new LegacyBoundingBoxNode(node.ModelSize));
                float max = node.ModelSize.max();
                node.Scale        *= 7.0f / max;
                node.WorldPosition = new vec3(0, 0, 0);
                var rootElement = this.scene.RootNode;
                this.scene.RootNode = node;
                if (rootElement != null)
                {
                    rootElement.Dispose();
                }
            }
        }
Esempio n. 6
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(5, 3, 4);
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.teapot = TeapotNode.Create();
            teapot.Children.Add(new LegacyBoundingBoxNode(teapot.ModelSize));
            var ground = GroundNode.Create(); ground.Color = Color.Gray.ToVec4(); ground.Scale *= 10; ground.WorldPosition = new vec3(0, -3, 0);

            this.textNode = new DirectTextNode()
            {
                Text = "Color Coded Picking"
            };
            var group = new GroupNode(this.teapot, ground, this.textNode);

            this.scene = new Scene(camera, this.winGLCanvas1)
            {
                RootElement = group,
            };

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            this.pickingAction = new PickingAction(scene);

            this.triangleTip = new LegacyTriangleNode();
            this.quadTip     = new LegacyQuadNode();
            this.chkRenderWireframe_CheckedChanged(this.chkRenderWireframe, EventArgs.Empty);
            this.chkRenderBody_CheckedChanged(this.chkRenderBody, EventArgs.Empty);

            // uncomment these lines to enable manipualter of camera!
            //var manipulater = new FirstPerspectiveManipulater();
            //manipulater.BindingMouseButtons = System.Windows.Forms.MouseButtons.Right;
            //manipulater.Bind(camera, this.winGLCanvas1);
        }
Esempio n. 7
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(8, 6, 4) * 4;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.teapot = TeapotNode.Create(); this.teapot.Scale *= 3;
            teapot.Children.Add(new LegacyBoundingBoxNode(teapot.ModelSize));
            string folder   = System.Windows.Forms.Application.StartupPath;
            var    totalBmp = new Bitmap(System.IO.Path.Combine(folder, @"cubemaps_skybox.png"));

            this.skybox = SkyboxNode.Create(totalBmp); this.skybox.Scale *= 60;
            var group = new GroupNode(this.teapot, this.skybox);

            this.scene = new Scene(camera)

            {
                RootNode = group,
            };

            var list            = new ActionList();
            var transformAction = new TransformAction(scene.RootNode);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);

            this.pickingAction = new Picking(scene);

            this.triangleTip = new LegacyTriangleNode();
            this.quadTip     = new LegacyQuadNode();
            this.chkRenderWireframe_CheckedChanged(this.chkRenderWireframe, EventArgs.Empty);
            this.chkRenderBody_CheckedChanged(this.chkRenderBody, EventArgs.Empty);
        }
Esempio n. 8
0
        /// <summary>
        /// Color coded picking.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void winGLCanvas1_MouseMove(object sender, MouseEventArgs e)
        {
            LegacyTriangleNode triangleTip = this.triangleTip;

            if (triangleTip == null)
            {
                return;
            }
            LegacyQuadNode quadTip = this.quadTip;

            if (quadTip == null)
            {
                return;
            }

            int            x = e.X;
            int            y = this.winGLCanvas1.Height - e.Y - 1;
            PickedGeometry pickedGeometry = null;

            try
            {
                pickedGeometry = this.pickingAction.Pick(x, y, true, true, false);
            }
            catch (Exception)
            { }
            if (pickedGeometry != null)
            {
                switch (pickedGeometry.Type)
                {
                case GeometryType.Point:
                    throw new NotImplementedException();

                case GeometryType.Line:
                    throw new NotImplementedException();

                case GeometryType.Triangle:
                    triangleTip.Vertex0 = pickedGeometry.Positions[0];
                    triangleTip.Vertex1 = pickedGeometry.Positions[1];
                    triangleTip.Vertex2 = pickedGeometry.Positions[2];
                    triangleTip.Parent  = pickedGeometry.FromRenderer as SceneNodeBase;
                    quadTip.Parent      = null;
                    break;

                case GeometryType.Quad:
                    quadTip.Vertex0    = pickedGeometry.Positions[0];
                    quadTip.Vertex1    = pickedGeometry.Positions[1];
                    quadTip.Vertex2    = pickedGeometry.Positions[2];
                    quadTip.Vertex3    = pickedGeometry.Positions[3];
                    quadTip.Parent     = pickedGeometry.FromRenderer as SceneNodeBase;
                    triangleTip.Parent = null;
                    break;

                case GeometryType.Polygon:
                    throw new NotImplementedException();

                default:
                    break;
                }
            }
            else
            {
                triangleTip.Parent = null;
                quadTip.Parent     = null;
            }
        }