Click here to Skip to main content
15,886,772 members
Articles / Multimedia / OpenGL

A small VRML viewer using OpenGL and MFC

Rate me:
Please Sign up or sign in to vote.
4.96/5 (57 votes)
30 Nov 19992 min read 428K   16.8K   159  
//********************************************
// Edge3d.cpp
//********************************************
// class CEdge3d
//********************************************
// pierre.alliez@cnet.francetelecom.fr
// Created : 10/12/97
// Modified : 16/12/97
//********************************************

#include "stdafx.h"

#include "Base3d.h"
#include "Edge3d.h"

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

//********************************************
// Constructor
//********************************************
CEdge3d::CEdge3d()
{
	m_pVertex1 = NULL;
	m_pVertex2 = NULL;
	m_pFace1 = NULL;
	m_pFace2 = NULL;
	m_Flag = 0;
}


//********************************************
// Constructor
//********************************************
CEdge3d::CEdge3d(CVertex3d *pVertex1,
								 CVertex3d *pVertex2)
{
	Set(pVertex1,pVertex2);
	m_pFace1 = NULL;
	m_pFace2 = NULL;
	m_Flag = 0;
}

//********************************************
// Constructor
//********************************************
CEdge3d::CEdge3d(CVertex3d *pVertex1,
								 CVertex3d *pVertex2,
								 CFace3d *pFace1,
								 CFace3d *pFace2)
{
	Set(pVertex1,pVertex2);
	Set(pFace1,pFace2);
	m_Flag = 0;
}


//********************************************
// Constructor
//********************************************
CEdge3d::CEdge3d(CEdge3d *pEdge)
{
	Set(pEdge);
	m_Flag = 0;
}



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

//********************************************
// GetType
//********************************************
int CEdge3d::GetType()
{
	return TYPE_EDGE3D;
}

//********************************************
// Set
//********************************************
void CEdge3d::Set(CVertex3d *pVertex1,
									CVertex3d *pVertex2)
{
	m_pVertex1 = pVertex1;
	m_pVertex2 = pVertex2;
}

//********************************************
// Set
//********************************************
void CEdge3d::Set(CFace3d *pFace1,
									CFace3d *pFace2)
{
	m_pFace1 = pFace1;
	m_pFace2 = pFace2;
}


//********************************************
// Set
//********************************************
void CEdge3d::Set(CEdge3d *pEdge)
{
	Set(pEdge->v1(),pEdge->v2());
	Set(pEdge->f1(),pEdge->f2());
}

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

//********************************************
// sharp
// threshold : sin(angle)
//********************************************
int CEdge3d::sharp(float threshold)
{
	// Check
	if(m_pFace1 == NULL || 
	   m_pFace2 == NULL)
		return 0;

	return (SinAngle(m_pFace1,m_pFace2) >= threshold);
}

//********************************************
// Equal (order independant)
//********************************************
int CEdge3d::Equal(CEdge3d *pEdge)
{
	int success = 0;
	success += m_pVertex1 == pEdge->v1();
	success += m_pVertex1 == pEdge->v2();
	success += m_pVertex2 == pEdge->v1();
	success += m_pVertex2 == pEdge->v2();
	return (success >= 2);
}


//********************************************
// GetVertexDiff
//********************************************
CVertex3d *CEdge3d::GetVertexDiff(CVertex3d *pVertexDiff)
{
	if(m_pVertex1 != pVertexDiff)
		return m_pVertex1;
	else
	{
		ASSERT(m_pVertex2 != pVertexDiff);
		return m_pVertex2;
	}
}

//////////////////////////////////////////////
//////////////////////////////////////////////
// OPENGL
//////////////////////////////////////////////
//////////////////////////////////////////////

//********************************************
// glDrawHighlight
// Highlights edge
//********************************************
void CEdge3d::glDrawHighlight(unsigned char *color)
{
	// Color
	glColor3ub(color[0],color[1],color[2]);

	::glBegin(GL_LINES);
		::glVertex3f(m_pVertex1->x(),m_pVertex1->y(),m_pVertex1->z());
		::glVertex3f(m_pVertex2->x(),m_pVertex2->y(),m_pVertex2->z());
	::glEnd();
}

//********************************************
// glDrawHighlight
// Highlights edge and neighbors
//********************************************
void CEdge3d::glDrawHighlight(unsigned char *color,
															unsigned char *ColorNeighbor)
{
	// Color
	glColor3ub(color[0],color[1],color[2]);

	::glBegin(GL_LINES);
		::glVertex3f(m_pVertex1->x(),m_pVertex1->y(),m_pVertex1->z());
		::glVertex3f(m_pVertex2->x(),m_pVertex2->y(),m_pVertex2->z());
	::glEnd();

	m_pFace1->glDraw(ColorNeighbor);
	m_pFace2->glDraw(ColorNeighbor);
}




// ** 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


Written By
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions