]> icculus.org git repositories - taylor/freespace2.git/blob - src/observer/observer.cpp
clean up and simplify effects and updating
[taylor/freespace2.git] / src / observer / observer.cpp
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Observer/Observer.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * $NoKeywords: $
16  */
17
18 #include "observer.h"
19 #include "object.h"
20 #include "vecmat.h"
21 #include "systemvars.h"
22 #include "player.h"
23
24 observer Observers[MAX_OBSERVER_OBS];
25
26 int Num_observer_obs;
27
28 void observer_init()
29 {
30         int idx;
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;
35         }
36
37         Num_observer_obs = 0;
38 }
39
40 int observer_create(matrix *orient, vector *pos)
41 {
42         int objnum,idx; 
43         physics_info *pi;
44
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))
48                         break;
49         }
50         // if we couldn't find an open slot
51         if(idx == MAX_OBSERVER_OBS){
52                 mprintf(("Ran out of observer slots!\n"));
53                 return -1;
54         }
55         
56         // attempt to create the object
57         objnum = obj_create(OBJ_OBSERVER,0,idx,orient,pos,1.0f,0);
58
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;
64         
65         
66         // setup some physics parameters
67         pi->max_vel.xyz.x = OBS_MAX_VEL_X;
68         pi->max_vel.xyz.y = OBS_MAX_VEL_Y;
69         pi->max_vel.xyz.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;
78         pi->speed = 0.0f;
79         pi->fspeed = 0.0f;
80         pi->heading = 0.0f;
81                 
82         // fail situation
83         if(objnum == -1)
84                 return -1;
85
86         // set up the observer data
87         Observers[idx].flags |= OBS_FLAG_USED;
88         Observers[idx].objnum = objnum;
89         Observers[idx].target_objnum = -1;
90
91         return objnum;
92 }
93
94 void observer_delete(object *obj)
95 {
96         int num;
97         
98         num = obj->instance;
99         SDL_assert( Observers[num].objnum == OBJ_INDEX(obj));
100
101         Observers[num].objnum = -1;
102         Observers[num].target_objnum = -1;
103         Observers[num].flags = 0;           // mark it as being free
104 }
105
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)
108 {
109         // copy in the observer position and orientation
110         memcpy(eye_pos,&obj->pos,sizeof(vector));
111         memcpy(eye_orient,&obj->orient,sizeof(matrix));
112
113         // if we're in a weird padlock view
114         if ( Viewer_mode & VM_PADLOCK_ANY ){
115                 player_get_padlock_orient(eye_orient);
116         }
117 }