Allow floating object around the center object

Former-commit-id: 7e35a8b2ef76b3e4160d28f273f038a08f6ad0eb
This commit is contained in:
hasufell 2014-06-13 15:41:27 +02:00
parent 82792c0d65
commit 3b079c94ff
5 changed files with 103 additions and 15 deletions

View File

@ -54,10 +54,13 @@ int yearabs = 365;
int day = 0;
int dayabs = 30;
HE_obj *obj;
HE_obj *float_obj;
HE_obj *bez_obj;
bool show_normals = false;
bool shademodel = true;
bool draw_bezier = true;
bool draw_frame = false;
float ball_speed = 1.0f;
float ball_speed = 0.2f;
@ -203,6 +206,7 @@ void draw_vertices(HE_obj const * const obj,
} while ((tmp_edge = tmp_edge->next) != obj->faces[i].edge);
glEnd();
}
glPopMatrix();
}
@ -319,6 +323,9 @@ void draw_bez_frame(const bez_curv *bez,
bez_curv cur_bez = *bez;
bez_curv next_bez = { NULL, 0 };
glPushMatrix();
glColor3f(0.0, 1.0, 0.0);
while ((get_reduced_bez_curv(&cur_bez, &next_bez, pos))) {
glBegin(GL_LINES);
@ -341,6 +348,7 @@ void draw_bez_frame(const bez_curv *bez,
}
free(cur_bez.vec);
glPopMatrix();
}
/**
@ -366,6 +374,37 @@ void draw_ball(const bez_curv *bez,
free(point);
}
/**
* Draws a ship on the bezier curve at the given position.
*
* @param bez the bezier curve to draw the ship on
* @param pos the position of the ship
* @param scale_fac the scale factor
*/
void draw_ship(const bez_curv *bez,
const float pos,
const float scale_fac)
{
const float ship_pos = pos;
vector *point;
glPushMatrix();
glColor3f(0.0, 1.0, 0.0);
point = calculate_bezier_point(bez,
ship_pos);
glTranslatef(point->x, point->y, point->z);
glScalef(VISIBILITY_FACTOR * scale_fac,
VISIBILITY_FACTOR * scale_fac,
VISIBILITY_FACTOR * scale_fac);
draw_vertices(float_obj, false);
glPopMatrix();
free(point);
}
/**
* Draws an object.
@ -431,11 +470,34 @@ void draw_obj(int32_t const myxrot,
draw_vertices(obj, false);
}
if (obj->bzc != 0) {
draw_bez(&(obj->bez_curves[0]), bez_inc);
draw_ball(&(obj->bez_curves[0]), ball_inc);
glPopMatrix();
glPushMatrix();
FIND_CENTER(bez_obj, &center_vert);
/* rotate according to static members */
glTranslatef(0.0f, 0.0f, SYSTEM_POS_Z);
glScalef(VISIBILITY_FACTOR * 5,
VISIBILITY_FACTOR * 5,
VISIBILITY_FACTOR * 5);
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
glRotatef(zrot, 0.0f, 0.0f, 1.0f);
glTranslatef(0.0f, 0.0f, SYSTEM_POS_Z_BACK);
/* pull into middle of universe */
glTranslatef(-center_vert.x,
-center_vert.y,
-center_vert.z + SYSTEM_POS_Z);
if (bez_obj->bzc != 0) {
if(draw_bezier)
draw_bez(&(bez_obj->bez_curves[0]), bez_inc);
if(draw_frame)
draw_bez_frame(&(obj->bez_curves[0]), ball_inc);
draw_bez_frame(&(bez_obj->bez_curves[0]), ball_inc);
draw_ship(&(bez_obj->bez_curves[0]), ball_inc, 0.03);
}
glPopMatrix();

View File

@ -59,9 +59,12 @@
extern int yearabs;
extern int dayabs;
extern HE_obj *obj;
extern HE_obj *float_obj;
extern HE_obj *bez_obj;
extern bool show_normals;
extern bool shademodel;
extern bool draw_frame;
extern bool draw_bezier;
extern float ball_speed;

View File

@ -275,7 +275,11 @@ static bool process_keypress(SDL_KeyboardEvent *key_event)
}
break;
case 'f':
draw_frame = !draw_frame;
if (mod & KMOD_SHIFT) {
draw_bezier = !draw_bezier;
} else {
draw_frame = !draw_frame;
}
break;
case 'l':
if (mod & KMOD_SHIFT) {
@ -323,16 +327,32 @@ static void gl_destroy(SDL_Window *win, SDL_GLContext glctx)
/**
* Initialize the global obj object.
*
* @param filename the file to parse and build the object from
* @param sun the file to parse and build the object from which
* will construct the sun
* @param object the file to parse and build the object from which
* will float around the sun
* @param bez the file to parse and build the object from which
* will define on which curve the object floats around the sun
*/
void init_object(char const * const filename)
void init_object(char const * const sun,
char const * const object,
char const * const bez)
{
obj = read_obj_file(filename);
obj = read_obj_file(sun);
float_obj = read_obj_file(object);
bez_obj = read_obj_file(bez);
if (!obj)
ABORT("Failed to read object file \"%s\"!", filename);
if (!obj) {
ABORT("Failed to read object file \"%s\"!", sun);
} else if (!float_obj) {
ABORT("Failed to read object file \"%s\"!", object);
} else if (!bez_obj) {
ABORT("Failed to read object file \"%s\"!", bez);
}
NORMALIZE_OBJECT(obj);
NORMALIZE_OBJECT(float_obj);
NORMALIZE_OBJECT(bez_obj);
}
/**

View File

@ -26,7 +26,9 @@
#define _DROW_ENGINE_SETUP_H
void init_object(char const * const filename);
void init_object(char const * const sun,
char const * const object,
char const * const bez);
void init_sdl_loop(void);

View File

@ -40,19 +40,20 @@
/**
* Program help text.
*/
char const * const helptext = "Usage: drow-engine <file.obj>\n";
char const * const helptext = "Usage: drow-engine <center.obj>"
" <float.obj> <bez.obj>\n";
int main(int argc, char *argv[])
{
if (argc == 1) {
if (argc != 4) {
printf("%s", helptext);
return 1;
}
glutInit(&argc, argv);
init_object(argv[1]);
init_object(argv[1], argv[2], argv[3]);
init_sdl_loop();
return 0;