twn_draw.h: new camera api
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
#include "twn_draw_c.h"
|
||||
#include "twn_draw.h"
|
||||
#include "twn_engine_context_c.h"
|
||||
#include "twn_camera.h"
|
||||
#include "twn_camera_c.h"
|
||||
#include "twn_types.h"
|
||||
#include "twn_vec.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stb_ds.h>
|
||||
@ -382,8 +383,39 @@ void render(void) {
|
||||
}
|
||||
|
||||
|
||||
void draw_camera(const Camera *const camera) {
|
||||
/* TODO: skip recaulculating if it's the same? */
|
||||
camera_projection_matrix = camera_perspective(camera);
|
||||
camera_look_at_matrix = camera_look_at(camera);
|
||||
void draw_camera(Vec3 position, float fov, Vec3 up, Vec3 direction) {
|
||||
Camera const camera = {
|
||||
.fov = fov,
|
||||
.pos = position,
|
||||
.target = direction,
|
||||
.up = up,
|
||||
};
|
||||
camera_projection_matrix = camera_perspective(&camera);
|
||||
camera_look_at_matrix = camera_look_at(&camera);
|
||||
}
|
||||
|
||||
|
||||
/* TODO: https://stackoverflow.com/questions/62493770/how-to-add-roll-in-camera-class */
|
||||
DrawCameraFromPrincipalAxesResult draw_camera_from_principal_axes(Vec3 position, float fov, float roll, float pitch, float yaw) {
|
||||
(void)roll;
|
||||
float yawc, yaws, pitchc, pitchs;
|
||||
sincosf(yaw, &yaws, &yawc);
|
||||
sincosf(pitch, &pitchs, &pitchc);
|
||||
Camera const camera = {
|
||||
.fov = fov,
|
||||
.pos = position,
|
||||
.target = m_vec_norm(((Vec3){
|
||||
yawc * pitchc,
|
||||
pitchs,
|
||||
yaws * pitchc,
|
||||
})),
|
||||
.up = (Vec3){0, 1, 0},
|
||||
};
|
||||
camera_projection_matrix = camera_perspective(&camera);
|
||||
camera_look_at_matrix = camera_look_at(&camera);
|
||||
|
||||
return (DrawCameraFromPrincipalAxesResult) {
|
||||
.direction = camera.target,
|
||||
.up = camera.up,
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user