2 * $Logfile: /Freespace2/code/Observer/Observer.cpp $
13 #include "systemvars.h"
16 observer Observers[MAX_OBSERVER_OBS];
23 for(idx=0;idx<MAX_OBSERVER_OBS;idx++){
24 Observers[idx].flags = 0;
25 Observers[idx].objnum = -1;
26 Observers[idx].target_objnum = -1;
32 int observer_create(matrix *orient, vector *pos)
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))
42 // if we couldn't find an open slot
43 if(idx == MAX_OBSERVER_OBS){
44 mprintf(("Ran out of observer slots!\n"));
48 // attempt to create the object
49 objnum = obj_create(OBJ_OBSERVER,0,idx,orient,pos,1.0f,0);
51 // give the observer Descent style physics
52 Objects[objnum].flags |= OF_PHYSICS;
53 physics_init(&Objects[objnum].phys_info);
54 pi = &Objects[objnum].phys_info;
55 pi->flags |= PF_ACCELERATES | PF_SLIDE_ENABLED;
58 // setup some physics parameters
59 pi->max_vel.x = OBS_MAX_VEL_X;
60 pi->max_vel.y = OBS_MAX_VEL_Y;
61 pi->max_vel.z = OBS_MAX_VEL_Z;
62 vm_vec_zero(&pi->prev_ramp_vel);
63 vm_vec_zero(&pi->desired_vel);
64 vm_vec_zero(&pi->desired_rotvel);
65 vm_vec_zero(&pi->vel);
66 vm_vec_zero(&pi->rotvel);
67 vm_vec_zero(&pi->prev_fvec);
68 memset(&pi->last_rotmat,0,sizeof(matrix));
69 pi->forward_thrust = 0.0f;
78 // set up the observer data
79 Observers[idx].flags |= OBS_FLAG_USED;
80 Observers[idx].objnum = objnum;
81 Observers[idx].target_objnum = -1;
86 void observer_delete(object *obj)
91 Assert( Observers[num].objnum == OBJ_INDEX(obj));
93 Observers[num].objnum = -1;
94 Observers[num].target_objnum = -1;
95 Observers[num].flags = 0; // mark it as being free
98 // get the eye position and orientation for the passed observer object
99 void observer_get_eye(vector *eye_pos, matrix *eye_orient, object *obj)
101 // copy in the observer position and orientation
102 memcpy(eye_pos,&obj->pos,sizeof(vector));
103 memcpy(eye_orient,&obj->orient,sizeof(matrix));
105 // if we're in a weird padlock view
106 if ( Viewer_mode & VM_PADLOCK_ANY ){
107 player_get_padlock_orient(eye_orient);