2
* Copyright (C) 2001-2005 Terence M. Welsh
4
* This file is part of Implicit.
6
* Implicit is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License version 2.1 as published by the Free Software Foundation.
10
* Implicit is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include <Implicit/impShape.h>
26
mat[0] = mat[5] = mat[10] = mat[15]
27
= invmat[0] = invmat[5] = invmat[10] = invmat[15] = 1.0f;
28
mat[1] = mat[2] = mat[3] = mat[4]
29
= mat[6] = mat[7] = mat[8] = mat[9]
30
= mat[11] = mat[12] = mat[13] = mat[14]
31
= invmat[1] = invmat[2] = invmat[3] = invmat[4]
32
= invmat[6] = invmat[7] = invmat[8] = invmat[9]
33
= invmat[11] = invmat[12] = invmat[13] = invmat[14] = 0.0f;
36
thicknessSquared = thickness * thickness;
40
void impShape::setPosition(float x, float y, float z){
50
void impShape::setPosition(float* position){
51
mat[12] = position[0];
52
mat[13] = position[1];
53
mat[14] = position[2];
54
invmat[12] = -position[0];
55
invmat[13] = -position[1];
56
invmat[14] = -position[2];
60
// Don't need to set this for simple spheres.
61
// A whole matrix is only necessary for weird asymmetric objects.
62
void impShape::setMatrix(float* m){
63
for(int i=0; i<16; i++)
70
void impShape::invertMatrix(){
75
// inititialize reduction matrix
109
// perform reductions
113
return; // matrix is singular, can't be inverted
116
rmat[i][j] = rmat[i][j] * a;
121
rmat[k][j] = rmat[k][j] - b * rmat[i][j];
126
// extract inverted matrix
127
invmat[0] = rmat[0][4];
128
invmat[1] = rmat[1][4];
129
invmat[2] = rmat[2][4];
130
invmat[3] = rmat[3][4];
131
invmat[4] = rmat[0][5];
132
invmat[5] = rmat[1][5];
133
invmat[6] = rmat[2][5];
134
invmat[7] = rmat[3][5];
135
invmat[8] = rmat[0][6];
136
invmat[9] = rmat[1][6];
137
invmat[10] = rmat[2][6];
138
invmat[11] = rmat[3][6];
139
invmat[12] = rmat[0][7];
140
invmat[13] = rmat[1][7];
141
invmat[14] = rmat[2][7];
142
invmat[15] = rmat[3][7];
146
float impShape::value(float* position){
151
void impShape::center(float* position){
152
position[0] = mat[12];
153
position[1] = mat[13];
154
position[2] = mat[14];
158
void impShape::addCrawlPoint(impCrawlPointVector &cpv){
159
cpv.push_back(impCrawlPoint(&(mat[12])));