From 5335603b151d07df55e4d3650c5c261cd8102995 Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Sun, 23 Oct 2011 21:43:54 +0200 Subject: [PATCH] Correct some lighting and make real LED models. --- editor/src/config.h | 6 +++++- editor/src/display.c | 32 ++++++++++++++++++++++---------- editor/src/main.c | 15 +++++++++------ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/editor/src/config.h b/editor/src/config.h index 6f7c629..dfe7447 100644 --- a/editor/src/config.h +++ b/editor/src/config.h @@ -2,7 +2,7 @@ #define _CONFIG_H #define WINDOW_WIDTH 800 -#define WINDOW_HEIGHT 600 +#define WINDOW_HEIGHT 800 #define CUBE_SIZE 30 #define MOVE_SPEED 7 @@ -10,8 +10,12 @@ #define PI 3.1415926535897932 +#define TOP_ORIENTATION 1 +#define SIDE_ORIENTATION 2 + // Materials extern float ledOnMaterial[]; +extern float ledOffMaterial[]; extern float wireMaterial[]; extern float innerWireMaterial[]; diff --git a/editor/src/display.c b/editor/src/display.c index d2c7e49..d5ec987 100644 --- a/editor/src/display.c +++ b/editor/src/display.c @@ -5,21 +5,33 @@ #include "display.h" -void drawLEDCube() { +void drawLEDCube(orientation) { int x, y, z; + if (orientation == TOP_ORIENTATION) { + glRotatef(90, 2, 0, 0); + } + // LEDs - glMaterialfv(GL_FRONT, GL_DIFFUSE, ledOnMaterial); + glMaterialfv(GL_FRONT, GL_AMBIENT, ledOnMaterial); for (z=-10; z<=10; z+=10) // Ebene for (y=-10; y<=10; y+=10) // Zeile for (x=-10; x<=10; x+=10) { // Spalte + + // TODO: Test different colors + glMaterialfv(GL_FRONT, GL_AMBIENT, (z == 0 ? ledOnMaterial : ledOffMaterial)); + glPushMatrix(); - glTranslatef(x, y, z); - glutSolidSphere(1.0, 16, 16); - gluCylinder(quadric, 1.0, 1.0, 1.3, 16, 2); - //glTranslatef(x, y, z+0.8); - //gluCylinder(quadric, 1.3, 1.3, 0.2, 16, 2); - //gluDisk( + glTranslatef(x, y, z-0.8); + glutSolidSphere(1, 16, 16); + gluCylinder(quadric, 1, 1, 1.9, 16, 2); + + glTranslatef(0, 0, 1.9); + gluCylinder(quadric, 1.25, 1.25, 0.35, 16, 2); + + gluDisk(quadric, 0, 1.25, 16, 16); + glTranslatef(0, 0, 0.35); + gluDisk(quadric, 0, 1.25, 16, 16); glPopMatrix(); } @@ -27,7 +39,7 @@ void drawLEDCube() { // Wires for (y=-10; y<=10; y+=10) for (x=-10; x<=10; x+=10) { - glMaterialfv(GL_FRONT, GL_DIFFUSE, ((x == 0 || y == 0) ? innerWireMaterial : wireMaterial)); + glMaterialfv(GL_FRONT, GL_AMBIENT, ((x == 0 || y == 0) ? innerWireMaterial : wireMaterial)); // Front glBegin(GL_LINES); @@ -60,7 +72,7 @@ void display() { glLoadIdentity(); gluLookAt(lookX, eyeAngle, lookZ, 0, 0, 0, 0, 1, 0); - drawLEDCube(); + drawLEDCube(TOP_ORIENTATION); glutSwapBuffers(); } diff --git a/editor/src/main.c b/editor/src/main.c index 4ca1c76..d0f9eaf 100644 --- a/editor/src/main.c +++ b/editor/src/main.c @@ -8,12 +8,13 @@ #include "input.h" 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}; -float light_diffuse[] = {0.0, 0.0, 1.0, 1.0}; -float light_position[] = {1.0, 1.0, 1.0, 0.0}; - +float backgroundColor[] = {0.3, 0.3, 0.3, 0.4}; +float light0Pos[] = {70, 70, 70, 0.0}; float lookX = 0.0, lookZ = 0.0; float eyePos = 0.0, eyeAngle = 45.0; @@ -36,12 +37,14 @@ int main(int argc, char* argv[]) { glClearColor(0.0, 0.0, 0.0, 1.0); glShadeModel(GL_SMOOTH); - // OpenGL Features + // Lighting glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0, GL_POSITION, light0Pos); + glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor); + glMatrixMode(GL_MODELVIEW); moveCameraPosition(0); // Init the Position