コード例 #1
0
 public void AddVertex(HullVertex hullVertex)
 {
     this.vertices.Add(hullVertex);
 }
コード例 #2
0
ファイル: Hull.cs プロジェクト: AndrewHackler/shooter
        /// <summary>
        /// Draws the hull.
        /// </summary>
        /// <param name="drawBuffer">The Lightmap Draw Buffer</param>
        public void Draw(ILightmapDrawBuffer drawBuffer)
        {
            // Create the matrices (3X speed boost versus prior version)
            this.cos = (float)Math.Cos(this.angle);
            this.sin = (float)Math.Sin(this.angle);

            // vertexMatrix = scale * rotation * translation;
            this.vertexMatrix.M11 = this.scale.X * this.cos;
            this.vertexMatrix.M12 = this.scale.X * this.sin;
            this.vertexMatrix.M21 = this.scale.Y * -this.sin;
            this.vertexMatrix.M22 = this.scale.Y * this.cos;
            this.vertexMatrix.M41 = this.position.X;
            this.vertexMatrix.M42 = this.position.Y;

            // normalMatrix = scaleInv * rotation;
            this.normalMatrix.M11 = (1f / this.scale.X) * this.cos;
            this.normalMatrix.M12 = (1f / this.scale.X) * this.sin;
            this.normalMatrix.M21 = (1f / this.scale.Y) * -this.sin;
            this.normalMatrix.M22 = (1f / this.scale.Y) * this.cos;

            drawBuffer.SetStartVertex();

            // Add the vertices to the buffer

            var hullVerticesLength = this.Vertices.Length;
            for (var i = 0; i < hullVerticesLength; i++)
            {
                // Transform the vertices to world coordinates
                this.point = this.Vertices[i];

                Vector2.Transform(ref this.point.Position, ref this.vertexMatrix, out this.hullVertex.Position);
                Vector2.TransformNormal(ref this.point.Normal, ref this.normalMatrix, out this.hullVertex.Normal);

                this.hullVertex.Color = ShadowBlack;

                drawBuffer.AddVertex(this.hullVertex);
            }

            var hullIndicesLength = this.Indices.Length;
            for (var i = 0; i < hullIndicesLength; i++)
            {
                drawBuffer.AddIndex(this.Indices[i]);
            }
        }