コード例 #1
0
ファイル: Icosphere.cs プロジェクト: DarkDestry/Cauldron
        private int AddUnitVertex(CldVector3 v3)
        {
            float length = (float)Math.Sqrt(v3.X * v3.X + v3.Y * v3.Y + v3.Z * v3.Z);

            Vertices.Add(new CldVector3(v3.X / length, v3.Y / length, v3.Z / length));
            return(Vertices.Count - 1);
        }
コード例 #2
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (Template != null)
            {
                openGLControl   = Template.FindName("Viewport_3D", this) as OpenGLControl;
                hwndHostElement = Template.FindName("Ether_Viewport", this) as Control_Ether_HwndHost;
                sceneWindow     = Template.FindName("SceneWindow", this) as Grid;

                //TODO: Reference by name
                if (CommandArguments.TryGetArgument("ether"))
                {
                    sceneWindow.Children.RemoveAt(1);
                    return;
                }
                sceneWindow.Children.RemoveAt(2);


                CompositionTarget.Rendering += (sender, args) => openGLControl.DoRender();

                shaderErrorLabel = Template.FindName("Shader_Compiler_Error", this) as TextBlock;

                Hierarchy.FocusChangedEvent += o => cameraFocusPoint = o.Transform.Position;
            }
        }
コード例 #3
0
ファイル: OpenGLRenderer.cs プロジェクト: DarkDestry/Cauldron
        private void Viewport_MouseMove(object sender, MouseEventArgs e)
        {
            OpenGLControl viewport = sender as OpenGLControl;

            if (e.MiddleButton == MouseButtonState.Pressed)
            {
                if (!mmDown)
                {
                    cursorPos = Mouse.GetPosition(viewport);
                }

                mmDown = true;
                if (Keyboard.IsKeyDown(Key.LeftShift))
                {
                    panning = true;
                }
                else
                {
                    orbiting = true;
                }
            }
            else if (e.MiddleButton == MouseButtonState.Released)
            {
                mmDown   = false;
                panning  = false;
                orbiting = false;

                Mouse.OverrideCursor = null;
                Mouse.Capture(null);
            }

            if (orbiting)
            {
                Vector delta = e.GetPosition(viewport) - cursorPos;

                cursorPos = e.GetPosition(viewport);

                cameraPitch += (float)-delta.Y / 2;
                cameraYaw   += (float)-delta.X / 2;
            }

            if (panning)
            {
                Vector delta = e.GetPosition(viewport) - cursorPos;

                cursorPos = e.GetPosition(viewport);
                if (delta.X != 0)
                {
                    bool b = true;
                }
                cameraFocusPoint += (CldVector3)(cameraRight * (float)-delta.X / 30);
                cameraFocusPoint += (CldVector3)(cameraUp * (float)delta.Y / 30);
            }
        }
コード例 #4
0
ファイル: Icosphere.cs プロジェクト: DarkDestry/Cauldron
        private int GetMiddlePointIndex(int p1, int p2)
        {
            Int64 lower  = Math.Min(p1, p2);
            Int64 higher = Math.Max(p1, p2);

            Int64 key = (lower << 32) + higher;

            if (indexDictionary.TryGetValue(key, out int index))
            {
                return(index);
            }

            CldVector3 point1 = Vertices[p1];
            CldVector3 point2 = Vertices[p2];
            CldVector3 middle = new CldVector3(
                (float)((point1.X + point2.X) / 2.0),
                (float)((point1.Y + point2.Y) / 2.0),
                (float)((point1.Z + point2.Z) / 2.0));

            index = AddUnitVertex(middle);

            indexDictionary.Add(key, index);
            return(index);
        }
コード例 #5
0
 public Transform()
 {
     _position = new CldVector3(0, 0, 0);
     _rotation = new CldVector3(0, 0, 0);
     _scale    = new CldVector3(1, 1, 1);
 }
コード例 #6
0
ファイル: OpenGLRenderer.cs プロジェクト: DarkDestry/Cauldron
 public void SetCameraFocus(CldVector3 pos)
 {
     cameraFocusPoint = pos;
 }
コード例 #7
0
 private void Color_FieldChanged(CldVector3 value)
 {
     Hierarchy.GetObject(currentObjectGuid).MeshRenderer.Color = (GLColor)value;
 }
コード例 #8
0
        public void SetupGeometry()
        {
            vertices[0] = new CldVector3(0.5f, 0.5f, 0.5f);
            vertices[1] = new CldVector3(0.5f, 0.5f, -0.5f);
            vertices[2] = new CldVector3(0.5f, -0.5f, -0.5f);
            vertices[3] = new CldVector3(0.5f, -0.5f, 0.5f);
            vertices[4] = new CldVector3(-0.5f, 0.5f, 0.5f);
            vertices[5] = new CldVector3(-0.5f, 0.5f, -0.5f);
            vertices[6] = new CldVector3(-0.5f, -0.5f, -0.5f);
            vertices[7] = new CldVector3(-0.5f, -0.5f, 0.5f);


            vertexTriangles = new ushort[]
            {
                0, 1, 2, 0, 2, 3, //Right Face
                0, 4, 5, 0, 5, 1, //Top Face
                0, 3, 7, 0, 7, 4, //Front Face
                4, 7, 6, 4, 6, 5, //Left Face
                6, 7, 3, 6, 3, 2, //Bottom Face
                5, 2, 1, 5, 6, 2  //Back Face
            };


            vertexNormals = new[]
            {
                //Right Face
                new CldVector3(1, 0, 0),
                new CldVector3(1, 0, 0),
                new CldVector3(1, 0, 0),
                new CldVector3(1, 0, 0),
                new CldVector3(1, 0, 0),
                new CldVector3(1, 0, 0),

                //Top Face
                new CldVector3(0, 1, 0),
                new CldVector3(0, 1, 0),
                new CldVector3(0, 1, 0),
                new CldVector3(0, 1, 0),
                new CldVector3(0, 1, 0),
                new CldVector3(0, 1, 0),

                //Front Face
                new CldVector3(0, 0, 1),
                new CldVector3(0, 0, 1),
                new CldVector3(0, 0, 1),
                new CldVector3(0, 0, 1),
                new CldVector3(0, 0, 1),
                new CldVector3(0, 0, 1),

                //Left Face
                new CldVector3(-1, 0, 0),
                new CldVector3(-1, 0, 0),
                new CldVector3(-1, 0, 0),
                new CldVector3(-1, 0, 0),
                new CldVector3(-1, 0, 0),
                new CldVector3(-1, 0, 0),

                //Bottom Face
                new CldVector3(0, -1, 0),
                new CldVector3(0, -1, 0),
                new CldVector3(0, -1, 0),
                new CldVector3(0, -1, 0),
                new CldVector3(0, -1, 0),
                new CldVector3(0, -1, 0),

                //Back Face
                new CldVector3(0, 0, -1),
                new CldVector3(0, 0, -1),
                new CldVector3(0, 0, -1),
                new CldVector3(0, 0, -1),
                new CldVector3(0, 0, -1),
                new CldVector3(0, 0, -1)
            };

            uvCoordinates = new[]
            {
                new CldVector2(1, 0),
                new CldVector2(1, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 0),
                new CldVector2(1, 0),
                new CldVector2(1, 0),
                new CldVector2(1, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 0),
                new CldVector2(1, 0),
                new CldVector2(1, 0),
                new CldVector2(1, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 0),
                new CldVector2(1, 0),
                new CldVector2(1, 0),
                new CldVector2(1, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 0),
                new CldVector2(1, 0),
                new CldVector2(1, 0),
                new CldVector2(1, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 0),
                new CldVector2(1, 0),
                new CldVector2(1, 0),
                new CldVector2(1, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 1),
                new CldVector2(0, 0),
                new CldVector2(1, 0)
            };
        }
コード例 #9
0
 private void Position_FieldChanged(CldVector3 value)
 {
     Hierarchy.GetObject(currentObjectGuid).Transform.Position = value;
     Hierarchy.TriggerHierarchyUpdate();
 }