//
//  HapticShape.m
//  OffScreenHapticRenderer
//
//  Created by Luke on 4/04/06.
//  Copyright 2006 Luke Pullella. All rights reserved.
//

#import "HapticShape.h"


@implementation HapticShape

- init
{
	self = [super init];
	if(self != nil)
	{
		name = @"Unnamed Shape";
		scale = 1.0f;
		rotX  = 0.0f;
		rotY  = 0.0f;
		rotZ  = 0.0f;
		boxShape = hlGenShapes(1);
		
		glNewList(boxFace, GL_COMPILE);
			glBegin(GL_QUADS);
				glNormal3f(0.0f,0.0f,1.0f);
				glVertex3f(1.0f,-1.0f,0.0f);
				glVertex3f(1.0f,1.0f,0.0f);
				glVertex3f(-1.0f,1.0f,0.0f);
				glVertex3f(-1.0f,-1.0f,0.0f);
			glEnd();
		glEndList();
	}
	return self;
}

- (void) dealloc
{
	hlDeleteShapes(boxShape,1);
	[name release];
	[super dealloc];
}


- (void)scaleEntity:(GLfloat)size
{
	scale = size;
}

- (void)rotateEntityX:(GLfloat)angle
{
	rotX = angle;
}

- (void)rotateEntityY:(GLfloat)angle
{
	rotY = angle;
}

- (void)rotateEntityZ:(GLfloat)angle
{
	rotZ = angle;
}

- (void)entityTransform
{
	glScalef(scale,scale,scale);
	glRotatef(rotX,1,0,0);
	glRotatef(rotY,0,1,0);
	glRotatef(rotZ,0,0,1);
}

- (void)drawShape
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glColor3f(1.0f, 1.0f, 1.0f);
	
	[self drawGL];
	
	hlBeginFrame();
	
		[self drawHL];
		/* DOSEN'T WORK?!?!? DOH!
		// Draw Bounding Box
		hlTouchModel(HL_CONTACT);
		hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER,boxShape);
			
			// Front
			glPushMatrix();
				glTranslatef(0.0f,0.0f,0.5f);
				glRotatef(180.0f,1.0f,0.0f,0.0f);
				glCallList(boxFace);
			glPopMatrix();
			
			// Top
			glPushMatrix();
				glTranslatef(0.0f,1.0f,0.0f);
				glRotatef(-90.0f,1.0f,0.0f,0.0f);
				glCallList(boxFace);
			glPopMatrix();
			
			// Bottom
			glPushMatrix();
				glTranslatef(0.0f,-1.0f,0.0f);
				glRotatef(90.0f,1.0f,0.0f,0.0f);
				glCallList(boxFace);
			glPopMatrix();
			
			// Left
			glPushMatrix();
				glTranslatef(-1.0f,0.0f,0.0f);
				glRotatef(90.0f,0.0f,1.0f,0.0f);
				glCallList(boxFace);
			glPopMatrix();
			
			// Right
			glPushMatrix();
				glTranslatef(0.0f,1.0f,0.0f);
				glRotatef(-90.0f,0.0f,1.0f,0.0f);
				glCallList(boxFace);
			glPopMatrix();
		
		hlEndShape(); */
		
	hlEndFrame();
	
	glFinish();
}

- (void)drawGL
{
}

- (void)drawHL
{
}

@end
