Exemplo n.º 1
0
 /// <summary>
 /// Create anew ASLight object
 /// </summary>
 /// <param name="ambient"></param>
 /// <param name="specular"></param>
 /// <param name="diffuse"></param>
 public ASLight(ASVECTOR4 ambient, ASVECTOR4 specular, ASVECTOR4 diffuse, ASVECTOR4 position)
 {
     this.ambient  = ambient;
     this.specular = specular;
     this.diffuse  = diffuse;
     this.position = position;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Blank light constructor, this will be used to create a white light
 /// </summary>
 public ASLight()
 {
     ambient = new ASVECTOR4();
     ambient.OneVector();
     specular = new ASVECTOR4();
     specular.OneVector();
     diffuse = new ASVECTOR4();
     diffuse.OneVector();
     position = new ASVECTOR4(0, 0, 0, 0);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Recieves the pointer to the current location of the StreamReader, from here we
        /// read all face information into the geometry buffer
        /// </summary>
        /// <param name="reader">Pointer to the current stream reader</param>
        /// <returns>True if the array was populated, else false, also sets last error in exception</returns>
        internal bool FillGeometryBuffer(StreamReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            try
            {
                // Loop numVertices times to build the vertex buffers
                for (var i = 0; i < m_numFaces; i++)
                {
                    // Values to hold the x,y,z position of this vertex
                    var nums = reader.ReadLine();
                    if (nums == null)
                    {
                        continue;
                    }
                    var bits = nums.Trim().Split(' ');

                    // Don't read from location 0 of bits as this contains the redundant 0 figure.
                    // We could attempt to trim "3" by removing it from array but this is simple for now.
                    // Get the int value of each point
                    var pA = int.Parse(bits[1]);
                    var pB = int.Parse(bits[2]);
                    var pC = int.Parse(bits[3]);

                    // Read the next three doubles from the file into x,y,z, we then create a new
                    // vector made from each point
                    var pointA = new ASVECTOR4(m_vertices[pA].Points[0], m_vertices[pA].Points[1], m_vertices[pA].Points[2]);
                    var pointB = new ASVECTOR4(m_vertices[pB].Points[0], m_vertices[pB].Points[1], m_vertices[pB].Points[2]);
                    var pointC = new ASVECTOR4(m_vertices[pC].Points[0], m_vertices[pC].Points[1], m_vertices[pC].Points[2]);

                    // Create the face - we use an ASMATRIX3 so we can map all points to one object
                    m_mesh[i] = new ASFace(pointA, pointB, pointC);
                }

                return(true);
            }
            // Something went wrong, probably an index out of bounds exception or something.
            catch (Exception e)
            {
                m_lastErr = e.ToString();
                return(false);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Recieves the pointer to the current location of the StreamReader, from here we
        /// read all vertice and indice information into the respective buffers
        /// </summary>
        /// <param name="reader">Pointer to the current stream reader</param>
        /// <returns>True if the array was populated, else false, also sets last error in exception</returns>
        internal bool FillVertexBuffer(StreamReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            try
            {
                // Loop numVertices times to build the vertex buffers
                for (var i = 0; i < m_numVertices; i++)
                {
                    // Values to hold the x,y,z position of this vertex
                    var nums = reader.ReadLine();
                    if (nums == null)
                    {
                        continue;
                    }
                    ;
                    var bits = nums.Trim().Split(' ');

                    // Read the next three doubles from the file into x,y,z
                    var x = float.Parse(bits[0]);
                    var y = float.Parse(bits[1]);
                    var z = float.Parse(bits[2]);

                    m_vertices[i] = new ASVECTOR4(x, y, z);

                    // Set the indice for this vertex
                    m_indices[i] = i;
                }

                return(true);
            }
            // Something went wrong, probably an index out of bounds exception or something.
            catch (Exception e)
            {
                m_lastErr = e.ToString();
                return(false);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Draws the point to the canvas using hidden surface removal
        /// </summary>
        private void DrawPoint()
        {
            try
            {
                for (var i = 0; i < m_numFaces; i++)
                {
                    var face       = m_meshData[i];
                    var faceNormal = new ASVECTOR4();

                    // Check if we will be performing back face culling
                    if (m_computeNormals)
                    {
                        faceNormal = face.ComputeFaceNormals();
                    }
                    else
                    {
                        faceNormal.ZeroVector();
                    }

                    // Check what we need to draw
                    if (m_showPoints)
                    {
                        // Draw the face
                        if (faceNormal.Points[2] >= 0.0)
                        {
                            for (var j = 0; j < 2; j++)
                            {
                                m_graphicsContext.DrawLine(m_pen,
                                                           (int)face.GetPointAtIndex(j).Points[0] + m_originX,
                                                           (int)face.GetPointAtIndex(j).Points[1] + m_originY,
                                                           (int)face.GetPointAtIndex(j + 1).Points[0] + m_originX,
                                                           (int)face.GetPointAtIndex(j + 1).Points[1] + m_originY
                                                           );
                            }
                        }
                    }
                    else
                    {
                        for (var j = 0; j < 2; j++)
                        {
                            m_graphicsContext.DrawRectangle(m_pen, (int)face.GetPointAtIndex(j).Points[0] + m_originX,
                                                            (int)face.GetPointAtIndex(j).Points[1] + m_originY, 1, 1);
                            m_graphicsContext.DrawRectangle(m_pen, (int)face.GetPointAtIndex(j + 1).Points[0] + m_originX,
                                                            (int)face.GetPointAtIndex(j + 1).Points[1] + m_originY, 1, 1);
                        }
                    }

                    // Note this is not Phong - I just wanted to apply some sort of colour after I computed hidden face surface
                    // removal
                    if (m_colorPolys)
                    {
                        // Draw from first point back to last line
                        m_graphicsContext.DrawLine(m_pen,
                                                   (int)face.GetPointAtIndex(2).Points[0] + m_originX,
                                                   (int)face.GetPointAtIndex(2).Points[1] + m_originY,
                                                   (int)face.GetPointAtIndex(0).Points[0] + m_originX,
                                                   (int)face.GetPointAtIndex(0).Points[1] + m_originY
                                                   );

                        // Colour polys
                        var     pointA = new Point((int)face.GetPointAtIndex(0).Points[0] + m_originX, (int)face.GetPointAtIndex(0).Points[1] + m_originY);
                        var     pointB = new Point((int)face.GetPointAtIndex(1).Points[0] + m_originX, (int)face.GetPointAtIndex(1).Points[1] + m_originY);
                        var     pointC = new Point((int)face.GetPointAtIndex(2).Points[0] + m_originX, (int)face.GetPointAtIndex(2).Points[1] + m_originY);
                        Point[] points = { pointA, pointB, pointC };


                        // Set the colour
                        var factorX = 1;
                        var factorY = 1;
                        var factorZ = 1;
                        if (faceNormal.Points[0] < 0)
                        {
                            factorX = -1;
                        }
                        if (faceNormal.Points[1] < 0)
                        {
                            factorY = -1;
                        }
                        if (faceNormal.Points[2] < 0)
                        {
                            factorZ = -1;
                        }

                        var color = Color.FromArgb(
                            (int)(255 * (faceNormal.Points[0] * factorX)),
                            (int)(255 * (faceNormal.Points[1] * factorY)),
                            (int)(255 * (faceNormal.Points[2] * factorZ)));
                        var brush = new SolidBrush(color);

                        m_graphicsContext.FillPolygon(brush, points, FillMode.Winding);
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
Exemplo n.º 6
0
 public void SetPosition(ASVECTOR4 value)
 {
     position = value;
 }
Exemplo n.º 7
0
 public void SetDiffuse(ASVECTOR4 value)
 {
     diffuse = value;
 }
Exemplo n.º 8
0
 public void SetSpecular(ASVECTOR4 value)
 {
     specular = value;
 }
Exemplo n.º 9
0
 public void SetAmbient(ASVECTOR4 value)
 {
     ambient = value;
 }