Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #215
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed May 3, 2014
2 parents 61f528d + de40a13 commit e5793ed
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 149 deletions.
28 changes: 18 additions & 10 deletions MonoGame.Framework/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ public ContainmentType Contains(BoundingBox box)
public ContainmentType Contains(BoundingFrustum frustum)
{
/* TODO: bad done here need a fix.
* Because question is not frustum contain box but reverse and this is not the same
* Because the question is not if frustum contains box but the reverse and
* this is not the same.
*/
int i;
ContainmentType contained;
Vector3[] corners = frustum.GetCorners();

// First we check if frustum is in box
// First we check if frustum is in box.
for (i = 0; i < corners.Length; i += 1)
{
this.Contains(ref corners[i], out contained);
Expand All @@ -146,15 +147,16 @@ public ContainmentType Contains(BoundingFrustum frustum)
return ContainmentType.Contains;
}

// if i is not equal to zero, we can fastpath and say that this box intersects
// If i is not equal to zero, we can fastpath and say that this box intersects
if (i != 0)
{
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
/* 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 += 1;
Expand All @@ -168,7 +170,9 @@ public ContainmentType Contains(BoundingFrustum frustum)

}

// If we get here, then we know all the points were actually contained, therefore result is Contains
/* If we get here, then we know all the points were actually contained,
* therefore result is Contains.
*/
return ContainmentType.Contains;
}

Expand Down Expand Up @@ -262,7 +266,7 @@ public ContainmentType Contains(BoundingSphere sphere)

public void Contains(ref Vector3 point, out ContainmentType result)
{
// first we get if point is out of box
// First determine if point is outside of this box.
if ( point.X < this.Min.X ||
point.X > this.Max.X ||
point.Y < this.Min.Y ||
Expand All @@ -272,7 +276,7 @@ public void Contains(ref Vector3 point, out ContainmentType result)
{
result = ContainmentType.Disjoint;
}
// or if point is on box because coordonate of point is lesser or equal
// Or, if the point is on box because coordinate is less than or equal.
else if ( MathHelper.WithinEpsilon(point.X, this.Min.X) ||
MathHelper.WithinEpsilon(point.X, this.Max.X) ||
MathHelper.WithinEpsilon(point.Y, this.Min.Y) ||
Expand Down Expand Up @@ -508,9 +512,13 @@ public bool Equals(BoundingBox other)
/// <summary>
/// Create a bounding box from the given list of points.
/// </summary>
/// <param name="points">The list of Vector3 instances defining the point cloud to bound</param>
/// <param name="points">
/// The list of Vector3 instances defining the point cloud to bound.
/// </param>
/// <returns>A bounding box that encapsulates the given point cloud.</returns>
/// <exception cref="System.ArgumentException">Thrown if the given list has no points.</exception>
/// <exception cref="System.ArgumentException">
/// Thrown if the given list has no points.
/// </exception>
public static BoundingBox CreateFromPoints(IEnumerable<Vector3> points)
{
if (points == null)
Expand Down
19 changes: 12 additions & 7 deletions MonoGame.Framework/BoundingFrustum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public Matrix Matrix
}
set
{
/* 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 ;)
/* 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.matrix = value;
this.CreatePlanes();
Expand Down Expand Up @@ -183,7 +183,7 @@ public void Contains(ref BoundingSphere sphere, out ContainmentType result)
{
PlaneIntersectionType planeIntersectionType = default(PlaneIntersectionType);

// TODO: we might want to inline this for performance reasons
// TODO: We might want to inline this for performance reasons.
sphere.Intersects(ref this.planes[i], out planeIntersectionType);
switch (planeIntersectionType)
{
Expand Down Expand Up @@ -397,14 +397,19 @@ private void NormalizePlane(ref Plane p)

#region Private Static Methods

private static void IntersectionPoint(ref Plane a, ref Plane b, ref Plane c, out Vector3 result)
{
private static void IntersectionPoint(
ref Plane a,
ref Plane b,
ref Plane c,
out Vector3 result
) {
/* Formula used
* d1 ( N2 * N3 ) + d2 ( N3 * N1 ) + d3 ( N1 * N2 )
* P = -------------------------------------------------------------------------
* P = -------------------------------------------------------------------
* N1 . ( N2 * N3 )
*
* Note: N refers to the normal, d refers to the displacement. '.' means dot product. '*' means cross product
* Note: N refers to the normal, d refers to the displacement. '.' means dot
* product. '*' means cross product
*/

Vector3 v1, v2, v3;
Expand Down
16 changes: 8 additions & 8 deletions MonoGame.Framework/BoundingSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void Contains(ref Vector3 point, out ContainmentType result)

public ContainmentType Contains(BoundingBox box)
{
// Check if all corner is in sphere
// Check if all corners are in sphere.
bool inside = true;
foreach (Vector3 corner in box.GetCorners())
{
Expand All @@ -135,7 +135,7 @@ public ContainmentType Contains(BoundingBox box)
return ContainmentType.Contains;
}

// Check if the distance from sphere center to cube face < radius
// Check if the distance from sphere center to cube face is less than radius.
double dmin = 0;

if (Center.X < box.Min.X)
Expand Down Expand Up @@ -176,7 +176,7 @@ public ContainmentType Contains(BoundingBox box)

public ContainmentType Contains(BoundingFrustum frustum)
{
// Check if all corner is in sphere
// Check if all corners are in sphere.
bool inside = true;

Vector3[] corners = frustum.GetCorners();
Expand All @@ -193,7 +193,7 @@ public ContainmentType Contains(BoundingFrustum frustum)
return ContainmentType.Contains;
}

// Check if the distance from sphere center to frustrum face < radius
// Check if the distance from sphere center to frustrum face is less than radius.
double dmin = 0;
// TODO : calcul dmin

Expand Down Expand Up @@ -326,13 +326,13 @@ public static BoundingSphere CreateMerged(BoundingSphere original, BoundingSpher
// Intersect
if (distance <= original.Radius + additional.Radius)
{
// Original contain additional
// Original contains additional.
if (distance <= original.Radius - additional.Radius)
{
return original;
}

// Additional contain original
// Additional contains original.
if (distance <= additional.Radius - original.Radius)
{
return additional;
Expand Down Expand Up @@ -402,15 +402,15 @@ public bool Intersects(BoundingSphere sphere)
public PlaneIntersectionType Intersects(Plane plane)
{
PlaneIntersectionType result = default(PlaneIntersectionType);
// TODO: we might want to inline this for performance reasons
// TODO: We might want to inline this for performance reasons.
this.Intersects(ref plane, out result);
return result;
}

public void Intersects(ref Plane plane, out PlaneIntersectionType result)
{
float distance = default(float);
// TODO: we might want to inline this for performance reasons
// TODO: We might want to inline this for performance reasons.
Vector3.Dot(ref plane.Normal, ref this.Center, out distance);
distance += plane.D;
if (distance > this.Radius)
Expand Down
56 changes: 39 additions & 17 deletions MonoGame.Framework/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ static Color()
/// <summary>
/// Creates a new instance of <see cref="Color"/> struct.
/// </summary>
/// <param name="color">A <see cref="Vector4"/> representing color.</param>
/// <param name="color">A <see cref="Vector4"/> representing a color.</param>
public Color(Vector4 color)
{
_packedValue = 0;
Expand All @@ -1588,7 +1588,7 @@ public Color(Vector4 color)
/// <summary>
/// Creates a new instance of <see cref="Color"/> struct.
/// </summary>
/// <param name="color">A <see cref="Vector3"/> representing color.</param>
/// <param name="color">A <see cref="Vector3"/> representing a color.</param>
public Color(Vector3 color)
{
_packedValue = 0;
Expand All @@ -1602,7 +1602,9 @@ public Color(Vector3 color)
/// <summary>
/// Creates a new instance of <see cref="Color"/> struct.
/// </summary>
/// <param name="color">A <see cref="Color"/> for RGB values of new <see cref="Color"/> instance.</param>
/// <param name="color">
/// A <see cref="Color"/> for RGB values of new <see cref="Color"/> instance.
/// </param>
/// <param name="alpha">Alpha component value.</param>
public Color(Color color, int alpha)
{
Expand All @@ -1617,7 +1619,9 @@ public Color(Color color, int alpha)
/// <summary>
/// Creates a new instance of <see cref="Color"/> struct.
/// </summary>
/// <param name="color">A <see cref="Color"/> for RGB values of new <see cref="Color"/> instance.</param>
/// <param name="color">
/// A <see cref="Color"/> for RGB values of new <see cref="Color"/> instance.
/// </param>
/// <param name="alpha">Alpha component value.</param>
public Color(Color color, float alpha)
{
Expand All @@ -1634,7 +1638,7 @@ public Color(Color color, float alpha)
/// </summary>
/// <param name="r">Red component value.</param>
/// <param name="g">Green component value.</param>
/// <param name="b">Blue component value</param>
/// <param name="b">Blue component value.</param>
public Color(float r, float g, float b)
{
_packedValue = 0;
Expand All @@ -1650,7 +1654,7 @@ public Color(float r, float g, float b)
/// </summary>
/// <param name="r">Red component value.</param>
/// <param name="g">Green component value.</param>
/// <param name="b">Blue component value</param>
/// <param name="b">Blue component value.</param>
public Color(int r, int g, int b)
{
_packedValue = 0;
Expand All @@ -1665,7 +1669,7 @@ public Color(int r, int g, int b)
/// </summary>
/// <param name="r">Red component value.</param>
/// <param name="g">Green component value.</param>
/// <param name="b">Blue component value</param>
/// <param name="b">Blue component value.</param>
/// <param name="alpha">Alpha component value.</param>
public Color(int r, int g, int b, int alpha)
{
Expand All @@ -1681,7 +1685,7 @@ public Color(int r, int g, int b, int alpha)
/// </summary>
/// <param name="r">Red component value.</param>
/// <param name="g">Green component value.</param>
/// <param name="b">Blue component value</param>
/// <param name="b">Blue component value.</param>
/// <param name="alpha">Alpha component value.</param>
public Color(float r, float g, float b, float alpha)
{
Expand Down Expand Up @@ -1755,17 +1759,24 @@ public static Color Lerp(Color value1, Color value2, Single amount)
}

/// <summary>
/// Translate a non-premultipled alpha <see cref="Color"/> to a <see cref="Color"/> that contains premultiplied alpha.
/// Translate a non-premultipled alpha <see cref="Color"/> to a <see cref="Color"/>
/// that contains premultiplied alpha.
/// </summary>
/// <param name="vector">A <see cref="Vector4"/> representing color.</param>
/// <returns>A <see cref="Color"/> which contains premultiplied alpha data.</returns>
public static Color FromNonPremultiplied(Vector4 vector)
{
return new Color(vector.X * vector.W, vector.Y * vector.W, vector.Z * vector.W, vector.W);
return new Color(
vector.X * vector.W,
vector.Y * vector.W,
vector.Z * vector.W,
vector.W
);
}

/// <summary>
/// Translate a non-premultipled alpha <see cref="Color"/> to a <see cref="Color"/> that contains premultiplied alpha.
/// Translate a non-premultipled alpha <see cref="Color"/> to a <see cref="Color"/>
/// that contains premultiplied alpha.
/// </summary>
/// <param name="r">Red component value.</param>
/// <param name="g">Green component value.</param>
Expand All @@ -1774,7 +1785,12 @@ public static Color FromNonPremultiplied(Vector4 vector)
/// <returns>A <see cref="Color"/> which contains premultiplied alpha data.</returns>
public static Color FromNonPremultiplied(int r, int g, int b, int a)
{
return new Color((byte) (r * a / 255), (byte) (g * a / 255), (byte) (b * a / 255), a);
return new Color(
(byte) (r * a / 255),
(byte) (g * a / 255),
(byte) (b * a / 255),
a
);
}

#endregion
Expand All @@ -1786,7 +1802,7 @@ public static Color FromNonPremultiplied(int r, int g, int b, int a)
/// </summary>
/// <param name="a"><see cref="Color"/> instance on the left of the equal sign.</param>
/// <param name="b"><see cref="Color"/> instance on the right of the equal sign.</param>
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
/// <returns><c>True</c> if the instances are equal; <c>false</c> otherwise.</returns>
public static bool operator ==(Color a, Color b)
{
return ( a.A == b.A &&
Expand All @@ -1798,9 +1814,15 @@ public static Color FromNonPremultiplied(int r, int g, int b, int a)
/// <summary>
/// Compares whether two <see cref="Color"/> instances are not equal.
/// </summary>
/// <param name="a"><see cref="Color"/> instance on the left of the not equal sign.</param>
/// <param name="b"><see cref="Color"/> instance on the right of the not equal sign.</param>
/// <returns><c>true</c> if the instances are not equal; <c>false</c> otherwise.</returns>
/// <param name="a">
/// <see cref="Color"/> instance on the left of the not equal sign.
/// </param>
/// <param name="b">
/// <see cref="Color"/> instance on the right of the not equal sign.
/// </param>
/// <returns>
/// <c>True</c> if the instances are not equal; <c>false</c> otherwise.
/// </returns>
public static bool operator !=(Color a, Color b)
{
return !(a == b);
Expand All @@ -1819,7 +1841,7 @@ public override int GetHashCode()
/// Compares whether current instance is equal to specified object.
/// </summary>
/// <param name="obj">The <see cref="Color"/> to compare.</param>
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
/// <returns><c>True</c> if the instances are equal; <c>false</c> otherwise.</returns>
public override bool Equals(object obj)
{
return ((obj is Color) && this.Equals((Color) obj));
Expand Down
Loading

0 comments on commit e5793ed

Please sign in to comment.