Click here to Skip to main content
12,253,335 members (44,823 online)
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads

Stats

292.7K views
9.6K downloads
129 bookmarked
Posted

Achieving PostScript and Wmf outputs for OpenGL

, 9 Jun 2003
This article explains how to generate resolution independent versions of 3D meshes rendered by OpenGL/MFC programs, i.e. how to export the rendering results to vectorial formats such as encapsulated postscript (EPS) and Windows enhanced metafile (EMF) formats. The main goal consists of being able to
Src
Mesh.dsp
Mesh.dsw
Mesh.plg
Mesh.aps
Mesh.clw
Lib3D
res
Mesh.ico
MeshDoc.ico
Toolbar.bmp
Mesh.ncb
Mesh.opt
Bin
knot2.wrl
mnt.wrl
mannequin.wrl
venus.wrl
knot1.wrl
nefertiti.wrl
geosphere.wrl
metafile.emf
Mesh.exe
nefertiti_flat.eps
nefertiti_line_light.eps
nefertiti_line.eps
nefertiti_line_color.eps
nefertiti_smooth_light.eps
nefertiti_line_smooth_light.eps
nefertiti_vertex_color.eps
sample.ppt
//********************************************
// Vector3d.cpp
//********************************************
// class CVector3d
//********************************************
// alliez@usc.edu
// Created : 10/12/97
// Modified : 20/01/98
//********************************************

#include "stdafx.h"
#include <math.h>

#include "Vector3d.h"
#include "Base3d.h"


//////////////////////////////////////////////
// CONSTRUCTORS
//////////////////////////////////////////////


//********************************************
// Destructor
//********************************************
CVector3d::~CVector3d()
{
}

//********************************************
// Constructor
//********************************************
CVector3d::CVector3d(CVector3d &vector)
{
	Set(&vector);
}

//********************************************
// Constructor
//********************************************
CVector3d::CVector3d(CVector3d *pVector)
{
	Set(pVector);
}

//********************************************
// Constructor
//********************************************
CVector3d::CVector3d(const float x,
										 const float y,
										 const float z)
{
	Set(x,y,z);
}

//********************************************
// Constructor
//********************************************
CVector3d::CVector3d(CVertex3d *pVertex1,
										 CVertex3d *pVertex2)
{
	m_x = pVertex2->x()-pVertex1->x();
	m_y = pVertex2->y()-pVertex1->y();
	m_z = pVertex2->z()-pVertex1->z();
}
	
//********************************************
// Constructor
//********************************************
CVector3d::CVector3d(CVertex3d &vertex1,
										 CVertex3d &vertex2)
{
	m_x = vertex2.x()-vertex1.x();
	m_y = vertex2.y()-vertex1.y();
	m_z = vertex2.z()-vertex1.z();
}


//////////////////////////////////////////////
// DATAS
//////////////////////////////////////////////

//********************************************
// Copy
//********************************************
void CVector3d::Copy(CVector3d &vector)
{
	Set(&vector);
}

//********************************************
// Copy
//********************************************
void CVector3d::Copy(CVector3d *pVector)
{
	Set(pVector);
}


//********************************************
// GetType
//********************************************
int CVector3d::GetType()
{
	return TYPE_VECTOR3D;
}

//********************************************
// Set
//********************************************
void CVector3d::Clear(void)
{
	Set(0.0f,0.0f,0.0f);
}

//********************************************
// Set
//********************************************
void CVector3d::Set(const float x,
										const float y,
										const float z)
{
	m_x = x;
	m_y = y;
	m_z = z;
}

//********************************************
// Set
//********************************************
void CVector3d::Set(CVector3d *pVector)
{
	Set(pVector->x(),pVector->y(),pVector->z());
}

//********************************************
// Set
//********************************************
void CVector3d::Set(CVector3d &vector)
{
	Set(vector.x(),vector.y(),vector.z());
}


//********************************************
// Set
//********************************************
void CVector3d::Set(CVertex3d *pVertex1,
										 CVertex3d *pVertex2)
{
	m_x = pVertex2->x()-pVertex1->x();
	m_y = pVertex2->y()-pVertex1->y();
	m_z = pVertex2->z()-pVertex1->z();
}


//********************************************
// Trace
//********************************************
void CVector3d::Trace()
{
	TRACE("\n");
	TRACE("** Vector **\n");
	TRACE("Adress      : %x\n",this);
	TRACE("Coordinates : (%g %g %g)\n",m_x,m_y,m_z);
}

//////////////////////////////////////////////
// OPERATORS
//////////////////////////////////////////////

//********************************************
// Operator = 
//********************************************
CVector3d CVector3d::operator=(CVector3d& vector)
{
	CVector3d v;
	v.Set(vector);
	return v;
}


//********************************************
// Operator + 
//********************************************
void CVector3d::operator+=(CVector3d* pVector)
{
	m_x += pVector->x();
	m_y += pVector->y();
	m_z += pVector->z();
}

//********************************************
// Operator /=
//********************************************
void CVector3d::operator/=(float factor)
{
	m_x /= factor;
	m_y /= factor;
	m_z /= factor;
}

//********************************************
// Operator *=
//********************************************
void CVector3d::operator*=(float factor)
{
	m_x *= factor;
	m_y *= factor;
	m_z *= factor;
}


//********************************************
// Inner
//********************************************
void CVector3d::Inner(CVector3d& vector)
{
	double x = (double)m_y*(double)vector.z()-(double)m_z*(double)vector.y();
	double y = (double)m_z*(double)vector.x()-(double)m_x*(double)vector.z();
	double z = (double)m_x*(double)vector.y()-(double)m_y*(double)vector.x();
	Set((float)x,(float)y,(float)z);
}


//////////////////////////////////////////////
//////////////////////////////////////////////
// PROCESSING
//////////////////////////////////////////////
//////////////////////////////////////////////

//********************************************
// Normalize
//********************************************
void CVector3d::NormalizeL2(void)
{
	double norm = GetNormL2();
	if(norm != 0.0f)
	{
		m_x = (float)(m_x / norm);
		m_y = (float)(m_y / norm);
		m_z = (float)(m_z / norm);
	}
	//TRACE("norm : %g\n",GetNormL2());
}

//********************************************
// Normalize
//********************************************
void CVector3d::NormalizeL2(float value)
{
	double norm = GetNormL2();
	if(norm != 0.0f)
	{
		m_x *= (float)(value/norm);
		m_y *= (float)(value/norm);
		m_z *= (float)(value/norm);
	}
	//TRACE("norm : %g (wanted : %g)\n",GetNormL2(),value);
}
	
//********************************************
// GetNormSquare
//********************************************
double CVector3d::GetNormL2Square(void)
{
	return ((double)m_x*(double)m_x + 
		      (double)m_y*(double)m_y + 
					(double)m_z*(double)m_z);
}
	
//********************************************
// GetNorm
//********************************************
double CVector3d::GetNormL2(void)
{
	return sqrt((double)m_x*(double)m_x + 
		          (double)m_y*(double)m_y + 
							(double)m_z*(double)m_z);
}
	
//********************************************
// Collinear
//********************************************
int CVector3d::Collinear(CVector3d *pVector)
{
	float x = pVector->x() / m_x;
	float y = pVector->y() / m_y;
	float z = pVector->z() / m_z;
	return ((x == y) && (y == z));
}

//********************************************
// Collinear
//********************************************
int CVector3d::Collinear(CVector3d &vector)
{
	float x = vector.x() / m_x;
	float y = vector.y() / m_y;
	float z = vector.z() / m_z;
	return ((x == y) && (y == z));
}


//////////////////////////////////////////////
//////////////////////////////////////////////
// EXTERNAL OPERATORS
//////////////////////////////////////////////
//////////////////////////////////////////////


//********************************************
// Operator + 
//********************************************
CVector3d operator+(CVector3d& u,
                    CVector3d& v)
{
	CVector3d w;
	w.Set(u.x()+v.x(),u.y()+v.y(),u.z()+v.z());
	return w;
}

//********************************************
// Operator -
//********************************************
CVector3d operator-(CVector3d& u,
                    CVector3d& v)
{
	CVector3d w;
	w.Set(u.x()-v.x(),u.y()-v.y(),u.z()-v.z());
	return w;
}

//********************************************
// Operator ^
//********************************************
CVector3d operator^(CVector3d& u,
                    CVector3d& v)
{
	// w = u ^ v
	CVector3d w;
	w.Set(u.y()*v.z()-u.z()*v.y(),
		    u.z()*v.x()-u.x()*v.z(),
		    u.x()*v.y()-u.y()*v.x());
	return w;
}

//********************************************
// Inner
//********************************************
CVector3d CVector3d::Inner(CVector3d* u,
                           CVector3d* v)
{
	// w = u ^ v
	CVector3d w;
	w.Set(u->y()*v->z()-u->z()*v->y(),
		    u->z()*v->x()-u->x()*v->z(),
		    u->x()*v->y()-u->y()*v->x());
	return w;
}


void CVector3d::RotateXZ(float alpha)
{
	float x = (float)(m_x*cos(alpha)+m_z*sin(alpha));
	float z = (float)(-m_x*sin(alpha)+m_z*cos(alpha));
	m_x = x;
	m_z = z;
}


// ** EOF **



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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Pierre Alliez
France France
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 10 Jun 2003
Article Copyright 2001 by Pierre Alliez
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid