Merge branch 'USB' of github.com:klaute/Cthn.de-MiniLEDCube into USB
This commit is contained in:
commit
8ba8455abe
7 changed files with 83 additions and 19 deletions
|
@ -12,6 +12,7 @@ all:
|
||||||
|
|
||||||
$(CC) $(CFLAGS) $(LIBS) -o ledcube-edit main.o display.o input.o
|
$(CC) $(CFLAGS) $(LIBS) -o ledcube-edit main.o display.o input.o
|
||||||
chmod +x ledcube-edit
|
chmod +x ledcube-edit
|
||||||
|
strip ledcube-edit
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
|
|
|
@ -10,8 +10,12 @@
|
||||||
|
|
||||||
#define PI 3.1415926535897932
|
#define PI 3.1415926535897932
|
||||||
|
|
||||||
#define TOP_ORIENTATION 1
|
// Poor Man's enums
|
||||||
#define SIDE_ORIENTATION 2
|
#define TOP_ORIENTATION 0x01
|
||||||
|
#define SIDE_ORIENTATION 0x02
|
||||||
|
|
||||||
|
#define RENDER_MODE 0x01
|
||||||
|
#define PICKING_MODE 0x02
|
||||||
|
|
||||||
// Materials
|
// Materials
|
||||||
extern float ledOnMaterial[];
|
extern float ledOnMaterial[];
|
||||||
|
@ -22,9 +26,13 @@ extern float innerWireMaterial[];
|
||||||
// Movement
|
// Movement
|
||||||
extern float lookX, lookZ;
|
extern float lookX, lookZ;
|
||||||
extern float eyePos, eyeAngle;
|
extern float eyePos, eyeAngle;
|
||||||
|
extern int ledOrientation;
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
extern GLUquadricObj *quadric;
|
extern GLUquadricObj *quadric;
|
||||||
|
|
||||||
|
// LED data
|
||||||
|
extern int currentFrame[27];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -5,21 +5,23 @@
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
|
|
||||||
void drawLEDCube(orientation) {
|
void drawLEDs(int mode) {
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
|
int ledIndex = 0;
|
||||||
|
|
||||||
if (orientation == TOP_ORIENTATION) {
|
if (ledOrientation == TOP_ORIENTATION) {
|
||||||
glRotatef(90, 2, 0, 0);
|
glRotatef(90, 2, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// LEDs
|
|
||||||
glMaterialfv(GL_FRONT, GL_AMBIENT, ledOnMaterial);
|
|
||||||
for (z=-10; z<=10; z+=10) // Ebene
|
for (z=-10; z<=10; z+=10) // Ebene
|
||||||
for (y=-10; y<=10; y+=10) // Zeile
|
for (y=-10; y<=10; y+=10) // Zeile
|
||||||
for (x=-10; x<=10; x+=10) { // Spalte
|
for (x=-10; x<=10; x+=10) { // Spalte
|
||||||
|
ledIndex++;
|
||||||
// TODO: Test different colors
|
if (mode == PICKING_MODE) {
|
||||||
glMaterialfv(GL_FRONT, GL_AMBIENT, (z == 0 ? ledOnMaterial : ledOffMaterial));
|
glColor3ub(0, 0, ledIndex*8);
|
||||||
|
} else {
|
||||||
|
glMaterialfv(GL_FRONT, GL_AMBIENT, (currentFrame[ledIndex-1] == 1 ? ledOnMaterial : ledOffMaterial));
|
||||||
|
}
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(x, y, z-0.8);
|
glTranslatef(x, y, z-0.8);
|
||||||
|
@ -35,8 +37,10 @@ void drawLEDCube(orientation) {
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Wires
|
void drawWires() {
|
||||||
|
int x, y;
|
||||||
for (y=-10; y<=10; y+=10)
|
for (y=-10; y<=10; y+=10)
|
||||||
for (x=-10; x<=10; x+=10) {
|
for (x=-10; x<=10; x+=10) {
|
||||||
glMaterialfv(GL_FRONT, GL_AMBIENT, ((x == 0 || y == 0) ? innerWireMaterial : wireMaterial));
|
glMaterialfv(GL_FRONT, GL_AMBIENT, ((x == 0 || y == 0) ? innerWireMaterial : wireMaterial));
|
||||||
|
@ -61,9 +65,8 @@ void drawLEDCube(orientation) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void display() {
|
void setScene() {
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(ZOOM_LEVEL, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0, 350.0);
|
gluPerspective(ZOOM_LEVEL, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0, 350.0);
|
||||||
|
@ -71,8 +74,25 @@ void display() {
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt(lookX, eyeAngle, lookZ, 0, 0, 0, 0, 1, 0);
|
gluLookAt(lookX, eyeAngle, lookZ, 0, 0, 0, 0, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
drawLEDCube(TOP_ORIENTATION);
|
// OpenGL Display function
|
||||||
|
void display() {
|
||||||
|
setScene();
|
||||||
|
drawLEDs(RENDER_MODE);
|
||||||
|
drawWires();
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Picking function
|
||||||
|
void displayPickingObjects() {
|
||||||
|
setScene();
|
||||||
|
glDisable(GL_DITHER);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
|
drawLEDs(PICKING_MODE);
|
||||||
|
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glEnable(GL_DITHER);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,13 @@
|
||||||
#define _DISPLAY_H
|
#define _DISPLAY_H
|
||||||
|
|
||||||
|
|
||||||
void drawLEDCube();
|
void drawLEDs(int mode);
|
||||||
|
void drawWires();
|
||||||
|
|
||||||
void display();
|
void display();
|
||||||
|
void displayPickingObjects();
|
||||||
|
|
||||||
|
void setScene();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
#include "display.h"
|
||||||
|
|
||||||
|
|
||||||
void moveCameraPosition(float direction) {
|
void moveCameraPosition(float direction) {
|
||||||
eyePos += direction;
|
eyePos += direction;
|
||||||
|
@ -46,3 +48,22 @@ void keyboard_special(int key, int x, int y) {
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mouse(int button, int state, int x, int y) {
|
||||||
|
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
|
||||||
|
int position, viewport[4];
|
||||||
|
GLubyte pixel[3];
|
||||||
|
|
||||||
|
displayPickingObjects();
|
||||||
|
|
||||||
|
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||||
|
glReadPixels(x, viewport[3]-y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, (void*)pixel);
|
||||||
|
position = ((int)pixel[2]/8)-1; // Selected LED
|
||||||
|
|
||||||
|
printf("%d\n", position);
|
||||||
|
currentFrame[position] = currentFrame[position] == 0 ? 1 : 0;
|
||||||
|
printf("%d\n", currentFrame[position]);
|
||||||
|
|
||||||
|
display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,5 +7,7 @@ void moveCameraAngle(float angle);
|
||||||
void keyboard(unsigned char key, int x, int y);
|
void keyboard(unsigned char key, int x, int y);
|
||||||
void keyboard_special(int key, int x, int y);
|
void keyboard_special(int key, int x, int y);
|
||||||
|
|
||||||
|
void mouse(int button, int state, int x, int y);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <glut.h>
|
#include <glut.h>
|
||||||
|
@ -7,32 +6,40 @@
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
|
|
||||||
|
// Materials
|
||||||
float ledOnMaterial[] = {0.0, 0.0, 1.0, 1.0};
|
float ledOnMaterial[] = {0.0, 0.0, 1.0, 1.0};
|
||||||
float ledOffMaterial[] = {0.1, 0.1, 0.1, 0.0};
|
float ledOffMaterial[] = {0.1, 0.1, 0.1, 0.0};
|
||||||
|
|
||||||
float wireMaterial[] = {0.7, 0.7, 0.7, 1.0};
|
float wireMaterial[] = {0.7, 0.7, 0.7, 1.0};
|
||||||
float innerWireMaterial[] = {0.2, 0.2, 0.2, 0.3};
|
float innerWireMaterial[] = {0.2, 0.2, 0.2, 0.3};
|
||||||
|
|
||||||
|
// Colors
|
||||||
float backgroundColor[] = {0.3, 0.3, 0.3, 0.4};
|
float backgroundColor[] = {0.3, 0.3, 0.3, 0.4};
|
||||||
float light0Pos[] = {70, 70, 70, 0.0};
|
|
||||||
|
|
||||||
|
// Positions
|
||||||
|
float light0Pos[] = {70, 70, 70, 0.0};
|
||||||
float lookX = 0.0, lookZ = 0.0;
|
float lookX = 0.0, lookZ = 0.0;
|
||||||
float eyePos = 0.0, eyeAngle = 45.0;
|
float eyePos = 0.0, eyeAngle = 45.0;
|
||||||
|
int ledOrientation = TOP_ORIENTATION;
|
||||||
|
|
||||||
|
// Objects
|
||||||
GLUquadricObj *quadric;
|
GLUquadricObj *quadric;
|
||||||
|
|
||||||
extern void moveCameraPosition(float direction);
|
// LED data
|
||||||
|
int currentFrame[27] = {0};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
|
|
||||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||||
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
|
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||||
glutCreateWindow("CTHN LEDCube Editor");
|
glutCreateWindow("CTHN LEDCube Editor v0.1");
|
||||||
|
|
||||||
glutDisplayFunc(display);
|
glutDisplayFunc(display);
|
||||||
glutKeyboardFunc(keyboard);
|
glutKeyboardFunc(keyboard);
|
||||||
glutSpecialFunc(keyboard_special);
|
glutSpecialFunc(keyboard_special);
|
||||||
|
glutMouseFunc(mouse);
|
||||||
|
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
|
|
Loading…
Reference in a new issue