Correct some lighting and make real LED models.
This commit is contained in:
parent
c8e496195f
commit
5335603b15
3 changed files with 36 additions and 17 deletions
|
@ -2,7 +2,7 @@
|
||||||
#define _CONFIG_H
|
#define _CONFIG_H
|
||||||
|
|
||||||
#define WINDOW_WIDTH 800
|
#define WINDOW_WIDTH 800
|
||||||
#define WINDOW_HEIGHT 600
|
#define WINDOW_HEIGHT 800
|
||||||
|
|
||||||
#define CUBE_SIZE 30
|
#define CUBE_SIZE 30
|
||||||
#define MOVE_SPEED 7
|
#define MOVE_SPEED 7
|
||||||
|
@ -10,8 +10,12 @@
|
||||||
|
|
||||||
#define PI 3.1415926535897932
|
#define PI 3.1415926535897932
|
||||||
|
|
||||||
|
#define TOP_ORIENTATION 1
|
||||||
|
#define SIDE_ORIENTATION 2
|
||||||
|
|
||||||
// Materials
|
// Materials
|
||||||
extern float ledOnMaterial[];
|
extern float ledOnMaterial[];
|
||||||
|
extern float ledOffMaterial[];
|
||||||
extern float wireMaterial[];
|
extern float wireMaterial[];
|
||||||
extern float innerWireMaterial[];
|
extern float innerWireMaterial[];
|
||||||
|
|
||||||
|
|
|
@ -5,21 +5,33 @@
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
|
|
||||||
void drawLEDCube() {
|
void drawLEDCube(orientation) {
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
|
|
||||||
|
if (orientation == TOP_ORIENTATION) {
|
||||||
|
glRotatef(90, 2, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// LEDs
|
// LEDs
|
||||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, ledOnMaterial);
|
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
|
||||||
|
|
||||||
|
// TODO: Test different colors
|
||||||
|
glMaterialfv(GL_FRONT, GL_AMBIENT, (z == 0 ? ledOnMaterial : ledOffMaterial));
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(x, y, z);
|
glTranslatef(x, y, z-0.8);
|
||||||
glutSolidSphere(1.0, 16, 16);
|
glutSolidSphere(1, 16, 16);
|
||||||
gluCylinder(quadric, 1.0, 1.0, 1.3, 16, 2);
|
gluCylinder(quadric, 1, 1, 1.9, 16, 2);
|
||||||
//glTranslatef(x, y, z+0.8);
|
|
||||||
//gluCylinder(quadric, 1.3, 1.3, 0.2, 16, 2);
|
glTranslatef(0, 0, 1.9);
|
||||||
//gluDisk(
|
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();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
@ -27,7 +39,7 @@ void drawLEDCube() {
|
||||||
// Wires
|
// Wires
|
||||||
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_DIFFUSE, ((x == 0 || y == 0) ? innerWireMaterial : wireMaterial));
|
glMaterialfv(GL_FRONT, GL_AMBIENT, ((x == 0 || y == 0) ? innerWireMaterial : wireMaterial));
|
||||||
|
|
||||||
// Front
|
// Front
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
|
@ -60,7 +72,7 @@ void display() {
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt(lookX, eyeAngle, lookZ, 0, 0, 0, 0, 1, 0);
|
gluLookAt(lookX, eyeAngle, lookZ, 0, 0, 0, 0, 1, 0);
|
||||||
|
|
||||||
drawLEDCube();
|
drawLEDCube(TOP_ORIENTATION);
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,13 @@
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
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 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};
|
||||||
|
|
||||||
float light_diffuse[] = {0.0, 0.0, 1.0, 1.0};
|
float backgroundColor[] = {0.3, 0.3, 0.3, 0.4};
|
||||||
float light_position[] = {1.0, 1.0, 1.0, 0.0};
|
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;
|
||||||
|
@ -36,12 +37,14 @@ int main(int argc, char* argv[]) {
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
|
|
||||||
// OpenGL Features
|
// Lighting
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glEnable(GL_LIGHT0);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
glEnable(GL_LIGHT0);
|
||||||
|
glLightfv(GL_LIGHT0, GL_POSITION, light0Pos);
|
||||||
|
glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor);
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
moveCameraPosition(0); // Init the Position
|
moveCameraPosition(0); // Init the Position
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue