diff --git a/Descent3/AImain.cpp b/Descent3/AImain.cpp index e18f9fad..59ab020d 100644 --- a/Descent3/AImain.cpp +++ b/Descent3/AImain.cpp @@ -1534,7 +1534,7 @@ #include "attach.h" #include "demofile.h" #include "matcen.h" -#include "PHYSICS.H" +#include "physics.h" #include "difficulty.h" #include "osiris_dll.h" #include "multi.h" diff --git a/Descent3/Game2DLL.cpp b/Descent3/Game2DLL.cpp index d2eb2c3a..69a00c03 100644 --- a/Descent3/Game2DLL.cpp +++ b/Descent3/Game2DLL.cpp @@ -52,7 +52,7 @@ #include "vclip.h" #include "osiris_dll.h" #include "manage.h" -#include "PHYSICS.H" +#include "physics.h" #include "collide.h" #include "render.h" #include "audiotaunts.h" diff --git a/Descent3/GameLoop.cpp b/Descent3/GameLoop.cpp index 84c24e39..ac079deb 100644 --- a/Descent3/GameLoop.cpp +++ b/Descent3/GameLoop.cpp @@ -833,7 +833,7 @@ #include "SmallViews.h" #include "newui.h" #include "Inventory.h" -#include "PHYSICS.H" +#include "physics.h" #include "Controller.h" #include "controls.h" #include "gamesequence.h" diff --git a/Descent3/LoadLevel.cpp b/Descent3/LoadLevel.cpp index 07a0425f..cee185ac 100644 --- a/Descent3/LoadLevel.cpp +++ b/Descent3/LoadLevel.cpp @@ -1287,7 +1287,7 @@ #include "ambient.h" #include "matcen.h" #include "dedicated_server.h" -#include "PHYSICS.H" +#include "physics.h" #include "levelgoal.h" #include "aiambient.h" #include "args.h" diff --git a/Descent3/ObjInit.cpp b/Descent3/ObjInit.cpp index d1612ea3..06e19b4c 100644 --- a/Descent3/ObjInit.cpp +++ b/Descent3/ObjInit.cpp @@ -602,7 +602,7 @@ #include "player.h" #include "ship.h" #include "pserror.h" -#include "PHYSICS.H" +#include "physics.h" #include "weapon.h" #include "AIMain.h" #include "fireball.h" diff --git a/Descent3/Player.cpp b/Descent3/Player.cpp index 25ee4187..51246766 100644 --- a/Descent3/Player.cpp +++ b/Descent3/Player.cpp @@ -1098,7 +1098,7 @@ #include "findintersection.h" #include "hud.h" #include "splinter.h" -#include "PHYSICS.H" +#include "physics.h" #include "viseffect.h" #include "damage.h" #include "multi.h" diff --git a/Descent3/config.cpp b/Descent3/config.cpp index e85d9615..4a5371c8 100644 --- a/Descent3/config.cpp +++ b/Descent3/config.cpp @@ -299,7 +299,7 @@ #include "cfile.h" #include "mem.h" #include "lighting.h" -#include "PHYSICS.H" +#include "physics.h" #include "pilot.h" #include "hud.h" #include "voice.h" diff --git a/Descent3/config.h b/Descent3/config.h index e0fd088d..d2079aab 100644 --- a/Descent3/config.h +++ b/Descent3/config.h @@ -114,16 +114,12 @@ * $NoKeywords: $ */ -#ifndef __CONFIG_H__ -#define __CONFIG_H__ +#ifndef CONFIG_H_ +#define CONFIG_H_ + +#include // Main menu configuration functions -// ------------------------------------------------------ -// ConfigForceFeedback -// Purpose: -// Configures your Force Feedback device on your computer -// ------------------------------------------------------ -void ConfigForceFeedback(void); // General option toggles struct tGameToggles { diff --git a/Descent3/fireball.cpp b/Descent3/fireball.cpp index b82aa27a..115b1da5 100644 --- a/Descent3/fireball.cpp +++ b/Descent3/fireball.cpp @@ -593,7 +593,7 @@ #include "objinfo.h" #include "gametexture.h" #include "splinter.h" -#include "PHYSICS.H" +#include "physics.h" #include "damage.h" #include "gameevent.h" #include "weapon.h" diff --git a/Descent3/init.cpp b/Descent3/init.cpp index 28e9fe57..7c4ba7cc 100644 --- a/Descent3/init.cpp +++ b/Descent3/init.cpp @@ -953,7 +953,7 @@ #include "pilot.h" #include "gameloop.h" #include "trigger.h" -#include "PHYSICS.H" +#include "physics.h" #include "special_face.h" #include "voice.h" #include "localization.h" diff --git a/Descent3/matcen.cpp b/Descent3/matcen.cpp index abbb5ce3..dd61ffb4 100644 --- a/Descent3/matcen.cpp +++ b/Descent3/matcen.cpp @@ -165,7 +165,7 @@ #include "viseffect.h" #include "viseffect_external.h" #include "damage.h" -#include "PHYSICS.H" +#include "physics.h" #include "mem.h" #include "ObjScript.h" #ifndef NEWEDITOR diff --git a/Descent3/multi.cpp b/Descent3/multi.cpp index 0ccb53ba..4441b093 100644 --- a/Descent3/multi.cpp +++ b/Descent3/multi.cpp @@ -1692,7 +1692,7 @@ #include "doorway.h" #include "object_lighting.h" #include "spew.h" -#include "PHYSICS.H" +#include "physics.h" #include "SmallViews.h" #include "demofile.h" #include "debuggraph.h" diff --git a/Descent3/object.cpp b/Descent3/object.cpp index 58b4b3d1..5e1ee822 100644 --- a/Descent3/object.cpp +++ b/Descent3/object.cpp @@ -1144,7 +1144,7 @@ #include "slew.h" #include "game.h" #include "trigger.h" -#include "PHYSICS.H" +#include "physics.h" #include "collide.h" #include "door.h" #include "controls.h" diff --git a/Descent3/osiris_predefs.cpp b/Descent3/osiris_predefs.cpp index fcef38ad..b113ead1 100644 --- a/Descent3/osiris_predefs.cpp +++ b/Descent3/osiris_predefs.cpp @@ -460,7 +460,7 @@ #include "polymodel.h" #include "multi.h" #include "viseffect.h" -#include "PHYSICS.H" +#include "physics.h" #include "levelgoal.h" #include "BOA.h" #include "marker.h" diff --git a/Descent3/robotfire.cpp b/Descent3/robotfire.cpp index 87b6fa92..6e7328c3 100644 --- a/Descent3/robotfire.cpp +++ b/Descent3/robotfire.cpp @@ -32,7 +32,7 @@ #include "player.h" #include "demofile.h" #include "SmallViews.h" -#include "PHYSICS.H" +#include "physics.h" #include "AIMain.h" #include diff --git a/Descent3/viseffect.cpp b/Descent3/viseffect.cpp index 5fcff404..34577b72 100644 --- a/Descent3/viseffect.cpp +++ b/Descent3/viseffect.cpp @@ -450,7 +450,7 @@ #include "lighting.h" #include "mem.h" #include "object.h" -#include "PHYSICS.H" +#include "physics.h" #include "player.h" #include "polymodel.h" #include "psrand.h" diff --git a/model/CMakeLists.txt b/model/CMakeLists.txt index c07e9d8d..c89e063e 100644 --- a/model/CMakeLists.txt +++ b/model/CMakeLists.txt @@ -8,6 +8,7 @@ target_link_libraries(model PRIVATE cfile mem misc + physics ) target_include_directories(model PUBLIC $ +) diff --git a/physics/Collide.cpp b/physics/collide.cpp similarity index 88% rename from physics/Collide.cpp rename to physics/collide.cpp index 6be15e7d..1113d112 100644 --- a/physics/Collide.cpp +++ b/physics/collide.cpp @@ -1,5 +1,5 @@ /* -* Descent 3 +* Descent 3 * Copyright (C) 2024 Parallax Software * * This program is free software: you can redistribute it and/or modify @@ -827,41 +827,38 @@ * $NoKeywords: $ */ +#include #include -#include -#include +#include -#include "collide.h" -#include "PHYSICS.H" -#include "pserror.h" -#include "mono.h" -#include "object.h" -#include "player.h" -#include "hlsoundlib.h" -#include "weapon.h" -#include "damage.h" -#include "fireball.h" -#include "sounds.h" #include "AIMain.h" -#include "multi.h" -#include "game.h" -#include "soundload.h" -#include "game2dll.h" -#include "scorch.h" -#include "ddio.h" -#include "vecmat.h" -#include "trigger.h" -#include "lighting.h" -#include "hud.h" +#include "collide.h" #include "D3ForceFeedback.h" +#include "ddio_common.h" +#include "damage.h" #include "demofile.h" -#include "osiris_dll.h" -#include "marker.h" +#include "fireball.h" +#include "game.h" +#include "game2dll.h" +#include "hlsoundlib.h" #include "hud.h" #include "levelgoal.h" +#include "lighting.h" +#include "marker.h" +#include "mono.h" +#include "multi.h" +#include "object.h" +#include "osiris_dll.h" +#include "physics.h" +#include "player.h" +#include "polymodel.h" +#include "pserror.h" #include "psrand.h" - -#include +#include "scorch.h" +#include "sounds.h" +#include "trigger.h" +#include "vecmat.h" +#include "weapon.h" #define PLAYER_ROTATION_BY_FORCE_SCALAR 0.12f #define NONPLAYER_ROTATION_BY_FORCE_SCALAR 1.0f @@ -870,7 +867,6 @@ uint8_t CollisionResult[MAX_OBJECT_TYPES][MAX_OBJECT_TYPES]; uint8_t CollisionRayResult[MAX_OBJECT_TYPES]; static bool IsOKToApplyForce(object *objp); -static void bump_this_object(object *objp, object *other_objp, vector *force, vector *collision_pnt, int damage_flag); //! Creates some effects where a weapon has collided with a wall. static void DoWallEffects(object *weapon, int surface_tmap); //! Check for lava, volatile, or water surface. If contact, make special sound & kill the weapon. @@ -923,72 +919,6 @@ bool IsOKToApplyForce(object *objp) { return true; } -// ----------------------------------------------------------------------------- -void bump_this_object(object *objp, object *other_objp, vector *force, vector *collision_pnt, int damage_flag) { - // float force_mag; - - if (objp->type == OBJ_PLAYER) { - if ((Game_mode & GM_MULTI) && (objp != Player_object)) - return; - - phys_apply_force(objp, force); - } else { - if ((Game_mode & GM_MULTI) && (objp->type != OBJ_PLAYER && objp->type != OBJ_POWERUP) && - (Netgame.local_role != LR_SERVER)) - return; - - phys_apply_force(objp, force); - phys_apply_rot(objp, force); - } - - // if (! (objp->mtype.phys_info.flags & PF_PERSISTENT)) - // if (objp->type == OBJ_PLAYER) { - // vector force2; - // force2 = forcex/4; - - // phys_apply_force(objp,&force2); - - // if (damage_flag && ((other_objp->type != OBJ_ROBOT) || !Robot_info[other_objp->id].companion)) { - // force_mag = vm_vec_mag_quick(&force2); - // apply_force_damage(objp, force_mag, other_objp); - // } - // } else if ((objp->type == OBJ_ROBOT) || (objp->type == OBJ_CLUTTER) || (objp->type == OBJ_CNTRLCEN)) { - // if (!Robot_info[objp->id].boss_flag) { - // vector force2; - // force2.x = force->x/(4 + Difficulty_level); - // force2.y = force->y/(4 + Difficulty_level); - // force2.z = force->z/(4 + Difficulty_level); - - // phys_apply_force(objp, force); - // phys_apply_rot(objp, &force2); - // if (damage_flag) { - // force_mag = vm_vec_mag_quick(force); - // apply_force_damage(objp, force_mag, other_objp); - // } - // } - // } -} - -/* - - void bump_one_object(object *obj0, vector *hit_dir, float damage) -{ - vector hit_vec; - - hit_vec = *hit_dir; - vm_vec_scale(&hit_vec, damage); - - phys_apply_force(obj0,&hit_vec); - -} -*/ - -// #define DAMAGE_SCALE 128 // Was 32 before 8:55 am on Thursday, September 15, changed by MK, -// walls -// were hurting me more than robots! #define DAMAGE_THRESHOLD (F1_0/3) #define WALL_LOUDNESS_SCALE (20) - -// float force_force = 50.0; - struct vec2d { float i, j; }; @@ -1375,7 +1305,7 @@ void collide_player_and_wall(object *playerobj, float hitspeed, int hitseg, int if (!((Game_mode & GM_MULTI) && (Netgame.local_role == LR_CLIENT))) { int id = FindWeaponName("NapalmBlob"); if (id >= 0) - SetNapalmDamageEffect(playerobj, NULL, id); + SetNapalmDamageEffect(playerobj, nullptr, id); else Int3(); } @@ -1495,7 +1425,7 @@ void collide_generic_and_wall(object *genericobj, float hitspeed, int hitseg, in if (!((Game_mode & GM_MULTI) && (Netgame.local_role == LR_CLIENT))) { int id = FindWeaponName("NapalmBlob"); if (id >= 0) - SetNapalmDamageEffect(genericobj, NULL, id); + SetNapalmDamageEffect(genericobj, nullptr, id); else Int3(); } @@ -1534,146 +1464,8 @@ void collide_generic_and_wall(object *genericobj, float hitspeed, int hitseg, in DemoWrite3DSound(SOUND_PLAYER_HIT_WALL, OBJNUM(genericobj), 1, volume); } } - - return; } -static float Last_volatile_scrape_sound_time = 0; - -// this gets called when an object is scraping along the wall -void scrape_object_on_wall(object *obj, int hitseg, int hitwall, vector *hitpt, vector *wall_normal) { - /* switch (obj->type) { - - case OBJ_PLAYER: - - if (obj->id==Player_num) { - int type; - - //mprintf(0, "Scraped segment #%3i, side #%i\n", hitseg, hitside); - - if ((type=check_volatile_wall(obj,hitseg,hitside,hitpt))!=0) { - vector hit_dir, rand_vec; - - if ((GameTime > Last_volatile_scrape_sound_time + F1_0/4) || (GameTime < - Last_volatile_scrape_sound_time)) { int sound = (type==1)?SOUND_VOLATILE_WALL_HISS:SOUND_SHIP_IN_WATER; - - Last_volatile_scrape_sound_time = GameTime; - - digi_link_sound_to_pos( sound, hitseg, 0, hitpt, 0, F1_0 ); - if (Game_mode & GM_MULTI) - multi_send_play_sound(sound, F1_0); - } - - #ifdef COMPACT_SEGS - get_side_normal(&Segments[hitseg], higside, 0, &hit_dir ); - #else - hit_dir = Segments[hitseg].sides[hitside].normals[0]; - #endif - - make_random_vector(&rand_vec); - vm_vec_scale_add2(&hit_dir, &rand_vec, F1_0/8); - vm_vec_normalize_quick(&hit_dir); - bump_one_object(obj, &hit_dir, F1_0*8); - } - - //@@} else { - //@@ //what scrape sound - //@@ //PLAY_SOUND( SOUND_PLAYER_SCRAPE_WALL ); - //@@} - - } - - break; - - //these two kinds of objects below shouldn't really slide, so - //if this scrape routine gets called (which it might if the - //object (such as a fusion blob) was created already poking - //through the wall) call the collide routine. - - case OBJ_WEAPON: - collide_weapon_and_wall(obj,0,hitseg,hitside,hitpt); - break; - - case OBJ_DEBRIS: - collide_debris_and_wall(obj,0,hitseg,hitside,hitpt); - break; - } - */ -} -/* -void apply_damage_to_player(object *playerobj, object *killer, float damage) -{ - if (Player_is_dead) - return; - - if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) - return; - - if (Endlevel_sequence) - return; - - //for the player, the 'real' shields are maintained in the Players[] - //array. The shields value in the player's object are, I think, not - //used anywhere. This routine, however, sets the objects shields to - //be a mirror of the value in the Player structure. - - if (playerobj->id == Player_num) { //is this the local player? - - // MK: 08/14/95: This code can never be reached. See the return about 12 lines up. -// -- if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) { -// -- -// -- //invincible, so just do blue flash -// -- -// -- PALETTE_FLASH_ADD(0,0,f2i(damage)*4); //flash blue -// -- -// -- } -// -- else { //take damage, do red flash - - Players[Player_num].shields -= damage; - - PALETTE_FLASH_ADD(f2i(damage)*4,-f2i(damage/2),-f2i(damage/2)); //flash red - -// -- } - - if (Players[Player_num].shields < 0) { - - Players[Player_num].killer_objnum = killer-Objects; - -// if ( killer && (killer->type == OBJ_PLAYER)) -// Players[Player_num].killer_objnum = killer-Objects; - - playerobj->flags |= OF_DEAD; - - if (Buddy_objnum != -1) - if ((killer->type == OBJ_ROBOT) && (Robot_info[killer->id].companion)) - Buddy_sorry_time = GameTime; - } -// -- removed, 09/06/95, MK -- else if (Players[Player_num].shields < LOSE_WEAPON_THRESHOLD) { -// -- removed, 09/06/95, MK -- int randnum = ps_rand(); -// -- removed, 09/06/95, MK -- -// -- removed, 09/06/95, MK -- if (floatmul(Players[Player_num].shields, randnum) < damage/4) { -// -- removed, 09/06/95, MK -- if (ps_rand() > 20000) { -// -- removed, 09/06/95, MK -- destroy_secondary_weapon(Secondary_weapon); -// -- removed, 09/06/95, MK -- } else if (Primary_weapon == 0) { -// -- removed, 09/06/95, MK -- if (Players[Player_num].flags & -PLAYER_FLAGS_QUAD_LASERS) -// -- removed, 09/06/95, MK -- -destroy_primary_weapon(MAX_PRIMARY_WEAPONS); // This means to destroy quad laser. -// -- removed, 09/06/95, MK -- else if (Players[Player_num].laser_level > 0) -// -- removed, 09/06/95, MK -- destroy_primary_weapon(Primary_weapon); -// -- removed, 09/06/95, MK -- } else -// -- removed, 09/06/95, MK -- destroy_primary_weapon(Primary_weapon); -// -- removed, 09/06/95, MK -- } else -// -- removed, 09/06/95, MK -- ; // mprintf(0, "%8x > %8x, so don't lose weapon.\n", -floatmul(Players[Player_num].shields, randnum), damage/4); -// -- removed, 09/06/95, MK -- } - - playerobj->shields = Players[Player_num].shields; //mirror - - } -} -*/ - void CollideAnglesToMatrix(matrix *m, float p, float h, float b) { float sinp, cosp, sinb, cosb, sinh, cosh; @@ -1745,18 +1537,8 @@ void ConvertEulerToAxisAmount(vector *e, vector *n, float *w) { e_n = *e / scale; - // vector f; CollideAnglesToMatrix(&rotmat, e_n.x, e_n.y, e_n.z); - // mprintf(0, "F %f, %f, %f\n", XYZ(&rotmat.fvec)); - // mprintf(0, "R %f, %f, %f\n", XYZ(&rotmat.rvec)); - // mprintf(0, "U %f, %f, %f\n", XYZ(&rotmat.uvec)); - - // CollideExtractAnglesFromMatrix(&f, &rotmat); - - // mprintf(0, "Before %f, %f, %f\n", XYZ(&e_n)); - // mprintf(0, "After %f, %f, %f\n", XYZ(&f)); - // This is from Graphics Gems 1 p.467 I am converting from a angle vector // to the normal of that rotation (you can also get the angle about that normal, but // we don't need it) @@ -1776,9 +1558,6 @@ void ConvertEulerToAxisAmount(vector *e, vector *n, float *w) { float v = acos(ct); float z = sin(v); - // if(v < 0.0) - // *w = -rotspeed; - // else *w = rotspeed * ((2.0f * PI) / (65535.0f)); if (z >= 0.0f) @@ -1802,8 +1581,8 @@ void ConvertAxisAmountToEuler(vector *n, float *w, vector *e) { return; } - s = sin(.0001); - c = cos(.0001); + s = sin(.0001f); + c = cos(.0001f); t = 1.0f - c; matrix rotmat; @@ -1924,47 +1703,12 @@ void bump_obj_against_fixed(object *obj, vector *collision_point, vector *collis ASSERT(std::isfinite(obj->mtype.phys_info.velocity.x)); ASSERT(std::isfinite(obj->mtype.phys_info.velocity.y)); ASSERT(std::isfinite(obj->mtype.phys_info.velocity.z)); - - // hack rotvel - /* vector v = obj->mtype.phys_info.velocity; - vector c = *collision_normal; - - if(v != Zero_vector) - { - vm_NormalizeVector(&v); - - if(v != c) - { - float rad = vm_VectorDistance(&obj->pos, collision_point); - float rotvel = vm_GetMagnitude(&obj->mtype.phys_info.velocity)*((2*PI*rad)); - vector r; - vector e; - - vm_CrossProduct(&r, &v, &c); - vm_NormalizeVector(&r); - - ConvertAxisAmountToEuler(&r, &rotvel, &e); - - matrix rrr = obj->orient; - // vm_TransposeMatrix(&rrr); - obj->mtype.phys_info.rotvel = rrr * r; - } - else - { - obj->mtype.phys_info.rotvel = Zero_vector; - } - } - else - { - obj->mtype.phys_info.rotvel = Zero_vector; - }*/ } void bump_two_objects(object *object0, object *object1, vector *collision_point, vector *collision_normal, int damage_flag) { - // vector force; //dv, - object *t = NULL; - object *other = NULL; + object *t = nullptr; + object *other = nullptr; // Determine if a moving object hits a non-moving object if ((object0->movement_type != MT_PHYSICS && object0->movement_type != MT_WALKING) || @@ -2002,9 +1746,6 @@ void bump_two_objects(object *object0, object *object1, vector *collision_point, } if (!(t->flags & OF_DEAD)) { - // bump_obj_against_fixed(t, collision_point, collision_normal); - // } - ///* // Find hit speed moved_v = t->pos - t->last_pos; wall_part = *collision_normal * t->mtype.phys_info.velocity; @@ -2050,7 +1791,7 @@ void bump_two_objects(object *object0, object *object1, vector *collision_point, // Weapons should face their new heading. This is so missiles are pointing in the correct direct. if (t->type == OBJ_WEAPON && (t->mtype.phys_info.flags & (PF_BOUNCE | PF_GRAVITY | PF_WIND))) - vm_VectorToMatrix(&t->orient, &t->mtype.phys_info.velocity, &t->orient.uvec, NULL); + vm_VectorToMatrix(&t->orient, &t->mtype.phys_info.velocity, &t->orient.uvec, nullptr); } // Return it to the original direction @@ -2065,25 +1806,9 @@ void bump_two_objects(object *object0, object *object1, vector *collision_point, if (object0->type == OBJ_PLAYER && object0->id == Player_num) { } } - //*/ return; } - // force = object0->mtype.phys_info.velocity - object1->mtype.phys_info.velocity; - // force *= 2*(object0->mtype.phys_info.mass * object1->mtype.phys_info.mass)/(object0->mtype.phys_info.mass + - // object1->mtype.phys_info.mass); - - // if(!(object1->mtype.phys_info.flags & PF_PERSISTENT)) - // bump_this_object(object1, object0, &force, collision_point, damage_flag); - // - // force = -force; - // - // if(!(object0->mtype.phys_info.flags & PF_PERSISTENT)) - // bump_this_object(object0, object1, &force, collision_point, damage_flag); - - // vector r_vel = object0->mtype.phys_info.velocity - object1->mtype.phys_info.velocity; - // Add this back - ASSERT(std::isfinite(object1->mtype.phys_info.rotvel.x)); ASSERT(std::isfinite(object1->mtype.phys_info.rotvel.y)); ASSERT(std::isfinite(object1->mtype.phys_info.rotvel.z)); @@ -2259,7 +1984,7 @@ void bump_two_objects(object *object0, object *object1, vector *collision_point, if (object0->type == OBJ_PLAYER && object0->id == Player_num) { // v is the force vector vector v; - v = -1.0 * v_rel * (*collision_normal); + v = -1.0f * v_rel * (*collision_normal); // Was it weapon->player collide switch (object1->type) { @@ -2290,7 +2015,7 @@ void bump_two_objects(object *object0, object *object1, vector *collision_point, dest_obj->effect_info->type_flags |= EF_NAPALMED; - dest_obj->effect_info->damage_time = std::max(1.0, src_obj->effect_info->damage_time / 3.0); + dest_obj->effect_info->damage_time = std::max(1.0f, src_obj->effect_info->damage_time / 3.0f); dest_obj->effect_info->damage_per_second = src_obj->effect_info->damage_per_second; // We need this cap (as the gb burns forever @@ -2339,8 +2064,6 @@ void collide_player_and_player(object *p1, object *p2, vector *collision_point, bump_two_objects(p1, p2, collision_point, collision_normal, 1); } -#include "polymodel.h" - void collide_generic_and_player(object *robotobj, object *playerobj, vector *collision_point, vector *collision_normal, bool f_reverse_normal, fvi_info *hit_info) { if (f_reverse_normal) @@ -2373,7 +2096,7 @@ void collide_generic_and_player(object *robotobj, object *playerobj, vector *col if (!((Game_mode & GM_MULTI) && (Netgame.local_role == LR_CLIENT))) { int id = FindWeaponName("NapalmBlob"); if (id >= 0) - SetNapalmDamageEffect(playerobj, NULL, id); + SetNapalmDamageEffect(playerobj, nullptr, id); else Int3(); } @@ -2414,35 +2137,10 @@ void collide_generic_and_player(object *robotobj, object *playerobj, vector *col } } - // mprintf(0, "We hit a robot\n"); if (robotobj->control_type == CT_AI) { AINotify(robotobj, AIN_BUMPED_OBJ, (void *)playerobj); } - /* if((GameTextures[Rooms[hitseg].faces[hitwall].tmap].flags & TF_VOLATILE) && !((Game_mode & GM_MULTI) && - (Netgame.local_role==LR_CLIENT))) - { - int id = FindWeaponName("NapalmBlob"); - if(id >= 0) - { - int objnum = ObjCreate(OBJ_WEAPON, id, playerobj->roomnum, &playerobj->pos, NULL, - playerobj->handle); - - if(objnum >= 0) - { - object *weapon = &Objects[objnum]; - float damage_to_apply = Weapons[weapon->id].damage; - - // Factor in multiplier - damage_to_apply *= weapon->ctype.laser_info.multiplier; - - ApplyDamageToPlayer(playerobj, weapon, 0); - - SetObjectDeadFlag(objnum); - } - } - } - */ bump_two_objects(robotobj, playerobj, collision_point, collision_normal, 1); } @@ -2572,7 +2270,7 @@ void collide_generic_and_weapon(object *robotobj, object *weapon, vector *collis bump_two_objects(robotobj, weapon, collision_point, collision_normal, 0); - if (!f_stick || (hit_info == NULL)) { + if (!f_stick || (hit_info == nullptr)) { if ((robotobj->lighting_render_type == LRT_LIGHTMAPS) || !(weapon->mtype.phys_info.flags & PF_PERSISTENT)) SetObjectDeadFlag(weapon); } else { @@ -2638,7 +2336,7 @@ void collide_player_and_weapon(object *playerobj, object *weapon, vector *collis if (!electrical) { bump_two_objects(playerobj, weapon, collision_point, collision_normal, 0); - if (!f_stick || (hit_info == NULL)) { + if (!f_stick || (hit_info == nullptr)) { if (!(weapon->mtype.phys_info.flags & PF_PERSISTENT)) SetObjectDeadFlag(weapon); } else { diff --git a/lib/collide.h b/physics/collide.h similarity index 74% rename from lib/collide.h rename to physics/collide.h index 01629d48..6aa4ddc1 100644 --- a/lib/collide.h +++ b/physics/collide.h @@ -1,5 +1,5 @@ /* -* Descent 3 +* Descent 3 * Copyright (C) 2024 Parallax Software * * This program is free software: you can redistribute it and/or modify @@ -80,45 +80,27 @@ * $NoKeywords: $ */ -#ifndef _COLLIDE_H -#define _COLLIDE_H +#ifndef COLLIDE_H +#define COLLIDE_H +#include + +#include "findintersection.h" #include "object.h" #include "vecmat.h" -#include "findintersection.h" extern uint8_t CollisionResult[MAX_OBJECT_TYPES][MAX_OBJECT_TYPES]; extern uint8_t CollisionRayResult[MAX_OBJECT_TYPES]; void CollideInit(); void collide_two_objects(object *A, object *B, vector *collision_point, vector *collision_normal, - fvi_info *hit_info = NULL); -extern void apply_damage_to_player(object *player, object *killer, float damage); + fvi_info *hit_info = nullptr); // Process a collision between an object and a wall // Returns true if the object hits the wall, and false if should keep going though the wall (for breakable glass) bool collide_object_with_wall(object *A, float hitspeed, int hitseg, int hitwall, vector *hitpt, vector *wall_normal, float hit_dot); -extern int apply_damage_to_robot(object *robot, float damage, int killer_objnum); - -extern int Immaterial; - -extern void collide_player_and_weapon(object *player, object *weapon, vector *collision_point); -extern void collide_player_and_materialization_center(object *objp); -extern void collide_robot_and_materialization_center(object *objp); - -extern void scrape_object_on_wall(object *obj, int hitseg, int hitwall, vector *hitpt, vector *wall_normal); -extern int maybe_detonate_weapon(object *obj0p, object *obj, vector *pos); - -extern void collide_player_and_nasty_robot(object *player, object *robot, vector *collision_point); - -extern void net_destroy_controlcen(object *controlcen); -extern void collide_player_and_powerup(object *player, object *powerup, vector *collision_point); -// extern int check_effect_blowup(segment *seg,int side,vector *pnt, object *blower, int force_blowup_flag); -extern void apply_damage_to_controlcen(object *controlcen, float damage, int16_t who); -extern void bump_one_object(object *obj0, vector *hit_dir, float damage); - extern void FindHitpointUV(float *u, float *v, vector *point, room *rp, int facenum); void ConvertEulerToAxisAmount(vector *e, vector *n, float *w); diff --git a/physics/FindIntersection.cpp b/physics/findintersection.cpp similarity index 98% rename from physics/FindIntersection.cpp rename to physics/findintersection.cpp index 72f9d43d..a995ee41 100644 --- a/physics/FindIntersection.cpp +++ b/physics/findintersection.cpp @@ -1,5 +1,5 @@ /* -* Descent 3 +* Descent 3 * Copyright (C) 2024 Parallax Software * * This program is free software: you can redistribute it and/or modify @@ -855,37 +855,25 @@ */ #include +#include -#include -#include -#include +#include "3d.h" +#include "collide.h" +#include "doorway.h" #include "mono.h" #include "findintersection.h" +#include "physics.h" +#include "player.h" +#include "polymodel.h" #include "pserror.h" -#include "collide.h" -#include "terrain.h" -// #include "bspfi.h" -#include "3d.h" +#include "renderer.h" #include "room.h" -#include "descent.h" +#include "terrain.h" #include "weapon.h" #ifndef NED_PHYSICS #include "gametexture.h" -#else -#include "..\neweditor\ned_GameTexture.h" -#endif - -#include "BOA.h" -#include "polymodel.h" -#include "PHYSICS.H" -#include "player.h" -#include "doorway.h" -#include "renderer.h" - -// Debug performance includes (do nothing in final release) -#ifndef NED_PHYSICS -#include "rtperformance.h" +#include "rtperformance.h" // Debug performance includes (do nothing in final release) #endif int FVI_counter; @@ -905,9 +893,8 @@ float Ceiling_height = MAX_TERRAIN_HEIGHT; // Bit fields for quick 'already-checked' checking static uint8_t fvi_visit_list[MAX_ROOMS / 8 + 1]; // This bit-field provides a fast check if a mine segment has been visited -static uint8_t - fvi_terrain_visit_list[(TERRAIN_DEPTH * TERRAIN_WIDTH) / 8 + - 1]; // This bit-field provides a fast check if a terrain segment has been visited +static uint8_t fvi_terrain_visit_list[(TERRAIN_DEPTH * TERRAIN_WIDTH) / 8 + + 1]; // This bit-field provides a fast check if a terrain segment has been visited static uint8_t fvi_terrain_obj_visit_list[(TERRAIN_DEPTH * TERRAIN_WIDTH) / 8 + 1]; // This bit-field provides a fast check if a terrain segment has been visited @@ -1000,7 +987,7 @@ static bool PhysPastPortal(const room *rp, portal *pp); // FVI FUNCTIONS //------------------------------------------------------------------------------------------ -void InitFVI(void) { +void InitFVI() { memset(fvi_terrain_visit_list, 0, (TERRAIN_DEPTH * TERRAIN_WIDTH) / 8 + 1); memset(fvi_terrain_obj_visit_list, 0, (TERRAIN_DEPTH * TERRAIN_WIDTH) / 8 + 1); memset(fvi_visit_list, 0, MAX_ROOMS / 8 + 1); @@ -1019,8 +1006,8 @@ inline int find_plane_line_intersection(vector *intp, vector *colp, vector *plan float proj_dist_line; // Distance projection of line onto the plane normal float proj_dist_point_plane; // Distance of the object from the plane - ASSERT(intp != NULL && plane_pnt != NULL && colp != NULL && plane_norm != NULL && p0 != NULL && p1 != NULL && - rad >= 0.0); + ASSERT(intp != nullptr && plane_pnt != nullptr && colp != nullptr && plane_norm != nullptr && p0 != nullptr && + p1 != nullptr && rad >= 0.0); // Line direction line_vec = *p1 - *p0; @@ -1109,7 +1096,7 @@ uint32_t check_point_to_face(vector *colp, vector *face_normal, int nv, vector * vector t; // Temporary vector that holds the magnatude of the normal's x,y,z components (ABS) int biggest; // Index of the largest of the three components (0-x, 1-y, 2-z) Axis to ignore :) int i, j, edge; // Index for i-axis, Index for j-axis, and the current edge - uint32_t edgemask; // Bit-field for which side we are outside of + uint32_t edgemask; // Bit-field for which side we are outside of float check_i, check_j; // (i,j) checkpoint for 2d in/out test vector_array *v0, *v1; // Vertices of the current line segment in the 2d in/out check loop @@ -1222,12 +1209,12 @@ int check_vector_to_sphere_1(vector *intp, float *col_dist, const vector *p0, co // Is the initial p0 position an intersection? If so, warn us and collide immediately. if (point_to_center_vec * point_to_center_vec < sphere_rad * sphere_rad) { if (f_correcting) { -/* - // chrishack - mprintf(0, "FVI WARNING: Start point is inside of a checked sphere %f %f\n", - point_to_center_vec * point_to_center_vec, - sphere_rad * sphere_rad); -*/ + /* + // chrishack + mprintf(0, "FVI WARNING: Start point is inside of a checked sphere %f %f\n", + point_to_center_vec * point_to_center_vec, + sphere_rad * sphere_rad); + */ // chrishack this movement intersection fix is a hack... How do we do correct cylinder/vector interestion? vector n_ptc = point_to_center_vec; vm_NormalizeVector(&n_ptc); @@ -1329,7 +1316,7 @@ int check_vector_to_cylinder(vector *colp, vector *intp, float *col_dist, vector bool f_init_collide; if (!IsPointInCylinder(&init_normal, ep0, &edgevec, edge_len, rad, p0, &mvec3d, &f_init_collide)) { - vm_VectorToMatrix(&edge_orient, &edgevec, NULL, NULL); + vm_VectorToMatrix(&edge_orient, &edgevec, nullptr, nullptr); po0 = (*p0 - *ep0) * edge_orient; po1 = (*p1 - *ep0) * edge_orient; @@ -1702,7 +1689,7 @@ int check_line_to_face(vector *newp, vector *colp, float *col_dist, vector *wall vector *test = vertex_ptr_list[0]; int i; - ASSERT(newp != NULL && p0 != 0 && p1 != NULL && rad >= 0.0); + ASSERT(newp != nullptr && p0 != 0 && p1 != nullptr && rad >= 0.0); // This is so we always use the same vertex for (i = 1; i < nv; i++) { @@ -1938,7 +1925,7 @@ int fvi_QuickDistFaceList(int init_room_index, vector *pos, float rad, fvi_face_ int i; // ASSERT(quick_fr_list != NULL); - ASSERT(pos != NULL); + ASSERT(pos != nullptr); ASSERT(init_room_index >= 0 && init_room_index <= Highest_room_index && Rooms[init_room_index].used != 0); ASSERT(rad >= 0.0f); @@ -2013,7 +2000,7 @@ int fvi_QuickDistFaceList(int init_room_index, vector *pos, float rad, fvi_face_ if (!room_manual_AABB(&cur_room->faces[i], &min_xyz, &max_xyz)) continue; - if (quick_fr_list != NULL) { + if (quick_fr_list != nullptr) { if (num_faces < max_elements) { quick_fr_list[num_faces].face_index = i; quick_fr_list[num_faces].room_index = ROOMNUM(cur_room); @@ -2071,8 +2058,8 @@ int fvi_QuickDistCellList(int init_cell_index, vector *pos, float rad, int *quic int xcounter, ycounter; int cur_node; - ASSERT(quick_cell_list != NULL); - ASSERT(pos != NULL); + ASSERT(quick_cell_list != nullptr); + ASSERT(pos != nullptr); ASSERT(init_cell_index >= 0 && init_cell_index < TERRAIN_WIDTH * TERRAIN_DEPTH); ASSERT(rad >= 0.0f); @@ -2225,7 +2212,7 @@ int fvi_QuickDistObjectList(vector *pos, int init_room_index, float rad, int16_t int cur_next_room_index; int i; - ASSERT(pos != NULL); + ASSERT(pos != nullptr); ASSERT(init_room_index >= 0 && init_room_index <= Highest_room_index && Rooms[init_room_index].used != 0); ASSERT(rad >= 0.0f); @@ -2559,12 +2546,12 @@ void make_trigger_face_list(int last_sim_faces) { for (count = 0; count < cur_room->faces[i].num_verts; count++) vertex_ptr_list[count] = &cur_room->verts[cur_room->faces[i].face_verts[count]]; -/* - mprintf(0, "FVI:In trigger %f to %f crossed %f\n", - fvi_query_ptr->p0->z, - fvi_hit_data_ptr->hit_pnt.z, - vertex_ptr_list[0]->z); -*/ + /* + mprintf(0, "FVI:In trigger %f to %f crossed %f\n", + fvi_query_ptr->p0->z, + fvi_hit_data_ptr->hit_pnt.z, + vertex_ptr_list[0]->z); + */ face_normal = cur_room->faces[i].normal; @@ -2631,10 +2618,7 @@ int fvi_FindIntersection(fvi_query *fq, fvi_info *hit_data, bool no_subdivision) #ifndef NED_PHYSICS if (Tracking_FVI) { - mprintf(0, "Track FVI - Ray %d, thisobjnum=%d, startroom=%d, rad=%f\n", - FVI_counter, - fq->thisobjnum, - fq->startroom, + mprintf(0, "Track FVI - Ray %d, thisobjnum=%d, startroom=%d, rad=%f\n", FVI_counter, fq->thisobjnum, fq->startroom, fq->rad); } #endif @@ -2659,14 +2643,14 @@ int fvi_FindIntersection(fvi_query *fq, fvi_info *hit_data, bool no_subdivision) if (fq->thisobjnum >= 0) this_obj = &Objects[fq->thisobjnum]; else - this_obj = NULL; + this_obj = nullptr; if (fq->rad == 0.0f) fvi_zero_rad = true; else fvi_zero_rad = false; - ASSERT(fq != NULL && hit_data != NULL); + ASSERT(fq != nullptr && hit_data != nullptr); ASSERT(std::isfinite(fq->p1->x)); // Caller wants to go to infinity! -- Not FVI's fault. ASSERT(std::isfinite(fq->p1->y)); // Caller wants to go to infinity! -- Not FVI's fault. @@ -2787,7 +2771,7 @@ int fvi_FindIntersection(fvi_query *fq, fvi_info *hit_data, bool no_subdivision) fvi_new_query.flags &= (~FQ_NEW_RECORD_LIST); if (s_hit_type != HIT_NONE) { - //mprintf(0, "Hit %d at %f, %f, %f\n", s_hit_type, XYZ(&fvi_new_hit_data.hit_pnt)); + // mprintf(0, "Hit %d at %f, %f, %f\n", s_hit_type, XYZ(&fvi_new_hit_data.hit_pnt)); break; } @@ -3356,11 +3340,11 @@ void check_hit_obj(int objnum) { return; if (!(obj->flags & OF_DEAD)) { - if (!(m_obj_index == objnum)) { + if (m_obj_index != objnum) { if (!((m_obj_index > -1) && ((collision_type = CollisionResult[m_obj->type][obj->type]) == RESULT_NOTHING) && (CollisionResult[obj->type][m_obj->type] == RESULT_NOTHING))) { // Account for ray casting - if (!(m_obj_index > -1) && (CollisionRayResult[obj->type] == RESULT_NOTHING)) + if (m_obj_index <= -1 && (CollisionRayResult[obj->type] == RESULT_NOTHING)) return; if (object_movement_AABB(&Objects[objnum])) { @@ -3376,7 +3360,7 @@ void check_hit_obj(int objnum) { #endif #endif - if (fvi_query_ptr->ignore_obj_list == NULL || !obj_in_list(objnum, fvi_query_ptr->ignore_obj_list)) { + if (fvi_query_ptr->ignore_obj_list == nullptr || !obj_in_list(objnum, fvi_query_ptr->ignore_obj_list)) { if (!ObjectsAreRelated(objnum, m_obj_index)) { if (m_obj_index < 0) { @@ -3829,7 +3813,7 @@ inline void check_terrain_node(int cur_node, bool f_check_local_nodes, bool f_ch if (fvi_query_ptr->thisobjnum >= 0) this_obj = &Objects[fvi_query_ptr->thisobjnum]; else - this_obj = NULL; + this_obj = nullptr; // Object checks if ((fvi_terrain_obj_visit_list[cur_node >> 3] & (0x01 << (cur_node % 8))) == 0) { @@ -3961,12 +3945,11 @@ inline void check_terrain_node(int cur_node, bool f_check_local_nodes, bool f_ch check_line_to_face(&hit_point, &colp, &cur_dist, &wall_norm, fvi_query_ptr->p0, &fvi_hit_data_ptr->hit_pnt, &face_normal, vertex_ptr_list, 3, fvi_query_ptr->rad); } -/* - if(Objects[fvi_query_ptr->thisobjnum].type == OBJ_CLUTTER) { - mprintf(0, "Y = %f\n", Objects[fvi_query_ptr->thisobjnum].pos.y); - } -*/ - + /* + if(Objects[fvi_query_ptr->thisobjnum].type == OBJ_CLUTTER) { + mprintf(0, "Y = %f\n", Objects[fvi_query_ptr->thisobjnum].pos.y); + } + */ // chrisnote - closest hit should be tracked... So, we can call BBPI once with // false and all other times with true for fast exit. @@ -4504,7 +4487,7 @@ int fvi_room(int room_index, int from_portal, int room_obj) { if (fvi_query_ptr->thisobjnum >= 0) this_obj = &Objects[fvi_query_ptr->thisobjnum]; else - this_obj = NULL; + this_obj = nullptr; ASSERT(room_index >= 0 && room_index <= Highest_room_index); ASSERT(Rooms[room_index].used); @@ -4621,8 +4604,8 @@ int fvi_room(int room_index, int from_portal, int room_obj) { cf_max->x < fvi_wall_min_xyz.x || cf_max->y < fvi_wall_min_xyz.y || cf_max->z < fvi_wall_min_xyz.z) continue; - if (fvi_zero_rad && FastVectorBBox((float *)cf_min, (float *)cf_max, (float *)fvi_query_ptr->p0, - (float *)&fvi_movement_delta) == false) + if (fvi_zero_rad && !FastVectorBBox((float *)cf_min, (float *)cf_max, (float *)fvi_query_ptr->p0, + (float *)&fvi_movement_delta)) continue; portal_num = cur_face->portal_num; @@ -4804,8 +4787,6 @@ int fvi_room(int room_index, int from_portal, int room_obj) { if ((c_room > 0) && (Rooms[c_room].flags & RF_DOOR)) { bool f_add_next_portal = true; - int next_portal_index; - for (next_portal_index = 0; next_portal_index < num_next_portals; next_portal_index++) { if (next_portals[next_portal_index] == i) { f_add_next_portal = false; diff --git a/lib/findintersection.h b/physics/findintersection.h similarity index 99% rename from lib/findintersection.h rename to physics/findintersection.h index effb94b7..2d00d958 100644 --- a/lib/findintersection.h +++ b/physics/findintersection.h @@ -1,5 +1,5 @@ /* -* Descent 3 +* Descent 3 * Copyright (C) 2024 Parallax Software * * This program is free software: you can redistribute it and/or modify @@ -215,13 +215,12 @@ * $NoKeywords: $ */ -#ifndef _FVI_H -#define _FVI_H +#ifndef FVI_H +#define FVI_H #include "object.h" #include "vecmat.h" #include "terrain.h" -// #include "room.h" #include "findintersection_external.h" extern float Ceiling_height; @@ -426,7 +425,7 @@ extern int check_vector_to_sphere_1(vector *intp, float *col_dist, const vector extern int check_line_to_face(vector *newp, vector *colp, float *col_dist, vector *wall_norm, const vector *p0, const vector *p1, vector *face_normal, vector **vertex_ptr_list, const int nv, const float rad); -extern void InitFVI(void); +extern void InitFVI(); // Types of supported collisions #ifdef NED_PHYSICS diff --git a/physics/newstyle_fi.cpp b/physics/newstyle_fi.cpp index f716b835..ca742f63 100644 --- a/physics/newstyle_fi.cpp +++ b/physics/newstyle_fi.cpp @@ -1,30 +1,27 @@ /* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ + * Descent 3 + * Copyright (C) 2024 Parallax Software + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ -#include "pserror.h" -#include "pstypes.h" -#include "vecmat.h" -#include "polymodel.h" #include "findintersection.h" #include "game.h" +#include "polymodel.h" +#include "pserror.h" +#include "vecmat.h" -#include -#include #ifndef NED_PHYSICS #include "multi.h" #endif @@ -55,7 +52,7 @@ static struct instance_context instance_stack[MAX_INSTANCE_DEPTH]; static int instance_depth = 0; -static inline void ns_compute_movement_AABB(void); +static inline void ns_compute_movement_AABB(); static inline bool ns_movement_manual_AABB(vector *min_xyz, vector *max_xyz); static void CollideSubmodelFacesUnsorted(poly_model *pm, bsp_info *sm); @@ -69,7 +66,8 @@ static void newstyle_StartInstanceAngles(vector *pos, angvec *angles); /// pops the old context static void newstyle_DoneInstance(); static void CollideSubmodel(poly_model *pm, bsp_info *sm, uint32_t f_render_sub); -static void CollidePolygonModel(vector *pos, matrix *orient, int model_num, float *normalized_time, uint32_t f_render_sub); +static void CollidePolygonModel(vector *pos, matrix *orient, int model_num, float *normalized_time, + uint32_t f_render_sub); static void BuildModelAngleMatrix(matrix *mat, angle ang, vector *axis) { float x, y, z; @@ -96,24 +94,13 @@ static void BuildModelAngleMatrix(matrix *mat, angle ang, vector *axis) { mat->fvec.z = t * z * z + c; } -////rotates a point. returns codes. does not check if already rotated -// static inline void collide_RotatePoint(g3Point *dest,vector *src) -//{ -// vector tempv; -// -// tempv = *src - View_position; -// -// dest->p3_vec = tempv * View_matrix; -// -//} - float fvi_hit_param; bool fvi_check_param; static vector ns_min_xyz; static vector ns_max_xyz; -inline void ns_compute_movement_AABB(void) { +inline void ns_compute_movement_AABB() { vector delta_movement = *fvi_query_ptr->p1 - *fvi_query_ptr->p0; vector offset_vec; @@ -289,8 +276,8 @@ void newstyle_StartInstanceMatrix(vector *pos, matrix *orient) { static void newstyle_StartInstanceAngles(vector *pos, angvec *angles) { matrix tm; - if (angles == NULL) { - newstyle_StartInstanceMatrix(pos, NULL); + if (angles == nullptr) { + newstyle_StartInstanceMatrix(pos, nullptr); return; } @@ -416,7 +403,7 @@ bool PolyCollideObject(object *obj) { CollidePolygonModel(&obj->pos, &obj->orient, obj->rtype.pobj_info.model_num, normalized_time, obj->rtype.pobj_info.subobj_flags); } else { - CollidePolygonModel(&obj->pos, &obj->orient, obj->rtype.pobj_info.model_num, NULL, + CollidePolygonModel(&obj->pos, &obj->orient, obj->rtype.pobj_info.model_num, nullptr, obj->rtype.pobj_info.subobj_flags); } #else diff --git a/physics/physics.cpp b/physics/physics.cpp index 2a7516c1..f81256e2 100644 --- a/physics/physics.cpp +++ b/physics/physics.cpp @@ -1,49 +1,41 @@ /* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ + * Descent 3 + * Copyright (C) 2024 Parallax Software + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include - -#include -#include - +#include #include -#include "object.h" -#include "PHYSICS.H" -#include "collide.h" -#include "findintersection.h" -#include "vecmat.h" -#include "game.h" -#include "terrain.h" -#include "descent.h" -#include "weapon.h" -#include "polymodel.h" -#include "fireball.h" -#include "damage.h" -#include "gameevent.h" -#include "hlsoundlib.h" -#include "soundload.h" -#include "viseffect.h" -#include "multi.h" #include "attach.h" +#include "collide.h" #include "D3ForceFeedback.h" -#include "player.h" #include "demofile.h" +#include "findintersection.h" +#include "fireball.h" +#include "game.h" +#include "multi.h" +#include "object.h" +#include "physics.h" +#include "player.h" +#include "polymodel.h" +#include "terrain.h" +#include "vecmat.h" +#include "viseffect.h" +#include "weapon.h" // Global variables for physics system uint8_t Default_player_terrain_leveling = 0; @@ -414,16 +406,6 @@ bool PhysicsDoSimRot(object *obj, float frame_time, matrix *orient, vector *rott return true; } - // if(!(f_leveling) && fabs(rotthrust->x) < .000001 && fabs(rotthrust->y) < .000001 && fabs(rotthrust->z) < - //.000001) - // { - // if(!(fabs(rotvel->x) > .000001 || fabs(rotvel->y) > .000001 || fabs(rotvel->z) > .000001 || *turnroll != - // 0)) - // { - // return false; - // } - // } - // now rotate object // unrotate object for bank caused by turn if (*turnroll != 0) { @@ -554,103 +536,77 @@ bool PhysicsDoSimRot(object *obj, float frame_time, matrix *orient, vector *rott scale = 1.0; if (ang.p < 16834) { - // float temp_scale = (1.04f - ((16834 - ang.p)/16834.0f)); - // scale = temp_scale * temp_scale; rotthrust->x -= scale * obj->mtype.phys_info.full_rotthrust; - // mprintf(0, "1 scale %f\n", scale); } else if (ang.p < 32768) { - // float temp_scale = (1.04f - ((ang.p - 16834)/16834.0f)); - // scale = temp_scale * temp_scale; rotthrust->x += scale * obj->mtype.phys_info.full_rotthrust; - // mprintf(0, "2 scale %f\n", scale); } else if (ang.p < 49152) { - // float temp_scale = (1.04f - ((49152 - ang.p)/16834.0f)); - // scale = temp_scale * temp_scale; rotthrust->x -= scale * obj->mtype.phys_info.full_rotthrust; - // mprintf(0, "3 scale %f\n", scale); } else { - // float temp_scale = (1.04f - ((ang.p - 49152)/16834.0f)); - // scale = temp_scale * temp_scale; rotthrust->x += scale * obj->mtype.phys_info.full_rotthrust; - // mprintf(0, "4 scale %f\n", scale); } } } } if (!f_pitch_leveled && fabs(rotthrust->z) < 100.0f) { - if (1) ///*&& (pi->turnroll <= 10 || pi->turnroll >= 65535 - 10)*/) - { - angvec ang; - int bound; + angvec ang; + int bound; - // f_leveling = true; - // pi->turnroll = 0; + // extract angles from a matrix + vm_ExtractAnglesFromMatrix(&ang, orient); + if ((ang.p < 32768 && (abs((int)ang.p - (int)16834) > max_tilt_angle)) || + (ang.p >= 32768 && (abs((int)ang.p - (int)49152) > max_tilt_angle))) { - // extract angles from a matrix - vm_ExtractAnglesFromMatrix(&ang, orient); + if ((pi->flags & PF_TURNROLL) && *turnroll) { + bound = *turnroll; + if (bound > 32768) { + bound = 65535 - bound; + } + } else { + bound = 10; + } - if ((ang.p < 32768 && (abs((int)ang.p - (int)16834) > max_tilt_angle)) || - (ang.p >= 32768 && (abs((int)ang.p - (int)49152) > max_tilt_angle))) { + if (ang.b > bound && ang.b < 65535 - bound) // About 1 degree + { + float scale; - if ((pi->flags & PF_TURNROLL) && *turnroll) { - bound = *turnroll; - if (bound > 32768) { - bound = 65535 - bound; - } + // Scale on pitch + if (ang.p < 32768) { + scale = (abs(16834 - (int)ang.p) - max_tilt_angle) / (16384.0f - max_tilt_angle); } else { - bound = 10; + scale = (abs(49152 - (int)ang.p) - max_tilt_angle) / (16384.0f - max_tilt_angle); } - if (ang.b > bound && ang.b < 65535 - bound) // About 1 degree - { - float scale; - // vector level_rotthrust = Zero_vector; + if (ang.b < 32768) { + float temp_scale; - // Scale on pitch - if (ang.p < 32768) { - scale = (abs(16834 - (int)ang.p) - max_tilt_angle) / (16384.0f - max_tilt_angle); + if (ang.b > 28672) { + temp_scale = (1.04f - ((28672 - 16834) / 16384.0f)); } else { - scale = (abs(49152 - (int)ang.p) - max_tilt_angle) / (16384.0f - max_tilt_angle); + temp_scale = (1.04f - (abs(16834 - (int)ang.b) / 16384.0f)); } - // mprintf(0, "scale %f, ", scale); + temp_scale *= temp_scale; + scale *= temp_scale; + if (f_player_fired_recently) + scale *= .25f; - if (ang.b < 32768) { - float temp_scale; - // if(temp_scale * temp_scale > .05) + rotthrust->z -= scale * BANK_AUTOLEVEL_SPEED_SCALAR * obj->mtype.phys_info.full_rotthrust; + } else { + float temp_scale; - if (ang.b > 28672) { - temp_scale = (1.04f - ((28672 - 16834) / 16384.0f)); - } else { - temp_scale = (1.04f - (abs(16834 - (int)ang.b) / 16384.0f)); - } - - temp_scale *= temp_scale; - scale *= temp_scale; - if (f_player_fired_recently) - scale *= .25f; - - rotthrust->z -= scale * BANK_AUTOLEVEL_SPEED_SCALAR * obj->mtype.phys_info.full_rotthrust; + if (ang.b < 36864) { + temp_scale = (1.04f - ((49152 - 36864) / 16384.0f)); } else { - float temp_scale; - - if (ang.b < 36864) { - temp_scale = (1.04f - ((49152 - 36864) / 16384.0f)); - } else { - temp_scale = (1.04f - (abs(49152 - (int)ang.b) / 16384.0f)); - } - - temp_scale *= temp_scale; - scale *= temp_scale; - if (f_player_fired_recently) - scale *= .25f; - - rotthrust->z += scale * BANK_AUTOLEVEL_SPEED_SCALAR * obj->mtype.phys_info.full_rotthrust; + temp_scale = (1.04f - (abs(49152 - (int)ang.b) / 16384.0f)); } - // PhysicsApplyConstRotForce(*obj, level_rotthrust, *rotvel, - // frame_time); + temp_scale *= temp_scale; + scale *= temp_scale; + if (f_player_fired_recently) + scale *= .25f; + + rotthrust->z += scale * BANK_AUTOLEVEL_SPEED_SCALAR * obj->mtype.phys_info.full_rotthrust; } } } @@ -666,7 +622,8 @@ bool PhysicsDoSimRot(object *obj, float frame_time, matrix *orient, vector *rott } // Apply rotation to the "un-rollbanked" object - tangles.p = (int16_t)(rotvel->x * frame_time); // Casting to int16_t is required for aarch64 to avoid FCVTZU instruction which strips the negative sign + tangles.p = (int16_t)(rotvel->x * frame_time); // Casting to int16_t is required for aarch64 to avoid FCVTZU + // instruction which strips the negative sign tangles.h = (int16_t)(rotvel->y * frame_time); tangles.b = (int16_t)(rotvel->z * frame_time); @@ -685,12 +642,6 @@ bool PhysicsDoSimRot(object *obj, float frame_time, matrix *orient, vector *rott vm_AnglesToMatrix(&rotmat, tangles.p, tangles.h, tangles.b); *orient = *orient * rotmat; // ObjSetOrient is below } -/* - mprintf(0, " a %f, %f, %f,\n%f, %f, %f,\n%f %f %f\n\n", - XYZ(&obj->orient.fvec), - XYZ(&obj->orient.rvec), - XYZ(&obj->orient.uvec)); -*/ // Make sure the new orientation is valid vm_Orthogonalize(orient); @@ -706,10 +657,6 @@ void PhysicsDoSimLinear(const object &obj, const vector &pos, const vector &forc return; } - // Help so that we do not loss velocity when sliding (still framerate dependent -- fix with force stuff) - // if (!(count == 0 || (count > 0 && (~obj->mtype.phys_info.flags & (PF_BOUNCE | PF_GRAVITY))))) - // return; - vector forceToUse = force; if (!ROOMNUM_OUTSIDE(obj.roomnum) && !(obj.mtype.phys_info.flags & PF_LOCK_MASK) && Rooms[obj.roomnum].wind != Zero_vector && count == 0 && obj.mtype.phys_info.drag > 0.0f && @@ -970,30 +917,7 @@ void do_physics_sim(object *obj) { PhysicsDoSimRot(obj, sim_time_remaining, &end_orient, &obj->mtype.phys_info.rotthrust, &end_rotvel, &end_turnroll); - /* vector init_pos = obj->pos + obj->wall_sphere_offset;*/ ObjSetOrient(obj, &end_orient); - /* vector new_pos = obj->pos + obj->wall_sphere_offset; - - if(obj->wall_sphere_offset != Zero_vector && obj->type == OBJ_ROBOT && - !(obj->mtype.phys_info.flags & PF_POINT_COLLIDE_WALLS)) - { - fq.p0 = &init_pos; - fq.startroom = obj->roomnum; - fq.p1 = &new_pos; - fq.rad = - Poly_models[obj->rtype.pobj_info.model_num].wall_size; fq.thisobjnum = objnum; - fq.ignore_obj_list = NULL; - fq.flags = 0; - - fate = fvi_FindIntersection(&fq,&hit_info); - - // Only wiggle on a non-hit case - if(fate != HIT_NONE) - { - end_orient = start_orient; - ObjSetOrient(obj, &start_orient); - } - }*/ } else { f_set_orient = false; } @@ -1043,21 +967,6 @@ void do_physics_sim(object *obj) { goto end_of_sim; } - // If we are stationary, we are done :) -- breaks on high framerates (Gravity) - // if(vm_GetMagnitude(&movement_vec) < 0.00001) - // if(vm_GetMagnitude(&start_vel) < 0.00001) - // if(vm_GetMagnitude(&end_vel) < 0.00001) - // if(vm_GetMagnitude(&obj->mtype.phys_info.thrust) < 0.00001) - // if(vm_GetMagnitude(&obj->mtype.phys_info.rotthrust) < .0001) - // if(vm_GetMagnitude(&start_rotvel) < .0001) - // if(vm_GetMagnitude(&end_rotvel) < .0001) - // { - // mprintf(0, "At rest\n"); - // goto end_of_sim; - // } - - // mprintf(0, "PHYSICS: Try to move to (%f, %f, %f)\n", movement_pos.x, movement_pos.y, movement_pos.z); - Physics_normal_looping_counter++; // Cap ignore list -- (Objects we already hit this frame) @@ -1130,16 +1039,7 @@ void do_physics_sim(object *obj) { } vm_NormalizeVector(&hit_info.hit_wallnorm[0]); } -/* - if (obj == Player_object && fate != HIT_NONE) { - mprintf(0, "Hit type %d, obj %d\n", fate, hit_info.hit_object[0]); - if (fate == HIT_OBJECT || fate == HIT_SPHERE_2_POLY_OBJECT) { - mprintf(0, "Hit object type %d, id %d\n", - Objects[hit_info.hit_object[0]].type, - Objects[hit_info.hit_object[0]].id); - } - } -*/ + obj->mtype.phys_info.velocity = temp_vel; // Accounts for precomputed hit rays @@ -1213,7 +1113,6 @@ void do_physics_sim(object *obj) { if (f_set_orient) { obj->mtype.phys_info.turnroll = hit_info.hit_turnroll; obj->mtype.phys_info.rotvel = hit_info.hit_rotvel; - // ObjSetOrient(obj, &hit_info.hit_orient); f_set_orient = false; } @@ -1265,12 +1164,6 @@ void do_physics_sim(object *obj) { // We where sitting in a wall -- invalid starting point // moved backwards if (fate == HIT_WALL && moved_vec_n * movement_vec < -0.000001 && actual_dist != 0.0) { -/* - mprintf(0, "Obj %d Flew backwards!\n", OBJNUM(obj)); - mprintf(0, "PHYSICS NOTE: (%f, %f, %f) to (%f, %f, %f)\n", - XYZ(&start_pos), - XYZ(&obj->pos)); // don't change position or sim_time_remaining -*/ ObjSetPos(obj, &start_pos, start_room, NULL, false); moved_time = 0.0; @@ -1289,24 +1182,12 @@ void do_physics_sim(object *obj) { // chrishack -- negative simulation time pasted for this sim frame if (sim_time_remaining > old_sim_time_remaining) { -/* - mprintf(0,"PHYSICS WARNING: Bogus sim_time_remaining = %15.13f, old = %15.13f\n"" - "Attempted d = %15.13f, actual = %15.13f\n", - sim_time_remaining, - old_sim_time_remaining, - attempted_dist, - actual_dist); - Int3(); -*/ sim_time_remaining = old_sim_time_remaining; moved_time = 0.0; f_continue_sim = false; } } - // // Get the collision speed as a linear interp. - // if(old_sim_time_remaining > 0.0f) - // { // Get the collision speed as a linear interp. if (fate == HIT_OBJECT || fate == HIT_SPHERE_2_POLY_OBJECT || fate == HIT_TERRAIN || fate == HIT_WALL) { if (moved_time > 0.0001f) { @@ -1363,7 +1244,6 @@ void do_physics_sim(object *obj) { } } - // if(obj->type != OBJ_CLUTTER) { vector moved_v; float hit_speed, wall_part; @@ -1486,30 +1366,6 @@ void do_physics_sim(object *obj) { obj->mtype.phys_info.velocity += hit_info.hit_wallnorm[0] * (wall_part * -1.0f); } - // if(!f_forcefield && !(f_volatile && obj->type == OBJ_PLAYER)) - // { - // if(obj->mtype.phys_info.coeff_restitution != 1.0f) - // obj->mtype.phys_info.velocity -= - //(obj->mtype.phys_info.velocity * (1.0f - //- obj->mtype.phys_info.coeff_restitution)); - // } - - // if(!f_forcefield && !(f_volatile && obj->type == OBJ_PLAYER)) - // bump_obj_against_fixed(obj, &hit_info.hit_face_pnt[0], - //&hit_info.hit_wallnorm[0]); - // - // if(hit_info.hit_wallnorm[0].y > .4 && - //(vm_GetMagnitude(&obj->mtype.phys_info.velocity) < .001f - //|| obj->mtype.phys_info.velocity * hit_info.hit_wallnorm[0] <= 0.0f)) - // { - // mprintf(0, "At Rest!\n"); - // obj->movement_type = MT_NONE; - // obj->mtype.phys_info.velocity = Zero_vector; - // f_continue_sim = false; - // } - - // mprintf(0, "(%f, %f, %f) after bounce\n", XYZ(&obj->mtype.phys_info.velocity)); - // mprintf(0, "p (%f, %f, %f) after bounce\n", XYZ(&obj->pos)); } else { slide_sim: @@ -1519,18 +1375,18 @@ void do_physics_sim(object *obj) { if (obj->type != OBJ_CLUTTER) total_force += - hit_info.hit_wallnorm[0] * (wall_force * -1.001); // 1.001 so that we are not quite tangential + hit_info.hit_wallnorm[0] * (wall_force * -1.001f); // 1.001 so that we are not quite tangential else total_force += - hit_info.hit_wallnorm[0] * (wall_force * -1.0001); // 1.001 so that we are not quite tangential + hit_info.hit_wallnorm[0] * (wall_force * -1.0001f); // 1.001 so that we are not quite tangential // Update velocity from wall hit. if (obj->type != OBJ_CLUTTER) obj->mtype.phys_info.velocity += - hit_info.hit_wallnorm[0] * (wall_part * -1.001); // 1.001 so that we are not quite tangential + hit_info.hit_wallnorm[0] * (wall_part * -1.001f); // 1.001 so that we are not quite tangential else obj->mtype.phys_info.velocity += - hit_info.hit_wallnorm[0] * (wall_part * -1.0001); // 1.001 so that we are not quite tangential + hit_info.hit_wallnorm[0] * (wall_part * -1.0001f); // 1.001 so that we are not quite tangential if ((obj->type == OBJ_ROBOT || obj->type == OBJ_PLAYER || (obj->type == OBJ_BUILDING && obj->ai_info)) && sim_time_remaining == old_sim_time_remaining) { @@ -1584,93 +1440,6 @@ void do_physics_sim(object *obj) { vm_VectorToMatrix(&obj->orient, &obj->mtype.phys_info.velocity, &obj->orient.uvec, NULL); } } - // else - //{ - /* vector r1 = hit_info.hit_face_pnt[0] - obj->pos; - vector w1; - vector n1; - float temp1; - - float j; - - matrix o_t1 = obj->orient; - vm_TransposeMatrix(&o_t1); - vector cmp1 = obj->mtype.phys_info.rotvel * o_t1; - ConvertEulerToAxisAmount(&cmp1, &n1, &temp1); - - n1 *= temp1; - - if(temp1 != 0.0f) - { - vm_CrossProduct(&w1, &n1, &r1); - } - else - { - w1 = Zero_vector; - } - - vector p1 = obj->mtype.phys_info.velocity + w1; // *((2.0f*(float)PI)/65535.0f); - - if(p1.y < 0.0) - { - // if(p1.y == 0.0) - // mprintf(0, "AT REST: p1 (%f, %f, %f)\n", XYZ(&p1)); - // else - // mprintf(0, "SHIT: p1 (%f, %f, %f)\n", XYZ(&p1)); - // - // p1.y = -.0001f; - // } - - - float v_rel; - - float m1 = obj->mtype.phys_info.mass; - - v_rel = hit_info.hit_wallnorm[0] * (p1); - - float e = .1f; - - vector c1; - vector cc1; - float cv1; - - float i1 = (m1/12.0)*(2.0f * pow(obj->size*2.0, 2)); - - vm_CrossProduct(&c1, &r1, &hit_info.hit_wallnorm[0]); - - c1 = c1/i1; - - vm_CrossProduct(&cc1, &c1, &r1); - - cv1 = (hit_info.hit_wallnorm[0])*c1; - - j = (-(1.0f + e))*v_rel; - j /= (1/m1 + cv1); - - obj->mtype.phys_info.velocity += ((j*(hit_info.hit_wallnorm[0]))/m1); - - vector jcn = j * (hit_info.hit_wallnorm[0]); - - vm_CrossProduct(&c1, &r1, &jcn); - - n1 = (c1)/i1; - - temp1 = vm_NormalizeVector(&n1); - - vector txx1; - - ConvertAxisAmountToEuler(&n1, &temp1, &txx1); - - obj->mtype.phys_info.rotvel += (txx1*obj->orient); - } - else - { - obj->mtype.phys_info.velocity.y = .001f; - obj->mtype.phys_info.rotvel = Zero_vector; - }*/ - - // } - f_continue_sim = true; } break; @@ -1739,15 +1508,10 @@ void do_physics_sim(object *obj) { // chrishack -- we should have this point from FVI!!!!!!!!!!! // Calculcate the hit point between the two objects. - // old_vel = obj->mtype.phys_info.velocity; old_force = obj->mtype.phys_info.thrust; obj->mtype.phys_info.thrust = total_force; - // hit_info.hit_wallnorm[0] *= -1.0f; - - // mprintf(0, "hit dist %f\n", hit_info.hit_dist); - collide_two_objects(obj, &Objects[hit_info.hit_object[0]], &hit_info.hit_face_pnt[0], &hit_info.hit_wallnorm[0], &hit_info); if (obj->movement_type == MT_OBJ_LINKED) @@ -1767,20 +1531,6 @@ void do_physics_sim(object *obj) { obj->mtype.phys_info.velocity += hit_info.hit_wallnorm[0]; } - // mprintf(0, "OBJ %d t %d hit %d\n", OBJNUM(obj), obj->type, hit_info.hit_object[0]); - - // Let object continue its movement if collide_two_objects does not mark it as dead - // if ( !(obj->flags&OF_DEAD) ) - // { - // - // // chrishack -- check this later -- what is the old_vel stuff? - // if ((obj->mtype.phys_info.flags & PF_PERSISTENT) || - // (old_vel == obj->mtype.phys_info.velocity)) - // { - // ignore_obj_list[n_ignore_objs++] = hit_info.hit_object[0]; - // } - // } - // Let object continue its movement if collide_two_objects does not mark it as dead if (!(obj->flags & OF_DEAD)) { if ((obj->mtype.phys_info.flags & PF_PERSISTENT) || @@ -1810,11 +1560,6 @@ void do_physics_sim(object *obj) { f_continue_sim = true; - // if((obj->type == OBJ_CLUTTER)&&(Objects[hit_info.hit_object[0]].type == - // OBJ_CLUTTER)) - // { - // f_continue_sim = false; - // } } else { f_continue_sim = false; } @@ -1843,20 +1588,7 @@ void do_physics_sim(object *obj) { if (obj->type == OBJ_PLAYER) { mprintf(0, "PHYSICS NOTE: Too many collisions for player!\n"); obj->mtype.phys_info.velocity = Zero_vector; - } else { -/* - mprintf(0, "PHYSICS NOTE: Too many collisions for non-player object %d (%d to %d)!\n", - objnum, - init_room, - obj->roomnum); - obj->flags |= OF_DEAD; - obj->mtype.phys_info.velocity /= 2.0f; - obj->mtype.phys_info.rotvel /= 2.0f; -*/ } - - // ObjSetPos(obj,&init_pos, init_room); - // obj->last_pos = init_pos; } end_of_sim: @@ -1917,75 +1649,6 @@ int PhysCastWalkRay(object *obj, vector *p0, vector *p1, vector *hitpnt, int *st return fate; } -// void PhysComputeGroundPosOrient(object *obj, vector *pos, matrix *orient) -//{ -// vector pnt[3]; -// vector tpnt = obj->pos; -// matrix tmatrix = obj->orient; -// poly_model *pm=&Poly_models[obj->rtype.pobj_info.model_num]; -// int num_gps = (pm->n_ground == 5)?3:1; -// int i; -// -// obj->pos = *pos; -// obj->orient = *orient; -// -// for(i = 0; i < num_gps; i++) -// { -// PhysCalcGround(&pnt[i], NULL, obj, i); -// } -// -// obj->pos = tpnt; -// obj->orient = tmatrix; -// -// if(num_gps == 3 && ROOMNUM_OUTSIDE(obj->roomnum)) -// { -// float diff[3]; -// vector gp[3]; -// -// for(i = 0; i < 3; i++) -// { -// gp[i] = pnt[i]; -// gp[i].y = GetTerrainGroundPoint(&gp[i]); -// } -// -// for(i = 0; i < 3; i++) -// { -// diff[i] = gp[i].y - pnt[i].y; -// } -// -// float biggest_diff = diff[0]; -// for(i = 1; i < 3; i++) -// { -// if(fabs(diff[i]) > fabs(biggest_diff)) -// { -// biggest_diff = diff[i]; -// } -// } -// -// vector uvec; -// vm_GetPerp(&uvec, &gp[0], &gp[1], &gp[2]); -// vm_NormalizeVector(&uvec); -// -// float dot = orient->fvec * uvec; -// vector fvec = orient->fvec; -// fvec -= (uvec * dot); -// vm_NormalizeVector(&fvec); -// -// vm_VectorToMatrix(orient, &fvec, &uvec, NULL); -// pos->y += biggest_diff; -// } -// else -// { // Alignd to Y-axis -// float diff = GetTerrainGroundPoint(&pnt[0]) - pnt[0].y; -// -// pos->y += diff; -// -// angvec a; -// vm_ExtractAnglesFromMatrix(&a, orient); -// vm_AnglesToMatrix(orient, 0.0f, a.h, 0.0f); -// } -//} - void PhysCalPntOnCPntPlane(object *obj, vector *s_pnt, vector *d_pnt, float *dist) { vector tpnt = *s_pnt - obj->pos; *dist = obj->orient.uvec * tpnt; @@ -2354,7 +2017,7 @@ void do_walking_sim(object *obj) { } } - // mprintf(0, "PHYSICS: Current obj: %d, %9.2fx %9.2fy %9.2fz\n", OBJNUM(obj), XYZ(&obj->pos)); + // mprintf(0, "PHYSICS: Current obj: %d, %9.2fx %9.2fy %9.2fz\n", OBJNUM(obj), XYZ(&obj->pos)); // mprintf(2,1,0,"x %9.2f\ny %9.2f\nz %9.2f", XYZ(&obj->mtype.phys_info.velocity)); // mprintf(0, "PHYSICS: Current velocity (%f, %f, %f)\n", XYZ(&obj->mtype.phys_info.velocity)); @@ -2504,11 +2167,11 @@ void do_walking_sim(object *obj) { if (fate == HIT_WALL && moved_vec_n * movement_vec < -0.000001 && actual_dist != 0.0) { mprintf(0, "Obj %d Walked backwards!\n", OBJNUM(obj)); -/* - mprintf(0, "PHYSICS NOTE: (%f, %f, %f) to (%f, %f, %f)\n", - XYZ(&start_pos), - XYZ(&obj->pos))); // don't change position or sim_time_remaining -*/ + /* + mprintf(0, "PHYSICS NOTE: (%f, %f, %f) to (%f, %f, %f)\n", + XYZ(&start_pos), + XYZ(&obj->pos))); // don't change position or sim_time_remaining + */ ObjSetPos(obj, &start_pos, start_room, NULL, false); @@ -2529,9 +2192,9 @@ void do_walking_sim(object *obj) { // chrishack -- negative simulation time pasted for this sim frame if (sim_time_remaining > old_sim_time_remaining) { mprintf(0, - "PHYSICS WARNING: Bogus sim_time_remaining = %15.13f, old = %15.13f\nAttempted d = %15.13f, actual " - "= %15.13f\n", - sim_time_remaining, old_sim_time_remaining, attempted_dist, actual_dist); + "PHYSICS WARNING: Bogus sim_time_remaining = %15.13f, old = %15.13f\nAttempted d = %15.13f, actual " + "= %15.13f\n", + sim_time_remaining, old_sim_time_remaining, attempted_dist, actual_dist); // Int3(); sim_time_remaining = old_sim_time_remaining; moved_time = 0.0; @@ -2584,8 +2247,6 @@ void do_walking_sim(object *obj) { else // We hit a wall and are moving parallel to it collide_object_with_wall(obj, hit_speed, hit_info.hit_face_room[0], hit_info.hit_face[0], &hit_info.hit_face_pnt[0], &hit_info.hit_wallnorm[0], hit_dot); - // scrape_object_on_wall(obj, hit_info.hit_face_room, hit_info.hit_face, - //&hit_info.hit_face_pnt[0], &hit_info.hit_wallnorm[0] ); if (!(obj->flags & OF_DEAD)) { bool f_forcefield = false; // bounce off a forcefield @@ -2626,11 +2287,11 @@ void do_walking_sim(object *obj) { wall_force = total_force * hit_info.hit_wallnorm[0]; total_force += - hit_info.hit_wallnorm[0] * (wall_force * -1.001); // 1.001 so that we are not quite tangential + hit_info.hit_wallnorm[0] * (wall_force * -1.001f); // 1.001 so that we are not quite tangential // Update velocity from wall hit. obj->mtype.phys_info.velocity += - hit_info.hit_wallnorm[0] * (wall_part * -1.001); // 1.001 so that we are not quite tangential + hit_info.hit_wallnorm[0] * (wall_part * -1.001f); // 1.001 so that we are not quite tangential if ((obj->type == OBJ_ROBOT || obj->type == OBJ_PLAYER || OBJ_CLUTTER || (obj->type == OBJ_BUILDING && obj->ai_info)) && @@ -2643,7 +2304,6 @@ void do_walking_sim(object *obj) { real_vel = vm_NormalizeVector(&obj->mtype.phys_info.velocity); obj->mtype.phys_info.velocity *= ((real_vel + luke_test) / 2); - // obj->mtype.phys_info.velocity *= (luke_test); } } @@ -2666,93 +2326,6 @@ void do_walking_sim(object *obj) { vm_VectorToMatrix(&obj->orient, &obj->mtype.phys_info.velocity, &obj->orient.uvec, NULL); } } - // else - //{ - /* vector r1 = hit_info.hit_face_pnt[0] - obj->pos; - vector w1; - vector n1; - float temp1; - - float j; - - matrix o_t1 = obj->orient; - vm_TransposeMatrix(&o_t1); - vector cmp1 = obj->mtype.phys_info.rotvel * o_t1; - ConvertEulerToAxisAmount(&cmp1, &n1, &temp1); - - n1 *= temp1; - - if(temp1 != 0.0f) - { - vm_CrossProduct(&w1, &n1, &r1); - } - else - { - w1 = Zero_vector; - } - - vector p1 = obj->mtype.phys_info.velocity + w1; // *((2.0f*(float)PI)/65535.0f); - - if(p1.y < 0.0) - { - // if(p1.y == 0.0) - // mprintf(0, "AT REST: p1 (%f, %f, %f)\n", XYZ(&p1)); - // else - // mprintf(0, "SHIT: p1 (%f, %f, %f)\n", XYZ(&p1)); - // - // p1.y = -.0001f; - // } - - - float v_rel; - - float m1 = obj->mtype.phys_info.mass; - - v_rel = hit_info.hit_wallnorm[0] * (p1); - - float e = .1f; - - vector c1; - vector cc1; - float cv1; - - float i1 = (m1/12.0)*(2.0f * pow(obj->size*2.0, 2)); - - vm_CrossProduct(&c1, &r1, &hit_info.hit_wallnorm[0]); - - c1 = c1/i1; - - vm_CrossProduct(&cc1, &c1, &r1); - - cv1 = (hit_info.hit_wallnorm[0])*c1; - - j = (-(1.0f + e))*v_rel; - j /= (1/m1 + cv1); - - obj->mtype.phys_info.velocity += ((j*(hit_info.hit_wallnorm[0]))/m1); - - vector jcn = j * (hit_info.hit_wallnorm[0]); - - vm_CrossProduct(&c1, &r1, &jcn); - - n1 = (c1)/i1; - - temp1 = vm_NormalizeVector(&n1); - - vector txx1; - - ConvertAxisAmountToEuler(&n1, &temp1, &txx1); - - obj->mtype.phys_info.rotvel += (txx1*obj->orient); - } - else - { - obj->mtype.phys_info.velocity.y = .001f; - obj->mtype.phys_info.rotvel = Zero_vector; - }*/ - - // } - f_continue_sim = true; } break; @@ -2766,7 +2339,6 @@ void do_walking_sim(object *obj) { // chrishack -- we should have this point from FVI!!!!!!!!!!! // Calculcate the hit point between the two objects. - // old_vel = obj->mtype.phys_info.velocity; old_force = obj->mtype.phys_info.thrust; obj->mtype.phys_info.thrust = total_force; @@ -2790,17 +2362,6 @@ void do_walking_sim(object *obj) { // mprintf(0, "OBJ %d t %d hit %d\n", OBJNUM(obj), obj->type, hit_info.hit_object[0]); - // Let object continue its movement if collide_two_objects does not mark it as dead - // if ( !(obj->flags&OF_DEAD) ) - // { - // - // // chrishack -- check this later -- what is the old_vel stuff? - // if ((obj->mtype.phys_info.flags & PF_PERSISTENT) || - // (old_vel == obj->mtype.phys_info.velocity)) - // { - // ignore_obj_list[n_ignore_objs++] = hit_info.hit_object[0]; - // } - // } // Let object continue its movement if collide_two_objects does not mark it as dead if (!(obj->flags & OF_DEAD)) { if ((obj->mtype.phys_info.flags & PF_PERSISTENT) || @@ -2845,20 +2406,7 @@ void do_walking_sim(object *obj) { if (count >= sim_loop_limit) { if (obj->type == OBJ_PLAYER) { mprintf(0, "PHYSICS NOTE: Too many collisions for player!\n"); - } else { - /* - mprintf(0, "PHYSICS NOTE: Too many collisions for non-player object %d (%d to %d)!\n", - objnum, - init_room, - obj->roomnum)); - obj->flags |= OF_DEAD; - obj->mtype.phys_info.velocity /= 2.0f; - obj->mtype.phys_info.rotvel /= 2.0f; - */ } - - // ObjSetPos(obj,&init_pos, init_room); - // obj->last_pos = init_pos; } end_of_sim: @@ -2994,7 +2542,6 @@ void do_vis_physics_sim(vis_effect *vis) { } else { VisEffectDelete(vis - VisEffects); } - } void phys_apply_force(object *obj, vector *force_vec, int16_t weapon_index) { @@ -3044,155 +2591,5 @@ void phys_apply_force(object *obj, vector *force_vec, int16_t weapon_index) { // Add in acceleration due to force obj->mtype.phys_info.velocity += (*force_vec / obj->mtype.phys_info.mass); } -/* -// ---------------------------------------------------------------- -// Do *dest = *delta unless: -// *delta is pretty small -// and they are of different signs. -void physics_set_rotvel_and_saturate(float *dest, float delta) -{ - if ((delta ^ *dest) < 0) { - if (abs(delta) < F1_0/8) { - // mprintf(0, "D"); - *dest = delta/4; - } else - // mprintf(0, "d"); - *dest = delta; - } else { - // mprintf(0, "!"); - *dest = delta; - } -} - -// ------------------------------------------------------------------------------------------------------ -// Note: This is the old ai_turn_towards_vector code. -// phys_apply_rot used to call ai_turn_towards_vector until I fixed it, which broke phys_apply_rot. - -void physics_turn_towards_vector(vector *goal_vector, object *obj, float rate) -{ - vms_angvec dest_angles, cur_angles; - float delta_p, delta_h; - vector *rotvel_ptr = &obj->mtype.phys_info.rotvel; - - // Make this object turn towards the goal_vector. Changes orientation, doesn't change direction of movement. - // If no one moves, will be facing goal_vector in 1 second. - - // Detect null vector. - if ((goal_vector->x == 0) && (goal_vector->y == 0) && (goal_vector->z == 0)) - return; - - // Make morph objects turn more slowly. - if (obj->control_type == CT_MORPH) - rate *= 2; - - vm_extract_angles_vector(&dest_angles, goal_vector); - vm_extract_angles_vector(&cur_angles, &obj->orient.fvec); - - delta_p = (dest_angles.p - cur_angles.p); - delta_h = (dest_angles.h - cur_angles.h); - - if (delta_p > F1_0/2) delta_p = dest_angles.p - cur_angles.p - F1_0; - if (delta_p < -F1_0/2) delta_p = dest_angles.p - cur_angles.p + F1_0; - if (delta_h > F1_0/2) delta_h = dest_angles.h - cur_angles.h - F1_0; - if (delta_h < -F1_0/2) delta_h = dest_angles.h - cur_angles.h + F1_0; - - delta_p = fixdiv(delta_p, rate); - delta_h = fixdiv(delta_h, rate); - - if (abs(delta_p) < F1_0/16) delta_p *= 4; - if (abs(delta_h) < F1_0/16) delta_h *= 4; - - physics_set_rotvel_and_saturate(&rotvel_ptr->x, delta_p); - physics_set_rotvel_and_saturate(&rotvel_ptr->y, delta_h); - rotvel_ptr->z = 0; -} -*/ -// ----------------------------------------------------------------------------- -// Applies an instantaneous whack on an object, resulting in an instantaneous -// change in orientation. - -void phys_apply_rot(object *obj, vector *force_vec) { -/* - float rate, vecmag; - - if (obj->movement_type != MT_PHYSICS) - return; - - vecmag = vm_VectorMagnitude(force_vec); - - if (vecmag < F1_0 / 256) - rate = 4 * F1_0; - else if (vecmag < obj->mtype.phys_info.mass >> 14) - rate = 4 * F1_0; - else { - rate = fixdiv(obj->mtype.phys_info.mass, vecmag); - - if (obj->type == OBJ_ROBOT) { - if (rate < F1_0 / 4) - rate = F1_0 / 4; - // Changed by mk, 10/24/95, claw guys should not slow down when attacking! - if (!Robot_info[obj->id].thief && !Robot_info[obj->id].attack_type) { - if (obj->ctype.ai_info.SKIP_AI_COUNT * Frametime < 3 * F1_0 / 4) { - float tval = fixdiv(F1_0, 8 * Frametime); - int addval; - addval = f2i(tval); - if ((rand() * 2) < (tval & 0xffff)) - addval++; - obj->ctype.ai_info.SKIP_AI_COUNT += addval; - // -- mk: too much stuff making hard to see my debug messages... - mprintf(0, "Frametime = %7.3f, addval = %i\n", f2fl(Frametime), addval); - } - } - } else { - if (rate < F1_0 / 2) - rate = F1_0 / 2; - } - } - - // Turn amount inversely proportional to mass. Third parameter is seconds to do 360 turn. - physics_turn_towards_vector(force_vec, obj, rate); -*/ -} -/* -//this routine will set the thrust for an object to a value that will -//(hopefully) maintain the object's current velocity - -void set_thrust_from_velocity(object *obj) -{ - Int3(); -// float k; -// -// ASSERT(obj->movement_type == MT_PHYSICS); -// -// k = fixmuldiv(obj->mtype.phys_info.mass,obj->mtype.phys_info.drag,(f1_0-obj->mtype.phys_info.drag)); -// -// vm_vec_copy_scale(&obj->mtype.phys_info.thrust,&obj->mtype.phys_info.velocity,k); -// -} -*/ - -// Checks if an object is on the ground (we might do more in this function at a latter date) --chrishack -int check_obj_on_ground(object *obj, fvi_info *hit_info_ptr) { - vector ground; - fvi_query fq; - - ASSERT(obj->size - 2 * PHYSICS_GROUND_TOLERANCE > 0.0f); - - ground = obj->pos; - // This should account for an object that touches more than one face. (To find the real ground). - ground.y -= (obj->size + 3 * PHYSICS_GROUND_TOLERANCE); - - fq.p0 = &obj->pos; - fq.startroom = obj->roomnum; - fq.p1 = &ground; - fq.rad = obj->size - 2 * PHYSICS_GROUND_TOLERANCE; - fq.thisobjnum = OBJNUM(obj); - fq.ignore_obj_list = NULL; - fq.flags = FQ_CHECK_OBJS; - - if (obj->flags & OF_NO_OBJECT_COLLISIONS) - fq.flags &= ~FQ_CHECK_OBJS; - - return fvi_FindIntersection(&fq, hit_info_ptr); -} +void phys_apply_rot(object *obj, vector *force_vec) {} diff --git a/lib/PHYSICS.H b/physics/physics.h similarity index 93% rename from lib/PHYSICS.H rename to physics/physics.h index 0aa6a838..5a71c5e7 100644 --- a/lib/PHYSICS.H +++ b/physics/physics.h @@ -61,12 +61,12 @@ * $NoKeywords: $ */ -#ifndef _PHYSICS_H -#define _PHYSICS_H +#ifndef PHYSICS_H +#define PHYSICS_H -#include "vecmat.h" #include "findintersection.h" #include "object.h" +#include "vecmat.h" #include "viseffect.h" extern int Physics_normal_counter; @@ -78,7 +78,7 @@ extern int Physics_vis_counter; // The current strength of the world's gravity extern float Gravity_strength; -#define PHYSICS_UNLIMITED_BOUNCE -1 +#define PHYSICS_UNLIMITED_BOUNCE (-1) #ifdef _DEBUG extern int Physics_player_verbose; @@ -106,11 +106,10 @@ void do_walking_sim(object *obj); // Applies an instantaneous force on an object, resulting in an instantaneous // change in velocity. void phys_apply_force(object *obj, vector *force_vec, int16_t weapon_index = -1); -void phys_apply_rot(object *obj, vector *force_vec); -// this routine will set the thrust for an object to a value that will -//(hopefully) maintain the object's current velocity -void set_thrust_from_velocity(object *obj); +// Applies an instantaneous whack on an object, resulting in an instantaneous change in orientation. +// TODO: does nothing +void phys_apply_rot(object *obj, vector *force_vec); // Determines the point and normal of the ground point bool PhysCalcGround(vector *ground_point, vector *ground_normal, object *obj, int ground_num); diff --git a/sndlib/CMakeLists.txt b/sndlib/CMakeLists.txt index 6f9ad8d3..18c73506 100644 --- a/sndlib/CMakeLists.txt +++ b/sndlib/CMakeLists.txt @@ -16,6 +16,7 @@ target_link_libraries(sndlib PRIVATE mem misc stream_audio + physics SDL2::SDL2 ) target_include_directories(sndlib PUBLIC