[Scripts] Add clang-format

This commit is contained in:
Andre Meyering 2018-10-31 14:45:06 +01:00
parent 8c992e539e
commit 96a0749d91
4 changed files with 173 additions and 168 deletions

View file

@ -1,6 +1,6 @@
--- ---
Language: Cpp Language: Cpp
BasedOnStyle: WebKit BasedOnStyle: WebKit
ColumnLimit: 100 ColumnLimit: 0
FixNamespaceComments: true FixNamespaceComments: true
... ...

View file

@ -0,0 +1,16 @@
#!/usr/bin/env bash
SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
pushd "${SCRIPT_PATH}/.." > /dev/null
echo "Format all files using clang-format"
# We currently don't format test files
find . ! -path "./build/*" ! -path "./test/*" \
-type f \( -name "*.c" \
-o -name "*.hpp" \) \
-exec clang-format \
-i -style=file {} \;
popd > /dev/null

View file

@ -4,81 +4,77 @@
int width = 800; int width = 800;
int height = 600; int height = 600;
void init(int argc, char** argv) { void init(int argc, char** argv)
glutInit(&argc, argv); {
glutInitDisplayMode(GLUT_SINGLE); glutInit(&argc, argv);
glutInitWindowSize(width, height); glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowPosition(100, 100); glutInitWindowSize(width, height);
glViewport(0,0,width,height); glutInitWindowPosition(100, 100);
glutCreateWindow("Culling"); glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); glutCreateWindow("Culling");
glLoadIdentity(); glMatrixMode(GL_PROJECTION);
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
glOrtho(-2.0, 2.0,-2.0, 2.0, -2.0, 2.0); glMatrixMode(GL_MODELVIEW);
gluLookAt(0.25,0.5,0.1,0,0,0,0,1,0); glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0);
gluLookAt(0.25, 0.5, 0.1, 0, 0, 0, 0, 1, 0);
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT); glCullFace(GL_FRONT);
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
} }
void display(void) void display(void)
{ {
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f); glColor3f(1.0f, 0.0f, 0.0f);
// FRONT // FRONT
glVertex3f(-0.5f, -0.5f, 0.5f); glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f); glVertex3f(0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f); glVertex3f(0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f); glVertex3f(-0.5f, 0.5f, 0.5f);
// BACK // BACK
glVertex3f(-0.5f, -0.5f, -0.5f); glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f); glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f); glVertex3f(0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f); glVertex3f(0.5f, -0.5f, -0.5f);
glColor3f(0.0f, 1.0f, 0.0f); glColor3f(0.0f, 1.0f, 0.0f);
// LEFT // LEFT
glVertex3f(-0.5f, -0.5f, 0.5f); glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f); glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f); glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f); glVertex3f(-0.5f, -0.5f, -0.5f);
// RIGHT // RIGHT
glVertex3f( 0.5f, -0.5f, -0.5f); glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f); glVertex3f(0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f); glVertex3f(0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f); glVertex3f(0.5f, -0.5f, 0.5f);
glColor3f(0.0f, 0.0f, 1.0f); glColor3f(0.0f, 0.0f, 1.0f);
// BOTTOM // BOTTOM
glVertex3f(-0.5f, -0.5f, 0.5f); glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f); glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f); glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f); glVertex3f(0.5f, -0.5f, 0.5f);
glEnd(); glEnd();
glFlush(); glFlush();
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
init(argc, argv); init(argc, argv);
glutDisplayFunc(display); glutDisplayFunc(display);
glutMainLoop(); glutMainLoop();
return 0; return 0;
} }

View file

@ -1,7 +1,7 @@
#include <GL/glut.h> #include <GL/glut.h>
#include <string.h>
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#define PI 3.14159265358979323846 #define PI 3.14159265358979323846
#define PIf 3.14159265358979323846f #define PIf 3.14159265358979323846f
@ -9,138 +9,135 @@
static int width = 800; static int width = 800;
static int height = 600; static int height = 600;
void init(int argc, char** argv) { void init(int argc, char** argv)
glutInit(&argc, argv); {
glutInitDisplayMode(GLUT_SINGLE); glutInit(&argc, argv);
glutInitWindowSize(width, height); glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowPosition(100, 100); glutInitWindowSize(width, height);
glViewport(0, 0, width, height); glutInitWindowPosition(100, 100);
glutCreateWindow("Programmieruebung Kreis-Plotter"); glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); glutCreateWindow("Programmieruebung Kreis-Plotter");
glLoadIdentity(); glMatrixMode(GL_PROJECTION);
gluOrtho2D(0, width, 0, height); glLoadIdentity();
glMatrixMode(GL_MODELVIEW); gluOrtho2D(0, width, 0, height);
glEnable(GL_POINT_SMOOTH); glMatrixMode(GL_MODELVIEW);
glEnable(GL_BLEND); glEnable(GL_POINT_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} }
void drawCoordinateSystem(float* origin, int xLength, int yLength, int numTicksX, int numTicksY, float minX, float maxX, float minY, float maxY) { void drawCoordinateSystem(float* origin, int xLength, int yLength, int numTicksX, int numTicksY,
float minX, float maxX, float minY, float maxY)
{
float xTickDistance = (float) xLength / (float) numTicksX; float xTickDistance = (float)xLength / (float)numTicksX;
float yTickDistance = (float) yLength / (float) numTicksY; float yTickDistance = (float)yLength / (float)numTicksY;
char label[10]; char label[10];
double resX = (maxX - minX) / xLength; double resX = (maxX - minX) / xLength;
double resY = (maxY - minY) / yLength; double resY = (maxY - minY) / yLength;
glColor3f(0.0, 0.0, 0.0); glColor3f(0.0, 0.0, 0.0);
/* drawing the coordinate system */ /* drawing the coordinate system */
glBegin(GL_LINES); glBegin(GL_LINES);
// x axis // x axis
glVertex2f(origin[0], origin[1]); glVertex2f(origin[0], origin[1]);
glVertex2f(origin[0] + xLength, origin[1]); glVertex2f(origin[0] + xLength, origin[1]);
// y axis // y axis
glVertex2f(origin[0], origin[1]); glVertex2f(origin[0], origin[1]);
glVertex2f(origin[0], origin[1] + yLength); glVertex2f(origin[0], origin[1] + yLength);
// arrow head at x axis // arrow head at x axis
glVertex2f(origin[0] + xLength, origin[1]); glVertex2f(origin[0] + xLength, origin[1]);
glVertex2f(origin[0] + xLength - 15, origin[1] - 10); glVertex2f(origin[0] + xLength - 15, origin[1] - 10);
glVertex2f(origin[0] + xLength, origin[1]); glVertex2f(origin[0] + xLength, origin[1]);
glVertex2f(origin[0] + xLength - 15, origin[1] + 10); glVertex2f(origin[0] + xLength - 15, origin[1] + 10);
// arrow head at y axis // arrow head at y axis
glVertex2f(origin[0], origin[1] + yLength); glVertex2f(origin[0], origin[1] + yLength);
glVertex2f(origin[0] - 10, origin[1] + yLength - 15); glVertex2f(origin[0] - 10, origin[1] + yLength - 15);
glVertex2f(origin[0], origin[1] + yLength); glVertex2f(origin[0], origin[1] + yLength);
glVertex2f(origin[0] + 10, origin[1] + yLength - 15); glVertex2f(origin[0] + 10, origin[1] + yLength - 15);
glEnd(); glEnd();
// drawing ticks at x axis // drawing ticks at x axis
for (int j = 0; j < xLength; j = j + xTickDistance) { for (int j = 0; j < xLength; j = j + xTickDistance) {
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex2f(origin[0] + j, origin[1] - 5); glVertex2f(origin[0] + j, origin[1] - 5);
glVertex2f(origin[0] + j, origin[1] + 5); glVertex2f(origin[0] + j, origin[1] + 5);
glEnd(); glEnd();
sprintf(label, "%5.2f", minX + (j*resX)); sprintf(label, "%5.2f", minX + (j * resX));
glRasterPos2i((int) round(origin[0] + j - (8 * 5)), (int) round(origin[1] - 13 - 10)); glRasterPos2i((int)round(origin[0] + j - (8 * 5)), (int)round(origin[1] - 13 - 10));
for (int k = 0; k < 5; k++) { for (int k = 0; k < 5; k++) {
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, label[k]); glutBitmapCharacter(GLUT_BITMAP_8_BY_13, label[k]);
} }
} }
// drawing ticks at y axis // drawing ticks at y axis
for (int j = 0; j < yLength; j = j + yTickDistance) { for (int j = 0; j < yLength; j = j + yTickDistance) {
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex2f(origin[0] - 5, origin[1] + j); glVertex2f(origin[0] - 5, origin[1] + j);
glVertex2f(origin[0] + 5, origin[1] + j); glVertex2f(origin[0] + 5, origin[1] + j);
glEnd(); glEnd();
sprintf(label, "%5.2f", minY + (j*resY)); sprintf(label, "%5.2f", minY + (j * resY));
glRasterPos2i((int) round(origin[0] - (8 * 5) - 10), (int) round(origin[1] + j - 13 / 2)); glRasterPos2i((int)round(origin[0] - (8 * 5) - 10), (int)round(origin[1] + j - 13 / 2));
for (int k = 0; k < 5; k++) { for (int k = 0; k < 5; k++) {
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, label[k]); glutBitmapCharacter(GLUT_BITMAP_8_BY_13, label[k]);
} }
} }
} }
void drawCircle(float origin[2], float center[2], float radius, GLint numPoints) void drawCircle(float origin[2], float center[2], float radius, GLint numPoints)
{ {
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
// - calculate numPoints points on the surface of the circle with given center and radius // - calculate numPoints points on the surface of the circle with given center and radius
// hint: see circle equation in parametric form // hint: see circle equation in parametric form
// - position points in the coordinate system starting at given origin // - position points in the coordinate system starting at given origin
// - draw the points by OpenGL commands // - draw the points by OpenGL commands
glBegin(GL_POINTS); glBegin(GL_POINTS);
for (float i = 0.0f; i < 2*PIf; i += (2*PIf)/numPoints) { for (float i = 0.0f; i < 2 * PIf; i += (2 * PIf) / numPoints) {
float x = origin[0] + center[0] + cosf(i) + radius * cosf(i); float x = origin[0] + center[0] + cosf(i) + radius * cosf(i);
float y = origin[1] + center[1] + sinf(i) + radius * sinf(i); float y = origin[1] + center[1] + sinf(i) + radius * sinf(i);
glVertex2f(x, y); glVertex2f(x, y);
} }
glEnd(); glEnd();
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
} }
void display(void) void display(void)
{ {
int n; int n;
int xTickDistance = 50; int xTickDistance = 50;
int yTickDistance = 50; int yTickDistance = 50;
int numPoints = 30; int numPoints = 30;
float radius[] = { 50, 100, 150 }; float radius[] = { 50, 100, 150 };
float center[] = { 300, 200 }; float center[] = { 300, 200 };
float origin[] = { 100, 100 }; float origin[] = { 100, 100 };
GLfloat c[] = { 0.0,0.0,0.0 }; GLfloat c[] = { 0.0, 0.0, 0.0 };
int xLength = 600; int xLength = 600;
int yLength = 400; int yLength = 400;
float size = 2; float size = 2;
/* settings for the coordinate system */ /* settings for the coordinate system */
int numTicksX = 6; int numTicksX = 6;
int numTicksY = 4; int numTicksY = 4;
float minX = 0; float minX = 0;
float maxX = 600; float maxX = 600;
float minY = 0; float minY = 0;
float maxY = 400; float maxY = 400;
/* clearing the background color */ /* clearing the background color */
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
drawCoordinateSystem(origin, xLength, yLength, numTicksX, numTicksY, minX, maxX, minY, maxY); drawCoordinateSystem(origin, xLength, yLength, numTicksX, numTicksY, minX, maxX, minY, maxY);
for (n = 0; n < 3; n++) {
for (n = 0; n < 3; n++) { ///////////////////////////////////////////////////////////////////////////////
// - set the point size different for each loop iteration
/////////////////////////////////////////////////////////////////////////////// // - set the color different for each loop iteration
// - set the point size different for each loop iteration
// - set the color different for each loop iteration
if (n == 0) { if (n == 0) {
glColor3f(1.0f, 0.0f, 0.0f); glColor3f(1.0f, 0.0f, 0.0f);
@ -153,22 +150,18 @@ void display(void)
glPointSize(6.0f); glPointSize(6.0f);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
drawCircle(origin, center, radius[n], numPoints); drawCircle(origin, center, radius[n], numPoints);
} }
glFlush();
glFlush();
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
init(argc, argv); init(argc, argv);
glutDisplayFunc(display); glutDisplayFunc(display);
glutMainLoop(); glutMainLoop();
return 0; return 0;
} }