SuperShape.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 #ifndef __SUPERSHAPE_H__
00030 #define __SUPERSHAPE_H__
00031 
00032 #include "X3DGeometryNode.h"
00033 #include "SFFloat.h"
00034 #include "SFInt32.h"
00035 
00037 namespace H3D {
00038 
00042   class H3DAPI_API SuperShape : public X3DGeometryNode {
00043   public:
00044     
00045     SuperShape( Inst< SFNode   >  _metadata = 0,
00046                 Inst< SFFloat  > _ss1_m  = 0,
00047                 Inst< SFFloat  > _ss1_a  = 0,
00048                 Inst< SFFloat  > _ss1_b  = 0,
00049                 Inst< SFFloat  > _ss1_n1 = 0,
00050                 Inst< SFFloat  > _ss1_n2 = 0,
00051                 Inst< SFFloat  > _ss1_n3 = 0,
00052                 Inst< SFFloat  > _ss2_m  = 0,
00053                 Inst< SFFloat  > _ss2_a  = 0,
00054                 Inst< SFFloat  > _ss2_b  = 0,
00055                 Inst< SFFloat  > _ss2_n1 = 0,
00056                 Inst< SFFloat  > _ss2_n2 = 0,
00057                 Inst< SFFloat  > _ss2_n3 = 0,
00058                 Inst< SFInt32  > _resolution = 0 );
00059 
00060     virtual void render();
00061 
00062     float R( float phi, float m, float a, float b, 
00063              float n1, float n2, float n3 ) {
00064       float t2 = m*phi/4.0f;
00065       float t3 = cosf(t2);
00066       float t6 = fabsf(t3/a);
00067       float t7 = powf(t6,n2);
00068       float t8 = sinf(t2);
00069       float t11 = fabsf(t8/b);
00070       float t12 = powf(t11,n3);
00071       float t14 = powf(t7+t12,-1/n1);
00072       return t14;
00073       //return powf(powf(fabsf(cosf((alpha*m)/4.)/a), n2) 
00074       //            + powf(fabsf(sinf((alpha*m)/4.)/b),n3), -1/n1);
00075     }
00076   
00077     Vec3f SS( float theta, float phi, 
00078               float sm, float sa, float sb, float sn1, float sn2, float sn3,
00079               float tm, float ta, float tb, float tn1, float tn2, float tn3 ) { 
00080       float r1theta = R( theta, sm, sa, sb, sn1, sn2, sn3 );
00081       float r2phi = R( phi, tm, ta, tb, tn1, tn2, tn3 );
00082     
00083       float x = r1theta * cosf(theta) * r2phi * cosf(phi);
00084       float y = r1theta * sin(theta) * r2phi * cosf(phi);
00085       float z = r2phi * sin(phi);
00086 
00087       return Vec3f( x, y, z);
00088     }
00089 
00090     Vec3f SSd( float theta, float phi, 
00091               float sm, float sa, float sb, float sn1, float sn2, float sn3,
00092               float tm, float ta, float tb, float tn1, float tn2, float tn3 ) { 
00093       float r1theta = R( theta, sm, sa, sb, sn1, sn2, sn3 );
00094       float r2phi = R( phi, tm, ta, tb, tn1, tn2, tn3 );
00095     
00096       float dx1 = cosf(theta)-r1theta*sinf(theta);
00097       float dy1 = sinf(theta)+r1theta*cosf(theta);
00098 
00099       float dy2 = cosf(phi)-r2phi*sinf(phi);
00100       float dz2 = sinf(phi)+r2phi*cosf(phi);
00101       //float z = r2phi * sin(phi);
00102 
00103       return Vec3f( dx1, dy1*dy2, dz2);
00104     }
00105 
00106     float SSdz( float theta, float phi, float m, float a, float b, 
00107                 float n1, float n2, float n3 ) {
00108       return (4*n1*cosf(phi)*(powf(cosf((m*phi)/4.f)/a, n2) 
00109                               + powf(sinf((m*phi)/4.f)/b, n3)) 
00110               + m*sinf(phi)*(-(n3*(1/tanf((m*phi)/4.f))
00111                                *powf(sinf((m*phi)/4.f)/b, n3)) 
00112                              + n2*powf(cosf((m*phi)/4.f)/a, n2)
00113                              *tanf((m*phi)/4.f)))
00114         /(4.f*n1*powf(powf(cosf((m*phi)/4.f)/a, n2) 
00115                      + powf(sinf((m*phi)/4.f)/b, n3), (1 + n1)/n1));
00116     }
00117 
00118 #ifdef USE_HAPTICS
00121     virtual void traverseSG( TraverseInfo &ti );  
00122 #endif
00123     
00124     // Fields
00125     auto_ptr< SFFloat  > ss1_m;
00126     auto_ptr< SFFloat  > ss1_a;
00127     auto_ptr< SFFloat  > ss1_b;
00128     auto_ptr< SFFloat  > ss1_n1;
00129     auto_ptr< SFFloat  > ss1_n2;
00130     auto_ptr< SFFloat  > ss1_n3;
00131 
00132     auto_ptr< SFFloat  > ss2_m;
00133     auto_ptr< SFFloat  > ss2_a;
00134     auto_ptr< SFFloat  > ss2_b;
00135     auto_ptr< SFFloat  > ss2_n1;
00136     auto_ptr< SFFloat  > ss2_n2;
00137     auto_ptr< SFFloat  > ss2_n3;
00138 
00139     auto_ptr< SFInt32  > resolution;
00140 
00141     static H3DNodeDatabase database;
00142   };
00143 }
00144 
00145 #endif

Generated on Thu Aug 24 12:38:34 2006 for H3D API by  doxygen 1.4.5