2011-10-19 01:10:15 +02:00
|
|
|
#include <stdio.h>
|
2011-12-06 22:35:48 +01:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkgl.h>
|
|
|
|
#include <gtk/gtkgl.h>
|
|
|
|
#include <GL/glut.h>
|
2012-01-15 03:35:36 +01:00
|
|
|
#include <glade/glade.h>
|
2011-10-19 01:10:15 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "display.h"
|
|
|
|
|
2012-01-15 03:35:36 +01:00
|
|
|
#include "../firmware/globals.h"
|
|
|
|
|
|
|
|
extern void lc_setMode(int);
|
|
|
|
extern void lc_setFrame(unsigned long);
|
2012-01-15 22:43:32 +01:00
|
|
|
extern int lc_saveFrame(unsigned long frame, int delay, int index);
|
2011-10-19 01:10:15 +02:00
|
|
|
|
2011-12-27 18:48:15 +01:00
|
|
|
void drawLEDs(gint mode) {
|
|
|
|
gint x, y, z;
|
|
|
|
gint ledIndex = 0;
|
2012-01-15 22:43:32 +01:00
|
|
|
gint iLED = 0;
|
2011-10-20 20:28:00 +02:00
|
|
|
|
2011-10-31 00:25:07 +01:00
|
|
|
if (ledOrientation == TOP_ORIENTATION) {
|
2011-10-23 21:43:54 +02:00
|
|
|
glRotatef(90, 2, 0, 0);
|
|
|
|
}
|
|
|
|
|
2012-01-15 03:35:36 +01: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-31 00:25:07 +01:00
|
|
|
ledIndex++;
|
2011-10-30 23:55:53 +01:00
|
|
|
if (mode == PICKING_MODE) {
|
2011-10-31 00:25:07 +01:00
|
|
|
glColor3ub(0, 0, ledIndex*8);
|
2011-10-30 23:55:53 +01:00
|
|
|
} else {
|
2012-01-15 22:43:32 +01:00
|
|
|
iLED = animation[currentFrame][ledIndex-1];
|
|
|
|
glMaterialfv(GL_FRONT, GL_AMBIENT, (iLED == 1 ? ledOnMaterial : ledOffMaterial));
|
|
|
|
glMaterialfv(GL_FRONT, GL_DIFFUSE, (iLED == 1 ? ledOnMaterial : ledOffMaterial));
|
2011-10-30 23:55:53 +01:00
|
|
|
}
|
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() {
|
2011-12-27 18:48:15 +01:00
|
|
|
gint x, y;
|
2012-01-15 03:35:36 +01: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-12-22 01:07:43 +01:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2011-10-19 01:10:15 +02:00
|
|
|
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
|
2011-12-21 22:58:57 +01:00
|
|
|
void display(gboolean onlyForPicking) {
|
2011-12-06 22:35:48 +01:00
|
|
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
|
|
|
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor);
|
|
|
|
|
2011-10-30 23:55:53 +01:00
|
|
|
setScene();
|
2011-10-19 01:10:15 +02:00
|
|
|
|
2011-12-21 22:58:57 +01:00
|
|
|
if (onlyForPicking == TRUE) {
|
|
|
|
glDisable(GL_DITHER);
|
|
|
|
glDisable(GL_LIGHTING);
|
2011-10-30 23:55:53 +01:00
|
|
|
|
2011-12-21 22:58:57 +01:00
|
|
|
drawLEDs(PICKING_MODE);
|
2011-10-30 23:55:53 +01:00
|
|
|
|
2011-12-21 22:58:57 +01:00
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_DITHER);
|
|
|
|
} else {
|
|
|
|
drawLEDs(RENDER_MODE);
|
2011-12-22 01:07:43 +01:00
|
|
|
drawWires();
|
2011-12-21 22:58:57 +01:00
|
|
|
}
|
2011-10-30 23:55:53 +01:00
|
|
|
}
|
|
|
|
|
2012-01-15 03:35:36 +01:00
|
|
|
|
|
|
|
void displayCurrentFrame() {
|
|
|
|
int i;
|
|
|
|
unsigned long frame = 0;
|
|
|
|
for (i=0; i<27; ++i) {
|
2012-01-15 22:43:32 +01:00
|
|
|
if (animation[currentFrame][i] == 1) frame |= (1 << i);
|
2012-01-15 03:35:36 +01:00
|
|
|
}
|
|
|
|
lc_setMode(MODE_ANIMATION_STOP);
|
|
|
|
lc_setFrame(frame);
|
|
|
|
}
|
|
|
|
|
2012-01-15 22:43:32 +01:00
|
|
|
void uploadAnimation() {
|
|
|
|
int i, j;
|
|
|
|
unsigned long frame = 0;
|
|
|
|
int delay = 0; // TODO: Implement the delay
|
|
|
|
int skip = 1; // Skip
|
|
|
|
|
|
|
|
// Maximum delay
|
|
|
|
for (i=0; i<5; ++i) delay |= (1 << i);
|
|
|
|
|
|
|
|
lc_setMode(MODE_ANIMATION_STOP);
|
|
|
|
for (i=0; i<32; ++i) {
|
|
|
|
frame = 0;
|
|
|
|
for (j=0; j<27; ++j) {
|
|
|
|
if (animation[i][j] == 1) frame |= (1 << j);
|
|
|
|
}
|
|
|
|
|
|
|
|
lc_saveFrame(frame, (i<animationLength ? delay : skip), i);
|
|
|
|
}
|
|
|
|
lc_setMode(MODE_ANIMATION_LOOP);
|
|
|
|
}
|
|
|
|
|