[Code] Code hinzugefügt

This commit is contained in:
Andre Meyering 2018-11-21 15:46:14 +01:00
parent 1bd0638da8
commit 57f5e41f0b

View file

@ -5,15 +5,14 @@
#define ORTHO 1
#define PERSPECTIVE 2
#pragma warning(disable:4996)
#pragma warning(disable : 4996)
void mouse(int button, int state, int x, int y);
void key(unsigned char key, int x, int y);
void init(void);
void reshape(int, int);
void display(void);
int main(int, char **);
int main(int, char**);
void define_menu(void);
void idle(void);
void timer(int value);
@ -57,19 +56,15 @@ int lights = 0;
int shading = 0;
float shininess = 2;
////////////////////////////////////////////////////////////////////////////////////////////////////
// FARBEN DER LICHT KOMPONENTEN
float ambietntLightColor[3] = { 0.1f, 0.1f, 0.1f };
float diffuseLightColor[3] = { 0.5f, 0.5f, 0.5 };
float specularLightColor[3] = { 1.0f, 1.0f, 1.0f };
// LICHT POSITION
float lightPosition[4] = { 0, 0, 1, 1 };
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -119,8 +114,7 @@ void displaycloud(int modus)
for (i = 0; i < 3; i++)
range[i] = cpointsmax[i] - cpointsmin[i];
if (modus > 0)
{
if (modus > 0) {
if (modus == 1 || modus == 4) { // Darstellung von Punkten
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
}
@ -131,14 +125,12 @@ void displaycloud(int modus)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
glBegin(GL_TRIANGLES);
for (i = 0; i < maxcoords + 1; i++)
{
for (i = 0; i < maxcoords + 1; i++) {
if (modus > 3) { // Darstellung der Farben aus dem Mesh-File
currentColor[0] = ccolors[ccoord[i] * 3];
currentColor[1] = ccolors[ccoord[i] * 3 + 1];
currentColor[2] = ccolors[ccoord[i] * 3 + 2];
}
else { // Darstellung der interpolierten Farben entsprechend der Koordinaten
} else { // Darstellung der interpolierten Farben entsprechend der Koordinaten
currentColor[0] = (cpoints[ccoord[i] * 3] - cpointsmin[0]) / range[0];
currentColor[1] = (cpoints[ccoord[i] * 3 + 1] - cpointsmin[1]) / range[1];
currentColor[2] = (cpoints[ccoord[i] * 3 + 2] - cpointsmin[2]) / range[2];
@ -148,19 +140,14 @@ void displaycloud(int modus)
////////////////////////////////////////////////////////////////////////////////////////////////////////
// MATERIAL DEFINTION
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, currentColor);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, currentColor);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, currentColor);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
////////////////////////////////////////////////////////////////////////////////////////////////////////
}
else {
} else {
glColor3f(currentColor[0], currentColor[1], currentColor[2]);
}
@ -186,33 +173,30 @@ void displaycloud(int modus)
}
glEnd();
}
}
void display(void) {
void display(void)
{
if (lights == 1) {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// LICHT DEFINITION
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambietntLightColor);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLightColor);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLightColor);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glEnable(GL_LIGHTING);
// SHADING DEFINTION
if (shading == 0) { // Flat Shading
glShadeModel(GL_FLAT);
} else if (shading == 1) { // Gouraud Shading
glShadeModel(GL_SMOOTH);
}
else if (shading == 1) { // Gouraud Shading
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
else {
} else {
glDisable(GL_LIGHTING);
}
@ -239,8 +223,6 @@ void display(void) {
break;
}
glPushMatrix();
// enable depth buffer and clear color/depth buffer
@ -249,7 +231,6 @@ void display(void) {
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS); // Default: GL_LESS
glColor3f(0.0, 0.0, 0.0);
// center and rotate
glTranslatef(xoff, yoff, 0);
@ -291,7 +272,6 @@ void display(void) {
glutSwapBuffers(); // Buffer for animation needs to be swapped
}
void init(void)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -309,8 +289,6 @@ void init(void)
angle2 = 45;
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
@ -339,7 +317,7 @@ void readcloud(char* filename)
int index;
int indexBegin;
int numNeighbouringFaces = 0;
FILE * f;
FILE* f;
int abbruch = 0;
char str[200] = "";
printf("Lese '%s' ein\n", filename);
@ -350,16 +328,14 @@ void readcloud(char* filename)
fscanf(f, "%s", str);
printf("Lese Punkte ein...\n");
//Punkte einlesen
while (!feof(f) && abbruch == 0)
{
while (!feof(f) && abbruch == 0) {
//einlesen
if (((i + 1) % 3) == 0)
fscanf(f, "%f %c", &cpoints[i], str);
else
fscanf(f, "%f", &cpoints[i]);
// Extremalwerte initialisieren
if (i < 3)
{
if (i < 3) {
cpointsmax[i % 3] = cpoints[i];
cpointsmin[i % 3] = cpoints[i];
}
@ -376,14 +352,14 @@ void readcloud(char* filename)
cpoints_n = i - 1;
printf("Es wurden %i Vertices gelesen\n", cpoints_n / 3);
printf("Koordinaten sind in den Intervallen [%f,%f] [%f,%f] [%f,%f]\n\n", cpointsmin[0], cpointsmax[0], cpointsmin[1], cpointsmax[1], cpointsmin[2], cpointsmax[2]);
abbruch = 0; i = 0;
abbruch = 0;
i = 0;
//warten, bis es zu den colors geht
while (!feof(f) && str[0] != '[')
fscanf(f, "%s", str);
printf("Lese Farben ein...\n");
// Farben einlesen
while (!feof(f) && abbruch == 0)
{
while (!feof(f) && abbruch == 0) {
//einlesen
if (((i + 1) % 3) == 0)
fscanf(f, "%f %c", &ccolors[i], str);
@ -395,29 +371,27 @@ void readcloud(char* filename)
i++;
}
printf("Es wurden %i Farben eingelesen\n\n", (i - 1) / 3);
abbruch = 0; i = 0;
abbruch = 0;
i = 0;
//warten, bis es zu den koordinaten geht
while (!feof(f) && str[0] != '[')
fscanf(f, "%s", str);
printf("Lese Koordinaten fuer die Dreiecke ein...\n");
// Koordinaten einlesen
while (!feof(f) && abbruch < 2)
{
while (!feof(f) && abbruch < 2) {
//einlesen
fscanf(f, "%i %c", &ccoord[i], str);
//printf("%i\n",ccoord[i]);
//Abbruch, wenn alle Dreiecke 0 sind, (nicht ganz sauber, aber funktioniert, wenn nicht zufällig der Urspung ein gültiger Punkt ist)
if (ccoord[i] == -1)
{
if (ccoord[i] == -1) {
i--;
abbruch++;
}
else
} else
abbruch = 0;
i++;
}
maxcoords = i - 1;
printf("Es wurden %i Dreiecke eingelesen\n", (maxcoords + 1) / 3);// drei Punkte bilden ein Dreieck
printf("Es wurden %i Dreiecke eingelesen\n", (maxcoords + 1) / 3); // drei Punkte bilden ein Dreieck
fclose(f);
printf("Einlesen beendet\n\n");
@ -478,7 +452,6 @@ void readcloud(char* filename)
cvnormals[ccoord[i + 2] * 3] = cvnormals[ccoord[i + 2] * 3] + n[0];
cvnormals[ccoord[i + 2] * 3 + 1] = cvnormals[ccoord[i + 2] * 3 + 1] + n[1];
cvnormals[ccoord[i + 2] * 3 + 2] = cvnormals[ccoord[i + 2] * 3 + 2] + n[2];
}
counter++;
if (counter == 3) {
@ -488,33 +461,25 @@ void readcloud(char* filename)
printf("... beendet.\n");
}
void key(unsigned char k, int x, int y);
void mouseactive(int x, int y)
{
if (pressedbutton == GLUT_LEFT_BUTTON)
{
if (pressedbutton == GLUT_LEFT_BUTTON) {
angle1 = startangle1 + (x - startx) / 10;
angle2 = startangle2 + (y - starty) / 10;
}
if (pressedbutton == GLUT_RIGHT_BUTTON)
{
if (pressedbutton == GLUT_RIGHT_BUTTON) {
xoff = startxoff + (float)(x - startx) / 100;
yoff = startyoff + (float)(y - starty) / 100;
}
if (pressedbutton == GLUT_MIDDLE_BUTTON)
{
if (pressedbutton == GLUT_MIDDLE_BUTTON) {
zoff = startzoff + ((float)(y - startz) / 100);
}
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
if (state == GLUT_DOWN)
{
if (state == GLUT_DOWN) {
pressedbutton = button;
startx = x;
starty = y;
@ -524,13 +489,10 @@ void mouse(int button, int state, int x, int y)
startxoff = xoff;
startyoff = yoff;
startzoff = zoff;
}
else
} else
pressedbutton = 0;
}
void MainMenu(int value)
{
switch (value) {
@ -538,7 +500,6 @@ void MainMenu(int value)
case 2:
key('q', 0, 0);
break;
}
}
@ -546,7 +507,6 @@ void submenu1(int value)
{
}
void define_menu()
{
}
@ -589,20 +549,16 @@ void key(unsigned char k, int x, int y)
if (shading == 1) {
shading = 0;
printf(" Shading = FLAT\n");
}
else if (shading == 0) {
} else if (shading == 0) {
shading = 1;
printf(" Shading = GOURAUD\n");
}
break;
default:
if (k > '0' - 1 && k < '7')
{
if (k > '0' - 1 && k < '7') {
displaymodus = k - '0';
printf("Display-Modus: %i\n", displaymodus);
}
else
{
} else {
printf("Taste %c mit Steuerzeichen %i nicht belegt\n", k, k);
}
break;