aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/libg3d-0.0.8/include/g3d/vector.h
blob: aeb838cf2b2d65801ce2cfc9bf4bd6d447e966ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* $Id$ */

/*
    libg3d - 3D object loading library

    Copyright (C) 2005-2009  Markus Dahms <mad@automagically.de>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef __G3D_VECTOR_H__
#define __G3D_VECTOR_H__

#include <g3d/types.h>

#ifdef __cplusplus
extern "C" {
#endif /* ifdef __cplusplus */

/**
 * SECTION:vector
 * @short_description: Vector manipulation and calculation
 * @include: g3d/vector.h
 *
 * A vector is a one-dimensional array of floating point data.
 *
 * Declare it as statically as:
 *
 * G3DVector vector[3];
 *
 * or allocate it dynamically with:
 *
 * G3DVector *vector = g3d_vector_new(3, 1);
 */

/**
 * g3d_vector_new:
 * @size: number of items in one vector
 * @n: number of vectors to allocate
 *
 * Allocate memory for a number of vectors.
 *
 * Returns: newly allocated vectors
 */
_G3D_STATIC_INLINE G3DVector *g3d_vector_new(guint32 size, guint32 n) {
	return g_new0(G3DVector, size * n);
}

/**
 * g3d_vector_free:
 * @vector: vector to free
 *
 * Free memory allocated for vector.
 */
_G3D_STATIC_INLINE void g3d_vector_free(G3DVector *vector) {
	g_free(vector);
}

/**
 * g3d_vector_normal:
 * @ax: x component first vector
 * @ay: y component first vector
 * @az: z component first vector
 * @bx: x component second vector
 * @by: y component second vector
 * @bz: z component second vector
 * @nx: x component resulting normal
 * @ny: y component resulting normal
 * @nz: z component resulting normal
 *
 * calculate the normal from a plane defined by two vectors
 *
 * Returns: TRUE on success, FALSE else
 */
EAPI
gboolean g3d_vector_normal(G3DFloat ax, G3DFloat ay, G3DFloat az,
	G3DFloat bx, G3DFloat by, G3DFloat bz,
	G3DFloat *nx, G3DFloat *ny, G3DFloat *nz);

/**
 * g3d_vector_unify:
 * @nx: x component of vector
 * @ny: y component of vector
 * @nz: z component of vector
 *
 * Transforms the given vector to the unit vector.
 *
 * Returns: TRUE on success, FALSE else
 */
EAPI
gboolean g3d_vector_unify(G3DFloat *nx, G3DFloat *ny, G3DFloat *nz);

/**
 * g3d_vector_transform:
 * @x: x component of vector
 * @y: y component of vector
 * @z: z component of vector
 * @matrix: transformation matrix (4x4)
 *
 * Transforms the given vector corresponding to the given matrix
 *
 * Returns: TRUE on success, FALSE else
 */
EAPI
gboolean g3d_vector_transform(G3DFloat *x, G3DFloat *y, G3DFloat *z,
	G3DMatrix *matrix);

#ifdef __cplusplus
}
#endif /* ifdef __cplusplus */

#endif /* __G3D_VECTOR_H__ */