43 void asc_scene_init(AscScene *scene, AscCameraParams camera_params) { |
43 void asc_scene_init(AscScene *scene, AscCameraParams camera_params) { |
44 if (scene->root != NULL) { |
44 if (scene->root != NULL) { |
45 asc_wprintf("Scene %"PRIxPTR" is already initialized - initialization skipped.", (uintptr_t) scene); |
45 asc_wprintf("Scene %"PRIxPTR" is already initialized - initialization skipped.", (uintptr_t) scene); |
46 return; |
46 return; |
47 } |
47 } |
48 if (camera_params.type == ASC_CAMERA_ORTHO) { |
48 asc_camera_init(&scene->camera, camera_params); |
49 asc_camera_ortho(&scene->camera, camera_params.ortho.rect); |
|
50 } else if (camera_params.type == ASC_CAMERA_PERSPECTIVE) { |
|
51 // TODO: implement |
|
52 asc_wprintf("Camera type PERSPECTIVE is not yet implemented."); |
|
53 } else { |
|
54 // at least zero all the bytes (law of the least surprise) |
|
55 memset(&scene->camera, 0, sizeof(AscCamera)); |
|
56 } |
|
57 scene->camera.viewport_update_func = camera_params.viewport_update_func; |
|
58 scene->root = asc_scene_node_empty(); |
49 scene->root = asc_scene_node_empty(); |
59 |
50 |
60 asc_dprintf("Initialized scene %"PRIxPTR, (uintptr_t) scene); |
51 asc_dprintf("Initialized scene %"PRIxPTR, (uintptr_t) scene); |
61 } |
52 } |
62 |
53 |
70 void asc_scene_draw(AscScene *scene) { |
61 void asc_scene_draw(AscScene *scene) { |
71 if (scene->root == NULL) return; |
62 if (scene->root == NULL) return; |
72 |
63 |
73 // if the window resized, we must update the viewport |
64 // if the window resized, we must update the viewport |
74 if (asc_active_window->resized) { |
65 if (asc_active_window->resized) { |
|
66 asc_vec2i window_size = asc_active_window->dimensions; |
75 if (scene->camera.viewport_update_func == NULL) { |
67 if (scene->camera.viewport_update_func == NULL) { |
76 // this assumes the viewport was initialized with zeros! |
68 // this assumes the viewport was initialized with zeros! |
77 scene->camera.viewport.size = asc_active_window->dimensions; |
69 scene->camera.viewport.size = window_size; |
78 } else { |
70 } else { |
79 scene->camera.viewport = scene->camera.viewport_update_func(asc_active_window->dimensions); |
71 scene->camera.viewport = scene->camera.viewport_update_func(window_size); |
|
72 } |
|
73 if (scene->camera.projection_update_func != NULL) { |
|
74 scene->camera.projection_update_func(&scene->camera, window_size); |
80 } |
75 } |
81 } |
76 } |
82 |
77 |
83 // create render groups |
78 // create render groups |
84 CxList *render_group[ASC_RENDER_GROUP_COUNT]; |
79 CxList *render_group[ASC_RENDER_GROUP_COUNT]; |