Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/openal-0.0.8/src/al_vector.h @ 48

Last change on this file since 48 was 17, checked in by landauf, 17 years ago

added openal

File size: 2.2 KB
Line 
1/* -*- mode: C; tab-width:8; c-basic-offset:8 -*-
2 * vi:set ts=8:
3 *
4 * al_vector.h
5 *
6 * kludgey vector math stuff
7 */
8
9#ifndef AL_VECTOR_H_
10#define AL_VECTOR_H_
11
12#include <math.h>
13/*
14 * Returns magnitude of v2 with origin at (0,0,0).
15 */
16static __inline ALfloat _alVectorMagnitudeAtZero( const ALfloat *v2 ) {
17        ALfloat retval;
18
19        retval = sqrt( v2[0] * v2[0] +
20                       v2[1] * v2[1] +
21                       v2[2] * v2[2] );
22
23        retval = fabs( retval );
24
25        return retval;
26}
27
28/*
29 * Return magnitude of v with origin at origin.
30 */
31ALfloat _alVectorMagnitude( const ALfloat *origin, const ALfloat *v );
32
33/*
34 * Places distance between two vectors in retref.
35 */
36static __inline void _alVectorDistance( ALfloat *retref, const ALfloat *v1,
37                        const ALfloat *v2 ) {
38
39        retref[0] = fabs( v1[0] - v2[0] );
40        retref[1] = fabs( v1[1] - v2[1] );
41        retref[2] = fabs( v1[2] - v2[2] );
42       
43        return;
44}
45
46/*
47 * Rotate point about axis by angle.
48 */
49void _alRotatePointAboutAxis( const ALfloat angle, ALfloat *point,
50                              const ALfloat *axis );
51
52/*
53 * Returns angle between two vectors with v1, v2 with shared origin.
54 *
55 * NOTE: Always positive
56 */
57ALfloat _alVectorAngleBetween( const ALfloat *origin, const ALfloat *v1,
58                              const ALfloat *v2 );
59
60/*
61 * Returns dot product of v1 . v2 ( with shared origin )
62 */
63ALfloat _alVectorDotp( const ALfloat *origin, const ALfloat *v1,
64                       const ALfloat *v2 );
65
66/*
67 * Translate s by delta, populating d.
68 */
69static __inline void _alVectorTranslate( ALfloat *d, const ALfloat *s,
70                         const ALfloat *delta ) {
71        d[0] = s[0] + delta[0];
72        d[1] = s[1] + delta[1];
73        d[2] = s[2] + delta[2];
74
75        return;
76}
77
78/*
79 * Populates d with vector inverse of s.
80 */
81static __inline void _alVectorInverse( ALfloat *d, const ALfloat *s ) {
82        d[0] = -s[0];
83        d[1] = -s[1];
84        d[2] = -s[2];
85
86        return;
87}
88
89/*
90 * Normalizes s, places result in d.
91 */
92void _alVectorNormalize( ALfloat *d, const ALfloat *s );
93
94/*
95 * Returns cross product between v1 and v2, result in d.
96 */
97static __inline void _alVectorCrossProduct( ALfloat *d, const ALfloat *v1,
98                              const ALfloat *v2 ) {
99        d[0] = v1[1] * v2[2] - v1[2] * v2[1];
100        d[1] = v1[2] * v2[0] - v1[0] * v2[2];
101        d[2] = v1[0] * v2[1] - v1[1] * v2[0];
102
103        return;
104}
105
106#endif /* AL_VECTOR_H */
Note: See TracBrowser for help on using the repository browser.