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

« back to all changes in this revision

Viewing changes to reallyslick/Implicit/impTorus.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/impTorus.h>
 
22
 
 
23
 
 
24
 
 
25
float impTorus::value(float* position){
 
26
        const float tx(position[0] * invmat[0]
 
27
                + position[1] * invmat[4]
 
28
                + position[2] * invmat[8]
 
29
                + invmat[12]);
 
30
        const float ty(position[0] * invmat[1]
 
31
                + position[1] * invmat[5]
 
32
                + position[2] * invmat[9]
 
33
                + invmat[13]);
 
34
        const float tz(position[0] * invmat[2]
 
35
                + position[1] * invmat[6]
 
36
                + position[2] * invmat[10]
 
37
                + invmat[14]);
 
38
 
 
39
        const float temp(sqrtf(tx*tx + ty*ty) - radius);
 
40
        return(thicknessSquared / (temp*temp + tz*tz));
 
41
}
 
42
 
 
43
 
 
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];
 
50
}
 
51
 
 
52
 
 
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]));
 
57
}