1 /* 2 * Copyright (C) 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 #ifndef IMPKNOT_H 22 #define IMPKNOT_H 23 24 25 26 #include "impShape.h" 27 28 29 30 class impKnot : public impShape{ 31 private: 32 float radius1; 33 float radius2; 34 int coils, twists; // integer number of coils and twists, respectively 35 float coilsf, twistsf; // floating point versions of n and m 36 float twistsOverCoils, lat_offset; // precomputed variables 37 38 public: impKnot()39 impKnot(){ 40 radius1 = 1.0f; radius2 = 0.5f; thickness = 0.1f; 41 coils = 3; coilsf = float(coils); twists = 2; twistsf = float(twists); 42 thicknessSquared = thickness * thickness; 43 twistsOverCoils = twistsf / coilsf; 44 lat_offset = 6.28318530718f / coilsf; 45 } ~impKnot()46 ~impKnot(){} 47 // position is an array of 3 floats 48 // returns the field strenth of this sphere at a given position setRadius1(float r)49 void setRadius1(float r){radius1 = r;} getRadius1()50 float getRadius1(){return radius1;} setRadius2(float r)51 void setRadius2(float r){radius2 = r;} getRadius2()52 float getRadius2(){return radius2;} setNumCoils(int c)53 void setNumCoils(int c){ 54 coils = (c<1 ? 1 : c); // coils must be greater than 1 55 coilsf = float(coils); 56 twistsOverCoils = twistsf / coilsf; 57 lat_offset = 6.28318530718f / coilsf; 58 } getNumCoils()59 int getNumCoils(){return coils;} setNumTwists(int t)60 void setNumTwists(int t){ 61 twists = t; 62 twistsf = float(twists); 63 twistsOverCoils = twistsf / coilsf; 64 } getNumTwists()65 int getNumTwists(){return twists;} 66 virtual float value(float* position); 67 virtual void center(float* position); 68 virtual void addCrawlPoint(impCrawlPointVector &cpv); 69 }; 70 71 72 73 #endif 74