A
download TexturedCube.cpp
Language: C++
LOC: 81
Project Info
TableHockey3D(tablehockey)
Server: SourceForge
Type: cvs
...ey\CVSROOT\tablehockey\src\
   Application.cpp
   Application.h
   Camera.cpp
   Camera.h
   Cube.cpp
   Cube.h
   Data.cpp
   Data.h
   Disk.cpp
   Disk.h
   FloatingText.cpp
   FloatingText.h
   Floor.cpp
   Floor.h
   Input.cpp
   Input.h
   Light.cpp
   Light.h
   log.cpp
   log.h
   main.cpp
   mmgr.cpp
   mmgr.h
   Model.cpp
   Model.h
   nommgr.h
   Puck.cpp
   Puck.h
   Pyramid.cpp
   Pyramid.h
   scene.cpp
   scene.h
   SmartPtr.h
   Sound.cpp
   Sound.h
   TableHockey.dsp
   TableHockey.dsw
   TestScene.cpp
   TestScene.h
   text.cpp
   text.h
   TextHelp.cpp
   TextHelp.h
   texture.cpp
   texture.h
   TexturedCube.cpp
   TexturedCube.h
   timer.cpp
   timer.h
   View.cpp
   View.h

// TexturedCube.cpp: implementation of the CTexturedCube class.
//
//////////////////////////////////////////////////////////////////////

#include "TexturedCube.h"

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

CTexturedCube::CTexturedCube(char* szTextureName)
: cx(1.0),
  cy(1.0),
  cz(1.0)
{
	pTexture = new CTexture();
	if (pTexture->LoadGLTexture(szTextureName) == FALSE)
		pApp->pLog->Log("Loading texture for CTexturedCube failed!");

	bTexture = true;
}

CTexturedCube::~CTexturedCube()
{
	delete pTexture;
}


void CTexturedCube::Draw()
{
	glPushMatrix();

	if (bTexture)
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, pTexture->texture2d);
		glColor3f(1.0, 1.0, 1.0);

		glTranslatef(pos_x, pos_y, pos_z);
		glRotatef(rot_angle, rot_x, rot_y, rot_z);

		glBegin(GL_QUADS);
			// Front Face
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-cx, -cy,  cz);
			glTexCoord2f(1.0f, 0.0f); glVertex3f( cx, -cy,  cz);
			glTexCoord2f(1.0f, 1.0f); glVertex3f( cx,  cy,  cz);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-cx,  cy,  cz);
			// Back Face
			glTexCoord2f(1.0f, 0.0f); glVertex3f(-cx, -cy, -cz);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(-cx,  cy, -cz);;
			glTexCoord2f(0.0f, 1.0f); glVertex3f( cx,  cy, -cz);
			glTexCoord2f(0.0f, 0.0f); glVertex3f( cx, -cy, -cz);
			// Top Face
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-cx,  cy, -cz);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-cx,  cy,  cz);
			glTexCoord2f(1.0f, 0.0f); glVertex3f( cx,  cy,  cz);
			glTexCoord2f(1.0f, 1.0f); glVertex3f( cx,  cy, -cz);
			// Bottom Face
			glTexCoord2f(1.0f, 1.0f); glVertex3f(-cx, -cy, -cz);
			glTexCoord2f(0.0f, 1.0f); glVertex3f( cx, -cy, -cz);
			glTexCoord2f(0.0f, 0.0f); glVertex3f( cx, -cy,  cz);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(-cx, -cy,  cz);
			// Right face
			glTexCoord2f(1.0f, 0.0f); glVertex3f( cx, -cy, -cz);
			glTexCoord2f(1.0f, 1.0f); glVertex3f( cx,  cy, -cz);
			glTexCoord2f(0.0f, 1.0f); glVertex3f( cx,  cy,  cz);
			glTexCoord2f(0.0f, 0.0f); glVertex3f( cx, -cy,  cz);
			// Left Face
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-cx, -cy, -cz);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(-cx, -cy,  cz);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(-cx,  cy,  cz);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-cx,  cy, -cz);
		glEnd();

		glDisable(GL_TEXTURE_2D);
	}
	else		// don't use any texture
	{
		glTranslatef(pos_x, pos_y, pos_z);
		glRotatef(rot_angle, rot_x, rot_y, rot_z);
		glColor3f(1.0, 1.0, 1.0);

		glBegin(GL_QUADS);
			// Front Face - red
			glColor3f(0.5, .0, .0);
			glVertex3f(-cx, -cy,  cz); glVertex3f( cx, -cy,  cz);
			glVertex3f( cx,  cy,  cz); glVertex3f(-cx,  cy,  cz);
			// Back Face - green
			glColor3f(0.0, .5, 0.0);
			glVertex3f(-cx, -cy, -cz); glVertex3f(-cx,  cy, -cz);;
			glVertex3f( cx,  cy, -cz); glVertex3f( cx, -cy, -cz);

			// Top Face - blue
			glColor3f(0.0, 0.0, .5);
			glVertex3f(-cx,  cy, -cz); glVertex3f(-cx,  cy,  cz);
			glVertex3f( cx,  cy,  cz); glVertex3f( cx,  cy, -cz);

			// Bottom Face - 
			glColor3f(.5, .5, 0.0);
			glVertex3f(-cx, -cy, -cz); glVertex3f( cx, -cy, -cz);
			glVertex3f( cx, -cy,  cz); glVertex3f(-cx, -cy,  cz);

			// Right face
			glColor3f(0.0, .5, .5);
			glVertex3f( cx, -cy, -cz); glVertex3f( cx,  cy, -cz);
			glVertex3f( cx,  cy,  cz); glVertex3f( cx, -cy,  cz);

			// Left Face
			glColor3f(.5, 0.0, .5);
			glVertex3f(-cx, -cy, -cz); glVertex3f(-cx, -cy,  cz);
			glVertex3f(-cx,  cy,  cz); glVertex3f(-cx,  cy, -cz);
			
		glEnd();
	}

	glPopMatrix();
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us