Fix the "zoom" problem and add some wires in between.
This commit is contained in:
parent
1b468b8c22
commit
dc6b4346ce
4 changed files with 69 additions and 18 deletions
|
@ -5,16 +5,22 @@
|
|||
#define WINDOW_HEIGHT 600
|
||||
|
||||
#define CUBE_SIZE 30
|
||||
#define MOVE_SPEED 5
|
||||
#define MOVE_SPEED 7
|
||||
#define ZOOM_LEVEL 25
|
||||
|
||||
#define PI 3.14159265
|
||||
#define PI 3.1415926535897932
|
||||
|
||||
// Materials
|
||||
extern float ledOnMaterial[];
|
||||
extern float wireMaterial[];
|
||||
extern float innerWireMaterial[];
|
||||
|
||||
// Movement
|
||||
extern float lookX, lookZ;
|
||||
extern float eyePos, eyeAngle;
|
||||
|
||||
// Objects
|
||||
extern GLUquadricObj *quadric;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -4,22 +4,49 @@
|
|||
#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
|
||||
|
||||
// LEDs
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, 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
|
||||
glPushMatrix();
|
||||
glTranslatef(x*space, y*space, z*space);
|
||||
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(
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
||||
// Front
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(x, y, -10);
|
||||
glVertex3f(x, y, 10);
|
||||
glEnd();
|
||||
|
||||
// Side
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(-10, x, y);
|
||||
glVertex3f(10, x, y);
|
||||
glEnd();
|
||||
|
||||
// Top
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(x, -10, y);
|
||||
glVertex3f(x, 10, y);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void display() {
|
||||
|
@ -27,12 +54,11 @@ void display() {
|
|||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0, 250.0);
|
||||
gluPerspective(ZOOM_LEVEL, WINDOW_WIDTH/WINDOW_HEIGHT, 1.0, 350.0);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
moveCameraPosition(0.0);
|
||||
gluLookAt(lookX, eyeAngle, lookZ, CUBE_SIZE/2, 6.0, CUBE_SIZE/2, 0, 1, 0);
|
||||
gluLookAt(lookX, eyeAngle, lookZ, 0, 0, 0, 0, 1, 0);
|
||||
|
||||
drawLEDCube();
|
||||
glutSwapBuffers();
|
||||
|
|
|
@ -9,8 +9,8 @@ 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);
|
||||
lookX = sin(eyePos * PI/180.0)*70.0;
|
||||
lookZ = cos(eyePos * PI/180.0)*70.0;
|
||||
}
|
||||
|
||||
void moveCameraAngle(float angle) {
|
||||
|
|
|
@ -7,10 +7,20 @@
|
|||
#include "display.h"
|
||||
#include "input.h"
|
||||
|
||||
float ledOnMaterial[] = {1.0, 0.0, 0.0, 1.0};
|
||||
float ledOnMaterial[] = {0.0, 0.0, 1.0, 1.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 lookX = 0.0, lookZ = 0.0;
|
||||
float eyePos = 0.0, eyeAngle = 50.0;
|
||||
float eyePos = 0.0, eyeAngle = 45.0;
|
||||
|
||||
GLUquadricObj *quadric;
|
||||
|
||||
extern void moveCameraPosition(float direction);
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
glutInit(&argc, argv);
|
||||
|
@ -30,7 +40,16 @@ int main(int argc, char* argv[]) {
|
|||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
moveCameraPosition(0); // Init the Position
|
||||
|
||||
|
||||
quadric = gluNewQuadric();
|
||||
gluQuadricNormals(quadric, GLU_SMOOTH);
|
||||
gluQuadricDrawStyle(quadric, GLU_FILL);
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue