/* * _alcSpeakerMove( ALuint cid ) * * Moves speakers for context named by cid, using listener orientation and * position as modifiers. * * If cid is invalid, set ALC_INVALID_CONTEXT. * * assumes context cid is locked * * FIXME: * please check my math */ void _alcSpeakerMove( ALuint cid ) { AL_context *cc; ALfloat vec[3]; ALfloat *pos; /* listener position */ ALfloat *ori; /* listener orientation */ ALfloat ipos[3]; /* inverse listener position */ ALuint i; ALfloat m[3][3]; ALfloat pm[3]; ALfloat rm[3]; cc = _alcGetContext( cid ); if(cc == NULL) { _alDebug(ALD_CONTEXT, __FILE__, __LINE__, "_alcSpeakerMove: invalid context id %d", cid); _alcSetError( ALC_INVALID_CONTEXT ); return; } pos = cc->listener.position; ori = cc->listener.orientation; _alVectorCrossProduct(vec, ori + 0, ori + 3); _alVectorNormalize(m[0], vec); _alVectorCrossProduct(vec, m[0], ori + 0); _alVectorNormalize(m[1], vec); _alVectorNormalize(m[2], ori + 0); /* reset speaker position */ _alcSpeakerInit(cid); _alVectorInverse( ipos, cc->listener.position ); /* rotate about at and up vectors */ for(i = 0; i < _alcGetNumSpeakers(cid); i++) { _alVectorTranslate(pm, cc->_speaker_pos[i].pos, ipos); _alVecMatrixMulA3(rm, pm, m); _alVectorTranslate(cc->_speaker_pos[i].pos, rm, pos); } _alDebug(ALD_MATH, __FILE__, __LINE__, "SpAdj: l/r [%f|%f|%f] [%f|%f|%f]", cc->_speaker_pos[0].pos[0], cc->_speaker_pos[0].pos[1], cc->_speaker_pos[0].pos[2], cc->_speaker_pos[1].pos[0], cc->_speaker_pos[1].pos[1], cc->_speaker_pos[1].pos[2]); return; }
/* * _alVectorDotp( const ALfloat *origin, const ALfloat *v1, * const ALfloat *v2 ) * * Returns dot product between v1 and v2, with origin at origin. */ ALfloat _alVectorDotp( const ALfloat *origin, const ALfloat *v1, const ALfloat *v2 ) { ALfloat o_inverse[3]; ALfloat v1_trans[3]; ALfloat v2_trans[3]; ALfloat retval = 0.0f; _alVectorInverse( o_inverse, origin ); _alVectorTranslate( v1_trans, v1, o_inverse ); _alVectorTranslate( v2_trans, v2, o_inverse ); retval += v1_trans[0] * v2_trans[0]; retval += v1_trans[1] * v2_trans[1]; retval += v1_trans[2] * v2_trans[2]; return retval; }