Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions cube_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,20 @@ const bool rotate_y = true;
const bool rotate_z = true;

void get_screen_size(int* p_screen);
void draw_cube_vertices(double* p_cube_vertices, int len_to_vertex, int terminal_x, int terminal_y, int terminal_z);
void draw_cube_vertices(double* p_cube_vertices[3], int len_to_vertex, int terminal_x, int terminal_y, int terminal_z);
void test_vertex_render(int terminal_x, int terminal_y, double cube_vertices[8][3]);
void rotate_vertices(double angle, double cube_vertices[8][3], double* p_cube_vertices, int terminal_x, int terminal_y, int terminal_z);
void multiply_rotation_matrices(double* matrix, double* coord);
void loop(int terminal_x, int terminal_y, int terminal_z, double* p_cube_vertices, double cube_vertices[8][3]);
void group_triangles(double cube_vertices[8][3], double* p_triangles);
void group_triangles(double *cube_vertices[3], double* p_triangles[3][3]);

int main(void)
{
// set console width & height
// p_screen is used as a pointer to store the height and width from a function
int screen_size[2];
int* p_screen_size = &screen_size[0];

get_screen_size(p_screen_size);
get_screen_size(screen_size);

int terminal_x = screen_size[0];
int terminal_y = screen_size[1];
Expand All @@ -55,9 +54,8 @@ int main(void)
}
*/
double cube_vertices[8][3];
double* p_cube_vertices = &cube_vertices[0][0];

draw_cube_vertices(p_cube_vertices, len_to_vertex, terminal_x, terminal_y, terminal_z);
draw_cube_vertices(cube_vertices, len_to_vertex, terminal_x, terminal_y, terminal_z);

std::cout << "successfully drew vertexes! \n";

Expand All @@ -77,12 +75,11 @@ int main(void)
notes: we will always have 6 faces (of a cube), 12 triangles, 8 vertices. 3 vertices makes up a triangles.
*/
double triangles[12][3][3];
double* p_triangles = &triangles[0][0][0];

group_triangles(cube_vertices, p_triangles);
group_triangles(cube_vertices, triangles);

// tests
loop(terminal_x, terminal_y, terminal_z, p_cube_vertices, cube_vertices);
loop(terminal_x, terminal_y, terminal_z, cube_vertices, cube_vertices);

return 0;
}
Expand All @@ -107,7 +104,7 @@ void get_screen_size(int* p_screen)
}


void draw_cube_vertices(double* p_cube_vertices, int len_to_vertex, int terminal_x, int terminal_y, int terminal_z)
void draw_cube_vertices(double *p_cube_vertices[3], int len_to_vertex, int terminal_x, int terminal_y, int terminal_z)
{
/*
I'm using a weird hacky way to draw the vertices - it probably would be better to use some form of matrix multiplication but its done this way:
Expand Down Expand Up @@ -143,28 +140,28 @@ void draw_cube_vertices(double* p_cube_vertices, int len_to_vertex, int terminal
if (offset_system[2] == 0)
{
// 3 * vertex iterates over the number of vertexes in the array (i.e. 3 * 1 -> cube_vertices[1][0])
*(p_cube_vertices + (3 * vertex) + j) = centre_x - pythag_len;
p_cube_vertices[vertex][j] = centre_x - pythag_len;
} else {
*(p_cube_vertices + (3 * vertex) + j) = centre_x + pythag_len;
p_cube_vertices[vertex][j] = centre_x + pythag_len;
}


} else if (j == 1) {
// y coordinate
if (offset_system[1] == 0)
{
*(p_cube_vertices + (3 * vertex) + j) = centre_y - pythag_len;
p_cube_vertices[vertex][j] = centre_y - pythag_len;
} else {
*(p_cube_vertices + (3 * vertex) + j) = centre_y + pythag_len;
p_cube_vertices[vertex][j] = centre_y + pythag_len;
}

} else if (j == 2) {
// z coordinate
if (offset_system[0] == 0)
{
*(p_cube_vertices + (3 * vertex) + j) = centre_z - pythag_len;
p_cube_vertices[vertex][j] = centre_z - pythag_len;
} else {
*(p_cube_vertices + (3 * vertex) + j) = centre_z + pythag_len;
p_cube_vertices[vertex][j] = centre_z + pythag_len;
}

} else {
Expand Down Expand Up @@ -446,7 +443,7 @@ void loop(int terminal_x, int terminal_y, int terminal_z, double* p_cube_vertice
}
}

void group_triangles(double cube_vertices[8][3], double* p_triangles)
void group_triangles(double *cube_vertices[3], double *p_triangles[3][3])
{
/*
to start grouping triangles, we pick two random vertices. these two vertices cannot exceed the length of pythag_len (shortest length between two vertices)
Expand Down