forked from pnill/cartographer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pnill#503 from Berthalamew/interpolation_new
rewrite player_effect_apply_camera_effect_matrix function
- Loading branch information
Showing
21 changed files
with
1,452 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,186 @@ | ||
#include "stdafx.h" | ||
#include "player_effects.h" | ||
|
||
#include "Blam/Engine/game/game_time.h" | ||
#include "Blam/Engine/game/player_vibration.h" | ||
#include "Blam/Engine/main/interpolator.h" | ||
#include "Blam/Engine/math/random_math.h" | ||
|
||
void player_effect_apply_camera_effect_matrix_internal(real_matrix4x3* matrix, real32 a2, real32 a3); | ||
real32 player_effect_transition_function_evaluate(e_transition_function_type function_type, real32 a2, real32 a3, real32 a4); | ||
|
||
s_player_effect_globals* player_effect_globals_get(void) | ||
{ | ||
return *Memory::GetAddress<s_player_effect_globals**>(0x4CE860, 0x4F504C); | ||
} | ||
|
||
s_player_effect_user_globals* player_effects_get_user_globals(int32 user_index) | ||
{ | ||
return &player_effect_globals_get()->user_effects[user_index]; | ||
} | ||
|
||
/* | ||
void __cdecl player_effect_apply_camera_effect_matrix(int32 user_index, real_matrix4x3* matrix) | ||
{ | ||
INVOKE(0xA432D, 0x963AA, player_effect_apply_camera_effect_matrix, user_index, matrix); | ||
return; | ||
}*/ | ||
|
||
void player_effect_apply_camera_effect_matrix(int32 user_index, real_matrix4x3* matrix) | ||
{ | ||
real_matrix4x3 calculated_matrix; | ||
if (user_index != NONE) | ||
{ | ||
s_player_effect_globals* player_effects_globals = player_effect_globals_get(); | ||
if (player_effects_globals->flags.test(_player_effect_global_bit_0)) | ||
{ | ||
real32 vibration_intensity = player_effects_globals->max_intensity; | ||
calculated_matrix = global_identity4x3; | ||
|
||
if (player_effects_globals->attack_time_ticks > 0) | ||
{ | ||
real32 attack_time = player_effects_globals->attack_time_ticks / player_effects_globals->attack_time_ticks_1; | ||
if (!player_effects_globals->flags.test(_player_effect_global_bit_1)) | ||
{ | ||
attack_time = 1.0f - attack_time; | ||
} | ||
|
||
vibration_intensity *= attack_time; | ||
} | ||
|
||
if (vibration_intensity >= 0.0f) | ||
{ | ||
if (vibration_intensity > 1.0f) | ||
{ | ||
vibration_intensity = 1.0f; | ||
} | ||
} | ||
else | ||
{ | ||
vibration_intensity = 0.0f; | ||
} | ||
|
||
rumble_player_set_scripted_scale(vibration_intensity); | ||
|
||
real_vector3d random_angles; | ||
random_angles.k = _real_random_range(get_local_random_seed_address(), -1.0f, 1.0f); | ||
random_angles.j = _real_random_range(get_local_random_seed_address(), -1.0f, 1.0f); | ||
random_angles.i = _real_random_range(get_local_random_seed_address(), -1.0f, 1.0f); | ||
multiply_vectors3d(&random_angles, &player_effects_globals->position.orientation, &random_angles); | ||
scale_vector3d(&random_angles, vibration_intensity, &random_angles); | ||
|
||
matrix4x3_rotation_from_angles(&calculated_matrix, random_angles.i, random_angles.j, random_angles.k); | ||
|
||
random_angles.i = _real_random_range(get_local_random_seed_address(), -1.0f, 1.0f); | ||
random_angles.j = _real_random_range(get_local_random_seed_address(), -1.0f, 1.0f); | ||
random_angles.k = _real_random_range(get_local_random_seed_address(), -1.0f, 1.0f); | ||
|
||
calculated_matrix.position.x = random_angles.i * player_effects_globals->position.position.y * vibration_intensity; | ||
calculated_matrix.position.y = random_angles.j * player_effects_globals->position.position.x * vibration_intensity; | ||
calculated_matrix.position.z = random_angles.k * player_effects_globals->position.position.z * vibration_intensity; | ||
matrix4x3_multiply(matrix, &calculated_matrix, matrix); | ||
} | ||
else | ||
{ | ||
s_player_effect_user_globals* user_effect = &player_effects_globals->user_effects[user_index]; | ||
bool bit_1_result = user_effect->flags.test(_player_effect_user_global_bit_1); | ||
if (user_effect->field_80 > 0 || bit_1_result) | ||
{ | ||
real32 function_result; | ||
if (bit_1_result) | ||
{ | ||
function_result = 1.0f; | ||
} | ||
else | ||
{ | ||
real32 timing = user_effect->camera_impulse.duration - *(real32*)(&user_effect->field_80) - halo_interpolator_get_interpolation_time(); | ||
function_result = player_effect_transition_function_evaluate((e_transition_function_type)user_effect->camera_impulse.fade_function, user_effect->transition_function_scale_9C, timing, user_effect->camera_impulse.duration); | ||
} | ||
|
||
real_vector3d vector; | ||
cross_product3d(&global_up3d, &user_effect->vector_0, &vector); | ||
|
||
real32 function_result_scaled = user_effect->camera_impulse.rotation * function_result; | ||
matrix4x3_rotation_from_axis_and_angle(&calculated_matrix, &vector, sin(function_result_scaled), cos(function_result_scaled)); | ||
|
||
real32 position_scaler = user_effect->camera_impulse.pushback * function_result; | ||
calculated_matrix.position.x = user_effect->vector_0.i * position_scaler; | ||
calculated_matrix.position.y = user_effect->vector_0.j * position_scaler; | ||
calculated_matrix.position.z = user_effect->vector_0.k * position_scaler; | ||
point_from_line3d(&calculated_matrix.position, &user_effect->vector_C, function_result, &calculated_matrix.position); | ||
matrix4x3_multiply(matrix, &calculated_matrix, matrix); | ||
} | ||
|
||
bool bit_2_result = user_effect->flags.test(_player_effect_user_global_bit_2); | ||
if (user_effect->field_82 > 0 || bit_2_result) | ||
{ | ||
calculated_matrix = global_identity4x3; | ||
|
||
real32 transition_function_result; | ||
real32 field_82_real = (real32)user_effect->field_82; | ||
real32 timing = user_effect->camera_shaking.duration - game_ticks_to_seconds(*(real32*)(&user_effect->field_82)) - halo_interpolator_get_interpolation_time(); | ||
if (bit_2_result) | ||
{ | ||
transition_function_result = 1.0f; | ||
} | ||
else | ||
{ | ||
transition_function_result = player_effect_transition_function_evaluate((e_transition_function_type)user_effect->camera_shaking.falloff_function, user_effect->transition_function_scale_98, timing, user_effect->camera_shaking.duration); | ||
} | ||
|
||
real32 seconds_result = timing / user_effect->camera_shaking.wobble_function_period; | ||
real32 periodic_function_result = periodic_function_evaluate(user_effect->camera_shaking.wobble_function, seconds_result); | ||
real32 periodic_function_result_scaled = periodic_function_result * transition_function_result * user_effect->camera_shaking.wobble_weight + transition_function_result * (1.0 - user_effect->camera_shaking.wobble_weight); | ||
|
||
// Set v1 to 0 if v1_value is less than 0 | ||
real32 v1_value = user_effect->camera_shaking.random_translation * periodic_function_result_scaled; | ||
real32 v1 = (v1_value <= 0.0f ? 0.0f : v1_value); | ||
|
||
// Set v2 to 0 if v2_value is less than 0 | ||
real32 v2_value = user_effect->camera_shaking.random_rotation * periodic_function_result_scaled; | ||
real32 v2 = (v2_value <= 0.0f ? 0.0f : v2_value); | ||
|
||
if (user_effect->field_7C > 0) | ||
{ | ||
real32 seconds_7C = game_ticks_to_seconds(*(real32*)(&user_effect->field_7C)); | ||
real32 seconds_7C_x2 = seconds_7C + seconds_7C; | ||
|
||
v1 += seconds_7C_x2 * user_effect->field_74; | ||
v2 += seconds_7C_x2 * user_effect->field_78; | ||
|
||
rumble_player_continuous(user_index, user_effect->rumble_intensity_left, user_effect->rumble_intensity_right); | ||
} | ||
player_effect_apply_camera_effect_matrix_internal(&calculated_matrix, v1, v2); | ||
matrix4x3_multiply(matrix, &calculated_matrix, matrix); | ||
} | ||
} | ||
} | ||
|
||
return; | ||
} | ||
|
||
|
||
void player_effect_apply_camera_effect_matrix_internal(real_matrix4x3* matrix, real32 a2, real32 a3) | ||
{ | ||
real_vector3d vector; | ||
|
||
if (a3 != 0.0f) | ||
{ | ||
_random_direction3d(get_local_random_seed_address(), NULL, __FILE__, __LINE__, &vector); | ||
matrix4x3_rotation_from_axis_and_angle(matrix, &vector, sin(a3), cos(a3)); | ||
} | ||
if (a2 != 0.0f) | ||
{ | ||
_random_direction3d(get_local_random_seed_address(), NULL, __FILE__, __LINE__, &vector); | ||
matrix->position.x = vector.i * a2; | ||
matrix->position.y = vector.j * a2; | ||
matrix->position.z = vector.k * a2; | ||
} | ||
return; | ||
} | ||
|
||
real32 player_effect_transition_function_evaluate(e_transition_function_type function_type, real32 a2, real32 a3, real32 a4) | ||
{ | ||
real32 function_value = 1.0f - (a3 / a4); | ||
return transition_function_evaluate(function_type, function_value) * a2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,92 @@ | ||
#pragma once | ||
#include "Blam/Engine/camera/observer.h" | ||
#include "Blam/Engine/math/matrix_math.h" | ||
#include "Blam/Engine/math/periodic_functions.h" | ||
#include "Blam/Engine/Networking/Session/NetworkSession.h" | ||
|
||
void __cdecl player_effect_apply_camera_effect_matrix(int32 user_index, real_matrix4x3* matrix); | ||
enum e_player_effect_user_global_flags : uint8 | ||
{ | ||
_player_effect_user_global_bit_0 = 0, | ||
_player_effect_user_global_bit_1 = 1, | ||
_player_effect_user_global_bit_2 = 2, | ||
k_player_effect_user_global_flag_count | ||
}; | ||
|
||
enum e_player_effect_global_flags : uint32 | ||
{ | ||
_player_effect_global_bit_0 = 0, | ||
_player_effect_global_bit_1 = 1, | ||
k_player_effect_global_flag_count | ||
}; | ||
|
||
struct s_temporary_camera_impulse | ||
{ | ||
real32 duration; | ||
int8 fade_function; // e_transition_function_type | ||
int8 pad; | ||
real32 rotation; | ||
real32 pushback; | ||
real_bounds jitter; | ||
}; | ||
CHECK_STRUCT_SIZE(s_temporary_camera_impulse, 24); | ||
|
||
struct s_player_effect_camera_shaking | ||
{ | ||
real32 duration; | ||
int8 falloff_function; // e_transition_function_type | ||
real32 random_translation; | ||
real_angle random_rotation; | ||
e_periodic_function_type wobble_function; | ||
real32 wobble_function_period; | ||
real32 wobble_weight; | ||
}; | ||
CHECK_STRUCT_SIZE(s_player_effect_camera_shaking, 28); | ||
|
||
struct s_player_effect_user_globals | ||
{ | ||
real_vector3d vector_0; | ||
real_vector3d vector_C; | ||
int16 field_18; | ||
int16 pad_1A; | ||
real32 field_1C; | ||
e_transition_function_type screen_flash_function; | ||
int16 pad; | ||
real32 field_24; | ||
real_argb_color screen_flash_color; | ||
s_temporary_camera_impulse camera_impulse; | ||
s_player_effect_camera_shaking camera_shaking; | ||
real32 rumble_intensity_left; | ||
real32 rumble_intensity_right; | ||
real32 field_74; | ||
real32 field_78; | ||
int16 field_7C; | ||
int16 game_time; | ||
int16 field_80; | ||
int16 field_82; | ||
int8 field_84[4]; | ||
c_flags<e_player_effect_user_global_flags, uint8, k_player_effect_user_global_flag_count> flags; | ||
int8 field_89; | ||
int16 pad_8A; | ||
real_point3d origin; | ||
real32 transition_function_scale_98; | ||
real32 transition_function_scale_9C; | ||
}; | ||
CHECK_STRUCT_SIZE(s_player_effect_user_globals, 160); | ||
|
||
struct s_player_effect_globals | ||
{ | ||
int32 field_0; | ||
int16 field_4; | ||
bool field_6; | ||
int8 field_7; | ||
s_observer_command_displacement position; | ||
real32 max_intensity; | ||
int16 attack_time_ticks; | ||
int16 attack_time_ticks_1; | ||
c_flags<e_player_effect_global_flags, uint32, k_player_effect_global_flag_count> flags; | ||
uint32 current_time_ticks; | ||
s_player_effect_user_globals user_effects[k_number_of_users]; | ||
}; | ||
CHECK_STRUCT_SIZE(s_player_effect_globals, 688); | ||
|
||
void player_effect_apply_camera_effect_matrix(int32 user_index, real_matrix4x3* matrix); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
#include "stdafx.h" | ||
#include "player_vibration.h" | ||
|
||
void rumble_player_set_scripted_scale(real32 scale) | ||
void __cdecl rumble_player_set_scripted_scale(real32 scale) | ||
{ | ||
INVOKE(0x9004F, 0x8EC60, rumble_player_set_scripted_scale, scale); | ||
return; | ||
} | ||
|
||
void __cdecl rumble_player_continuous(int32 user_index, real32 rumble_intensity_left, real32 rumble_intensity_right) | ||
{ | ||
INVOKE(0x90222, 0x8EE33, rumble_player_continuous, user_index, rumble_intensity_left, rumble_intensity_right); | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#pragma once | ||
|
||
void rumble_player_set_scripted_scale(real32 scale); | ||
void __cdecl rumble_player_set_scripted_scale(real32 scale); | ||
|
||
void __cdecl rumble_player_continuous(int32 user_index, real32 rumble_intensity_left, real32 rumble_intensity_right); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.