예제 #1
0
파일: Cube.cs 프로젝트: pdeparcq/iGL
        public Cube(float depth, float height, float width)
        {
            Depth = depth;
            Height = height;
            Width = width;

            var halfWidth = Width / 2.0f;
            var halfHeight = Height / 2.0f;
            var halfDepth = Depth / 2.0f;

            _meshComponent = new MeshComponent(this);

            /* create cube vertices */
            var vertices = new Vector3[8];
            vertices[0] = new Vector3(-halfWidth, -halfHeight, halfDepth);
            vertices[1] = new Vector3(halfWidth, -halfHeight, halfDepth);
            vertices[2] = new Vector3(halfWidth, halfHeight, halfDepth);
            vertices[3] = new Vector3(-halfWidth, halfHeight, halfDepth);
            vertices[4] = new Vector3(-halfWidth, -halfHeight, -halfDepth);
            vertices[5] = new Vector3(halfWidth, -halfHeight, -halfDepth);
            vertices[6] = new Vector3(halfWidth, halfHeight, -halfDepth);
            vertices[7] = new Vector3(-halfWidth, halfHeight, -halfDepth);

            /* create indices */
            var indices = new short[]{
             // front face
                0, 1, 2, 2, 3, 0,
                // top face
                3, 2, 6, 6, 7, 3,
                // back face
                7, 6, 5, 5, 4, 7,
                // left face
                4, 0, 3, 3, 7, 4,
                // bottom face
                0, 1, 5, 5, 4, 0,
                // right face
                1, 5, 6, 6, 2, 1 };

            _meshComponent.Vertices = vertices;
            _meshComponent.Indices = indices;

            _meshComponent.CalculateNormals();

             AddComponent(_meshComponent);

            _meshRenderComponent = new MeshRenderComponent(this);

            AddComponent(_meshRenderComponent);
        }
예제 #2
0
파일: Gizmo.cs 프로젝트: BaldMan82/iGL
        private void LoadGizmo()
        {
            YDirectionArrow.Scale = new Vector3(1, 3, 1);

            YDirectionArrow.Position = new Vector3(0, ArrowLength, 0);

            var mesh = new MeshComponent();

            var vertices = new Vector3[5];

            vertices[0] = new Vector3(-1, -0.5f, -1);
            vertices[1] = new Vector3(-1, -0.5f, 1);
            vertices[2] = new Vector3(0, 0.5f, 0);
            vertices[3] = new Vector3(1, -0.5f, 1);
            vertices[4] = new Vector3(1, -0.5f, -1);

            var indices = new short[18];
            int index = 0;

            indices[index++] = 0;
            indices[index++] = 1;
            indices[index++] = 2;

            indices[index++] = 1;
            indices[index++] = 3;
            indices[index++] = 2;

            indices[index++] = 3;
            indices[index++] = 4;
            indices[index++] = 2;

            indices[index++] = 4;
            indices[index++] = 0;
            indices[index++] = 2;

            indices[index++] = 3;
            indices[index++] = 1;
            indices[index++] = 0;

            indices[index++] = 0;
            indices[index++] = 4;
            indices[index++] = 3;

            mesh.Vertices = vertices;
            mesh.Indices = indices;
            mesh.UV = new Vector2[vertices.Length];

            mesh.Material.Ambient = new Vector4(0, 0, 1, 1);
            mesh.Material.Diffuse = Vector4.Zero;
            mesh.CalculateNormals();

            var render = new MeshRenderComponent();

            YDirectionArrow.AddComponent(mesh);
            YDirectionArrow.AddComponent(render);

            ZDirectionArrow.Rotation = new Vector3((float)(System.Math.PI / 2.0f), 0, 0);
            ZDirectionArrow.Scale = new Vector3(1, 3, 1);
            ZDirectionArrow.Position = new Vector3(0, 0, ArrowLength);

            var zMesh = new MeshComponent();

            zMesh.Vertices = mesh.Vertices;
            zMesh.Normals = mesh.Normals;
            zMesh.Indices = mesh.Indices;
            zMesh.UV = mesh.UV;
            zMesh.Material.Ambient = new Vector4(1, 0, 0, 1);
            zMesh.Material.Diffuse = Vector4.Zero;

            render = render.CloneForReuse();

            ZDirectionArrow.AddComponent(zMesh);
            ZDirectionArrow.AddComponent(render);

            XDirectionArrow.Rotation = new Vector3(0, 0, -(float)(System.Math.PI / 2.0f));
            XDirectionArrow.Scale = new Vector3(1, 3, 1);
            XDirectionArrow.Position = new Vector3(ArrowLength, 0, 0);

            var xMesh = new MeshComponent();

            xMesh.Vertices = mesh.Vertices;
            xMesh.Normals = mesh.Normals;
            xMesh.Indices = mesh.Indices;
            xMesh.UV = mesh.UV;
            xMesh.Material.Ambient = new Vector4(0, 1, 0, 1);
            xMesh.Material.Diffuse = Vector4.Zero;

            render = render.CloneForReuse();

            XDirectionArrow.AddComponent(xMesh);
            XDirectionArrow.AddComponent(render);

            _xDirection.Scale = new Vector3(ArrowLength, 0.5f, 0.5f);
            _xDirection.Position = new Vector3((ArrowLength / 2.0f) - 0.25f, 0, 0);
            ((Cube)_xDirection).Material.Ambient = new Vector4(0, 1, 0, 1);
            ((Cube)_xDirection).Material.Diffuse = Vector4.Zero;

            _yDirection.Scale = new Vector3(0.5f, ArrowLength, 0.5f);
            _yDirection.Position = new Vector3(0, (ArrowLength / 2.0f) - 0.25f, 0);
            ((Cube)_yDirection).Material.Ambient = new Vector4(0, 0, 1, 1);
            ((Cube)_yDirection).Material.Diffuse = Vector4.Zero;

            _zDirection.Scale = new Vector3(0.5f, 0.5f, ArrowLength);
            _zDirection.Position = new Vector3(0, 0, (ArrowLength / 2.0f) - 0.25f);
            ((Cube)_zDirection).Material.Ambient = new Vector4(1, 0, 0, 1);
            ((Cube)_zDirection).Material.Diffuse = Vector4.Zero;

            Scale = new Vector3(0.1f, 0.1f, 0.1f);

            Designer = true;

            UniformSphere.Material.Ambient = new Vector4(1, 1, 1, 1);
            UniformSphere.Scale = new Vector3(3);
            UniformSphere.Visible = ShowUniformSphere;
            UniformSphere.Enabled = ShowUniformSphere;
        }