Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Membres des namespaces | Composants | Déclarations

# ExCGizmoLineBezier.cpp

Aller à la documentation de ce fichier.

    00001 /*
    00002  * ExNihilo 3D Engine
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  *
    00018  * Please read AUTHORS file !!!
    00019  *
    00020  * $Id: ExCGizmoLineBezier.cpp,v 1.5 2002/08/14 15:20:54 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExCGizmoLineBezier.h"
    00025
    00026 ExCGizmoLineBezier::ExCGizmoLineBezier(void)
    00027 {
    00028         SetName("ExCGizmoLineBezier");
    00029         SetType(typeid(this).name());
    00030         m_OriginePoint.SetValue(0.0f,0.0f,100.0f);
    00031         m_ControlPoint1.SetValue(0.0f,100.0f,100.0f);
    00032         m_ControlPoint2.SetValue(0.0f,200.0f,500.0f);
    00033         m_EndPoint.SetValue(200.0f,300.0f,500.0f);
    00034         m_Color.SetValue(0.5,1,0.5);
    00035 }
    00036
    00037 ExCGizmoLineBezier::ExCGizmoLineBezier(ExCVec3D Origine,ExCVec3D Ctrl1,ExCVec3D Ctrl2,ExCVec3D End)
    00038 {
    00039         SetName("ExCGizmoLineBezier");
    00040         SetType(typeid(this).name());
    00041
    00042 }
    00043
    00044 ExCGizmoLineBezier::~ExCGizmoLineBezier(void)
    00045 {
    00046 }
    00047
    00048 ExCVec3D ExCGizmoLineBezier::PointOnCurve(float t)
    00049 {
    00050         ExCVec3D vPoint;
    00051 /*
    00052
    00053         double plouf=pow((1-t),3);
    00054         //double plouf=pow((1-t),3);
    00055         vPoint.m_Vector[0]=m_OriginePoint.GetX()*plouf;//pow(t,0)*pow((1-t),m_VectorPoint.size()-1);
    00056         vPoint.m_Vector[1]=m_OriginePoint.GetY()*plouf;//pow(t,0)*pow((1-t),m_VectorPoint.size()-1);
    00057         vPoint.m_Vector[2]=m_OriginePoint.GetZ()*plouf;//pow(t,0)*pow((1-t),m_VectorPoint.size()-1);
    00058
    00059         //for(i=1,j=m_VectorPoint.size()-2;i<m_VectorPoint.size()-1;i++,j--)
    00060
    00061         plouf=pow(t,1)*pow((1-t),2)*4;
    00062         vPoint.m_Vector[0]+=m_ControlPoint1.GetX()*plouf;//pow(t,i)*pow((1-t),j)*3;
    00063         vPoint.m_Vector[1]+=m_ControlPoint1.GetY()*plouf;//pow(t,i)*pow((1-t),j)*3;
    00064         vPoint.m_Vector[2]+=m_ControlPoint1.GetZ()*plouf;//pow(t,i)*pow((1-t),j)*3;
    00065
    00066         plouf=pow(t,2)*pow((1-t),1)*4;
    00067         vPoint.m_Vector[0]+=m_ControlPoint2.GetX()*plouf;//pow(t,i)*pow((1-t),j)*3;
    00068         vPoint.m_Vector[1]+=m_ControlPoint2.GetY()*plouf;//pow(t,i)*pow((1-t),j)*3;
    00069         vPoint.m_Vector[2]+=m_ControlPoint2.GetZ()*plouf;//pow(t,i)*pow((1-t),j)*3;
    00070
    00071         vPoint.m_Vector[0]+=m_EndPoint.GetX()*pow(t,3);//*pow((1-t),j);
    00072         vPoint.m_Vector[1]+=m_EndPoint.GetY()*pow(t,3);//*pow((1-t),j);
    00073         vPoint.m_Vector[2]+=m_EndPoint.GetZ()*pow(t,3);//*pow((1-t),j);
    00074 */
    00075
    00076         float var1, var2, var3;
    00077
    00078
    00079         var1 = 1 - t;
    00080
    00081
    00082         var2 = var1 * var1 * var1;
    00083
    00084
    00085         var3 = t * t * t;
    00086
    00087         vPoint.m_Vector[0] = var2*m_OriginePoint.GetX() + 3*t*var1*var1*m_ControlPoint1.GetX() + 3*t*t*var1*m_ControlPoint2.GetX() + var3*m_EndPoint.GetX();
    00088         vPoint.m_Vector[1]= var2*m_OriginePoint.GetY() + 3*t*var1*var1*m_ControlPoint1.GetY() + 3*t*t*var1*m_ControlPoint2.GetY() + var3*m_EndPoint.GetY();
    00089         vPoint.m_Vector[2]= var2*m_OriginePoint.GetZ() + 3*t*var1*var1*m_ControlPoint1.GetZ() + 3*t*t*var1*m_ControlPoint2.GetZ() + var3*m_EndPoint.GetZ();
    00090
    00091
    00092         return vPoint;
    00093 }
    00094
    00095 void ExCGizmoLineBezier::Draw()
    00096 {
    00097         if (m_Visible)
    00098         {
    00099                 DrawLine();
    00100                 DrawControlPoint();
    00101         }
    00102
    00103 }
    00104
    00105 void ExCGizmoLineBezier::DrawLine()
    00106 {
    00107         int plouf;
    00108         plouf=100;
    00109         glColor3fv(m_Color.m_Vector);
    00110         glBegin(GL_LINE_STRIP);
    00111                 for(float t = 0; t <= (1 + (1.0f / plouf)); t += 1.0f / plouf)
    00112                 {
    00113                 //vPoint= PointOnCurve(t);
    00114                         glVertex3fv(PointOnCurve(t).m_Vector);
    00115                 }
    00116         glEnd();
    00117 }
    00118
    00119 void ExCGizmoLineBezier::DrawControlPoint()
    00120 {
    00121         glColor3f(1,1,1);
    00122
    00123         glPushMatrix();
    00124                 glTranslatef(m_OriginePoint.GetX(),m_OriginePoint.GetY(),m_OriginePoint.GetZ());
    00125                 glutWireSphere(0.5,4,4);
    00126         glPopMatrix();
    00127
    00128         glPushMatrix();
    00129                 glTranslatef(m_ControlPoint1.GetX(),m_ControlPoint1.GetY(),m_ControlPoint1.GetZ());
    00130                 glutWireSphere(0.5,4,4);
    00131         glPopMatrix();
    00132
    00133         glPushMatrix();
    00134                 glTranslatef(m_ControlPoint2.GetX(),m_ControlPoint2.GetY(),m_ControlPoint2.GetZ());
    00135                 glutWireSphere(0.5,4,4);
    00136         glPopMatrix();
    00137
    00138         glPushMatrix();
    00139                 glTranslatef(m_EndPoint.GetX(),m_EndPoint.GetY(),m_EndPoint.GetZ());
    00140                 glutWireSphere(0.5,4,4);
    00141         glPopMatrix();
    00142 }
    00143
    00144 bool ExCGizmoLineBezier::LoadFile(std::string FileName)
    00145 {
    00146 Guard(bool ExCGizmoLineBezier::LoadFile(std::string FileName))
    00147         SetFileName(FileName);
    00148         //std::cout<<"Loading ExCGizmoLineBezier"<<std::endl;
    00149
    00150         char                    buffer[255];
    00151         sprintf(buffer, "../Data/Gizmo/%s", FileName.data());
    00152         std::ifstream fin;
    00153         std::string buffstring;
    00154         char b[256];
    00155         fin.open(buffer,std::ios::in);
    00156         if(fin.is_open())
    00157         {
    00158                 try
    00159                 {
    00160
    00161                 //----Read Type
    00162                 memset(b,0,255);fin.getline(b,256,'\n');
    00163
    00164                 //Control point 1
    00165                 memset(b,0,255);fin.getline(b,256,'\n');
    00166                 buffstring=ExNihilo::ExtracValueFromSring(b,"<CtrlPoint0>","<#CtrlPoint0>");
    00167                 m_OriginePoint.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00168                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00169                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00170
    00171                 //Control point 1
    00172                 memset(b,0,255);fin.getline(b,256,'\n');
    00173                 buffstring=ExNihilo::ExtracValueFromSring(b,"<CtrlPoint1>","<#CtrlPoint1>");
    00174                 m_ControlPoint1.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00175                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00176                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00177
    00178                 //Control point 1
    00179                 memset(b,0,255);fin.getline(b,256,'\n');
    00180                 buffstring=ExNihilo::ExtracValueFromSring(b,"<CtrlPoint2>","<#CtrlPoint2>");
    00181                 m_ControlPoint2.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00182                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00183                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00184
    00185                 //Control point 1
    00186                 memset(b,0,255);fin.getline(b,256,'\n');
    00187                 buffstring=ExNihilo::ExtracValueFromSring(b,"<CtrlPoint3>","<#CtrlPoint3>");
    00188                 m_EndPoint.SetValue(ExNihilo::ExtractFloatValueFromSring(buffstring,"<X>","<#X>"),
    00189                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Y>","<#Y>"),
    00190                         ExNihilo::ExtractFloatValueFromSring(buffstring,"<Z>","<#Z>"));
    00191                 fin.close();
    00192
    00193
    00194                 }catch(...){throw ExCExpFileReadError();}
    00195         }else throw   ExCExpFileNotFound();
    00196         return true;
    00197 UnGuard
    00198 }