~ubuntu-branches/ubuntu/gutsy/rss-glx/gutsy

« back to all changes in this revision

Viewing changes to reallyslick/Implicit/impShape.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-11-30 18:21:27 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051130182127-5iww7elbiyzej1lk
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2001-2005  Terence M. Welsh
 
3
 *
 
4
 * This file is part of Implicit.
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 */
 
19
 
 
20
 
 
21
#include <Implicit/impShape.h>
 
22
 
 
23
 
 
24
 
 
25
impShape::impShape(){
 
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;
 
34
 
 
35
        thickness = 1.0f;
 
36
        thicknessSquared = thickness * thickness;
 
37
}
 
38
 
 
39
 
 
40
void impShape::setPosition(float x, float y, float z){
 
41
        mat[12] = x;
 
42
        mat[13] = y;
 
43
        mat[14] = z;
 
44
        invmat[12] = -x;
 
45
        invmat[13] = -y;
 
46
        invmat[14] = -z;
 
47
}
 
48
 
 
49
 
 
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];
 
57
}
 
58
 
 
59
 
 
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++)
 
64
                mat[i] = m[i];
 
65
        
 
66
        invertMatrix();
 
67
}
 
68
 
 
69
 
 
70
void impShape::invertMatrix(){
 
71
        float rmat[4][8];
 
72
        float a, b;
 
73
        int i, j, k;
 
74
 
 
75
        // inititialize reduction matrix
 
76
        rmat[0][0] = mat[0];
 
77
        rmat[1][0] = mat[1];
 
78
        rmat[2][0] = mat[2];
 
79
        rmat[3][0] = mat[3];
 
80
        rmat[0][1] = mat[4];
 
81
        rmat[1][1] = mat[5];
 
82
        rmat[2][1] = mat[6];
 
83
        rmat[3][1] = mat[7];
 
84
        rmat[0][2] = mat[8];
 
85
        rmat[1][2] = mat[9];
 
86
        rmat[2][2] = mat[10];
 
87
        rmat[3][2] = mat[11];
 
88
        rmat[0][3] = mat[12];
 
89
        rmat[1][3] = mat[13];
 
90
        rmat[2][3] = mat[14];
 
91
        rmat[3][3] = mat[15];
 
92
        rmat[0][4] = 1.0f;
 
93
        rmat[1][4] = 0.0f;
 
94
        rmat[2][4] = 0.0f;
 
95
        rmat[3][4] = 0.0f;
 
96
        rmat[0][5] = 0.0f;
 
97
        rmat[1][5] = 1.0f;
 
98
        rmat[2][5] = 0.0f;
 
99
        rmat[3][5] = 0.0f;
 
100
        rmat[0][6] = 0.0f;
 
101
        rmat[1][6] = 0.0f;
 
102
        rmat[2][6] = 1.0f;
 
103
        rmat[3][6] = 0.0f;
 
104
        rmat[0][7] = 0.0f;
 
105
        rmat[1][7] = 0.0f;
 
106
        rmat[2][7] = 0.0f;
 
107
        rmat[3][7] = 1.0f;
 
108
 
 
109
        // perform reductions
 
110
        for(i=0; i<4; i++){
 
111
                a = rmat[i][i];
 
112
                if(a == 0.0f)
 
113
                        return;  // matrix is singular, can't be inverted
 
114
                a = 1.0f / a;
 
115
                for(j=0; j<8; j++)
 
116
                        rmat[i][j] = rmat[i][j] * a;
 
117
                for(k=0; k<4; k++){
 
118
                        if((k-i) != 0){
 
119
                                b = rmat[k][i];
 
120
                                for(j=0; j<8; j++)
 
121
                                        rmat[k][j] = rmat[k][j] - b * rmat[i][j];
 
122
                        }
 
123
                }
 
124
        }
 
125
 
 
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];
 
143
}
 
144
 
 
145
 
 
146
float impShape::value(float* position){
 
147
        return(0.0f);
 
148
}
 
149
 
 
150
 
 
151
void impShape::center(float* position){
 
152
        position[0] = mat[12];
 
153
        position[1] = mat[13];
 
154
        position[2] = mat[14];
 
155
}
 
156
 
 
157
 
 
158
void impShape::addCrawlPoint(impCrawlPointVector &cpv){
 
159
        cpv.push_back(impCrawlPoint(&(mat[12])));
 
160
}