Merge branch 'master' into refactor
This commit is contained in:
commit
49dc760681
@ -37,9 +37,12 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define XY_WIRE_COUNT 10.0f
|
||||
|
||||
#define FPS_OUT_SIZE 17
|
||||
|
||||
#define ROT_FACTOR_PLANET_SUN (360.0 / yearabs)
|
||||
#define ROT_FACTOR_PLANET (360.0 / 1.0)
|
||||
#define ROT_FACTOR_MOON (360.0 / dayabs)
|
||||
@ -72,6 +75,7 @@ static void draw_normals(HE_obj const * const obj,
|
||||
float const scale_inc);
|
||||
static void draw_vertices(HE_obj const * const obj,
|
||||
bool disco);
|
||||
static float calculateFPS();
|
||||
|
||||
|
||||
static void draw_normals(HE_obj const * const obj,
|
||||
@ -356,12 +360,40 @@ static void draw_Planet_2(void)
|
||||
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,
|
||||
* planet two and the frame rate
|
||||
*/
|
||||
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);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
@ -380,6 +412,11 @@ void display(void)
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
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);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
@ -104,6 +104,8 @@ int main(void)
|
||||
test_parse_obj4)) ||
|
||||
(NULL == CU_add_test(pSuite, "test5 parsing .obj",
|
||||
test_parse_obj5)) ||
|
||||
(NULL == CU_add_test(pSuite, "test6 parsing .obj",
|
||||
test_parse_obj6)) ||
|
||||
(NULL == CU_add_test(pSuite, "test1 finding center ob obj",
|
||||
test_find_center1)) ||
|
||||
(NULL == CU_add_test(pSuite, "test2 finding center ob obj",
|
||||
|
@ -43,6 +43,7 @@ void test_parse_obj2(void);
|
||||
void test_parse_obj3(void);
|
||||
void test_parse_obj4(void);
|
||||
void test_parse_obj5(void);
|
||||
void test_parse_obj6(void);
|
||||
|
||||
void test_find_center1(void);
|
||||
void test_find_center2(void);
|
||||
|
@ -469,13 +469,66 @@ void test_parse_obj5(void)
|
||||
while(next_edge != start_edge) {
|
||||
CU_ASSERT_PTR_NOT_NULL(next_edge);
|
||||
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]));
|
||||
/* check if pairs are consistently set */
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user