3dtoys/camera.h

80 lines
2.2 KiB
C
Raw Permalink Normal View History

2024-08-13 01:47:01 +00:00
#ifndef __3DTOYS_CAMERA
#define __3DTOYS_CAMERA
#include "haloo3d/haloo3d.h"
2024-08-13 06:08:21 +00:00
// #include "unigi/unigi.headers/src/main.h"
#define LOOKLOCK MPI / 32
2024-08-13 01:47:01 +00:00
typedef struct {
mfloat_t xofs;
mfloat_t yofs;
mfloat_t zofs;
mfloat_t yaw;
mfloat_t pitch;
} camset;
static inline int readcam(camset *set, int max, char *filename) {
FILE *f = fopen(filename, "r");
if (f == NULL) {
dieerr("Can't open %s for reading cam\n", filename);
}
int num = 0;
while (5 == fscanf(f, "%f %f %f %f %f", &set[num].xofs, &set[num].yofs,
&set[num].zofs, &set[num].yaw, &set[num].pitch)) {
num++;
if (num >= max) {
eprintf("Camera file too big! Ignoring rest\n");
break;
}
}
fclose(f);
printf("Read %d camlines from %s\n", num, filename);
return num;
}
2024-08-13 06:08:21 +00:00
/*
void camera_from_unigi(unigi_type_event * ev, haloo3d_camera * cam, float speed)
{
Fps := float32(*fps)
mouse := rl.GetMouseDelta()
pitch += Rotation * mouse.Y / Fps
yaw += Rotation * mouse.X / Fps
pitch = hrend.Clamp(pitch, LookLock, math.Pi-LookLock)
newcamtrans := hrend.Vec3f{X: 0, Y: 0, Z: 0}
move := float32(Movement)
if rl.IsMouseButtonDown(rl.MouseButtonLeft) {
move *= 6
}
if rl.IsKeyDown(rl.KeyD) {
newcamtrans.X += move / Fps
}
if rl.IsKeyDown(rl.KeyA) {
newcamtrans.X -= move / Fps
}
// Moving forward moves in the negative z direction, since we FACE
// the -z axis (the camera does anyway)
if rl.IsKeyDown(rl.KeyW) {
newcamtrans.Z -= move / Fps
}
if rl.IsKeyDown(rl.KeyS) {
newcamtrans.Z += move / Fps
}
if rl.IsKeyDown(rl.KeySpace) {
newcamtrans.Y += move / Fps
}
if rl.IsKeyDown(rl.KeyLeftShift) {
newcamtrans.Y -= move / Fps
}
// translate the new camera movement based on the yaw
var moverot hrend.Mat44f
moverot.SetRotationY(-yaw)
hnewcamtrans := moverot.MultiplyPoint3(newcamtrans)
return yaw, pitch, hnewcamtrans.MakeConventional()
}*/
2024-08-13 01:47:01 +00:00
#endif