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

StL Data File Viewer

, 5 Mar 2003
A simple StereoLithography data file viewer.
// GLObject.cpp: implementation of the CGLObject class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GLObject.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
int CGLObject::glObjCount = 0;

CGLObject::CGLObject()
{
	displayMode = GLWIREFRAME;
	itsMaterial = GOLD;
	itsRed = 205;
	itsGreen = 205;
	itsBlue = 25;
	itsBox.SetLimits(-1, 1, -1, 1, -1, 1);
	glObjCount++;
}

CGLObject::~CGLObject()
{
	glObjCount--;
}

GLObjectType CGLObject::GLObjType() const
{
	return glObjType;
}

bool CGLObject::IsOfType(const GLObjectType& type) const
{
	GLObjectType typ = type;
	bool b = (glObjType == typ);
	return b;
}

void CGLObject::SetDisplayMode(const GLDisplayMode& mode)
{
	displayMode = mode;
	DefineDisplay();
}

GLDisplayMode CGLObject::GetDisplayMode() const
{
	return displayMode;
}

void CGLObject::SetMaterial(const GLMaterial& mat)
{
	itsMaterial = mat;
	DefineDisplay();
}

GLMaterial CGLObject::GetMaterial() const
{
	return itsMaterial;
}

void CGLObject::SetColor(const GLubyte& red, const GLubyte& green, const GLubyte& blue)
{
	itsRed = red;
	itsGreen = green;
	itsBlue = blue;
	DefineDisplay();
}

void CGLObject::GetColor(GLubyte* colVect) const
{
	colVect = new GLubyte[3];
	colVect[0] = itsRed;
	colVect[1] = itsGreen;
	colVect[2] = itsBlue;
}

void CGLObject::SetBoundingBox(const CBoundingBox& B)
{
	itsBox = B;
}

CBoundingBox CGLObject::GetBoundingBox() const
{
	return itsBox;
}

void CGLObject::AddMaterial(float* matArray)
{
	ambiMat[0] = matArray[0];
	ambiMat[1] = matArray[1];
	ambiMat[2] = matArray[2];
	ambiMat[3] = matArray[3];

	diffMat[0] = matArray[4];
	diffMat[1] = matArray[5];
	diffMat[2] = matArray[6];
	diffMat[3] = matArray[7];

	specMat[0] = matArray[8];
	specMat[1] = matArray[9];
	specMat[2] = matArray[10];
	specMat[3] = matArray[11];

	emisMat[0] = 0.0f;
	emisMat[1] = 0.0f;
	emisMat[2] = 0.0f;
	emisMat[3] = 0.0f;

	coloMat[0] = ambiMat[0]*1.2;
	coloMat[1] = ambiMat[1]*1.2;
	coloMat[2] = ambiMat[2]*1.2;
	coloMat[3] = ambiMat[3]*1.2;

	shine = matArray[12];
}

void CGLObject::ApplyMaterial(const GLMaterial& mat)
{
	switch (mat)
	{
		//Default Setting
		case DEFAULT:
			AddMaterial(Default);
			break;
		//Non Metals
		case EMERALD:
			AddMaterial(Emerald);
			break;
		case JADE:
			AddMaterial(Jade);
			break;
		case OBSIDIAN:
			AddMaterial(Obsidian);
			break;
		case PEARL:
			AddMaterial(Pearl);
			break;
		case PEWTER:
			AddMaterial(Pewter);
			break;
		case RUBY:
			AddMaterial(Ruby);
			break;
		case TURQUOISE:
			AddMaterial(Turquoise);
			break;
		case PLASTIC:
			AddMaterial(Plastic);
			break;
		case RUBBER:
			AddMaterial(Rubber);
			break;
		//Metals
		case ALUMINIUM:
			AddMaterial(Aluminium);
			break;
		case BRASS:
			AddMaterial(Brass);
			break;
		case BRONZE:
			AddMaterial(Bronze);
			break;
		case P_BRONZE:
			AddMaterial(Polished_Bronze);
			break;
		case CHROME:
			AddMaterial(Chrome);
			break;
		case COPPER:
			AddMaterial(Copper);
			break;
		case P_COPPER:
			AddMaterial(Polished_Copper);
			break;
		case GOLD:
			AddMaterial(Gold);
			break;
		case P_GOLD:
			AddMaterial(Polished_Gold);
			break;
		case SILVER:
			AddMaterial(Silver);
			break;
		case P_SILVER:
			AddMaterial(Polished_Silver);
			break;
		case STEEL:
			AddMaterial(Steel);
			break;
		case NONE:
			AddMaterial(None);
			break;
		default:
			AddMaterial(Matl);
			break;
	}
	glLightfv(GL_LIGHT0,GL_AMBIENT,ambiMat);
	glLightfv(GL_LIGHT0,GL_DIFFUSE,diffMat);
	glLightfv(GL_LIGHT0,GL_SPECULAR,specMat);
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambiMat);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shine);
	glEnable(GL_LIGHT0);
}

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 GNU General Public License (GPLv3)

Share

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
Web01 | 2.8.140922.1 | Last Updated 6 Mar 2003
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid