Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Portions of this file are copyright Rebirth contributors and licensed as
  3.  * described in COPYING.txt.
  4.  * Portions of this file are copyright Parallax Software and licensed
  5.  * according to the Parallax license below.
  6.  * See COPYING.txt for license details.
  7.  
  8. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  9. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  10. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  11. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  12. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  13. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  14. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  15. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  16. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  17. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  18. */
  19.  
  20. /*
  21.  *
  22.  * Basic slew system for moving around the mine
  23.  *
  24.  */
  25.  
  26. #include <stdlib.h>
  27.  
  28. #include "inferno.h"
  29. #include "game.h"
  30. #include "vecmat.h"
  31. #include "key.h"
  32. #include "joy.h"
  33. #include "object.h"
  34. #include "dxxerror.h"
  35. #include "physics.h"
  36. #include "kconfig.h"
  37. #include "slew.h"
  38. #include "segment.h"
  39.  
  40. #if DXX_USE_EDITOR
  41. #include "editor/editor.h"
  42. #endif
  43.  
  44.  
  45. //variables for slew system
  46.  
  47. object *slew_obj=NULL;  //what object is slewing, or NULL if none
  48.  
  49. // -------------------------------------------------------------------
  50. //say start slewing with this object
  51. void slew_init(const vmobjptr_t obj)
  52. {
  53.         slew_obj = obj;
  54.  
  55.         slew_obj->control_type = CT_SLEW;
  56.         slew_obj->movement_type = MT_NONE;
  57.  
  58.         slew_stop();            //make sure not moving
  59. }
  60.  
  61.  
  62. int slew_stop()
  63. {
  64.         if (!slew_obj || slew_obj->control_type!=CT_SLEW) return 0;
  65.  
  66.         vm_vec_zero(slew_obj->mtype.phys_info.velocity);
  67.         return 1;
  68. }
  69.  
  70. void slew_reset_orient()
  71. {
  72.         if (!slew_obj || slew_obj->control_type!=CT_SLEW) return;
  73.  
  74.         slew_obj->orient.rvec.x = slew_obj->orient.uvec.y = slew_obj->orient.fvec.z = f1_0;
  75.  
  76.         slew_obj->orient.rvec.y = slew_obj->orient.rvec.z = slew_obj->orient.uvec.x =
  77.    slew_obj->orient.uvec.z = slew_obj->orient.fvec.x = slew_obj->orient.fvec.y = 0;
  78.  
  79. }
  80.  
  81. static int do_slew_movement(const vmobjptridx_t obj, int check_keys )
  82. {
  83.         auto &Objects = LevelUniqueObjectState.Objects;
  84.         auto &vmobjptr = Objects.vmptr;
  85.         constexpr int ROT_SPEED = 2;            //rate of rotation while key held down
  86.         constexpr int SLIDE_SPEED = 700;
  87.         constexpr int ZOOM_SPEED_FACTOR = 1000; //(1500)
  88.  
  89.         int moved = 0;
  90.         vms_vector svel;                                //scaled velocity (per this frame)
  91.         vms_angvec rotang;
  92.  
  93.         if (!slew_obj || slew_obj->control_type!=CT_SLEW) return 0;
  94.  
  95.         if (check_keys) {
  96. #if 0   //def EDITOR    // might be useful for people with playing keys set to modifiers or such,
  97.                 if (EditorWindow)       // or just use a separate player file for the editor
  98.                 {
  99.                         obj->mtype.phys_info.velocity.x += SLIDE_SPEED * keyd_pressed[KEY_PAD9] * FrameTime;
  100.                         obj->mtype.phys_info.velocity.x -= SLIDE_SPEED * keyd_pressed[KEY_PAD7] * FrameTime;
  101.                         obj->mtype.phys_info.velocity.y += SLIDE_SPEED * keyd_pressed[KEY_PADMINUS] * FrameTime;
  102.                         obj->mtype.phys_info.velocity.y -= SLIDE_SPEED * keyd_pressed[KEY_PADPLUS] * FrameTime;
  103.                         obj->mtype.phys_info.velocity.z += ZOOM_SPEED_FACTOR * keyd_pressed[KEY_PAD8] * FrameTime;
  104.                         obj->mtype.phys_info.velocity.z -= ZOOM_SPEED_FACTOR * keyd_pressed[KEY_PAD2] * FrameTime;
  105.  
  106.                         rotang.p = rotang.b  = rotang.h  = 0;
  107.                         rotang.p += keyd_pressed[KEY_LBRACKET] * FrameTime / ROT_SPEED;
  108.                         rotang.p -= keyd_pressed[KEY_RBRACKET] * FrameTime / ROT_SPEED;
  109.                         rotang.b  += keyd_pressed[KEY_PAD1] * FrameTime / ROT_SPEED;
  110.                         rotang.b  -= keyd_pressed[KEY_PAD3] * FrameTime / ROT_SPEED;
  111.                         rotang.h  += keyd_pressed[KEY_PAD6] * FrameTime / ROT_SPEED;
  112.                         rotang.h  -= keyd_pressed[KEY_PAD4] * FrameTime / ROT_SPEED;
  113.                 }
  114.                 else
  115. #endif
  116.                 {
  117.                         obj->mtype.phys_info.velocity.x = SLIDE_SPEED * Controls.sideways_thrust_time;
  118.                         obj->mtype.phys_info.velocity.y = SLIDE_SPEED * Controls.vertical_thrust_time;
  119.                         obj->mtype.phys_info.velocity.z = ZOOM_SPEED_FACTOR * Controls.forward_thrust_time;
  120.  
  121.                         rotang.p = Controls.pitch_time/ROT_SPEED ;
  122.                         rotang.b  = Controls.bank_time/ROT_SPEED;
  123.                         rotang.h  = Controls.heading_time/ROT_SPEED;
  124.                 }
  125.         }
  126.         else
  127.                 rotang.p = rotang.b  = rotang.h  = 0;
  128.  
  129.         moved = rotang.p | rotang.b | rotang.h;
  130.  
  131.         const auto &&rotmat = vm_angles_2_matrix(rotang);
  132.         const auto new_pm = vm_transposed_matrix(obj->orient = vm_matrix_x_matrix(obj->orient,rotmat));         //make those columns rows
  133.  
  134.         moved |= obj->mtype.phys_info.velocity.x | obj->mtype.phys_info.velocity.y | obj->mtype.phys_info.velocity.z;
  135.  
  136.         svel = obj->mtype.phys_info.velocity;
  137.         vm_vec_scale(svel,FrameTime);           //movement in this frame
  138.         const auto movement = vm_vec_rotate(svel,new_pm);
  139.  
  140.         vm_vec_add2(obj->pos,movement);
  141.  
  142.         moved |= (movement.x || movement.y || movement.z);
  143.  
  144.         if (moved)
  145.                 update_object_seg(vmobjptr, LevelSharedSegmentState, LevelUniqueSegmentState, obj);     //update segment id
  146.  
  147.         return moved;
  148. }
  149.  
  150. //do slew for this frame
  151. int slew_frame(int check_keys)
  152. {
  153.         auto &Objects = LevelUniqueObjectState.Objects;
  154.         auto &vmobjptridx = Objects.vmptridx;
  155.         return do_slew_movement(vmobjptridx(slew_obj), !check_keys);
  156. }
  157.  
  158.