Implement the LED voltage switch.
LEDs can now be switched on or off with the mouse. The current state of the LEd cube is saved in a array which can be easily printed out to STDOUT.
This commit is contained in:
parent
8e91376491
commit
2694d9988f
5 changed files with 33 additions and 16 deletions
|
@ -26,9 +26,13 @@ extern float innerWireMaterial[];
|
|||
// Movement
|
||||
extern float lookX, lookZ;
|
||||
extern float eyePos, eyeAngle;
|
||||
extern int ledOrientation;
|
||||
|
||||
// Objects
|
||||
extern GLUquadricObj *quadric;
|
||||
|
||||
// LED data
|
||||
extern int currentFrame[27];
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -5,22 +5,22 @@
|
|||
#include "display.h"
|
||||
|
||||
|
||||
void drawLEDs(int orientation, int mode) {
|
||||
void drawLEDs(int mode) {
|
||||
int x, y, z;
|
||||
int colorIndex = 0;
|
||||
int ledIndex = 0;
|
||||
|
||||
if (orientation == TOP_ORIENTATION) {
|
||||
if (ledOrientation == TOP_ORIENTATION) {
|
||||
glRotatef(90, 2, 0, 0);
|
||||
}
|
||||
|
||||
for (z=-10; z<=10; z+=10) // Ebene
|
||||
for (y=-10; y<=10; y+=10) // Zeile
|
||||
for (x=-10; x<=10; x+=10) { // Spalte
|
||||
ledIndex++;
|
||||
if (mode == PICKING_MODE) {
|
||||
glColor3ub(0, 0, colorIndex*8);
|
||||
colorIndex++;
|
||||
glColor3ub(0, 0, ledIndex*8);
|
||||
} else {
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT, (z == 0 ? ledOnMaterial : ledOffMaterial));
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT, (currentFrame[ledIndex-1] == 1 ? ledOnMaterial : ledOffMaterial));
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
|
@ -79,7 +79,7 @@ void setScene() {
|
|||
// OpenGL Display function
|
||||
void display() {
|
||||
setScene();
|
||||
drawLEDs(TOP_ORIENTATION, RENDER_MODE);
|
||||
drawLEDs(RENDER_MODE);
|
||||
drawWires();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ void displayPickingObjects() {
|
|||
glDisable(GL_DITHER);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
drawLEDs(TOP_ORIENTATION, PICKING_MODE);
|
||||
drawLEDs(PICKING_MODE);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_DITHER);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _DISPLAY_H
|
||||
|
||||
|
||||
void drawLEDs(int orientation, int mode);
|
||||
void drawLEDs(int mode);
|
||||
void drawWires();
|
||||
|
||||
void display();
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "input.h"
|
||||
#include "display.h"
|
||||
|
||||
|
||||
void moveCameraPosition(float direction) {
|
||||
eyePos += direction;
|
||||
if (eyePos > 360.0) eyePos = 0.0;
|
||||
|
@ -49,14 +50,20 @@ void keyboard_special(int key, int x, int y) {
|
|||
|
||||
void mouse(int button, int state, int x, int y) {
|
||||
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
|
||||
int viewport[4];
|
||||
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);
|
||||
printf("%d\n", pixel[2]/8); // Selected LED
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <glut.h>
|
||||
|
@ -7,28 +6,35 @@
|
|||
#include "display.h"
|
||||
#include "input.h"
|
||||
|
||||
|
||||
// Materials
|
||||
float ledOnMaterial[] = {0.0, 0.0, 1.0, 1.0};
|
||||
float ledOffMaterial[] = {0.1, 0.1, 0.1, 0.0};
|
||||
|
||||
float wireMaterial[] = {0.7, 0.7, 0.7, 1.0};
|
||||
float innerWireMaterial[] = {0.2, 0.2, 0.2, 0.3};
|
||||
|
||||
// Colors
|
||||
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 eyePos = 0.0, eyeAngle = 45.0;
|
||||
int ledOrientation = TOP_ORIENTATION;
|
||||
|
||||
// Objects
|
||||
GLUquadricObj *quadric;
|
||||
|
||||
extern void moveCameraPosition(float direction);
|
||||
// LED data
|
||||
int currentFrame[27] = {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");
|
||||
glutCreateWindow("CTHN LEDCube Editor v0.1");
|
||||
|
||||
glutDisplayFunc(display);
|
||||
glutKeyboardFunc(keyboard);
|
||||
|
|
Loading…
Reference in a new issue