1 package nl.tudelft.goal.ut2004.visualizer.timeline.map;
2
3 import java.util.LinkedList;
4 import java.util.List;
5 import java.util.logging.Level;
6 import java.util.logging.Logger;
7
8 import javax.media.opengl.GL;
9 import javax.media.opengl.GL2;
10 import javax.media.opengl.glu.GLU;
11 import javax.media.opengl.glu.GLUquadric;
12
13 import nl.tudelft.goal.ut2004.visualizer.map.BlendTriangle;
14 import static javax.media.opengl.GL.*;
15 import static javax.media.opengl.GL2.*;
16 import com.jogamp.opengl.util.gl2.GLUT;
17
18 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
19
20
21
22
23
24
25
26
27 public class UTFlagSubGLRenderer implements
28 ISubGLRenderer<IRenderableWorldObject> {
29
30 private Logger logger;
31 private GLU glu;
32 private GLUT glut;
33 private GLUquadric quadratic;
34
35
36 private final IRenderableWorldObject flag;
37 private static final double SPHERE_RADIUS = 64;
38 private static final int SPHERE_SLICES = 32;
39 private static final int SPHERE_STACKS = 32;
40 private static final double CYLINDER_RADIUS = 16;
41 private static final int CYLINDER_SLICES = 5;
42 private static final int CYLINDER_STACKS = 1;
43 private static final double CYLINDER_HEIGHT = SPHERE_RADIUS * 3;
44
45
46
47
48
49
50
51 public UTFlagSubGLRenderer(IRenderableWorldObject flag) {
52 this.flag = flag;
53 }
54
55 @Override
56 public void prepare(GL gl) {
57 glu = new GLU();
58 glut = new GLUT();
59 quadratic = glu.gluNewQuadric();
60
61 logger = Logger.getLogger("UTFlagRenderer");
62 logger.setLevel(Level.INFO);
63 }
64
65 @Override
66 public void render(GL gla) {
67 GL2 gl = gla.getGL2();
68
69 try {
70 Location flagLocation = flag.getLocation();
71 if (flagLocation == null) {
72 return;
73 }
74 Location center = new Location(flagLocation.x, flagLocation.y,
75 flagLocation.z);
76 GlColor color = new GlColor(flag.getColor());
77 gl.glLoadName(flag.getGLName());
78 renderFlag(gl, color, center);
79 gl.glLoadName(-1);
80
81 } catch (RuntimeException e) {
82 e.printStackTrace();
83 }
84
85 }
86
87 private void renderFlag(GL gla, GlColor color, Location position) {
88 GL2 gl = gla.getGL2();
89 gl.glPushMatrix();
90 {
91 gl.glTranslated(position.x, position.y, position.z);
92 gl.glColor4d(color.r, color.g, color.b, color.a);
93 glu.gluCylinder(quadratic, CYLINDER_RADIUS, CYLINDER_RADIUS,
94 CYLINDER_HEIGHT, CYLINDER_SLICES, CYLINDER_STACKS);
95 gl.glTranslated(0, 0, CYLINDER_HEIGHT);
96 glu.gluSphere(quadratic, SPHERE_RADIUS, SPHERE_SLICES,
97 SPHERE_STACKS);
98 }
99 gl.glPopMatrix();
100 }
101
102 @Override
103 public IRenderableWorldObject getObject() {
104 return flag;
105 }
106
107 @Override
108 public List<BlendTriangle> getBlendedTris() {
109 return new LinkedList<BlendTriangle>();
110 }
111
112 }