UFO: Alien Invasion
Loading...
Searching...
No Matches
g_camera.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, 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
30static 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
41static 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
50void 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;
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}
Definition aabb.h:42
void set(const AABB &other)
Copies the values from the given aabb.
Definition aabb.h:60
int flags
Definition g_edict.h:169
camera_edict_data_t camera
Definition g_edict.h:134
const char * classname
Definition g_edict.h:67
vec3_t origin
Definition g_edict.h:53
const char * particle
Definition g_edict.h:128
pos3_t pos
Definition g_edict.h:55
actorSizeEnum_t fieldSize
Definition g_edict.h:141
byte dir
Definition g_edict.h:86
bool(* use)(Edict *self, Edict *activator)
Definition g_edict.h:154
AABB entBox
Definition g_edict.h:60
bool(* destroy)(Edict *self)
Definition g_edict.h:155
int spawnflags
Definition g_edict.h:118
solid_t solid
Definition g_edict.h:58
entity_type_t type
Definition g_edict.h:81
void toggleActive()
Definition g_edict.h:201
edictMaterial_t material
Definition g_edict.h:133
const char * model
Definition g_edict.h:74
#define ACTOR_SIZE_NORMAL
Definition defines.h:302
static bool Destroy_Camera(Edict *self)
Definition g_camera.cpp:41
static bool G_CameraUse(Edict *self, Edict *activator)
Definition g_camera.cpp:30
void G_InitCamera(Edict *ent, camera_type_t cameraType, float angle, bool rotate)
Definition g_camera.cpp:50
#define CAMERAMODEL(X, IDX)
Definition g_camera.cpp:48
Local definitions for game module.
#define G_IsActor(ent)
Definition g_local.h:127
game_import_t gi
Definition g_main.cpp:39
@ MAT_ELECTRICAL
Definition g_local.h:270
#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:289
Edict * G_SpawnParticle(const vec3_t origin, int spawnflags, const char *particle)
Definition g_spawn.cpp:551
Brings new objects into the world.
void G_FreeEdict(Edict *ent)
Marks the edict as free.
Definition g_utils.cpp:41
Misc utility functions for game module.
@ SOLID_BBOX
Definition game.h:156
int AngleToDir(int angle)
Returns the index of array directionAngles[DIRECTIONS] whose value is the closest to angle.
Definition mathlib.cpp:130
#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
camera_type_t
Definition q_shared.h:178
@ CAMERA_STATIONARY
Definition q_shared.h:180
@ CAMERA_MOBILE
Definition q_shared.h:179
@ ET_CAMERA
Definition q_shared.h:171
camera_type_t cameraType
Definition g_local.h:317