Temp commit. Sound

This commit is contained in:
korenkonder
2022-10-03 15:54:28 +03:00
parent 64c1775f92
commit a15befd8fb
232 changed files with 19396 additions and 12396 deletions
+88 -50
View File
@@ -6,14 +6,14 @@
#include "camera.hpp"
static void camera_calculate_projection(camera* c);
static void camera_calculate_projection_aet(camera* c);
static void camera_calculate_view(camera* c);
static void camera_calculate_forward(camera* c);
camera::camera() : view(), inv_view(), projection(), inv_projection(), view_projection(),
inv_view_projection(), view_projection_prev(), inv_view_projection_prev(), view_mat3(), inv_view_mat3(),
view_rot(), inv_view_rot(), forward(), rotation(), view_point(), interest(), width(), height(), field_1E4(),
field_1F0(), field_1FC(), field_208(), yaw(), pitch(), roll(), aspect(), fov(), fov_rad(),max_distance(),
min_distance(), changed_view(), changed_proj(), fast_change(), fast_change_hist0(), fast_change_hist1() {
camera::camera() : forward(), rotation(), view_point(), interest(), render_width(), render_height(),
sprite_width(), sprite_height(), field_1E4(), field_1F0(), field_1FC(), field_208(), yaw(),
pitch(), roll(), aspect(), fov(), fov_rad(), max_distance(), min_distance(), changed_view(),
changed_proj(), changed_proj_aet(), fast_change(), fast_change_hist0(), fast_change_hist1() {
}
@@ -21,15 +21,18 @@ camera::~camera() {
}
void camera::initialize(double_t aspect, int32_t width, int32_t height) {
void camera::initialize(double_t aspect, int32_t render_width,
int32_t render_height, int32_t sprite_width, int32_t sprite_height) {
this->aspect = aspect;
fov = 0.0;
forward = { 0.0f, 0.0f, -1.0f };
rotation = { 0.0f, 0.0f, 0.0f };
view_point = { 0.0, 0.0f, 0.0f };
interest = { 0.0f, 0.0f, -1.0f };
this->width = width;
this->height = height;
this->render_width = render_width;
this->render_height = render_height;
this->sprite_width = sprite_width;
this->sprite_height = sprite_height;
view = mat4_identity;
inv_view = mat4_identity;
projection = mat4_identity;
@@ -41,6 +44,7 @@ void camera::initialize(double_t aspect, int32_t width, int32_t height) {
min_distance = 0.05;
max_distance = 6000.0;
changed_proj = true;
changed_proj_aet = true;
changed_view = true;
fast_change = false;
fast_change_hist0 = false;
@@ -62,6 +66,7 @@ void camera::set_min_distance(double_t value) {
if (value != min_distance) {
min_distance = value;
changed_proj = true;
changed_proj_aet = true;
}
}
@@ -92,7 +97,7 @@ double_t camera::get_fov() {
}
void camera::set_fov(double_t value) {
value = clamp(value, 1.0, 180.0);
value = clamp_def(value, 1.0, 180.0);
if (value != fov) {
fov = value;
fov_rad = value * DEG_TO_RAD;
@@ -106,7 +111,7 @@ double_t camera::get_pitch() {
void camera::set_pitch(double_t value) {
value = fmod(value, 360.0);
value = clamp(value, -89.5, 89.5);
value = clamp_def(value, -89.5, 89.5);
if (pitch != value) {
pitch = value;
changed_view = true;
@@ -173,16 +178,24 @@ void camera::set_interest(const vec3&& value) {
}
}
void camera::get_res(int32_t& width, int32_t& height) {
width = this->width;
height = this->height;
void camera::get_res(int32_t& render_width, int32_t& render_height,
int32_t& sprite_width, int32_t& sprite_height) {
render_width = this->render_width;
render_height = this->render_height;
sprite_width = this->sprite_width;
sprite_height = this->sprite_height;
}
void camera::set_res(int32_t width, int32_t height) {
if (this->width != width || this->height != height) {
this->width = width;
this->height = height;
void camera::set_res(int32_t render_width, int32_t render_height,
int32_t sprite_width, int32_t sprite_height) {
if (this->render_width != render_width || this->render_height != render_height
|| this->sprite_width != sprite_width || this->sprite_height != sprite_height) {
this->render_width = render_width;
this->render_height = render_height;
this->sprite_width = sprite_width;
this->sprite_height = sprite_height;
changed_proj = true;
changed_proj_aet = true;
}
}
@@ -215,20 +228,12 @@ void camera::reset() {
void camera::move(double_t move_x, double_t move_y) {
if (move_x != 0.0 || move_y != 0.0) {
vec3 temp;
vec3 view_point;
vec3 interest;
vec3 up = { 0.0f, 1.0f, 0.0f };
vec3_cross(forward, up, temp);
vec3_normalize(temp, temp);
vec3_mult_scalar(temp, (float_t)move_y, temp);
vec3_add(this->view_point, temp, view_point);
vec3_mult_scalar(forward, (float_t)move_x, temp);
vec3_add(view_point, temp, view_point);
vec3_add(view_point, forward, interest);
vec3 view_point = this->view_point;
view_point += vec3::normalize(vec3::cross(forward, up)) * (float_t)move_y;
view_point += forward * (float_t)move_x;
set_view_point(view_point);
set_interest(interest);
set_interest(view_point + forward);
}
}
@@ -242,9 +247,7 @@ void camera::rotate(double_t rotate_x, double_t rotate_y) {
if (rotate_x != 0.0 || rotate_y != 0.0) {
camera_calculate_forward(this);
vec3 interest;
vec3_add(view_point, forward, interest);
set_interest(interest);
set_interest(view_point + forward);
}
}
@@ -279,17 +282,13 @@ void camera::set(const vec3&& view_point, const vec3&& interest,
}
void camera::set_position(const vec3& pos) {
vec3 interest;
vec3_add(pos, forward, interest);
set_view_point(pos);
set_interest(interest);
set_interest(pos + forward);
}
void camera::set_position(const vec3&& pos) {
vec3 interest;
vec3_add(pos, forward, interest);
set_view_point(pos);
set_interest(interest);
set_interest(pos + forward);
}
void camera::update() {
@@ -304,6 +303,9 @@ void camera::update_data() {
if (changed_proj)
camera_calculate_projection(this);
if (changed_proj_aet)
camera_calculate_projection_aet(this);
if (changed_view)
camera_calculate_view(this);
@@ -313,6 +315,7 @@ void camera::update_data() {
}
changed_proj = false;
changed_proj_aet = false;
changed_view = false;
}
@@ -326,31 +329,67 @@ static void camera_calculate_projection(camera* c) {
mat4_persp(c->fov_rad, c->aspect, c->min_distance, c->max_distance, &c->projection);
mat4_inverse(&c->projection, &c->inv_projection);
float_t fov_correct_height = (float_t)(((double_t)c->height * 0.5) / tan(c->fov_rad * 0.5));
float_t height = (float_t)c->height * 0.5f;
float_t width = (float_t)c->height * (float_t)c->aspect * 0.5f;
float_t fov_correct_height = (float_t)(((double_t)c->render_height * 0.5) / tan(c->fov_rad * 0.5));
float_t height = (float_t)c->render_height * 0.5f;
float_t width = (float_t)c->render_height * (float_t)c->aspect * 0.5f;
c->field_1E4.x = fov_correct_height;
c->field_1E4.y = 0.0f;
c->field_1E4.z = -width;
vec3_normalize(c->field_1E4, c->field_1E4);
c->field_1E4 = vec3::normalize(c->field_1E4);
c->field_1F0.x = -fov_correct_height;
c->field_1F0.y = 0.0f;
c->field_1F0.z = -width;
vec3_normalize(c->field_1F0, c->field_1F0);
c->field_1F0 = vec3::normalize(c->field_1F0);
c->field_1FC.x = 0.0f;
c->field_1FC.y = fov_correct_height;
c->field_1FC.z = -height;
vec3_normalize(c->field_1FC, c->field_1FC);
c->field_1FC = vec3::normalize(c->field_1FC);
c->field_208.x = 0.0f;
c->field_208.y = -fov_correct_height;
c->field_208.z = -height;
vec3_normalize(c->field_208, c->field_208);
c->field_208 = vec3::normalize(c->field_208);
}
static void camera_calculate_projection_aet(camera* c) {
float_t sprite_half_width = (float_t)c->sprite_width * 0.5f;
float_t sprite_half_height = (float_t)c->sprite_height * 0.5f;
float_t render_half_width = (float_t)c->render_width * 0.5f;
float_t render_half_height = (float_t)c->render_height * 0.5f;
float_t aet_depth = sprite_half_height / (tanf(0.34557518363f) * 0.75f);
float_t v8a = (float_t)c->min_distance / aet_depth * sprite_half_width;
float_t v8b = (float_t)c->min_distance / aet_depth * sprite_half_height;
mat4 spr_2d_proj;
mat4_frustrum(-v8a, v8a, v8b, -v8b, c->min_distance, 3000.0, &spr_2d_proj);
vec3 spr_2d_viewpoint = { sprite_half_width, sprite_half_height, aet_depth };
vec3 spr_2d_interest = { sprite_half_width, sprite_half_height, 0.0f };
vec3 spr_2d_up = { 0.0f, 1.0f, 0.0f };
mat4 spr_2d_view;
mat4_look_at(&spr_2d_viewpoint, &spr_2d_interest, &spr_2d_up, &spr_2d_view);
mat4_mult(&spr_2d_view, &spr_2d_proj, &c->projection_aet_2d);
float_t v13a = (float_t)c->min_distance / aet_depth * render_half_width;
float_t v13b = (float_t)c->min_distance / aet_depth * render_half_height;
mat4 spr_3d_proj;
mat4_frustrum(-v13a, v13a, v13b, -v13b, c->min_distance, 3000.0, &spr_3d_proj);
vec3 spr_3d_viewpoint = { render_half_width, render_half_height, render_half_height };
vec3 spr_3d_interest = { render_half_width, render_half_height, 0.0f };
vec3 spr_3d_up = { 0.0f, 1.0f, 0.0f };
mat4 spr_3d_view;
mat4_look_at(&spr_3d_viewpoint, &spr_3d_interest, &spr_3d_up, &spr_3d_view);
mat4_mult(&spr_3d_view, &spr_3d_proj, &c->projection_aet_3d);
}
static void camera_calculate_view(camera* c) {
vec3 direction;
vec3_sub(c->view_point, c->interest, direction);
vec3 direction = c->view_point - c->interest;
vec3 rotation;
rotation.x = atan2f(-direction.y, sqrtf(direction.x * direction.x + direction.z * direction.z));
@@ -358,10 +397,9 @@ static void camera_calculate_view(camera* c) {
rotation.z = (float_t)(c->roll * DEG_TO_RAD);
c->rotation = rotation;
vec3_negate(rotation, rotation);
rotation = -rotation;
vec3 view_point;
vec3_negate(c->view_point, view_point);
vec3 view_point = -c->view_point;
mat4_rotate_z(rotation.z, &c->view);
mat4_rotate_x_mult(&c->view, rotation.x, &c->view);