Click here to Skip to main content
15,886,085 members
Articles / Desktop Programming / MFC

Basic Curves And Surfaces Modeler

Rate me:
Please Sign up or sign in to vote.
4.17/5 (40 votes)
18 Apr 2012CPOL3 min read 246.5K   16.4K   117  
A basic demo of modeling curves and surfaces in OpenGL.
// OffsetCurve.cpp: implementation of the COffsetCurve class.
//
//////////////////////////////////////////////////////////////////////

#if HAVE_CONFIG_H
#  include <config.h>
#endif

#include "stdafx.h"

#include "OffsetCurve.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

COffsetCurve::COffsetCurve(const CCurve& aCurve, const double& offset, const CPlane& refPlane, const bool& sense)
{
	itsCurve = aCurve.Copy();
	itsOffset = offset;
	itsPlane = refPlane;
	itsSense = sense;
}

COffsetCurve::~COffsetCurve()
{
	if(itsCurve)
		delete itsCurve;
}

void COffsetCurve::Reverse()
{
	itsCurve->Reverse();
}

CPoint3D COffsetCurve::PointAtPara(const double& para)
{
	CVector3D dir = itsPlane.GetDirection();
	CVector3D tangent(itsCurve->PointAtPara(para), itsCurve->PointAtPara(para+0.001));
	CVector3D normal = dir^tangent;
	normal.Normalize();
	if(!itsSense)
		normal = normal * -1.0;
	CPoint3D P = itsCurve->PointAtPara(para);
	P = P + normal * itsOffset;
	return P;
}

double COffsetCurve::FirstParameter() const
{
	return itsCurve->FirstParameter();
}

double COffsetCurve::LastParameter() const
{
	return itsCurve->LastParameter();
}

bool COffsetCurve::IsClosed() const
{
	return itsCurve->IsClosed();
}

bool COffsetCurve::IsOfType(const CurveType& type) const
{
	bool b = (type == OFFSETCURVE);
	return b;

}

CCurve* COffsetCurve::Copy() const
{
	COffsetCurve* myCurve = new COffsetCurve(*itsCurve, itsOffset, itsPlane, itsSense);
	return myCurve;
}

void COffsetCurve::Translate(double dx, double dy, double dz)
{
    itsCurve->Translate(dx, dy, dz);
}

void COffsetCurve::Translate(const CVector3D& V)
{
    itsCurve->Translate(V);
}

void COffsetCurve::Translate(const CPoint3D& fro, const CPoint3D& to)
{
    itsCurve->Translate(fro, to);
}

void COffsetCurve::Rotate(const COneAxis& axis, double angle)
{
    itsCurve->Rotate(axis, angle);
}

void COffsetCurve::Scale(const CPoint3D& point, double fact)
{
    itsCurve->Scale(point, fact);
}

void COffsetCurve::Mirror(const CPoint3D& point)
{
    itsCurve->Mirror(point );
}

void COffsetCurve::Mirror(const COneAxis& axis)
{
    itsCurve->Mirror(axis);
}

void COffsetCurve::Mirror(const CPlane& plane)
{
    itsCurve->Mirror(plane);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Product Manager Mahindra & Mahindra
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

Comments and Discussions