Click here to Skip to main content
15,885,757 members
Articles / Desktop Programming / MFC

StL Data File Viewer

Rate me:
Please Sign up or sign in to vote.
4.87/5 (43 votes)
5 Mar 2003CPOL2 min read 511.2K   14.7K   60  
A simple StereoLithography data file viewer.
// GLTrihedron.cpp: implementation of the CGLTrihedron class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GLTrihedron.h"

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

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

CGLTrihedron::CGLTrihedron()
{
	glObjType = GLTRIHEDRON;
}

CGLTrihedron::CGLTrihedron(GLfloat size)
{
	glObjType = GLTRIHEDRON;
	csSize = size;
	ComputeBoundLimits();
	glObjID = (int)glObjType + CGLObject::GetCount();
}

CGLTrihedron::~CGLTrihedron()
{
}

CGLObject* CGLTrihedron::Copy() const
{
	CGLTrihedron* T = new CGLTrihedron(csSize);
	T->glObjID = glObjID;
	return T;
}

void CGLTrihedron::DefineDisplay()
{
	glDisable(GL_LIGHTING);
	glDisable(GL_COLOR_MATERIAL);
	glEnable(GL_DEPTH_TEST);

	//Axes' label
	glColor3f(1.0f, 1.0f, 0.0f);
	glRasterPos3d(0.5*csSize, 0, 0);
	DrawText("X");
	glRasterPos3d(0, 0.5*csSize, 0);
	DrawText("Y");
	glRasterPos3d(0, 0, 0.5*csSize);
	DrawText("Z");

	glColor3f(0.70f, 0.70f, 1.70f);
	//X Axis
	glBegin(GL_LINES);
	glVertex3f(0.0f, 0.0f, 0.0f);
	glVertex3f(0.8*csSize*0.5, 0.0f, 0.0f);
	glEnd();
	glPushMatrix();	
	glTranslatef(0.8*csSize*0.5, 0.0f, 0.0f);
	glRotatef(90.0f,0.0f,1.0f,0.0f);
	glutWireCone(0.027*csSize,0.09*csSize,10,10);
	glPopMatrix();

	//Y Axis
	glBegin(GL_LINES);
	glVertex3f(0.0f, 0.0f, 0.0f);
	glVertex3f(0.0f, 0.8*csSize*0.5, 0.0f);
	glEnd();
	glPushMatrix();	
	glTranslatef(0.0f, 0.8*csSize*0.5, 0.0f);
	glRotatef(-90.0f,1.0f,0.0f,0.0f);
	glutWireCone(0.027*csSize,0.09*csSize,10,10);
	glPopMatrix();

	//Z Axis
	glBegin(GL_LINES);
	glVertex3f(0.0f, 0.0f, 0.0f);
	glVertex3f(0.0f, 0.0f, 0.8*csSize*0.5);
	glEnd();
	glPushMatrix();	
	glTranslatef(0.0f, 0.0f, 0.8*csSize*0.5);
	glutWireCone(0.027*csSize,0.09*csSize,10,10);
	glPopMatrix();

	glDisable(GL_DEPTH_TEST);
}

void CGLTrihedron::Display(const GLDisplayMode& dMode)
{
	DefineDisplay();
}

void CGLTrihedron::Hilight(const GLDisplayMode& dMode)
{
}

void CGLTrihedron::SetSize(GLfloat size)
{
	csSize = size;
}

void CGLTrihedron::DrawText(char* string)
{
    char* p = NULL;

    for (p = string; *p; p++)
	glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *p);
}

void CGLTrihedron::ComputeBoundLimits()
{
	itsBox.SetLimits(-csSize, csSize, -csSize, csSize, -csSize, csSize);
}

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