g_camera.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // leave this line at the top for all g_xxxx.cpp files...
  2. #include "g_headers.h"
  3. //g_camera.cpp
  4. #include "g_local.h"
  5. //#include "Q3_Interface.h"
  6. //#include "anims.h"
  7. //#include "b_local.h"
  8. #include "..\cgame\cg_camera.h"
  9. #include "g_functions.h"
  10. /*
  11. #define MAX_CAMERA_GROUP_SUBJECTS 16
  12. void misc_camera_focus_think (gentity_t *self)
  13. {
  14. //Check to see if I should stop?
  15. gi.linkentity(self);
  16. self->nextthink = level.time + FRAMETIME;
  17. }
  18. void misc_camera_focus_use (gentity_t *self, gentity_t *other, gentity_t *activator)
  19. {
  20. G_ActivateBehavior(self,BSET_USE);
  21. //First, find everyone in my cameraGroup, if I have one
  22. //Now find my first path_corner, if I have one
  23. //Start thinking
  24. self->e_ThinkFunc = thinkF_misc_camera_focus_think;
  25. misc_camera_focus_think(self);
  26. self->e_clThinkFunc = clThinkF_CG_MiscCameraFocusThink; // blurgh!...
  27. self->s.eType = ET_THINKER;
  28. self->aimDebounceTime = level.time;
  29. }
  30. */
  31. /*QUAK-ED misc_camera_focus (0 0 1) (-4 -4 -4) (4 4 4) lerptostart
  32. LERPTOSTART - With interpolate from camera's current angles to this thing's start angle instead of snapping to it, which is the default behavior
  33. The focal point for a camera in a scene
  34. "targetname" - Use it to get it to find it's cameraGroup and start tracking it, also get started on it's path, if any
  35. "cameraGroup" - will find all ents in this group and pick a point in the center of that group.
  36. "speed" angular speed modifier - 100 is normal
  37. */
  38. void SP_misc_camera_focus (gentity_t *self)
  39. {
  40. if(!self->targetname)
  41. {
  42. gi.Printf(S_COLOR_RED"ERROR: misc_camera_focus with no targetname\n");
  43. G_FreeEntity(self);
  44. return;
  45. }
  46. /*
  47. if(self->speed > 0)
  48. {
  49. self->moveInfo.aspeed = self->speed;
  50. }
  51. else
  52. {
  53. self->moveInfo.aspeed = 100.f;
  54. }
  55. */
  56. self->speed = 0;
  57. self->script_targetname = G_NewString(self->targetname);
  58. // self->e_UseFunc = useF_misc_camera_focus_use;
  59. }
  60. /*
  61. void misc_camera_track_think (gentity_t *self)
  62. {
  63. vec3_t vec;
  64. float dist;
  65. //Check to see if I should stop?
  66. gi.linkentity(self);
  67. if(self->enemy)
  68. {//We're already heading to a path_corner
  69. VectorSubtract(self->currentOrigin, self->s.origin2, vec);
  70. dist = VectorLengthSquared(vec);
  71. if(dist < 256)//16 squared
  72. {
  73. G_UseTargets(self, self);
  74. self->target = self->enemy->target;
  75. self->enemy = NULL;
  76. }
  77. }
  78. if( !self->enemy)
  79. {
  80. if( self->target && self->target[0] )
  81. {//Find out next path_corner
  82. self->enemy = G_Find(NULL, FOFS(targetname), self->target);
  83. if(self->enemy)
  84. {
  85. if(self->enemy->radius < 0)
  86. {//Don't bother trying to maintain a radius
  87. self->radius = 0;
  88. self->moveInfo.speed = self->speed/10.0f;
  89. }
  90. else if(self->enemy->radius > 0)
  91. {
  92. self->radius = self->enemy->radius;
  93. }
  94. if(self->enemy->speed < 0)
  95. {//go back to our default speed
  96. self->moveInfo.speed = self->speed/10.0f;
  97. }
  98. else if(self->enemy->speed > 0)
  99. {
  100. self->moveInfo.speed = self->enemy->speed/10.0f;
  101. }
  102. }
  103. }
  104. else
  105. {//stop thinking if this is the last one
  106. self->e_ThinkFunc = thinkF_NULL;
  107. self->e_clThinkFunc = clThinkF_NULL;
  108. self->s.eType = ET_GENERAL;
  109. self->nextthink = -1;
  110. }
  111. }
  112. if(self->enemy)
  113. {//clThink will lerp this
  114. VectorCopy(self->enemy->currentOrigin, self->s.origin2);
  115. }
  116. self->nextthink = level.time + FRAMETIME;
  117. }
  118. void misc_camera_track_use (gentity_t *self, gentity_t *other, gentity_t *activator)
  119. {
  120. G_ActivateBehavior(self,BSET_USE);
  121. //Start thinking
  122. self->e_ThinkFunc = thinkF_misc_camera_track_think;
  123. misc_camera_track_think(self);
  124. self->e_clThinkFunc = clThinkF_CG_MiscCameraTrackThink;
  125. self->s.eType = ET_THINKER;
  126. }
  127. */
  128. /*QUAK-ED misc_camera_track (0 0 1) (-4 -4 -4) (4 4 4)
  129. The track for a camera to stay on
  130. "targetname" - Use it to get it started on it's path
  131. "target" - First point on it's path - if misc_camera_focus is on a path, it will pick the point on it's path closest to the above calced point
  132. use "path_corner"s - path it should stay on- if that path_corner has a speed value, it will use this as it's speed to the next path_corner
  133. "speed" - How quickly to move, 0 by default
  134. "radius" - How far camera should try to stay from it's subject, default is 0 (dist doesn't matter), can pick this up from a path_corner too
  135. */
  136. void SP_misc_camera_track (gentity_t *self)
  137. {
  138. if(!self->targetname || !self->targetname[0])
  139. {
  140. gi.Printf(S_COLOR_RED"ERROR: misc_camera_track with no targetname\n");
  141. G_FreeEntity(self);
  142. return;
  143. }
  144. self->script_targetname = G_NewString(self->targetname);
  145. //self->moveInfo.speed = self->speed/10;
  146. // self->e_UseFunc = useF_misc_camera_track_use;
  147. }
  148. //-------------------------------------------------
  149. // Bezier camera stuff
  150. //-------------------------------------------------
  151. void cam_point_link( gentity_t *ent )
  152. {
  153. }
  154. void cam_ctrl_point_link( gentity_t *ent )
  155. {
  156. /* gentity_t *target2 = NULL;
  157. target2 = G_Find( NULL, FOFS(targetname), ent->target2 );
  158. if ( !target2 )
  159. {
  160. // Bah, you fool! Target2 not found
  161. Com_Printf( "cam_point_link: target2 specified but not found: %s\n", ent->target2 );
  162. G_FreeEntity( ent );
  163. return;
  164. }
  165. // Store the control point here
  166. VectorCopy( target2->s.origin, ent->pos1 );
  167. //---------------------
  168. if ( ent->target )
  169. {
  170. gentity_t *target = NULL;
  171. target = G_Find( NULL, FOFS(targetname), ent->target );
  172. if ( !target )
  173. {
  174. // Bah, you fool! Target not found
  175. Com_Printf( "cam_point_link: target specified but not found: %s\n", ent->target );
  176. G_FreeEntity( ent );
  177. return;
  178. }
  179. ent->nextTrain = target;
  180. }
  181. */
  182. }
  183. /*QUAK-ED cam_point (0.25 0 0.5) (-2 -2 -2) (2 2 2)
  184. Under development -- DONT USE ME!!!!!
  185. A camera point used to construct a camera bezier path
  186. Every cam_point MUST be targeted (target2) at one and only one control point
  187. */
  188. void SP_cam_point( gentity_t *ent )
  189. {
  190. /* if ( !ent->target2 )
  191. {
  192. // Bah, you fool! Target2 not found so we have no idea how to make the curve
  193. Com_Printf( "cam_point_link: target2 was required but not found\n" );
  194. G_FreeEntity( ent );
  195. return;
  196. }
  197. // The thing we are targeting may not be spawned in yet so, wait a bit to try and link to it
  198. ent->e_ThinkFunc = thinkF_cam_ctrl_point_link;
  199. ent->nextthink = level.time + 200;
  200. // Save our position and link us up!
  201. G_SetOrigin( ent, ent->s.origin );
  202. gi.linkentity( ent );
  203. */
  204. }