00001
00011 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00012 #ifndef __AUX_OBJECTS_H__
00013 #define __AUX_OBJECTS_H__
00014
00015 #include <Curve.h>
00016
00017
00018 void pointat_circle(float rad, float s, Vector3& p, Vector3& t) {
00019
00020 p = Vector3(rad*sin(2.*M_PI*s), rad*cos(2.*M_PI*s),0.);
00021 t = Vector3(cos(2.*M_PI*s),-sin(2.*M_PI*s),0.);
00022 t.normalize();
00023 }
00024
00025 Curve<Vector3>* gen_circle(float rad, int nodes) {
00026 Curve<Vector3>* circle = new Curve<Vector3>;
00027 Vector3 p,t;
00028 circle->header("Circle","libbiarc","","");
00029
00030 for (int i=0;i<nodes;i++) {
00031 pointat_circle(rad, (float)i/(float)nodes,p,t);
00032 circle->append(p,t);
00033 }
00034 circle->link();
00035 circle->make_default();
00036
00037 return circle;
00038 }
00039
00040
00041 void pointat_ellipse(float a, float b, float s, Vector3& p, Vector3& t) {
00042
00043 float omega = 2*M_PI;
00044 p = Vector3(a*cos(s*omega), b*sin(s*omega),0);
00045 t = Vector3(-a*sin(s*omega), b*cos(s*omega),0);
00046 t.normalize();
00047 }
00048
00049 Curve<Vector3>* gen_ellipse(float a, float b, int nodes) {
00050 Curve<Vector3>* ellipse = new Curve<Vector3>;
00051 Vector3 p,t;
00052 ellipse->header("Ellipse","libbiarc","","");
00053 for (int i=0;i<nodes;i++) {
00054 pointat_ellipse(a,b,(float)i/(float)nodes,p,t);
00055 ellipse->append(p,t);
00056 }
00057 ellipse->link();
00058 ellipse->make_default();
00059
00060 return ellipse;
00061 }
00062
00063
00064
00065
00066
00067
00068 void pointat_bone(float a, float b, float scale, float s,
00069 Vector3& p, Vector3& t) {
00070
00071 float omega = 2*M_PI;
00072 float ex0 = exp(-pow(s*omega*2.-3.*M_PI,2.));
00073 float ex0p = ex0*(12.*M_PI-8.*s*omega);
00074 float ex1 = exp(-pow(s*omega*2.-M_PI,2.));
00075 float ex1p = ex1*(4.*M_PI-8.*s*omega);
00076
00077 p = Vector3(a*cos(s*omega),
00078 b*sin(s*omega)+scale*(ex0-ex1),
00079 0.);
00080 t = Vector3(-a*sin(s*omega),
00081 b*cos(s*omega)+scale*(ex0p-ex1p),
00082 0.);
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 }
00094
00095 Curve<Vector3>* gen_bone(float a, float b, float scale, int nodes) {
00096 Curve<Vector3>* bone = new Curve<Vector3>;
00097 Vector3 p,t;
00098 bone->header("Bone shape","libbiarc","","");
00099 for (int i=0;i<nodes;i++) {
00100 pointat_bone(a,b,scale,(float)i/(float)nodes,p,t);
00101 bone->append(p,t);
00102 }
00103 bone->link();
00104 bone->computeTangents();
00105 return bone;
00106 }
00107
00108
00109 void pointat_inf(float a, float b, float scale, float s,
00110 Vector3& p, Vector3& t) {
00111
00112 float omega = 2*M_PI;
00113 float ex0 = exp(-pow(s*omega*2.-3.*M_PI,2.));
00114 float ex0p = ex0*(12.*M_PI-8.*s*omega);
00115 float ex1 = exp(-pow(s*omega*2.-M_PI,2.));
00116 float ex1p = ex1*(4.*M_PI-8.*s*omega);
00117
00118 p = Vector3(a*cos(s*omega),b*sin(2.*s*omega),scale*(ex0-ex1));
00119 t = Vector3(-a*sin(s*omega),2.*b*cos(2.*s*omega),scale*(ex0p-ex1p));
00120 t.normalize();
00121 }
00122
00123 Curve<Vector3>* gen_inf(float a, float b, float scale, int nodes) {
00124 Curve<Vector3>* inf = new Curve<Vector3>;
00125 Vector3 p,t;
00126 inf->header("Infinity","libbiarc","","");
00127 for (int i=0;i<nodes;i++) {
00128 pointat_inf(a,b,scale,(float)i/(float)nodes,p,t);
00129 inf->append(p,t);
00130 }
00131 return inf;
00132 }
00133
00134
00135 void pointat_stadium(float rad, float l, float s, Vector3& p, Vector3& t) {
00136
00137 float ss = s*(2.*M_PI*rad+2.*l);
00138 if (ss>=0. && ss<l) {
00139 p = Vector3(l/2.,rad,0.)+Vector3(-1,0,0)*ss;
00140 t = Vector3(-1,0,0);
00141 }
00142 else if (ss>=l && ss<(l+M_PI*rad)) {
00143 p = -Vector3(l/2.,0,0)+Vector3(-rad*sin(ss-l),
00144 rad*cos(ss-l),0.);
00145 t = Vector3(-cos(ss-l),-sin(ss-l),0.);
00146 }
00147 else if (ss>=(l+M_PI*rad) && ss<(2.*l+M_PI*rad)) {
00148 p = Vector3(-l/2.,-rad,0.)+Vector3(1,0,0)*(ss-l-M_PI*rad);
00149 t = Vector3(1,0,0);
00150 }
00151 else {
00152 p = Vector3(l/2.,0,0)+Vector3(-rad*sin(ss-2.*l),
00153 rad*cos(ss-2.*l),0.);
00154 t = Vector3(-cos(ss-2.*l),-sin(ss-2.*l),0.);
00155 }
00156 t.normalize();
00157 }
00158
00159 Curve<Vector3>* gen_stadium(float rad, float l, int nodes) {
00160 Curve<Vector3>* stadium = new Curve<Vector3>;
00161 Vector3 p,t;
00162 stadium->header("Stadiumcurve","libbiarc","","");
00163
00164 for (int i=0;i<nodes;i++) {
00165 pointat_stadium(rad, l, (float)i/(float)nodes,p,t);
00166 stadium->append(p,t);
00167 }
00168 return stadium;
00169 }
00170
00171 #endif // __AUX_OBJECTS_H__
00172 #endif // DOXYGEN_SHOULD_SKIP_THIS