summaryrefslogtreecommitdiff
path: root/src/spirt.c
diff options
context:
space:
mode:
authorAiden Gall <aiden@aidengall.xyz>2024-02-06 11:23:46 +0000
committerAiden Gall <aiden@aidengall.xyz>2024-02-06 11:23:46 +0000
commit54d21d69838b394003d243bf21f2fb14d765307e (patch)
treecf198688353d2042c990ccaf443931590c885d9d /src/spirt.c
parente77c9dc9354b715fc2d3894ee553caac3784b00c (diff)
refactor camera and a few miscellaneous thingsHEADmaster
Diffstat (limited to 'src/spirt.c')
-rw-r--r--src/spirt.c42
1 files changed, 5 insertions, 37 deletions
diff --git a/src/spirt.c b/src/spirt.c
index 612c36e..4103bff 100644
--- a/src/spirt.c
+++ b/src/spirt.c
@@ -13,6 +13,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#include "camera.h"
#include "util.h"
#include "util_cl.h"
@@ -44,13 +45,6 @@ struct opts {
long devidx;
};
-struct camera {
- cl_float3 centre;
- cl_float3 pixel_delta_u;
- cl_float3 pixel_delta_v;
- cl_float3 corner00;
-};
-
static float *kernel_render(struct kernel_context *runtime, size_t image_width,
size_t image_height, struct camera cam);
@@ -217,7 +211,7 @@ get_args(int argc, char *argv[])
char flag;
if (argv[0][2])
- die("arg_parse: Invalid flag '%s'\n", argv[0]);
+ die("get_args: Invalid flag '%s'\n", argv[0]);
flag = argv[0][1];
argv++, argc--;
@@ -238,13 +232,13 @@ get_args(int argc, char *argv[])
case '-':
goto end_flags;
default:
- die("arg_parse: Unknown flag '-%c'\n", flag);
+ die("get_args: Unknown flag '-%c'\n", flag);
}
}
end_flags:
if (argc > 0)
- die("arg_parse: Unexpected argument\n");
+ die("get_args: Unexpected argument\n");
return opts;
}
@@ -257,7 +251,6 @@ main(int argc, char *argv[])
struct kernel_context runtime;
float *h_canvas;
struct camera cam;
- float focal_length, viewport_width, viewport_height;
Image img;
Texture2D texture;
@@ -266,32 +259,7 @@ main(int argc, char *argv[])
runtime = kernel_context_init(opts.platidx, opts.devidx);
- focal_length = 1.0f;
- viewport_height = 2.0f;
- viewport_width =
- viewport_height * ((float)opts.width / (float)opts.height);
-
- cam.centre.s[0] = 0.0f;
- cam.centre.s[1] = 0.0f;
- cam.centre.s[2] = 0.0f;
-
- cam.pixel_delta_u.s[0] = viewport_width / (float)opts.width;
- cam.pixel_delta_u.s[1] = 0.0f;
- cam.pixel_delta_u.s[2] = 0.0f;
-
- cam.pixel_delta_v.s[0] = 0.0f;
- cam.pixel_delta_v.s[1] = -viewport_height / (float)opts.height;
- cam.pixel_delta_v.s[2] = 0.0f;
-
- cam.corner00.s[0] =
- cam.centre.s[0] - viewport_width / 2.0f +
- 0.5f * (cam.pixel_delta_u.s[0] + cam.pixel_delta_v.s[0]);
- cam.corner00.s[1] =
- cam.centre.s[1] + viewport_height / 2.0f +
- 0.5f * (cam.pixel_delta_u.s[1] + cam.pixel_delta_v.s[1]);
- cam.corner00.s[2] =
- cam.centre.s[2] - focal_length +
- 0.5f * (cam.pixel_delta_u.s[2] + cam.pixel_delta_v.s[2]);
+ cam = camera_init(opts.width, opts.height, 1.0f);
h_canvas = kernel_render(&runtime, opts.width, opts.height, cam);