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/impTorus.h>
25
float impTorus::value(float* position){
26
const float tx(position[0] * invmat[0]
27
+ position[1] * invmat[4]
28
+ position[2] * invmat[8]
30
const float ty(position[0] * invmat[1]
31
+ position[1] * invmat[5]
32
+ position[2] * invmat[9]
34
const float tz(position[0] * invmat[2]
35
+ position[1] * invmat[6]
36
+ position[2] * invmat[10]
39
const float temp(sqrtf(tx*tx + ty*ty) - radius);
40
return(thicknessSquared / (temp*temp + tz*tz));
44
// Finding a point inside a torus is trickier than
45
// finding a point inside a sphere or ellipsoid.
46
void impTorus::center(float* position){
47
position[0] = mat[0] * radius + mat[12];
48
position[1] = mat[1] * radius + mat[13];
49
position[2] = mat[2] * radius + mat[14];
53
void impTorus::addCrawlPoint(impCrawlPointVector &cpv){
54
cpv.push_back(impCrawlPoint(mat[0] * radius + mat[12],
55
mat[1] * radius + mat[13],
56
mat[2] * radius + mat[14]));