/// <summary> /// A standard game object used for games /// </summary> /// <param name="name">Name of the GameObject's object type name /// Ex: LightSource : GameObject { ... } /// LightSource sun = new LightSource("Sun"); /// LightSource torch1 = new LightSource("Torch"), torch2 = new LightSource("Torch"); /// </param> public GameObject(string name) { if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); m_name = name; m_pos = m_velocity = m_accel = Vector.Zero; }
/// <summary> /// Updates the GameObject /// </summary> /// <param name="updateTime">Time, in milliseconds, since last update</param> public void Update(float updateTime) { m_velocity += m_accel * (float)updateTime; m_pos += m_velocity; }
/// <summary> /// Calculates the reflection vector between this /// and another vector /// </summary> /// <param name="normal">Vector normal to use</param> /// <returns>Returns reflected vector</returns> public Vector Reflect(Vector normal) { float mult = 2f * (m_x * normal.m_x + m_y * normal.m_y) / (normal.m_x * normal.m_x + normal.m_y * normal.m_y); return new Vector(m_x - normal.m_x * mult, m_y - normal.m_y * mult); }
/// <summary> /// Calculates the reflection vector between this /// and another vector and stores it in this vector /// </summary> /// <param name="normal">Vector normal to use</param> public void ReflectInPlace(Vector normal) { float mult = 2f * (m_x * normal.m_x + m_y * normal.m_y) / (normal.m_x * normal.m_x + normal.m_y * normal.m_y); m_x -= normal.m_x * mult; m_y -= normal.m_y * mult; }
/// <summary> /// Calculates the angle between this vector /// and one other vector /// </summary> /// <param name="other">Vector to use for calculations</param> /// <returns>Angle, in degrees, between the two vectors</returns> public float AngleBetween(Vector other) { return (float)Math.Acos(Normalize() * other.Normalize() * 180f / PI); }