-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
251 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* @file | ||
* @author Benny Bobaganoosh <[email protected]> | ||
* @section LICENSE | ||
* | ||
* Copyright (C) 2014 Benny Bobaganoosh | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "aabb.h" | ||
|
||
IntersectData AABB::IntersectAABB(const AABB& other) const | ||
{ | ||
//The distance between the AABB's on the X, Y, and Z axis. | ||
//Computed twice because there are two possible valid distances, depending | ||
//on the location of the AABB's. | ||
Vector3f distances1 = other.GetMinExtents() - m_maxExtents; | ||
Vector3f distances2 = m_minExtents - other.GetMaxExtents(); | ||
|
||
//The correct distances will be whichever distance is larger for that | ||
//particular axis. | ||
Vector3f distances = Vector3f(distances1.Max(distances2)); | ||
|
||
float maxDistance = distances.Max(); | ||
|
||
//If there is any distance between the two AABB's, then max distance will | ||
//be greather than or equal to 0. If there is distance between the two | ||
//AABBs, then they aren't intersecting. | ||
// | ||
//Therefore, if the AABBs are intersecting, then the distance between them | ||
//must be less than zero. | ||
return IntersectData(maxDistance < 0, maxDistance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* @file | ||
* @author Benny Bobaganoosh <[email protected]> | ||
* @section LICENSE | ||
* | ||
* Copyright (C) 2014 Benny Bobaganoosh | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef AABB_INCLUDED_H | ||
#define AABB_INCLUDED_H | ||
|
||
#include "math3d.h" | ||
#include "intersectData.h" | ||
|
||
/** | ||
* The AABB class represents an Axis Aligned Bounding Box that can be used as | ||
* a collider in a physics engine. | ||
*/ | ||
class AABB | ||
{ | ||
public: | ||
/** | ||
* Creates an AABB in a usable state. | ||
* | ||
* @param minExtents The corner of the AABB with the smallest coordinates. | ||
* @param maxExtents The corner of the AABB with the largest coordinates. | ||
*/ | ||
AABB(const Vector3f& minExtents, const Vector3f& maxExtents) : | ||
m_minExtents(minExtents), | ||
m_maxExtents(maxExtents) {} | ||
|
||
/** | ||
* Computes information about if this AABB intersects another AABB. | ||
* | ||
* @param other The AABB that's being tested for intersection with this | ||
* AABB. | ||
*/ | ||
IntersectData IntersectAABB(const AABB& other) const; | ||
|
||
/** Basic getter for the min extents */ | ||
inline const Vector3f& GetMinExtents() const { return m_minExtents; } | ||
/** Basic getter for the max extents */ | ||
inline const Vector3f& GetMaxExtents() const { return m_maxExtents; } | ||
private: | ||
/** The corner of the AABB with the smallest coordinates */ | ||
const Vector3f m_minExtents; | ||
/** The corner of the AABB with the largest coordinates */ | ||
const Vector3f m_maxExtents; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,41 @@ | ||
/* | ||
* @file | ||
* @author Benny Bobaganoosh <[email protected]> | ||
* @section LICENSE | ||
* | ||
* Copyright (C) 2014 Benny Bobaganoosh | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "boundingSphere.h" | ||
|
||
IntersectData BoundingSphere::IntersectBoundingSphere(const BoundingSphere& other) | ||
IntersectData BoundingSphere::IntersectBoundingSphere(const BoundingSphere& other) const | ||
{ | ||
//The radius is the distance from any point on the sphere to the center. | ||
// | ||
//Therefore, by adding the radius of two spheres together, the result is | ||
//the distance between the centers of the spheres when they are touching. | ||
float radiusDistance = m_radius + other.GetRadius(); | ||
float centerDistance = (other.GetCenter() - m_center).Length(); | ||
|
||
//Since the radiusDistance is the distance bwteen the centers of the | ||
//spheres are when they're touching, you can subtract that from the | ||
//distance between the centers of the spheres to get the actual distance | ||
//between the two spheres. | ||
float distance = centerDistance - radiusDistance; | ||
|
||
return IntersectData(centerDistance < radiusDistance, distance); | ||
//Spheres can only be intersecting if the distance between them is less | ||
//than 0. | ||
return IntersectData(distance < 0, distance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,62 @@ | ||
/* | ||
* @file | ||
* @author Benny Bobaganoosh <[email protected]> | ||
* @section LICENSE | ||
* | ||
* Copyright (C) 2014 Benny Bobaganoosh | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef BOUNDING_SPHERE_INCLUDED_H | ||
#define BOUNDING_SPHERE_INCLUDED_H | ||
|
||
#include "math3d.h" | ||
#include "intersectData.h" | ||
|
||
/** | ||
* The BoundingSphere class represents an sphere that can be used as a | ||
* collider in a physics engine. | ||
*/ | ||
class BoundingSphere | ||
{ | ||
public: | ||
/** | ||
* Creates a BoundingSphere in a usable state. | ||
* | ||
* @param center The center point of the sphere. | ||
* @param radius The distance from any point on the sphere to the center. | ||
*/ | ||
BoundingSphere(const Vector3f& center, float radius) : | ||
m_center(center), | ||
m_radius(radius) {} | ||
|
||
IntersectData IntersectBoundingSphere(const BoundingSphere& other); | ||
/** | ||
* Computes information about if this sphere intersects another aphere. | ||
* | ||
* @param other The sphere that's being tested for intersection with this | ||
* sphere. | ||
*/ | ||
IntersectData IntersectBoundingSphere(const BoundingSphere& other) const; | ||
|
||
/** Basic getter for the center */ | ||
inline const Vector3f& GetCenter() const { return m_center; } | ||
/** Basic getter for the radius */ | ||
inline float GetRadius() const { return m_radius; } | ||
private: | ||
/** The center point of the sphere */ | ||
const Vector3f m_center; | ||
/** The distance from any point on the sphere to the center */ | ||
const float m_radius; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,50 @@ | ||
/* | ||
* @file | ||
* @author Benny Bobaganoosh <[email protected]> | ||
* @section LICENSE | ||
* | ||
* Copyright (C) 2014 Benny Bobaganoosh | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef INTERSECT_DATA_INCLUDED_H | ||
#define INTERSECT_DATA_INCLUDED_H | ||
|
||
/** | ||
* The IntersectData class stores information about two intersecting objects. | ||
*/ | ||
class IntersectData | ||
{ | ||
public: | ||
/** | ||
* Creates Intersect Data in a usable state. | ||
* | ||
* @param doesIntersect Whether or not the objects are intersecting. | ||
* @param distance The distance between the two objects | ||
*/ | ||
IntersectData(const bool doesIntersect, const float distance) : | ||
m_doesIntersect(doesIntersect), | ||
m_distance(distance) {} | ||
|
||
/** Basic getter for m_doesIntersect */ | ||
inline bool GetDoesIntersect() const { return m_doesIntersect; } | ||
/** Basic getter for m_distance */ | ||
inline float GetDistance() const { return m_distance; } | ||
private: | ||
/** Whether or not the objects are intersecting */ | ||
const bool m_doesIntersect; | ||
/** The distance between the two objects */ | ||
const float m_distance; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters