[Code] Code ergänzt

This commit is contained in:
Andre Meyering 2018-10-24 15:45:27 +02:00
parent fe6e8c0ee1
commit 13af6dd6f2
2 changed files with 27 additions and 34 deletions

View file

@ -18,3 +18,4 @@ target_link_libraries(culling ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
add_executable (koordinatensystem box/template_koordinatensystemUndPunkte.c)
target_include_directories(koordinatensystem PRIVATE ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS})
target_link_libraries(koordinatensystem ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
target_link_libraries(koordinatensystem m) # Math library

View file

@ -6,9 +6,10 @@
#pragma warning(disable:4996)
#define PI 3.14159265358979323846
#define PIf 3.14159265358979323846f
int width = 800;
int height = 600;
static int width = 800;
static int height = 600;
void init(int argc, char** argv) {
glutInit(&argc, argv);
@ -31,15 +32,10 @@ void drawCoordinateSystem(float* origin, int xLength, int yLength, int numTicksX
float xTickDistance = (float) xLength / (float) numTicksX;
float yTickDistance = (float) yLength / (float) numTicksY;
int k;
float j;
float resX, resY;
char label[10];
resX = (maxX - minX) / xLength;
resY = (maxY - minY) / yLength;
double resX = (maxX - minX) / xLength;
double resY = (maxY - minY) / yLength;
glColor3f(0.0, 0.0, 0.0);
/* drawing the coordinate system */
@ -63,27 +59,27 @@ void drawCoordinateSystem(float* origin, int xLength, int yLength, int numTicksX
glEnd();
// drawing ticks at x axis
for (j = 0; j < xLength; j = j + xTickDistance) {
for (int j = 0; j < xLength; j = j + xTickDistance) {
glBegin(GL_LINES);
glVertex2f(origin[0] + j, origin[1] - 5);
glVertex2f(origin[0] + j, origin[1] + 5);
glEnd();
sprintf(label, "%5.2f", minX + (j*resX));
glRasterPos2i((int) round(origin[0] + j - (8 * 5)), (int) round(origin[1] - 13 - 10));
for (k = 0; k < 5; k++) {
for (int k = 0; k < 5; k++) {
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, label[k]);
}
}
// drawing ticks at y axis
for (j = 0; j < yLength; j = j + yTickDistance) {
for (int j = 0; j < yLength; j = j + yTickDistance) {
glBegin(GL_LINES);
glVertex2f(origin[0] - 5, origin[1] + j);
glVertex2f(origin[0] + 5, origin[1] + j);
glEnd();
sprintf(label, "%5.2f", minY + (j*resY));
glRasterPos2i((int) round(origin[0] - (8 * 5) - 10), (int) round(origin[1] + j - 13 / 2));
for (k = 0; k < 5; k++) {
for (int k = 0; k < 5; k++) {
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, label[k]);
}
}
@ -98,17 +94,13 @@ void drawCircle(float origin[2], float center[2], float radius, GLint numPoints)
// - position points in the coordinate system starting at given origin
// - draw the points by OpenGL commands
glBegin(GL_POINTS);
for (float i = 0.0f; i < 2*PIf; i += (2*PIf)/numPoints) {
float x = origin[0] + center[0] + cosf(i) + radius * cosf(i);
float y = origin[1] + center[1] + sinf(i) + radius * sinf(i);
glVertex2f(x, y);
}
glEnd();
//////////////////////////////////////////////////////////////////////////////////////////////
}
@ -118,7 +110,6 @@ void drawCircle(float origin[2], float center[2], float radius, GLint numPoints)
void display(void)
{
int n;
int xTickDistance = 50;
int yTickDistance = 50;
@ -140,12 +131,10 @@ void display(void)
float minY = 0;
float maxY = 400;
/* clearing the background color */
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
drawCoordinateSystem(origin, xLength, yLength, numTicksX, numTicksY, minX, maxX, minY, maxY);
@ -155,13 +144,16 @@ void display(void)
// - set the point size different for each loop iteration
// - set the color different for each loop iteration
if (n == 0) {
glColor3f(1.0f, 0.0f, 0.0f);
glPointSize(2.0f);
} else if (n == 1) {
glColor3f(0.0f, 1.0f, 0.0f);
glPointSize(4.0f);
} else if (n == 2) {
glColor3f(0.0f, 0.0f, 1.0f);
glPointSize(6.0f);
}
//////////////////////////////////////////////////////////////////////////////
drawCircle(origin, center, radius[n], numPoints);