12,501,337 members (38,606 online)

189.3K views
114 bookmarked
Posted

# Basic Curves And Surfaces Modeler

, 18 Apr 2012 CPOL
A basic demo of modeling curves and surfaces in OpenGL.
 ```// Matrix33.cpp: implementation of the CMatrix33 class. // ////////////////////////////////////////////////////////////////////// #if HAVE_CONFIG_H # include #endif #include "stdafx.h" #include "Matrix33.h" #include "Point3D.h" #include "Vector3D.h" #include "GeomException.h" #include "MMath.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// //Implementation of CMatrix33 class CMatrix33::CMatrix33() { int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { Row[i][j]=0; } } } CMatrix33::CMatrix33(double R1[3], double R2[3], double R3[3]) { int i; for(i=0;i<3;i++) { Row[0][i]=R1[i]; } for(i=0;i<3;i++) { Row[1][i]=R2[i]; } for(i=0;i<3;i++) { Row[2][i]=R3[i]; } } CMatrix33::~CMatrix33() { } CMatrix33 CMatrix33::operator*(const CMatrix33 &Other) { int i,j,k; CMatrix33 New; double temp[3][3]; for(i=0;i<3;i++) { for(j=0;j<3;j++) { temp[i][j]=0; } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { for(k=0;k<3;k++) { temp[i][j]=temp[i][j]+Row[i][k]*Other.Row[k][j]; } } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { New.Row[i][j]=temp[i][j]; } } return New; } CVector3D CMatrix33::operator*(const CVector3D &Other) { CVector3D O = Other; CVector3D Result; Result.SetX(this->Row[0][0]*O.GetX() + this->Row[0][1]*O.GetY() + this->Row[0][2]*O.GetZ()); Result.SetY(this->Row[1][0]*O.GetX() + this->Row[1][1]*O.GetY() + this->Row[1][2]*O.GetZ()); Result.SetZ(this->Row[2][0]*O.GetX() + this->Row[2][1]*O.GetY() + this->Row[2][2]*O.GetZ()); return Result; } CMatrix33 CMatrix33::operator*(double value) { CMatrix33 New; int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { New.Row[i][j]=Row[i][j]; } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { New.Row[i][j]*=value; } } return New; } void CMatrix33::operator*=(const CMatrix33 &Other) { int i,j,k; double temp[3][3]; for(i=0;i<3;i++) { for(j=0;j<3;j++) { temp[i][j]=0; } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { for(k=0;k<3;k++) { temp[i][j]=temp[i][j]+Row[i][k]*Other.Row[k][j]; } } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { Row[i][j]=temp[i][j]; } } } void CMatrix33::operator*=(double value) { int i, j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { Row[i][j]*=value; } } } CMatrix33 CMatrix33::operator/(const double Value) { CMatrix33 New; int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { New.Row[i][j]=Row[i][j]; } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { New.Row[i][j]/=Value; } } return New; } void CMatrix33::operator/=(const double Value) { int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { Row[i][j]/=Value; } } } CMatrix33 CMatrix33::operator+(const CMatrix33 &Other) { CMatrix33 New; int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { New.Row[i][j]=Row[i][j]; } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { New.Row[i][j]+=Other.Row[i][j]; } } return New; } void CMatrix33::operator+=(const CMatrix33 &Other) { int i, j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { Row[i][j]+=Other.Row[i][j]; } } } CMatrix33 CMatrix33::operator-(const CMatrix33 &Other) { CMatrix33 New; int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { New.Row[i][j]=Row[i][j]; } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { New.Row[i][j]-=Other.Row[i][j]; } } return New; } void CMatrix33::operator-=(const CMatrix33 &Other) { int i, j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { Row[i][j]-=Other.Row[i][j]; } } } double CMatrix33::Determinant() { double D; D=(Row[0][0]*(Row[1][1]*Row[2][2]-Row[2][1]*Row[1][2])) -(Row[0][1]*(Row[1][0]*Row[2][2]-Row[2][0]*Row[1][2])) +(Row[0][2]*(Row[1][0]*Row[2][1]-Row[2][0]*Row[1][1])); return D; } void CMatrix33::Invert() { CMatrix33 tmpCMatrix33; if(Determinant()==0) throw CGeomException(DivideByZero); tmpCMatrix33=Adjoint()/Determinant(); int i, j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { Row[i][j]=tmpCMatrix33.Row[i][j]; } } } CMatrix33 CMatrix33::Inverted() const { CMatrix33 tmpCMatrix33; tmpCMatrix33.Invert(); return tmpCMatrix33; } void CMatrix33::Transpose() { double temp[3][3]; int i, j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { temp[i][j]=Row[j][i]; } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { Row[i][j]=temp[i][j]; } } } void CMatrix33::Value() const { int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cout<<" "<

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.