Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads
 
Add your own
alternative version

Basic Curves And Surfaces Modeler

, 18 Apr 2012
A basic demo of modeling curves and surfaces in OpenGL.
cadsurfexe.zip
CadSurfexe
CadSurf.exe
VKGeom.dll
VKGraphic.dll
cadsurf_demo.zip
cadsurf_src.zip
CadSurf_src
VKernel
VKGraphic
VKGraphic.dsp
VKGraphic.dsw
VKGraphic.plg
VKGeom
VKGeom.dsp
VKGeom.dsw
cadsurf
CadSurf.clw
CadSurf.dsp
cadsurf.dsw
Thumbs.db
res
bmp00001.bmp
cadsurf.ico
CADSURFDOC.ICO
new_splash.bmp
new_splash.PNG
new_splash_small.bmp
tb_geom.bmp
Thumbs.db
toolbar.bmp
toolbar1.bmp
untitled.bmp
XPStyle.manifest
CadSurf_VS2008.zip
CadSurf
cadsurf
CadSurf.suo
res
bmp00001.bmp
cadsurf.ico
CADSURFDOC.ICO
new_splash.bmp
new_splash.PNG
new_splash_small.bmp
tb_geom.bmp
Thumbs.db
toolbar.bmp
toolbar1.bmp
untitled.bmp
VKernel
VKGeom
VKGraphic
VKGraphic.plg
// AxisSystem.cpp: implementation of the CAxisSystem class.
//
//////////////////////////////////////////////////////////////////////

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

#include "stdafx.h"

#include "Point3D.h"
#include "Vector3D.h"
#include "OneAxis.h"
#include "AxisSystem.h"
#include "GeomException.h"
#include "MMath.h"

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

//Implementation of class CoordSys (Local Coordinate System)
CAxisSystem::CAxisSystem()
{
	geomType = CAXISSYSTEM;
}

CAxisSystem::CAxisSystem(const CPoint3D& Pos, const CVector3D& Dir, const CVector3D& XDir)
{
	Position = Pos;
	Origin.SetParam(Pos.GetX(),Pos.GetY(),Pos.GetZ());
	Direction = Dir;
	Direction.Normalize();
	XDirection = XDir;
	XDirection.Normalize();
	if(!Direction.IsNormal(XDirection))
		throw CGeomException(ConstructionFailure);
	else
		YDirection = Direction.Crossed(XDirection);

	geomType = CAXISSYSTEM;
}

CAxisSystem::CAxisSystem(const CPoint3D& Pos, const CVector3D& Dir)
{
	Position = Pos;
	Origin.SetParam(Pos.GetX(),Pos.GetY(),Pos.GetZ());
	Direction = Dir;
	Direction.Normalize();

	CVector3D V = Direction;
	double lA = V.GetX();
	double lB = V.GetY();
	double lC = V.GetZ();

	double Aabs = lA;
	if (Aabs < 0)
		Aabs = - Aabs;

	double Babs = lB;
	if (Babs < 0)
		Babs = - Babs;

	double Cabs = lC;
	if (Cabs < 0)
		Cabs = - Cabs;

	CVector3D XAxis;
    
	if      ( Babs <= Aabs && Babs <= Cabs)
	{

		if (Aabs > Cabs)
			XAxis.SetParam(-lC,0., lA);
		else
			XAxis.SetParam( lC,0.,-lA);
	}
	else if( Aabs <= Babs && Aabs <= Cabs)
	{
		if (Babs > Cabs)
			XAxis.SetParam(0.,-lC, lB);
		else
			XAxis.SetParam(0., lC,-lB);
	}
	else
	{
		if (Aabs > Babs)
			XAxis.SetParam(-lB, lA,0.);
		else
			XAxis.SetParam(lB,-lA,0.);
	}
	XDirection = XAxis;
	XDirection.Normalize();
	if(!Direction.IsNormal(XDirection))
		throw CGeomException(ConstructionFailure);
	else
		YDirection = Direction.Crossed(XDirection);

	geomType = CAXISSYSTEM;
}

CAxisSystem::CAxisSystem(const CAxisSystem& Ax) : CGeometry()
{
	Position = Ax.GetPosition();
	Origin = Ax.GetOrigin();
	Direction = Ax.GetDirection();
	XDirection = Ax.GetXDirection();
	YDirection = Direction.Crossed(XDirection);

	geomType = CAXISSYSTEM;
}

CAxisSystem::~CAxisSystem()
{
}

void CAxisSystem::SetDirection(const CVector3D& D)
{
	Direction = D;
	Direction.Normalize();
	if(!XDirection.IsParallel(Direction))
	{
		CVector3D tempY = D.Crossed(XDirection);
		XDirection = tempY.Crossed(D);
		YDirection = Direction.Crossed(XDirection);
		XDirection.Normalize();
		YDirection.Normalize();
	}
	else
	{
		CVector3D tempX = YDirection.Crossed(D);
		YDirection = D.Crossed(tempX);
		XDirection = Direction.Crossed(YDirection);
		XDirection.Normalize();
		YDirection.Normalize();
	}
}

void CAxisSystem::SetDirection(double dx, double dy, double dz)
{
	CVector3D D(dx, dy, dz);
	D.Unit();
	SetDirection(D);
}

void CAxisSystem::SetXDirection(const CVector3D& XD)
{
	if(!this->Direction.IsParallel(XD))
	{
		CVector3D XDir = XD;
		XDir.Normalize();
		XDirection = Direction.CrossCrossed(XDir,Direction);
		YDirection = Direction.Crossed(XDirection);
	}
	else
		throw CGeomException(ConstructionFailure);
}

void CAxisSystem::SetXDirection(double dxx, double dxy, double dxz)
{
	CVector3D XD(dxx, dxy, dxz);
	if(!this->Direction.IsParallel(XD))
	{
		SetXDirection(XD.Unit());
	}
	else
		throw CGeomException(ConstructionFailure);
}

void CAxisSystem::SetYDirection(const CVector3D& YD)
{
	if(!this->Direction.IsParallel(YD))
	{
		CVector3D YDir = YD;
		YDir.Normalize();
		YDirection = Direction.CrossCrossed(YDir, Direction);
		XDirection = YDirection.Crossed(Direction);
	}
	else
		throw CGeomException(ConstructionFailure);
}

void CAxisSystem::SetYDirection(double dyx, double dyy, double dyz)
{
	CVector3D YD(dyx, dyy, dyz);
	if(!this->Direction.IsParallel(YD))
	{
		SetYDirection(YD.Unit());
	}
	else
		throw CGeomException(ConstructionFailure);
}

void CAxisSystem::SetPosition(double x, double y, double z)
{
	Position.SetParam(x,y,z);
	Origin.SetParam(x,y,z);
}

void CAxisSystem::SetPosition(const CPoint3D& P)
{
	SetPosition(P.GetX(), P.GetY(), P.GetZ());
}

bool CAxisSystem::operator == (const CAxisSystem& C) const
{
	return (Position==C.GetPosition()&&Direction==C.GetDirection()
		&&XDirection==C.GetXDirection()&&YDirection==C.GetYDirection());
}

void CAxisSystem::Translate(const COneAxis& Ax, const double& amt)
{
	CGeometry::Translate(Ax, amt);
}


void CAxisSystem::Translate(double dx, double dy, double dz)
{
	Position.Translate(dx,dy,dz);
	Origin.Translate(dx,dy,dz);
}

void CAxisSystem::Translate(const CVector3D& V)
{
	Position.Translate(V);
	Origin.Translate(V);
}

void CAxisSystem::Translate(const CPoint3D& P1, const CPoint3D& P2)
{
	Position.Translate(P1, P2);
	Origin.Translate(P1, P2);
}

void CAxisSystem::Rotate(const COneAxis& Ax, double ang)
{
	COneAxis tAx = Ax;
	tAx.Translate(tAx.GetPosition(), CPoint3D(0,0,0));
	CVector3D Dir = GetDirection();
	COneAxis ax(GetPosition(), GetDirection());
	ax.Rotate(tAx, ang);
	Origin.Rotate(Ax, ang);
	Position = Origin.Point();
	SetDirection(ax.GetDirection());
}

void CAxisSystem::Scale(const CPoint3D& P, double fact)
{
	Position.Scale(P, fact);
	Origin.Scale(P, fact);
	if (fact < 0)
	{
		Direction.Reverse();
	    XDirection.Reverse();
		YDirection.Reverse();
	}
}

void CAxisSystem::Mirror(const CPoint3D& P)
{
	Position.Mirror(P);
	Origin.Mirror(P);
	Direction.Reverse();
	XDirection.Reverse();
	YDirection.Reverse();
}

void CAxisSystem::Mirror(const COneAxis& Ax)
{
	Position.Mirror(Ax);
	Origin.Mirror(Ax);
	if(Direction.IsParallel(Ax.GetDirection()))
		Direction.Mirror (Ax.GetDirection());
	else
		Direction.Mirror (Ax);
	if(XDirection.IsParallel(Ax.GetDirection()))
		XDirection.Mirror (Ax.GetDirection());
	else
		XDirection.Mirror (Ax);
	if(YDirection.IsParallel(Ax.GetDirection()))
		YDirection.Mirror (Ax.GetDirection());
	else
		YDirection.Mirror (Ax);
	//SetDirection (XDirection.Crossed(YDirection));
}

void CAxisSystem::Mirror(const CPlane& Pln)
{
	Position.Mirror(Pln);
	Origin.Mirror(Pln);
	Direction.Mirror (Pln);
	XDirection.Mirror (Pln);
	YDirection.Mirror (Pln);
}



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)

About the Author

Sharjith
Engineer Tata Technologies Ltd
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 18 Apr 2012
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid