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.
This commit is contained in:
parent
d7dedd3baa
commit
1b468b8c22
7 changed files with 185 additions and 0 deletions
19
editor/Makefile
Normal file
19
editor/Makefile
Normal file
|
@ -0,0 +1,19 @@
|
|||
CC=gcc
|
||||
CFLAGS=-Wall
|
||||
INCLUDES=-I/usr/include/GL
|
||||
LIBS=-lglut -lGLU -lGL -lm
|
||||
|
||||
SRCDIR=src
|
||||
|
||||
all:
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c $(SRCDIR)/display.c
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c $(SRCDIR)/input.c
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c $(SRCDIR)/main.c
|
||||
|
||||
$(CC) $(CFLAGS) $(LIBS) -o ledcube-edit main.o display.o input.o
|
||||
chmod +x ledcube-edit
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
#rm -f ledcube-edit
|
||||
|
20
editor/src/config.h
Normal file
20
editor/src/config.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
|
||||
#define WINDOW_WIDTH 800
|
||||
#define WINDOW_HEIGHT 600
|
||||
|
||||
#define CUBE_SIZE 30
|
||||
#define MOVE_SPEED 5
|
||||
|
||||
#define PI 3.14159265
|
||||
|
||||
// Materials
|
||||
extern float ledOnMaterial[];
|
||||
|
||||
// Movement
|
||||
extern float lookX, lookZ;
|
||||
extern float eyePos, eyeAngle;
|
||||
|
||||
#endif
|
||||
|
40
editor/src/display.c
Normal file
40
editor/src/display.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
#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();
|
||||
}
|
||||
|
9
editor/src/display.h
Normal file
9
editor/src/display.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef _DISPLAY_H
|
||||
#define _DISPLAY_H
|
||||
|
||||
|
||||
void drawLEDCube();
|
||||
void display();
|
||||
|
||||
#endif
|
||||
|
48
editor/src/input.c
Normal file
48
editor/src/input.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <glut.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "input.h"
|
||||
|
||||
void moveCameraPosition(float direction) {
|
||||
eyePos += direction;
|
||||
if (eyePos > 360.0) eyePos = 0.0;
|
||||
|
||||
lookX = cos(eyePos * PI/180.0)*(CUBE_SIZE/2+50.0) + (CUBE_SIZE/2);
|
||||
lookZ = sin(eyePos * PI/180.0)*(CUBE_SIZE/2+50.0) + (CUBE_SIZE/2);
|
||||
}
|
||||
|
||||
void moveCameraAngle(float angle) {
|
||||
eyeAngle += angle;
|
||||
if (eyeAngle > 120) eyeAngle = 120;
|
||||
if (eyeAngle < 0) eyeAngle = 0;
|
||||
}
|
||||
|
||||
|
||||
void keyboard(unsigned char key, int x, int y) {
|
||||
switch (key) {
|
||||
case 27: // ESC
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
void keyboard_special(int key, int x, int y) {
|
||||
switch (key) {
|
||||
case GLUT_KEY_LEFT:
|
||||
moveCameraPosition(MOVE_SPEED);
|
||||
break;
|
||||
case GLUT_KEY_RIGHT:
|
||||
moveCameraPosition(MOVE_SPEED*-1);
|
||||
break;
|
||||
case GLUT_KEY_UP:
|
||||
moveCameraAngle(MOVE_SPEED);
|
||||
break;
|
||||
case GLUT_KEY_DOWN:
|
||||
moveCameraAngle(MOVE_SPEED*-1);
|
||||
}
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
11
editor/src/input.h
Normal file
11
editor/src/input.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef _INPUT_H
|
||||
#define _INPUT_H
|
||||
|
||||
void moveCameraPosition(float direction);
|
||||
void moveCameraAngle(float angle);
|
||||
|
||||
void keyboard(unsigned char key, int x, int y);
|
||||
void keyboard_special(int key, int x, int y);
|
||||
|
||||
#endif
|
||||
|
38
editor/src/main.c
Normal file
38
editor/src/main.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <glut.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "display.h"
|
||||
#include "input.h"
|
||||
|
||||
float ledOnMaterial[] = {1.0, 0.0, 0.0, 1.0};
|
||||
|
||||
float lookX = 0.0, lookZ = 0.0;
|
||||
float eyePos = 0.0, eyeAngle = 50.0;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
glutInit(&argc, argv);
|
||||
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
glutCreateWindow("CTHN LEDCube Editor");
|
||||
|
||||
glutDisplayFunc(display);
|
||||
glutKeyboardFunc(keyboard);
|
||||
glutSpecialFunc(keyboard_special);
|
||||
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
// OpenGL Features
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glutMainLoop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in a new issue