Author: alanmc
Date: 2007-01-13 13:45:24 -0500 (Sat, 13 Jan 2007)
New Revision: 70961

Added:
   trunk/Mono.Xna/tests/Microsoft.Xna.Framework/Vector3Tests.cs
Modified:
   trunk/Mono.Xna/examples/SimpleExample/Program.cs
   trunk/Mono.Xna/examples/SimpleExample/SimpleExampleGame.cs
   trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingBox.cs
   trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingFrustum.cs
   trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingSphere.cs
   trunk/Mono.Xna/src/Microsoft.Xna.Framework/CurveKey.cs
   trunk/Mono.Xna/src/Microsoft.Xna.Framework/CurveKeyCollection.cs
   trunk/Mono.Xna/src/Microsoft.Xna.Framework/Plane.cs
   trunk/Mono.Xna/src/Microsoft.Xna.Framework/Vector3.cs
   trunk/Mono.Xna/tests/Microsoft.Xna.Framework/BoundingBoxTests.cs
   trunk/Mono.Xna/tests/Microsoft.Xna.Framework/BoundingSphereTests.cs
   trunk/Mono.Xna/tests/Microsoft.Xna.Framework/CurveKeyCollectionTests.cs
Log:
Patch from duff implementing a lot of new features with very minor 
modifications to fix some tests.

Modified: trunk/Mono.Xna/examples/SimpleExample/Program.cs
===================================================================
--- trunk/Mono.Xna/examples/SimpleExample/Program.cs    2007-01-13 18:41:29 UTC 
(rev 70960)
+++ trunk/Mono.Xna/examples/SimpleExample/Program.cs    2007-01-13 18:45:24 UTC 
(rev 70961)
@@ -26,6 +26,7 @@
 #endregion License
 
 using System;
+using Microsoft.Xna.Framework;
 
 namespace SimpleExample
 {
@@ -38,6 +39,8 @@
         {
             using (SimpleExampleGame game = new SimpleExampleGame())
             {
+                CurveKeyCollection c = new CurveKeyCollection();
+                c.Add(null);
                 game.Run();
             }
         }

Modified: trunk/Mono.Xna/examples/SimpleExample/SimpleExampleGame.cs
===================================================================
--- trunk/Mono.Xna/examples/SimpleExample/SimpleExampleGame.cs  2007-01-13 
18:41:29 UTC (rev 70960)
+++ trunk/Mono.Xna/examples/SimpleExample/SimpleExampleGame.cs  2007-01-13 
18:45:24 UTC (rev 70961)
@@ -118,13 +118,26 @@
         /// This is called when the game should draw itself.
         /// </summary>
         /// <param name="gameTime">Provides a snapshot of timing 
values.</param>
+        private int count = 0;
+        DateTime start;
         protected override void Draw(GameTime gameTime)
         {
-            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
+            if (count++ == 0)
+                start = DateTime.Now;
 
+            graphics.GraphicsDevice.Clear(this.colors[index++ % 
colors.Length]);
             // TODO: Add your drawing code here
 
+            if (count == 10000)
+            {
+                TimeSpan s = DateTime.Now - start;
+                float fps = (float)count / (float)s.TotalSeconds;
+                System.Windows.Forms.MessageBox.Show("fps: " + fps.ToString());
+            }
             base.Draw(gameTime);
         }
+
+        private int index = 0;
+        private Color[] colors = new Color[] { Color.AliceBlue, Color.Red, 
Color.Yellow, Color.Green, Color.Indigo, Color.LightSteelBlue };
     }
 }

Modified: trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingBox.cs
===================================================================
--- trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingBox.cs   2007-01-13 
18:41:29 UTC (rev 70960)
+++ trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingBox.cs   2007-01-13 
18:45:24 UTC (rev 70961)
@@ -59,39 +59,171 @@
 
         public ContainmentType Contains(BoundingBox box)
         {
-            throw new NotImplementedException();
+            ContainmentType result;
+            this.Contains(ref box, out result);
+            return result;
         }
         
         public void Contains(ref BoundingBox box, out ContainmentType result)
         {
-            throw new NotImplementedException();
+            // The box is disjoint when all corner is outside of one plane of 
box.
+            // The box contain the other box when all corner is inside
+            // else it intersect
+            //So take care of the other box contain and the following situation
+            //                ____________              
+            //               /                      
+            //     _________/_____                    
+            //             /     /|                   
+            //            /     / |  
+            //           /_ _ _/_____                         
+            //  ______________/                    
+            //          |     |                    
+            //          |     |                    
+            //          |_ _ _|_____                          
+            //                |   |                  
+            //                |   |                  
+            //                |   /                  
+            //                |  /                  
+            //                | /  
+            //      __________|/
+
+            //test if all corner is in the same side of a face by just 
checking min and max
+            if (box.Max.X < Min.X 
+                || box.Min.X > Max.X
+                || box.Max.Y < Min.Y
+                || box.Min.Y > Max.Y
+                || box.Max.Z < Min.Z
+                || box.Min.Z > Max.Z)
+            {
+                result = ContainmentType.Disjoint;
+                return;
+            }
+
+            //test if all corner of box is inside
+            bool isInside = true;
+            foreach (Vector3 corner in box.GetCorners())
+            {
+                               if (this.Contains(corner) != 
ContainmentType.Contains 
+                                       && this.Contains(corner) != 
ContainmentType.Intersects)
+                {
+                    isInside = false;
+                }
+            }
+            if (isInside)
+            {
+                //all corner is inside
+                result = ContainmentType.Contains;
+                return;
+            }
+            result = ContainmentType.Intersects;
+            return;
         }
 
         public ContainmentType Contains(BoundingFrustum frustum)
         {
-            ContainmentType result;
-            frustum.Contains(ref this, out result);
-            return result;
-        }
+                       //TODO: bad done here need a fix. 
+                       //Because question is not frustum contain box but 
reverse and this is not the same
+            int i;
+            ContainmentType contained;
+            Vector3[] corners = frustum.GetCorners();
 
+            // First we check if frustum is in box
+            for (i = 0; i < corners.Length; i++)
+            {
+                this.Contains(ref corners[i], out contained);
+                if (contained == ContainmentType.Disjoint)
+                    break;
+            }
+
+            if (i == corners.Length) // This means we checked all the corners 
and they were all contain or instersect
+                return ContainmentType.Contains;
+
+            if (i != 0)             // if i is not equal to zero, we can 
fastpath and say that this box intersects
+                return ContainmentType.Intersects;
+             
+
+            // If we get here, it means the first (and only) point we checked 
was actually contained in the frustum.
+            // So we assume that all other points will also be contained. If 
one of the points is disjoint, we can
+            // exit immediately saying that the result is Intersects
+            i++;
+            for (; i < corners.Length; i++)
+            {
+                this.Contains(ref corners[i], out contained);
+                if (contained != ContainmentType.Contains)
+                    return ContainmentType.Intersects;
+               
+            }
+
+            // If we get here, then we know all the points were actually 
contained, therefore result is Contains
+            return ContainmentType.Contains;
+               }
+
         public ContainmentType Contains(BoundingSphere sphere)
         {
-            throw new NotImplementedException();
+                       if (sphere.Center.X > Min.X && sphere.Center.X - Min.X 
> sphere.Radius
+                               && sphere.Center.Y > Min.Y && sphere.Center.Y - 
Min.Y > sphere.Radius
+                               && sphere.Center.Z > Min.Z && sphere.Center.Z - 
Min.Z > sphere.Radius
+                               && sphere.Center.X < Max.X && Max.X - 
sphere.Center.X > sphere.Radius
+                               && sphere.Center.Y < Max.Y && Max.Y - 
sphere.Center.Y > sphere.Radius
+                               && sphere.Center.Z < Max.Z && Max.Z - 
sphere.Center.Z > sphere.Radius)
+                               return ContainmentType.Contains;
+
+                       double dmin = 0;
+
+                       if (sphere.Center.X < Min.X)
+                               dmin += (sphere.Center.X - Min.X) * 
(sphere.Center.X - Min.X);
+                       else if (sphere.Center.X > Max.X)
+                                       dmin += (sphere.Center.X - Max.X) * 
(sphere.Center.X - Max.X);
+                       if (sphere.Center.Y < Min.Y)
+                               dmin += (sphere.Center.Y - Min.Y) * 
(sphere.Center.Y - Min.Y);
+                       else if (sphere.Center.Y > Max.Y)
+                               dmin += (sphere.Center.Y - Max.Y) * 
(sphere.Center.Y - Max.Y);
+                       if (sphere.Center.Z < Min.Z)
+                               dmin += (sphere.Center.Z - Min.Z) * 
(sphere.Center.Z - Min.Z);
+                       else if (sphere.Center.Z > Max.Z)
+                               dmin += (sphere.Center.Z - Max.Z) * 
(sphere.Center.Z - Max.Z);
+
+                       if (dmin <= sphere.Radius * sphere.Radius) 
+                               return ContainmentType.Intersects;
+
+                       return ContainmentType.Disjoint;
         }
         
         public void Contains(ref BoundingSphere sphere, out ContainmentType 
result)
         {
-            throw new NotImplementedException();
+            result = this.Contains(sphere);
         }
 
         public ContainmentType Contains(Vector3 point)
         {
-            throw new NotImplementedException();
+            ContainmentType result;
+            this.Contains(ref point, out result);
+            return result;            
         }
         
         public void Contains(ref Vector3 point, out ContainmentType result)
         {
-            throw new NotImplementedException();
+            //first we get if point is out of box
+            if (point.X < this.Min.X
+                || point.X > this.Max.X
+                || point.Y < this.Min.Y
+                || point.Y > this.Max.Y
+                || point.Z < this.Min.Z
+                || point.Z > this.Max.Z)
+            {
+                result = ContainmentType.Disjoint;
+            }//or if point is on box because coordonate of point is lesser or 
equal
+            else if (point.X == this.Min.X
+                || point.X == this.Max.X
+                || point.Y == this.Min.Y
+                || point.Y == this.Max.Y
+                || point.Z == this.Min.Z
+                || point.Z == this.Max.Z)
+                result = ContainmentType.Intersects;
+            else
+                result = ContainmentType.Contains;
+
+
         }
 
         public static BoundingBox CreateFromPoints(IEnumerable<Vector3> points)
@@ -114,7 +246,7 @@
 
         public static void CreateFromSphere(ref BoundingSphere sphere, out 
BoundingBox result)
         {
-            throw new NotImplementedException();
+            result = BoundingBox.CreateFromSphere(sphere);
         }
 
         public static BoundingBox CreateMerged(BoundingBox original, 
BoundingBox additional)
@@ -125,7 +257,7 @@
 
         public static void CreateMerged(ref BoundingBox original, ref 
BoundingBox additional, out BoundingBox result)
         {
-            throw new NotImplementedException();
+            result = BoundingBox.CreateMerged(original, additional);
         }
 
         public bool Equals(BoundingBox other)
@@ -221,7 +353,7 @@
 
         public override string ToString()
         {
-            return string.Format(CultureInfo.CurrentCulture, "{Min:{0} 
Max:{1}}", this.Min.ToString(), this.Max.ToString());
+            return string.Format("{{Min:{0} Max:{1}}}", this.Min.ToString(), 
this.Max.ToString());
         }
 
         #endregion Public Methods

Modified: trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingFrustum.cs
===================================================================
--- trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingFrustum.cs       
2007-01-13 18:41:29 UTC (rev 70960)
+++ trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingFrustum.cs       
2007-01-13 18:45:24 UTC (rev 70961)
@@ -44,15 +44,28 @@
         private Plane right;
         private Plane near;
         private Plane top;
+        private Vector3[] corners;
 
-
         #region Public Constructors
 
         public BoundingFrustum(Matrix value)
         {
             this.matrix = value;
             CreatePlanes();
+            CreateCorners();
         }
+        private void CreateCorners()
+        {
+            corners = new Vector3[8];
+            corners[0] = IntersectionPoint(ref this.near, ref this.left, ref 
this.top);
+            corners[1] = IntersectionPoint(ref this.near, ref this.right, ref 
this.top);
+            corners[2] = IntersectionPoint(ref this.near, ref this.right, ref 
this.bottom);
+            corners[3] = IntersectionPoint(ref this.near, ref this.left, ref 
this.bottom);
+            corners[4] = IntersectionPoint(ref this.far, ref this.left, ref 
this.top);
+            corners[5] = IntersectionPoint(ref this.far, ref this.right, ref 
this.top);
+            corners[6] = IntersectionPoint(ref this.far, ref this.right, ref 
this.bottom);
+            corners[7] = IntersectionPoint(ref this.far, ref this.left, ref 
this.bottom);
+        }
 
         private void CreatePlanes()
         {
@@ -118,7 +131,8 @@
             {
                 this.matrix = value;
                 this.CreatePlanes();    // FIXME: The odds are the planes will 
be used a lot more often than the matrix
-            }                           // is updated, so this should help 
performance. I hope ;)
+               this.CreateCorners();   // is updated, so this should help 
performance. I hope ;)
+                       }
         }
 
         public Plane Near
@@ -280,7 +294,11 @@
                 result = ContainmentType.Contains;
                 return;
             }
+            //duff idea : test if all corner is in same side of a plane if yes 
and outside it is disjoint else intersect
+            // issue is that we can have some times when really close aabb 
 
+
+
             // If we're here, the the sphere's centre was outside of the 
frustum. This makes things hard :(
             // We can't use perpendicular distance anymore. I'm not sure how 
to code this.
             throw new NotImplementedException();
@@ -371,16 +389,7 @@
 
         public Vector3[] GetCorners()
         {
-            Vector3[] array = new Vector3[8];
-            array[0] = IntersectionPoint(ref this.near, ref this.left, ref 
this.top);
-            array[1] = IntersectionPoint(ref this.near, ref this.right, ref 
this.top);
-            array[2] = IntersectionPoint(ref this.near, ref this.right, ref 
this.bottom);
-            array[3] = IntersectionPoint(ref this.near, ref this.left, ref 
this.bottom);
-            array[4] = IntersectionPoint(ref this.far, ref this.left, ref 
this.top);
-            array[5] = IntersectionPoint(ref this.far, ref this.right, ref 
this.top);
-            array[6] = IntersectionPoint(ref this.far, ref this.right, ref 
this.bottom);
-            array[7] = IntersectionPoint(ref this.far, ref this.left, ref 
this.bottom);
-            return array;
+            return corners;
         }
 
 
@@ -424,6 +433,24 @@
             throw new NotImplementedException();
         }
 
+        internal void SupportMapping(ref Vector3 v, out Vector3 result)
+        {
+            float maxDistance;
+            int cornerIndex = 0;
+            Vector3.Dot(ref this.corners[0], ref v, out maxDistance);
+            for (int i = 1; i < this.corners.Length; i++)
+            {
+                float currentDistance;
+                Vector3.Dot(ref this.corners[i], ref v, out currentDistance);
+                if (currentDistance > maxDistance)
+                {
+                    cornerIndex = i;
+                    maxDistance = currentDistance;
+                }
+            }
+            result = this.corners[cornerIndex];
+        }
+
         public bool Intersects(BoundingSphere sphere)
         {
             throw new NotImplementedException();

Modified: trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingSphere.cs
===================================================================
--- trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingSphere.cs        
2007-01-13 18:41:29 UTC (rev 70960)
+++ trunk/Mono.Xna/src/Microsoft.Xna.Framework/BoundingSphere.cs        
2007-01-13 18:45:24 UTC (rev 70961)
@@ -60,34 +60,95 @@
 
         public ContainmentType Contains(BoundingBox box)
         {
-            throw new NotImplementedException("The method or operation is not 
implemented.");
+            //check if all corner is in sphere
+            bool inside = true;
+            foreach (Vector3 corner in box.GetCorners())
+            {
+                if (this.Contains(corner) == ContainmentType.Disjoint)
+                {
+                    inside = false;
+                    break;
+                }
+            }
+            if (inside)
+                return ContainmentType.Contains;
+
+            //check if the distance from sphere center to cube face < radius
+            double dmin = 0;
+            if (Center.X < box.Min.X)
+                               dmin += (Center.X - box.Min.X) * (Center.X - 
box.Min.X);
+                       else if (Center.X > box.Max.X)
+                                       dmin += (Center.X - box.Max.X) * 
(Center.X - box.Max.X);
+                       if (Center.Y < box.Min.Y)
+                               dmin += (Center.Y - box.Min.Y) * (Center.Y - 
box.Min.Y);
+                       else if (Center.Y > box.Max.Y)
+                               dmin += (Center.Y - box.Max.Y) * (Center.Y - 
box.Max.Y);
+                       if (Center.Z < box.Min.Z)
+                               dmin += (Center.Z - box.Min.Z) * (Center.Z - 
box.Min.Z);
+                       else if (Center.Z > box.Max.Z)
+                               dmin += (Center.Z - box.Max.Z) * (Center.Z - 
box.Max.Z);
+
+                       if (dmin <= Radius * Radius) 
+                               return ContainmentType.Intersects;
+            
+            //else disjoint
+            return ContainmentType.Disjoint;
+
         }
 
         public void Contains(ref BoundingBox box, out ContainmentType result)
         {
-            throw new NotImplementedException();
+            result = this.Contains(box);
         }
 
         public ContainmentType Contains(BoundingFrustum frustum)
         {
-            ContainmentType result;
-            frustum.Contains(ref this, out result);
-            return result;
+            //check if all corner is in sphere
+            bool inside = true;
+
+            Vector3[] corners = frustum.GetCorners();
+            foreach (Vector3 corner in corners)
+            {
+                if (this.Contains(corner) == ContainmentType.Disjoint)
+                {
+                    inside = false;
+                    break;
+                }
+            }
+            if (inside)
+                return ContainmentType.Contains;
+
+            //check if the distance from sphere center to frustrum face < 
radius
+            double dmin = 0;
+            //TODO : calcul dmin
+
+            if (dmin <= Radius * Radius)
+                return ContainmentType.Intersects;
+
+            //else disjoint
+            return ContainmentType.Disjoint;
         }
 
         public ContainmentType Contains(BoundingSphere sphere)
         {
-            throw new NotImplementedException("The method or operation is not 
implemented.");
+            float val = Vector3.Distance(sphere.Center, Center);
+
+            if (val > sphere.Radius + Radius)
+                return ContainmentType.Disjoint;
+            else if (val <= Radius - sphere.Radius)
+                return ContainmentType.Contains;
+            else
+                return ContainmentType.Intersects;
         }
 
         public void Contains(ref BoundingSphere sphere, out ContainmentType 
result)
         {
-            throw new NotImplementedException();
+            result = Contains(sphere);
         }
 
         public ContainmentType Contains(Vector3 point)
         {
-            float distance = ((Vector3)(point - this.Center)).LengthSquared();
+            float distance = Vector3.Distance(point, Center);
 
             if (distance > this.Radius)
             {
@@ -103,36 +164,39 @@
 
         public void Contains(ref Vector3 point, out ContainmentType result)
         {
-            throw new NotImplementedException();
+            result = Contains(point);
         }
 
         public static BoundingSphere CreateFromBoundingBox(BoundingBox box)
         {
             // Find the center of the box.
             Vector3 center = new Vector3(
-                (box.Min.X * box.Max.X) / 2.0f,
-                (box.Min.Y * box.Max.Y) / 2.0f,
-                (box.Min.Z * box.Max.Z) / 2.0f
+                (box.Min.X + box.Max.X) / 2.0f,
+                (box.Min.Y + box.Max.Y) / 2.0f,
+                (box.Min.Z + box.Max.Z) / 2.0f
                 );
 
             // Find the distance between the center and one of the corners of 
the box.
-            float radius = ((Vector3)(center - box.Max)).Length();
+            float radius = Vector3.Distance(center, box.Max);
 
             return new BoundingSphere(center, radius);
         }
 
         public static void CreateFromBoundingBox(ref BoundingBox box, out 
BoundingSphere result)
         {
-            throw new NotImplementedException();
+            result = CreateFromBoundingBox(box);
         }
 
         public static BoundingSphere CreateFromFrustum(BoundingFrustum frustum)
         {
-            throw new NotImplementedException("The method or operation is not 
implemented.");
+            return BoundingSphere.CreateFromPoints(frustum.GetCorners());
         }
 
         public static BoundingSphere CreateFromPoints(IEnumerable<Vector3> 
points)
         {
+            if (points == null)
+                throw new ArgumentNullException("points");
+
             float radius = 0;
             Vector3 center = new Vector3();
             // First, we'll find the center of gravity for the point 'cloud'.
@@ -160,12 +224,30 @@
 
         public static BoundingSphere CreateMerged(BoundingSphere original, 
BoundingSphere additional)
         {
-            throw new NotImplementedException("The method or operation is not 
implemented.");
+            Vector3 ocenterToaCenter = Vector3.Subtract(additional.Center, 
original.Center);
+            float distance = ocenterToaCenter.Length();
+            if (distance <= original.Radius + additional.Radius)//intersect
+            {
+                if (distance <= original.Radius - additional.Radius)//original 
contain additional
+                    return original;
+                if (distance <= additional.Radius - 
original.Radius)//additional contain original
+                    return additional;
+            }
+
+            //else find center of new sphere and radius
+            float leftRadius = Math.Max(original.Radius - distance, 
additional.Radius);
+            float Rightradius = Math.Max(original.Radius + distance, 
additional.Radius);
+            ocenterToaCenter = ocenterToaCenter + (((leftRadius - Rightradius) 
/ (2 * ocenterToaCenter.Length())) * ocenterToaCenter);//oCenterToResultCenter
+            
+            BoundingSphere result = new BoundingSphere();
+            result.Center = original.Center + ocenterToaCenter;
+            result.Radius = (leftRadius + Rightradius) / 2;
+            return result;
         }
 
         public static void CreateMerged(ref BoundingSphere original, ref 
BoundingSphere additional, out BoundingSphere result)
         {
-            throw new NotImplementedException();
+            result = BoundingSphere.CreateMerged(original, additional);
         }
 
         public bool Equals(BoundingSphere other)

Modified: trunk/Mono.Xna/src/Microsoft.Xna.Framework/CurveKey.cs
===================================================================
--- trunk/Mono.Xna/src/Microsoft.Xna.Framework/CurveKey.cs      2007-01-13 
18:41:29 UTC (rev 70960)
+++ trunk/Mono.Xna/src/Microsoft.Xna.Framework/CurveKey.cs      2007-01-13 
18:45:24 UTC (rev 70961)
@@ -60,8 +60,8 @@
 
         public float TangentOut
         {
-            get { return m_tangentIn; }
-            set { m_tangentIn = value; }
+            get { return m_tangentOut; }
+            set { m_tangentOut = value; }
         }
 
         public float Value
@@ -95,12 +95,22 @@
 
         public static bool operator !=(CurveKey a, CurveKey b)
         {
-            return !a.Equals(b);
+            return !(a == b);
         }
         
         public static bool operator ==(CurveKey a, CurveKey b)
         {
-            return a.Equals(b);
+            if(object.Equals(a, null))
+                return object.Equals(b, null);
+
+            if(object.Equals(b, null))
+                return object.Equals(a, null);
+
+            return (a.m_position == b.m_position)
+                                    && (a.m_value == b.m_value)
+                                    && (a.m_tangentIn == b.m_tangentIn)
+                                    && (a.m_tangentOut == b.m_tangentOut)
+                                    && (a.m_continuity == b.m_continuity);
         }
 
         public CurveKey Clone()
@@ -120,17 +130,15 @@
             //}
             //return 0;
         }
-        
+
         public bool Equals(CurveKey other)
         {
-            return (m_position == other.m_position) && (m_value == 
other.m_value) && (m_tangentIn == other.m_tangentIn) &&
-                (m_tangentOut == other.m_tangentOut) && (m_continuity == 
other.m_continuity);
+            return (this == other);
         }
 
         public override bool Equals(object obj)
         {
-            CurveKey other = obj as CurveKey;
-            return (other == null) ? false : this.Equals(other);
+            return (obj is CurveKey) ? this.Equals((CurveKey)obj) : false;
         }
 
         public override int GetHashCode()

Modified: trunk/Mono.Xna/src/Microsoft.Xna.Framework/CurveKeyCollection.cs
===================================================================
--- trunk/Mono.Xna/src/Microsoft.Xna.Framework/CurveKeyCollection.cs    
2007-01-13 18:41:29 UTC (rev 70960)
+++ trunk/Mono.Xna/src/Microsoft.Xna.Framework/CurveKeyCollection.cs    
2007-01-13 18:45:24 UTC (rev 70961)
@@ -59,10 +59,12 @@
             get { return innerlist[index]; }
             set
             {
-#warning This duplicates "add"
                 if (value == null)
                     throw new ArgumentNullException();
 
+                if (index >= innerlist.Count)
+                    throw new IndexOutOfRangeException();
+
                 float pos = innerlist[index].m_position;
                 if (pos == value.m_position)
                     innerlist[index] = value;
@@ -79,19 +81,7 @@
             if (item == null)
                 throw new ArgumentNullException();
 
-            int index = 0;
-            foreach (CurveKey key in innerlist)
-            {
-                if( key.m_position == item.m_position )
-                    innerlist[index] = item;
-
-                else 
-                {
-                    innerlist.RemoveAt(index);
-                    innerlist.Add(item);
-                }
-                index++;
-            }
+            innerlist.Add(item);
         }
         
         public void Clear()
@@ -101,7 +91,10 @@
         
         public CurveKeyCollection Clone()
         {
-            throw new NotImplementedException();
+            CurveKeyCollection ckc = new CurveKeyCollection();
+            foreach (CurveKey key in this.innerlist)
+                ckc.Add(key);
+            return ckc;
         }
         
         public bool Contains(CurveKey item)

Modified: trunk/Mono.Xna/src/Microsoft.Xna.Framework/Plane.cs
===================================================================
--- trunk/Mono.Xna/src/Microsoft.Xna.Framework/Plane.cs 2007-01-13 18:41:29 UTC 
(rev 70960)
+++ trunk/Mono.Xna/src/Microsoft.Xna.Framework/Plane.cs 2007-01-13 18:45:24 UTC 
(rev 70961)
@@ -132,28 +132,6 @@
         /// <returns>The type of intersection.</returns>
         public PlaneIntersectionType Intersects(BoundingBox box)
         {
-            // Move the code to BoundingBox class
-
-            //Vector3 vectorA, vectorB;
-
-            //vectorB.X = Normal.X >= 0 ? box.Min.X : box.Max.X;
-            //vectorB.Y = Normal.Y >= 0 ? box.Min.Y : box.Max.Y;
-            //vectorB.Z = Normal.Z >= 0 ? box.Min.Z : box.Max.Z;
-
-            //vectorA.X = Normal.X >= 0 ? box.Max.X : box.Min.X;
-            //vectorA.Y = Normal.Y >= 0 ? box.Max.Y : box.Min.Y;
-            //vectorA.Z = Normal.Z >= 0 ? box.Max.Z : box.Min.Z;
-
-            //float distanceB = Vector3.Dot(Normal, vectorB) + D;
-            //if (distanceB > 0)
-            //    return PlaneIntersectionType.Front;
-
-            //float distanceA = Vector3.Dot(Normal, vectorA ) + D;
-            //if (distanceA < 0)
-            //    return PlaneIntersectionType.Back;
-
-            //return PlaneIntersectionType.Intersecting;
-
             return box.Intersects(this);
         }
 
@@ -178,21 +156,6 @@
         /// <returns>The type of intersection.</returns>
         public PlaneIntersectionType Intersects(BoundingSphere sphere)
         {
-            //TODO: Move to BoundingSphere class
-
-            //float distance = Vector3.Dot(sphere.Center, Normal ) + D;
-
-            //if (distance > sphere.Radius)
-            //{
-            //    return PlaneIntersectionType.Front;
-            //}
-            //else if (distance < -sphere.Radius)
-            //{
-            //    return PlaneIntersectionType.Back;
-            //}
-            //else
-            //    return PlaneIntersectionType.Intersecting;
-
             return sphere.Intersects(this);
         }
 
@@ -208,7 +171,7 @@
         /// <returns>String that represents the object.</returns>
         public override string ToString()
         {
-            return string.Format("Normal : {0} D: {1}", Normal, D);
+            return string.Format("{{Normal:{0} D:{1}}}", Normal, D);
         }
     }
 }

Modified: trunk/Mono.Xna/src/Microsoft.Xna.Framework/Vector3.cs
===================================================================
--- trunk/Mono.Xna/src/Microsoft.Xna.Framework/Vector3.cs       2007-01-13 
18:41:29 UTC (rev 70960)
+++ trunk/Mono.Xna/src/Microsoft.Xna.Framework/Vector3.cs       2007-01-13 
18:45:24 UTC (rev 70961)
@@ -162,7 +162,7 @@
         /// <returns>String that represents the object.</returns>
         public override string ToString()
         {
-            return X.ToString() + ", " + Y.ToString() + ", " + Z.ToString();
+                       return "{X:" + X.ToString() + " Y:" + Y.ToString() + " 
Z:" + Z.ToString() + "}";
         }
         
         /// <summary>Determines whether the specified System.Object is equal 
to the Vector3.</summary>

Modified: trunk/Mono.Xna/tests/Microsoft.Xna.Framework/BoundingBoxTests.cs
===================================================================
--- trunk/Mono.Xna/tests/Microsoft.Xna.Framework/BoundingBoxTests.cs    
2007-01-13 18:41:29 UTC (rev 70960)
+++ trunk/Mono.Xna/tests/Microsoft.Xna.Framework/BoundingBoxTests.cs    
2007-01-13 18:45:24 UTC (rev 70961)
@@ -49,6 +49,28 @@
         #endregion Setup
 
         [Test]
+        public void Constructor()
+        {
+            //regular
+            BoundingBox b = new BoundingBox(new Vector3(-5,3,1),new 
Vector3(8,-10,0));
+
+            Assert.AreEqual(new Vector3(-5, 3, 1), b.Min,"BoundingBox()#1Min");
+            Assert.AreEqual(new Vector3(8, -10, 0), b.Max, 
"BoundingBox()#1Max");
+
+            //min = max
+            b = new BoundingBox(new Vector3(0, 0, 1), new Vector3(0, 1, 2));
+
+            Assert.AreEqual(new Vector3(0, 0, 1), b.Min, "BoundingBox()#2Min");
+            Assert.AreEqual(new Vector3(0, 1, 2), b.Max, "BoundingBox()#2Max");
+
+            //min = int.min max = int.max
+            b = new BoundingBox(new Vector3(float.MinValue), new 
Vector3(float.MaxValue));
+
+            Assert.AreEqual(new Vector3(float.MinValue), b.Min, 
"BoundingBox()#3Min");
+            Assert.AreEqual(new Vector3(float.MaxValue), b.Max, 
"BoundingBox()#3Max");
+        }
+
+        [Test]
         public void CreateFromPoints()
         {
             List<Vector3> points = new List<Vector3>();
@@ -78,13 +100,30 @@
             BoundingBox b1 = new BoundingBox(new Vector3(2, 51, 1), new 
Vector3(-12, -4, -2));
             BoundingBox b2 = new BoundingBox(new Vector3(35, 35, -1), new 
Vector3(14, -25, 21));
             BoundingBox b = BoundingBox.CreateMerged(b1, b2);
-            Assert.AreEqual(new Vector3(2, 35, -1), b.Min);
-            Assert.AreEqual(new Vector3(14, -4, 21), b.Max);
+            Assert.AreEqual(new Vector3(2, 35, -1), b.Min, "#1");
+            Assert.AreEqual(new Vector3(14, -4, 21), b.Max, "#2");
         }
 
+        [Test]
+        public void ContainsVector3()
+        {
+            ContainmentType result;
 
+            result = b.Contains(new Vector3(1, 2, 3));
+            Assert.AreEqual(ContainmentType.Contains, result, "PointTest#1");
+
+            result = b.Contains(new Vector3(4, 8, 12));
+            Assert.AreEqual(ContainmentType.Disjoint, result, "PointTest#2");
+
+            result = b.Contains(new Vector3(100, 22, 1));
+            Assert.AreEqual(ContainmentType.Disjoint, result, "PointTest#3");
+
+            result = b.Contains(new Vector3(3, 4, 5));
+            Assert.AreEqual(ContainmentType.Contains, result, "PointTest#4");
+        }
+
         [Test]
-        public void Contains()
+        public void ContainsBoundingBox()
         {
             ContainmentType result;
 
@@ -97,9 +136,29 @@
             result = b.Contains(new BoundingBox(new Vector3(-5, -6, -7), new 
Vector3(-11, -23, -24)));
             Assert.AreEqual(ContainmentType.Disjoint, result, "BoundingBox#3");
 
+        }
+
+        [Test]
+        public void ContainsBoundingFrustum()
+        {
+            ContainmentType result;
+
             result = b.Contains(new BoundingFrustum(new Matrix(0, 9, 78, 6, 4, 
3, 35, 6, 8, 8, 2, 1, 4, 5, 8, 5)));
             Assert.AreEqual(ContainmentType.Intersects, result, 
"BoundingFrustrum#1");
 
+            result = b.Contains(new BoundingFrustum(new Matrix(1, 1, 2, 3, 5, 
7, 42, 1243, 12, 55, 3, 22, 35, 346, 73, 5)));
+            Assert.AreEqual(ContainmentType.Disjoint, result, 
"BoundingFrustrum#2");
+
+            result = b.Contains(new BoundingFrustum(new Matrix(1, 1, 2, 3, 5, 
7, 42, 1243, 12, 55, 3, 22, 35, 346, 73, 5)));
+            Assert.AreEqual(ContainmentType.Disjoint, result, 
"BoundingFrustrum#2");
+
+        }
+
+        [Test]
+        public void ContainsBoundingSphere()
+        {
+            ContainmentType result;
+
             result = b.Contains(new BoundingSphere(new Vector3(-5, -5, -5), 
5));
             Assert.AreEqual(ContainmentType.Disjoint, result, 
"BoundingSphere#1");
 
@@ -114,21 +173,7 @@
 
             result = b.Contains(new BoundingSphere(new Vector3(-1, -1, -1), 
19));
             Assert.AreEqual(ContainmentType.Intersects, result, 
"BoundingSphere#5");
-
-            result = b.Contains(new Vector3(1, 2, 3));
-            Assert.AreEqual(ContainmentType.Contains, result, "PointTest#1");
-
-            result = b.Contains(new Vector3(4, 8, 12));
-            Assert.AreEqual(ContainmentType.Disjoint, result, "PointTest#2");
-
-            result = b.Contains(new Vector3(100, 22, 1));
-            Assert.AreEqual(ContainmentType.Disjoint, result, "PointTest#3");
-
-            result = b.Contains(new Vector3(3, 4, 5));
-            Assert.AreEqual(ContainmentType.Contains, result, "PointTest#4");
         }
-
-
         [Test]
         public void EqualsTest()
         {
@@ -182,7 +227,7 @@
 
 
         [Test]
-        public void Intersects()
+        public void IntersectsBoundingBox()
         {
             bool result;
 
@@ -192,31 +237,57 @@
             result = b.Intersects(new BoundingBox(new Vector3(11, 12, 14), new 
Vector3(21, 2, 1)));
             Assert.AreEqual(false, result, "BoundingBox#2");
 
+        }
+
+        [Test]
+        public void IntersectsBoundingFrustum()
+        {
+
+            bool result;
+
             result = b.Intersects(new BoundingFrustum(new Matrix(1, 1, 2, 3, 
5, 7, 42, 1243, 12, 55, 3, 22, 35, 346, 73, 5)));
-            Assert.AreEqual(false, result);
+                       Assert.AreEqual(false, result, "Frustum#1");
+        }
 
+        [Test]
+        public void IntersectsBoundingSphere()
+        {
+            bool result;
+
             result = b.Intersects(new BoundingSphere(new Vector3(1, 2, 3), 
5.3f));
-            Assert.AreEqual(true, result);
+                       Assert.AreEqual(true, result, "BoundingSphere#1");
 
             result = b.Intersects(new BoundingSphere(new Vector3(151, 3512, 
311), 53));
-            Assert.AreEqual(false, result);
+                       Assert.AreEqual(false, result, "BoundingSphere#2");
+        }
 
+        [Test]
+        public void IntersectsPlane()
+        {
+            bool result;
+
             PlaneIntersectionType planeResult;
             planeResult = b.Intersects(new Plane(new Vector3(-1, -1, -1), new 
Vector3(-1, -1, -2), new Vector3(-1, -4, -5)));
-            Assert.AreEqual(PlaneIntersectionType.Back, planeResult);
+                       Assert.AreEqual(PlaneIntersectionType.Back, 
planeResult, "Plane#A");
 
             planeResult = b.Intersects(new Plane(new Vector3(-100, -1, 0), new 
Vector3(-100, -1, 1), new Vector3(-1, -1, -1)));
-            Assert.AreEqual(PlaneIntersectionType.Front, planeResult);
+                       Assert.AreEqual(PlaneIntersectionType.Front, 
planeResult, "Plane#2");
+        }
 
+        [Test]
+        public void IntersectsRay()
+        {
+            bool result;
+
             float? rayResult;
             rayResult = b.Intersects(new Ray(new Vector3(-1, -2, -3), new 
Vector3(-1, -2, -3)));
-            Assert.AreEqual(rayResult, null);
+                       Assert.AreEqual(rayResult, null, "Ray#1");
 
             rayResult = b.Intersects(new Ray(new Vector3(1, 2, 3), new 
Vector3(4, 5, 6)));
-            Assert.AreEqual(rayResult, 0.0);
+                       Assert.AreEqual(rayResult, 0.0, "Ray#2");
 
             rayResult = b.Intersects(new Ray(new Vector3(-1, -1, -1), new 
Vector3(1, 1, 1)));
-            Assert.AreEqual(rayResult, 1.0);
+                       Assert.AreEqual(rayResult, 1.0, "Ray#3");
         }
 
 
@@ -237,7 +308,7 @@
         [Test]
         public void ToStringTest()
         {
-            Assert.AreEqual("{Min:{X:0 Y:0 Z:0} Max:{X:10 Y:10 Z:10}}", 
this.b.ToString());
+                       Assert.AreEqual("{Min:{X:0 Y:0 Z:0} Max:{X:10 Y:10 
Z:10}}", this.b.ToString());
         }
     }
 }

Modified: trunk/Mono.Xna/tests/Microsoft.Xna.Framework/BoundingSphereTests.cs
===================================================================
--- trunk/Mono.Xna/tests/Microsoft.Xna.Framework/BoundingSphereTests.cs 
2007-01-13 18:41:29 UTC (rev 70960)
+++ trunk/Mono.Xna/tests/Microsoft.Xna.Framework/BoundingSphereTests.cs 
2007-01-13 18:45:24 UTC (rev 70961)
@@ -58,7 +58,7 @@
 
 
         [Test]
-        public void Contains()
+        public void ContainsBoundingBox()
         {
             ContainmentType r1;
             r1 = s.Contains(new BoundingBox(new Vector3(1, 1, 1), new 
Vector3(2, 2, 2)));
@@ -73,6 +73,15 @@
             r1 = s.Contains(new BoundingBox(new Vector3(100, 90, 80), new 
Vector3(76, 65, 54)));
             Assert.AreEqual(ContainmentType.Disjoint, r1, "BoundingBox#4");
 
+            r1 = s.Contains(new BoundingBox(new Vector3(float.MinValue), new 
Vector3(float.MaxValue)));
+            Assert.AreEqual(ContainmentType.Intersects, r1, "#5");
+        }
+
+
+        [Test]
+        public void ContainsBoundingFrustum()
+        {
+            ContainmentType r1;
             r1 = s.Contains(new BoundingFrustum(new Matrix(1, 2, 3, 4, 5, 6, 
7, 8, 9, 8, 7, 6, 5, 4, 3, 2)));
             Assert.AreEqual(ContainmentType.Disjoint, r1, "BoundingFrustum#1");
 
@@ -81,7 +90,13 @@
 
             r1 = s.Contains(new BoundingFrustum(new Matrix(2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2)));
             Assert.AreEqual(ContainmentType.Contains, r1, "BoundingFrustum#3");
+        }
 
+
+        [Test]
+        public void ContainsBoundingSphere()
+        {
+            ContainmentType r1;
             r1 = s.Contains(new BoundingSphere(new Vector3(2, 3, 4), 5));
             Assert.AreEqual(ContainmentType.Contains, r1, "BoundingSphere#1");
 
@@ -90,7 +105,13 @@
 
             r1 = s.Contains(new BoundingSphere(new Vector3(22, 35, 41), 17));
             Assert.AreEqual(ContainmentType.Disjoint, r1, "BoundingSphere#3");
+        }
 
+
+        [Test]
+        public void ContainsVector3()
+        {
+            ContainmentType r1;
             r1 = s.Contains(new Vector3(4, 4, 4));
             Assert.AreEqual(ContainmentType.Contains, r1, "Vector3#1");
 
@@ -109,7 +130,28 @@
             s.Contains(null);
         }
 
+        [Test]
+        public void CreateMerged()
+        {
+            BoundingSphere result = BoundingSphere.CreateMerged(s, new 
BoundingSphere(new Vector3(2,3,4),6));
+            Assert.AreEqual(new BoundingSphere(new Vector3(2,3,4),6), 
result,"SphereMerge#1");
 
+            result = BoundingSphere.CreateMerged(s, new BoundingSphere(new 
Vector3(2, 3, 3), 2));
+            Assert.AreEqual(new BoundingSphere(new Vector3(2, 3, 4), 5), 
result, "SphereMerge#2");
+
+            result = BoundingSphere.CreateMerged(s, new BoundingSphere(new 
Vector3(2, 3, -2), 1));//just hit
+            Assert.AreEqual(new BoundingSphere(new Vector3(2, 3, 3), 6), 
result, "SphereMerge#3");
+
+            result = BoundingSphere.CreateMerged(s, new BoundingSphere(new 
Vector3(2, 3, -2), 3));//intersect
+            Assert.AreEqual(new BoundingSphere(new Vector3(2, 3, 2), 7), 
result, "SphereMerge#4");
+
+            result = BoundingSphere.CreateMerged(s, new BoundingSphere(new 
Vector3(2, 3, -4), 1));//disjoint
+            Assert.AreEqual(new BoundingSphere(new Vector3(2, 3, 2), 7), 
result, "SphereMerge#5");
+
+
+        }
+        
+
         [Test]
         public void TestEquals()
         {
@@ -133,7 +175,7 @@
 
 
         [Test]
-        public void Intersects()
+        public void IntersectsBoundingBox()
         {
             bool result;
             result = s.Intersects(new BoundingBox(new Vector3(2, 3, 4), new 
Vector3(55, 44, 32)));
@@ -144,7 +186,13 @@
 
             result = s.Intersects(new BoundingBox(new Vector3(55, 53, 35), new 
Vector3(55, 55, 53)));
             Assert.AreEqual(false, result, "BoundingBox#3");
+        }
 
+
+        [Test]
+        public void IntersectsBoundingFrustum()
+        {
+            bool result;
             result = s.Intersects(new BoundingFrustum(new Matrix(1, 2, 3, 2, 
1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 1)));
             Assert.AreEqual(true, result, "BoundingFrustum#1");
 
@@ -153,13 +201,24 @@
 
             result = s.Intersects(new BoundingFrustum(new Matrix(57, 47, 36, 
85, 37, 253, 4587, 457, 34, 457, 347, 246, 458, 5698, 35473, 46)));
             Assert.AreEqual(false, result, "BoundingFrustum#3");
+        }
 
+
+        [Test]
+        public void IntersectsBoundingSphere()
+        {
+            bool result;
             result = s.Intersects(new BoundingSphere(new Vector3(2, 2, 2), 2));
             Assert.AreEqual(true, result, "BoundingSphere#1");
 
             result = s.Intersects(new BoundingSphere(new Vector3(12, 14, 241), 
15));
             Assert.AreEqual(false, result, "BoundingSphere#2");
+        }
 
+
+        [Test]
+        public void IntersectsPlane()
+        {
             PlaneIntersectionType result2;
             result2 = s.Intersects(new Plane(new Vector4(2, 3, 4, 5)));
             Assert.AreEqual(PlaneIntersectionType.Front, result2, "Plane#1");
@@ -169,7 +228,12 @@
 
             result2 = s.Intersects(new Plane(new Vector4(-1, -2, -3, 0)));
             Assert.AreEqual(PlaneIntersectionType.Back, result2, "Plane#3");
+        }
 
+
+        [Test]
+        public void IntersectsRay()
+        {
             float? result3;
             result3 = s.Intersects(new Ray(new Vector3(23, 25, 12), new 
Vector3(12, 13, 13)));
             Assert.AreEqual(null, result3, "Vector3#1");

Modified: 
trunk/Mono.Xna/tests/Microsoft.Xna.Framework/CurveKeyCollectionTests.cs
===================================================================
--- trunk/Mono.Xna/tests/Microsoft.Xna.Framework/CurveKeyCollectionTests.cs     
2007-01-13 18:41:29 UTC (rev 70960)
+++ trunk/Mono.Xna/tests/Microsoft.Xna.Framework/CurveKeyCollectionTests.cs     
2007-01-13 18:45:24 UTC (rev 70961)
@@ -57,18 +57,26 @@
             c.Add(k3);
         }
 
+        [Test]
+        public void ConstructTests()
+        {
+            Assert.AreEqual(k3, c[0], "#1");
+            Assert.AreEqual(k2, c[1], "#2");
+            Assert.AreEqual(k1, c[2], "#3");
+        }
 
+
         [Test]
         public void Add()
         {
             CurveKey k = new CurveKey(123, 123);
             c.Add(k);
-            Assert.IsTrue(c.Count == 4, "#1");
-            Assert.IsTrue(c[3].Equals(k), "#2");
+            Assert.AreEqual(4, c.Count, "#1");
+            Assert.AreEqual((k), c[3], "#2");
 
             c.Add(k);
-            Assert.IsTrue(c.Count == 5, "#3");
-            Assert.IsTrue(c[4].Equals(k), "#4");
+            Assert.AreEqual(5, c.Count, "#3");
+            Assert.AreEqual((k), c[4], "#4");
         }
 
 
@@ -151,7 +159,6 @@
             Assert.AreEqual(2, c.IndexOf(k1), "#1");
             Assert.AreEqual(1, c.IndexOf(k2), "#2");
             Assert.AreEqual(0, c.IndexOf(k3), "#3");
-
             Assert.AreEqual(-1, c.IndexOf(null), "#4");
         }
 

Added: trunk/Mono.Xna/tests/Microsoft.Xna.Framework/Vector3Tests.cs
===================================================================
--- trunk/Mono.Xna/tests/Microsoft.Xna.Framework/Vector3Tests.cs        
2007-01-13 18:41:29 UTC (rev 70960)
+++ trunk/Mono.Xna/tests/Microsoft.Xna.Framework/Vector3Tests.cs        
2007-01-13 18:45:24 UTC (rev 70961)
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NUnit.Framework;
+using Microsoft.Xna.Framework;
+using System.Globalization;
+
+
+namespace XnaNUnits
+{
+    [TestFixture]
+    public class Vector3Tests
+    {
+        Vector3 a;
+        Vector3 b;
+        Vector3 c;
+        [SetUp]
+        public void Setup()
+        {
+            a = new Vector3(1, 2, 3);
+            b = new Vector3(4.5f, 6f, 7f);
+            c = new Vector3(-124, 352.234f, 123.123f);
+        }
+
+        [Test]
+        public void ToStringTest()
+        {
+            Assert.AreEqual("{X:-124 Y:352.234 Z:123.123}", c.ToString());
+            System.Threading.Thread.CurrentThread.CurrentCulture = 
CultureInfo.GetCultureInfo("de-DE");
+            Assert.AreEqual("{X:-124 Y:352,234 Z:123,123}", c.ToString());
+        }
+    }
+}


Property changes on: 
trunk/Mono.Xna/tests/Microsoft.Xna.Framework/Vector3Tests.cs
___________________________________________________________________
Name: svn:eol-style
   + native

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to