private void _init()
        {
            _glControl = new OpenGLControl();

            var init = (System.ComponentModel.ISupportInitialize)_glControl;

            init.BeginInit();

            _glControl.Dock      = System.Windows.Forms.DockStyle.Fill;
            _glControl.FrameRate = 16;
            _glControl.DrawFPS   = true;
            //_glControl.ClientSize = _form.ClientSize;
            _glControl.GDIDraw           += _glControl_GDIDraw;
            _glControl.OpenGLDraw        += _glControl_OpenGLDraw;
            _glControl.OpenGLInitialized += _glControl_OpenGLInitialized;
            _glControl.Resized           += _glControl_Resized;
            _glControl.MouseDown         += _glControl_MouseDown;
            _glControl.MouseMove         += _glControl_MouseMove;
            _glControl.MouseUp           += _glControl_MouseUp;
            _glControl.MouseClick        += _glControl_MouseClick;
            _glControl.KeyPress          += _glControl_KeyPress;
            _glControl.KeyUp             += _glControl_KeyUp;
            _glControl.PreviewKeyDown    += _glControl_PreviewKeyDown;


            init.EndInit();
        }
        public BuildingObjectLib3DS CreateBuildingModel()
        {
            BuildingObjectLib3DS Building;
            Hashtable            Textures  = new Hashtable();
            Lib3dsMesh           test      = new Lib3dsMesh();
            OpenGLControl        openglCtr = new SharpGL.OpenGLControl();

            foreach (Lib3dsMaterial material in MyModel.materials)
            {
                Texture texture = new Texture();
                try
                {
                    texture.Create(openglCtr.OpenGL, "..\\Model\\" + material.name + ".jpg");
                    Textures.Add(material.name, texture);
                }
                catch
                {
                    // Do not find the texture file
                }
            }

            Building = new BuildingObjectLib3DS(null, BuildingObjectType.Building, 0,
                                                MyModel, Textures);

            foreach (Lib3dsMeshInstanceNode node in MyModel.nodes)
            {
                if (node.type != Lib3dsNodeType.LIB3DS_NODE_MESH_INSTANCE || node.childs == null)
                {
                    continue;
                }
                Building.AddNewChild(node);
            }

            return(Building);
        }
Exemplo n.º 3
0
 private void Init(SharpGL.OpenGLControl openGLControl, int interval, double eyex, double eyey, double eyez,
                   double centerx, double centery, double centerz,
                   double upx, double upy, double upz, double fovy, double aspect, double zNear, double zFar)
 {
     this.openGLControl      = openGLControl;
     this.interval           = interval;
     this.eye                = new TriTuple(eyex, eyey, eyez);
     this.center             = new TriTuple(centerx, centery, centerz);
     this.up                 = new TriTuple(upx, upy, upz);
     this.perspective        = new PerspectiveParam(fovy, aspect, zNear, zFar);
     this.updateViewDelegate = new Action(UpdateView);
 }
Exemplo n.º 4
0
        public Form1()
        {
            InitializeComponent();

            SharpGL.SceneGraph.Assets.Material SunMaterial   = new SharpGL.SceneGraph.Assets.Material();
            SharpGL.SceneGraph.Assets.Material EarthMaterial = new SharpGL.SceneGraph.Assets.Material();
            SharpGL.SceneGraph.Assets.Material MoonMaterial  = new SharpGL.SceneGraph.Assets.Material();

            SharpGL.SceneGraph.Assets.Texture SunTexture   = new SharpGL.SceneGraph.Assets.Texture();
            SharpGL.SceneGraph.Assets.Texture EarthTexture = new SharpGL.SceneGraph.Assets.Texture();
            SharpGL.SceneGraph.Assets.Texture MoonTexture  = new SharpGL.SceneGraph.Assets.Texture();

            OpenGLControl openglCtr = new SharpGL.OpenGLControl();

            SunTexture.Create(openglCtr.OpenGL, "Sun.bmp");

            OpenGLControl openglCtr1 = new SharpGL.OpenGLControl();

            MoonTexture.Create(openglCtr1.OpenGL, "Moon.jpg");

            OpenGLControl openglCtr2 = new SharpGL.OpenGLControl();

            EarthTexture.Create(openglCtr2.OpenGL, "Earth.jpg");

            //// texture1.Create(openglCtr.OpenGL, "Crate.bmp");

            //// material.Texture = texture1;
            SunMaterial.Texture = SunTexture;
            Sun.TextureCoords   = true;

            EarthMaterial.Texture = EarthTexture;
            Earth.TextureCoords   = true;

            MoonMaterial.Texture = MoonTexture;
            Moon.TextureCoords   = true;

            Light light = new Light()
            {
                On       = true,
                Position = new Vertex(0, 0, 0),
                GLCode   = OpenGL.GL_LIGHT1
            };



            sceneControl1.Scene.SceneContainer.AddChild(light);


            //SharpGL.OpenGL gl = this.sceneControl1.OpenGL;
            //texture.Create(gl, "Crate.bmp");
            //texture.Bind(gl);

            //uint[] textureID = new uint[1];
            //byte[] colors = new byte[256 * 256 * 4];
            //gl.BindTexture(OpenGL.GL_TEXTURE_2D, textureID[0]);
            //gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_TEXTURE, 256, 256, 50, OpenGL.GL_TEXTURE, OpenGL.GL_BYTE, colors);

            //// SunMaterial.Diffuse = Color.Orange;
            //EarthMaterial.Diffuse = Color.Cyan;
            //MoonMaterial.Diffuse = Color.Silver;
            ////SunMaterial.Ambient = Color.FromArgb(0, Color.Orange);
            //EarthMaterial.Ambient = Color.FromArgb(255, Color.Blue);
            //MoonMaterial.Ambient = Color.FromArgb(255, Color.Silver);

            SunMaterial.Texture = SunTexture;

            Sun.Material   = SunMaterial;
            Moon.Material  = MoonMaterial;
            Earth.Material = EarthMaterial;

            Earth.Radius = 2;
            Moon.Radius  = 0.5;
            Sun.Radius   = 4;

            sceneControl1.Scene.SceneContainer.AddChild(Earth);
            sceneControl1.Scene.SceneContainer.AddChild(Moon);
            sceneControl1.Scene.SceneContainer.AddChild(Sun);


            sceneControl1.Scene.RenderBoundingVolumes = !sceneControl1.Scene.RenderBoundingVolumes;
        }
        public BuildingObjectLib3DS CreateBuildingModel()
        {
            BuildingObjectLib3DS Building;
            Hashtable Textures = new Hashtable();
            Lib3dsMesh test = new Lib3dsMesh();
            OpenGLControl openglCtr = new SharpGL.OpenGLControl();

            foreach (Lib3dsMaterial material in MyModel.materials)
            {
                Texture texture = new Texture();
                try
                {
                    texture.Create(openglCtr.OpenGL, "..\\Model\\" + material.name + ".jpg");
                    Textures.Add(material.name, texture);
                }
                catch
                {
                    // Do not find the texture file
                }
            }

            Building = new BuildingObjectLib3DS(null, BuildingObjectType.Building, 0,
                MyModel, Textures);

            foreach (Lib3dsMeshInstanceNode node in MyModel.nodes)
            {
                if (node.type != Lib3dsNodeType.LIB3DS_NODE_MESH_INSTANCE || node.childs == null)
                    continue;
                Building.AddNewChild(node);
            }

            return Building;
        }
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.m_btnCalcInverse = new System.Windows.Forms.Button();
     this.m_tbxXCoord = new System.Windows.Forms.TextBox();
     this.m_tbxCoord = new System.Windows.Forms.TextBox();
     this.m_tbxSholderAngle = new System.Windows.Forms.TextBox();
     this.agolLakt = new System.Windows.Forms.TextBox();
     this.m_tbxErrorConsole = new System.Windows.Forms.TextBox();
     this.m_lblX = new System.Windows.Forms.Label();
     this.label2 = new System.Windows.Forms.Label();
     this.label3 = new System.Windows.Forms.Label();
     this.m_lblSholderAngle = new System.Windows.Forms.Label();
     this.m_lblConsole = new System.Windows.Forms.Label();
     this.openGLControl1 = new SharpGL.OpenGLControl();
     this.ramoSt = new System.Windows.Forms.TextBox();
     this.laktSt = new System.Windows.Forms.TextBox();
     this.label6 = new System.Windows.Forms.Label();
     this.label7 = new System.Windows.Forms.Label();
     this.label8 = new System.Windows.Forms.Label();
     this.m_gbxInverse = new System.Windows.Forms.GroupBox();
     this.m_gbxOutput = new System.Windows.Forms.GroupBox();
     this.m_gbxInput = new System.Windows.Forms.GroupBox();
     this.m_gbxInverse.SuspendLayout();
     this.m_gbxOutput.SuspendLayout();
     this.m_gbxInput.SuspendLayout();
     this.SuspendLayout();
     //
     // m_btnCalcInverse
     //
     this.m_btnCalcInverse.Location = new System.Drawing.Point(23, 406);
     this.m_btnCalcInverse.Name = "m_btnCalcInverse";
     this.m_btnCalcInverse.Size = new System.Drawing.Size(126, 23);
     this.m_btnCalcInverse.TabIndex = 0;
     this.m_btnCalcInverse.Text = "Calculate inverse kinematics";
     this.m_btnCalcInverse.UseVisualStyleBackColor = true;
     this.m_btnCalcInverse.Click += new System.EventHandler(this.OnCalcInverseCb);
     //
     // m_tbxXCoord
     //
     this.m_tbxXCoord.Location = new System.Drawing.Point(35, 13);
     this.m_tbxXCoord.Name = "m_tbxXCoord";
     this.m_tbxXCoord.Size = new System.Drawing.Size(100, 20);
     this.m_tbxXCoord.TabIndex = 1;
     //
     // m_tbxCoord
     //
     this.m_tbxCoord.Location = new System.Drawing.Point(35, 39);
     this.m_tbxCoord.Name = "m_tbxCoord";
     this.m_tbxCoord.Size = new System.Drawing.Size(100, 20);
     this.m_tbxCoord.TabIndex = 2;
     //
     // m_tbxSholderAngle
     //
     this.m_tbxSholderAngle.Location = new System.Drawing.Point(9, 39);
     this.m_tbxSholderAngle.Name = "m_tbxSholderAngle";
     this.m_tbxSholderAngle.Size = new System.Drawing.Size(155, 20);
     this.m_tbxSholderAngle.TabIndex = 3;
     //
     // agolLakt
     //
     this.agolLakt.Location = new System.Drawing.Point(176, 39);
     this.agolLakt.Name = "agolLakt";
     this.agolLakt.Size = new System.Drawing.Size(161, 20);
     this.agolLakt.TabIndex = 4;
     //
     // m_tbxErrorConsole
     //
     this.m_tbxErrorConsole.ForeColor = System.Drawing.Color.Red;
     this.m_tbxErrorConsole.Location = new System.Drawing.Point(9, 179);
     this.m_tbxErrorConsole.Multiline = true;
     this.m_tbxErrorConsole.Name = "m_tbxErrorConsole";
     this.m_tbxErrorConsole.Size = new System.Drawing.Size(339, 96);
     this.m_tbxErrorConsole.TabIndex = 5;
     //
     // m_lblX
     //
     this.m_lblX.AutoSize = true;
     this.m_lblX.Location = new System.Drawing.Point(6, 16);
     this.m_lblX.Name = "m_lblX";
     this.m_lblX.Size = new System.Drawing.Size(23, 13);
     this.m_lblX.TabIndex = 6;
     this.m_lblX.Text = "X : ";
     //
     // label2
     //
     this.label2.AutoSize = true;
     this.label2.Location = new System.Drawing.Point(6, 42);
     this.label2.Name = "label2";
     this.label2.Size = new System.Drawing.Size(17, 13);
     this.label2.TabIndex = 7;
     this.label2.Text = "Y:";
     //
     // label3
     //
     this.label3.AutoSize = true;
     this.label3.Location = new System.Drawing.Point(173, 23);
     this.label3.Name = "label3";
     this.label3.Size = new System.Drawing.Size(72, 13);
     this.label3.TabIndex = 8;
     this.label3.Text = "Aгол на лакт";
     //
     // m_lblSholderAngle
     //
     this.m_lblSholderAngle.AutoSize = true;
     this.m_lblSholderAngle.Location = new System.Drawing.Point(9, 23);
     this.m_lblSholderAngle.Name = "m_lblSholderAngle";
     this.m_lblSholderAngle.Size = new System.Drawing.Size(75, 13);
     this.m_lblSholderAngle.TabIndex = 9;
     this.m_lblSholderAngle.Text = "Sholder angle:";
     //
     // m_lblConsole
     //
     this.m_lblConsole.AutoSize = true;
     this.m_lblConsole.Location = new System.Drawing.Point(9, 163);
     this.m_lblConsole.Name = "m_lblConsole";
     this.m_lblConsole.Size = new System.Drawing.Size(48, 13);
     this.m_lblConsole.TabIndex = 10;
     this.m_lblConsole.Text = "Console:";
     //
     // openGLControl1
     //
     this.openGLControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     | System.Windows.Forms.AnchorStyles.Left)
     | System.Windows.Forms.AnchorStyles.Right)));
     this.openGLControl1.DrawRenderTime = false;
     this.openGLControl1.FrameRate = 62.5F;
     this.openGLControl1.GDIEnabled = false;
     this.openGLControl1.Location = new System.Drawing.Point(495, 12);
     this.openGLControl1.Name = "openGLControl1";
     this.openGLControl1.Size = new System.Drawing.Size(576, 608);
     this.openGLControl1.TabIndex = 14;
     this.openGLControl1.OpenGLDraw += new System.Windows.Forms.PaintEventHandler(this.openGLControl1_OpenGLDraw_1);
     this.openGLControl1.Resized += new System.EventHandler(this.openGLControl1_Resized);
     this.openGLControl1.Load += new System.EventHandler(this.openGLControl1_Load_1);
     this.openGLControl1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.openGLControl1_KeyPress);
     //
     // ramoSt
     //
     this.ramoSt.Location = new System.Drawing.Point(9, 86);
     this.ramoSt.Name = "ramoSt";
     this.ramoSt.Size = new System.Drawing.Size(155, 20);
     this.ramoSt.TabIndex = 15;
     //
     // laktSt
     //
     this.laktSt.Location = new System.Drawing.Point(176, 86);
     this.laktSt.Name = "laktSt";
     this.laktSt.Size = new System.Drawing.Size(161, 20);
     this.laktSt.TabIndex = 16;
     //
     // label6
     //
     this.label6.AutoSize = true;
     this.label6.Location = new System.Drawing.Point(6, 70);
     this.label6.Name = "label6";
     this.label6.Size = new System.Drawing.Size(52, 13);
     this.label6.TabIndex = 17;
     this.label6.Text = "Степени:";
     //
     // label7
     //
     this.label7.AutoSize = true;
     this.label7.Location = new System.Drawing.Point(173, 70);
     this.label7.Name = "label7";
     this.label7.Size = new System.Drawing.Size(52, 13);
     this.label7.TabIndex = 18;
     this.label7.Text = "Степени:";
     //
     // label8
     //
     this.label8.AutoSize = true;
     this.label8.Location = new System.Drawing.Point(9, 127);
     this.label8.Name = "label8";
     this.label8.Size = new System.Drawing.Size(35, 13);
     this.label8.TabIndex = 19;
     this.label8.Text = "label8";
     //
     // m_gbxInverse
     //
     this.m_gbxInverse.Controls.Add(this.m_gbxOutput);
     this.m_gbxInverse.Controls.Add(this.m_gbxInput);
     this.m_gbxInverse.Controls.Add(this.m_btnCalcInverse);
     this.m_gbxInverse.Location = new System.Drawing.Point(12, 12);
     this.m_gbxInverse.Name = "m_gbxInverse";
     this.m_gbxInverse.Size = new System.Drawing.Size(372, 480);
     this.m_gbxInverse.TabIndex = 20;
     this.m_gbxInverse.TabStop = false;
     this.m_gbxInverse.Text = "Inverse kinematics";
     //
     // m_gbxOutput
     //
     this.m_gbxOutput.Controls.Add(this.agolLakt);
     this.m_gbxOutput.Controls.Add(this.m_lblSholderAngle);
     this.m_gbxOutput.Controls.Add(this.label3);
     this.m_gbxOutput.Controls.Add(this.m_lblConsole);
     this.m_gbxOutput.Controls.Add(this.label8);
     this.m_gbxOutput.Controls.Add(this.m_tbxSholderAngle);
     this.m_gbxOutput.Controls.Add(this.m_tbxErrorConsole);
     this.m_gbxOutput.Controls.Add(this.label7);
     this.m_gbxOutput.Controls.Add(this.laktSt);
     this.m_gbxOutput.Controls.Add(this.ramoSt);
     this.m_gbxOutput.Controls.Add(this.label6);
     this.m_gbxOutput.Location = new System.Drawing.Point(11, 100);
     this.m_gbxOutput.Name = "m_gbxOutput";
     this.m_gbxOutput.Size = new System.Drawing.Size(355, 281);
     this.m_gbxOutput.TabIndex = 21;
     this.m_gbxOutput.TabStop = false;
     this.m_gbxOutput.Text = "Output";
     //
     // m_gbxInput
     //
     this.m_gbxInput.Controls.Add(this.m_tbxCoord);
     this.m_gbxInput.Controls.Add(this.m_tbxXCoord);
     this.m_gbxInput.Controls.Add(this.label2);
     this.m_gbxInput.Controls.Add(this.m_lblX);
     this.m_gbxInput.Location = new System.Drawing.Point(11, 19);
     this.m_gbxInput.Name = "m_gbxInput";
     this.m_gbxInput.Size = new System.Drawing.Size(355, 75);
     this.m_gbxInput.TabIndex = 20;
     this.m_gbxInput.TabStop = false;
     this.m_gbxInput.Text = "Input";
     //
     // UiInvKinematics
     //
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     this.ClientSize = new System.Drawing.Size(1083, 634);
     this.Controls.Add(this.m_gbxInverse);
     this.Controls.Add(this.openGLControl1);
     this.Name = "UiInvKinematics";
     this.Text = "InvKinem";
     this.Load += new System.EventHandler(this.Form1_Load);
     this.m_gbxInverse.ResumeLayout(false);
     this.m_gbxOutput.ResumeLayout(false);
     this.m_gbxOutput.PerformLayout();
     this.m_gbxInput.ResumeLayout(false);
     this.m_gbxInput.PerformLayout();
     this.ResumeLayout(false);
 }
Exemplo n.º 7
0
        public Form1()
        {
            InitializeComponent();

            OpenGL gl = sceneControl1.OpenGL;

            SharpGL.SceneGraph.Assets.Material SunMaterial     = new SharpGL.SceneGraph.Assets.Material();
            SharpGL.SceneGraph.Assets.Material EarthMaterial   = new SharpGL.SceneGraph.Assets.Material();
            SharpGL.SceneGraph.Assets.Material MoonMaterial    = new SharpGL.SceneGraph.Assets.Material();
            SharpGL.SceneGraph.Assets.Material MercuryMaterial = new SharpGL.SceneGraph.Assets.Material();

            SharpGL.SceneGraph.Assets.Texture SunTexture     = new SharpGL.SceneGraph.Assets.Texture();
            SharpGL.SceneGraph.Assets.Texture EarthTexture   = new SharpGL.SceneGraph.Assets.Texture();
            SharpGL.SceneGraph.Assets.Texture MoonTexture    = new SharpGL.SceneGraph.Assets.Texture();
            SharpGL.SceneGraph.Assets.Texture MercuryTexture = new SharpGL.SceneGraph.Assets.Texture();

            OpenGLControl openglCtr = new SharpGL.OpenGLControl();

            SunTexture.Create(openglCtr.OpenGL, "Sun.jpg");

            OpenGLControl openglCtr1 = new SharpGL.OpenGLControl();

            MoonTexture.Create(openglCtr1.OpenGL, "Moon.jpg");

            OpenGLControl openglCtr2 = new SharpGL.OpenGLControl();

            EarthTexture.Create(openglCtr2.OpenGL, "Earth.jpg");

            OpenGLControl openglCtr3 = new SharpGL.OpenGLControl();

            MercuryTexture.Create(openglCtr2.OpenGL, "Mercury.jpg");

            SunMaterial.Texture = SunTexture;
            Sun.TextureCoords   = true;

            EarthMaterial.Texture = EarthTexture;
            Earth.TextureCoords   = true;

            MoonMaterial.Texture = MoonTexture;
            Moon.TextureCoords   = true;

            MercuryMaterial.Texture = MoonTexture;
            Mercury.TextureCoords   = true;



            SunMaterial.Texture = SunTexture;

            Sun.Material     = SunMaterial;
            Moon.Material    = MoonMaterial;
            Earth.Material   = EarthMaterial;
            Mercury.Material = MercuryMaterial;

            Earth.Radius   = 2;
            Moon.Radius    = 0.5;
            Sun.Radius     = 4;
            Mercury.Radius = 0.7;

            sceneControl1.Scene.SceneContainer.AddChild(Earth);
            sceneControl1.Scene.SceneContainer.AddChild(Moon);
            sceneControl1.Scene.SceneContainer.AddChild(Sun);
            sceneControl1.Scene.SceneContainer.AddChild(Mercury);


            sceneControl1.Scene.RenderBoundingVolumes = !sceneControl1.Scene.RenderBoundingVolumes;

            Light light = new Light()
            {
                On       = true,
                Position = new Vertex(0, 0, 0),
                GLCode   = OpenGL.GL_LIGHT0
            };

            sceneControl1.Scene.SceneContainer.AddChild(light);
        }
Exemplo n.º 8
0
 public ViewController(SharpGL.OpenGLControl openGLControl, int interval, double eyex, double eyey, double eyez,
                       double centerx, double centery, double centerz,
                       double upx, double upy, double upz, double fovy, double aspect, double zNear, double zFar)
 {
     this.Init(openGLControl, interval, eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz, fovy, aspect, zNear, zFar);
 }