aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/libg3d-0.0.8/include/g3d/quat.h
blob: 2d68907e569c747e59c41757bd739bfd5ad36d99 (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
/* $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_QUAT_H
#define _G3D_QUAT_H

#include <g3d/types.h>

/**
 * SECTION:quat
 * @short_description: quaternion helpers
 * @include: g3d/quat.h
 */

/**
 * g3d_quat_normalize:
 * @q: a quaternion
 *
 * normalize the quaternion to a length of 1.0.
 *
 * Returns: TRUE on success, FALSE else
 */
EAPI
gboolean g3d_quat_normalize(G3DQuat *q);

/**
 * g3d_quat_rotate:
 * @q: resulting quat
 * @axis: rotation axis
 * @angle: rotation angle
 *
 * Encode a rotation around an axis into quaternion.
 *
 * Returns: TRUE on success, FALSE else
 */
EAPI
gboolean g3d_quat_rotate(G3DQuat *q, G3DVector *axis, G3DFloat angle);

/**
 * g3d_quat_add:
 * @qr: result quat
 * @q1: first quat
 * @q2: second quat
 *
 * Add two quats.
 *
 * Returns: TRUE on success, FALSE else
 */
EAPI
gboolean g3d_quat_add(G3DQuat *qr, G3DQuat *q1, G3DQuat *q2);

/**
 * g3d_quat_trackball:
 * @q: resulting quaternion
 * @x1: x value of first point
 * @y1: y value of first point
 * @x2: x value of second point
 * @y2: y value of second point
 * @r: radius of virtual trackball, usually 0.8
 *
 * Emulate a virtual trackball movement and return rotation as quaternion.
 * The x and y values of the starting and end point of the movement have
 * to be in the range -1.0 .. 1.0.
 *
 * Returns: TRUE on success, FALSE else
 */
EAPI
gboolean g3d_quat_trackball(G3DQuat *q, G3DFloat x1, G3DFloat y1,
	G3DFloat x2, G3DFloat y2, G3DFloat r);

/**
 * g3d_quat_to_matrix:
 * @q: source quat
 * @matrix: resulting matrix
 *
 * Convert a quaternion to a transformation matrix.
 *
 * Returns: TRUE on success, FALSE else
 */
EAPI
gboolean g3d_quat_to_matrix(G3DQuat *q, G3DMatrix *matrix);

/**
 * g3d_quat_to_rotation_xyz:
 * @q: a quaternion
 * @rx: rotation around x axis
 * @ry: rotation around y axis
 * @rz: rotation around z axis
 *
 * Calculate the rotation around the three coordinate axes from a given
 * quaternion.
 *
 * Returns: TRUE on success, FALSE else
 */
EAPI
gboolean g3d_quat_to_rotation_xyz(G3DQuat *q, G3DFloat *rx, G3DFloat *ry,
	G3DFloat *rz);

#endif /* _G3D_QUAT_H */