diff options
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/camera.c | 23 | ||||
-rw-r--r-- | libdimension/dimension/camera.h | 20 | ||||
-rw-r--r-- | libdimension/perspective.c | 4 |
3 files changed, 33 insertions, 14 deletions
diff --git a/libdimension/camera.c b/libdimension/camera.c index 1c5a1fc..38fde35 100644 --- a/libdimension/camera.c +++ b/libdimension/camera.c @@ -26,26 +26,35 @@ #include "dimension-internal.h" #include <stdlib.h> +static void dmnsn_default_camera_free_fn(dmnsn_camera *camera) +{ + dmnsn_free(camera); +} + /* Allocate a new dummy camera */ dmnsn_camera * dmnsn_new_camera(void) { dmnsn_camera *camera = DMNSN_MALLOC(dmnsn_camera); - camera->free_fn = NULL; - camera->trans = dmnsn_identity_matrix(); - DMNSN_REFCOUNT_INIT(camera); + dmnsn_init_camera(camera); return camera; } +/* Initialize a camera */ +void +dmnsn_init_camera(dmnsn_camera *camera) +{ + camera->free_fn = dmnsn_default_camera_free_fn; + camera->trans = dmnsn_identity_matrix(); + DMNSN_REFCOUNT_INIT(camera); +} + /* Free a dummy camera */ void dmnsn_delete_camera(dmnsn_camera *camera) { if (DMNSN_DECREF(camera)) { - if (camera->free_fn) { - camera->free_fn(camera->ptr); - } - dmnsn_free(camera); + camera->free_fn(camera); } } diff --git a/libdimension/dimension/camera.h b/libdimension/dimension/camera.h index 00f0ad5..d8e0bdf 100644 --- a/libdimension/dimension/camera.h +++ b/libdimension/dimension/camera.h @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2009-2014 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Library. * * * @@ -36,16 +36,20 @@ typedef struct dmnsn_camera dmnsn_camera; typedef dmnsn_line dmnsn_camera_ray_fn(const dmnsn_camera *camera, double x, double y); +/** + * Camera destruction callback. + * @param[in,out] camera The camera to delete. + */ +typedef void dmnsn_camera_free_fn(dmnsn_camera *camera); + /** A camera. */ struct dmnsn_camera { /* Callback functions */ - dmnsn_camera_ray_fn *ray_fn; /**< Camera ray callback. */ - dmnsn_free_fn *free_fn; /**< Destructor callback. */ + dmnsn_camera_ray_fn *ray_fn; /**< Camera ray callback. */ + dmnsn_camera_free_fn *free_fn; /**< Destructor callback. */ dmnsn_matrix trans; /**< Transformation matrix. */ - void *ptr; /**< Generic pointer for camera info. */ - DMNSN_REFCOUNT; /**< Reference count. */ }; @@ -56,6 +60,12 @@ struct dmnsn_camera { dmnsn_camera *dmnsn_new_camera(void); /** + * Initialize a dmnsn_camera field. + * @param[in,out] camera The camera to initialize. + */ +void dmnsn_init_camera(dmnsn_camera *camera); + +/** * Delete a camera. * @param[in,out] camera The camera to delete. */ diff --git a/libdimension/perspective.c b/libdimension/perspective.c index 5b4b3b5..10b7c18 100644 --- a/libdimension/perspective.c +++ b/libdimension/perspective.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2010-2011 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2010-2014 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Library. * * * @@ -42,6 +42,6 @@ dmnsn_camera * dmnsn_new_perspective_camera(void) { dmnsn_camera *camera = dmnsn_new_camera(); - camera->ray_fn = dmnsn_perspective_camera_ray_fn; + camera->ray_fn = dmnsn_perspective_camera_ray_fn; return camera; } |