Merge branch 'master' into refactor

This commit is contained in:
hasufell 2014-05-16 14:53:47 +02:00
commit 49dc760681
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
5 changed files with 225923 additions and 225830 deletions

File diff suppressed because it is too large Load Diff

View File

@ -37,9 +37,12 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#define XY_WIRE_COUNT 10.0f #define XY_WIRE_COUNT 10.0f
#define FPS_OUT_SIZE 17
#define ROT_FACTOR_PLANET_SUN (360.0 / yearabs) #define ROT_FACTOR_PLANET_SUN (360.0 / yearabs)
#define ROT_FACTOR_PLANET (360.0 / 1.0) #define ROT_FACTOR_PLANET (360.0 / 1.0)
#define ROT_FACTOR_MOON (360.0 / dayabs) #define ROT_FACTOR_MOON (360.0 / dayabs)
@ -72,6 +75,7 @@ static void draw_normals(HE_obj const * const obj,
float const scale_inc); float const scale_inc);
static void draw_vertices(HE_obj const * const obj, static void draw_vertices(HE_obj const * const obj,
bool disco); bool disco);
static float calculateFPS();
static void draw_normals(HE_obj const * const obj, static void draw_normals(HE_obj const * const obj,
@ -356,12 +360,40 @@ static void draw_Planet_2(void)
glPopMatrix(); glPopMatrix();
} }
/**
* Calculates the frames per second rate.
*
* @return the actual frames per second rate
*/
static float calculateFPS(void)
{
static int frameCount = 0;
static int currentTime = 0;
static int previousTime = 0;
static float fps = 0;
frameCount++;
currentTime = glutGet(GLUT_ELAPSED_TIME);
int timeInterval = currentTime - previousTime;
if (timeInterval > 1000) {
fps = frameCount / (timeInterval / 1000.0f);
previousTime = currentTime;
frameCount = 0;
}
return fps;
}
/** /**
* Displays the whole setup with the sun, planet one, * Displays the whole setup with the sun, planet one,
* planet two and the frame rate * planet two and the frame rate
*/ */
void display(void) void display(void)
{ {
char fps_out[FPS_OUT_SIZE];
char *tmp_ptr = fps_out;
float fps = calculateFPS();
int i;
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
@ -380,6 +412,11 @@ void display(void)
glColor3f(1.0f, 1.0f, 1.0f); glColor3f(1.0f, 1.0f, 1.0f);
glRasterPos2i(5, 10); glRasterPos2i(5, 10);
sprintf(fps_out, "FPS: %f", fps);
for (i = 0; i < FPS_OUT_SIZE; ++i)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, *tmp_ptr++);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPopMatrix(); glPopMatrix();
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);

View File

@ -104,6 +104,8 @@ int main(void)
test_parse_obj4)) || test_parse_obj4)) ||
(NULL == CU_add_test(pSuite, "test5 parsing .obj", (NULL == CU_add_test(pSuite, "test5 parsing .obj",
test_parse_obj5)) || test_parse_obj5)) ||
(NULL == CU_add_test(pSuite, "test6 parsing .obj",
test_parse_obj6)) ||
(NULL == CU_add_test(pSuite, "test1 finding center ob obj", (NULL == CU_add_test(pSuite, "test1 finding center ob obj",
test_find_center1)) || test_find_center1)) ||
(NULL == CU_add_test(pSuite, "test2 finding center ob obj", (NULL == CU_add_test(pSuite, "test2 finding center ob obj",

View File

@ -43,6 +43,7 @@ void test_parse_obj2(void);
void test_parse_obj3(void); void test_parse_obj3(void);
void test_parse_obj4(void); void test_parse_obj4(void);
void test_parse_obj5(void); void test_parse_obj5(void);
void test_parse_obj6(void);
void test_find_center1(void); void test_find_center1(void);
void test_find_center2(void); void test_find_center2(void);

View File

@ -469,13 +469,66 @@ void test_parse_obj5(void)
while(next_edge != start_edge) { while(next_edge != start_edge) {
CU_ASSERT_PTR_NOT_NULL(next_edge); CU_ASSERT_PTR_NOT_NULL(next_edge);
CU_ASSERT_PTR_NOT_NULL(next_edge->pair->pair); CU_ASSERT_PTR_NOT_NULL(next_edge->pair->pair);
/* check if edges have all the same face */
CU_ASSERT_EQUAL(next_edge->face, &(obj->faces[i])); CU_ASSERT_EQUAL(next_edge->face, &(obj->faces[i]));
/* check if pairs are consistently set */
CU_ASSERT_EQUAL(next_edge->pair->pair, next_edge); CU_ASSERT_EQUAL(next_edge->pair->pair, next_edge);
CU_ASSERT_NOT_EQUAL(next_edge->pair, next_edge);
/* check if vertices are consistent with edges */
CU_ASSERT_PTR_NOT_NULL(next_edge->vert->edge);
CU_ASSERT_EQUAL(next_edge->vert->edge->vert, next_edge->vert);
next_edge = next_edge->next; next_edge = next_edge->next;
} }
} }
} }
/**
* Test the whole object for consistency by walking
* through all vertices and checking them for consistency.
*/
void test_parse_obj6(void)
{
char const * const string = ""
"v 9.0 10.0 11.0\n"
"v 11.0 10.0 11.0\n"
"v 9.0 11.0 11.0\n"
"v 11.0 11.0 11.0\n"
"v 9.0 11.0 9.0\n"
"v 11.0 11.0 9.0\n"
"v 9.0 10.0 9.0\n"
"v 11.0 10.0 9.0\n"
"f 1 2 4 3\n"
"f 3 4 6 5\n"
"f 5 6 8 7\n"
"f 7 8 2 1\n"
"f 2 8 6 4\n"
"f 7 1 3 5\n";
HE_obj *obj = parse_obj(string);
CU_ASSERT_PTR_NOT_NULL(obj);
for (uint32_t i = 0; i < obj->vc; i++) {
HE_edge *edge = obj->vertices[i].edge;
do {
/* check if pairs are consistently set */
CU_ASSERT_EQUAL(edge->pair->pair, edge);
CU_ASSERT_NOT_EQUAL(edge->pair, edge);
/* check if neighbor vertex is consistently connected
* to half-edge */
CU_ASSERT_NOT_EQUAL(edge->pair->vert, edge->vert);
CU_ASSERT_PTR_NOT_NULL(edge->pair->vert->edge);
CU_ASSERT_EQUAL(edge->pair->next->vert, edge->vert);
CU_ASSERT_EQUAL(edge->vert->edge->vert, edge->vert);
edge = edge->pair->next;
} while (edge && edge != obj->vertices[i].edge);
}
}
/** /**
* Test finding the center of an object. * Test finding the center of an object.
*/ */