3 * Some vector operations.
6 * - vector with x components : float x[3], int x[3], etc
10 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version. The Blender
16 * Foundation also sells licenses for use in proprietary software under
17 * the Blender License. See http://www.blender.org/BL/ for information
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software Foundation,
27 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
30 * All rights reserved.
32 * The Original Code is: all of this file.
34 * Contributor(s): none yet.
36 * ***** END GPL/BL DUAL LICENSE BLOCK *****
39 /* ------------------------------------------------------------------------- */
40 /* General format: op(a, b, c): a = b op c */
41 /* Copying is done cp <from, to> */
42 /* ------------------------------------------------------------------------- */
44 #include "MTC_vectorops.h"
51 void MTC_diff3Int(int v1[3], int v2[3], int v3[3])
53 v1[0] = v2[0] - v3[0];
54 v1[1] = v2[1] - v3[1];
55 v1[2] = v2[2] - v3[2];
58 /* ------------------------------------------------------------------------- */
59 void MTC_diff3Float(float v1[3], float v2[3], float v3[3])
61 v1[0] = v2[0] - v3[0];
62 v1[1] = v2[1] - v3[1];
63 v1[2] = v2[2] - v3[2];
66 /* ------------------------------------------------------------------------- */
68 void MTC_cross3Int(int v1[3], int v2[3], int v3[3])
70 v1[0] = v2[1]*v3[2] - v2[2]*v3[1];
71 v1[1] = v2[2]*v3[0] - v2[0]*v3[2];
72 v1[2] = v2[0]*v3[1] - v2[1]*v3[0];
75 /* ------------------------------------------------------------------------- */
77 void MTC_cross3Float(float v1[3], float v2[3], float v3[3])
79 v1[0] = v2[1]*v3[2] - v2[2]*v3[1];
80 v1[1] = v2[2]*v3[0] - v2[0]*v3[2];
81 v1[2] = v2[0]*v3[1] - v2[1]*v3[0];
83 /* ------------------------------------------------------------------------- */
85 void MTC_cross3Double(double v1[3], double v2[3], double v3[3])
87 v1[0] = v2[1]*v3[2] - v2[2]*v3[1];
88 v1[1] = v2[2]*v3[0] - v2[0]*v3[2];
89 v1[2] = v2[0]*v3[1] - v2[1]*v3[0];
92 /* ------------------------------------------------------------------------- */
94 int MTC_dot3Int(int v1[3], int v2[3])
96 return (v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]);
99 /* ------------------------------------------------------------------------- */
101 float MTC_dot3Float(float v1[3], float v2[3])
103 return (v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]);
106 /* ------------------------------------------------------------------------- */
108 void MTC_cp3Float(float v1[3], float v2[3])
115 /* ------------------------------------------------------------------------- */
117 void MTC_cp3FloatInv(float v1[3], float v2[3])
124 /* ------------------------------------------------------------------------- */
126 void MTC_swapInt(int *i1, int *i2)
134 /* ------------------------------------------------------------------------- */
136 void MTC_diff3DFF(double v1[3], float v2[3], float v3[3])
138 v1[0] = v2[0] - v3[0];
139 v1[1] = v2[1] - v3[1];
140 v1[2] = v2[2] - v3[2];
143 /* ------------------------------------------------------------------------- */
144 float MTC_normalise3DF(float n[3])
148 d= n[0]*n[0]+n[1]*n[1]+n[2]*n[2];
149 /* FLT_EPSILON is too large! A larger value causes normalise errors in */
150 /* a scaled down utah teapot */
151 if(d>0.0000000000001) {
153 /* d= sqrt(d); This _should_ be sqrt, but internally it's a double*/
154 /* anyway. This is safe. */
167 /* ------------------------------------------------------------------------- */