diff --git a/bin/back b/bin/back index b31b648..030047c 100755 Binary files a/bin/back and b/bin/back differ diff --git a/obj/base.o b/obj/base.o index 133f544..cfa7f2a 100644 Binary files a/obj/base.o and b/obj/base.o differ diff --git a/obj/display.o b/obj/display.o index 8160256..aabae8e 100644 Binary files a/obj/display.o and b/obj/display.o differ diff --git a/obj/generation.o b/obj/generation.o index 26ccd15..2c334d6 100644 Binary files a/obj/generation.o and b/obj/generation.o differ diff --git a/obj/main.o b/obj/main.o index e18d15d..c3ef0a9 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/src/base.c b/src/base.c index a040a1f..129e39b 100644 --- a/src/base.c +++ b/src/base.c @@ -118,7 +118,7 @@ bool str_equal(char* s1, char* s2) { // ------------------------------------------------------------------------------------------------ // -cube_0 create_cube_0(double x, double y, double z, double w, double h, double d, int r, int g, int b) { +cube_0 create_cube_0(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b) { cube_0 cb ; cb.red = r ; cb.green = g ; @@ -129,14 +129,14 @@ cube_0 create_cube_0(double x, double y, double z, double w, double h, double d, cb.w = w ; cb.h = h ; cb.d = d ; - cb.hz_angle = 0.0 ; - cb.vt_angle = 0.0 ; + cb.hz_angle = hz_a ; + cb.vt_angle = vt_a ; return cb ; } -cube create_cube(double x, double y, double z, double w, double h, double d, int r, int g, int b) { +cube create_cube(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b) { cube cb = malloc(sizeof(cube_0)); - *cb = create_cube_0(x, y, z, w, d, h, r, g, b) ; + *cb = create_cube_0(x, y, z, w, h, d, hz_a, vt_a, r, g, b) ; return cb; } diff --git a/src/base.h b/src/base.h index 3adcaed..7dd5b91 100644 --- a/src/base.h +++ b/src/base.h @@ -15,8 +15,8 @@ int line_count(char* filename); int str_to_int(char* s); bool str_equal(char* s1, char* s2); -cube_0 create_cube_0(double x, double y, double z, double w, double h, double d, int r, int g, int b); -cube create_cube(double x, double y, double z, double w, double h, double d, int r, int g, int b); +cube_0 create_cube_0(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b); +cube create_cube(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b); void free_cube(cube c); double convex_pt(double a, double b, double theta); double distance_pt_pt_3d(double x0, double y0, double z0, double x1, double y1, double z1); diff --git a/src/display.c b/src/display.c index 57f1165..4e93ac9 100644 --- a/src/display.c +++ b/src/display.c @@ -214,25 +214,84 @@ void draw_segment(SDL_Renderer* renderer, double sx, double sy, double sz, doubl } // else : not visible (behind camera) } +void axialRotation_X0(double* y, double* z, double theta) { + double y0 = *y ; + *y = (*y)*cos(theta) - (*z)*sin(theta) ; + *z = (*z)*cos(theta) + y0*sin(theta) ; +} + +void axialRotation_X(double* y, double* z, double theta, double cst_y, double cst_z) { + // project the space onto the (y, z) plane to get cst_y and cst_z + double y1 = *y - cst_y; + double z1 = *z - cst_z; + axialRotation_X0(&y1, &z1, theta); + *y = y1 + cst_y ; + *z = z1 + cst_z ; +} + +void axialRotation_Y0(double* x, double* z, double theta) { + double x0 = *x ; + *x = (*x)*cos(theta) + (*z)*sin(theta) ; + *z = (*z)*cos(theta) - x0*sin(theta) ; +} + +void axialRotation_Y(double* x, double* z, double theta, double cst_x, double cst_z) { + // project the space onto the (y, z) plane to get cst_y and cst_z + double x1 = *x - cst_x; + double z1 = *z - cst_z; + axialRotation_Y0(&x1, &z1, theta); + *x = x1 + cst_x ; + *z = z1 + cst_z ; +} + +void axialRotation_Z0(double* x, double* y, double theta) { + double x0 = *x ; + *x = (*x)*cos(theta) - (*y)*sin(theta) ; + *y = (*y)*cos(theta) + x0*sin(theta) ; +} + +void axialRotation_Z(double* x, double* y, double theta, double cst_x, double cst_y) { + // project the space onto the (y, z) plane to get cst_y and cst_z + double x1 = *x - cst_x; + double y1 = *y - cst_y; + axialRotation_Z0(&x1, &y1, theta); + *x = x1 + cst_x ; + *y = y1 + cst_y ; +} + +void drawSegmentRotated(SDL_Renderer* renderer, double sx, double sy, double sz, double ex, double ey, double ez, double hz_angle, double vt_angle, double center_x, double center_y, double center_z) { + double psx = sx; + double psy = sy; + double psz = sz; + double pex = ex; + double pey = ey; + double pez = ez; + axialRotation_Y(&psx, &psz, hz_angle, center_x, center_z); + axialRotation_Y(&pex, &pez, hz_angle, center_x, center_z); + axialRotation_X(&psy, &psz, vt_angle, center_y, center_z); + axialRotation_X(&pey, &pez, vt_angle, center_y, center_z); + draw_segment(renderer, psx, psy, psz, pex, pey, pez); +} + void drawOutlineOfCube_0(SDL_Renderer* renderer, cube_0 c) { SDL_SetRenderDrawColor(renderer, c.red, c.green, c.blue, 255) ; // x = constant - draw_segment(renderer, c.x, c.y, c.z, c.x + c.w, c.y, c.z) ; - draw_segment(renderer, c.x, c.y + c.h, c.z, c.x + c.w, c.y + c.h, c.z) ; - draw_segment(renderer, c.x, c.y, c.z + c.d, c.x + c.w, c.y, c.z + c.d) ; - draw_segment(renderer, c.x, c.y + c.h, c.z + c.d, c.x + c.w, c.y + c.h, c.z + c.d) ; + drawSegmentRotated(renderer, c.x, c.y, c.z, c.x + c.w, c.y, c.z, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; + drawSegmentRotated(renderer, c.x, c.y + c.h, c.z, c.x + c.w, c.y + c.h, c.z, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; + drawSegmentRotated(renderer, c.x, c.y, c.z + c.d, c.x + c.w, c.y, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; + drawSegmentRotated(renderer, c.x, c.y + c.h, c.z + c.d, c.x + c.w, c.y + c.h, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; // y = constant - draw_segment(renderer, c.x, c.y, c.z, c.x, c.y + c.h, c.z) ; - draw_segment(renderer, c.x + c.w, c.y, c.z, c.x + c.w, c.y + c.h, c.z) ; - draw_segment(renderer, c.x, c.y, c.z + c.d, c.x, c.y + c.h, c.z + c.d) ; - draw_segment(renderer, c.x + c.w, c.y, c.z + c.d, c.x + c.w, c.y + c.h, c.z + c.d) ; + drawSegmentRotated(renderer, c.x, c.y, c.z, c.x, c.y + c.h, c.z, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; + drawSegmentRotated(renderer, c.x + c.w, c.y, c.z, c.x + c.w, c.y + c.h, c.z, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; + drawSegmentRotated(renderer, c.x, c.y, c.z + c.d, c.x, c.y + c.h, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; + drawSegmentRotated(renderer, c.x + c.w, c.y, c.z + c.d, c.x + c.w, c.y + c.h, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; // z = constant - draw_segment(renderer, c.x, c.y, c.z, c.x, c.y, c.z + c.d) ; - draw_segment(renderer, c.x + c.w, c.y, c.z, c.x + c.w, c.y, c.z + c.d) ; - draw_segment(renderer, c.x, c.y + c.h, c.z, c.x, c.y + c.h, c.z + c.d) ; - draw_segment(renderer, c.x + c.w, c.y + c.h, c.z, c.x + c.w, c.y + c.h, c.z + c.d) ; + drawSegmentRotated(renderer, c.x, c.y, c.z, c.x, c.y, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; + drawSegmentRotated(renderer, c.x + c.w, c.y, c.z, c.x + c.w, c.y, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; + drawSegmentRotated(renderer, c.x, c.y + c.h, c.z, c.x, c.y + c.h, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; + drawSegmentRotated(renderer, c.x + c.w, c.y + c.h, c.z, c.x + c.w, c.y + c.h, c.z + c.d, c.hz_angle, c.vt_angle, c.x + c.w/2.0, c.y + c.h/2.0, c.z + c.d/2.0) ; } // -------------------------------------------------------------------------------------------------------------------------------- // diff --git a/src/display.h b/src/display.h index ecc810d..93fc30e 100644 --- a/src/display.h +++ b/src/display.h @@ -19,6 +19,13 @@ void drawCharToRenderer(SDL_Renderer* renderer, imgs data, char c, int X, int Y, void drawNumberToRenderer(SDL_Renderer* renderer, imgs data, int n, int X, int Y, int W, int H, int Woffset); void drawStringToRenderer(SDL_Renderer* renderer, imgs data, char* s, int X, int Y, int W, int H); +void axialRotation_X0(double* y, double* z, double theta); +void axialRotation_X(double* y, double* z, double theta, double cst_y, double cst_z); +void axialRotation_Y0(double* x, double* z, double theta); +void axialRotation_Y(double* x, double* z, double theta, double cst_x, double cst_z); +void axialRotation_Z0(double* x, double* y, double theta); +void axialRotation_Z(double* x, double* z, double theta, double cst_x, double cst_z); + void project_to_camera(double x0, double y0, double z0, double* rx, double* ry, double* rz); void draw_segment(SDL_Renderer* renderer, double sx, double sy, double sz, double ex, double ey, double ez); void drawOutlineOfCube_0(SDL_Renderer* renderer, cube_0 c); diff --git a/src/generation.c b/src/generation.c index 0885334..c74f79f 100644 --- a/src/generation.c +++ b/src/generation.c @@ -16,4 +16,5 @@ #include "base.h" #include "generation.h" -// ------------------------------------------------------------------------ // \ No newline at end of file +hashtbl visited ; + diff --git a/src/main.c b/src/main.c index 5b79a52..0efee75 100644 --- a/src/main.c +++ b/src/main.c @@ -47,7 +47,8 @@ int main(int argc, char** argv) { init_csts() ; import_digits(rend) ; import_letters(rend) ; - cube_0 cb = create_cube_0(1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 255, 255, 255) ; + cube_0 cb = create_cube_0(1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 0.0, 3.14159/4.0, 255, 255, 255) ; + cube_0 cb2 = create_cube_0(1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 0.0, 0.0, 255, 0, 255) ; while(true) { resetRenderer(rend) ; @@ -55,6 +56,7 @@ int main(int argc, char** argv) { playerActions() ; drawData(rend) ; drawOutlineOfCube_0(rend, cb) ; + drawOutlineOfCube_0(rend, cb2) ; //draw_segment(rend, 1.0, 1.0, 1.0, 10.0, 2.0, -1.0) ; updateRenderer(rend) ;