Sphere Module of libSIMDx86

The Sphere module of libSIMDx86 gives functions to accelerate sphere functions often used in collision detection between two objects. A sphere has a central point as a 3D vector and a radius as a floating point number.

#include <SIMDx86/sphere.h>

typedef struct SIMDx86Sphere

{

SIMDx86Vector Center;

float radius;

float __SIMD_pad__[3]; /* Pad to 16th byte for efficient SIMD operation */

} SIMDx86Sphere;


int SIMDx86Sphere_SphereCollision(const SIMDx86Sphere* pIn1, const SIMDx86Sphere* pIn2)

Calculates whether 'pIn1' and 'pIn2' are colliding with eachother, including touching, and returns non-zero if they are. This can be used to implement efficient sphere collision with each sphere representing the bounds of an object.


int SIMDx86Sphere_ContainsPoint(const SIMDx86Sphere* pSphere, const SIMDx86Vector* pVec)

Calculates whether 'pVec' is contained inside of 'pSphere'.


int SIMDx86Sphere_ContainsPolygon(const SIMDx86Sphere* pSphere, const SIMDx86Polygon* pPoly)

Calculates whether 'pPoly' is completely contained by 'pSphere'.


float SIMDx86Sphere_DistanceToPoint(const SIMDx86Sphere* pSphere, const SIMDx86Vector* pVec)

Calculates the distance between 'pSphere' and 'pVec'

float SIMDx86Sphere_DistanceToPointSq(const SIMDx86Sphere* pSphere, const SIMDx86Vector* pVec)

Calculates the squared distance between 'pSphere' and 'pVec'.


float SIMDx86Sphere_DistanceToSphere(const SIMDx86Sphere* pSphere1, const SIMDx86Sphere* pSphere1)

Calculates the distance between 'pSphere1' and 'pSphere2'. Unlike SIMDx86Vector_Length(), this function is faster than its compliment, SIMDx86Sphere_DistanceToSphereSq().


float SIMDx86Sphere_DistanceToSphereSq(const SIMDx86Sphere* pSphere1, const SIMDx86Sphere* pSphere1)

Calculates the squared distance between 'pSphere1' and 'pSphere2'. Unlike SIMDx86Vector_LengthSq(), this function is not faster than its compliment, SIMDx86Sphere_DistanceToSphere().