' Author:       Simon Dexter, M.A. 
' Source:       www.geocities.com/simondex
' Project:      Kinematics2D 
' Name:         Ellipse
' Description:  descendant of Vertex class representing an elliptical shape with variable center of mass
' Date started: 09/13/08 10:40 pm
' Modification log: 
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectDraw

Public Class Ellipse
    Inherits Vertex 

    public sideRatio as Single = 0.5 
    

    ' ==================================================================================================================
    ' status:           completed
    ' description:      constructor 
    ' date started:     09/13/08 10:40 pm
    ' date modified:    09/13/08
    ' date completed:   09/13/08
    public sub new (color as System.Drawing.Color)     
        MyBase.New (color) 
        
        me.orientation = new Vector2 (1,0)
    End Sub

    public overrides sub advancePosition (deltaTime as Single )
        MyBase.advancePosition (deltaTime) 
        if Not me.velocity.Length = 0 then
            me.orientation = me.velocity     
        End If
        
        me.recalculateBoundingBox ()
    End Sub


    ' status:           completed
    ' description:      drawing this ellipse 
    ' date started:     09/14/08 01:41 pm 
    ' date modified:    09/14/08
    ' date completed:   09/14/08    
    public overrides sub  draw() 
        PhysicalBody.graphics.drawEllipse (me.radius, me.sideRatio, me.orientation , me.positionVector, me.color )
        PhysicalBody.graphics.drawVector (me.positionVector + me.centerOfMass , me.velocity , Drawing.Color.Cyan  )
        PhysicalBody.graphics.drawVector (me.positionVector + me.centerOfMass , me.acceleration, Drawing.Color.LimeGreen  ) 
        PhysicalBody.graphics.drawVector (me.positionVector + me.centerOfMass , me.reactionForce, Drawing.Color.Violet  )
        
        PhysicalBody.graphics.drawBox (me.boundingRectangle.X, me.boundingRectangle.Y, me.boundingRectangle.X + me.boundingRectangle.Width , me.boundingRectangle.Y+me.boundingRectangle.Height, Drawing.Color.White  )
    End Sub    

    ' status:           completed
    ' description:      implementation of subroutine which places bounding box around this ellipse
    ' date started:     09/14/08 01:44 pm 
    ' date modified:    09/14/08 01:44 pm
    ' date completed:   09/14/08 01:44 pm
    Public Overrides Sub recalculateBoundingBox()
        try 
            With boundingRectangle 
                .X = me.positionVector.X - me.radius 
                .Y = me.positionVector.Y - me.radius 
                .Width = me.radius * 2
                .Height = me.radius * 2
            End With
        Catch exc As OverflowException 
            Trace.TraceError  ("E5: " + System.DateTime.Now ())
            Trace.TraceError ("Terminated")
            End ' instantenous termination of application
        End Try
    End Sub    
End Class
