~ubuntu-branches/debian/sid/3depict/sid

« back to all changes in this revision

Viewing changes to src/quat.h

  • Committer: Bazaar Package Importer
  • Author(s): D Haley
  • Date: 2010-08-09 21:23:50 UTC
  • Revision ID: james.westby@ubuntu.com-20100809212350-cg6yumndhwi3bqws
Tags: upstream-0.0.1
ImportĀ upstreamĀ versionĀ 0.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      Quat.h - quaternion rotation and mathematics header.
 
3
 *      Copyright (C) 2010 D Haley
 
4
 *      THanks to R. Minehan for mathematical discussions.
 
5
 *
 
6
 *      This program is free software: you can redistribute it and/or modify
 
7
 *      it under the terms of the GNU General Public License as published by
 
8
 *      the Free Software Foundation, either version 3 of the License, or
 
9
 *      (at your option) any later version.
 
10
 
 
11
 *      This program is distributed in the hope that it will be useful,
 
12
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *      GNU General Public License for more details.
 
15
 
 
16
 *      You should have received a copy of the GNU General Public License
 
17
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
 
 
21
#ifndef QUAT_H
 
22
#define QUAT_H
 
23
 
 
24
//needed for sin and cos
 
25
#include <math.h>
 
26
 
 
27
typedef struct 
 
28
{
 
29
        float a;
 
30
        float b;
 
31
        float c;
 
32
        float d;
 
33
} Quaternion;
 
34
 
 
35
typedef struct
 
36
{
 
37
        float fx;
 
38
        float fy;
 
39
        float fz;
 
40
} Point3f;
 
41
 
 
42
//conjugates the argument
 
43
#ifdef __cplusplus
 
44
extern "C" {
 
45
#endif
 
46
 
 
47
void quat_conj(Quaternion *quat);
 
48
//calculates the square length of the quaternion
 
49
float quat_sqrlen(Quaternion *quat);
 
50
//multiplies two quaternions result=q1*q2
 
51
void quat_mult(Quaternion *result, Quaternion *q1, Quaternion *q2);
 
52
 
 
53
//this is a little optimisation that doesnt calculate the a component for
 
54
//the returned quaternion. Note that the result is specific to quaternion rotation 
 
55
void quat_pointmult(Point3f *result, Quaternion *q1, Quaternion *q2);
 
56
 
 
57
//Uses quaternion mathematics to perform a rotation around your favourite axis
 
58
//IMPORTANT: rotVec must be normalised before passing to this function 
 
59
//failure to do so will have wierd results
 
60
//Note result is stored in  point passsed as argument
 
61
void quat_rot(Point3f *point, Point3f *rotVec, float angle);
 
62
 
 
63
//Retrieve the two quaternions for repeated rotations. pass to the quat_rot_apply_quats
 
64
void quat_get_rot_quats(Point3f *rotVec, float angle, 
 
65
                Quaternion *rotQuat, Quaternion *conjQuat);
 
66
 
 
67
//Use previously generated quats from quat_get_rot_quats to rotate a point
 
68
void quat_rot_apply_quats(Point3f *point, Quaternion *rotQuat, Quaternion *conjQuat);
 
69
 
 
70
//this performs an optimised rotation of a point around 3 angles
 
71
//pitch, then yaw and then roll. Pitch is defined to be rotation around x
 
72
//yaw around z and roll around y. x is right, y is forwards, z is up
 
73
//The results are derived by special case quaternion rotation around basis vectors
 
74
void quat_rot_pitchyawroll(Point3f *point, float pitchAngle,float yawAngle, float rollAngle);
 
75
 
 
76
//As for the above but in reverse order. This allows you to undo the above transform by simply
 
77
//passing through the negative roll yaw and pitch angles
 
78
void quat_rot_rollyawpitch(Point3f *point, float rollAngle,float yawAngle,float pitchAngle);
 
79
 
 
80
#ifdef __cplusplus
 
81
}
 
82
#endif
 
83
//TODO: determine if we need an array version of the quat_rot_pyr/ryp funcs
 
84
#endif