2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/Observer/Observer.cpp $
21 #include "systemvars.h"
24 observer Observers[MAX_OBSERVER_OBS];
31 for(idx=0;idx<MAX_OBSERVER_OBS;idx++){
32 Observers[idx].flags = 0;
33 Observers[idx].objnum = -1;
34 Observers[idx].target_objnum = -1;
40 int observer_create(matrix *orient, vector *pos)
45 // try and find the first free observer slot
46 for(idx=0;idx<MAX_OBSERVER_OBS;idx++){
47 if(!(Observers[idx].flags & OBS_FLAG_USED))
50 // if we couldn't find an open slot
51 if(idx == MAX_OBSERVER_OBS){
52 mprintf(("Ran out of observer slots!\n"));
56 // attempt to create the object
57 objnum = obj_create(OBJ_OBSERVER,0,idx,orient,pos,1.0f,0);
59 // give the observer Descent style physics
60 Objects[objnum].flags |= OF_PHYSICS;
61 physics_init(&Objects[objnum].phys_info);
62 pi = &Objects[objnum].phys_info;
63 pi->flags |= PF_ACCELERATES | PF_SLIDE_ENABLED;
66 // setup some physics parameters
67 pi->max_vel.x = OBS_MAX_VEL_X;
68 pi->max_vel.y = OBS_MAX_VEL_Y;
69 pi->max_vel.z = OBS_MAX_VEL_Z;
70 vm_vec_zero(&pi->prev_ramp_vel);
71 vm_vec_zero(&pi->desired_vel);
72 vm_vec_zero(&pi->desired_rotvel);
73 vm_vec_zero(&pi->vel);
74 vm_vec_zero(&pi->rotvel);
75 vm_vec_zero(&pi->prev_fvec);
76 memset(&pi->last_rotmat,0,sizeof(matrix));
77 pi->forward_thrust = 0.0f;
86 // set up the observer data
87 Observers[idx].flags |= OBS_FLAG_USED;
88 Observers[idx].objnum = objnum;
89 Observers[idx].target_objnum = -1;
94 void observer_delete(object *obj)
99 Assert( Observers[num].objnum == OBJ_INDEX(obj));
101 Observers[num].objnum = -1;
102 Observers[num].target_objnum = -1;
103 Observers[num].flags = 0; // mark it as being free
106 // get the eye position and orientation for the passed observer object
107 void observer_get_eye(vector *eye_pos, matrix *eye_orient, object *obj)
109 // copy in the observer position and orientation
110 memcpy(eye_pos,&obj->pos,sizeof(vector));
111 memcpy(eye_orient,&obj->orient,sizeof(matrix));
113 // if we're in a weird padlock view
114 if ( Viewer_mode & VM_PADLOCK_ANY ){
115 player_get_padlock_orient(eye_orient);