Add convenience methods fix_sin, fix_cos
This commit is contained in:
parent
7a4a6ed1d4
commit
4f11c2516f
|
@ -16,6 +16,7 @@
|
|||
#define D_RAND_MAX 32767
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstddef>
|
||||
#include "dxxsconf.h"
|
||||
|
||||
void d_srand (unsigned int seed);
|
||||
|
@ -126,6 +127,21 @@ fix fix_sqrt (fix a);
|
|||
//compute sine and cosine of an angle, filling in the variables
|
||||
//either of the pointers can be NULL
|
||||
void fix_sincos (fix a, fix * s, fix * c); //with interpolation
|
||||
void fix_sincos(fix, std::nullptr_t, std::nullptr_t) = delete;
|
||||
|
||||
__attribute_warn_unused_result
|
||||
static inline fix fix_sin(fix a)
|
||||
{
|
||||
fix s;
|
||||
return fix_sincos(a, &s, nullptr), s;
|
||||
}
|
||||
|
||||
__attribute_warn_unused_result
|
||||
static inline fix fix_cos(fix a)
|
||||
{
|
||||
fix c;
|
||||
return fix_sincos(a, nullptr, &c), c;
|
||||
}
|
||||
|
||||
void fix_fastsincos (fix a, fix * s, fix * c); //no interpolation
|
||||
|
||||
|
|
|
@ -2229,13 +2229,13 @@ void start_boss_death_sequence(const vobjptr_t objp)
|
|||
#if defined(DXX_BUILD_DESCENT_I)
|
||||
static void do_boss_dying_frame(const vobjptridx_t objp)
|
||||
{
|
||||
fix boss_roll_val, temp;
|
||||
fix boss_roll_val;
|
||||
|
||||
boss_roll_val = fixdiv(GameTime64 - Boss_dying_start_time, BOSS_DEATH_DURATION);
|
||||
|
||||
fix_sincos(fixmul(boss_roll_val, boss_roll_val), &temp, &objp->mtype.phys_info.rotvel.x);
|
||||
fix_sincos(boss_roll_val, &temp, &objp->mtype.phys_info.rotvel.y);
|
||||
fix_sincos(boss_roll_val-F1_0/8, &temp, &objp->mtype.phys_info.rotvel.z);
|
||||
fix_sincos(fixmul(boss_roll_val, boss_roll_val), nullptr, &objp->mtype.phys_info.rotvel.x);
|
||||
fix_sincos(boss_roll_val, nullptr, &objp->mtype.phys_info.rotvel.y);
|
||||
fix_sincos(boss_roll_val-F1_0/8, nullptr, &objp->mtype.phys_info.rotvel.z);
|
||||
|
||||
objp->mtype.phys_info.rotvel.x = (GameTime64 - Boss_dying_start_time)/9;
|
||||
objp->mtype.phys_info.rotvel.y = (GameTime64 - Boss_dying_start_time)/5;
|
||||
|
@ -2329,7 +2329,7 @@ void start_robot_death_sequence(const vobjptr_t objp)
|
|||
// scale: F1_0*4 for boss, much smaller for much smaller guys
|
||||
static int do_robot_dying_frame(const vobjptridx_t objp, fix64 start_time, fix roll_duration, sbyte *dying_sound_playing, int death_sound, fix expl_scale, fix sound_scale)
|
||||
{
|
||||
fix roll_val, temp;
|
||||
fix roll_val;
|
||||
fix sound_duration;
|
||||
|
||||
if (!roll_duration)
|
||||
|
@ -2337,9 +2337,9 @@ static int do_robot_dying_frame(const vobjptridx_t objp, fix64 start_time, fix r
|
|||
|
||||
roll_val = fixdiv(GameTime64 - start_time, roll_duration);
|
||||
|
||||
fix_sincos(fixmul(roll_val, roll_val), &temp, &objp->mtype.phys_info.rotvel.x);
|
||||
fix_sincos(roll_val, &temp, &objp->mtype.phys_info.rotvel.y);
|
||||
fix_sincos(roll_val-F1_0/8, &temp, &objp->mtype.phys_info.rotvel.z);
|
||||
fix_sincos(fixmul(roll_val, roll_val), nullptr, &objp->mtype.phys_info.rotvel.x);
|
||||
fix_sincos(roll_val, nullptr, &objp->mtype.phys_info.rotvel.y);
|
||||
fix_sincos(roll_val-F1_0/8, nullptr, &objp->mtype.phys_info.rotvel.z);
|
||||
|
||||
objp->mtype.phys_info.rotvel.x = (GameTime64 - start_time)/9;
|
||||
objp->mtype.phys_info.rotvel.y = (GameTime64 - start_time)/5;
|
||||
|
|
|
@ -133,7 +133,7 @@ static void digi_get_sound_loc(const vms_matrix &listener, const vms_vector &lis
|
|||
{
|
||||
|
||||
vms_vector vector_to_sound;
|
||||
fix angle_from_ear, cosang,sinang;
|
||||
fix angle_from_ear;
|
||||
fix distance;
|
||||
fix path_distance;
|
||||
|
||||
|
@ -154,7 +154,7 @@ static void digi_get_sound_loc(const vms_matrix &listener, const vms_vector &lis
|
|||
*volume = max_volume - fixdiv(path_distance,max_distance);
|
||||
if (*volume > 0 ) {
|
||||
angle_from_ear = vm_vec_delta_ang_norm(listener.rvec,vector_to_sound,listener.uvec);
|
||||
fix_sincos(angle_from_ear,&sinang,&cosang);
|
||||
auto cosang = fix_cos(angle_from_ear);
|
||||
if (GameCfg.ReverseStereo) cosang *= -1;
|
||||
*pan = (cosang + F1_0)/2;
|
||||
} else {
|
||||
|
|
|
@ -269,10 +269,10 @@ static g3s_lrgb compute_light_emission(int objnum)
|
|||
}
|
||||
else if (game_mode_hoard() && Players[obj->id].secondary_ammo[PROXIMITY_INDEX]) // If hoard game and player, add extra light based on how many orbs you have Pulse as well.
|
||||
{
|
||||
fix s,hoardlight;
|
||||
fix hoardlight;
|
||||
hoardlight=i2f(Players[obj->id].secondary_ammo[PROXIMITY_INDEX])/2; //i2f(12));
|
||||
hoardlight++;
|
||||
fix_sincos (((fix)(GameTime64/2)) & 0xFFFF,&s,NULL); // probably a bad way to do it
|
||||
auto s = fix_sin(static_cast<fix>(GameTime64/2) & 0xFFFF); // probably a bad way to do it
|
||||
s+=F1_0;
|
||||
s>>=1;
|
||||
hoardlight=fixmul (s,hoardlight);
|
||||
|
|
Loading…
Reference in a new issue