Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/openal-0.0.8/src/al_matrix.c @ 17

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

added openal

File size: 1.6 KB
Line 
1#include "al_siteconfig.h"
2
3#include <AL/al.h>
4#include <math.h>
5#include <stdlib.h>
6
7#include "al_debug.h"
8#include "al_types.h"
9#include "al_main.h"
10#include "al_matrix.h"
11
12/*
13 * _alMatrixMul( ALmatrix *result, ALmatrix *m1, ALmatrix *m2 )
14 *
15 * Multiplies m1 by m2, populating result.
16 *
17 *  FIXME: please check my math
18 */
19void _alMatrixMul( ALmatrix *result, ALmatrix *m1, ALmatrix *m2 ) {
20        int m2cols = m2->cols;
21        int m1rows = m1->rows;
22        int m1cols = m1->cols;
23        int i;
24        int j;
25        int k;
26
27        ALfloat sum;
28
29        for(i = 0; i < m2cols; i++) {
30                for(j = 0; j < m1rows; j++) {
31                        sum = 0.0f;
32
33                        for(k = 0; k < m1cols; k++) {
34                                sum += m1->data[j][k] * m2->data[k][i];
35                        }
36
37                        result->data[j][i] = sum;
38                }
39        }
40
41        return;
42}
43
44/*
45 * _alMatrixAlloc( int rows, int cols )
46 *
47 * Allocates, initializes, and returns a matrix with the dimensions matching
48 * the passed arguments, or NULL on error.
49 */
50ALmatrix *_alMatrixAlloc(int rows, int cols) {
51        ALmatrix *retval;
52        int i;
53
54        retval = malloc(sizeof *retval);
55        if(retval == NULL) {
56                return NULL;
57        }
58
59        retval->data = malloc(rows * sizeof *retval->data);
60        if(retval->data == NULL) {
61                return NULL;
62        }
63
64        for(i = 0; i < rows; i++) {
65                /* FIXME: clean return on error */
66                retval->data[i] = malloc(cols * sizeof *retval->data[i]);
67        }
68
69        retval->rows = rows;
70        retval->cols = cols;
71
72        return retval;
73}
74
75/*
76 * _alMatrixFree( ALmatrix *m )
77 *
78 * Frees a matrix allocated with _alMatrixAlloc.
79 */
80void _alMatrixFree(ALmatrix *m) {
81        int i;
82
83        if(m == NULL) {
84                return;
85        }
86
87        for(i = 0; i < m->rows; i++) {
88                free( m->data[i] );
89        }
90
91        free(m->data);
92        free(m);
93
94        return;
95}
96
Note: See TracBrowser for help on using the repository browser.