Beispiel #1
0
        private static void OnRenderFrame()
        {
            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit
                     | ClearBufferMask.DepthBufferBit);

            //Use shader
            Gl.UseProgram(program);

            //Drawing cube
            #region
            int num = 0;
            for (int j = 0; j < maxY; j++)
            {
                for (int i = 0; i < maxX; i++)
                {
                    if (num == numShapes)
                    {
                        break;
                    }

                    //select texture
                    if (texRandom[num] == 0)
                    {
                        Gl.BindTexture(crateTexture);
                    }
                    else if (texRandom[num] == 1)
                    {
                        Gl.BindTexture(rectTexture);
                    }
                    else
                    {
                        Gl.BindTexture(pyTexture);
                    }

                    //set translation offset
                    program["model_matrix"].SetValue(
                        Matrix4.CreateScaling(new Vector3(0.5f, 0.5f, 0.5f)) *
                        Matrix4.CreateTranslation(new Vector3(-3 + i * 1.1f, 1.5f - j * 1.1f, 0)));
                    Gl.BindBufferToShaderAttribute(cube, program, "vertexPosition");
                    Gl.BindBufferToShaderAttribute(cubeUV, program, "vertexUV");
                    Gl.BindBuffer(cubeElements);
                    //Dibuja el cube
                    Gl.DrawElements(BeginMode.Quads, cubeElements.Count,
                                    DrawElementsType.UnsignedInt, IntPtr.Zero);
                    num++;
                }
                if (num == numShapes)
                {
                    break;
                }
            }

            #endregion

            Glut.glutSwapBuffers();
        }
Beispiel #2
0
 private static void DrawChessBoard(float centerX, float centerY, float CenterZ, float width_x, float depth_z, Texture texture)
 {
     Gl.UseProgram(program);
     Gl.BindTexture(texture);
     Gl.BindBufferToShaderAttribute(panel, program, "vertexPosition");
     Gl.BindBufferToShaderAttribute(panelUV, program, "vertexUV");
     Gl.BindBuffer(panelTriangles);
     program["model_matrix"].SetValue(Matrix4.CreateScaling(new Vector3(width_x, 1, depth_z)) * Matrix4.CreateTranslation(new Vector3(centerX - width_x / 2, centerY, CenterZ - depth_z / 2)));
     Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
 }
        public void Update(long elapsedMilliseconds)
        {
            rot += (float)(GameTime.ElapsedSeconds * 15.0f);
            var scalefactor = (float)(12.0f * Math.Sin(rot * 0.1f) * Math.Sin(rot * 0.1f) + 2);

            var rotAxis = new Vector3(0.0f, 1.0f, 0.0f);

            rotAxis = rotAxis.Normalize();
            var r = Matrix4.CreateRotation(rotAxis, MathHelper.ToRads(rot * 16));

            model = Matrix4.CreateScaling(new Vector3(scalefactor, scalefactor, scalefactor)) * r;
        }
Beispiel #4
0
        private static void Draw3Corner(float x, float y, float z, float width, float height, float depth, Matrix4 quaternion, Texture texture_panel, Texture texture_corner)
        {
            //quaternion = Matrix4.Identity;

            Gl.UseProgram(program);


            Gl.BindTexture(texture_panel);
            Gl.BindBufferToShaderAttribute(panel, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(panelUV, program, "vertexUV");
            Gl.BindBuffer(panelTriangles);

            program["model_matrix"].SetValue(Matrix4.CreateScaling(new Vector3(width / 2, height, depth / 2)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.BindTexture(texture_panel);

            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 2, height / 2, depth / 2)) * Matrix4.CreateTranslation(new Vector3(0, height / 2, depth)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.BindTexture(texture_panel);

            program["model_matrix"].SetValue(Matrix4.CreateScaling(new Vector3(width / 2, height, depth / 2)) * Matrix4.CreateTranslation(new Vector3(0, height / 2, depth / 2)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.BindTexture(texture_panel);

            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 2, height / 2, depth / 2)) * Matrix4.CreateTranslation(new Vector3(0, 0, depth / 2)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.BindTexture(texture_panel);

            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitZ, -(float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 2, height / 2, depth / 2)) * Matrix4.CreateTranslation(new Vector3(width / 2, height, depth / 2)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.BindTexture(texture_panel);

            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitZ, -(float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 2, height / 2, depth / 2)) * Matrix4.CreateTranslation(new Vector3(width / 2, height / 2, 0)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.BindTexture(texture_panel);

            program["model_matrix"].SetValue(Matrix4.CreateScaling(new Vector3(width / 2, height, depth / 2)) * Matrix4.CreateTranslation(new Vector3(width / 2, height / 2, 0)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.BindTexture(texture_panel);

            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 2, height / 2, depth / 2)) * Matrix4.CreateTranslation(new Vector3(width / 2, height / 2, depth / 2)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.BindTexture(texture_panel);

            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitZ, -(float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 2, height / 2, depth / 2)) * Matrix4.CreateTranslation(new Vector3(width, height, 0)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); Gl.BindTexture(texture_panel);

            Gl.BindTexture(texture_corner);
            Gl.BindBufferToShaderAttribute(corner, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(cornerUV, program, "vertexUV");
            Gl.BindBuffer(cornerTriangles);

            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitZ, -(float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width, height, depth)) * Matrix4.CreateTranslation(new Vector3(0, height, 0)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, cornerTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            program["model_matrix"].SetValue(Matrix4.CreateScaling(new Vector3(width, height, depth)) * Matrix4.CreateTranslation(new Vector3(0, height, 0)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, cornerTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, (float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width, height, depth)) * Matrix4.CreateTranslation(new Vector3(0, height, 0)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, cornerTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
        }
Beispiel #5
0
        public GeometryAuxWeight(Geometry geometry)
        {
            m_mtx_zoom_in_y   = Matrix4.CreateScaling(1, 100);
            m_mtx_zoom_out_y  = Matrix4.CreateScaling(1, 1.0 / 100.0);
            m_trans_zoom_in_y = GeometryMatrix4Transformer.CreateOptimizedTransformer(geometry, m_mtx_zoom_in_y);
            m_contour         = new GeometryContour(m_trans_zoom_in_y);
            m_trans_zoom_out  = GeometryMatrix4Transformer.CreateOptimizedTransformer(m_contour, m_mtx_zoom_out_y);

            m_contour.AutoDetectOrientation = false;

            Geometry = m_trans_zoom_out;
        }
Beispiel #6
0
        private static void DrawCross(float x, float y, float z, float width, float height, float depth, Matrix4 quaternion, Texture texture_panel, Texture texture_cross)
        {
            Gl.UseProgram(program);
            Gl.BindTexture(texture_panel);
            Gl.BindBufferToShaderAttribute(panel, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(panelUV, program, "vertexUV");
            Gl.BindBuffer(panelTriangles);

            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 4, height, depth / 4)) * Matrix4.CreateTranslation(new Vector3(0, 0, depth)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateFromAxisAngle(Vector3.UnitY, (float)Math.PI / 4) * Matrix4.CreateScaling(new Vector3(1.414f * width / 4, height, 1.414f * depth / 4)) * Matrix4.CreateTranslation(new Vector3(width / 4, 0, depth)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateFromAxisAngle(Vector3.UnitY, -(float)Math.PI / 4) * Matrix4.CreateScaling(new Vector3(1.414f * width / 4, height, 1.414f * depth / 4)) * Matrix4.CreateTranslation(new Vector3(width / 2, 0, depth * 0.75f)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 4, height, depth / 4)) * Matrix4.CreateTranslation(new Vector3(0.75f * width, 0, depth)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitZ, (float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 4, height, depth / 4)) * Matrix4.CreateTranslation(new Vector3(width, 0, 0.75f * depth)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateFromAxisAngle(Vector3.UnitY, -(float)Math.PI / 4) * Matrix4.CreateScaling(new Vector3(1.414f * width / 4, height, 1.414f * depth / 4)) * Matrix4.CreateTranslation(new Vector3(0.75f * width, 0, depth * 0.5f)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateFromAxisAngle(Vector3.UnitY, (float)Math.PI / 4) * Matrix4.CreateScaling(new Vector3(1.414f * width / 4, height, 1.414f * depth / 4)) * Matrix4.CreateTranslation(new Vector3(width * 0.75f, 0, depth * 0.5f)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitZ, (float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 4, height, depth / 4)) * Matrix4.CreateTranslation(new Vector3(width, 0, 0)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 4, height, depth / 4)) * Matrix4.CreateTranslation(new Vector3(0.75f * width, 0, 0)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateFromAxisAngle(Vector3.UnitY, (float)Math.PI / 4) * Matrix4.CreateScaling(new Vector3(1.414f * width / 4, height, 1.414f * depth / 4)) * Matrix4.CreateTranslation(new Vector3(width / 2, 0, depth / 4)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateFromAxisAngle(Vector3.UnitY, -(float)Math.PI / 4) * Matrix4.CreateScaling(new Vector3(1.414f * width / 4, height, 1.414f * depth / 4)) * Matrix4.CreateTranslation(new Vector3(width / 4, 0, 0)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 4, height, depth / 4)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitZ, (float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 4, height, depth / 4)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateFromAxisAngle(Vector3.UnitY, -(float)Math.PI / 4) * Matrix4.CreateScaling(new Vector3(1.414f * width / 4, height, 1.414f * depth / 4)) * Matrix4.CreateTranslation(new Vector3(0, 0, depth * 0.25f)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)Math.PI / 2) * Matrix4.CreateFromAxisAngle(Vector3.UnitY, (float)Math.PI / 4) * Matrix4.CreateScaling(new Vector3(1.414f * width / 4, height, 1.414f * depth / 4)) * Matrix4.CreateTranslation(new Vector3(0, 0, depth * 0.75f)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitZ, (float)Math.PI / 2) * Matrix4.CreateScaling(new Vector3(width / 4, height, depth / 4)) * Matrix4.CreateTranslation(new Vector3(0, 0, 0.75f * depth)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            Gl.UseProgram(program);
            Gl.BindTexture(texture_cross);
            Gl.BindBufferToShaderAttribute(cross, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(crossUV, program, "vertexUV");
            Gl.BindBuffer(crossTriangles);

            program["model_matrix"].SetValue(Matrix4.CreateScaling(new Vector3(width, height, depth)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, crossTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            program["model_matrix"].SetValue(Matrix4.CreateScaling(new Vector3(width, height, depth)) * Matrix4.CreateTranslation(new Vector3(0, height, 0)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            Gl.DrawElements(BeginMode.Triangles, crossTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
        }
Beispiel #7
0
        static void drawSquare(Square square)
        {
            Matrix4 scaling     = Matrix4.CreateScaling(square.size);
            Matrix4 translation = Matrix4.CreateTranslation(new Vector3(square.x, square.y, 0));

            program["model_matrix"].SetValue(scaling * translation);
            if (squareColor != null)
            {
                squareColor.Dispose();
            }
            squareColor = new VBO <Vector3>(new Vector3[] { square.color, square.color, square.color, square.color });
            Gl.BindBufferToShaderAttribute(squareColor, program, "vertexColor");
            Gl.DrawElements(BeginMode.Quads, squareElements.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
        }
Beispiel #8
0
        public static Matrix4 GetViewMatrix()
        {
            Matrix4 viewTranslation = Matrix4.Identity;
            Matrix4 viewRotation    = Matrix4.Identity;
            Matrix4 viewScale       = Matrix4.Identity;

            viewTranslation = Matrix4.CreateTranslation(new Vector3(-Camera.worldPosition.X, -Camera.worldPosition.Y, Camera.worldPosition.Z));
            viewRotation    = Matrix4.CreateRotation(new Vector3(0f, 1f, 0f), Camera.cameraYaw); // In radiant
            viewScale       = Matrix4.CreateScaling(new Vector3(1.0f, 1.0f, 1.0f));

            Matrix4 view = viewRotation * viewTranslation * viewScale;// RTS matrix -> scale, rotate then translate -> All applied in LOCAL Coordinates

            return(view);
        }
Beispiel #9
0
        int parse_scale(string str)
        {
            double[] args = new double[2];
            int      na   = 0;
            int      len  = parse_transform_args(str, args, ref na);

            if (na == 1)
            {
                args[1] = args[0];
            }
            m_SVGPath.Transform = m_SVGPath.Transform.Multiply(Matrix4.CreateScaling(args[0], args[1]), MatrixOrder.Append);

            return(len);
        }
Beispiel #10
0
 public void Draw(ShaderProgram program)
 {
     Gl.BindTexture(texture);
     program["model_matrix"].SetValue(
         Matrix4.CreateRotationX(rotation.X) *
         Matrix4.CreateRotationY(rotation.Y) *
         Matrix4.CreateRotationZ(rotation.Z) *
         Matrix4.CreateScaling(scale) *
         Matrix4.CreateTranslation(position));
     Gl.BindBufferToShaderAttribute(vertex, program, "vertexPosition");
     Gl.BindBufferToShaderAttribute(uvs, program, "vertexUV");
     Gl.BindBuffer(elements);
     Gl.DrawElements(BeginMode.Quads, elements.Count,
                     DrawElementsType.UnsignedInt, IntPtr.Zero);
 }
Beispiel #11
0
 public void Draw(ShaderProgram program)
 {
     #region
     Gl.BindTexture(texture);
     program["model_matrix"].SetValue(Matrix4.CreateRotation(rotation, angle) *
                                      Matrix4.CreateScaling(scale) *
                                      Matrix4.CreateTranslation(position));
     Gl.BindBufferToShaderAttribute(vertex, program, "vertexPosition");
     Gl.BindBufferToShaderAttribute(uvs, program, "vertexUV");
     Gl.BindBuffer(elements);
     //Dibuja el cube
     Gl.DrawElements(BeginMode.Triangles, elements.Count,
                     DrawElementsType.UnsignedInt, IntPtr.Zero);
     #endregion
 }
Beispiel #12
0
        public Matrix4 GetTRS()
        {
            Matrix4 modelTranslation = Matrix4.CreateTranslation(Position);
            Matrix4 modelRotationX   = Matrix4.CreateRotation(new Vector3(1.0f, 0.0f, 0.0f),
                                                              Mathf.ToRad(Rotation.X));
            Matrix4 modelRotationY = Matrix4.CreateRotation(new Vector3(0.0f, 1.0f, 0.0f),
                                                            Mathf.ToRad(Rotation.Y));
            Matrix4 modelRotationZ = Matrix4.CreateRotation(new Vector3(0.0f, 0.0f, 1.0f),
                                                            Mathf.ToRad(Rotation.Z));
            Matrix4 modelRotation = modelRotationX * modelRotationY * modelRotationZ;
            Matrix4 modelScale    = Matrix4.CreateScaling(Scale);
            Matrix4 model         = modelTranslation * modelRotation * modelScale;// Compose TRS matr

            return(model);
        }
Beispiel #13
0
        private static void DrawSphere(float x, float y, float z, float r, float n, Matrix4 quaternion, Texture texture)
        {
            float angle = (float)((Math.PI) / n);

            Gl.UseProgram(program_cylindre);
            Gl.BindTexture(texture);
            Gl.BindBufferToShaderAttribute(sphere, program_cylindre, "vertexPosition");
            Gl.BindBufferToShaderAttribute(sphereUV, program_cylindre, "vertexUV");
            Gl.BindBuffer(sphereTriangles);

            for (int i = 0; i < 2 * n; i++)
            {
                program_cylindre["ind"].SetValue(new Vector2(i, 2 * n));
                program["model_matrix"].SetValue(Matrix4.CreateScaling(new Vector3(r, r, r)) * Matrix4.CreateFromAxisAngle(Vector3.UnitY, -angle * i) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
                Gl.DrawElements(BeginMode.Triangles, sphereTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            }
        }
Beispiel #14
0
        protected override void OnPaint(GUI.PaintEventArgs e)
        {
            base.OnPaint(e);


            Graphics graphics = e.Graphics;

            graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
            graphics.SmoothingMode     = SmoothingMode.AntiAlias;


            Geometry outlinePath = GeometryMatrix4Transformer.
                                   CreateOptimizedTransformer(Common.GraphicsPath_AltSketch,
                                                              Matrix4.CreateScaling(0.9 * ClientWidth / Common.GraphicsPath_AltSketch_Bounds.Width));
            Rect  outlinePathBounds = outlinePath.Bounds;
            Point textOffset        = ((ClientSize - outlinePathBounds.Size) / 2).ToPoint();

            graphics.TranslateTransform(textOffset.X, textOffset.Y - outlinePathBounds.Top);


            GeometryVertexCommandAndFlags flag = GeometryVertexCommandAndFlags.None;

            if (rbCloseCW.IsChecked)
            {
                flag = GeometryVertexCommandAndFlags.FlagCW;
            }
            else if (rbCloseCCW.IsChecked)
            {
                flag = GeometryVertexCommandAndFlags.FlagCCW;
            }

            SpecialContourGeometry specialContourGeometry = new SpecialContourGeometry(outlinePath, flag);
            FlattenCurveGeometry   curve   = new FlattenCurveGeometry(specialContourGeometry);
            GeometryContour        contour = new GeometryContour(curve);

            contour.Width = m_WidthSlider.Value;
            contour.AutoDetectOrientation = m_AutoDetectCheckBox.IsChecked;


            graphics.FillGeometry(m_FillBrush, contour);
            graphics.DrawGeometry(m_ContourPen, contour);
        }
Beispiel #15
0
        private static void DrawCylinder(float x, float y, float z, float r, float h, float n, Matrix4 quaternion, Texture texture_cyrcle, Texture body)
        {
            Gl.UseProgram(program_cyrcle);
            Gl.BindTexture(texture_cyrcle);
            Gl.BindBufferToShaderAttribute(cyrcle, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(cyrcleUV, program, "vertexUV");
            Gl.BindBuffer(cyrcleTriangles);
            float angle = (float)((Math.PI * 2) / n);

            program_cyrcle["segment_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitY, angle));
            program_cyrcle["model_matrix"].SetValue(Matrix4.CreateScaling(new Vector3(r, r, r)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            for (int i = 0; i < n; i++)
            {
                program_cyrcle["rotate_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitY, angle * i));
                Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            }
            program_cyrcle["model_matrix"].SetValue(Matrix4.CreateScaling(new Vector3(r, r, r)) * Matrix4.CreateTranslation(new Vector3(0, h, 0)) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
            for (int i = 0; i < n; i++)
            {
                program_cyrcle["rotate_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitY, angle * i));
                Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            }
            Gl.UseProgram(program_cylindre);
            Gl.BindTexture(body);
            Gl.BindBufferToShaderAttribute(panel, program_cylindre, "vertexPosition");
            Gl.BindBufferToShaderAttribute(panelUV, program_cylindre, "vertexUV");
            Gl.BindBuffer(panelTriangles);
            float len = (float)Math.Sqrt((double)(2 * r * r - 2 * r * r * Math.Cos((double)angle)));

            for (int i = 0; i < n; i++)
            {
                program_cylindre["ind"].SetValue(new Vector2(i, n));
                program["model_matrix"].SetValue(Matrix4.CreateFromAxisAngle(Vector3.UnitX, -(float)(Math.PI / 2)) * Matrix4.CreateScaling(new Vector3(len, h, 0)) * Matrix4.CreateFromAxisAngle(Vector3.UnitY, (float)(Math.PI / 2) + angle / 2) * Matrix4.CreateTranslation(new Vector3(r, 0, 0)) * Matrix4.CreateFromAxisAngle(Vector3.UnitY, angle * i) * quaternion * Matrix4.CreateTranslation(new Vector3(x, y, z)));
                Gl.DrawElements(BeginMode.Triangles, panelTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            }
        }
Beispiel #16
0
        private void ParseGeometries(IEnumerable <XElement> geometryNodes, IEnumerable <XElement> visualSceneNodes)
        {
            int i = 0;

            foreach (var geometry in geometryNodes.Elements("geometry"))
            {
                String geometryId = geometry.Attribute("id").Value;
                Dictionary <String, float[]> floatArrays      = new Dictionary <string, float[]>();
                Dictionary <String, String>  positionToVertex = new Dictionary <string, string>();
                Dictionary <String, String>  normalToVertex   = new Dictionary <string, string>();

                //Get the transformation
                Matrix4 transformationMatrix = Matrix4.Identity;

                foreach (var node in visualSceneNodes.Elements("node"))
                {
                    if (node.Element("instance_geometry") != null && node.Element("instance_geometry").Attribute("url").Value.Replace("#", "").Equals(geometryId))
                    {
                        if (node.Element("matrix") != null)
                        {
                            transformationMatrix = ParseMatrix(node.Element("matrix").Value);
                            Matrix4 scaleMatrix = Matrix4.Scale(scale);
                            transformationMatrix = Matrix4.Mult(transformationMatrix, scaleMatrix);
                        }
                        else
                        {
                            Matrix4 rotationMatrix    = Matrix4.Identity;
                            Matrix4 translationMatrix = Matrix4.Identity;
                            Matrix4 scaleMatrix       = Matrix4.Identity;

                            //Rotation
                            translationMatrix    = Matrix4.CreateRotationX((float)-Math.PI / 2);
                            transformationMatrix = Matrix4.Mult(transformationMatrix, translationMatrix);
                            foreach (var rotation in node.Elements("rotate"))
                            {
                                if (rotation.Attribute("sid").Value.Equals("rotateX"))
                                {
                                    Matrix4 rotationX = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(float.Parse(rotation.Value)));
                                    rotationMatrix = Matrix4.Mult(rotationMatrix, rotationX);
                                }
                                else if (rotation.Attribute("sid").Value.Equals("rotateY"))
                                {
                                    Matrix4 rotationY = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(float.Parse(rotation.Value)));
                                    rotationMatrix = Matrix4.Mult(rotationMatrix, rotationY);
                                }
                                else if (rotation.Attribute("sid").Value.Equals("rotateZ"))
                                {
                                    Matrix4 rotationZ = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(float.Parse(rotation.Value)));
                                    rotationMatrix = Matrix4.Mult(rotationMatrix, rotationZ);
                                }
                                transformationMatrix = Matrix4.Mult(transformationMatrix, rotationMatrix);
                            }
                            //Translation
                            if (node.Element("translation") != null)
                            {
                                transformationMatrix.Translation = new Vector4(ParseVector(node.Element("translation").Value));
                            }
                            //Scaling
                            if (node.Element("scale") != null)
                            {
                                scaleMatrix          = Matrix4.CreateScaling(ParseVector(node.Element("scale").Value));
                                transformationMatrix = Matrix4.Mult(transformationMatrix, scaleMatrix);
                            }
                        }
                    }
                }

                //Parse the Float Arrays
                foreach (var source in geometry.Element("mesh").Elements("source"))
                {
                    String  key    = source.Attribute("id").Value.Replace("#", "");
                    float[] values = ParseFloatArray(source.Element("float_array").Value);
                    floatArrays.Add(key, values);
                }
                //Get the vertices
                foreach (var source in geometry.Element("mesh").Elements("vertices"))
                {
                    String vertexID = source.Attribute("id").Value.Replace("#", "");
                    foreach (var element in source.Elements("input"))
                    {
                        if (element.Attribute("semantic").Value.Equals("POSITION"))
                        {
                            String positionId = element.Attribute("source").Value.Replace("#", "");
                            positionToVertex.Add(vertexID, positionId);
                        }
                        if (element.Attribute("semantic").Value.Equals("NORMAL"))
                        {
                            String normalId = element.Attribute("source").Value.Replace("#", "");
                            normalToVertex.Add(vertexID, normalId);
                        }
                    }
                }
                //Parse the Triangle

                #region TriangleMesh

                if (geometry.Element("mesh").Elements("triangles").Count() > 0)
                {
                    foreach (var source in geometry.Element("mesh").Elements("triangles"))
                    {
                        int    triangleCount = Convert.ToInt32(source.Attribute("count").Value);
                        String materialName  = source.Attribute("material").Value.Replace("-material", "");
                        //Parse Everything
                        IEnumerable <string> vertexArrayNames = from item in source.Elements("input")
                                                                where item.Attribute("semantic").Value == "VERTEX"
                                                                select item.Attribute("source").Value.Remove(0, 1);

                        IEnumerable <string> vertexArrayOffsets = from item in source.Elements("input")
                                                                  where item.Attribute("semantic").Value == "VERTEX"
                                                                  select item.Attribute("offset").Value;

                        IEnumerable <string> normalArrayNames = from item in source.Elements("input")
                                                                where item.Attribute("semantic").Value == "NORMAL"
                                                                select item.Attribute("source").Value.Remove(0, 1);

                        IEnumerable <string> normalArrayOffsets = from item in source.Elements("input")
                                                                  where item.Attribute("semantic").Value == "NORMAL"
                                                                  select item.Attribute("offset").Value;

                        IEnumerable <string> texCordArrayNames = from item in source.Elements("input")
                                                                 where item.Attribute("semantic").Value == "TEXCOORD"
                                                                 select item.Attribute("source").Value.Remove(0, 1);

                        IEnumerable <string> texCordArrayOffsets = from item in source.Elements("input")
                                                                   where item.Attribute("semantic").Value == "TEXCOORD"
                                                                   select item.Attribute("offset").Value;

                        String normalArrayName = normalArrayNames.FirstOrDefault();
                        if (!string.IsNullOrEmpty(normalArrayName))
                        {
                            normalArrayName = normalArrayName.Replace("#", "");
                        }
                        String vertexArrayName = vertexArrayNames.FirstOrDefault();
                        if (!string.IsNullOrEmpty(vertexArrayName))
                        {
                            vertexArrayName = vertexArrayName.Replace("#", "");
                        }
                        String texCordArrayName = texCordArrayNames.FirstOrDefault();
                        if (!string.IsNullOrEmpty(texCordArrayName))
                        {
                            texCordArrayName = texCordArrayName.Replace("#", "");
                        }

                        int normalOffset   = -1;
                        int vertexOffset   = -1;
                        int texCoordOffset = -1;

                        float[] normals   = null;
                        float[] vertices  = null;
                        float[] texCoords = null;

                        int[]  vertexIndices   = null;
                        int[]  normalIndices   = null;
                        int[]  texCoordIndices = null;
                        String indices         = source.Element("p").Value;

                        int count = 0;
                        count += vertexArrayNames.Count();
                        count += normalArrayNames.Count();
                        count += texCordArrayNames.Count();

                        if (!string.IsNullOrEmpty(normalArrayName))
                        {
                            int.TryParse(normalArrayOffsets.First(), out normalOffset);
                            normals = floatArrays[normalArrayName];
                        }
                        if (!string.IsNullOrEmpty(vertexArrayName))
                        {
                            int.TryParse(vertexArrayOffsets.First(), out vertexOffset);
                            vertices = floatArrays[positionToVertex[vertexArrayName]];
                        }
                        if (!string.IsNullOrEmpty(texCordArrayName))
                        {
                            int.TryParse(texCordArrayOffsets.First(), out texCoordOffset);
                            texCoords = floatArrays[texCordArrayName];
                        }
                        if (!string.IsNullOrEmpty(normalArrayName))
                        {
                            normalIndices = ParseTriangleIndices(indices, normalOffset, count, triangleCount);
                        }
                        if (!string.IsNullOrEmpty(vertexArrayName))
                        {
                            vertexIndices = ParseTriangleIndices(indices, vertexOffset, count, triangleCount);
                        }
                        if (!string.IsNullOrEmpty(texCordArrayName))
                        {
                            texCoordIndices = ParseTriangleIndices(indices, texCoordOffset, count, triangleCount);
                        }
                        //Create the Mesh
                        Material mat;

                        mat = Materials[materialName];

                        Mesh           m   = new Mesh(vertices, vertexIndices, normals, normalIndices, texCoords, texCoordIndices, mat);
                        BspAccelerator acc = new BspAccelerator();
                        acc.Construct(m);
                        Instance instance = new Instance(acc, transformationMatrix);
                        Meshes.Add(geometryId + "_" + i, instance);
                        i++;
                    }
                }

                #endregion
            }
        }
Beispiel #17
0
        private static void renderScene()
        {
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;

            watch.Restart();

            Vector3 preLoc      = camera.position;
            float   currentUnit = blocks[0].scale[0];

            // update our camera's position
            if (down)
            {
                camera.MoveRelative(Vector3.UnitZ * deltaTime * currentUnit * moveSpeed);
            }
            if (up)
            {
                camera.MoveRelative(-Vector3.UnitZ * deltaTime * currentUnit * moveSpeed);
            }
            if (left)
            {
                camera.MoveRelative(-Vector3.UnitX * deltaTime * currentUnit * moveSpeed);
            }
            if (right)
            {
                camera.MoveRelative(Vector3.UnitX * deltaTime * currentUnit * moveSpeed);
            }
            if (isFlying)
            {
                if (eKey)
                {
                    camera.MoveRelative(Vector3.UnitY * deltaTime * currentUnit * moveSpeed);
                }
                if (qKey)
                {
                    camera.MoveRelative(-Vector3.UnitY * deltaTime * currentUnit * moveSpeed);
                }
            }

            if (!isFlying) //figure out the camera's height based on the fractal geometry
            {
                List <float> surfaces = new List <float>();
                float        camX = camera.position[0], camZ = camera.position[2];

                for (int i = 0; i < blocks.Count(); ++i)
                {
                    float blockX = blocks[i].position[0];
                    float blockZ = blocks[i].position[2];
                    if (Math.Sqrt(Math.Pow(blockX - camX, 2) +
                                  Math.Pow(blockZ - camZ, 2)) < blocks[i].scale[0] * 1.5) //check to forgo calculations for blocks outside of user range
                    {
                        for (int n = 0; n < blocks[i].verticeData.Length; n = n + 3)      //for each face
                        {
                            if (blocks[i].normalData[n][1] > 0)                           //if the normal is pointing upwards
                            {
                                //determine the determinant between each edge of the face and the camera position.
                                //if the determinant lies on the same side of each edge, the camera is contained in the face when looking from above.
                                float[] determinants = new float[3];
                                float   transformedY = 0;
                                for (int x = 0; x < 3; ++x)
                                {
                                    Vector4 point1 = (new Vector4(blocks[i].verticeData[n + x], 1)
                                                      * Matrix4.CreateScaling(blocks[i].scale)
                                                      * Matrix4.CreateRotationY(blocks[i].yOrientation))
                                                     + new Vector4(blocks[i].position, 1);
                                    Vector4 point2 = (new Vector4(blocks[i].verticeData[n + (x + 1) % 3], 1)
                                                      * Matrix4.CreateScaling(blocks[i].scale)
                                                      * Matrix4.CreateRotationY(blocks[i].yOrientation))
                                                     + new Vector4(blocks[i].position, 1);
                                    determinants[x] = (point2.Get(0) - point1.Get(0)) * (camZ - point1.Get(2)) - (point2.Get(2) - point1.Get(2)) * (camX - point1.Get(0));
                                    transformedY    = point1.Get(1);
                                }

                                if ((Math.Sign(determinants[0]) == Math.Sign(determinants[1]) && Math.Sign(determinants[1]) == Math.Sign(determinants[2])) ||
                                    determinants[0] == 0 || determinants[1] == 0 || determinants[2] == 0)
                                {
                                    surfaces.Add(transformedY);
                                }
                            }
                        }
                    }
                }

                //loop through the surfaces and find the highest one the camera is still above.
                float highest = float.NegativeInfinity;
                for (int i = 0; i < surfaces.Count(); ++i)
                {
                    if ((camera.position[1]) > surfaces[i] && surfaces[i] > highest || camera.position[1] == 0)
                    {
                        highest = surfaces[i];
                    }
                }

                if (highest == float.NegativeInfinity) //camera is not above any surfaces
                {
                    camera.position = preLoc;
                }
                else
                {
                    camera.destY = highest + currentUnit * 2.5f;
                }

                camera.position[1] = camera.position[1] + Convert.ToSingle(Math.Pow((camera.destY - camera.position[1]) / 10, 1));
            }


            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // use our shader program
            Gl.UseProgram(program);

            program["view_matrix"].SetValue(camera.ViewMatrix);
            program["cameraPosition"].SetValue(camera.position);

            //draw faces
            program["model_matrix"].SetValue(Matrix4.CreateTranslation(new Vector3(0, 0, 0)));
            program["enable_lighting"].SetValue(lighting);
            program["isEdge"].SetValue(1f);

            Gl.BindBufferToShaderAttribute(drawVertices, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(drawNormals, program, "vertexNormal");
            Gl.BindBuffer(drawElements);

            Gl.DrawElements(BeginMode.Triangles, drawElements.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            //draw edges
            program["enable_lighting"].SetValue(false);
            program["isEdge"].SetValue(0.1f);

            Gl.BindBufferToShaderAttribute(drawEdges, program, "vertexPosition");
            Gl.BindBuffer(drawEdgeElements);

            Gl.DrawElements(BeginMode.Lines, drawEdgeElements.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            Glut.glutSwapBuffers();
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    Console.WriteLine("Input the number of levels to recurse. Must be greater than or equal to zero.\r\n" +
                                      "Mouse to look and WASD to move. Hold R to run. F to toggle fullscreen.\r\n" +
                                      "O to toggle between walking and flying. When flying, use E/Q to ascend/descend.");
                    if ((levelNum = Convert.ToInt32(Console.ReadLine())) >= 0)
                    {
                        break;
                    }
                }
                catch
                {
                    Console.WriteLine("Please input an integer greater than or equal to zero.");
                }
            }

            // init GLUT and create window
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE);   // multisampling purportedly "makes things beautiful!"
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("Fractal");

            // register main loop callbacks
            Glut.glutDisplayFunc(renderScene);
            Glut.glutIdleFunc(idle);
            Glut.glutCloseFunc(onClose);

            //register resize callback
            Glut.glutReshapeFunc(OnReshape);

            // register keyboard callbacks
            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            // register mouse callbacks
            Glut.glutMotionFunc(OnMove);
            Glut.glutPassiveMotionFunc(OnMove);

            //hide mouse
            Glut.glutSetCursor(Glut.GLUT_CURSOR_NONE);

            //enable depth testing
            Gl.Enable(EnableCap.DepthTest);

            //enable alpha blending
            Gl.Enable(EnableCap.Blend);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            //compile shader
            program = new ShaderProgram(VertexShader, FragmentShader);

            //make a camera
            camera = new Camera(new Vector3(0, 0, 0), Quaternion.Identity); //set the camera starting location here
            camera.SetDirection(new Vector3(0, 0, -1));

            // set the view and projection matrix
            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.90f, (float)width / height, 0.01f, 1000f));

            program["light_direction"].SetValue(new Vector3(-0.3f, -0.8f, -0.7f));  //pink
            program["light2_direction"].SetValue(new Vector3(0.7f, -0.8f, 0.3f));   //cyan
            program["light3_direction"].SetValue(new Vector3(0.3f, -0.8f, 0.7f));   //celadon
            program["light4_direction"].SetValue(new Vector3(-0.7f, -0.8f, -0.3f)); //yellow
            program["enable_lighting"].SetValue(lighting);

            //set background color
            Gl.ClearColor(0.99f, 0.93f, 0.85f, 1f);

            // load each block's model and decomposition rule from files and add to blockRef
            int fCount = Directory.GetFiles("assets", "*", SearchOption.TopDirectoryOnly).Length;

            for (int n = 0; n < fCount / 2; ++n)
            {
                List <Vector3> indexVertices = new List <Vector3>();
                List <Vector3> indexNormals  = new List <Vector3>();
                List <Vector3> vertices      = new List <Vector3>();
                List <Vector3> normals       = new List <Vector3>();
                List <Vector3> edgeVertices  = new List <Vector3>();

                StreamReader sr = new StreamReader("assets/" + n.ToString() + ".txt");
                while (!sr.EndOfStream)
                {
                    string[] fields = sr.ReadLine().Split();
                    if (fields[0] == "v") //a vertex
                    {
                        Vector3 vertex = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3]));
                        indexVertices.Add(vertex);
                    }
                    else if (fields[0] == "vn") //a vertex normal
                    {
                        Vector3 normal = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3]));
                        indexNormals.Add(normal);
                    }
                    else if (fields[0] == "f") //a face
                    {
                        for (int i = 1; i < fields.Length; ++i)
                        {
                            string[] indices = fields[i].Split('/');
                            vertices.Add(indexVertices[Convert.ToInt32(indices[0]) - 1]);
                            normals.Add(indexNormals[Convert.ToInt32(indices[2]) - 1]);
                        }
                    }
                    else if (fields[0] == "l") //an edge
                    {
                        edgeVertices.Add(indexVertices[Convert.ToInt32(fields[1]) - 1]);
                        edgeVertices.Add(indexVertices[Convert.ToInt32(fields[2]) - 1]);
                    }
                }
                sr.Close();

                //create the block object
                Block newBlock = new Block();
                newBlock.position     = new Vector3(0, 0, 0);
                newBlock.yOrientation = 0;
                newBlock.scale        = new Vector3(1, 1, 1);
                newBlock.ID           = n;

                //fill the block object with data loaded from .obj above
                newBlock.verticeData = vertices.ToArray();
                newBlock.normalData  = normals.ToArray();

                newBlock.edgeVerticeData = edgeVertices.ToArray();

                blockRef.Add(newBlock);

                //load the decomposition rule for this block
                List <DecompBlock> newDRule = new List <DecompBlock>();
                float scaleConst            = 1;
                float unitConst             = 1;

                sr = new StreamReader("assets/" + n.ToString() + "rule.txt");
                while (!sr.EndOfStream)
                {
                    string[] fields = sr.ReadLine().Split();
                    if (fields[0] != "#") //check its not a comment
                    {
                        if (fields[0] == "!")
                        {
                            //setting scale down values. e.g. if set to 1/3 and 2/3, each new block would be scaled down
                            //by 1/3, and each 1 unit offset written in the rule file would be scaled to move the block 2/3 units instead.
                            //default 1 and 1: no scaling applied.
                            scaleConst = Convert.ToSingle(fields[1]);
                            unitConst  = Convert.ToSingle(fields[2]);
                        }
                        else
                        {
                            //load in fields
                            DecompBlock newDBlock = new DecompBlock();
                            newDBlock.ID             = Convert.ToInt32(fields[0]);
                            newDBlock.posOffset      = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3]));
                            newDBlock.xAngleOffset   = Convert.ToSingle(fields[4]);
                            newDBlock.extraScale     = new Vector3(1, 1, 1);
                            newDBlock.unitScaleConst = unitConst;
                            newDBlock.scaleDownConst = scaleConst;
                            if (fields.Length > 5)
                            {
                                newDBlock.extraScale = new Vector3(Convert.ToInt32(fields[5]), Convert.ToInt32(fields[6]), Convert.ToInt32(fields[7]));
                            }

                            //add block to rule
                            newDRule.Add(newDBlock);
                        }
                    }
                }
                sr.Close();

                decompRules.Add(newDRule);
            }

            Block seedBlock = blockRef[0];

            blocks = Decompose(seedBlock, levelNum);

            //merge all vertices and normals into a an interleaved vbo
            List <Vector3> preVertices = new List <Vector3>();
            List <Vector3> preNormals  = new List <Vector3>();
            List <Vector3> preEdges    = new List <Vector3>();

            foreach (Block block in blocks)
            {
                foreach (Vector3 point in block.verticeData)
                {
                    Vector4 preVertex = (new Vector4(point, 1)
                                         * Matrix4.CreateScaling(block.scale)
                                         * Matrix4.CreateRotationY(block.yOrientation)
                                         + new Vector4(block.position, 1));
                    preVertices.Add(new Vector3(preVertex.Get(0), preVertex.Get(1), preVertex.Get(2)));
                }

                foreach (Vector3 normal in block.normalData)
                {
                    Vector4 preNormal = (new Vector4(normal, 1)
                                         * Matrix4.CreateScaling(new Vector3(Math.Sign(block.scale[0]),
                                                                             Math.Sign(block.scale[1]),
                                                                             Math.Sign(block.scale[2])))
                                         * Matrix4.CreateRotationY(block.yOrientation));

                    preNormals.Add(new Vector3(Convert.ToSingle(Math.Round(preNormal.Get(0))),
                                               Convert.ToSingle(Math.Round(preNormal.Get(1))),
                                               Convert.ToSingle(Math.Round(preNormal.Get(2)))));
                }

                foreach (Vector3 point in block.edgeVerticeData)
                {
                    Vector4 preVertex = (new Vector4(point, 1)
                                         * Matrix4.CreateScaling(block.scale)
                                         * Matrix4.CreateRotationY(block.yOrientation)
                                         + new Vector4(block.position, 1));
                    preEdges.Add(new Vector3(preVertex.Get(0), preVertex.Get(1), preVertex.Get(2)));
                }
            }

            //exportOBJ(preVertices, preNormals); //exports fractal if left uncommented

            drawVertices = new VBO <Vector3>(preVertices.ToArray());
            drawNormals  = new VBO <Vector3>(preNormals.ToArray());
            drawEdges    = new VBO <Vector3>(preEdges.ToArray());

            List <uint> drawOrder = new List <uint>();

            for (int x = 0; x < preVertices.Count; ++x)
            {
                drawOrder.Add(Convert.ToUInt32(x));
            }
            drawElements = new VBO <uint>(drawOrder.ToArray(), BufferTarget.ElementArrayBuffer);

            drawOrder.Clear();
            for (int x = 0; x < preEdges.Count; ++x)
            {
                drawOrder.Add(Convert.ToUInt32(x));
            }
            drawEdgeElements = new VBO <uint>(drawOrder.ToArray(), BufferTarget.ElementArrayBuffer);

            watch = System.Diagnostics.Stopwatch.StartNew();

            // enter GLUT event processing cycle
            Glut.glutMainLoop();
        }
Beispiel #19
0
        private static void OnRenderFrame()
        {
            //Clock tick used for animation
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;

            watch.Restart();
            angle += deltaTime;

            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit
                     | ClearBufferMask.DepthBufferBit);

            //Use shader
            Gl.UseProgram(program);

            //Drawing cube
            #region
            Gl.BindTexture(crateTexture);
            program["model_matrix"].SetValue(
                Matrix4.CreateRotationZ(angle * speedS) *
                Matrix4.CreateRotationY(angle * speedS) *
                Matrix4.CreateRotationX(angle * speedS) *
                Matrix4.CreateScaling(new Vector3(0.5f, 0.5f, 0.5f)) *
                Matrix4.CreateTranslation(new Vector3(0, 0, -5)));
            Gl.BindBufferToShaderAttribute(cube, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(cubeUV, program, "vertexUV");
            Gl.BindBuffer(cubeElements);
            //Dibuja el cube
            Gl.DrawElements(BeginMode.Quads, cubeElements.Count,
                            DrawElementsType.UnsignedInt, IntPtr.Zero);
            #endregion

            //Drawing rect
            #region
            Gl.BindTexture(rectTexture);
            program["model_matrix"].SetValue(
                Matrix4.CreateRotationY(angle * speedS) *
                Matrix4.CreateScaling(new Vector3(0.5f, 0.5f, 0.5f)) *
                Matrix4.CreateTranslation(new Vector3(-3, 0, -2)));
            Gl.BindBufferToShaderAttribute(rect, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(rectUV, program, "vertexUV");
            Gl.BindBuffer(rectElements);
            Gl.DrawElements(BeginMode.Quads, rectElements.Count,
                            DrawElementsType.UnsignedInt, IntPtr.Zero);
            #endregion

            //Drawing pyramid
            #region
            Gl.BindTexture(pyTexture);
            program["model_matrix"].SetValue(
                Matrix4.CreateRotationZ(angle * speedS) *
                Matrix4.CreateTranslation(new Vector3(2, 0, -2)));
            Gl.BindBufferToShaderAttribute(pyramid, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(pyUV, program, "vertexUV");
            Gl.BindBuffer(pyramidElements);
            Gl.DrawElements(BeginMode.Triangles, pyramidElements.Count,
                            DrawElementsType.UnsignedInt, IntPtr.Zero);
            #endregion

            Glut.glutSwapBuffers();
        }
Beispiel #20
0
 public static Matrix4 ModelMatrix(Vector3 scale, Vector3 rotation, Vector3 translation)
 {
     return(Matrix4.CreateScaling(scale) * Matrix4.CreateRotationX(rotation.x) * Matrix4.CreateRotationY(rotation.y) * Matrix4.CreateRotationZ(rotation.z) * Matrix4.CreateTranslation(translation));
 }
Beispiel #21
0
 protected void UpdateModelMatrix()
 {
     modelMatrix    = orientation.Matrix4 * Matrix4.CreateScaling(scale) * Matrix4.CreateTranslation(location);
     modelMatrixOld = false;
 }
Beispiel #22
0
        private static void OnRenderFrame()
        {
            //Clock tick used for animation
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;

            watch.Restart();

            //Perfom rotations
            if (up)
            {
                theta += deltaTime;
            }
            if (down)
            {
                theta -= deltaTime;
            }
            if (left)
            {
                phi -= deltaTime;
            }
            if (right)
            {
                phi += deltaTime;
            }

            if (theta < 0)
            {
                theta += (float)Math.PI * 2;
            }

            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit
                     | ClearBufferMask.DepthBufferBit);

            //Use shader
            Gl.UseProgram(program);

            //Calculate something
            Gl.BindTexture(starTexture);
            Vector3 pos = 20 * new Vector3(
                (float)(Math.Cos(phi) * Math.Sin(theta)),
                (float)(Math.Cos(theta)),
                (float)(Math.Sin(phi) * Math.Sin(theta)));
            Vector3 upVector = ((theta % (Math.PI * 2)) > Math.PI) ?
                               new Vector3(0, 1, 0) :
                               new Vector3(0, -1, 0);

            program["view_matrix"].SetValue(Matrix4.LookAt(pos, Vector3.Zero, upVector));

            //Drawing stars
            #region
            for (int i = 0; i < numStars; i++)
            {
                program["model_matrix"].SetValue(
                    Matrix4.CreateScaling(new Vector3(0.1f, 0.1f, 0.1f)) *
                    Matrix4.CreateTranslation(new Vector3(s[i].dist * Math.Cos(s[i].dist), 0,
                                                          s[i].dist * -0.05 * Math.Cos(rng.NextDouble()))) *
                    Matrix4.CreateRotationZ(s[i].angle)
                    );
                // z = Math.Cos(s[i].angle + s[i].dist)
                // x = s[i].dist * Math.Cos(s[i].dist + s[i].angle)
                program["color"].SetValue(s[i].color);

                Gl.BindBufferToShaderAttribute(start, program, "vertexPosition");
                Gl.BindBufferToShaderAttribute(startUV, program, "vertexUV");
                Gl.BindBuffer(startElements);

                Gl.DrawElements(BeginMode.Quads, startElements.Count,
                                DrawElementsType.UnsignedInt, IntPtr.Zero);

                s[i].angle += (float)i / s.Count * deltaTime * (rng.Next(2, 4) * 2);
                s[i].dist  -= (1f * rng.Next(0, 2)) * deltaTime;

                if (s[i].dist < 0f)
                {
                    s[i].dist += 4f;
                    s[i].color = new Vector3(
                        (float)rng.NextDouble(),
                        (float)rng.NextDouble(),
                        (float)rng.NextDouble()
                        );
                }
            }
            #endregion

            Glut.glutSwapBuffers();
        }
Beispiel #23
0
        private static void OnRenderFrame()
        {
            //Clock tick used for animation
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;

            watch.Restart();

            //Perfom movement
            if (up)
            {
                playerY += speed;
            }
            if (down)
            {
                playerY -= speed;
            }
            if (left)
            {
                playerX -= speed;
            }
            if (right)
            {
                playerX += speed;
            }

            if (playerX > limX - 0.25f)
            {
                playerX = limX - 0.25f;
            }
            else if (playerX < -limX)
            {
                playerX = -limX;
            }
            //Clamp movement
            if (playerY > limY)
            {
                playerY = limY;
            }
            else if (playerY < -limY)
            {
                playerY = -limY;
            }

            if (shoot && timeShot <= 0)
            {
                Vector3 c = new Vector3(rng.NextDouble(), rng.NextDouble(), rng.NextDouble());
                shots.Add(new Shot(playerX + 0.6f, playerY, c));
                timeShot = speedShot;
            }

            if (timeEnemy <= 0)
            {
                float ey = (rng.Next() < 0.5)? -1: 1;
                ey *= (float)rng.NextDouble() * limY;
                float ex = limX + 0.5f;
                enemies.Add(new Shot(ex, ey, Vector3.One));
                timeEnemy = speedEnemy;
            }

            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit
                     | ClearBufferMask.DepthBufferBit);

            //Use shader
            Gl.UseProgram(program);
            program["color"].SetValue(playerColor);

            //Player Draw
            program["model_matrix"].SetValue(
                Matrix4.CreateScaling(new Vector3(0.5, 0.5, 0.5)) *
                Matrix4.CreateTranslation(new Vector3(playerX, playerY, 0))
                );
            Gl.BindTexture(playerTexture);
            Gl.BindBufferToShaderAttribute(player, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(playerUV, program, "vertexUV");
            Gl.BindBuffer(playerElements);

            Gl.DrawElements(BeginMode.Quads, playerElements.Count,
                            DrawElementsType.UnsignedInt, IntPtr.Zero);



            //Calculate something
            Gl.BindTexture(starTexture);
            for (int i = shots.Count - 1; i > 0; i--)
            {
                program["color"].SetValue(shots[i].color);

                program["model_matrix"].SetValue(
                    Matrix4.CreateScaling(new Vector3(0.3f, 0.3f, 0.3f)) *
                    Matrix4.CreateTranslation(new Vector3(shots[i].x, shots[i].y, 0))
                    );
                Gl.BindBufferToShaderAttribute(start, program, "vertexPosition");
                Gl.BindBufferToShaderAttribute(startUV, program, "vertexUV");
                Gl.BindBuffer(startElements);

                Gl.DrawElements(BeginMode.Quads, startElements.Count,
                                DrawElementsType.UnsignedInt, IntPtr.Zero);

                shots[i].x += Shot.speed;
                if (shots[i].x > limX)
                {
                    shots.RemoveAt(i);
                }
            }

            Gl.BindTexture(enemyTexture);
            for (int i = enemies.Count - 1; i > 0; i--)
            {
                program["color"].SetValue(enemies[i].color);

                program["model_matrix"].SetValue(
                    Matrix4.CreateScaling(new Vector3(0.5f, 0.5f, 0.5f)) *
                    Matrix4.CreateTranslation(new Vector3(enemies[i].x, enemies[i].y, 0))
                    );
                Gl.BindBufferToShaderAttribute(start, program, "vertexPosition");
                Gl.BindBufferToShaderAttribute(startUV, program, "vertexUV");
                Gl.BindBuffer(startElements);

                Gl.DrawElements(BeginMode.Quads, startElements.Count,
                                DrawElementsType.UnsignedInt, IntPtr.Zero);

                enemies[i].x -= Shot.speed * 0.3f;
                if (enemies[i].x < -limX - 0.7f)
                {
                    enemies.RemoveAt(i);
                }
            }

            timeShot  -= deltaTime;
            timeEnemy -= deltaTime;

            Glut.glutSwapBuffers();
        }
        void panel2_Paint(object sender, GUI.PaintEventArgs e)
        {
            Graphics graphics           = e.Graphics;
            bool     isSoftwareGraphics = graphics is SoftwareGraphics;

            //if (isSoftwareGraphics)
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
            }


            // Two simple paths
            if (rbGeometry5.IsChecked)
            {
                GraphicsPath ps1_path = new GraphicsPath();

                double x = m_X - m_DrawingPanel.ClientRectangle.Center.X / 2 + 100;
                double y = m_Y - m_DrawingPanel.ClientRectangle.Center.Y / 2 + 100;
                ps1_path.MoveTo(x + 140, y + 145);
                ps1_path.LineTo(x + 225, y + 44);
                ps1_path.LineTo(x + 296, y + 219);
                ps1_path.ClosePolygon();

                ps1_path.LineTo(x + 226, y + 289);
                ps1_path.LineTo(x + 82, y + 292);

                ps1_path.MoveTo(x + 220, y + 222);
                ps1_path.LineTo(x + 363, y + 249);
                ps1_path.LineTo(x + 265, y + 331);

                ps1_path.MoveTo(x + 242, y + 243);
                ps1_path.LineTo(x + 268, y + 309);
                ps1_path.LineTo(x + 325, y + 261);

                ps1_path.MoveTo(x + 259, y + 259);
                ps1_path.LineTo(x + 273, y + 288);
                ps1_path.LineTo(x + 298, y + 266);

                Rect ps1Bounds          = ps1_path.Bounds;
                GeometryTransformer ps1 = GeometryMatrix4Transformer.CreateOptimizedTransformer(ps1_path, Matrix4.CreateTranslation(
                                                                                                    m_X - ps1Bounds.Center.X,
                                                                                                    m_Y - ps1Bounds.Center.Y));


                GraphicsPath ps2_path = new GraphicsPath();
                ps2_path.MoveTo(100 + 32, 100 + 77);
                ps2_path.LineTo(100 + 473, 100 + 263);
                ps2_path.LineTo(100 + 351, 100 + 290);
                ps2_path.LineTo(100 + 354, 100 + 374);
                Rect ps2Bounds          = ps2_path.Bounds;
                GeometryTransformer ps2 = GeometryMatrix4Transformer.CreateOptimizedTransformer(ps2_path, Matrix4.CreateTranslation(
                                                                                                    (m_DrawingPanel.Width - ps2Bounds.Width) / 2 - ps2Bounds.Left,
                                                                                                    (m_DrawingPanel.Height - ps2Bounds.Height) / 2 - ps2Bounds.Top));


                graphics.FillGeometry(m_GeometryBColor, ps2);
                graphics.FillGeometry(m_GeometryAColor, ps1);

                CombinedGeometry clp = new CombinedGeometry(ps1, ps2, CombinedGeometry.CombineMode.Or, CombinedGeometry.FillType.NonZero, CombinedGeometry.FillType.NonZero);

                PerformRendering(graphics, clp);
            }
            // Closed stroke
            else if (rbGeometry4.IsChecked)
            {
                GraphicsPath ps1_path = new GraphicsPath();

                double x = m_X - m_DrawingPanel.ClientRectangle.Center.X / 2 + 100;
                double y = m_Y - m_DrawingPanel.ClientRectangle.Center.Y / 2 + 100;
                ps1_path.MoveTo(x + 140, y + 145);
                ps1_path.LineTo(x + 225, y + 44);
                ps1_path.LineTo(x + 296, y + 219);
                ps1_path.ClosePolygon();

                ps1_path.LineTo(x + 226, y + 289);
                ps1_path.LineTo(x + 82, y + 292);

                ps1_path.MoveTo(x + 220 - 50, y + 222);
                ps1_path.LineTo(x + 265 - 50, y + 331);
                ps1_path.LineTo(x + 363 - 50, y + 249);
                ps1_path.ClosePolygon(GeometryVertexCommandAndFlags.FlagCCW);

                Rect ps1Bounds          = ps1_path.Bounds;
                GeometryTransformer ps1 = GeometryMatrix4Transformer.CreateOptimizedTransformer(ps1_path, Matrix4.CreateTranslation(
                                                                                                    m_X - ps1Bounds.Center.X,
                                                                                                    m_Y - ps1Bounds.Center.Y));


                GraphicsPath ps2_path = new GraphicsPath();
                ps2_path.MoveTo(100 + 32, 100 + 77);
                ps2_path.LineTo(100 + 473, 100 + 263);
                ps2_path.LineTo(100 + 351, 100 + 290);
                ps2_path.LineTo(100 + 354, 100 + 374);
                ps2_path.ClosePolygon();
                Rect ps2Bounds          = ps2_path.Bounds;
                GeometryTransformer ps2 = GeometryMatrix4Transformer.CreateOptimizedTransformer(ps2_path, Matrix4.CreateTranslation(
                                                                                                    (m_DrawingPanel.Width - ps2Bounds.Width) / 2 - ps2Bounds.Left,
                                                                                                    (m_DrawingPanel.Height - ps2Bounds.Height) / 2 - ps2Bounds.Top));

                GeometryStroke stroke = new GeometryStroke(ps2, 10);


                graphics.FillGeometry(m_GeometryBColor, stroke);
                graphics.FillGeometry(m_GeometryAColor, ps1);

                CombinedGeometry clp = new CombinedGeometry(ps1, stroke, CombinedGeometry.CombineMode.Or, CombinedGeometry.FillType.NonZero, CombinedGeometry.FillType.NonZero);

                PerformRendering(graphics, clp);
            }
            // Great Britain and Arrows
            else if (rbGeometry3.IsChecked)
            {
                Geometry poly       = GreatBritain;
                Rect     polyBounds = poly.Bounds;
                double   scale      = 3;
                Matrix4  mtx        = Matrix4.CreateTranslation(-polyBounds.Center.X, -polyBounds.Center.Y);
                mtx *= Matrix4.CreateScaling(scale, scale);
                mtx *= Matrix4.CreateTranslation(m_DrawingPanel.Width / 2, m_DrawingPanel.Height / 2);
                GeometryTransformer trans_gb_poly = GeometryMatrix4Transformer.CreateOptimizedTransformer(poly, mtx);

                Geometry arrows       = Arrows;
                Rect     arrowsBounds = arrows.Bounds;
                mtx  = Matrix4.CreateTranslation(-arrowsBounds.Center.X, -arrowsBounds.Center.Y);
                mtx *= Matrix4.CreateScaling(scale, scale);
                mtx *= Matrix4.CreateTranslation(m_X, m_Y);
                GeometryTransformer trans_arrows = GeometryMatrix4Transformer.CreateOptimizedTransformer(arrows, mtx);

                CombinedGeometry clp = new CombinedGeometry(trans_gb_poly, trans_arrows,
                                                            CombinedGeometry.CombineMode.Or,
                                                            CombinedGeometry.FillType.NonZero,
                                                            CombinedGeometry.FillType.NonZero);

                graphics.FillGeometry(m_GeometryBColor, trans_gb_poly);
                graphics.DrawGeometry(isSoftwareGraphics ? m_GreatBritainContourPen_SWR : m_GreatBritainContourPen_HWR, trans_gb_poly);
                graphics.FillGeometry(m_GeometryAColor, trans_arrows);

                PerformRendering(graphics, clp);
            }
            // Great Britain and a Spiral
            else if (rbGeometry2.IsChecked)
            {
                Geometry poly       = GreatBritain;
                Rect     polyBounds = poly.Bounds;
                double   scale      = 3;
                Matrix4  mtx        = Matrix4.CreateTranslation(-polyBounds.Center.X, -polyBounds.Center.Y);
                mtx *= Matrix4.CreateScaling(scale, scale);
                mtx *= Matrix4.CreateTranslation(m_DrawingPanel.Width / 2, m_DrawingPanel.Height / 2);
                GeometryTransformer trans_gb_poly = GeometryMatrix4Transformer.CreateOptimizedTransformer(poly, mtx);

                Geometry       sp     = GeometryMatrix4Transformer.CreateOptimizedTransformer(Spiral, Matrix4.CreateTranslation(m_X, m_Y));
                GeometryStroke stroke = new GeometryStroke(sp, 15);

                CombinedGeometry clp = new CombinedGeometry(trans_gb_poly, stroke,
                                                            CombinedGeometry.CombineMode.Or,
                                                            CombinedGeometry.FillType.NonZero,
                                                            CombinedGeometry.FillType.NonZero);

                graphics.FillGeometry(m_GeometryBColor, trans_gb_poly);
                graphics.DrawGeometry(isSoftwareGraphics ? m_GreatBritainContourPen_SWR : m_GreatBritainContourPen_HWR, trans_gb_poly);
                graphics.DrawGeometry(m_SpiralPen, sp);

                PerformRendering(graphics, clp);
            }
            // Spiral and text
            else if (rbGeometry1.IsChecked)
            {
                Geometry            text            = Text;
                Rect                textBounds      = text.Bounds;
                GeometryTransformer transformedText = GeometryMatrix4Transformer.CreateOptimizedTransformer(text,
                                                                                                            Matrix4.CreateTranslation(
                                                                                                                (m_DrawingPanel.Width - textBounds.Width) / 2 - textBounds.Left,
                                                                                                                (m_DrawingPanel.Height - textBounds.Height) / 2 - textBounds.Top));

                Geometry       sp     = GeometryMatrix4Transformer.CreateOptimizedTransformer(Spiral, Matrix4.CreateTranslation(m_X, m_Y));
                GeometryStroke stroke = new GeometryStroke(sp, 15);

                CombinedGeometry clp = new CombinedGeometry(stroke, transformedText,
                                                            CombinedGeometry.CombineMode.Or,
                                                            CombinedGeometry.FillType.NonZero,
                                                            CombinedGeometry.FillType.NonZero);

                graphics.FillGeometry(m_GeometryBColor, transformedText);
                graphics.DrawGeometry(m_SpiralPen, sp);

                PerformRendering(graphics, clp);
            }
        }
Beispiel #25
0
 public Matrix4 GetTransformationMatrix() => Matrix4.CreateScaling(new Vector3(Scale.X, 0, Scale.Y)) * Matrix4.CreateTranslation(Position);
Beispiel #26
0
 public override void CalculateModelMatrix()
 {
     ModelMatrix = Matrix4.CreateScaling(Scale) * Matrix4.CreateRotationX(Rotation.X) * Matrix4.CreateRotationY(Rotation.Y) * Matrix4.CreateRotationZ(Rotation.Z) * Matrix4.CreateTranslation(Position);
 }