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
// GLObject.cpp: implementation of the CGLObject class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "GLObject.h"

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

CGLObject::CGLObject()
{
    displayMode = GLWIREFRAME;

    //matl
    itsMaterial = CGLMaterial(ALUMINIUM);
    ambiMat[0] = itsMaterial.GetAmbient().GetRed();
    ambiMat[1] = itsMaterial.GetAmbient().GetGreen();
    ambiMat[2] = itsMaterial.GetAmbient().GetBlue();
    ambiMat[3] = itsMaterial.GetAmbientCoeff();

    diffMat[0] = itsMaterial.GetDiffuse().GetRed();
    diffMat[1] = itsMaterial.GetDiffuse().GetGreen();
    diffMat[2] = itsMaterial.GetDiffuse().GetBlue();
    diffMat[3] = itsMaterial.GetDiffuseCoeff();

    specMat[0] = itsMaterial.GetSpecular().GetRed();
    specMat[1] = itsMaterial.GetSpecular().GetGreen();
    specMat[2] = itsMaterial.GetSpecular().GetBlue();
    specMat[3] = itsMaterial.GetSpecularCoeff();

    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 = itsMaterial.GetShininessCoeff();
    //end matl
    
    itsRed = 205;
    itsGreen = 205;
    itsBlue = 25;
    itsTransparency = 255;
    itsBox.SetLimits(-1, 1, -1, 1, -1, 1);
    glObjCount++;
    MakeHidden(false);
    firstTime = true;
}

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 GLMaterialName& matName)
{
    SetMaterial(CGLMaterial(matName));
}

void CGLObject::SetMaterial(const CGLMaterial& mat)
{
    itsMaterial = mat;
    ambiMat[0] = itsMaterial.GetAmbient().GetRed();
    ambiMat[1] = itsMaterial.GetAmbient().GetGreen();
    ambiMat[2] = itsMaterial.GetAmbient().GetBlue();
    ambiMat[3] = itsMaterial.GetAmbientCoeff();

    diffMat[0] = itsMaterial.GetDiffuse().GetRed();
    diffMat[1] = itsMaterial.GetDiffuse().GetGreen();
    diffMat[2] = itsMaterial.GetDiffuse().GetBlue();
    diffMat[3] = itsMaterial.GetDiffuseCoeff();

    specMat[0] = itsMaterial.GetSpecular().GetRed();
    specMat[1] = itsMaterial.GetSpecular().GetGreen();
    specMat[2] = itsMaterial.GetSpecular().GetBlue();
    specMat[3] = itsMaterial.GetSpecularCoeff();

    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 = itsMaterial.GetShininessCoeff();
    firstTime = true;
}

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

void CGLObject::ApplyMaterial()
{
    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);
}

void CGLObject::SetColor(const GLubyte& red, const GLubyte& green, const GLubyte& blue)
{
    itsRed = red;
    itsGreen = green;
    itsBlue = blue;
    firstTime = true;
    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;
}


//helper function to draw torus removes 'glut' dependency
void drawTorus(int numMajor, int numMinor, float majorRadius, float minorRadius)
{
    double majorStep = 2.0 * PI / numMajor;
    double minorStep = 2.0 * PI / numMinor;
    int i, j;

    for (i = 0; i < numMajor; ++i) {
	double a0 = i * majorStep;
	double a1 = a0 + majorStep;
	GLfloat x0 = cos(a0);
	GLfloat y0 = sin(a0);
	GLfloat x1 = cos(a1);
	GLfloat y1 = sin(a1);

	glBegin(GL_TRIANGLE_STRIP);
	for (j = 0; j <= numMinor; ++j) {
	    double b = j * minorStep;
	    GLfloat c = cos(b);
	    GLfloat r = minorRadius * c + majorRadius;
	    GLfloat z = minorRadius * sin(b);

	    glNormal3f(x0 * c, y0 * c, z / minorRadius);
	    glTexCoord2f(i / (GLfloat) numMajor, j / (GLfloat) numMinor);
	    glVertex3f(x0 * r, y0 * r, z);

	    glNormal3f(x1 * c, y1 * c, z / minorRadius);
	    glTexCoord2f((i + 1) / (GLfloat) numMajor, j / (GLfloat) numMinor);
	    glVertex3f(x1 * r, y1 * r, z);
	}
	glEnd();
    }
}

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)

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
Web03 | 2.8.140814.1 | Last Updated 18 Apr 2012
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid