| 43 asc_wprintf("Camera type PERSPECTIVE is not yet implemented."); |
43 asc_wprintf("Camera type PERSPECTIVE is not yet implemented."); |
| 44 } else { |
44 } else { |
| 45 asc_error("Illegal argument for asc_camera_init(): type = %d", args.type); |
45 asc_error("Illegal argument for asc_camera_init(): type = %d", args.type); |
| 46 } |
46 } |
| 47 camera->viewport_update_func = args.viewport_update_func; |
47 camera->viewport_update_func = args.viewport_update_func; |
| 48 camera->projection_update_func = args.projection_update_func; |
48 camera->update_func = args.update_func; |
| 49 camera->viewport_clear = args.viewport_clear; |
49 camera->viewport_clear = args.viewport_clear; |
| 50 camera->clear_color = args.clear_color; |
50 camera->clear_color = args.clear_color; |
| 51 } |
51 } |
| 52 |
52 |
| 53 void asc_camera_ortho(AscCamera *camera, asc_rect rect) { |
53 void asc_camera_ortho(AscCamera *camera, asc_rect rect) { |
| 58 float bottom = top + (float) rect.size.height; |
58 float bottom = top + (float) rect.size.height; |
| 59 asc_mat4f_ortho(camera->projection, left, right, bottom, top, -1, 1); |
59 asc_mat4f_ortho(camera->projection, left, right, bottom, top, -1, 1); |
| 60 } |
60 } |
| 61 |
61 |
| 62 void asc_camera_ortho_update_size(AscCamera *camera, asc_vec2u size) { |
62 void asc_camera_ortho_update_size(AscCamera *camera, asc_vec2u size) { |
| |
63 camera->viewport.size = size; |
| 63 asc_mat4f_ortho_update_size(camera->projection, (float)size.width, (float)size.height); |
64 asc_mat4f_ortho_update_size(camera->projection, (float)size.width, (float)size.height); |
| 64 } |
65 } |
| 65 |
66 |
| 66 void asc_camera_update_viewport(AscCamera *camera, asc_vec2u window_size) { |
|
| 67 if (camera->viewport_update_func == NULL) { |
|
| 68 // this assumes the viewport was initialized with zeros! |
|
| 69 camera->viewport.size = window_size; |
|
| 70 } else { |
|
| 71 camera->viewport = camera->viewport_update_func(window_size); |
|
| 72 } |
|
| 73 if (camera->projection_update_func != NULL) { |
|
| 74 camera->projection_update_func(camera, window_size); |
|
| 75 } |
|
| 76 } |
|