-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcamera.c
executable file
·242 lines (206 loc) · 5.73 KB
/
camera.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*===================================================================
Include File...
===================================================================*/
#include "main.h"
#include <stdio.h>
#include "new3d.h"
#include "quat.h"
#include "compobjects.h"
#include "bgobjects.h"
#include "object.h"
#include "networking.h"
#include "mload.h"
#include "camera.h"
#include "util.h"
#define CAM_VERSION_NUMBER 1
/*===================================================================
Externals ...
===================================================================*/
/*===================================================================
Globals ...
===================================================================*/
CAMERA CurrentCamera;
CAMERA MainCamera; // the main viewing screen...
int32_t NumOfCams = 0;
REMOTECAMERA * ActiveRemoteCamera = NULL;
REMOTECAMERA * RemoteCameras = NULL;
/*===================================================================
Procedure : Load .Cam File
Input : char * Filename
Output : Nothing
===================================================================*/
bool Cameraload( char * Filename )
{
char * Buffer;
char * OrgBuffer;
int32_t * int32Pnt;
u_int32_t * u_int32Pnt;
int16_t * int16Pnt;
float * FloatPnt;
int e;
long File_Size;
long Read_Size;
REMOTECAMERA * CamPnt;
u_int32_t MagicNumber;
u_int32_t VersionNumber;
VECTOR Tempv;
ActiveRemoteCamera = NULL;
RemoteCameras = NULL;
File_Size = Get_File_Size( Filename );
if( !File_Size )
{
// Doesnt Matter.....
return true;
}
Buffer = calloc( 1, File_Size );
OrgBuffer = Buffer;
if( !Buffer )
{
Msg( "Camload failed to Allocate buffer for %s failed\n", Filename );
return false;
}
Read_Size = Read_File( Filename, Buffer, File_Size );
if( Read_Size != File_Size )
{
Msg( "Camload Error reading file %s\n", Filename );
return false;
}
u_int32Pnt = (u_int32_t *) Buffer;
MagicNumber = *u_int32Pnt++;
VersionNumber = *u_int32Pnt++;
Buffer = (char *) u_int32Pnt;
if( ( MagicNumber != MAGIC_NUMBER ) || ( VersionNumber != CAM_VERSION_NUMBER ) )
{
Msg( "CamLoad() Incompatible .CAM file %s", Filename );
return( false );
}
int32Pnt = (int32_t*) Buffer;
NumOfCams = *int32Pnt++;
RemoteCameras = (REMOTECAMERA*) calloc( NumOfCams, sizeof(REMOTECAMERA) );
CamPnt = RemoteCameras;
if( !CamPnt )
{
Msg( "Camload failed allocate Cam Pointer in %s \n", Filename );
return false;
}
Buffer = (char*) int32Pnt;
for( e = 0 ; e < NumOfCams ; e++ )
{
CamPnt->enable = false;
int16Pnt = (int16_t*) Buffer;
CamPnt->Group = *int16Pnt++;
FloatPnt = (float*) int16Pnt;
CamPnt->Pos.x = *FloatPnt++;
CamPnt->Pos.y = *FloatPnt++;
CamPnt->Pos.z = *FloatPnt++;
CamPnt->Dir.x = *FloatPnt++;
CamPnt->Dir.y = *FloatPnt++;
CamPnt->Dir.z = *FloatPnt++;
CamPnt->Up.x = *FloatPnt++;
CamPnt->Up.y = *FloatPnt++;
CamPnt->Up.z = *FloatPnt++;
Buffer = (char*) FloatPnt;
Tempv.x = CamPnt->Pos.x + CamPnt->Dir.x;
Tempv.y = CamPnt->Pos.y + CamPnt->Dir.y;
Tempv.z = CamPnt->Pos.z + CamPnt->Dir.z;
MakeViewMatrix( &CamPnt->Pos, &Tempv, &CamPnt->Up, &CamPnt->Mat);
MatrixTranspose( &CamPnt->Mat, &CamPnt->InvMat );
CamPnt++;
}
// All Cameras Networks have been loaded...
free(OrgBuffer);
return true;
}
/*===================================================================
Procedure : Release NodeHeader..
Input : NOTHING
Output : Nothing
===================================================================*/
void CameraRelease( void)
{
if( RemoteCameras )
{
free( RemoteCameras );
ActiveRemoteCamera = NULL;
RemoteCameras = NULL;
}
NumOfCams = 0;
}
/*===================================================================
Procedure : Enable Remote Camera
Input : u_int16_t * Data
Output : Nothing
===================================================================*/
void EnableRemoteCamera( u_int16_t * Data )
{
REMOTECAMERA * CamPnt;
CamPnt = RemoteCameras;
if( !CamPnt )
return;
CamPnt += *Data;
CamPnt->enable = true;
ActiveRemoteCamera = CamPnt;
}
/*===================================================================
Procedure : Disable Remote Camera
Input : u_int16_t * Data
Output : Nothing
===================================================================*/
void DisableRemoteCamera( u_int16_t * Data )
{
REMOTECAMERA * CamPnt;
CamPnt = RemoteCameras;
if( !CamPnt )
return;
CamPnt += *Data;
CamPnt->enable = false;
if( ActiveRemoteCamera == CamPnt )
ActiveRemoteCamera = NULL;
}
/*===================================================================
Procedure : Save RemoteCameras arrays & Connected Global Variables
Input : FILE * File Pointer
Output : FILE * Updated File Pointer
===================================================================*/
FILE * SaveRemoteCameras( FILE * fp )
{
u_int16_t TempIndex;
if( fp )
{
if( ActiveRemoteCamera ) TempIndex = (u_int16_t) ( ActiveRemoteCamera - RemoteCameras );
else TempIndex = (u_int16_t) -1;
fwrite( &TempIndex, sizeof( u_int16_t ), 1, fp );
}
return( fp );
}
/*===================================================================
Procedure : Load RemoteCameras Arrays & Connected Global Variables
Input : FILE * File Pointer
Output : FILE * Updated File Pointer
===================================================================*/
FILE * LoadRemoteCameras( FILE * fp )
{
u_int16_t i;
u_int16_t TempIndex;
REMOTECAMERA * CamPnt;
CamPnt = RemoteCameras;
for( i = 0; i < NumOfCams ; i++ )
{
CamPnt->enable = false;
CamPnt++;
}
if( fp )
{
fread( &TempIndex, sizeof( u_int16_t ), 1, fp );
if( TempIndex != (u_int16_t) -1 )
{
ActiveRemoteCamera = ( RemoteCameras + TempIndex );
ActiveRemoteCamera->enable = true;
}
else
{
ActiveRemoteCamera = NULL;
}
}
return( fp );
}