diff --git a/src/CRE/Glitter/file_reader.cpp b/src/CRE/Glitter/file_reader.cpp index d7c368ae..3271102c 100644 --- a/src/CRE/Glitter/file_reader.cpp +++ b/src/CRE/Glitter/file_reader.cpp @@ -1862,8 +1862,8 @@ namespace Glitter { ptcl->data.unk0 = unk0; ptcl->data.unk1 = unk1; - vec2_rcp(ptcl->data.split_uv, ptcl->data.split_uv); - vec4_mult_scalar(ptcl->data.color, (float_t)(1.0 / 255.0), ptcl->data.color); + ptcl->data.split_uv = vec2::rcp(ptcl->data.split_uv); + ptcl->data.color *= (float_t)(1.0 / 255.0); int32_t uv_max_count = (int32_t)(split_u * split_v); if (uv_max_count) diff --git a/src/CRE/Glitter/glitter.cpp b/src/CRE/Glitter/glitter.cpp index 5daf006c..22870a26 100644 --- a/src/CRE/Glitter/glitter.cpp +++ b/src/CRE/Glitter/glitter.cpp @@ -263,10 +263,9 @@ namespace Glitter { }; void axis_angle_from_vectors(vec3* axis, float_t* angle, const vec3* vec1, const vec3* vec2) { - float_t t; + *axis = vec3::cross(*vec1, *vec2); + *angle = vec3::length(*axis); - vec3_cross(*vec1, *vec2, *axis); - vec3_length(*axis, *angle); if (*angle >= 0.000001f) *angle = asinf(min_def(*angle, 1.0f)); else { @@ -274,16 +273,14 @@ namespace Glitter { axis->x = vec1->z; axis->y = 0.0f; axis->z = vec1->x; - vec3_length(*axis, t); - if (t < 0.000001f) { + if (vec3::length(*axis) < 0.000001f) { axis->x = -vec1->y; axis->y = vec1->x; axis->z = 0.0f; } } - vec3_dot(*vec1, *vec2, t); - if (t < 0.0f) + if (vec3::dot(*vec1, *vec2) < 0.0f) *angle = (float_t)M_PI - *angle; } } diff --git a/src/CRE/Glitter/render_group.cpp b/src/CRE/Glitter/render_group.cpp index df1f9d6b..af3469f1 100644 --- a/src/CRE/Glitter/render_group.cpp +++ b/src/CRE/Glitter/render_group.cpp @@ -121,13 +121,10 @@ namespace Glitter { glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, buffer_size, (void*)offsetof(Buffer, position)); glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, buffer_size, - (void*)offsetof(Buffer, uv[0])); + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, buffer_size, + (void*)offsetof(Buffer, uv)); glEnableVertexAttribArray(2); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, buffer_size, - (void*)offsetof(Buffer, uv[1])); - glEnableVertexAttribArray(3); - glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, buffer_size, + glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, buffer_size, (void*)offsetof(Buffer, color)); gl_state_bind_array_buffer(0); @@ -217,8 +214,10 @@ namespace Glitter { if (!particle || (particle->data.data.flags & PARTICLE_LOOP && particle->HasEnded(false)) || rend_elem->frame >= rend_elem->life_time) { rend_elem->alive = false; - delete rend_elem->locus_history; - rend_elem->locus_history = 0; + if (rend_elem->locus_history) { + delete rend_elem->locus_history; + rend_elem->locus_history = 0; + } ctrl--; return; } @@ -467,13 +466,10 @@ namespace Glitter { glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, buffer_size, (void*)offsetof(Buffer, position)); glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, buffer_size, - (void*)offsetof(Buffer, uv[0])); + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, buffer_size, + (void*)offsetof(Buffer, uv)); glEnableVertexAttribArray(2); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, buffer_size, - (void*)offsetof(Buffer, uv[1])); - glEnableVertexAttribArray(3); - glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, buffer_size, + glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, buffer_size, (void*)offsetof(Buffer, color)); gl_state_bind_array_buffer(0); @@ -567,8 +563,10 @@ namespace Glitter { if (!particle || (particle->data.data.flags & PARTICLE_LOOP && particle->HasEnded(false)) || rend_elem->frame >= rend_elem->life_time) { rend_elem->alive = false; - delete rend_elem->locus_history; - rend_elem->locus_history = 0; + if (rend_elem->locus_history) { + delete rend_elem->locus_history; + rend_elem->locus_history = 0; + } ctrl--; return; } @@ -581,18 +579,16 @@ namespace Glitter { else rend_elem->rotation.z += rend_elem->rotation_add.z * delta_frame; - vec2 uv_scroll; - vec2_mult_scalar(particle->data.data.uv_scroll_add, - particle->data.data.uv_scroll_add_scale * delta_frame, uv_scroll); + vec2 uv_scroll = particle->data.data.uv_scroll_add + * (particle->data.data.uv_scroll_add_scale * delta_frame); if (uv_scroll.x != 0.0f) rend_elem->uv_scroll.x = fmodf(rend_elem->uv_scroll.x + uv_scroll.x, 1.0f); if (uv_scroll.y != 0.0f) rend_elem->uv_scroll.y = fmodf(rend_elem->uv_scroll.y + uv_scroll.y, 1.0f); if (particle->data.data.sub_flags & PARTICLE_SUB_UV_2ND_ADD) { - vec2 uv_scroll_2nd; - vec2_mult_scalar(particle->data.data.uv_scroll_2nd_add, - particle->data.data.uv_scroll_2nd_add_scale * delta_frame, uv_scroll_2nd); + vec2 uv_scroll_2nd = particle->data.data.uv_scroll_2nd_add + * (particle->data.data.uv_scroll_2nd_add_scale * delta_frame); if (uv_scroll_2nd.x != 0.0f) rend_elem->uv_scroll_2nd.x = fmodf(rend_elem->uv_scroll_2nd.x + uv_scroll_2nd.x, 1.0f); if (uv_scroll_2nd.y != 0.0f) diff --git a/src/CRE/Glitter/render_scene.cpp b/src/CRE/Glitter/render_scene.cpp index 8ac4e31b..2e52fe22 100644 --- a/src/CRE/Glitter/render_scene.cpp +++ b/src/CRE/Glitter/render_scene.cpp @@ -783,11 +783,9 @@ namespace Glitter { vec3 pos = elem->translation; if (has_scale) { - vec3 pos_diff; - vec3_sub(pos, elem->base_translation, pos_diff); - vec3_mult(pos_diff, scale, pos_diff); + vec3 pos_diff = (pos - elem->base_translation) * scale; mat4_mult_vec3(&inv_model_mat, &pos_diff, &pos_diff); - vec3_add(pos, pos_diff, pos); + pos += pos_diff; } float_t v00; diff --git a/src/CRE/post_process.cpp b/src/CRE/post_process.cpp index bc8daa4a..d56b968c 100644 --- a/src/CRE/post_process.cpp +++ b/src/CRE/post_process.cpp @@ -58,9 +58,9 @@ screen_x_offset(), screen_y_offset(), screen_width(), screen_height(), mag_filte glBufferData(GL_ARRAY_BUFFER, sizeof(float_t) * 5 * (6 * 16), 0, GL_DYNAMIC_DRAW); glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 20, (void*)0); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float_t) * 5, (void*)0); glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 20, (void*)8); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(float_t) * 5, (void*)(sizeof(float_t) * 2)); gl_state_bind_array_buffer(0); gl_state_bind_vertex_array(0); diff --git a/src/CRE/render_context.cpp b/src/CRE/render_context.cpp index 654eebf8..89cc35fd 100644 --- a/src/CRE/render_context.cpp +++ b/src/CRE/render_context.cpp @@ -2481,13 +2481,13 @@ chara_refract(), view_mat(), matrix_buffer(), box_vao(), box_vbo() { glBufferData(GL_ARRAY_BUFFER, sizeof(box_texcoords), box_texcoords, GL_STATIC_DRAW); glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 64, (void*)0); + glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(float_t) * 16, (void*)0); glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 64, (void*)16); + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(float_t) * 16, (void*)(sizeof(float_t) * 4)); glEnableVertexAttribArray(2); - glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 64, (void*)32); + glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(float_t) * 16, (void*)(sizeof(float_t) * 8)); glEnableVertexAttribArray(3); - glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, 64, (void*)48); + glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(float_t) * 16, (void*)(sizeof(float_t) * 12)); gl_state_bind_array_buffer(0); gl_state_bind_vertex_array(0); @@ -2907,11 +2907,10 @@ void shadow::ctrl(render_context* rctx) { if (field_2EC >= 2) { vec3 v12 = field_1A8[0] - interest_shared; vec3 v14 = field_1A8[1] - interest_shared; - float_t v15 = vec3::dot(v12, direction); - vec3 v6 = direction * v15 - v12; + float_t v6 = vec3::length(direction * vec3::dot(v12, direction) - v12); - float_t v16 = vec3::length(v6) - 0.25f; + float_t v16 = v6 - 0.25f; if (v16 < 0.0f) v16 = 0.0f; diff --git a/src/CRE/rob/rob.cpp b/src/CRE/rob/rob.cpp index 023980f4..f9ecd004 100644 --- a/src/CRE/rob/rob.cpp +++ b/src/CRE/rob/rob.cpp @@ -2439,14 +2439,10 @@ static void sub_140509D30(rob_chara* rob_chr) { float_t chara_scale = rob_chr->data.adjust_data.scale; - vec3 v23; - vec3_mult_scalar(*(vec3*)&v42->row3, chara_scale, v23); - vec3_add(v23, rob_chr->data.adjust_data.trans, v23); + vec3 v23 = *(vec3*)&v42->row3 * chara_scale + rob_chr->data.adjust_data.trans; *(vec3*)&v42->row3 = v23; - vec3 v29; - vec3_mult_scalar(*(vec3*)&v43->row3, chara_scale, v23); - vec3_add(v23, rob_chr->data.adjust_data.trans, v29); + vec3 v29 = *(vec3*)&v43->row3 * chara_scale + rob_chr->data.adjust_data.trans; *(vec3*)&v43->row3 = v29; float_t v20 = v3->scale * chara_scale; @@ -4054,14 +4050,14 @@ static bool bone_data_mult_1_ik(bone_data* a1, bone_data* a2) { v5 = a2[MOTION_BONE_CL_MOMO_L].node; mat4_get_translation(v5[2].mat, &v30); mat4_mult_vec3_inv_trans(a1->node[0].mat, &v30, &v30); - vec3_negate(v30, v30); + v30 = -v30; bone_data_mult_1_ik_legs(a1, &v30); break; case MOTION_BONE_N_MOMO_A_R_WJ_CD_EX: v5 = a2[MOTION_BONE_CL_MOMO_R].node; mat4_get_translation(v5[2].mat, &v30); mat4_mult_vec3_inv_trans(a1->node[0].mat, &v30, &v30); - vec3_negate(v30, v30); + v30 = -v30; bone_data_mult_1_ik_legs(a1, &v30); break; case MOTION_BONE_N_HARA_CD_EX: @@ -4081,28 +4077,27 @@ static void bone_data_mult_1_ik_hands(bone_data* a1, vec3* a2) { mat4_mult_vec3_inv_trans(a1->node[0].mat, a2, &v15); float_t len; - vec3_length_squared(v15, len); + len = vec3::length_squared(v15); if (len <= 0.000001f) return; len = sqrtf(len); if (len != 0.0f) - vec3_mult_scalar(v15, 1.0f / len, v15); + v15 *= 1.0f / len; vec3 v17; v17.x = -v15.z * v15.x - v15.z; v17.y = -v15.y * v15.z; v17.z = v15.x * v15.x + v15.y * v15.y + v15.x; - vec3_length_squared(v17, len); + len = vec3::length_squared(v17); if (len <= 0.000001f) return; len = sqrtf(len); if (len != 0.0f) - vec3_mult_scalar(v17, 1.0f / len, v17); + v17 *= 1.0f / len; - vec3 v16; - vec3_cross(v17, v15, v16); + vec3 v16 = vec3::cross(v17, v15); mat4 rot_mat = mat4_identity; *(vec3*)&rot_mat.row0 = v15; @@ -4113,16 +4108,15 @@ static void bone_data_mult_1_ik_hands(bone_data* a1, vec3* a2) { } static void bone_data_mult_1_ik_hands_2(bone_data* a1, vec3* a2, float_t a3) { - float_t len; vec3 v8; - mat4_mult_vec3_inv_trans(a1->node[0].mat, a2, &v8); v8.x = 0.0f; - vec3_length(v8, len); + + float_t len = vec3::length(v8); if (len <= 0.000001f) return; - vec3_mult_scalar(v8, 1.0f / len, v8); + v8 *= 1.0f / len; float_t angle = atan2f(v8.z, v8.y); mat4_rotate_x_mult(a1->node[0].mat, angle * a3, a1->node[0].mat); } @@ -4131,29 +4125,28 @@ static void bone_data_mult_1_ik_legs(bone_data* a1, vec3* a2) { vec3 v9 = *a2; float_t len; - vec3_length_squared(v9, len); + len = vec3::length_squared(v9); if (len <= 0.000001f) return; len = sqrtf(len); if (len != 0.0f) - vec3_mult_scalar(v9, 1.0f / len, v9); + v9 *= 1.0f / len; vec3 v8; v8.x = -v9.z * v9.x; v8.y = -v9.z * v9.y - v9.z; v8.z = v9.y * v9.y - v9.x * -v9.x + v9.y; - vec3_length_squared(v8, len); + len = vec3::length_squared(v8); if (len <= 0.000001f) return; len = sqrtf(len); if (len != 0.0f) - vec3_mult_scalar(v8, 1.0f / len, v8); + v8 *= 1.0f / len; - vec3 v10; - vec3_cross(v9, v8, v10); + vec3 v10 = vec3::cross(v9, v8); mat4 rot_mat = mat4_identity; *(vec3*)&rot_mat.row0 = v10; @@ -4286,10 +4279,8 @@ static void bone_data_mult_ik(bone_data* a1, int32_t skeleton_select) { vec3 v30; mat4_mult_vec3_inv_trans(&mat, &a1->ik_target, &v30); - float_t v6; - float_t v8; - vec2_length_squared(*(vec2*)&v30, v6); - vec3_length_squared(v30, v8); + float_t v6 = vec2::length_squared(*(vec2*)&v30); + float_t v8 = vec3::length_squared(v30); float_t v9 = sqrtf(v6); float_t v10 = sqrtf(v8); mat4 rot_mat; @@ -4305,10 +4296,9 @@ static void bone_data_mult_ik(bone_data* a1, int32_t skeleton_select) { vec3 pole_target; mat4_get_translation(a1->pole_target_mat, &pole_target); mat4_mult_vec3_inv_trans(&mat, &pole_target, &pole_target); - float_t pole_target_length; - vec2_length(*(vec2*)&pole_target.y, pole_target_length); + float_t pole_target_length = vec2::length(*(vec2*)&pole_target.y); if (pole_target_length > 0.000001f) { - vec3_mult_scalar(pole_target, 1.0f / pole_target_length, pole_target); + pole_target *= 1.0f / pole_target_length; float_t rot_cos = pole_target.y; float_t rot_sin = pole_target.z; mat4_rotate_x_mult_sin_cos(&mat, rot_sin, rot_cos, &mat); @@ -5189,7 +5179,7 @@ static void mothead_func_17(mothead_func_data* func_data, + (float_t)(v5->field_1588.field_330.field_20.y * v5->field_1588.field_330.field_20.y)) + (float_t)(v5->field_1588.field_330.field_20.z * v5->field_1588.field_330.field_20.z); if (_mm_sqrt_ps(v29).m128_f32[0] > v18) { - vec3_normalize(&v5->field_1588.field_330.field_20); + vec3::normalize(&v5->field_1588.field_330.field_20); v30 = v18 * *v11; v31 = v18 * v5->field_1588.field_330.field_20.y; v5->field_1588.field_330.field_20.z = v18 * v5->field_1588.field_330.field_20.z; @@ -6179,10 +6169,8 @@ static void motion_blend_mot_interpolate(motion_blend_mot* a1) { } keyframe_data = (vec3*)&a1->mot_key_data.key_set_data.data()[bone_key_set_count]; - vec3 global_trans = keyframe_data[0]; + vec3 global_trans = reverse ? -keyframe_data[0] : keyframe_data[0]; vec3 global_rotation = keyframe_data[1]; - if (reverse) - vec3_negate(global_trans, global_trans); a1->bone_data.global_trans = global_trans; a1->bone_data.global_rotation = global_rotation; @@ -6411,7 +6399,7 @@ static void sub_140412E10(motion_blend_mot* a1, int32_t skeleton_select) { & a1->field_0.field_8.bitfield.data()[i.motion_bone_index >> 5]) { sub_1401EB1D0(&i, skeleton_select); if (i.type == BONE_DATABASE_BONE_POSITION_ROTATION && (a1->field_4F8.field_0 & 0x02)) - vec3_add(i.trans_prev[skeleton_select], a1->field_4F8.field_90, i.trans_prev[skeleton_select]); + i.trans_prev[skeleton_select] += a1->field_4F8.field_90; } } @@ -6580,8 +6568,8 @@ static void sub_140507F60(rob_chara* rob_chr) { mat4* v3 = rob_chara_bone_data_get_mats_mat(rob_chr->bone_data, ROB_BONE_N_HARA); mat4_get_translation(v3, &rob_chr->data.miku_rot.field_24); - vec3_sub(rob_chr->data.miku_rot.field_24, - rob_chr->data.miku_rot.field_48, rob_chr->data.miku_rot.field_54); + rob_chr->data.miku_rot.field_54 = rob_chr->data.miku_rot.field_24 + - rob_chr->data.miku_rot.field_48; mat4* v8 = rob_chara_bone_data_get_mats_mat(rob_chr->bone_data, ROB_BONE_N_HARA_CP); vec3 v10 = { 0.0f, 0.0f, 1.0f }; @@ -6607,12 +6595,8 @@ void rob_chara_data_adjust_ctrl(rob_chara* rob_chr, rob_chara_data_adjust* adjus break; } - vec3 v8; - vec3 v9; - vec3_add_scalar(adjust->external_force_cycle, v7, v8); - vec3_mult(adjust->external_force, adjust->external_force_cycle_strength, v9); - vec3_mult(v8, v9, v9); - vec3_add(v9, adjust->external_force, adjust->curr_external_force); + adjust->curr_external_force = (adjust->external_force_cycle + v7) + * (adjust->external_force * adjust->external_force_cycle_strength) + adjust->external_force; if (adjust->type == 1) { mat4 mat = mat4_identity; @@ -7804,8 +7788,7 @@ static void sub_140504AC0(rob_chara* rob_chr) { vec3 v4 = rob_chr->data.miku_rot.field_30; vec3 v20 = 0.0f; if (rob_chr->data.field_0 & 0x02) { - vec3_add(v4, rob_chr->data.miku_rot.field_3C, v20); - vec3_add(v20, rob_chr->data.field_8.field_B8.field_10, v20); + v20 = v4 + rob_chr->data.miku_rot.field_3C + rob_chr->data.field_8.field_B8.field_10; v4.y = rob_chr->data.field_8.field_B8.field_10.y - get_osage_gravity_const() * rob_chr->data.field_1588.field_0.field_200; } @@ -7872,7 +7855,7 @@ static void sub_140504AC0(rob_chara* rob_chr) { rob_chr->data.miku_rot.field_30 = v4; rob_chr->data.miku_rot.field_3C = 0.0f; - vec3_add(v20, rob_chr->data.miku_rot.position, rob_chr->data.miku_rot.position); + rob_chr->data.miku_rot.position = v20 + rob_chr->data.miku_rot.position; } static void rob_base_rob_chara_ctrl_thread_main(rob_chara* rob_chr) { @@ -8119,23 +8102,19 @@ static void sub_140407280(struc_258* a1, std::vector* a2, mat4* mat, vec3 v67; mat4_mult_vec3_inv_trans(v73, &a1->field_184, &v67); - float_t v26; - vec3_length(v67, v26); - if (v26 < 0.000001f) + if (vec3::length(v67) < 0.000001f) return; vec3 v68; mat4_mult_vec3_inv_trans(v73, &v69, &v68); - float_t v28; - vec3_length(v68, v28); + float_t v28 = vec3::length(v68); if (v28 < 0.000001f) return; - vec3_normalize(v67, v67); - vec3_mult_scalar(v67, v28, v68); - float_t v39; - vec2_length(*(vec2*)&v67, v39); + v67 = vec3::normalize(v67); + v68 = v67 * v28; + float_t v39 = vec2::length(*(vec2*)&v67); float_t v38; if (a1->field_1C8 == 3) @@ -8143,8 +8122,7 @@ static void sub_140407280(struc_258* a1, std::vector* a2, mat4* mat, else v38 = (float_t)(75.0 * DEG_TO_RAD); - float_t v31; - vec3_length(v67, v31); + float_t v31 = vec3::length(v67); bool v36; float_t v40; @@ -8275,7 +8253,7 @@ static void sub_140407280(struc_258* a1, std::vector* a2, mat4* mat, float_t v51 = (v48 - atan2f(-v68.x, v68.y)) * a1->field_198; vec3 v71 = *(vec3*&)v73->row2; v71.y += 1.0f; - vec3_mult_scalar(v71, 0.5f, v71); + v71 *= 0.5f; mat4 v72 = *v7[MOTION_BONE_CL_KAO].node[1].mat; mat4_mult_axis_angle(&v72, &v71, v51, &v72); @@ -8285,7 +8263,7 @@ static void sub_140407280(struc_258* a1, std::vector* a2, mat4* mat, if (v36) v52 = a1->field_1A0; else - vec2_length(*(vec2*)&v67, v52); + v52 = vec2::length(*(vec2*)&v67); if (a1->field_190) { float_t v55 = fabsf(v49); @@ -8473,15 +8451,13 @@ static void sub_140409170(struc_258* a1, mat4* a2, std::vector* a3, m mat4_get_translation(v19->data()[MOTION_BONE_KL_EYE_L].parent_mat, &v52); mat4_get_translation(v19->data()[MOTION_BONE_KL_EYE_R].parent_mat, &v54); - vec3_add(v52, v54, v52); - vec3_mult_scalar(v52, 0.5f, v54); + v54 = (v52 + v54) * 0.5f; mat4_set_translation(mat, &v54); vec3 v53; mat4_mult_vec3_inv_trans(mat, &a1->field_C0, &v53); - float_t v37; - vec3_length(v53, v37); + float_t v37 = vec3::length(v53); if (fabsf(v37) <= 0.000001f || v53.x * v53.x + v53.z * v53.z <= 0.01f) { v29 = 0.0f; v32 = 0.0f; @@ -8489,7 +8465,7 @@ static void sub_140409170(struc_258* a1, mat4* a2, std::vector* a3, m else if (v37 < a1->field_B0) { v53.z = fabsf(v53.z); - vec3_mult_scalar(v53, a1->field_B0 / v37, v53); + v53 *= a1->field_B0 / v37; mat4_mult_vec3_trans(mat, &v53, &v53); vec3 v56; @@ -8525,7 +8501,7 @@ static void sub_140409170(struc_258* a1, mat4* a2, std::vector* a3, m vec3 v58; mat4_mult_vec3_inv_trans(v19->data()[MOTION_BONE_KL_EYE_L].parent_mat, &a1->field_C0, &v58); - vec3_sub(v58, a1->field_48.field_20, v58); + v58 -= a1->field_48.field_20; vec3 v56; v56.x = v43; @@ -8546,7 +8522,7 @@ static void sub_140409170(struc_258* a1, mat4* a2, std::vector* a3, m mat4_mult_vec3_inv_trans(v19->data()[MOTION_BONE_KL_EYE_R].parent_mat, &a1->field_C0, &v59); vec3 v60 = a1->field_48.field_20; v60.x = -v60.x; - vec3_sub(v59, v60, v59); + v59 -= v60; sub_140406FC0(a1, &v19->data()[MOTION_BONE_KL_EYE_R], &a1->field_10C, &v59, &v55, &v56, a7, v11, v15); @@ -8674,9 +8650,9 @@ static void rob_chara_set_hands_adjust(rob_chara* rob_chr) { &rob_chr->data.motion.hand_adjust_prev[i]); } -static void sub_14040AE10(mat4* mat, vec3* a2) { +static void sub_14040AE10(mat4* mat, const vec3 a2) { vec3 v8; - mat4_mult_vec3_inv_trans(mat, a2, &v8); + mat4_mult_vec3_inv_trans(mat, &a2, &v8); float_t v3 = v8.x * v8.x + v8.y * v8.y; float_t v5 = sqrtf(v3); float_t v6 = sqrtf(v3 + (v8.z * v8.z)); @@ -8699,11 +8675,11 @@ static void sub_140406A70(vec3* a1, std::vector* bones, mat4* a3, vec mat4_get_translation(v14->pole_target_mat, &v36); mat4 v38 = *v14->node->mat; - sub_14040AE10(&v38, &v14->ik_target); + sub_14040AE10(&v38, v14->ik_target); mat4_mult_vec3_inv_trans(&v38, &v36, &v36); v38 = *v14->node->mat; - sub_14040AE10(&v38, a4); + sub_14040AE10(&v38, *a4); vec3 v37; mat4_mult_vec3_trans(&v38, &v36, &v37); @@ -8776,8 +8752,7 @@ static bool sub_14053ACA0(rob_chara* rob_chr, int32_t hand) { mat4 v42; mat4_mult(v40, &adjust_data.mat, &v42); - vec3 v37; - vec3_mult_scalar(rob_chr->data.motion.hand_adjust[hand].offset, 1.0f - chara_scale / adjust_scale, v37); + vec3 v37 = rob_chr->data.motion.hand_adjust[hand].offset * (1.0f - chara_scale / adjust_scale); vec3 v38; mat4_mult_vec3_trans(&v42, &v37, &v38); @@ -8790,13 +8765,12 @@ static bool sub_14053ACA0(rob_chara* rob_chr, int32_t hand) { if (rob_chr->data.motion.hand_adjust[hand].disable_z) v27.z = v40->row3.z - v38.z; - vec3 v39; - vec3_add(v38, v27, v39); + vec3 v39 = v38 + v27; vec3 v18 = 0.0f; if (v15 > 0) { mat4_mult_vec3_trans(&v42, &rob_chr->data.motion.hand_adjust[hand].offset, &v38); - vec3_add(v38, v27, v18); + v18 = v38 + v27; } sub_140418A00(rob_chr->bone_data, &v39, off_140C9E020[hand], rotation_blend, @@ -8806,8 +8780,7 @@ static bool sub_14053ACA0(rob_chara* rob_chr, int32_t hand) { mat4* v40 = rob_chara_bone_data_get_mats_mat(rob_chr->bone_data, rob_kl_te_bones[hand]); mat4_set_translation(v40, &v18); - vec3 v37; - vec3_negate(rob_chr->data.motion.hand_adjust[hand].offset, v37); + vec3 v37 = -rob_chr->data.motion.hand_adjust[hand].offset; mat4_mult_vec3_trans(v40, &v37, &v39); if (!--v15) { rotation_blend = 1.0f; @@ -8883,38 +8856,38 @@ static bool sub_14053B580(rob_chara* rob_chr, int32_t a2) { v45 = v0.field_10; break; case 16: - vec3_add(v0.field_10, v13, v45); + v45 = v0.field_10 + v13; break; case 10: { float_t ratio0 = ((rob_chara_bone_data*)((size_t)rob_chr->field_20 + 0x28))->ik_scale.ratio0; - vec3_mult_scalar(v13, ratio0, v45); + v45 = v13 * ratio0; } break; case 11: { float_t ratio1 = ((rob_chara_bone_data*)((size_t)rob_chr->field_20 + 0x28))->ik_scale.ratio1; - vec3_mult_scalar(v13, ratio1, v45); + v45 = v13 * ratio1; } break; case 12: { float_t ratio3 = ((rob_chara_bone_data*)((size_t)rob_chr->field_20 + 0x28))->ik_scale.ratio3; - vec3_mult_scalar(v13, ratio3, v45); + v45 = v13 * ratio3; } break; case 13: { float_t ratio0 = rob_chr->bone_data->ik_scale.ratio0; - vec3_mult_scalar(v13, 1.0f / ratio0, v45); + v45 = v13 * (1.0f / ratio0); } break; case 14: { float_t ratio1 = rob_chr->bone_data->ik_scale.ratio1; - vec3_mult_scalar(v13, 1.0f / ratio1, v45); + v45 = v13 * (1.0f / ratio1); } break; case 15: { float_t ratio3 = rob_chr->bone_data->ik_scale.ratio3; - vec3_mult_scalar(v13, 1.0f / ratio3, v45); + v45 = v13 * (1.0f / ratio3); } break; default: if (v0.field_C < 16) { mat4* v26 = rob_chara_bone_data_get_mats_mat( (rob_chara_bone_data*)((size_t)rob_chr->field_20 + 0x28), dword_140A2DDD0[v0.field_C]); mat4_get_translation(v26, &v45); - vec3_add(v45, v0.field_10, v45); + v45 += v0.field_10; } else { mat4* v23 = rob_chara_bone_data_get_mats_mat( @@ -8972,8 +8945,7 @@ static bool sub_14053B580(rob_chara* rob_chr, int32_t a2) { break; } - vec3 v36; - vec3_sub(v48, v13, v36); + vec3 v36 = v48 - v13; if (v0.field_1C.x != 0.0f && v36.x < v0.field_1C.x) v48.x = v0.field_1C.x + v13.x; else if (v0.field_28.x != 0.0f && v36.x > v0.field_28.x) @@ -9001,12 +8973,9 @@ static void sub_1403F9A40(vec3* a1, vec3* a2, mat4* a3, float_t a4, float_t a5) } static bool sub_14040AC40(vec3* a1, vec3* a2, float_t a3, vec3* a4) { - vec3 v4; - vec3_negate(*a2, v4); - float_t v7; - vec3_dot(*a1, v4, v7); - float_t v8; - vec3_dot(v4, v4, v8); + vec3 v4 = -*a2; + float_t v7 = vec3::dot(*a1, v4); + float_t v8 = vec3::dot(v4, v4); v8 -= a3 * a3; if (v8 > 0.0f && v7 > 0.0f) return false; @@ -9015,7 +8984,7 @@ static bool sub_14040AC40(vec3* a1, vec3* a2, float_t a3, vec3* a4) { if (v10 < 0.0f) return false; - vec3_mult_scalar(*a1, sqrtf(v10) - v7, *a4); + *a4 = *a1 * (sqrtf(v10) - v7); return true; } @@ -9027,12 +8996,13 @@ static void sub_1403FA040(vec3* a1, float_t a2, mat4* a3, float_t ymin, mat4_mult_vec3_inv(a3, a1, &v16); v16.x = 0.0f; - float_t v18; - vec3_length_squared(v16, v18); + float_t v18 = vec3::length_squared(v16); if (fabsf(v18) <= 0.000001f) goto LABEL_66; - vec3_normalize(v16, v16); + v18 = sqrtf(v18); + if (v18 != 0.0f) + v16 *= 1.0f / v18; float_t v23; if (zmax - zmin >= ymax - ymin) { @@ -9047,7 +9017,7 @@ static void sub_1403FA040(vec3* a1, float_t a2, mat4* a3, float_t ymin, v52.z = zmax - v23; if (fabsf(v16.y) <= 0.000001f) { if (fabsf(ymin) <= 0.000001f || fabsf(ymax) <= 0.000001f) { - vec3_mult_scalar(v16, a2, v16); + v16 *= a2; if (v16.z < zmin + v23) { v16.z = zmin + v23; goto LABEL_66; @@ -9072,7 +9042,7 @@ static void sub_1403FA040(vec3* a1, float_t a2, mat4* a3, float_t ymin, v32 = a2; v17 = false; } - vec3_mult_scalar(v16, v32, v16); + v16 *= v32; if (v17) goto LABEL_66; } @@ -9080,8 +9050,7 @@ static void sub_1403FA040(vec3* a1, float_t a2, mat4* a3, float_t ymin, else { v16.y = 0.0f; if (fabsf(v16.z) > 0.000001f) { - vec3_normalize(v16, v16); - vec3_mult_scalar(v16, a2, v16); + v16 = vec3::normalize(v16) * a2; v16.z = clamp_def(v16.z, zmin, zmax); } goto LABEL_66; @@ -9099,7 +9068,7 @@ static void sub_1403FA040(vec3* a1, float_t a2, mat4* a3, float_t ymin, v52.z = zmax - v23; if (fabsf(v16.z) <= 0.000001f) { if (fabsf(zmin) <= 0.000001f || fabsf(zmax) <= 0.000001f) { - vec3_mult_scalar(v16, a2, v16); + v16 *= a2; if (v16.y < ymin + v23) { v16.y = ymin + v23; goto LABEL_66; @@ -9124,7 +9093,7 @@ static void sub_1403FA040(vec3* a1, float_t a2, mat4* a3, float_t ymin, v32 = a2; v17 = false; } - vec3_mult_scalar(v16, v32, v16); + v16 *= v32; if (v17) goto LABEL_66; } @@ -9132,8 +9101,7 @@ static void sub_1403FA040(vec3* a1, float_t a2, mat4* a3, float_t ymin, else { v16.z = 0.0f; if (fabsf(v16.y) > 0.000001f) { - vec3_normalize(v16, v16); - vec3_mult_scalar(v16, a2, v16); + v16 = vec3::normalize(v16) * a2; v16.y = clamp_def(v16.y, ymin, ymax); } goto LABEL_66; @@ -9147,34 +9115,27 @@ static void sub_1403FA040(vec3* a1, float_t a2, mat4* a3, float_t ymin, goto LABEL_66; } - float_t v40; - vec3_length(v51, v40); + float_t v40 = vec3::length(v51); bool v17 = true; if (a2 < v40) { v40 = a2; v17 = false; } - vec3_mult_scalar(v16, v40, v16); + v16 *= v40; if (v17) goto LABEL_66; } LABEL_60: - { - float_t v20; - vec3_dot(*a8, v16, v20); - if (v20 != 0.0f) { - float_t v43; - vec3_length(*a8, v43); - float_t v44 = v43 + (v43 * 0.97f - v43) * step; + if (vec3::dot(*a8, v16) != 0.0f) { + float_t v43 = vec3::length(*a8); + float_t v44 = v43 + (v43 * 0.97f - v43) * step; - float_t v45; - vec3_length(v16, v45); - if (v45 < v44) { - if (v45 != 0.0f) - vec3_mult_scalar(v16, 1.0f / v45, v16); - vec3_mult_scalar(v16, v44, v16); - } + float_t v45 = vec3::length(v16); + if (v45 < v44) { + if (v45 != 0.0f) + v16 *= 1.0f / v45; + v16 *= v44; } } @@ -9197,14 +9158,9 @@ static void sub_1403FA770(rob_chara_bone_data_sleeve_adjust* a1) { vec3 v40; sub_1403F9A40(&v40, &v43, v5, a1->sleeve_r.cyofs, a1->sleeve_r.czofs); - vec3 v45; - vec3_sub(v41, v40, v45); - - vec3 v44; - vec3_sub(v40, v41, v44); - - float_t v20; - vec3_distance(v41, v40, v20); + vec3 v45 = v41 - v40; + vec3 v44 = v40 - v41; + float_t v20 = vec3::distance(v41, v40); float_t v21 = (a1->sleeve_l.radius * a1->radius + a1->sleeve_r.radius - v20) * 0.5f; float_t v22 = (a1->sleeve_r.radius * a1->radius + a1->sleeve_l.radius - v20) * 0.5f; @@ -9213,14 +9169,14 @@ static void sub_1403FA770(rob_chara_bone_data_sleeve_adjust* a1) { bool v17 = false; if (v21 <= 0.0f) { v16 = false; - vec3_length(a1->field_5C, v21); + v21 = vec3::length(a1->field_5C); float_t v25 = (0.97f * v21 - v21) * a1->step + v21; if (v21 <= 0.001f || v25 <= 0.0f) { a1->field_5C = 0.0f; v45 = 0.0f; } else { - vec3_mult_scalar(a1->field_5C, v25 / v21, a1->field_5C); + a1->field_5C *= v25 / v21; mat4_mult_vec3(v4, &a1->field_5C, &v45); v17 = true; } @@ -9230,14 +9186,14 @@ static void sub_1403FA770(rob_chara_bone_data_sleeve_adjust* a1) { bool v18 = false; if (v22 <= 0.0f) { v19 = false; - vec3_length(a1->field_68, v22); + v22 = vec3::length(a1->field_68); float_t v31 = (0.97f * v22 - v22) * a1->step + v22; if (v22 <= 0.001f || v31 <= 0.0f) { a1->field_68 = 0.0f; v44 = 0.0f; } else { - vec3_mult_scalar(a1->field_68, v31 / v22, a1->field_68); + a1->field_68 *= v31 / v22; mat4_mult_vec3(v5, &a1->field_68, &v44); v18 = true; } @@ -9251,15 +9207,11 @@ static void sub_1403FA770(rob_chara_bone_data_sleeve_adjust* a1) { sub_1403FA040(&v44, v22, v5, a1->sleeve_r.ymin, a1->sleeve_r.ymax, a1->sleeve_r.zmin, a1->sleeve_r.zmax, &a1->field_68, a1->step); - if (v16 || v17) { - vec3_add(v42, v45, v42); - sub_14040AE10(a1->bones->data()[MOTION_BONE_C_KATA_L].node[2].mat, &v42); - } + if (v16 || v17) + sub_14040AE10(a1->bones->data()[MOTION_BONE_C_KATA_L].node[2].mat, v42 + v45); - if (v19 || v18) { - vec3_add(v43, v44, v43); - sub_14040AE10(a1->bones->data()[MOTION_BONE_C_KATA_R].node[2].mat, &v43); - } + if (v19 || v18) + sub_14040AE10(a1->bones->data()[MOTION_BONE_C_KATA_R].node[2].mat, v43 + v44); } static void sub_1403F9B20(rob_chara_bone_data_sleeve_adjust* a1, motion_bone_index motion_bone_index) { @@ -9318,29 +9270,24 @@ static void sub_1403F9B20(rob_chara_bone_data_sleeve_adjust* a1, motion_bone_ind mat4* v23 = v15[MOTION_BONE_KL_MUNE_B_WJ].node->mat; mat4_mult_vec3_trans(v23, &sleeve_mune_ofs, &v40); - vec3 v41; - vec3_sub(v37, v40, v41); + vec3 v41 = v37 - v40; - float_t v24; - vec3_length(v41, v24); - float_t v26 = sleeve_radius * a1->radius + sleeve_mune_rad - v24; + float_t v26 = sleeve_radius * a1->radius + sleeve_mune_rad - vec3::length(v41); if (v26 > 0.0f) sub_1403FA040(&v41, v26, v19, sleeve_ymin, sleeve_ymax, sleeve_zmin, sleeve_zmax, v6, a1->step); else { - float_t v31; - vec3_length(*v6, v31); + float_t v31 = vec3::length(*v6); float_t v32 = (0.97f * v31 - v31) * a1->step + v31; if (v31 <= 0.001f || v32 <= 0.0f) { *v6 = 0.0f; return; } - vec3_mult_scalar(*v6, v32 / v31, *v6); + *v6 *= v32 / v31; mat4_mult_vec3(v19, v6, &v41); } mat4* v42 = v15[motion_bone_index].node[2].mat; - vec3_add(v39, v41, v39); - sub_14040AE10(v42, &v39); + sub_14040AE10(v42, v39 + v41); } static void sub_1403FAF30(rob_chara_bone_data_sleeve_adjust* a1, std::vector* bones, float_t step) { @@ -9495,14 +9442,10 @@ static void rob_chara_bone_data_set_left_hand_scale(rob_chara_bone_data* rob_bon vec3 trans; mat4_get_translation(kl_te_wj_mat, &trans); + trans -= trans * scale; mat4 mat; mat4_scale(scale, scale, scale, &mat); - - vec3 temp; - vec3_mult_scalar(trans, scale, temp); - vec3_sub(trans, temp, trans); - mat4_set_translation(&mat, &trans); for (int32_t i = ROB_BONE_KL_TE_L_WJ; i <= ROB_BONE_NL_OYA_C_L_WJ; i++) { @@ -9525,14 +9468,10 @@ static void rob_chara_bone_data_set_right_hand_scale(rob_chara_bone_data* rob_bo vec3 trans; mat4_get_translation(kl_te_wj_mat, &trans); + trans -= trans * scale; mat4 mat; mat4_scale(scale, scale, scale, &mat); - - vec3 temp; - vec3_mult_scalar(trans, scale, temp); - vec3_sub(trans, temp, trans); - mat4_set_translation(&mat, &trans); for (int32_t i = ROB_BONE_KL_TE_R_WJ; i <= ROB_BONE_NL_OYA_C_R_WJ; i++) { @@ -10704,7 +10643,7 @@ static void sub_1404182B0(rob_chara_bone_data* rob_bone_data) { v3->field_4F8.field_9C = v7->trans; if (sub_140413790(&v3->field_4F8)) { // WTF??? v3->field_4F8.field_90 = v7->trans; - vec3_sub(v7->trans, v7->trans, v7->trans); + v7->trans -= v7->trans; } } diff --git a/src/KKdLib/vec.hpp b/src/KKdLib/vec.hpp index ca49467d..e9356525 100644 --- a/src/KKdLib/vec.hpp +++ b/src/KKdLib/vec.hpp @@ -1985,418 +1985,6 @@ inline void vec4i_to_vec4u16(const vec4i& src, vec4u16& dst) { dst.w = (uint16_t)src.w; } -inline void vec2_add(const vec2& x, const vec2& y, vec2& z) { - z = x + y; -} - -inline void vec2_add_scalar(const vec2& x, const float_t y, vec2& z) { - z = x + y; -} - -inline void vec2_sub(const vec2& x, const vec2& y, vec2& z) { - z = x - y; -} - -inline void vec2_sub_scalar(const vec2& x, const float_t y, vec2& z) { - z = x - y; -} - -inline void vec2_mult(const vec2& x, const vec2& y, vec2& z) { - z = x * y; -} - -inline void vec2_mult_scalar(const vec2& x, const float_t y, vec2& z) { - z = x * y; -} - -inline void vec2_div(const vec2& x, const vec2& y, vec2& z) { - z = x / y; -} - -inline void vec2_div_scalar(const vec2& x, const float_t y, vec2& z) { - z = x / y; -} - -inline void vec2_and(const vec2& x, const vec2& y, vec2& z) { - z = x & y; -} - -inline void vec2_and_scalar(const vec2& x, const float_t y, vec2& z) { - z = x & y; -} - -inline void vec2_xor(const vec2& x, const vec2& y, vec2& z) { - z = x ^ y; -} - -inline void vec2_xor_scalar(const vec2& x, const float_t y, vec2& z) { - z = x ^ y; -} - -inline void vec2_negate(const vec2& x, vec2& z) { - z = -x; -} - -inline void vec2_dot(const vec2& x, const vec2& y, float_t& z) { - z = vec2::dot(x, y); -} - -inline void vec2_length(const vec2& x, float_t& z) { - z = vec2::length(x); -} - -inline void vec2_length_squared(const vec2& x, float_t& z) { - z = vec2::length_squared(x); -} - -inline void vec2_distance(const vec2& x, const vec2& y, float_t& z) { - z = vec2::distance(x, y); -} - -inline void vec2_distance_squared(const vec2& x, const vec2& y, float_t& z) { - z = vec2::distance_squared(x, y); -} - -inline void vec2_lerp(const vec2& x, const vec2& y, vec2& z, const float_t blend) { - z = vec2::lerp(x, y, blend); -} - -inline void vec2_lerp_scalar(const vec2& x, const vec2& y, vec2& z, const float_t blend) { - z = vec2::lerp(x, y, blend); -} - -inline void vec2_normalize(const vec2& x, vec2& z) { - z = vec2::normalize(x); -} - -inline void vec2_rcp(const vec2& x, vec2& z) { - z = vec2::rcp(x); -} - -inline void vec2_min(const vec2& x, const vec2& y, vec2& z) { - z = vec2::min(x, y); -} - -inline void vec2_max(const vec2& x, const vec2& y, vec2& z) { - z = vec2::max(x, y); -} - -inline void vec2_clamp(const vec2& x, const vec2& y, const vec2& z, vec2& w) { - w = vec2::clamp(x, y, z); -} - -inline void vec2_clamp_scalar(const vec2& x, const float_t y, const float_t z, vec2& w) { - w = vec2::clamp(x, y, z); -} - -inline void vec2_mult_min_max(const vec2& x, const vec2& y, const vec2& z, vec2& w) { - w = vec2::mult_min_max(x, y, z); -} - -inline void vec2_mult_min_max_scalar(const vec2& x, const float_t y, const float_t z, vec2& w) { - w = vec2::mult_min_max(x, y, z); -} - -inline void vec2_div_min_max(const vec2& x, const vec2& y, const vec2& z, vec2& w) { - w = vec2::div_min_max(x, y, z); -} - -inline void vec2_div_min_max_scalar(const vec2& x, const float_t y, const float_t z, vec2& w) { - w = vec2::div_min_max(x, y, z); -} - -inline void vec3_add(const vec3& x, const vec3& y, vec3& z) { - z = x + y; -} - -inline void vec3_add_scalar(const vec3& x, const float_t y, vec3& z) { - z = x + y; -} - -inline void vec3_sub(const vec3& x, const vec3& y, vec3& z) { - z = x - y; -} - -inline void vec3_sub_scalar(const vec3& x, const float_t y, vec3& z) { - z = x - y; -} - -inline void vec3_mult(const vec3& x, const vec3& y, vec3& z) { - z = x * y; -} - -inline void vec3_mult_scalar(const vec3& x, const float_t y, vec3& z) { - z = x * y; -} - -inline void vec3_div(const vec3& x, const vec3& y, vec3& z) { - z = x / y; -} - -inline void vec3_div_scalar(const vec3& x, const float_t y, vec3& z) { - z = x / y; -} - -inline void vec3_and(const vec3& x, const vec3& y, vec3& z) { - z = x & y; -} - -inline void vec3_and_scalar(const vec3& x, const float_t y, vec3& z) { - z = x & y; -} - -inline void vec3_xor(const vec3& x, const vec3& y, vec3& z) { - z = x ^ y; -} - -inline void vec3_xor_scalar(const vec3& x, const float_t y, vec3& z) { - z = x ^ y; -} - -inline void vec3_negate(const vec3& x, vec3& z) { - z = -x; -} - -inline void vec3_dot(const vec3& x, const vec3& y, float_t& z) { - z = vec3::dot(x, y); -} - -inline void vec3_length(const vec3& x, float_t& z) { - z = vec3::length(x); -} - -inline void vec3_length_squared(const vec3& x, float_t& z) { - z = vec3::length_squared(x); -} - -inline void vec3_distance(const vec3& x, const vec3& y, float_t& z) { - z = vec3::distance(x, y); -} - -inline void vec3_distance_squared(const vec3& x, const vec3& y, float_t& z) { - z = vec3::distance_squared(x, y); -} - -inline void vec3_lerp(const vec3& x, const vec3& y, vec3& z, const vec3& blend) { - z = vec3::lerp(x, y, blend); -} - -inline void vec3_lerp_scalar(const vec3& x, const vec3& y, vec3& z, const float_t blend) { - z = vec3::lerp(x, y, blend); -} - -inline void vec3_normalize(const vec3& x, vec3& z) { - z = vec3::normalize(x); -} - -inline void vec3_rcp(const vec3& x, vec3& z) { - z = vec3::rcp(x); -} - -inline void vec3_min(const vec3& x, const vec3& y, vec3& z) { - z = vec3::min(x, y); -} - -inline void vec3_max(const vec3& x, const vec3& y, vec3& z) { - z = vec3::max(x, y); -} - -inline void vec3_clamp(const vec3& x, const vec3& y, const vec3& z, vec3& w) { - w = vec3::clamp(x, y, z); -} - -inline void vec3_clamp_scalar(const vec3& x, const vec3& y, const float_t z, vec3& w) { - w = vec3::clamp(x, y, z); -} - -inline void vec3_mult_min_max(const vec3& x, const vec3& y, const vec3& z, vec3& w) { - w = vec3::mult_min_max(x, y, z); -} - -inline void vec3_mult_min_max_scalar(const vec3& x, const vec3& y, const float_t z, vec3& w) { - w = vec3::mult_min_max(x, y, z); -} - -inline void vec3_div_min_max(const vec3& x, const vec3& y, const vec3& z, vec3& w) { - w = vec3::div_min_max(x, y, z); -} - -inline void vec3_div_min_max_scalar(const vec3& x, const vec3& y, const float_t z, vec3& w) { - w = vec3::div_min_max(x, y, z); -} - -inline void vec3_cross(const vec3& x, const vec3& y, vec3& z) { - z = vec3::cross(x, y); -} - -inline void vec4_add(const vec4& x, const vec4& y, vec4& z) { - z = x + y; -} - -inline void vec4_add_scalar(const vec4& x, const float_t y, vec4& z) { - z = x + y; -} - -inline void vec4_sub(const vec4& x, const vec4& y, vec4& z) { - z = x - y; -} - -inline void vec4_sub_scalar(const vec4& x, const float_t y, vec4& z) { - z = x - y; -} - -inline void vec4_mult(const vec4& x, const vec4& y, vec4& z) { - z = x * y; -} - -inline void vec4_mult_scalar(const vec4& x, const float_t y, vec4& z) { - z = x * y; -} - -inline void vec4_div(const vec4& x, const vec4& y, vec4& z) { - z = x / y; -} - -inline void vec4_div_scalar(const vec4& x, const float_t y, vec4& z) { - z = x / y; -} - -inline void vec4_and(const vec4& x, const vec4& y, vec4& z) { - z = x & y; -} - -inline void vec4_and_scalar(const vec4& x, const float_t y, vec4& z) { - z = x & y; -} - -inline void vec4_xor(const vec4& x, const vec4& y, vec4& z) { - z = x ^ y; -} - -inline void vec4_xor_scalar(const vec4& x, const float_t y, vec4& z) { - z = x ^ y; -} - -inline void vec4_negate(const vec4& x, vec4& z) { - z = -x; -} - -inline void vec4_dot(const vec4& x, const vec4& y, float_t& z) { - z = vec4::dot(x, y); -} - -inline void vec4_length(const vec4& x, float_t& z) { - z = vec4::length(x); -} - -inline void vec4_length_squared(const vec4& x, float_t& z) { - z = vec4::length_squared(x); -} - -inline void vec4_distance(const vec4& x, const vec4& y, float_t& z) { - z = vec4::distance(x, y); -} - -inline void vec4_distance_squared(const vec4& x, const vec4& y, float_t& z) { - z = vec4::distance_squared(x, y); -} - -inline void vec4_lerp(const vec4& x, const vec4& y, vec4& z, const vec4& blend) { - z = vec4::lerp(x, y, blend); -} - -inline void vec4_lerp_scalar(const vec4& x, const vec4& y, vec4& z, const float_t blend) { - z = vec4::lerp(x, y, blend); -} - -inline void vec4_normalize(const vec4& x, vec4& z) { - z = vec4::normalize(x); -} - -inline void vec4_rcp(const vec4& x, vec4& z) { - z = vec4::rcp(x); -} - -inline void vec4_min(const vec4& x, const vec4& y, vec4& z) { - z = vec4::min(x, y); -} - -inline void vec4_max(const vec4& x, const vec4& y, vec4& z) { - z = vec4::max(x, y); -} - -inline void vec4_clamp(const vec4& x, const vec4& y, const vec4& z, vec4& w) { - w = vec4::clamp(x, y, z); -} - -inline void vec4_clamp_scalar(const vec4& x, const float_t y, const float_t z, vec4& w) { - w = vec4::clamp(x, y, z); -} - -inline void vec4_mult_min_max(const vec4& x, const vec4& y, const vec4& z, vec4& w) { - w = vec4::mult_min_max(x, y, z); -} - -inline void vec4_mult_min_max_scalar(const vec4& x, const float_t y, const float_t z, vec4& w) { - w = vec4::mult_min_max(x, y, z); -} - -inline void vec4_div_min_max(const vec4& x, const vec4& y, const vec4& z, vec4& w) { - w = vec4::div_min_max(x, y, z); -} - -inline void vec4_div_min_max_scalar(const vec4& x, const float_t y, const float_t z, vec4& w) { - w = vec4::div_min_max(x, y, z); -} - -inline void vec2i_add(const vec2i& x, const vec2i& y, vec2i& z) { - z = x + y; -} - -inline void vec2i_add_scalar(const vec2i& x, const int32_t y, vec2i& z) { - z = x + y; -} - -inline void vec2i_sub(const vec2i& x, const vec2i& y, vec2i& z) { - z = x - y; -} - -inline void vec2i_sub_scalar(const vec2i& x, const int32_t y, vec2i& z) { - z = x - y; -} - -inline void vec3i_add(const vec3i& x, const vec3i& y, vec3i& z) { - z = x + y; -} - -inline void vec3i_add_scalar(const vec3i& x, const int32_t y, vec3i& z) { - z = x + y; -} - -inline void vec3i_sub(const vec3i& x, const vec3i& y, vec3i& z) { - z = x - y; -} - -inline void vec3i_sub_scalar(const vec3i& x, const int32_t y, vec3i& z) { - z = x - y; -} - -inline void vec4i_add(const vec4i& x, const vec4i& y, vec4i& z) { - z = x + y; -} - -inline void vec4i_add_scalar(const vec4i& x, const int32_t y, vec4i& z) { - z = x + y; -} - -inline void vec4i_sub(const vec4i& x, const vec4i& y, vec4i& z) { - z = x - y; -} - -inline void vec4i_sub_scalar(const vec4i& x, const int32_t y, vec4i& z) { - z = x - y; -} - inline void vec2_to_vec2i(const vec2& x, vec2i& z) { z = vec2i::store_xmm(_mm_cvtps_epi32(vec2::load_xmm(x))); } diff --git a/src/ReDIVA/render.cpp b/src/ReDIVA/render.cpp index b8f1de03..47a02ce8 100644 --- a/src/ReDIVA/render.cpp +++ b/src/ReDIVA/render.cpp @@ -87,7 +87,6 @@ struct common_data_struct { struct render_data { GLuint grid_vao; GLuint grid_vbo; - GL::UniformBuffer common_data_ubo; render_data(); ~render_data(); @@ -97,7 +96,6 @@ struct render_data { void load_common_data(); void unload_common_data(); - void update_common_data(common_data_struct* common_data, camera* cam); }; common_data_struct common_data; @@ -313,7 +311,7 @@ void draw_pass_3d_grid(render_context* rctx) { gl_state_set_depth_mask(GL_TRUE); shaders_ft.set(SHADER_FT_GRID); - render->common_data_ubo.Bind(0); + rctx->obj_scene_ubo.Bind(0); gl_state_bind_vertex_array(render->grid_vao); glDrawArrays(GL_LINES, 0, (GLsizei)grid_vertex_count); gl_state_use_program(0); @@ -325,7 +323,7 @@ void draw_pass_3d_grid(render_context* rctx) { float_t rob_frame = 0.0f; -render_data::render_data() : grid_vao(), grid_vbo(), common_data_ubo() { +render_data::render_data() : grid_vao(), grid_vbo() { } @@ -349,8 +347,6 @@ void render_data::unload() { } void render_data::load_common_data() { - common_data_ubo.Create(sizeof(common_data_struct)); - float_t* grid_verts = force_malloc_s(float_t, 3 * grid_vertex_count); size_t v = 0; @@ -400,10 +396,10 @@ void render_data::load_common_data() { glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, - sizeof(float_t) * 3, (void*)0); // Pos + sizeof(float_t) * 3, (void*)0); glEnableVertexAttribArray(1); glVertexAttribIPointer(1, 1, GL_INT, - sizeof(float_t) * 3, (void*)(sizeof(float_t) * 2)); // Color + sizeof(float_t) * 3, (void*)(sizeof(float_t) * 2)); gl_state_bind_array_buffer(0); gl_state_bind_vertex_array(0); @@ -412,8 +408,6 @@ void render_data::load_common_data() { } void render_data::unload_common_data() { - common_data_ubo.Destroy(); - if (grid_vbo) { glDeleteBuffers(1, &grid_vbo); grid_vbo = 0; @@ -425,10 +419,6 @@ void render_data::unload_common_data() { } } -void render_data::update_common_data(common_data_struct* common_data, camera* cam) { - common_data_ubo.WriteMapMemory(*common_data); -} - static bool render_init(render_init_struct* ris) { GLFWmonitor* monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); @@ -1039,17 +1029,6 @@ static void render_context_ctrl(render_context* rctx) { glfwSetWindowTitle(window, buf); ImGui::Render(); - - common_data_struct common_data = {}; - common_data.res.x = (float_t)internal_3d_res.x; - common_data.res.y = (float_t)internal_3d_res.y; - common_data.res.z = 1.0f / (float_t)internal_3d_res.x; - common_data.res.w = 1.0f / (float_t)internal_3d_res.y; - common_data.vp = cam->view_projection; - common_data.view = cam->view; - common_data.projection = cam->projection; - common_data.view_pos = cam->view_point; - render->update_common_data(&common_data, cam); } static void render_context_disp(render_context* rctx) {