/// <summary> /// Tells you how far along the line of this phasor /// it would be to strike the <paramref name="other"/> Sprite. /// /// Gives you NULL if it simply wouldn't hit the other Sprite. /// </summary> /// <param name="other">The sprite to check if it hits</param> /// <returns>Distance along line if hits, NULL if does not</returns> public float? GetStrikeDistanceToFirstLevel( Sprite other ) { Vector2 shipHeading = shooter.GetHeading(); // create the ray Ray thisRay = new Ray( // starts at the center of // wherever the owning ship currently is. new Vector3( shooter.position.X, shooter.position.Y, 0.0f ), // it goes in the direction the ship is currently facing new Vector3( shipHeading.X, shipHeading.Y, 0.0f ) ); // treat the other thing as a sphere BoundingSphere thatSphere = new BoundingSphere( new Vector3( other.position.X, other.position.Y, 0.0f ), other.GetApproxRadius() ); return FindStrikeDistanceToSphere( thisRay, thatSphere ); }
/// <summary> /// Tells you how far along the line of the WRAPPED COPY of this phasor /// it would be to strike the <paramref name="other"/> Sprite. /// /// ^ /// +------------------/----+ /// | / | /// | C | /// | | /// | ^ | /// +------------------/----+ /// / /// C (wrapped copy) /// /// Gives you NULL if it simply wouldn't hit the other Sprite. /// </summary> /// <param name="other"></param> /// <returns></returns> private float? GetStrikeDistanceToSecondLevel( Sprite other ) { // get the duplicated wrapped ray Ray? dupeRay = GetDupeRay(); // if the dupe ray exists (the phasor should wrap) // then proceed with the calculation if( dupeRay != null ) { // treat the other thing as a sphere BoundingSphere thatSphere = new BoundingSphere( new Vector3( other.position.X, other.position.Y, 0.0f ), other.GetApproxRadius() ); return FindStrikeDistanceToSphere( dupeRay.Value, thatSphere ); } else // there is no duperay (the original phasor did not intersect any of the walls) return null; // so return null }
// Intersection method to tell if this sprite intersects another // default uses bounding spheres. public virtual bool Intersects( Sprite other ) { // construct BoundingSpheres and see if the // two sprites should collide BoundingSphere thisSphere = new BoundingSphere( new Vector3( this.position.X, this.position.Y, 0.0f ), this.GetApproxRadius() ); BoundingSphere thatSphere = new BoundingSphere( new Vector3( other.position.X, other.position.Y, 0.0f ), other.GetApproxRadius() ); if( thisSphere.Intersects( thatSphere ) ) return true; else return false; }