package edu.agh.tunev.ui.opengl;

import javax.media.opengl.GL2;

import com.jogamp.opengl.util.gl2.GLUT;

import edu.agh.tunev.model.AbstractModel;
import edu.agh.tunev.model.PersonProfile;
import edu.agh.tunev.model.PersonState;

final class PersonRenderer implements Renderable {

	private final PersonProfile person;
	private final AbstractModel model;

	public PersonRenderer(PersonProfile person, AbstractModel model) {
		this.person = person;
		this.model = model;
	}

	@Override
	public void render(GL2 gl, double t) {
		gl.glPushMatrix();

		PersonState state = model.getPersonState(person, t);

		gl.glTranslated(state.position.x, 0, state.position.y);
		gl.glRotated(state.orientation, 0, 1, 0);
		gl.glColor4d(1, 1, 1, 1);
		
		switch (state.movement) {
		case HIDDEN:
			break;
		case DEAD:
			gl.glColor4d(1, 0, 0, 1);
		case CRAWLING:
			drawCrawlingPerson(gl);
			break;
		case SQUATTING:
			drawSquattingPerson(gl);
			break;
		case STANDING:
		default:
			drawStandingPerson(gl);
			break;
		}

		gl.glPopMatrix();
	}

	private static double relativeHeadSize = 0.3;

	private void drawStandingPerson(GL2 gl) {
		gl.glPushMatrix();

		gl.glPushMatrix();
		gl.glTranslated(-PersonProfile.WIDTH / 2, 0, -PersonProfile.GIRTH / 2);
		Common.drawCuboid(gl, PersonProfile.WIDTH, person.height
				* (1.0 - relativeHeadSize), PersonProfile.GIRTH);
		gl.glPopMatrix();

		gl.glTranslated(0, person.height * (1.0 - relativeHeadSize / 2.0), 0);
		GLUT glut = new GLUT();
		final double radius = person.height * relativeHeadSize / 2;
		glut.glutSolidSphere(radius, 20, 20);
		gl.glColor4d(1, 0, 0, 1);
		glut.glutSolidCone(radius/2, radius * 4, 20, 20);

		gl.glPopMatrix();
	}

	private void drawCrawlingPerson(GL2 gl) {
		drawStandingPerson(gl);
	}

	private void drawSquattingPerson(GL2 gl) {
		drawStandingPerson(gl);
	}
}

@@ -469,16 +469,64 @@
 el;%0A%09%7D%0A%0A
+%09private static double relativeHeadSize = 0.3;%0A%0A
 %09@Overri
@@ -780,35 +780,84 @@
 1);%0A
-%09%09
 %0A%09%09
-switch (s
+PersonState.Movement test = PersonS
 tate.
-m
+M
 ovement
+.STANDING;%0A%09%09switch (test
 ) %7B%0A
@@ -1006,179 +1006,525 @@
 draw
-SquattingPerson(gl);%0A%09%09%09break;%0A%09%09case STANDING:%0A%09%09default:%0A%09%09%09drawStandingPerson(gl);%0A%09%09%09break;%0A%09%09%7D%0A%0A%09%09gl.glPopMatrix();%0A%09%7D%0A%0A%09private static double relativeHeadSize = 0.3;
+BasicPerson(gl, person.height * (0.5 - relativeHeadSize),%0A%09%09%09%09%09person.height * relativeHeadSize / 2);%0A%09%09%09break;%0A%09%09case STANDING:%0A%09%09default:%0A%09%09%09drawBasicPerson(gl, person.height * (1.0 - relativeHeadSize),%0A%09%09%09%09%09person.height * relativeHeadSize / 2);%0A%09%09%09break;%0A%09%09%7D%0A%0A%09%09gl.glPopMatrix();%0A%09%7D%0A%0A%09private void drawBasicPerson(GL2 gl, double bodyHeight, double headRadius) %7B%0A%09%09gl.glPushMatrix();%0A%0A%09%09drawBody(gl, bodyHeight);%0A%09%09gl.glTranslated(0, bodyHeight + headRadius, 0);%0A%09%09drawHead(gl, headRadius);%0A%0A%09%09gl.glPopMatrix();%0A%09%7D
 %0A%0A%09p
@@ -1535,29 +1535,29 @@
 te void draw
-Stand
+Crawl
 ingPerson(GL
@@ -1566,35 +1566,93 @@
 gl) %7B%0A%09%09
-gl.glPushMatrix();%0A
+//drawStandingPerson(gl);%0A%09%7D%0A%0A%09private void drawBody(GL2 gl, double height) %7B
 %0A%09%09gl.gl
@@ -1788,256 +1788,134 @@
 TH, 
-person.height%0A%09%09%09%09* (1.0 - relativeHeadSize), PersonProfile.GIRTH);%0A%09%09gl.glPopMatrix();%0A%0A%09%09gl.glTranslated(0, person.height * (1.0 - relativeHeadSize / 2.0), 0);%0A%09%09GLUT glut = new GLUT();%0A%09%09final double radius = person.height * relativeHeadSize / 2
+height, PersonProfile.GIRTH);%0A%09%09gl.glPopMatrix();%0A%09%7D%0A%0A%09private void drawHead(GL2 gl, double radius) %7B%0A%09%09GLUT glut = new GLUT()
 ;%0A%09%09
@@ -2007,17 +2007,19 @@
 e(radius
-/
+ / 
 2, radiu
@@ -2037,176 +2037,8 @@
 20);
-%0A%0A%09%09gl.glPopMatrix();%0A%09%7D%0A%0A%09private void drawCrawlingPerson(GL2 gl) %7B%0A%09%09drawStandingPerson(gl);%0A%09%7D%0A%0A%09private void drawSquattingPerson(GL2 gl) %7B%0A%09%09drawStandingPerson(gl);
 %0A%09%7D%0A

Draw a squatting Person