mini-led-cube/editor/src/display.c
Aaron Mueller 1b468b8c22 Start implementing a 3D GUI to configure the cube.
The idea is to use OpenGL and some simple C code to display a 3D cube.
With the mouse you can define which LED should be on or off on a
particular frame. With this technique, you can define whole sequences of
frames to form animations.
2011-10-19 01:10:15 +02:00

41 lines
903 B
C

#include <stdio.h>
#include <glut.h>
#include "config.h"
#include "display.h"
extern void moveCameraPosition(float direction);
void drawLEDCube() {
glMatrixMode(GL_MODELVIEW);
glMaterialfv(GL_FRONT, GL_DIFFUSE, ledOnMaterial);
int x, y, z;
float space = 10.0;
for (z=0; z<3; ++z) // Ebene
for (y=0; y<3; ++y) // Zeile
for (x=0; x<3; ++x) { // Spalte
glPushMatrix();
glTranslatef(x*space, y*space, z*space);
glutSolidSphere(1.0, 16, 16);
glPopMatrix();
}
}
void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0, 250.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
moveCameraPosition(0.0);
gluLookAt(lookX, eyeAngle, lookZ, CUBE_SIZE/2, 6.0, CUBE_SIZE/2, 0, 1, 0);
drawLEDCube();
glutSwapBuffers();
}