This repository has been archived by the owner on Jun 16, 2019. It is now read-only.
/
camera.cpp
297 lines (239 loc) · 7.92 KB
/
camera.cpp
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*
Copyright (C) 1999-2007 id Software, Inc. and contributors.
For a list of contributors, see the accompanying CONTRIBUTORS file.
This file is part of GtkRadiant.
GtkRadiant is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GtkRadiant is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GtkRadiant; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
Camera plugin for GtkRadiant
Copyright (C) 2002 Splash Damage Ltd.
*/
#include "camera.h"
// Render view
CRenderer *Renderer = NULL;
// Interaction
CListener *Listener = NULL;
// plugin name
static const char *PLUGIN_NAME = "Camera";
// commands in the menu
static const char *PLUGIN_COMMANDS = "About...,-,Load Camera...,-,Preview Camera,-,Camera Inspector...,-,New Spline Camera,New Interpolated Camera,New Fixed Camera";
// globals
GtkWidget *g_pRadiantWnd = NULL;
GtkWidget *g_pCameraInspectorWnd = NULL;
CCamera *firstCam = NULL; // double linked list
CCamera *firstFreeCam = NULL; // single linked list
CCamera *currentCam = NULL; // single item
bool g_bEditOn = false;
int g_iEditMode = 0; // 0: editting points 1: adding points
int g_iActiveTarget = -1;
int g_iPreviewRunning = 0; // 0: no preview 1: start preview 2: preview in progress
static const char *PLUGIN_ABOUT = "Camera v1.0 for GtkRadiant\n"
"by Arnout van Meer (rr2do2@splashdamage.com)\n\n"
"This product contains software technology\n"
"from id Software, Inc. ('id Technology').\n"
"id Technology (c) 2001, 2002 id Software, Inc.";
#include "iplugin.h"
const char* QERPlug_Init(void* hApp, void* pMainWidget)
{
g_pRadiantWnd = (GtkWidget*)pMainWidget;
// initialize cams
for( int i = 0; i < MAX_CAMERAS; i++ ) {
if( i == 0 ) {
firstFreeCam = new CCamera( i );
firstCam = firstFreeCam;
} else {
firstCam->SetNext( new CCamera( i ) );
firstCam = firstCam->GetNext();
}
}
firstCam = NULL;
if( !Renderer )
{
Renderer = new CRenderer;
}
if( g_pCameraInspectorWnd == NULL )
g_pCameraInspectorWnd = CreateCameraInspectorDialog();
InitIglToQgl(&g_QglTable);
GetFileTypeRegistry()->addType("camera", filetype_t("Camera file", "*.camera"));
return "Camera for GtkRadiant";
}
const char* QERPlug_GetName()
{
return PLUGIN_NAME;
}
const char* QERPlug_GetCommandList()
{
return PLUGIN_COMMANDS;
}
void QERPlug_Dispatch (const char* p, float* vMin, float* vMax, bool bSingleBrush)
{
if( !strcmp( p, "New Fixed Camera" ) )
DoNewFixedCamera();
else if( !strcmp( p, "New Interpolated Camera" ) )
DoNewInterpolatedCamera();
else if( !strcmp( p, "New Spline Camera" ) )
DoNewSplineCamera();
else if( !strcmp( p, "Camera Inspector..." ) )
DoCameraInspector();
else if( !strcmp( p, "Preview Camera" ) )
DoPreviewCamera();
else if( !strcmp( p, "Load Camera..." ) )
DoLoadCamera();
else if( !strcmp( p, "About..." ) )
g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, PLUGIN_ABOUT, "About", MB_OK, NULL );
}
// toolbar
#include "itoolbar.h"
unsigned int ToolbarButtonCount()
{
return 1;
}
class CameraInspectorButton : public IToolbarButton
{
public:
virtual const char* getImage() const
{
return "camera_insp.bmp";
}
virtual const char* getText() const
{
return "Inspector";
}
virtual const char* getTooltip() const
{
return "Camera Inspector";
}
virtual void activate() const
{
DoCameraInspector();
}
virtual EType getType() const
{
return eButton;
}
};
CameraInspectorButton g_camerainspectorbutton;
const IToolbarButton* GetToolbarButton(unsigned int index)
{
return &g_camerainspectorbutton;
}
_QERFuncTable_1 g_FuncTable;
_QERQglTable g_QglTable;
_QERUITable g_UITable;
_QERCameraTable g_CameraTable;
// =============================================================================
// SYNAPSE
#include "synapse.h"
class CameraSynapseClient : public CSynapseClient
{
public:
// CSynapseClient API
bool RequestAPI(APIDescriptor_t *pAPI);
const char* GetInfo();
CameraSynapseClient() { }
virtual ~CameraSynapseClient() { }
};
CSynapseServer* g_pSynapseServer = NULL;
CameraSynapseClient g_SynapseClient;
#if __GNUC__ >= 4
#pragma GCC visibility push(default)
#endif
extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
#if __GNUC__ >= 4
#pragma GCC visibility pop
#endif
if (strcmp(version, SYNAPSE_VERSION))
{
Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
return NULL;
}
g_pSynapseServer = pServer;
g_pSynapseServer->IncRef();
Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
g_SynapseClient.AddAPI(TOOLBAR_MAJOR, "camera", sizeof(_QERPlugToolbarTable));
g_SynapseClient.AddAPI(PLUGIN_MAJOR, "camera", sizeof(_QERPluginTable));
g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(_QERFuncTable_1), SYN_REQUIRE, &g_FuncTable);
g_SynapseClient.AddAPI(UI_MAJOR, NULL, sizeof(_QERUITable), SYN_REQUIRE, &g_UITable);
g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(_QERQglTable), SYN_REQUIRE, &g_QglTable);
g_SynapseClient.AddAPI(CAMERA_MAJOR, NULL, sizeof(_QERCameraTable), SYN_REQUIRE, &g_CameraTable);
return &g_SynapseClient;
}
bool CameraSynapseClient::RequestAPI(APIDescriptor_t *pAPI)
{
if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR))
{
_QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
pTable->m_pfnGetToolbarButton = &GetToolbarButton;
return true;
}
else if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))
{
_QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
pTable->m_pfnQERPlug_Init = QERPlug_Init;
pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
return true;
}
Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
return false;
}
#include "version.h"
const char* CameraSynapseClient::GetInfo()
{
return "Camera plugin v1.0 - Arnout van Meer - built " __DATE__ " " RADIANT_VERSION;
}
//
// CCamera
//
CCamera *AllocCam() {
if( !firstFreeCam )
return( NULL );
CCamera *cam = firstFreeCam;
firstFreeCam = firstFreeCam->GetNext();
cam->Init();
if( firstCam ) {
cam->SetNext( firstCam );
firstCam->SetPrev( cam );
}
firstCam = cam;
return( cam );
}
void FreeCam( CCamera *cam ) {
if( cam->GetPrev() ) {
if( cam->GetNext() ) {
cam->GetPrev()->SetNext( cam->GetNext() );
cam->GetNext()->SetPrev( cam->GetPrev() );
} else {
cam->GetPrev()->SetNext( NULL );
}
} else if( cam->GetNext() ) {
cam->GetNext()->SetPrev( NULL );
firstCam = cam->GetNext();
} else {
firstCam = NULL;
}
cam->GetCam()->clear();
cam->Init();
if( firstFreeCam ) {
cam->SetNext( firstFreeCam );
}
firstFreeCam = cam;
}
void SetCurrentCam( CCamera *cam ) {
currentCam = cam;
}
CCamera *GetCurrentCam() {
return( currentCam );
}