FS2_Open
Open source remastering of the Freespace 2 engine
observer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #include "globalincs/systemvars.h"
13 #include "object/object.h"
14 #include "observer/observer.h"
15 #include "playerman/player.h"
16 
17 
18 
19 
21 
23 {
24  int idx;
25  for(idx=0;idx<MAX_OBSERVER_OBS;idx++){
26  Observers[idx].flags = 0;
27  Observers[idx].objnum = -1;
28  Observers[idx].target_objnum = -1;
29  }
30 }
31 
33 {
34  int objnum,idx;
35  physics_info *pi;
36 
37  // try and find the first free observer slot
38  for(idx=0;idx<MAX_OBSERVER_OBS;idx++){
39  if(!(Observers[idx].flags & OBS_FLAG_USED))
40  break;
41  }
42  // if we couldn't find an open slot
43  if(idx == MAX_OBSERVER_OBS){
44  mprintf(("Ran out of observer slots!\n"));
45  return -1;
46  }
47 
48  // attempt to create the object
49  objnum = obj_create(OBJ_OBSERVER,-1,idx,orient,pos,1.0f,0);
50 
51  // fail situation
52  if(objnum == -1)
53  return -1;
54 
55  // give the observer Descent style physics
56  Objects[objnum].flags |= OF_PHYSICS;
57  physics_init(&Objects[objnum].phys_info);
58  pi = &Objects[objnum].phys_info;
60 
61 
62  // setup some physics parameters
63  pi->max_vel.xyz.x = OBS_MAX_VEL_X;
64  pi->max_vel.xyz.y = OBS_MAX_VEL_Y;
65  pi->max_vel.xyz.z = OBS_MAX_VEL_Z;
69  vm_vec_zero(&pi->vel);
70  vm_vec_zero(&pi->rotvel);
71  vm_vec_zero(&pi->prev_fvec);
73  pi->forward_thrust = 0.0f;
74  pi->speed = 0.0f;
75  pi->fspeed = 0.0f;
76  pi->heading = 0.0f;
77 
78  // set up the observer data
79  Observers[idx].flags |= OBS_FLAG_USED;
80  Observers[idx].objnum = objnum;
81  Observers[idx].target_objnum = -1;
82 
83  return objnum;
84 }
85 
86 void observer_delete(object *obj)
87 {
88  int num;
89 
90  num = obj->instance;
91  Assert( Observers[num].objnum == OBJ_INDEX(obj));
92 
93  Observers[num].objnum = -1;
94  Observers[num].target_objnum = -1;
95  Observers[num].flags = 0; // mark it as being free
96 }
97 
98 // get the eye position and orientation for the passed observer object
100 {
101  // copy in the observer position and orientation
102  memcpy(eye_pos,&obj->pos,sizeof(vec3d));
103  memcpy(eye_orient,&obj->orient,sizeof(matrix));
104 }
void observer_get_eye(vec3d *eye_pos, matrix *eye_orient, object *obj)
Definition: observer.cpp:99
int observer_create(matrix *orient, vec3d *pos)
Definition: observer.cpp:32
observer Observers[MAX_OBSERVER_OBS]
Definition: observer.cpp:20
vec3d rotvel
Definition: physics.h:78
vec3d desired_vel
Definition: physics.h:70
physics_info phys_info
Definition: object.h:157
Assert(pm!=NULL)
Definition: pstypes.h:88
#define mprintf(args)
Definition: pstypes.h:238
#define OBS_FLAG_USED
Definition: observer.h:24
struct vec3d::@225::@227 xyz
vec3d max_vel
Definition: physics.h:49
GLclampf f
Definition: Glext.h:7097
#define OBS_MAX_VEL_Z
Definition: observer.h:21
hull_check orient
Definition: lua.cpp:5049
#define OBJ_OBSERVER
Definition: object.h:43
vec3d pos
Definition: object.h:152
void observer_init()
Definition: observer.cpp:22
int target_objnum
Definition: observer.h:29
int instance
Definition: object.h:150
vec3d desired_rotvel
Definition: physics.h:71
int obj_create(ubyte type, int parent_obj, int instance, matrix *orient, vec3d *pos, float radius, uint flags)
Definition: object.cpp:467
float speed
Definition: physics.h:79
#define PF_ACCELERATES
Definition: physics.h:18
int objnum
Definition: observer.h:27
void vm_set_identity(matrix *m)
Definition: vecmat.cpp:150
void physics_init(physics_info *pi)
Definition: physics.cpp:49
matrix eye_orient
Definition: fredrender.cpp:112
int flags
Definition: observer.h:30
vec3d eye_pos
Definition: fredrender.cpp:103
int idx
Definition: multiui.cpp:761
#define OBS_MAX_VEL_Y
Definition: observer.h:20
object Objects[MAX_OBJECTS]
Definition: object.cpp:62
#define vm_vec_zero(v)
Definition: vecmat.h:37
uint flags
Definition: physics.h:37
#define OBJ_INDEX(objp)
Definition: object.h:235
matrix orient
Definition: object.h:153
vec3d prev_fvec
Definition: physics.h:82
#define MAX_OBSERVER_OBS
Definition: observer.h:33
GLbitfield flags
Definition: Glext.h:6722
vec3d vel
Definition: physics.h:77
float fspeed
Definition: physics.h:80
GLuint GLuint num
Definition: Glext.h:9089
matrix last_rotmat
Definition: physics.h:83
#define OF_PHYSICS
Definition: object.h:105
#define PF_SLIDE_ENABLED
Definition: physics.h:21
#define OBS_MAX_VEL_X
Definition: observer.h:19
hull_check pos
Definition: lua.cpp:5050
GLsizei GLsizei GLuint * obj
Definition: Glext.h:5619
vec3d prev_ramp_vel
Definition: physics.h:69
uint flags
Definition: object.h:151
void observer_delete(object *obj)
Definition: observer.cpp:86
float heading
Definition: physics.h:81
float forward_thrust
Definition: physics.h:72