Explorar o código

adaptations and modernizations

Thomas Salm hai 9 meses
pai
achega
0313156ebf
Modificáronse 8 ficheiros con 79 adicións e 23 borrados
  1. 2 0
      .gitignore
  2. 25 0
      Makefile
  3. 14 1
      README.md
  4. 4 4
      src/propeller.cpp
  5. 2 2
      src/spirale.cpp
  6. 2 2
      src/stern.cpp
  7. 23 9
      src/uhr_main.cpp
  8. 7 5
      src/zifferblatt.cpp

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+bin/
+build/

+ 25 - 0
Makefile

@@ -0,0 +1,25 @@
+CXX = g++
+CXXFLAGS = -Wall -std=c++11 -g
+
+LIBS = -lGL -lGLU -lglut
+
+SRCDIR = src
+BUILDDIR = build
+BINDIR = bin
+
+SRCS = $(wildcard $(SRCDIR)/*.cpp)
+OBJS = $(patsubst $(SRCDIR)/%.cpp, $(BUILDDIR)/%.o, $(SRCS))
+TARGET = $(BINDIR)/uhr_programm
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+	@mkdir -p $(BINDIR)
+	$(CXX) $(OBJS) -o $(TARGET) $(LIBS)
+
+$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
+	@mkdir -p $(BUILDDIR)
+	$(CXX) $(CXXFLAGS) -c $< -o $@
+
+clean:
+	rm -rf $(BUILDDIR) $(BINDIR)

+ 14 - 1
README.md

@@ -1 +1,14 @@
-# OpenGL Uhr (GDV 2 Praktikum 2004)
+# OpenGL Uhr (GDV 2 Praktikum 2004)
+
+## Install requirements
+
+```sh
+sudo apt install build-essential freeglut3-dev libgl1-mesa-dev libglu1-mesa-dev
+```
+
+## Usage
+
+```sh
+make
+./bin/uhr_programm
+```

+ 4 - 4
src/propeller.cpp

@@ -31,7 +31,7 @@ void propeller()
 	glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
 	glVertex3f(0.0f, 0.1f, 0.0f);
 	//glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
-	for(i = 0; i<=72; i++)
+	for(int i = 0; i<=72; i++)
 		glVertex3f(0.3f * xabschnitt[i], 0.1f, 0.3f * zabschnitt[i]);
 	glEnd();
 
@@ -39,13 +39,13 @@ void propeller()
 	glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
 	glVertex3f(0.0f, -0.1f, 0.0f);
 	//glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
-	for(i = 0; i<=72; i++)
+	for(int i = 0; i<=72; i++)
 		glVertex3f(0.4f * xabschnitt[i], -0.1f, 0.4f * zabschnitt[i]);
 	glEnd();
 
 	glBegin(GL_QUAD_STRIP); //Seitenflaeche
 	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
-	for(i=0; i<=72; i++)
+	for(int i=0; i<=72; i++)
 	{
 		glVertex3f(0.3f * xabschnitt[i],  0.1f, 0.3f * zabschnitt[i]);
 		glVertex3f(0.4f * xabschnitt[i], -0.1f, 0.4f * zabschnitt[i]);
@@ -56,7 +56,7 @@ void propeller()
 	int fluegel = 5;
 	int abstand = 72 / fluegel;
 
-	for(i = 0;i<fluegel; i++)
+	for(int i = 0;i<fluegel; i++)
 	{
 		int position = abstand * i;
 

+ 2 - 2
src/spirale.cpp

@@ -26,7 +26,7 @@ void spirale(int AnzahlSekunden, int AnzahlMillisekunden)
 
 	int bewegung = 360.0f * AnzahlMillisekunden / 1000.0f;
 
-	for(i; i<AnzahlSekunden; i++)
+	for(; i<AnzahlSekunden; i++)
 	{
 		glPopMatrix();
 		glPushMatrix();
@@ -41,7 +41,7 @@ void spirale(int AnzahlSekunden, int AnzahlMillisekunden)
 		wuerfel();
 	}
 
-	for(i; i<60; i++)
+	for(; i<60; i++)
 	{
 		glPopMatrix();
 		glPushMatrix();

+ 2 - 2
src/stern.cpp

@@ -33,7 +33,7 @@ void stern()
 	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
 	glVertex3f(0.0f, 0.0f, 0.5f);
 	glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
-	for(i=0; i<10; i++)
+	for(int i=0; i<10; i++)
 	{
 		glVertex3f(2.0f * xabs[i], 2.0f * yabs[i], 0.0f);
 		i++;
@@ -46,7 +46,7 @@ void stern()
 	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
 	glVertex3f(0.0f, 0.0f, -0.5f);
 	glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
-	for(i=0; i<10; i++)
+	for(int i=0; i<10; i++)
 	{
 		glVertex3f(2.0f * xabs[i], 2.0f * yabs[i], 0.0f);
 		i++;

+ 23 - 9
src/uhr_main.cpp

@@ -30,8 +30,8 @@
 #endif
 
 #include <time.h>
-#include <sys/timeb.h>
-#include <iostream.h>
+#include <chrono>
+#include <iostream>
 #include <math.h>
 
 extern void pfeil();
@@ -42,9 +42,9 @@ extern void zifferblatt(int);
 extern void spirale(int, int);
 
 GLfloat movpropeller = 0.0f;
-struct _timeb tstruct;
 struct tm *jetzt;
 time_t ltime;
+int milliseconds = 0;
 
 int tmp=0;
 float drehung=0.0;
@@ -81,13 +81,17 @@ void RenderScene(void)
 	glPushMatrix();
 
 	glScalef(0.3f, 0.3f, 0.3f);
+	if(jetzt == nullptr) {
+		std::cerr << "Fehler: std::localtime konnte nicht ausgefÜhrt werden!" << std::endl;
+		exit(EXIT_FAILURE);
+	}
 	zifferblatt(jetzt->tm_hour);
 
 	glPopMatrix();
 	glPushMatrix();
 	glTranslatef(0.0f, 0.5f, 0.0f);
 	glScalef(0.15f, 0.15f, 0.15f);
-	spirale(jetzt->tm_sec, tstruct.millitm);
+	spirale(jetzt->tm_sec, milliseconds);
 
 	glPopMatrix();
 	glPushMatrix();
@@ -145,6 +149,9 @@ void Reshape(int width,int height)
 
 void Animate ()
 {
+	auto now = std::chrono::system_clock::now();
+	auto duration = now.time_since_epoch();
+	auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
 // An dieser Stelle werden Berechnungen durchgeführt, die zu einer
 // Animation der Szene erforderlich sind. Dieser Prozess läuft im Hintergrund.
 
@@ -153,10 +160,9 @@ void Animate ()
 	else
 		movpropeller = 0.0f;
 
-	_ftime( &tstruct );
-	time( &ltime );
-	jetzt = localtime( &ltime );
-
+	milliseconds = millis % 1000;
+	std::time_t t = std::time(nullptr);
+	jetzt = std::localtime(&t);
 
   glutPostRedisplay(); // Bewirkt redraw des Fensters
 }
@@ -164,7 +170,15 @@ void Animate ()
 
 int main(int argc, char **argv)
 {
-	cout<<"Startprogramm fuer das Bachelor gd-Praktikum"<<endl;
+	std::cout<<"Startprogramm fuer das Bachelor gd-Praktikum"<<std::endl;
+
+	std::time_t t = std::time(nullptr);
+	jetzt = std::localtime(&t);
+	if(jetzt == nullptr) {
+		std::cerr << "Fehler: std::localtime konnte nicht ausgefÜhrt werden!" << std::endl;
+		exit(EXIT_FAILURE);
+	}
+	
 	glutInit ( &argc, argv );
 	glutInitDisplayMode ( GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH );
 	glutInitWindowSize ( 600,600 );

+ 7 - 5
src/zifferblatt.cpp

@@ -33,7 +33,8 @@ void zifferblatt(int hour)
 		glPopMatrix();
 		glPushMatrix();
 
-		for(int i=1; i<=hour; i++)
+		int i=1;
+		for(; i<=hour; i++)
 		{
 			glTranslatef(4.0f * sin(6.28318530718 * i / 12.0), 4.0f * cos(6.28318530718 * i / 12.0), 0.0f);
 			glScalef(0.5f, 0.5f, 0.5f);
@@ -43,7 +44,7 @@ void zifferblatt(int hour)
 			glPushMatrix();
 		}
 
-		for(i; i<12; i++)
+		for(; i<12; i++)
 		{
 			glTranslatef(4.0f * sin(6.28318530718 * i / 12.0), 4.0f * cos(6.28318530718 * i / 12.0), 0.0f);
 			glScalef(0.5f, 0.5f, 0.5f);
@@ -63,8 +64,9 @@ void zifferblatt(int hour)
 
 		glPopMatrix();
 		glPushMatrix();
-
-		for(int i=1; i<=pm; i++)
+		
+		int i=1;
+		for(; i<=pm; i++)
 		{
 			glTranslatef(4.0f * sin(6.28318530718 * i / 12.0), 4.0f * cos(6.28318530718 * i / 12.0), 0.0f);
 			glScalef(0.5f, 0.5f, 0.5f);
@@ -74,7 +76,7 @@ void zifferblatt(int hour)
 			glPushMatrix();
 		}
 
-		for(i; i<12; i++)
+		for(; i<12; i++)
 		{
 			glTranslatef(4.0f * sin(6.28318530718 * i / 12.0), 4.0f * cos(6.28318530718 * i / 12.0), 0.0f);
 			glScalef(0.5f, 0.5f, 0.5f);