src/camera.c

changeset 101
febf3dc10011
parent 99
ac143db979dc
equal deleted inserted replaced
100:5231da78831e 101:febf3dc10011
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
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/context.h"
28 #include "ascension/camera.h" 29 #include "ascension/camera.h"
30
31 void asc_camera_init(AscCamera *camera, AscCameraParams params) {
32 if (params.type == ASC_CAMERA_ORTHO) {
33 asc_recti rect = params.ortho.rect;
34 if (rect.size.width <= 0 || rect.size.height <= 0) {
35 rect.size.width = 1;
36 rect.size.height = 1;
37 }
38 asc_camera_ortho(camera, rect);
39 } else if (params.type == ASC_CAMERA_PERSPECTIVE) {
40 // TODO: implement
41 asc_wprintf("Camera type PERSPECTIVE is not yet implemented.");
42 } else {
43 // at least zero all the bytes (law of the least surprise)
44 memset(camera, 0, sizeof(AscCamera));
45 }
46 camera->viewport_update_func = params.viewport_update_func;
47 camera->projection_update_func = params.projection_update_func;
48 }
29 49
30 void asc_camera_ortho(AscCamera *camera, asc_recti rect) { 50 void asc_camera_ortho(AscCamera *camera, asc_recti rect) {
31 asc_mat4f_unit(camera->view); 51 asc_mat4f_unit(camera->view);
32 float left = (float) rect.pos.x; 52 float left = (float) rect.pos.x;
33 float right = left + (float) rect.size.width; 53 float right = left + (float) rect.size.width;

mercurial