diff --git a/editor/Makefile b/editor/Makefile new file mode 100644 index 0000000..e9e50d8 --- /dev/null +++ b/editor/Makefile @@ -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 + diff --git a/editor/src/config.h b/editor/src/config.h new file mode 100644 index 0000000..737cde2 --- /dev/null +++ b/editor/src/config.h @@ -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 + diff --git a/editor/src/display.c b/editor/src/display.c new file mode 100644 index 0000000..773e278 --- /dev/null +++ b/editor/src/display.c @@ -0,0 +1,40 @@ +#include +#include + +#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(); +} + diff --git a/editor/src/display.h b/editor/src/display.h new file mode 100644 index 0000000..079f5bc --- /dev/null +++ b/editor/src/display.h @@ -0,0 +1,9 @@ +#ifndef _DISPLAY_H +#define _DISPLAY_H + + +void drawLEDCube(); +void display(); + +#endif + diff --git a/editor/src/input.c b/editor/src/input.c new file mode 100644 index 0000000..5606335 --- /dev/null +++ b/editor/src/input.c @@ -0,0 +1,48 @@ +#include +#include +#include + +#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(); +} + diff --git a/editor/src/input.h b/editor/src/input.h new file mode 100644 index 0000000..d3bc2b9 --- /dev/null +++ b/editor/src/input.h @@ -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 + diff --git a/editor/src/main.c b/editor/src/main.c new file mode 100644 index 0000000..0a90791 --- /dev/null +++ b/editor/src/main.c @@ -0,0 +1,38 @@ + +#include +#include +#include + +#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; +} +