2011-10-19 01:10:15 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <glut.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "display.h"
|
|
|
|
|
|
|
|
|
2011-10-30 23:55:53 +01:00
|
|
|
void drawLEDs(int orientation, int mode) {
|
2011-10-19 01:10:15 +02:00
|
|
|
int x, y, z;
|
2011-10-30 23:55:53 +01:00
|
|
|
int colorIndex = 0;
|
2011-10-20 20:28:00 +02:00
|
|
|
|
2011-10-23 21:43:54 +02:00
|
|
|
if (orientation == TOP_ORIENTATION) {
|
|
|
|
glRotatef(90, 2, 0, 0);
|
|
|
|
}
|
|
|
|
|
2011-10-20 20:28:00 +02:00
|
|
|
for (z=-10; z<=10; z+=10) // Ebene
|
|
|
|
for (y=-10; y<=10; y+=10) // Zeile
|
|
|
|
for (x=-10; x<=10; x+=10) { // Spalte
|
2011-10-30 23:55:53 +01:00
|
|
|
if (mode == PICKING_MODE) {
|
|
|
|
glColor3ub(0, 0, colorIndex*8);
|
|
|
|
colorIndex++;
|
|
|
|
} else {
|
|
|
|
glMaterialfv(GL_FRONT, GL_AMBIENT, (z == 0 ? ledOnMaterial : ledOffMaterial));
|
|
|
|
}
|
2011-10-23 21:43:54 +02:00
|
|
|
|
2011-10-19 01:10:15 +02:00
|
|
|
glPushMatrix();
|
2011-10-23 21:43:54 +02:00
|
|
|
glTranslatef(x, y, z-0.8);
|
|
|
|
glutSolidSphere(1, 16, 16);
|
|
|
|
gluCylinder(quadric, 1, 1, 1.9, 16, 2);
|
|
|
|
|
|
|
|
glTranslatef(0, 0, 1.9);
|
|
|
|
gluCylinder(quadric, 1.25, 1.25, 0.35, 16, 2);
|
|
|
|
|
|
|
|
gluDisk(quadric, 0, 1.25, 16, 16);
|
|
|
|
glTranslatef(0, 0, 0.35);
|
|
|
|
gluDisk(quadric, 0, 1.25, 16, 16);
|
2011-10-20 20:28:00 +02:00
|
|
|
|
2011-10-19 01:10:15 +02:00
|
|
|
glPopMatrix();
|
|
|
|
}
|
2011-10-30 23:55:53 +01:00
|
|
|
}
|
2011-10-20 20:28:00 +02:00
|
|
|
|
2011-10-30 23:55:53 +01:00
|
|
|
void drawWires() {
|
|
|
|
int x, y;
|
2011-10-20 20:28:00 +02:00
|
|
|
for (y=-10; y<=10; y+=10)
|
|
|
|
for (x=-10; x<=10; x+=10) {
|
2011-10-23 21:43:54 +02:00
|
|
|
glMaterialfv(GL_FRONT, GL_AMBIENT, ((x == 0 || y == 0) ? innerWireMaterial : wireMaterial));
|
2011-10-20 20:28:00 +02:00
|
|
|
|
|
|
|
// Front
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3f(x, y, -10);
|
|
|
|
glVertex3f(x, y, 10);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// Side
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3f(-10, x, y);
|
|
|
|
glVertex3f(10, x, y);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// Top
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3f(x, -10, y);
|
|
|
|
glVertex3f(x, 10, y);
|
|
|
|
glEnd();
|
|
|
|
}
|
2011-10-19 01:10:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-30 23:55:53 +01:00
|
|
|
void setScene() {
|
2011-10-19 01:10:15 +02:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
2011-10-20 20:28:00 +02:00
|
|
|
gluPerspective(ZOOM_LEVEL, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0, 350.0);
|
2011-10-19 01:10:15 +02:00
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
2011-10-20 20:28:00 +02:00
|
|
|
gluLookAt(lookX, eyeAngle, lookZ, 0, 0, 0, 0, 1, 0);
|
2011-10-30 23:55:53 +01:00
|
|
|
}
|
2011-10-19 01:10:15 +02:00
|
|
|
|
2011-10-30 23:55:53 +01:00
|
|
|
// OpenGL Display function
|
|
|
|
void display() {
|
|
|
|
setScene();
|
|
|
|
drawLEDs(TOP_ORIENTATION, RENDER_MODE);
|
|
|
|
drawWires();
|
2011-10-19 01:10:15 +02:00
|
|
|
glutSwapBuffers();
|
|
|
|
}
|
|
|
|
|
2011-10-30 23:55:53 +01:00
|
|
|
// Picking function
|
|
|
|
void displayPickingObjects() {
|
|
|
|
setScene();
|
|
|
|
glDisable(GL_DITHER);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
|
|
|
|
drawLEDs(TOP_ORIENTATION, PICKING_MODE);
|
|
|
|
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_DITHER);
|
|
|
|
}
|
|
|
|
|