Initial commit
This commit is contained in:
718
Lib/Include/AL/al.h
Normal file
718
Lib/Include/AL/al.h
Normal file
@@ -0,0 +1,718 @@
|
||||
#ifndef AL_AL_H
|
||||
#define AL_AL_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef AL_API
|
||||
#if defined(AL_LIBTYPE_STATIC)
|
||||
#define AL_API
|
||||
#elif defined(_WIN32)
|
||||
#define AL_API __declspec(dllimport)
|
||||
#else
|
||||
#define AL_API extern
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define AL_APIENTRY __cdecl
|
||||
#else
|
||||
#define AL_APIENTRY
|
||||
#endif
|
||||
|
||||
#if defined(TARGET_OS_MAC) && TARGET_OS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The OPENAL, ALAPI, ALAPIENTRY, AL_INVALID, AL_ILLEGAL_ENUM, and
|
||||
* AL_ILLEGAL_COMMAND macros are deprecated, but are included for
|
||||
* applications porting code from AL 1.0
|
||||
*/
|
||||
#define OPENAL
|
||||
#define ALAPI AL_API
|
||||
#define ALAPIENTRY AL_APIENTRY
|
||||
#define AL_INVALID (-1)
|
||||
#define AL_ILLEGAL_ENUM AL_INVALID_ENUM
|
||||
#define AL_ILLEGAL_COMMAND AL_INVALID_OPERATION
|
||||
|
||||
#define AL_VERSION_1_0
|
||||
#define AL_VERSION_1_1
|
||||
|
||||
|
||||
/** 8-bit boolean */
|
||||
typedef char ALboolean;
|
||||
|
||||
/** character */
|
||||
typedef char ALchar;
|
||||
|
||||
/** signed 8-bit 2's complement integer */
|
||||
typedef signed char ALbyte;
|
||||
|
||||
/** unsigned 8-bit integer */
|
||||
typedef unsigned char ALubyte;
|
||||
|
||||
/** signed 16-bit 2's complement integer */
|
||||
typedef short ALshort;
|
||||
|
||||
/** unsigned 16-bit integer */
|
||||
typedef unsigned short ALushort;
|
||||
|
||||
/** signed 32-bit 2's complement integer */
|
||||
typedef int ALint;
|
||||
|
||||
/** unsigned 32-bit integer */
|
||||
typedef unsigned int ALuint;
|
||||
|
||||
/** non-negative 32-bit binary integer size */
|
||||
typedef int ALsizei;
|
||||
|
||||
/** enumerated 32-bit value */
|
||||
typedef int ALenum;
|
||||
|
||||
/** 32-bit IEEE754 floating-point */
|
||||
typedef float ALfloat;
|
||||
|
||||
/** 64-bit IEEE754 floating-point */
|
||||
typedef double ALdouble;
|
||||
|
||||
/** void type (for opaque pointers only) */
|
||||
typedef void ALvoid;
|
||||
|
||||
|
||||
/* Enumerant values begin at column 50. No tabs. */
|
||||
|
||||
/* "no distance model" or "no buffer" */
|
||||
#define AL_NONE 0
|
||||
|
||||
/* Boolean False. */
|
||||
#define AL_FALSE 0
|
||||
|
||||
/** Boolean True. */
|
||||
#define AL_TRUE 1
|
||||
|
||||
/** Indicate Source has relative coordinates. */
|
||||
#define AL_SOURCE_RELATIVE 0x202
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Directional source, inner cone angle, in degrees.
|
||||
* Range: [0-360]
|
||||
* Default: 360
|
||||
*/
|
||||
#define AL_CONE_INNER_ANGLE 0x1001
|
||||
|
||||
/**
|
||||
* Directional source, outer cone angle, in degrees.
|
||||
* Range: [0-360]
|
||||
* Default: 360
|
||||
*/
|
||||
#define AL_CONE_OUTER_ANGLE 0x1002
|
||||
|
||||
/**
|
||||
* Specify the pitch to be applied at source.
|
||||
* Range: [0.5-2.0]
|
||||
* Default: 1.0
|
||||
*/
|
||||
#define AL_PITCH 0x1003
|
||||
|
||||
/**
|
||||
* Specify the current location in three dimensional space.
|
||||
* OpenAL, like OpenGL, uses a right handed coordinate system,
|
||||
* where in a frontal default view X (thumb) points right,
|
||||
* Y points up (index finger), and Z points towards the
|
||||
* viewer/camera (middle finger).
|
||||
* To switch from a left handed coordinate system, flip the
|
||||
* sign on the Z coordinate.
|
||||
* Listener position is always in the world coordinate system.
|
||||
*/
|
||||
#define AL_POSITION 0x1004
|
||||
|
||||
/** Specify the current direction. */
|
||||
#define AL_DIRECTION 0x1005
|
||||
|
||||
/** Specify the current velocity in three dimensional space. */
|
||||
#define AL_VELOCITY 0x1006
|
||||
|
||||
/**
|
||||
* Indicate whether source is looping.
|
||||
* Type: ALboolean?
|
||||
* Range: [AL_TRUE, AL_FALSE]
|
||||
* Default: FALSE.
|
||||
*/
|
||||
#define AL_LOOPING 0x1007
|
||||
|
||||
/**
|
||||
* Indicate the buffer to provide sound samples.
|
||||
* Type: ALuint.
|
||||
* Range: any valid Buffer id.
|
||||
*/
|
||||
#define AL_BUFFER 0x1009
|
||||
|
||||
/**
|
||||
* Indicate the gain (volume amplification) applied.
|
||||
* Type: ALfloat.
|
||||
* Range: ]0.0- ]
|
||||
* A value of 1.0 means un-attenuated/unchanged.
|
||||
* Each division by 2 equals an attenuation of -6dB.
|
||||
* Each multiplicaton with 2 equals an amplification of +6dB.
|
||||
* A value of 0.0 is meaningless with respect to a logarithmic
|
||||
* scale; it is interpreted as zero volume - the channel
|
||||
* is effectively disabled.
|
||||
*/
|
||||
#define AL_GAIN 0x100A
|
||||
|
||||
/*
|
||||
* Indicate minimum source attenuation
|
||||
* Type: ALfloat
|
||||
* Range: [0.0 - 1.0]
|
||||
*
|
||||
* Logarthmic
|
||||
*/
|
||||
#define AL_MIN_GAIN 0x100D
|
||||
|
||||
/**
|
||||
* Indicate maximum source attenuation
|
||||
* Type: ALfloat
|
||||
* Range: [0.0 - 1.0]
|
||||
*
|
||||
* Logarthmic
|
||||
*/
|
||||
#define AL_MAX_GAIN 0x100E
|
||||
|
||||
/**
|
||||
* Indicate listener orientation.
|
||||
*
|
||||
* at/up
|
||||
*/
|
||||
#define AL_ORIENTATION 0x100F
|
||||
|
||||
/**
|
||||
* Source state information.
|
||||
*/
|
||||
#define AL_SOURCE_STATE 0x1010
|
||||
#define AL_INITIAL 0x1011
|
||||
#define AL_PLAYING 0x1012
|
||||
#define AL_PAUSED 0x1013
|
||||
#define AL_STOPPED 0x1014
|
||||
|
||||
/**
|
||||
* Buffer Queue params
|
||||
*/
|
||||
#define AL_BUFFERS_QUEUED 0x1015
|
||||
#define AL_BUFFERS_PROCESSED 0x1016
|
||||
|
||||
/**
|
||||
* Source buffer position information
|
||||
*/
|
||||
#define AL_SEC_OFFSET 0x1024
|
||||
#define AL_SAMPLE_OFFSET 0x1025
|
||||
#define AL_BYTE_OFFSET 0x1026
|
||||
|
||||
/*
|
||||
* Source type (Static, Streaming or undetermined)
|
||||
* Source is Static if a Buffer has been attached using AL_BUFFER
|
||||
* Source is Streaming if one or more Buffers have been attached using alSourceQueueBuffers
|
||||
* Source is undetermined when it has the NULL buffer attached
|
||||
*/
|
||||
#define AL_SOURCE_TYPE 0x1027
|
||||
#define AL_STATIC 0x1028
|
||||
#define AL_STREAMING 0x1029
|
||||
#define AL_UNDETERMINED 0x1030
|
||||
|
||||
/** Sound samples: format specifier. */
|
||||
#define AL_FORMAT_MONO8 0x1100
|
||||
#define AL_FORMAT_MONO16 0x1101
|
||||
#define AL_FORMAT_STEREO8 0x1102
|
||||
#define AL_FORMAT_STEREO16 0x1103
|
||||
|
||||
/**
|
||||
* source specific reference distance
|
||||
* Type: ALfloat
|
||||
* Range: 0.0 - +inf
|
||||
*
|
||||
* At 0.0, no distance attenuation occurs. Default is
|
||||
* 1.0.
|
||||
*/
|
||||
#define AL_REFERENCE_DISTANCE 0x1020
|
||||
|
||||
/**
|
||||
* source specific rolloff factor
|
||||
* Type: ALfloat
|
||||
* Range: 0.0 - +inf
|
||||
*
|
||||
*/
|
||||
#define AL_ROLLOFF_FACTOR 0x1021
|
||||
|
||||
/**
|
||||
* Directional source, outer cone gain.
|
||||
*
|
||||
* Default: 0.0
|
||||
* Range: [0.0 - 1.0]
|
||||
* Logarithmic
|
||||
*/
|
||||
#define AL_CONE_OUTER_GAIN 0x1022
|
||||
|
||||
/**
|
||||
* Indicate distance above which sources are not
|
||||
* attenuated using the inverse clamped distance model.
|
||||
*
|
||||
* Default: +inf
|
||||
* Type: ALfloat
|
||||
* Range: 0.0 - +inf
|
||||
*/
|
||||
#define AL_MAX_DISTANCE 0x1023
|
||||
|
||||
/**
|
||||
* Sound samples: frequency, in units of Hertz [Hz].
|
||||
* This is the number of samples per second. Half of the
|
||||
* sample frequency marks the maximum significant
|
||||
* frequency component.
|
||||
*/
|
||||
#define AL_FREQUENCY 0x2001
|
||||
#define AL_BITS 0x2002
|
||||
#define AL_CHANNELS 0x2003
|
||||
#define AL_SIZE 0x2004
|
||||
|
||||
/**
|
||||
* Buffer state.
|
||||
*
|
||||
* Not supported for public use (yet).
|
||||
*/
|
||||
#define AL_UNUSED 0x2010
|
||||
#define AL_PENDING 0x2011
|
||||
#define AL_PROCESSED 0x2012
|
||||
|
||||
|
||||
/** Errors: No Error. */
|
||||
#define AL_NO_ERROR 0
|
||||
|
||||
/**
|
||||
* Invalid Name paramater passed to AL call.
|
||||
*/
|
||||
#define AL_INVALID_NAME 0xA001
|
||||
|
||||
/**
|
||||
* Invalid parameter passed to AL call.
|
||||
*/
|
||||
#define AL_INVALID_ENUM 0xA002
|
||||
|
||||
/**
|
||||
* Invalid enum parameter value.
|
||||
*/
|
||||
#define AL_INVALID_VALUE 0xA003
|
||||
|
||||
/**
|
||||
* Illegal call.
|
||||
*/
|
||||
#define AL_INVALID_OPERATION 0xA004
|
||||
|
||||
|
||||
/**
|
||||
* No mojo.
|
||||
*/
|
||||
#define AL_OUT_OF_MEMORY 0xA005
|
||||
|
||||
|
||||
/** Context strings: Vendor Name. */
|
||||
#define AL_VENDOR 0xB001
|
||||
#define AL_VERSION 0xB002
|
||||
#define AL_RENDERER 0xB003
|
||||
#define AL_EXTENSIONS 0xB004
|
||||
|
||||
/** Global tweakage. */
|
||||
|
||||
/**
|
||||
* Doppler scale. Default 1.0
|
||||
*/
|
||||
#define AL_DOPPLER_FACTOR 0xC000
|
||||
|
||||
/**
|
||||
* Tweaks speed of propagation.
|
||||
*/
|
||||
#define AL_DOPPLER_VELOCITY 0xC001
|
||||
|
||||
/**
|
||||
* Speed of Sound in units per second
|
||||
*/
|
||||
#define AL_SPEED_OF_SOUND 0xC003
|
||||
|
||||
/**
|
||||
* Distance models
|
||||
*
|
||||
* used in conjunction with DistanceModel
|
||||
*
|
||||
* implicit: NONE, which disances distance attenuation.
|
||||
*/
|
||||
#define AL_DISTANCE_MODEL 0xD000
|
||||
#define AL_INVERSE_DISTANCE 0xD001
|
||||
#define AL_INVERSE_DISTANCE_CLAMPED 0xD002
|
||||
#define AL_LINEAR_DISTANCE 0xD003
|
||||
#define AL_LINEAR_DISTANCE_CLAMPED 0xD004
|
||||
#define AL_EXPONENT_DISTANCE 0xD005
|
||||
#define AL_EXPONENT_DISTANCE_CLAMPED 0xD006
|
||||
|
||||
/*
|
||||
* Renderer State management
|
||||
*/
|
||||
AL_API void AL_APIENTRY alEnable( ALenum capability );
|
||||
|
||||
AL_API void AL_APIENTRY alDisable( ALenum capability );
|
||||
|
||||
AL_API ALboolean AL_APIENTRY alIsEnabled( ALenum capability );
|
||||
|
||||
|
||||
/*
|
||||
* State retrieval
|
||||
*/
|
||||
AL_API const ALchar* AL_APIENTRY alGetString( ALenum param );
|
||||
|
||||
AL_API void AL_APIENTRY alGetBooleanv( ALenum param, ALboolean* data );
|
||||
|
||||
AL_API void AL_APIENTRY alGetIntegerv( ALenum param, ALint* data );
|
||||
|
||||
AL_API void AL_APIENTRY alGetFloatv( ALenum param, ALfloat* data );
|
||||
|
||||
AL_API void AL_APIENTRY alGetDoublev( ALenum param, ALdouble* data );
|
||||
|
||||
AL_API ALboolean AL_APIENTRY alGetBoolean( ALenum param );
|
||||
|
||||
AL_API ALint AL_APIENTRY alGetInteger( ALenum param );
|
||||
|
||||
AL_API ALfloat AL_APIENTRY alGetFloat( ALenum param );
|
||||
|
||||
AL_API ALdouble AL_APIENTRY alGetDouble( ALenum param );
|
||||
|
||||
|
||||
/*
|
||||
* Error support.
|
||||
* Obtain the most recent error generated in the AL state machine.
|
||||
*/
|
||||
AL_API ALenum AL_APIENTRY alGetError( void );
|
||||
|
||||
|
||||
/*
|
||||
* Extension support.
|
||||
* Query for the presence of an extension, and obtain any appropriate
|
||||
* function pointers and enum values.
|
||||
*/
|
||||
AL_API ALboolean AL_APIENTRY alIsExtensionPresent( const ALchar* extname );
|
||||
|
||||
AL_API void* AL_APIENTRY alGetProcAddress( const ALchar* fname );
|
||||
|
||||
AL_API ALenum AL_APIENTRY alGetEnumValue( const ALchar* ename );
|
||||
|
||||
|
||||
/*
|
||||
* LISTENER
|
||||
* Listener represents the location and orientation of the
|
||||
* 'user' in 3D-space.
|
||||
*
|
||||
* Properties include: -
|
||||
*
|
||||
* Gain AL_GAIN ALfloat
|
||||
* Position AL_POSITION ALfloat[3]
|
||||
* Velocity AL_VELOCITY ALfloat[3]
|
||||
* Orientation AL_ORIENTATION ALfloat[6] (Forward then Up vectors)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Set Listener parameters
|
||||
*/
|
||||
AL_API void AL_APIENTRY alListenerf( ALenum param, ALfloat value );
|
||||
|
||||
AL_API void AL_APIENTRY alListener3f( ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
|
||||
|
||||
AL_API void AL_APIENTRY alListenerfv( ALenum param, const ALfloat* values );
|
||||
|
||||
AL_API void AL_APIENTRY alListeneri( ALenum param, ALint value );
|
||||
|
||||
AL_API void AL_APIENTRY alListener3i( ALenum param, ALint value1, ALint value2, ALint value3 );
|
||||
|
||||
AL_API void AL_APIENTRY alListeneriv( ALenum param, const ALint* values );
|
||||
|
||||
/*
|
||||
* Get Listener parameters
|
||||
*/
|
||||
AL_API void AL_APIENTRY alGetListenerf( ALenum param, ALfloat* value );
|
||||
|
||||
AL_API void AL_APIENTRY alGetListener3f( ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3 );
|
||||
|
||||
AL_API void AL_APIENTRY alGetListenerfv( ALenum param, ALfloat* values );
|
||||
|
||||
AL_API void AL_APIENTRY alGetListeneri( ALenum param, ALint* value );
|
||||
|
||||
AL_API void AL_APIENTRY alGetListener3i( ALenum param, ALint *value1, ALint *value2, ALint *value3 );
|
||||
|
||||
AL_API void AL_APIENTRY alGetListeneriv( ALenum param, ALint* values );
|
||||
|
||||
|
||||
/**
|
||||
* SOURCE
|
||||
* Sources represent individual sound objects in 3D-space.
|
||||
* Sources take the PCM data provided in the specified Buffer,
|
||||
* apply Source-specific modifications, and then
|
||||
* submit them to be mixed according to spatial arrangement etc.
|
||||
*
|
||||
* Properties include: -
|
||||
*
|
||||
* Gain AL_GAIN ALfloat
|
||||
* Min Gain AL_MIN_GAIN ALfloat
|
||||
* Max Gain AL_MAX_GAIN ALfloat
|
||||
* Position AL_POSITION ALfloat[3]
|
||||
* Velocity AL_VELOCITY ALfloat[3]
|
||||
* Direction AL_DIRECTION ALfloat[3]
|
||||
* Head Relative Mode AL_SOURCE_RELATIVE ALint (AL_TRUE or AL_FALSE)
|
||||
* Reference Distance AL_REFERENCE_DISTANCE ALfloat
|
||||
* Max Distance AL_MAX_DISTANCE ALfloat
|
||||
* RollOff Factor AL_ROLLOFF_FACTOR ALfloat
|
||||
* Inner Angle AL_CONE_INNER_ANGLE ALint or ALfloat
|
||||
* Outer Angle AL_CONE_OUTER_ANGLE ALint or ALfloat
|
||||
* Cone Outer Gain AL_CONE_OUTER_GAIN ALint or ALfloat
|
||||
* Pitch AL_PITCH ALfloat
|
||||
* Looping AL_LOOPING ALint (AL_TRUE or AL_FALSE)
|
||||
* MS Offset AL_MSEC_OFFSET ALint or ALfloat
|
||||
* Byte Offset AL_BYTE_OFFSET ALint or ALfloat
|
||||
* Sample Offset AL_SAMPLE_OFFSET ALint or ALfloat
|
||||
* Attached Buffer AL_BUFFER ALint
|
||||
* State (Query only) AL_SOURCE_STATE ALint
|
||||
* Buffers Queued (Query only) AL_BUFFERS_QUEUED ALint
|
||||
* Buffers Processed (Query only) AL_BUFFERS_PROCESSED ALint
|
||||
*/
|
||||
|
||||
/* Create Source objects */
|
||||
AL_API void AL_APIENTRY alGenSources( ALsizei n, ALuint* sources );
|
||||
|
||||
/* Delete Source objects */
|
||||
AL_API void AL_APIENTRY alDeleteSources( ALsizei n, const ALuint* sources );
|
||||
|
||||
/* Verify a handle is a valid Source */
|
||||
AL_API ALboolean AL_APIENTRY alIsSource( ALuint sid );
|
||||
|
||||
/*
|
||||
* Set Source parameters
|
||||
*/
|
||||
AL_API void AL_APIENTRY alSourcef( ALuint sid, ALenum param, ALfloat value );
|
||||
|
||||
AL_API void AL_APIENTRY alSource3f( ALuint sid, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
|
||||
|
||||
AL_API void AL_APIENTRY alSourcefv( ALuint sid, ALenum param, const ALfloat* values );
|
||||
|
||||
AL_API void AL_APIENTRY alSourcei( ALuint sid, ALenum param, ALint value );
|
||||
|
||||
AL_API void AL_APIENTRY alSource3i( ALuint sid, ALenum param, ALint value1, ALint value2, ALint value3 );
|
||||
|
||||
AL_API void AL_APIENTRY alSourceiv( ALuint sid, ALenum param, const ALint* values );
|
||||
|
||||
/*
|
||||
* Get Source parameters
|
||||
*/
|
||||
AL_API void AL_APIENTRY alGetSourcef( ALuint sid, ALenum param, ALfloat* value );
|
||||
|
||||
AL_API void AL_APIENTRY alGetSource3f( ALuint sid, ALenum param, ALfloat* value1, ALfloat* value2, ALfloat* value3);
|
||||
|
||||
AL_API void AL_APIENTRY alGetSourcefv( ALuint sid, ALenum param, ALfloat* values );
|
||||
|
||||
AL_API void AL_APIENTRY alGetSourcei( ALuint sid, ALenum param, ALint* value );
|
||||
|
||||
AL_API void AL_APIENTRY alGetSource3i( ALuint sid, ALenum param, ALint* value1, ALint* value2, ALint* value3);
|
||||
|
||||
AL_API void AL_APIENTRY alGetSourceiv( ALuint sid, ALenum param, ALint* values );
|
||||
|
||||
|
||||
/*
|
||||
* Source vector based playback calls
|
||||
*/
|
||||
|
||||
/* Play, replay, or resume (if paused) a list of Sources */
|
||||
AL_API void AL_APIENTRY alSourcePlayv( ALsizei ns, const ALuint *sids );
|
||||
|
||||
/* Stop a list of Sources */
|
||||
AL_API void AL_APIENTRY alSourceStopv( ALsizei ns, const ALuint *sids );
|
||||
|
||||
/* Rewind a list of Sources */
|
||||
AL_API void AL_APIENTRY alSourceRewindv( ALsizei ns, const ALuint *sids );
|
||||
|
||||
/* Pause a list of Sources */
|
||||
AL_API void AL_APIENTRY alSourcePausev( ALsizei ns, const ALuint *sids );
|
||||
|
||||
/*
|
||||
* Source based playback calls
|
||||
*/
|
||||
|
||||
/* Play, replay, or resume a Source */
|
||||
AL_API void AL_APIENTRY alSourcePlay( ALuint sid );
|
||||
|
||||
/* Stop a Source */
|
||||
AL_API void AL_APIENTRY alSourceStop( ALuint sid );
|
||||
|
||||
/* Rewind a Source (set playback postiton to beginning) */
|
||||
AL_API void AL_APIENTRY alSourceRewind( ALuint sid );
|
||||
|
||||
/* Pause a Source */
|
||||
AL_API void AL_APIENTRY alSourcePause( ALuint sid );
|
||||
|
||||
/*
|
||||
* Source Queuing
|
||||
*/
|
||||
AL_API void AL_APIENTRY alSourceQueueBuffers( ALuint sid, ALsizei numEntries, const ALuint *bids );
|
||||
|
||||
AL_API void AL_APIENTRY alSourceUnqueueBuffers( ALuint sid, ALsizei numEntries, ALuint *bids );
|
||||
|
||||
|
||||
/**
|
||||
* BUFFER
|
||||
* Buffer objects are storage space for sample data.
|
||||
* Buffers are referred to by Sources. One Buffer can be used
|
||||
* by multiple Sources.
|
||||
*
|
||||
* Properties include: -
|
||||
*
|
||||
* Frequency (Query only) AL_FREQUENCY ALint
|
||||
* Size (Query only) AL_SIZE ALint
|
||||
* Bits (Query only) AL_BITS ALint
|
||||
* Channels (Query only) AL_CHANNELS ALint
|
||||
*/
|
||||
|
||||
/* Create Buffer objects */
|
||||
AL_API void AL_APIENTRY alGenBuffers( ALsizei n, ALuint* buffers );
|
||||
|
||||
/* Delete Buffer objects */
|
||||
AL_API void AL_APIENTRY alDeleteBuffers( ALsizei n, const ALuint* buffers );
|
||||
|
||||
/* Verify a handle is a valid Buffer */
|
||||
AL_API ALboolean AL_APIENTRY alIsBuffer( ALuint bid );
|
||||
|
||||
/* Specify the data to be copied into a buffer */
|
||||
AL_API void AL_APIENTRY alBufferData( ALuint bid, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq );
|
||||
|
||||
/*
|
||||
* Set Buffer parameters
|
||||
*/
|
||||
AL_API void AL_APIENTRY alBufferf( ALuint bid, ALenum param, ALfloat value );
|
||||
|
||||
AL_API void AL_APIENTRY alBuffer3f( ALuint bid, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
|
||||
|
||||
AL_API void AL_APIENTRY alBufferfv( ALuint bid, ALenum param, const ALfloat* values );
|
||||
|
||||
AL_API void AL_APIENTRY alBufferi( ALuint bid, ALenum param, ALint value );
|
||||
|
||||
AL_API void AL_APIENTRY alBuffer3i( ALuint bid, ALenum param, ALint value1, ALint value2, ALint value3 );
|
||||
|
||||
AL_API void AL_APIENTRY alBufferiv( ALuint bid, ALenum param, const ALint* values );
|
||||
|
||||
/*
|
||||
* Get Buffer parameters
|
||||
*/
|
||||
AL_API void AL_APIENTRY alGetBufferf( ALuint bid, ALenum param, ALfloat* value );
|
||||
|
||||
AL_API void AL_APIENTRY alGetBuffer3f( ALuint bid, ALenum param, ALfloat* value1, ALfloat* value2, ALfloat* value3);
|
||||
|
||||
AL_API void AL_APIENTRY alGetBufferfv( ALuint bid, ALenum param, ALfloat* values );
|
||||
|
||||
AL_API void AL_APIENTRY alGetBufferi( ALuint bid, ALenum param, ALint* value );
|
||||
|
||||
AL_API void AL_APIENTRY alGetBuffer3i( ALuint bid, ALenum param, ALint* value1, ALint* value2, ALint* value3);
|
||||
|
||||
AL_API void AL_APIENTRY alGetBufferiv( ALuint bid, ALenum param, ALint* values );
|
||||
|
||||
|
||||
/*
|
||||
* Global Parameters
|
||||
*/
|
||||
AL_API void AL_APIENTRY alDopplerFactor( ALfloat value );
|
||||
|
||||
AL_API void AL_APIENTRY alDopplerVelocity( ALfloat value );
|
||||
|
||||
AL_API void AL_APIENTRY alSpeedOfSound( ALfloat value );
|
||||
|
||||
AL_API void AL_APIENTRY alDistanceModel( ALenum distanceModel );
|
||||
|
||||
/*
|
||||
* Pointer-to-function types, useful for dynamically getting AL entry points.
|
||||
*/
|
||||
typedef void (AL_APIENTRY *LPALENABLE)( ALenum capability );
|
||||
typedef void (AL_APIENTRY *LPALDISABLE)( ALenum capability );
|
||||
typedef ALboolean (AL_APIENTRY *LPALISENABLED)( ALenum capability );
|
||||
typedef const ALchar* (AL_APIENTRY *LPALGETSTRING)( ALenum param );
|
||||
typedef void (AL_APIENTRY *LPALGETBOOLEANV)( ALenum param, ALboolean* data );
|
||||
typedef void (AL_APIENTRY *LPALGETINTEGERV)( ALenum param, ALint* data );
|
||||
typedef void (AL_APIENTRY *LPALGETFLOATV)( ALenum param, ALfloat* data );
|
||||
typedef void (AL_APIENTRY *LPALGETDOUBLEV)( ALenum param, ALdouble* data );
|
||||
typedef ALboolean (AL_APIENTRY *LPALGETBOOLEAN)( ALenum param );
|
||||
typedef ALint (AL_APIENTRY *LPALGETINTEGER)( ALenum param );
|
||||
typedef ALfloat (AL_APIENTRY *LPALGETFLOAT)( ALenum param );
|
||||
typedef ALdouble (AL_APIENTRY *LPALGETDOUBLE)( ALenum param );
|
||||
typedef ALenum (AL_APIENTRY *LPALGETERROR)( void );
|
||||
typedef ALboolean (AL_APIENTRY *LPALISEXTENSIONPRESENT)(const ALchar* extname );
|
||||
typedef void* (AL_APIENTRY *LPALGETPROCADDRESS)( const ALchar* fname );
|
||||
typedef ALenum (AL_APIENTRY *LPALGETENUMVALUE)( const ALchar* ename );
|
||||
typedef void (AL_APIENTRY *LPALLISTENERF)( ALenum param, ALfloat value );
|
||||
typedef void (AL_APIENTRY *LPALLISTENER3F)( ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
|
||||
typedef void (AL_APIENTRY *LPALLISTENERFV)( ALenum param, const ALfloat* values );
|
||||
typedef void (AL_APIENTRY *LPALLISTENERI)( ALenum param, ALint value );
|
||||
typedef void (AL_APIENTRY *LPALLISTENER3I)( ALenum param, ALint value1, ALint value2, ALint value3 );
|
||||
typedef void (AL_APIENTRY *LPALLISTENERIV)( ALenum param, const ALint* values );
|
||||
typedef void (AL_APIENTRY *LPALGETLISTENERF)( ALenum param, ALfloat* value );
|
||||
typedef void (AL_APIENTRY *LPALGETLISTENER3F)( ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3 );
|
||||
typedef void (AL_APIENTRY *LPALGETLISTENERFV)( ALenum param, ALfloat* values );
|
||||
typedef void (AL_APIENTRY *LPALGETLISTENERI)( ALenum param, ALint* value );
|
||||
typedef void (AL_APIENTRY *LPALGETLISTENER3I)( ALenum param, ALint *value1, ALint *value2, ALint *value3 );
|
||||
typedef void (AL_APIENTRY *LPALGETLISTENERIV)( ALenum param, ALint* values );
|
||||
typedef void (AL_APIENTRY *LPALGENSOURCES)( ALsizei n, ALuint* sources );
|
||||
typedef void (AL_APIENTRY *LPALDELETESOURCES)( ALsizei n, const ALuint* sources );
|
||||
typedef ALboolean (AL_APIENTRY *LPALISSOURCE)( ALuint sid );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEF)( ALuint sid, ALenum param, ALfloat value);
|
||||
typedef void (AL_APIENTRY *LPALSOURCE3F)( ALuint sid, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEFV)( ALuint sid, ALenum param, const ALfloat* values );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEI)( ALuint sid, ALenum param, ALint value);
|
||||
typedef void (AL_APIENTRY *LPALSOURCE3I)( ALuint sid, ALenum param, ALint value1, ALint value2, ALint value3 );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEIV)( ALuint sid, ALenum param, const ALint* values );
|
||||
typedef void (AL_APIENTRY *LPALGETSOURCEF)( ALuint sid, ALenum param, ALfloat* value );
|
||||
typedef void (AL_APIENTRY *LPALGETSOURCE3F)( ALuint sid, ALenum param, ALfloat* value1, ALfloat* value2, ALfloat* value3);
|
||||
typedef void (AL_APIENTRY *LPALGETSOURCEFV)( ALuint sid, ALenum param, ALfloat* values );
|
||||
typedef void (AL_APIENTRY *LPALGETSOURCEI)( ALuint sid, ALenum param, ALint* value );
|
||||
typedef void (AL_APIENTRY *LPALGETSOURCE3I)( ALuint sid, ALenum param, ALint* value1, ALint* value2, ALint* value3);
|
||||
typedef void (AL_APIENTRY *LPALGETSOURCEIV)( ALuint sid, ALenum param, ALint* values );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEPLAYV)( ALsizei ns, const ALuint *sids );
|
||||
typedef void (AL_APIENTRY *LPALSOURCESTOPV)( ALsizei ns, const ALuint *sids );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEREWINDV)( ALsizei ns, const ALuint *sids );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEPAUSEV)( ALsizei ns, const ALuint *sids );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEPLAY)( ALuint sid );
|
||||
typedef void (AL_APIENTRY *LPALSOURCESTOP)( ALuint sid );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEREWIND)( ALuint sid );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEPAUSE)( ALuint sid );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEQUEUEBUFFERS)(ALuint sid, ALsizei numEntries, const ALuint *bids );
|
||||
typedef void (AL_APIENTRY *LPALSOURCEUNQUEUEBUFFERS)(ALuint sid, ALsizei numEntries, ALuint *bids );
|
||||
typedef void (AL_APIENTRY *LPALGENBUFFERS)( ALsizei n, ALuint* buffers );
|
||||
typedef void (AL_APIENTRY *LPALDELETEBUFFERS)( ALsizei n, const ALuint* buffers );
|
||||
typedef ALboolean (AL_APIENTRY *LPALISBUFFER)( ALuint bid );
|
||||
typedef void (AL_APIENTRY *LPALBUFFERDATA)( ALuint bid, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq );
|
||||
typedef void (AL_APIENTRY *LPALBUFFERF)( ALuint bid, ALenum param, ALfloat value);
|
||||
typedef void (AL_APIENTRY *LPALBUFFER3F)( ALuint bid, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
|
||||
typedef void (AL_APIENTRY *LPALBUFFERFV)( ALuint bid, ALenum param, const ALfloat* values );
|
||||
typedef void (AL_APIENTRY *LPALBUFFERI)( ALuint bid, ALenum param, ALint value);
|
||||
typedef void (AL_APIENTRY *LPALBUFFER3I)( ALuint bid, ALenum param, ALint value1, ALint value2, ALint value3 );
|
||||
typedef void (AL_APIENTRY *LPALBUFFERIV)( ALuint bid, ALenum param, const ALint* values );
|
||||
typedef void (AL_APIENTRY *LPALGETBUFFERF)( ALuint bid, ALenum param, ALfloat* value );
|
||||
typedef void (AL_APIENTRY *LPALGETBUFFER3F)( ALuint bid, ALenum param, ALfloat* value1, ALfloat* value2, ALfloat* value3);
|
||||
typedef void (AL_APIENTRY *LPALGETBUFFERFV)( ALuint bid, ALenum param, ALfloat* values );
|
||||
typedef void (AL_APIENTRY *LPALGETBUFFERI)( ALuint bid, ALenum param, ALint* value );
|
||||
typedef void (AL_APIENTRY *LPALGETBUFFER3I)( ALuint bid, ALenum param, ALint* value1, ALint* value2, ALint* value3);
|
||||
typedef void (AL_APIENTRY *LPALGETBUFFERIV)( ALuint bid, ALenum param, ALint* values );
|
||||
typedef void (AL_APIENTRY *LPALDOPPLERFACTOR)( ALfloat value );
|
||||
typedef void (AL_APIENTRY *LPALDOPPLERVELOCITY)( ALfloat value );
|
||||
typedef void (AL_APIENTRY *LPALSPEEDOFSOUND)( ALfloat value );
|
||||
typedef void (AL_APIENTRY *LPALDISTANCEMODEL)( ALenum distanceModel );
|
||||
|
||||
#if defined(TARGET_OS_MAC) && TARGET_OS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* AL_AL_H */
|
||||
280
Lib/Include/AL/alc.h
Normal file
280
Lib/Include/AL/alc.h
Normal file
@@ -0,0 +1,280 @@
|
||||
#ifndef AL_ALC_H
|
||||
#define AL_ALC_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef ALC_API
|
||||
#if defined(AL_LIBTYPE_STATIC)
|
||||
#define ALC_API
|
||||
#elif defined(_WIN32)
|
||||
#define ALC_API __declspec(dllimport)
|
||||
#else
|
||||
#define ALC_API extern
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define ALC_APIENTRY __cdecl
|
||||
#else
|
||||
#define ALC_APIENTRY
|
||||
#endif
|
||||
|
||||
#if defined(TARGET_OS_MAC) && TARGET_OS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The ALCAPI, ALCAPIENTRY, and ALC_INVALID macros are deprecated, but are
|
||||
* included for applications porting code from AL 1.0
|
||||
*/
|
||||
#define ALCAPI ALC_API
|
||||
#define ALCAPIENTRY ALC_APIENTRY
|
||||
#define ALC_INVALID 0
|
||||
|
||||
|
||||
#define ALC_VERSION_0_1 1
|
||||
|
||||
typedef struct ALCdevice_struct ALCdevice;
|
||||
typedef struct ALCcontext_struct ALCcontext;
|
||||
|
||||
|
||||
/** 8-bit boolean */
|
||||
typedef char ALCboolean;
|
||||
|
||||
/** character */
|
||||
typedef char ALCchar;
|
||||
|
||||
/** signed 8-bit 2's complement integer */
|
||||
typedef signed char ALCbyte;
|
||||
|
||||
/** unsigned 8-bit integer */
|
||||
typedef unsigned char ALCubyte;
|
||||
|
||||
/** signed 16-bit 2's complement integer */
|
||||
typedef short ALCshort;
|
||||
|
||||
/** unsigned 16-bit integer */
|
||||
typedef unsigned short ALCushort;
|
||||
|
||||
/** signed 32-bit 2's complement integer */
|
||||
typedef int ALCint;
|
||||
|
||||
/** unsigned 32-bit integer */
|
||||
typedef unsigned int ALCuint;
|
||||
|
||||
/** non-negative 32-bit binary integer size */
|
||||
typedef int ALCsizei;
|
||||
|
||||
/** enumerated 32-bit value */
|
||||
typedef int ALCenum;
|
||||
|
||||
/** 32-bit IEEE754 floating-point */
|
||||
typedef float ALCfloat;
|
||||
|
||||
/** 64-bit IEEE754 floating-point */
|
||||
typedef double ALCdouble;
|
||||
|
||||
/** void type (for opaque pointers only) */
|
||||
typedef void ALCvoid;
|
||||
|
||||
|
||||
/* Enumerant values begin at column 50. No tabs. */
|
||||
|
||||
/* Boolean False. */
|
||||
#define ALC_FALSE 0
|
||||
|
||||
/* Boolean True. */
|
||||
#define ALC_TRUE 1
|
||||
|
||||
/**
|
||||
* followed by <int> Hz
|
||||
*/
|
||||
#define ALC_FREQUENCY 0x1007
|
||||
|
||||
/**
|
||||
* followed by <int> Hz
|
||||
*/
|
||||
#define ALC_REFRESH 0x1008
|
||||
|
||||
/**
|
||||
* followed by AL_TRUE, AL_FALSE
|
||||
*/
|
||||
#define ALC_SYNC 0x1009
|
||||
|
||||
/**
|
||||
* followed by <int> Num of requested Mono (3D) Sources
|
||||
*/
|
||||
#define ALC_MONO_SOURCES 0x1010
|
||||
|
||||
/**
|
||||
* followed by <int> Num of requested Stereo Sources
|
||||
*/
|
||||
#define ALC_STEREO_SOURCES 0x1011
|
||||
|
||||
/**
|
||||
* errors
|
||||
*/
|
||||
|
||||
/**
|
||||
* No error
|
||||
*/
|
||||
#define ALC_NO_ERROR 0
|
||||
|
||||
/**
|
||||
* No device
|
||||
*/
|
||||
#define ALC_INVALID_DEVICE 0xA001
|
||||
|
||||
/**
|
||||
* invalid context ID
|
||||
*/
|
||||
#define ALC_INVALID_CONTEXT 0xA002
|
||||
|
||||
/**
|
||||
* bad enum
|
||||
*/
|
||||
#define ALC_INVALID_ENUM 0xA003
|
||||
|
||||
/**
|
||||
* bad value
|
||||
*/
|
||||
#define ALC_INVALID_VALUE 0xA004
|
||||
|
||||
/**
|
||||
* Out of memory.
|
||||
*/
|
||||
#define ALC_OUT_OF_MEMORY 0xA005
|
||||
|
||||
|
||||
/**
|
||||
* The Specifier string for default device
|
||||
*/
|
||||
#define ALC_DEFAULT_DEVICE_SPECIFIER 0x1004
|
||||
#define ALC_DEVICE_SPECIFIER 0x1005
|
||||
#define ALC_EXTENSIONS 0x1006
|
||||
|
||||
#define ALC_MAJOR_VERSION 0x1000
|
||||
#define ALC_MINOR_VERSION 0x1001
|
||||
|
||||
#define ALC_ATTRIBUTES_SIZE 0x1002
|
||||
#define ALC_ALL_ATTRIBUTES 0x1003
|
||||
|
||||
|
||||
/**
|
||||
* Capture extension
|
||||
*/
|
||||
#define ALC_EXT_CAPTURE 1
|
||||
#define ALC_CAPTURE_DEVICE_SPECIFIER 0x310
|
||||
#define ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER 0x311
|
||||
#define ALC_CAPTURE_SAMPLES 0x312
|
||||
|
||||
|
||||
/**
|
||||
* ALC_ENUMERATE_ALL_EXT enums
|
||||
*/
|
||||
#define ALC_ENUMERATE_ALL_EXT 1
|
||||
#define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
|
||||
#define ALC_ALL_DEVICES_SPECIFIER 0x1013
|
||||
|
||||
|
||||
/*
|
||||
* Context Management
|
||||
*/
|
||||
ALC_API ALCcontext * ALC_APIENTRY alcCreateContext( ALCdevice *device, const ALCint* attrlist );
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent( ALCcontext *context );
|
||||
|
||||
ALC_API void ALC_APIENTRY alcProcessContext( ALCcontext *context );
|
||||
|
||||
ALC_API void ALC_APIENTRY alcSuspendContext( ALCcontext *context );
|
||||
|
||||
ALC_API void ALC_APIENTRY alcDestroyContext( ALCcontext *context );
|
||||
|
||||
ALC_API ALCcontext * ALC_APIENTRY alcGetCurrentContext( void );
|
||||
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice( ALCcontext *context );
|
||||
|
||||
|
||||
/*
|
||||
* Device Management
|
||||
*/
|
||||
ALC_API ALCdevice * ALC_APIENTRY alcOpenDevice( const ALCchar *devicename );
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice( ALCdevice *device );
|
||||
|
||||
|
||||
/*
|
||||
* Error support.
|
||||
* Obtain the most recent Context error
|
||||
*/
|
||||
ALC_API ALCenum ALC_APIENTRY alcGetError( ALCdevice *device );
|
||||
|
||||
|
||||
/*
|
||||
* Extension support.
|
||||
* Query for the presence of an extension, and obtain any appropriate
|
||||
* function pointers and enum values.
|
||||
*/
|
||||
ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent( ALCdevice *device, const ALCchar *extname );
|
||||
|
||||
ALC_API void * ALC_APIENTRY alcGetProcAddress( ALCdevice *device, const ALCchar *funcname );
|
||||
|
||||
ALC_API ALCenum ALC_APIENTRY alcGetEnumValue( ALCdevice *device, const ALCchar *enumname );
|
||||
|
||||
|
||||
/*
|
||||
* Query functions
|
||||
*/
|
||||
ALC_API const ALCchar * ALC_APIENTRY alcGetString( ALCdevice *device, ALCenum param );
|
||||
|
||||
ALC_API void ALC_APIENTRY alcGetIntegerv( ALCdevice *device, ALCenum param, ALCsizei size, ALCint *data );
|
||||
|
||||
|
||||
/*
|
||||
* Capture functions
|
||||
*/
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice( const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize );
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice( ALCdevice *device );
|
||||
|
||||
ALC_API void ALC_APIENTRY alcCaptureStart( ALCdevice *device );
|
||||
|
||||
ALC_API void ALC_APIENTRY alcCaptureStop( ALCdevice *device );
|
||||
|
||||
ALC_API void ALC_APIENTRY alcCaptureSamples( ALCdevice *device, ALCvoid *buffer, ALCsizei samples );
|
||||
|
||||
/*
|
||||
* Pointer-to-function types, useful for dynamically getting ALC entry points.
|
||||
*/
|
||||
typedef ALCcontext * (ALC_APIENTRY *LPALCCREATECONTEXT) (ALCdevice *device, const ALCint *attrlist);
|
||||
typedef ALCboolean (ALC_APIENTRY *LPALCMAKECONTEXTCURRENT)( ALCcontext *context );
|
||||
typedef void (ALC_APIENTRY *LPALCPROCESSCONTEXT)( ALCcontext *context );
|
||||
typedef void (ALC_APIENTRY *LPALCSUSPENDCONTEXT)( ALCcontext *context );
|
||||
typedef void (ALC_APIENTRY *LPALCDESTROYCONTEXT)( ALCcontext *context );
|
||||
typedef ALCcontext * (ALC_APIENTRY *LPALCGETCURRENTCONTEXT)( void );
|
||||
typedef ALCdevice * (ALC_APIENTRY *LPALCGETCONTEXTSDEVICE)( ALCcontext *context );
|
||||
typedef ALCdevice * (ALC_APIENTRY *LPALCOPENDEVICE)( const ALCchar *devicename );
|
||||
typedef ALCboolean (ALC_APIENTRY *LPALCCLOSEDEVICE)( ALCdevice *device );
|
||||
typedef ALCenum (ALC_APIENTRY *LPALCGETERROR)( ALCdevice *device );
|
||||
typedef ALCboolean (ALC_APIENTRY *LPALCISEXTENSIONPRESENT)( ALCdevice *device, const ALCchar *extname );
|
||||
typedef void * (ALC_APIENTRY *LPALCGETPROCADDRESS)(ALCdevice *device, const ALCchar *funcname );
|
||||
typedef ALCenum (ALC_APIENTRY *LPALCGETENUMVALUE)(ALCdevice *device, const ALCchar *enumname );
|
||||
typedef const ALCchar* (ALC_APIENTRY *LPALCGETSTRING)( ALCdevice *device, ALCenum param );
|
||||
typedef void (ALC_APIENTRY *LPALCGETINTEGERV)( ALCdevice *device, ALCenum param, ALCsizei size, ALCint *dest );
|
||||
typedef ALCdevice * (ALC_APIENTRY *LPALCCAPTUREOPENDEVICE)( const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize );
|
||||
typedef ALCboolean (ALC_APIENTRY *LPALCCAPTURECLOSEDEVICE)( ALCdevice *device );
|
||||
typedef void (ALC_APIENTRY *LPALCCAPTURESTART)( ALCdevice *device );
|
||||
typedef void (ALC_APIENTRY *LPALCCAPTURESTOP)( ALCdevice *device );
|
||||
typedef void (ALC_APIENTRY *LPALCCAPTURESAMPLES)( ALCdevice *device, ALCvoid *buffer, ALCsizei samples );
|
||||
|
||||
#if defined(TARGET_OS_MAC) && TARGET_OS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AL_ALC_H */
|
||||
296
Lib/Include/AL/alext.h
Normal file
296
Lib/Include/AL/alext.h
Normal file
@@ -0,0 +1,296 @@
|
||||
/**
|
||||
* OpenAL cross platform audio library
|
||||
* Copyright (C) 2008 by authors.
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
||||
*/
|
||||
|
||||
#ifndef AL_ALEXT_H
|
||||
#define AL_ALEXT_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef AL_LOKI_IMA_ADPCM_format
|
||||
#define AL_LOKI_IMA_ADPCM_format 1
|
||||
#define AL_FORMAT_IMA_ADPCM_MONO16_EXT 0x10000
|
||||
#define AL_FORMAT_IMA_ADPCM_STEREO16_EXT 0x10001
|
||||
#endif
|
||||
|
||||
#ifndef AL_LOKI_WAVE_format
|
||||
#define AL_LOKI_WAVE_format 1
|
||||
#define AL_FORMAT_WAVE_EXT 0x10002
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_vorbis
|
||||
#define AL_EXT_vorbis 1
|
||||
#define AL_FORMAT_VORBIS_EXT 0x10003
|
||||
#endif
|
||||
|
||||
#ifndef AL_LOKI_quadriphonic
|
||||
#define AL_LOKI_quadriphonic 1
|
||||
#define AL_FORMAT_QUAD8_LOKI 0x10004
|
||||
#define AL_FORMAT_QUAD16_LOKI 0x10005
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_float32
|
||||
#define AL_EXT_float32 1
|
||||
#define AL_FORMAT_MONO_FLOAT32 0x10010
|
||||
#define AL_FORMAT_STEREO_FLOAT32 0x10011
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_double
|
||||
#define AL_EXT_double 1
|
||||
#define AL_FORMAT_MONO_DOUBLE_EXT 0x10012
|
||||
#define AL_FORMAT_STEREO_DOUBLE_EXT 0x10013
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_MULAW
|
||||
#define AL_EXT_MULAW 1
|
||||
#define AL_FORMAT_MONO_MULAW_EXT 0x10014
|
||||
#define AL_FORMAT_STEREO_MULAW_EXT 0x10015
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_ALAW
|
||||
#define AL_EXT_ALAW 1
|
||||
#define AL_FORMAT_MONO_ALAW_EXT 0x10016
|
||||
#define AL_FORMAT_STEREO_ALAW_EXT 0x10017
|
||||
#endif
|
||||
|
||||
#ifndef ALC_LOKI_audio_channel
|
||||
#define ALC_LOKI_audio_channel 1
|
||||
#define ALC_CHAN_MAIN_LOKI 0x500001
|
||||
#define ALC_CHAN_PCM_LOKI 0x500002
|
||||
#define ALC_CHAN_CD_LOKI 0x500003
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_MCFORMATS
|
||||
#define AL_EXT_MCFORMATS 1
|
||||
#define AL_FORMAT_QUAD8 0x1204
|
||||
#define AL_FORMAT_QUAD16 0x1205
|
||||
#define AL_FORMAT_QUAD32 0x1206
|
||||
#define AL_FORMAT_REAR8 0x1207
|
||||
#define AL_FORMAT_REAR16 0x1208
|
||||
#define AL_FORMAT_REAR32 0x1209
|
||||
#define AL_FORMAT_51CHN8 0x120A
|
||||
#define AL_FORMAT_51CHN16 0x120B
|
||||
#define AL_FORMAT_51CHN32 0x120C
|
||||
#define AL_FORMAT_61CHN8 0x120D
|
||||
#define AL_FORMAT_61CHN16 0x120E
|
||||
#define AL_FORMAT_61CHN32 0x120F
|
||||
#define AL_FORMAT_71CHN8 0x1210
|
||||
#define AL_FORMAT_71CHN16 0x1211
|
||||
#define AL_FORMAT_71CHN32 0x1212
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_MULAW_MCFORMATS
|
||||
#define AL_EXT_MULAW_MCFORMATS 1
|
||||
#define AL_FORMAT_MONO_MULAW 0x10014
|
||||
#define AL_FORMAT_STEREO_MULAW 0x10015
|
||||
#define AL_FORMAT_QUAD_MULAW 0x10021
|
||||
#define AL_FORMAT_REAR_MULAW 0x10022
|
||||
#define AL_FORMAT_51CHN_MULAW 0x10023
|
||||
#define AL_FORMAT_61CHN_MULAW 0x10024
|
||||
#define AL_FORMAT_71CHN_MULAW 0x10025
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_IMA4
|
||||
#define AL_EXT_IMA4 1
|
||||
#define AL_FORMAT_MONO_IMA4 0x1300
|
||||
#define AL_FORMAT_STEREO_IMA4 0x1301
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_STATIC_BUFFER
|
||||
#define AL_EXT_STATIC_BUFFER 1
|
||||
typedef ALvoid (AL_APIENTRY*PFNALBUFFERDATASTATICPROC)(const ALint,ALenum,ALvoid*,ALsizei,ALsizei);
|
||||
#ifdef AL_ALEXT_PROTOTYPES
|
||||
AL_API ALvoid AL_APIENTRY alBufferDataStatic(const ALint buffer, ALenum format, ALvoid *data, ALsizei len, ALsizei freq);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ALC_EXT_EFX
|
||||
#define ALC_EXT_EFX 1
|
||||
#include "efx.h"
|
||||
#endif
|
||||
|
||||
#ifndef ALC_EXT_disconnect
|
||||
#define ALC_EXT_disconnect 1
|
||||
#define ALC_CONNECTED 0x313
|
||||
#endif
|
||||
|
||||
#ifndef ALC_EXT_thread_local_context
|
||||
#define ALC_EXT_thread_local_context 1
|
||||
typedef ALCboolean (ALC_APIENTRY*PFNALCSETTHREADCONTEXTPROC)(ALCcontext *context);
|
||||
typedef ALCcontext* (ALC_APIENTRY*PFNALCGETTHREADCONTEXTPROC)(void);
|
||||
#ifdef AL_ALEXT_PROTOTYPES
|
||||
ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context);
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_source_distance_model
|
||||
#define AL_EXT_source_distance_model 1
|
||||
#define AL_SOURCE_DISTANCE_MODEL 0x200
|
||||
#endif
|
||||
|
||||
#ifndef AL_SOFT_buffer_sub_data
|
||||
#define AL_SOFT_buffer_sub_data 1
|
||||
#define AL_BYTE_RW_OFFSETS_SOFT 0x1031
|
||||
#define AL_SAMPLE_RW_OFFSETS_SOFT 0x1032
|
||||
typedef ALvoid (AL_APIENTRY*PFNALBUFFERSUBDATASOFTPROC)(ALuint,ALenum,const ALvoid*,ALsizei,ALsizei);
|
||||
#ifdef AL_ALEXT_PROTOTYPES
|
||||
AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer,ALenum format,const ALvoid *data,ALsizei offset,ALsizei length);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef AL_SOFT_loop_points
|
||||
#define AL_SOFT_loop_points 1
|
||||
#define AL_LOOP_POINTS_SOFT 0x2015
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_FOLDBACK
|
||||
#define AL_EXT_FOLDBACK 1
|
||||
#define AL_EXT_FOLDBACK_NAME "AL_EXT_FOLDBACK"
|
||||
#define AL_FOLDBACK_EVENT_BLOCK 0x4112
|
||||
#define AL_FOLDBACK_EVENT_START 0x4111
|
||||
#define AL_FOLDBACK_EVENT_STOP 0x4113
|
||||
#define AL_FOLDBACK_MODE_MONO 0x4101
|
||||
#define AL_FOLDBACK_MODE_STEREO 0x4102
|
||||
typedef void (AL_APIENTRY*LPALFOLDBACKCALLBACK)(ALenum,ALsizei);
|
||||
typedef void (AL_APIENTRY*LPALREQUESTFOLDBACKSTART)(ALenum,ALsizei,ALsizei,ALfloat*,LPALFOLDBACKCALLBACK);
|
||||
typedef void (AL_APIENTRY*LPALREQUESTFOLDBACKSTOP)(void);
|
||||
#ifdef AL_ALEXT_PROTOTYPES
|
||||
AL_API void AL_APIENTRY alRequestFoldbackStart(ALenum mode,ALsizei count,ALsizei length,ALfloat *mem,LPALFOLDBACKCALLBACK callback);
|
||||
AL_API void AL_APIENTRY alRequestFoldbackStop(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ALC_EXT_DEDICATED
|
||||
#define ALC_EXT_DEDICATED 1
|
||||
#define AL_DEDICATED_GAIN 0x0001
|
||||
#define AL_EFFECT_DEDICATED_DIALOGUE 0x9001
|
||||
#define AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT 0x9000
|
||||
#endif
|
||||
|
||||
#ifndef AL_SOFT_buffer_samples
|
||||
#define AL_SOFT_buffer_samples 1
|
||||
/* Channel configurations */
|
||||
#define AL_MONO_SOFT 0x1500
|
||||
#define AL_STEREO_SOFT 0x1501
|
||||
#define AL_REAR_SOFT 0x1502
|
||||
#define AL_QUAD_SOFT 0x1503
|
||||
#define AL_5POINT1_SOFT 0x1504
|
||||
#define AL_6POINT1_SOFT 0x1505
|
||||
#define AL_7POINT1_SOFT 0x1506
|
||||
|
||||
/* Sample types */
|
||||
#define AL_BYTE_SOFT 0x1400
|
||||
#define AL_UNSIGNED_BYTE_SOFT 0x1401
|
||||
#define AL_SHORT_SOFT 0x1402
|
||||
#define AL_UNSIGNED_SHORT_SOFT 0x1403
|
||||
#define AL_INT_SOFT 0x1404
|
||||
#define AL_UNSIGNED_INT_SOFT 0x1405
|
||||
#define AL_FLOAT_SOFT 0x1406
|
||||
#define AL_DOUBLE_SOFT 0x1407
|
||||
#define AL_BYTE3_SOFT 0x1408
|
||||
#define AL_UNSIGNED_BYTE3_SOFT 0x1409
|
||||
|
||||
/* Storage formats */
|
||||
#define AL_MONO8_SOFT 0x1100
|
||||
#define AL_MONO16_SOFT 0x1101
|
||||
#define AL_MONO32F_SOFT 0x10010
|
||||
#define AL_STEREO8_SOFT 0x1102
|
||||
#define AL_STEREO16_SOFT 0x1103
|
||||
#define AL_STEREO32F_SOFT 0x10011
|
||||
#define AL_QUAD8_SOFT 0x1204
|
||||
#define AL_QUAD16_SOFT 0x1205
|
||||
#define AL_QUAD32F_SOFT 0x1206
|
||||
#define AL_REAR8_SOFT 0x1207
|
||||
#define AL_REAR16_SOFT 0x1208
|
||||
#define AL_REAR32F_SOFT 0x1209
|
||||
#define AL_5POINT1_8_SOFT 0x120A
|
||||
#define AL_5POINT1_16_SOFT 0x120B
|
||||
#define AL_5POINT1_32F_SOFT 0x120C
|
||||
#define AL_6POINT1_8_SOFT 0x120D
|
||||
#define AL_6POINT1_16_SOFT 0x120E
|
||||
#define AL_6POINT1_32F_SOFT 0x120F
|
||||
#define AL_7POINT1_8_SOFT 0x1210
|
||||
#define AL_7POINT1_16_SOFT 0x1211
|
||||
#define AL_7POINT1_32F_SOFT 0x1212
|
||||
|
||||
/* Buffer attributes */
|
||||
#define AL_INTERNAL_FORMAT_SOFT 0x2008
|
||||
#define AL_BYTE_LENGTH_SOFT 0x2009
|
||||
#define AL_SAMPLE_LENGTH_SOFT 0x200A
|
||||
#define AL_SEC_LENGTH_SOFT 0x200B
|
||||
|
||||
typedef void (AL_APIENTRY*LPALBUFFERSAMPLESSOFT)(ALuint,ALuint,ALenum,ALsizei,ALenum,ALenum,const ALvoid*);
|
||||
typedef void (AL_APIENTRY*LPALBUFFERSUBSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,const ALvoid*);
|
||||
typedef void (AL_APIENTRY*LPALGETBUFFERSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,ALvoid*);
|
||||
typedef ALboolean (AL_APIENTRY*LPALISBUFFERFORMATSUPPORTEDSOFT)(ALenum);
|
||||
#ifdef AL_ALEXT_PROTOTYPES
|
||||
AL_API void AL_APIENTRY alBufferSamplesSOFT(ALuint buffer, ALuint samplerate, ALenum internalformat, ALsizei samples, ALenum channels, ALenum type, const ALvoid *data);
|
||||
AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint buffer, ALsizei offset, ALsizei samples, ALenum channels, ALenum type, const ALvoid *data);
|
||||
AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint buffer, ALsizei offset, ALsizei samples, ALenum channels, ALenum type, ALvoid *data);
|
||||
AL_API ALboolean AL_APIENTRY alIsBufferFormatSupportedSOFT(ALenum format);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef AL_SOFT_direct_channels
|
||||
#define AL_SOFT_direct_channels 1
|
||||
#define AL_DIRECT_CHANNELS_SOFT 0x1033
|
||||
#endif
|
||||
|
||||
#ifndef ALC_SOFT_loopback
|
||||
#define ALC_SOFT_loopback 1
|
||||
#define ALC_FORMAT_CHANNELS_SOFT 0x1990
|
||||
#define ALC_FORMAT_TYPE_SOFT 0x1991
|
||||
|
||||
/* Sample types */
|
||||
#define ALC_BYTE_SOFT 0x1400
|
||||
#define ALC_UNSIGNED_BYTE_SOFT 0x1401
|
||||
#define ALC_SHORT_SOFT 0x1402
|
||||
#define ALC_UNSIGNED_SHORT_SOFT 0x1403
|
||||
#define ALC_INT_SOFT 0x1404
|
||||
#define ALC_UNSIGNED_INT_SOFT 0x1405
|
||||
#define ALC_FLOAT_SOFT 0x1406
|
||||
|
||||
/* Channel configurations */
|
||||
#define ALC_MONO_SOFT 0x1500
|
||||
#define ALC_STEREO_SOFT 0x1501
|
||||
#define ALC_QUAD_SOFT 0x1503
|
||||
#define ALC_5POINT1_SOFT 0x1504
|
||||
#define ALC_6POINT1_SOFT 0x1505
|
||||
#define ALC_7POINT1_SOFT 0x1506
|
||||
|
||||
typedef ALCdevice* (ALC_APIENTRY*LPALCLOOPBACKOPENDEVICESOFT)(const ALCchar*);
|
||||
typedef ALCboolean (ALC_APIENTRY*LPALCISRENDERFORMATSUPPORTEDSOFT)(ALCdevice*,ALCsizei,ALCenum,ALCenum);
|
||||
typedef void (ALC_APIENTRY*LPALCRENDERSAMPLESSOFT)(ALCdevice*,ALCvoid*,ALCsizei);
|
||||
#ifdef AL_ALEXT_PROTOTYPES
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceName);
|
||||
ALC_API ALCboolean ALC_APIENTRY alcIsRenderFormatSupportedSOFT(ALCdevice *device, ALCsizei freq, ALCenum channels, ALCenum type);
|
||||
ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, ALCvoid *buffer, ALCsizei samples);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
3
Lib/Include/AL/efx-creative.h
Normal file
3
Lib/Include/AL/efx-creative.h
Normal file
@@ -0,0 +1,3 @@
|
||||
/* The tokens that would be defined here are already defined in efx.h. This
|
||||
* empty file is here to provide compatibility with Windows-based projects
|
||||
* that would include it. */
|
||||
402
Lib/Include/AL/efx-presets.h
Normal file
402
Lib/Include/AL/efx-presets.h
Normal file
@@ -0,0 +1,402 @@
|
||||
/* Reverb presets for EFX */
|
||||
|
||||
#ifndef EFX_PRESETS_H
|
||||
#define EFX_PRESETS_H
|
||||
|
||||
#ifndef EFXEAXREVERBPROPERTIES_DEFINED
|
||||
#define EFXEAXREVERBPROPERTIES_DEFINED
|
||||
typedef struct {
|
||||
float flDensity;
|
||||
float flDiffusion;
|
||||
float flGain;
|
||||
float flGainHF;
|
||||
float flGainLF;
|
||||
float flDecayTime;
|
||||
float flDecayHFRatio;
|
||||
float flDecayLFRatio;
|
||||
float flReflectionsGain;
|
||||
float flReflectionsDelay;
|
||||
float flReflectionsPan[3];
|
||||
float flLateReverbGain;
|
||||
float flLateReverbDelay;
|
||||
float flLateReverbPan[3];
|
||||
float flEchoTime;
|
||||
float flEchoDepth;
|
||||
float flModulationTime;
|
||||
float flModulationDepth;
|
||||
float flAirAbsorptionGainHF;
|
||||
float flHFReference;
|
||||
float flLFReference;
|
||||
float flRoomRolloffFactor;
|
||||
int iDecayHFLimit;
|
||||
} EFXEAXREVERBPROPERTIES, *LPEFXEAXREVERBPROPERTIES;
|
||||
#endif
|
||||
|
||||
/* Default Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_GENERIC \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.8913f, 1.0000f, 1.4900f, 0.8300f, 1.0000f, 0.0500f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PADDEDCELL \
|
||||
{ 0.1715f, 1.0000f, 0.3162f, 0.0010f, 1.0000f, 0.1700f, 0.1000f, 1.0000f, 0.2500f, 0.0010f, { 0.0000f, 0.0000f, 0.0000f }, 1.2691f, 0.0020f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_ROOM \
|
||||
{ 0.4287f, 1.0000f, 0.3162f, 0.5929f, 1.0000f, 0.4000f, 0.8300f, 1.0000f, 0.1503f, 0.0020f, { 0.0000f, 0.0000f, 0.0000f }, 1.0629f, 0.0030f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_BATHROOM \
|
||||
{ 0.1715f, 1.0000f, 0.3162f, 0.2512f, 1.0000f, 1.4900f, 0.5400f, 1.0000f, 0.6531f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 3.2734f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_LIVINGROOM \
|
||||
{ 0.9766f, 1.0000f, 0.3162f, 0.0010f, 1.0000f, 0.5000f, 0.1000f, 1.0000f, 0.2051f, 0.0030f, { 0.0000f, 0.0000f, 0.0000f }, 0.2805f, 0.0040f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_STONEROOM \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.7079f, 1.0000f, 2.3100f, 0.6400f, 1.0000f, 0.4411f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.1003f, 0.0170f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_AUDITORIUM \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.5781f, 1.0000f, 4.3200f, 0.5900f, 1.0000f, 0.4032f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.7170f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CONCERTHALL \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.5623f, 1.0000f, 3.9200f, 0.7000f, 1.0000f, 0.2427f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.9977f, 0.0290f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CAVE \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 1.0000f, 1.0000f, 2.9100f, 1.3000f, 1.0000f, 0.5000f, 0.0150f, { 0.0000f, 0.0000f, 0.0000f }, 0.7063f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_ARENA \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.4477f, 1.0000f, 7.2400f, 0.3300f, 1.0000f, 0.2612f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.0186f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_HANGAR \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.3162f, 1.0000f, 10.0500f, 0.2300f, 1.0000f, 0.5000f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.2560f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CARPETEDHALLWAY \
|
||||
{ 0.4287f, 1.0000f, 0.3162f, 0.0100f, 1.0000f, 0.3000f, 0.1000f, 1.0000f, 0.1215f, 0.0020f, { 0.0000f, 0.0000f, 0.0000f }, 0.1531f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_HALLWAY \
|
||||
{ 0.3645f, 1.0000f, 0.3162f, 0.7079f, 1.0000f, 1.4900f, 0.5900f, 1.0000f, 0.2458f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.6615f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_STONECORRIDOR \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.7612f, 1.0000f, 2.7000f, 0.7900f, 1.0000f, 0.2472f, 0.0130f, { 0.0000f, 0.0000f, 0.0000f }, 1.5758f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_ALLEY \
|
||||
{ 1.0000f, 0.3000f, 0.3162f, 0.7328f, 1.0000f, 1.4900f, 0.8600f, 1.0000f, 0.2500f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 0.9954f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.1250f, 0.9500f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_FOREST \
|
||||
{ 1.0000f, 0.3000f, 0.3162f, 0.0224f, 1.0000f, 1.4900f, 0.5400f, 1.0000f, 0.0525f, 0.1620f, { 0.0000f, 0.0000f, 0.0000f }, 0.7682f, 0.0880f, { 0.0000f, 0.0000f, 0.0000f }, 0.1250f, 1.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CITY \
|
||||
{ 1.0000f, 0.5000f, 0.3162f, 0.3981f, 1.0000f, 1.4900f, 0.6700f, 1.0000f, 0.0730f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 0.1427f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_MOUNTAINS \
|
||||
{ 1.0000f, 0.2700f, 0.3162f, 0.0562f, 1.0000f, 1.4900f, 0.2100f, 1.0000f, 0.0407f, 0.3000f, { 0.0000f, 0.0000f, 0.0000f }, 0.1919f, 0.1000f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_QUARRY \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.3162f, 1.0000f, 1.4900f, 0.8300f, 1.0000f, 0.0000f, 0.0610f, { 0.0000f, 0.0000f, 0.0000f }, 1.7783f, 0.0250f, { 0.0000f, 0.0000f, 0.0000f }, 0.1250f, 0.7000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PLAIN \
|
||||
{ 1.0000f, 0.2100f, 0.3162f, 0.1000f, 1.0000f, 1.4900f, 0.5000f, 1.0000f, 0.0585f, 0.1790f, { 0.0000f, 0.0000f, 0.0000f }, 0.1089f, 0.1000f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PARKINGLOT \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 1.0000f, 1.0000f, 1.6500f, 1.5000f, 1.0000f, 0.2082f, 0.0080f, { 0.0000f, 0.0000f, 0.0000f }, 0.2652f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SEWERPIPE \
|
||||
{ 0.3071f, 0.8000f, 0.3162f, 0.3162f, 1.0000f, 2.8100f, 0.1400f, 1.0000f, 1.6387f, 0.0140f, { 0.0000f, 0.0000f, 0.0000f }, 3.2471f, 0.0210f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_UNDERWATER \
|
||||
{ 0.3645f, 1.0000f, 0.3162f, 0.0100f, 1.0000f, 1.4900f, 0.1000f, 1.0000f, 0.5963f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 7.0795f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 1.1800f, 0.3480f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_DRUGGED \
|
||||
{ 0.4287f, 0.5000f, 0.3162f, 1.0000f, 1.0000f, 8.3900f, 1.3900f, 1.0000f, 0.8760f, 0.0020f, { 0.0000f, 0.0000f, 0.0000f }, 3.1081f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 1.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_DIZZY \
|
||||
{ 0.3645f, 0.6000f, 0.3162f, 0.6310f, 1.0000f, 17.2300f, 0.5600f, 1.0000f, 0.1392f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.4937f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.8100f, 0.3100f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PSYCHOTIC \
|
||||
{ 0.0625f, 0.5000f, 0.3162f, 0.8404f, 1.0000f, 7.5600f, 0.9100f, 1.0000f, 0.4864f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 2.4378f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 4.0000f, 1.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
/* Castle Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_CASTLE_SMALLROOM \
|
||||
{ 1.0000f, 0.8900f, 0.3162f, 0.3981f, 0.1000f, 1.2200f, 0.8300f, 0.3100f, 0.8913f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 1.9953f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.1380f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CASTLE_SHORTPASSAGE \
|
||||
{ 1.0000f, 0.8900f, 0.3162f, 0.3162f, 0.1000f, 2.3200f, 0.8300f, 0.3100f, 0.8913f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0230f, { 0.0000f, 0.0000f, 0.0000f }, 0.1380f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CASTLE_MEDIUMROOM \
|
||||
{ 1.0000f, 0.9300f, 0.3162f, 0.2818f, 0.1000f, 2.0400f, 0.8300f, 0.4600f, 0.6310f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 1.5849f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.1550f, 0.0300f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CASTLE_LARGEROOM \
|
||||
{ 1.0000f, 0.8200f, 0.3162f, 0.2818f, 0.1259f, 2.5300f, 0.8300f, 0.5000f, 0.4467f, 0.0340f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0160f, { 0.0000f, 0.0000f, 0.0000f }, 0.1850f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CASTLE_LONGPASSAGE \
|
||||
{ 1.0000f, 0.8900f, 0.3162f, 0.3981f, 0.1000f, 3.4200f, 0.8300f, 0.3100f, 0.8913f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0230f, { 0.0000f, 0.0000f, 0.0000f }, 0.1380f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CASTLE_HALL \
|
||||
{ 1.0000f, 0.8100f, 0.3162f, 0.2818f, 0.1778f, 3.1400f, 0.7900f, 0.6200f, 0.1778f, 0.0560f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0240f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CASTLE_CUPBOARD \
|
||||
{ 1.0000f, 0.8900f, 0.3162f, 0.2818f, 0.1000f, 0.6700f, 0.8700f, 0.3100f, 1.4125f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 3.5481f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 0.1380f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CASTLE_COURTYARD \
|
||||
{ 1.0000f, 0.4200f, 0.3162f, 0.4467f, 0.1995f, 2.1300f, 0.6100f, 0.2300f, 0.2239f, 0.1600f, { 0.0000f, 0.0000f, 0.0000f }, 0.7079f, 0.0360f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.3700f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CASTLE_ALCOVE \
|
||||
{ 1.0000f, 0.8900f, 0.3162f, 0.5012f, 0.1000f, 1.6400f, 0.8700f, 0.3100f, 1.0000f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0340f, { 0.0000f, 0.0000f, 0.0000f }, 0.1380f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 5168.6001f, 139.5000f, 0.0000f, 0x1 }
|
||||
|
||||
/* Factory Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_FACTORY_SMALLROOM \
|
||||
{ 0.3645f, 0.8200f, 0.3162f, 0.7943f, 0.5012f, 1.7200f, 0.6500f, 1.3100f, 0.7079f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.7783f, 0.0240f, { 0.0000f, 0.0000f, 0.0000f }, 0.1190f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_FACTORY_SHORTPASSAGE \
|
||||
{ 0.3645f, 0.6400f, 0.2512f, 0.7943f, 0.5012f, 2.5300f, 0.6500f, 1.3100f, 1.0000f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0380f, { 0.0000f, 0.0000f, 0.0000f }, 0.1350f, 0.2300f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_FACTORY_MEDIUMROOM \
|
||||
{ 0.4287f, 0.8200f, 0.2512f, 0.7943f, 0.5012f, 2.7600f, 0.6500f, 1.3100f, 0.2818f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0230f, { 0.0000f, 0.0000f, 0.0000f }, 0.1740f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_FACTORY_LARGEROOM \
|
||||
{ 0.4287f, 0.7500f, 0.2512f, 0.7079f, 0.6310f, 4.2400f, 0.5100f, 1.3100f, 0.1778f, 0.0390f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0230f, { 0.0000f, 0.0000f, 0.0000f }, 0.2310f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_FACTORY_LONGPASSAGE \
|
||||
{ 0.3645f, 0.6400f, 0.2512f, 0.7943f, 0.5012f, 4.0600f, 0.6500f, 1.3100f, 1.0000f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0370f, { 0.0000f, 0.0000f, 0.0000f }, 0.1350f, 0.2300f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_FACTORY_HALL \
|
||||
{ 0.4287f, 0.7500f, 0.3162f, 0.7079f, 0.6310f, 7.4300f, 0.5100f, 1.3100f, 0.0631f, 0.0730f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0270f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_FACTORY_CUPBOARD \
|
||||
{ 0.3071f, 0.6300f, 0.2512f, 0.7943f, 0.5012f, 0.4900f, 0.6500f, 1.3100f, 1.2589f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.9953f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 0.1070f, 0.0700f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_FACTORY_COURTYARD \
|
||||
{ 0.3071f, 0.5700f, 0.3162f, 0.3162f, 0.6310f, 2.3200f, 0.2900f, 0.5600f, 0.2239f, 0.1400f, { 0.0000f, 0.0000f, 0.0000f }, 0.3981f, 0.0390f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2900f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_FACTORY_ALCOVE \
|
||||
{ 0.3645f, 0.5900f, 0.2512f, 0.7943f, 0.5012f, 3.1400f, 0.6500f, 1.3100f, 1.4125f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.0000f, 0.0380f, { 0.0000f, 0.0000f, 0.0000f }, 0.1140f, 0.1000f, 0.2500f, 0.0000f, 0.9943f, 3762.6001f, 362.5000f, 0.0000f, 0x1 }
|
||||
|
||||
/* Ice Palace Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_ICEPALACE_SMALLROOM \
|
||||
{ 1.0000f, 0.8400f, 0.3162f, 0.5623f, 0.2818f, 1.5100f, 1.5300f, 0.2700f, 0.8913f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.1640f, 0.1400f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_ICEPALACE_SHORTPASSAGE \
|
||||
{ 1.0000f, 0.7500f, 0.3162f, 0.5623f, 0.2818f, 1.7900f, 1.4600f, 0.2800f, 0.5012f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0190f, { 0.0000f, 0.0000f, 0.0000f }, 0.1770f, 0.0900f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_ICEPALACE_MEDIUMROOM \
|
||||
{ 1.0000f, 0.8700f, 0.3162f, 0.5623f, 0.4467f, 2.2200f, 1.5300f, 0.3200f, 0.3981f, 0.0390f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0270f, { 0.0000f, 0.0000f, 0.0000f }, 0.1860f, 0.1200f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_ICEPALACE_LARGEROOM \
|
||||
{ 1.0000f, 0.8100f, 0.3162f, 0.5623f, 0.4467f, 3.1400f, 1.5300f, 0.3200f, 0.2512f, 0.0390f, { 0.0000f, 0.0000f, 0.0000f }, 1.0000f, 0.0270f, { 0.0000f, 0.0000f, 0.0000f }, 0.2140f, 0.1100f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_ICEPALACE_LONGPASSAGE \
|
||||
{ 1.0000f, 0.7700f, 0.3162f, 0.5623f, 0.3981f, 3.0100f, 1.4600f, 0.2800f, 0.7943f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0250f, { 0.0000f, 0.0000f, 0.0000f }, 0.1860f, 0.0400f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_ICEPALACE_HALL \
|
||||
{ 1.0000f, 0.7600f, 0.3162f, 0.4467f, 0.5623f, 5.4900f, 1.5300f, 0.3800f, 0.1122f, 0.0540f, { 0.0000f, 0.0000f, 0.0000f }, 0.6310f, 0.0520f, { 0.0000f, 0.0000f, 0.0000f }, 0.2260f, 0.1100f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_ICEPALACE_CUPBOARD \
|
||||
{ 1.0000f, 0.8300f, 0.3162f, 0.5012f, 0.2239f, 0.7600f, 1.5300f, 0.2600f, 1.1220f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.9953f, 0.0160f, { 0.0000f, 0.0000f, 0.0000f }, 0.1430f, 0.0800f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_ICEPALACE_COURTYARD \
|
||||
{ 1.0000f, 0.5900f, 0.3162f, 0.2818f, 0.3162f, 2.0400f, 1.2000f, 0.3800f, 0.3162f, 0.1730f, { 0.0000f, 0.0000f, 0.0000f }, 0.3162f, 0.0430f, { 0.0000f, 0.0000f, 0.0000f }, 0.2350f, 0.4800f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_ICEPALACE_ALCOVE \
|
||||
{ 1.0000f, 0.8400f, 0.3162f, 0.5623f, 0.2818f, 2.7600f, 1.4600f, 0.2800f, 1.1220f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.1610f, 0.0900f, 0.2500f, 0.0000f, 0.9943f, 12428.5000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
/* Space Station Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_SPACESTATION_SMALLROOM \
|
||||
{ 0.2109f, 0.7000f, 0.3162f, 0.7079f, 0.8913f, 1.7200f, 0.8200f, 0.5500f, 0.7943f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0130f, { 0.0000f, 0.0000f, 0.0000f }, 0.1880f, 0.2600f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPACESTATION_SHORTPASSAGE \
|
||||
{ 0.2109f, 0.8700f, 0.3162f, 0.6310f, 0.8913f, 3.5700f, 0.5000f, 0.5500f, 1.0000f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0160f, { 0.0000f, 0.0000f, 0.0000f }, 0.1720f, 0.2000f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPACESTATION_MEDIUMROOM \
|
||||
{ 0.2109f, 0.7500f, 0.3162f, 0.6310f, 0.8913f, 3.0100f, 0.5000f, 0.5500f, 0.3981f, 0.0340f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0350f, { 0.0000f, 0.0000f, 0.0000f }, 0.2090f, 0.3100f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPACESTATION_LARGEROOM \
|
||||
{ 0.3645f, 0.8100f, 0.3162f, 0.6310f, 0.8913f, 3.8900f, 0.3800f, 0.6100f, 0.3162f, 0.0560f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0350f, { 0.0000f, 0.0000f, 0.0000f }, 0.2330f, 0.2800f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPACESTATION_LONGPASSAGE \
|
||||
{ 0.4287f, 0.8200f, 0.3162f, 0.6310f, 0.8913f, 4.6200f, 0.6200f, 0.5500f, 1.0000f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0310f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2300f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPACESTATION_HALL \
|
||||
{ 0.4287f, 0.8700f, 0.3162f, 0.6310f, 0.8913f, 7.1100f, 0.3800f, 0.6100f, 0.1778f, 0.1000f, { 0.0000f, 0.0000f, 0.0000f }, 0.6310f, 0.0470f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2500f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPACESTATION_CUPBOARD \
|
||||
{ 0.1715f, 0.5600f, 0.3162f, 0.7079f, 0.8913f, 0.7900f, 0.8100f, 0.5500f, 1.4125f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.7783f, 0.0180f, { 0.0000f, 0.0000f, 0.0000f }, 0.1810f, 0.3100f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPACESTATION_ALCOVE \
|
||||
{ 0.2109f, 0.7800f, 0.3162f, 0.7079f, 0.8913f, 1.1600f, 0.8100f, 0.5500f, 1.4125f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 1.0000f, 0.0180f, { 0.0000f, 0.0000f, 0.0000f }, 0.1920f, 0.2100f, 0.2500f, 0.0000f, 0.9943f, 3316.1001f, 458.2000f, 0.0000f, 0x1 }
|
||||
|
||||
/* Wooden Galleon Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_WOODEN_SMALLROOM \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.1122f, 0.3162f, 0.7900f, 0.3200f, 0.8700f, 1.0000f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0290f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_WOODEN_SHORTPASSAGE \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.1259f, 0.3162f, 1.7500f, 0.5000f, 0.8700f, 0.8913f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 0.6310f, 0.0240f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_WOODEN_MEDIUMROOM \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.1000f, 0.2818f, 1.4700f, 0.4200f, 0.8200f, 0.8913f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0290f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_WOODEN_LARGEROOM \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.0891f, 0.2818f, 2.6500f, 0.3300f, 0.8200f, 0.8913f, 0.0660f, { 0.0000f, 0.0000f, 0.0000f }, 0.7943f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_WOODEN_LONGPASSAGE \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.1000f, 0.3162f, 1.9900f, 0.4000f, 0.7900f, 1.0000f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.4467f, 0.0360f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_WOODEN_HALL \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.0794f, 0.2818f, 3.4500f, 0.3000f, 0.8200f, 0.8913f, 0.0880f, { 0.0000f, 0.0000f, 0.0000f }, 0.7943f, 0.0630f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_WOODEN_CUPBOARD \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.1413f, 0.3162f, 0.5600f, 0.4600f, 0.9100f, 1.1220f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0280f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_WOODEN_COURTYARD \
|
||||
{ 1.0000f, 0.6500f, 0.3162f, 0.0794f, 0.3162f, 1.7900f, 0.3500f, 0.7900f, 0.5623f, 0.1230f, { 0.0000f, 0.0000f, 0.0000f }, 0.1000f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_WOODEN_ALCOVE \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.1259f, 0.3162f, 1.2200f, 0.6200f, 0.9100f, 1.1220f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 0.7079f, 0.0240f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 4705.0000f, 99.6000f, 0.0000f, 0x1 }
|
||||
|
||||
/* Sports Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_SPORT_EMPTYSTADIUM \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.4467f, 0.7943f, 6.2600f, 0.5100f, 1.1000f, 0.0631f, 0.1830f, { 0.0000f, 0.0000f, 0.0000f }, 0.3981f, 0.0380f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPORT_SQUASHCOURT \
|
||||
{ 1.0000f, 0.7500f, 0.3162f, 0.3162f, 0.7943f, 2.2200f, 0.9100f, 1.1600f, 0.4467f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 0.7943f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.1260f, 0.1900f, 0.2500f, 0.0000f, 0.9943f, 7176.8999f, 211.2000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPORT_SMALLSWIMMINGPOOL \
|
||||
{ 1.0000f, 0.7000f, 0.3162f, 0.7943f, 0.8913f, 2.7600f, 1.2500f, 1.1400f, 0.6310f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.7943f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.1790f, 0.1500f, 0.8950f, 0.1900f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPORT_LARGESWIMMINGPOOL \
|
||||
{ 1.0000f, 0.8200f, 0.3162f, 0.7943f, 1.0000f, 5.4900f, 1.3100f, 1.1400f, 0.4467f, 0.0390f, { 0.0000f, 0.0000f, 0.0000f }, 0.5012f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.2220f, 0.5500f, 1.1590f, 0.2100f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPORT_GYMNASIUM \
|
||||
{ 1.0000f, 0.8100f, 0.3162f, 0.4467f, 0.8913f, 3.1400f, 1.0600f, 1.3500f, 0.3981f, 0.0290f, { 0.0000f, 0.0000f, 0.0000f }, 0.5623f, 0.0450f, { 0.0000f, 0.0000f, 0.0000f }, 0.1460f, 0.1400f, 0.2500f, 0.0000f, 0.9943f, 7176.8999f, 211.2000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPORT_FULLSTADIUM \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.0708f, 0.7943f, 5.2500f, 0.1700f, 0.8000f, 0.1000f, 0.1880f, { 0.0000f, 0.0000f, 0.0000f }, 0.2818f, 0.0380f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SPORT_STADIUMTANNOY \
|
||||
{ 1.0000f, 0.7800f, 0.3162f, 0.5623f, 0.5012f, 2.5300f, 0.8800f, 0.6800f, 0.2818f, 0.2300f, { 0.0000f, 0.0000f, 0.0000f }, 0.5012f, 0.0630f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
/* Prefab Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_PREFAB_WORKSHOP \
|
||||
{ 0.4287f, 1.0000f, 0.3162f, 0.1413f, 0.3981f, 0.7600f, 1.0000f, 1.0000f, 1.0000f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PREFAB_SCHOOLROOM \
|
||||
{ 0.4022f, 0.6900f, 0.3162f, 0.6310f, 0.5012f, 0.9800f, 0.4500f, 0.1800f, 1.4125f, 0.0170f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0150f, { 0.0000f, 0.0000f, 0.0000f }, 0.0950f, 0.1400f, 0.2500f, 0.0000f, 0.9943f, 7176.8999f, 211.2000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PREFAB_PRACTISEROOM \
|
||||
{ 0.4022f, 0.8700f, 0.3162f, 0.3981f, 0.5012f, 1.1200f, 0.5600f, 0.1800f, 1.2589f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0110f, { 0.0000f, 0.0000f, 0.0000f }, 0.0950f, 0.1400f, 0.2500f, 0.0000f, 0.9943f, 7176.8999f, 211.2000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PREFAB_OUTHOUSE \
|
||||
{ 1.0000f, 0.8200f, 0.3162f, 0.1122f, 0.1585f, 1.3800f, 0.3800f, 0.3500f, 0.8913f, 0.0240f, { 0.0000f, 0.0000f, -0.0000f }, 0.6310f, 0.0440f, { 0.0000f, 0.0000f, 0.0000f }, 0.1210f, 0.1700f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 107.5000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PREFAB_CARAVAN \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.0891f, 0.1259f, 0.4300f, 1.5000f, 1.0000f, 1.0000f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 1.9953f, 0.0120f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
/* Dome and Pipe Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_DOME_TOMB \
|
||||
{ 1.0000f, 0.7900f, 0.3162f, 0.3548f, 0.2239f, 4.1800f, 0.2100f, 0.1000f, 0.3868f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 1.6788f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 0.1770f, 0.1900f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PIPE_SMALL \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.3548f, 0.2239f, 5.0400f, 0.1000f, 0.1000f, 0.5012f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 2.5119f, 0.0150f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_DOME_SAINTPAULS \
|
||||
{ 1.0000f, 0.8700f, 0.3162f, 0.3548f, 0.2239f, 10.4800f, 0.1900f, 0.1000f, 0.1778f, 0.0900f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0420f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.1200f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PIPE_LONGTHIN \
|
||||
{ 0.2560f, 0.9100f, 0.3162f, 0.4467f, 0.2818f, 9.2100f, 0.1800f, 0.1000f, 0.7079f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 0.7079f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PIPE_LARGE \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.3548f, 0.2239f, 8.4500f, 0.1000f, 0.1000f, 0.3981f, 0.0460f, { 0.0000f, 0.0000f, 0.0000f }, 1.5849f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_PIPE_RESONANT \
|
||||
{ 0.1373f, 0.9100f, 0.3162f, 0.4467f, 0.2818f, 6.8100f, 0.1800f, 0.1000f, 0.7079f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.0000f, 0.0220f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 20.0000f, 0.0000f, 0x0 }
|
||||
|
||||
/* Outdoors Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_OUTDOORS_BACKYARD \
|
||||
{ 1.0000f, 0.4500f, 0.3162f, 0.2512f, 0.5012f, 1.1200f, 0.3400f, 0.4600f, 0.4467f, 0.0690f, { 0.0000f, 0.0000f, -0.0000f }, 0.7079f, 0.0230f, { 0.0000f, 0.0000f, 0.0000f }, 0.2180f, 0.3400f, 0.2500f, 0.0000f, 0.9943f, 4399.1001f, 242.9000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_OUTDOORS_ROLLINGPLAINS \
|
||||
{ 1.0000f, 0.0000f, 0.3162f, 0.0112f, 0.6310f, 2.1300f, 0.2100f, 0.4600f, 0.1778f, 0.3000f, { 0.0000f, 0.0000f, -0.0000f }, 0.4467f, 0.0190f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.2500f, 0.0000f, 0.9943f, 4399.1001f, 242.9000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_OUTDOORS_DEEPCANYON \
|
||||
{ 1.0000f, 0.7400f, 0.3162f, 0.1778f, 0.6310f, 3.8900f, 0.2100f, 0.4600f, 0.3162f, 0.2230f, { 0.0000f, 0.0000f, -0.0000f }, 0.3548f, 0.0190f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.2500f, 0.0000f, 0.9943f, 4399.1001f, 242.9000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_OUTDOORS_CREEK \
|
||||
{ 1.0000f, 0.3500f, 0.3162f, 0.1778f, 0.5012f, 2.1300f, 0.2100f, 0.4600f, 0.3981f, 0.1150f, { 0.0000f, 0.0000f, -0.0000f }, 0.1995f, 0.0310f, { 0.0000f, 0.0000f, 0.0000f }, 0.2180f, 0.3400f, 0.2500f, 0.0000f, 0.9943f, 4399.1001f, 242.9000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_OUTDOORS_VALLEY \
|
||||
{ 1.0000f, 0.2800f, 0.3162f, 0.0282f, 0.1585f, 2.8800f, 0.2600f, 0.3500f, 0.1413f, 0.2630f, { 0.0000f, 0.0000f, -0.0000f }, 0.3981f, 0.1000f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.3400f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 107.5000f, 0.0000f, 0x0 }
|
||||
|
||||
/* Mood Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_MOOD_HEAVEN \
|
||||
{ 1.0000f, 0.9400f, 0.3162f, 0.7943f, 0.4467f, 5.0400f, 1.1200f, 0.5600f, 0.2427f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0290f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0800f, 2.7420f, 0.0500f, 0.9977f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_MOOD_HELL \
|
||||
{ 1.0000f, 0.5700f, 0.3162f, 0.3548f, 0.4467f, 3.5700f, 0.4900f, 2.0000f, 0.0000f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.1100f, 0.0400f, 2.1090f, 0.5200f, 0.9943f, 5000.0000f, 139.5000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_MOOD_MEMORY \
|
||||
{ 1.0000f, 0.8500f, 0.3162f, 0.6310f, 0.3548f, 4.0600f, 0.8200f, 0.5600f, 0.0398f, 0.0000f, { 0.0000f, 0.0000f, 0.0000f }, 1.1220f, 0.0000f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.4740f, 0.4500f, 0.9886f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
/* Driving Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_DRIVING_COMMENTATOR \
|
||||
{ 1.0000f, 0.0000f, 3.1623f, 0.5623f, 0.5012f, 2.4200f, 0.8800f, 0.6800f, 0.1995f, 0.0930f, { 0.0000f, 0.0000f, 0.0000f }, 0.2512f, 0.0170f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 1.0000f, 0.2500f, 0.0000f, 0.9886f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_DRIVING_PITGARAGE \
|
||||
{ 0.4287f, 0.5900f, 0.3162f, 0.7079f, 0.5623f, 1.7200f, 0.9300f, 0.8700f, 0.5623f, 0.0000f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0160f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.1100f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_DRIVING_INCAR_RACER \
|
||||
{ 0.0832f, 0.8000f, 0.3162f, 1.0000f, 0.7943f, 0.1700f, 2.0000f, 0.4100f, 1.7783f, 0.0070f, { 0.0000f, 0.0000f, 0.0000f }, 0.7079f, 0.0150f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 10268.2002f, 251.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_DRIVING_INCAR_SPORTS \
|
||||
{ 0.0832f, 0.8000f, 0.3162f, 0.6310f, 1.0000f, 0.1700f, 0.7500f, 0.4100f, 1.0000f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 0.5623f, 0.0000f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 10268.2002f, 251.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_DRIVING_INCAR_LUXURY \
|
||||
{ 0.2560f, 1.0000f, 0.3162f, 0.1000f, 0.5012f, 0.1300f, 0.4100f, 0.4600f, 0.7943f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 1.5849f, 0.0100f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 10268.2002f, 251.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_DRIVING_FULLGRANDSTAND \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 0.2818f, 0.6310f, 3.0100f, 1.3700f, 1.2800f, 0.3548f, 0.0900f, { 0.0000f, 0.0000f, 0.0000f }, 0.1778f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 10420.2002f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_DRIVING_EMPTYGRANDSTAND \
|
||||
{ 1.0000f, 1.0000f, 0.3162f, 1.0000f, 0.7943f, 4.6200f, 1.7500f, 1.4000f, 0.2082f, 0.0900f, { 0.0000f, 0.0000f, 0.0000f }, 0.2512f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.0000f, 0.9943f, 10420.2002f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_DRIVING_TUNNEL \
|
||||
{ 1.0000f, 0.8100f, 0.3162f, 0.3981f, 0.8913f, 3.4200f, 0.9400f, 1.3100f, 0.7079f, 0.0510f, { 0.0000f, 0.0000f, 0.0000f }, 0.7079f, 0.0470f, { 0.0000f, 0.0000f, 0.0000f }, 0.2140f, 0.0500f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 155.3000f, 0.0000f, 0x1 }
|
||||
|
||||
/* City Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_CITY_STREETS \
|
||||
{ 1.0000f, 0.7800f, 0.3162f, 0.7079f, 0.8913f, 1.7900f, 1.1200f, 0.9100f, 0.2818f, 0.0460f, { 0.0000f, 0.0000f, 0.0000f }, 0.1995f, 0.0280f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2000f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CITY_SUBWAY \
|
||||
{ 1.0000f, 0.7400f, 0.3162f, 0.7079f, 0.8913f, 3.0100f, 1.2300f, 0.9100f, 0.7079f, 0.0460f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0280f, { 0.0000f, 0.0000f, 0.0000f }, 0.1250f, 0.2100f, 0.2500f, 0.0000f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CITY_MUSEUM \
|
||||
{ 1.0000f, 0.8200f, 0.3162f, 0.1778f, 0.1778f, 3.2800f, 1.4000f, 0.5700f, 0.2512f, 0.0390f, { 0.0000f, 0.0000f, -0.0000f }, 0.8913f, 0.0340f, { 0.0000f, 0.0000f, 0.0000f }, 0.1300f, 0.1700f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 107.5000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CITY_LIBRARY \
|
||||
{ 1.0000f, 0.8200f, 0.3162f, 0.2818f, 0.0891f, 2.7600f, 0.8900f, 0.4100f, 0.3548f, 0.0290f, { 0.0000f, 0.0000f, -0.0000f }, 0.8913f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 0.1300f, 0.1700f, 0.2500f, 0.0000f, 0.9943f, 2854.3999f, 107.5000f, 0.0000f, 0x0 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CITY_UNDERPASS \
|
||||
{ 1.0000f, 0.8200f, 0.3162f, 0.4467f, 0.8913f, 3.5700f, 1.1200f, 0.9100f, 0.3981f, 0.0590f, { 0.0000f, 0.0000f, 0.0000f }, 0.8913f, 0.0370f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.1400f, 0.2500f, 0.0000f, 0.9920f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CITY_ABANDONED \
|
||||
{ 1.0000f, 0.6900f, 0.3162f, 0.7943f, 0.8913f, 3.2800f, 1.1700f, 0.9100f, 0.4467f, 0.0440f, { 0.0000f, 0.0000f, 0.0000f }, 0.2818f, 0.0240f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.2000f, 0.2500f, 0.0000f, 0.9966f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
/* Misc. Presets */
|
||||
|
||||
#define EFX_REVERB_PRESET_DUSTYROOM \
|
||||
{ 0.3645f, 0.5600f, 0.3162f, 0.7943f, 0.7079f, 1.7900f, 0.3800f, 0.2100f, 0.5012f, 0.0020f, { 0.0000f, 0.0000f, 0.0000f }, 1.2589f, 0.0060f, { 0.0000f, 0.0000f, 0.0000f }, 0.2020f, 0.0500f, 0.2500f, 0.0000f, 0.9886f, 13046.0000f, 163.3000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_CHAPEL \
|
||||
{ 1.0000f, 0.8400f, 0.3162f, 0.5623f, 1.0000f, 4.6200f, 0.6400f, 1.2300f, 0.4467f, 0.0320f, { 0.0000f, 0.0000f, 0.0000f }, 0.7943f, 0.0490f, { 0.0000f, 0.0000f, 0.0000f }, 0.2500f, 0.0000f, 0.2500f, 0.1100f, 0.9943f, 5000.0000f, 250.0000f, 0.0000f, 0x1 }
|
||||
|
||||
#define EFX_REVERB_PRESET_SMALLWATERROOM \
|
||||
{ 1.0000f, 0.7000f, 0.3162f, 0.4477f, 1.0000f, 1.5100f, 1.2500f, 1.1400f, 0.8913f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.1790f, 0.1500f, 0.8950f, 0.1900f, 0.9920f, 5000.0000f, 250.0000f, 0.0000f, 0x0 }
|
||||
|
||||
#endif /* EFX_PRESETS_H */
|
||||
758
Lib/Include/AL/efx.h
Normal file
758
Lib/Include/AL/efx.h
Normal file
@@ -0,0 +1,758 @@
|
||||
#ifndef AL_EFX_H
|
||||
#define AL_EFX_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ALC_EXT_EFX_NAME "ALC_EXT_EFX"
|
||||
|
||||
#define ALC_EFX_MAJOR_VERSION 0x20001
|
||||
#define ALC_EFX_MINOR_VERSION 0x20002
|
||||
#define ALC_MAX_AUXILIARY_SENDS 0x20003
|
||||
|
||||
|
||||
/* Listener properties. */
|
||||
#define AL_METERS_PER_UNIT 0x20004
|
||||
|
||||
/* Source properties. */
|
||||
#define AL_DIRECT_FILTER 0x20005
|
||||
#define AL_AUXILIARY_SEND_FILTER 0x20006
|
||||
#define AL_AIR_ABSORPTION_FACTOR 0x20007
|
||||
#define AL_ROOM_ROLLOFF_FACTOR 0x20008
|
||||
#define AL_CONE_OUTER_GAINHF 0x20009
|
||||
#define AL_DIRECT_FILTER_GAINHF_AUTO 0x2000A
|
||||
#define AL_AUXILIARY_SEND_FILTER_GAIN_AUTO 0x2000B
|
||||
#define AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO 0x2000C
|
||||
|
||||
|
||||
/* Effect properties. */
|
||||
|
||||
/* Reverb effect parameters */
|
||||
#define AL_REVERB_DENSITY 0x0001
|
||||
#define AL_REVERB_DIFFUSION 0x0002
|
||||
#define AL_REVERB_GAIN 0x0003
|
||||
#define AL_REVERB_GAINHF 0x0004
|
||||
#define AL_REVERB_DECAY_TIME 0x0005
|
||||
#define AL_REVERB_DECAY_HFRATIO 0x0006
|
||||
#define AL_REVERB_REFLECTIONS_GAIN 0x0007
|
||||
#define AL_REVERB_REFLECTIONS_DELAY 0x0008
|
||||
#define AL_REVERB_LATE_REVERB_GAIN 0x0009
|
||||
#define AL_REVERB_LATE_REVERB_DELAY 0x000A
|
||||
#define AL_REVERB_AIR_ABSORPTION_GAINHF 0x000B
|
||||
#define AL_REVERB_ROOM_ROLLOFF_FACTOR 0x000C
|
||||
#define AL_REVERB_DECAY_HFLIMIT 0x000D
|
||||
|
||||
/* EAX Reverb effect parameters */
|
||||
#define AL_EAXREVERB_DENSITY 0x0001
|
||||
#define AL_EAXREVERB_DIFFUSION 0x0002
|
||||
#define AL_EAXREVERB_GAIN 0x0003
|
||||
#define AL_EAXREVERB_GAINHF 0x0004
|
||||
#define AL_EAXREVERB_GAINLF 0x0005
|
||||
#define AL_EAXREVERB_DECAY_TIME 0x0006
|
||||
#define AL_EAXREVERB_DECAY_HFRATIO 0x0007
|
||||
#define AL_EAXREVERB_DECAY_LFRATIO 0x0008
|
||||
#define AL_EAXREVERB_REFLECTIONS_GAIN 0x0009
|
||||
#define AL_EAXREVERB_REFLECTIONS_DELAY 0x000A
|
||||
#define AL_EAXREVERB_REFLECTIONS_PAN 0x000B
|
||||
#define AL_EAXREVERB_LATE_REVERB_GAIN 0x000C
|
||||
#define AL_EAXREVERB_LATE_REVERB_DELAY 0x000D
|
||||
#define AL_EAXREVERB_LATE_REVERB_PAN 0x000E
|
||||
#define AL_EAXREVERB_ECHO_TIME 0x000F
|
||||
#define AL_EAXREVERB_ECHO_DEPTH 0x0010
|
||||
#define AL_EAXREVERB_MODULATION_TIME 0x0011
|
||||
#define AL_EAXREVERB_MODULATION_DEPTH 0x0012
|
||||
#define AL_EAXREVERB_AIR_ABSORPTION_GAINHF 0x0013
|
||||
#define AL_EAXREVERB_HFREFERENCE 0x0014
|
||||
#define AL_EAXREVERB_LFREFERENCE 0x0015
|
||||
#define AL_EAXREVERB_ROOM_ROLLOFF_FACTOR 0x0016
|
||||
#define AL_EAXREVERB_DECAY_HFLIMIT 0x0017
|
||||
|
||||
/* Chorus effect parameters */
|
||||
#define AL_CHORUS_WAVEFORM 0x0001
|
||||
#define AL_CHORUS_PHASE 0x0002
|
||||
#define AL_CHORUS_RATE 0x0003
|
||||
#define AL_CHORUS_DEPTH 0x0004
|
||||
#define AL_CHORUS_FEEDBACK 0x0005
|
||||
#define AL_CHORUS_DELAY 0x0006
|
||||
|
||||
/* Distortion effect parameters */
|
||||
#define AL_DISTORTION_EDGE 0x0001
|
||||
#define AL_DISTORTION_GAIN 0x0002
|
||||
#define AL_DISTORTION_LOWPASS_CUTOFF 0x0003
|
||||
#define AL_DISTORTION_EQCENTER 0x0004
|
||||
#define AL_DISTORTION_EQBANDWIDTH 0x0005
|
||||
|
||||
/* Echo effect parameters */
|
||||
#define AL_ECHO_DELAY 0x0001
|
||||
#define AL_ECHO_LRDELAY 0x0002
|
||||
#define AL_ECHO_DAMPING 0x0003
|
||||
#define AL_ECHO_FEEDBACK 0x0004
|
||||
#define AL_ECHO_SPREAD 0x0005
|
||||
|
||||
/* Flanger effect parameters */
|
||||
#define AL_FLANGER_WAVEFORM 0x0001
|
||||
#define AL_FLANGER_PHASE 0x0002
|
||||
#define AL_FLANGER_RATE 0x0003
|
||||
#define AL_FLANGER_DEPTH 0x0004
|
||||
#define AL_FLANGER_FEEDBACK 0x0005
|
||||
#define AL_FLANGER_DELAY 0x0006
|
||||
|
||||
/* Frequency shifter effect parameters */
|
||||
#define AL_FREQUENCY_SHIFTER_FREQUENCY 0x0001
|
||||
#define AL_FREQUENCY_SHIFTER_LEFT_DIRECTION 0x0002
|
||||
#define AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION 0x0003
|
||||
|
||||
/* Vocal morpher effect parameters */
|
||||
#define AL_VOCAL_MORPHER_PHONEMEA 0x0001
|
||||
#define AL_VOCAL_MORPHER_PHONEMEA_COARSE_TUNING 0x0002
|
||||
#define AL_VOCAL_MORPHER_PHONEMEB 0x0003
|
||||
#define AL_VOCAL_MORPHER_PHONEMEB_COARSE_TUNING 0x0004
|
||||
#define AL_VOCAL_MORPHER_WAVEFORM 0x0005
|
||||
#define AL_VOCAL_MORPHER_RATE 0x0006
|
||||
|
||||
/* Pitchshifter effect parameters */
|
||||
#define AL_PITCH_SHIFTER_COARSE_TUNE 0x0001
|
||||
#define AL_PITCH_SHIFTER_FINE_TUNE 0x0002
|
||||
|
||||
/* Ringmodulator effect parameters */
|
||||
#define AL_RING_MODULATOR_FREQUENCY 0x0001
|
||||
#define AL_RING_MODULATOR_HIGHPASS_CUTOFF 0x0002
|
||||
#define AL_RING_MODULATOR_WAVEFORM 0x0003
|
||||
|
||||
/* Autowah effect parameters */
|
||||
#define AL_AUTOWAH_ATTACK_TIME 0x0001
|
||||
#define AL_AUTOWAH_RELEASE_TIME 0x0002
|
||||
#define AL_AUTOWAH_RESONANCE 0x0003
|
||||
#define AL_AUTOWAH_PEAK_GAIN 0x0004
|
||||
|
||||
/* Compressor effect parameters */
|
||||
#define AL_COMPRESSOR_ONOFF 0x0001
|
||||
|
||||
/* Equalizer effect parameters */
|
||||
#define AL_EQUALIZER_LOW_GAIN 0x0001
|
||||
#define AL_EQUALIZER_LOW_CUTOFF 0x0002
|
||||
#define AL_EQUALIZER_MID1_GAIN 0x0003
|
||||
#define AL_EQUALIZER_MID1_CENTER 0x0004
|
||||
#define AL_EQUALIZER_MID1_WIDTH 0x0005
|
||||
#define AL_EQUALIZER_MID2_GAIN 0x0006
|
||||
#define AL_EQUALIZER_MID2_CENTER 0x0007
|
||||
#define AL_EQUALIZER_MID2_WIDTH 0x0008
|
||||
#define AL_EQUALIZER_HIGH_GAIN 0x0009
|
||||
#define AL_EQUALIZER_HIGH_CUTOFF 0x000A
|
||||
|
||||
/* Effect type */
|
||||
#define AL_EFFECT_FIRST_PARAMETER 0x0000
|
||||
#define AL_EFFECT_LAST_PARAMETER 0x8000
|
||||
#define AL_EFFECT_TYPE 0x8001
|
||||
|
||||
/* Effect types, used with the AL_EFFECT_TYPE property */
|
||||
#define AL_EFFECT_NULL 0x0000
|
||||
#define AL_EFFECT_REVERB 0x0001
|
||||
#define AL_EFFECT_CHORUS 0x0002
|
||||
#define AL_EFFECT_DISTORTION 0x0003
|
||||
#define AL_EFFECT_ECHO 0x0004
|
||||
#define AL_EFFECT_FLANGER 0x0005
|
||||
#define AL_EFFECT_FREQUENCY_SHIFTER 0x0006
|
||||
#define AL_EFFECT_VOCAL_MORPHER 0x0007
|
||||
#define AL_EFFECT_PITCH_SHIFTER 0x0008
|
||||
#define AL_EFFECT_RING_MODULATOR 0x0009
|
||||
#define AL_EFFECT_AUTOWAH 0x000A
|
||||
#define AL_EFFECT_COMPRESSOR 0x000B
|
||||
#define AL_EFFECT_EQUALIZER 0x000C
|
||||
#define AL_EFFECT_EAXREVERB 0x8000
|
||||
|
||||
/* Auxiliary Effect Slot properties. */
|
||||
#define AL_EFFECTSLOT_EFFECT 0x0001
|
||||
#define AL_EFFECTSLOT_GAIN 0x0002
|
||||
#define AL_EFFECTSLOT_AUXILIARY_SEND_AUTO 0x0003
|
||||
|
||||
/* NULL Auxiliary Slot ID to disable a source send. */
|
||||
#define AL_EFFECTSLOT_NULL 0x0000
|
||||
|
||||
|
||||
/* Filter properties. */
|
||||
|
||||
/* Lowpass filter parameters */
|
||||
#define AL_LOWPASS_GAIN 0x0001
|
||||
#define AL_LOWPASS_GAINHF 0x0002
|
||||
|
||||
/* Highpass filter parameters */
|
||||
#define AL_HIGHPASS_GAIN 0x0001
|
||||
#define AL_HIGHPASS_GAINLF 0x0002
|
||||
|
||||
/* Bandpass filter parameters */
|
||||
#define AL_BANDPASS_GAIN 0x0001
|
||||
#define AL_BANDPASS_GAINLF 0x0002
|
||||
#define AL_BANDPASS_GAINHF 0x0003
|
||||
|
||||
/* Filter type */
|
||||
#define AL_FILTER_FIRST_PARAMETER 0x0000
|
||||
#define AL_FILTER_LAST_PARAMETER 0x8000
|
||||
#define AL_FILTER_TYPE 0x8001
|
||||
|
||||
/* Filter types, used with the AL_FILTER_TYPE property */
|
||||
#define AL_FILTER_NULL 0x0000
|
||||
#define AL_FILTER_LOWPASS 0x0001
|
||||
#define AL_FILTER_HIGHPASS 0x0002
|
||||
#define AL_FILTER_BANDPASS 0x0003
|
||||
|
||||
|
||||
/* Effect object function types. */
|
||||
typedef void (AL_APIENTRY *LPALGENEFFECTS)(ALsizei, ALuint*);
|
||||
typedef void (AL_APIENTRY *LPALDELETEEFFECTS)(ALsizei, const ALuint*);
|
||||
typedef ALboolean (AL_APIENTRY *LPALISEFFECT)(ALuint);
|
||||
typedef void (AL_APIENTRY *LPALEFFECTI)(ALuint, ALenum, ALint);
|
||||
typedef void (AL_APIENTRY *LPALEFFECTIV)(ALuint, ALenum, const ALint*);
|
||||
typedef void (AL_APIENTRY *LPALEFFECTF)(ALuint, ALenum, ALfloat);
|
||||
typedef void (AL_APIENTRY *LPALEFFECTFV)(ALuint, ALenum, const ALfloat*);
|
||||
typedef void (AL_APIENTRY *LPALGETEFFECTI)(ALuint, ALenum, ALint*);
|
||||
typedef void (AL_APIENTRY *LPALGETEFFECTIV)(ALuint, ALenum, ALint*);
|
||||
typedef void (AL_APIENTRY *LPALGETEFFECTF)(ALuint, ALenum, ALfloat*);
|
||||
typedef void (AL_APIENTRY *LPALGETEFFECTFV)(ALuint, ALenum, ALfloat*);
|
||||
|
||||
/* Filter object function types. */
|
||||
typedef void (AL_APIENTRY *LPALGENFILTERS)(ALsizei, ALuint*);
|
||||
typedef void (AL_APIENTRY *LPALDELETEFILTERS)(ALsizei, const ALuint*);
|
||||
typedef ALboolean (AL_APIENTRY *LPALISFILTER)(ALuint);
|
||||
typedef void (AL_APIENTRY *LPALFILTERI)(ALuint, ALenum, ALint);
|
||||
typedef void (AL_APIENTRY *LPALFILTERIV)(ALuint, ALenum, const ALint*);
|
||||
typedef void (AL_APIENTRY *LPALFILTERF)(ALuint, ALenum, ALfloat);
|
||||
typedef void (AL_APIENTRY *LPALFILTERFV)(ALuint, ALenum, const ALfloat*);
|
||||
typedef void (AL_APIENTRY *LPALGETFILTERI)(ALuint, ALenum, ALint*);
|
||||
typedef void (AL_APIENTRY *LPALGETFILTERIV)(ALuint, ALenum, ALint*);
|
||||
typedef void (AL_APIENTRY *LPALGETFILTERF)(ALuint, ALenum, ALfloat*);
|
||||
typedef void (AL_APIENTRY *LPALGETFILTERFV)(ALuint, ALenum, ALfloat*);
|
||||
|
||||
/* Auxiliary Effect Slot object function types. */
|
||||
typedef void (AL_APIENTRY *LPALGENAUXILIARYEFFECTSLOTS)(ALsizei, ALuint*);
|
||||
typedef void (AL_APIENTRY *LPALDELETEAUXILIARYEFFECTSLOTS)(ALsizei, const ALuint*);
|
||||
typedef ALboolean (AL_APIENTRY *LPALISAUXILIARYEFFECTSLOT)(ALuint);
|
||||
typedef void (AL_APIENTRY *LPALAUXILIARYEFFECTSLOTI)(ALuint, ALenum, ALint);
|
||||
typedef void (AL_APIENTRY *LPALAUXILIARYEFFECTSLOTIV)(ALuint, ALenum, const ALint*);
|
||||
typedef void (AL_APIENTRY *LPALAUXILIARYEFFECTSLOTF)(ALuint, ALenum, ALfloat);
|
||||
typedef void (AL_APIENTRY *LPALAUXILIARYEFFECTSLOTFV)(ALuint, ALenum, const ALfloat*);
|
||||
typedef void (AL_APIENTRY *LPALGETAUXILIARYEFFECTSLOTI)(ALuint, ALenum, ALint*);
|
||||
typedef void (AL_APIENTRY *LPALGETAUXILIARYEFFECTSLOTIV)(ALuint, ALenum, ALint*);
|
||||
typedef void (AL_APIENTRY *LPALGETAUXILIARYEFFECTSLOTF)(ALuint, ALenum, ALfloat*);
|
||||
typedef void (AL_APIENTRY *LPALGETAUXILIARYEFFECTSLOTFV)(ALuint, ALenum, ALfloat*);
|
||||
|
||||
#ifdef AL_ALEXT_PROTOTYPES
|
||||
AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects);
|
||||
AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, const ALuint *effects);
|
||||
AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect);
|
||||
AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue);
|
||||
AL_API ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, const ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue);
|
||||
AL_API ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, const ALfloat *pflValues);
|
||||
AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues);
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters);
|
||||
AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters);
|
||||
AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter);
|
||||
AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue);
|
||||
AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, const ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat flValue);
|
||||
AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, const ALfloat *pflValues);
|
||||
AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *piValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pflValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues);
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots);
|
||||
AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *effectslots);
|
||||
AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot);
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint iValue);
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, const ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat flValue);
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, const ALfloat *pflValues);
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *piValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *pflValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues);
|
||||
#endif
|
||||
|
||||
/* Filter ranges and defaults. */
|
||||
|
||||
/* Lowpass filter */
|
||||
#define AL_LOWPASS_MIN_GAIN (0.0f)
|
||||
#define AL_LOWPASS_MAX_GAIN (1.0f)
|
||||
#define AL_LOWPASS_DEFAULT_GAIN (1.0f)
|
||||
|
||||
#define AL_LOWPASS_MIN_GAINHF (0.0f)
|
||||
#define AL_LOWPASS_MAX_GAINHF (1.0f)
|
||||
#define AL_LOWPASS_DEFAULT_GAINHF (1.0f)
|
||||
|
||||
/* Highpass filter */
|
||||
#define AL_HIGHPASS_MIN_GAIN (0.0f)
|
||||
#define AL_HIGHPASS_MAX_GAIN (1.0f)
|
||||
#define AL_HIGHPASS_DEFAULT_GAIN (1.0f)
|
||||
|
||||
#define AL_HIGHPASS_MIN_GAINLF (0.0f)
|
||||
#define AL_HIGHPASS_MAX_GAINLF (1.0f)
|
||||
#define AL_HIGHPASS_DEFAULT_GAINLF (1.0f)
|
||||
|
||||
/* Bandpass filter */
|
||||
#define AL_BANDPASS_MIN_GAIN (0.0f)
|
||||
#define AL_BANDPASS_MAX_GAIN (1.0f)
|
||||
#define AL_BANDPASS_DEFAULT_GAIN (1.0f)
|
||||
|
||||
#define AL_BANDPASS_MIN_GAINHF (0.0f)
|
||||
#define AL_BANDPASS_MAX_GAINHF (1.0f)
|
||||
#define AL_BANDPASS_DEFAULT_GAINHF (1.0f)
|
||||
|
||||
#define AL_BANDPASS_MIN_GAINLF (0.0f)
|
||||
#define AL_BANDPASS_MAX_GAINLF (1.0f)
|
||||
#define AL_BANDPASS_DEFAULT_GAINLF (1.0f)
|
||||
|
||||
|
||||
/* Effect parameter ranges and defaults. */
|
||||
|
||||
/* Standard reverb effect */
|
||||
#define AL_REVERB_MIN_DENSITY (0.0f)
|
||||
#define AL_REVERB_MAX_DENSITY (1.0f)
|
||||
#define AL_REVERB_DEFAULT_DENSITY (1.0f)
|
||||
|
||||
#define AL_REVERB_MIN_DIFFUSION (0.0f)
|
||||
#define AL_REVERB_MAX_DIFFUSION (1.0f)
|
||||
#define AL_REVERB_DEFAULT_DIFFUSION (1.0f)
|
||||
|
||||
#define AL_REVERB_MIN_GAIN (0.0f)
|
||||
#define AL_REVERB_MAX_GAIN (1.0f)
|
||||
#define AL_REVERB_DEFAULT_GAIN (0.32f)
|
||||
|
||||
#define AL_REVERB_MIN_GAINHF (0.0f)
|
||||
#define AL_REVERB_MAX_GAINHF (1.0f)
|
||||
#define AL_REVERB_DEFAULT_GAINHF (0.89f)
|
||||
|
||||
#define AL_REVERB_MIN_DECAY_TIME (0.1f)
|
||||
#define AL_REVERB_MAX_DECAY_TIME (20.0f)
|
||||
#define AL_REVERB_DEFAULT_DECAY_TIME (1.49f)
|
||||
|
||||
#define AL_REVERB_MIN_DECAY_HFRATIO (0.1f)
|
||||
#define AL_REVERB_MAX_DECAY_HFRATIO (2.0f)
|
||||
#define AL_REVERB_DEFAULT_DECAY_HFRATIO (0.83f)
|
||||
|
||||
#define AL_REVERB_MIN_REFLECTIONS_GAIN (0.0f)
|
||||
#define AL_REVERB_MAX_REFLECTIONS_GAIN (3.16f)
|
||||
#define AL_REVERB_DEFAULT_REFLECTIONS_GAIN (0.05f)
|
||||
|
||||
#define AL_REVERB_MIN_REFLECTIONS_DELAY (0.0f)
|
||||
#define AL_REVERB_MAX_REFLECTIONS_DELAY (0.3f)
|
||||
#define AL_REVERB_DEFAULT_REFLECTIONS_DELAY (0.007f)
|
||||
|
||||
#define AL_REVERB_MIN_LATE_REVERB_GAIN (0.0f)
|
||||
#define AL_REVERB_MAX_LATE_REVERB_GAIN (10.0f)
|
||||
#define AL_REVERB_DEFAULT_LATE_REVERB_GAIN (1.26f)
|
||||
|
||||
#define AL_REVERB_MIN_LATE_REVERB_DELAY (0.0f)
|
||||
#define AL_REVERB_MAX_LATE_REVERB_DELAY (0.1f)
|
||||
#define AL_REVERB_DEFAULT_LATE_REVERB_DELAY (0.011f)
|
||||
|
||||
#define AL_REVERB_MIN_AIR_ABSORPTION_GAINHF (0.892f)
|
||||
#define AL_REVERB_MAX_AIR_ABSORPTION_GAINHF (1.0f)
|
||||
#define AL_REVERB_DEFAULT_AIR_ABSORPTION_GAINHF (0.994f)
|
||||
|
||||
#define AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR (0.0f)
|
||||
#define AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR (10.0f)
|
||||
#define AL_REVERB_DEFAULT_ROOM_ROLLOFF_FACTOR (0.0f)
|
||||
|
||||
#define AL_REVERB_MIN_DECAY_HFLIMIT AL_FALSE
|
||||
#define AL_REVERB_MAX_DECAY_HFLIMIT AL_TRUE
|
||||
#define AL_REVERB_DEFAULT_DECAY_HFLIMIT AL_TRUE
|
||||
|
||||
/* EAX reverb effect */
|
||||
#define AL_EAXREVERB_MIN_DENSITY (0.0f)
|
||||
#define AL_EAXREVERB_MAX_DENSITY (1.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_DENSITY (1.0f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_DIFFUSION (0.0f)
|
||||
#define AL_EAXREVERB_MAX_DIFFUSION (1.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_DIFFUSION (1.0f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_GAIN (0.0f)
|
||||
#define AL_EAXREVERB_MAX_GAIN (1.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_GAIN (0.32f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_GAINHF (0.0f)
|
||||
#define AL_EAXREVERB_MAX_GAINHF (1.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_GAINHF (0.89f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_GAINLF (0.0f)
|
||||
#define AL_EAXREVERB_MAX_GAINLF (1.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_GAINLF (1.0f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_DECAY_TIME (0.1f)
|
||||
#define AL_EAXREVERB_MAX_DECAY_TIME (20.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_DECAY_TIME (1.49f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_DECAY_HFRATIO (0.1f)
|
||||
#define AL_EAXREVERB_MAX_DECAY_HFRATIO (2.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_DECAY_HFRATIO (0.83f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_DECAY_LFRATIO (0.1f)
|
||||
#define AL_EAXREVERB_MAX_DECAY_LFRATIO (2.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_DECAY_LFRATIO (1.0f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_REFLECTIONS_GAIN (0.0f)
|
||||
#define AL_EAXREVERB_MAX_REFLECTIONS_GAIN (3.16f)
|
||||
#define AL_EAXREVERB_DEFAULT_REFLECTIONS_GAIN (0.05f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_REFLECTIONS_DELAY (0.0f)
|
||||
#define AL_EAXREVERB_MAX_REFLECTIONS_DELAY (0.3f)
|
||||
#define AL_EAXREVERB_DEFAULT_REFLECTIONS_DELAY (0.007f)
|
||||
|
||||
#define AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ (0.0f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_LATE_REVERB_GAIN (0.0f)
|
||||
#define AL_EAXREVERB_MAX_LATE_REVERB_GAIN (10.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_LATE_REVERB_GAIN (1.26f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_LATE_REVERB_DELAY (0.0f)
|
||||
#define AL_EAXREVERB_MAX_LATE_REVERB_DELAY (0.1f)
|
||||
#define AL_EAXREVERB_DEFAULT_LATE_REVERB_DELAY (0.011f)
|
||||
|
||||
#define AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ (0.0f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_ECHO_TIME (0.075f)
|
||||
#define AL_EAXREVERB_MAX_ECHO_TIME (0.25f)
|
||||
#define AL_EAXREVERB_DEFAULT_ECHO_TIME (0.25f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_ECHO_DEPTH (0.0f)
|
||||
#define AL_EAXREVERB_MAX_ECHO_DEPTH (1.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_ECHO_DEPTH (0.0f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_MODULATION_TIME (0.04f)
|
||||
#define AL_EAXREVERB_MAX_MODULATION_TIME (4.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_MODULATION_TIME (0.25f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_MODULATION_DEPTH (0.0f)
|
||||
#define AL_EAXREVERB_MAX_MODULATION_DEPTH (1.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_MODULATION_DEPTH (0.0f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF (0.892f)
|
||||
#define AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF (1.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_AIR_ABSORPTION_GAINHF (0.994f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_HFREFERENCE (1000.0f)
|
||||
#define AL_EAXREVERB_MAX_HFREFERENCE (20000.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_HFREFERENCE (5000.0f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_LFREFERENCE (20.0f)
|
||||
#define AL_EAXREVERB_MAX_LFREFERENCE (1000.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_LFREFERENCE (250.0f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_ROOM_ROLLOFF_FACTOR (0.0f)
|
||||
#define AL_EAXREVERB_MAX_ROOM_ROLLOFF_FACTOR (10.0f)
|
||||
#define AL_EAXREVERB_DEFAULT_ROOM_ROLLOFF_FACTOR (0.0f)
|
||||
|
||||
#define AL_EAXREVERB_MIN_DECAY_HFLIMIT AL_FALSE
|
||||
#define AL_EAXREVERB_MAX_DECAY_HFLIMIT AL_TRUE
|
||||
#define AL_EAXREVERB_DEFAULT_DECAY_HFLIMIT AL_TRUE
|
||||
|
||||
/* Chorus effect */
|
||||
#define AL_CHORUS_WAVEFORM_SINUSOID (0)
|
||||
#define AL_CHORUS_WAVEFORM_TRIANGLE (1)
|
||||
|
||||
#define AL_CHORUS_MIN_WAVEFORM (0)
|
||||
#define AL_CHORUS_MAX_WAVEFORM (1)
|
||||
#define AL_CHORUS_DEFAULT_WAVEFORM (1)
|
||||
|
||||
#define AL_CHORUS_MIN_PHASE (-180)
|
||||
#define AL_CHORUS_MAX_PHASE (180)
|
||||
#define AL_CHORUS_DEFAULT_PHASE (90)
|
||||
|
||||
#define AL_CHORUS_MIN_RATE (0.0f)
|
||||
#define AL_CHORUS_MAX_RATE (10.0f)
|
||||
#define AL_CHORUS_DEFAULT_RATE (1.1f)
|
||||
|
||||
#define AL_CHORUS_MIN_DEPTH (0.0f)
|
||||
#define AL_CHORUS_MAX_DEPTH (1.0f)
|
||||
#define AL_CHORUS_DEFAULT_DEPTH (0.1f)
|
||||
|
||||
#define AL_CHORUS_MIN_FEEDBACK (-1.0f)
|
||||
#define AL_CHORUS_MAX_FEEDBACK (1.0f)
|
||||
#define AL_CHORUS_DEFAULT_FEEDBACK (0.25f)
|
||||
|
||||
#define AL_CHORUS_MIN_DELAY (0.0f)
|
||||
#define AL_CHORUS_MAX_DELAY (0.016f)
|
||||
#define AL_CHORUS_DEFAULT_DELAY (0.016f)
|
||||
|
||||
/* Distortion effect */
|
||||
#define AL_DISTORTION_MIN_EDGE (0.0f)
|
||||
#define AL_DISTORTION_MAX_EDGE (1.0f)
|
||||
#define AL_DISTORTION_DEFAULT_EDGE (0.2f)
|
||||
|
||||
#define AL_DISTORTION_MIN_GAIN (0.01f)
|
||||
#define AL_DISTORTION_MAX_GAIN (1.0f)
|
||||
#define AL_DISTORTION_DEFAULT_GAIN (0.05f)
|
||||
|
||||
#define AL_DISTORTION_MIN_LOWPASS_CUTOFF (80.0f)
|
||||
#define AL_DISTORTION_MAX_LOWPASS_CUTOFF (24000.0f)
|
||||
#define AL_DISTORTION_DEFAULT_LOWPASS_CUTOFF (8000.0f)
|
||||
|
||||
#define AL_DISTORTION_MIN_EQCENTER (80.0f)
|
||||
#define AL_DISTORTION_MAX_EQCENTER (24000.0f)
|
||||
#define AL_DISTORTION_DEFAULT_EQCENTER (3600.0f)
|
||||
|
||||
#define AL_DISTORTION_MIN_EQBANDWIDTH (80.0f)
|
||||
#define AL_DISTORTION_MAX_EQBANDWIDTH (24000.0f)
|
||||
#define AL_DISTORTION_DEFAULT_EQBANDWIDTH (3600.0f)
|
||||
|
||||
/* Echo effect */
|
||||
#define AL_ECHO_MIN_DELAY (0.0f)
|
||||
#define AL_ECHO_MAX_DELAY (0.207f)
|
||||
#define AL_ECHO_DEFAULT_DELAY (0.1f)
|
||||
|
||||
#define AL_ECHO_MIN_LRDELAY (0.0f)
|
||||
#define AL_ECHO_MAX_LRDELAY (0.404f)
|
||||
#define AL_ECHO_DEFAULT_LRDELAY (0.1f)
|
||||
|
||||
#define AL_ECHO_MIN_DAMPING (0.0f)
|
||||
#define AL_ECHO_MAX_DAMPING (0.99f)
|
||||
#define AL_ECHO_DEFAULT_DAMPING (0.5f)
|
||||
|
||||
#define AL_ECHO_MIN_FEEDBACK (0.0f)
|
||||
#define AL_ECHO_MAX_FEEDBACK (1.0f)
|
||||
#define AL_ECHO_DEFAULT_FEEDBACK (0.5f)
|
||||
|
||||
#define AL_ECHO_MIN_SPREAD (-1.0f)
|
||||
#define AL_ECHO_MAX_SPREAD (1.0f)
|
||||
#define AL_ECHO_DEFAULT_SPREAD (-1.0f)
|
||||
|
||||
/* Flanger effect */
|
||||
#define AL_FLANGER_WAVEFORM_SINUSOID (0)
|
||||
#define AL_FLANGER_WAVEFORM_TRIANGLE (1)
|
||||
|
||||
#define AL_FLANGER_MIN_WAVEFORM (0)
|
||||
#define AL_FLANGER_MAX_WAVEFORM (1)
|
||||
#define AL_FLANGER_DEFAULT_WAVEFORM (1)
|
||||
|
||||
#define AL_FLANGER_MIN_PHASE (-180)
|
||||
#define AL_FLANGER_MAX_PHASE (180)
|
||||
#define AL_FLANGER_DEFAULT_PHASE (0)
|
||||
|
||||
#define AL_FLANGER_MIN_RATE (0.0f)
|
||||
#define AL_FLANGER_MAX_RATE (10.0f)
|
||||
#define AL_FLANGER_DEFAULT_RATE (0.27f)
|
||||
|
||||
#define AL_FLANGER_MIN_DEPTH (0.0f)
|
||||
#define AL_FLANGER_MAX_DEPTH (1.0f)
|
||||
#define AL_FLANGER_DEFAULT_DEPTH (1.0f)
|
||||
|
||||
#define AL_FLANGER_MIN_FEEDBACK (-1.0f)
|
||||
#define AL_FLANGER_MAX_FEEDBACK (1.0f)
|
||||
#define AL_FLANGER_DEFAULT_FEEDBACK (-0.5f)
|
||||
|
||||
#define AL_FLANGER_MIN_DELAY (0.0f)
|
||||
#define AL_FLANGER_MAX_DELAY (0.004f)
|
||||
#define AL_FLANGER_DEFAULT_DELAY (0.002f)
|
||||
|
||||
/* Frequency shifter effect */
|
||||
#define AL_FREQUENCY_SHIFTER_MIN_FREQUENCY (0.0f)
|
||||
#define AL_FREQUENCY_SHIFTER_MAX_FREQUENCY (24000.0f)
|
||||
#define AL_FREQUENCY_SHIFTER_DEFAULT_FREQUENCY (0.0f)
|
||||
|
||||
#define AL_FREQUENCY_SHIFTER_MIN_LEFT_DIRECTION (0)
|
||||
#define AL_FREQUENCY_SHIFTER_MAX_LEFT_DIRECTION (2)
|
||||
#define AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION (0)
|
||||
|
||||
#define AL_FREQUENCY_SHIFTER_DIRECTION_DOWN (0)
|
||||
#define AL_FREQUENCY_SHIFTER_DIRECTION_UP (1)
|
||||
#define AL_FREQUENCY_SHIFTER_DIRECTION_OFF (2)
|
||||
|
||||
#define AL_FREQUENCY_SHIFTER_MIN_RIGHT_DIRECTION (0)
|
||||
#define AL_FREQUENCY_SHIFTER_MAX_RIGHT_DIRECTION (2)
|
||||
#define AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION (0)
|
||||
|
||||
/* Vocal morpher effect */
|
||||
#define AL_VOCAL_MORPHER_MIN_PHONEMEA (0)
|
||||
#define AL_VOCAL_MORPHER_MAX_PHONEMEA (29)
|
||||
#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEA (0)
|
||||
|
||||
#define AL_VOCAL_MORPHER_MIN_PHONEMEA_COARSE_TUNING (-24)
|
||||
#define AL_VOCAL_MORPHER_MAX_PHONEMEA_COARSE_TUNING (24)
|
||||
#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEA_COARSE_TUNING (0)
|
||||
|
||||
#define AL_VOCAL_MORPHER_MIN_PHONEMEB (0)
|
||||
#define AL_VOCAL_MORPHER_MAX_PHONEMEB (29)
|
||||
#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEB (10)
|
||||
|
||||
#define AL_VOCAL_MORPHER_MIN_PHONEMEB_COARSE_TUNING (-24)
|
||||
#define AL_VOCAL_MORPHER_MAX_PHONEMEB_COARSE_TUNING (24)
|
||||
#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEB_COARSE_TUNING (0)
|
||||
|
||||
#define AL_VOCAL_MORPHER_PHONEME_A (0)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_E (1)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_I (2)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_O (3)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_U (4)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_AA (5)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_AE (6)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_AH (7)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_AO (8)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_EH (9)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_ER (10)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_IH (11)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_IY (12)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_UH (13)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_UW (14)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_B (15)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_D (16)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_F (17)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_G (18)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_J (19)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_K (20)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_L (21)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_M (22)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_N (23)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_P (24)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_R (25)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_S (26)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_T (27)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_V (28)
|
||||
#define AL_VOCAL_MORPHER_PHONEME_Z (29)
|
||||
|
||||
#define AL_VOCAL_MORPHER_WAVEFORM_SINUSOID (0)
|
||||
#define AL_VOCAL_MORPHER_WAVEFORM_TRIANGLE (1)
|
||||
#define AL_VOCAL_MORPHER_WAVEFORM_SAWTOOTH (2)
|
||||
|
||||
#define AL_VOCAL_MORPHER_MIN_WAVEFORM (0)
|
||||
#define AL_VOCAL_MORPHER_MAX_WAVEFORM (2)
|
||||
#define AL_VOCAL_MORPHER_DEFAULT_WAVEFORM (0)
|
||||
|
||||
#define AL_VOCAL_MORPHER_MIN_RATE (0.0f)
|
||||
#define AL_VOCAL_MORPHER_MAX_RATE (10.0f)
|
||||
#define AL_VOCAL_MORPHER_DEFAULT_RATE (1.41f)
|
||||
|
||||
/* Pitch shifter effect */
|
||||
#define AL_PITCH_SHIFTER_MIN_COARSE_TUNE (-12)
|
||||
#define AL_PITCH_SHIFTER_MAX_COARSE_TUNE (12)
|
||||
#define AL_PITCH_SHIFTER_DEFAULT_COARSE_TUNE (12)
|
||||
|
||||
#define AL_PITCH_SHIFTER_MIN_FINE_TUNE (-50)
|
||||
#define AL_PITCH_SHIFTER_MAX_FINE_TUNE (50)
|
||||
#define AL_PITCH_SHIFTER_DEFAULT_FINE_TUNE (0)
|
||||
|
||||
/* Ring modulator effect */
|
||||
#define AL_RING_MODULATOR_MIN_FREQUENCY (0.0f)
|
||||
#define AL_RING_MODULATOR_MAX_FREQUENCY (8000.0f)
|
||||
#define AL_RING_MODULATOR_DEFAULT_FREQUENCY (440.0f)
|
||||
|
||||
#define AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF (0.0f)
|
||||
#define AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF (24000.0f)
|
||||
#define AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF (800.0f)
|
||||
|
||||
#define AL_RING_MODULATOR_SINUSOID (0)
|
||||
#define AL_RING_MODULATOR_SAWTOOTH (1)
|
||||
#define AL_RING_MODULATOR_SQUARE (2)
|
||||
|
||||
#define AL_RING_MODULATOR_MIN_WAVEFORM (0)
|
||||
#define AL_RING_MODULATOR_MAX_WAVEFORM (2)
|
||||
#define AL_RING_MODULATOR_DEFAULT_WAVEFORM (0)
|
||||
|
||||
/* Autowah effect */
|
||||
#define AL_AUTOWAH_MIN_ATTACK_TIME (0.0001f)
|
||||
#define AL_AUTOWAH_MAX_ATTACK_TIME (1.0f)
|
||||
#define AL_AUTOWAH_DEFAULT_ATTACK_TIME (0.06f)
|
||||
|
||||
#define AL_AUTOWAH_MIN_RELEASE_TIME (0.0001f)
|
||||
#define AL_AUTOWAH_MAX_RELEASE_TIME (1.0f)
|
||||
#define AL_AUTOWAH_DEFAULT_RELEASE_TIME (0.06f)
|
||||
|
||||
#define AL_AUTOWAH_MIN_RESONANCE (2.0f)
|
||||
#define AL_AUTOWAH_MAX_RESONANCE (1000.0f)
|
||||
#define AL_AUTOWAH_DEFAULT_RESONANCE (1000.0f)
|
||||
|
||||
#define AL_AUTOWAH_MIN_PEAK_GAIN (0.00003f)
|
||||
#define AL_AUTOWAH_MAX_PEAK_GAIN (31621.0f)
|
||||
#define AL_AUTOWAH_DEFAULT_PEAK_GAIN (11.22f)
|
||||
|
||||
/* Compressor effect */
|
||||
#define AL_COMPRESSOR_MIN_ONOFF (0)
|
||||
#define AL_COMPRESSOR_MAX_ONOFF (1)
|
||||
#define AL_COMPRESSOR_DEFAULT_ONOFF (1)
|
||||
|
||||
/* Equalizer effect */
|
||||
#define AL_EQUALIZER_MIN_LOW_GAIN (0.126f)
|
||||
#define AL_EQUALIZER_MAX_LOW_GAIN (7.943f)
|
||||
#define AL_EQUALIZER_DEFAULT_LOW_GAIN (1.0f)
|
||||
|
||||
#define AL_EQUALIZER_MIN_LOW_CUTOFF (50.0f)
|
||||
#define AL_EQUALIZER_MAX_LOW_CUTOFF (800.0f)
|
||||
#define AL_EQUALIZER_DEFAULT_LOW_CUTOFF (200.0f)
|
||||
|
||||
#define AL_EQUALIZER_MIN_MID1_GAIN (0.126f)
|
||||
#define AL_EQUALIZER_MAX_MID1_GAIN (7.943f)
|
||||
#define AL_EQUALIZER_DEFAULT_MID1_GAIN (1.0f)
|
||||
|
||||
#define AL_EQUALIZER_MIN_MID1_CENTER (200.0f)
|
||||
#define AL_EQUALIZER_MAX_MID1_CENTER (3000.0f)
|
||||
#define AL_EQUALIZER_DEFAULT_MID1_CENTER (500.0f)
|
||||
|
||||
#define AL_EQUALIZER_MIN_MID1_WIDTH (0.01f)
|
||||
#define AL_EQUALIZER_MAX_MID1_WIDTH (1.0f)
|
||||
#define AL_EQUALIZER_DEFAULT_MID1_WIDTH (1.0f)
|
||||
|
||||
#define AL_EQUALIZER_MIN_MID2_GAIN (0.126f)
|
||||
#define AL_EQUALIZER_MAX_MID2_GAIN (7.943f)
|
||||
#define AL_EQUALIZER_DEFAULT_MID2_GAIN (1.0f)
|
||||
|
||||
#define AL_EQUALIZER_MIN_MID2_CENTER (1000.0f)
|
||||
#define AL_EQUALIZER_MAX_MID2_CENTER (8000.0f)
|
||||
#define AL_EQUALIZER_DEFAULT_MID2_CENTER (3000.0f)
|
||||
|
||||
#define AL_EQUALIZER_MIN_MID2_WIDTH (0.01f)
|
||||
#define AL_EQUALIZER_MAX_MID2_WIDTH (1.0f)
|
||||
#define AL_EQUALIZER_DEFAULT_MID2_WIDTH (1.0f)
|
||||
|
||||
#define AL_EQUALIZER_MIN_HIGH_GAIN (0.126f)
|
||||
#define AL_EQUALIZER_MAX_HIGH_GAIN (7.943f)
|
||||
#define AL_EQUALIZER_DEFAULT_HIGH_GAIN (1.0f)
|
||||
|
||||
#define AL_EQUALIZER_MIN_HIGH_CUTOFF (4000.0f)
|
||||
#define AL_EQUALIZER_MAX_HIGH_CUTOFF (16000.0f)
|
||||
#define AL_EQUALIZER_DEFAULT_HIGH_CUTOFF (6000.0f)
|
||||
|
||||
|
||||
/* Source parameter value ranges and defaults. */
|
||||
#define AL_MIN_AIR_ABSORPTION_FACTOR (0.0f)
|
||||
#define AL_MAX_AIR_ABSORPTION_FACTOR (10.0f)
|
||||
#define AL_DEFAULT_AIR_ABSORPTION_FACTOR (0.0f)
|
||||
|
||||
#define AL_MIN_ROOM_ROLLOFF_FACTOR (0.0f)
|
||||
#define AL_MAX_ROOM_ROLLOFF_FACTOR (10.0f)
|
||||
#define AL_DEFAULT_ROOM_ROLLOFF_FACTOR (0.0f)
|
||||
|
||||
#define AL_MIN_CONE_OUTER_GAINHF (0.0f)
|
||||
#define AL_MAX_CONE_OUTER_GAINHF (1.0f)
|
||||
#define AL_DEFAULT_CONE_OUTER_GAINHF (1.0f)
|
||||
|
||||
#define AL_MIN_DIRECT_FILTER_GAINHF_AUTO AL_FALSE
|
||||
#define AL_MAX_DIRECT_FILTER_GAINHF_AUTO AL_TRUE
|
||||
#define AL_DEFAULT_DIRECT_FILTER_GAINHF_AUTO AL_TRUE
|
||||
|
||||
#define AL_MIN_AUXILIARY_SEND_FILTER_GAIN_AUTO AL_FALSE
|
||||
#define AL_MAX_AUXILIARY_SEND_FILTER_GAIN_AUTO AL_TRUE
|
||||
#define AL_DEFAULT_AUXILIARY_SEND_FILTER_GAIN_AUTO AL_TRUE
|
||||
|
||||
#define AL_MIN_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_FALSE
|
||||
#define AL_MAX_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_TRUE
|
||||
#define AL_DEFAULT_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_TRUE
|
||||
|
||||
|
||||
/* Listener parameter value ranges and defaults. */
|
||||
#define AL_MIN_METERS_PER_UNIT FLT_MIN
|
||||
#define AL_MAX_METERS_PER_UNIT FLT_MAX
|
||||
#define AL_DEFAULT_METERS_PER_UNIT (1.0f)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* AL_EFX_H */
|
||||
68
Lib/Include/Box2D/Box2D.h
Normal file
68
Lib/Include/Box2D/Box2D.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BOX2D_H
|
||||
#define BOX2D_H
|
||||
|
||||
/**
|
||||
\mainpage Box2D API Documentation
|
||||
|
||||
\section intro_sec Getting Started
|
||||
|
||||
For documentation please see http://box2d.org/documentation.html
|
||||
|
||||
For discussion please visit http://box2d.org/forum
|
||||
*/
|
||||
|
||||
// These include files constitute the main Box2D API
|
||||
|
||||
#include <Box2D/Common/b2Settings.h>
|
||||
#include <Box2D/Common/b2Draw.h>
|
||||
#include <Box2D/Common/b2Timer.h>
|
||||
|
||||
#include <Box2D/Collision/Shapes/b2CircleShape.h>
|
||||
#include <Box2D/Collision/Shapes/b2EdgeShape.h>
|
||||
#include <Box2D/Collision/Shapes/b2ChainShape.h>
|
||||
#include <Box2D/Collision/Shapes/b2PolygonShape.h>
|
||||
|
||||
#include <Box2D/Collision/b2BroadPhase.h>
|
||||
#include <Box2D/Collision/b2Distance.h>
|
||||
#include <Box2D/Collision/b2DynamicTree.h>
|
||||
#include <Box2D/Collision/b2TimeOfImpact.h>
|
||||
|
||||
#include <Box2D/Dynamics/b2Body.h>
|
||||
#include <Box2D/Dynamics/b2Fixture.h>
|
||||
#include <Box2D/Dynamics/b2WorldCallbacks.h>
|
||||
#include <Box2D/Dynamics/b2TimeStep.h>
|
||||
#include <Box2D/Dynamics/b2World.h>
|
||||
|
||||
#include <Box2D/Dynamics/Contacts/b2Contact.h>
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2DistanceJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2FrictionJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2GearJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2MotorJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2MouseJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2PrismaticJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2PulleyJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2RevoluteJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2RopeJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2WeldJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2WheelJoint.h>
|
||||
|
||||
#endif
|
||||
102
Lib/Include/Box2D/Collision/Shapes/b2ChainShape.h
Normal file
102
Lib/Include/Box2D/Collision/Shapes/b2ChainShape.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_CHAIN_SHAPE_H
|
||||
#define B2_CHAIN_SHAPE_H
|
||||
|
||||
#include <Box2D/Collision/Shapes/b2Shape.h>
|
||||
|
||||
class b2EdgeShape;
|
||||
|
||||
/// A chain shape is a free form sequence of line segments.
|
||||
/// The chain has two-sided collision, so you can use inside and outside collision.
|
||||
/// Therefore, you may use any winding order.
|
||||
/// Since there may be many vertices, they are allocated using b2Alloc.
|
||||
/// Connectivity information is used to create smooth collisions.
|
||||
/// WARNING: The chain will not collide properly if there are self-intersections.
|
||||
class BOX2D_API b2ChainShape : public b2Shape
|
||||
{
|
||||
public:
|
||||
b2ChainShape();
|
||||
|
||||
/// The destructor frees the vertices using b2Free.
|
||||
~b2ChainShape();
|
||||
|
||||
/// Create a loop. This automatically adjusts connectivity.
|
||||
/// @param vertices an array of vertices, these are copied
|
||||
/// @param count the vertex count
|
||||
void CreateLoop(const b2Vec2* vertices, int32 count);
|
||||
|
||||
/// Create a chain with isolated end vertices.
|
||||
/// @param vertices an array of vertices, these are copied
|
||||
/// @param count the vertex count
|
||||
void CreateChain(const b2Vec2* vertices, int32 count);
|
||||
|
||||
/// Establish connectivity to a vertex that precedes the first vertex.
|
||||
/// Don't call this for loops.
|
||||
void SetPrevVertex(const b2Vec2& prevVertex);
|
||||
|
||||
/// Establish connectivity to a vertex that follows the last vertex.
|
||||
/// Don't call this for loops.
|
||||
void SetNextVertex(const b2Vec2& nextVertex);
|
||||
|
||||
/// Implement b2Shape. Vertices are cloned using b2Alloc.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
|
||||
/// Get a child edge.
|
||||
void GetChildEdge(b2EdgeShape* edge, int32 index) const;
|
||||
|
||||
/// This always return false.
|
||||
/// @see b2Shape::TestPoint
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// Chains have zero mass.
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
|
||||
/// The vertices. Owned by this class.
|
||||
b2Vec2* m_vertices;
|
||||
|
||||
/// The vertex count.
|
||||
int32 m_count;
|
||||
|
||||
b2Vec2 m_prevVertex, m_nextVertex;
|
||||
bool m_hasPrevVertex, m_hasNextVertex;
|
||||
};
|
||||
|
||||
inline b2ChainShape::b2ChainShape()
|
||||
{
|
||||
m_type = e_chain;
|
||||
m_radius = b2_polygonRadius;
|
||||
m_vertices = NULL;
|
||||
m_count = 0;
|
||||
m_hasPrevVertex = false;
|
||||
m_hasNextVertex = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
91
Lib/Include/Box2D/Collision/Shapes/b2CircleShape.h
Normal file
91
Lib/Include/Box2D/Collision/Shapes/b2CircleShape.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_CIRCLE_SHAPE_H
|
||||
#define B2_CIRCLE_SHAPE_H
|
||||
|
||||
#include <Box2D/Collision/Shapes/b2Shape.h>
|
||||
|
||||
/// A circle shape.
|
||||
class BOX2D_API b2CircleShape : public b2Shape
|
||||
{
|
||||
public:
|
||||
b2CircleShape();
|
||||
|
||||
/// Implement b2Shape.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
|
||||
/// Implement b2Shape.
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
|
||||
/// Get the supporting vertex index in the given direction.
|
||||
int32 GetSupport(const b2Vec2& d) const;
|
||||
|
||||
/// Get the supporting vertex in the given direction.
|
||||
const b2Vec2& GetSupportVertex(const b2Vec2& d) const;
|
||||
|
||||
/// Get the vertex count.
|
||||
int32 GetVertexCount() const { return 1; }
|
||||
|
||||
/// Get a vertex by index. Used by b2Distance.
|
||||
const b2Vec2& GetVertex(int32 index) const;
|
||||
|
||||
/// Position
|
||||
b2Vec2 m_p;
|
||||
};
|
||||
|
||||
inline b2CircleShape::b2CircleShape()
|
||||
{
|
||||
m_type = e_circle;
|
||||
m_radius = 0.0f;
|
||||
m_p.SetZero();
|
||||
}
|
||||
|
||||
inline int32 b2CircleShape::GetSupport(const b2Vec2 &d) const
|
||||
{
|
||||
B2_NOT_USED(d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2CircleShape::GetSupportVertex(const b2Vec2 &d) const
|
||||
{
|
||||
B2_NOT_USED(d);
|
||||
return m_p;
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2CircleShape::GetVertex(int32 index) const
|
||||
{
|
||||
B2_NOT_USED(index);
|
||||
b2Assert(index == 0);
|
||||
return m_p;
|
||||
}
|
||||
|
||||
#endif
|
||||
74
Lib/Include/Box2D/Collision/Shapes/b2EdgeShape.h
Normal file
74
Lib/Include/Box2D/Collision/Shapes/b2EdgeShape.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_EDGE_SHAPE_H
|
||||
#define B2_EDGE_SHAPE_H
|
||||
|
||||
#include <Box2D/Collision/Shapes/b2Shape.h>
|
||||
|
||||
/// A line segment (edge) shape. These can be connected in chains or loops
|
||||
/// to other edge shapes. The connectivity information is used to ensure
|
||||
/// correct contact normals.
|
||||
class BOX2D_API b2EdgeShape : public b2Shape
|
||||
{
|
||||
public:
|
||||
b2EdgeShape();
|
||||
|
||||
/// Set this as an isolated edge.
|
||||
void Set(const b2Vec2& v1, const b2Vec2& v2);
|
||||
|
||||
/// Implement b2Shape.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
|
||||
/// @see b2Shape::TestPoint
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
|
||||
/// These are the edge vertices
|
||||
b2Vec2 m_vertex1, m_vertex2;
|
||||
|
||||
/// Optional adjacent vertices. These are used for smooth collision.
|
||||
b2Vec2 m_vertex0, m_vertex3;
|
||||
bool m_hasVertex0, m_hasVertex3;
|
||||
};
|
||||
|
||||
inline b2EdgeShape::b2EdgeShape()
|
||||
{
|
||||
m_type = e_edge;
|
||||
m_radius = b2_polygonRadius;
|
||||
m_vertex0.x = 0.0f;
|
||||
m_vertex0.y = 0.0f;
|
||||
m_vertex3.x = 0.0f;
|
||||
m_vertex3.y = 0.0f;
|
||||
m_hasVertex0 = false;
|
||||
m_hasVertex3 = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
101
Lib/Include/Box2D/Collision/Shapes/b2PolygonShape.h
Normal file
101
Lib/Include/Box2D/Collision/Shapes/b2PolygonShape.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_POLYGON_SHAPE_H
|
||||
#define B2_POLYGON_SHAPE_H
|
||||
|
||||
#include <Box2D/Collision/Shapes/b2Shape.h>
|
||||
|
||||
/// A convex polygon. It is assumed that the interior of the polygon is to
|
||||
/// the left of each edge.
|
||||
/// Polygons have a maximum number of vertices equal to b2_maxPolygonVertices.
|
||||
/// In most cases you should not need many vertices for a convex polygon.
|
||||
class BOX2D_API b2PolygonShape : public b2Shape
|
||||
{
|
||||
public:
|
||||
b2PolygonShape();
|
||||
|
||||
/// Implement b2Shape.
|
||||
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
||||
|
||||
/// @see b2Shape::GetChildCount
|
||||
int32 GetChildCount() const;
|
||||
|
||||
/// Create a convex hull from the given array of local points.
|
||||
/// The count must be in the range [3, b2_maxPolygonVertices].
|
||||
/// @warning the points may be re-ordered, even if they form a convex polygon
|
||||
/// @warning collinear points are handled but not removed. Collinear points
|
||||
/// may lead to poor stacking behavior.
|
||||
void Set(const b2Vec2* points, int32 count);
|
||||
|
||||
/// Build vertices to represent an axis-aligned box centered on the local origin.
|
||||
/// @param hx the half-width.
|
||||
/// @param hy the half-height.
|
||||
void SetAsBox(float32 hx, float32 hy);
|
||||
|
||||
/// Build vertices to represent an oriented box.
|
||||
/// @param hx the half-width.
|
||||
/// @param hy the half-height.
|
||||
/// @param center the center of the box in local coordinates.
|
||||
/// @param angle the rotation of the box in local coordinates.
|
||||
void SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle);
|
||||
|
||||
/// @see b2Shape::TestPoint
|
||||
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
||||
|
||||
/// Implement b2Shape.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeAABB
|
||||
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
||||
|
||||
/// @see b2Shape::ComputeMass
|
||||
void ComputeMass(b2MassData* massData, float32 density) const;
|
||||
|
||||
/// Get the vertex count.
|
||||
int32 GetVertexCount() const { return m_count; }
|
||||
|
||||
/// Get a vertex by index.
|
||||
const b2Vec2& GetVertex(int32 index) const;
|
||||
|
||||
/// Validate convexity. This is a very time consuming operation.
|
||||
/// @returns true if valid
|
||||
bool Validate() const;
|
||||
|
||||
b2Vec2 m_centroid;
|
||||
b2Vec2 m_vertices[b2_maxPolygonVertices];
|
||||
b2Vec2 m_normals[b2_maxPolygonVertices];
|
||||
int32 m_count;
|
||||
};
|
||||
|
||||
inline b2PolygonShape::b2PolygonShape()
|
||||
{
|
||||
m_type = e_polygon;
|
||||
m_radius = b2_polygonRadius;
|
||||
m_count = 0;
|
||||
m_centroid.SetZero();
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2PolygonShape::GetVertex(int32 index) const
|
||||
{
|
||||
b2Assert(0 <= index && index < m_count);
|
||||
return m_vertices[index];
|
||||
}
|
||||
|
||||
#endif
|
||||
101
Lib/Include/Box2D/Collision/Shapes/b2Shape.h
Normal file
101
Lib/Include/Box2D/Collision/Shapes/b2Shape.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_SHAPE_H
|
||||
#define B2_SHAPE_H
|
||||
|
||||
#include <Box2D/Common/b2BlockAllocator.h>
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
#include <Box2D/Collision/b2Collision.h>
|
||||
|
||||
/// This holds the mass data computed for a shape.
|
||||
struct b2MassData
|
||||
{
|
||||
/// The mass of the shape, usually in kilograms.
|
||||
float32 mass;
|
||||
|
||||
/// The position of the shape's centroid relative to the shape's origin.
|
||||
b2Vec2 center;
|
||||
|
||||
/// The rotational inertia of the shape about the local origin.
|
||||
float32 I;
|
||||
};
|
||||
|
||||
/// A shape is used for collision detection. You can create a shape however you like.
|
||||
/// Shapes used for simulation in b2World are created automatically when a b2Fixture
|
||||
/// is created. Shapes may encapsulate a one or more child shapes.
|
||||
class BOX2D_API b2Shape
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
e_circle = 0,
|
||||
e_edge = 1,
|
||||
e_polygon = 2,
|
||||
e_chain = 3,
|
||||
e_typeCount = 4
|
||||
};
|
||||
|
||||
virtual ~b2Shape() {}
|
||||
|
||||
/// Clone the concrete shape using the provided allocator.
|
||||
virtual b2Shape* Clone(b2BlockAllocator* allocator) const = 0;
|
||||
|
||||
/// Get the type of this shape. You can use this to down cast to the concrete shape.
|
||||
/// @return the shape type.
|
||||
Type GetType() const;
|
||||
|
||||
/// Get the number of child primitives.
|
||||
virtual int32 GetChildCount() const = 0;
|
||||
|
||||
/// Test a point for containment in this shape. This only works for convex shapes.
|
||||
/// @param xf the shape world transform.
|
||||
/// @param p a point in world coordinates.
|
||||
virtual bool TestPoint(const b2Transform& xf, const b2Vec2& p) const = 0;
|
||||
|
||||
/// Cast a ray against a child shape.
|
||||
/// @param output the ray-cast results.
|
||||
/// @param input the ray-cast input parameters.
|
||||
/// @param transform the transform to be applied to the shape.
|
||||
/// @param childIndex the child shape index
|
||||
virtual bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
||||
const b2Transform& transform, int32 childIndex) const = 0;
|
||||
|
||||
/// Given a transform, compute the associated axis aligned bounding box for a child shape.
|
||||
/// @param aabb returns the axis aligned box.
|
||||
/// @param xf the world transform of the shape.
|
||||
/// @param childIndex the child shape
|
||||
virtual void ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const = 0;
|
||||
|
||||
/// Compute the mass properties of this shape using its dimensions and density.
|
||||
/// The inertia tensor is computed about the local origin.
|
||||
/// @param massData returns the mass data for this shape.
|
||||
/// @param density the density in kilograms per meter squared.
|
||||
virtual void ComputeMass(b2MassData* massData, float32 density) const = 0;
|
||||
|
||||
Type m_type;
|
||||
float32 m_radius;
|
||||
};
|
||||
|
||||
inline b2Shape::Type b2Shape::GetType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
#endif
|
||||
257
Lib/Include/Box2D/Collision/b2BroadPhase.h
Normal file
257
Lib/Include/Box2D/Collision/b2BroadPhase.h
Normal file
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_BROAD_PHASE_H
|
||||
#define B2_BROAD_PHASE_H
|
||||
|
||||
#include <Box2D/Common/b2Settings.h>
|
||||
#include <Box2D/Collision/b2Collision.h>
|
||||
#include <Box2D/Collision/b2DynamicTree.h>
|
||||
#include <algorithm>
|
||||
|
||||
struct b2Pair
|
||||
{
|
||||
int32 proxyIdA;
|
||||
int32 proxyIdB;
|
||||
};
|
||||
|
||||
/// The broad-phase is used for computing pairs and performing volume queries and ray casts.
|
||||
/// This broad-phase does not persist pairs. Instead, this reports potentially new pairs.
|
||||
/// It is up to the client to consume the new pairs and to track subsequent overlap.
|
||||
class BOX2D_API b2BroadPhase
|
||||
{
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
e_nullProxy = -1
|
||||
};
|
||||
|
||||
b2BroadPhase();
|
||||
~b2BroadPhase();
|
||||
|
||||
/// Create a proxy with an initial AABB. Pairs are not reported until
|
||||
/// UpdatePairs is called.
|
||||
int32 CreateProxy(const b2AABB& aabb, void* userData);
|
||||
|
||||
/// Destroy a proxy. It is up to the client to remove any pairs.
|
||||
void DestroyProxy(int32 proxyId);
|
||||
|
||||
/// Call MoveProxy as many times as you like, then when you are done
|
||||
/// call UpdatePairs to finalized the proxy pairs (for your time step).
|
||||
void MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement);
|
||||
|
||||
/// Call to trigger a re-processing of it's pairs on the next call to UpdatePairs.
|
||||
void TouchProxy(int32 proxyId);
|
||||
|
||||
/// Get the fat AABB for a proxy.
|
||||
const b2AABB& GetFatAABB(int32 proxyId) const;
|
||||
|
||||
/// Get user data from a proxy. Returns NULL if the id is invalid.
|
||||
void* GetUserData(int32 proxyId) const;
|
||||
|
||||
/// Test overlap of fat AABBs.
|
||||
bool TestOverlap(int32 proxyIdA, int32 proxyIdB) const;
|
||||
|
||||
/// Get the number of proxies.
|
||||
int32 GetProxyCount() const;
|
||||
|
||||
/// Update the pairs. This results in pair callbacks. This can only add pairs.
|
||||
template <typename T>
|
||||
void UpdatePairs(T* callback);
|
||||
|
||||
/// Query an AABB for overlapping proxies. The callback class
|
||||
/// is called for each proxy that overlaps the supplied AABB.
|
||||
template <typename T>
|
||||
void Query(T* callback, const b2AABB& aabb) const;
|
||||
|
||||
/// Ray-cast against the proxies in the tree. This relies on the callback
|
||||
/// to perform a exact ray-cast in the case were the proxy contains a shape.
|
||||
/// The callback also performs the any collision filtering. This has performance
|
||||
/// roughly equal to k * log(n), where k is the number of collisions and n is the
|
||||
/// number of proxies in the tree.
|
||||
/// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
|
||||
/// @param callback a callback class that is called for each proxy that is hit by the ray.
|
||||
template <typename T>
|
||||
void RayCast(T* callback, const b2RayCastInput& input) const;
|
||||
|
||||
/// Get the height of the embedded tree.
|
||||
int32 GetTreeHeight() const;
|
||||
|
||||
/// Get the balance of the embedded tree.
|
||||
int32 GetTreeBalance() const;
|
||||
|
||||
/// Get the quality metric of the embedded tree.
|
||||
float32 GetTreeQuality() const;
|
||||
|
||||
/// Shift the world origin. Useful for large worlds.
|
||||
/// The shift formula is: position -= newOrigin
|
||||
/// @param newOrigin the new origin with respect to the old origin
|
||||
void ShiftOrigin(const b2Vec2& newOrigin);
|
||||
|
||||
private:
|
||||
|
||||
friend class b2DynamicTree;
|
||||
|
||||
void BufferMove(int32 proxyId);
|
||||
void UnBufferMove(int32 proxyId);
|
||||
|
||||
bool QueryCallback(int32 proxyId);
|
||||
|
||||
b2DynamicTree m_tree;
|
||||
|
||||
int32 m_proxyCount;
|
||||
|
||||
int32* m_moveBuffer;
|
||||
int32 m_moveCapacity;
|
||||
int32 m_moveCount;
|
||||
|
||||
b2Pair* m_pairBuffer;
|
||||
int32 m_pairCapacity;
|
||||
int32 m_pairCount;
|
||||
|
||||
int32 m_queryProxyId;
|
||||
};
|
||||
|
||||
/// This is used to sort pairs.
|
||||
inline bool b2PairLessThan(const b2Pair& pair1, const b2Pair& pair2)
|
||||
{
|
||||
if (pair1.proxyIdA < pair2.proxyIdA)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pair1.proxyIdA == pair2.proxyIdA)
|
||||
{
|
||||
return pair1.proxyIdB < pair2.proxyIdB;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void* b2BroadPhase::GetUserData(int32 proxyId) const
|
||||
{
|
||||
return m_tree.GetUserData(proxyId);
|
||||
}
|
||||
|
||||
inline bool b2BroadPhase::TestOverlap(int32 proxyIdA, int32 proxyIdB) const
|
||||
{
|
||||
const b2AABB& aabbA = m_tree.GetFatAABB(proxyIdA);
|
||||
const b2AABB& aabbB = m_tree.GetFatAABB(proxyIdB);
|
||||
return b2TestOverlap(aabbA, aabbB);
|
||||
}
|
||||
|
||||
inline const b2AABB& b2BroadPhase::GetFatAABB(int32 proxyId) const
|
||||
{
|
||||
return m_tree.GetFatAABB(proxyId);
|
||||
}
|
||||
|
||||
inline int32 b2BroadPhase::GetProxyCount() const
|
||||
{
|
||||
return m_proxyCount;
|
||||
}
|
||||
|
||||
inline int32 b2BroadPhase::GetTreeHeight() const
|
||||
{
|
||||
return m_tree.GetHeight();
|
||||
}
|
||||
|
||||
inline int32 b2BroadPhase::GetTreeBalance() const
|
||||
{
|
||||
return m_tree.GetMaxBalance();
|
||||
}
|
||||
|
||||
inline float32 b2BroadPhase::GetTreeQuality() const
|
||||
{
|
||||
return m_tree.GetAreaRatio();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void b2BroadPhase::UpdatePairs(T* callback)
|
||||
{
|
||||
// Reset pair buffer
|
||||
m_pairCount = 0;
|
||||
|
||||
// Perform tree queries for all moving proxies.
|
||||
for (int32 i = 0; i < m_moveCount; ++i)
|
||||
{
|
||||
m_queryProxyId = m_moveBuffer[i];
|
||||
if (m_queryProxyId == e_nullProxy)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// We have to query the tree with the fat AABB so that
|
||||
// we don't fail to create a pair that may touch later.
|
||||
const b2AABB& fatAABB = m_tree.GetFatAABB(m_queryProxyId);
|
||||
|
||||
// Query tree, create pairs and add them pair buffer.
|
||||
m_tree.Query(this, fatAABB);
|
||||
}
|
||||
|
||||
// Reset move buffer
|
||||
m_moveCount = 0;
|
||||
|
||||
// Sort the pair buffer to expose duplicates.
|
||||
std::sort(m_pairBuffer, m_pairBuffer + m_pairCount, b2PairLessThan);
|
||||
|
||||
// Send the pairs back to the client.
|
||||
int32 i = 0;
|
||||
while (i < m_pairCount)
|
||||
{
|
||||
b2Pair* primaryPair = m_pairBuffer + i;
|
||||
void* userDataA = m_tree.GetUserData(primaryPair->proxyIdA);
|
||||
void* userDataB = m_tree.GetUserData(primaryPair->proxyIdB);
|
||||
|
||||
callback->AddPair(userDataA, userDataB);
|
||||
++i;
|
||||
|
||||
// Skip any duplicate pairs.
|
||||
while (i < m_pairCount)
|
||||
{
|
||||
b2Pair* pair = m_pairBuffer + i;
|
||||
if (pair->proxyIdA != primaryPair->proxyIdA || pair->proxyIdB != primaryPair->proxyIdB)
|
||||
{
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to keep the tree balanced.
|
||||
//m_tree.Rebalance(4);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void b2BroadPhase::Query(T* callback, const b2AABB& aabb) const
|
||||
{
|
||||
m_tree.Query(callback, aabb);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void b2BroadPhase::RayCast(T* callback, const b2RayCastInput& input) const
|
||||
{
|
||||
m_tree.RayCast(callback, input);
|
||||
}
|
||||
|
||||
inline void b2BroadPhase::ShiftOrigin(const b2Vec2& newOrigin)
|
||||
{
|
||||
m_tree.ShiftOrigin(newOrigin);
|
||||
}
|
||||
|
||||
#endif
|
||||
277
Lib/Include/Box2D/Collision/b2Collision.h
Normal file
277
Lib/Include/Box2D/Collision/b2Collision.h
Normal file
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_COLLISION_H
|
||||
#define B2_COLLISION_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
#include <limits.h>
|
||||
|
||||
/// @file
|
||||
/// Structures and functions used for computing contact points, distance
|
||||
/// queries, and TOI queries.
|
||||
|
||||
class b2Shape;
|
||||
class b2CircleShape;
|
||||
class b2EdgeShape;
|
||||
class b2PolygonShape;
|
||||
|
||||
const uint8 b2_nullFeature = UCHAR_MAX;
|
||||
|
||||
/// The features that intersect to form the contact point
|
||||
/// This must be 4 bytes or less.
|
||||
struct b2ContactFeature
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
e_vertex = 0,
|
||||
e_face = 1
|
||||
};
|
||||
|
||||
uint8 indexA; ///< Feature index on shapeA
|
||||
uint8 indexB; ///< Feature index on shapeB
|
||||
uint8 typeA; ///< The feature type on shapeA
|
||||
uint8 typeB; ///< The feature type on shapeB
|
||||
};
|
||||
|
||||
/// Contact ids to facilitate warm starting.
|
||||
union b2ContactID
|
||||
{
|
||||
b2ContactFeature cf;
|
||||
uint32 key; ///< Used to quickly compare contact ids.
|
||||
};
|
||||
|
||||
/// A manifold point is a contact point belonging to a contact
|
||||
/// manifold. It holds details related to the geometry and dynamics
|
||||
/// of the contact points.
|
||||
/// The local point usage depends on the manifold type:
|
||||
/// -e_circles: the local center of circleB
|
||||
/// -e_faceA: the local center of cirlceB or the clip point of polygonB
|
||||
/// -e_faceB: the clip point of polygonA
|
||||
/// This structure is stored across time steps, so we keep it small.
|
||||
/// Note: the impulses are used for internal caching and may not
|
||||
/// provide reliable contact forces, especially for high speed collisions.
|
||||
struct b2ManifoldPoint
|
||||
{
|
||||
b2Vec2 localPoint; ///< usage depends on manifold type
|
||||
float32 normalImpulse; ///< the non-penetration impulse
|
||||
float32 tangentImpulse; ///< the friction impulse
|
||||
b2ContactID id; ///< uniquely identifies a contact point between two shapes
|
||||
};
|
||||
|
||||
/// A manifold for two touching convex shapes.
|
||||
/// Box2D supports multiple types of contact:
|
||||
/// - clip point versus plane with radius
|
||||
/// - point versus point with radius (circles)
|
||||
/// The local point usage depends on the manifold type:
|
||||
/// -e_circles: the local center of circleA
|
||||
/// -e_faceA: the center of faceA
|
||||
/// -e_faceB: the center of faceB
|
||||
/// Similarly the local normal usage:
|
||||
/// -e_circles: not used
|
||||
/// -e_faceA: the normal on polygonA
|
||||
/// -e_faceB: the normal on polygonB
|
||||
/// We store contacts in this way so that position correction can
|
||||
/// account for movement, which is critical for continuous physics.
|
||||
/// All contact scenarios must be expressed in one of these types.
|
||||
/// This structure is stored across time steps, so we keep it small.
|
||||
struct b2Manifold
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
e_circles,
|
||||
e_faceA,
|
||||
e_faceB
|
||||
};
|
||||
|
||||
b2ManifoldPoint points[b2_maxManifoldPoints]; ///< the points of contact
|
||||
b2Vec2 localNormal; ///< not use for Type::e_points
|
||||
b2Vec2 localPoint; ///< usage depends on manifold type
|
||||
Type type;
|
||||
int32 pointCount; ///< the number of manifold points
|
||||
};
|
||||
|
||||
/// This is used to compute the current state of a contact manifold.
|
||||
struct BOX2D_API b2WorldManifold
|
||||
{
|
||||
/// Evaluate the manifold with supplied transforms. This assumes
|
||||
/// modest motion from the original state. This does not change the
|
||||
/// point count, impulses, etc. The radii must come from the shapes
|
||||
/// that generated the manifold.
|
||||
void Initialize(const b2Manifold* manifold,
|
||||
const b2Transform& xfA, float32 radiusA,
|
||||
const b2Transform& xfB, float32 radiusB);
|
||||
|
||||
b2Vec2 normal; ///< world vector pointing from A to B
|
||||
b2Vec2 points[b2_maxManifoldPoints]; ///< world contact point (point of intersection)
|
||||
float32 separations[b2_maxManifoldPoints]; ///< a negative value indicates overlap, in meters
|
||||
};
|
||||
|
||||
/// This is used for determining the state of contact points.
|
||||
enum b2PointState
|
||||
{
|
||||
b2_nullState, ///< point does not exist
|
||||
b2_addState, ///< point was added in the update
|
||||
b2_persistState, ///< point persisted across the update
|
||||
b2_removeState ///< point was removed in the update
|
||||
};
|
||||
|
||||
/// Compute the point states given two manifolds. The states pertain to the transition from manifold1
|
||||
/// to manifold2. So state1 is either persist or remove while state2 is either add or persist.
|
||||
BOX2D_API void b2GetPointStates(b2PointState state1[b2_maxManifoldPoints], b2PointState state2[b2_maxManifoldPoints],
|
||||
const b2Manifold* manifold1, const b2Manifold* manifold2);
|
||||
|
||||
/// Used for computing contact manifolds.
|
||||
struct b2ClipVertex
|
||||
{
|
||||
b2Vec2 v;
|
||||
b2ContactID id;
|
||||
};
|
||||
|
||||
/// Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
|
||||
struct b2RayCastInput
|
||||
{
|
||||
b2Vec2 p1, p2;
|
||||
float32 maxFraction;
|
||||
};
|
||||
|
||||
/// Ray-cast output data. The ray hits at p1 + fraction * (p2 - p1), where p1 and p2
|
||||
/// come from b2RayCastInput.
|
||||
struct b2RayCastOutput
|
||||
{
|
||||
b2Vec2 normal;
|
||||
float32 fraction;
|
||||
};
|
||||
|
||||
/// An axis aligned bounding box.
|
||||
struct BOX2D_API b2AABB
|
||||
{
|
||||
/// Verify that the bounds are sorted.
|
||||
bool IsValid() const;
|
||||
|
||||
/// Get the center of the AABB.
|
||||
b2Vec2 GetCenter() const
|
||||
{
|
||||
return 0.5f * (lowerBound + upperBound);
|
||||
}
|
||||
|
||||
/// Get the extents of the AABB (half-widths).
|
||||
b2Vec2 GetExtents() const
|
||||
{
|
||||
return 0.5f * (upperBound - lowerBound);
|
||||
}
|
||||
|
||||
/// Get the perimeter length
|
||||
float32 GetPerimeter() const
|
||||
{
|
||||
float32 wx = upperBound.x - lowerBound.x;
|
||||
float32 wy = upperBound.y - lowerBound.y;
|
||||
return 2.0f * (wx + wy);
|
||||
}
|
||||
|
||||
/// Combine an AABB into this one.
|
||||
void Combine(const b2AABB& aabb)
|
||||
{
|
||||
lowerBound = b2Min(lowerBound, aabb.lowerBound);
|
||||
upperBound = b2Max(upperBound, aabb.upperBound);
|
||||
}
|
||||
|
||||
/// Combine two AABBs into this one.
|
||||
void Combine(const b2AABB& aabb1, const b2AABB& aabb2)
|
||||
{
|
||||
lowerBound = b2Min(aabb1.lowerBound, aabb2.lowerBound);
|
||||
upperBound = b2Max(aabb1.upperBound, aabb2.upperBound);
|
||||
}
|
||||
|
||||
/// Does this aabb contain the provided AABB.
|
||||
bool Contains(const b2AABB& aabb) const
|
||||
{
|
||||
bool result = true;
|
||||
result = result && lowerBound.x <= aabb.lowerBound.x;
|
||||
result = result && lowerBound.y <= aabb.lowerBound.y;
|
||||
result = result && aabb.upperBound.x <= upperBound.x;
|
||||
result = result && aabb.upperBound.y <= upperBound.y;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const;
|
||||
|
||||
b2Vec2 lowerBound; ///< the lower vertex
|
||||
b2Vec2 upperBound; ///< the upper vertex
|
||||
};
|
||||
|
||||
/// Compute the collision manifold between two circles.
|
||||
BOX2D_API void b2CollideCircles(b2Manifold* manifold,
|
||||
const b2CircleShape* circleA, const b2Transform& xfA,
|
||||
const b2CircleShape* circleB, const b2Transform& xfB);
|
||||
|
||||
/// Compute the collision manifold between a polygon and a circle.
|
||||
BOX2D_API void b2CollidePolygonAndCircle(b2Manifold* manifold,
|
||||
const b2PolygonShape* polygonA, const b2Transform& xfA,
|
||||
const b2CircleShape* circleB, const b2Transform& xfB);
|
||||
|
||||
/// Compute the collision manifold between two polygons.
|
||||
BOX2D_API void b2CollidePolygons(b2Manifold* manifold,
|
||||
const b2PolygonShape* polygonA, const b2Transform& xfA,
|
||||
const b2PolygonShape* polygonB, const b2Transform& xfB);
|
||||
|
||||
/// Compute the collision manifold between an edge and a circle.
|
||||
BOX2D_API void b2CollideEdgeAndCircle(b2Manifold* manifold,
|
||||
const b2EdgeShape* polygonA, const b2Transform& xfA,
|
||||
const b2CircleShape* circleB, const b2Transform& xfB);
|
||||
|
||||
/// Compute the collision manifold between an edge and a circle.
|
||||
BOX2D_API void b2CollideEdgeAndPolygon(b2Manifold* manifold,
|
||||
const b2EdgeShape* edgeA, const b2Transform& xfA,
|
||||
const b2PolygonShape* circleB, const b2Transform& xfB);
|
||||
|
||||
/// Clipping for contact manifolds.
|
||||
BOX2D_API int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2],
|
||||
const b2Vec2& normal, float32 offset, int32 vertexIndexA);
|
||||
|
||||
/// Determine if two generic shapes overlap.
|
||||
BOX2D_API bool b2TestOverlap( const b2Shape* shapeA, int32 indexA,
|
||||
const b2Shape* shapeB, int32 indexB,
|
||||
const b2Transform& xfA, const b2Transform& xfB);
|
||||
|
||||
// ---------------- Inline Functions ------------------------------------------
|
||||
|
||||
inline bool b2AABB::IsValid() const
|
||||
{
|
||||
b2Vec2 d = upperBound - lowerBound;
|
||||
bool valid = d.x >= 0.0f && d.y >= 0.0f;
|
||||
valid = valid && lowerBound.IsValid() && upperBound.IsValid();
|
||||
return valid;
|
||||
}
|
||||
|
||||
inline bool b2TestOverlap(const b2AABB& a, const b2AABB& b)
|
||||
{
|
||||
b2Vec2 d1, d2;
|
||||
d1 = b.lowerBound - a.upperBound;
|
||||
d2 = a.lowerBound - b.upperBound;
|
||||
|
||||
if (d1.x > 0.0f || d1.y > 0.0f)
|
||||
return false;
|
||||
|
||||
if (d2.x > 0.0f || d2.y > 0.0f)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
141
Lib/Include/Box2D/Collision/b2Distance.h
Normal file
141
Lib/Include/Box2D/Collision/b2Distance.h
Normal file
@@ -0,0 +1,141 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_DISTANCE_H
|
||||
#define B2_DISTANCE_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
|
||||
class b2Shape;
|
||||
|
||||
/// A distance proxy is used by the GJK algorithm.
|
||||
/// It encapsulates any shape.
|
||||
struct BOX2D_API b2DistanceProxy
|
||||
{
|
||||
b2DistanceProxy() : m_vertices(NULL), m_count(0), m_radius(0.0f) {}
|
||||
|
||||
/// Initialize the proxy using the given shape. The shape
|
||||
/// must remain in scope while the proxy is in use.
|
||||
void Set(const b2Shape* shape, int32 index);
|
||||
|
||||
/// Get the supporting vertex index in the given direction.
|
||||
int32 GetSupport(const b2Vec2& d) const;
|
||||
|
||||
/// Get the supporting vertex in the given direction.
|
||||
const b2Vec2& GetSupportVertex(const b2Vec2& d) const;
|
||||
|
||||
/// Get the vertex count.
|
||||
int32 GetVertexCount() const;
|
||||
|
||||
/// Get a vertex by index. Used by b2Distance.
|
||||
const b2Vec2& GetVertex(int32 index) const;
|
||||
|
||||
b2Vec2 m_buffer[2];
|
||||
const b2Vec2* m_vertices;
|
||||
int32 m_count;
|
||||
float32 m_radius;
|
||||
};
|
||||
|
||||
/// Used to warm start b2Distance.
|
||||
/// Set count to zero on first call.
|
||||
struct b2SimplexCache
|
||||
{
|
||||
float32 metric; ///< length or area
|
||||
uint16 count;
|
||||
uint8 indexA[3]; ///< vertices on shape A
|
||||
uint8 indexB[3]; ///< vertices on shape B
|
||||
};
|
||||
|
||||
/// Input for b2Distance.
|
||||
/// You have to option to use the shape radii
|
||||
/// in the computation. Even
|
||||
struct b2DistanceInput
|
||||
{
|
||||
b2DistanceProxy proxyA;
|
||||
b2DistanceProxy proxyB;
|
||||
b2Transform transformA;
|
||||
b2Transform transformB;
|
||||
bool useRadii;
|
||||
};
|
||||
|
||||
/// Output for b2Distance.
|
||||
struct b2DistanceOutput
|
||||
{
|
||||
b2Vec2 pointA; ///< closest point on shapeA
|
||||
b2Vec2 pointB; ///< closest point on shapeB
|
||||
float32 distance;
|
||||
int32 iterations; ///< number of GJK iterations used
|
||||
};
|
||||
|
||||
/// Compute the closest points between two shapes. Supports any combination of:
|
||||
/// b2CircleShape, b2PolygonShape, b2EdgeShape. The simplex cache is input/output.
|
||||
/// On the first call set b2SimplexCache.count to zero.
|
||||
void b2Distance(b2DistanceOutput* output,
|
||||
b2SimplexCache* cache,
|
||||
const b2DistanceInput* input);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline int32 b2DistanceProxy::GetVertexCount() const
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2DistanceProxy::GetVertex(int32 index) const
|
||||
{
|
||||
b2Assert(0 <= index && index < m_count);
|
||||
return m_vertices[index];
|
||||
}
|
||||
|
||||
inline int32 b2DistanceProxy::GetSupport(const b2Vec2& d) const
|
||||
{
|
||||
int32 bestIndex = 0;
|
||||
float32 bestValue = b2Dot(m_vertices[0], d);
|
||||
for (int32 i = 1; i < m_count; ++i)
|
||||
{
|
||||
float32 value = b2Dot(m_vertices[i], d);
|
||||
if (value > bestValue)
|
||||
{
|
||||
bestIndex = i;
|
||||
bestValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
return bestIndex;
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2DistanceProxy::GetSupportVertex(const b2Vec2& d) const
|
||||
{
|
||||
int32 bestIndex = 0;
|
||||
float32 bestValue = b2Dot(m_vertices[0], d);
|
||||
for (int32 i = 1; i < m_count; ++i)
|
||||
{
|
||||
float32 value = b2Dot(m_vertices[i], d);
|
||||
if (value > bestValue)
|
||||
{
|
||||
bestIndex = i;
|
||||
bestValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
return m_vertices[bestIndex];
|
||||
}
|
||||
|
||||
#endif
|
||||
289
Lib/Include/Box2D/Collision/b2DynamicTree.h
Normal file
289
Lib/Include/Box2D/Collision/b2DynamicTree.h
Normal file
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_DYNAMIC_TREE_H
|
||||
#define B2_DYNAMIC_TREE_H
|
||||
|
||||
#include <Box2D/Collision/b2Collision.h>
|
||||
#include <Box2D/Common/b2GrowableStack.h>
|
||||
|
||||
#define b2_nullNode (-1)
|
||||
|
||||
/// A node in the dynamic tree. The client does not interact with this directly.
|
||||
struct b2TreeNode
|
||||
{
|
||||
bool IsLeaf() const
|
||||
{
|
||||
return child1 == b2_nullNode;
|
||||
}
|
||||
|
||||
/// Enlarged AABB
|
||||
b2AABB aabb;
|
||||
|
||||
void* userData;
|
||||
|
||||
union
|
||||
{
|
||||
int32 parent;
|
||||
int32 next;
|
||||
};
|
||||
|
||||
int32 child1;
|
||||
int32 child2;
|
||||
|
||||
// leaf = 0, free node = -1
|
||||
int32 height;
|
||||
};
|
||||
|
||||
/// A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt.
|
||||
/// A dynamic tree arranges data in a binary tree to accelerate
|
||||
/// queries such as volume queries and ray casts. Leafs are proxies
|
||||
/// with an AABB. In the tree we expand the proxy AABB by b2_fatAABBFactor
|
||||
/// so that the proxy AABB is bigger than the client object. This allows the client
|
||||
/// object to move by small amounts without triggering a tree update.
|
||||
///
|
||||
/// Nodes are pooled and relocatable, so we use node indices rather than pointers.
|
||||
class BOX2D_API b2DynamicTree
|
||||
{
|
||||
public:
|
||||
/// Constructing the tree initializes the node pool.
|
||||
b2DynamicTree();
|
||||
|
||||
/// Destroy the tree, freeing the node pool.
|
||||
~b2DynamicTree();
|
||||
|
||||
/// Create a proxy. Provide a tight fitting AABB and a userData pointer.
|
||||
int32 CreateProxy(const b2AABB& aabb, void* userData);
|
||||
|
||||
/// Destroy a proxy. This asserts if the id is invalid.
|
||||
void DestroyProxy(int32 proxyId);
|
||||
|
||||
/// Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB,
|
||||
/// then the proxy is removed from the tree and re-inserted. Otherwise
|
||||
/// the function returns immediately.
|
||||
/// @return true if the proxy was re-inserted.
|
||||
bool MoveProxy(int32 proxyId, const b2AABB& aabb1, const b2Vec2& displacement);
|
||||
|
||||
/// Get proxy user data.
|
||||
/// @return the proxy user data or 0 if the id is invalid.
|
||||
void* GetUserData(int32 proxyId) const;
|
||||
|
||||
/// Get the fat AABB for a proxy.
|
||||
const b2AABB& GetFatAABB(int32 proxyId) const;
|
||||
|
||||
/// Query an AABB for overlapping proxies. The callback class
|
||||
/// is called for each proxy that overlaps the supplied AABB.
|
||||
template <typename T>
|
||||
void Query(T* callback, const b2AABB& aabb) const;
|
||||
|
||||
/// Ray-cast against the proxies in the tree. This relies on the callback
|
||||
/// to perform a exact ray-cast in the case were the proxy contains a shape.
|
||||
/// The callback also performs the any collision filtering. This has performance
|
||||
/// roughly equal to k * log(n), where k is the number of collisions and n is the
|
||||
/// number of proxies in the tree.
|
||||
/// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
|
||||
/// @param callback a callback class that is called for each proxy that is hit by the ray.
|
||||
template <typename T>
|
||||
void RayCast(T* callback, const b2RayCastInput& input) const;
|
||||
|
||||
/// Validate this tree. For testing.
|
||||
void Validate() const;
|
||||
|
||||
/// Compute the height of the binary tree in O(N) time. Should not be
|
||||
/// called often.
|
||||
int32 GetHeight() const;
|
||||
|
||||
/// Get the maximum balance of an node in the tree. The balance is the difference
|
||||
/// in height of the two children of a node.
|
||||
int32 GetMaxBalance() const;
|
||||
|
||||
/// Get the ratio of the sum of the node areas to the root area.
|
||||
float32 GetAreaRatio() const;
|
||||
|
||||
/// Build an optimal tree. Very expensive. For testing.
|
||||
void RebuildBottomUp();
|
||||
|
||||
/// Shift the world origin. Useful for large worlds.
|
||||
/// The shift formula is: position -= newOrigin
|
||||
/// @param newOrigin the new origin with respect to the old origin
|
||||
void ShiftOrigin(const b2Vec2& newOrigin);
|
||||
|
||||
private:
|
||||
|
||||
int32 AllocateNode();
|
||||
void FreeNode(int32 node);
|
||||
|
||||
void InsertLeaf(int32 node);
|
||||
void RemoveLeaf(int32 node);
|
||||
|
||||
int32 Balance(int32 index);
|
||||
|
||||
int32 ComputeHeight() const;
|
||||
int32 ComputeHeight(int32 nodeId) const;
|
||||
|
||||
void ValidateStructure(int32 index) const;
|
||||
void ValidateMetrics(int32 index) const;
|
||||
|
||||
|
||||
b2TreeNode* m_nodes;
|
||||
int32 m_root;
|
||||
int32 m_nodeCount;
|
||||
int32 m_nodeCapacity;
|
||||
|
||||
int32 m_freeList;
|
||||
|
||||
/// This is used to incrementally traverse the tree for re-balancing.
|
||||
uint32 m_path;
|
||||
|
||||
int32 m_insertionCount;
|
||||
};
|
||||
|
||||
inline void* b2DynamicTree::GetUserData(int32 proxyId) const
|
||||
{
|
||||
b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
|
||||
return m_nodes[proxyId].userData;
|
||||
}
|
||||
|
||||
inline const b2AABB& b2DynamicTree::GetFatAABB(int32 proxyId) const
|
||||
{
|
||||
b2Assert(0 <= proxyId && proxyId < m_nodeCapacity);
|
||||
return m_nodes[proxyId].aabb;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void b2DynamicTree::Query(T* callback, const b2AABB& aabb) const
|
||||
{
|
||||
b2GrowableStack<int32, 256> stack;
|
||||
stack.Push(m_root);
|
||||
|
||||
while (stack.GetCount() > 0)
|
||||
{
|
||||
int32 nodeId = stack.Pop();
|
||||
if (nodeId == b2_nullNode)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const b2TreeNode* node = m_nodes + nodeId;
|
||||
|
||||
if (b2TestOverlap(node->aabb, aabb))
|
||||
{
|
||||
if (node->IsLeaf())
|
||||
{
|
||||
bool proceed = callback->QueryCallback(nodeId);
|
||||
if (proceed == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.Push(node->child1);
|
||||
stack.Push(node->child2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void b2DynamicTree::RayCast(T* callback, const b2RayCastInput& input) const
|
||||
{
|
||||
b2Vec2 p1 = input.p1;
|
||||
b2Vec2 p2 = input.p2;
|
||||
b2Vec2 r = p2 - p1;
|
||||
b2Assert(r.LengthSquared() > 0.0f);
|
||||
r.Normalize();
|
||||
|
||||
// v is perpendicular to the segment.
|
||||
b2Vec2 v = b2Cross(1.0f, r);
|
||||
b2Vec2 abs_v = b2Abs(v);
|
||||
|
||||
// Separating axis for segment (Gino, p80).
|
||||
// |dot(v, p1 - c)| > dot(|v|, h)
|
||||
|
||||
float32 maxFraction = input.maxFraction;
|
||||
|
||||
// Build a bounding box for the segment.
|
||||
b2AABB segmentAABB;
|
||||
{
|
||||
b2Vec2 t = p1 + maxFraction * (p2 - p1);
|
||||
segmentAABB.lowerBound = b2Min(p1, t);
|
||||
segmentAABB.upperBound = b2Max(p1, t);
|
||||
}
|
||||
|
||||
b2GrowableStack<int32, 256> stack;
|
||||
stack.Push(m_root);
|
||||
|
||||
while (stack.GetCount() > 0)
|
||||
{
|
||||
int32 nodeId = stack.Pop();
|
||||
if (nodeId == b2_nullNode)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const b2TreeNode* node = m_nodes + nodeId;
|
||||
|
||||
if (b2TestOverlap(node->aabb, segmentAABB) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Separating axis for segment (Gino, p80).
|
||||
// |dot(v, p1 - c)| > dot(|v|, h)
|
||||
b2Vec2 c = node->aabb.GetCenter();
|
||||
b2Vec2 h = node->aabb.GetExtents();
|
||||
float32 separation = b2Abs(b2Dot(v, p1 - c)) - b2Dot(abs_v, h);
|
||||
if (separation > 0.0f)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node->IsLeaf())
|
||||
{
|
||||
b2RayCastInput subInput;
|
||||
subInput.p1 = input.p1;
|
||||
subInput.p2 = input.p2;
|
||||
subInput.maxFraction = maxFraction;
|
||||
|
||||
float32 value = callback->RayCastCallback(subInput, nodeId);
|
||||
|
||||
if (value == 0.0f)
|
||||
{
|
||||
// The client has terminated the ray cast.
|
||||
return;
|
||||
}
|
||||
|
||||
if (value > 0.0f)
|
||||
{
|
||||
// Update segment bounding box.
|
||||
maxFraction = value;
|
||||
b2Vec2 t = p1 + maxFraction * (p2 - p1);
|
||||
segmentAABB.lowerBound = b2Min(p1, t);
|
||||
segmentAABB.upperBound = b2Max(p1, t);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.Push(node->child1);
|
||||
stack.Push(node->child2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
58
Lib/Include/Box2D/Collision/b2TimeOfImpact.h
Normal file
58
Lib/Include/Box2D/Collision/b2TimeOfImpact.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_TIME_OF_IMPACT_H
|
||||
#define B2_TIME_OF_IMPACT_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
#include <Box2D/Collision/b2Distance.h>
|
||||
|
||||
/// Input parameters for b2TimeOfImpact
|
||||
struct b2TOIInput
|
||||
{
|
||||
b2DistanceProxy proxyA;
|
||||
b2DistanceProxy proxyB;
|
||||
b2Sweep sweepA;
|
||||
b2Sweep sweepB;
|
||||
float32 tMax; // defines sweep interval [0, tMax]
|
||||
};
|
||||
|
||||
// Output parameters for b2TimeOfImpact.
|
||||
struct b2TOIOutput
|
||||
{
|
||||
enum State
|
||||
{
|
||||
e_unknown,
|
||||
e_failed,
|
||||
e_overlapped,
|
||||
e_touching,
|
||||
e_separated
|
||||
};
|
||||
|
||||
State state;
|
||||
float32 t;
|
||||
};
|
||||
|
||||
/// Compute the upper bound on time before two shapes penetrate. Time is represented as
|
||||
/// a fraction between [0,tMax]. This uses a swept separating axis and may miss some intermediate,
|
||||
/// non-tunneling collision. If you change the time interval, you should call this function
|
||||
/// again.
|
||||
/// Note: use b2Distance to compute the contact point and normal at the time of impact.
|
||||
BOX2D_API void b2TimeOfImpact(b2TOIOutput* output, const b2TOIInput* input);
|
||||
|
||||
#endif
|
||||
62
Lib/Include/Box2D/Common/b2BlockAllocator.h
Normal file
62
Lib/Include/Box2D/Common/b2BlockAllocator.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_BLOCK_ALLOCATOR_H
|
||||
#define B2_BLOCK_ALLOCATOR_H
|
||||
|
||||
#include <Box2D/Common/b2Settings.h>
|
||||
|
||||
const int32 b2_chunkSize = 16 * 1024;
|
||||
const int32 b2_maxBlockSize = 640;
|
||||
const int32 b2_blockSizes = 14;
|
||||
const int32 b2_chunkArrayIncrement = 128;
|
||||
|
||||
struct b2Block;
|
||||
struct b2Chunk;
|
||||
|
||||
/// This is a small object allocator used for allocating small
|
||||
/// objects that persist for more than one time step.
|
||||
/// See: http://www.codeproject.com/useritems/Small_Block_Allocator.asp
|
||||
class BOX2D_API b2BlockAllocator
|
||||
{
|
||||
public:
|
||||
b2BlockAllocator();
|
||||
~b2BlockAllocator();
|
||||
|
||||
/// Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize.
|
||||
void* Allocate(int32 size);
|
||||
|
||||
/// Free memory. This will use b2Free if the size is larger than b2_maxBlockSize.
|
||||
void Free(void* p, int32 size);
|
||||
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
|
||||
b2Chunk* m_chunks;
|
||||
int32 m_chunkCount;
|
||||
int32 m_chunkSpace;
|
||||
|
||||
b2Block* m_freeLists[b2_blockSizes];
|
||||
|
||||
static int32 s_blockSizes[b2_blockSizes];
|
||||
static uint8 s_blockSizeLookup[b2_maxBlockSize + 1];
|
||||
static bool s_blockSizeLookupInitialized;
|
||||
};
|
||||
|
||||
#endif
|
||||
86
Lib/Include/Box2D/Common/b2Draw.h
Normal file
86
Lib/Include/Box2D/Common/b2Draw.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Erin Catto http://box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_DRAW_H
|
||||
#define B2_DRAW_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
|
||||
/// Color for debug drawing. Each value has the range [0,1].
|
||||
struct b2Color
|
||||
{
|
||||
b2Color() {}
|
||||
b2Color(float32 r, float32 g, float32 b) : r(r), g(g), b(b) {}
|
||||
void Set(float32 ri, float32 gi, float32 bi) { r = ri; g = gi; b = bi; }
|
||||
float32 r, g, b;
|
||||
};
|
||||
|
||||
/// Implement and register this class with a b2World to provide debug drawing of physics
|
||||
/// entities in your game.
|
||||
class BOX2D_API b2Draw
|
||||
{
|
||||
public:
|
||||
b2Draw();
|
||||
|
||||
virtual ~b2Draw() {}
|
||||
|
||||
enum
|
||||
{
|
||||
e_shapeBit = 0x0001, ///< draw shapes
|
||||
e_jointBit = 0x0002, ///< draw joint connections
|
||||
e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes
|
||||
e_pairBit = 0x0008, ///< draw broad-phase pairs
|
||||
e_centerOfMassBit = 0x0010 ///< draw center of mass frame
|
||||
};
|
||||
|
||||
/// Set the drawing flags.
|
||||
void SetFlags(uint32 flags);
|
||||
|
||||
/// Get the drawing flags.
|
||||
uint32 GetFlags() const;
|
||||
|
||||
/// Append flags to the current flags.
|
||||
void AppendFlags(uint32 flags);
|
||||
|
||||
/// Clear flags from the current flags.
|
||||
void ClearFlags(uint32 flags);
|
||||
|
||||
/// Draw a closed polygon provided in CCW order.
|
||||
virtual void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;
|
||||
|
||||
/// Draw a solid closed polygon provided in CCW order.
|
||||
virtual void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;
|
||||
|
||||
/// Draw a circle.
|
||||
virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) = 0;
|
||||
|
||||
/// Draw a solid circle.
|
||||
virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) = 0;
|
||||
|
||||
/// Draw a line segment.
|
||||
virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) = 0;
|
||||
|
||||
/// Draw a transform. Choose your own length scale.
|
||||
/// @param xf a transform.
|
||||
virtual void DrawTransform(const b2Transform& xf) = 0;
|
||||
|
||||
protected:
|
||||
uint32 m_drawFlags;
|
||||
};
|
||||
|
||||
#endif
|
||||
85
Lib/Include/Box2D/Common/b2GrowableStack.h
Normal file
85
Lib/Include/Box2D/Common/b2GrowableStack.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2010 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_GROWABLE_STACK_H
|
||||
#define B2_GROWABLE_STACK_H
|
||||
#include <Box2D/Common/b2Settings.h>
|
||||
#include <memory.h>
|
||||
|
||||
/// This is a growable LIFO stack with an initial capacity of N.
|
||||
/// If the stack size exceeds the initial capacity, the heap is used
|
||||
/// to increase the size of the stack.
|
||||
template <typename T, int32 N>
|
||||
class b2GrowableStack
|
||||
{
|
||||
public:
|
||||
b2GrowableStack()
|
||||
{
|
||||
m_stack = m_array;
|
||||
m_count = 0;
|
||||
m_capacity = N;
|
||||
}
|
||||
|
||||
~b2GrowableStack()
|
||||
{
|
||||
if (m_stack != m_array)
|
||||
{
|
||||
b2Free(m_stack);
|
||||
m_stack = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Push(const T& element)
|
||||
{
|
||||
if (m_count == m_capacity)
|
||||
{
|
||||
T* old = m_stack;
|
||||
m_capacity *= 2;
|
||||
m_stack = (T*)b2Alloc(m_capacity * sizeof(T));
|
||||
memcpy(m_stack, old, m_count * sizeof(T));
|
||||
if (old != m_array)
|
||||
{
|
||||
b2Free(old);
|
||||
}
|
||||
}
|
||||
|
||||
m_stack[m_count] = element;
|
||||
++m_count;
|
||||
}
|
||||
|
||||
T Pop()
|
||||
{
|
||||
b2Assert(m_count > 0);
|
||||
--m_count;
|
||||
return m_stack[m_count];
|
||||
}
|
||||
|
||||
int32 GetCount()
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
private:
|
||||
T* m_stack;
|
||||
T m_array[N];
|
||||
int32 m_count;
|
||||
int32 m_capacity;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
722
Lib/Include/Box2D/Common/b2Math.h
Normal file
722
Lib/Include/Box2D/Common/b2Math.h
Normal file
@@ -0,0 +1,722 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_MATH_H
|
||||
#define B2_MATH_H
|
||||
|
||||
#include <Box2D/Common/b2Settings.h>
|
||||
#include <math.h>
|
||||
#include <string.h> //memcpy()
|
||||
|
||||
/// This function is used to ensure that a floating point number is not a NaN or infinity.
|
||||
inline bool b2IsValid(float32 x)
|
||||
{
|
||||
int32 ix;
|
||||
memcpy(&ix, &x, sizeof(int32));
|
||||
return (ix & 0x7f800000) != 0x7f800000;
|
||||
}
|
||||
|
||||
/// This is a approximate yet fast inverse square-root.
|
||||
inline float32 b2InvSqrt(float32 x)
|
||||
{
|
||||
union
|
||||
{
|
||||
float32 x;
|
||||
int32 i;
|
||||
} convert;
|
||||
|
||||
convert.x = x;
|
||||
float32 xhalf = 0.5f * x;
|
||||
convert.i = 0x5f3759df - (convert.i >> 1);
|
||||
x = convert.x;
|
||||
x = x * (1.5f - xhalf * x * x);
|
||||
return x;
|
||||
}
|
||||
|
||||
#define b2Sqrt(x) sqrtf(x)
|
||||
#define b2Atan2(y, x) atan2f(y, x)
|
||||
|
||||
/// A 2D column vector.
|
||||
struct BOX2D_API b2Vec2
|
||||
{
|
||||
/// Default constructor does nothing (for performance).
|
||||
b2Vec2() {}
|
||||
|
||||
/// Construct using coordinates.
|
||||
b2Vec2(float32 x, float32 y) : x(x), y(y) {}
|
||||
|
||||
/// Set this vector to all zeros.
|
||||
void SetZero() { x = 0.0f; y = 0.0f; }
|
||||
|
||||
/// Set this vector to some specified coordinates.
|
||||
void Set(float32 x_, float32 y_) { x = x_; y = y_; }
|
||||
|
||||
/// Negate this vector.
|
||||
b2Vec2 operator -() const { b2Vec2 v; v.Set(-x, -y); return v; }
|
||||
|
||||
/// Read from and indexed element.
|
||||
float32 operator () (int32 i) const
|
||||
{
|
||||
return (&x)[i];
|
||||
}
|
||||
|
||||
/// Write to an indexed element.
|
||||
float32& operator () (int32 i)
|
||||
{
|
||||
return (&x)[i];
|
||||
}
|
||||
|
||||
/// Add a vector to this vector.
|
||||
void operator += (const b2Vec2& v)
|
||||
{
|
||||
x += v.x; y += v.y;
|
||||
}
|
||||
|
||||
/// Subtract a vector from this vector.
|
||||
void operator -= (const b2Vec2& v)
|
||||
{
|
||||
x -= v.x; y -= v.y;
|
||||
}
|
||||
|
||||
/// Multiply this vector by a scalar.
|
||||
void operator *= (float32 a)
|
||||
{
|
||||
x *= a; y *= a;
|
||||
}
|
||||
|
||||
/// Get the length of this vector (the norm).
|
||||
float32 Length() const
|
||||
{
|
||||
return b2Sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
/// Get the length squared. For performance, use this instead of
|
||||
/// b2Vec2::Length (if possible).
|
||||
float32 LengthSquared() const
|
||||
{
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
/// Convert this vector into a unit vector. Returns the length.
|
||||
float32 Normalize()
|
||||
{
|
||||
float32 length = Length();
|
||||
if (length < b2_epsilon)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
float32 invLength = 1.0f / length;
|
||||
x *= invLength;
|
||||
y *= invLength;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/// Does this vector contain finite coordinates?
|
||||
bool IsValid() const
|
||||
{
|
||||
return b2IsValid(x) && b2IsValid(y);
|
||||
}
|
||||
|
||||
/// Get the skew vector such that dot(skew_vec, other) == cross(vec, other)
|
||||
b2Vec2 Skew() const
|
||||
{
|
||||
return b2Vec2(-y, x);
|
||||
}
|
||||
|
||||
float32 x, y;
|
||||
};
|
||||
|
||||
/// A 2D column vector with 3 elements.
|
||||
struct BOX2D_API b2Vec3
|
||||
{
|
||||
/// Default constructor does nothing (for performance).
|
||||
b2Vec3() {}
|
||||
|
||||
/// Construct using coordinates.
|
||||
b2Vec3(float32 x, float32 y, float32 z) : x(x), y(y), z(z) {}
|
||||
|
||||
/// Set this vector to all zeros.
|
||||
void SetZero() { x = 0.0f; y = 0.0f; z = 0.0f; }
|
||||
|
||||
/// Set this vector to some specified coordinates.
|
||||
void Set(float32 x_, float32 y_, float32 z_) { x = x_; y = y_; z = z_; }
|
||||
|
||||
/// Negate this vector.
|
||||
b2Vec3 operator -() const { b2Vec3 v; v.Set(-x, -y, -z); return v; }
|
||||
|
||||
/// Add a vector to this vector.
|
||||
void operator += (const b2Vec3& v)
|
||||
{
|
||||
x += v.x; y += v.y; z += v.z;
|
||||
}
|
||||
|
||||
/// Subtract a vector from this vector.
|
||||
void operator -= (const b2Vec3& v)
|
||||
{
|
||||
x -= v.x; y -= v.y; z -= v.z;
|
||||
}
|
||||
|
||||
/// Multiply this vector by a scalar.
|
||||
void operator *= (float32 s)
|
||||
{
|
||||
x *= s; y *= s; z *= s;
|
||||
}
|
||||
|
||||
float32 x, y, z;
|
||||
};
|
||||
|
||||
/// A 2-by-2 matrix. Stored in column-major order.
|
||||
struct BOX2D_API b2Mat22
|
||||
{
|
||||
/// The default constructor does nothing (for performance).
|
||||
b2Mat22() {}
|
||||
|
||||
/// Construct this matrix using columns.
|
||||
b2Mat22(const b2Vec2& c1, const b2Vec2& c2)
|
||||
{
|
||||
ex = c1;
|
||||
ey = c2;
|
||||
}
|
||||
|
||||
/// Construct this matrix using scalars.
|
||||
b2Mat22(float32 a11, float32 a12, float32 a21, float32 a22)
|
||||
{
|
||||
ex.x = a11; ex.y = a21;
|
||||
ey.x = a12; ey.y = a22;
|
||||
}
|
||||
|
||||
/// Initialize this matrix using columns.
|
||||
void Set(const b2Vec2& c1, const b2Vec2& c2)
|
||||
{
|
||||
ex = c1;
|
||||
ey = c2;
|
||||
}
|
||||
|
||||
/// Set this to the identity matrix.
|
||||
void SetIdentity()
|
||||
{
|
||||
ex.x = 1.0f; ey.x = 0.0f;
|
||||
ex.y = 0.0f; ey.y = 1.0f;
|
||||
}
|
||||
|
||||
/// Set this matrix to all zeros.
|
||||
void SetZero()
|
||||
{
|
||||
ex.x = 0.0f; ey.x = 0.0f;
|
||||
ex.y = 0.0f; ey.y = 0.0f;
|
||||
}
|
||||
|
||||
b2Mat22 GetInverse() const
|
||||
{
|
||||
float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
|
||||
b2Mat22 B;
|
||||
float32 det = a * d - b * c;
|
||||
if (det != 0.0f)
|
||||
{
|
||||
det = 1.0f / det;
|
||||
}
|
||||
B.ex.x = det * d; B.ey.x = -det * b;
|
||||
B.ex.y = -det * c; B.ey.y = det * a;
|
||||
return B;
|
||||
}
|
||||
|
||||
/// Solve A * x = b, where b is a column vector. This is more efficient
|
||||
/// than computing the inverse in one-shot cases.
|
||||
b2Vec2 Solve(const b2Vec2& b) const
|
||||
{
|
||||
float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
|
||||
float32 det = a11 * a22 - a12 * a21;
|
||||
if (det != 0.0f)
|
||||
{
|
||||
det = 1.0f / det;
|
||||
}
|
||||
b2Vec2 x;
|
||||
x.x = det * (a22 * b.x - a12 * b.y);
|
||||
x.y = det * (a11 * b.y - a21 * b.x);
|
||||
return x;
|
||||
}
|
||||
|
||||
b2Vec2 ex, ey;
|
||||
};
|
||||
|
||||
/// A 3-by-3 matrix. Stored in column-major order.
|
||||
struct BOX2D_API b2Mat33
|
||||
{
|
||||
/// The default constructor does nothing (for performance).
|
||||
b2Mat33() {}
|
||||
|
||||
/// Construct this matrix using columns.
|
||||
b2Mat33(const b2Vec3& c1, const b2Vec3& c2, const b2Vec3& c3)
|
||||
{
|
||||
ex = c1;
|
||||
ey = c2;
|
||||
ez = c3;
|
||||
}
|
||||
|
||||
/// Set this matrix to all zeros.
|
||||
void SetZero()
|
||||
{
|
||||
ex.SetZero();
|
||||
ey.SetZero();
|
||||
ez.SetZero();
|
||||
}
|
||||
|
||||
/// Solve A * x = b, where b is a column vector. This is more efficient
|
||||
/// than computing the inverse in one-shot cases.
|
||||
b2Vec3 Solve33(const b2Vec3& b) const;
|
||||
|
||||
/// Solve A * x = b, where b is a column vector. This is more efficient
|
||||
/// than computing the inverse in one-shot cases. Solve only the upper
|
||||
/// 2-by-2 matrix equation.
|
||||
b2Vec2 Solve22(const b2Vec2& b) const;
|
||||
|
||||
/// Get the inverse of this matrix as a 2-by-2.
|
||||
/// Returns the zero matrix if singular.
|
||||
void GetInverse22(b2Mat33* M) const;
|
||||
|
||||
/// Get the symmetric inverse of this matrix as a 3-by-3.
|
||||
/// Returns the zero matrix if singular.
|
||||
void GetSymInverse33(b2Mat33* M) const;
|
||||
|
||||
b2Vec3 ex, ey, ez;
|
||||
};
|
||||
|
||||
/// Rotation
|
||||
struct BOX2D_API b2Rot
|
||||
{
|
||||
b2Rot() {}
|
||||
|
||||
/// Initialize from an angle in radians
|
||||
explicit b2Rot(float32 angle)
|
||||
{
|
||||
/// TODO_ERIN optimize
|
||||
s = sinf(angle);
|
||||
c = cosf(angle);
|
||||
}
|
||||
|
||||
/// Set using an angle in radians.
|
||||
void Set(float32 angle)
|
||||
{
|
||||
/// TODO_ERIN optimize
|
||||
s = sinf(angle);
|
||||
c = cosf(angle);
|
||||
}
|
||||
|
||||
/// Set to the identity rotation
|
||||
void SetIdentity()
|
||||
{
|
||||
s = 0.0f;
|
||||
c = 1.0f;
|
||||
}
|
||||
|
||||
/// Get the angle in radians
|
||||
float32 GetAngle() const
|
||||
{
|
||||
return b2Atan2(s, c);
|
||||
}
|
||||
|
||||
/// Get the x-axis
|
||||
b2Vec2 GetXAxis() const
|
||||
{
|
||||
return b2Vec2(c, s);
|
||||
}
|
||||
|
||||
/// Get the u-axis
|
||||
b2Vec2 GetYAxis() const
|
||||
{
|
||||
return b2Vec2(-s, c);
|
||||
}
|
||||
|
||||
/// Sine and cosine
|
||||
float32 s, c;
|
||||
};
|
||||
|
||||
/// A transform contains translation and rotation. It is used to represent
|
||||
/// the position and orientation of rigid frames.
|
||||
struct BOX2D_API b2Transform
|
||||
{
|
||||
/// The default constructor does nothing.
|
||||
b2Transform() {}
|
||||
|
||||
/// Initialize using a position vector and a rotation.
|
||||
b2Transform(const b2Vec2& position, const b2Rot& rotation) : p(position), q(rotation) {}
|
||||
|
||||
/// Set this to the identity transform.
|
||||
void SetIdentity()
|
||||
{
|
||||
p.SetZero();
|
||||
q.SetIdentity();
|
||||
}
|
||||
|
||||
/// Set this based on the position and angle.
|
||||
void Set(const b2Vec2& position, float32 angle)
|
||||
{
|
||||
p = position;
|
||||
q.Set(angle);
|
||||
}
|
||||
|
||||
b2Vec2 p;
|
||||
b2Rot q;
|
||||
};
|
||||
|
||||
/// This describes the motion of a body/shape for TOI computation.
|
||||
/// Shapes are defined with respect to the body origin, which may
|
||||
/// no coincide with the center of mass. However, to support dynamics
|
||||
/// we must interpolate the center of mass position.
|
||||
struct BOX2D_API b2Sweep
|
||||
{
|
||||
/// Get the interpolated transform at a specific time.
|
||||
/// @param beta is a factor in [0,1], where 0 indicates alpha0.
|
||||
void GetTransform(b2Transform* xfb, float32 beta) const;
|
||||
|
||||
/// Advance the sweep forward, yielding a new initial state.
|
||||
/// @param alpha the new initial time.
|
||||
void Advance(float32 alpha);
|
||||
|
||||
/// Normalize the angles.
|
||||
void Normalize();
|
||||
|
||||
b2Vec2 localCenter; ///< local center of mass position
|
||||
b2Vec2 c0, c; ///< center world positions
|
||||
float32 a0, a; ///< world angles
|
||||
|
||||
/// Fraction of the current time step in the range [0,1]
|
||||
/// c0 and a0 are the positions at alpha0.
|
||||
float32 alpha0;
|
||||
};
|
||||
|
||||
/// Useful constant
|
||||
BOX2D_API extern const b2Vec2 b2Vec2_zero;
|
||||
|
||||
/// Perform the dot product on two vectors.
|
||||
inline float32 b2Dot(const b2Vec2& a, const b2Vec2& b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y;
|
||||
}
|
||||
|
||||
/// Perform the cross product on two vectors. In 2D this produces a scalar.
|
||||
inline float32 b2Cross(const b2Vec2& a, const b2Vec2& b)
|
||||
{
|
||||
return a.x * b.y - a.y * b.x;
|
||||
}
|
||||
|
||||
/// Perform the cross product on a vector and a scalar. In 2D this produces
|
||||
/// a vector.
|
||||
inline b2Vec2 b2Cross(const b2Vec2& a, float32 s)
|
||||
{
|
||||
return b2Vec2(s * a.y, -s * a.x);
|
||||
}
|
||||
|
||||
/// Perform the cross product on a scalar and a vector. In 2D this produces
|
||||
/// a vector.
|
||||
inline b2Vec2 b2Cross(float32 s, const b2Vec2& a)
|
||||
{
|
||||
return b2Vec2(-s * a.y, s * a.x);
|
||||
}
|
||||
|
||||
/// Multiply a matrix times a vector. If a rotation matrix is provided,
|
||||
/// then this transforms the vector from one frame to another.
|
||||
inline b2Vec2 b2Mul(const b2Mat22& A, const b2Vec2& v)
|
||||
{
|
||||
return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
|
||||
}
|
||||
|
||||
/// Multiply a matrix transpose times a vector. If a rotation matrix is provided,
|
||||
/// then this transforms the vector from one frame to another (inverse transform).
|
||||
inline b2Vec2 b2MulT(const b2Mat22& A, const b2Vec2& v)
|
||||
{
|
||||
return b2Vec2(b2Dot(v, A.ex), b2Dot(v, A.ey));
|
||||
}
|
||||
|
||||
/// Add two vectors component-wise.
|
||||
inline b2Vec2 operator + (const b2Vec2& a, const b2Vec2& b)
|
||||
{
|
||||
return b2Vec2(a.x + b.x, a.y + b.y);
|
||||
}
|
||||
|
||||
/// Subtract two vectors component-wise.
|
||||
inline b2Vec2 operator - (const b2Vec2& a, const b2Vec2& b)
|
||||
{
|
||||
return b2Vec2(a.x - b.x, a.y - b.y);
|
||||
}
|
||||
|
||||
inline b2Vec2 operator * (float32 s, const b2Vec2& a)
|
||||
{
|
||||
return b2Vec2(s * a.x, s * a.y);
|
||||
}
|
||||
|
||||
inline bool operator == (const b2Vec2& a, const b2Vec2& b)
|
||||
{
|
||||
return a.x == b.x && a.y == b.y;
|
||||
}
|
||||
|
||||
inline float32 b2Distance(const b2Vec2& a, const b2Vec2& b)
|
||||
{
|
||||
b2Vec2 c = a - b;
|
||||
return c.Length();
|
||||
}
|
||||
|
||||
inline float32 b2DistanceSquared(const b2Vec2& a, const b2Vec2& b)
|
||||
{
|
||||
b2Vec2 c = a - b;
|
||||
return b2Dot(c, c);
|
||||
}
|
||||
|
||||
inline b2Vec3 operator * (float32 s, const b2Vec3& a)
|
||||
{
|
||||
return b2Vec3(s * a.x, s * a.y, s * a.z);
|
||||
}
|
||||
|
||||
/// Add two vectors component-wise.
|
||||
inline b2Vec3 operator + (const b2Vec3& a, const b2Vec3& b)
|
||||
{
|
||||
return b2Vec3(a.x + b.x, a.y + b.y, a.z + b.z);
|
||||
}
|
||||
|
||||
/// Subtract two vectors component-wise.
|
||||
inline b2Vec3 operator - (const b2Vec3& a, const b2Vec3& b)
|
||||
{
|
||||
return b2Vec3(a.x - b.x, a.y - b.y, a.z - b.z);
|
||||
}
|
||||
|
||||
/// Perform the dot product on two vectors.
|
||||
inline float32 b2Dot(const b2Vec3& a, const b2Vec3& b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||
}
|
||||
|
||||
/// Perform the cross product on two vectors.
|
||||
inline b2Vec3 b2Cross(const b2Vec3& a, const b2Vec3& b)
|
||||
{
|
||||
return b2Vec3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
|
||||
}
|
||||
|
||||
inline b2Mat22 operator + (const b2Mat22& A, const b2Mat22& B)
|
||||
{
|
||||
return b2Mat22(A.ex + B.ex, A.ey + B.ey);
|
||||
}
|
||||
|
||||
// A * B
|
||||
inline b2Mat22 b2Mul(const b2Mat22& A, const b2Mat22& B)
|
||||
{
|
||||
return b2Mat22(b2Mul(A, B.ex), b2Mul(A, B.ey));
|
||||
}
|
||||
|
||||
// A^T * B
|
||||
inline b2Mat22 b2MulT(const b2Mat22& A, const b2Mat22& B)
|
||||
{
|
||||
b2Vec2 c1(b2Dot(A.ex, B.ex), b2Dot(A.ey, B.ex));
|
||||
b2Vec2 c2(b2Dot(A.ex, B.ey), b2Dot(A.ey, B.ey));
|
||||
return b2Mat22(c1, c2);
|
||||
}
|
||||
|
||||
/// Multiply a matrix times a vector.
|
||||
inline b2Vec3 b2Mul(const b2Mat33& A, const b2Vec3& v)
|
||||
{
|
||||
return v.x * A.ex + v.y * A.ey + v.z * A.ez;
|
||||
}
|
||||
|
||||
/// Multiply a matrix times a vector.
|
||||
inline b2Vec2 b2Mul22(const b2Mat33& A, const b2Vec2& v)
|
||||
{
|
||||
return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
|
||||
}
|
||||
|
||||
/// Multiply two rotations: q * r
|
||||
inline b2Rot b2Mul(const b2Rot& q, const b2Rot& r)
|
||||
{
|
||||
// [qc -qs] * [rc -rs] = [qc*rc-qs*rs -qc*rs-qs*rc]
|
||||
// [qs qc] [rs rc] [qs*rc+qc*rs -qs*rs+qc*rc]
|
||||
// s = qs * rc + qc * rs
|
||||
// c = qc * rc - qs * rs
|
||||
b2Rot qr;
|
||||
qr.s = q.s * r.c + q.c * r.s;
|
||||
qr.c = q.c * r.c - q.s * r.s;
|
||||
return qr;
|
||||
}
|
||||
|
||||
/// Transpose multiply two rotations: qT * r
|
||||
inline b2Rot b2MulT(const b2Rot& q, const b2Rot& r)
|
||||
{
|
||||
// [ qc qs] * [rc -rs] = [qc*rc+qs*rs -qc*rs+qs*rc]
|
||||
// [-qs qc] [rs rc] [-qs*rc+qc*rs qs*rs+qc*rc]
|
||||
// s = qc * rs - qs * rc
|
||||
// c = qc * rc + qs * rs
|
||||
b2Rot qr;
|
||||
qr.s = q.c * r.s - q.s * r.c;
|
||||
qr.c = q.c * r.c + q.s * r.s;
|
||||
return qr;
|
||||
}
|
||||
|
||||
/// Rotate a vector
|
||||
inline b2Vec2 b2Mul(const b2Rot& q, const b2Vec2& v)
|
||||
{
|
||||
return b2Vec2(q.c * v.x - q.s * v.y, q.s * v.x + q.c * v.y);
|
||||
}
|
||||
|
||||
/// Inverse rotate a vector
|
||||
inline b2Vec2 b2MulT(const b2Rot& q, const b2Vec2& v)
|
||||
{
|
||||
return b2Vec2(q.c * v.x + q.s * v.y, -q.s * v.x + q.c * v.y);
|
||||
}
|
||||
|
||||
inline b2Vec2 b2Mul(const b2Transform& T, const b2Vec2& v)
|
||||
{
|
||||
float32 x = (T.q.c * v.x - T.q.s * v.y) + T.p.x;
|
||||
float32 y = (T.q.s * v.x + T.q.c * v.y) + T.p.y;
|
||||
|
||||
return b2Vec2(x, y);
|
||||
}
|
||||
|
||||
inline b2Vec2 b2MulT(const b2Transform& T, const b2Vec2& v)
|
||||
{
|
||||
float32 px = v.x - T.p.x;
|
||||
float32 py = v.y - T.p.y;
|
||||
float32 x = (T.q.c * px + T.q.s * py);
|
||||
float32 y = (-T.q.s * px + T.q.c * py);
|
||||
|
||||
return b2Vec2(x, y);
|
||||
}
|
||||
|
||||
// v2 = A.q.Rot(B.q.Rot(v1) + B.p) + A.p
|
||||
// = (A.q * B.q).Rot(v1) + A.q.Rot(B.p) + A.p
|
||||
inline b2Transform b2Mul(const b2Transform& A, const b2Transform& B)
|
||||
{
|
||||
b2Transform C;
|
||||
C.q = b2Mul(A.q, B.q);
|
||||
C.p = b2Mul(A.q, B.p) + A.p;
|
||||
return C;
|
||||
}
|
||||
|
||||
// v2 = A.q' * (B.q * v1 + B.p - A.p)
|
||||
// = A.q' * B.q * v1 + A.q' * (B.p - A.p)
|
||||
inline b2Transform b2MulT(const b2Transform& A, const b2Transform& B)
|
||||
{
|
||||
b2Transform C;
|
||||
C.q = b2MulT(A.q, B.q);
|
||||
C.p = b2MulT(A.q, B.p - A.p);
|
||||
return C;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T b2Abs(T a)
|
||||
{
|
||||
return a > T(0) ? a : -a;
|
||||
}
|
||||
|
||||
inline b2Vec2 b2Abs(const b2Vec2& a)
|
||||
{
|
||||
return b2Vec2(b2Abs(a.x), b2Abs(a.y));
|
||||
}
|
||||
|
||||
inline b2Mat22 b2Abs(const b2Mat22& A)
|
||||
{
|
||||
return b2Mat22(b2Abs(A.ex), b2Abs(A.ey));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T b2Min(T a, T b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
inline b2Vec2 b2Min(const b2Vec2& a, const b2Vec2& b)
|
||||
{
|
||||
return b2Vec2(b2Min(a.x, b.x), b2Min(a.y, b.y));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T b2Max(T a, T b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
inline b2Vec2 b2Max(const b2Vec2& a, const b2Vec2& b)
|
||||
{
|
||||
return b2Vec2(b2Max(a.x, b.x), b2Max(a.y, b.y));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T b2Clamp(T a, T low, T high)
|
||||
{
|
||||
return b2Max(low, b2Min(a, high));
|
||||
}
|
||||
|
||||
inline b2Vec2 b2Clamp(const b2Vec2& a, const b2Vec2& low, const b2Vec2& high)
|
||||
{
|
||||
return b2Max(low, b2Min(a, high));
|
||||
}
|
||||
|
||||
template<typename T> inline void b2Swap(T& a, T& b)
|
||||
{
|
||||
T tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
/// "Next Largest Power of 2
|
||||
/// Given a binary integer value x, the next largest power of 2 can be computed by a SWAR algorithm
|
||||
/// that recursively "folds" the upper bits into the lower bits. This process yields a bit vector with
|
||||
/// the same most significant 1 as x, but all 1's below it. Adding 1 to that value yields the next
|
||||
/// largest power of 2. For a 32-bit value:"
|
||||
inline uint32 b2NextPowerOfTwo(uint32 x)
|
||||
{
|
||||
x |= (x >> 1);
|
||||
x |= (x >> 2);
|
||||
x |= (x >> 4);
|
||||
x |= (x >> 8);
|
||||
x |= (x >> 16);
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
inline bool b2IsPowerOfTwo(uint32 x)
|
||||
{
|
||||
bool result = x > 0 && (x & (x - 1)) == 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void b2Sweep::GetTransform(b2Transform* xf, float32 beta) const
|
||||
{
|
||||
xf->p = (1.0f - beta) * c0 + beta * c;
|
||||
float32 angle = (1.0f - beta) * a0 + beta * a;
|
||||
xf->q.Set(angle);
|
||||
|
||||
// Shift to origin
|
||||
xf->p -= b2Mul(xf->q, localCenter);
|
||||
}
|
||||
|
||||
inline void b2Sweep::Advance(float32 alpha)
|
||||
{
|
||||
b2Assert(alpha0 < 1.0f);
|
||||
float32 beta = (alpha - alpha0) / (1.0f - alpha0);
|
||||
c0 += beta * (c - c0);
|
||||
a0 += beta * (a - a0);
|
||||
alpha0 = alpha;
|
||||
}
|
||||
|
||||
/// Normalize an angle in radians to be between -pi and pi
|
||||
inline void b2Sweep::Normalize()
|
||||
{
|
||||
float32 twoPi = 2.0f * b2_pi;
|
||||
float32 d = twoPi * floorf(a0 / twoPi);
|
||||
a0 -= d;
|
||||
a -= d;
|
||||
}
|
||||
|
||||
#endif
|
||||
161
Lib/Include/Box2D/Common/b2Settings.h
Normal file
161
Lib/Include/Box2D/Common/b2Settings.h
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_SETTINGS_H
|
||||
#define B2_SETTINGS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
#include <float.h>
|
||||
|
||||
#define B2_NOT_USED(x) ((void)(x))
|
||||
#define b2Assert(A) assert(A)
|
||||
|
||||
typedef signed char int8;
|
||||
typedef signed short int16;
|
||||
typedef signed int int32;
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned int uint32;
|
||||
typedef float float32;
|
||||
typedef double float64;
|
||||
|
||||
#define b2_maxFloat FLT_MAX
|
||||
#define b2_epsilon FLT_EPSILON
|
||||
#define b2_pi 3.14159265359f
|
||||
|
||||
/// @file
|
||||
/// Global tuning constants based on meters-kilograms-seconds (MKS) units.
|
||||
///
|
||||
|
||||
// Collision
|
||||
|
||||
/// The maximum number of contact points between two convex shapes. Do
|
||||
/// not change this value.
|
||||
#define b2_maxManifoldPoints 2
|
||||
|
||||
/// The maximum number of vertices on a convex polygon. You cannot increase
|
||||
/// this too much because b2BlockAllocator has a maximum object size.
|
||||
#define b2_maxPolygonVertices 8
|
||||
|
||||
/// This is used to fatten AABBs in the dynamic tree. This allows proxies
|
||||
/// to move by a small amount without triggering a tree adjustment.
|
||||
/// This is in meters.
|
||||
#define b2_aabbExtension 0.1f
|
||||
|
||||
/// This is used to fatten AABBs in the dynamic tree. This is used to predict
|
||||
/// the future position based on the current displacement.
|
||||
/// This is a dimensionless multiplier.
|
||||
#define b2_aabbMultiplier 2.0f
|
||||
|
||||
/// A small length used as a collision and constraint tolerance. Usually it is
|
||||
/// chosen to be numerically significant, but visually insignificant.
|
||||
#define b2_linearSlop 0.005f
|
||||
|
||||
/// A small angle used as a collision and constraint tolerance. Usually it is
|
||||
/// chosen to be numerically significant, but visually insignificant.
|
||||
#define b2_angularSlop (2.0f / 180.0f * b2_pi)
|
||||
|
||||
/// The radius of the polygon/edge shape skin. This should not be modified. Making
|
||||
/// this smaller means polygons will have an insufficient buffer for continuous collision.
|
||||
/// Making it larger may create artifacts for vertex collision.
|
||||
#define b2_polygonRadius (2.0f * b2_linearSlop)
|
||||
|
||||
/// Maximum number of sub-steps per contact in continuous physics simulation.
|
||||
#define b2_maxSubSteps 8
|
||||
|
||||
|
||||
// Dynamics
|
||||
|
||||
/// Maximum number of contacts to be handled to solve a TOI impact.
|
||||
#define b2_maxTOIContacts 32
|
||||
|
||||
/// A velocity threshold for elastic collisions. Any collision with a relative linear
|
||||
/// velocity below this threshold will be treated as inelastic.
|
||||
#define b2_velocityThreshold 1.0f
|
||||
|
||||
/// The maximum linear position correction used when solving constraints. This helps to
|
||||
/// prevent overshoot.
|
||||
#define b2_maxLinearCorrection 0.2f
|
||||
|
||||
/// The maximum angular position correction used when solving constraints. This helps to
|
||||
/// prevent overshoot.
|
||||
#define b2_maxAngularCorrection (8.0f / 180.0f * b2_pi)
|
||||
|
||||
/// The maximum linear velocity of a body. This limit is very large and is used
|
||||
/// to prevent numerical problems. You shouldn't need to adjust this.
|
||||
#define b2_maxTranslation 2.0f
|
||||
#define b2_maxTranslationSquared (b2_maxTranslation * b2_maxTranslation)
|
||||
|
||||
/// The maximum angular velocity of a body. This limit is very large and is used
|
||||
/// to prevent numerical problems. You shouldn't need to adjust this.
|
||||
#define b2_maxRotation (0.5f * b2_pi)
|
||||
#define b2_maxRotationSquared (b2_maxRotation * b2_maxRotation)
|
||||
|
||||
/// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
|
||||
/// that overlap is removed in one time step. However using values close to 1 often lead
|
||||
/// to overshoot.
|
||||
#define b2_baumgarte 0.2f
|
||||
#define b2_toiBaugarte 0.75f
|
||||
|
||||
|
||||
// Sleep
|
||||
|
||||
/// The time that a body must be still before it will go to sleep.
|
||||
#define b2_timeToSleep 0.5f
|
||||
|
||||
/// A body cannot sleep if its linear velocity is above this tolerance.
|
||||
#define b2_linearSleepTolerance 0.01f
|
||||
|
||||
/// A body cannot sleep if its angular velocity is above this tolerance.
|
||||
#define b2_angularSleepTolerance (2.0f / 180.0f * b2_pi)
|
||||
|
||||
// Memory Allocation
|
||||
|
||||
/// Implement this function to use your own memory allocator.
|
||||
void* b2Alloc(int32 size);
|
||||
|
||||
/// If you implement b2Alloc, you should also implement this function.
|
||||
void b2Free(void* mem);
|
||||
|
||||
/// Logging function.
|
||||
void b2Log(const char* string, ...);
|
||||
|
||||
/// Version numbering scheme.
|
||||
/// See http://en.wikipedia.org/wiki/Software_versioning
|
||||
struct b2Version
|
||||
{
|
||||
int32 major; ///< significant changes
|
||||
int32 minor; ///< incremental changes
|
||||
int32 revision; ///< bug fixes
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef BOX2D_BUILD_DLL
|
||||
#define BOX2D_API __declspec(dllexport)
|
||||
#else
|
||||
#define BOX2D_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define BOX2D_API /* Nothing */
|
||||
#endif
|
||||
|
||||
/// Current version.
|
||||
extern BOX2D_API b2Version b2_version;
|
||||
|
||||
#endif
|
||||
60
Lib/Include/Box2D/Common/b2StackAllocator.h
Normal file
60
Lib/Include/Box2D/Common/b2StackAllocator.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_STACK_ALLOCATOR_H
|
||||
#define B2_STACK_ALLOCATOR_H
|
||||
|
||||
#include <Box2D/Common/b2Settings.h>
|
||||
|
||||
const int32 b2_stackSize = 100 * 1024; // 100k
|
||||
const int32 b2_maxStackEntries = 32;
|
||||
|
||||
struct b2StackEntry
|
||||
{
|
||||
char* data;
|
||||
int32 size;
|
||||
bool usedMalloc;
|
||||
};
|
||||
|
||||
// This is a stack allocator used for fast per step allocations.
|
||||
// You must nest allocate/free pairs. The code will assert
|
||||
// if you try to interleave multiple allocate/free pairs.
|
||||
class BOX2D_API b2StackAllocator
|
||||
{
|
||||
public:
|
||||
b2StackAllocator();
|
||||
~b2StackAllocator();
|
||||
|
||||
void* Allocate(int32 size);
|
||||
void Free(void* p);
|
||||
|
||||
int32 GetMaxAllocation() const;
|
||||
|
||||
private:
|
||||
|
||||
char m_data[b2_stackSize];
|
||||
int32 m_index;
|
||||
|
||||
int32 m_allocation;
|
||||
int32 m_maxAllocation;
|
||||
|
||||
b2StackEntry m_entries[b2_maxStackEntries];
|
||||
int32 m_entryCount;
|
||||
};
|
||||
|
||||
#endif
|
||||
50
Lib/Include/Box2D/Common/b2Timer.h
Normal file
50
Lib/Include/Box2D/Common/b2Timer.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Erin Catto http://box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_TIMER_H
|
||||
#define B2_TIMER_H
|
||||
|
||||
#include <Box2D/Common/b2Settings.h>
|
||||
|
||||
/// Timer for profiling. This has platform specific code and may
|
||||
/// not work on every platform.
|
||||
class BOX2D_API b2Timer
|
||||
{
|
||||
public:
|
||||
|
||||
/// Constructor
|
||||
b2Timer();
|
||||
|
||||
/// Reset the timer.
|
||||
void Reset();
|
||||
|
||||
/// Get the time since construction or the last reset.
|
||||
float32 GetMilliseconds() const;
|
||||
|
||||
private:
|
||||
|
||||
#if defined(_WIN32)
|
||||
float64 m_start;
|
||||
static float64 s_invFrequency;
|
||||
#elif defined(__linux__) || defined (__APPLE__)
|
||||
unsigned long m_start_sec;
|
||||
unsigned long m_start_usec;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_CHAIN_AND_CIRCLE_CONTACT_H
|
||||
#define B2_CHAIN_AND_CIRCLE_CONTACT_H
|
||||
|
||||
#include <Box2D/Dynamics/Contacts/b2Contact.h>
|
||||
|
||||
class b2BlockAllocator;
|
||||
|
||||
class BOX2D_API b2ChainAndCircleContact : public b2Contact
|
||||
{
|
||||
public:
|
||||
static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,
|
||||
b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
|
||||
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
|
||||
|
||||
b2ChainAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB);
|
||||
~b2ChainAndCircleContact() {}
|
||||
|
||||
void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_CHAIN_AND_POLYGON_CONTACT_H
|
||||
#define B2_CHAIN_AND_POLYGON_CONTACT_H
|
||||
|
||||
#include <Box2D/Dynamics/Contacts/b2Contact.h>
|
||||
|
||||
class b2BlockAllocator;
|
||||
|
||||
class BOX2D_API b2ChainAndPolygonContact : public b2Contact
|
||||
{
|
||||
public:
|
||||
static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,
|
||||
b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
|
||||
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
|
||||
|
||||
b2ChainAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB);
|
||||
~b2ChainAndPolygonContact() {}
|
||||
|
||||
void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
|
||||
};
|
||||
|
||||
#endif
|
||||
39
Lib/Include/Box2D/Dynamics/Contacts/b2CircleContact.h
Normal file
39
Lib/Include/Box2D/Dynamics/Contacts/b2CircleContact.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_CIRCLE_CONTACT_H
|
||||
#define B2_CIRCLE_CONTACT_H
|
||||
|
||||
#include <Box2D/Dynamics/Contacts/b2Contact.h>
|
||||
|
||||
class b2BlockAllocator;
|
||||
|
||||
class BOX2D_API b2CircleContact : public b2Contact
|
||||
{
|
||||
public:
|
||||
static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,
|
||||
b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
|
||||
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
|
||||
|
||||
b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB);
|
||||
~b2CircleContact() {}
|
||||
|
||||
void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
|
||||
};
|
||||
|
||||
#endif
|
||||
349
Lib/Include/Box2D/Dynamics/Contacts/b2Contact.h
Normal file
349
Lib/Include/Box2D/Dynamics/Contacts/b2Contact.h
Normal file
@@ -0,0 +1,349 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_CONTACT_H
|
||||
#define B2_CONTACT_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
#include <Box2D/Collision/b2Collision.h>
|
||||
#include <Box2D/Collision/Shapes/b2Shape.h>
|
||||
#include <Box2D/Dynamics/b2Fixture.h>
|
||||
|
||||
class b2Body;
|
||||
class b2Contact;
|
||||
class b2Fixture;
|
||||
class b2World;
|
||||
class b2BlockAllocator;
|
||||
class b2StackAllocator;
|
||||
class b2ContactListener;
|
||||
|
||||
/// Friction mixing law. The idea is to allow either fixture to drive the restitution to zero.
|
||||
/// For example, anything slides on ice.
|
||||
inline float32 b2MixFriction(float32 friction1, float32 friction2)
|
||||
{
|
||||
return b2Sqrt(friction1 * friction2);
|
||||
}
|
||||
|
||||
/// Restitution mixing law. The idea is allow for anything to bounce off an inelastic surface.
|
||||
/// For example, a superball bounces on anything.
|
||||
inline float32 b2MixRestitution(float32 restitution1, float32 restitution2)
|
||||
{
|
||||
return restitution1 > restitution2 ? restitution1 : restitution2;
|
||||
}
|
||||
|
||||
typedef b2Contact* b2ContactCreateFcn( b2Fixture* fixtureA, int32 indexA,
|
||||
b2Fixture* fixtureB, int32 indexB,
|
||||
b2BlockAllocator* allocator);
|
||||
typedef void b2ContactDestroyFcn(b2Contact* contact, b2BlockAllocator* allocator);
|
||||
|
||||
struct b2ContactRegister
|
||||
{
|
||||
b2ContactCreateFcn* createFcn;
|
||||
b2ContactDestroyFcn* destroyFcn;
|
||||
bool primary;
|
||||
};
|
||||
|
||||
/// A contact edge is used to connect bodies and contacts together
|
||||
/// in a contact graph where each body is a node and each contact
|
||||
/// is an edge. A contact edge belongs to a doubly linked list
|
||||
/// maintained in each attached body. Each contact has two contact
|
||||
/// nodes, one for each attached body.
|
||||
struct b2ContactEdge
|
||||
{
|
||||
b2Body* other; ///< provides quick access to the other body attached.
|
||||
b2Contact* contact; ///< the contact
|
||||
b2ContactEdge* prev; ///< the previous contact edge in the body's contact list
|
||||
b2ContactEdge* next; ///< the next contact edge in the body's contact list
|
||||
};
|
||||
|
||||
/// The class manages contact between two shapes. A contact exists for each overlapping
|
||||
/// AABB in the broad-phase (except if filtered). Therefore a contact object may exist
|
||||
/// that has no contact points.
|
||||
class BOX2D_API b2Contact
|
||||
{
|
||||
public:
|
||||
|
||||
/// Get the contact manifold. Do not modify the manifold unless you understand the
|
||||
/// internals of Box2D.
|
||||
b2Manifold* GetManifold();
|
||||
const b2Manifold* GetManifold() const;
|
||||
|
||||
/// Get the world manifold.
|
||||
void GetWorldManifold(b2WorldManifold* worldManifold) const;
|
||||
|
||||
/// Is this contact touching?
|
||||
bool IsTouching() const;
|
||||
|
||||
/// Enable/disable this contact. This can be used inside the pre-solve
|
||||
/// contact listener. The contact is only disabled for the current
|
||||
/// time step (or sub-step in continuous collisions).
|
||||
void SetEnabled(bool flag);
|
||||
|
||||
/// Has this contact been disabled?
|
||||
bool IsEnabled() const;
|
||||
|
||||
/// Get the next contact in the world's contact list.
|
||||
b2Contact* GetNext();
|
||||
const b2Contact* GetNext() const;
|
||||
|
||||
/// Get fixture A in this contact.
|
||||
b2Fixture* GetFixtureA();
|
||||
const b2Fixture* GetFixtureA() const;
|
||||
|
||||
/// Get the child primitive index for fixture A.
|
||||
int32 GetChildIndexA() const;
|
||||
|
||||
/// Get fixture B in this contact.
|
||||
b2Fixture* GetFixtureB();
|
||||
const b2Fixture* GetFixtureB() const;
|
||||
|
||||
/// Get the child primitive index for fixture B.
|
||||
int32 GetChildIndexB() const;
|
||||
|
||||
/// Override the default friction mixture. You can call this in b2ContactListener::PreSolve.
|
||||
/// This value persists until set or reset.
|
||||
void SetFriction(float32 friction);
|
||||
|
||||
/// Get the friction.
|
||||
float32 GetFriction() const;
|
||||
|
||||
/// Reset the friction mixture to the default value.
|
||||
void ResetFriction();
|
||||
|
||||
/// Override the default restitution mixture. You can call this in b2ContactListener::PreSolve.
|
||||
/// The value persists until you set or reset.
|
||||
void SetRestitution(float32 restitution);
|
||||
|
||||
/// Get the restitution.
|
||||
float32 GetRestitution() const;
|
||||
|
||||
/// Reset the restitution to the default value.
|
||||
void ResetRestitution();
|
||||
|
||||
/// Set the desired tangent speed for a conveyor belt behavior. In meters per second.
|
||||
void SetTangentSpeed(float32 speed);
|
||||
|
||||
/// Get the desired tangent speed. In meters per second.
|
||||
float32 GetTangentSpeed() const;
|
||||
|
||||
/// Evaluate this contact with your own manifold and transforms.
|
||||
virtual void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) = 0;
|
||||
|
||||
protected:
|
||||
friend class b2ContactManager;
|
||||
friend class b2World;
|
||||
friend class b2ContactSolver;
|
||||
friend class b2Body;
|
||||
friend class b2Fixture;
|
||||
|
||||
// Flags stored in m_flags
|
||||
enum
|
||||
{
|
||||
// Used when crawling contact graph when forming islands.
|
||||
e_islandFlag = 0x0001,
|
||||
|
||||
// Set when the shapes are touching.
|
||||
e_touchingFlag = 0x0002,
|
||||
|
||||
// This contact can be disabled (by user)
|
||||
e_enabledFlag = 0x0004,
|
||||
|
||||
// This contact needs filtering because a fixture filter was changed.
|
||||
e_filterFlag = 0x0008,
|
||||
|
||||
// This bullet contact had a TOI event
|
||||
e_bulletHitFlag = 0x0010,
|
||||
|
||||
// This contact has a valid TOI in m_toi
|
||||
e_toiFlag = 0x0020
|
||||
};
|
||||
|
||||
/// Flag this contact for filtering. Filtering will occur the next time step.
|
||||
void FlagForFiltering();
|
||||
|
||||
static void AddType(b2ContactCreateFcn* createFcn, b2ContactDestroyFcn* destroyFcn,
|
||||
b2Shape::Type typeA, b2Shape::Type typeB);
|
||||
static void InitializeRegisters();
|
||||
static b2Contact* Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
|
||||
static void Destroy(b2Contact* contact, b2Shape::Type typeA, b2Shape::Type typeB, b2BlockAllocator* allocator);
|
||||
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
|
||||
|
||||
b2Contact() : m_fixtureA(NULL), m_fixtureB(NULL) {}
|
||||
b2Contact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB);
|
||||
virtual ~b2Contact() {}
|
||||
|
||||
void Update(b2ContactListener* listener);
|
||||
|
||||
static b2ContactRegister s_registers[b2Shape::e_typeCount][b2Shape::e_typeCount];
|
||||
static bool s_initialized;
|
||||
|
||||
uint32 m_flags;
|
||||
|
||||
// World pool and list pointers.
|
||||
b2Contact* m_prev;
|
||||
b2Contact* m_next;
|
||||
|
||||
// Nodes for connecting bodies.
|
||||
b2ContactEdge m_nodeA;
|
||||
b2ContactEdge m_nodeB;
|
||||
|
||||
b2Fixture* m_fixtureA;
|
||||
b2Fixture* m_fixtureB;
|
||||
|
||||
int32 m_indexA;
|
||||
int32 m_indexB;
|
||||
|
||||
b2Manifold m_manifold;
|
||||
|
||||
int32 m_toiCount;
|
||||
float32 m_toi;
|
||||
|
||||
float32 m_friction;
|
||||
float32 m_restitution;
|
||||
|
||||
float32 m_tangentSpeed;
|
||||
};
|
||||
|
||||
inline b2Manifold* b2Contact::GetManifold()
|
||||
{
|
||||
return &m_manifold;
|
||||
}
|
||||
|
||||
inline const b2Manifold* b2Contact::GetManifold() const
|
||||
{
|
||||
return &m_manifold;
|
||||
}
|
||||
|
||||
inline void b2Contact::GetWorldManifold(b2WorldManifold* worldManifold) const
|
||||
{
|
||||
const b2Body* bodyA = m_fixtureA->GetBody();
|
||||
const b2Body* bodyB = m_fixtureB->GetBody();
|
||||
const b2Shape* shapeA = m_fixtureA->GetShape();
|
||||
const b2Shape* shapeB = m_fixtureB->GetShape();
|
||||
|
||||
worldManifold->Initialize(&m_manifold, bodyA->GetTransform(), shapeA->m_radius, bodyB->GetTransform(), shapeB->m_radius);
|
||||
}
|
||||
|
||||
inline void b2Contact::SetEnabled(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
m_flags |= e_enabledFlag;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_flags &= ~e_enabledFlag;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool b2Contact::IsEnabled() const
|
||||
{
|
||||
return (m_flags & e_enabledFlag) == e_enabledFlag;
|
||||
}
|
||||
|
||||
inline bool b2Contact::IsTouching() const
|
||||
{
|
||||
return (m_flags & e_touchingFlag) == e_touchingFlag;
|
||||
}
|
||||
|
||||
inline b2Contact* b2Contact::GetNext()
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
inline const b2Contact* b2Contact::GetNext() const
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
inline b2Fixture* b2Contact::GetFixtureA()
|
||||
{
|
||||
return m_fixtureA;
|
||||
}
|
||||
|
||||
inline const b2Fixture* b2Contact::GetFixtureA() const
|
||||
{
|
||||
return m_fixtureA;
|
||||
}
|
||||
|
||||
inline b2Fixture* b2Contact::GetFixtureB()
|
||||
{
|
||||
return m_fixtureB;
|
||||
}
|
||||
|
||||
inline int32 b2Contact::GetChildIndexA() const
|
||||
{
|
||||
return m_indexA;
|
||||
}
|
||||
|
||||
inline const b2Fixture* b2Contact::GetFixtureB() const
|
||||
{
|
||||
return m_fixtureB;
|
||||
}
|
||||
|
||||
inline int32 b2Contact::GetChildIndexB() const
|
||||
{
|
||||
return m_indexB;
|
||||
}
|
||||
|
||||
inline void b2Contact::FlagForFiltering()
|
||||
{
|
||||
m_flags |= e_filterFlag;
|
||||
}
|
||||
|
||||
inline void b2Contact::SetFriction(float32 friction)
|
||||
{
|
||||
m_friction = friction;
|
||||
}
|
||||
|
||||
inline float32 b2Contact::GetFriction() const
|
||||
{
|
||||
return m_friction;
|
||||
}
|
||||
|
||||
inline void b2Contact::ResetFriction()
|
||||
{
|
||||
m_friction = b2MixFriction(m_fixtureA->m_friction, m_fixtureB->m_friction);
|
||||
}
|
||||
|
||||
inline void b2Contact::SetRestitution(float32 restitution)
|
||||
{
|
||||
m_restitution = restitution;
|
||||
}
|
||||
|
||||
inline float32 b2Contact::GetRestitution() const
|
||||
{
|
||||
return m_restitution;
|
||||
}
|
||||
|
||||
inline void b2Contact::ResetRestitution()
|
||||
{
|
||||
m_restitution = b2MixRestitution(m_fixtureA->m_restitution, m_fixtureB->m_restitution);
|
||||
}
|
||||
|
||||
inline void b2Contact::SetTangentSpeed(float32 speed)
|
||||
{
|
||||
m_tangentSpeed = speed;
|
||||
}
|
||||
|
||||
inline float32 b2Contact::GetTangentSpeed() const
|
||||
{
|
||||
return m_tangentSpeed;
|
||||
}
|
||||
|
||||
#endif
|
||||
95
Lib/Include/Box2D/Dynamics/Contacts/b2ContactSolver.h
Normal file
95
Lib/Include/Box2D/Dynamics/Contacts/b2ContactSolver.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_CONTACT_SOLVER_H
|
||||
#define B2_CONTACT_SOLVER_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
#include <Box2D/Collision/b2Collision.h>
|
||||
#include <Box2D/Dynamics/b2TimeStep.h>
|
||||
|
||||
class b2Contact;
|
||||
class b2Body;
|
||||
class b2StackAllocator;
|
||||
struct b2ContactPositionConstraint;
|
||||
|
||||
struct b2VelocityConstraintPoint
|
||||
{
|
||||
b2Vec2 rA;
|
||||
b2Vec2 rB;
|
||||
float32 normalImpulse;
|
||||
float32 tangentImpulse;
|
||||
float32 normalMass;
|
||||
float32 tangentMass;
|
||||
float32 velocityBias;
|
||||
};
|
||||
|
||||
struct b2ContactVelocityConstraint
|
||||
{
|
||||
b2VelocityConstraintPoint points[b2_maxManifoldPoints];
|
||||
b2Vec2 normal;
|
||||
b2Mat22 normalMass;
|
||||
b2Mat22 K;
|
||||
int32 indexA;
|
||||
int32 indexB;
|
||||
float32 invMassA, invMassB;
|
||||
float32 invIA, invIB;
|
||||
float32 friction;
|
||||
float32 restitution;
|
||||
float32 tangentSpeed;
|
||||
int32 pointCount;
|
||||
int32 contactIndex;
|
||||
};
|
||||
|
||||
struct b2ContactSolverDef
|
||||
{
|
||||
b2TimeStep step;
|
||||
b2Contact** contacts;
|
||||
int32 count;
|
||||
b2Position* positions;
|
||||
b2Velocity* velocities;
|
||||
b2StackAllocator* allocator;
|
||||
};
|
||||
|
||||
class BOX2D_API b2ContactSolver
|
||||
{
|
||||
public:
|
||||
b2ContactSolver(b2ContactSolverDef* def);
|
||||
~b2ContactSolver();
|
||||
|
||||
void InitializeVelocityConstraints();
|
||||
|
||||
void WarmStart();
|
||||
void SolveVelocityConstraints();
|
||||
void StoreImpulses();
|
||||
|
||||
bool SolvePositionConstraints();
|
||||
bool SolveTOIPositionConstraints(int32 toiIndexA, int32 toiIndexB);
|
||||
|
||||
b2TimeStep m_step;
|
||||
b2Position* m_positions;
|
||||
b2Velocity* m_velocities;
|
||||
b2StackAllocator* m_allocator;
|
||||
b2ContactPositionConstraint* m_positionConstraints;
|
||||
b2ContactVelocityConstraint* m_velocityConstraints;
|
||||
b2Contact** m_contacts;
|
||||
int m_count;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
39
Lib/Include/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h
Normal file
39
Lib/Include/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_EDGE_AND_CIRCLE_CONTACT_H
|
||||
#define B2_EDGE_AND_CIRCLE_CONTACT_H
|
||||
|
||||
#include <Box2D/Dynamics/Contacts/b2Contact.h>
|
||||
|
||||
class b2BlockAllocator;
|
||||
|
||||
class BOX2D_API b2EdgeAndCircleContact : public b2Contact
|
||||
{
|
||||
public:
|
||||
static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,
|
||||
b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
|
||||
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
|
||||
|
||||
b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB);
|
||||
~b2EdgeAndCircleContact() {}
|
||||
|
||||
void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_EDGE_AND_POLYGON_CONTACT_H
|
||||
#define B2_EDGE_AND_POLYGON_CONTACT_H
|
||||
|
||||
#include <Box2D/Dynamics/Contacts/b2Contact.h>
|
||||
|
||||
class b2BlockAllocator;
|
||||
|
||||
class BOX2D_API b2EdgeAndPolygonContact : public b2Contact
|
||||
{
|
||||
public:
|
||||
static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,
|
||||
b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
|
||||
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
|
||||
|
||||
b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB);
|
||||
~b2EdgeAndPolygonContact() {}
|
||||
|
||||
void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_POLYGON_AND_CIRCLE_CONTACT_H
|
||||
#define B2_POLYGON_AND_CIRCLE_CONTACT_H
|
||||
|
||||
#include <Box2D/Dynamics/Contacts/b2Contact.h>
|
||||
|
||||
class b2BlockAllocator;
|
||||
|
||||
class BOX2D_API b2PolygonAndCircleContact : public b2Contact
|
||||
{
|
||||
public:
|
||||
static b2Contact* Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
|
||||
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
|
||||
|
||||
b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB);
|
||||
~b2PolygonAndCircleContact() {}
|
||||
|
||||
void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
|
||||
};
|
||||
|
||||
#endif
|
||||
39
Lib/Include/Box2D/Dynamics/Contacts/b2PolygonContact.h
Normal file
39
Lib/Include/Box2D/Dynamics/Contacts/b2PolygonContact.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_POLYGON_CONTACT_H
|
||||
#define B2_POLYGON_CONTACT_H
|
||||
|
||||
#include <Box2D/Dynamics/Contacts/b2Contact.h>
|
||||
|
||||
class b2BlockAllocator;
|
||||
|
||||
class BOX2D_API b2PolygonContact : public b2Contact
|
||||
{
|
||||
public:
|
||||
static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,
|
||||
b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);
|
||||
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);
|
||||
|
||||
b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB);
|
||||
~b2PolygonContact() {}
|
||||
|
||||
void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);
|
||||
};
|
||||
|
||||
#endif
|
||||
169
Lib/Include/Box2D/Dynamics/Joints/b2DistanceJoint.h
Normal file
169
Lib/Include/Box2D/Dynamics/Joints/b2DistanceJoint.h
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_DISTANCE_JOINT_H
|
||||
#define B2_DISTANCE_JOINT_H
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
||||
|
||||
/// Distance joint definition. This requires defining an
|
||||
/// anchor point on both bodies and the non-zero length of the
|
||||
/// distance joint. The definition uses local anchor points
|
||||
/// so that the initial configuration can violate the constraint
|
||||
/// slightly. This helps when saving and loading a game.
|
||||
/// @warning Do not use a zero or short length.
|
||||
struct BOX2D_API b2DistanceJointDef : public b2JointDef
|
||||
{
|
||||
b2DistanceJointDef()
|
||||
{
|
||||
type = e_distanceJoint;
|
||||
localAnchorA.Set(0.0f, 0.0f);
|
||||
localAnchorB.Set(0.0f, 0.0f);
|
||||
length = 1.0f;
|
||||
frequencyHz = 0.0f;
|
||||
dampingRatio = 0.0f;
|
||||
}
|
||||
|
||||
/// Initialize the bodies, anchors, and length using the world
|
||||
/// anchors.
|
||||
void Initialize(b2Body* bodyA, b2Body* bodyB,
|
||||
const b2Vec2& anchorA, const b2Vec2& anchorB);
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
b2Vec2 localAnchorA;
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
b2Vec2 localAnchorB;
|
||||
|
||||
/// The natural length between the anchor points.
|
||||
float32 length;
|
||||
|
||||
/// The mass-spring-damper frequency in Hertz. A value of 0
|
||||
/// disables softness.
|
||||
float32 frequencyHz;
|
||||
|
||||
/// The damping ratio. 0 = no damping, 1 = critical damping.
|
||||
float32 dampingRatio;
|
||||
};
|
||||
|
||||
/// A distance joint constrains two points on two bodies
|
||||
/// to remain at a fixed distance from each other. You can view
|
||||
/// this as a massless, rigid rod.
|
||||
class BOX2D_API b2DistanceJoint : public b2Joint
|
||||
{
|
||||
public:
|
||||
|
||||
b2Vec2 GetAnchorA() const;
|
||||
b2Vec2 GetAnchorB() const;
|
||||
|
||||
/// Get the reaction force given the inverse time step.
|
||||
/// Unit is N.
|
||||
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
||||
|
||||
/// Get the reaction torque given the inverse time step.
|
||||
/// Unit is N*m. This is always zero for a distance joint.
|
||||
float32 GetReactionTorque(float32 inv_dt) const;
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
|
||||
|
||||
/// Set/get the natural length.
|
||||
/// Manipulating the length can lead to non-physical behavior when the frequency is zero.
|
||||
void SetLength(float32 length);
|
||||
float32 GetLength() const;
|
||||
|
||||
/// Set/get frequency in Hz.
|
||||
void SetFrequency(float32 hz);
|
||||
float32 GetFrequency() const;
|
||||
|
||||
/// Set/get damping ratio.
|
||||
void SetDampingRatio(float32 ratio);
|
||||
float32 GetDampingRatio() const;
|
||||
|
||||
/// Dump joint to dmLog
|
||||
void Dump();
|
||||
|
||||
protected:
|
||||
|
||||
friend class b2Joint;
|
||||
b2DistanceJoint(const b2DistanceJointDef* data);
|
||||
|
||||
void InitVelocityConstraints(const b2SolverData& data);
|
||||
void SolveVelocityConstraints(const b2SolverData& data);
|
||||
bool SolvePositionConstraints(const b2SolverData& data);
|
||||
|
||||
float32 m_frequencyHz;
|
||||
float32 m_dampingRatio;
|
||||
float32 m_bias;
|
||||
|
||||
// Solver shared
|
||||
b2Vec2 m_localAnchorA;
|
||||
b2Vec2 m_localAnchorB;
|
||||
float32 m_gamma;
|
||||
float32 m_impulse;
|
||||
float32 m_length;
|
||||
|
||||
// Solver temp
|
||||
int32 m_indexA;
|
||||
int32 m_indexB;
|
||||
b2Vec2 m_u;
|
||||
b2Vec2 m_rA;
|
||||
b2Vec2 m_rB;
|
||||
b2Vec2 m_localCenterA;
|
||||
b2Vec2 m_localCenterB;
|
||||
float32 m_invMassA;
|
||||
float32 m_invMassB;
|
||||
float32 m_invIA;
|
||||
float32 m_invIB;
|
||||
float32 m_mass;
|
||||
};
|
||||
|
||||
inline void b2DistanceJoint::SetLength(float32 length)
|
||||
{
|
||||
m_length = length;
|
||||
}
|
||||
|
||||
inline float32 b2DistanceJoint::GetLength() const
|
||||
{
|
||||
return m_length;
|
||||
}
|
||||
|
||||
inline void b2DistanceJoint::SetFrequency(float32 hz)
|
||||
{
|
||||
m_frequencyHz = hz;
|
||||
}
|
||||
|
||||
inline float32 b2DistanceJoint::GetFrequency() const
|
||||
{
|
||||
return m_frequencyHz;
|
||||
}
|
||||
|
||||
inline void b2DistanceJoint::SetDampingRatio(float32 ratio)
|
||||
{
|
||||
m_dampingRatio = ratio;
|
||||
}
|
||||
|
||||
inline float32 b2DistanceJoint::GetDampingRatio() const
|
||||
{
|
||||
return m_dampingRatio;
|
||||
}
|
||||
|
||||
#endif
|
||||
119
Lib/Include/Box2D/Dynamics/Joints/b2FrictionJoint.h
Normal file
119
Lib/Include/Box2D/Dynamics/Joints/b2FrictionJoint.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_FRICTION_JOINT_H
|
||||
#define B2_FRICTION_JOINT_H
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
||||
|
||||
/// Friction joint definition.
|
||||
struct BOX2D_API b2FrictionJointDef : public b2JointDef
|
||||
{
|
||||
b2FrictionJointDef()
|
||||
{
|
||||
type = e_frictionJoint;
|
||||
localAnchorA.SetZero();
|
||||
localAnchorB.SetZero();
|
||||
maxForce = 0.0f;
|
||||
maxTorque = 0.0f;
|
||||
}
|
||||
|
||||
/// Initialize the bodies, anchors, axis, and reference angle using the world
|
||||
/// anchor and world axis.
|
||||
void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor);
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
b2Vec2 localAnchorA;
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
b2Vec2 localAnchorB;
|
||||
|
||||
/// The maximum friction force in N.
|
||||
float32 maxForce;
|
||||
|
||||
/// The maximum friction torque in N-m.
|
||||
float32 maxTorque;
|
||||
};
|
||||
|
||||
/// Friction joint. This is used for top-down friction.
|
||||
/// It provides 2D translational friction and angular friction.
|
||||
class BOX2D_API b2FrictionJoint : public b2Joint
|
||||
{
|
||||
public:
|
||||
b2Vec2 GetAnchorA() const;
|
||||
b2Vec2 GetAnchorB() const;
|
||||
|
||||
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
||||
float32 GetReactionTorque(float32 inv_dt) const;
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
|
||||
|
||||
/// Set the maximum friction force in N.
|
||||
void SetMaxForce(float32 force);
|
||||
|
||||
/// Get the maximum friction force in N.
|
||||
float32 GetMaxForce() const;
|
||||
|
||||
/// Set the maximum friction torque in N*m.
|
||||
void SetMaxTorque(float32 torque);
|
||||
|
||||
/// Get the maximum friction torque in N*m.
|
||||
float32 GetMaxTorque() const;
|
||||
|
||||
/// Dump joint to dmLog
|
||||
void Dump();
|
||||
|
||||
protected:
|
||||
|
||||
friend class b2Joint;
|
||||
|
||||
b2FrictionJoint(const b2FrictionJointDef* def);
|
||||
|
||||
void InitVelocityConstraints(const b2SolverData& data);
|
||||
void SolveVelocityConstraints(const b2SolverData& data);
|
||||
bool SolvePositionConstraints(const b2SolverData& data);
|
||||
|
||||
b2Vec2 m_localAnchorA;
|
||||
b2Vec2 m_localAnchorB;
|
||||
|
||||
// Solver shared
|
||||
b2Vec2 m_linearImpulse;
|
||||
float32 m_angularImpulse;
|
||||
float32 m_maxForce;
|
||||
float32 m_maxTorque;
|
||||
|
||||
// Solver temp
|
||||
int32 m_indexA;
|
||||
int32 m_indexB;
|
||||
b2Vec2 m_rA;
|
||||
b2Vec2 m_rB;
|
||||
b2Vec2 m_localCenterA;
|
||||
b2Vec2 m_localCenterB;
|
||||
float32 m_invMassA;
|
||||
float32 m_invMassB;
|
||||
float32 m_invIA;
|
||||
float32 m_invIB;
|
||||
b2Mat22 m_linearMass;
|
||||
float32 m_angularMass;
|
||||
};
|
||||
|
||||
#endif
|
||||
125
Lib/Include/Box2D/Dynamics/Joints/b2GearJoint.h
Normal file
125
Lib/Include/Box2D/Dynamics/Joints/b2GearJoint.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_GEAR_JOINT_H
|
||||
#define B2_GEAR_JOINT_H
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
||||
|
||||
/// Gear joint definition. This definition requires two existing
|
||||
/// revolute or prismatic joints (any combination will work).
|
||||
struct BOX2D_API b2GearJointDef : public b2JointDef
|
||||
{
|
||||
b2GearJointDef()
|
||||
{
|
||||
type = e_gearJoint;
|
||||
joint1 = NULL;
|
||||
joint2 = NULL;
|
||||
ratio = 1.0f;
|
||||
}
|
||||
|
||||
/// The first revolute/prismatic joint attached to the gear joint.
|
||||
b2Joint* joint1;
|
||||
|
||||
/// The second revolute/prismatic joint attached to the gear joint.
|
||||
b2Joint* joint2;
|
||||
|
||||
/// The gear ratio.
|
||||
/// @see b2GearJoint for explanation.
|
||||
float32 ratio;
|
||||
};
|
||||
|
||||
/// A gear joint is used to connect two joints together. Either joint
|
||||
/// can be a revolute or prismatic joint. You specify a gear ratio
|
||||
/// to bind the motions together:
|
||||
/// coordinate1 + ratio * coordinate2 = constant
|
||||
/// The ratio can be negative or positive. If one joint is a revolute joint
|
||||
/// and the other joint is a prismatic joint, then the ratio will have units
|
||||
/// of length or units of 1/length.
|
||||
/// @warning You have to manually destroy the gear joint if joint1 or joint2
|
||||
/// is destroyed.
|
||||
class BOX2D_API b2GearJoint : public b2Joint
|
||||
{
|
||||
public:
|
||||
b2Vec2 GetAnchorA() const;
|
||||
b2Vec2 GetAnchorB() const;
|
||||
|
||||
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
||||
float32 GetReactionTorque(float32 inv_dt) const;
|
||||
|
||||
/// Get the first joint.
|
||||
b2Joint* GetJoint1() { return m_joint1; }
|
||||
|
||||
/// Get the second joint.
|
||||
b2Joint* GetJoint2() { return m_joint2; }
|
||||
|
||||
/// Set/Get the gear ratio.
|
||||
void SetRatio(float32 ratio);
|
||||
float32 GetRatio() const;
|
||||
|
||||
/// Dump joint to dmLog
|
||||
void Dump();
|
||||
|
||||
protected:
|
||||
|
||||
friend class b2Joint;
|
||||
b2GearJoint(const b2GearJointDef* data);
|
||||
|
||||
void InitVelocityConstraints(const b2SolverData& data);
|
||||
void SolveVelocityConstraints(const b2SolverData& data);
|
||||
bool SolvePositionConstraints(const b2SolverData& data);
|
||||
|
||||
b2Joint* m_joint1;
|
||||
b2Joint* m_joint2;
|
||||
|
||||
b2JointType m_typeA;
|
||||
b2JointType m_typeB;
|
||||
|
||||
// Body A is connected to body C
|
||||
// Body B is connected to body D
|
||||
b2Body* m_bodyC;
|
||||
b2Body* m_bodyD;
|
||||
|
||||
// Solver shared
|
||||
b2Vec2 m_localAnchorA;
|
||||
b2Vec2 m_localAnchorB;
|
||||
b2Vec2 m_localAnchorC;
|
||||
b2Vec2 m_localAnchorD;
|
||||
|
||||
b2Vec2 m_localAxisC;
|
||||
b2Vec2 m_localAxisD;
|
||||
|
||||
float32 m_referenceAngleA;
|
||||
float32 m_referenceAngleB;
|
||||
|
||||
float32 m_constant;
|
||||
float32 m_ratio;
|
||||
|
||||
float32 m_impulse;
|
||||
|
||||
// Solver temp
|
||||
int32 m_indexA, m_indexB, m_indexC, m_indexD;
|
||||
b2Vec2 m_lcA, m_lcB, m_lcC, m_lcD;
|
||||
float32 m_mA, m_mB, m_mC, m_mD;
|
||||
float32 m_iA, m_iB, m_iC, m_iD;
|
||||
b2Vec2 m_JvAC, m_JvBD;
|
||||
float32 m_JwA, m_JwB, m_JwC, m_JwD;
|
||||
float32 m_mass;
|
||||
};
|
||||
|
||||
#endif
|
||||
226
Lib/Include/Box2D/Dynamics/Joints/b2Joint.h
Normal file
226
Lib/Include/Box2D/Dynamics/Joints/b2Joint.h
Normal file
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_JOINT_H
|
||||
#define B2_JOINT_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
|
||||
class b2Body;
|
||||
class b2Joint;
|
||||
struct b2SolverData;
|
||||
class b2BlockAllocator;
|
||||
|
||||
enum b2JointType
|
||||
{
|
||||
e_unknownJoint,
|
||||
e_revoluteJoint,
|
||||
e_prismaticJoint,
|
||||
e_distanceJoint,
|
||||
e_pulleyJoint,
|
||||
e_mouseJoint,
|
||||
e_gearJoint,
|
||||
e_wheelJoint,
|
||||
e_weldJoint,
|
||||
e_frictionJoint,
|
||||
e_ropeJoint,
|
||||
e_motorJoint
|
||||
};
|
||||
|
||||
enum b2LimitState
|
||||
{
|
||||
e_inactiveLimit,
|
||||
e_atLowerLimit,
|
||||
e_atUpperLimit,
|
||||
e_equalLimits
|
||||
};
|
||||
|
||||
struct b2Jacobian
|
||||
{
|
||||
b2Vec2 linear;
|
||||
float32 angularA;
|
||||
float32 angularB;
|
||||
};
|
||||
|
||||
/// A joint edge is used to connect bodies and joints together
|
||||
/// in a joint graph where each body is a node and each joint
|
||||
/// is an edge. A joint edge belongs to a doubly linked list
|
||||
/// maintained in each attached body. Each joint has two joint
|
||||
/// nodes, one for each attached body.
|
||||
struct b2JointEdge
|
||||
{
|
||||
b2Body* other; ///< provides quick access to the other body attached.
|
||||
b2Joint* joint; ///< the joint
|
||||
b2JointEdge* prev; ///< the previous joint edge in the body's joint list
|
||||
b2JointEdge* next; ///< the next joint edge in the body's joint list
|
||||
};
|
||||
|
||||
/// Joint definitions are used to construct joints.
|
||||
struct BOX2D_API b2JointDef
|
||||
{
|
||||
b2JointDef()
|
||||
{
|
||||
type = e_unknownJoint;
|
||||
userData = NULL;
|
||||
bodyA = NULL;
|
||||
bodyB = NULL;
|
||||
collideConnected = false;
|
||||
}
|
||||
|
||||
/// Use this to attach application specific data to your joints.
|
||||
void* userData;
|
||||
|
||||
/// The first attached body.
|
||||
b2Body* bodyA;
|
||||
|
||||
/// The second attached body.
|
||||
b2Body* bodyB;
|
||||
|
||||
/// The joint type is set automatically for concrete joint types.
|
||||
b2JointType type;
|
||||
|
||||
/// Set this flag to true if the attached bodies should collide.
|
||||
bool collideConnected;
|
||||
};
|
||||
|
||||
/// The base joint class. Joints are used to constraint two bodies together in
|
||||
/// various fashions. Some joints also feature limits and motors.
|
||||
class BOX2D_API b2Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/// Get the type of the concrete joint.
|
||||
b2JointType GetType() const;
|
||||
|
||||
/// Get the first body attached to this joint.
|
||||
b2Body* GetBodyA();
|
||||
|
||||
/// Get the second body attached to this joint.
|
||||
b2Body* GetBodyB();
|
||||
|
||||
/// Get the anchor point on bodyA in world coordinates.
|
||||
virtual b2Vec2 GetAnchorA() const = 0;
|
||||
|
||||
/// Get the anchor point on bodyB in world coordinates.
|
||||
virtual b2Vec2 GetAnchorB() const = 0;
|
||||
|
||||
/// Get the reaction force on bodyB at the joint anchor in Newtons.
|
||||
virtual b2Vec2 GetReactionForce(float32 inv_dt) const = 0;
|
||||
|
||||
/// Get the reaction torque on bodyB in N*m.
|
||||
virtual float32 GetReactionTorque(float32 inv_dt) const = 0;
|
||||
|
||||
/// Get the next joint the world joint list.
|
||||
b2Joint* GetNext();
|
||||
const b2Joint* GetNext() const;
|
||||
|
||||
/// Get the user data pointer.
|
||||
void* GetUserData() const;
|
||||
|
||||
/// Set the user data pointer.
|
||||
void SetUserData(void* data);
|
||||
|
||||
/// Short-cut function to determine if either body is inactive.
|
||||
bool IsActive() const;
|
||||
|
||||
/// Get collide connected.
|
||||
/// Note: modifying the collide connect flag won't work correctly because
|
||||
/// the flag is only checked when fixture AABBs begin to overlap.
|
||||
bool GetCollideConnected() const;
|
||||
|
||||
/// Dump this joint to the log file.
|
||||
virtual void Dump() { b2Log("// Dump is not supported for this joint type.\n"); }
|
||||
|
||||
/// Shift the origin for any points stored in world coordinates.
|
||||
virtual void ShiftOrigin(const b2Vec2& newOrigin) { B2_NOT_USED(newOrigin); }
|
||||
|
||||
protected:
|
||||
friend class b2World;
|
||||
friend class b2Body;
|
||||
friend class b2Island;
|
||||
friend class b2GearJoint;
|
||||
|
||||
static b2Joint* Create(const b2JointDef* def, b2BlockAllocator* allocator);
|
||||
static void Destroy(b2Joint* joint, b2BlockAllocator* allocator);
|
||||
|
||||
b2Joint(const b2JointDef* def);
|
||||
virtual ~b2Joint() {}
|
||||
|
||||
virtual void InitVelocityConstraints(const b2SolverData& data) = 0;
|
||||
virtual void SolveVelocityConstraints(const b2SolverData& data) = 0;
|
||||
|
||||
// This returns true if the position errors are within tolerance.
|
||||
virtual bool SolvePositionConstraints(const b2SolverData& data) = 0;
|
||||
|
||||
b2JointType m_type;
|
||||
b2Joint* m_prev;
|
||||
b2Joint* m_next;
|
||||
b2JointEdge m_edgeA;
|
||||
b2JointEdge m_edgeB;
|
||||
b2Body* m_bodyA;
|
||||
b2Body* m_bodyB;
|
||||
|
||||
int32 m_index;
|
||||
|
||||
bool m_islandFlag;
|
||||
bool m_collideConnected;
|
||||
|
||||
void* m_userData;
|
||||
};
|
||||
|
||||
inline b2JointType b2Joint::GetType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
inline b2Body* b2Joint::GetBodyA()
|
||||
{
|
||||
return m_bodyA;
|
||||
}
|
||||
|
||||
inline b2Body* b2Joint::GetBodyB()
|
||||
{
|
||||
return m_bodyB;
|
||||
}
|
||||
|
||||
inline b2Joint* b2Joint::GetNext()
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
inline const b2Joint* b2Joint::GetNext() const
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
inline void* b2Joint::GetUserData() const
|
||||
{
|
||||
return m_userData;
|
||||
}
|
||||
|
||||
inline void b2Joint::SetUserData(void* data)
|
||||
{
|
||||
m_userData = data;
|
||||
}
|
||||
|
||||
inline bool b2Joint::GetCollideConnected() const
|
||||
{
|
||||
return m_collideConnected;
|
||||
}
|
||||
|
||||
#endif
|
||||
133
Lib/Include/Box2D/Dynamics/Joints/b2MotorJoint.h
Normal file
133
Lib/Include/Box2D/Dynamics/Joints/b2MotorJoint.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2012 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_MOTOR_JOINT_H
|
||||
#define B2_MOTOR_JOINT_H
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
||||
|
||||
/// Motor joint definition.
|
||||
struct BOX2D_API b2MotorJointDef : public b2JointDef
|
||||
{
|
||||
b2MotorJointDef()
|
||||
{
|
||||
type = e_motorJoint;
|
||||
linearOffset.SetZero();
|
||||
angularOffset = 0.0f;
|
||||
maxForce = 1.0f;
|
||||
maxTorque = 1.0f;
|
||||
correctionFactor = 0.3f;
|
||||
}
|
||||
|
||||
/// Initialize the bodies and offsets using the current transforms.
|
||||
void Initialize(b2Body* bodyA, b2Body* bodyB);
|
||||
|
||||
/// Position of bodyB minus the position of bodyA, in bodyA's frame, in meters.
|
||||
b2Vec2 linearOffset;
|
||||
|
||||
/// The bodyB angle minus bodyA angle in radians.
|
||||
float32 angularOffset;
|
||||
|
||||
/// The maximum motor force in N.
|
||||
float32 maxForce;
|
||||
|
||||
/// The maximum motor torque in N-m.
|
||||
float32 maxTorque;
|
||||
|
||||
/// Position correction factor in the range [0,1].
|
||||
float32 correctionFactor;
|
||||
};
|
||||
|
||||
/// A motor joint is used to control the relative motion
|
||||
/// between two bodies. A typical usage is to control the movement
|
||||
/// of a dynamic body with respect to the ground.
|
||||
class BOX2D_API b2MotorJoint : public b2Joint
|
||||
{
|
||||
public:
|
||||
b2Vec2 GetAnchorA() const;
|
||||
b2Vec2 GetAnchorB() const;
|
||||
|
||||
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
||||
float32 GetReactionTorque(float32 inv_dt) const;
|
||||
|
||||
/// Set/get the target linear offset, in frame A, in meters.
|
||||
void SetLinearOffset(const b2Vec2& linearOffset);
|
||||
const b2Vec2& GetLinearOffset() const;
|
||||
|
||||
/// Set/get the target angular offset, in radians.
|
||||
void SetAngularOffset(float32 angularOffset);
|
||||
float32 GetAngularOffset() const;
|
||||
|
||||
/// Set the maximum friction force in N.
|
||||
void SetMaxForce(float32 force);
|
||||
|
||||
/// Get the maximum friction force in N.
|
||||
float32 GetMaxForce() const;
|
||||
|
||||
/// Set the maximum friction torque in N*m.
|
||||
void SetMaxTorque(float32 torque);
|
||||
|
||||
/// Get the maximum friction torque in N*m.
|
||||
float32 GetMaxTorque() const;
|
||||
|
||||
/// Set the position correction factor in the range [0,1].
|
||||
void SetCorrectionFactor(float32 factor);
|
||||
|
||||
/// Get the position correction factor in the range [0,1].
|
||||
float32 GetCorrectionFactor() const;
|
||||
|
||||
/// Dump to b2Log
|
||||
void Dump();
|
||||
|
||||
protected:
|
||||
|
||||
friend class b2Joint;
|
||||
|
||||
b2MotorJoint(const b2MotorJointDef* def);
|
||||
|
||||
void InitVelocityConstraints(const b2SolverData& data);
|
||||
void SolveVelocityConstraints(const b2SolverData& data);
|
||||
bool SolvePositionConstraints(const b2SolverData& data);
|
||||
|
||||
// Solver shared
|
||||
b2Vec2 m_linearOffset;
|
||||
float32 m_angularOffset;
|
||||
b2Vec2 m_linearImpulse;
|
||||
float32 m_angularImpulse;
|
||||
float32 m_maxForce;
|
||||
float32 m_maxTorque;
|
||||
float32 m_correctionFactor;
|
||||
|
||||
// Solver temp
|
||||
int32 m_indexA;
|
||||
int32 m_indexB;
|
||||
b2Vec2 m_rA;
|
||||
b2Vec2 m_rB;
|
||||
b2Vec2 m_localCenterA;
|
||||
b2Vec2 m_localCenterB;
|
||||
b2Vec2 m_linearError;
|
||||
float32 m_angularError;
|
||||
float32 m_invMassA;
|
||||
float32 m_invMassB;
|
||||
float32 m_invIA;
|
||||
float32 m_invIB;
|
||||
b2Mat22 m_linearMass;
|
||||
float32 m_angularMass;
|
||||
};
|
||||
|
||||
#endif
|
||||
129
Lib/Include/Box2D/Dynamics/Joints/b2MouseJoint.h
Normal file
129
Lib/Include/Box2D/Dynamics/Joints/b2MouseJoint.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_MOUSE_JOINT_H
|
||||
#define B2_MOUSE_JOINT_H
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
||||
|
||||
/// Mouse joint definition. This requires a world target point,
|
||||
/// tuning parameters, and the time step.
|
||||
struct BOX2D_API b2MouseJointDef : public b2JointDef
|
||||
{
|
||||
b2MouseJointDef()
|
||||
{
|
||||
type = e_mouseJoint;
|
||||
target.Set(0.0f, 0.0f);
|
||||
maxForce = 0.0f;
|
||||
frequencyHz = 5.0f;
|
||||
dampingRatio = 0.7f;
|
||||
}
|
||||
|
||||
/// The initial world target point. This is assumed
|
||||
/// to coincide with the body anchor initially.
|
||||
b2Vec2 target;
|
||||
|
||||
/// The maximum constraint force that can be exerted
|
||||
/// to move the candidate body. Usually you will express
|
||||
/// as some multiple of the weight (multiplier * mass * gravity).
|
||||
float32 maxForce;
|
||||
|
||||
/// The response speed.
|
||||
float32 frequencyHz;
|
||||
|
||||
/// The damping ratio. 0 = no damping, 1 = critical damping.
|
||||
float32 dampingRatio;
|
||||
};
|
||||
|
||||
/// A mouse joint is used to make a point on a body track a
|
||||
/// specified world point. This a soft constraint with a maximum
|
||||
/// force. This allows the constraint to stretch and without
|
||||
/// applying huge forces.
|
||||
/// NOTE: this joint is not documented in the manual because it was
|
||||
/// developed to be used in the testbed. If you want to learn how to
|
||||
/// use the mouse joint, look at the testbed.
|
||||
class BOX2D_API b2MouseJoint : public b2Joint
|
||||
{
|
||||
public:
|
||||
|
||||
/// Implements b2Joint.
|
||||
b2Vec2 GetAnchorA() const;
|
||||
|
||||
/// Implements b2Joint.
|
||||
b2Vec2 GetAnchorB() const;
|
||||
|
||||
/// Implements b2Joint.
|
||||
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
||||
|
||||
/// Implements b2Joint.
|
||||
float32 GetReactionTorque(float32 inv_dt) const;
|
||||
|
||||
/// Use this to update the target point.
|
||||
void SetTarget(const b2Vec2& target);
|
||||
const b2Vec2& GetTarget() const;
|
||||
|
||||
/// Set/get the maximum force in Newtons.
|
||||
void SetMaxForce(float32 force);
|
||||
float32 GetMaxForce() const;
|
||||
|
||||
/// Set/get the frequency in Hertz.
|
||||
void SetFrequency(float32 hz);
|
||||
float32 GetFrequency() const;
|
||||
|
||||
/// Set/get the damping ratio (dimensionless).
|
||||
void SetDampingRatio(float32 ratio);
|
||||
float32 GetDampingRatio() const;
|
||||
|
||||
/// The mouse joint does not support dumping.
|
||||
void Dump() { b2Log("Mouse joint dumping is not supported.\n"); }
|
||||
|
||||
/// Implement b2Joint::ShiftOrigin
|
||||
void ShiftOrigin(const b2Vec2& newOrigin);
|
||||
|
||||
protected:
|
||||
friend class b2Joint;
|
||||
|
||||
b2MouseJoint(const b2MouseJointDef* def);
|
||||
|
||||
void InitVelocityConstraints(const b2SolverData& data);
|
||||
void SolveVelocityConstraints(const b2SolverData& data);
|
||||
bool SolvePositionConstraints(const b2SolverData& data);
|
||||
|
||||
b2Vec2 m_localAnchorB;
|
||||
b2Vec2 m_targetA;
|
||||
float32 m_frequencyHz;
|
||||
float32 m_dampingRatio;
|
||||
float32 m_beta;
|
||||
|
||||
// Solver shared
|
||||
b2Vec2 m_impulse;
|
||||
float32 m_maxForce;
|
||||
float32 m_gamma;
|
||||
|
||||
// Solver temp
|
||||
int32 m_indexA;
|
||||
int32 m_indexB;
|
||||
b2Vec2 m_rB;
|
||||
b2Vec2 m_localCenterB;
|
||||
float32 m_invMassB;
|
||||
float32 m_invIB;
|
||||
b2Mat22 m_mass;
|
||||
b2Vec2 m_C;
|
||||
};
|
||||
|
||||
#endif
|
||||
196
Lib/Include/Box2D/Dynamics/Joints/b2PrismaticJoint.h
Normal file
196
Lib/Include/Box2D/Dynamics/Joints/b2PrismaticJoint.h
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_PRISMATIC_JOINT_H
|
||||
#define B2_PRISMATIC_JOINT_H
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
||||
|
||||
/// Prismatic joint definition. This requires defining a line of
|
||||
/// motion using an axis and an anchor point. The definition uses local
|
||||
/// anchor points and a local axis so that the initial configuration
|
||||
/// can violate the constraint slightly. The joint translation is zero
|
||||
/// when the local anchor points coincide in world space. Using local
|
||||
/// anchors and a local axis helps when saving and loading a game.
|
||||
struct BOX2D_API b2PrismaticJointDef : public b2JointDef
|
||||
{
|
||||
b2PrismaticJointDef()
|
||||
{
|
||||
type = e_prismaticJoint;
|
||||
localAnchorA.SetZero();
|
||||
localAnchorB.SetZero();
|
||||
localAxisA.Set(1.0f, 0.0f);
|
||||
referenceAngle = 0.0f;
|
||||
enableLimit = false;
|
||||
lowerTranslation = 0.0f;
|
||||
upperTranslation = 0.0f;
|
||||
enableMotor = false;
|
||||
maxMotorForce = 0.0f;
|
||||
motorSpeed = 0.0f;
|
||||
}
|
||||
|
||||
/// Initialize the bodies, anchors, axis, and reference angle using the world
|
||||
/// anchor and unit world axis.
|
||||
void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor, const b2Vec2& axis);
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
b2Vec2 localAnchorA;
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
b2Vec2 localAnchorB;
|
||||
|
||||
/// The local translation unit axis in bodyA.
|
||||
b2Vec2 localAxisA;
|
||||
|
||||
/// The constrained angle between the bodies: bodyB_angle - bodyA_angle.
|
||||
float32 referenceAngle;
|
||||
|
||||
/// Enable/disable the joint limit.
|
||||
bool enableLimit;
|
||||
|
||||
/// The lower translation limit, usually in meters.
|
||||
float32 lowerTranslation;
|
||||
|
||||
/// The upper translation limit, usually in meters.
|
||||
float32 upperTranslation;
|
||||
|
||||
/// Enable/disable the joint motor.
|
||||
bool enableMotor;
|
||||
|
||||
/// The maximum motor torque, usually in N-m.
|
||||
float32 maxMotorForce;
|
||||
|
||||
/// The desired motor speed in radians per second.
|
||||
float32 motorSpeed;
|
||||
};
|
||||
|
||||
/// A prismatic joint. This joint provides one degree of freedom: translation
|
||||
/// along an axis fixed in bodyA. Relative rotation is prevented. You can
|
||||
/// use a joint limit to restrict the range of motion and a joint motor to
|
||||
/// drive the motion or to model joint friction.
|
||||
class BOX2D_API b2PrismaticJoint : public b2Joint
|
||||
{
|
||||
public:
|
||||
b2Vec2 GetAnchorA() const;
|
||||
b2Vec2 GetAnchorB() const;
|
||||
|
||||
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
||||
float32 GetReactionTorque(float32 inv_dt) const;
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
|
||||
|
||||
/// The local joint axis relative to bodyA.
|
||||
const b2Vec2& GetLocalAxisA() const { return m_localXAxisA; }
|
||||
|
||||
/// Get the reference angle.
|
||||
float32 GetReferenceAngle() const { return m_referenceAngle; }
|
||||
|
||||
/// Get the current joint translation, usually in meters.
|
||||
float32 GetJointTranslation() const;
|
||||
|
||||
/// Get the current joint translation speed, usually in meters per second.
|
||||
float32 GetJointSpeed() const;
|
||||
|
||||
/// Is the joint limit enabled?
|
||||
bool IsLimitEnabled() const;
|
||||
|
||||
/// Enable/disable the joint limit.
|
||||
void EnableLimit(bool flag);
|
||||
|
||||
/// Get the lower joint limit, usually in meters.
|
||||
float32 GetLowerLimit() const;
|
||||
|
||||
/// Get the upper joint limit, usually in meters.
|
||||
float32 GetUpperLimit() const;
|
||||
|
||||
/// Set the joint limits, usually in meters.
|
||||
void SetLimits(float32 lower, float32 upper);
|
||||
|
||||
/// Is the joint motor enabled?
|
||||
bool IsMotorEnabled() const;
|
||||
|
||||
/// Enable/disable the joint motor.
|
||||
void EnableMotor(bool flag);
|
||||
|
||||
/// Set the motor speed, usually in meters per second.
|
||||
void SetMotorSpeed(float32 speed);
|
||||
|
||||
/// Get the motor speed, usually in meters per second.
|
||||
float32 GetMotorSpeed() const;
|
||||
|
||||
/// Set the maximum motor force, usually in N.
|
||||
void SetMaxMotorForce(float32 force);
|
||||
float32 GetMaxMotorForce() const { return m_maxMotorForce; }
|
||||
|
||||
/// Get the current motor force given the inverse time step, usually in N.
|
||||
float32 GetMotorForce(float32 inv_dt) const;
|
||||
|
||||
/// Dump to b2Log
|
||||
void Dump();
|
||||
|
||||
protected:
|
||||
friend class b2Joint;
|
||||
friend class b2GearJoint;
|
||||
b2PrismaticJoint(const b2PrismaticJointDef* def);
|
||||
|
||||
void InitVelocityConstraints(const b2SolverData& data);
|
||||
void SolveVelocityConstraints(const b2SolverData& data);
|
||||
bool SolvePositionConstraints(const b2SolverData& data);
|
||||
|
||||
// Solver shared
|
||||
b2Vec2 m_localAnchorA;
|
||||
b2Vec2 m_localAnchorB;
|
||||
b2Vec2 m_localXAxisA;
|
||||
b2Vec2 m_localYAxisA;
|
||||
float32 m_referenceAngle;
|
||||
b2Vec3 m_impulse;
|
||||
float32 m_motorImpulse;
|
||||
float32 m_lowerTranslation;
|
||||
float32 m_upperTranslation;
|
||||
float32 m_maxMotorForce;
|
||||
float32 m_motorSpeed;
|
||||
bool m_enableLimit;
|
||||
bool m_enableMotor;
|
||||
b2LimitState m_limitState;
|
||||
|
||||
// Solver temp
|
||||
int32 m_indexA;
|
||||
int32 m_indexB;
|
||||
b2Vec2 m_localCenterA;
|
||||
b2Vec2 m_localCenterB;
|
||||
float32 m_invMassA;
|
||||
float32 m_invMassB;
|
||||
float32 m_invIA;
|
||||
float32 m_invIB;
|
||||
b2Vec2 m_axis, m_perp;
|
||||
float32 m_s1, m_s2;
|
||||
float32 m_a1, m_a2;
|
||||
b2Mat33 m_K;
|
||||
float32 m_motorMass;
|
||||
};
|
||||
|
||||
inline float32 b2PrismaticJoint::GetMotorSpeed() const
|
||||
{
|
||||
return m_motorSpeed;
|
||||
}
|
||||
|
||||
#endif
|
||||
152
Lib/Include/Box2D/Dynamics/Joints/b2PulleyJoint.h
Normal file
152
Lib/Include/Box2D/Dynamics/Joints/b2PulleyJoint.h
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_PULLEY_JOINT_H
|
||||
#define B2_PULLEY_JOINT_H
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
||||
|
||||
const float32 b2_minPulleyLength = 2.0f;
|
||||
|
||||
/// Pulley joint definition. This requires two ground anchors,
|
||||
/// two dynamic body anchor points, and a pulley ratio.
|
||||
struct BOX2D_API b2PulleyJointDef : public b2JointDef
|
||||
{
|
||||
b2PulleyJointDef()
|
||||
{
|
||||
type = e_pulleyJoint;
|
||||
groundAnchorA.Set(-1.0f, 1.0f);
|
||||
groundAnchorB.Set(1.0f, 1.0f);
|
||||
localAnchorA.Set(-1.0f, 0.0f);
|
||||
localAnchorB.Set(1.0f, 0.0f);
|
||||
lengthA = 0.0f;
|
||||
lengthB = 0.0f;
|
||||
ratio = 1.0f;
|
||||
collideConnected = true;
|
||||
}
|
||||
|
||||
/// Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors.
|
||||
void Initialize(b2Body* bodyA, b2Body* bodyB,
|
||||
const b2Vec2& groundAnchorA, const b2Vec2& groundAnchorB,
|
||||
const b2Vec2& anchorA, const b2Vec2& anchorB,
|
||||
float32 ratio);
|
||||
|
||||
/// The first ground anchor in world coordinates. This point never moves.
|
||||
b2Vec2 groundAnchorA;
|
||||
|
||||
/// The second ground anchor in world coordinates. This point never moves.
|
||||
b2Vec2 groundAnchorB;
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
b2Vec2 localAnchorA;
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
b2Vec2 localAnchorB;
|
||||
|
||||
/// The a reference length for the segment attached to bodyA.
|
||||
float32 lengthA;
|
||||
|
||||
/// The a reference length for the segment attached to bodyB.
|
||||
float32 lengthB;
|
||||
|
||||
/// The pulley ratio, used to simulate a block-and-tackle.
|
||||
float32 ratio;
|
||||
};
|
||||
|
||||
/// The pulley joint is connected to two bodies and two fixed ground points.
|
||||
/// The pulley supports a ratio such that:
|
||||
/// length1 + ratio * length2 <= constant
|
||||
/// Yes, the force transmitted is scaled by the ratio.
|
||||
/// Warning: the pulley joint can get a bit squirrelly by itself. They often
|
||||
/// work better when combined with prismatic joints. You should also cover the
|
||||
/// the anchor points with static shapes to prevent one side from going to
|
||||
/// zero length.
|
||||
class BOX2D_API b2PulleyJoint : public b2Joint
|
||||
{
|
||||
public:
|
||||
b2Vec2 GetAnchorA() const;
|
||||
b2Vec2 GetAnchorB() const;
|
||||
|
||||
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
||||
float32 GetReactionTorque(float32 inv_dt) const;
|
||||
|
||||
/// Get the first ground anchor.
|
||||
b2Vec2 GetGroundAnchorA() const;
|
||||
|
||||
/// Get the second ground anchor.
|
||||
b2Vec2 GetGroundAnchorB() const;
|
||||
|
||||
/// Get the current length of the segment attached to bodyA.
|
||||
float32 GetLengthA() const;
|
||||
|
||||
/// Get the current length of the segment attached to bodyB.
|
||||
float32 GetLengthB() const;
|
||||
|
||||
/// Get the pulley ratio.
|
||||
float32 GetRatio() const;
|
||||
|
||||
/// Get the current length of the segment attached to bodyA.
|
||||
float32 GetCurrentLengthA() const;
|
||||
|
||||
/// Get the current length of the segment attached to bodyB.
|
||||
float32 GetCurrentLengthB() const;
|
||||
|
||||
/// Dump joint to dmLog
|
||||
void Dump();
|
||||
|
||||
/// Implement b2Joint::ShiftOrigin
|
||||
void ShiftOrigin(const b2Vec2& newOrigin);
|
||||
|
||||
protected:
|
||||
|
||||
friend class b2Joint;
|
||||
b2PulleyJoint(const b2PulleyJointDef* data);
|
||||
|
||||
void InitVelocityConstraints(const b2SolverData& data);
|
||||
void SolveVelocityConstraints(const b2SolverData& data);
|
||||
bool SolvePositionConstraints(const b2SolverData& data);
|
||||
|
||||
b2Vec2 m_groundAnchorA;
|
||||
b2Vec2 m_groundAnchorB;
|
||||
float32 m_lengthA;
|
||||
float32 m_lengthB;
|
||||
|
||||
// Solver shared
|
||||
b2Vec2 m_localAnchorA;
|
||||
b2Vec2 m_localAnchorB;
|
||||
float32 m_constant;
|
||||
float32 m_ratio;
|
||||
float32 m_impulse;
|
||||
|
||||
// Solver temp
|
||||
int32 m_indexA;
|
||||
int32 m_indexB;
|
||||
b2Vec2 m_uA;
|
||||
b2Vec2 m_uB;
|
||||
b2Vec2 m_rA;
|
||||
b2Vec2 m_rB;
|
||||
b2Vec2 m_localCenterA;
|
||||
b2Vec2 m_localCenterB;
|
||||
float32 m_invMassA;
|
||||
float32 m_invMassB;
|
||||
float32 m_invIA;
|
||||
float32 m_invIB;
|
||||
float32 m_mass;
|
||||
};
|
||||
|
||||
#endif
|
||||
204
Lib/Include/Box2D/Dynamics/Joints/b2RevoluteJoint.h
Normal file
204
Lib/Include/Box2D/Dynamics/Joints/b2RevoluteJoint.h
Normal file
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_REVOLUTE_JOINT_H
|
||||
#define B2_REVOLUTE_JOINT_H
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
||||
|
||||
/// Revolute joint definition. This requires defining an
|
||||
/// anchor point where the bodies are joined. The definition
|
||||
/// uses local anchor points so that the initial configuration
|
||||
/// can violate the constraint slightly. You also need to
|
||||
/// specify the initial relative angle for joint limits. This
|
||||
/// helps when saving and loading a game.
|
||||
/// The local anchor points are measured from the body's origin
|
||||
/// rather than the center of mass because:
|
||||
/// 1. you might not know where the center of mass will be.
|
||||
/// 2. if you add/remove shapes from a body and recompute the mass,
|
||||
/// the joints will be broken.
|
||||
struct BOX2D_API b2RevoluteJointDef : public b2JointDef
|
||||
{
|
||||
b2RevoluteJointDef()
|
||||
{
|
||||
type = e_revoluteJoint;
|
||||
localAnchorA.Set(0.0f, 0.0f);
|
||||
localAnchorB.Set(0.0f, 0.0f);
|
||||
referenceAngle = 0.0f;
|
||||
lowerAngle = 0.0f;
|
||||
upperAngle = 0.0f;
|
||||
maxMotorTorque = 0.0f;
|
||||
motorSpeed = 0.0f;
|
||||
enableLimit = false;
|
||||
enableMotor = false;
|
||||
}
|
||||
|
||||
/// Initialize the bodies, anchors, and reference angle using a world
|
||||
/// anchor point.
|
||||
void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor);
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
b2Vec2 localAnchorA;
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
b2Vec2 localAnchorB;
|
||||
|
||||
/// The bodyB angle minus bodyA angle in the reference state (radians).
|
||||
float32 referenceAngle;
|
||||
|
||||
/// A flag to enable joint limits.
|
||||
bool enableLimit;
|
||||
|
||||
/// The lower angle for the joint limit (radians).
|
||||
float32 lowerAngle;
|
||||
|
||||
/// The upper angle for the joint limit (radians).
|
||||
float32 upperAngle;
|
||||
|
||||
/// A flag to enable the joint motor.
|
||||
bool enableMotor;
|
||||
|
||||
/// The desired motor speed. Usually in radians per second.
|
||||
float32 motorSpeed;
|
||||
|
||||
/// The maximum motor torque used to achieve the desired motor speed.
|
||||
/// Usually in N-m.
|
||||
float32 maxMotorTorque;
|
||||
};
|
||||
|
||||
/// A revolute joint constrains two bodies to share a common point while they
|
||||
/// are free to rotate about the point. The relative rotation about the shared
|
||||
/// point is the joint angle. You can limit the relative rotation with
|
||||
/// a joint limit that specifies a lower and upper angle. You can use a motor
|
||||
/// to drive the relative rotation about the shared point. A maximum motor torque
|
||||
/// is provided so that infinite forces are not generated.
|
||||
class BOX2D_API b2RevoluteJoint : public b2Joint
|
||||
{
|
||||
public:
|
||||
b2Vec2 GetAnchorA() const;
|
||||
b2Vec2 GetAnchorB() const;
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
|
||||
|
||||
/// Get the reference angle.
|
||||
float32 GetReferenceAngle() const { return m_referenceAngle; }
|
||||
|
||||
/// Get the current joint angle in radians.
|
||||
float32 GetJointAngle() const;
|
||||
|
||||
/// Get the current joint angle speed in radians per second.
|
||||
float32 GetJointSpeed() const;
|
||||
|
||||
/// Is the joint limit enabled?
|
||||
bool IsLimitEnabled() const;
|
||||
|
||||
/// Enable/disable the joint limit.
|
||||
void EnableLimit(bool flag);
|
||||
|
||||
/// Get the lower joint limit in radians.
|
||||
float32 GetLowerLimit() const;
|
||||
|
||||
/// Get the upper joint limit in radians.
|
||||
float32 GetUpperLimit() const;
|
||||
|
||||
/// Set the joint limits in radians.
|
||||
void SetLimits(float32 lower, float32 upper);
|
||||
|
||||
/// Is the joint motor enabled?
|
||||
bool IsMotorEnabled() const;
|
||||
|
||||
/// Enable/disable the joint motor.
|
||||
void EnableMotor(bool flag);
|
||||
|
||||
/// Set the motor speed in radians per second.
|
||||
void SetMotorSpeed(float32 speed);
|
||||
|
||||
/// Get the motor speed in radians per second.
|
||||
float32 GetMotorSpeed() const;
|
||||
|
||||
/// Set the maximum motor torque, usually in N-m.
|
||||
void SetMaxMotorTorque(float32 torque);
|
||||
float32 GetMaxMotorTorque() const { return m_maxMotorTorque; }
|
||||
|
||||
/// Get the reaction force given the inverse time step.
|
||||
/// Unit is N.
|
||||
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
||||
|
||||
/// Get the reaction torque due to the joint limit given the inverse time step.
|
||||
/// Unit is N*m.
|
||||
float32 GetReactionTorque(float32 inv_dt) const;
|
||||
|
||||
/// Get the current motor torque given the inverse time step.
|
||||
/// Unit is N*m.
|
||||
float32 GetMotorTorque(float32 inv_dt) const;
|
||||
|
||||
/// Dump to b2Log.
|
||||
void Dump();
|
||||
|
||||
protected:
|
||||
|
||||
friend class b2Joint;
|
||||
friend class b2GearJoint;
|
||||
|
||||
b2RevoluteJoint(const b2RevoluteJointDef* def);
|
||||
|
||||
void InitVelocityConstraints(const b2SolverData& data);
|
||||
void SolveVelocityConstraints(const b2SolverData& data);
|
||||
bool SolvePositionConstraints(const b2SolverData& data);
|
||||
|
||||
// Solver shared
|
||||
b2Vec2 m_localAnchorA;
|
||||
b2Vec2 m_localAnchorB;
|
||||
b2Vec3 m_impulse;
|
||||
float32 m_motorImpulse;
|
||||
|
||||
bool m_enableMotor;
|
||||
float32 m_maxMotorTorque;
|
||||
float32 m_motorSpeed;
|
||||
|
||||
bool m_enableLimit;
|
||||
float32 m_referenceAngle;
|
||||
float32 m_lowerAngle;
|
||||
float32 m_upperAngle;
|
||||
|
||||
// Solver temp
|
||||
int32 m_indexA;
|
||||
int32 m_indexB;
|
||||
b2Vec2 m_rA;
|
||||
b2Vec2 m_rB;
|
||||
b2Vec2 m_localCenterA;
|
||||
b2Vec2 m_localCenterB;
|
||||
float32 m_invMassA;
|
||||
float32 m_invMassB;
|
||||
float32 m_invIA;
|
||||
float32 m_invIB;
|
||||
b2Mat33 m_mass; // effective mass for point-to-point constraint.
|
||||
float32 m_motorMass; // effective mass for motor/limit angular constraint.
|
||||
b2LimitState m_limitState;
|
||||
};
|
||||
|
||||
inline float32 b2RevoluteJoint::GetMotorSpeed() const
|
||||
{
|
||||
return m_motorSpeed;
|
||||
}
|
||||
|
||||
#endif
|
||||
114
Lib/Include/Box2D/Dynamics/Joints/b2RopeJoint.h
Normal file
114
Lib/Include/Box2D/Dynamics/Joints/b2RopeJoint.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_ROPE_JOINT_H
|
||||
#define B2_ROPE_JOINT_H
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
||||
|
||||
/// Rope joint definition. This requires two body anchor points and
|
||||
/// a maximum lengths.
|
||||
/// Note: by default the connected objects will not collide.
|
||||
/// see collideConnected in b2JointDef.
|
||||
struct BOX2D_API b2RopeJointDef : public b2JointDef
|
||||
{
|
||||
b2RopeJointDef()
|
||||
{
|
||||
type = e_ropeJoint;
|
||||
localAnchorA.Set(-1.0f, 0.0f);
|
||||
localAnchorB.Set(1.0f, 0.0f);
|
||||
maxLength = 0.0f;
|
||||
}
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
b2Vec2 localAnchorA;
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
b2Vec2 localAnchorB;
|
||||
|
||||
/// The maximum length of the rope.
|
||||
/// Warning: this must be larger than b2_linearSlop or
|
||||
/// the joint will have no effect.
|
||||
float32 maxLength;
|
||||
};
|
||||
|
||||
/// A rope joint enforces a maximum distance between two points
|
||||
/// on two bodies. It has no other effect.
|
||||
/// Warning: if you attempt to change the maximum length during
|
||||
/// the simulation you will get some non-physical behavior.
|
||||
/// A model that would allow you to dynamically modify the length
|
||||
/// would have some sponginess, so I chose not to implement it
|
||||
/// that way. See b2DistanceJoint if you want to dynamically
|
||||
/// control length.
|
||||
class BOX2D_API b2RopeJoint : public b2Joint
|
||||
{
|
||||
public:
|
||||
b2Vec2 GetAnchorA() const;
|
||||
b2Vec2 GetAnchorB() const;
|
||||
|
||||
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
||||
float32 GetReactionTorque(float32 inv_dt) const;
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
|
||||
|
||||
/// Set/Get the maximum length of the rope.
|
||||
void SetMaxLength(float32 length) { m_maxLength = length; }
|
||||
float32 GetMaxLength() const;
|
||||
|
||||
b2LimitState GetLimitState() const;
|
||||
|
||||
/// Dump joint to dmLog
|
||||
void Dump();
|
||||
|
||||
protected:
|
||||
|
||||
friend class b2Joint;
|
||||
b2RopeJoint(const b2RopeJointDef* data);
|
||||
|
||||
void InitVelocityConstraints(const b2SolverData& data);
|
||||
void SolveVelocityConstraints(const b2SolverData& data);
|
||||
bool SolvePositionConstraints(const b2SolverData& data);
|
||||
|
||||
// Solver shared
|
||||
b2Vec2 m_localAnchorA;
|
||||
b2Vec2 m_localAnchorB;
|
||||
float32 m_maxLength;
|
||||
float32 m_length;
|
||||
float32 m_impulse;
|
||||
|
||||
// Solver temp
|
||||
int32 m_indexA;
|
||||
int32 m_indexB;
|
||||
b2Vec2 m_u;
|
||||
b2Vec2 m_rA;
|
||||
b2Vec2 m_rB;
|
||||
b2Vec2 m_localCenterA;
|
||||
b2Vec2 m_localCenterB;
|
||||
float32 m_invMassA;
|
||||
float32 m_invMassB;
|
||||
float32 m_invIA;
|
||||
float32 m_invIB;
|
||||
float32 m_mass;
|
||||
b2LimitState m_state;
|
||||
};
|
||||
|
||||
#endif
|
||||
126
Lib/Include/Box2D/Dynamics/Joints/b2WeldJoint.h
Normal file
126
Lib/Include/Box2D/Dynamics/Joints/b2WeldJoint.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_WELD_JOINT_H
|
||||
#define B2_WELD_JOINT_H
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
||||
|
||||
/// Weld joint definition. You need to specify local anchor points
|
||||
/// where they are attached and the relative body angle. The position
|
||||
/// of the anchor points is important for computing the reaction torque.
|
||||
struct BOX2D_API b2WeldJointDef : public b2JointDef
|
||||
{
|
||||
b2WeldJointDef()
|
||||
{
|
||||
type = e_weldJoint;
|
||||
localAnchorA.Set(0.0f, 0.0f);
|
||||
localAnchorB.Set(0.0f, 0.0f);
|
||||
referenceAngle = 0.0f;
|
||||
frequencyHz = 0.0f;
|
||||
dampingRatio = 0.0f;
|
||||
}
|
||||
|
||||
/// Initialize the bodies, anchors, and reference angle using a world
|
||||
/// anchor point.
|
||||
void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor);
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
b2Vec2 localAnchorA;
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
b2Vec2 localAnchorB;
|
||||
|
||||
/// The bodyB angle minus bodyA angle in the reference state (radians).
|
||||
float32 referenceAngle;
|
||||
|
||||
/// The mass-spring-damper frequency in Hertz. Rotation only.
|
||||
/// Disable softness with a value of 0.
|
||||
float32 frequencyHz;
|
||||
|
||||
/// The damping ratio. 0 = no damping, 1 = critical damping.
|
||||
float32 dampingRatio;
|
||||
};
|
||||
|
||||
/// A weld joint essentially glues two bodies together. A weld joint may
|
||||
/// distort somewhat because the island constraint solver is approximate.
|
||||
class BOX2D_API b2WeldJoint : public b2Joint
|
||||
{
|
||||
public:
|
||||
b2Vec2 GetAnchorA() const;
|
||||
b2Vec2 GetAnchorB() const;
|
||||
|
||||
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
||||
float32 GetReactionTorque(float32 inv_dt) const;
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
|
||||
|
||||
/// Get the reference angle.
|
||||
float32 GetReferenceAngle() const { return m_referenceAngle; }
|
||||
|
||||
/// Set/get frequency in Hz.
|
||||
void SetFrequency(float32 hz) { m_frequencyHz = hz; }
|
||||
float32 GetFrequency() const { return m_frequencyHz; }
|
||||
|
||||
/// Set/get damping ratio.
|
||||
void SetDampingRatio(float32 ratio) { m_dampingRatio = ratio; }
|
||||
float32 GetDampingRatio() const { return m_dampingRatio; }
|
||||
|
||||
/// Dump to b2Log
|
||||
void Dump();
|
||||
|
||||
protected:
|
||||
|
||||
friend class b2Joint;
|
||||
|
||||
b2WeldJoint(const b2WeldJointDef* def);
|
||||
|
||||
void InitVelocityConstraints(const b2SolverData& data);
|
||||
void SolveVelocityConstraints(const b2SolverData& data);
|
||||
bool SolvePositionConstraints(const b2SolverData& data);
|
||||
|
||||
float32 m_frequencyHz;
|
||||
float32 m_dampingRatio;
|
||||
float32 m_bias;
|
||||
|
||||
// Solver shared
|
||||
b2Vec2 m_localAnchorA;
|
||||
b2Vec2 m_localAnchorB;
|
||||
float32 m_referenceAngle;
|
||||
float32 m_gamma;
|
||||
b2Vec3 m_impulse;
|
||||
|
||||
// Solver temp
|
||||
int32 m_indexA;
|
||||
int32 m_indexB;
|
||||
b2Vec2 m_rA;
|
||||
b2Vec2 m_rB;
|
||||
b2Vec2 m_localCenterA;
|
||||
b2Vec2 m_localCenterB;
|
||||
float32 m_invMassA;
|
||||
float32 m_invMassB;
|
||||
float32 m_invIA;
|
||||
float32 m_invIB;
|
||||
b2Mat33 m_mass;
|
||||
};
|
||||
|
||||
#endif
|
||||
211
Lib/Include/Box2D/Dynamics/Joints/b2WheelJoint.h
Normal file
211
Lib/Include/Box2D/Dynamics/Joints/b2WheelJoint.h
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_WHEEL_JOINT_H
|
||||
#define B2_WHEEL_JOINT_H
|
||||
|
||||
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
||||
|
||||
/// Wheel joint definition. This requires defining a line of
|
||||
/// motion using an axis and an anchor point. The definition uses local
|
||||
/// anchor points and a local axis so that the initial configuration
|
||||
/// can violate the constraint slightly. The joint translation is zero
|
||||
/// when the local anchor points coincide in world space. Using local
|
||||
/// anchors and a local axis helps when saving and loading a game.
|
||||
struct BOX2D_API b2WheelJointDef : public b2JointDef
|
||||
{
|
||||
b2WheelJointDef()
|
||||
{
|
||||
type = e_wheelJoint;
|
||||
localAnchorA.SetZero();
|
||||
localAnchorB.SetZero();
|
||||
localAxisA.Set(1.0f, 0.0f);
|
||||
enableMotor = false;
|
||||
maxMotorTorque = 0.0f;
|
||||
motorSpeed = 0.0f;
|
||||
frequencyHz = 2.0f;
|
||||
dampingRatio = 0.7f;
|
||||
}
|
||||
|
||||
/// Initialize the bodies, anchors, axis, and reference angle using the world
|
||||
/// anchor and world axis.
|
||||
void Initialize(b2Body* bodyA, b2Body* bodyB, const b2Vec2& anchor, const b2Vec2& axis);
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
b2Vec2 localAnchorA;
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
b2Vec2 localAnchorB;
|
||||
|
||||
/// The local translation axis in bodyA.
|
||||
b2Vec2 localAxisA;
|
||||
|
||||
/// Enable/disable the joint motor.
|
||||
bool enableMotor;
|
||||
|
||||
/// The maximum motor torque, usually in N-m.
|
||||
float32 maxMotorTorque;
|
||||
|
||||
/// The desired motor speed in radians per second.
|
||||
float32 motorSpeed;
|
||||
|
||||
/// Suspension frequency, zero indicates no suspension
|
||||
float32 frequencyHz;
|
||||
|
||||
/// Suspension damping ratio, one indicates critical damping
|
||||
float32 dampingRatio;
|
||||
};
|
||||
|
||||
/// A wheel joint. This joint provides two degrees of freedom: translation
|
||||
/// along an axis fixed in bodyA and rotation in the plane. You can use a
|
||||
/// joint limit to restrict the range of motion and a joint motor to drive
|
||||
/// the rotation or to model rotational friction.
|
||||
/// This joint is designed for vehicle suspensions.
|
||||
class BOX2D_API b2WheelJoint : public b2Joint
|
||||
{
|
||||
public:
|
||||
b2Vec2 GetAnchorA() const;
|
||||
b2Vec2 GetAnchorB() const;
|
||||
|
||||
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
||||
float32 GetReactionTorque(float32 inv_dt) const;
|
||||
|
||||
/// The local anchor point relative to bodyA's origin.
|
||||
const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
|
||||
|
||||
/// The local anchor point relative to bodyB's origin.
|
||||
const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
|
||||
|
||||
/// The local joint axis relative to bodyA.
|
||||
const b2Vec2& GetLocalAxisA() const { return m_localXAxisA; }
|
||||
|
||||
/// Get the current joint translation, usually in meters.
|
||||
float32 GetJointTranslation() const;
|
||||
|
||||
/// Get the current joint translation speed, usually in meters per second.
|
||||
float32 GetJointSpeed() const;
|
||||
|
||||
/// Is the joint motor enabled?
|
||||
bool IsMotorEnabled() const;
|
||||
|
||||
/// Enable/disable the joint motor.
|
||||
void EnableMotor(bool flag);
|
||||
|
||||
/// Set the motor speed, usually in radians per second.
|
||||
void SetMotorSpeed(float32 speed);
|
||||
|
||||
/// Get the motor speed, usually in radians per second.
|
||||
float32 GetMotorSpeed() const;
|
||||
|
||||
/// Set/Get the maximum motor force, usually in N-m.
|
||||
void SetMaxMotorTorque(float32 torque);
|
||||
float32 GetMaxMotorTorque() const;
|
||||
|
||||
/// Get the current motor torque given the inverse time step, usually in N-m.
|
||||
float32 GetMotorTorque(float32 inv_dt) const;
|
||||
|
||||
/// Set/Get the spring frequency in hertz. Setting the frequency to zero disables the spring.
|
||||
void SetSpringFrequencyHz(float32 hz);
|
||||
float32 GetSpringFrequencyHz() const;
|
||||
|
||||
/// Set/Get the spring damping ratio
|
||||
void SetSpringDampingRatio(float32 ratio);
|
||||
float32 GetSpringDampingRatio() const;
|
||||
|
||||
/// Dump to b2Log
|
||||
void Dump();
|
||||
|
||||
protected:
|
||||
|
||||
friend class b2Joint;
|
||||
b2WheelJoint(const b2WheelJointDef* def);
|
||||
|
||||
void InitVelocityConstraints(const b2SolverData& data);
|
||||
void SolveVelocityConstraints(const b2SolverData& data);
|
||||
bool SolvePositionConstraints(const b2SolverData& data);
|
||||
|
||||
float32 m_frequencyHz;
|
||||
float32 m_dampingRatio;
|
||||
|
||||
// Solver shared
|
||||
b2Vec2 m_localAnchorA;
|
||||
b2Vec2 m_localAnchorB;
|
||||
b2Vec2 m_localXAxisA;
|
||||
b2Vec2 m_localYAxisA;
|
||||
|
||||
float32 m_impulse;
|
||||
float32 m_motorImpulse;
|
||||
float32 m_springImpulse;
|
||||
|
||||
float32 m_maxMotorTorque;
|
||||
float32 m_motorSpeed;
|
||||
bool m_enableMotor;
|
||||
|
||||
// Solver temp
|
||||
int32 m_indexA;
|
||||
int32 m_indexB;
|
||||
b2Vec2 m_localCenterA;
|
||||
b2Vec2 m_localCenterB;
|
||||
float32 m_invMassA;
|
||||
float32 m_invMassB;
|
||||
float32 m_invIA;
|
||||
float32 m_invIB;
|
||||
|
||||
b2Vec2 m_ax, m_ay;
|
||||
float32 m_sAx, m_sBx;
|
||||
float32 m_sAy, m_sBy;
|
||||
|
||||
float32 m_mass;
|
||||
float32 m_motorMass;
|
||||
float32 m_springMass;
|
||||
|
||||
float32 m_bias;
|
||||
float32 m_gamma;
|
||||
};
|
||||
|
||||
inline float32 b2WheelJoint::GetMotorSpeed() const
|
||||
{
|
||||
return m_motorSpeed;
|
||||
}
|
||||
|
||||
inline float32 b2WheelJoint::GetMaxMotorTorque() const
|
||||
{
|
||||
return m_maxMotorTorque;
|
||||
}
|
||||
|
||||
inline void b2WheelJoint::SetSpringFrequencyHz(float32 hz)
|
||||
{
|
||||
m_frequencyHz = hz;
|
||||
}
|
||||
|
||||
inline float32 b2WheelJoint::GetSpringFrequencyHz() const
|
||||
{
|
||||
return m_frequencyHz;
|
||||
}
|
||||
|
||||
inline void b2WheelJoint::SetSpringDampingRatio(float32 ratio)
|
||||
{
|
||||
m_dampingRatio = ratio;
|
||||
}
|
||||
|
||||
inline float32 b2WheelJoint::GetSpringDampingRatio() const
|
||||
{
|
||||
return m_dampingRatio;
|
||||
}
|
||||
|
||||
#endif
|
||||
859
Lib/Include/Box2D/Dynamics/b2Body.h
Normal file
859
Lib/Include/Box2D/Dynamics/b2Body.h
Normal file
@@ -0,0 +1,859 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_BODY_H
|
||||
#define B2_BODY_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
#include <Box2D/Collision/Shapes/b2Shape.h>
|
||||
#include <memory>
|
||||
|
||||
class b2Fixture;
|
||||
class b2Joint;
|
||||
class b2Contact;
|
||||
class b2Controller;
|
||||
class b2World;
|
||||
struct b2FixtureDef;
|
||||
struct b2JointEdge;
|
||||
struct b2ContactEdge;
|
||||
|
||||
/// The body type.
|
||||
/// static: zero mass, zero velocity, may be manually moved
|
||||
/// kinematic: zero mass, non-zero velocity set by user, moved by solver
|
||||
/// dynamic: positive mass, non-zero velocity determined by forces, moved by solver
|
||||
enum b2BodyType
|
||||
{
|
||||
b2_staticBody = 0,
|
||||
b2_kinematicBody,
|
||||
b2_dynamicBody
|
||||
|
||||
// TODO_ERIN
|
||||
//b2_bulletBody,
|
||||
};
|
||||
|
||||
/// A body definition holds all the data needed to construct a rigid body.
|
||||
/// You can safely re-use body definitions. Shapes are added to a body after construction.
|
||||
struct b2BodyDef
|
||||
{
|
||||
/// This constructor sets the body definition default values.
|
||||
b2BodyDef()
|
||||
{
|
||||
userData = NULL;
|
||||
position.Set(0.0f, 0.0f);
|
||||
angle = 0.0f;
|
||||
linearVelocity.Set(0.0f, 0.0f);
|
||||
angularVelocity = 0.0f;
|
||||
linearDamping = 0.0f;
|
||||
angularDamping = 0.0f;
|
||||
allowSleep = true;
|
||||
awake = true;
|
||||
fixedRotation = false;
|
||||
bullet = false;
|
||||
type = b2_staticBody;
|
||||
active = true;
|
||||
gravityScale = 1.0f;
|
||||
}
|
||||
/// Use this to store application specific body data.
|
||||
void* userData;
|
||||
|
||||
/// The body type: static, kinematic, or dynamic.
|
||||
/// Note: if a dynamic body would have zero mass, the mass is set to one.
|
||||
b2BodyType type;
|
||||
|
||||
/// The world position of the body. Avoid creating bodies at the origin
|
||||
/// since this can lead to many overlapping shapes.
|
||||
b2Vec2 position;
|
||||
|
||||
/// The world angle of the body in radians.
|
||||
float32 angle;
|
||||
|
||||
/// The linear velocity of the body's origin in world co-ordinates.
|
||||
b2Vec2 linearVelocity;
|
||||
|
||||
/// The angular velocity of the body.
|
||||
float32 angularVelocity;
|
||||
|
||||
/// Linear damping is use to reduce the linear velocity. The damping parameter
|
||||
/// can be larger than 1.0f but the damping effect becomes sensitive to the
|
||||
/// time step when the damping parameter is large.
|
||||
float32 linearDamping;
|
||||
|
||||
/// Angular damping is use to reduce the angular velocity. The damping parameter
|
||||
/// can be larger than 1.0f but the damping effect becomes sensitive to the
|
||||
/// time step when the damping parameter is large.
|
||||
float32 angularDamping;
|
||||
|
||||
/// Scale the gravity applied to this body.
|
||||
float32 gravityScale;
|
||||
|
||||
/// Set this flag to false if this body should never fall asleep. Note that
|
||||
/// this increases CPU usage.
|
||||
bool allowSleep;
|
||||
|
||||
/// Is this body initially awake or sleeping?
|
||||
bool awake;
|
||||
|
||||
/// Should this body be prevented from rotating? Useful for characters.
|
||||
bool fixedRotation;
|
||||
|
||||
/// Is this a fast moving body that should be prevented from tunneling through
|
||||
/// other moving bodies? Note that all bodies are prevented from tunneling through
|
||||
/// kinematic and static bodies. This setting is only considered on dynamic bodies.
|
||||
/// @warning You should use this flag sparingly since it increases processing time.
|
||||
bool bullet;
|
||||
|
||||
/// Does this body start out active?
|
||||
bool active;
|
||||
};
|
||||
|
||||
/// A rigid body. These are created via b2World::CreateBody.
|
||||
class BOX2D_API b2Body
|
||||
{
|
||||
public:
|
||||
/// Creates a fixture and attach it to this body. Use this function if you need
|
||||
/// to set some fixture parameters, like friction. Otherwise you can create the
|
||||
/// fixture directly from a shape.
|
||||
/// If the density is non-zero, this function automatically updates the mass of the body.
|
||||
/// Contacts are not created until the next time step.
|
||||
/// @param def the fixture definition.
|
||||
/// @warning This function is locked during callbacks.
|
||||
b2Fixture* CreateFixture(const b2FixtureDef* def);
|
||||
|
||||
/// Creates a fixture from a shape and attach it to this body.
|
||||
/// This is a convenience function. Use b2FixtureDef if you need to set parameters
|
||||
/// like friction, restitution, user data, or filtering.
|
||||
/// If the density is non-zero, this function automatically updates the mass of the body.
|
||||
/// @param shape the shape to be cloned.
|
||||
/// @param density the shape density (set to zero for static bodies).
|
||||
/// @warning This function is locked during callbacks.
|
||||
b2Fixture* CreateFixture(const b2Shape* shape, float32 density);
|
||||
|
||||
/// Destroy a fixture. This removes the fixture from the broad-phase and
|
||||
/// destroys all contacts associated with this fixture. This will
|
||||
/// automatically adjust the mass of the body if the body is dynamic and the
|
||||
/// fixture has positive density.
|
||||
/// All fixtures attached to a body are implicitly destroyed when the body is destroyed.
|
||||
/// @param fixture the fixture to be removed.
|
||||
/// @warning This function is locked during callbacks.
|
||||
void DestroyFixture(b2Fixture* fixture);
|
||||
|
||||
/// Set the position of the body's origin and rotation.
|
||||
/// Manipulating a body's transform may cause non-physical behavior.
|
||||
/// Note: contacts are updated on the next call to b2World::Step.
|
||||
/// @param position the world position of the body's local origin.
|
||||
/// @param angle the world rotation in radians.
|
||||
void SetTransform(const b2Vec2& position, float32 angle);
|
||||
|
||||
/// Get the body transform for the body's origin.
|
||||
/// @return the world transform of the body's origin.
|
||||
const b2Transform& GetTransform() const;
|
||||
|
||||
/// Get the world body origin position.
|
||||
/// @return the world position of the body's origin.
|
||||
const b2Vec2& GetPosition() const;
|
||||
|
||||
/// Get the angle in radians.
|
||||
/// @return the current world rotation angle in radians.
|
||||
float32 GetAngle() const;
|
||||
|
||||
/// Get the world position of the center of mass.
|
||||
const b2Vec2& GetWorldCenter() const;
|
||||
|
||||
/// Get the local position of the center of mass.
|
||||
const b2Vec2& GetLocalCenter() const;
|
||||
|
||||
/// Set the linear velocity of the center of mass.
|
||||
/// @param v the new linear velocity of the center of mass.
|
||||
void SetLinearVelocity(const b2Vec2& v);
|
||||
|
||||
/// Get the linear velocity of the center of mass.
|
||||
/// @return the linear velocity of the center of mass.
|
||||
const b2Vec2& GetLinearVelocity() const;
|
||||
|
||||
/// Set the angular velocity.
|
||||
/// @param omega the new angular velocity in radians/second.
|
||||
void SetAngularVelocity(float32 omega);
|
||||
|
||||
/// Get the angular velocity.
|
||||
/// @return the angular velocity in radians/second.
|
||||
float32 GetAngularVelocity() const;
|
||||
|
||||
/// Apply a force at a world point. If the force is not
|
||||
/// applied at the center of mass, it will generate a torque and
|
||||
/// affect the angular velocity. This wakes up the body.
|
||||
/// @param force the world force vector, usually in Newtons (N).
|
||||
/// @param point the world position of the point of application.
|
||||
/// @param wake also wake up the body
|
||||
void ApplyForce(const b2Vec2& force, const b2Vec2& point, bool wake);
|
||||
|
||||
/// Apply a force to the center of mass. This wakes up the body.
|
||||
/// @param force the world force vector, usually in Newtons (N).
|
||||
/// @param wake also wake up the body
|
||||
void ApplyForceToCenter(const b2Vec2& force, bool wake);
|
||||
|
||||
/// Apply a torque. This affects the angular velocity
|
||||
/// without affecting the linear velocity of the center of mass.
|
||||
/// This wakes up the body.
|
||||
/// @param torque about the z-axis (out of the screen), usually in N-m.
|
||||
/// @param wake also wake up the body
|
||||
void ApplyTorque(float32 torque, bool wake);
|
||||
|
||||
/// Apply an impulse at a point. This immediately modifies the velocity.
|
||||
/// It also modifies the angular velocity if the point of application
|
||||
/// is not at the center of mass. This wakes up the body.
|
||||
/// @param impulse the world impulse vector, usually in N-seconds or kg-m/s.
|
||||
/// @param point the world position of the point of application.
|
||||
/// @param wake also wake up the body
|
||||
void ApplyLinearImpulse(const b2Vec2& impulse, const b2Vec2& point, bool wake);
|
||||
|
||||
/// Apply an angular impulse.
|
||||
/// @param impulse the angular impulse in units of kg*m*m/s
|
||||
/// @param wake also wake up the body
|
||||
void ApplyAngularImpulse(float32 impulse, bool wake);
|
||||
|
||||
/// Get the total mass of the body.
|
||||
/// @return the mass, usually in kilograms (kg).
|
||||
float32 GetMass() const;
|
||||
|
||||
/// Get the rotational inertia of the body about the local origin.
|
||||
/// @return the rotational inertia, usually in kg-m^2.
|
||||
float32 GetInertia() const;
|
||||
|
||||
/// Get the mass data of the body.
|
||||
/// @return a struct containing the mass, inertia and center of the body.
|
||||
void GetMassData(b2MassData* data) const;
|
||||
|
||||
/// Set the mass properties to override the mass properties of the fixtures.
|
||||
/// Note that this changes the center of mass position.
|
||||
/// Note that creating or destroying fixtures can also alter the mass.
|
||||
/// This function has no effect if the body isn't dynamic.
|
||||
/// @param massData the mass properties.
|
||||
void SetMassData(const b2MassData* data);
|
||||
|
||||
/// This resets the mass properties to the sum of the mass properties of the fixtures.
|
||||
/// This normally does not need to be called unless you called SetMassData to override
|
||||
/// the mass and you later want to reset the mass.
|
||||
void ResetMassData();
|
||||
|
||||
/// Get the world coordinates of a point given the local coordinates.
|
||||
/// @param localPoint a point on the body measured relative the the body's origin.
|
||||
/// @return the same point expressed in world coordinates.
|
||||
b2Vec2 GetWorldPoint(const b2Vec2& localPoint) const;
|
||||
|
||||
/// Get the world coordinates of a vector given the local coordinates.
|
||||
/// @param localVector a vector fixed in the body.
|
||||
/// @return the same vector expressed in world coordinates.
|
||||
b2Vec2 GetWorldVector(const b2Vec2& localVector) const;
|
||||
|
||||
/// Gets a local point relative to the body's origin given a world point.
|
||||
/// @param a point in world coordinates.
|
||||
/// @return the corresponding local point relative to the body's origin.
|
||||
b2Vec2 GetLocalPoint(const b2Vec2& worldPoint) const;
|
||||
|
||||
/// Gets a local vector given a world vector.
|
||||
/// @param a vector in world coordinates.
|
||||
/// @return the corresponding local vector.
|
||||
b2Vec2 GetLocalVector(const b2Vec2& worldVector) const;
|
||||
|
||||
/// Get the world linear velocity of a world point attached to this body.
|
||||
/// @param a point in world coordinates.
|
||||
/// @return the world velocity of a point.
|
||||
b2Vec2 GetLinearVelocityFromWorldPoint(const b2Vec2& worldPoint) const;
|
||||
|
||||
/// Get the world velocity of a local point.
|
||||
/// @param a point in local coordinates.
|
||||
/// @return the world velocity of a point.
|
||||
b2Vec2 GetLinearVelocityFromLocalPoint(const b2Vec2& localPoint) const;
|
||||
|
||||
/// Get the linear damping of the body.
|
||||
float32 GetLinearDamping() const;
|
||||
|
||||
/// Set the linear damping of the body.
|
||||
void SetLinearDamping(float32 linearDamping);
|
||||
|
||||
/// Get the angular damping of the body.
|
||||
float32 GetAngularDamping() const;
|
||||
|
||||
/// Set the angular damping of the body.
|
||||
void SetAngularDamping(float32 angularDamping);
|
||||
|
||||
/// Get the gravity scale of the body.
|
||||
float32 GetGravityScale() const;
|
||||
|
||||
/// Set the gravity scale of the body.
|
||||
void SetGravityScale(float32 scale);
|
||||
|
||||
/// Set the type of this body. This may alter the mass and velocity.
|
||||
void SetType(b2BodyType type);
|
||||
|
||||
/// Get the type of this body.
|
||||
b2BodyType GetType() const;
|
||||
|
||||
/// Should this body be treated like a bullet for continuous collision detection?
|
||||
void SetBullet(bool flag);
|
||||
|
||||
/// Is this body treated like a bullet for continuous collision detection?
|
||||
bool IsBullet() const;
|
||||
|
||||
/// You can disable sleeping on this body. If you disable sleeping, the
|
||||
/// body will be woken.
|
||||
void SetSleepingAllowed(bool flag);
|
||||
|
||||
/// Is this body allowed to sleep
|
||||
bool IsSleepingAllowed() const;
|
||||
|
||||
/// Set the sleep state of the body. A sleeping body has very
|
||||
/// low CPU cost.
|
||||
/// @param flag set to true to wake the body, false to put it to sleep.
|
||||
void SetAwake(bool flag);
|
||||
|
||||
/// Get the sleeping state of this body.
|
||||
/// @return true if the body is awake.
|
||||
bool IsAwake() const;
|
||||
|
||||
/// Set the active state of the body. An inactive body is not
|
||||
/// simulated and cannot be collided with or woken up.
|
||||
/// If you pass a flag of true, all fixtures will be added to the
|
||||
/// broad-phase.
|
||||
/// If you pass a flag of false, all fixtures will be removed from
|
||||
/// the broad-phase and all contacts will be destroyed.
|
||||
/// Fixtures and joints are otherwise unaffected. You may continue
|
||||
/// to create/destroy fixtures and joints on inactive bodies.
|
||||
/// Fixtures on an inactive body are implicitly inactive and will
|
||||
/// not participate in collisions, ray-casts, or queries.
|
||||
/// Joints connected to an inactive body are implicitly inactive.
|
||||
/// An inactive body is still owned by a b2World object and remains
|
||||
/// in the body list.
|
||||
void SetActive(bool flag);
|
||||
|
||||
/// Get the active state of the body.
|
||||
bool IsActive() const;
|
||||
|
||||
/// Set this body to have fixed rotation. This causes the mass
|
||||
/// to be reset.
|
||||
void SetFixedRotation(bool flag);
|
||||
|
||||
/// Does this body have fixed rotation?
|
||||
bool IsFixedRotation() const;
|
||||
|
||||
/// Get the list of all fixtures attached to this body.
|
||||
b2Fixture* GetFixtureList();
|
||||
const b2Fixture* GetFixtureList() const;
|
||||
|
||||
/// Get the list of all joints attached to this body.
|
||||
b2JointEdge* GetJointList();
|
||||
const b2JointEdge* GetJointList() const;
|
||||
|
||||
/// Get the list of all contacts attached to this body.
|
||||
/// @warning this list changes during the time step and you may
|
||||
/// miss some collisions if you don't use b2ContactListener.
|
||||
b2ContactEdge* GetContactList();
|
||||
const b2ContactEdge* GetContactList() const;
|
||||
|
||||
/// Get the next body in the world's body list.
|
||||
b2Body* GetNext();
|
||||
const b2Body* GetNext() const;
|
||||
|
||||
/// Get the user data pointer that was provided in the body definition.
|
||||
void* GetUserData() const;
|
||||
|
||||
/// Set the user data. Use this to store your application specific data.
|
||||
void SetUserData(void* data);
|
||||
|
||||
/// Get the parent world of this body.
|
||||
b2World* GetWorld();
|
||||
const b2World* GetWorld() const;
|
||||
|
||||
/// Dump this body to a log file
|
||||
void Dump();
|
||||
|
||||
private:
|
||||
|
||||
friend class b2World;
|
||||
friend class b2Island;
|
||||
friend class b2ContactManager;
|
||||
friend class b2ContactSolver;
|
||||
friend class b2Contact;
|
||||
|
||||
friend class b2DistanceJoint;
|
||||
friend class b2FrictionJoint;
|
||||
friend class b2GearJoint;
|
||||
friend class b2MotorJoint;
|
||||
friend class b2MouseJoint;
|
||||
friend class b2PrismaticJoint;
|
||||
friend class b2PulleyJoint;
|
||||
friend class b2RevoluteJoint;
|
||||
friend class b2RopeJoint;
|
||||
friend class b2WeldJoint;
|
||||
friend class b2WheelJoint;
|
||||
|
||||
// m_flags
|
||||
enum
|
||||
{
|
||||
e_islandFlag = 0x0001,
|
||||
e_awakeFlag = 0x0002,
|
||||
e_autoSleepFlag = 0x0004,
|
||||
e_bulletFlag = 0x0008,
|
||||
e_fixedRotationFlag = 0x0010,
|
||||
e_activeFlag = 0x0020,
|
||||
e_toiFlag = 0x0040
|
||||
};
|
||||
|
||||
b2Body(const b2BodyDef* bd, b2World* world);
|
||||
~b2Body();
|
||||
|
||||
void SynchronizeFixtures();
|
||||
void SynchronizeTransform();
|
||||
|
||||
// This is used to prevent connected bodies from colliding.
|
||||
// It may lie, depending on the collideConnected flag.
|
||||
bool ShouldCollide(const b2Body* other) const;
|
||||
|
||||
void Advance(float32 t);
|
||||
|
||||
b2BodyType m_type;
|
||||
|
||||
uint16 m_flags;
|
||||
|
||||
int32 m_islandIndex;
|
||||
|
||||
b2Transform m_xf; // the body origin transform
|
||||
b2Sweep m_sweep; // the swept motion for CCD
|
||||
|
||||
b2Vec2 m_linearVelocity;
|
||||
float32 m_angularVelocity;
|
||||
|
||||
b2Vec2 m_force;
|
||||
float32 m_torque;
|
||||
|
||||
b2World* m_world;
|
||||
b2Body* m_prev;
|
||||
b2Body* m_next;
|
||||
|
||||
b2Fixture* m_fixtureList;
|
||||
int32 m_fixtureCount;
|
||||
|
||||
b2JointEdge* m_jointList;
|
||||
b2ContactEdge* m_contactList;
|
||||
|
||||
float32 m_mass, m_invMass;
|
||||
|
||||
// Rotational inertia about the center of mass.
|
||||
float32 m_I, m_invI;
|
||||
|
||||
float32 m_linearDamping;
|
||||
float32 m_angularDamping;
|
||||
float32 m_gravityScale;
|
||||
|
||||
float32 m_sleepTime;
|
||||
|
||||
void* m_userData;
|
||||
};
|
||||
|
||||
inline b2BodyType b2Body::GetType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
inline const b2Transform& b2Body::GetTransform() const
|
||||
{
|
||||
return m_xf;
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2Body::GetPosition() const
|
||||
{
|
||||
return m_xf.p;
|
||||
}
|
||||
|
||||
inline float32 b2Body::GetAngle() const
|
||||
{
|
||||
return m_sweep.a;
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2Body::GetWorldCenter() const
|
||||
{
|
||||
return m_sweep.c;
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2Body::GetLocalCenter() const
|
||||
{
|
||||
return m_sweep.localCenter;
|
||||
}
|
||||
|
||||
inline void b2Body::SetLinearVelocity(const b2Vec2& v)
|
||||
{
|
||||
if (m_type == b2_staticBody)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (b2Dot(v,v) > 0.0f)
|
||||
{
|
||||
SetAwake(true);
|
||||
}
|
||||
|
||||
m_linearVelocity = v;
|
||||
}
|
||||
|
||||
inline const b2Vec2& b2Body::GetLinearVelocity() const
|
||||
{
|
||||
return m_linearVelocity;
|
||||
}
|
||||
|
||||
inline void b2Body::SetAngularVelocity(float32 w)
|
||||
{
|
||||
if (m_type == b2_staticBody)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (w * w > 0.0f)
|
||||
{
|
||||
SetAwake(true);
|
||||
}
|
||||
|
||||
m_angularVelocity = w;
|
||||
}
|
||||
|
||||
inline float32 b2Body::GetAngularVelocity() const
|
||||
{
|
||||
return m_angularVelocity;
|
||||
}
|
||||
|
||||
inline float32 b2Body::GetMass() const
|
||||
{
|
||||
return m_mass;
|
||||
}
|
||||
|
||||
inline float32 b2Body::GetInertia() const
|
||||
{
|
||||
return m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter);
|
||||
}
|
||||
|
||||
inline void b2Body::GetMassData(b2MassData* data) const
|
||||
{
|
||||
data->mass = m_mass;
|
||||
data->I = m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter);
|
||||
data->center = m_sweep.localCenter;
|
||||
}
|
||||
|
||||
inline b2Vec2 b2Body::GetWorldPoint(const b2Vec2& localPoint) const
|
||||
{
|
||||
return b2Mul(m_xf, localPoint);
|
||||
}
|
||||
|
||||
inline b2Vec2 b2Body::GetWorldVector(const b2Vec2& localVector) const
|
||||
{
|
||||
return b2Mul(m_xf.q, localVector);
|
||||
}
|
||||
|
||||
inline b2Vec2 b2Body::GetLocalPoint(const b2Vec2& worldPoint) const
|
||||
{
|
||||
return b2MulT(m_xf, worldPoint);
|
||||
}
|
||||
|
||||
inline b2Vec2 b2Body::GetLocalVector(const b2Vec2& worldVector) const
|
||||
{
|
||||
return b2MulT(m_xf.q, worldVector);
|
||||
}
|
||||
|
||||
inline b2Vec2 b2Body::GetLinearVelocityFromWorldPoint(const b2Vec2& worldPoint) const
|
||||
{
|
||||
return m_linearVelocity + b2Cross(m_angularVelocity, worldPoint - m_sweep.c);
|
||||
}
|
||||
|
||||
inline b2Vec2 b2Body::GetLinearVelocityFromLocalPoint(const b2Vec2& localPoint) const
|
||||
{
|
||||
return GetLinearVelocityFromWorldPoint(GetWorldPoint(localPoint));
|
||||
}
|
||||
|
||||
inline float32 b2Body::GetLinearDamping() const
|
||||
{
|
||||
return m_linearDamping;
|
||||
}
|
||||
|
||||
inline void b2Body::SetLinearDamping(float32 linearDamping)
|
||||
{
|
||||
m_linearDamping = linearDamping;
|
||||
}
|
||||
|
||||
inline float32 b2Body::GetAngularDamping() const
|
||||
{
|
||||
return m_angularDamping;
|
||||
}
|
||||
|
||||
inline void b2Body::SetAngularDamping(float32 angularDamping)
|
||||
{
|
||||
m_angularDamping = angularDamping;
|
||||
}
|
||||
|
||||
inline float32 b2Body::GetGravityScale() const
|
||||
{
|
||||
return m_gravityScale;
|
||||
}
|
||||
|
||||
inline void b2Body::SetGravityScale(float32 scale)
|
||||
{
|
||||
m_gravityScale = scale;
|
||||
}
|
||||
|
||||
inline void b2Body::SetBullet(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
m_flags |= e_bulletFlag;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_flags &= ~e_bulletFlag;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool b2Body::IsBullet() const
|
||||
{
|
||||
return (m_flags & e_bulletFlag) == e_bulletFlag;
|
||||
}
|
||||
|
||||
inline void b2Body::SetAwake(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
if ((m_flags & e_awakeFlag) == 0)
|
||||
{
|
||||
m_flags |= e_awakeFlag;
|
||||
m_sleepTime = 0.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_flags &= ~e_awakeFlag;
|
||||
m_sleepTime = 0.0f;
|
||||
m_linearVelocity.SetZero();
|
||||
m_angularVelocity = 0.0f;
|
||||
m_force.SetZero();
|
||||
m_torque = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool b2Body::IsAwake() const
|
||||
{
|
||||
return (m_flags & e_awakeFlag) == e_awakeFlag;
|
||||
}
|
||||
|
||||
inline bool b2Body::IsActive() const
|
||||
{
|
||||
return (m_flags & e_activeFlag) == e_activeFlag;
|
||||
}
|
||||
|
||||
inline bool b2Body::IsFixedRotation() const
|
||||
{
|
||||
return (m_flags & e_fixedRotationFlag) == e_fixedRotationFlag;
|
||||
}
|
||||
|
||||
inline void b2Body::SetSleepingAllowed(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
m_flags |= e_autoSleepFlag;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_flags &= ~e_autoSleepFlag;
|
||||
SetAwake(true);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool b2Body::IsSleepingAllowed() const
|
||||
{
|
||||
return (m_flags & e_autoSleepFlag) == e_autoSleepFlag;
|
||||
}
|
||||
|
||||
inline b2Fixture* b2Body::GetFixtureList()
|
||||
{
|
||||
return m_fixtureList;
|
||||
}
|
||||
|
||||
inline const b2Fixture* b2Body::GetFixtureList() const
|
||||
{
|
||||
return m_fixtureList;
|
||||
}
|
||||
|
||||
inline b2JointEdge* b2Body::GetJointList()
|
||||
{
|
||||
return m_jointList;
|
||||
}
|
||||
|
||||
inline const b2JointEdge* b2Body::GetJointList() const
|
||||
{
|
||||
return m_jointList;
|
||||
}
|
||||
|
||||
inline b2ContactEdge* b2Body::GetContactList()
|
||||
{
|
||||
return m_contactList;
|
||||
}
|
||||
|
||||
inline const b2ContactEdge* b2Body::GetContactList() const
|
||||
{
|
||||
return m_contactList;
|
||||
}
|
||||
|
||||
inline b2Body* b2Body::GetNext()
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
inline const b2Body* b2Body::GetNext() const
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
inline void b2Body::SetUserData(void* data)
|
||||
{
|
||||
m_userData = data;
|
||||
}
|
||||
|
||||
inline void* b2Body::GetUserData() const
|
||||
{
|
||||
return m_userData;
|
||||
}
|
||||
|
||||
inline void b2Body::ApplyForce(const b2Vec2& force, const b2Vec2& point, bool wake)
|
||||
{
|
||||
if (m_type != b2_dynamicBody)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (wake && (m_flags & e_awakeFlag) == 0)
|
||||
{
|
||||
SetAwake(true);
|
||||
}
|
||||
|
||||
// Don't accumulate a force if the body is sleeping.
|
||||
if (m_flags & e_awakeFlag)
|
||||
{
|
||||
m_force += force;
|
||||
m_torque += b2Cross(point - m_sweep.c, force);
|
||||
}
|
||||
}
|
||||
|
||||
inline void b2Body::ApplyForceToCenter(const b2Vec2& force, bool wake)
|
||||
{
|
||||
if (m_type != b2_dynamicBody)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (wake && (m_flags & e_awakeFlag) == 0)
|
||||
{
|
||||
SetAwake(true);
|
||||
}
|
||||
|
||||
// Don't accumulate a force if the body is sleeping
|
||||
if (m_flags & e_awakeFlag)
|
||||
{
|
||||
m_force += force;
|
||||
}
|
||||
}
|
||||
|
||||
inline void b2Body::ApplyTorque(float32 torque, bool wake)
|
||||
{
|
||||
if (m_type != b2_dynamicBody)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (wake && (m_flags & e_awakeFlag) == 0)
|
||||
{
|
||||
SetAwake(true);
|
||||
}
|
||||
|
||||
// Don't accumulate a force if the body is sleeping
|
||||
if (m_flags & e_awakeFlag)
|
||||
{
|
||||
m_torque += torque;
|
||||
}
|
||||
}
|
||||
|
||||
inline void b2Body::ApplyLinearImpulse(const b2Vec2& impulse, const b2Vec2& point, bool wake)
|
||||
{
|
||||
if (m_type != b2_dynamicBody)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (wake && (m_flags & e_awakeFlag) == 0)
|
||||
{
|
||||
SetAwake(true);
|
||||
}
|
||||
|
||||
// Don't accumulate velocity if the body is sleeping
|
||||
if (m_flags & e_awakeFlag)
|
||||
{
|
||||
m_linearVelocity += m_invMass * impulse;
|
||||
m_angularVelocity += m_invI * b2Cross(point - m_sweep.c, impulse);
|
||||
}
|
||||
}
|
||||
|
||||
inline void b2Body::ApplyAngularImpulse(float32 impulse, bool wake)
|
||||
{
|
||||
if (m_type != b2_dynamicBody)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (wake && (m_flags & e_awakeFlag) == 0)
|
||||
{
|
||||
SetAwake(true);
|
||||
}
|
||||
|
||||
// Don't accumulate velocity if the body is sleeping
|
||||
if (m_flags & e_awakeFlag)
|
||||
{
|
||||
m_angularVelocity += m_invI * impulse;
|
||||
}
|
||||
}
|
||||
|
||||
inline void b2Body::SynchronizeTransform()
|
||||
{
|
||||
m_xf.q.Set(m_sweep.a);
|
||||
m_xf.p = m_sweep.c - b2Mul(m_xf.q, m_sweep.localCenter);
|
||||
}
|
||||
|
||||
inline void b2Body::Advance(float32 alpha)
|
||||
{
|
||||
// Advance to the new safe time. This doesn't sync the broad-phase.
|
||||
m_sweep.Advance(alpha);
|
||||
m_sweep.c = m_sweep.c0;
|
||||
m_sweep.a = m_sweep.a0;
|
||||
m_xf.q.Set(m_sweep.a);
|
||||
m_xf.p = m_sweep.c - b2Mul(m_xf.q, m_sweep.localCenter);
|
||||
}
|
||||
|
||||
inline b2World* b2Body::GetWorld()
|
||||
{
|
||||
return m_world;
|
||||
}
|
||||
|
||||
inline const b2World* b2Body::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
}
|
||||
|
||||
#endif
|
||||
52
Lib/Include/Box2D/Dynamics/b2ContactManager.h
Normal file
52
Lib/Include/Box2D/Dynamics/b2ContactManager.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_CONTACT_MANAGER_H
|
||||
#define B2_CONTACT_MANAGER_H
|
||||
|
||||
#include <Box2D/Collision/b2BroadPhase.h>
|
||||
|
||||
class b2Contact;
|
||||
class b2ContactFilter;
|
||||
class b2ContactListener;
|
||||
class b2BlockAllocator;
|
||||
|
||||
// Delegate of b2World.
|
||||
class BOX2D_API b2ContactManager
|
||||
{
|
||||
public:
|
||||
b2ContactManager();
|
||||
|
||||
// Broad-phase callback.
|
||||
void AddPair(void* proxyUserDataA, void* proxyUserDataB);
|
||||
|
||||
void FindNewContacts();
|
||||
|
||||
void Destroy(b2Contact* c);
|
||||
|
||||
void Collide();
|
||||
|
||||
b2BroadPhase m_broadPhase;
|
||||
b2Contact* m_contactList;
|
||||
int32 m_contactCount;
|
||||
b2ContactFilter* m_contactFilter;
|
||||
b2ContactListener* m_contactListener;
|
||||
b2BlockAllocator* m_allocator;
|
||||
};
|
||||
|
||||
#endif
|
||||
345
Lib/Include/Box2D/Dynamics/b2Fixture.h
Normal file
345
Lib/Include/Box2D/Dynamics/b2Fixture.h
Normal file
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_FIXTURE_H
|
||||
#define B2_FIXTURE_H
|
||||
|
||||
#include <Box2D/Dynamics/b2Body.h>
|
||||
#include <Box2D/Collision/b2Collision.h>
|
||||
#include <Box2D/Collision/Shapes/b2Shape.h>
|
||||
|
||||
class b2BlockAllocator;
|
||||
class b2Body;
|
||||
class b2BroadPhase;
|
||||
class b2Fixture;
|
||||
|
||||
/// This holds contact filtering data.
|
||||
struct BOX2D_API b2Filter
|
||||
{
|
||||
b2Filter()
|
||||
{
|
||||
categoryBits = 0x0001;
|
||||
maskBits = 0xFFFF;
|
||||
groupIndex = 0;
|
||||
}
|
||||
|
||||
/// The collision category bits. Normally you would just set one bit.
|
||||
uint16 categoryBits;
|
||||
|
||||
/// The collision mask bits. This states the categories that this
|
||||
/// shape would accept for collision.
|
||||
uint16 maskBits;
|
||||
|
||||
/// Collision groups allow a certain group of objects to never collide (negative)
|
||||
/// or always collide (positive). Zero means no collision group. Non-zero group
|
||||
/// filtering always wins against the mask bits.
|
||||
int16 groupIndex;
|
||||
};
|
||||
|
||||
/// A fixture definition is used to create a fixture. This class defines an
|
||||
/// abstract fixture definition. You can reuse fixture definitions safely.
|
||||
struct b2FixtureDef
|
||||
{
|
||||
/// The constructor sets the default fixture definition values.
|
||||
b2FixtureDef()
|
||||
{
|
||||
shape = NULL;
|
||||
userData = NULL;
|
||||
friction = 0.2f;
|
||||
restitution = 0.0f;
|
||||
density = 0.0f;
|
||||
isSensor = false;
|
||||
}
|
||||
|
||||
/// The shape, this must be set. The shape will be cloned, so you
|
||||
/// can create the shape on the stack.
|
||||
const b2Shape* shape;
|
||||
|
||||
/// Use this to store application specific fixture data.
|
||||
void* userData;
|
||||
|
||||
/// The friction coefficient, usually in the range [0,1].
|
||||
float32 friction;
|
||||
|
||||
/// The restitution (elasticity) usually in the range [0,1].
|
||||
float32 restitution;
|
||||
|
||||
/// The density, usually in kg/m^2.
|
||||
float32 density;
|
||||
|
||||
/// A sensor shape collects contact information but never generates a collision
|
||||
/// response.
|
||||
bool isSensor;
|
||||
|
||||
/// Contact filtering data.
|
||||
b2Filter filter;
|
||||
};
|
||||
|
||||
/// This proxy is used internally to connect fixtures to the broad-phase.
|
||||
struct b2FixtureProxy
|
||||
{
|
||||
b2AABB aabb;
|
||||
b2Fixture* fixture;
|
||||
int32 childIndex;
|
||||
int32 proxyId;
|
||||
};
|
||||
|
||||
/// A fixture is used to attach a shape to a body for collision detection. A fixture
|
||||
/// inherits its transform from its parent. Fixtures hold additional non-geometric data
|
||||
/// such as friction, collision filters, etc.
|
||||
/// Fixtures are created via b2Body::CreateFixture.
|
||||
/// @warning you cannot reuse fixtures.
|
||||
class BOX2D_API b2Fixture
|
||||
{
|
||||
public:
|
||||
/// Get the type of the child shape. You can use this to down cast to the concrete shape.
|
||||
/// @return the shape type.
|
||||
b2Shape::Type GetType() const;
|
||||
|
||||
/// Get the child shape. You can modify the child shape, however you should not change the
|
||||
/// number of vertices because this will crash some collision caching mechanisms.
|
||||
/// Manipulating the shape may lead to non-physical behavior.
|
||||
b2Shape* GetShape();
|
||||
const b2Shape* GetShape() const;
|
||||
|
||||
/// Set if this fixture is a sensor.
|
||||
void SetSensor(bool sensor);
|
||||
|
||||
/// Is this fixture a sensor (non-solid)?
|
||||
/// @return the true if the shape is a sensor.
|
||||
bool IsSensor() const;
|
||||
|
||||
/// Set the contact filtering data. This will not update contacts until the next time
|
||||
/// step when either parent body is active and awake.
|
||||
/// This automatically calls Refilter.
|
||||
void SetFilterData(const b2Filter& filter);
|
||||
|
||||
/// Get the contact filtering data.
|
||||
const b2Filter& GetFilterData() const;
|
||||
|
||||
/// Call this if you want to establish collision that was previously disabled by b2ContactFilter::ShouldCollide.
|
||||
void Refilter();
|
||||
|
||||
/// Get the parent body of this fixture. This is NULL if the fixture is not attached.
|
||||
/// @return the parent body.
|
||||
b2Body* GetBody();
|
||||
const b2Body* GetBody() const;
|
||||
|
||||
/// Get the next fixture in the parent body's fixture list.
|
||||
/// @return the next shape.
|
||||
b2Fixture* GetNext();
|
||||
const b2Fixture* GetNext() const;
|
||||
|
||||
/// Get the user data that was assigned in the fixture definition. Use this to
|
||||
/// store your application specific data.
|
||||
void* GetUserData() const;
|
||||
|
||||
/// Set the user data. Use this to store your application specific data.
|
||||
void SetUserData(void* data);
|
||||
|
||||
/// Test a point for containment in this fixture.
|
||||
/// @param p a point in world coordinates.
|
||||
bool TestPoint(const b2Vec2& p) const;
|
||||
|
||||
/// Cast a ray against this shape.
|
||||
/// @param output the ray-cast results.
|
||||
/// @param input the ray-cast input parameters.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, int32 childIndex) const;
|
||||
|
||||
/// Get the mass data for this fixture. The mass data is based on the density and
|
||||
/// the shape. The rotational inertia is about the shape's origin. This operation
|
||||
/// may be expensive.
|
||||
void GetMassData(b2MassData* massData) const;
|
||||
|
||||
/// Set the density of this fixture. This will _not_ automatically adjust the mass
|
||||
/// of the body. You must call b2Body::ResetMassData to update the body's mass.
|
||||
void SetDensity(float32 density);
|
||||
|
||||
/// Get the density of this fixture.
|
||||
float32 GetDensity() const;
|
||||
|
||||
/// Get the coefficient of friction.
|
||||
float32 GetFriction() const;
|
||||
|
||||
/// Set the coefficient of friction. This will _not_ change the friction of
|
||||
/// existing contacts.
|
||||
void SetFriction(float32 friction);
|
||||
|
||||
/// Get the coefficient of restitution.
|
||||
float32 GetRestitution() const;
|
||||
|
||||
/// Set the coefficient of restitution. This will _not_ change the restitution of
|
||||
/// existing contacts.
|
||||
void SetRestitution(float32 restitution);
|
||||
|
||||
/// Get the fixture's AABB. This AABB may be enlarge and/or stale.
|
||||
/// If you need a more accurate AABB, compute it using the shape and
|
||||
/// the body transform.
|
||||
const b2AABB& GetAABB(int32 childIndex) const;
|
||||
|
||||
/// Dump this fixture to the log file.
|
||||
void Dump(int32 bodyIndex);
|
||||
|
||||
protected:
|
||||
|
||||
friend class b2Body;
|
||||
friend class b2World;
|
||||
friend class b2Contact;
|
||||
friend class b2ContactManager;
|
||||
|
||||
b2Fixture();
|
||||
|
||||
// We need separation create/destroy functions from the constructor/destructor because
|
||||
// the destructor cannot access the allocator (no destructor arguments allowed by C++).
|
||||
void Create(b2BlockAllocator* allocator, b2Body* body, const b2FixtureDef* def);
|
||||
void Destroy(b2BlockAllocator* allocator);
|
||||
|
||||
// These support body activation/deactivation.
|
||||
void CreateProxies(b2BroadPhase* broadPhase, const b2Transform& xf);
|
||||
void DestroyProxies(b2BroadPhase* broadPhase);
|
||||
|
||||
void Synchronize(b2BroadPhase* broadPhase, const b2Transform& xf1, const b2Transform& xf2);
|
||||
|
||||
float32 m_density;
|
||||
|
||||
b2Fixture* m_next;
|
||||
b2Body* m_body;
|
||||
|
||||
b2Shape* m_shape;
|
||||
|
||||
float32 m_friction;
|
||||
float32 m_restitution;
|
||||
|
||||
b2FixtureProxy* m_proxies;
|
||||
int32 m_proxyCount;
|
||||
|
||||
b2Filter m_filter;
|
||||
|
||||
bool m_isSensor;
|
||||
|
||||
void* m_userData;
|
||||
};
|
||||
|
||||
inline b2Shape::Type b2Fixture::GetType() const
|
||||
{
|
||||
return m_shape->GetType();
|
||||
}
|
||||
|
||||
inline b2Shape* b2Fixture::GetShape()
|
||||
{
|
||||
return m_shape;
|
||||
}
|
||||
|
||||
inline const b2Shape* b2Fixture::GetShape() const
|
||||
{
|
||||
return m_shape;
|
||||
}
|
||||
|
||||
inline bool b2Fixture::IsSensor() const
|
||||
{
|
||||
return m_isSensor;
|
||||
}
|
||||
|
||||
inline const b2Filter& b2Fixture::GetFilterData() const
|
||||
{
|
||||
return m_filter;
|
||||
}
|
||||
|
||||
inline void* b2Fixture::GetUserData() const
|
||||
{
|
||||
return m_userData;
|
||||
}
|
||||
|
||||
inline void b2Fixture::SetUserData(void* data)
|
||||
{
|
||||
m_userData = data;
|
||||
}
|
||||
|
||||
inline b2Body* b2Fixture::GetBody()
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
inline const b2Body* b2Fixture::GetBody() const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
inline b2Fixture* b2Fixture::GetNext()
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
inline const b2Fixture* b2Fixture::GetNext() const
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
inline void b2Fixture::SetDensity(float32 density)
|
||||
{
|
||||
b2Assert(b2IsValid(density) && density >= 0.0f);
|
||||
m_density = density;
|
||||
}
|
||||
|
||||
inline float32 b2Fixture::GetDensity() const
|
||||
{
|
||||
return m_density;
|
||||
}
|
||||
|
||||
inline float32 b2Fixture::GetFriction() const
|
||||
{
|
||||
return m_friction;
|
||||
}
|
||||
|
||||
inline void b2Fixture::SetFriction(float32 friction)
|
||||
{
|
||||
m_friction = friction;
|
||||
}
|
||||
|
||||
inline float32 b2Fixture::GetRestitution() const
|
||||
{
|
||||
return m_restitution;
|
||||
}
|
||||
|
||||
inline void b2Fixture::SetRestitution(float32 restitution)
|
||||
{
|
||||
m_restitution = restitution;
|
||||
}
|
||||
|
||||
inline bool b2Fixture::TestPoint(const b2Vec2& p) const
|
||||
{
|
||||
return m_shape->TestPoint(m_body->GetTransform(), p);
|
||||
}
|
||||
|
||||
inline bool b2Fixture::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, int32 childIndex) const
|
||||
{
|
||||
return m_shape->RayCast(output, input, m_body->GetTransform(), childIndex);
|
||||
}
|
||||
|
||||
inline void b2Fixture::GetMassData(b2MassData* massData) const
|
||||
{
|
||||
m_shape->ComputeMass(massData, m_density);
|
||||
}
|
||||
|
||||
inline const b2AABB& b2Fixture::GetAABB(int32 childIndex) const
|
||||
{
|
||||
b2Assert(0 <= childIndex && childIndex < m_proxyCount);
|
||||
return m_proxies[childIndex].aabb;
|
||||
}
|
||||
|
||||
#endif
|
||||
93
Lib/Include/Box2D/Dynamics/b2Island.h
Normal file
93
Lib/Include/Box2D/Dynamics/b2Island.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_ISLAND_H
|
||||
#define B2_ISLAND_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
#include <Box2D/Dynamics/b2Body.h>
|
||||
#include <Box2D/Dynamics/b2TimeStep.h>
|
||||
|
||||
class b2Contact;
|
||||
class b2Joint;
|
||||
class b2StackAllocator;
|
||||
class b2ContactListener;
|
||||
struct b2ContactVelocityConstraint;
|
||||
struct b2Profile;
|
||||
|
||||
/// This is an internal class.
|
||||
class b2Island
|
||||
{
|
||||
public:
|
||||
b2Island(int32 bodyCapacity, int32 contactCapacity, int32 jointCapacity,
|
||||
b2StackAllocator* allocator, b2ContactListener* listener);
|
||||
~b2Island();
|
||||
|
||||
void Clear()
|
||||
{
|
||||
m_bodyCount = 0;
|
||||
m_contactCount = 0;
|
||||
m_jointCount = 0;
|
||||
}
|
||||
|
||||
void Solve(b2Profile* profile, const b2TimeStep& step, const b2Vec2& gravity, bool allowSleep);
|
||||
|
||||
void SolveTOI(const b2TimeStep& subStep, int32 toiIndexA, int32 toiIndexB);
|
||||
|
||||
void Add(b2Body* body)
|
||||
{
|
||||
b2Assert(m_bodyCount < m_bodyCapacity);
|
||||
body->m_islandIndex = m_bodyCount;
|
||||
m_bodies[m_bodyCount] = body;
|
||||
++m_bodyCount;
|
||||
}
|
||||
|
||||
void Add(b2Contact* contact)
|
||||
{
|
||||
b2Assert(m_contactCount < m_contactCapacity);
|
||||
m_contacts[m_contactCount++] = contact;
|
||||
}
|
||||
|
||||
void Add(b2Joint* joint)
|
||||
{
|
||||
b2Assert(m_jointCount < m_jointCapacity);
|
||||
m_joints[m_jointCount++] = joint;
|
||||
}
|
||||
|
||||
void Report(const b2ContactVelocityConstraint* constraints);
|
||||
|
||||
b2StackAllocator* m_allocator;
|
||||
b2ContactListener* m_listener;
|
||||
|
||||
b2Body** m_bodies;
|
||||
b2Contact** m_contacts;
|
||||
b2Joint** m_joints;
|
||||
|
||||
b2Position* m_positions;
|
||||
b2Velocity* m_velocities;
|
||||
|
||||
int32 m_bodyCount;
|
||||
int32 m_jointCount;
|
||||
int32 m_contactCount;
|
||||
|
||||
int32 m_bodyCapacity;
|
||||
int32 m_contactCapacity;
|
||||
int32 m_jointCapacity;
|
||||
};
|
||||
|
||||
#endif
|
||||
70
Lib/Include/Box2D/Dynamics/b2TimeStep.h
Normal file
70
Lib/Include/Box2D/Dynamics/b2TimeStep.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_TIME_STEP_H
|
||||
#define B2_TIME_STEP_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
|
||||
/// Profiling data. Times are in milliseconds.
|
||||
struct b2Profile
|
||||
{
|
||||
float32 step;
|
||||
float32 collide;
|
||||
float32 solve;
|
||||
float32 solveInit;
|
||||
float32 solveVelocity;
|
||||
float32 solvePosition;
|
||||
float32 broadphase;
|
||||
float32 solveTOI;
|
||||
};
|
||||
|
||||
/// This is an internal structure.
|
||||
struct b2TimeStep
|
||||
{
|
||||
float32 dt; // time step
|
||||
float32 inv_dt; // inverse time step (0 if dt == 0).
|
||||
float32 dtRatio; // dt * inv_dt0
|
||||
int32 velocityIterations;
|
||||
int32 positionIterations;
|
||||
bool warmStarting;
|
||||
};
|
||||
|
||||
/// This is an internal structure.
|
||||
struct b2Position
|
||||
{
|
||||
b2Vec2 c;
|
||||
float32 a;
|
||||
};
|
||||
|
||||
/// This is an internal structure.
|
||||
struct b2Velocity
|
||||
{
|
||||
b2Vec2 v;
|
||||
float32 w;
|
||||
};
|
||||
|
||||
/// Solver Data
|
||||
struct b2SolverData
|
||||
{
|
||||
b2TimeStep step;
|
||||
b2Position* positions;
|
||||
b2Velocity* velocities;
|
||||
};
|
||||
|
||||
#endif
|
||||
354
Lib/Include/Box2D/Dynamics/b2World.h
Normal file
354
Lib/Include/Box2D/Dynamics/b2World.h
Normal file
@@ -0,0 +1,354 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_WORLD_H
|
||||
#define B2_WORLD_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
#include <Box2D/Common/b2BlockAllocator.h>
|
||||
#include <Box2D/Common/b2StackAllocator.h>
|
||||
#include <Box2D/Dynamics/b2ContactManager.h>
|
||||
#include <Box2D/Dynamics/b2WorldCallbacks.h>
|
||||
#include <Box2D/Dynamics/b2TimeStep.h>
|
||||
|
||||
struct b2AABB;
|
||||
struct b2BodyDef;
|
||||
struct b2Color;
|
||||
struct b2JointDef;
|
||||
class b2Body;
|
||||
class b2Draw;
|
||||
class b2Fixture;
|
||||
class b2Joint;
|
||||
|
||||
/// The world class manages all physics entities, dynamic simulation,
|
||||
/// and asynchronous queries. The world also contains efficient memory
|
||||
/// management facilities.
|
||||
class BOX2D_API b2World
|
||||
{
|
||||
public:
|
||||
/// Construct a world object.
|
||||
/// @param gravity the world gravity vector.
|
||||
b2World(const b2Vec2& gravity);
|
||||
|
||||
/// Destruct the world. All physics entities are destroyed and all heap memory is released.
|
||||
~b2World();
|
||||
|
||||
/// Register a destruction listener. The listener is owned by you and must
|
||||
/// remain in scope.
|
||||
void SetDestructionListener(b2DestructionListener* listener);
|
||||
|
||||
/// Register a contact filter to provide specific control over collision.
|
||||
/// Otherwise the default filter is used (b2_defaultFilter). The listener is
|
||||
/// owned by you and must remain in scope.
|
||||
void SetContactFilter(b2ContactFilter* filter);
|
||||
|
||||
/// Register a contact event listener. The listener is owned by you and must
|
||||
/// remain in scope.
|
||||
void SetContactListener(b2ContactListener* listener);
|
||||
|
||||
/// Register a routine for debug drawing. The debug draw functions are called
|
||||
/// inside with b2World::DrawDebugData method. The debug draw object is owned
|
||||
/// by you and must remain in scope.
|
||||
void SetDebugDraw(b2Draw* debugDraw);
|
||||
|
||||
/// Create a rigid body given a definition. No reference to the definition
|
||||
/// is retained.
|
||||
/// @warning This function is locked during callbacks.
|
||||
b2Body* CreateBody(const b2BodyDef* def);
|
||||
|
||||
/// Destroy a rigid body given a definition. No reference to the definition
|
||||
/// is retained. This function is locked during callbacks.
|
||||
/// @warning This automatically deletes all associated shapes and joints.
|
||||
/// @warning This function is locked during callbacks.
|
||||
void DestroyBody(b2Body* body);
|
||||
|
||||
/// Create a joint to constrain bodies together. No reference to the definition
|
||||
/// is retained. This may cause the connected bodies to cease colliding.
|
||||
/// @warning This function is locked during callbacks.
|
||||
b2Joint* CreateJoint(const b2JointDef* def);
|
||||
|
||||
/// Destroy a joint. This may cause the connected bodies to begin colliding.
|
||||
/// @warning This function is locked during callbacks.
|
||||
void DestroyJoint(b2Joint* joint);
|
||||
|
||||
/// Take a time step. This performs collision detection, integration,
|
||||
/// and constraint solution.
|
||||
/// @param timeStep the amount of time to simulate, this should not vary.
|
||||
/// @param velocityIterations for the velocity constraint solver.
|
||||
/// @param positionIterations for the position constraint solver.
|
||||
void Step( float32 timeStep,
|
||||
int32 velocityIterations,
|
||||
int32 positionIterations);
|
||||
|
||||
/// Manually clear the force buffer on all bodies. By default, forces are cleared automatically
|
||||
/// after each call to Step. The default behavior is modified by calling SetAutoClearForces.
|
||||
/// The purpose of this function is to support sub-stepping. Sub-stepping is often used to maintain
|
||||
/// a fixed sized time step under a variable frame-rate.
|
||||
/// When you perform sub-stepping you will disable auto clearing of forces and instead call
|
||||
/// ClearForces after all sub-steps are complete in one pass of your game loop.
|
||||
/// @see SetAutoClearForces
|
||||
void ClearForces();
|
||||
|
||||
/// Call this to draw shapes and other debug draw data. This is intentionally non-const.
|
||||
void DrawDebugData();
|
||||
|
||||
/// Query the world for all fixtures that potentially overlap the
|
||||
/// provided AABB.
|
||||
/// @param callback a user implemented callback class.
|
||||
/// @param aabb the query box.
|
||||
void QueryAABB(b2QueryCallback* callback, const b2AABB& aabb) const;
|
||||
|
||||
/// Ray-cast the world for all fixtures in the path of the ray. Your callback
|
||||
/// controls whether you get the closest point, any point, or n-points.
|
||||
/// The ray-cast ignores shapes that contain the starting point.
|
||||
/// @param callback a user implemented callback class.
|
||||
/// @param point1 the ray starting point
|
||||
/// @param point2 the ray ending point
|
||||
void RayCast(b2RayCastCallback* callback, const b2Vec2& point1, const b2Vec2& point2) const;
|
||||
|
||||
/// Get the world body list. With the returned body, use b2Body::GetNext to get
|
||||
/// the next body in the world list. A NULL body indicates the end of the list.
|
||||
/// @return the head of the world body list.
|
||||
b2Body* GetBodyList();
|
||||
const b2Body* GetBodyList() const;
|
||||
|
||||
/// Get the world joint list. With the returned joint, use b2Joint::GetNext to get
|
||||
/// the next joint in the world list. A NULL joint indicates the end of the list.
|
||||
/// @return the head of the world joint list.
|
||||
b2Joint* GetJointList();
|
||||
const b2Joint* GetJointList() const;
|
||||
|
||||
/// Get the world contact list. With the returned contact, use b2Contact::GetNext to get
|
||||
/// the next contact in the world list. A NULL contact indicates the end of the list.
|
||||
/// @return the head of the world contact list.
|
||||
/// @warning contacts are created and destroyed in the middle of a time step.
|
||||
/// Use b2ContactListener to avoid missing contacts.
|
||||
b2Contact* GetContactList();
|
||||
const b2Contact* GetContactList() const;
|
||||
|
||||
/// Enable/disable sleep.
|
||||
void SetAllowSleeping(bool flag);
|
||||
bool GetAllowSleeping() const { return m_allowSleep; }
|
||||
|
||||
/// Enable/disable warm starting. For testing.
|
||||
void SetWarmStarting(bool flag) { m_warmStarting = flag; }
|
||||
bool GetWarmStarting() const { return m_warmStarting; }
|
||||
|
||||
/// Enable/disable continuous physics. For testing.
|
||||
void SetContinuousPhysics(bool flag) { m_continuousPhysics = flag; }
|
||||
bool GetContinuousPhysics() const { return m_continuousPhysics; }
|
||||
|
||||
/// Enable/disable single stepped continuous physics. For testing.
|
||||
void SetSubStepping(bool flag) { m_subStepping = flag; }
|
||||
bool GetSubStepping() const { return m_subStepping; }
|
||||
|
||||
/// Get the number of broad-phase proxies.
|
||||
int32 GetProxyCount() const;
|
||||
|
||||
/// Get the number of bodies.
|
||||
int32 GetBodyCount() const;
|
||||
|
||||
/// Get the number of joints.
|
||||
int32 GetJointCount() const;
|
||||
|
||||
/// Get the number of contacts (each may have 0 or more contact points).
|
||||
int32 GetContactCount() const;
|
||||
|
||||
/// Get the height of the dynamic tree.
|
||||
int32 GetTreeHeight() const;
|
||||
|
||||
/// Get the balance of the dynamic tree.
|
||||
int32 GetTreeBalance() const;
|
||||
|
||||
/// Get the quality metric of the dynamic tree. The smaller the better.
|
||||
/// The minimum is 1.
|
||||
float32 GetTreeQuality() const;
|
||||
|
||||
/// Change the global gravity vector.
|
||||
void SetGravity(const b2Vec2& gravity);
|
||||
|
||||
/// Get the global gravity vector.
|
||||
b2Vec2 GetGravity() const;
|
||||
|
||||
/// Is the world locked (in the middle of a time step).
|
||||
bool IsLocked() const;
|
||||
|
||||
/// Set flag to control automatic clearing of forces after each time step.
|
||||
void SetAutoClearForces(bool flag);
|
||||
|
||||
/// Get the flag that controls automatic clearing of forces after each time step.
|
||||
bool GetAutoClearForces() const;
|
||||
|
||||
/// Shift the world origin. Useful for large worlds.
|
||||
/// The body shift formula is: position -= newOrigin
|
||||
/// @param newOrigin the new origin with respect to the old origin
|
||||
void ShiftOrigin(const b2Vec2& newOrigin);
|
||||
|
||||
/// Get the contact manager for testing.
|
||||
const b2ContactManager& GetContactManager() const;
|
||||
|
||||
/// Get the current profile.
|
||||
const b2Profile& GetProfile() const;
|
||||
|
||||
/// Dump the world into the log file.
|
||||
/// @warning this should be called outside of a time step.
|
||||
void Dump();
|
||||
|
||||
private:
|
||||
|
||||
// m_flags
|
||||
enum
|
||||
{
|
||||
e_newFixture = 0x0001,
|
||||
e_locked = 0x0002,
|
||||
e_clearForces = 0x0004
|
||||
};
|
||||
|
||||
friend class b2Body;
|
||||
friend class b2Fixture;
|
||||
friend class b2ContactManager;
|
||||
friend class b2Controller;
|
||||
|
||||
void Solve(const b2TimeStep& step);
|
||||
void SolveTOI(const b2TimeStep& step);
|
||||
|
||||
void DrawJoint(b2Joint* joint);
|
||||
void DrawShape(b2Fixture* shape, const b2Transform& xf, const b2Color& color);
|
||||
|
||||
b2BlockAllocator m_blockAllocator;
|
||||
b2StackAllocator m_stackAllocator;
|
||||
|
||||
int32 m_flags;
|
||||
|
||||
b2ContactManager m_contactManager;
|
||||
|
||||
b2Body* m_bodyList;
|
||||
b2Joint* m_jointList;
|
||||
|
||||
int32 m_bodyCount;
|
||||
int32 m_jointCount;
|
||||
|
||||
b2Vec2 m_gravity;
|
||||
bool m_allowSleep;
|
||||
|
||||
b2DestructionListener* m_destructionListener;
|
||||
b2Draw* m_debugDraw;
|
||||
|
||||
// This is used to compute the time step ratio to
|
||||
// support a variable time step.
|
||||
float32 m_inv_dt0;
|
||||
|
||||
// These are for debugging the solver.
|
||||
bool m_warmStarting;
|
||||
bool m_continuousPhysics;
|
||||
bool m_subStepping;
|
||||
|
||||
bool m_stepComplete;
|
||||
|
||||
b2Profile m_profile;
|
||||
};
|
||||
|
||||
inline b2Body* b2World::GetBodyList()
|
||||
{
|
||||
return m_bodyList;
|
||||
}
|
||||
|
||||
inline const b2Body* b2World::GetBodyList() const
|
||||
{
|
||||
return m_bodyList;
|
||||
}
|
||||
|
||||
inline b2Joint* b2World::GetJointList()
|
||||
{
|
||||
return m_jointList;
|
||||
}
|
||||
|
||||
inline const b2Joint* b2World::GetJointList() const
|
||||
{
|
||||
return m_jointList;
|
||||
}
|
||||
|
||||
inline b2Contact* b2World::GetContactList()
|
||||
{
|
||||
return m_contactManager.m_contactList;
|
||||
}
|
||||
|
||||
inline const b2Contact* b2World::GetContactList() const
|
||||
{
|
||||
return m_contactManager.m_contactList;
|
||||
}
|
||||
|
||||
inline int32 b2World::GetBodyCount() const
|
||||
{
|
||||
return m_bodyCount;
|
||||
}
|
||||
|
||||
inline int32 b2World::GetJointCount() const
|
||||
{
|
||||
return m_jointCount;
|
||||
}
|
||||
|
||||
inline int32 b2World::GetContactCount() const
|
||||
{
|
||||
return m_contactManager.m_contactCount;
|
||||
}
|
||||
|
||||
inline void b2World::SetGravity(const b2Vec2& gravity)
|
||||
{
|
||||
m_gravity = gravity;
|
||||
}
|
||||
|
||||
inline b2Vec2 b2World::GetGravity() const
|
||||
{
|
||||
return m_gravity;
|
||||
}
|
||||
|
||||
inline bool b2World::IsLocked() const
|
||||
{
|
||||
return (m_flags & e_locked) == e_locked;
|
||||
}
|
||||
|
||||
inline void b2World::SetAutoClearForces(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
m_flags |= e_clearForces;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_flags &= ~e_clearForces;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the flag that controls automatic clearing of forces after each time step.
|
||||
inline bool b2World::GetAutoClearForces() const
|
||||
{
|
||||
return (m_flags & e_clearForces) == e_clearForces;
|
||||
}
|
||||
|
||||
inline const b2ContactManager& b2World::GetContactManager() const
|
||||
{
|
||||
return m_contactManager;
|
||||
}
|
||||
|
||||
inline const b2Profile& b2World::GetProfile() const
|
||||
{
|
||||
return m_profile;
|
||||
}
|
||||
|
||||
#endif
|
||||
155
Lib/Include/Box2D/Dynamics/b2WorldCallbacks.h
Normal file
155
Lib/Include/Box2D/Dynamics/b2WorldCallbacks.h
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_WORLD_CALLBACKS_H
|
||||
#define B2_WORLD_CALLBACKS_H
|
||||
|
||||
#include <Box2D/Common/b2Settings.h>
|
||||
|
||||
struct b2Vec2;
|
||||
struct b2Transform;
|
||||
class b2Fixture;
|
||||
class b2Body;
|
||||
class b2Joint;
|
||||
class b2Contact;
|
||||
struct b2ContactResult;
|
||||
struct b2Manifold;
|
||||
|
||||
/// Joints and fixtures are destroyed when their associated
|
||||
/// body is destroyed. Implement this listener so that you
|
||||
/// may nullify references to these joints and shapes.
|
||||
class BOX2D_API b2DestructionListener
|
||||
{
|
||||
public:
|
||||
virtual ~b2DestructionListener() {}
|
||||
|
||||
/// Called when any joint is about to be destroyed due
|
||||
/// to the destruction of one of its attached bodies.
|
||||
virtual void SayGoodbye(b2Joint* joint) = 0;
|
||||
|
||||
/// Called when any fixture is about to be destroyed due
|
||||
/// to the destruction of its parent body.
|
||||
virtual void SayGoodbye(b2Fixture* fixture) = 0;
|
||||
};
|
||||
|
||||
/// Implement this class to provide collision filtering. In other words, you can implement
|
||||
/// this class if you want finer control over contact creation.
|
||||
class BOX2D_API b2ContactFilter
|
||||
{
|
||||
public:
|
||||
virtual ~b2ContactFilter() {}
|
||||
|
||||
/// Return true if contact calculations should be performed between these two shapes.
|
||||
/// @warning for performance reasons this is only called when the AABBs begin to overlap.
|
||||
virtual bool ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB);
|
||||
};
|
||||
|
||||
/// Contact impulses for reporting. Impulses are used instead of forces because
|
||||
/// sub-step forces may approach infinity for rigid body collisions. These
|
||||
/// match up one-to-one with the contact points in b2Manifold.
|
||||
struct b2ContactImpulse
|
||||
{
|
||||
float32 normalImpulses[b2_maxManifoldPoints];
|
||||
float32 tangentImpulses[b2_maxManifoldPoints];
|
||||
int32 count;
|
||||
};
|
||||
|
||||
/// Implement this class to get contact information. You can use these results for
|
||||
/// things like sounds and game logic. You can also get contact results by
|
||||
/// traversing the contact lists after the time step. However, you might miss
|
||||
/// some contacts because continuous physics leads to sub-stepping.
|
||||
/// Additionally you may receive multiple callbacks for the same contact in a
|
||||
/// single time step.
|
||||
/// You should strive to make your callbacks efficient because there may be
|
||||
/// many callbacks per time step.
|
||||
/// @warning You cannot create/destroy Box2D entities inside these callbacks.
|
||||
class BOX2D_API b2ContactListener
|
||||
{
|
||||
public:
|
||||
virtual ~b2ContactListener() {}
|
||||
|
||||
/// Called when two fixtures begin to touch.
|
||||
virtual void BeginContact(b2Contact* contact) { B2_NOT_USED(contact); }
|
||||
|
||||
/// Called when two fixtures cease to touch.
|
||||
virtual void EndContact(b2Contact* contact) { B2_NOT_USED(contact); }
|
||||
|
||||
/// This is called after a contact is updated. This allows you to inspect a
|
||||
/// contact before it goes to the solver. If you are careful, you can modify the
|
||||
/// contact manifold (e.g. disable contact).
|
||||
/// A copy of the old manifold is provided so that you can detect changes.
|
||||
/// Note: this is called only for awake bodies.
|
||||
/// Note: this is called even when the number of contact points is zero.
|
||||
/// Note: this is not called for sensors.
|
||||
/// Note: if you set the number of contact points to zero, you will not
|
||||
/// get an EndContact callback. However, you may get a BeginContact callback
|
||||
/// the next step.
|
||||
virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
|
||||
{
|
||||
B2_NOT_USED(contact);
|
||||
B2_NOT_USED(oldManifold);
|
||||
}
|
||||
|
||||
/// This lets you inspect a contact after the solver is finished. This is useful
|
||||
/// for inspecting impulses.
|
||||
/// Note: the contact manifold does not include time of impact impulses, which can be
|
||||
/// arbitrarily large if the sub-step is small. Hence the impulse is provided explicitly
|
||||
/// in a separate data structure.
|
||||
/// Note: this is only called for contacts that are touching, solid, and awake.
|
||||
virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
|
||||
{
|
||||
B2_NOT_USED(contact);
|
||||
B2_NOT_USED(impulse);
|
||||
}
|
||||
};
|
||||
|
||||
/// Callback class for AABB queries.
|
||||
/// See b2World::Query
|
||||
class BOX2D_API b2QueryCallback
|
||||
{
|
||||
public:
|
||||
virtual ~b2QueryCallback() {}
|
||||
|
||||
/// Called for each fixture found in the query AABB.
|
||||
/// @return false to terminate the query.
|
||||
virtual bool ReportFixture(b2Fixture* fixture) = 0;
|
||||
};
|
||||
|
||||
/// Callback class for ray casts.
|
||||
/// See b2World::RayCast
|
||||
class BOX2D_API b2RayCastCallback
|
||||
{
|
||||
public:
|
||||
virtual ~b2RayCastCallback() {}
|
||||
|
||||
/// Called for each fixture found in the query. You control how the ray cast
|
||||
/// proceeds by returning a float:
|
||||
/// return -1: ignore this fixture and continue
|
||||
/// return 0: terminate the ray cast
|
||||
/// return fraction: clip the ray to this point
|
||||
/// return 1: don't clip the ray and continue
|
||||
/// @param fixture the fixture hit by the ray
|
||||
/// @param point the point of initial intersection
|
||||
/// @param normal the normal vector at the point of intersection
|
||||
/// @return -1 to filter, 0 to terminate, fraction to clip the ray for
|
||||
/// closest hit, 1 to continue
|
||||
virtual float32 ReportFixture( b2Fixture* fixture, const b2Vec2& point,
|
||||
const b2Vec2& normal, float32 fraction) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
115
Lib/Include/Box2D/Rope/b2Rope.h
Normal file
115
Lib/Include/Box2D/Rope/b2Rope.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B2_ROPE_H
|
||||
#define B2_ROPE_H
|
||||
|
||||
#include <Box2D/Common/b2Math.h>
|
||||
|
||||
class b2Draw;
|
||||
|
||||
///
|
||||
struct b2RopeDef
|
||||
{
|
||||
b2RopeDef()
|
||||
{
|
||||
vertices = NULL;
|
||||
count = 0;
|
||||
masses = NULL;
|
||||
gravity.SetZero();
|
||||
damping = 0.1f;
|
||||
k2 = 0.9f;
|
||||
k3 = 0.1f;
|
||||
}
|
||||
|
||||
///
|
||||
b2Vec2* vertices;
|
||||
|
||||
///
|
||||
int32 count;
|
||||
|
||||
///
|
||||
float32* masses;
|
||||
|
||||
///
|
||||
b2Vec2 gravity;
|
||||
|
||||
///
|
||||
float32 damping;
|
||||
|
||||
/// Stretching stiffness
|
||||
float32 k2;
|
||||
|
||||
/// Bending stiffness. Values above 0.5 can make the simulation blow up.
|
||||
float32 k3;
|
||||
};
|
||||
|
||||
///
|
||||
class b2Rope
|
||||
{
|
||||
public:
|
||||
b2Rope();
|
||||
~b2Rope();
|
||||
|
||||
///
|
||||
void Initialize(const b2RopeDef* def);
|
||||
|
||||
///
|
||||
void Step(float32 timeStep, int32 iterations);
|
||||
|
||||
///
|
||||
int32 GetVertexCount() const
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
///
|
||||
const b2Vec2* GetVertices() const
|
||||
{
|
||||
return m_ps;
|
||||
}
|
||||
|
||||
///
|
||||
void Draw(b2Draw* draw) const;
|
||||
|
||||
///
|
||||
void SetAngle(float32 angle);
|
||||
|
||||
private:
|
||||
|
||||
void SolveC2();
|
||||
void SolveC3();
|
||||
|
||||
int32 m_count;
|
||||
b2Vec2* m_ps;
|
||||
b2Vec2* m_p0s;
|
||||
b2Vec2* m_vs;
|
||||
|
||||
float32* m_ims;
|
||||
|
||||
float32* m_Ls;
|
||||
float32* m_as;
|
||||
|
||||
b2Vec2 m_gravity;
|
||||
float32 m_damping;
|
||||
|
||||
float32 m_k2;
|
||||
float32 m_k3;
|
||||
};
|
||||
|
||||
#endif
|
||||
75
Lib/Include/CML/cml.h
Normal file
75
Lib/Include/CML/cml.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief Main CML header to include all CML functionality.
|
||||
*
|
||||
* @todo load vectors, matrices, and quaternions from a stream.
|
||||
*
|
||||
* @todo Move common vector and matrix class ops to a base class (requires
|
||||
* SCOOP-like programming, see below).
|
||||
*
|
||||
* @todo Implement matrix<>::orthogonalize().
|
||||
*
|
||||
* @todo Add is_square<>, is_rectangular<>, etc. to make it easier to
|
||||
* detect specific matrix types.
|
||||
*
|
||||
* @todo Implement dedicated square matrix classes to get rid of duplicated
|
||||
* code in the specialized matrix classes.
|
||||
*
|
||||
* @todo Implement automatic temporary generation, along with expression
|
||||
* node return types for mat-vec and mat-mat operators.
|
||||
*
|
||||
* @todo switch to ssize_t instead of size_t to avoid having to explicitly
|
||||
* deal with wrap-arounds to 2^32-1 when a size_t is subtracted from.
|
||||
*
|
||||
* @todo Finish tests for mat-vec multiply.
|
||||
*
|
||||
* @todo Differentiate between references used for function arguments, and
|
||||
* those used for variable types. In particular, GCC 3.4 requires const T &
|
||||
* function arguments to ensure complete unrolling/inlining of expressions.
|
||||
*
|
||||
* @todo Specialize matrix multiplication based upon the size type (fixed or
|
||||
* dynamic). This makes a difference for at least GCC 3.4.
|
||||
*
|
||||
* @todo need a build system for the tests/ and examples/ directories.
|
||||
*
|
||||
* @todo clean up the testing infrastructure, and make it easier to add new
|
||||
* tests
|
||||
*
|
||||
* @todo figure out if scalars should be passed by value or reference, or
|
||||
* if it should be determined by traits
|
||||
*
|
||||
* @todo change use of typename and class to be like Alexandrescu book
|
||||
*
|
||||
* @todo figure out if it makes sense to unroll assignment if either the
|
||||
* source expression or the target vector/matrix has a fixed size (right
|
||||
* now, unrolling happens only if the target has a fixed size)
|
||||
*
|
||||
* @todo Allow addition of new types, a la glommable ETs (but simpler).
|
||||
* Can use ideas from "SCOOP" method: Nicolas Burrus, Alexandre Duret-Lutz,
|
||||
* Thierry G<>raud, David Lesage and Rapha<68>l Poss. A Static C++
|
||||
* Object-Oriented Programming (SCOOP) Paradigm Mixing Benefits of
|
||||
* Traditional OOP and Generic Programming. In the Proceedings of the
|
||||
* Workshop on Multiple Paradigm with OO Languages (MPOOL'03) Anaheim, CA,
|
||||
* USA Oct. 2003
|
||||
*/
|
||||
|
||||
#ifndef cml_h
|
||||
#define cml_h
|
||||
|
||||
#include <cml/vector.h>
|
||||
#include <cml/matrix.h>
|
||||
#include <cml/quaternion.h>
|
||||
#include <cml/util.h>
|
||||
#include <cml/mathlib/mathlib.h>
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
89
Lib/Include/CML/constants.h
Normal file
89
Lib/Include/CML/constants.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief Useful constants.
|
||||
*/
|
||||
|
||||
#ifndef cml_constants_h
|
||||
#define cml_constants_h
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#if !defined(M_PI)
|
||||
#define M_PI 3.14159265358979323846264338327950288
|
||||
#endif
|
||||
|
||||
#if !defined(M_SQRT2)
|
||||
#define M_SQRT2 1.41421356237309504880168872420969808
|
||||
#endif
|
||||
|
||||
#if !defined(M_E)
|
||||
#define M_E 2.71828182845904523536028747135266250
|
||||
#endif
|
||||
|
||||
namespace cml {
|
||||
|
||||
#if 1
|
||||
|
||||
/** Templated constants struct.
|
||||
*
|
||||
* Either float or double can be used.
|
||||
*/
|
||||
template<typename Float>
|
||||
struct constants {
|
||||
static Float pi() { return Float(M_PI); }
|
||||
static Float two_pi() { return Float(2.*M_PI); }
|
||||
static Float inv_pi() { return Float(1./M_PI); }
|
||||
static Float inv_two_pi() { return Float(1./(2.*M_PI)); }
|
||||
static Float pi_over_2() { return Float(M_PI/2.); }
|
||||
static Float pi_over_4() { return Float(M_PI/4.); }
|
||||
static Float deg_per_rad() { return Float(180./M_PI); }
|
||||
static Float rad_per_deg() { return Float(M_PI/180.); }
|
||||
|
||||
static Float sqrt_2() { return Float(M_SQRT2); }
|
||||
static Float sqrt_3() { return Float(1.732050807568877293527446341505); }
|
||||
static Float sqrt_5() { return Float(2.236067977499789696409173668731); }
|
||||
static Float sqrt_6() { return Float(2.449489742783178098197284074705); }
|
||||
|
||||
static Float e() { return Float(M_E); }
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
/* XXX This version requires an explicit instantiation of *every* constant
|
||||
* below, e.g.:
|
||||
*
|
||||
* template<typename F> const F cml::constants<F>::pi;
|
||||
*/
|
||||
/** Templated constants struct.
|
||||
*
|
||||
* Either float or double can be used.
|
||||
*/
|
||||
template<typename Float>
|
||||
struct constants {
|
||||
static const Float pi = M_PI;
|
||||
static const Float two_pi = 2.*M_PI;
|
||||
static const Float inv_pi = 1./M_PI; /* 1/pi */
|
||||
static const Float inv_two_pi = 1./(2.*M_PI); /* 1/(2*pi) */
|
||||
static const Float pi_over_2 = M_PI/2.; /* pi/2 */
|
||||
static const Float pi_over_4 = M_PI/4.; /* pi/4 */
|
||||
static const Float deg_per_rad = 180./M_PI;
|
||||
static const Float rad_per_deg = M_PI/180.;
|
||||
static const Float sqrt_2 = M_SQRT2;
|
||||
static const Float sqrt_3 = 1.73205080756887729352744634150587237;
|
||||
static const Float sqrt_5 = 2.23606797749978969640917366873127624;
|
||||
static const Float sqrt_6 = 2.44948974278317809819728407470589139;
|
||||
static const Float e = M_E;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
97
Lib/Include/CML/core/cml_assert.h
Normal file
97
Lib/Include/CML/core/cml_assert.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*
|
||||
* Macros and template metaprogramming to implement compile- and run-time
|
||||
* assertions.
|
||||
*/
|
||||
|
||||
#ifndef cml_assert_h
|
||||
#define cml_assert_h
|
||||
|
||||
#include <cml/core/cml_meta.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/* Join preprocessor macros into a new preprocessor macro: */
|
||||
#define CML_JOIN(X,Y) CML_DO_JOIN(X,Y)
|
||||
#define CML_DO_JOIN(X,Y) CML_DO_JOIN2(X,Y)
|
||||
#define CML_DO_JOIN2(X,Y) X##Y
|
||||
|
||||
/* Change a macro value into a string: */
|
||||
#define TO_STRING(X) TO_STRING2(X)
|
||||
#define TO_STRING2(X) #X
|
||||
|
||||
/** Default undefined compile-time assertion struct. */
|
||||
template<bool T> struct STATIC_ASSERTION_FAILURE;
|
||||
|
||||
/** Struct instantiated when a true assertion is made at compile-time. */
|
||||
template<> struct STATIC_ASSERTION_FAILURE<true> {
|
||||
typedef true_type result;
|
||||
enum { value = true };
|
||||
};
|
||||
|
||||
/** Create a compile-time assertion.
|
||||
*
|
||||
* @note Compile-time assertions must be expressions that can be evaluated at
|
||||
* comile time. This means that the expression must only rely on constants,
|
||||
* enums, and/or template parameters, not variables having run-time storage
|
||||
* requirements.
|
||||
*
|
||||
* @warning Enclose expressions that have commas with parens, otherwise the
|
||||
* preprocessor will parse the commas as macro argument separators!
|
||||
*
|
||||
* @sa STATIC_ASSERTION_FAILURE
|
||||
*/
|
||||
#define CML_STATIC_REQUIRE(_E_) \
|
||||
typedef typename STATIC_ASSERTION_FAILURE<(_E_)>::result \
|
||||
CML_JOIN(__cml_assert_test_typedef_, __LINE__)
|
||||
|
||||
|
||||
/** A more meaningful compile-time assertion struct.
|
||||
*
|
||||
* The parameter M is a struct type which has been declared but not
|
||||
* defined; e.g. struct this_is_an_error.
|
||||
*
|
||||
* When used with CML_STATIC_REQUIRE_M(<expr>,M), the compiler errors will
|
||||
* contain the struct name at the point of the error.
|
||||
*/
|
||||
template<bool T, typename M> struct STATIC_ASSERTION_FAILURE_M {
|
||||
typename M::bogus result;
|
||||
};
|
||||
|
||||
/** Instantiated for true assertions. */
|
||||
template<typename M> struct STATIC_ASSERTION_FAILURE_M<true,M> {
|
||||
typedef true_type result;
|
||||
enum { value = true };
|
||||
};
|
||||
|
||||
/** Create a compile-time assertion with a message.
|
||||
*
|
||||
* @note Compile-time assertions must be expressions that can be evaluated at
|
||||
* comile time. This means that the expression must only rely on constants,
|
||||
* enums, and/or template parameters, not variables having run-time storage
|
||||
* requirements.
|
||||
*
|
||||
* @warning Enclose expressions that have commas with parens, otherwise the
|
||||
* preprocessor will parse the commas as macro argument separators!
|
||||
*
|
||||
* @sa STATIC_ASSERTION_FAILURE_M
|
||||
*/
|
||||
#define CML_STATIC_REQUIRE_M(_E_, _M_) \
|
||||
typedef typename STATIC_ASSERTION_FAILURE_M<(_E_),_M_> \
|
||||
::result CML_JOIN(__bogus_assert_type_, __LINE__)
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
24
Lib/Include/CML/core/cml_meta.h
Normal file
24
Lib/Include/CML/core/cml_meta.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief A few simple metaprogramming tools.
|
||||
*/
|
||||
|
||||
#ifndef cml_meta_h
|
||||
#define cml_meta_h
|
||||
|
||||
/* Include all of the template metaprogramming tools: */
|
||||
#include <cml/core/meta/common.h>
|
||||
#include <cml/core/meta/if.h>
|
||||
#include <cml/core/meta/switch.h>
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
87
Lib/Include/CML/core/common.h
Normal file
87
Lib/Include/CML/core/common.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef core_common_h
|
||||
#define core_common_h
|
||||
|
||||
// XXX This isn't really the right place for this.
|
||||
#if defined(_MSC_VER)
|
||||
#include <cstdlib>
|
||||
#ifndef _SSIZE_T_DEFINED
|
||||
#ifdef _WIN64
|
||||
typedef __int64 ssize_t;
|
||||
#else
|
||||
typedef _W64 int ssize_t;
|
||||
#endif
|
||||
#define _SSIZE_T_DEFINED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <cstddef> // for size_t
|
||||
#include <utility> // for std::pair<>
|
||||
#include <cml/defaults.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** 1D tag (to select array shape). */
|
||||
struct oned_tag {};
|
||||
|
||||
/** 2D tag (to select array shape). */
|
||||
struct twod_tag {};
|
||||
|
||||
/** Statically-allocated memory tag. */
|
||||
struct fixed_memory_tag {};
|
||||
|
||||
/** Dynamically-allocated memory tag. */
|
||||
struct dynamic_memory_tag {};
|
||||
|
||||
/** Externally-allocated memory tag. */
|
||||
struct external_memory_tag {};
|
||||
|
||||
/** Statically-sized tag. */
|
||||
struct fixed_size_tag {};
|
||||
|
||||
/** Runtime-sized tag. */
|
||||
struct dynamic_size_tag {};
|
||||
|
||||
/** Resizable tag. */
|
||||
struct resizable_tag {};
|
||||
|
||||
/** Not resizable tag. */
|
||||
struct not_resizable_tag {};
|
||||
|
||||
/** Unit-sized tag. */
|
||||
struct unit_size_tag {};
|
||||
|
||||
/** Row-major storage tag. */
|
||||
struct row_major {};
|
||||
|
||||
/** Col-major storage tag. */
|
||||
struct col_major {};
|
||||
|
||||
/** Row-vector matrix basis tag. */
|
||||
struct row_basis {};
|
||||
|
||||
/** Column-vector matrix basis tag. */
|
||||
struct col_basis {};
|
||||
|
||||
/* This is the pair returned from the matrix size() method, as well as from
|
||||
* the matrix expression size checking code:
|
||||
*/
|
||||
typedef std::pair<size_t,size_t> matrix_size;
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
202
Lib/Include/CML/core/dynamic_1D.h
Normal file
202
Lib/Include/CML/core/dynamic_1D.h
Normal file
@@ -0,0 +1,202 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef dynamic_1D_h
|
||||
#define dynamic_1D_h
|
||||
|
||||
#include <memory>
|
||||
#include <cml/core/common.h>
|
||||
#include <cml/dynamic.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** Dynamically-sized and allocated 1D array.
|
||||
*
|
||||
* @note The allocator should be an STL-compatible allocator.
|
||||
*
|
||||
* @internal The internal array type <em>must</em> have the proper copy
|
||||
* semantics, otherwise copy construction will fail.
|
||||
*/
|
||||
template<typename Element, class Alloc>
|
||||
class dynamic_1D
|
||||
{
|
||||
public:
|
||||
|
||||
/* Record the allocator type: */
|
||||
typedef typename Alloc::template rebind<Element>::other allocator_type;
|
||||
|
||||
/* Record the generator: */
|
||||
typedef dynamic<Alloc> generator_type;
|
||||
|
||||
/* Standard: */
|
||||
typedef typename allocator_type::value_type value_type;
|
||||
typedef typename allocator_type::pointer pointer;
|
||||
typedef typename allocator_type::reference reference;
|
||||
typedef typename allocator_type::const_reference const_reference;
|
||||
typedef typename allocator_type::const_pointer const_pointer;
|
||||
|
||||
/* For matching by memory type: */
|
||||
typedef dynamic_memory_tag memory_tag;
|
||||
|
||||
/* For matching by size type: */
|
||||
typedef dynamic_size_tag size_tag;
|
||||
|
||||
/* For matching by resizability: */
|
||||
typedef resizable_tag resizing_tag;
|
||||
|
||||
/* For matching by dimensions: */
|
||||
typedef oned_tag dimension_tag;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Dynamic arrays have no fixed size. */
|
||||
enum { array_size = -1 };
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Construct a dynamic array with no size. */
|
||||
dynamic_1D() : m_size(0), m_data(0), m_alloc() {}
|
||||
|
||||
/** Construct a dynamic array given the size. */
|
||||
explicit dynamic_1D(size_t size) : m_size(0), m_data(0), m_alloc() {
|
||||
this->resize(size);
|
||||
}
|
||||
|
||||
/** Copy construct a dynamic array. */
|
||||
dynamic_1D(const dynamic_1D& other)
|
||||
: m_size(0), m_data(0), m_alloc()
|
||||
{
|
||||
this->copy(other);
|
||||
}
|
||||
|
||||
~dynamic_1D() {
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Return the number of elements in the array. */
|
||||
size_t size() const { return m_size; }
|
||||
|
||||
/** Access to the data as a C array.
|
||||
*
|
||||
* @param i a size_t index into the array.
|
||||
* @return a mutable reference to the array value at i.
|
||||
*
|
||||
* @note This function does not range-check the argument.
|
||||
*/
|
||||
reference operator[](size_t i) { return m_data[i]; }
|
||||
|
||||
/** Const access to the data as a C array.
|
||||
*
|
||||
* @param i a size_t index into the array.
|
||||
* @return a const reference to the array value at i.
|
||||
*
|
||||
* @note This function does not range-check the argument.
|
||||
*/
|
||||
const_reference operator[](size_t i) const { return m_data[i]; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
pointer data() { return &m_data[0]; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
const_pointer data() const { return &m_data[0]; }
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Set the array size to the given value. The previous contents are
|
||||
* destroyed before reallocating the array. If s == size(),
|
||||
* nothing happens.
|
||||
*
|
||||
* @warning This is not guaranteed to preserve the original data.
|
||||
*/
|
||||
void resize(size_t s) {
|
||||
|
||||
/* Nothing to do if the size isn't changing: */
|
||||
if(s == m_size) return;
|
||||
|
||||
/* Destroy the current array contents: */
|
||||
this->destroy();
|
||||
|
||||
/* Set the new size if non-zero: */
|
||||
if(s > 0) {
|
||||
value_type* data = m_alloc.allocate(s);
|
||||
for(size_t i = 0; i < s; ++ i)
|
||||
m_alloc.construct(&data[i], value_type());
|
||||
|
||||
/* Success, save s and data: */
|
||||
m_size = s;
|
||||
m_data = data;
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy the source array. The previous contents are destroyed before
|
||||
* reallocating the array. If other == *this, nothing happens.
|
||||
*/
|
||||
void copy(const dynamic_1D& other) {
|
||||
|
||||
/* Nothing to do if it's the same array: */
|
||||
if(&other == this) return;
|
||||
|
||||
/* Destroy the current array contents: */
|
||||
this->destroy();
|
||||
|
||||
/* Set the new size if non-zero: */
|
||||
size_t s = other.size();
|
||||
if(s > 0) {
|
||||
value_type* data = m_alloc.allocate(s);
|
||||
for(size_t i = 0; i < s; ++ i)
|
||||
m_alloc.construct(&data[i], other[i]);
|
||||
|
||||
/* Success, so save the new array and the size: */
|
||||
m_size = s;
|
||||
m_data = data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Destroy the current contents of the array. */
|
||||
void destroy() {
|
||||
if(m_data) {
|
||||
for(size_t i = 0; i < m_size; ++ i)
|
||||
m_alloc.destroy(&m_data[i]);
|
||||
m_alloc.deallocate(m_data, m_size);
|
||||
m_size = 0;
|
||||
m_data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Current array size (may be 0). */
|
||||
size_t m_size;
|
||||
|
||||
/** Array data (may be NULL). */
|
||||
value_type* m_data;
|
||||
|
||||
/** Allocator for the array. */
|
||||
allocator_type m_alloc;
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
248
Lib/Include/CML/core/dynamic_2D.h
Normal file
248
Lib/Include/CML/core/dynamic_2D.h
Normal file
@@ -0,0 +1,248 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef dynamic_2D_h
|
||||
#define dynamic_2D_h
|
||||
|
||||
#include <memory>
|
||||
#include <cml/core/common.h>
|
||||
#include <cml/core/dynamic_1D.h>
|
||||
#include <cml/dynamic.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** Dynamically-sized and allocated 2D array.
|
||||
*
|
||||
* @note The allocator should be an STL-compatible allocator.
|
||||
*
|
||||
* @internal The internal array type <em>must</em> have the proper copy
|
||||
* semantics, otherwise copy construction will fail.
|
||||
*
|
||||
* @internal This class does not need a destructor.
|
||||
*/
|
||||
template<typename Element, typename Layout, class Alloc>
|
||||
class dynamic_2D
|
||||
{
|
||||
public:
|
||||
|
||||
/* Record the allocator type: */
|
||||
typedef typename Alloc::template rebind<Element>::other allocator_type;
|
||||
|
||||
/* Record the generator: */
|
||||
typedef dynamic<Alloc> generator_type;
|
||||
|
||||
/* Standard: */
|
||||
typedef typename allocator_type::value_type value_type;
|
||||
typedef typename allocator_type::pointer pointer;
|
||||
typedef typename allocator_type::reference reference;
|
||||
typedef typename allocator_type::const_reference const_reference;
|
||||
typedef typename allocator_type::const_pointer const_pointer;
|
||||
|
||||
/* For matching by memory layout: */
|
||||
typedef Layout layout;
|
||||
|
||||
/* For matching by memory type: */
|
||||
typedef dynamic_memory_tag memory_tag;
|
||||
|
||||
/* For matching by size type: */
|
||||
typedef dynamic_size_tag size_tag;
|
||||
|
||||
/* For matching by resizability: */
|
||||
typedef resizable_tag resizing_tag;
|
||||
|
||||
/* For matching by dimensions: */
|
||||
typedef twod_tag dimension_tag;
|
||||
|
||||
/* To simplify the matrix transpose operator: */
|
||||
typedef dynamic_2D<typename cml::remove_const<Element>::type,
|
||||
Layout,Alloc> transposed_type;
|
||||
|
||||
/* To simplify the matrix row and column operators: */
|
||||
typedef dynamic_1D<Element,Alloc> row_array_type;
|
||||
typedef dynamic_1D<Element,Alloc> col_array_type;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Construct a dynamic array with no size. */
|
||||
dynamic_2D() : m_rows(0), m_cols(0), m_data(0), m_alloc() {}
|
||||
|
||||
/** Construct a dynamic matrix given the dimensions. */
|
||||
explicit dynamic_2D(size_t rows, size_t cols)
|
||||
: m_rows(0), m_cols(0), m_data(0), m_alloc()
|
||||
{
|
||||
this->resize(rows, cols);
|
||||
}
|
||||
|
||||
/** Copy construct a dynamic matrix. */
|
||||
dynamic_2D(const dynamic_2D& other)
|
||||
: m_rows(0), m_cols(0), m_data(0), m_alloc()
|
||||
{
|
||||
this->copy(other);
|
||||
}
|
||||
|
||||
~dynamic_2D() {
|
||||
this->destroy();
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
enum { array_rows = -1, array_cols = -1 };
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Return the number of rows in the array. */
|
||||
size_t rows() const { return m_rows; }
|
||||
|
||||
/** Return the number of cols in the array. */
|
||||
size_t cols() const { return m_cols; }
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Access the given element of the matrix.
|
||||
*
|
||||
* @param row row of element.
|
||||
* @param col column of element.
|
||||
* @returns mutable reference.
|
||||
*/
|
||||
reference operator()(size_t row, size_t col) {
|
||||
return this->get_element(row, col, layout());
|
||||
}
|
||||
|
||||
/** Access the given element of the matrix.
|
||||
*
|
||||
* @param row row of element.
|
||||
* @param col column of element.
|
||||
* @returns const reference.
|
||||
*/
|
||||
const_reference operator()(size_t row, size_t col) const {
|
||||
return this->get_element(row, col, layout());
|
||||
}
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
pointer data() { return &m_data[0]; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
const_pointer data() const { return &m_data[0]; }
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Set the array dimensions. The previous contents are destroyed
|
||||
* before reallocating the array. If the number of rows and columns
|
||||
* isn't changing, nothing happens. Also, if either rows or cols is 0,
|
||||
* the array is cleared.
|
||||
*
|
||||
* @warning This is not guaranteed to preserve the original data.
|
||||
*/
|
||||
void resize(size_t rows, size_t cols) {
|
||||
|
||||
/* Nothing to do if the size isn't changing: */
|
||||
if(rows == m_rows && cols == m_cols) return;
|
||||
|
||||
/* Destroy the current array contents: */
|
||||
this->destroy();
|
||||
|
||||
/* Set the new size if non-zero: */
|
||||
if(rows*cols > 0) {
|
||||
value_type* data = m_alloc.allocate(rows*cols);
|
||||
for(size_t i = 0; i < rows*cols; ++ i)
|
||||
m_alloc.construct(&data[i], value_type());
|
||||
|
||||
/* Success, so save the new array and the dimensions: */
|
||||
m_rows = rows;
|
||||
m_cols = cols;
|
||||
m_data = data;
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy the other array. The previous contents are destroyed before
|
||||
* reallocating the array. If other == *this, nothing happens. Also,
|
||||
* if either other.rows() or other.cols() is 0, the array is cleared.
|
||||
*/
|
||||
void copy(const dynamic_2D& other) {
|
||||
|
||||
/* Nothing to do if it's the same array: */
|
||||
if(&other == this) return;
|
||||
|
||||
/* Destroy the current array contents: */
|
||||
this->destroy();
|
||||
|
||||
/* Set the new size if non-zero: */
|
||||
size_t rows = other.rows(), cols = other.cols();
|
||||
if(rows*cols > 0) {
|
||||
value_type* data = m_alloc.allocate(rows*cols);
|
||||
for(size_t i = 0; i < rows*cols; ++ i)
|
||||
m_alloc.construct(&data[i], other[i]);
|
||||
|
||||
/* Success, so save the new array and the dimensions: */
|
||||
m_rows = rows;
|
||||
m_cols = cols;
|
||||
m_data = data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
reference get_element(size_t row, size_t col, row_major) {
|
||||
return m_data[row*m_cols + col];
|
||||
}
|
||||
|
||||
const_reference get_element(size_t row, size_t col, row_major) const {
|
||||
return m_data[row*m_cols + col];
|
||||
}
|
||||
|
||||
reference get_element(size_t row, size_t col, col_major) {
|
||||
return m_data[col*m_rows + row];
|
||||
}
|
||||
|
||||
const_reference get_element(size_t row, size_t col, col_major) const {
|
||||
return m_data[col*m_rows + row];
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Destroy the current contents of the array. */
|
||||
void destroy() {
|
||||
if(m_data) {
|
||||
for(size_t i = 0; i < m_rows*m_cols; ++ i)
|
||||
m_alloc.destroy(&m_data[i]);
|
||||
m_alloc.deallocate(m_data, m_rows*m_cols);
|
||||
m_rows = m_cols = 0;
|
||||
m_data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Current array dimensions (may be 0,0). */
|
||||
size_t m_rows, m_cols;
|
||||
|
||||
/** Array data (may be NULL). */
|
||||
value_type* m_data;
|
||||
|
||||
/** Allocator for the array. */
|
||||
allocator_type m_alloc;
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
226
Lib/Include/CML/core/external_1D.h
Normal file
226
Lib/Include/CML/core/external_1D.h
Normal file
@@ -0,0 +1,226 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*
|
||||
* Defines the fixed-size and runtime-sized external 1D arrays.
|
||||
*
|
||||
* @todo Need a better way to designate non-resizable, run-time sized
|
||||
* arrays (e.g. by a resizeable tag).
|
||||
*/
|
||||
|
||||
#ifndef external_1D_h
|
||||
#define external_1D_h
|
||||
|
||||
#include <cml/core/common.h>
|
||||
#include <cml/core/cml_meta.h>
|
||||
#include <cml/core/cml_assert.h>
|
||||
#include <cml/external.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** Fixed-size external 1D array.
|
||||
*
|
||||
* Both the memory and the size are fixed at compile time, and cannot be
|
||||
* changed.
|
||||
*/
|
||||
template<typename Element, int Size = -1>
|
||||
class external_1D
|
||||
{
|
||||
public:
|
||||
|
||||
/* Require Size > 0: */
|
||||
CML_STATIC_REQUIRE(Size > 0);
|
||||
|
||||
/* Record the generator: */
|
||||
typedef external<Size,-1> generator_type;
|
||||
|
||||
/* Standard: */
|
||||
typedef Element value_type;
|
||||
typedef Element* pointer;
|
||||
typedef Element& reference;
|
||||
typedef const Element& const_reference;
|
||||
typedef const Element* const_pointer;
|
||||
|
||||
/* Array implementation: */
|
||||
typedef value_type array_impl[Size];
|
||||
|
||||
/* For matching by memory type: */
|
||||
typedef external_memory_tag memory_tag;
|
||||
|
||||
/* For matching by size type: */
|
||||
typedef fixed_size_tag size_tag;
|
||||
|
||||
/* For matching by resizability: */
|
||||
typedef not_resizable_tag resizing_tag;
|
||||
|
||||
/* For matching by dimensions: */
|
||||
typedef oned_tag dimension_tag;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** The length as an enumerated value. */
|
||||
enum { array_size = Size };
|
||||
|
||||
|
||||
public:
|
||||
|
||||
external_1D(pointer const ptr)
|
||||
: m_data(ptr) {}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Return the number of elements in the array. */
|
||||
size_t size() const { return size_t(array_size); }
|
||||
|
||||
/** Access to the data as a C array.
|
||||
*
|
||||
* @param i a size_t index into the array.
|
||||
* @return a mutable reference to the array value at i.
|
||||
*
|
||||
* @note This function does not range-check the argument.
|
||||
*/
|
||||
reference operator[](size_t i) { return m_data[i]; }
|
||||
|
||||
/** Const access to the data as a C array.
|
||||
*
|
||||
* @param i a size_t index into the array.
|
||||
* @return a const reference to the array value at i.
|
||||
*
|
||||
* @note This function does not range-check the argument.
|
||||
*/
|
||||
const_reference operator[](size_t i) const { return m_data[i]; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
pointer data() { return m_data; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
const_pointer data() const { return m_data; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
pointer m_data;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/* Initialization without an argument isn't allowed: */
|
||||
external_1D();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
external_1D& operator=(const external_1D&);
|
||||
};
|
||||
|
||||
/** Run-time sized external 1D array.
|
||||
*
|
||||
* Both the memory and the size are fixed at run-time, and cannot be
|
||||
* changed. This is a specialization for the case that Rows and Cols are
|
||||
* not specified (i.e. given as the default of -1,-1).
|
||||
*/
|
||||
template<typename Element>
|
||||
class external_1D<Element,-1>
|
||||
{
|
||||
public:
|
||||
|
||||
/* Record the generator. Note: this is *not* unique, as it is the same
|
||||
* generator used by external_2D. However, external_2D is used only by
|
||||
* matrix<> classes, so this is not a problem.
|
||||
*/
|
||||
typedef external<> generator_type;
|
||||
|
||||
/* Standard: */
|
||||
typedef Element value_type;
|
||||
typedef Element* pointer;
|
||||
typedef Element& reference;
|
||||
typedef const Element& const_reference;
|
||||
typedef const Element* const_pointer;
|
||||
|
||||
/* For matching by memory type: */
|
||||
typedef external_memory_tag memory_tag;
|
||||
|
||||
/* For matching by size type: */
|
||||
typedef dynamic_size_tag size_tag;
|
||||
|
||||
/* For matching by resizability: */
|
||||
typedef not_resizable_tag resizing_tag;
|
||||
|
||||
/* For matching by dimensions: */
|
||||
typedef oned_tag dimension_tag;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** The length as an enumerated value. */
|
||||
enum { array_size = -1 };
|
||||
|
||||
|
||||
public:
|
||||
|
||||
external_1D(pointer const ptr, size_t size)
|
||||
: m_data(ptr), m_size(size) {}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Return the number of elements in the array. */
|
||||
size_t size() const { return m_size; }
|
||||
|
||||
/** Access to the data as a C array.
|
||||
*
|
||||
* @param i a size_t index into the array.
|
||||
* @return a mutable reference to the array value at i.
|
||||
*
|
||||
* @note This function does not range-check the argument.
|
||||
*/
|
||||
reference operator[](size_t i) { return m_data[i]; }
|
||||
|
||||
/** Const access to the data as a C array.
|
||||
*
|
||||
* @param i a size_t index into the array.
|
||||
* @return a const reference to the array value at i.
|
||||
*
|
||||
* @note This function does not range-check the argument.
|
||||
*/
|
||||
const_reference operator[](size_t i) const { return m_data[i]; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
pointer data() { return m_data; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
const_pointer data() const { return m_data; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
pointer m_data;
|
||||
size_t m_size;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/* Initialization without an argument isn't allowed: */
|
||||
external_1D();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
external_1D& operator=(const external_1D&);
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
315
Lib/Include/CML/core/external_2D.h
Normal file
315
Lib/Include/CML/core/external_2D.h
Normal file
@@ -0,0 +1,315 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*
|
||||
* Defines the fixed-size and runtime-sized external 2D arrays.
|
||||
*
|
||||
* @todo Would casting get better performance in the external_2D<> element
|
||||
* access methods?
|
||||
*/
|
||||
|
||||
#ifndef external_2D_h
|
||||
#define external_2D_h
|
||||
|
||||
#include <cml/core/common.h>
|
||||
#include <cml/core/fixed_1D.h>
|
||||
#include <cml/core/fixed_2D.h>
|
||||
#include <cml/core/dynamic_1D.h>
|
||||
#include <cml/core/dynamic_2D.h>
|
||||
#include <cml/external.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** Fixed-size external 2D array.
|
||||
*
|
||||
* Both the memory and the size are fixed at compile time, and cannot be
|
||||
* changed.
|
||||
*/
|
||||
template<typename Element, int Rows, int Cols, typename Layout>
|
||||
class external_2D
|
||||
{
|
||||
public:
|
||||
|
||||
/* Require Rows > 0, Cols > 0: */
|
||||
CML_STATIC_REQUIRE((Rows > 0) && (Cols > 0));
|
||||
|
||||
/* Record the generator: */
|
||||
typedef external<Rows,Cols> generator_type;
|
||||
|
||||
/* Standard: */
|
||||
typedef Element value_type;
|
||||
typedef Element* pointer;
|
||||
typedef Element& reference;
|
||||
typedef const Element& const_reference;
|
||||
typedef const Element* const_pointer;
|
||||
|
||||
/* For matching by memory layout: */
|
||||
typedef Layout layout;
|
||||
|
||||
/* For matching by memory type: */
|
||||
typedef external_memory_tag memory_tag;
|
||||
|
||||
/* For matching by size type: */
|
||||
typedef fixed_size_tag size_tag;
|
||||
|
||||
/* For matching by resizability: */
|
||||
typedef not_resizable_tag resizing_tag;
|
||||
|
||||
/* For matching by dimensions: */
|
||||
typedef twod_tag dimension_tag;
|
||||
|
||||
/* To simplify the matrix transpose operator: */
|
||||
typedef fixed_2D<typename cml::remove_const<Element>::type,
|
||||
Cols,Rows,Layout> transposed_type;
|
||||
/* Note: the transposed type must be fixed_2D, since an external array
|
||||
* cannot be specified without a corresponding memory location.
|
||||
*/
|
||||
|
||||
/* To simplify the matrix row and column operators: */
|
||||
typedef fixed_1D<Element,Rows> row_array_type;
|
||||
typedef fixed_1D<Element,Cols> col_array_type;
|
||||
/* Note: the row types must be fixed_1D, since external arrays cannot be
|
||||
* specified without a memory location.
|
||||
*/
|
||||
|
||||
|
||||
public:
|
||||
|
||||
enum { array_rows = Rows, array_cols = Cols };
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Construct an external array from a pointer. */
|
||||
external_2D(value_type const ptr[Rows][Cols])
|
||||
: m_data(const_cast<pointer>(&ptr[0][0])) {}
|
||||
|
||||
/** Construct an external array from a pointer. */
|
||||
external_2D(value_type* const ptr) : m_data(ptr) {}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Return the number of rows in the array. */
|
||||
size_t rows() const { return size_t(array_rows); }
|
||||
|
||||
/** Return the number of cols in the array. */
|
||||
size_t cols() const { return size_t(array_cols); }
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Access element (row,col) of the matrix.
|
||||
*
|
||||
* @param row row of element.
|
||||
* @param col column of element.
|
||||
* @returns mutable reference.
|
||||
*
|
||||
* @note This function does not range-check the arguments.
|
||||
*/
|
||||
reference operator()(size_t row, size_t col) {
|
||||
/* Dispatch to the right function based on layout: */
|
||||
return get_element(row,col,layout());
|
||||
}
|
||||
|
||||
/** Const access element (row,col) of the matrix.
|
||||
*
|
||||
* @param row row of element.
|
||||
* @param col column of element.
|
||||
* @returns const reference.
|
||||
*
|
||||
* @note This function does not range-check the arguments.
|
||||
*/
|
||||
const_reference operator()(size_t row, size_t col) const {
|
||||
/* Dispatch to the right function based on layout: */
|
||||
return get_element(row,col,layout());
|
||||
}
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
pointer data() { return m_data; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
const_pointer data() const { return m_data; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/* XXX May be able to cast to get better performance? */
|
||||
reference get_element(size_t row, size_t col, row_major) {
|
||||
return m_data[row*Cols + col];
|
||||
}
|
||||
|
||||
const_reference get_element(size_t row, size_t col, row_major) const {
|
||||
return m_data[row*Cols + col];
|
||||
}
|
||||
|
||||
reference get_element(size_t row, size_t col, col_major) {
|
||||
return m_data[col*Rows + row];
|
||||
}
|
||||
|
||||
const_reference get_element(size_t row, size_t col, col_major) const {
|
||||
return m_data[col*Rows + row];
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/* Declare the data array: */
|
||||
pointer m_data;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
external_2D& operator=(const external_2D&);
|
||||
};
|
||||
|
||||
/** Run-time sized external 2D array.
|
||||
*
|
||||
* Both the memory and the size are fixed at run-time, but cannot be changed.
|
||||
* This is a specialization for the case that Rows and Cols are not specified
|
||||
* (i.e. given as the default of -1,-1).
|
||||
*/
|
||||
template<typename Element, typename Layout>
|
||||
class external_2D<Element,-1,-1,Layout>
|
||||
{
|
||||
public:
|
||||
|
||||
/* Record the generator. Note: this is *not* unique, as it is the same
|
||||
* generator used by external_1D. However, external_1D is used only by
|
||||
* vector<> classes, so this is not a problem.
|
||||
*/
|
||||
typedef external<> generator_type;
|
||||
|
||||
/* Standard: */
|
||||
typedef Element value_type;
|
||||
typedef Element* pointer;
|
||||
typedef Element& reference;
|
||||
typedef const Element& const_reference;
|
||||
typedef const Element* const_pointer;
|
||||
|
||||
/* For matching by memory layout: */
|
||||
typedef Layout layout;
|
||||
|
||||
/* For matching by memory type: */
|
||||
typedef external_memory_tag memory_tag;
|
||||
|
||||
/* For matching by size type: */
|
||||
typedef dynamic_size_tag size_tag;
|
||||
|
||||
/* For matching by resizability: */
|
||||
typedef not_resizable_tag resizing_tag;
|
||||
|
||||
/* For matching by dimensions: */
|
||||
typedef twod_tag dimension_tag;
|
||||
|
||||
/* To simplify the matrix transpose operator: */
|
||||
typedef dynamic_2D<typename cml::remove_const<Element>::type,
|
||||
Layout, CML_DEFAULT_ARRAY_ALLOC> transposed_type;
|
||||
|
||||
/* To simplify the matrix row and column operators: */
|
||||
typedef dynamic_1D<Element, CML_DEFAULT_ARRAY_ALLOC> row_array_type;
|
||||
typedef dynamic_1D<Element, CML_DEFAULT_ARRAY_ALLOC> col_array_type;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
enum { array_rows = -1, array_cols = -1 };
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Construct an external array with no size. */
|
||||
external_2D(pointer const ptr, size_t rows, size_t cols)
|
||||
: m_data(ptr), m_rows(rows), m_cols(cols) {}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Return the number of rows in the array. */
|
||||
size_t rows() const { return m_rows; }
|
||||
|
||||
/** Return the number of cols in the array. */
|
||||
size_t cols() const { return m_cols; }
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Access element (row,col) of the matrix.
|
||||
*
|
||||
* @param row row of element.
|
||||
* @param col column of element.
|
||||
* @returns mutable reference.
|
||||
*
|
||||
* @note This function does not range-check the arguments.
|
||||
*/
|
||||
reference operator()(size_t row, size_t col) {
|
||||
/* Dispatch to the right function based on layout: */
|
||||
return get_element(row,col,layout());
|
||||
}
|
||||
|
||||
/** Const access element (row,col) of the matrix.
|
||||
*
|
||||
* @param row row of element.
|
||||
* @param col column of element.
|
||||
* @returns const reference.
|
||||
*
|
||||
* @note This function does not range-check the arguments.
|
||||
*/
|
||||
const_reference operator()(size_t row, size_t col) const {
|
||||
/* Dispatch to the right function based on layout: */
|
||||
return get_element(row,col,layout());
|
||||
}
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
pointer data() { return m_data; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
const_pointer data() const { return m_data; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/* XXX May be able to cast to get better performance? */
|
||||
reference get_element(size_t row, size_t col, row_major) {
|
||||
return m_data[row*m_cols + col];
|
||||
}
|
||||
|
||||
const_reference get_element(size_t row, size_t col, row_major) const {
|
||||
return m_data[row*m_cols + col];
|
||||
}
|
||||
|
||||
reference get_element(size_t row, size_t col, col_major) {
|
||||
return m_data[col*m_rows + row];
|
||||
}
|
||||
|
||||
const_reference get_element(size_t row, size_t col, col_major) const {
|
||||
return m_data[col*m_rows + row];
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/* Declare the data array: */
|
||||
value_type* m_data;
|
||||
size_t m_rows;
|
||||
size_t m_cols;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
external_2D& operator=(const external_2D&);
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
135
Lib/Include/CML/core/fixed_1D.h
Normal file
135
Lib/Include/CML/core/fixed_1D.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef fixed_1D_h
|
||||
#define fixed_1D_h
|
||||
|
||||
#include <cml/core/common.h>
|
||||
#include <cml/core/cml_meta.h>
|
||||
#include <cml/core/cml_assert.h>
|
||||
#include <cml/fixed.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** Statically-allocated array.
|
||||
*
|
||||
* @note This class is designed to have the same size as a C array with the
|
||||
* same length. It's therefore possible (but not recommended!) to coerce
|
||||
* a normal C array into a fixed_1D<> like this:
|
||||
*
|
||||
* typedef fixed_1D<double,10> array;
|
||||
* double c_array[10];
|
||||
* array& array_object = *((array*)&c_array);
|
||||
* double e1 = array_object[1];
|
||||
*
|
||||
* It's also possible to do this with a pointer to an array of values (e.g. a
|
||||
* double*), whether or not it was actually declared as a fixed C array. This
|
||||
* is HIGHLY DISCOURAGED, though. It's relatively straightforward to implement
|
||||
* a separate class to take a C array (or pointer) and turn it into an array
|
||||
* object.
|
||||
*
|
||||
* @sa cml::fixed
|
||||
*
|
||||
* @internal Do <em>not</em> add the empty constructor and destructor; at
|
||||
* least one compiler (Intel C++ 9.0) fails to optimize them away, and they
|
||||
* aren't needed anyway here.
|
||||
*/
|
||||
template<typename Element, int Size>
|
||||
class fixed_1D
|
||||
{
|
||||
public:
|
||||
|
||||
/* Require Size > 0: */
|
||||
CML_STATIC_REQUIRE(Size > 0);
|
||||
|
||||
/* Record the generator: */
|
||||
typedef fixed<Size,-1> generator_type;
|
||||
|
||||
/* Standard: */
|
||||
typedef Element value_type;
|
||||
typedef Element* pointer;
|
||||
typedef Element& reference;
|
||||
typedef const Element& const_reference;
|
||||
typedef const Element* const_pointer;
|
||||
|
||||
/* Array implementation: */
|
||||
typedef value_type array_impl[Size];
|
||||
|
||||
/* For matching by memory type: */
|
||||
typedef fixed_memory_tag memory_tag;
|
||||
|
||||
/* For matching by size type: */
|
||||
typedef fixed_size_tag size_tag;
|
||||
|
||||
/* For matching by resizability: */
|
||||
typedef not_resizable_tag resizing_tag;
|
||||
|
||||
/* For matching by dimensions: */
|
||||
typedef oned_tag dimension_tag;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** The length as an enumerated value. */
|
||||
enum { array_size = Size };
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Return the number of elements in the array. */
|
||||
size_t size() const { return size_t(array_size); }
|
||||
|
||||
/** Access to the data as a C array.
|
||||
*
|
||||
* @param i a size_t index into the array.
|
||||
* @return a mutable reference to the array value at i.
|
||||
*
|
||||
* @note This function does not range-check the argument.
|
||||
*/
|
||||
reference operator[](size_t i) { return m_data[i]; }
|
||||
|
||||
/** Const access to the data as a C array.
|
||||
*
|
||||
* @param i a size_t index into the array.
|
||||
* @return a const reference to the array value at i.
|
||||
*
|
||||
* @note This function does not range-check the argument.
|
||||
*/
|
||||
const_reference operator[](size_t i) const { return m_data[i]; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
pointer data() { return &m_data[0]; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
const_pointer data() const { return &m_data[0]; }
|
||||
|
||||
protected:
|
||||
|
||||
fixed_1D() {}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
array_impl m_data;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
fixed_1D& operator=(const fixed_1D&);
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
205
Lib/Include/CML/core/fixed_2D.h
Normal file
205
Lib/Include/CML/core/fixed_2D.h
Normal file
@@ -0,0 +1,205 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef fixed_2D_h
|
||||
#define fixed_2D_h
|
||||
|
||||
#include <cml/core/common.h>
|
||||
#include <cml/core/fixed_1D.h>
|
||||
|
||||
/* This is used below to create a more meaningful compile-time error when
|
||||
* an unknown layout argument is given:
|
||||
*/
|
||||
struct invalid_layout_type_error;
|
||||
|
||||
/* This is used below to create a more meaningful compile-time error when
|
||||
* a negative size is given.
|
||||
*/
|
||||
struct negative_array_size_error;
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** The internal statically-allocated 2D-array implementation class.
|
||||
*
|
||||
* This uses an internal class to setup the data matrix with the proper
|
||||
* layout. The alternative is to use a 1D array with size Rows*Cols and a
|
||||
* multiplication to dereference an element, but it seems that compilers
|
||||
* better optimize 2D array dereferences. This is different from
|
||||
* dynamic_2D<>, which must use the 1D array method.
|
||||
*
|
||||
* @sa cml::fixed
|
||||
*
|
||||
* @note This class is designed to have the same size as a C array with the
|
||||
* same dimensions. It's therefore possible (but not recommended!) to coerce
|
||||
* a normal C array into a fixed_2D<> like this:
|
||||
*
|
||||
* typedef fixed_2D<double,10,10,row_major> array;
|
||||
* double c_array[10][10];
|
||||
* array& array_object = *((array*)&c_array);
|
||||
* double e11 = array_object[1][1];
|
||||
*
|
||||
* It's also possible to do this with a pointer to an array of values (e.g. a
|
||||
* double*), whether or not it was actually declared as a fixed C array. This
|
||||
* is HIGHLY DISCOURAGED, though, since it's relatively straightforward to
|
||||
* implement a separate class to take a C array (or pointer) and turn it into
|
||||
* an array object.
|
||||
*
|
||||
* @internal Do <em>not</em> add the empty constructor and destructor; at
|
||||
* least one compiler (Intel C++ 9.0) fails to optimize them away, and they
|
||||
* aren't needed anyway here.
|
||||
*/
|
||||
template<typename Element, int Rows, int Cols, typename Layout>
|
||||
class fixed_2D
|
||||
{
|
||||
public:
|
||||
|
||||
/* Require Rows > 0, Cols > 0: */
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(Rows > 0) && (Cols > 0),
|
||||
negative_array_size_error);
|
||||
|
||||
/* Require Layout to be row_major or col_major: */
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(same_type<Layout,row_major>::is_true
|
||||
|| same_type<Layout,col_major>::is_true),
|
||||
invalid_layout_type_error);
|
||||
|
||||
|
||||
/* Record the generator: */
|
||||
typedef fixed<Rows,Cols> generator_type;
|
||||
|
||||
/* Standard: */
|
||||
typedef Element value_type;
|
||||
typedef Element* pointer;
|
||||
typedef Element& reference;
|
||||
typedef const Element& const_reference;
|
||||
typedef const Element* const_pointer;
|
||||
|
||||
/* For matching by memory layout: */
|
||||
typedef Layout layout;
|
||||
|
||||
/* For matching by memory type: */
|
||||
typedef fixed_memory_tag memory_tag;
|
||||
|
||||
/* For matching by size type: */
|
||||
typedef fixed_size_tag size_tag;
|
||||
|
||||
/* For matching by resizability: */
|
||||
typedef not_resizable_tag resizing_tag;
|
||||
|
||||
/* For matching by dimensions: */
|
||||
typedef twod_tag dimension_tag;
|
||||
|
||||
/* To simplify the matrix transpose operator: */
|
||||
typedef fixed_2D<typename cml::remove_const<Element>::type,
|
||||
Cols,Rows,Layout> transposed_type;
|
||||
|
||||
/* To simplify the matrix row and column operators: */
|
||||
typedef fixed_1D<Element,Rows> row_array_type;
|
||||
typedef fixed_1D<Element,Cols> col_array_type;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
enum { array_rows = Rows, array_cols = Cols };
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Return the number of rows in the array. */
|
||||
size_t rows() const { return size_t(array_rows); }
|
||||
|
||||
/** Return the number of cols in the array. */
|
||||
size_t cols() const { return size_t(array_cols); }
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** Access element (row,col) of the matrix.
|
||||
*
|
||||
* @param row row of element.
|
||||
* @param col column of element.
|
||||
* @returns mutable reference.
|
||||
*
|
||||
* @note This function does not range-check the arguments.
|
||||
*/
|
||||
reference operator()(size_t row, size_t col) {
|
||||
/* Dispatch to the right function based on layout: */
|
||||
return get_element(row,col,layout());
|
||||
}
|
||||
|
||||
/** Const access element (row,col) of the matrix.
|
||||
*
|
||||
* @param row row of element.
|
||||
* @param col column of element.
|
||||
* @returns const reference.
|
||||
*
|
||||
* @note This function does not range-check the arguments.
|
||||
*/
|
||||
const_reference operator()(size_t row, size_t col) const {
|
||||
/* Dispatch to the right function based on layout: */
|
||||
return get_element(row,col,layout());
|
||||
}
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
pointer data() { return &m_data[0][0]; }
|
||||
|
||||
/** Return access to the data as a raw pointer. */
|
||||
const_pointer data() const { return &m_data[0][0]; }
|
||||
|
||||
|
||||
public:
|
||||
|
||||
fixed_2D() {}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
reference get_element(size_t row, size_t col, row_major) {
|
||||
return m_data[row][col];
|
||||
}
|
||||
|
||||
const_reference get_element(size_t row, size_t col, row_major) const {
|
||||
return m_data[row][col];
|
||||
}
|
||||
|
||||
reference get_element(size_t row, size_t col, col_major) {
|
||||
return m_data[col][row];
|
||||
}
|
||||
|
||||
const_reference get_element(size_t row, size_t col, col_major) const {
|
||||
return m_data[col][row];
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/* Typedef the possible layouts: */
|
||||
typedef Element row_major_array[Rows][Cols];
|
||||
typedef Element col_major_array[Cols][Rows];
|
||||
|
||||
/* Now, select the right layout for the current matrix: */
|
||||
typedef typename select_switch<
|
||||
Layout, row_major, row_major_array, /* Case 1 */
|
||||
col_major, col_major_array /* Case 2 */
|
||||
>::result array_data;
|
||||
|
||||
/* Declare the data array: */
|
||||
array_data m_data;
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
63
Lib/Include/CML/core/fwd.h
Normal file
63
Lib/Include/CML/core/fwd.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*
|
||||
* Forward declarations, useful to avoid including lots of headers.
|
||||
*
|
||||
* @sa cml/et/array_promotions.h
|
||||
*/
|
||||
|
||||
#ifndef core_fwd_h
|
||||
#define core_fwd_h
|
||||
|
||||
namespace cml {
|
||||
|
||||
/* cml/core/fixed_1D.h */
|
||||
template<typename E, int S> class fixed_1D;
|
||||
|
||||
/* cml/core/fixed_2D.h */
|
||||
template<typename E, int R, int C, class L> class fixed_2D;
|
||||
|
||||
/* cml/core/dynamic_1D.h */
|
||||
template<typename E, class A> class dynamic_1D;
|
||||
|
||||
/* cml/core/dynamic_2D.h */
|
||||
template<typename E, class L, class A> class dynamic_2D;
|
||||
|
||||
/* cml/core/external_1D.h */
|
||||
template<typename E, int S> class external_1D;
|
||||
|
||||
/* cml/core/external_2D.h */
|
||||
template<typename E, int R, int C, class L> class external_2D;
|
||||
|
||||
/* cml/fixed.h */
|
||||
template<int Dim1, int Dim2> struct fixed;
|
||||
|
||||
/* cml/dynamic.h */
|
||||
template<class Alloc> struct dynamic;
|
||||
|
||||
/* cml/external.h */
|
||||
template<int Dim1, int Dim2> struct external;
|
||||
|
||||
/* cml/vector.h */
|
||||
template<typename E, class AT> class vector;
|
||||
|
||||
/* cml/matrix.h */
|
||||
template<typename E, class AT, class BO, class L> class matrix;
|
||||
|
||||
/* cml/quaternion.h */
|
||||
template<typename E, class AT, class OT, class CT> class quaternion;
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
118
Lib/Include/CML/core/meta/common.h
Normal file
118
Lib/Include/CML/core/meta/common.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef core_meta_common_h
|
||||
#define core_meta_common_h
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** Type of a true statement. */
|
||||
struct true_type {};
|
||||
|
||||
/** Type of a false statement. */
|
||||
struct false_type {};
|
||||
|
||||
template<bool B> struct is_true {
|
||||
typedef false_type result;
|
||||
};
|
||||
|
||||
template<> struct is_true<true> {
|
||||
typedef true_type result;
|
||||
};
|
||||
|
||||
/** A "type pair". */
|
||||
template<typename T1, typename T2> struct type_pair {
|
||||
typedef T1 first;
|
||||
typedef T2 second;
|
||||
};
|
||||
|
||||
/** A "type quadruple". */
|
||||
template<typename T1, typename T2, typename T3, typename T4>
|
||||
struct type_quad {
|
||||
typedef T1 first;
|
||||
typedef T2 second;
|
||||
typedef T3 third;
|
||||
typedef T3 fourth;
|
||||
};
|
||||
|
||||
/** Match any type (for use with same_type<> and select_switch<>). */
|
||||
struct any_type {};
|
||||
|
||||
/** Determine if two types are the same.
|
||||
*
|
||||
* Defaults to false.
|
||||
*/
|
||||
template<typename T, typename U> struct same_type {
|
||||
typedef false_type result;
|
||||
enum { is_true = false, is_false = true };
|
||||
};
|
||||
|
||||
/** Match the same type for both of same_type's template arguments. */
|
||||
template<typename T> struct same_type<T,T> {
|
||||
typedef true_type result;
|
||||
enum { is_true = true, is_false = false };
|
||||
};
|
||||
|
||||
/** Match a type and any_type. */
|
||||
template<typename T> struct same_type<T,any_type> {
|
||||
typedef true_type result;
|
||||
enum { is_true = true, is_false = false };
|
||||
};
|
||||
|
||||
/** Match a type and any_type. */
|
||||
template<typename T> struct same_type<any_type,T> {
|
||||
typedef true_type result;
|
||||
enum { is_true = true, is_false = false };
|
||||
};
|
||||
|
||||
/** Disambiguate pair of any_type's. */
|
||||
template<> struct same_type<any_type,any_type> {
|
||||
typedef true_type result;
|
||||
enum { is_true = true, is_false = false };
|
||||
};
|
||||
|
||||
/** Remove a reference qualifier from a type. */
|
||||
template<typename T> struct remove_reference {
|
||||
template<typename Q, typename Dummy> struct helper {
|
||||
typedef Q type;
|
||||
};
|
||||
|
||||
template<typename Q> struct helper<Q&, void> {
|
||||
typedef Q type;
|
||||
};
|
||||
|
||||
template<typename Q> struct helper<const Q&, void> {
|
||||
typedef const Q type;
|
||||
};
|
||||
|
||||
typedef typename helper<T,void>::type type;
|
||||
};
|
||||
|
||||
/** Remove a const qualifier from a type. */
|
||||
template<typename T> struct remove_const {
|
||||
template<typename Q, typename Dummy> struct helper {
|
||||
typedef Q type;
|
||||
};
|
||||
|
||||
template<typename Q> struct helper<const Q, void> {
|
||||
typedef Q type;
|
||||
};
|
||||
|
||||
typedef typename helper<T,void>::type type;
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
42
Lib/Include/CML/core/meta/if.h
Normal file
42
Lib/Include/CML/core/meta/if.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef meta_if_h
|
||||
#define meta_if_h
|
||||
|
||||
#include <cml/core/meta/common.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** Select argument type based upon truth value. */
|
||||
template<bool yn, typename TrueT, typename FalseT> struct select_if;
|
||||
|
||||
/** Result is TrueT if true. */
|
||||
template<typename TrueT, typename FalseT>
|
||||
struct select_if<true,TrueT,FalseT> {
|
||||
typedef TrueT result;
|
||||
enum { is_true = true };
|
||||
};
|
||||
|
||||
/** Result is FalseT if false. */
|
||||
template<typename TrueT, typename FalseT>
|
||||
struct select_if<false,TrueT,FalseT> {
|
||||
typedef FalseT result;
|
||||
enum { is_true = false };
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
116
Lib/Include/CML/core/meta/switch.h
Normal file
116
Lib/Include/CML/core/meta/switch.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef meta_switch_h
|
||||
#define meta_switch_h
|
||||
|
||||
#include <cml/core/meta/common.h>
|
||||
#include <cml/core/meta/if.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
struct NilCase {}; /* For terminating the case list. */
|
||||
struct Default {}; /* For indicating the default result. */
|
||||
|
||||
/* The working parts of the meta-switch go into namespace meta: */
|
||||
namespace meta {
|
||||
|
||||
/* "Interior" case statements: */
|
||||
template<typename Case, typename Result, typename NextCase>
|
||||
struct select_case
|
||||
{
|
||||
template<typename Find> struct match {
|
||||
typedef typename select_if<
|
||||
same_type<Find,Case>::is_true,
|
||||
Result,
|
||||
typename NextCase::template match<Find>::result
|
||||
>::result result;
|
||||
};
|
||||
};
|
||||
|
||||
/* Default case, returned when no match is found in a previous case: */
|
||||
template<typename Result>
|
||||
struct select_case<Default,Result,NilCase>
|
||||
{
|
||||
template<typename Find> struct match {
|
||||
typedef Result result;
|
||||
};
|
||||
};
|
||||
|
||||
/* The last case statement (if no match until now, the result is 'void'): */
|
||||
template<typename Case, typename Result>
|
||||
struct select_case<Case,Result,NilCase>
|
||||
{
|
||||
template<typename Find> struct match {
|
||||
typedef typename select_if<
|
||||
same_type<Find,Case>::is_true,
|
||||
Result,
|
||||
void
|
||||
>::result result;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace meta
|
||||
|
||||
/** Return the matched type (like a switch/case statement).
|
||||
*
|
||||
* This is a convenience wrapper to avoid having to explicitly type out
|
||||
* select_case for each case in the list of types to match against.
|
||||
*/
|
||||
template<typename Find
|
||||
, typename T1, typename R1
|
||||
, typename T2 = NilCase, typename R2 = void
|
||||
, typename T3 = NilCase, typename R3 = void
|
||||
, typename T4 = NilCase, typename R4 = void
|
||||
, typename T5 = NilCase, typename R5 = void
|
||||
, typename T6 = NilCase, typename R6 = void
|
||||
, typename T7 = NilCase, typename R7 = void
|
||||
, typename T8 = NilCase, typename R8 = void
|
||||
, typename T9 = NilCase, typename R9 = void
|
||||
, typename T10 = NilCase, typename R10 = void
|
||||
, typename T11 = NilCase, typename R11 = void
|
||||
, typename T12 = NilCase, typename R12 = void
|
||||
, typename T13 = NilCase, typename R13 = void
|
||||
, typename T14 = NilCase, typename R14 = void
|
||||
, typename T15 = NilCase, typename R15 = void
|
||||
, typename T16 = NilCase, typename R16 = void
|
||||
> struct select_switch
|
||||
{
|
||||
typedef typename
|
||||
meta::select_case< T1,R1
|
||||
, meta::select_case< T2,R2
|
||||
, meta::select_case< T3,R3
|
||||
, meta::select_case< T4,R4
|
||||
, meta::select_case< T5,R5
|
||||
, meta::select_case< T6,R6
|
||||
, meta::select_case< T7,R7
|
||||
, meta::select_case< T8,R8
|
||||
, meta::select_case< T9,R9
|
||||
, meta::select_case< T10,R10
|
||||
, meta::select_case< T11,R11
|
||||
, meta::select_case< T12,R12
|
||||
, meta::select_case< T13,R13
|
||||
, meta::select_case< T14,R14
|
||||
, meta::select_case< T15,R15
|
||||
, meta::select_case< T16,R16
|
||||
, NilCase
|
||||
> > > > > > /* 6 */
|
||||
> > > > > > > > > > /* 10 */
|
||||
::template match<Find>::result result;
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
89
Lib/Include/CML/defaults.h
Normal file
89
Lib/Include/CML/defaults.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief Default values for certain parameters.
|
||||
*/
|
||||
|
||||
#ifndef defaults_h
|
||||
#define defaults_h
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
#if _MSC_VER >= 1400
|
||||
|
||||
/* Ignore "C4003: not enough actual parameters for macro": */
|
||||
#pragma warning (disable: 4003)
|
||||
|
||||
/* This one is odd, but apparently harmless (but should be fixed!):
|
||||
* "C4348: redefinition of default parameter"
|
||||
*/
|
||||
#pragma warning (disable: 4348)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* The default vector unroll limit: */
|
||||
#if !defined(CML_VECTOR_UNROLL_LIMIT)
|
||||
#define CML_VECTOR_UNROLL_LIMIT 8
|
||||
#endif
|
||||
|
||||
/* Don't unroll matrix operations by default: */
|
||||
#if !defined(CML_2D_UNROLLER) && !defined(CML_NO_2D_UNROLLER)
|
||||
#define CML_NO_2D_UNROLLER
|
||||
#endif
|
||||
|
||||
/* The default vector dot() unroll limit: */
|
||||
#if !defined(CML_VECTOR_DOT_UNROLL_LIMIT)
|
||||
#define CML_VECTOR_DOT_UNROLL_LIMIT CML_VECTOR_UNROLL_LIMIT
|
||||
#endif
|
||||
|
||||
/* The default array layout is the C/C++ row-major array layout: */
|
||||
#if !defined(CML_DEFAULT_ARRAY_LAYOUT)
|
||||
#define CML_DEFAULT_ARRAY_LAYOUT cml::row_major
|
||||
#endif
|
||||
|
||||
/* The default basis orientation: */
|
||||
#if !defined(CML_DEFAULT_BASIS_ORIENTATION)
|
||||
#define CML_DEFAULT_BASIS_ORIENTATION cml::col_basis
|
||||
#endif
|
||||
|
||||
/* Always use the default layout in promotions, by default: */
|
||||
#if !defined(CML_ALWAYS_PROMOTE_TO_DEFAULT_LAYOUT)
|
||||
#define CML_ALWAYS_PROMOTE_TO_DEFAULT_LAYOUT
|
||||
#endif
|
||||
|
||||
/* The default memory allocator is std::allocator<void>: */
|
||||
#if !defined(CML_DEFAULT_ARRAY_ALLOC)
|
||||
#include <memory> // for std::allocator
|
||||
#define CML_DEFAULT_ARRAY_ALLOC std::allocator<void>
|
||||
#endif
|
||||
|
||||
/* By default, automatically resize dynamic vectors and matrices: */
|
||||
#if !defined(CML_AUTOMATIC_VECTOR_RESIZE_ON_ASSIGNMENT)
|
||||
#define CML_AUTOMATIC_VECTOR_RESIZE_ON_ASSIGNMENT
|
||||
#endif
|
||||
|
||||
#if !defined(CML_AUTOMATIC_MATRIX_RESIZE_ON_ASSIGNMENT)
|
||||
#define CML_AUTOMATIC_MATRIX_RESIZE_ON_ASSIGNMENT
|
||||
#endif
|
||||
|
||||
/* By default, check vector and matrix sizes: */
|
||||
#if !defined(CML_CHECK_VECTOR_EXPR_SIZES)
|
||||
#define CML_CHECK_VECTOR_EXPR_SIZES
|
||||
#endif
|
||||
|
||||
#if !defined(CML_CHECK_MATRIX_EXPR_SIZES)
|
||||
#define CML_CHECK_MATRIX_EXPR_SIZES
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
35
Lib/Include/CML/dynamic.h
Normal file
35
Lib/Include/CML/dynamic.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef dynamic_h
|
||||
#define dynamic_h
|
||||
|
||||
#include <cml/defaults.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** This is a selector for dynamic 1D and 2D arrays.
|
||||
*
|
||||
* The dynamic<> struct has no implementation; it is used only to select a
|
||||
* 1D or 2D array type as the base class of a vector or matrix.
|
||||
*
|
||||
* @sa fixed
|
||||
* @sa external
|
||||
*/
|
||||
template<class Alloc = CML_DEFAULT_ARRAY_ALLOC> struct dynamic;
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
288
Lib/Include/CML/et/array_promotions.h
Normal file
288
Lib/Include/CML/et/array_promotions.h
Normal file
@@ -0,0 +1,288 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*
|
||||
* Defines promotions between array types.
|
||||
*
|
||||
* @todo Can/should an expression with a fixed-size argument promote to a
|
||||
* fixed array instead of a dynamic array?
|
||||
*/
|
||||
|
||||
#ifndef array_promotions_h
|
||||
#define array_promotions_h
|
||||
|
||||
#include <cml/core/cml_meta.h>
|
||||
#include <cml/et/scalar_promotions.h>
|
||||
|
||||
namespace cml {
|
||||
namespace et {
|
||||
|
||||
#define VAL_MAX(_a_,_b_) ( ((_a_)>(_b_))?(_a_):(_b_) )
|
||||
|
||||
namespace detail {
|
||||
|
||||
/* This is specialized for 1D and 2D promotions: */
|
||||
template<class A1, class A2, typename DTag1, typename DTag2,
|
||||
typename PromotedSizeTag> struct promote;
|
||||
|
||||
/* Promote 1D fixed-size arrays to a 1D fixed-size array: */
|
||||
template<class A1, class A2>
|
||||
struct promote<A1,A2,oned_tag,oned_tag,fixed_size_tag>
|
||||
{
|
||||
typedef typename A1::value_type left_scalar;
|
||||
typedef typename A2::value_type right_scalar;
|
||||
|
||||
/* First, promote the scalar type: */
|
||||
typedef typename ScalarPromote<
|
||||
left_scalar,right_scalar>::type promoted_scalar;
|
||||
|
||||
/* Next, deduce the array size: */
|
||||
enum { Size = VAL_MAX((size_t)A1::array_size, (size_t)A2::array_size) };
|
||||
|
||||
/* Finally, generate the promoted array type: */
|
||||
typedef fixed_1D<promoted_scalar,Size> type;
|
||||
};
|
||||
|
||||
/* Promote 1D dynamic arrays to a 1D dynamic array: */
|
||||
template<class A1, class A2>
|
||||
struct promote<A1,A2,oned_tag,oned_tag,dynamic_size_tag>
|
||||
{
|
||||
typedef typename A1::value_type left_scalar;
|
||||
typedef typename A2::value_type right_scalar;
|
||||
|
||||
/* First, promote the scalar type: */
|
||||
typedef typename ScalarPromote<
|
||||
left_scalar,right_scalar>::type promoted_scalar;
|
||||
|
||||
/* Next, rebind to get the proper allocator: */
|
||||
typedef typename CML_DEFAULT_ARRAY_ALLOC
|
||||
::rebind<promoted_scalar>::other allocator;
|
||||
|
||||
/* Finally, generate the promoted array type: */
|
||||
typedef dynamic_1D<promoted_scalar,allocator> type;
|
||||
};
|
||||
|
||||
/* Promote fixed 2D+1D array expressions to a fixed 1D array: */
|
||||
template<class A1, class A2>
|
||||
struct promote<A1,A2,twod_tag,oned_tag,fixed_size_tag>
|
||||
{
|
||||
typedef typename A1::value_type left_scalar;
|
||||
typedef typename A2::value_type right_scalar;
|
||||
|
||||
/* First, promote the scalar type: */
|
||||
typedef typename ScalarPromote<
|
||||
left_scalar,right_scalar>::type promoted_scalar;
|
||||
|
||||
/* Next, deduce the array size: */
|
||||
enum { Size = (size_t)A1::array_rows };
|
||||
|
||||
/* Finally, generate the promoted array type: */
|
||||
typedef fixed_1D<promoted_scalar,Size> type;
|
||||
};
|
||||
|
||||
/* Promote fixed 1D+2D array expressions to a fixed 1D array: */
|
||||
template<class A1, class A2>
|
||||
struct promote<A1,A2,oned_tag,twod_tag,fixed_size_tag>
|
||||
{
|
||||
typedef typename A1::value_type left_scalar;
|
||||
typedef typename A2::value_type right_scalar;
|
||||
|
||||
/* First, promote the scalar type: */
|
||||
typedef typename ScalarPromote<
|
||||
left_scalar,right_scalar>::type promoted_scalar;
|
||||
|
||||
/* Next, deduce the array size: */
|
||||
enum { Size = (size_t)A2::array_cols };
|
||||
|
||||
/* Finally, generate the promoted array type: */
|
||||
typedef fixed_1D<promoted_scalar,Size> type;
|
||||
};
|
||||
|
||||
/* Promote dynamic 2D+1D array expression to a 1D dynamic array: */
|
||||
template<class A1, class A2>
|
||||
struct promote<A1,A2,twod_tag,oned_tag,dynamic_size_tag>
|
||||
{
|
||||
typedef typename A1::value_type left_scalar;
|
||||
typedef typename A2::value_type right_scalar;
|
||||
|
||||
/* First, promote the scalar type: */
|
||||
typedef typename ScalarPromote<
|
||||
left_scalar,right_scalar>::type promoted_scalar;
|
||||
|
||||
/* Next, rebind to get the proper allocator: */
|
||||
typedef typename CML_DEFAULT_ARRAY_ALLOC
|
||||
::rebind<promoted_scalar>::other allocator;
|
||||
|
||||
/* Finally, generate the promoted array type: */
|
||||
typedef dynamic_1D<promoted_scalar,allocator> type;
|
||||
};
|
||||
|
||||
/* Promote dynamic 1D+2D array expression to a 1D dynamic array: */
|
||||
template<class A1, class A2>
|
||||
struct promote<A1,A2,oned_tag,twod_tag,dynamic_size_tag>
|
||||
{
|
||||
typedef typename A1::value_type left_scalar;
|
||||
typedef typename A2::value_type right_scalar;
|
||||
|
||||
/* First, promote the scalar type: */
|
||||
typedef typename ScalarPromote<
|
||||
left_scalar,right_scalar>::type promoted_scalar;
|
||||
|
||||
/* Next, rebind to get the proper allocator: */
|
||||
typedef typename CML_DEFAULT_ARRAY_ALLOC
|
||||
::rebind<promoted_scalar>::other allocator;
|
||||
|
||||
/* Finally, generate the promoted array type: */
|
||||
typedef dynamic_1D<promoted_scalar,allocator> type;
|
||||
};
|
||||
|
||||
|
||||
/* This is a helper to deduce the result of a promoted 2D array: */
|
||||
template<typename LeftL, typename RightL> struct deduce_layout {
|
||||
#if defined(CML_ALWAYS_PROMOTE_TO_DEFAULT_LAYOUT)
|
||||
typedef CML_DEFAULT_ARRAY_LAYOUT promoted_layout;
|
||||
#else
|
||||
typedef typename select_if<
|
||||
same_type<LeftL,RightL>::is_true, LeftL,
|
||||
CML_DEFAULT_ARRAY_LAYOUT>::result promoted_layout;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Promote 2D fixed-size arrays to a 2D fixed-size array. The resulting
|
||||
* matrix has the same number of rows as A1, and the same number of
|
||||
* columns as A2.
|
||||
*/
|
||||
template<class A1, class A2>
|
||||
struct promote<A1,A2,twod_tag,twod_tag,fixed_size_tag>
|
||||
{
|
||||
typedef typename A1::value_type left_scalar;
|
||||
typedef typename A2::value_type right_scalar;
|
||||
|
||||
/* First, promote the scalar type: */
|
||||
typedef typename ScalarPromote<
|
||||
left_scalar,right_scalar>::type promoted_scalar;
|
||||
|
||||
/* Next, deduce the array size: */
|
||||
enum {
|
||||
Rows = (size_t)A1::array_rows,
|
||||
Cols = (size_t)A2::array_cols
|
||||
};
|
||||
|
||||
/* Then deduce the array layout: */
|
||||
typedef typename A1::layout left_layout;
|
||||
typedef typename A2::layout right_layout;
|
||||
typedef typename deduce_layout<left_layout,right_layout>
|
||||
::promoted_layout promoted_layout;
|
||||
|
||||
/* Finally, generate the promoted array type: */
|
||||
typedef fixed_2D<promoted_scalar,Rows,Cols,promoted_layout> type;
|
||||
};
|
||||
|
||||
/* Promote 2D dynamic arrays to a 2D dynamic array: */
|
||||
template<class A1, class A2>
|
||||
struct promote<A1,A2,twod_tag,twod_tag,dynamic_size_tag>
|
||||
{
|
||||
typedef typename A1::value_type left_scalar;
|
||||
typedef typename A2::value_type right_scalar;
|
||||
|
||||
/* First, promote the scalar type: */
|
||||
typedef typename ScalarPromote<
|
||||
left_scalar,right_scalar>::type promoted_scalar;
|
||||
|
||||
/* Next, rebind to get the proper allocator: */
|
||||
typedef typename CML_DEFAULT_ARRAY_ALLOC
|
||||
::rebind<promoted_scalar>::other allocator;
|
||||
|
||||
/* Then deduce the array layout: */
|
||||
typedef typename A1::layout left_layout;
|
||||
typedef typename A2::layout right_layout;
|
||||
typedef typename deduce_layout<left_layout,right_layout>
|
||||
::promoted_layout promoted_layout;
|
||||
|
||||
/* Finally, generate the promoted array type: */
|
||||
typedef dynamic_2D<promoted_scalar,promoted_layout,allocator> type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/** Class to promote array types.
|
||||
*
|
||||
* Both arguments must be array types.
|
||||
*
|
||||
* @sa fixed_1D
|
||||
* @sa fixed_2D
|
||||
* @sa dynamic_1D
|
||||
* @sa dynamic_2D
|
||||
*/
|
||||
template<class A1, class A2>
|
||||
struct ArrayPromote
|
||||
{
|
||||
/* Shorthand: */
|
||||
//typedef typename A1::value_type left_scalar;
|
||||
//typedef typename A2::value_type right_scalar;
|
||||
typedef typename A1::dimension_tag left_dtag;
|
||||
typedef typename A2::dimension_tag right_dtag;
|
||||
|
||||
/* Deduce the proper type based upon the characteristics of AT1 and
|
||||
* AT2. This is the table of type conversions:
|
||||
*
|
||||
* AT1 AT2 Result
|
||||
* memory size memory size memory size
|
||||
*
|
||||
* fixed fixed fixed fixed fixed fixed
|
||||
* fixed fixed dynamic dynamic dynamic dynamic
|
||||
* fixed fixed external fixed fixed fixed
|
||||
* fixed fixed external dynamic dynamic dynamic
|
||||
*
|
||||
* dynamic dynamic fixed fixed dynamic dynamic
|
||||
* dynamic dynamic dynamic dynamic dynamic dynamic
|
||||
* dynamic dynamic external fixed dynamic dynamic
|
||||
* dynamic dynamic external dynamic dynamic dynamic
|
||||
*
|
||||
* external fixed external fixed fixed fixed
|
||||
* external fixed fixed fixed fixed fixed
|
||||
* external fixed dynamic dynamic dynamic dynamic
|
||||
* external fixed external dynamic dynamic dynamic
|
||||
*
|
||||
* external dynamic external fixed dynamic dynamic
|
||||
* external dynamic fixed fixed dynamic dynamic
|
||||
* external dynamic dynamic dynamic dynamic dynamic
|
||||
* external dynamic external dynamic dynamic dynamic
|
||||
*
|
||||
* Note that if one argument is a dynamically-sized array, the result
|
||||
* must be a dynamically allocated and sized array. Likewise, if both
|
||||
* arguments have fixed size, the result can be a fixed-sized array.
|
||||
*/
|
||||
|
||||
/* Check if both arguments are fixed-size arrays. If so, the promoted
|
||||
* array will be a fixed array, and if not, it will be a dynamic array:
|
||||
*/
|
||||
typedef typename select_if<
|
||||
(same_type<typename A1::size_tag, fixed_size_tag>::is_true
|
||||
&& same_type<typename A2::size_tag, fixed_size_tag>::is_true),
|
||||
fixed_size_tag, /* True */
|
||||
dynamic_size_tag /* False */
|
||||
>::result promoted_size_tag;
|
||||
|
||||
/* Deduce the promoted type: */
|
||||
typedef typename detail::promote<
|
||||
A1, A2, left_dtag, right_dtag, promoted_size_tag>::type type;
|
||||
};
|
||||
|
||||
/* Cleanup internal macros: */
|
||||
#undef VAL_MAX
|
||||
|
||||
} // namespace et
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
138
Lib/Include/CML/et/scalar_ops.h
Normal file
138
Lib/Include/CML/et/scalar_ops.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef ops_h
|
||||
#define ops_h
|
||||
|
||||
#include <cml/et/traits.h>
|
||||
#include <cml/et/scalar_promotions.h>
|
||||
|
||||
/** Declare a unary scalar operator, like negation. */
|
||||
#define CML_UNARY_SCALAR_OP(_op_, _op_name_) \
|
||||
template<typename ArgT> struct _op_name_ { \
|
||||
typedef ExprTraits<ArgT> arg_traits; \
|
||||
typedef typename arg_traits::const_reference arg_reference; \
|
||||
typedef typename arg_traits::value_type value_type; \
|
||||
typedef scalar_result_tag result_tag; \
|
||||
value_type apply(arg_reference arg) const { return _op_ arg; } \
|
||||
};
|
||||
|
||||
/** Declare a binary scalar operator, like addition, s1+s2. */
|
||||
#define CML_BINARY_SCALAR_OP(_op_, _op_name_) \
|
||||
template<typename LeftT, typename RightT> struct _op_name_ { \
|
||||
typedef ExprTraits<LeftT> left_traits; \
|
||||
typedef ExprTraits<RightT> right_traits; \
|
||||
typedef typename left_traits::const_reference left_reference; \
|
||||
typedef typename right_traits::const_reference right_reference; \
|
||||
typedef typename left_traits::value_type left_value; \
|
||||
typedef typename right_traits::value_type right_value; \
|
||||
typedef typename ScalarPromote<left_value,right_value>::type value_type; \
|
||||
typedef scalar_result_tag result_tag; \
|
||||
value_type apply(left_reference left, right_reference right) const { \
|
||||
return left _op_ right; } \
|
||||
};
|
||||
|
||||
/** Declare an op-assignment operator.
|
||||
*
|
||||
* @note The ExprTraits for both argument types must be defined, LeftT must
|
||||
* have an assignment operator, and ExprTraits<LeftT>::reference must specify
|
||||
* a type that allows assignment.
|
||||
*/
|
||||
#define CML_BINARY_SCALAR_OP_ASSIGN(_op_, _op_name_) \
|
||||
template<typename LeftT, typename RightT> struct _op_name_ { \
|
||||
typedef ExprTraits<LeftT> left_traits; \
|
||||
typedef ExprTraits<RightT> right_traits; \
|
||||
typedef typename left_traits::reference left_reference; \
|
||||
typedef typename right_traits::const_reference right_reference; \
|
||||
typedef typename left_traits::value_type left_value; \
|
||||
typedef typename right_traits::value_type right_value; \
|
||||
typedef typename ScalarPromote<left_value,right_value>::type value_type; \
|
||||
typedef scalar_result_tag result_tag; \
|
||||
value_type apply(left_reference left, right_reference right) const { \
|
||||
return left _op_ (LeftT) right; } \
|
||||
};
|
||||
|
||||
/** Declare a binary boolean operator, like less-than, s1 < s2.
|
||||
*
|
||||
* The operator should return the appropriate truth value for the operator.
|
||||
*
|
||||
* @note Both scalar types must have operator<() defined.
|
||||
*/
|
||||
#define CML_BOOLEAN_SCALAR_OP(_op_, _op_name_) \
|
||||
template<typename LeftT, typename RightT> struct _op_name_ { \
|
||||
typedef ExprTraits<LeftT> left_traits; \
|
||||
typedef ExprTraits<RightT> right_traits; \
|
||||
typedef typename left_traits::const_reference left_reference; \
|
||||
typedef typename right_traits::const_reference right_reference; \
|
||||
typedef scalar_result_tag result_tag; \
|
||||
bool apply(left_reference left, right_reference right) const { \
|
||||
return left _op_ right; } \
|
||||
};
|
||||
|
||||
namespace cml {
|
||||
namespace et {
|
||||
|
||||
/* Define the operators: */
|
||||
|
||||
/* Unary scalar ops: */
|
||||
CML_UNARY_SCALAR_OP(-, OpNeg)
|
||||
CML_UNARY_SCALAR_OP(+, OpPos)
|
||||
|
||||
/* Binary scalar ops: */
|
||||
CML_BINARY_SCALAR_OP(+, OpAdd)
|
||||
CML_BINARY_SCALAR_OP(-, OpSub)
|
||||
CML_BINARY_SCALAR_OP(*, OpMul)
|
||||
|
||||
#if defined(CML_RECIPROCAL_OPTIMIZATION)
|
||||
/* XXX Yikes... this should really be written out in full. *= 1./ is the
|
||||
* "_op_" parameter to the macro (see above):
|
||||
*/
|
||||
CML_BINARY_SCALAR_OP(* value_type(1)/, OpDiv)
|
||||
#else
|
||||
CML_BINARY_SCALAR_OP(/, OpDiv)
|
||||
#endif
|
||||
|
||||
/* Binary scalar op-assigns: */
|
||||
CML_BINARY_SCALAR_OP_ASSIGN( =, OpAssign)
|
||||
CML_BINARY_SCALAR_OP_ASSIGN(+=, OpAddAssign)
|
||||
CML_BINARY_SCALAR_OP_ASSIGN(-=, OpSubAssign)
|
||||
CML_BINARY_SCALAR_OP_ASSIGN(*=, OpMulAssign)
|
||||
|
||||
#if defined(CML_RECIPROCAL_OPTIMIZATION)
|
||||
/* XXX Yikes... this should really be written out in full. *= 1./ is the
|
||||
* "_op_" parameter to the macro (see above):
|
||||
*/
|
||||
CML_BINARY_SCALAR_OP_ASSIGN(*= value_type(1)/, OpDivAssign)
|
||||
#else
|
||||
CML_BINARY_SCALAR_OP_ASSIGN(/=, OpDivAssign)
|
||||
#endif
|
||||
|
||||
/* Boolean operators for scalars: */
|
||||
CML_BOOLEAN_SCALAR_OP(==, OpEqual)
|
||||
CML_BOOLEAN_SCALAR_OP(!=, OpNotEqual)
|
||||
CML_BOOLEAN_SCALAR_OP( <, OpLess)
|
||||
CML_BOOLEAN_SCALAR_OP( >, OpGreater)
|
||||
CML_BOOLEAN_SCALAR_OP(<=, OpLessEqual)
|
||||
CML_BOOLEAN_SCALAR_OP(>=, OpGreaterEqual)
|
||||
|
||||
#undef CML_UNARY_SCALAR_OP
|
||||
#undef CML_BINARY_SCALAR_OP
|
||||
#undef CML_BINARY_SCALAR_OP_ASSIGN
|
||||
#undef CML_BOOLEAN_SCALAR_OP
|
||||
|
||||
} // namespace et
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
151
Lib/Include/CML/et/scalar_promotions.h
Normal file
151
Lib/Include/CML/et/scalar_promotions.h
Normal file
@@ -0,0 +1,151 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef scalar_promotions_h
|
||||
#define scalar_promotions_h
|
||||
|
||||
#include <complex>
|
||||
#include <cml/core/cml_meta.h>
|
||||
|
||||
namespace cml {
|
||||
namespace et {
|
||||
|
||||
/* The type promotion code below is a slightly modified version of:
|
||||
* http://ubiety.uwaterloo.ca/~tveldhui/papers/techniques/techniques01.html
|
||||
*/
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
struct precision_trait {
|
||||
enum { precisionRank = 0,
|
||||
knowPrecisionRank = 0 };
|
||||
};
|
||||
|
||||
#define DECLARE_PRECISION(T,rank) \
|
||||
template<> \
|
||||
struct precision_trait< T > { \
|
||||
enum { precisionRank = rank, \
|
||||
knowPrecisionRank = 1 }; \
|
||||
};
|
||||
|
||||
DECLARE_PRECISION(int,100)
|
||||
DECLARE_PRECISION(unsigned int,200)
|
||||
DECLARE_PRECISION(long,300)
|
||||
DECLARE_PRECISION(unsigned long,400)
|
||||
|
||||
DECLARE_PRECISION(long long,425)
|
||||
DECLARE_PRECISION(unsigned long long,475)
|
||||
|
||||
DECLARE_PRECISION(float,500)
|
||||
DECLARE_PRECISION(double,600)
|
||||
DECLARE_PRECISION(long double,700)
|
||||
DECLARE_PRECISION(std::complex<float>,800)
|
||||
DECLARE_PRECISION(std::complex<double>,900)
|
||||
DECLARE_PRECISION(std::complex<long double>,1000)
|
||||
|
||||
template<class T>
|
||||
struct autopromote_trait {
|
||||
typedef T T_numtype;
|
||||
};
|
||||
|
||||
#define DECLARE_AUTOPROMOTE(T1,T2) \
|
||||
template<> \
|
||||
struct autopromote_trait<T1> { \
|
||||
typedef T2 T_numtype; \
|
||||
};
|
||||
|
||||
// These are the odd cases where small integer types
|
||||
// are automatically promoted to int or unsigned int for
|
||||
// arithmetic.
|
||||
DECLARE_AUTOPROMOTE(bool, int)
|
||||
DECLARE_AUTOPROMOTE(char, int)
|
||||
DECLARE_AUTOPROMOTE(unsigned char, int)
|
||||
DECLARE_AUTOPROMOTE(short int, int)
|
||||
DECLARE_AUTOPROMOTE(short unsigned int, unsigned int)
|
||||
|
||||
template<class T1, class T2, int promoteToT1>
|
||||
struct promote2 {
|
||||
typedef T1 T_promote;
|
||||
};
|
||||
|
||||
template<class T1, class T2>
|
||||
struct promote2<T1,T2,0> {
|
||||
typedef T2 T_promote;
|
||||
};
|
||||
|
||||
template<class T1_orig, class T2_orig>
|
||||
struct promote_trait {
|
||||
|
||||
// Need to remove const-ness:
|
||||
typedef typename cml::remove_const<T1_orig>::type T1_non_const;
|
||||
typedef typename cml::remove_const<T2_orig>::type T2_non_const;
|
||||
|
||||
// Handle promotion of small integers to int/unsigned int
|
||||
typedef typename autopromote_trait<T1_non_const>::T_numtype T1;
|
||||
typedef typename autopromote_trait<T2_non_const>::T_numtype T2;
|
||||
|
||||
// True if T1 is higher ranked
|
||||
enum {
|
||||
T1IsBetter =
|
||||
(int) precision_trait<T1>::precisionRank >
|
||||
(int) precision_trait<T2>::precisionRank,
|
||||
|
||||
// True if we know ranks for both T1 and T2
|
||||
knowBothRanks =
|
||||
precision_trait<T1>::knowPrecisionRank
|
||||
&& precision_trait<T2>::knowPrecisionRank,
|
||||
|
||||
// True if we know T1 but not T2
|
||||
knowT1butNotT2 = precision_trait<T1>::knowPrecisionRank
|
||||
&& !(precision_trait<T2>::knowPrecisionRank),
|
||||
|
||||
// True if we know T2 but not T1
|
||||
knowT2butNotT1 = precision_trait<T2>::knowPrecisionRank
|
||||
&& !(precision_trait<T1>::knowPrecisionRank),
|
||||
|
||||
// True if T1 is bigger than T2
|
||||
T1IsLarger = sizeof(T1) >= sizeof(T2),
|
||||
|
||||
// We know T1 but not T2: true
|
||||
// We know T2 but not T1: false
|
||||
// Otherwise, if T1 is bigger than T2: true
|
||||
defaultPromotion = knowT1butNotT2 ? false :
|
||||
(knowT2butNotT1 ? true : T1IsLarger)
|
||||
};
|
||||
|
||||
// If we have both ranks, then use them.
|
||||
// If we have only one rank, then use the unknown type.
|
||||
// If we have neither rank, then promote to the larger type.
|
||||
|
||||
enum {
|
||||
promoteToT1 = (knowBothRanks ? T1IsBetter : defaultPromotion)
|
||||
? 1 : 0
|
||||
};
|
||||
|
||||
typedef typename promote2<T1,T2,promoteToT1>::T_promote T_promote;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/** Defers to detail::promote_trait<>. */
|
||||
template<class E1, class E2> struct ScalarPromote
|
||||
{
|
||||
typedef typename detail::promote_trait<E1,E2>::T_promote type;
|
||||
};
|
||||
|
||||
} // namespace et
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
431
Lib/Include/CML/et/size_checking.h
Normal file
431
Lib/Include/CML/et/size_checking.h
Normal file
@@ -0,0 +1,431 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*
|
||||
* Define matrix and vector linear expression size-checking classes.
|
||||
*/
|
||||
|
||||
#ifndef size_checking_h
|
||||
#define size_checking_h
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cml/core/cml_meta.h>
|
||||
#include <cml/core/cml_assert.h>
|
||||
#include <cml/core/fwd.h>
|
||||
#include <cml/et/traits.h>
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1400
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4348)
|
||||
// XXX This is a terrible hack for VC7.1, and should really be fixed by
|
||||
// separating out the "impl" templates from GetCheckedSize.
|
||||
#endif
|
||||
|
||||
/* This is used below to create a more meaningful compile-time error when
|
||||
* fixed-size vector arguments don't match at compile time:
|
||||
*/
|
||||
struct incompatible_expression_size_error;
|
||||
|
||||
/* This is used below to create a more meaningful compile-time error when a
|
||||
* function is not provided with a square matrix or MatrixExpr argument:
|
||||
*/
|
||||
struct square_matrix_arg_expected_error;
|
||||
|
||||
namespace cml {
|
||||
namespace et {
|
||||
namespace detail {
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/* Forward declare for specialization below: */
|
||||
template<typename LeftT, typename RightT, typename SizeT>
|
||||
struct GetCheckedSize;
|
||||
|
||||
/* Checking for fixed-size expression: */
|
||||
template<typename LeftT, typename RightT>
|
||||
struct GetCheckedSize<LeftT,RightT,fixed_size_tag>
|
||||
{
|
||||
/* Record argument traits: */
|
||||
typedef ExprTraits<LeftT> left_traits;
|
||||
typedef ExprTraits<RightT> right_traits;
|
||||
|
||||
/* Result types: */
|
||||
typedef typename left_traits::result_tag left_result;
|
||||
typedef typename right_traits::result_tag right_result;
|
||||
|
||||
|
||||
/* For specialization below: */
|
||||
template<typename LR, typename RR, class X = void> struct impl;
|
||||
|
||||
/* Check for two matrices (linear operators only): */
|
||||
template<class X> struct impl<matrix_result_tag,matrix_result_tag,X> {
|
||||
typedef matrix_size size_type;
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(size_t)LeftT::array_rows == (size_t)RightT::array_rows
|
||||
&& (size_t)LeftT::array_cols == (size_t)RightT::array_cols,
|
||||
incompatible_expression_size_error);
|
||||
|
||||
/* Record the array size as a constant: */
|
||||
enum {
|
||||
array_rows = LeftT::array_rows,
|
||||
array_cols = LeftT::array_cols
|
||||
};
|
||||
|
||||
/* Return the matrix size: */
|
||||
size_type size() const { return size_type(array_rows,array_cols); }
|
||||
};
|
||||
|
||||
/* Check for a matrix and a vector: */
|
||||
template<class X> struct impl<matrix_result_tag,vector_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(size_t)LeftT::array_cols == (size_t)RightT::array_size,
|
||||
incompatible_expression_size_error);
|
||||
|
||||
/* Record the array size as a constant: */
|
||||
enum { array_size = LeftT::array_rows };
|
||||
|
||||
/* Return the vector size: */
|
||||
size_type size() const { return size_type(array_size); }
|
||||
};
|
||||
|
||||
/* Check for a vector and a matrix: */
|
||||
template<class X> struct impl<vector_result_tag,matrix_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(size_t)LeftT::array_size == (size_t)RightT::array_rows,
|
||||
incompatible_expression_size_error);
|
||||
|
||||
/* Record the array size as a constant: */
|
||||
enum { array_size = RightT::array_cols };
|
||||
|
||||
/* Return the vector size: */
|
||||
size_type size() const { return size_type(array_size); }
|
||||
};
|
||||
|
||||
/* Check for a matrix and a scalar: */
|
||||
template<class X> struct impl<matrix_result_tag,scalar_result_tag,X> {
|
||||
typedef matrix_size size_type;
|
||||
|
||||
/* Record the array size as a constant: */
|
||||
enum {
|
||||
array_rows = LeftT::array_rows,
|
||||
array_cols = LeftT::array_cols
|
||||
};
|
||||
|
||||
/* Return the matrix size: */
|
||||
size_type size() const { return size_type(array_rows,array_cols); }
|
||||
};
|
||||
|
||||
/* Check for a scalar and a matrix: */
|
||||
template<class X> struct impl<scalar_result_tag,matrix_result_tag,X> {
|
||||
typedef matrix_size size_type;
|
||||
|
||||
/* Record the array size as a constant: */
|
||||
enum {
|
||||
array_rows = RightT::array_rows,
|
||||
array_cols = RightT::array_cols
|
||||
};
|
||||
|
||||
/* Return the matrix size: */
|
||||
size_type size() const { return size_type(array_rows,array_cols); }
|
||||
};
|
||||
|
||||
|
||||
/* Check for two vectors: */
|
||||
template<class X> struct impl<vector_result_tag,vector_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(size_t)LeftT::array_size == (size_t)RightT::array_size,
|
||||
incompatible_expression_size_error);
|
||||
|
||||
/* Record the array size as a constant: */
|
||||
enum { array_size = LeftT::array_size };
|
||||
|
||||
/* Return the vector size: */
|
||||
size_type size() const { return size_type(array_size); }
|
||||
};
|
||||
|
||||
/* Check for a vector and a scalar: */
|
||||
template<class X> struct impl<vector_result_tag,scalar_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
|
||||
/* Record the array size as a constant: */
|
||||
enum { array_size = LeftT::array_size };
|
||||
|
||||
/* Return the vector size: */
|
||||
size_type size() const { return size_type(array_size); }
|
||||
};
|
||||
|
||||
/* Check for a scalar and a vector: */
|
||||
template<class X> struct impl<scalar_result_tag,vector_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
|
||||
/* Record the array size as a constant: */
|
||||
enum { array_size = RightT::array_size };
|
||||
|
||||
/* Return the vector size: */
|
||||
size_type size() const { return size_type(array_size); }
|
||||
};
|
||||
|
||||
|
||||
/* Check for two quaternions: */
|
||||
template<class X>
|
||||
struct impl<quaternion_result_tag,quaternion_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
|
||||
/* Record the quaternion size as a constant: */
|
||||
enum { array_size = 4 };
|
||||
|
||||
/* Return the quaternion size: */
|
||||
size_type size() const { return size_type(array_size); }
|
||||
};
|
||||
|
||||
/* Check for a quaternion and a vector: */
|
||||
template<class X> struct impl<quaternion_result_tag,vector_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
CML_STATIC_REQUIRE_M(
|
||||
RightT::array_size == 4,
|
||||
incompatible_expression_size_error);
|
||||
|
||||
/* Record the quaternion size as a constant: */
|
||||
enum { array_size = 4 };
|
||||
|
||||
/* Return the quaternion size: */
|
||||
size_type size() const { return size_type(array_size); }
|
||||
};
|
||||
|
||||
/* Check for a vector and a quaternion: */
|
||||
template<class X> struct impl<vector_result_tag,quaternion_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
CML_STATIC_REQUIRE_M(
|
||||
LeftT::array_size == 4,
|
||||
incompatible_expression_size_error);
|
||||
|
||||
/* Record the quaternion size as a constant: */
|
||||
enum { array_size = 4 };
|
||||
|
||||
/* Return the quaternion size: */
|
||||
size_type size() const { return size_type(array_size); }
|
||||
};
|
||||
|
||||
/* Check for a quaternion and a scalar: */
|
||||
template<class X> struct impl<quaternion_result_tag,scalar_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
|
||||
/* Record the quaternion size as a constant: */
|
||||
enum { array_size = 4 };
|
||||
|
||||
/* Return the quaternion size: */
|
||||
size_type size() const { return size_type(array_size); }
|
||||
};
|
||||
|
||||
/* Check for a scalar and a quaternion: */
|
||||
template<class X> struct impl<scalar_result_tag,quaternion_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
|
||||
/* Record the array size as a constant: */
|
||||
enum { array_size = 4 };
|
||||
|
||||
/* Return the quaternion size: */
|
||||
size_type size() const { return size_type(array_size); }
|
||||
};
|
||||
|
||||
/* Record the type of the checker: */
|
||||
typedef impl<left_result,right_result> check_type;
|
||||
typedef typename check_type::size_type size_type;
|
||||
|
||||
/* The implementation: */
|
||||
size_type operator()(const LeftT&, const RightT&) const {
|
||||
return check_type().size();
|
||||
}
|
||||
};
|
||||
|
||||
/* Checking for resizeable expression: */
|
||||
template<typename LeftT, typename RightT>
|
||||
struct GetCheckedSize<LeftT,RightT,dynamic_size_tag>
|
||||
{
|
||||
/* Type of the size checker (for calling equal_or_fail): */
|
||||
typedef GetCheckedSize<LeftT,RightT,dynamic_size_tag> self;
|
||||
|
||||
/* Record argument traits: */
|
||||
typedef ExprTraits<LeftT> left_traits;
|
||||
typedef ExprTraits<RightT> right_traits;
|
||||
|
||||
/* Result types: */
|
||||
typedef typename left_traits::result_tag left_result;
|
||||
typedef typename right_traits::result_tag right_result;
|
||||
|
||||
|
||||
/* For specialization below: */
|
||||
template<typename LR, typename RR, class X = void> struct impl;
|
||||
|
||||
/* Return the size if the same, or fail if different: */
|
||||
template<typename V> V equal_or_fail(V left, V right) const {
|
||||
if(left != right)
|
||||
throw std::invalid_argument(
|
||||
"expressions have incompatible sizes.");
|
||||
return left;
|
||||
}
|
||||
|
||||
/* Check for two matrices (linear operators only): */
|
||||
template<class X> struct impl<matrix_result_tag,matrix_result_tag,X> {
|
||||
typedef matrix_size size_type;
|
||||
|
||||
/* Return the matrix size, or fail if incompatible: */
|
||||
size_type size(const LeftT& left, const RightT& right) const {
|
||||
#if defined(CML_CHECK_MATRIX_EXPR_SIZES)
|
||||
return self().equal_or_fail(left.size(), right.size());
|
||||
#else
|
||||
return left.size();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
/* Check for a matrix and a vector: */
|
||||
template<class X> struct impl<matrix_result_tag,vector_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
|
||||
/* Return the vector size: */
|
||||
#if defined(CML_CHECK_MATVEC_EXPR_SIZES)
|
||||
size_type size(const LeftT& left, const RightT& right) const
|
||||
#else
|
||||
size_type size(const LeftT& left, const RightT& /*right*/) const
|
||||
#endif
|
||||
{
|
||||
#if defined(CML_CHECK_MATVEC_EXPR_SIZES)
|
||||
self().equal_or_fail(left.cols(), right.size());
|
||||
#endif
|
||||
return left.rows();
|
||||
}
|
||||
};
|
||||
|
||||
/* Check for a vector and a matrix: */
|
||||
template<class X> struct impl<vector_result_tag,matrix_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
|
||||
/* Return the vector size: */
|
||||
size_type size(const LeftT& left, const RightT& right) const {
|
||||
#if defined(CML_CHECK_MATVEC_EXPR_SIZES)
|
||||
self().equal_or_fail(left.size(), right.rows());
|
||||
#endif
|
||||
return right.cols(right);
|
||||
}
|
||||
};
|
||||
|
||||
/* Check for a matrix and a scalar: */
|
||||
template<class X> struct impl<matrix_result_tag,scalar_result_tag,X> {
|
||||
typedef matrix_size size_type;
|
||||
|
||||
/* Return the matrix size: */
|
||||
size_type size(const LeftT& left, const RightT&) const {
|
||||
return left.size();
|
||||
}
|
||||
};
|
||||
|
||||
/* Check for a scalar and a matrix: */
|
||||
template<class X> struct impl<scalar_result_tag,matrix_result_tag,X> {
|
||||
typedef matrix_size size_type;
|
||||
|
||||
/* Return the matrix size: */
|
||||
size_type size(const LeftT&, const RightT& right) const {
|
||||
return right.size();
|
||||
}
|
||||
};
|
||||
|
||||
/* Check for two vectors: */
|
||||
template<class X> struct impl<vector_result_tag,vector_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
|
||||
/* Return the vector size: */
|
||||
size_type size(const LeftT& left, const RightT& right) const {
|
||||
#if defined(CML_CHECK_VECTOR_EXPR_SIZES)
|
||||
return self().equal_or_fail(left.size(), right.size());
|
||||
#else
|
||||
return left.size();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
/* Check for a vector and a scalar: */
|
||||
template<class X> struct impl<vector_result_tag,scalar_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
|
||||
/* Return the vector size: */
|
||||
size_type size(const LeftT& left, const RightT&) const {
|
||||
return left.size();
|
||||
}
|
||||
};
|
||||
|
||||
/* Check for a scalar and a vector: */
|
||||
template<class X> struct impl<scalar_result_tag,vector_result_tag,X> {
|
||||
typedef size_t size_type;
|
||||
|
||||
/* Return the vector size: */
|
||||
size_type size(const LeftT&, const RightT& right) const {
|
||||
return right.size();
|
||||
}
|
||||
};
|
||||
|
||||
/* Record the type of the checker: */
|
||||
typedef impl<left_result,right_result> check_type;
|
||||
typedef typename check_type::size_type size_type;
|
||||
|
||||
/* The implementation: */
|
||||
size_type operator()(const LeftT& left, const RightT& right) const {
|
||||
return check_type().size(left,right);
|
||||
}
|
||||
};
|
||||
|
||||
/** Generator for GetCheckedSize. */
|
||||
template<typename LeftT, typename RightT, typename SizeTag>
|
||||
inline typename et::GetCheckedSize<LeftT,RightT,SizeTag>::size_type
|
||||
CheckedSize(const LeftT& left, const RightT& right, SizeTag)
|
||||
{
|
||||
return et::GetCheckedSize<LeftT,RightT,SizeTag>()(left,right);
|
||||
}
|
||||
|
||||
/** Verify the sizes of the argument matrices for matrix multiplication.
|
||||
*
|
||||
* @returns a the size of the resulting matrix.
|
||||
*/
|
||||
template<typename MatT> inline size_t
|
||||
CheckedSquare(const MatT&, fixed_size_tag)
|
||||
{
|
||||
CML_STATIC_REQUIRE_M(
|
||||
((size_t)MatT::array_rows == (size_t)MatT::array_cols),
|
||||
square_matrix_arg_expected_error);
|
||||
return (size_t)MatT::array_rows;
|
||||
}
|
||||
|
||||
/** Verify the sizes of the argument matrices for matrix multiplication.
|
||||
*
|
||||
* @returns the size of the resulting matrix.
|
||||
*/
|
||||
template<typename MatT> inline size_t
|
||||
CheckedSquare(const MatT& m, dynamic_size_tag)
|
||||
{
|
||||
matrix_size N = m.size();
|
||||
et::GetCheckedSize<MatT,MatT,dynamic_size_tag>()
|
||||
.equal_or_fail(N.first, N.second);
|
||||
return N.first;
|
||||
}
|
||||
|
||||
} // namespace et
|
||||
} // namespace cml
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1400
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
55
Lib/Include/CML/et/tags.h
Normal file
55
Lib/Include/CML/et/tags.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef et_tags_h
|
||||
#define et_tags_h
|
||||
|
||||
namespace cml {
|
||||
namespace et {
|
||||
|
||||
/** Tag an expression as returning a scalar. */
|
||||
struct scalar_result_tag {};
|
||||
|
||||
/** Tag an expression as returning a vector. */
|
||||
struct vector_result_tag {};
|
||||
|
||||
/** Tag an expression as returning a matrix. */
|
||||
struct matrix_result_tag {};
|
||||
|
||||
/** Tag an expression as returning a quaternion. */
|
||||
struct quaternion_result_tag {};
|
||||
|
||||
/** Marker for unary expression ops. */
|
||||
struct unary_expression {};
|
||||
|
||||
/** Marker for biary expression ops. */
|
||||
struct binary_expression {};
|
||||
|
||||
/** Marker for expression tree operator nodes. */
|
||||
struct expr_node_tag {};
|
||||
|
||||
/** Marker for expression tree terminals (leaves). */
|
||||
struct expr_leaf_tag {};
|
||||
|
||||
/** Marker for assignable types. */
|
||||
struct assignable_tag {};
|
||||
|
||||
/** Marker for assignable types. */
|
||||
struct not_assignable_tag {};
|
||||
|
||||
} // namespace et
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
143
Lib/Include/CML/et/traits.h
Normal file
143
Lib/Include/CML/et/traits.h
Normal file
@@ -0,0 +1,143 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef traits_h
|
||||
#define traits_h
|
||||
|
||||
#include <cml/et/tags.h>
|
||||
|
||||
/* XXX This is here temporarily, should be rolled into the traits classes
|
||||
* once it's clear how to best specify scalar args
|
||||
*/
|
||||
//#define SCALAR_ARG_TYPE const ScalarT&
|
||||
//#define ELEMENT_ARG_TYPE const Element&
|
||||
#define SCALAR_ARG_TYPE ScalarT
|
||||
#define ELEMENT_ARG_TYPE Element
|
||||
|
||||
namespace cml {
|
||||
namespace et {
|
||||
|
||||
/** The expression traits class.
|
||||
*
|
||||
* The traits class is used to provide uniform access to expression
|
||||
* objects, including scalars, when used in vector and matrix expressions.
|
||||
* One especially useful property for scalars is that scalars are
|
||||
* implicitly "promoted" to vectors or scalars as necessary via the
|
||||
* ExprTraits's get() method. Without this functionality, a separate
|
||||
* expression tree node would be needed to hold a scalar, which would
|
||||
* adversely affect performance.
|
||||
*
|
||||
* @internal This is also currently used for determining traits of scalar
|
||||
* types from the scalar operators (+,-,etc.). Really, a separate traits
|
||||
* class should probably be used for this (e.g. ScalarTraits).
|
||||
*/
|
||||
template<typename T> struct ExprTraits
|
||||
#if defined(CML_NO_DEFAULT_EXPR_TRAITS)
|
||||
/* For testing, don't default to scalar traits: */
|
||||
#else
|
||||
{
|
||||
/* Standard: */
|
||||
typedef T expr_type;
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef T const_reference;
|
||||
typedef scalar_result_tag result_tag;
|
||||
typedef fixed_memory_tag memory_tag;
|
||||
typedef unit_size_tag size_tag;
|
||||
typedef expr_type result_type;
|
||||
typedef expr_leaf_tag node_tag;
|
||||
|
||||
/** Vector-like access, just returns the value. */
|
||||
value_type get(const_reference v, size_t) const { return v; }
|
||||
|
||||
/** Matrix-like access, just returns the value. */
|
||||
value_type get(const_reference v, size_t, size_t) const { return v; }
|
||||
|
||||
/** Size is always 1. */
|
||||
size_t size(const_reference) const { return 1; }
|
||||
|
||||
/** Size is always 1. */
|
||||
size_t rows(double) const { return 1; }
|
||||
|
||||
/** Size is always 1. */
|
||||
size_t cols(double) const { return 1; }
|
||||
}
|
||||
#endif
|
||||
;
|
||||
|
||||
#if defined(CML_NO_DEFAULT_EXPR_TRAITS)
|
||||
template<> struct ExprTraits<double>
|
||||
{
|
||||
/* Standard: */
|
||||
typedef double expr_type;
|
||||
typedef double value_type;
|
||||
typedef double& reference;
|
||||
typedef double const_reference;
|
||||
typedef scalar_result_tag result_tag;
|
||||
typedef fixed_memory_tag memory_tag;
|
||||
typedef unit_size_tag size_tag;
|
||||
typedef double result_type;
|
||||
typedef expr_leaf_tag node_tag;
|
||||
|
||||
/** Vector-like access, just returns the value. */
|
||||
value_type get(double v, size_t) const { return v; }
|
||||
|
||||
/** Matrix-like access, just returns the value. */
|
||||
value_type get(double v, size_t, size_t) const { return v; }
|
||||
|
||||
/** Size is always 1. */
|
||||
size_t size(double) const { return 1; }
|
||||
|
||||
/** Size is always 1. */
|
||||
size_t rows(double) const { return 1; }
|
||||
|
||||
/** Size is always 1. */
|
||||
size_t cols(double) const { return 1; }
|
||||
};
|
||||
|
||||
template<> struct ExprTraits<float>
|
||||
{
|
||||
/* Standard: */
|
||||
typedef float expr_type;
|
||||
typedef float value_type;
|
||||
typedef float& reference;
|
||||
typedef float const_reference;
|
||||
typedef scalar_result_tag result_tag;
|
||||
typedef fixed_memory_tag memory_tag;
|
||||
typedef unit_size_tag size_tag;
|
||||
typedef float result_type;
|
||||
typedef expr_leaf_tag node_tag;
|
||||
|
||||
/** Vector-like access, just returns the value. */
|
||||
value_type get(float v, size_t) const { return v; }
|
||||
|
||||
/** Matrix-like access, just returns the value. */
|
||||
value_type get(float v, size_t, size_t) const { return v; }
|
||||
|
||||
/** Size is always 1. */
|
||||
size_t size(float) const { return 1; }
|
||||
|
||||
/** Size is always 1. */
|
||||
size_t rows(float) const { return 1; }
|
||||
|
||||
/** Size is always 1. */
|
||||
size_t cols(float) const { return 1; }
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace et
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
41
Lib/Include/CML/external.h
Normal file
41
Lib/Include/CML/external.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef external_h
|
||||
#define external_h
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** This is a selector for external 1D and 2D arrays.
|
||||
*
|
||||
* The external<> struct is used only to select a 1D or 2D array as the
|
||||
* base class of a vector or matrix. The rebind<> template is used by
|
||||
* quaternion<> to select its vector length in a generic way.
|
||||
*
|
||||
* @sa fixed
|
||||
* @sa dynamic
|
||||
*/
|
||||
template<int Dim1 = -1, int Dim2 = -1> struct external {
|
||||
|
||||
/** Rebind to a 1D type.
|
||||
*
|
||||
* This is used by quaternion<>.
|
||||
*/
|
||||
template<int D> struct rebind { typedef external<D> other; };
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
42
Lib/Include/CML/fixed.h
Normal file
42
Lib/Include/CML/fixed.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef fixed_h
|
||||
#define fixed_h
|
||||
|
||||
namespace cml {
|
||||
|
||||
|
||||
/** This is a selector for fixed 1D and 2D arrays.
|
||||
*
|
||||
* The fixed<> struct is used only to select a 1D or 2D array as the base
|
||||
* class of a vector or matrix. The rebind<> template is used by
|
||||
* quaternion<> to select its vector length in a generic way.
|
||||
*
|
||||
* @sa dynamic
|
||||
* @sa external
|
||||
*/
|
||||
template<int Dim1 = -1, int Dim2 = -1> struct fixed {
|
||||
|
||||
/** Rebind to a 1D type.
|
||||
*
|
||||
* This is used by quaternion<>.
|
||||
*/
|
||||
template<int D> struct rebind { typedef fixed<D> other; };
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vim:ft=cpp
|
||||
382
Lib/Include/CML/mathlib/checking.h
Normal file
382
Lib/Include/CML/mathlib/checking.h
Normal file
@@ -0,0 +1,382 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef checking_h
|
||||
#define checking_h
|
||||
|
||||
#include <cml/vector/vector_expr.h>
|
||||
#include <cml/matrix/matrix_expr.h>
|
||||
#include <cml/quaternion/quaternion_expr.h>
|
||||
|
||||
/* Run- and compile-time checking of argument types, values and sizes. */
|
||||
|
||||
struct function_expects_vector_arg_error;
|
||||
struct function_expects_matrix_arg_error;
|
||||
struct function_expects_quaternion_arg_error;
|
||||
|
||||
struct function_expects_2D_vector_arg_error;
|
||||
struct function_expects_3D_vector_arg_error;
|
||||
struct function_expects_4D_vector_arg_error;
|
||||
struct function_expects_2D_or_3D_vector_arg_error;
|
||||
struct function_expects_2x2_matrix_arg_error;
|
||||
struct function_expects_3x3_matrix_arg_error;
|
||||
struct function_expects_4x4_matrix_arg_error;
|
||||
struct function_expects_square_matrix_arg_error;
|
||||
|
||||
struct matrix_arg_fails_minimum_size_requirement;
|
||||
|
||||
namespace cml {
|
||||
namespace detail {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Vector argument checking
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Compile-time check for a vector argument */
|
||||
template< class VecT > inline void
|
||||
CheckVec(const VecT&)
|
||||
{
|
||||
typedef et::ExprTraits<VecT> vector_traits;
|
||||
typedef typename vector_traits::result_tag result_type;
|
||||
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(same_type<result_type, et::vector_result_tag>::is_true),
|
||||
function_expects_vector_arg_error);
|
||||
}
|
||||
|
||||
/** Compile-time check for a vector of size N */
|
||||
template< class VecT, size_t N, class ErrorT > inline void
|
||||
CheckVecN(const VecT& v, fixed_size_tag) {
|
||||
CheckVec(v);
|
||||
|
||||
CML_STATIC_REQUIRE_M(((size_t)VecT::array_size == N), ErrorT);
|
||||
}
|
||||
|
||||
/** Run-time check for a vector of size N */
|
||||
template< class VecT, size_t N, class /*ErrorT*/ > inline void
|
||||
CheckVecN(const VecT& v, dynamic_size_tag) {
|
||||
CheckVec(v);
|
||||
|
||||
et::GetCheckedSize<VecT,VecT,dynamic_size_tag>()
|
||||
.equal_or_fail(v.size(),size_t(N));
|
||||
}
|
||||
|
||||
/** Check for a vector of size N */
|
||||
template< class VecT, size_t N, class ErrorT > inline void
|
||||
CheckVecN(const VecT& v) {
|
||||
typedef et::ExprTraits<VecT> vector_traits;
|
||||
typedef typename vector_traits::size_tag size_tag;
|
||||
|
||||
detail::CheckVecN<VecT,N,ErrorT>(v, size_tag());
|
||||
}
|
||||
|
||||
/** Check for a vector of size 2 */
|
||||
template< class VecT > inline void
|
||||
CheckVec2(const VecT& v) {
|
||||
detail::CheckVecN<VecT,2,function_expects_2D_vector_arg_error>(v);
|
||||
}
|
||||
|
||||
/** Check for a vector of size 3 */
|
||||
template< class VecT > inline void
|
||||
CheckVec3(const VecT& v) {
|
||||
detail::CheckVecN<VecT,3,function_expects_3D_vector_arg_error>(v);
|
||||
}
|
||||
|
||||
/** Check for a vector of size 4 */
|
||||
template< class VecT > inline void
|
||||
CheckVec4(const VecT& v) {
|
||||
CheckVecN<VecT,4,function_expects_4D_vector_arg_error>(v);
|
||||
}
|
||||
|
||||
/** Compile-time check for a vector of size 2 or 3 */
|
||||
template< class VecT > inline void
|
||||
CheckVec2Or3(const VecT& v, fixed_size_tag) {
|
||||
CheckVec(v);
|
||||
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(VecT::array_size == 2 || VecT::array_size == 3),
|
||||
function_expects_2D_or_3D_vector_arg_error);
|
||||
}
|
||||
|
||||
/** Run-time check for a vector of size 2 or 3 */
|
||||
template< class VecT > inline void
|
||||
CheckVec2Or3(const VecT& v, dynamic_size_tag) {
|
||||
CheckVec(v);
|
||||
|
||||
if (v.size() != 2 && v.size() != 3) {
|
||||
throw std::invalid_argument("2d or 3d vector arg expected");
|
||||
}
|
||||
}
|
||||
|
||||
/** Check for a vector of size 2 or 3 */
|
||||
template< class VecT > inline void
|
||||
CheckVec2Or3(const VecT& v) {
|
||||
typedef et::ExprTraits<VecT> vector_traits;
|
||||
typedef typename vector_traits::size_tag size_tag;
|
||||
|
||||
detail::CheckVec2Or3(v, size_tag());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Matrix argument checking
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Compile-time check for a matrix argument */
|
||||
template< class MatT > inline void
|
||||
CheckMat(const MatT&)
|
||||
{
|
||||
typedef et::ExprTraits<MatT> matrix_traits;
|
||||
typedef typename matrix_traits::result_tag result_type;
|
||||
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(same_type<result_type, et::matrix_result_tag>::is_true),
|
||||
function_expects_matrix_arg_error);
|
||||
}
|
||||
|
||||
/** Compile-time check for a matrix of size NxM */
|
||||
template< class MatT, size_t N, size_t M, class ErrorT > inline void
|
||||
CheckMatNxM(const MatT& m, fixed_size_tag) {
|
||||
CheckMat(m);
|
||||
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(MatT::array_rows == N && MatT::array_cols == M), ErrorT);
|
||||
}
|
||||
|
||||
/** Run-time check for a matrix of size NxM */
|
||||
template< class MatT, size_t N, size_t M, class /*ErrorT*/ > inline void
|
||||
CheckMatNxM(const MatT& m, dynamic_size_tag) {
|
||||
CheckMat(m);
|
||||
|
||||
et::GetCheckedSize<MatT,MatT,dynamic_size_tag>()
|
||||
.equal_or_fail(m.rows(),N);
|
||||
et::GetCheckedSize<MatT,MatT,dynamic_size_tag>()
|
||||
.equal_or_fail(m.cols(),M);
|
||||
}
|
||||
|
||||
/** Check for a matrix of size NxM */
|
||||
template< class MatT, size_t N, size_t M, class ErrorT > inline void
|
||||
CheckMatNxM(const MatT& m) {
|
||||
typedef et::ExprTraits<MatT> matrix_traits;
|
||||
typedef typename matrix_traits::size_tag size_tag;
|
||||
|
||||
CheckMatNxM<MatT,N,M,ErrorT>(m, size_tag());
|
||||
}
|
||||
|
||||
/** Check for a square matrix of size NxN */
|
||||
template< class MatT, size_t N, class ErrorT > inline void
|
||||
CheckMatN(const MatT& m) {
|
||||
CheckMatNxM<MatT,N,N,ErrorT>(m);
|
||||
}
|
||||
|
||||
/** Check for a square matrix of size 2x2 */
|
||||
template< class MatT > inline void
|
||||
CheckMat2x2(const MatT& m) {
|
||||
CheckMatN<MatT,2,function_expects_2x2_matrix_arg_error>(m);
|
||||
}
|
||||
|
||||
/** Check for a square matrix of size 3x3 */
|
||||
template< class MatT > inline void
|
||||
CheckMat3x3(const MatT& m) {
|
||||
CheckMatN<MatT,3,function_expects_3x3_matrix_arg_error>(m);
|
||||
}
|
||||
|
||||
/** Check for a square matrix of size 4x4 */
|
||||
template< class MatT > inline void
|
||||
CheckMat4x4(const MatT& m) {
|
||||
CheckMatN<MatT,4,function_expects_4x4_matrix_arg_error>(m);
|
||||
}
|
||||
|
||||
/** Compile-time check for a matrix with minimum dimensions NxM */
|
||||
template< class MatT, size_t N, size_t M, class ErrorT > inline void
|
||||
CheckMatMinNxM(const MatT& m, fixed_size_tag) {
|
||||
CheckMat(m);
|
||||
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(MatT::array_rows >= N && MatT::array_cols >= M), ErrorT);
|
||||
}
|
||||
|
||||
/** Run-time check for a matrix with minimum dimensions NxM */
|
||||
template< class MatT, size_t N, size_t M, class /*ErrorT*/ > inline void
|
||||
CheckMatMinNxM(const MatT& m, dynamic_size_tag) {
|
||||
CheckMat(m);
|
||||
|
||||
if (m.rows() < N || m.cols() < M) {
|
||||
throw std::invalid_argument(
|
||||
"matrix does not meet minimum size requirement");
|
||||
}
|
||||
}
|
||||
|
||||
/** Check for a matrix with minimum dimensions NxM */
|
||||
template< class MatT, size_t N, size_t M, class ErrorT > inline void
|
||||
CheckMatMinNxM(const MatT& m) {
|
||||
typedef et::ExprTraits<MatT> matrix_traits;
|
||||
typedef typename matrix_traits::size_tag size_tag;
|
||||
|
||||
CheckMatMinNxM<MatT,N,M,ErrorT>(m, size_tag());
|
||||
}
|
||||
|
||||
/** Check for a matrix with minimum dimensions NxN */
|
||||
template< class MatT, size_t N, class ErrorT > inline void
|
||||
CheckMatMinN(const MatT& m) {
|
||||
CheckMatMinNxM<MatT,N,N,ErrorT>(m);
|
||||
}
|
||||
|
||||
/** Check for a matrix with minimum dimensions 2x2 */
|
||||
template< class MatT > inline void
|
||||
CheckMatMin2x2(const MatT& m) {
|
||||
CheckMatMinN<MatT,2,matrix_arg_fails_minimum_size_requirement>(m);
|
||||
}
|
||||
|
||||
/** Check for a matrix with minimum dimensions 3x3 */
|
||||
template< class MatT > inline void
|
||||
CheckMatMin3x3(const MatT& m) {
|
||||
CheckMatMinN<MatT,3,matrix_arg_fails_minimum_size_requirement>(m);
|
||||
}
|
||||
|
||||
/** Check for a matrix with minimum dimensions 4x4 */
|
||||
template< class MatT > inline void
|
||||
CheckMatMin4x4(const MatT& m) {
|
||||
CheckMatMinN<MatT,4,matrix_arg_fails_minimum_size_requirement>(m);
|
||||
}
|
||||
|
||||
/** Check for a matrix that can represent a 3D linear transform */
|
||||
template< class MatT > inline void
|
||||
CheckMatLinear3D(const MatT& m) {
|
||||
CheckMatMin3x3(m);
|
||||
}
|
||||
|
||||
/** Check for a matrix that can represent a 2D linear transform */
|
||||
template< class MatT > inline void
|
||||
CheckMatLinear2D(const MatT& m) {
|
||||
CheckMatMin2x2(m);
|
||||
}
|
||||
|
||||
/** Check for a matrix that can represent a 3D row-basis affine transform */
|
||||
template< class MatT > inline void
|
||||
CheckMatAffine3D(const MatT& m, row_basis) {
|
||||
CheckMatMinNxM<MatT,4,3,matrix_arg_fails_minimum_size_requirement>(m);
|
||||
}
|
||||
|
||||
/** Check for a matrix that can represent a 3D col-basis affine transform */
|
||||
template< class MatT > inline void
|
||||
CheckMatAffine3D(const MatT& m, col_basis) {
|
||||
CheckMatMinNxM<MatT,3,4,matrix_arg_fails_minimum_size_requirement>(m);
|
||||
}
|
||||
|
||||
/** Check for a matrix that can represent a 2D row-basis affine transform */
|
||||
template< class MatT > inline void
|
||||
CheckMatAffine2D(const MatT& m, row_basis) {
|
||||
CheckMatMinNxM<MatT,3,2,matrix_arg_fails_minimum_size_requirement>(m);
|
||||
}
|
||||
|
||||
/** Check for a matrix that can represent a 2D col-basis affine transform */
|
||||
template< class MatT > inline void
|
||||
CheckMatAffine2D(const MatT& m, col_basis) {
|
||||
CheckMatMinNxM<MatT,2,3,matrix_arg_fails_minimum_size_requirement>(m);
|
||||
}
|
||||
|
||||
/** Check for a matrix that can represent a 3D affine transform */
|
||||
template< class MatT > inline void
|
||||
CheckMatAffine3D(const MatT& m) {
|
||||
CheckMatAffine3D(m, typename MatT::basis_orient());
|
||||
}
|
||||
|
||||
/** Check for a matrix that can represent a 2D affine transform */
|
||||
template< class MatT > inline void
|
||||
CheckMatAffine2D(const MatT& m) {
|
||||
CheckMatAffine2D(m, typename MatT::basis_orient());
|
||||
}
|
||||
|
||||
/** Check for a matrix that can represent a 3D homogenous transform */
|
||||
template< class MatT > inline void
|
||||
CheckMatHomogeneous3D(const MatT& m) {
|
||||
CheckMatMin4x4(m);
|
||||
}
|
||||
|
||||
/** Compile-time check for a square matrix */
|
||||
template< class MatT, class ErrorT> inline void
|
||||
CheckMatSquare(const MatT& m, fixed_size_tag) {
|
||||
CheckMat(m);
|
||||
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(MatT::array_rows == MatT::array_cols), ErrorT);
|
||||
}
|
||||
|
||||
/** Run-time check for a square matrix */
|
||||
template< class MatT, class /*ErrorT*/ > inline void
|
||||
CheckMatSquare(const MatT& m, dynamic_size_tag) {
|
||||
CheckMat(m);
|
||||
|
||||
if (m.rows() != m.cols()) {
|
||||
throw std::invalid_argument(
|
||||
"function expects square matrix as argument");
|
||||
}
|
||||
}
|
||||
|
||||
/** Check for a square matrix */
|
||||
template< class MatT > inline void
|
||||
CheckMatSquare(const MatT& m) {
|
||||
typedef et::ExprTraits<MatT> matrix_traits;
|
||||
typedef typename matrix_traits::size_tag size_tag;
|
||||
|
||||
detail::CheckMatSquare<
|
||||
MatT,function_expects_square_matrix_arg_error>(m, size_tag());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Quaternion argument checking
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Compile-time check for a quaternion argument*/
|
||||
template< class QuatT > inline void
|
||||
CheckQuat(const QuatT& /*q*/)
|
||||
{
|
||||
typedef et::ExprTraits<QuatT> quaternion_traits;
|
||||
typedef typename quaternion_traits::result_tag result_type;
|
||||
|
||||
CML_STATIC_REQUIRE_M(
|
||||
(same_type<result_type, et::quaternion_result_tag>::is_true),
|
||||
function_expects_quaternion_arg_error);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Index argument checking
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Run-time check for a valid argument */
|
||||
inline void CheckValidArg(bool valid)
|
||||
{
|
||||
if (!valid) {
|
||||
throw std::invalid_argument("invalid function argument");
|
||||
}
|
||||
}
|
||||
|
||||
/** Check for a valid integer index with value < N */
|
||||
template < size_t N >
|
||||
inline void CheckIndexN(size_t index) {
|
||||
CheckValidArg(index < N);
|
||||
}
|
||||
|
||||
/** Check for a valid integer index with value < 2 */
|
||||
inline void CheckIndex2(size_t index) {
|
||||
CheckIndexN<2>(index);
|
||||
}
|
||||
|
||||
/** Check for a valid integer index with value < 3 */
|
||||
inline void CheckIndex3(size_t index) {
|
||||
CheckIndexN<3>(index);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
162
Lib/Include/CML/mathlib/coord_conversion.h
Normal file
162
Lib/Include/CML/mathlib/coord_conversion.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef coord_conversion_h
|
||||
#define coord_conversion_h
|
||||
|
||||
#include <cml/mathlib/checking.h>
|
||||
#include <cml/mathlib/epsilon.h>
|
||||
#include <cml/mathlib/helper.h>
|
||||
|
||||
/* Functions for converting between Cartesian, polar, cylindrical and
|
||||
* spherical coordinates.
|
||||
*
|
||||
* The 3D conversion functions take an integer axis index argument. For
|
||||
* cylindrical coordinates this determines the axis of the cylinder, and for
|
||||
* spherical it determines which cardinal axis is normal to the azimuth plane.
|
||||
*
|
||||
* For spherical coordinates the option of whether to treat phi as latitude
|
||||
* or colatitude is also available. The 'type' argument takes either of the
|
||||
* enumerants cml::latitude and cml::colatitude to reflect this.
|
||||
*/
|
||||
|
||||
namespace cml {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Conversion to Cartesian coordinates
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Convert cylindrical coordinates to Cartesian coordinates in R3 */
|
||||
template < typename E, class A > void
|
||||
cylindrical_to_cartesian(
|
||||
E radius, E theta, E height, size_t axis, vector<E,A>& v)
|
||||
{
|
||||
typedef vector<E,A> vector_type;
|
||||
typedef typename vector_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckVec3(v);
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(axis, i, j, k);
|
||||
|
||||
v[i] = height;
|
||||
v[j] = std::cos(theta) * radius;
|
||||
v[k] = std::sin(theta) * radius;
|
||||
}
|
||||
|
||||
/* Convert spherical coordinates to Cartesian coordinates in R3 */
|
||||
template < typename E, class A > void
|
||||
spherical_to_cartesian(E radius, E theta, E phi, size_t axis,
|
||||
SphericalType type, vector<E,A>& v)
|
||||
{
|
||||
typedef vector<E,A> vector_type;
|
||||
typedef typename vector_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckVec3(v);
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
if (type == latitude) {
|
||||
phi = constants<value_type>::pi_over_2() - phi;
|
||||
}
|
||||
|
||||
value_type sin_phi = std::sin(phi);
|
||||
value_type cos_phi = std::cos(phi);
|
||||
value_type sin_phi_r = sin_phi * radius;
|
||||
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(axis, i, j, k);
|
||||
|
||||
v[i] = cos_phi * radius;
|
||||
v[j] = sin_phi_r * std::cos(theta);
|
||||
v[k] = sin_phi_r * std::sin(theta);
|
||||
}
|
||||
|
||||
/* Convert polar coordinates to Cartesian coordinates in R2 */
|
||||
template < typename E, class A > void
|
||||
polar_to_cartesian(E radius, E theta, vector<E,A>& v)
|
||||
{
|
||||
/* Checking handled by set() */
|
||||
v.set(std::cos(theta) * radius, std::sin(theta) * radius);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Conversion from Cartesian coordinates
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Convert Cartesian coordinates to cylindrical coordinates in R3 */
|
||||
template < class VecT, typename Real > void
|
||||
cartesian_to_cylindrical(const VecT& v, Real& radius, Real& theta,
|
||||
Real& height, size_t axis, Real tolerance = epsilon<Real>::placeholder())
|
||||
{
|
||||
typedef Real value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckVec3(v);
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(axis, i, j, k);
|
||||
|
||||
radius = length(v[j],v[k]);
|
||||
theta = radius < tolerance ? value_type(0) : std::atan2(v[k],v[j]);
|
||||
height = v[i];
|
||||
}
|
||||
|
||||
/* Convert Cartesian coordinates to spherical coordinates in R3 */
|
||||
template < class VecT, typename Real > void
|
||||
cartesian_to_spherical(const VecT& v, Real& radius, Real& theta, Real& phi,
|
||||
size_t axis, SphericalType type,
|
||||
Real tolerance = epsilon<Real>::placeholder())
|
||||
{
|
||||
typedef Real value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckVec3(v);
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(axis, i, j, k);
|
||||
|
||||
value_type len = length(v[j],v[k]);
|
||||
theta = len < tolerance ? value_type(0) : std::atan2(v[k],v[j]);
|
||||
radius = length(v[i], len);
|
||||
if (radius < tolerance) {
|
||||
phi = value_type(0);
|
||||
} else {
|
||||
phi = std::atan2(len,v[i]);
|
||||
//phi = type.convert(phi);
|
||||
if (type == latitude) {
|
||||
phi = constants<value_type>::pi_over_2() - phi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert Cartesian coordinates to polar coordinates in R2 */
|
||||
template < class VecT, typename Real > void
|
||||
cartesian_to_polar(const VecT& v, Real& radius, Real& theta,
|
||||
Real tolerance = epsilon<Real>::placeholder())
|
||||
{
|
||||
typedef Real value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckVec2(v);
|
||||
|
||||
radius = v.length();
|
||||
theta = radius < tolerance ? value_type(0) : std::atan2(v[1],v[0]);
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
44
Lib/Include/CML/mathlib/epsilon.h
Normal file
44
Lib/Include/CML/mathlib/epsilon.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef epsilon_h
|
||||
#define epsilon_h
|
||||
|
||||
namespace cml {
|
||||
|
||||
/* @todo: epsilon and tolerance handling.
|
||||
*
|
||||
* @note This is a placeholder for a more sophisticated epsilon/tolerance
|
||||
* system.
|
||||
*/
|
||||
|
||||
template < typename Real >
|
||||
struct epsilon
|
||||
{
|
||||
typedef Real value_type;
|
||||
|
||||
private:
|
||||
|
||||
/** For convenience */
|
||||
typedef value_type T;
|
||||
|
||||
public:
|
||||
|
||||
static T placeholder() {
|
||||
/* Completely arbitrary placeholder value: */
|
||||
return T(0.0001);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
258
Lib/Include/CML/mathlib/frustum.h
Normal file
258
Lib/Include/CML/mathlib/frustum.h
Normal file
@@ -0,0 +1,258 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef frustum_h
|
||||
#define frustum_h
|
||||
|
||||
#include <cml/mathlib/matrix_concat.h>
|
||||
#include <cml/mathlib/checking.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/* @todo: plane class, and perhaps named arguments instead of an array. */
|
||||
|
||||
/* Extract the planes of a frustum given a modelview matrix and a projection
|
||||
* matrix with the given near z-clipping range. The planes are normalized by
|
||||
* default, but this can be turned off with the 'normalize' argument.
|
||||
*
|
||||
* The planes are in ax+by+cz+d = 0 form, and are in the order:
|
||||
* left
|
||||
* right
|
||||
* bottom
|
||||
* top
|
||||
* near
|
||||
* far
|
||||
*/
|
||||
|
||||
template < class MatT, typename Real > void
|
||||
extract_frustum_planes(
|
||||
const MatT& modelview,
|
||||
const MatT& projection,
|
||||
Real planes[6][4],
|
||||
ZClip z_clip,
|
||||
bool normalize = true)
|
||||
{
|
||||
extract_frustum_planes(
|
||||
detail::matrix_concat_transforms_4x4(modelview,projection),
|
||||
planes,
|
||||
z_clip,
|
||||
normalize
|
||||
);
|
||||
}
|
||||
|
||||
/* Extract the planes of a frustum from a single matrix assumed to contain any
|
||||
* model and view transforms followed by a projection transform with the given
|
||||
* near z-cliping range. The planes are normalized by default, but this can be
|
||||
* turned off with the 'normalize' argument.
|
||||
*
|
||||
* The planes are in ax+by+cz+d = 0 form, and are in the order:
|
||||
* left
|
||||
* right
|
||||
* bottom
|
||||
* top
|
||||
* near
|
||||
* far
|
||||
*/
|
||||
|
||||
template < class MatT, typename Real > void
|
||||
extract_frustum_planes(
|
||||
const MatT& m,
|
||||
Real planes[6][4],
|
||||
ZClip z_clip,
|
||||
bool normalize = true)
|
||||
{
|
||||
detail::CheckMatHomogeneous3D(m);
|
||||
|
||||
/* Left: [03+00, 13+10, 23+20, 33+30] */
|
||||
|
||||
planes[0][0] = m.basis_element(0,3) + m.basis_element(0,0);
|
||||
planes[0][1] = m.basis_element(1,3) + m.basis_element(1,0);
|
||||
planes[0][2] = m.basis_element(2,3) + m.basis_element(2,0);
|
||||
planes[0][3] = m.basis_element(3,3) + m.basis_element(3,0);
|
||||
|
||||
/* Right: [03-00, 13-10, 23-20, 33-30] */
|
||||
|
||||
planes[1][0] = m.basis_element(0,3) - m.basis_element(0,0);
|
||||
planes[1][1] = m.basis_element(1,3) - m.basis_element(1,0);
|
||||
planes[1][2] = m.basis_element(2,3) - m.basis_element(2,0);
|
||||
planes[1][3] = m.basis_element(3,3) - m.basis_element(3,0);
|
||||
|
||||
/* Bottom: [03+01, 13+11, 23+21, 33+31] */
|
||||
|
||||
planes[2][0] = m.basis_element(0,3) + m.basis_element(0,1);
|
||||
planes[2][1] = m.basis_element(1,3) + m.basis_element(1,1);
|
||||
planes[2][2] = m.basis_element(2,3) + m.basis_element(2,1);
|
||||
planes[2][3] = m.basis_element(3,3) + m.basis_element(3,1);
|
||||
|
||||
/* Top: [03-01, 13-11, 23-21, 33-31] */
|
||||
|
||||
planes[3][0] = m.basis_element(0,3) - m.basis_element(0,1);
|
||||
planes[3][1] = m.basis_element(1,3) - m.basis_element(1,1);
|
||||
planes[3][2] = m.basis_element(2,3) - m.basis_element(2,1);
|
||||
planes[3][3] = m.basis_element(3,3) - m.basis_element(3,1);
|
||||
|
||||
/* Far: [03-02, 13-12, 23-22, 33-32] */
|
||||
|
||||
planes[5][0] = m.basis_element(0,3) - m.basis_element(0,2);
|
||||
planes[5][1] = m.basis_element(1,3) - m.basis_element(1,2);
|
||||
planes[5][2] = m.basis_element(2,3) - m.basis_element(2,2);
|
||||
planes[5][3] = m.basis_element(3,3) - m.basis_element(3,2);
|
||||
|
||||
/* Near: [03+02, 13+12, 23+22, 33+32] : [02, 12, 22, 32] */
|
||||
extract_near_frustum_plane(m, planes[4], z_clip);
|
||||
|
||||
/* @todo: This will be handled by the plane class */
|
||||
if (normalize) {
|
||||
for (size_t i = 0; i < 6; ++i) {
|
||||
Real invl = inv_sqrt(planes[i][0] * planes[i][0] +
|
||||
planes[i][1] * planes[i][1] +
|
||||
planes[i][2] * planes[i][2]);
|
||||
|
||||
planes[i][0] *= invl;
|
||||
planes[i][1] *= invl;
|
||||
planes[i][2] *= invl;
|
||||
planes[i][3] *= invl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Extract the near plane of a frustum given a concatenated modelview and
|
||||
* projection matrix with the given near z-clipping range. The plane is
|
||||
* not normalized.
|
||||
*
|
||||
* @note The plane is in ax+by+cz+d = 0 form.
|
||||
*
|
||||
* @warning The matrix is assumed to be a homogeneous transformation
|
||||
* matrix.
|
||||
*/
|
||||
template < class MatT, class PlaneT > void
|
||||
extract_near_frustum_plane(
|
||||
const MatT& m,
|
||||
PlaneT& plane,
|
||||
ZClip z_clip
|
||||
)
|
||||
{
|
||||
/* Near: [03+02, 13+12, 23+22, 33+32] : [02, 12, 22, 32] */
|
||||
if (z_clip == z_clip_neg_one) {
|
||||
plane[0] = m.basis_element(0,3) + m.basis_element(0,2);
|
||||
plane[1] = m.basis_element(1,3) + m.basis_element(1,2);
|
||||
plane[2] = m.basis_element(2,3) + m.basis_element(2,2);
|
||||
plane[3] = m.basis_element(3,3) + m.basis_element(3,2);
|
||||
} else { // z_clip == z_clip_zero
|
||||
plane[0] = m.basis_element(0,2);
|
||||
plane[1] = m.basis_element(1,2);
|
||||
plane[2] = m.basis_element(2,2);
|
||||
plane[3] = m.basis_element(3,2);
|
||||
}
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
/* This is currently only in support of finding the corners of a frustum.
|
||||
* The input planes are assumed to have a single unique intersection, so
|
||||
* no tolerance is used.
|
||||
*/
|
||||
|
||||
template < typename Real > vector< Real, fixed<3> >
|
||||
intersect_planes(Real p1[4], Real p2[4], Real p3[4])
|
||||
{
|
||||
typedef vector< Real, fixed<3> > vector_type;
|
||||
typedef typename vector_type::value_type value_type;
|
||||
|
||||
vector_type n1(p1[0],p1[1],p1[2]);
|
||||
vector_type n2(p2[0],p2[1],p2[2]);
|
||||
vector_type n3(p3[0],p3[1],p3[2]);
|
||||
|
||||
value_type d1 = -p1[3];
|
||||
value_type d2 = -p2[3];
|
||||
value_type d3 = -p3[3];
|
||||
|
||||
vector_type numer =
|
||||
d1*cross(n2,n3) + d2*cross(n3,n1) + d3*cross(n1,n2);
|
||||
value_type denom = triple_product(n1,n2,n3);
|
||||
return numer/denom;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/* Get the corners of a frustum defined by 6 planes. The planes are in
|
||||
* ax+by+cz+d = 0 form, and are in the order:
|
||||
* left
|
||||
* right
|
||||
* bottom
|
||||
* top
|
||||
* near
|
||||
* far
|
||||
*
|
||||
* The corners are in CCW order starting in the lower-left, first at the near
|
||||
* plane, then at the far plane.
|
||||
*/
|
||||
|
||||
template < typename Real, typename E, class A > void
|
||||
get_frustum_corners(Real planes[6][4], vector<E,A> corners[8])
|
||||
{
|
||||
// NOTE: Prefixed with 'PLANE_' due to symbol conflict with Windows
|
||||
// macros PLANE_LEFT and PLANE_RIGHT.
|
||||
enum {
|
||||
PLANE_LEFT,
|
||||
PLANE_RIGHT,
|
||||
PLANE_BOTTOM,
|
||||
PLANE_TOP,
|
||||
PLANE_NEAR,
|
||||
PLANE_FAR
|
||||
};
|
||||
|
||||
corners[0] = detail::intersect_planes(
|
||||
planes[PLANE_LEFT],
|
||||
planes[PLANE_BOTTOM],
|
||||
planes[PLANE_NEAR]
|
||||
);
|
||||
corners[1] = detail::intersect_planes(
|
||||
planes[PLANE_RIGHT],
|
||||
planes[PLANE_BOTTOM],
|
||||
planes[PLANE_NEAR]
|
||||
);
|
||||
corners[2] = detail::intersect_planes(
|
||||
planes[PLANE_RIGHT],
|
||||
planes[PLANE_TOP],
|
||||
planes[PLANE_NEAR]
|
||||
);
|
||||
corners[3] = detail::intersect_planes(
|
||||
planes[PLANE_LEFT],
|
||||
planes[PLANE_TOP],
|
||||
planes[PLANE_NEAR]
|
||||
);
|
||||
corners[4] = detail::intersect_planes(
|
||||
planes[PLANE_LEFT],
|
||||
planes[PLANE_BOTTOM],
|
||||
planes[PLANE_FAR]
|
||||
);
|
||||
corners[5] = detail::intersect_planes(
|
||||
planes[PLANE_RIGHT],
|
||||
planes[PLANE_BOTTOM],
|
||||
planes[PLANE_FAR]
|
||||
);
|
||||
corners[6] = detail::intersect_planes(
|
||||
planes[PLANE_RIGHT],
|
||||
planes[PLANE_TOP],
|
||||
planes[PLANE_FAR]
|
||||
);
|
||||
corners[7] = detail::intersect_planes(
|
||||
planes[PLANE_LEFT],
|
||||
planes[PLANE_TOP],
|
||||
planes[PLANE_FAR]
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
158
Lib/Include/CML/mathlib/helper.h
Normal file
158
Lib/Include/CML/mathlib/helper.h
Normal file
@@ -0,0 +1,158 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef helper_h
|
||||
#define helper_h
|
||||
|
||||
#include <cstddef>
|
||||
#include <cml/constants.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/* Helper classes for axis order, coordinate system handedness, z-clipping
|
||||
* range and spherical coordinate type.
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Euler order
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum EulerOrder {
|
||||
euler_order_xyz, // 0x00 [0000]
|
||||
euler_order_xyx, // 0x01 [0001]
|
||||
euler_order_xzy, // 0x02 [0010]
|
||||
euler_order_xzx, // 0x03 [0011]
|
||||
euler_order_yzx, // 0x04 [0100]
|
||||
euler_order_yzy, // 0x05 [0101]
|
||||
euler_order_yxz, // 0x06 [0110]
|
||||
euler_order_yxy, // 0x07 [0111]
|
||||
euler_order_zxy, // 0x08 [1000]
|
||||
euler_order_zxz, // 0x09 [1001]
|
||||
euler_order_zyx, // 0x0A [1010]
|
||||
euler_order_zyz // 0x0B [1011]
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
inline void unpack_euler_order(
|
||||
EulerOrder order,
|
||||
size_t& i,
|
||||
size_t& j,
|
||||
size_t& k,
|
||||
bool& odd,
|
||||
bool& repeat)
|
||||
{
|
||||
enum { REPEAT = 0x01, ODD = 0x02, AXIS = 0x0C };
|
||||
|
||||
repeat = order & REPEAT;
|
||||
odd = ((order & ODD) == ODD);
|
||||
size_t offset = size_t(odd);
|
||||
i = (order & AXIS) % 3;
|
||||
j = (i + 1 + offset) % 3;
|
||||
k = (i + 2 - offset) % 3;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Axis order
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum AxisOrder {
|
||||
axis_order_xyz = euler_order_xyz, // 0x00 [0000]
|
||||
axis_order_xzy = euler_order_xzy, // 0x02 [0010]
|
||||
axis_order_yzx = euler_order_yzx, // 0x04 [0100]
|
||||
axis_order_yxz = euler_order_yxz, // 0x06 [0110]
|
||||
axis_order_zxy = euler_order_zxy, // 0x08 [1000]
|
||||
axis_order_zyx = euler_order_zyx // 0x0A [1010]
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
inline void unpack_axis_order(
|
||||
AxisOrder order,
|
||||
size_t& i,
|
||||
size_t& j,
|
||||
size_t& k,
|
||||
bool& odd)
|
||||
{
|
||||
enum { ODD = 0x02, AXIS = 0x0C };
|
||||
|
||||
odd = ((order & ODD) == ODD);
|
||||
size_t offset = size_t(odd);
|
||||
i = (order & AXIS) % 3;
|
||||
j = (i + 1 + offset) % 3;
|
||||
k = (i + 2 - offset) % 3;
|
||||
}
|
||||
|
||||
inline AxisOrder pack_axis_order(size_t i, bool odd) {
|
||||
return AxisOrder((i << 2) | (size_t(odd) << 1));
|
||||
}
|
||||
|
||||
inline AxisOrder swap_axis_order(AxisOrder order)
|
||||
{
|
||||
size_t i, j, k;
|
||||
bool odd;
|
||||
unpack_axis_order(order, i, j, k, odd);
|
||||
return pack_axis_order(j, !odd);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Axis order 2D
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum AxisOrder2D {
|
||||
axis_order_xy = axis_order_xyz, // 0x00 [0000]
|
||||
axis_order_yx = axis_order_yxz // 0x06 [0110]
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
inline void unpack_axis_order_2D(
|
||||
AxisOrder2D order,
|
||||
size_t& i,
|
||||
size_t& j,
|
||||
bool& odd)
|
||||
{
|
||||
enum { ODD = 0x02, AXIS = 0x0C };
|
||||
|
||||
odd = ((order & ODD) == ODD);
|
||||
size_t offset = size_t(odd);
|
||||
i = (order & AXIS) % 3;
|
||||
j = (i + 1 + offset) % 3;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Handedness
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum Handedness { left_handed, right_handed };
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Z clip
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum ZClip { z_clip_neg_one, z_clip_zero };
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Spherical coordinate type
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum SphericalType { latitude, colatitude };
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
1129
Lib/Include/CML/mathlib/interpolation.h
Normal file
1129
Lib/Include/CML/mathlib/interpolation.h
Normal file
File diff suppressed because it is too large
Load Diff
33
Lib/Include/CML/mathlib/mathlib.h
Normal file
33
Lib/Include/CML/mathlib/mathlib.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef mathlib_h
|
||||
#define mathlib_h
|
||||
|
||||
#include <cml/mathlib/typedef.h>
|
||||
#include <cml/mathlib/epsilon.h>
|
||||
#include <cml/mathlib/vector_angle.h>
|
||||
#include <cml/mathlib/vector_ortho.h>
|
||||
#include <cml/mathlib/vector_transform.h>
|
||||
#include <cml/mathlib/matrix_ortho.h>
|
||||
#include <cml/mathlib/matrix_rotation.h>
|
||||
#include <cml/mathlib/matrix_transform.h>
|
||||
#include <cml/mathlib/matrix_projection.h>
|
||||
#include <cml/mathlib/quaternion_basis.h>
|
||||
#include <cml/mathlib/quaternion_rotation.h>
|
||||
#include <cml/mathlib/coord_conversion.h>
|
||||
#include <cml/mathlib/interpolation.h>
|
||||
#include <cml/mathlib/frustum.h>
|
||||
#include <cml/mathlib/projection.h>
|
||||
#include <cml/mathlib/picking.h>
|
||||
|
||||
#endif
|
||||
364
Lib/Include/CML/mathlib/matrix_basis.h
Normal file
364
Lib/Include/CML/mathlib/matrix_basis.h
Normal file
@@ -0,0 +1,364 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef matrix_basis_h
|
||||
#define matrix_basis_h
|
||||
|
||||
#include <cml/mathlib/checking.h>
|
||||
|
||||
/* This file contains functions for setting and retrieving the basis vectors
|
||||
* or transposed basis vectors of a matrix representing a 3D or 2D transform,
|
||||
* either by index (0,1,2) or name (x,y,z).
|
||||
*
|
||||
* In addition to being a convenience for the user, the functions are also
|
||||
* in support of other matrix functions which are best implemented in vector
|
||||
* form (such as orthogonalization and construction of orthonormal bases).
|
||||
*
|
||||
* Note that matrix expression arguments are allowed to have dimensions larger
|
||||
* than the minimum requirement. For example, matrix_get_basis_vector() can be
|
||||
* called on any NxM matrix with N,M >= 3.
|
||||
*
|
||||
* As with other matrix functions, the following template argument notation is
|
||||
* used for conciseness:
|
||||
*
|
||||
* E = vector or matrix element type
|
||||
* A = vector or matrix array storage type
|
||||
* B = matrix basis orientation type
|
||||
* L = matrix layout type
|
||||
*/
|
||||
|
||||
namespace cml {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Functions for setting the basis vectors of a 3D or 2D transform matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Set the i'th basis vector of a 3D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_basis_vector(matrix<E,A,B,L>& m, size_t i, const VecT& v)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckVec3(v);
|
||||
detail::CheckIndex3(i);
|
||||
|
||||
m.set_basis_element(i,0,v[0]);
|
||||
m.set_basis_element(i,1,v[1]);
|
||||
m.set_basis_element(i,2,v[2]);
|
||||
}
|
||||
|
||||
/** Set the i'th transposed basis vector of a 3D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_transposed_basis_vector(matrix<E,A,B,L>& m,size_t i,const VecT& v)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckVec3(v);
|
||||
detail::CheckIndex3(i);
|
||||
|
||||
m.set_basis_element(0,i,v[0]);
|
||||
m.set_basis_element(1,i,v[1]);
|
||||
m.set_basis_element(2,i,v[2]);
|
||||
}
|
||||
|
||||
/** Set the i'th basis vector of a 2D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_basis_vector_2D(matrix<E,A,B,L>& m, size_t i, const VecT& v)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
detail::CheckVec2(v);
|
||||
detail::CheckIndex2(i);
|
||||
|
||||
m.set_basis_element(i,0,v[0]);
|
||||
m.set_basis_element(i,1,v[1]);
|
||||
}
|
||||
|
||||
/** Set the i'th transposed basis vector of a 2D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_transposed_basis_vector_2D(
|
||||
matrix<E,A,B,L>& m, size_t i, const VecT& v)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
detail::CheckVec2(v);
|
||||
detail::CheckIndex2(i);
|
||||
|
||||
m.set_basis_element(0,i,v[0]);
|
||||
m.set_basis_element(1,i,v[1]);
|
||||
}
|
||||
|
||||
/** Set the x basis vector of a 3D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_x_basis_vector(matrix<E,A,B,L>& m, const VecT& x) {
|
||||
matrix_set_basis_vector(m,0,x);
|
||||
}
|
||||
|
||||
/** Set the y basis vector of a 3D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_y_basis_vector(matrix<E,A,B,L>& m, const VecT& y) {
|
||||
matrix_set_basis_vector(m,1,y);
|
||||
}
|
||||
|
||||
/** Set the z basis vector of a 3D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_z_basis_vector(matrix<E,A,B,L>& m, const VecT& z) {
|
||||
matrix_set_basis_vector(m,2,z);
|
||||
}
|
||||
|
||||
/** Set the transposed x basis vector of a 3D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_transposed_x_basis_vector(matrix<E,A,B,L>& m, const VecT& x) {
|
||||
matrix_set_transposed_basis_vector(m,0,x);
|
||||
}
|
||||
|
||||
/** Set the transposed y basis vector of a 3D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_transposed_y_basis_vector(matrix<E,A,B,L>& m, const VecT& y) {
|
||||
matrix_set_transposed_basis_vector(m,1,y);
|
||||
}
|
||||
|
||||
/** Set the transposed z basis vector of a 3D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_transposed_z_basis_vector(matrix<E,A,B,L>& m, const VecT& z) {
|
||||
matrix_set_transposed_basis_vector(m,2,z);
|
||||
}
|
||||
|
||||
/** Set the x basis vector of a 2D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_x_basis_vector_2D(matrix<E,A,B,L>& m, const VecT& x) {
|
||||
matrix_set_basis_vector_2D(m,0,x);
|
||||
}
|
||||
|
||||
/** Set the y basis vector of a 2D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_y_basis_vector_2D(matrix<E,A,B,L>& m, const VecT& y) {
|
||||
matrix_set_basis_vector_2D(m,1,y);
|
||||
}
|
||||
|
||||
/** Set the transposed x basis vector of a 2D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_transposed_x_basis_vector_2D(matrix<E,A,B,L>& m,const VecT& x) {
|
||||
matrix_set_transposed_basis_vector_2D(m,0,x);
|
||||
}
|
||||
|
||||
/** Set the transposed y basis vector of a 2D transform */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_transposed_y_basis_vector_2D(matrix<E,A,B,L>& m,const VecT& y) {
|
||||
matrix_set_transposed_basis_vector_2D(m,1,y);
|
||||
}
|
||||
|
||||
/** Set the basis vectors of a 3D transform */
|
||||
template < typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
matrix_set_basis_vectors(
|
||||
matrix<E,A,B,L>& m, const VecT_1& x, const VecT_2& y, const VecT_3& z)
|
||||
{
|
||||
matrix_set_x_basis_vector(m,x);
|
||||
matrix_set_y_basis_vector(m,y);
|
||||
matrix_set_z_basis_vector(m,z);
|
||||
}
|
||||
|
||||
/** Set the transposed basis vectors of a 3D transform */
|
||||
template < typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
matrix_set_transposed_basis_vectors(
|
||||
matrix<E,A,B,L>& m, const VecT_1& x, const VecT_2& y, const VecT_3& z)
|
||||
{
|
||||
matrix_set_transposed_x_basis_vector(m,x);
|
||||
matrix_set_transposed_y_basis_vector(m,y);
|
||||
matrix_set_transposed_z_basis_vector(m,z);
|
||||
}
|
||||
|
||||
/** Set the basis vectors of a 2D transform */
|
||||
template < typename E,class A,class B,class L,class VecT_1,class VecT_2 > void
|
||||
matrix_set_basis_vectors_2D(
|
||||
matrix<E,A,B,L>& m, const VecT_1& x, const VecT_2& y)
|
||||
{
|
||||
matrix_set_x_basis_vector_2D(m,x);
|
||||
matrix_set_y_basis_vector_2D(m,y);
|
||||
}
|
||||
|
||||
/** Set the transposed basis vectors of a 2D transform */
|
||||
template < typename E,class A,class B,class L,class VecT_1,class VecT_2 > void
|
||||
matrix_set_transposed_basis_vectors_2D(
|
||||
matrix<E,A,B,L>& m, const VecT_1& x, const VecT_2& y)
|
||||
{
|
||||
matrix_set_transposed_x_basis_vector_2D(m,x);
|
||||
matrix_set_transposed_y_basis_vector_2D(m,y);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Functions for getting the basis vectors of a 3D or 2D transform matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TEMP_VEC3 vector< typename MatT::value_type, fixed<3> >
|
||||
#define TEMP_VEC2 vector< typename MatT::value_type, fixed<2> >
|
||||
|
||||
/** Get the i'th basis vector of a 3D transform */
|
||||
template < class MatT > TEMP_VEC3
|
||||
matrix_get_basis_vector(const MatT& m, size_t i)
|
||||
{
|
||||
typedef TEMP_VEC3 vector_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckIndex3(i);
|
||||
|
||||
return vector_type(
|
||||
m.basis_element(i,0), m.basis_element(i,1), m.basis_element(i,2));
|
||||
}
|
||||
|
||||
/** Get the i'th transposed basis vector of a 3D transform */
|
||||
template < class MatT > TEMP_VEC3
|
||||
matrix_get_transposed_basis_vector(const MatT& m, size_t i)
|
||||
{
|
||||
typedef typename MatT::value_type value_type;
|
||||
typedef vector< value_type, fixed<3> > vector_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckIndex3(i);
|
||||
|
||||
return vector_type(
|
||||
m.basis_element(0,i), m.basis_element(1,i), m.basis_element(2,i));
|
||||
}
|
||||
|
||||
/** Get the i'th basis vector of a 2D transform */
|
||||
template < class MatT > TEMP_VEC2
|
||||
matrix_get_basis_vector_2D(const MatT& m, size_t i)
|
||||
{
|
||||
typedef TEMP_VEC2 vector_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
detail::CheckIndex2(i);
|
||||
|
||||
return vector_type(m.basis_element(i,0), m.basis_element(i,1));
|
||||
}
|
||||
|
||||
/** Get the i'th transposed basis vector of a 2D transform */
|
||||
template < class MatT > TEMP_VEC2
|
||||
matrix_get_transposed_basis_vector_2D(const MatT& m, size_t i)
|
||||
{
|
||||
typedef TEMP_VEC2 vector_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
detail::CheckIndex2(i);
|
||||
|
||||
return vector_type(m.basis_element(0,i), m.basis_element(1,i));
|
||||
}
|
||||
|
||||
/** Get the x basis vector of a 3D transform */
|
||||
template < class MatT > TEMP_VEC3
|
||||
matrix_get_x_basis_vector(const MatT& m) {
|
||||
return matrix_get_basis_vector(m,0);
|
||||
}
|
||||
|
||||
/** Get the y basis vector of a 3D transform */
|
||||
template < class MatT > TEMP_VEC3
|
||||
matrix_get_y_basis_vector(const MatT& m) {
|
||||
return matrix_get_basis_vector(m,1);
|
||||
}
|
||||
|
||||
/** Get the z basis vector of a 3D transform */
|
||||
template < class MatT > TEMP_VEC3
|
||||
matrix_get_z_basis_vector(const MatT& m) {
|
||||
return matrix_get_basis_vector(m,2);
|
||||
}
|
||||
|
||||
/** Get the transposed x basis vector of a 3D transform */
|
||||
template < class MatT > TEMP_VEC3
|
||||
matrix_get_transposed_x_basis_vector(const MatT& m) {
|
||||
return matrix_get_transposed_basis_vector(m,0);
|
||||
}
|
||||
|
||||
/** Get the transposed y basis vector of a 3D transform */
|
||||
template < class MatT > TEMP_VEC3
|
||||
matrix_get_transposed_y_basis_vector(const MatT& m) {
|
||||
return matrix_get_transposed_basis_vector(m,1);
|
||||
}
|
||||
|
||||
/** Get the transposed z basis vector of a 3D transform */
|
||||
template < class MatT > TEMP_VEC3
|
||||
matrix_get_transposed_z_basis_vector(const MatT& m) {
|
||||
return matrix_get_transposed_basis_vector(m,2);
|
||||
}
|
||||
|
||||
/** Get the x basis vector of a 2D transform */
|
||||
template < class MatT > TEMP_VEC2
|
||||
matrix_get_x_basis_vector_2D(const MatT& m) {
|
||||
return matrix_get_basis_vector_2D(m,0);
|
||||
}
|
||||
|
||||
/** Get the y basis vector of a 2D transform */
|
||||
template < class MatT > TEMP_VEC2
|
||||
matrix_get_y_basis_vector_2D(const MatT& m) {
|
||||
return matrix_get_basis_vector_2D(m,1);
|
||||
}
|
||||
|
||||
/** Get the transposed x basis vector of a 2D transform */
|
||||
template < class MatT > TEMP_VEC2
|
||||
matrix_get_transposed_x_basis_vector_2D(const MatT& m) {
|
||||
return matrix_get_transposed_basis_vector_2D(m,0);
|
||||
}
|
||||
|
||||
/** Get the transposed y basis vector of a 2D transform */
|
||||
template < class MatT > TEMP_VEC2
|
||||
matrix_get_transposed_y_basis_vector_2D(const MatT& m) {
|
||||
return matrix_get_transposed_basis_vector_2D(m,1);
|
||||
}
|
||||
|
||||
/** Get the basis vectors of a 3D transform */
|
||||
template < class MatT, class E, class A > void
|
||||
matrix_get_basis_vectors(
|
||||
const MatT& m, vector<E,A>& x, vector<E,A>& y, vector<E,A>& z)
|
||||
{
|
||||
x = matrix_get_x_basis_vector(m);
|
||||
y = matrix_get_y_basis_vector(m);
|
||||
z = matrix_get_z_basis_vector(m);
|
||||
}
|
||||
|
||||
/** Get the transposed basis vectors of a 3D transform */
|
||||
template < class MatT, typename E, class A > void
|
||||
matrix_get_transposed_basis_vectors(
|
||||
const MatT& m, vector<E,A>& x, vector<E,A>& y, vector<E,A>& z)
|
||||
{
|
||||
x = matrix_get_transposed_x_basis_vector(m);
|
||||
y = matrix_get_transposed_y_basis_vector(m);
|
||||
z = matrix_get_transposed_z_basis_vector(m);
|
||||
}
|
||||
|
||||
/** Get the basis vectors of a 2D transform */
|
||||
template < class MatT, typename E, class A > void
|
||||
matrix_get_basis_vectors_2D(const MatT& m,vector<E,A>& x,vector<E,A>& y)
|
||||
{
|
||||
x = matrix_get_x_basis_vector_2D(m);
|
||||
y = matrix_get_y_basis_vector_2D(m);
|
||||
}
|
||||
|
||||
/** Get the transposed basis vectors of a 2D transform */
|
||||
template < class MatT, typename E, class A > void
|
||||
matrix_get_transposed_basis_vectors_2D(
|
||||
const MatT& m, vector<E,A>& x, vector<E,A>& y)
|
||||
{
|
||||
x = matrix_get_transposed_x_basis_vector_2D(m);
|
||||
y = matrix_get_transposed_y_basis_vector_2D(m);
|
||||
}
|
||||
|
||||
#undef TEMP_VEC3
|
||||
#undef TEMP_VEC2
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
62
Lib/Include/CML/mathlib/matrix_concat.h
Normal file
62
Lib/Include/CML/mathlib/matrix_concat.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef matrix_concat_h
|
||||
#define matrix_concat_h
|
||||
|
||||
#include <cml/matrix/matrix_expr.h>
|
||||
|
||||
/* This will all most likely be abstracted away in a future version of the
|
||||
* CML. For now, this file provides support for functions that need to
|
||||
* concatenate transformation matrices in a basis-independent manner.
|
||||
*
|
||||
* @todo: The 2x2 and 3x3 versions of these functions are currently in
|
||||
* matrix_rotation.h. They should be moved here.
|
||||
*/
|
||||
|
||||
namespace cml {
|
||||
namespace detail {
|
||||
|
||||
/** A fixed-size temporary 4x4 matrix */
|
||||
#define MAT_TEMP_4X4 matrix< \
|
||||
typename et::ScalarPromote< \
|
||||
typename MatT_1::value_type, \
|
||||
typename MatT_2::value_type \
|
||||
>::type, \
|
||||
fixed<4,4>, \
|
||||
typename MatT_1::basis_orient, \
|
||||
typename MatT_1::layout \
|
||||
>
|
||||
|
||||
template < class MatT_1, class MatT_2 > MAT_TEMP_4X4
|
||||
matrix_concat_transforms_4x4(const MatT_1& m1, const MatT_2& m2, row_basis) {
|
||||
return m1*m2;
|
||||
}
|
||||
|
||||
/** Concatenate two 3D col-basis rotation matrices in the order m1->m2 */
|
||||
template < class MatT_1, class MatT_2 > MAT_TEMP_4X4
|
||||
matrix_concat_transforms_4x4(const MatT_1& m1, const MatT_2& m2, col_basis) {
|
||||
return m2*m1;
|
||||
}
|
||||
|
||||
/** Concatenate two 3D rotation matrices in the order m1->m2 */
|
||||
template < class MatT_1, class MatT_2 > MAT_TEMP_4X4
|
||||
matrix_concat_transforms_4x4(const MatT_1& m1, const MatT_2& m2) {
|
||||
return matrix_concat_transforms_4x4(m1,m2,typename MatT_1::basis_orient());
|
||||
}
|
||||
|
||||
#undef MAT_TEMP_4x4
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
135
Lib/Include/CML/mathlib/matrix_misc.h
Normal file
135
Lib/Include/CML/mathlib/matrix_misc.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef matrix_misc_h
|
||||
#define matrix_misc_h
|
||||
|
||||
#include <cml/mathlib/checking.h>
|
||||
|
||||
/* Miscellaneous matrix functions. */
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** Set a (possibly non-square) matrix to represent an identity transform */
|
||||
template < typename E, class A, class B, class L > void
|
||||
identity_transform(matrix<E,A,B,L>& m)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
for (size_t i = 0; i < m.rows(); ++i) {
|
||||
for (size_t j = 0; j < m.cols(); ++j) {
|
||||
m(i,j) = value_type((i == j) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Trace of a square matrix */
|
||||
template < class MatT > typename MatT::value_type
|
||||
trace(const MatT& m)
|
||||
{
|
||||
typedef typename MatT::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatSquare(m);
|
||||
|
||||
value_type t = value_type(0);
|
||||
for (size_t i = 0; i < m.rows(); ++i) {
|
||||
t += m(i,i);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/** Trace of the upper-left 3x3 part of a matrix */
|
||||
template < class MatT > typename MatT::value_type
|
||||
trace_3x3(const MatT& m)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatMin3x3(m);
|
||||
|
||||
return m(0,0) + m(1,1) + m(2,2);
|
||||
}
|
||||
|
||||
/** Trace of the upper-left 2x2 part of a matrix */
|
||||
template < class MatT > typename MatT::value_type
|
||||
trace_2x2(const MatT& m)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatMin2x2(m);
|
||||
|
||||
return m(0,0) + m(1,1);
|
||||
}
|
||||
|
||||
/** 3D skew-symmetric matrix */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_skew_symmetric(matrix<E,A,B,L>& m, const VecT& v)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatMin3x3(m);
|
||||
detail::CheckVec3(v);
|
||||
|
||||
m.zero();
|
||||
|
||||
m.set_basis_element(1,2, v[0]);
|
||||
m.set_basis_element(2,1,-v[0]);
|
||||
m.set_basis_element(2,0, v[1]);
|
||||
m.set_basis_element(0,2,-v[1]);
|
||||
m.set_basis_element(0,1, v[2]);
|
||||
m.set_basis_element(1,0,-v[2]);
|
||||
}
|
||||
|
||||
/** 2D skew-symmetric matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_skew_symmetric_2D(matrix<E,A,B,L>& m, E s)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatMin2x2(m);
|
||||
|
||||
m.zero();
|
||||
|
||||
m.set_basis_element(0,1, s);
|
||||
m.set_basis_element(1,0,-s);
|
||||
}
|
||||
|
||||
/* @todo: Clean this up, and implement SRT as well */
|
||||
|
||||
/** Invert a matrix consisting of a 3D rotation and translation */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_invert_RT_only(matrix<E,A,B,L>& m)
|
||||
{
|
||||
typedef vector< E, fixed<3> > vector_type;
|
||||
|
||||
vector_type x, y, z;
|
||||
matrix_get_basis_vectors(m,x,y,z);
|
||||
matrix_set_transposed_basis_vectors(m,x,y,z);
|
||||
|
||||
vector_type p = matrix_get_translation(m);
|
||||
matrix_set_translation(m,-dot(p,x),-dot(p,y),-dot(p,z));
|
||||
}
|
||||
|
||||
/** Invert a matrix consisting of a 2D rotation and ranslation */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_invert_RT_only_2D(matrix<E,A,B,L>& m)
|
||||
{
|
||||
typedef vector< E, fixed<2> > vector_type;
|
||||
|
||||
vector_type x, y;
|
||||
matrix_get_basis_vectors_2D(m,x,y);
|
||||
matrix_set_transposed_basis_vectors_2D(m,x,y);
|
||||
|
||||
vector_type p = matrix_get_translation_2D(m);
|
||||
matrix_set_translation_2D(m,-dot(p,x),-dot(p,y));
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
60
Lib/Include/CML/mathlib/matrix_ortho.h
Normal file
60
Lib/Include/CML/mathlib/matrix_ortho.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef matrix_ortho_h
|
||||
#define matrix_ortho_h
|
||||
|
||||
#include <cml/mathlib/vector_ortho.h>
|
||||
|
||||
/* Functions for orthogonalizing a matrix.
|
||||
*
|
||||
* matrix_orthogonalize_3x3() and _2x2() operate on the upper-left-hand part
|
||||
* of any matrix of suitable size; this is to allow orthonormalization of the
|
||||
* rotation part of an affine transform matrix.
|
||||
*
|
||||
* Note: These functions pass off to the orthonormalization functions in
|
||||
* vector_ortho.h, so see that file for details on the optional parameters.
|
||||
*
|
||||
* @todo: General NxN matrix orthogonalization.
|
||||
*/
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** Orthogonalize the upper-left 3x3 portion of a matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_orthogonalize_3x3(matrix<E,A,B,L>& m, size_t stable_axis = 2,
|
||||
size_t num_iter = 0, E s = E(1))
|
||||
{
|
||||
typedef vector< E, fixed<3> > vector_type;
|
||||
|
||||
vector_type x, y, z;
|
||||
matrix_get_basis_vectors(m,x,y,z);
|
||||
orthonormalize(x,y,z,stable_axis,num_iter,s);
|
||||
matrix_set_basis_vectors(m,x,y,z);
|
||||
}
|
||||
|
||||
/** Orthogonalize the upper-left 2x2 portion of a matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_orthogonalize_2x2(matrix<E,A,B,L>& m, size_t stable_axis = 0,
|
||||
size_t num_iter = 0, E s = E(1))
|
||||
{
|
||||
typedef vector< E, fixed<2> > vector_type;
|
||||
|
||||
vector_type x, y;
|
||||
matrix_get_basis_vectors_2D(m,x,y);
|
||||
orthonormalize(x,y,stable_axis,num_iter,s);
|
||||
matrix_set_basis_vectors_2D(m,x,y);
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
348
Lib/Include/CML/mathlib/matrix_projection.h
Normal file
348
Lib/Include/CML/mathlib/matrix_projection.h
Normal file
@@ -0,0 +1,348 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef matrix_projection_h
|
||||
#define matrix_projection_h
|
||||
|
||||
#include <cml/mathlib/checking.h>
|
||||
#include <cml/mathlib/helper.h>
|
||||
|
||||
/* Functions for building matrix transforms other than rotations
|
||||
* (matrix_rotation.h) and viewing projections (matrix_projection.h).
|
||||
*
|
||||
* @todo: Clean up comments and documentation throughout.
|
||||
*/
|
||||
|
||||
// NOTE: Changed 'near' and 'far' to 'n' and 'f' throughout to work around
|
||||
// windows.h 'near' and 'far' macros.
|
||||
|
||||
namespace cml {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D perspective projection from frustum
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a perspective projection, specified by frustum
|
||||
* bounds in l,r,b,t,n,f form, and with the given handedness and z clipping
|
||||
* range
|
||||
*/
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective(matrix<E,A,B,L>& m, E left, E right, E bottom, E top,
|
||||
E n, E f, Handedness handedness,
|
||||
ZClip z_clip)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatHomogeneous3D(m);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
value_type inv_width = value_type(1) / (right - left);
|
||||
value_type inv_height = value_type(1) / (top - bottom);
|
||||
value_type inv_depth = value_type(1) / (f - n);
|
||||
value_type near2 = value_type(2) * n;
|
||||
value_type s = handedness == left_handed
|
||||
? value_type(1) : value_type(-1);
|
||||
|
||||
if (z_clip == z_clip_neg_one) {
|
||||
m.set_basis_element(2,2,s * (f + n) * inv_depth);
|
||||
m.set_basis_element(3,2,value_type(-2) * f * n * inv_depth);
|
||||
} else { // z_clip == z_clip_zero
|
||||
m.set_basis_element(2,2,s * f * inv_depth);
|
||||
m.set_basis_element(3,2,-s * n * m.basis_element(2,2));
|
||||
}
|
||||
|
||||
m.set_basis_element(0,0,near2 * inv_width );
|
||||
m.set_basis_element(1,1,near2 * inv_height );
|
||||
m.set_basis_element(2,0,-s * (right + left) * inv_width );
|
||||
m.set_basis_element(2,1,-s * (top + bottom) * inv_height);
|
||||
m.set_basis_element(2,3,s );
|
||||
m.set_basis_element(3,3,value_type(0) );
|
||||
}
|
||||
|
||||
/** Build a matrix representing a perspective projection, specified by frustum
|
||||
* bounds in w,h,n,f form, and with the given handedness and z clipping
|
||||
* range
|
||||
*/
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective(matrix<E,A,B,L>& m, E width, E height, E n, E f,
|
||||
Handedness handedness, ZClip z_clip)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
value_type half_width = width * value_type(.5);
|
||||
value_type half_height = height * value_type(.5);
|
||||
matrix_perspective(m, -half_width, half_width,
|
||||
-half_height, half_height, n, f, handedness, z_clip);
|
||||
}
|
||||
|
||||
/** Build a left-handedness frustum perspective matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective_LH(matrix<E,A,B,L>& m, E left, E right, E bottom,
|
||||
E top, E n, E f, ZClip z_clip)
|
||||
{
|
||||
matrix_perspective(m, left, right, bottom, top, n, f,
|
||||
left_handed, z_clip);
|
||||
}
|
||||
|
||||
/** Build a right-handedness frustum perspective matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective_RH(matrix<E,A,B,L>& m, E left, E right, E bottom,
|
||||
E top, E n, E f, ZClip z_clip)
|
||||
{
|
||||
matrix_perspective(m, left, right, bottom, top, n, f,
|
||||
right_handed, z_clip);
|
||||
}
|
||||
|
||||
/** Build a left-handedness frustum perspective matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective_LH(matrix<E,A,B,L>& m, E width, E height, E n,
|
||||
E f, ZClip z_clip)
|
||||
{
|
||||
matrix_perspective(m, width, height, n, f, left_handed, z_clip);
|
||||
}
|
||||
|
||||
/** Build a right-handedness frustum perspective matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective_RH(matrix<E,A,B,L>& m, E width, E height, E n,
|
||||
E f, ZClip z_clip)
|
||||
{
|
||||
matrix_perspective(m, width, height, n, f, right_handed, z_clip);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D perspective projection from horizontal field of view
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a perspective matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective_xfov(matrix<E,A,B,L>& m, E xfov, E aspect, E n,
|
||||
E f, Handedness handedness, ZClip z_clip)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
value_type width = value_type(2) * std::tan(xfov * value_type(.5)) * n;
|
||||
matrix_perspective(m, width, width / aspect, n, f,
|
||||
handedness, z_clip);
|
||||
}
|
||||
|
||||
/** Build a left-handedness perspective matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective_xfov_LH(matrix<E,A,B,L>& m, E xfov, E aspect, E n,
|
||||
E f, ZClip z_clip)
|
||||
{
|
||||
matrix_perspective_xfov(m,xfov,aspect,n,f,left_handed,z_clip);
|
||||
}
|
||||
|
||||
/** Build a right-handedness perspective matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective_xfov_RH(matrix<E,A,B,L>& m, E xfov, E aspect, E n,
|
||||
E f, ZClip z_clip)
|
||||
{
|
||||
matrix_perspective_xfov(m,xfov,aspect,n,f,right_handed,z_clip);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D perspective projection from vertical field of view
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a perspective matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective_yfov(matrix<E,A,B,L>& m, E yfov, E aspect, E n,
|
||||
E f, Handedness handedness, ZClip z_clip)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
value_type height = value_type(2) * std::tan(yfov * value_type(.5)) * n;
|
||||
matrix_perspective(m, height * aspect, height, n, f,
|
||||
handedness, z_clip);
|
||||
}
|
||||
|
||||
/** Build a left-handedness perspective matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective_yfov_LH(matrix<E,A,B,L>& m, E yfov, E aspect, E n,
|
||||
E f, ZClip z_clip)
|
||||
{
|
||||
matrix_perspective_yfov(m,yfov,aspect,n,f,left_handed,z_clip);
|
||||
}
|
||||
|
||||
/** Build a right-handedness perspective matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_perspective_yfov_RH(matrix<E,A,B,L>& m, E yfov, E aspect, E n,
|
||||
E f, ZClip z_clip)
|
||||
{
|
||||
matrix_perspective_yfov(m,yfov,aspect,n,f,right_handed,z_clip);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D orthographic projection from frustum
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing an orthographic projection, specified by
|
||||
* frustum bounds in l,r,b,t,n,f form, and with the given handedness and z
|
||||
* clipping range
|
||||
*/
|
||||
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_orthographic(matrix<E,A,B,L>& m, E left, E right, E bottom, E top,
|
||||
E n, E f, Handedness handedness,
|
||||
ZClip z_clip)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatHomogeneous3D(m);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
value_type inv_width = value_type(1) / (right - left);
|
||||
value_type inv_height = value_type(1) / (top - bottom);
|
||||
value_type inv_depth = value_type(1) / (f - n);
|
||||
value_type s = handedness == left_handed
|
||||
? value_type(1) : value_type(-1);
|
||||
|
||||
if (z_clip == z_clip_neg_one) {
|
||||
m.set_basis_element(2,2,s * value_type(2) * inv_depth);
|
||||
m.set_basis_element(3,2,-(f + n) * inv_depth);
|
||||
} else { // z_clip.z_clip() == 0
|
||||
m.set_basis_element(2,2,s * inv_depth);
|
||||
m.set_basis_element(3,2,-n * inv_depth);
|
||||
}
|
||||
|
||||
m.set_basis_element(0,0,value_type(2) * inv_width );
|
||||
m.set_basis_element(1,1,value_type(2) * inv_height );
|
||||
m.set_basis_element(3,0,-(right + left) * inv_width );
|
||||
m.set_basis_element(3,1,-(top + bottom) * inv_height);
|
||||
}
|
||||
|
||||
/** Build an orthographic projection matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_orthographic(matrix<E,A,B,L>& m, E width, E height, E n, E f,
|
||||
Handedness handedness, ZClip z_clip)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
value_type half_width = width * value_type(.5);
|
||||
value_type half_height = height * value_type(.5);
|
||||
matrix_orthographic(m, -half_width, half_width,
|
||||
-half_height, half_height, n, f, handedness, z_clip);
|
||||
}
|
||||
|
||||
/** Build a left-handedness orthographic projection matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_orthographic_LH(matrix<E,A,B,L>& m, E left, E right, E bottom,
|
||||
E top, E n, E f, ZClip z_clip)
|
||||
{
|
||||
matrix_orthographic(m, left, right, bottom, top, n, f,
|
||||
left_handed, z_clip);
|
||||
}
|
||||
|
||||
/** Build a right-handedness orthographic projection matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_orthographic_RH(matrix<E,A,B,L>& m, E left, E right, E bottom,
|
||||
E top, E n, E f, ZClip z_clip)
|
||||
{
|
||||
matrix_orthographic(m, left, right, bottom, top, n, f,
|
||||
right_handed, z_clip);
|
||||
}
|
||||
|
||||
/** Build a left-handedness orthographic projection matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_orthographic_LH(matrix<E,A,B,L>& m, E width, E height, E n,
|
||||
E f, ZClip z_clip)
|
||||
{
|
||||
matrix_orthographic(m, width, height, n, f, left_handed,
|
||||
z_clip);
|
||||
}
|
||||
|
||||
/** Build a right-handedness orthographic projection matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_orthographic_RH(matrix<E,A,B,L>& m, E width, E height, E n,
|
||||
E f, ZClip z_clip)
|
||||
{
|
||||
matrix_orthographic(m, width, height, n, f, right_handed,
|
||||
z_clip);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D viewport
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Build a viewport matrix
|
||||
*
|
||||
* Note: A viewport matrix is in a sense the opposite of an orthographics
|
||||
* projection matrix, and can be build by constructing and inverting the
|
||||
* latter.
|
||||
*
|
||||
* @todo: Need to look into D3D viewport conventions and see if this needs to
|
||||
* be adapted accordingly.
|
||||
*/
|
||||
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_viewport(matrix<E,A,B,L>& m, E left, E right, E bottom,
|
||||
E top, ZClip z_clip, E n = E(0), E f = E(1))
|
||||
{
|
||||
matrix_orthographic_LH(m, left, right, bottom, top, n, f, z_clip);
|
||||
/* @todo: invert(m), when available */
|
||||
m = inverse(m);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D picking volume
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Build a pick volume matrix
|
||||
*
|
||||
* When post-concatenated with a projection matrix, the pick matrix modifies
|
||||
* the view volume to create a 'picking volume'. This volume corresponds to
|
||||
* a screen rectangle centered at (pick_x, pick_y) and with dimensions
|
||||
* pick_widthXpick_height.
|
||||
*
|
||||
* @todo: Representation of viewport between this function and
|
||||
* matrix_viewport() is inconsistent (position and dimensions vs. bounds).
|
||||
* Should this be addressed?
|
||||
*/
|
||||
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_pick(
|
||||
matrix<E,A,B,L>& m, E pick_x, E pick_y, E pick_width, E pick_height,
|
||||
E viewport_x, E viewport_y, E viewport_width, E viewport_height)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatHomogeneous3D(m);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
value_type inv_width = value_type(1) / pick_width;
|
||||
value_type inv_height = value_type(1) / pick_height;
|
||||
|
||||
m.set_basis_element(0,0,viewport_width*inv_width);
|
||||
m.set_basis_element(1,1,viewport_height*inv_height);
|
||||
m.set_basis_element(3,0,
|
||||
(viewport_width+value_type(2)*(viewport_x-pick_x))*inv_width);
|
||||
m.set_basis_element(3,1,
|
||||
(viewport_height+value_type(2)*(viewport_y-pick_y))*inv_height);
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
980
Lib/Include/CML/mathlib/matrix_rotation.h
Normal file
980
Lib/Include/CML/mathlib/matrix_rotation.h
Normal file
@@ -0,0 +1,980 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef matrix_rotation_h
|
||||
#define matrix_rotation_h
|
||||
|
||||
#include <cml/mathlib/matrix_misc.h>
|
||||
#include <cml/mathlib/vector_ortho.h>
|
||||
|
||||
/* Functions related to matrix rotations in 3D and 2D. */
|
||||
|
||||
namespace cml {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D rotation about world axes
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 3D rotation about the given world axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotation_world_axis( matrix<E,A,B,L>& m, size_t axis, E angle)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(axis, i, j, k);
|
||||
|
||||
value_type s = value_type(std::sin(angle));
|
||||
value_type c = value_type(std::cos(angle));
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
m.set_basis_element(j,j, c);
|
||||
m.set_basis_element(j,k, s);
|
||||
m.set_basis_element(k,j,-s);
|
||||
m.set_basis_element(k,k, c);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 3D rotation about the world x axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotation_world_x(matrix<E,A,B,L>& m, E angle) {
|
||||
matrix_rotation_world_axis(m,0,angle);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 3D rotation about the world y axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotation_world_y(matrix<E,A,B,L>& m, E angle) {
|
||||
matrix_rotation_world_axis(m,1,angle);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 3D rotation about the world z axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotation_world_z(matrix<E,A,B,L>& m, E angle) {
|
||||
matrix_rotation_world_axis(m,2,angle);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D rotation from an axis-angle pair
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a rotation matrix from an axis-angle pair */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_rotation_axis_angle(matrix<E,A,B,L>& m, const VecT& axis, E angle)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckVec3(axis);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
value_type s = std::sin(angle);
|
||||
value_type c = std::cos(angle);
|
||||
value_type omc = value_type(1) - c;
|
||||
|
||||
value_type xomc = axis[0] * omc;
|
||||
value_type yomc = axis[1] * omc;
|
||||
value_type zomc = axis[2] * omc;
|
||||
|
||||
value_type xxomc = axis[0] * xomc;
|
||||
value_type yyomc = axis[1] * yomc;
|
||||
value_type zzomc = axis[2] * zomc;
|
||||
value_type xyomc = axis[0] * yomc;
|
||||
value_type yzomc = axis[1] * zomc;
|
||||
value_type zxomc = axis[2] * xomc;
|
||||
|
||||
value_type xs = axis[0] * s;
|
||||
value_type ys = axis[1] * s;
|
||||
value_type zs = axis[2] * s;
|
||||
|
||||
m.set_basis_element(0,0, xxomc + c );
|
||||
m.set_basis_element(0,1, xyomc + zs);
|
||||
m.set_basis_element(0,2, zxomc - ys);
|
||||
m.set_basis_element(1,0, xyomc - zs);
|
||||
m.set_basis_element(1,1, yyomc + c );
|
||||
m.set_basis_element(1,2, yzomc + xs);
|
||||
m.set_basis_element(2,0, zxomc + ys);
|
||||
m.set_basis_element(2,1, yzomc - xs);
|
||||
m.set_basis_element(2,2, zzomc + c );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D rotation from a quaternion
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a rotation matrix from a quaternion */
|
||||
template < typename E, class A, class B, class L, class QuatT > void
|
||||
matrix_rotation_quaternion(matrix<E,A,B,L>& m, const QuatT& q)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef QuatT quaternion_type;
|
||||
typedef typename quaternion_type::order_type order_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
enum {
|
||||
W = order_type::W,
|
||||
X = order_type::X,
|
||||
Y = order_type::Y,
|
||||
Z = order_type::Z
|
||||
};
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckQuat(q);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
value_type x2 = q[X] + q[X];
|
||||
value_type y2 = q[Y] + q[Y];
|
||||
value_type z2 = q[Z] + q[Z];
|
||||
|
||||
value_type xx2 = q[X] * x2;
|
||||
value_type yy2 = q[Y] * y2;
|
||||
value_type zz2 = q[Z] * z2;
|
||||
value_type xy2 = q[X] * y2;
|
||||
value_type yz2 = q[Y] * z2;
|
||||
value_type zx2 = q[Z] * x2;
|
||||
value_type xw2 = q[W] * x2;
|
||||
value_type yw2 = q[W] * y2;
|
||||
value_type zw2 = q[W] * z2;
|
||||
|
||||
m.set_basis_element(0,0, value_type(1) - yy2 - zz2);
|
||||
m.set_basis_element(0,1, xy2 + zw2);
|
||||
m.set_basis_element(0,2, zx2 - yw2);
|
||||
m.set_basis_element(1,0, xy2 - zw2);
|
||||
m.set_basis_element(1,1, value_type(1) - zz2 - xx2);
|
||||
m.set_basis_element(1,2, yz2 + xw2);
|
||||
m.set_basis_element(2,0, zx2 + yw2);
|
||||
m.set_basis_element(2,1, yz2 - xw2);
|
||||
m.set_basis_element(2,2, value_type(1) - xx2 - yy2);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D rotation from Euler angles
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a rotation matrix from an Euler-angle triple
|
||||
*
|
||||
* The rotations are applied about the cardinal axes in the order specified by
|
||||
* the 'order' argument, where 'order' is one of the following enumerants:
|
||||
*
|
||||
* euler_order_xyz
|
||||
* euler_order_xzy
|
||||
* euler_order_xyx
|
||||
* euler_order_xzx
|
||||
* euler_order_yzx
|
||||
* euler_order_yxz
|
||||
* euler_order_yzy
|
||||
* euler_order_yxy
|
||||
* euler_order_zxy
|
||||
* euler_order_zyx
|
||||
* euler_order_zxz
|
||||
* euler_order_zyz
|
||||
*
|
||||
* e.g. euler_order_xyz means compute the column-basis rotation matrix
|
||||
* equivalent to R_x * R_y * R_z, where R_i is the rotation matrix above
|
||||
* axis i (the row-basis matrix would be R_z * R_y * R_x).
|
||||
*/
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotation_euler(matrix<E,A,B,L>& m, E angle_0, E angle_1, E angle_2,
|
||||
EulerOrder order)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
size_t i, j, k;
|
||||
bool odd, repeat;
|
||||
detail::unpack_euler_order(order, i, j, k, odd, repeat);
|
||||
|
||||
if (odd) {
|
||||
angle_0 = -angle_0;
|
||||
angle_1 = -angle_1;
|
||||
angle_2 = -angle_2;
|
||||
}
|
||||
|
||||
value_type s0 = std::sin(angle_0);
|
||||
value_type c0 = std::cos(angle_0);
|
||||
value_type s1 = std::sin(angle_1);
|
||||
value_type c1 = std::cos(angle_1);
|
||||
value_type s2 = std::sin(angle_2);
|
||||
value_type c2 = std::cos(angle_2);
|
||||
|
||||
value_type s0s2 = s0 * s2;
|
||||
value_type s0c2 = s0 * c2;
|
||||
value_type c0s2 = c0 * s2;
|
||||
value_type c0c2 = c0 * c2;
|
||||
|
||||
if (repeat) {
|
||||
m.set_basis_element(i,i, c1 );
|
||||
m.set_basis_element(i,j, s1 * s2 );
|
||||
m.set_basis_element(i,k,-s1 * c2 );
|
||||
m.set_basis_element(j,i, s0 * s1 );
|
||||
m.set_basis_element(j,j,-c1 * s0s2 + c0c2);
|
||||
m.set_basis_element(j,k, c1 * s0c2 + c0s2);
|
||||
m.set_basis_element(k,i, c0 * s1 );
|
||||
m.set_basis_element(k,j,-c1 * c0s2 - s0c2);
|
||||
m.set_basis_element(k,k, c1 * c0c2 - s0s2);
|
||||
} else {
|
||||
m.set_basis_element(i,i, c1 * c2 );
|
||||
m.set_basis_element(i,j, c1 * s2 );
|
||||
m.set_basis_element(i,k,-s1 );
|
||||
m.set_basis_element(j,i, s1 * s0c2 - c0s2);
|
||||
m.set_basis_element(j,j, s1 * s0s2 + c0c2);
|
||||
m.set_basis_element(j,k, s0 * c1 );
|
||||
m.set_basis_element(k,i, s1 * c0c2 + s0s2);
|
||||
m.set_basis_element(k,j, s1 * c0s2 - s0c2);
|
||||
m.set_basis_element(k,k, c0 * c1 );
|
||||
}
|
||||
}
|
||||
|
||||
/** Build a matrix of derivatives of Euler angles about the specified axis.
|
||||
*
|
||||
* The rotation derivatives are applied about the cardinal axes in the
|
||||
* order specified by the 'order' argument, where 'order' is one of the
|
||||
* following enumerants:
|
||||
*
|
||||
* euler_order_xyz
|
||||
* euler_order_xzy
|
||||
* euler_order_yzx
|
||||
* euler_order_yxz
|
||||
* euler_order_zxy
|
||||
* euler_order_zyx
|
||||
*
|
||||
* e.g. euler_order_xyz means compute the column-basis rotation matrix
|
||||
* equivalent to R_x * R_y * R_z, where R_i is the rotation matrix above
|
||||
* axis i (the row-basis matrix would be R_z * R_y * R_x).
|
||||
*
|
||||
* The derivative is taken with respect to the specified 'axis', which is
|
||||
* the position of the axis in the triple; e.g. if order = euler_order_xyz,
|
||||
* then axis = 0 would mean take the derivative with respect to x. Note
|
||||
* that repeated axes are not currently supported.
|
||||
*/
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotation_euler_derivatives(
|
||||
matrix<E,A,B,L>& m, int axis, E angle_0, E angle_1, E angle_2,
|
||||
EulerOrder order)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
|
||||
size_t i, j, k;
|
||||
bool odd, repeat;
|
||||
detail::unpack_euler_order(order, i, j, k, odd, repeat);
|
||||
if(repeat) throw std::invalid_argument(
|
||||
"matrix_rotation_euler_derivatives does not support repeated axes");
|
||||
|
||||
if (odd) {
|
||||
angle_0 = -angle_0;
|
||||
angle_1 = -angle_1;
|
||||
angle_2 = -angle_2;
|
||||
}
|
||||
|
||||
value_type s0 = std::sin(angle_0);
|
||||
value_type c0 = std::cos(angle_0);
|
||||
value_type s1 = std::sin(angle_1);
|
||||
value_type c1 = std::cos(angle_1);
|
||||
value_type s2 = std::sin(angle_2);
|
||||
value_type c2 = std::cos(angle_2);
|
||||
|
||||
value_type s0s2 = s0 * s2;
|
||||
value_type s0c2 = s0 * c2;
|
||||
value_type c0s2 = c0 * s2;
|
||||
value_type c0c2 = c0 * c2;
|
||||
|
||||
if(axis == 0) {
|
||||
m.set_basis_element(i,i, 0. );
|
||||
m.set_basis_element(i,j, 0. );
|
||||
m.set_basis_element(i,k, 0. );
|
||||
m.set_basis_element(j,i, s1 * c0*c2 + s0*s2);
|
||||
m.set_basis_element(j,j, s1 * c0*s2 - s0*c2);
|
||||
m.set_basis_element(j,k, c0 * c1 );
|
||||
m.set_basis_element(k,i,-s1 * s0*c2 + c0*s2);
|
||||
m.set_basis_element(k,j,-s1 * s0*s2 - c0*c2);
|
||||
m.set_basis_element(k,k,-s0 * c1 );
|
||||
} else if(axis == 1) {
|
||||
m.set_basis_element(i,i,-s1 * c2 );
|
||||
m.set_basis_element(i,j,-s1 * s2 );
|
||||
m.set_basis_element(i,k,-c1 );
|
||||
m.set_basis_element(j,i, c1 * s0*c2 );
|
||||
m.set_basis_element(j,j, c1 * s0*s2 );
|
||||
m.set_basis_element(j,k,-s0 * s1 );
|
||||
m.set_basis_element(k,i, c1 * c0*c2 );
|
||||
m.set_basis_element(k,j, c1 * c0*s2 );
|
||||
m.set_basis_element(k,k,-c0 * s1 );
|
||||
} else if(axis == 2) {
|
||||
m.set_basis_element(i,i,-c1 * s2 );
|
||||
m.set_basis_element(i,j, c1 * c2 );
|
||||
m.set_basis_element(i,k, 0. );
|
||||
m.set_basis_element(j,i,-s1 * s0*s2 - c0*c2);
|
||||
m.set_basis_element(j,j, s1 * s0*c2 - c0*s2);
|
||||
m.set_basis_element(j,k, 0. );
|
||||
m.set_basis_element(k,i,-s1 * c0*s2 + s0*c2);
|
||||
m.set_basis_element(k,j, s1 * c0*c2 + s0*s2);
|
||||
m.set_basis_element(k,k, 0. );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D rotation to align with a vector, multiple vectors, or the view plane
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E,class A,class B,class L,class VecT_1,class VecT_2 > void
|
||||
matrix_rotation_align(
|
||||
matrix<E,A,B,L>& m,
|
||||
const VecT_1& align,
|
||||
const VecT_2& reference,
|
||||
bool normalize = true,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef vector< E,fixed<3> > vector_type;
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
vector_type x, y, z;
|
||||
|
||||
orthonormal_basis(align, reference, x, y, z, normalize, order);
|
||||
matrix_set_basis_vectors(m, x, y, z);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_rotation_align(matrix<E,A,B,L>& m, const VecT& align,
|
||||
bool normalize = true, AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef vector< E,fixed<3> > vector_type;
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
vector_type x, y, z;
|
||||
|
||||
orthonormal_basis(align, x, y, z, normalize, order);
|
||||
matrix_set_basis_vectors(m, x, y, z);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E,class A,class B,class L,class VecT_1,class VecT_2 > void
|
||||
matrix_rotation_align_axial(matrix<E,A,B,L>& m, const VecT_1& align,
|
||||
const VecT_2& axis, bool normalize = true,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef vector< E,fixed<3> > vector_type;
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
vector_type x, y, z;
|
||||
|
||||
orthonormal_basis_axial(align, axis, x, y, z, normalize, order);
|
||||
matrix_set_basis_vectors(m, x, y, z);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class B, class L, class MatT > void
|
||||
matrix_rotation_align_viewplane(
|
||||
matrix<E,A,B,L>& m,
|
||||
const MatT& view_matrix,
|
||||
Handedness handedness,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef vector< E, fixed<3> > vector_type;
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
vector_type x, y, z;
|
||||
|
||||
orthonormal_basis_viewplane(view_matrix, x, y, z, handedness, order);
|
||||
matrix_set_basis_vectors(m, x, y, z);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class B, class L, class MatT > void
|
||||
matrix_rotation_align_viewplane_LH(
|
||||
matrix<E,A,B,L>& m,
|
||||
const MatT& view_matrix,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
matrix_rotation_align_viewplane(
|
||||
m,view_matrix,left_handed,order);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class B, class L, class MatT > void
|
||||
matrix_rotation_align_viewplane_RH(
|
||||
matrix<E,A,B,L>& m,
|
||||
const MatT& view_matrix,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
matrix_rotation_align_viewplane(
|
||||
m,view_matrix,right_handed,order);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D rotation to aim at a target
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
matrix_rotation_aim_at(
|
||||
matrix<E,A,B,L>& m,
|
||||
const VecT_1& pos,
|
||||
const VecT_2& target,
|
||||
const VecT_3& reference,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
matrix_rotation_align(m, target - pos, reference, true, order);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2 > void
|
||||
matrix_rotation_aim_at(
|
||||
matrix<E,A,B,L>& m,
|
||||
const VecT_1& pos,
|
||||
const VecT_2& target,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
matrix_rotation_align(m, target - pos, true, order);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
matrix_rotation_aim_at_axial(
|
||||
matrix<E,A,B,L>& m,
|
||||
const VecT_1& pos,
|
||||
const VecT_2& target,
|
||||
const VecT_3& axis,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
matrix_rotation_align_axial(m, target - pos, axis, true, order);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D rotation
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 2D rotation */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotation_2D( matrix<E,A,B,L>& m, E angle)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
|
||||
value_type s = value_type(std::sin(angle));
|
||||
value_type c = value_type(std::cos(angle));
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
m.set_basis_element(0,0, c);
|
||||
m.set_basis_element(0,1, s);
|
||||
m.set_basis_element(1,0,-s);
|
||||
m.set_basis_element(1,1, c);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D rotation to align with a vector
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_rotation_align_2D(matrix<E,A,B,L>& m, const VecT& align,
|
||||
bool normalize = true, AxisOrder2D order = axis_order_xy)
|
||||
{
|
||||
typedef vector< E, fixed<2> > vector_type;
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
vector_type x, y;
|
||||
|
||||
orthonormal_basis_2D(align, x, y, normalize, order);
|
||||
matrix_set_basis_vectors_2D(m, x, y);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D relative rotation about world axes
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Rotate a rotation matrix about the given world axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotate_about_world_axis(matrix<E,A,B,L>& m, size_t axis, E angle)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(axis, i, j, k);
|
||||
|
||||
value_type s = value_type(std::sin(angle));
|
||||
value_type c = value_type(std::cos(angle));
|
||||
|
||||
value_type ij = c * m.basis_element(i,j) - s * m.basis_element(i,k);
|
||||
value_type jj = c * m.basis_element(j,j) - s * m.basis_element(j,k);
|
||||
value_type kj = c * m.basis_element(k,j) - s * m.basis_element(k,k);
|
||||
|
||||
m.set_basis_element(i,k, s*m.basis_element(i,j) + c*m.basis_element(i,k));
|
||||
m.set_basis_element(j,k, s*m.basis_element(j,j) + c*m.basis_element(j,k));
|
||||
m.set_basis_element(k,k, s*m.basis_element(k,j) + c*m.basis_element(k,k));
|
||||
|
||||
m.set_basis_element(i,j,ij);
|
||||
m.set_basis_element(j,j,jj);
|
||||
m.set_basis_element(k,j,kj);
|
||||
}
|
||||
|
||||
/** Rotate a rotation matrix about the world x axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotate_about_world_x(matrix<E,A,B,L>& m, E angle) {
|
||||
matrix_rotate_about_world_axis(m,0,angle);
|
||||
}
|
||||
|
||||
/** Rotate a rotation matrix about the world y axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotate_about_world_y(matrix<E,A,B,L>& m, E angle) {
|
||||
matrix_rotate_about_world_axis(m,1,angle);
|
||||
}
|
||||
|
||||
/** Rotate a rotation matrix about the world z axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotate_about_world_z(matrix<E,A,B,L>& m, E angle) {
|
||||
matrix_rotate_about_world_axis(m,2,angle);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D relative rotation about local axes
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Rotate a rotation matrix about the given local axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotate_about_local_axis(matrix<E,A,B,L>& m, size_t axis, E angle)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(axis, i, j, k);
|
||||
|
||||
value_type s = value_type(std::sin(angle));
|
||||
value_type c = value_type(std::cos(angle));
|
||||
|
||||
value_type j0 = c * m.basis_element(j,0) + s * m.basis_element(k,0);
|
||||
value_type j1 = c * m.basis_element(j,1) + s * m.basis_element(k,1);
|
||||
value_type j2 = c * m.basis_element(j,2) + s * m.basis_element(k,2);
|
||||
|
||||
m.set_basis_element(k,0, c*m.basis_element(k,0) - s*m.basis_element(j,0));
|
||||
m.set_basis_element(k,1, c*m.basis_element(k,1) - s*m.basis_element(j,1));
|
||||
m.set_basis_element(k,2, c*m.basis_element(k,2) - s*m.basis_element(j,2));
|
||||
|
||||
m.set_basis_element(j,0,j0);
|
||||
m.set_basis_element(j,1,j1);
|
||||
m.set_basis_element(j,2,j2);
|
||||
}
|
||||
|
||||
/** Rotate a rotation matrix about its local x axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotate_about_local_x(matrix<E,A,B,L>& m, E angle) {
|
||||
matrix_rotate_about_local_axis(m,0,angle);
|
||||
}
|
||||
|
||||
/** Rotate a rotation matrix about its local y axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotate_about_local_y(matrix<E,A,B,L>& m, E angle) {
|
||||
matrix_rotate_about_local_axis(m,1,angle);
|
||||
}
|
||||
|
||||
/** Rotate a rotation matrix about its local z axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotate_about_local_z(matrix<E,A,B,L>& m, E angle) {
|
||||
matrix_rotate_about_local_axis(m,2,angle);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D relative rotation
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_rotate_2D(matrix<E,A,B,L>& m, E angle)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
|
||||
value_type s = value_type(std::sin(angle));
|
||||
value_type c = value_type(std::cos(angle));
|
||||
|
||||
value_type m00 = c * m.basis_element(0,0) - s * m.basis_element(0,1);
|
||||
value_type m10 = c * m.basis_element(1,0) - s * m.basis_element(1,1);
|
||||
|
||||
m.set_basis_element(0,1, s*m.basis_element(0,0) + c*m.basis_element(0,1));
|
||||
m.set_basis_element(1,1, s*m.basis_element(1,0) + c*m.basis_element(1,1));
|
||||
|
||||
m.set_basis_element(0,0,m00);
|
||||
m.set_basis_element(1,0,m10);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Rotation from vector to vector
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a rotation matrix to rotate from one vector to another
|
||||
*
|
||||
* Note: The quaternion algorithm is more stable than the matrix algorithm, so
|
||||
* we simply pass off to the quaternion function here.
|
||||
*/
|
||||
template < class E,class A,class B,class L,class VecT_1,class VecT_2 > void
|
||||
matrix_rotation_vec_to_vec(
|
||||
matrix<E,A,B,L>& m,
|
||||
const VecT_1& v1,
|
||||
const VecT_2& v2,
|
||||
bool unit_length_vectors = false)
|
||||
{
|
||||
typedef quaternion< E,fixed<>,vector_first,positive_cross >
|
||||
quaternion_type;
|
||||
|
||||
quaternion_type q;
|
||||
quaternion_rotation_vec_to_vec(q,v1,v2,unit_length_vectors);
|
||||
matrix_rotation_quaternion(m,q);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Scale the angle of a rotation matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Scale the angle of a 3D rotation matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_scale_rotation_angle(matrix<E,A,B,L>& m, E t,
|
||||
E tolerance = epsilon<E>::placeholder())
|
||||
{
|
||||
typedef vector< E,fixed<3> > vector_type;
|
||||
typedef typename vector_type::value_type value_type;
|
||||
|
||||
vector_type axis;
|
||||
value_type angle;
|
||||
matrix_to_axis_angle(m, axis, angle, tolerance);
|
||||
matrix_rotation_axis_angle(m, axis, angle * t);
|
||||
}
|
||||
|
||||
/** Scale the angle of a 2D rotation matrix */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_scale_rotation_angle_2D(
|
||||
matrix<E,A,B,L>& m, E t, E tolerance = epsilon<E>::placeholder())
|
||||
{
|
||||
typedef vector< E,fixed<2> > vector_type;
|
||||
typedef typename vector_type::value_type value_type;
|
||||
|
||||
value_type angle = matrix_to_rotation_2D(m);
|
||||
matrix_rotation_2D(m, angle * t);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Support functions for uniform handling of row- and column-basis matrices
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Note: The matrix rotation slerp, difference and concatenation functions do
|
||||
* not use et::MatrixPromote<M1,M2>::temporary_type as the return type, even
|
||||
* though that is the return type of the underlying matrix multiplication.
|
||||
* This is because the sizes of these matrices are known at compile time (3x3
|
||||
* and 2x2), and using fixed<> obviates the need for resizing of intermediate
|
||||
* temporaries.
|
||||
*
|
||||
* Also, no size- or type-checking is done on the arguments to these
|
||||
* functions, as any such errors will be caught by the matrix multiplication
|
||||
* and assignment to the 3x3 temporary.
|
||||
*/
|
||||
|
||||
/** A fixed-size temporary 3x3 matrix */
|
||||
#define MAT_TEMP_3X3 matrix< \
|
||||
typename et::ScalarPromote< \
|
||||
typename MatT_1::value_type, \
|
||||
typename MatT_2::value_type \
|
||||
>::type, \
|
||||
fixed<3,3>, \
|
||||
typename MatT_1::basis_orient, \
|
||||
row_major \
|
||||
>
|
||||
|
||||
/** A fixed-size temporary 2x2 matrix */
|
||||
#define MAT_TEMP_2X2 matrix< \
|
||||
typename et::ScalarPromote< \
|
||||
typename MatT_1::value_type, \
|
||||
typename MatT_2::value_type \
|
||||
>::type, \
|
||||
fixed<2,2>, \
|
||||
typename MatT_1::basis_orient, \
|
||||
row_major \
|
||||
>
|
||||
|
||||
namespace detail {
|
||||
|
||||
/** Concatenate two 3D row-basis rotation matrices in the order m1->m2 */
|
||||
template < class MatT_1, class MatT_2 > MAT_TEMP_3X3
|
||||
matrix_concat_rotations(const MatT_1& m1, const MatT_2& m2, row_basis) {
|
||||
return m1*m2;
|
||||
}
|
||||
|
||||
/** Concatenate two 3D col-basis rotation matrices in the order m1->m2 */
|
||||
template < class MatT_1, class MatT_2 > MAT_TEMP_3X3
|
||||
matrix_concat_rotations(const MatT_1& m1, const MatT_2& m2, col_basis) {
|
||||
return m2*m1;
|
||||
}
|
||||
|
||||
/** Concatenate two 3D rotation matrices in the order m1->m2 */
|
||||
template < class MatT_1, class MatT_2 > MAT_TEMP_3X3
|
||||
matrix_concat_rotations(const MatT_1& m1, const MatT_2& m2) {
|
||||
return matrix_concat_rotations(m1,m2,typename MatT_1::basis_orient());
|
||||
}
|
||||
|
||||
/** Concatenate two 2D row-basis rotation matrices in the order m1->m2 */
|
||||
template < class MatT_1, class MatT_2 > MAT_TEMP_2X2
|
||||
matrix_concat_rotations_2D(const MatT_1& m1, const MatT_2& m2, row_basis) {
|
||||
return m1*m2;
|
||||
}
|
||||
|
||||
/** Concatenate two 2D col-basis rotation matrices in the order m1->m2 */
|
||||
template < class MatT_1, class MatT_2 > MAT_TEMP_2X2
|
||||
matrix_concat_rotations_2D(const MatT_1& m1, const MatT_2& m2, col_basis) {
|
||||
return m2*m1;
|
||||
}
|
||||
|
||||
/** Concatenate two 2D rotation matrices in the order m1->m2 */
|
||||
template < class MatT_1, class MatT_2 > MAT_TEMP_2X2
|
||||
matrix_concat_rotations_2D(const MatT_1& m1, const MatT_2& m2) {
|
||||
return matrix_concat_rotations_2D(m1,m2,typename MatT_1::basis_orient());
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Matrix rotation difference
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Return the rotational 'difference' between two 3D rotation matrices */
|
||||
template < class MatT_1, class MatT_2 > MAT_TEMP_3X3
|
||||
matrix_rotation_difference(const MatT_1& m1, const MatT_2& m2) {
|
||||
return detail::matrix_concat_rotations(transpose(m1),m2);
|
||||
}
|
||||
|
||||
/** Return the rotational 'difference' between two 2D rotation matrices */
|
||||
template < class MatT_1, class MatT_2 > MAT_TEMP_2X2
|
||||
matrix_rotation_difference_2D(const MatT_1& m1, const MatT_2& m2) {
|
||||
return detail::matrix_concat_rotations_2D(transpose(m1),m2);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Spherical linear interpolation of rotation matrices
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* @todo: It might be as fast or faster to simply convert the matrices to
|
||||
* quaternions, interpolate, and convert back.
|
||||
*
|
||||
* @todo: The behavior of matrix slerp is currently a little different than
|
||||
* for quaternions: in the matrix function, when the two matrices are close
|
||||
* to identical the first is returned, while in the quaternion function the
|
||||
* quaternions are nlerp()'d in this case.
|
||||
*
|
||||
* I still need to do the equivalent of nlerp() for matrices, in which case
|
||||
* these functions could be revised to pass off to nlerp() when the matrices
|
||||
* are nearly aligned.
|
||||
*/
|
||||
|
||||
/** Spherical linear interpolation of two 3D rotation matrices */
|
||||
template < class MatT_1, class MatT_2, typename E > MAT_TEMP_3X3
|
||||
matrix_slerp(const MatT_1& m1, const MatT_2& m2, E t,
|
||||
E tolerance = epsilon<E>::placeholder())
|
||||
{
|
||||
typedef MAT_TEMP_3X3 temporary_type;
|
||||
|
||||
temporary_type m = matrix_rotation_difference(m1,m2);
|
||||
matrix_scale_rotation_angle(m,t,tolerance);
|
||||
return detail::matrix_concat_rotations(m1,m);
|
||||
}
|
||||
|
||||
/** Spherical linear interpolation of two 2D rotation matrices */
|
||||
template < class MatT_1, class MatT_2, typename E > MAT_TEMP_2X2
|
||||
matrix_slerp_2D(const MatT_1& m1, const MatT_2& m2, E t,
|
||||
E tolerance = epsilon<E>::placeholder())
|
||||
{
|
||||
typedef MAT_TEMP_2X2 temporary_type;
|
||||
|
||||
temporary_type m = matrix_rotation_difference_2D(m1,m2);
|
||||
matrix_scale_rotation_angle_2D(m,t,tolerance);
|
||||
return detail::matrix_concat_rotations_2D(m1,m);
|
||||
}
|
||||
|
||||
#undef MAT_TEMP_3X3
|
||||
#undef MAT_TEMP_2X2
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Conversions
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Convert a 3D rotation matrix to an axis-angle pair */
|
||||
template < class MatT, typename E, class A > void
|
||||
matrix_to_axis_angle(
|
||||
const MatT& m,
|
||||
vector<E,A >& axis,
|
||||
E& angle,
|
||||
E tolerance = epsilon<E>::placeholder())
|
||||
{
|
||||
typedef MatT matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
|
||||
axis.set(
|
||||
m.basis_element(1,2) - m.basis_element(2,1),
|
||||
m.basis_element(2,0) - m.basis_element(0,2),
|
||||
m.basis_element(0,1) - m.basis_element(1,0)
|
||||
);
|
||||
value_type l = length(axis);
|
||||
value_type tmo = trace_3x3(m) - value_type(1);
|
||||
|
||||
if (l > tolerance) {
|
||||
axis /= l;
|
||||
angle = std::atan2(l, tmo); // l=2sin(theta),tmo=2cos(theta)
|
||||
} else if (tmo > value_type(0)) {
|
||||
axis.zero();
|
||||
angle = value_type(0);
|
||||
} else {
|
||||
size_t largest_diagonal_element =
|
||||
index_of_max(
|
||||
m.basis_element(0,0),
|
||||
m.basis_element(1,1),
|
||||
m.basis_element(2,2)
|
||||
);
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(largest_diagonal_element, i, j, k);
|
||||
axis[i] =
|
||||
std::sqrt(
|
||||
m.basis_element(i,i) -
|
||||
m.basis_element(j,j) -
|
||||
m.basis_element(k,k) +
|
||||
value_type(1)
|
||||
) * value_type(.5);
|
||||
value_type s = value_type(.5) / axis[i];
|
||||
axis[j] = m.basis_element(i,j) * s;
|
||||
axis[k] = m.basis_element(i,k) * s;
|
||||
angle = constants<value_type>::pi();
|
||||
}
|
||||
}
|
||||
|
||||
/** Convert a 3D rotation matrix to an Euler-angle triple */
|
||||
template < class MatT, typename Real >
|
||||
void matrix_to_euler(
|
||||
const MatT& m,
|
||||
Real& angle_0,
|
||||
Real& angle_1,
|
||||
Real& angle_2,
|
||||
EulerOrder order,
|
||||
Real tolerance = epsilon<Real>::placeholder())
|
||||
{
|
||||
typedef MatT matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
|
||||
size_t i, j, k;
|
||||
bool odd, repeat;
|
||||
detail::unpack_euler_order(order, i, j, k, odd, repeat);
|
||||
|
||||
if (repeat) {
|
||||
value_type s1 = length(m.basis_element(j,i),m.basis_element(k,i));
|
||||
value_type c1 = m.basis_element(i,i);
|
||||
|
||||
angle_1 = std::atan2(s1, c1);
|
||||
if (s1 > tolerance) {
|
||||
angle_0 = std::atan2(m.basis_element(j,i),m.basis_element(k,i));
|
||||
angle_2 = std::atan2(m.basis_element(i,j),-m.basis_element(i,k));
|
||||
} else {
|
||||
angle_0 = value_type(0);
|
||||
angle_2 = sign(c1) *
|
||||
std::atan2(-m.basis_element(k,j),m.basis_element(j,j));
|
||||
}
|
||||
} else {
|
||||
value_type s1 = -m.basis_element(i,k);
|
||||
value_type c1 = length(m.basis_element(i,i),m.basis_element(i,j));
|
||||
|
||||
angle_1 = std::atan2(s1, c1);
|
||||
if (c1 > tolerance) {
|
||||
angle_0 = std::atan2(m.basis_element(j,k),m.basis_element(k,k));
|
||||
angle_2 = std::atan2(m.basis_element(i,j),m.basis_element(i,i));
|
||||
} else {
|
||||
angle_0 = value_type(0);
|
||||
angle_2 = -sign(s1) *
|
||||
std::atan2(-m.basis_element(k,j),m.basis_element(j,j));
|
||||
}
|
||||
}
|
||||
|
||||
if (odd) {
|
||||
angle_0 = -angle_0;
|
||||
angle_1 = -angle_1;
|
||||
angle_2 = -angle_2;
|
||||
}
|
||||
}
|
||||
|
||||
/** Convenience function to return a 3D vector containing the Euler angles
|
||||
* in the requested order.
|
||||
*/
|
||||
template < class MatT > vector< typename MatT::value_type, fixed<3> >
|
||||
matrix_to_euler(
|
||||
const MatT& m,
|
||||
EulerOrder order,
|
||||
const typename MatT::value_type&
|
||||
tolerance = epsilon<typename MatT::value_type>::placeholder())
|
||||
{
|
||||
typename MatT::value_type e0, e1, e2;
|
||||
matrix_to_euler(m, e0, e1, e2, order, tolerance);
|
||||
return vector< typename MatT::value_type, fixed<3> >(e0, e1, e2);
|
||||
}
|
||||
|
||||
/** Convert a 2D rotation matrix to a rotation angle */
|
||||
template < class MatT > typename MatT::value_type
|
||||
matrix_to_rotation_2D(const MatT& m)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
|
||||
return std::atan2(m.basis_element(0,1),m.basis_element(0,0));
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
984
Lib/Include/CML/mathlib/matrix_transform.h
Normal file
984
Lib/Include/CML/mathlib/matrix_transform.h
Normal file
@@ -0,0 +1,984 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef matrix_transform_h
|
||||
#define matrix_transform_h
|
||||
|
||||
#include <cml/mathlib/matrix_basis.h>
|
||||
#include <cml/mathlib/matrix_rotation.h>
|
||||
#include <cml/mathlib/matrix_translation.h>
|
||||
|
||||
/* Functions for building matrix transforms other than rotations
|
||||
* (matrix_rotation.h) and viewing projections (matrix_projection.h).
|
||||
*/
|
||||
|
||||
namespace cml {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D translation
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 3D translation */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_translation(matrix<E,A,B,L>& m, E x, E y, E z)
|
||||
{
|
||||
identity_transform(m);
|
||||
matrix_set_translation(m,x,y,z);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 3D translation with z set to 0 */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_translation(matrix<E,A,B,L>& m, E x, E y)
|
||||
{
|
||||
identity_transform(m);
|
||||
matrix_set_translation(m,x,y);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 3D translation */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_translation(matrix<E,A,B,L>& m, const VecT& translation)
|
||||
{
|
||||
identity_transform(m);
|
||||
matrix_set_translation(m,translation);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D translation
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 2D translation */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_translation_2D(matrix<E,A,B,L>& m, E x, E y)
|
||||
{
|
||||
identity_transform(m);
|
||||
matrix_set_translation_2D(m,x,y);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 2D translation */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_translation_2D(matrix<E,A,B,L>& m, const VecT& translation)
|
||||
{
|
||||
identity_transform(m);
|
||||
matrix_set_translation_2D(m, translation);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D scale
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a uniform 3D scale */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_uniform_scale(matrix<E,A,B,L>& m, E scale) {
|
||||
matrix_scale(m,scale,scale,scale);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a non-uniform 3D scale */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_scale(matrix<E,A,B,L>& m, E scale_x, E scale_y, E scale_z)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
m.set_basis_element(0,0,scale_x);
|
||||
m.set_basis_element(1,1,scale_y);
|
||||
m.set_basis_element(2,2,scale_z);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a non-uniform 3D scale */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_scale(matrix<E,A,B,L>& m, const VecT& scale)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckVec3(scale);
|
||||
|
||||
matrix_scale(m, scale[0], scale[1], scale[2]);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D scale
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a uniform 2D scale */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_uniform_scale_2D(matrix<E,A,B,L>& m, E scale) {
|
||||
matrix_scale_2D(m,scale,scale);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a non-uniform 2D scale */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_scale_2D(matrix<E,A,B,L>& m, E scale_x, E scale_y)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
m.set_basis_element(0,0,scale_x);
|
||||
m.set_basis_element(1,1,scale_y);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a non-uniform 2D scale */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_scale_2D(matrix<E,A,B,L>& m, const VecT& scale)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckVec2(scale);
|
||||
|
||||
matrix_scale_2D(m, scale[0], scale[1]);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D scale along axis
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 3D scale along an arbitrary axis */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_scale_along_axis(matrix<E,A,B,L>&m, const VecT& axis, E scale)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckVec3(axis);
|
||||
|
||||
matrix<E,fixed<3,3>,B,L> outer_p = outer(axis,axis)*(scale-value_type(1));
|
||||
outer_p(0,0) += value_type(1);
|
||||
outer_p(1,1) += value_type(1);
|
||||
outer_p(2,2) += value_type(1);
|
||||
|
||||
matrix_linear_transform(m, outer_p);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D scale along axis
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 2D scale along an arbitrary axis */
|
||||
template < typename E, class A, class B, class L, class VecT >
|
||||
void matrix_scale_along_axis_2D(matrix<E,A,B,L>& m, const VecT& axis,
|
||||
E scale)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckVec2(axis);
|
||||
|
||||
matrix<E,fixed<2,2>,B,L> outer_p = outer(axis,axis)*(scale-value_type(1));
|
||||
outer_p(0,0) += value_type(1);
|
||||
outer_p(1,1) += value_type(1);
|
||||
|
||||
matrix_linear_transform_2D(m, outer_p);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D shear
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 3D shear along the specified world axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_shear(matrix<E,A,B,L>& m, size_t axis, E shear_s, E shear_t)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(axis, i, j, k);
|
||||
|
||||
m.set_basis_element(i,j,shear_s);
|
||||
m.set_basis_element(i,k,shear_t);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 3D shear along the world x axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_shear_x(matrix<E,A,B,L>& m, E shear_s, E shear_t) {
|
||||
matrix_shear(m,0,shear_s,shear_t);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 3D shear along the world y axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_shear_y(matrix<E,A,B,L>& m, E shear_s, E shear_t) {
|
||||
matrix_shear(m,1,shear_s,shear_t);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 3D shear along the world z axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_shear_z(matrix<E,A,B,L>& m, E shear_s, E shear_t) {
|
||||
matrix_shear(m,2,shear_s,shear_t);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D shear
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 2D shear along the specified world axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_shear_2D(matrix<E,A,B,L>& m, size_t axis, E shear)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
detail::CheckIndex2(axis);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
size_t i, j;
|
||||
cyclic_permutation(axis, i, j);
|
||||
|
||||
m.set_basis_element(i,j,shear);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 2D shear along the world x axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_shear_x_2D(matrix<E,A,B,L>& m, E shear) {
|
||||
matrix_shear_2D(m,0,shear);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 2D shear along the world y axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_shear_y_2D(matrix<E,A,B,L>& m, E shear) {
|
||||
matrix_shear_2D(m,1,shear);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D reflection
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 3D reflection along the given world axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_reflect(matrix<E,A,B,L>& m, size_t axis)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
m(axis,axis) = value_type(-1);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 3D reflection along the world x axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_reflect_x(matrix<E,A,B,L>& m) {
|
||||
matrix_reflect(m,0);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 3D reflection along the world y axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_reflect_y(matrix<E,A,B,L>& m) {
|
||||
matrix_reflect(m,1);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 3D reflection along the world z axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_reflect_z(matrix<E,A,B,L>& m) {
|
||||
matrix_reflect(m,2);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D reflection
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 2D reflection along the given world axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_reflect_2D(matrix<E,A,B,L>& m, size_t axis)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
detail::CheckIndex2(axis);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
m(axis,axis) = value_type(-1);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 2D reflection along the world x axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_reflect_x_2D(matrix<E,A,B,L>& m) {
|
||||
matrix_reflect_2D(m,0);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 2D reflection along the world y axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_reflect_y_2D(matrix<E,A,B,L>& m) {
|
||||
matrix_reflect_2D(m,1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D reflection about hyperplane
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 3D reflection about the given hyperplane */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_reflect_about_hplane(matrix<E,A,B,L>& m, const VecT& normal)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
matrix_scale_along_axis(m, normal, value_type(-1));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D reflection about hyperplane
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 2D reflection about the given hyperplane */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_reflect_about_hplane_2D(matrix<E,A,B,L>&m, const VecT& normal)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
matrix_scale_along_axis_2D(m, normal, value_type(-1));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D orthographic projection to cardinal hyperplane
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing an orthographic projection onto a plane */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_ortho_project(matrix<E,A,B,L>& m, size_t axis)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
m(axis,axis) = value_type(0);
|
||||
}
|
||||
|
||||
/** Build a matrix representing an orthographic projection onto the yz plane*/
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_ortho_project_yz(matrix<E,A,B,L>& m) {
|
||||
matrix_ortho_project(m,0);
|
||||
}
|
||||
|
||||
/** Build a matrix representing an orthographic projection onto the zx plane*/
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_ortho_project_zx(matrix<E,A,B,L>& m) {
|
||||
matrix_ortho_project(m,1);
|
||||
}
|
||||
|
||||
/** Build a matrix representing an orthographic projection onto the zy plane*/
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_ortho_project_xy(matrix<E,A,B,L>& m) {
|
||||
matrix_ortho_project(m,2);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D orthographic projection to cardinal hyperplane
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 2D orthographic projection */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_ortho_project_2D(matrix<E,A,B,L>& m, size_t axis)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
detail::CheckIndex2(axis);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
m(axis,axis) = value_type(0);
|
||||
}
|
||||
|
||||
/** Build a matrix representing an orthographic projection onto the y axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_ortho_project_y_2D(matrix<E,A,B,L>& m) {
|
||||
matrix_ortho_project_2D(m,0);
|
||||
}
|
||||
|
||||
/** Build a matrix representing an orthographic projection onto the x axis */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_ortho_project_x_2D(matrix<E,A,B,L>& m) {
|
||||
matrix_ortho_project_2D(m,1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D orthographic projection to hyperplane
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 3D orthographic projection about the given
|
||||
* hyperplane passing through the origin.
|
||||
*/
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_ortho_project_to_hplane(matrix<E,A,B,L>& m, const VecT& normal)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
matrix_scale_along_axis(m, normal, value_type(0));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D orthographic projection to hyperplane
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 2D orthographic projection about the given
|
||||
* hyperplane passing through the origin.
|
||||
*/
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_ortho_project_to_hplane_2D(matrix<E,A,B,L>& m, const VecT& normal)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
matrix_scale_along_axis_2D(m, normal, value_type(0));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D 'aim at'
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
matrix_aim_at(matrix<E,A,B,L>& m, const VecT_1& pos, const VecT_2& target,
|
||||
const VecT_3& reference,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
matrix_rotation_aim_at(m, pos, target, reference, order);
|
||||
matrix_set_translation(m, pos);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2 > void
|
||||
matrix_aim_at(matrix<E,A,B,L>& m, const VecT_1& pos, const VecT_2& target,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
matrix_rotation_aim_at(m, pos, target, order);
|
||||
matrix_set_translation(m, pos);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
matrix_aim_at_axial(
|
||||
matrix<E,A,B,L>& m,
|
||||
const VecT_1& pos,
|
||||
const VecT_2& target,
|
||||
const VecT_3& axis,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
matrix_rotation_aim_at_axial(m, pos, target, axis, order);
|
||||
matrix_set_translation(m, pos);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E,class A,class B,class L,class VecT,class MatT > void
|
||||
matrix_aim_at_viewplane(
|
||||
matrix<E,A,B,L>& m,
|
||||
const VecT& pos,
|
||||
const MatT& view_matrix,
|
||||
Handedness handedness,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
matrix_rotation_align_viewplane(m, view_matrix, handedness, order);
|
||||
matrix_set_translation(m, pos);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D 'aim at'
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E,class A,class B,class L,class VecT_1,class VecT_2 > void
|
||||
matrix_aim_at_2D(
|
||||
matrix<E,A,B,L>& m,
|
||||
const VecT_1& pos,
|
||||
const VecT_2& target,
|
||||
AxisOrder2D order = axis_order_xy)
|
||||
{
|
||||
matrix_rotation_align_2D(m, target - pos, true, order);
|
||||
matrix_set_translation_2D(m, pos);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D 'look at' view matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix representing a 'look at' view transform */
|
||||
template < typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
matrix_look_at(
|
||||
matrix<E,A,B,L>& m,
|
||||
const VecT_1& eye,
|
||||
const VecT_2& target,
|
||||
const VecT_3& up,
|
||||
Handedness handedness)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef vector< E,fixed<3> > vector_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatAffine3D(m);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
value_type s = handedness == left_handed ?
|
||||
static_cast<value_type>(1) : static_cast<value_type>(-1);
|
||||
vector_type z = s * normalize(target - eye);
|
||||
vector_type x = unit_cross(up,z);
|
||||
vector_type y = cross(z,x);
|
||||
|
||||
matrix_set_transposed_basis_vectors(m,x,y,z);
|
||||
matrix_set_translation(m,-dot(eye,x),-dot(eye,y),-dot(eye,z));
|
||||
}
|
||||
|
||||
/** Build a matrix representing a left-handedness 'look at' view transform */
|
||||
template < typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
matrix_look_at_LH(matrix<E,A,B,L>& m, const VecT_1& eye,
|
||||
const VecT_2& target, const VecT_3& up)
|
||||
{
|
||||
matrix_look_at(m, eye, target, up, left_handed);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a right-handedness 'look at' view transform */
|
||||
template < typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
matrix_look_at_RH(matrix<E,A,B,L>& m, const VecT_1& eye,
|
||||
const VecT_2& target, const VecT_3& up)
|
||||
{
|
||||
matrix_look_at(m, eye, target, up, right_handed);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a 'look at' view transform */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_look_at(matrix<E,A,B,L>& m, E eye_x, E eye_y, E eye_z, E target_x,
|
||||
E target_y, E target_z, E up_x, E up_y, E up_z,
|
||||
Handedness handedness)
|
||||
{
|
||||
typedef vector< E, fixed<3> > vector_type;
|
||||
|
||||
matrix_look_at(m,
|
||||
vector_type(eye_x,eye_y,eye_z),
|
||||
vector_type(target_x,target_y,target_z),
|
||||
vector_type(up_x,up_y,up_z),
|
||||
handedness
|
||||
);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a left-handed'look at' view transform */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_look_at_LH(matrix<E,A,B,L>& m, E eye_x, E eye_y, E eye_z,
|
||||
E target_x, E target_y, E target_z, E up_x, E up_y, E up_z)
|
||||
{
|
||||
matrix_look_at(m,eye_x,eye_y,eye_z,target_x,target_y,target_z,up_x,up_y,
|
||||
up_z,left_handed);
|
||||
}
|
||||
|
||||
/** Build a matrix representing a right-handed'look at' view transform */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_look_at_RH(matrix<E,A,B,L>& m, E eye_x, E eye_y, E eye_z,
|
||||
E target_x, E target_y, E target_z, E up_x, E up_y, E up_z)
|
||||
{
|
||||
matrix_look_at(m,eye_x,eye_y,eye_z,target_x,target_y,target_z,up_x,up_y,
|
||||
up_z,right_handed);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D linear transform
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix from the 3x3 linear transform part of another matrix */
|
||||
template < typename E, class A, class B, class L, class MatT > void
|
||||
matrix_linear_transform(matrix<E,A,B,L>& m, const MatT& linear)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
detail::CheckMatLinear3D(linear);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
for(size_t i = 0; i < 3; ++i) {
|
||||
for(size_t j = 0; j < 3; ++j) {
|
||||
m.set_basis_element(i,j,linear.basis_element(i,j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D linear transform
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a matrix from the 2x2 linear transform part of another matrix */
|
||||
template < typename E, class A, class B, class L, class MatT > void
|
||||
matrix_linear_transform_2D(matrix<E,A,B,L>& m, const MatT& linear)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatLinear2D(m);
|
||||
detail::CheckMatLinear2D(linear);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
for(size_t i = 0; i < 2; ++i) {
|
||||
for(size_t j = 0; j < 2; ++j) {
|
||||
m.set_basis_element(i,j,linear.basis_element(i,j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D affine transform
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** 3D affine transform from three basis vectors and a translation */
|
||||
template <typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2, class VecT_3, class VecT_4 > void
|
||||
matrix_affine_transform(matrix<E,A,B,L>& m, const VecT_1& x, const VecT_2& y,
|
||||
const VecT_3& z, const VecT_4& translation)
|
||||
{
|
||||
identity_transform(m);
|
||||
matrix_set_basis_vectors(m,x,y,z);
|
||||
matrix_set_translation(m,translation);
|
||||
}
|
||||
|
||||
/** 3D affine transform from a quaternion and a translation */
|
||||
template <
|
||||
typename E, class A, class B, class L,
|
||||
typename QE, class QA, class O, class C, class VecT > void
|
||||
matrix_affine_transform(
|
||||
matrix<E,A,B,L>& m, const quaternion<QE,QA,O,C>& q,
|
||||
const VecT& translation)
|
||||
{
|
||||
matrix_rotation_quaternion(m,q);
|
||||
matrix_set_translation(m,translation);
|
||||
}
|
||||
|
||||
/** 3D affine transform from a quaternion expression and a translation */
|
||||
template < typename E,class A,class B,class L,class XprT,class VecT > void
|
||||
matrix_affine_transform(
|
||||
matrix<E,A,B,L>& m, const et::QuaternionXpr<XprT>& q,
|
||||
const VecT& translation)
|
||||
{
|
||||
matrix_rotation_quaternion(m,q);
|
||||
matrix_set_translation(m,translation);
|
||||
}
|
||||
|
||||
/** 3D affine transform from an axis-angle pair and a translation */
|
||||
template <
|
||||
typename E, class A, class B, class L, class VecT_1, class VecT_2 > void
|
||||
matrix_affine_transform(
|
||||
matrix<E,A,B,L>& m,const VecT_1& axis,E angle,const VecT_2& translation)
|
||||
{
|
||||
matrix_rotation_axis_angle(m,axis,angle);
|
||||
matrix_set_translation(m,translation);
|
||||
}
|
||||
|
||||
/** 3D affine transform from an Euler-angle triple and a translation */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_affine_transform(matrix<E,A,B,L>& m, E angle_0, E angle_1,
|
||||
E angle_2, EulerOrder order, const VecT& translation)
|
||||
{
|
||||
matrix_rotation_euler(m,angle_0,angle_1,angle_2,order);
|
||||
matrix_set_translation(m,translation);
|
||||
}
|
||||
|
||||
/** 3D affine transform from a matrix and a translation */
|
||||
template <
|
||||
typename E, class A, class B, class L,
|
||||
typename ME, class MA, class MB, class ML, class VecT > void
|
||||
matrix_affine_transform(matrix<E,A,B,L>& m,
|
||||
const matrix<ME,MA,MB,ML>& linear, const VecT& translation)
|
||||
{
|
||||
matrix_linear_transform(m,linear);
|
||||
matrix_set_translation(m,translation);
|
||||
}
|
||||
|
||||
/** 3D affine transform from a matrix expression and a translation */
|
||||
template < typename E,class A,class B,class L,class XprT,class VecT > void
|
||||
matrix_affine_transform(
|
||||
matrix<E,A,B,L>& m, const et::MatrixXpr<XprT>& linear,
|
||||
const VecT& translation)
|
||||
{
|
||||
matrix_linear_transform(m,linear);
|
||||
matrix_set_translation(m,translation);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 2D affine transform
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** 2D affine transform from two basis vectors and a translation */
|
||||
template <typename E, class A, class B, class L,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
matrix_affine_transform_2D(matrix<E,A,B,L>& m, const VecT_1& x,
|
||||
const VecT_2& y, const VecT_3& translation)
|
||||
{
|
||||
identity_transform(m);
|
||||
matrix_set_basis_vectors_2D(m,x,y);
|
||||
matrix_set_translation_2D(m,translation);
|
||||
}
|
||||
|
||||
/** 2D affine transform from a rotation angle and a translation */
|
||||
template <typename E, class A, class B, class L, class VecT >
|
||||
void matrix_affine_transform_2D(matrix<E,A,B,L>& m, E angle,
|
||||
const VecT& translation)
|
||||
{
|
||||
matrix_rotation_2D(m,angle);
|
||||
matrix_set_translation_2D(m,translation);
|
||||
}
|
||||
|
||||
/** 2D affine transform from a matrix and a translation */
|
||||
template < typename E,class A,class B,class L,class MatT,class VecT > void
|
||||
matrix_affine_transform_2D(
|
||||
matrix<E,A,B,L>& m, const MatT& linear, const VecT& translation)
|
||||
{
|
||||
matrix_linear_transform_2D(m, linear);
|
||||
matrix_set_translation_2D(m,translation);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D affine from 2D affine
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Construct a 3D affine transform from a 2D affine transform */
|
||||
template < typename E, class A, class B, class L, class MatT > void
|
||||
matrix_3D_affine_from_2D_affine(matrix<E,A,B,L>& m, const MatT& affine_2D)
|
||||
{
|
||||
typedef vector< E, fixed<2> > vector_type;
|
||||
|
||||
vector_type x = matrix_get_x_basis_vector_2D(affine_2D);
|
||||
vector_type y = matrix_get_y_basis_vector_2D(affine_2D);
|
||||
vector_type p = matrix_get_translation_2D(affine_2D);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
matrix_set_basis_vectors_2D(m,x,y);
|
||||
matrix_set_translation(m,p);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 3D affine from 3D affine
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Construct a 3D affine transform from another 3D affine transform */
|
||||
template < typename E, class A, class B, class L, class MatT > void
|
||||
matrix_3D_affine_from_3D_affine(matrix<E,A,B,L>& m, const MatT& affine_3D)
|
||||
{
|
||||
typedef vector< E, fixed<3> > vector_type;
|
||||
|
||||
vector_type x = matrix_get_x_basis_vector(affine_3D);
|
||||
vector_type y = matrix_get_y_basis_vector(affine_3D);
|
||||
vector_type z = matrix_get_z_basis_vector(affine_3D);
|
||||
vector_type p = matrix_get_translation(affine_3D);
|
||||
|
||||
identity_transform(m);
|
||||
|
||||
matrix_set_basis_vectors(m,x,y,z);
|
||||
matrix_set_translation(m,p);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Matrix decomposition (scale->rotate->translate)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* 3x3 matrix version */
|
||||
template <
|
||||
class MatT,
|
||||
typename Real,
|
||||
typename ME,
|
||||
class MA,
|
||||
class B,
|
||||
class L,
|
||||
typename VE,
|
||||
class VA
|
||||
>
|
||||
void matrix_decompose_SRT(
|
||||
const MatT& m,
|
||||
Real& scale_x,
|
||||
Real& scale_y,
|
||||
Real& scale_z,
|
||||
matrix<ME,MA,B,L>& rotation,
|
||||
vector<VE,VA>& translation)
|
||||
{
|
||||
typedef MatT matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
typedef vector<value_type, fixed<3> > vector_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatAffine3D(m);
|
||||
detail::CheckMatLinear3D(rotation);
|
||||
|
||||
vector_type x, y, z;
|
||||
matrix_get_basis_vectors(m, x, y, z);
|
||||
|
||||
scale_x = x.length();
|
||||
scale_y = y.length();
|
||||
scale_z = z.length();
|
||||
|
||||
x /= scale_x;
|
||||
y /= scale_y;
|
||||
z /= scale_z;
|
||||
|
||||
matrix_set_basis_vectors(rotation, x, y, z);
|
||||
translation = matrix_get_translation(m);
|
||||
}
|
||||
|
||||
/* Quaternion version */
|
||||
template <
|
||||
class MatT,
|
||||
typename Real,
|
||||
typename QE,
|
||||
class QA,
|
||||
class O,
|
||||
class C,
|
||||
typename VE,
|
||||
class VA
|
||||
>
|
||||
void matrix_decompose_SRT(
|
||||
const MatT& m,
|
||||
Real& scale_x,
|
||||
Real& scale_y,
|
||||
Real& scale_z,
|
||||
quaternion<QE,QA,O,C>& rotation,
|
||||
vector<VE,VA>& translation)
|
||||
{
|
||||
typedef MatT matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
typedef matrix< value_type, fixed<3,3> > rotation_type;
|
||||
|
||||
rotation_type rotation_matrix;
|
||||
matrix_decompose_SRT(
|
||||
m, scale_x, scale_y, scale_z, rotation_matrix, translation);
|
||||
quaternion_rotation_matrix(rotation, rotation_matrix);
|
||||
}
|
||||
|
||||
/* Euler angle version */
|
||||
template < class MatT, typename Real, typename E, class A >
|
||||
void matrix_decompose_SRT(
|
||||
const MatT& m,
|
||||
Real& scale_x,
|
||||
Real& scale_y,
|
||||
Real& scale_z,
|
||||
Real& angle_0,
|
||||
Real& angle_1,
|
||||
Real& angle_2,
|
||||
EulerOrder order,
|
||||
vector<E,A>& translation,
|
||||
Real tolerance = epsilon<Real>::placeholder())
|
||||
{
|
||||
typedef MatT matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
typedef matrix< value_type, fixed<3,3> > rotation_type;
|
||||
|
||||
rotation_type rotation_matrix;
|
||||
matrix_decompose_SRT(
|
||||
m, scale_x, scale_y, scale_z, rotation_matrix, translation);
|
||||
matrix_to_euler(
|
||||
rotation_matrix, angle_0, angle_1, angle_2, order, tolerance);
|
||||
}
|
||||
|
||||
/* Axis-angle version */
|
||||
template < class MatT, typename Real, typename E, class A >
|
||||
void matrix_decompose_SRT(
|
||||
const MatT& m,
|
||||
Real& scale_x,
|
||||
Real& scale_y,
|
||||
Real& scale_z,
|
||||
vector<E,A>& axis,
|
||||
Real& angle,
|
||||
vector<E,A>& translation,
|
||||
Real tolerance = epsilon<Real>::placeholder())
|
||||
{
|
||||
typedef MatT matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
typedef matrix< value_type, fixed<3,3> > rotation_type;
|
||||
|
||||
rotation_type rotation_matrix;
|
||||
matrix_decompose_SRT(
|
||||
m, scale_x, scale_y, scale_z, rotation_matrix, translation);
|
||||
matrix_to_axis_angle(rotation_matrix, axis, angle, tolerance);
|
||||
}
|
||||
|
||||
/* 2x2 matrix version, 2-d */
|
||||
template <
|
||||
class MatT,
|
||||
typename Real,
|
||||
typename ME,
|
||||
class MA,
|
||||
class B,
|
||||
class L,
|
||||
typename VE,
|
||||
class VA
|
||||
>
|
||||
void matrix_decompose_SRT_2D(
|
||||
const MatT& m,
|
||||
Real& scale_x,
|
||||
Real& scale_y,
|
||||
matrix<ME,MA,B,L>& rotation,
|
||||
vector<VE,VA>& translation)
|
||||
{
|
||||
typedef MatT matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
typedef vector<value_type, fixed<2> > vector_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatAffine2D(m);
|
||||
detail::CheckMatLinear2D(rotation);
|
||||
|
||||
vector_type x, y;
|
||||
matrix_get_basis_vectors_2D(m, x, y);
|
||||
|
||||
scale_x = x.length();
|
||||
scale_y = y.length();
|
||||
|
||||
x /= scale_x;
|
||||
y /= scale_y;
|
||||
|
||||
matrix_set_basis_vectors_2D(rotation, x, y);
|
||||
translation = matrix_get_translation_2D(m);
|
||||
}
|
||||
|
||||
/* Angle version, 2-d */
|
||||
template < class MatT, typename Real, typename E, class A >
|
||||
void matrix_decompose_SRT_2D(
|
||||
const MatT& m,
|
||||
Real& scale_x,
|
||||
Real& scale_y,
|
||||
Real& angle,
|
||||
vector<E,A>& translation)
|
||||
{
|
||||
typedef MatT matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
typedef matrix< value_type, fixed<2,2> > rotation_type;
|
||||
|
||||
rotation_type rotation_matrix;
|
||||
matrix_decompose_SRT_2D(
|
||||
m, scale_x, scale_y, rotation_matrix, translation);
|
||||
angle = matrix_to_rotation_2D(rotation_matrix);
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
177
Lib/Include/CML/mathlib/matrix_translation.h
Normal file
177
Lib/Include/CML/mathlib/matrix_translation.h
Normal file
@@ -0,0 +1,177 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef matrix_translation_h
|
||||
#define matrix_translation_h
|
||||
|
||||
#include <cml/mathlib/checking.h>
|
||||
|
||||
/* Functions for getting and setting the translation of a 3D or 2D affine
|
||||
* transform.
|
||||
*/
|
||||
|
||||
namespace cml {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Functions for setting the translation of a 3D or 2D affine transform matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Set the translation of a 3D affine transform */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_set_translation(matrix<E,A,B,L>& m, E x, E y, E z)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatAffine3D(m);
|
||||
|
||||
m.set_basis_element(3,0,x);
|
||||
m.set_basis_element(3,1,y);
|
||||
m.set_basis_element(3,2,z);
|
||||
}
|
||||
|
||||
/** Set the translation of a 3D affine transform with z set to 0 */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_set_translation(matrix<E,A,B,L>& m, E x, E y)
|
||||
{
|
||||
typedef matrix<E,A,B,L> matrix_type;
|
||||
typedef typename matrix_type::value_type value_type;
|
||||
|
||||
matrix_set_translation(m, x, y, value_type(0));
|
||||
}
|
||||
|
||||
/** Set the translation of a 3D affine transform from a 3D or 2D vector */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_translation(matrix<E,A,B,L>& m, const VecT& translation)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckVec2Or3(translation);
|
||||
|
||||
if (translation.size() == 3) {
|
||||
matrix_set_translation(
|
||||
m,translation[0], translation[1], translation[2]);
|
||||
} else { // translation.size() == 2
|
||||
matrix_set_translation(m, translation[0], translation[1]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Set the translation of a 2D affine transform */
|
||||
template < typename E, class A, class B, class L > void
|
||||
matrix_set_translation_2D(matrix<E,A,B,L>& m, E x, E y)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckMatAffine2D(m);
|
||||
|
||||
m.set_basis_element(2,0,x);
|
||||
m.set_basis_element(2,1,y);
|
||||
}
|
||||
|
||||
/** Set the translation of a 2D affine transform from a 2D vector */
|
||||
template < typename E, class A, class B, class L, class VecT > void
|
||||
matrix_set_translation_2D(matrix<E,A,B,L>& m, const VecT& translation)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckVec2(translation);
|
||||
|
||||
matrix_set_translation_2D(m, translation[0], translation[1]);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Functions for getting the translation of a 3D or 2D affine transform matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Get the translation of a 3D affine transform */
|
||||
template < class MatT > vector< typename MatT::value_type, fixed<3> >
|
||||
matrix_get_translation(const MatT& m)
|
||||
{
|
||||
typedef typename MatT::value_type value_type;
|
||||
typedef vector< value_type, fixed<3> > vector_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatAffine3D(m);
|
||||
|
||||
return vector_type(
|
||||
m.basis_element(3,0),
|
||||
m.basis_element(3,1),
|
||||
m.basis_element(3,2)
|
||||
);
|
||||
}
|
||||
|
||||
/** Get the translation of a 3D affine transform */
|
||||
template < class MatT > void
|
||||
matrix_get_translation(
|
||||
const MatT& m,
|
||||
typename MatT::value_type& t1,
|
||||
typename MatT::value_type& t2,
|
||||
typename MatT::value_type& t3
|
||||
)
|
||||
{
|
||||
typedef typename MatT::value_type value_type;
|
||||
typedef vector< value_type, fixed<3> > vector_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatAffine3D(m);
|
||||
|
||||
t1 = m.basis_element(3,0);
|
||||
t2 = m.basis_element(3,1);
|
||||
t3 = m.basis_element(3,2);
|
||||
}
|
||||
|
||||
/** Get the translation of a 2D affine transform */
|
||||
template < class MatT > vector< typename MatT::value_type, fixed<2> >
|
||||
matrix_get_translation_2D(const MatT& m)
|
||||
{
|
||||
typedef typename MatT::value_type value_type;
|
||||
typedef vector< value_type, fixed<2> > vector_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatAffine2D(m);
|
||||
|
||||
return vector_type(m.basis_element(2,0), m.basis_element(2,1));
|
||||
}
|
||||
|
||||
/** Get the translation of a 2D affine transform */
|
||||
template < class MatT > void
|
||||
matrix_get_translation_2D(
|
||||
const MatT& m,
|
||||
typename MatT::value_type& t1,
|
||||
typename MatT::value_type& t2
|
||||
)
|
||||
{
|
||||
typedef typename MatT::value_type value_type;
|
||||
typedef vector< value_type, fixed<2> > vector_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatAffine2D(m);
|
||||
|
||||
t1 = m.basis_element(2,0);
|
||||
t2 = m.basis_element(2,1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Function for getting the translation of a 3D view matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Get the translation of a 3D affine transform */
|
||||
template < class MatT > vector< typename MatT::value_type, fixed<3> >
|
||||
matrix_get_view_translation(const MatT& m)
|
||||
{
|
||||
typedef typename MatT::value_type value_type;
|
||||
typedef vector< value_type, fixed<3> > vector_type;
|
||||
|
||||
vector_type x, y, z;
|
||||
matrix_get_basis_vectors(m,x,y,z);
|
||||
vector_type p = matrix_get_translation(m);
|
||||
return vector_type(-dot(p,x),-dot(p,y),-dot(p,z));
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
210
Lib/Include/CML/mathlib/misc.h
Normal file
210
Lib/Include/CML/mathlib/misc.h
Normal file
@@ -0,0 +1,210 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef misc_h
|
||||
#define misc_h
|
||||
|
||||
#include <cml/mathlib/checking.h>
|
||||
|
||||
/* A few miscellaneous functions and helper classes.
|
||||
*
|
||||
* @note: This is somewhat ad-hoc and will probably all be replaced in a future
|
||||
* version of the CML (I don't think I even bothered to document these functions
|
||||
* on the website).
|
||||
*/
|
||||
|
||||
namespace cml {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// N-d functions
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Return an N-d zero vector */
|
||||
template < size_t N >
|
||||
vector< double, fixed<N> > zero()
|
||||
{
|
||||
typedef vector< double, fixed<N> > vector_type;
|
||||
|
||||
vector_type result;
|
||||
result.zero();
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Return an N-d cardinal axis by index */
|
||||
template < size_t N >
|
||||
vector< double, fixed<N> > axis(size_t i)
|
||||
{
|
||||
/* Checking */
|
||||
detail::CheckValidArg(i < N);
|
||||
|
||||
typedef vector< double, fixed<N> > vector_type;
|
||||
vector_type result;
|
||||
result.cardinal(i);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Return an NxM zero matrix */
|
||||
template < size_t N, size_t M >
|
||||
matrix< double, fixed<N,M>, row_basis, row_major > zero()
|
||||
{
|
||||
typedef matrix< double, fixed<N,M>, row_basis, row_major > matrix_type;
|
||||
|
||||
matrix_type result;
|
||||
result.zero();
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Return an NxN identity matrix */
|
||||
template < size_t N >
|
||||
matrix< double, fixed<N,N>, row_basis, row_major > identity()
|
||||
{
|
||||
typedef matrix< double, fixed<N,N>, row_basis, row_major > matrix_type;
|
||||
|
||||
matrix_type result;
|
||||
result.identity();
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Return an NxM identity transform */
|
||||
template < size_t N, size_t M >
|
||||
matrix< double, fixed<N,M>, row_basis, row_major > identity_transform()
|
||||
{
|
||||
typedef matrix< double, fixed<N,M>, row_basis, row_major > matrix_type;
|
||||
|
||||
matrix_type result;
|
||||
identity_transform(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Zero vector
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Return the 2D zero vector */
|
||||
inline vector< double, fixed<2> > zero_2D() {
|
||||
return zero<2>();
|
||||
}
|
||||
|
||||
/** Return the 3D zero vector */
|
||||
inline vector< double, fixed<3> > zero_3D() {
|
||||
return zero<3>();
|
||||
}
|
||||
|
||||
/** Return the 4D zero vector */
|
||||
inline vector< double, fixed<4> > zero_4D() {
|
||||
return zero<4>();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Cardinal axis
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Return a 2D cardinal axis by index */
|
||||
inline vector< double, fixed<2> > axis_2D(size_t i) {
|
||||
return axis<2>(i);
|
||||
}
|
||||
|
||||
/** Return a 3D cardinal axis by index */
|
||||
inline vector< double, fixed<3> > axis_3D(size_t i) {
|
||||
return axis<3>(i);
|
||||
}
|
||||
|
||||
/** Return a the 2D x cardinal axis */
|
||||
inline vector< double, fixed<2> > x_axis_2D() {
|
||||
return axis_2D(0);
|
||||
}
|
||||
|
||||
/** Return a the 2D y cardinal axis */
|
||||
inline vector< double, fixed<2> > y_axis_2D() {
|
||||
return axis_2D(1);
|
||||
}
|
||||
|
||||
/** Return a the 3D x cardinal axis */
|
||||
inline vector< double, fixed<3> > x_axis_3D() {
|
||||
return axis_3D(0);
|
||||
}
|
||||
|
||||
/** Return a the 3D y cardinal axis */
|
||||
inline vector< double, fixed<3> > y_axis_3D() {
|
||||
return axis_3D(1);
|
||||
}
|
||||
|
||||
/** Return a the 3D z cardinal axis */
|
||||
inline vector< double, fixed<3> > z_axis_3D() {
|
||||
return axis_3D(2);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Zero matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Return the 2x2 zero matrix */
|
||||
inline matrix< double, fixed<2,2>, row_basis, row_major > zero_2x2() {
|
||||
return zero<2,2>();
|
||||
}
|
||||
|
||||
/** Return the 3x3 zero matrix */
|
||||
inline matrix< double, fixed<3,3>, row_basis, row_major > zero_3x3() {
|
||||
return zero<3,3>();
|
||||
}
|
||||
|
||||
/** Return the 4x4 zero matrix */
|
||||
inline matrix< double, fixed<4,4>, row_basis, row_major > zero_4x4() {
|
||||
return zero<4,4>();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Identity matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Return the 2x2 identity matrix */
|
||||
inline matrix< double, fixed<2,2>, row_basis, row_major > identity_2x2() {
|
||||
return identity<2>();
|
||||
}
|
||||
|
||||
/** Return the 3x3 identity matrix */
|
||||
inline matrix< double, fixed<3,3>, row_basis, row_major > identity_3x3() {
|
||||
return identity<3>();
|
||||
}
|
||||
|
||||
/** Return the 4x4 identity matrix */
|
||||
inline matrix< double, fixed<4,4>, row_basis, row_major > identity_4x4() {
|
||||
return identity<4>();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Identity transform matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Return a 3x2 identity transform */
|
||||
inline matrix< double,fixed<3,2>,row_basis,row_major > identity_transform_3x2() {
|
||||
return identity_transform<3,2>();
|
||||
}
|
||||
|
||||
/** Return a 2x3 identity transform */
|
||||
inline matrix< double,fixed<2,3>,col_basis,col_major > identity_transform_2x3() {
|
||||
return identity_transform<2,3>();
|
||||
}
|
||||
|
||||
/** Return a 4x3 identity transform */
|
||||
inline matrix< double,fixed<4,3>,row_basis,row_major > identity_transform_4x3() {
|
||||
return identity_transform<4,3>();
|
||||
}
|
||||
|
||||
/** Return a 3x4 identity transform */
|
||||
inline matrix< double,fixed<3,4>,col_basis,col_major > identity_transform_3x4() {
|
||||
return identity_transform<3,4>();
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
195
Lib/Include/CML/mathlib/picking.h
Normal file
195
Lib/Include/CML/mathlib/picking.h
Normal file
@@ -0,0 +1,195 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef picking_h
|
||||
#define picking_h
|
||||
|
||||
#include <cml/mathlib/projection.h>
|
||||
|
||||
/* Functions for picking with rays, volumes, and drag-enclosed volumes. */
|
||||
|
||||
namespace cml {
|
||||
|
||||
/* Support function for extracting the near and far depth range values from
|
||||
* a viewport matrix.
|
||||
*/
|
||||
|
||||
namespace detail {
|
||||
|
||||
// NOTE: Changed 'near' and 'far' to 'n' and 'f' to work around windows.h
|
||||
// 'near' and 'far' macros.
|
||||
|
||||
template < class MatT, typename Real > void
|
||||
depth_range_from_viewport_matrix(const MatT& viewport, Real& n, Real& f)
|
||||
{
|
||||
detail::CheckMatHomogeneous3D(viewport);
|
||||
|
||||
n = viewport.basis_element(3,2);
|
||||
f = viewport.basis_element(2,2) + n;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/* Make a pick ray given screen coordinates and view, projection, and viewport
|
||||
* matrices. The origin of the ray lies in the near plane of the frustum; the
|
||||
* direction vector extends to the far plane if 'normalize' is false, and is
|
||||
* made unit-length if 'normalize' is true (its default value).
|
||||
*
|
||||
* Note that the origin of the ray lies in the near plane rather than
|
||||
* coinciding with the position of the virtual camera, as the latter gives
|
||||
* incorrect results when the projection is orthographic.
|
||||
*
|
||||
* Note also that the screen y coordinate increases from bottom to top rather
|
||||
* than top to bottom. If mouse coordinates are returned in window space where
|
||||
* the y coordinate increases from top to bottom (as is often the case), the
|
||||
* y value should be recomputed as 'y = <window height> - y' before being
|
||||
* submitted to this function.
|
||||
*/
|
||||
|
||||
template < class MatT_1, class MatT_2, class MatT_3, typename E, class A >
|
||||
void make_pick_ray(
|
||||
E pick_x,
|
||||
E pick_y,
|
||||
const MatT_1& view,
|
||||
const MatT_2& projection,
|
||||
const MatT_3& viewport,
|
||||
vector<E,A>& origin,
|
||||
vector<E,A>& direction,
|
||||
bool normalize = true)
|
||||
{
|
||||
typedef vector<E,A> vector_type;
|
||||
typedef typename vector_type::value_type value_type;
|
||||
|
||||
// NOTE: Changed 'near' and 'far' to 'n' and 'f' to work around
|
||||
// windows.h 'near' and 'far' macros.
|
||||
value_type n, f;
|
||||
detail::depth_range_from_viewport_matrix(viewport, n, f);
|
||||
|
||||
origin =
|
||||
unproject_point(
|
||||
view,projection,viewport,vector_type(pick_x,pick_y,n)
|
||||
);
|
||||
direction =
|
||||
unproject_point(
|
||||
view,projection,viewport,vector_type(pick_x,pick_y,f)
|
||||
) - origin;
|
||||
if (normalize) {
|
||||
direction.normalize();
|
||||
}
|
||||
}
|
||||
|
||||
/* Make a pick volume given the screen coordinates of the center of the
|
||||
* picking rect, the width and height of the picking rect, and view and
|
||||
* projection matrices.
|
||||
*
|
||||
* The volume is loaded into the 'planes' array. The planes are of the form
|
||||
* ax+by+cz+d = 0, and are in the order left, right, bottom, top, near, far.
|
||||
*
|
||||
* The z_clip argument should be either z_clip_neg_one or z_clip_zero, and
|
||||
* should correspond to the near z-clipping range of the projection matrix
|
||||
* argument.
|
||||
*
|
||||
* The 'normalize' argument indicates whether the output planes should be
|
||||
* normalized; its default value is 'true'.
|
||||
*
|
||||
* Note that the screen y coordinate increases from bottom to top rather
|
||||
* than top to bottom. If mouse coordinates are returned in window space where
|
||||
* the y coordinate increases from top to bottom (as is often the case), the
|
||||
* y value should be recomputed as 'y = <window height> - y' before being
|
||||
* submitted to this function.
|
||||
*/
|
||||
|
||||
template < class MatT_1, class MatT_2, typename Real >
|
||||
void make_pick_volume(
|
||||
Real pick_x,
|
||||
Real pick_y,
|
||||
Real pick_width,
|
||||
Real pick_height,
|
||||
Real viewport_x,
|
||||
Real viewport_y,
|
||||
Real viewport_width,
|
||||
Real viewport_height,
|
||||
const MatT_1& view,
|
||||
const MatT_2& projection,
|
||||
Real planes[6][4],
|
||||
ZClip z_clip,
|
||||
bool normalize = true)
|
||||
{
|
||||
// FIXME: Should be promoted type...
|
||||
typedef matrix<
|
||||
Real, fixed<4,4>,
|
||||
typename MatT_1::basis_orient, typename MatT_1::layout >
|
||||
matrix_type;
|
||||
|
||||
matrix_type pick;
|
||||
matrix_pick(
|
||||
pick, pick_x, pick_y, pick_width, pick_height,
|
||||
viewport_x, viewport_y, viewport_width, viewport_height
|
||||
);
|
||||
cml::extract_frustum_planes(
|
||||
view,detail::matrix_concat_transforms_4x4(projection,pick),
|
||||
planes,z_clip,normalize);
|
||||
}
|
||||
|
||||
/* Make a pick volume given two opposite corners of a rectangle in screen
|
||||
* space, and view and projection matrices. The corners of the screen rect
|
||||
* need not be in any particular 'order' with regard to the values of the
|
||||
* coordinates.
|
||||
*
|
||||
* The volume is loaded into the 'planes' array. The planes are of the form
|
||||
* ax+by+cz+d = 0, and are in the order left, right, bottom, top, near, far.
|
||||
*
|
||||
* The z_clip argument should be either z_clip_neg_one or z_clip_zero, and
|
||||
* should correspond to the near z-clipping range of the projection matrix
|
||||
* argument.
|
||||
*
|
||||
* The 'normalize' argument indicates whether the output planes should be
|
||||
* normalized; its default value is 'true'.
|
||||
*
|
||||
* Note that the screen y coordinate increases from bottom to top rather
|
||||
* than top to bottom. If mouse coordinates are returned in window space where
|
||||
* the y coordinate increases from top to bottom (as is often the case), the
|
||||
* y value should be recomputed as 'y = <window height> - y' before being
|
||||
* submitted to this function.
|
||||
*/
|
||||
|
||||
template < class MatT_1, class MatT_2, typename Real >
|
||||
void make_pick_drag_volume(
|
||||
Real pick_x1,
|
||||
Real pick_y1,
|
||||
Real pick_x2,
|
||||
Real pick_y2,
|
||||
Real viewport_x,
|
||||
Real viewport_y,
|
||||
Real viewport_width,
|
||||
Real viewport_height,
|
||||
const MatT_1& view,
|
||||
const MatT_2& projection,
|
||||
Real planes[6][4],
|
||||
ZClip z_clip,
|
||||
bool normalize = true)
|
||||
{
|
||||
typedef Real value_type;
|
||||
|
||||
make_pick_volume(
|
||||
(pick_x1+pick_x2)*value_type(.5),
|
||||
(pick_y1+pick_y2)*value_type(.5),
|
||||
std::fabs(pick_x2-pick_x1),
|
||||
std::fabs(pick_y2-pick_y1),
|
||||
viewport_x, viewport_y, viewport_width, viewport_height,
|
||||
view, projection, planes, z_clip, normalize
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
142
Lib/Include/CML/mathlib/projection.h
Normal file
142
Lib/Include/CML/mathlib/projection.h
Normal file
@@ -0,0 +1,142 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef projection_h
|
||||
#define projection_h
|
||||
|
||||
#include <cml/mathlib/matrix_concat.h>
|
||||
#include <cml/mathlib/vector_transform.h>
|
||||
|
||||
/* Functions for projection and 'unprojection' of points in 3D. */
|
||||
|
||||
namespace cml {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template < typename E > void
|
||||
divide_by_w(vector< E,fixed<4> >& v) {
|
||||
v *= E(1) / v[3];
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/* Project a point to screen space using the given model, view, projection,
|
||||
* and viewport matrices. The z value of the returned point is a depth value
|
||||
* in the range specified by the viewport matrix.
|
||||
*/
|
||||
|
||||
template <class MatT_1, class MatT_2, class MatT_3, class MatT_4, class VecT>
|
||||
vector< typename VecT::value_type, fixed<3> > project_point(
|
||||
const MatT_1& model,
|
||||
const MatT_2& view,
|
||||
const MatT_3& projection,
|
||||
const MatT_4& viewport,
|
||||
const VecT& p)
|
||||
{
|
||||
return project_point(
|
||||
detail::matrix_concat_transforms_4x4(model,view),
|
||||
projection,
|
||||
viewport,
|
||||
p
|
||||
);
|
||||
}
|
||||
|
||||
/* Project a point to screen space using the given modelview, projection, and
|
||||
* viewport matrices. The z value of the returned point is a depth value in
|
||||
* the range specified by the viewport matrix.
|
||||
*/
|
||||
|
||||
template < class MatT_1, class MatT_2, class MatT_3, class VecT >
|
||||
vector< typename VecT::value_type, fixed<3> > project_point(
|
||||
const MatT_1& modelview,
|
||||
const MatT_2& projection,
|
||||
const MatT_3& viewport,
|
||||
const VecT& p)
|
||||
{
|
||||
typedef vector< typename VecT::value_type, fixed<3> > vector3_type;
|
||||
typedef vector< typename VecT::value_type, fixed<4> > vector4_type;
|
||||
typedef typename vector3_type::value_type value_type;
|
||||
|
||||
detail::CheckVec3(p);
|
||||
|
||||
vector4_type result = transform_vector_4D(
|
||||
detail::matrix_concat_transforms_4x4(
|
||||
modelview,
|
||||
detail::matrix_concat_transforms_4x4(
|
||||
projection,
|
||||
viewport
|
||||
)
|
||||
),
|
||||
vector4_type(p[0],p[1],p[2],value_type(1))
|
||||
);
|
||||
detail::divide_by_w(result);
|
||||
return vector3_type(result[0],result[1],result[2]);
|
||||
}
|
||||
|
||||
/* 'Unproject' a point from screen space using the given model, view,
|
||||
* projection, and viewport matrices. The z value of the input point is a
|
||||
* depth value in the range specified by the viewport matrix.
|
||||
*/
|
||||
|
||||
template <class MatT_1, class MatT_2, class MatT_3, class MatT_4, class VecT>
|
||||
vector< typename VecT::value_type, fixed<3> > unproject_point(
|
||||
const MatT_1& model,
|
||||
const MatT_2& view,
|
||||
const MatT_3& projection,
|
||||
const MatT_4& viewport,
|
||||
const VecT& p)
|
||||
{
|
||||
return unproject_point(
|
||||
detail::matrix_concat_transforms_4x4(model,view),
|
||||
projection,
|
||||
viewport,
|
||||
p
|
||||
);
|
||||
}
|
||||
|
||||
/* 'Unproject' a point from screen space using the given modelview,
|
||||
* projection, and viewport matrices. The z value of the input point is a
|
||||
* depth value in the range specified by the viewport matrix.
|
||||
*/
|
||||
|
||||
template < class MatT_1, class MatT_2, class MatT_3, class VecT >
|
||||
vector< typename VecT::value_type, fixed<3> > unproject_point(
|
||||
const MatT_1& modelview,
|
||||
const MatT_2& projection,
|
||||
const MatT_3& viewport,
|
||||
const VecT& p)
|
||||
{
|
||||
typedef vector< typename VecT::value_type, fixed<3> > vector3_type;
|
||||
typedef vector< typename VecT::value_type, fixed<4> > vector4_type;
|
||||
typedef typename vector3_type::value_type value_type;
|
||||
|
||||
detail::CheckVec3(p);
|
||||
|
||||
vector4_type result = transform_vector_4D(
|
||||
inverse(
|
||||
detail::matrix_concat_transforms_4x4(
|
||||
modelview,
|
||||
detail::matrix_concat_transforms_4x4(
|
||||
projection,
|
||||
viewport
|
||||
)
|
||||
)
|
||||
),
|
||||
vector4_type(p[0],p[1],p[2],value_type(1))
|
||||
);
|
||||
detail::divide_by_w(result);
|
||||
return vector3_type(result[0],result[1],result[2]);
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
89
Lib/Include/CML/mathlib/quaternion_basis.h
Normal file
89
Lib/Include/CML/mathlib/quaternion_basis.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef quaternion_basis_h
|
||||
#define quaternion_basis_h
|
||||
|
||||
#include <cml/mathlib/checking.h>
|
||||
|
||||
/* Functions for getting the basis vectors of a quaternion rotation. */
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** Get the i'th basis vector of a quaternion rotation */
|
||||
template < class QuatT > vector< typename QuatT::value_type, fixed<3> >
|
||||
quaternion_get_basis_vector(const QuatT& q, size_t i)
|
||||
{
|
||||
typedef QuatT quaternion_type;
|
||||
typedef typename quaternion_type::value_type value_type;
|
||||
typedef typename quaternion_type::order_type order_type;
|
||||
typedef vector< value_type, fixed<3> > vector_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckQuat(q);
|
||||
detail::CheckIndex3(i);
|
||||
|
||||
size_t j, k;
|
||||
cyclic_permutation(i, i, j, k);
|
||||
|
||||
/* @todo: Clean this up. */
|
||||
const size_t W = order_type::W;
|
||||
const size_t I = order_type::X + i;
|
||||
const size_t J = order_type::X + j;
|
||||
const size_t K = order_type::X + k;
|
||||
|
||||
value_type j2 = q[J] + q[J];
|
||||
value_type k2 = q[K] + q[K];
|
||||
|
||||
/* @todo: use set_permuted() for the following when available. */
|
||||
|
||||
vector_type result;
|
||||
result[i] = value_type(1) - q[J] * j2 - q[K] * k2;
|
||||
result[j] = q[I] * j2 + q[W] * k2;
|
||||
result[k] = q[I] * k2 - q[W] * j2;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Get the x basis vector of a quaternion rotation */
|
||||
template < class QuatT > vector< typename QuatT::value_type, fixed<3> >
|
||||
quaternion_get_x_basis_vector(const QuatT& q) {
|
||||
return quaternion_get_basis_vector(q,0);
|
||||
}
|
||||
|
||||
/** Get the y basis vector of a quaternion rotation */
|
||||
template < class QuatT > vector< typename QuatT::value_type, fixed<3> >
|
||||
quaternion_get_y_basis_vector(const QuatT& q) {
|
||||
return quaternion_get_basis_vector(q,1);
|
||||
}
|
||||
|
||||
/** Get the z basis vector of a quaternion rotation */
|
||||
template < class QuatT > vector< typename QuatT::value_type, fixed<3> >
|
||||
quaternion_get_z_basis_vector(const QuatT& q) {
|
||||
return quaternion_get_basis_vector(q,2);
|
||||
}
|
||||
|
||||
/** Get the basis vectors of a quaternion rotation */
|
||||
template < class QuatT, typename E, class A > void
|
||||
quaternion_get_basis_vectors(
|
||||
const QuatT& q,
|
||||
vector<E,A>& x,
|
||||
vector<E,A>& y,
|
||||
vector<E,A>& z)
|
||||
{
|
||||
x = quaternion_get_x_basis_vector(q);
|
||||
y = quaternion_get_y_basis_vector(q);
|
||||
z = quaternion_get_z_basis_vector(q);
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
635
Lib/Include/CML/mathlib/quaternion_rotation.h
Normal file
635
Lib/Include/CML/mathlib/quaternion_rotation.h
Normal file
@@ -0,0 +1,635 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef quaternion_rotation_h
|
||||
#define quaternion_rotation_h
|
||||
|
||||
#include <cml/mathlib/checking.h>
|
||||
|
||||
/* Functions related to quaternion rotations.
|
||||
*
|
||||
* Note: A number of these functions simply wrap calls to the corresponding
|
||||
* matrix functions. Some of them (the 'aim-at' and 'align' functions in
|
||||
* particular) might be considered a bit superfluous, since the resulting
|
||||
* quaternion will most likely be converted to a matrix at some point anyway.
|
||||
* However, they're included here for completeness, and for convenience in
|
||||
* cases where a quaternion is being used as the primary rotation
|
||||
* representation.
|
||||
*/
|
||||
|
||||
namespace cml {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Rotation about world axes
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a quaternion representing a rotation about the given world axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotation_world_axis(quaternion<E,A,O,C>& q, size_t axis, E angle)
|
||||
{
|
||||
typedef quaternion<E,A,O,C> quaternion_type;
|
||||
typedef typename quaternion_type::value_type value_type;
|
||||
typedef typename quaternion_type::order_type order_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
q.identity();
|
||||
|
||||
const size_t W = order_type::W;
|
||||
const size_t I = order_type::X + axis;
|
||||
|
||||
angle *= value_type(.5);
|
||||
q[I] = std::sin(angle);
|
||||
q[W] = std::cos(angle);
|
||||
}
|
||||
|
||||
/** Build a quaternion representing a rotation about the world x axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotation_world_x(quaternion<E,A,O,C>& q, E angle) {
|
||||
quaternion_rotation_world_axis(q,0,angle);
|
||||
}
|
||||
|
||||
/** Build a quaternion representing a rotation about the world y axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotation_world_y(quaternion<E,A,O,C>& q, E angle) {
|
||||
quaternion_rotation_world_axis(q,1,angle);
|
||||
}
|
||||
|
||||
/** Build a quaternion representing a rotation about the world z axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotation_world_z(quaternion<E,A,O,C>& q, E angle) {
|
||||
quaternion_rotation_world_axis(q,2,angle);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Rotation from an axis-angle pair
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a quaternion from an axis-angle pair */
|
||||
template < class E, class A, class O, class C, class VecT > void
|
||||
quaternion_rotation_axis_angle(
|
||||
quaternion<E,A,O,C>& q, const VecT& axis, E angle)
|
||||
{
|
||||
typedef quaternion<E,A,O,C> quaternion_type;
|
||||
typedef typename quaternion_type::value_type value_type;
|
||||
typedef typename quaternion_type::order_type order_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckVec3(axis);
|
||||
|
||||
enum {
|
||||
W = order_type::W,
|
||||
X = order_type::X,
|
||||
Y = order_type::Y,
|
||||
Z = order_type::Z
|
||||
};
|
||||
|
||||
angle *= value_type(.5);
|
||||
|
||||
/* @todo: If and when we have a set() function that takes a vector and a
|
||||
* scalar, this can be written as:
|
||||
*
|
||||
* q.set(std::cos(angle), axis * std::sin(angle));
|
||||
*
|
||||
* In which case the enum will also not be necessary.
|
||||
*/
|
||||
|
||||
q[W] = std::cos(angle);
|
||||
value_type s = std::sin(angle);
|
||||
q[X] = axis[0] * s;
|
||||
q[Y] = axis[1] * s;
|
||||
q[Z] = axis[2] * s;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Rotation from a matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a quaternion from a rotation matrix */
|
||||
template < class E, class A, class O, class C, class MatT > void
|
||||
quaternion_rotation_matrix(quaternion<E,A,O,C>& q, const MatT& m)
|
||||
{
|
||||
typedef quaternion<E,A,O,C> quaternion_type;
|
||||
typedef typename quaternion_type::value_type value_type;
|
||||
typedef typename quaternion_type::order_type order_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckMatLinear3D(m);
|
||||
|
||||
enum {
|
||||
W = order_type::W,
|
||||
X = order_type::X,
|
||||
Y = order_type::Y,
|
||||
Z = order_type::Z
|
||||
};
|
||||
|
||||
value_type tr = trace_3x3(m);
|
||||
if (tr >= value_type(0)) {
|
||||
q[W] = std::sqrt(tr + value_type(1)) * value_type(.5);
|
||||
value_type s = value_type(.25) / q[W];
|
||||
q[X] = (m.basis_element(1,2) - m.basis_element(2,1)) * s;
|
||||
q[Y] = (m.basis_element(2,0) - m.basis_element(0,2)) * s;
|
||||
q[Z] = (m.basis_element(0,1) - m.basis_element(1,0)) * s;
|
||||
} else {
|
||||
size_t largest_diagonal_element =
|
||||
index_of_max(
|
||||
m.basis_element(0,0),
|
||||
m.basis_element(1,1),
|
||||
m.basis_element(2,2)
|
||||
);
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(largest_diagonal_element, i, j, k);
|
||||
const size_t I = X + i;
|
||||
const size_t J = X + j;
|
||||
const size_t K = X + k;
|
||||
q[I] =
|
||||
std::sqrt(
|
||||
m.basis_element(i,i) -
|
||||
m.basis_element(j,j) -
|
||||
m.basis_element(k,k) +
|
||||
value_type(1)
|
||||
) * value_type(.5);
|
||||
value_type s = value_type(.25) / q[I];
|
||||
q[J] = (m.basis_element(i,j) + m.basis_element(j,i)) * s;
|
||||
q[K] = (m.basis_element(i,k) + m.basis_element(k,i)) * s;
|
||||
q[W] = (m.basis_element(j,k) - m.basis_element(k,j)) * s;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Rotation from Euler angles
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Build a quaternion from an Euler-angle triple */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotation_euler(
|
||||
quaternion<E,A,O,C>& q, E angle_0, E angle_1, E angle_2,
|
||||
EulerOrder order)
|
||||
{
|
||||
typedef quaternion<E,A,O,C> quaternion_type;
|
||||
typedef typename quaternion_type::value_type value_type;
|
||||
typedef typename quaternion_type::order_type order_type;
|
||||
|
||||
size_t i, j, k;
|
||||
bool odd, repeat;
|
||||
detail::unpack_euler_order(order, i, j, k, odd, repeat);
|
||||
|
||||
const size_t W = order_type::W;
|
||||
const size_t I = order_type::X + i;
|
||||
const size_t J = order_type::X + j;
|
||||
const size_t K = order_type::X + k;
|
||||
|
||||
if (odd) {
|
||||
angle_1 = -angle_1;
|
||||
}
|
||||
|
||||
angle_0 *= value_type(.5);
|
||||
angle_1 *= value_type(.5);
|
||||
angle_2 *= value_type(.5);
|
||||
|
||||
value_type s0 = std::sin(angle_0);
|
||||
value_type c0 = std::cos(angle_0);
|
||||
value_type s1 = std::sin(angle_1);
|
||||
value_type c1 = std::cos(angle_1);
|
||||
value_type s2 = std::sin(angle_2);
|
||||
value_type c2 = std::cos(angle_2);
|
||||
|
||||
value_type s0s2 = s0 * s2;
|
||||
value_type s0c2 = s0 * c2;
|
||||
value_type c0s2 = c0 * s2;
|
||||
value_type c0c2 = c0 * c2;
|
||||
|
||||
if (repeat) {
|
||||
q[I] = c1 * (c0s2 + s0c2);
|
||||
q[J] = s1 * (c0c2 + s0s2);
|
||||
q[K] = s1 * (c0s2 - s0c2);
|
||||
q[W] = c1 * (c0c2 - s0s2);
|
||||
} else {
|
||||
q[I] = c1 * s0c2 - s1 * c0s2;
|
||||
q[J] = c1 * s0s2 + s1 * c0c2;
|
||||
q[K] = c1 * c0s2 - s1 * s0c2;
|
||||
q[W] = c1 * c0c2 + s1 * s0s2;
|
||||
}
|
||||
if (odd) {
|
||||
q[J] = -q[J];
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Rotation to align with a vector, multiple vectors, or the view plane
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E,class A,class O,class C,class VecT_1,class VecT_2 > void
|
||||
quaternion_rotation_align(
|
||||
quaternion<E,A,O,C>& q,
|
||||
const VecT_1& align,
|
||||
const VecT_2& reference,
|
||||
bool normalize = true,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef matrix< E,fixed<3,3>,row_basis,row_major > matrix_type;
|
||||
|
||||
matrix_type m;
|
||||
matrix_rotation_align(m,align,reference,normalize,order);
|
||||
quaternion_rotation_matrix(q,m);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class O, class C, class VecT > void
|
||||
quaternion_rotation_align(quaternion<E,A,O,C>& q, const VecT& align,
|
||||
bool normalize = true, AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef matrix< E,fixed<3,3>,row_basis,row_major > matrix_type;
|
||||
|
||||
matrix_type m;
|
||||
matrix_rotation_align(m,align,normalize,order);
|
||||
quaternion_rotation_matrix(q,m);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E,class A,class O,class C,class VecT_1,class VecT_2 > void
|
||||
quaternion_rotation_align_axial(quaternion<E,A,O,C>& q, const VecT_1& align,
|
||||
const VecT_2& axis, bool normalize = true,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef matrix< E,fixed<3,3>,row_basis,row_major > matrix_type;
|
||||
|
||||
matrix_type m;
|
||||
matrix_rotation_align_axial(m,align,axis,normalize,order);
|
||||
quaternion_rotation_matrix(q,m);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class O, class C, class MatT > void
|
||||
quaternion_rotation_align_viewplane(
|
||||
quaternion<E,A,O,C>& q,
|
||||
const MatT& view_matrix,
|
||||
Handedness handedness,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef matrix< E,fixed<3,3>,row_basis,row_major > matrix_type;
|
||||
|
||||
matrix_type m;
|
||||
matrix_rotation_align_viewplane(m,view_matrix,handedness,order);
|
||||
quaternion_rotation_matrix(q,m);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class O, class C, class MatT > void
|
||||
quaternion_rotation_align_viewplane_LH(
|
||||
quaternion<E,A,O,C>& q,
|
||||
const MatT& view_matrix,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef matrix< E,fixed<3,3>,row_basis,row_major > matrix_type;
|
||||
|
||||
matrix_type m;
|
||||
matrix_rotation_align_viewplane_LH(m,view_matrix,order);
|
||||
quaternion_rotation_matrix(q,m);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class O, class C, class MatT > void
|
||||
quaternion_rotation_align_viewplane_RH(
|
||||
quaternion<E,A,O,C>& q,
|
||||
const MatT& view_matrix,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef matrix< E,fixed<3,3>,row_basis,row_major > matrix_type;
|
||||
|
||||
matrix_type m;
|
||||
matrix_rotation_align_viewplane_RH(m,view_matrix,order);
|
||||
quaternion_rotation_matrix(q,m);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Rotation to aim at a target
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class O, class C,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
quaternion_rotation_aim_at(
|
||||
quaternion<E,A,O,C>& q,
|
||||
const VecT_1& pos,
|
||||
const VecT_2& target,
|
||||
const VecT_3& reference,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef matrix< E,fixed<3,3>,row_basis,row_major > matrix_type;
|
||||
|
||||
matrix_type m;
|
||||
matrix_rotation_aim_at(m,pos,target,reference,order);
|
||||
quaternion_rotation_matrix(q,m);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class O, class C,
|
||||
class VecT_1, class VecT_2 > void
|
||||
quaternion_rotation_aim_at(
|
||||
quaternion<E,A,O,C>& q,
|
||||
const VecT_1& pos,
|
||||
const VecT_2& target,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef matrix< E,fixed<3,3>,row_basis,row_major > matrix_type;
|
||||
|
||||
matrix_type m;
|
||||
matrix_rotation_aim_at(m,pos,target,order);
|
||||
quaternion_rotation_matrix(q,m);
|
||||
}
|
||||
|
||||
/** See vector_ortho.h for details */
|
||||
template < typename E, class A, class O, class C,
|
||||
class VecT_1, class VecT_2, class VecT_3 > void
|
||||
quaternion_rotation_aim_at_axial(
|
||||
quaternion<E,A,O,C>& q,
|
||||
const VecT_1& pos,
|
||||
const VecT_2& target,
|
||||
const VecT_3& axis,
|
||||
AxisOrder order = axis_order_zyx)
|
||||
{
|
||||
typedef matrix< E,fixed<3,3>,row_basis,row_major > matrix_type;
|
||||
|
||||
matrix_type m;
|
||||
matrix_rotation_aim_at_axial(m,pos,target,axis,order);
|
||||
quaternion_rotation_matrix(q,m);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Relative rotation about world axes
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Rotate a quaternion about the given world axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotate_about_world_axis(quaternion<E,A,O,C>& q,size_t axis,E angle)
|
||||
{
|
||||
typedef quaternion<E,A,O,C> quaternion_type;
|
||||
typedef typename quaternion_type::value_type value_type;
|
||||
typedef typename quaternion_type::order_type order_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(axis, i, j, k);
|
||||
|
||||
const size_t W = order_type::W;
|
||||
const size_t I = order_type::X + i;
|
||||
const size_t J = order_type::X + j;
|
||||
const size_t K = order_type::X + k;
|
||||
|
||||
angle *= value_type(.5);
|
||||
value_type s = value_type(std::sin(angle));
|
||||
value_type c = value_type(std::cos(angle));
|
||||
|
||||
quaternion_type result;
|
||||
result[I] = c * q[I] + s * q[W];
|
||||
result[J] = c * q[J] - s * q[K];
|
||||
result[K] = c * q[K] + s * q[J];
|
||||
result[W] = c * q[W] - s * q[I];
|
||||
q = result;
|
||||
}
|
||||
|
||||
/* Rotate a quaternion about the world x axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotate_about_world_x(quaternion<E,A,O,C>& q, E angle) {
|
||||
quaternion_rotate_about_world_axis(q,0,angle);
|
||||
}
|
||||
|
||||
/* Rotate a quaternion about the world y axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotate_about_world_y(quaternion<E,A,O,C>& q, E angle) {
|
||||
quaternion_rotate_about_world_axis(q,1,angle);
|
||||
}
|
||||
|
||||
/* Rotate a quaternion about the world z axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotate_about_world_z(quaternion<E,A,O,C>& q, E angle) {
|
||||
quaternion_rotate_about_world_axis(q,2,angle);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Relative rotation about local axes
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Rotate a quaternion about the given local axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotate_about_local_axis(quaternion<E,A,O,C>& q,size_t axis,E angle)
|
||||
{
|
||||
typedef quaternion<E,A,O,C> quaternion_type;
|
||||
typedef typename quaternion_type::value_type value_type;
|
||||
typedef typename quaternion_type::order_type order_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckIndex3(axis);
|
||||
|
||||
size_t i, j, k;
|
||||
cyclic_permutation(axis, i, j, k);
|
||||
|
||||
const size_t W = order_type::W;
|
||||
const size_t I = order_type::X + i;
|
||||
const size_t J = order_type::X + j;
|
||||
const size_t K = order_type::X + k;
|
||||
|
||||
angle *= value_type(.5);
|
||||
value_type s = value_type(std::sin(angle));
|
||||
value_type c = value_type(std::cos(angle));
|
||||
|
||||
quaternion_type result;
|
||||
result[I] = c * q[I] + s * q[W];
|
||||
result[J] = c * q[J] + s * q[K];
|
||||
result[K] = c * q[K] - s * q[J];
|
||||
result[W] = c * q[W] - s * q[I];
|
||||
q = result;
|
||||
}
|
||||
|
||||
/* Rotate a quaternion about its local x axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotate_about_local_x(quaternion<E,A,O,C>& q, E angle) {
|
||||
quaternion_rotate_about_local_axis(q,0,angle);
|
||||
}
|
||||
|
||||
/* Rotate a quaternion about its local y axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotate_about_local_y(quaternion<E,A,O,C>& q, E angle) {
|
||||
quaternion_rotate_about_local_axis(q,1,angle);
|
||||
}
|
||||
|
||||
/* Rotate a quaternion about its local z axis */
|
||||
template < class E, class A, class O, class C > void
|
||||
quaternion_rotate_about_local_z(quaternion<E,A,O,C>& q, E angle) {
|
||||
quaternion_rotate_about_local_axis(q,2,angle);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Rotation from vector to vector
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* http://www.martinb.com/maths/algebra/vectors/angleBetween/index.htm. */
|
||||
|
||||
/** Build a quaternion to rotate from one vector to another */
|
||||
template < class E,class A,class O,class C,class VecT_1,class VecT_2 > void
|
||||
quaternion_rotation_vec_to_vec(
|
||||
quaternion<E,A,O,C>& q,
|
||||
const VecT_1& v1,
|
||||
const VecT_2& v2,
|
||||
bool unit_length_vectors = false)
|
||||
{
|
||||
typedef quaternion<E,A,O,C> quaternion_type;
|
||||
typedef typename quaternion_type::value_type value_type;
|
||||
typedef vector< value_type, fixed<3> > vector_type;
|
||||
|
||||
/* Checking handled by cross() */
|
||||
|
||||
/* @todo: If at some point quaternion<> has a set() function that takes a
|
||||
* vector and a scalar, this can then be written as:
|
||||
*
|
||||
* if (...) {
|
||||
* q.set(value_type(1)+dot(v1,v2), cross(v1,v2));
|
||||
* } else {
|
||||
* q.set(std::sqrt(...)+dot(v1,v2), cross(v1,v2));
|
||||
* }
|
||||
*/
|
||||
|
||||
vector_type c = cross(v1,v2);
|
||||
if (unit_length_vectors) {
|
||||
q = quaternion_type(value_type(1) + dot(v1,v2), c.data());
|
||||
} else {
|
||||
q = quaternion_type(
|
||||
std::sqrt(v1.length_squared() * v2.length_squared()) + dot(v1,v2),
|
||||
c/*.data()*/
|
||||
);
|
||||
}
|
||||
q.normalize();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Scale the angle of a rotation matrix
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template < typename E, class A, class O, class C > void
|
||||
quaternion_scale_angle(quaternion<E,A,O,C>& q, E t,
|
||||
E tolerance = epsilon<E>::placeholder())
|
||||
{
|
||||
typedef vector< E,fixed<3> > vector_type;
|
||||
typedef typename vector_type::value_type value_type;
|
||||
|
||||
vector_type axis;
|
||||
value_type angle;
|
||||
quaternion_to_axis_angle(q, axis, angle, tolerance);
|
||||
quaternion_rotation_axis_angle(q, axis, angle * t);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Support functions for uniform handling of pos- and neg-cross quaternions
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace detail {
|
||||
|
||||
/** Concatenate two quaternions in the order q1->q2 */
|
||||
template < class QuatT_1, class QuatT_2 >
|
||||
typename et::QuaternionPromote2<QuatT_1,QuatT_2>::temporary_type
|
||||
quaternion_rotation_difference(
|
||||
const QuatT_1& q1, const QuatT_2& q2, positive_cross)
|
||||
{
|
||||
return q2 * conjugate(q1);
|
||||
}
|
||||
|
||||
/** Concatenate two quaternions in the order q1->q2 */
|
||||
template < class QuatT_1, class QuatT_2 >
|
||||
typename et::QuaternionPromote2<QuatT_1,QuatT_2>::temporary_type
|
||||
quaternion_rotation_difference(
|
||||
const QuatT_1& q1, const QuatT_2& q2, negative_cross)
|
||||
{
|
||||
return conjugate(q1) * q2;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Quaternions rotation difference
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Return the rotational 'difference' between two quaternions */
|
||||
template < class QuatT_1, class QuatT_2 >
|
||||
typename et::QuaternionPromote2<QuatT_1,QuatT_2>::temporary_type
|
||||
quaternion_rotation_difference(const QuatT_1& q1, const QuatT_2& q2) {
|
||||
return detail::quaternion_rotation_difference(
|
||||
q1, q2, typename QuatT_1::cross_type());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Conversions
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Convert a quaternion to an axis-angle pair */
|
||||
template < class QuatT, typename E, class A > void
|
||||
quaternion_to_axis_angle(
|
||||
const QuatT& q,
|
||||
vector<E,A>& axis,
|
||||
E& angle,
|
||||
E tolerance = epsilon<E>::placeholder())
|
||||
{
|
||||
typedef QuatT quaternion_type;
|
||||
typedef typename quaternion_type::value_type value_type;
|
||||
typedef typename quaternion_type::order_type order_type;
|
||||
|
||||
/* Checking */
|
||||
detail::CheckQuat(q);
|
||||
|
||||
axis = q.imaginary();
|
||||
value_type l = length(axis);
|
||||
if (l > tolerance) {
|
||||
axis /= l;
|
||||
angle = value_type(2) * std::atan2(l,q.real());
|
||||
} else {
|
||||
axis.zero();
|
||||
angle = value_type(0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Convert a quaternion to an Euler-angle triple
|
||||
*
|
||||
* Note: I've implemented direct quaternion-to-Euler conversion, but as far as
|
||||
* I can tell it more or less reduces to converting the quaternion to a matrix
|
||||
* as you go. The direct method is a little more efficient in that it doesn't
|
||||
* require a temporary and only the necessary matrix elements need be
|
||||
* computed. However, the implementation is complex and there's considerable
|
||||
* opportunity for error, so from a development and debugging standpoint I
|
||||
* think it's better to just perform the conversion via matrix_to_euler(),
|
||||
* which is already known to be correct.
|
||||
*/
|
||||
|
||||
template < class QuatT, typename Real > void
|
||||
quaternion_to_euler(
|
||||
const QuatT& q,
|
||||
Real& angle_0,
|
||||
Real& angle_1,
|
||||
Real& angle_2,
|
||||
EulerOrder order,
|
||||
Real tolerance = epsilon<Real>::placeholder())
|
||||
{
|
||||
typedef QuatT quaternion_type;
|
||||
typedef typename quaternion_type::value_type value_type;
|
||||
typedef matrix< value_type,fixed<3,3>,row_basis,row_major > matrix_type;
|
||||
|
||||
matrix_type m;
|
||||
matrix_rotation_quaternion(m, q);
|
||||
matrix_to_euler(m, angle_0, angle_1, angle_2, order, tolerance);
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
134
Lib/Include/CML/mathlib/typedef.h
Normal file
134
Lib/Include/CML/mathlib/typedef.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef typedef_h
|
||||
#define typedef_h
|
||||
|
||||
#include <cml/vector.h>
|
||||
#include <cml/matrix.h>
|
||||
#include <cml/quaternion.h>
|
||||
#include <cml/constants.h>
|
||||
#include <cml/mathlib/epsilon.h>
|
||||
|
||||
namespace cml {
|
||||
|
||||
/* fixed-size vectors */
|
||||
typedef vector< int, fixed<2> > vector2i;
|
||||
typedef vector< float, fixed<2> > vector2f;
|
||||
typedef vector< double, fixed<2> > vector2d;
|
||||
|
||||
typedef vector< int, fixed<3> > vector3i;
|
||||
typedef vector< float, fixed<3> > vector3f;
|
||||
typedef vector< double, fixed<3> > vector3d;
|
||||
|
||||
typedef vector< int, fixed<4> > vector4i;
|
||||
typedef vector< float, fixed<4> > vector4f;
|
||||
typedef vector< double, fixed<4> > vector4d;
|
||||
|
||||
/* fixed-size matrices */
|
||||
|
||||
typedef matrix< int, fixed<2,2> > matrix22i;
|
||||
typedef matrix< float, fixed<2,2> > matrix22f;
|
||||
typedef matrix< double, fixed<2,2> > matrix22d;
|
||||
|
||||
typedef matrix< int, fixed<2,2>, row_basis, row_major > matrix22i_r;
|
||||
typedef matrix< int, fixed<2,2>, col_basis, col_major > matrix22i_c;
|
||||
typedef matrix< float, fixed<2,2>, row_basis, row_major > matrix22f_r;
|
||||
typedef matrix< float, fixed<2,2>, col_basis, col_major > matrix22f_c;
|
||||
typedef matrix< double, fixed<2,2>, row_basis, row_major > matrix22d_r;
|
||||
typedef matrix< double, fixed<2,2>, col_basis, col_major > matrix22d_c;
|
||||
|
||||
|
||||
typedef matrix< int, fixed<3,3> > matrix33i;
|
||||
typedef matrix< float, fixed<3,3> > matrix33f;
|
||||
typedef matrix< double, fixed<3,3> > matrix33d;
|
||||
|
||||
typedef matrix< int, fixed<3,3>, row_basis, row_major > matrix33i_r;
|
||||
typedef matrix< int, fixed<3,3>, col_basis, col_major > matrix33i_c;
|
||||
typedef matrix< float, fixed<3,3>, row_basis, row_major > matrix33f_r;
|
||||
typedef matrix< float, fixed<3,3>, col_basis, col_major > matrix33f_c;
|
||||
typedef matrix< double, fixed<3,3>, row_basis, row_major > matrix33d_r;
|
||||
typedef matrix< double, fixed<3,3>, col_basis, col_major > matrix33d_c;
|
||||
|
||||
|
||||
typedef matrix< int, fixed<4,4> > matrix44i;
|
||||
typedef matrix< float, fixed<4,4> > matrix44f;
|
||||
typedef matrix< double, fixed<4,4> > matrix44d;
|
||||
|
||||
typedef matrix< int, fixed<4,4>, row_basis, row_major > matrix44i_r;
|
||||
typedef matrix< int, fixed<4,4>, col_basis, col_major > matrix44i_c;
|
||||
typedef matrix< float, fixed<4,4>, row_basis, row_major > matrix44f_r;
|
||||
typedef matrix< float, fixed<4,4>, col_basis, col_major > matrix44f_c;
|
||||
typedef matrix< double, fixed<4,4>, row_basis, row_major > matrix44d_r;
|
||||
typedef matrix< double, fixed<4,4>, col_basis, col_major > matrix44d_c;
|
||||
|
||||
|
||||
typedef matrix< int, fixed<3,2>, row_basis, row_major > matrix32i_r;
|
||||
typedef matrix< float, fixed<3,2>, row_basis, row_major > matrix32f_r;
|
||||
typedef matrix< double, fixed<3,2>, row_basis, row_major > matrix32d_r;
|
||||
|
||||
typedef matrix< int, fixed<2,3>, col_basis, col_major > matrix23i_c;
|
||||
typedef matrix< float, fixed<2,3>, col_basis, col_major > matrix23f_c;
|
||||
typedef matrix< double, fixed<2,3>, col_basis, col_major > matrix23d_c;
|
||||
|
||||
typedef matrix< int, fixed<4,3>, row_basis, row_major > matrix43i_r;
|
||||
typedef matrix< float, fixed<4,3>, row_basis, row_major > matrix43f_r;
|
||||
typedef matrix< double, fixed<4,3>, row_basis, row_major > matrix43d_r;
|
||||
|
||||
typedef matrix< int, fixed<3,4>, col_basis, col_major > matrix34i_c;
|
||||
typedef matrix< float, fixed<3,4>, col_basis, col_major > matrix34f_c;
|
||||
typedef matrix< double, fixed<3,4>, col_basis, col_major > matrix34d_c;
|
||||
|
||||
|
||||
/* quaternions */
|
||||
typedef quaternion<float, fixed<>,vector_first,negative_cross>
|
||||
quaternionf_n;
|
||||
typedef quaternion<float, fixed<>,vector_first,positive_cross>
|
||||
quaternionf_p;
|
||||
typedef quaternion<double,fixed<>,vector_first,negative_cross>
|
||||
quaterniond_n;
|
||||
typedef quaternion<double,fixed<>,vector_first,positive_cross>
|
||||
quaterniond_p;
|
||||
typedef quaternion<float> quaternionf;
|
||||
typedef quaternion<double> quaterniond;
|
||||
|
||||
|
||||
/* dynamically resizable vectors */
|
||||
typedef vector< int, dynamic<> > vectori;
|
||||
typedef vector< float, dynamic<> > vectorf;
|
||||
typedef vector< double, dynamic<> > vectord;
|
||||
|
||||
|
||||
/* dynamically resizable matrices */
|
||||
typedef matrix< int, dynamic<> > matrixi;
|
||||
typedef matrix< float, dynamic<> > matrixf;
|
||||
typedef matrix< double, dynamic<> > matrixd;
|
||||
|
||||
typedef matrix< int, dynamic<>, row_basis, row_major > matrixi_r;
|
||||
typedef matrix< int, dynamic<>, col_basis, col_major > matrixi_c;
|
||||
typedef matrix< float, dynamic<>, row_basis, row_major > matrixf_r;
|
||||
typedef matrix< float, dynamic<>, col_basis, col_major > matrixf_c;
|
||||
typedef matrix< double, dynamic<>, row_basis, row_major > matrixd_r;
|
||||
typedef matrix< double, dynamic<>, col_basis, col_major > matrixd_c;
|
||||
|
||||
|
||||
/* constants */
|
||||
typedef constants<float> constantsf;
|
||||
typedef constants<double> constantsd;
|
||||
|
||||
/* epsilon/tolerance values (placeholder) */
|
||||
typedef epsilon<float> epsilonf;
|
||||
typedef epsilon<double> epsilond;
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
69
Lib/Include/CML/mathlib/vector_angle.h
Normal file
69
Lib/Include/CML/mathlib/vector_angle.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* -*- C++ -*- ------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
|
||||
|
||||
The Configurable Math Library (CML) is distributed under the terms of the
|
||||
Boost Software License, v1.0 (see cml/LICENSE for details).
|
||||
|
||||
*-----------------------------------------------------------------------*/
|
||||
/** @file
|
||||
* @brief
|
||||
*/
|
||||
|
||||
#ifndef vector_angle_h
|
||||
#define vector_angle_h
|
||||
|
||||
#include <cml/mathlib/checking.h>
|
||||
|
||||
/* Functions for finding the signed and unsigned angles between vectors in
|
||||
* 3D and 2D.
|
||||
*
|
||||
* Note that the input vectors for these functions are not required to be
|
||||
* unit length.
|
||||
*
|
||||
* @todo: Clean up promotions, conversions, and return types.
|
||||
*/
|
||||
|
||||
namespace cml {
|
||||
|
||||
/** Signed angle between two 3D vectors. */
|
||||
template< class VecT_1, class VecT_2, class VecT_3 >
|
||||
typename detail::DotPromote<
|
||||
typename detail::CrossPromote<VecT_1,VecT_2>::promoted_vector, VecT_3
|
||||
>::promoted_scalar
|
||||
signed_angle(const VecT_1& v1, const VecT_2& v2, const VecT_3& reference)
|
||||
{
|
||||
typedef typename detail::CrossPromote<VecT_1,VecT_2>::promoted_vector
|
||||
vector_type;
|
||||
typedef typename detail::DotPromote<vector_type,VecT_3>::promoted_scalar
|
||||
value_type;
|
||||
|
||||
vector_type c = cross(v1,v2);
|
||||
value_type angle = std::atan2(double(length(c)),double(dot(v1,v2)));
|
||||
return dot(c,reference) < value_type(0) ? -angle : angle;
|
||||
}
|
||||
|
||||
/** Unsigned angle between two 3D vectors. */
|
||||
template< class VecT_1, class VecT_2 >
|
||||
typename detail::DotPromote< VecT_1, VecT_2 >::promoted_scalar
|
||||
unsigned_angle(const VecT_1& v1, const VecT_2& v2) {
|
||||
return std::atan2(double(length(cross(v1,v2))),double(dot(v1,v2)));
|
||||
}
|
||||
|
||||
/** Signed angle between two 2D vectors. */
|
||||
template< class VecT_1, class VecT_2 >
|
||||
typename detail::DotPromote< VecT_1, VecT_2 >::promoted_scalar
|
||||
signed_angle_2D(const VecT_1& v1, const VecT_2& v2) {
|
||||
return std::atan2(double(perp_dot(v1,v2)),double(dot(v1,v2)));
|
||||
}
|
||||
|
||||
/** Unsigned angle between two 2D vectors. */
|
||||
template< class VecT_1, class VecT_2 >
|
||||
typename detail::DotPromote< VecT_1, VecT_2 >::promoted_scalar
|
||||
unsigned_angle_2D(const VecT_1& v1, const VecT_2& v2) {
|
||||
return std::fabs(signed_angle_2D(v1,v2));
|
||||
}
|
||||
|
||||
} // namespace cml
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user