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

#import "HS2DCircle1.h"


@implementation HS2DCircle1

- (id) init
{
	self = [super init];
	if (self != nil)
	{
		name = @"2D Haptic Circle (Ridge)";
		scale = DEFAULT_SCALE;
		height = DEFAULT_HEIGHT;
		slices = DEFAULT_SLICES;
		
		hlShape = hlGenShapes(1);
	}
	return self;
}

- (void) dealloc
{
	hlDeleteShapes(hlShape,1);
	[super dealloc];
}

/* Modified because there is no need for this function to handle scaleing */
- (void)entityTransform
{
	glRotatef(rotX,1,0,0);
	glRotatef(rotY,0,1,0);
	glRotatef(rotZ,0,0,1);
}

- (void)drawGL
{
	glPushMatrix();
		
		[self entityTransform];
		
		/**** Draw Shape ****/
		// Base
		glBegin(GL_QUADS);
			glColor3f(1.0f,0.0f,0.0f);
			glNormal3f(0.0f,0.0f,1.0f);
			glVertex3f(-1.0f,-1.0f,-1.0f);
			glVertex3f(1.0f,-1.0f,-1.0f);
			glVertex3f(1.0f,1.0f,-1.0f);
			glVertex3f(-1.0f,1.0f,-1.0f);
		glEnd();
		
		// Circle
		float DEG2RAD = 3.14159/180;
		int i;
		glBegin(GL_POLYGON);
			glColor3f(0.0f,1.0f,0.0f);
			glNormal3f(0.0f,0.0f,1.0f);
			for(i = 0; i < slices; i++)
			{
				float degInRad = i*(360.0f/slices)*DEG2RAD;
				glVertex3f(scale*cos(degInRad),scale*sin(degInRad),(-1.0f + height));
			}
		glEnd();
		
		// Ridge
		glBegin(GL_QUADS);
			glColor3f(0.0f,0.0f,1.0f);
			for(i = 0; i < slices; i++)
			{
				float degInRad1 = i*(360.0f/slices)*DEG2RAD;
				float degInRad2 = (i+1)*(360.0f/slices)*DEG2RAD;
				glNormal3f((cos(degInRad1)+cos(degInRad2))/2,(sin(degInRad1)+sin(degInRad2))/2,0.0f);
				glVertex3f(scale*cos(degInRad1),scale*sin(degInRad1),(-1.0f + height));
				glVertex3f(scale*cos(degInRad1),scale*sin(degInRad1),-1.0f);
				glVertex3f(scale*cos(degInRad2),scale*sin(degInRad2),-1.0f);
				glVertex3f(scale*cos(degInRad2),scale*sin(degInRad2),(-1.0f + height));
			}
		glEnd();
		
	glPopMatrix();
}

- (void)drawHL
{
	hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER,hlShape);
	
		[self drawGL];
	
	hlEndShape();
}

@end
