UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
g_camera.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23 */
24 
25 #include "g_local.h"
26 #include "g_spawn.h"
27 #include "g_utils.h"
28 #include "g_vis.h"
29 
30 static bool G_CameraUse (Edict* self, Edict* activator)
31 {
32  if (!activator || !G_IsActor(activator)) {
33  return false;
34  }
35 
36  self->toggleActive();
37 
38  return false;
39 }
40 
41 static bool Destroy_Camera (Edict* self)
42 {
43  G_SpawnParticle(self->origin, self->spawnflags, self->particle);
44  G_FreeEdict(self);
45  return true;
46 }
47 
48 #define CAMERAMODEL(X, IDX) case X: ent->model = "models/objects/cameras/camera" STRINGIFY(IDX); break
49 
50 void G_InitCamera (Edict* ent, camera_type_t cameraType, float angle, bool rotate)
51 {
52  switch (cameraType) {
55  default:
56  gi.DPrintf("unknown camera type given: %i\n", cameraType);
57  G_FreeEdict(ent);
58  return;
59  }
60 
61  AABB modelAabb;
62  if (gi.LoadModelAABB(ent->model, 0, modelAabb)) {
63  ent->entBox.set(modelAabb);
64 
65  ent->camera.cameraType = cameraType;
66  ent->camera.rotate = rotate;
67  ent->classname = "misc_camera";
68  ent->type = ET_CAMERA;
69  ent->solid = SOLID_BBOX;
70  ent->flags |= FL_DESTROYABLE;
71  ent->material = MAT_ELECTRICAL;
73  ent->destroy = Destroy_Camera;
74  ent->use = G_CameraUse;
75  ent->dir = AngleToDir(angle);
76 
77  /* Set the position of the entity */
78  VecToPos(ent->origin, ent->pos);
79 
80  gi.LinkEdict(ent);
81  } else {
82  gi.DPrintf("Could not get bounding box for model '%s'\n", ent->model);
83  G_FreeEdict(ent);
84  }
85 }
#define CAMERAMODEL(X, IDX)
Definition: g_camera.cpp:48
solid_t solid
Definition: g_edict.h:58
Misc utility functions for game module.
Definition: aabb.h:42
bool(* use)(Edict *self, Edict *activator)
Definition: g_edict.h:154
AABB entBox
Definition: g_edict.h:60
void set(const AABB &other)
Copies the values from the given aabb.
Definition: aabb.h:60
void G_InitCamera(Edict *ent, camera_type_t cameraType, float angle, bool rotate)
Definition: g_camera.cpp:50
byte dir
Definition: g_edict.h:86
#define G_IsActor(ent)
Definition: g_local.h:127
camera_edict_data_t camera
Definition: g_edict.h:134
int AngleToDir(int angle)
Returns the index of array directionAngles[DIRECTIONS] whose value is the closest to angle...
Definition: mathlib.cpp:130
game_import_t gi
Definition: g_main.cpp:39
#define VecToPos(v, p)
Map boundary is +/- MAX_WORLD_WIDTH - to get into the positive area we add the possible max negative ...
Definition: mathlib.h:100
pos3_t pos
Definition: g_edict.h:55
static bool G_CameraUse(Edict *self, Edict *activator)
Definition: g_camera.cpp:30
Edict * G_SpawnParticle(const vec3_t origin, int spawnflags, const char *particle)
Definition: g_spawn.cpp:551
int flags
Definition: g_edict.h:169
actorSizeEnum_t fieldSize
Definition: g_edict.h:141
Local definitions for game module.
#define FL_DESTROYABLE
If an edict is destroyable (like ET_BREAKABLE, ET_DOOR [if health set] or maybe a ET_MISSION [if heal...
Definition: g_local.h:287
Brings new objects into the world.
entity_type_t type
Definition: g_edict.h:81
camera_type_t
Definition: q_shared.h:178
vec3_t origin
Definition: g_edict.h:53
edictMaterial_t material
Definition: g_edict.h:133
bool(* destroy)(Edict *self)
Definition: g_edict.h:155
const char * classname
Definition: g_edict.h:67
Definition: g_edict.h:45
#define ACTOR_SIZE_NORMAL
Definition: defines.h:302
camera_type_t cameraType
Definition: g_local.h:309
void G_FreeEdict(Edict *ent)
Marks the edict as free.
Definition: g_utils.cpp:41
const char * model
Definition: g_edict.h:74
static bool Destroy_Camera(Edict *self)
Definition: g_camera.cpp:41