caudio/include/cVector3.h
Joshua Jones 0c3df1d430 Added audio capture capabilities. The user can now get an interface for audio capture from cAudioManager and record audio from the default recording device.
Added a raw audio decoder, allowing raw audio to be played if the format and frequency is known.  Will also load from .raw files on disk, but will assume the format is 16 bit mono and the frequency is 22050 hz
Added a tutorial to show how recording and playback can be done.
Added the ability for the user to unregister audio codecs that they will not be using.  Also added methods to test for the existance of a decoder and get the decoder factory back.
Moved cVector3.h to include instead of Headers to make using it in user projects easier (one less include path)
Moved the audio format enum to its own header file.
Small fix in the wav decoder to prevent the file header from being played as audio data.
2009-08-11 17:57:20 +00:00

135 lines
4.0 KiB
C++

#ifndef CVECTOR3_H
#define CVECTOR3_H
#include <float.h>
#include <math.h>
namespace cAudio
{
inline bool float_equals(const float a, const float b)
{
return (a + FLT_EPSILON >= b) && (a - FLT_EPSILON <= b);
}
class cVector3
{
public:
float x, y, z;
cVector3(void) : x(0), y(0), z(0)
{
}
cVector3(float nx, float ny, float nz) : x(nx), y(ny), z(nz)
{
}
cVector3(float n) : x(n), y(n), z(n)
{
}
cVector3(const cVector3& other) : x(other.x), y(other.y), z(other.z)
{
}
cVector3 operator-() const { return cVector3(-x, -y, -z); }
cVector3& operator=(const cVector3& other) { x = other.x; y = other.y; z = other.z; return *this; }
cVector3 operator+(const cVector3& other) const { return cVector3(x + other.x, y + other.y, z + other.z); }
cVector3& operator+=(const cVector3& other) { x+=other.x; y+=other.y; z+=other.z; return *this; }
cVector3 operator+(const float val) const { return cVector3(x + val, y + val, z + val); }
cVector3& operator+=(const float val) { x+=val; y+=val; z+=val; return *this; }
cVector3 operator-(const cVector3& other) const { return cVector3(x - other.x, y - other.y, z - other.z); }
cVector3& operator-=(const cVector3& other) { x-=other.x; y-=other.y; z-=other.z; return *this; }
cVector3 operator-(const float val) const { return cVector3(x - val, y - val, z - val); }
cVector3& operator-=(const float val) { x-=val; y-=val; z-=val; return *this; }
cVector3 operator*(const cVector3& other) const { return cVector3(x * other.x, y * other.y, z * other.z); }
cVector3& operator*=(const cVector3& other) { x*=other.x; y*=other.y; z*=other.z; return *this; }
cVector3 operator*(const float v) const { return cVector3(x * v, y * v, z * v); }
cVector3& operator*=(const float v) { x*=v; y*=v; z*=v; return *this; }
cVector3 operator/(const cVector3& other) const { return cVector3(x / other.x, y / other.y, z / other.z); }
cVector3& operator/=(const cVector3& other) { x/=other.x; y/=other.y; z/=other.z; return *this; }
cVector3 operator/(const float v) const { float i=(float)1.0/v; return cVector3(x * i, y * i, z * i); }
cVector3& operator/=(const float v) { float i=(float)1.0/v; x*=i; y*=i; z*=i; return *this; }
bool operator<=(const cVector3& other) const { return x<=other.x && y<=other.y && z<=other.z;}
bool operator>=(const cVector3& other) const { return x>=other.x && y>=other.y && z>=other.z;}
bool operator<(const cVector3& other) const { return x<other.x && y<other.y && z<other.z;}
bool operator>(const cVector3& other) const { return x>other.x && y>other.y && z>other.z;}
bool operator==(const cVector3& other) const
{
return float_equals(x, other.x) &&
float_equals(y, other.y) &&
float_equals(z, other.z);
}
bool operator!=(const cVector3& other) const
{
return !(float_equals(x, other.x) &&
float_equals(y, other.y) &&
float_equals(z, other.z));
}
operator const float*() const { return &x; }
operator float*() { return &x; }
const float operator[] ( int i ) const { return ( ( float* ) &x ) [i]; }
float &operator[] ( int i ) { return ( ( float* ) &x ) [i]; }
float length() const
{
return sqrtf( x*x + y*y + z*z );
}
void normalize()
{
float invLen = 1.0f / length();
x *= invLen;
y *= invLen;
z *= invLen;
}
float dot( const cVector3& other ) const
{
return ( x * other.x + y * other.y + z * other.z );
}
cVector3 cross( const cVector3& other ) const
{
return cVector3( y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x );
}
void set( float nx, float ny, float nz )
{
x = nx;
y = ny;
z = nz;
}
void set( float n )
{
x = y = z = n;
}
void set( const cVector3& other )
{
x = other.x;
y = other.y;
z = other.z;
}
void getAsArray(float* output)
{
output[0] = x;
output[1] = y;
output[2] = z;
}
};
};
#endif //! CVECTOR3_H