/// <summary> /// A cube with edge size with position shapePosition vector3 with a face color /// </summary> /// <param name="size"></param> /// <param name="shapePosition"></param> public Cube3D(float size, Vector3 shapePosition, Color facesColor, bool useTexture = false, int textureId = 0) { ShapeMesh = Mesh.Cube(size); Position = shapePosition; ShapeVersorsUVW = Matrix4.Identity; faceColors(facesColor); this.useTexture = useTexture; TextureID = textureId; LightPosition = new Vector3(1000f, 1000f, 1000f); if (useTexture) { TexCoords = LoadTexCoords(); // initialize shaders string vs = File.ReadAllText("Shaders\\vShader_UV_Normal.txt"); string fs = File.ReadAllText("Shaders\\fShader_UV_Normal.txt"); Shader = new Shader(ref vs, ref fs); // initialize buffer VertexFormat = NRCGL.VertexFormat.XYZ_NORMAL_UV; VertexBuffer = new VertexFloatBuffer(VertexFormat); } else { // initialize shaders string vs = File.ReadAllText("Shaders\\vShader_Color_Normal.txt"); string fs = File.ReadAllText("Shaders\\fShader_Color_Normal.txt"); Shader = new Shader(ref vs, ref fs); // initialize buffer VertexFormat = NRCGL.VertexFormat.XYZ_NORMAL_COLOR; VertexBuffer = new VertexFloatBuffer(VertexFormat); } }
public TextRender(int width, int height, Vector2 position, FontFamily fontFamily, float fontSize = 12, bool visible = true) { Width = width; Height = height; Position = position; Font = new System.Drawing.Font(fontFamily, fontSize, System.Drawing.FontStyle.Regular); TextBrush = Brushes.White; BackgroundColor = Color.FromArgb(150, 0, 0, 0); FontStyle = System.Drawing.FontStyle.Regular; Visible = visible; VertexsIndicesData = Tools.DeserializeModel(@"Models\Panel3D.xml"); // initialize shaders string vs = File.ReadAllText("Shaders\\vShader_UV_Text.txt"); string fs = File.ReadAllText("Shaders\\fShader_UV_Text.txt"); Shader = new Shader(ref vs, ref fs, this); // initialize buffer VertexFormat = NRCGL.VertexFormat.XY_UV; VertexBuffer = new VertexFloatBuffer(VertexFormat, 512); }
/// <summary> /// A cube with edge size at position (0,0,0) with default face colors /// </summary> /// <param name="size">size of the cube edge</param> public Cube3D(float size) { ShapeMesh = Mesh.Cube(size); Position = Vector3.Zero; useTexture = false; ShapeVersorsUVW = Matrix4.Identity; LightPosition = new Vector3(1000f, 1000f, 1000f); // initialize shaders string vs = File.ReadAllText("Shaders\\vShader_Color_Normal.txt"); string fs = File.ReadAllText("Shaders\\fShader_Color_Normal.txt"); Shader = new Shader(ref vs, ref fs); // initialize buffer VertexFormat = NRCGL.VertexFormat.XYZ_NORMAL_COLOR; VertexBuffer = new VertexFloatBuffer(VertexFormat); }
/// <summary> /// Draw shape to buffer using VertexFormat /// </summary> /// <param name="buffer"></param> /// <param name="vertexFormat"></param> public virtual void DrawBufer(VertexFloatBuffer buffer, VertexFormat vertexFormat) { switch (vertexFormat) { case VertexFormat.XY: break; case VertexFormat.XY_COLOR: break; case VertexFormat.XY_UV: break; case VertexFormat.XY_UV_COLOR: break; case VertexFormat.XYZ: break; case VertexFormat.XYZ_COLOR: break; case VertexFormat.XYZ_UV: break; case VertexFormat.XYZ_UV_COLOR: break; case VertexFormat.XYZ_NORMAL_COLOR: #region xyz_normal_color foreach (Vertex vertex in VertexsIndicesData.Vertexs) { buffer.AddVertex(vertex.Position.X, vertex.Position.Y, vertex.Position.Z, vertex.Normal.X, vertex.Normal.Y, vertex.Normal.Z, vertex.Color.R, vertex.Color.G, vertex.Color.B, vertex.Color.A); } #endregion break; case VertexFormat.XYZ_NORMAL_UV: #region xyz_normal_uv foreach (Vertex vertex in VertexsIndicesData.Vertexs) { buffer.AddVertex(vertex.Position.X, vertex.Position.Y, vertex.Position.Z, vertex.Normal.X, vertex.Normal.Y, vertex.Normal.Z, vertex.TexCoord.X, vertex.TexCoord.Y); } #endregion break; case VertexFormat.XYZ_NORMAL: #region xyz_normal foreach (Vertex vertex in VertexsIndicesData.Vertexs) { buffer.AddVertex(vertex.Position.X, vertex.Position.Y, vertex.Position.Z, new Vector3(vertex.Normal.X, vertex.Normal.Y, vertex.Normal.Z)); } #endregion break; case VertexFormat.XYZ_NORMAL_UV_COLOR: #region xyz_normal_uv_color foreach (Vertex vertex in VertexsIndicesData.Vertexs) { buffer.AddVertex(vertex.Position.X, vertex.Position.Y, vertex.Position.Z, vertex.Normal.X, vertex.Normal.Y, vertex.Normal.Z, vertex.TexCoord.X, vertex.TexCoord.Y, vertex.Color.R, vertex.Color.G, vertex.Color.B, vertex.Color.A); } #endregion break; default: break; } }
public Sphere3D(Vector3 position, float r, Color4 color, int textureId = 0, bool isSmoothShading = true) : base() { this.r = r; IsSmoothShading = isSmoothShading; Bounding = new Bounding(this, r); Model = @"Models\sphere3D.xml"; if (isSmoothShading) { // smooth shading if (vid_smooth is VertexsIndicesData) { VertexsIndicesData = vid_smooth; } else { vid_smooth = Tools.DeserializeModel(@"Models\sphere3D_smooth.xml"); VertexsIndicesData = vid_smooth; } } else { // flat shading if (vid is VertexsIndicesData) { VertexsIndicesData = vid; } else { vid = Tools.DeserializeModel(Model); VertexsIndicesData = vid; } } Scale(r); Position = position; FirstPosition = Position; ShapeVersorsUVW = Matrix4.Identity; TextureID = textureId; if (textureId == 0) { foreach (Vertex vertex in VertexsIndicesData.Vertexs) { vertex.Color = color; } // initialize shaders string vs = File.ReadAllText("Shaders\\vShader_Color_Normal1.txt"); string fs = File.ReadAllText("Shaders\\fShader_Color_Normal1.txt"); Shader = new Shader(ref vs, ref fs, this); // initialize buffer VertexFormat = NRCGL.VertexFormat.XYZ_NORMAL_COLOR; VertexBuffer = new VertexFloatBuffer(VertexFormat, 97920, BeginMode.Triangles); } else { // initialize shaders string vs = File.ReadAllText("Shaders\\vShader_UV_Normal.txt"); string fs = File.ReadAllText("Shaders\\fShader_UV_Normal_sphere.txt"); Shader = new Shader(ref vs, ref fs, this); // initialize buffer VertexFormat = NRCGL.VertexFormat.XYZ_NORMAL_UV_COLOR; VertexBuffer = new VertexFloatBuffer(VertexFormat, 97920); } }
/// <summary> /// Draws buffer. /// </summary> /// <param name="buffer"></param> /// <param name="vertexFormat"></param> public override void DrawBufer(VertexFloatBuffer buffer, VertexFormat vertexFormat) { switch (vertexFormat) { case VertexFormat.XY: break; case VertexFormat.XY_COLOR: break; case VertexFormat.XY_UV: break; case VertexFormat.XY_UV_COLOR: break; case VertexFormat.XYZ: break; case VertexFormat.XYZ_COLOR: break; case VertexFormat.XYZ_UV: break; case VertexFormat.XYZ_UV_COLOR: break; case VertexFormat.XYZ_NORMAL_COLOR: #region xyz_normal_color int count = 0; Vector4 color = Vector4.Zero; foreach (Matrix4 matrix4 in ShapeMesh) { switch (count) { case 0: color = Tools.ColorToVector4(frontFaceColor); break; case 2: color = Tools.ColorToVector4(rightFaceColor); break; case 4: color = Tools.ColorToVector4(topFaceColor); break; case 6: color = Tools.ColorToVector4(bottomFaceColor); break; case 8: color = Tools.ColorToVector4(leftFaceColor); break; case 10: color = Tools.ColorToVector4(backFaceColor); break; default: break; } buffer.AddVertex(matrix4.Row0.X, matrix4.Row0.Y, matrix4.Row0.Z, matrix4.Row3.X, matrix4.Row3.Y, matrix4.Row3.Z, color.X, color.Y, color.Z, color.W); buffer.AddVertex(matrix4.Row1.X, matrix4.Row1.Y, matrix4.Row1.Z, matrix4.Row3.X, matrix4.Row3.Y, matrix4.Row3.Z, color.X, color.Y, color.Z, color.W); buffer.AddVertex(matrix4.Row2.X, matrix4.Row2.Y, matrix4.Row2.Z, matrix4.Row3.X, matrix4.Row3.Y, matrix4.Row3.Z, color.X, color.Y, color.Z, color.W); count++; } #endregion break; case VertexFormat.XYZ_NORMAL_UV: #region xyz_normal_uv_color if (useTexture == false) { throw new ApplicationException("Use texture must be true."); } int count1 = 0; foreach (Matrix4 matrix4 in ShapeMesh) { buffer.AddVertex(matrix4.Row0.X, matrix4.Row0.Y, matrix4.Row0.Z, matrix4.Row3.X, matrix4.Row3.Y, matrix4.Row3.Z, TexCoords[count1].Row0.X, 1 - TexCoords[count1].Row0.Y); buffer.AddVertex(matrix4.Row1.X, matrix4.Row1.Y, matrix4.Row1.Z, matrix4.Row3.X, matrix4.Row3.Y, matrix4.Row3.Z, TexCoords[count1].Row1.X, 1 - TexCoords[count1].Row1.Y); buffer.AddVertex(matrix4.Row2.X, matrix4.Row2.Y, matrix4.Row2.Z, matrix4.Row3.X, matrix4.Row3.Y, matrix4.Row3.Z, TexCoords[count1].Row2.X, 1 - TexCoords[count1].Row2.Y); count1++; } #endregion break; case VertexFormat.XYZ_NORMAL_UV_COLOR: #region xyz_normal_uv_color if (useTexture == false) { throw new ApplicationException("Use texture must be true."); } int count2 = 0; Vector4 color1 = Vector4.Zero; foreach (Matrix4 matrix4 in ShapeMesh) { switch (count2) { case 0: color1 = Tools.ColorToVector4(frontFaceColor); break; case 2: color1 = Tools.ColorToVector4(rightFaceColor); break; case 4: color1 = Tools.ColorToVector4(topFaceColor); break; case 6: color = Tools.ColorToVector4(bottomFaceColor); break; case 8: color1 = Tools.ColorToVector4(leftFaceColor); break; case 10: color1 = Tools.ColorToVector4(backFaceColor); break; default: break; } buffer.AddVertex(matrix4.Row0.X, matrix4.Row0.Y, matrix4.Row0.Z, matrix4.Row3.X, matrix4.Row3.Y, matrix4.Row3.Z, TexCoords[count2].Row0.X, TexCoords[count2].Row0.Y, color1.X, color1.Y, color1.Z, color1.W); buffer.AddVertex(matrix4.Row1.X, matrix4.Row1.Y, matrix4.Row1.Z, matrix4.Row3.X, matrix4.Row3.Y, matrix4.Row3.Z, TexCoords[count2].Row1.X, TexCoords[count2].Row1.Y, color1.X, color1.Y, color1.Z, color1.W); buffer.AddVertex(matrix4.Row2.X, matrix4.Row2.Y, matrix4.Row2.Z, matrix4.Row3.X, matrix4.Row3.Y, matrix4.Row3.Z, TexCoords[count2].Row2.X, TexCoords[count2].Row2.Y, color1.X, color1.Y, color1.Z, color1.W); count2++; } #endregion break; default: break; } }