| 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 * POSSIBILITY OF SUCH DAMAGE. |
25 * POSSIBILITY OF SUCH DAMAGE. |
| 26 */ |
26 */ |
| 27 |
27 |
| 28 #include "ascension/error.h" |
28 #include "ascension/error.h" |
| |
29 #include "ascension/context.h" |
| 29 #include "ascension/camera.h" |
30 #include "ascension/camera.h" |
| 30 |
31 |
| 31 void asc_camera_init(AscCamera *camera, AscCameraParams params) { |
32 void asc_camera_init_(AscCamera *camera, struct asc_camera_init_args args) { |
| 32 if (params.type == ASC_CAMERA_ORTHO) { |
33 if (args.type == ASC_CAMERA_ORTHO) { |
| 33 asc_recti rect = params.ortho.rect; |
34 asc_recti rect = args.ortho.rect; |
| 34 if (rect.size.width <= 0 || rect.size.height <= 0) { |
35 if (rect.size.width <= 0 || rect.size.height <= 0) { |
| 35 rect.size.width = 1; |
36 rect.size.width = 1; |
| 36 rect.size.height = 1; |
37 rect.size.height = 1; |
| 37 } |
38 } |
| 38 asc_camera_ortho(camera, rect); |
39 asc_camera_ortho(camera, rect); |
| 39 } else if (params.type == ASC_CAMERA_PERSPECTIVE) { |
40 } else if (args.type == ASC_CAMERA_PERSPECTIVE) { |
| 40 // TODO: implement |
41 // TODO: implement |
| 41 asc_wprintf("Camera type PERSPECTIVE is not yet implemented."); |
42 asc_wprintf("Camera type PERSPECTIVE is not yet implemented."); |
| 42 } else { |
43 } else { |
| 43 // at least zero all the bytes (law of the least surprise) |
44 // at least zero all the bytes (law of the least surprise) |
| 44 memset(camera, 0, sizeof(AscCamera)); |
45 memset(camera, 0, sizeof(AscCamera)); |
| 45 } |
46 } |
| 46 camera->viewport_update_func = params.viewport_update_func; |
47 camera->viewport_update_func = args.viewport_update_func; |
| 47 camera->projection_update_func = params.projection_update_func; |
48 camera->projection_update_func = args.projection_update_func; |
| |
49 camera->viewport_clear = args.viewport_clear; |
| |
50 camera->clear_color = asc_col_itof(asc_context.ink); |
| 48 } |
51 } |
| 49 |
52 |
| 50 void asc_camera_ortho(AscCamera *camera, asc_recti rect) { |
53 void asc_camera_ortho(AscCamera *camera, asc_recti rect) { |
| 51 asc_mat4f_unit(camera->view); |
54 asc_mat4f_unit(camera->view); |
| 52 float left = (float) rect.pos.x; |
55 float left = (float) rect.pos.x; |