| 1 | /* |
| 2 | Copyright (C) 1999-2006 Id Software, Inc. and contributors. |
| 3 | For a list of contributors, see the accompanying CONTRIBUTORS file. |
| 4 | |
| 5 | This file is part of GtkRadiant. |
| 6 | |
| 7 | GtkRadiant is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | GtkRadiant is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with GtkRadiant; if not, write to the Free Software |
| 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | // |
| 23 | // Camera Window |
| 24 | // |
| 25 | // Leonardo Zide ([email protected]) |
| 26 | // |
| 27 | |
| 28 | #include "camwindow.h" |
| 29 | |
| 30 | #include <gtk/gtk.h> |
| 31 | #include <gdk/gdkkeysyms.h> |
| 32 | |
| 33 | #include "debugging/debugging.h" |
| 34 | |
| 35 | #include "iscenegraph.h" |
| 36 | #include "irender.h" |
| 37 | #include "igl.h" |
| 38 | #include "icamera.h" |
| 39 | #include "cullable.h" |
| 40 | #include "renderable.h" |
| 41 | #include "preferencesystem.h" |
| 42 | |
| 43 | #include "signal/signal.h" |
| 44 | #include "container/array.h" |
| 45 | #include "scenelib.h" |
| 46 | #include "render.h" |
| 47 | #include "cmdlib.h" |
| 48 | #include "math/frustum.h" |
| 49 | |
| 50 | #include "gtkutil/widget.h" |
| 51 | #include "gtkutil/button.h" |
| 52 | #include "gtkutil/toolbar.h" |
| 53 | #include "gtkutil/glwidget.h" |
| 54 | #include "gtkutil/xorrectangle.h" |
| 55 | #include "gtkmisc.h" |
| 56 | #include "selection.h" |
| 57 | #include "mainframe.h" |
| 58 | #include "preferences.h" |
| 59 | #include "commands.h" |
| 60 | #include "xywindow.h" |
| 61 | #include "windowobservers.h" |
| 62 | #include "renderstate.h" |
| 63 | |
| 64 | #include "timer.h" |
| 65 | |
| 66 | Signal0 g_cameraMoved_callbacks; |
| 67 | |
| 68 | void AddCameraMovedCallback( const SignalHandler& handler ){ |
| 69 | g_cameraMoved_callbacks.connectLast( handler ); |
| 70 | } |
| 71 | |
| 72 | void CameraMovedNotify(){ |
| 73 | g_cameraMoved_callbacks(); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | struct camwindow_globals_private_t |
| 78 | { |
| 79 | int m_nFOV; |
| 80 | int m_nMoveSpeed; |
| 81 | bool m_bCamLinkSpeed; |
| 82 | int m_nAngleSpeed; |
| 83 | bool m_bCamInverseMouse; |
| 84 | bool m_bCamDiscrete; |
| 85 | bool m_bCubicClipping; |
| 86 | bool m_showStats; |
| 87 | int m_nStrafeMode; |
| 88 | |
| 89 | camwindow_globals_private_t() : |
| 90 | m_nFOV( 110 ), |
| 91 | m_nMoveSpeed( 100 ), |
| 92 | m_bCamLinkSpeed( true ), |
| 93 | m_nAngleSpeed( 3 ), |
| 94 | m_bCamInverseMouse( false ), |
| 95 | m_bCamDiscrete( true ), |
| 96 | m_bCubicClipping( false ), |
| 97 | m_showStats( true ), |
| 98 | m_nStrafeMode( 3 ){ |
| 99 | } |
| 100 | |
| 101 | }; |
| 102 | |
| 103 | camwindow_globals_private_t g_camwindow_globals_private; |
| 104 | |
| 105 | |
| 106 | const Matrix4 g_opengl2radiant( |
| 107 | 0, 0,-1, 0, |
| 108 | -1, 0, 0, 0, |
| 109 | 0, 1, 0, 0, |
| 110 | 0, 0, 0, 1 |
| 111 | ); |
| 112 | |
| 113 | const Matrix4 g_radiant2opengl( |
| 114 | 0,-1, 0, 0, |
| 115 | 0, 0, 1, 0, |
| 116 | -1, 0, 0, 0, |
| 117 | 0, 0, 0, 1 |
| 118 | ); |
| 119 | |
| 120 | struct camera_t; |
| 121 | void Camera_mouseMove( camera_t& camera, int x, int y ); |
| 122 | |
| 123 | enum camera_draw_mode |
| 124 | { |
| 125 | cd_wire, |
| 126 | cd_solid, |
| 127 | cd_texture, |
| 128 | cd_lighting |
| 129 | }; |
| 130 | |
| 131 | struct camera_t |
| 132 | { |
| 133 | int width, height; |
| 134 | |
| 135 | bool timing; |
| 136 | |
| 137 | Vector3 origin; |
| 138 | Vector3 angles; |
| 139 | |
| 140 | Vector3 color; // background |
| 141 | |
| 142 | Vector3 forward, right; // move matrix (TTimo: used to have up but it was not updated) |
| 143 | Vector3 vup, vpn, vright; // view matrix (taken from the modelview matrix) |
| 144 | |
| 145 | Matrix4 projection; |
| 146 | Matrix4 modelview; |
| 147 | |
| 148 | bool m_strafe; // true when in strafemode toggled by the ctrl-key |
| 149 | bool m_strafe_forward; // true when in strafemode by ctrl-key and shift is pressed for forward strafing |
| 150 | bool m_strafe_forward_invert; //silly option to invert forward strafing to support old fegs |
| 151 | |
| 152 | unsigned int movementflags; // movement flags |
| 153 | Timer m_keycontrol_timer; |
| 154 | guint m_keymove_handler; |
| 155 | |
| 156 | |
| 157 | DeferredMotionDelta m_mouseMove; |
| 158 | |
| 159 | static void motionDelta( int x, int y, void* data ){ |
| 160 | Camera_mouseMove( *reinterpret_cast<camera_t*>( data ), x, y ); |
| 161 | } |
| 162 | |
| 163 | View* m_view; |
| 164 | Callback<void()> m_update; |
| 165 | |
| 166 | static camera_draw_mode draw_mode; |
| 167 | |
| 168 | camera_t( View* view, const Callback<void()>& update ) |
| 169 | : width( 0 ), |
| 170 | height( 0 ), |
| 171 | timing( false ), |
| 172 | origin( 0, 0, 0 ), |
| 173 | angles( 0, 0, 0 ), |
| 174 | color( 0, 0, 0 ), |
| 175 | projection( g_matrix4_identity ), |
| 176 | modelview( g_matrix4_identity ), |
| 177 | movementflags( 0 ), |
| 178 | m_keycontrol_timer(), |
| 179 | m_keymove_handler( 0 ), |
| 180 | m_mouseMove( motionDelta, this ), |
| 181 | m_view( view ), |
| 182 | m_update( update ){ |
| 183 | } |
| 184 | }; |
| 185 | |
| 186 | camera_draw_mode camera_t::draw_mode = cd_texture; |
| 187 | |
| 188 | inline Matrix4 projection_for_camera( float near_z, float far_z, float fieldOfView, int width, int height ){ |
| 189 | const float half_width = static_cast<float>( near_z * tan( degrees_to_radians( fieldOfView * 0.5 ) ) ); |
| 190 | const float half_height = half_width * ( static_cast<float>( height ) / static_cast<float>( width ) ); |
| 191 | |
| 192 | return matrix4_frustum( |
| 193 | -half_width, |
| 194 | half_width, |
| 195 | -half_height, |
| 196 | half_height, |
| 197 | near_z, |
| 198 | far_z |
| 199 | ); |
| 200 | } |
| 201 | |
| 202 | float Camera_getFarClipPlane( camera_t& camera ){ |
| 203 | return ( g_camwindow_globals_private.m_bCubicClipping ) ? pow( 2.0, ( g_camwindow_globals.m_nCubicScale + 7 ) / 2.0 ) : 32768.0f; |
| 204 | } |
| 205 | |
| 206 | void Camera_updateProjection( camera_t& camera ){ |
| 207 | float farClip = Camera_getFarClipPlane( camera ); |
| 208 | camera.projection = projection_for_camera( farClip / 4096.0f, farClip, (float)g_camwindow_globals_private.m_nFOV, camera.width, camera.height ); |
| 209 | |
| 210 | camera.m_view->Construct( camera.projection, camera.modelview, camera.width, camera.height ); |
| 211 | } |
| 212 | |
| 213 | void Camera_updateVectors( camera_t& camera ){ |
| 214 | for ( int i = 0 ; i < 3 ; i++ ) |
| 215 | { |
| 216 | camera.vright[i] = camera.modelview[( i << 2 ) + 0]; |
| 217 | camera.vup[i] = camera.modelview[( i << 2 ) + 1]; |
| 218 | camera.vpn[i] = camera.modelview[( i << 2 ) + 2]; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | void Camera_updateModelview( camera_t& camera ){ |
| 223 | camera.modelview = g_matrix4_identity; |
| 224 | |
| 225 | // roll, pitch, yaw |
| 226 | Vector3 radiant_eulerXYZ( 0, -camera.angles[CAMERA_PITCH], camera.angles[CAMERA_YAW] ); |
| 227 | |
| 228 | matrix4_translate_by_vec3( camera.modelview, camera.origin ); |
| 229 | matrix4_rotate_by_euler_xyz_degrees( camera.modelview, radiant_eulerXYZ ); |
| 230 | matrix4_multiply_by_matrix4( camera.modelview, g_radiant2opengl ); |
| 231 | matrix4_affine_invert( camera.modelview ); |
| 232 | |
| 233 | Camera_updateVectors( camera ); |
| 234 | |
| 235 | camera.m_view->Construct( camera.projection, camera.modelview, camera.width, camera.height ); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | void Camera_Move_updateAxes( camera_t& camera ){ |
| 240 | double ya = degrees_to_radians( camera.angles[CAMERA_YAW] ); |
| 241 | |
| 242 | // the movement matrix is kept 2d |
| 243 | camera.forward[0] = static_cast<float>( cos( ya ) ); |
| 244 | camera.forward[1] = static_cast<float>( sin( ya ) ); |
| 245 | camera.forward[2] = 0; |
| 246 | camera.right[0] = camera.forward[1]; |
| 247 | camera.right[1] = -camera.forward[0]; |
| 248 | } |
| 249 | |
| 250 | void Camera_Freemove_updateAxes( camera_t& camera ){ |
| 251 | camera.right = camera.vright; |
| 252 | camera.forward = vector3_negated( camera.vpn ); |
| 253 | } |
| 254 | |
| 255 | const Vector3& Camera_getOrigin( camera_t& camera ){ |
| 256 | return camera.origin; |
| 257 | } |
| 258 | |
| 259 | void Camera_setOrigin( camera_t& camera, const Vector3& origin ){ |
| 260 | camera.origin = origin; |
| 261 | Camera_updateModelview( camera ); |
| 262 | camera.m_update(); |
| 263 | CameraMovedNotify(); |
| 264 | } |
| 265 | |
| 266 | const Vector3& Camera_getAngles( camera_t& camera ){ |
| 267 | return camera.angles; |
| 268 | } |
| 269 | |
| 270 | void Camera_setAngles( camera_t& camera, const Vector3& angles ){ |
| 271 | camera.angles = angles; |
| 272 | Camera_updateModelview( camera ); |
| 273 | camera.m_update(); |
| 274 | CameraMovedNotify(); |
| 275 | } |
| 276 | |
| 277 | |
| 278 | void Camera_FreeMove( camera_t& camera, int dx, int dy ){ |
| 279 | // free strafe mode, toggled by the ctrl key with optional shift for forward movement |
| 280 | if ( camera.m_strafe ) { |
| 281 | float strafespeed = 0.65f; |
| 282 | |
| 283 | if ( g_camwindow_globals_private.m_bCamLinkSpeed ) { |
| 284 | strafespeed = (float)g_camwindow_globals_private.m_nMoveSpeed / 100; |
| 285 | } |
| 286 | |
| 287 | camera.origin -= camera.vright * strafespeed * dx; |
| 288 | if ( camera.m_strafe_forward ) { |
| 289 | camera.origin += camera.m_strafe_forward_invert ? ( camera.vpn * strafespeed * dy ) : ( -camera.vpn * strafespeed * dy ); |
| 290 | } |
| 291 | else{ |
| 292 | camera.origin += camera.vup * strafespeed * dy; |
| 293 | } |
| 294 | } |
| 295 | else // free rotation |
| 296 | { |
| 297 | const float dtime = 0.1f; |
| 298 | |
| 299 | if ( g_camwindow_globals_private.m_bCamInverseMouse ) { |
| 300 | camera.angles[CAMERA_PITCH] -= dy * dtime * g_camwindow_globals_private.m_nAngleSpeed; |
| 301 | } |
| 302 | else{ |
| 303 | camera.angles[CAMERA_PITCH] += dy * dtime * g_camwindow_globals_private.m_nAngleSpeed; |
| 304 | } |
| 305 | |
| 306 | camera.angles[CAMERA_YAW] += dx * dtime * g_camwindow_globals_private.m_nAngleSpeed; |
| 307 | |
| 308 | if ( camera.angles[CAMERA_PITCH] > 90 ) { |
| 309 | camera.angles[CAMERA_PITCH] = 90; |
| 310 | } |
| 311 | else if ( camera.angles[CAMERA_PITCH] < -90 ) { |
| 312 | camera.angles[CAMERA_PITCH] = -90; |
| 313 | } |
| 314 | |
| 315 | if ( camera.angles[CAMERA_YAW] >= 360 ) { |
| 316 | camera.angles[CAMERA_YAW] -= 360; |
| 317 | } |
| 318 | else if ( camera.angles[CAMERA_YAW] <= 0 ) { |
| 319 | camera.angles[CAMERA_YAW] += 360; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | Camera_updateModelview( camera ); |
| 324 | Camera_Freemove_updateAxes( camera ); |
| 325 | } |
| 326 | |
| 327 | void Cam_MouseControl( camera_t& camera, int x, int y ){ |
| 328 | float xf = (float)( x - camera.width / 2 ) / ( camera.width / 2 ); |
| 329 | float yf = (float)( y - camera.height / 2 ) / ( camera.height / 2 ); |
| 330 | |
| 331 | xf *= 1.0f - fabsf( yf ); |
| 332 | if ( xf < 0 ) { |
| 333 | xf += 0.1f; |
| 334 | if ( xf > 0 ) { |
| 335 | xf = 0; |
| 336 | } |
| 337 | } |
| 338 | else |
| 339 | { |
| 340 | xf -= 0.1f; |
| 341 | if ( xf < 0 ) { |
| 342 | xf = 0; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | vector3_add( camera.origin, vector3_scaled( camera.forward, yf * 0.1f * g_camwindow_globals_private.m_nMoveSpeed ) ); |
| 347 | camera.angles[CAMERA_YAW] += xf * -0.1f * g_camwindow_globals_private.m_nAngleSpeed; |
| 348 | |
| 349 | Camera_updateModelview( camera ); |
| 350 | } |
| 351 | |
| 352 | void Camera_mouseMove( camera_t& camera, int x, int y ){ |
| 353 | //globalOutputStream() << "mousemove... "; |
| 354 | Camera_FreeMove( camera, -x, -y ); |
| 355 | camera.m_update(); |
| 356 | CameraMovedNotify(); |
| 357 | } |
| 358 | |
| 359 | const unsigned int MOVE_NONE = 0; |
| 360 | const unsigned int MOVE_FORWARD = 1 << 0; |
| 361 | const unsigned int MOVE_BACK = 1 << 1; |
| 362 | const unsigned int MOVE_ROTRIGHT = 1 << 2; |
| 363 | const unsigned int MOVE_ROTLEFT = 1 << 3; |
| 364 | const unsigned int MOVE_STRAFERIGHT = 1 << 4; |
| 365 | const unsigned int MOVE_STRAFELEFT = 1 << 5; |
| 366 | const unsigned int MOVE_UP = 1 << 6; |
| 367 | const unsigned int MOVE_DOWN = 1 << 7; |
| 368 | const unsigned int MOVE_PITCHUP = 1 << 8; |
| 369 | const unsigned int MOVE_PITCHDOWN = 1 << 9; |
| 370 | const unsigned int MOVE_FOCUS = 1 << 10; |
| 371 | const unsigned int MOVE_ALL = MOVE_FORWARD | MOVE_BACK | MOVE_ROTRIGHT | MOVE_ROTLEFT | MOVE_STRAFERIGHT | MOVE_STRAFELEFT | MOVE_UP | MOVE_DOWN | MOVE_PITCHUP | MOVE_PITCHDOWN | MOVE_FOCUS; |
| 372 | |
| 373 | Vector3 Camera_getFocusPos( camera_t& camera ); |
| 374 | |
| 375 | void Cam_KeyControl( camera_t& camera, float dtime ){ |
| 376 | // Update angles |
| 377 | if ( camera.movementflags & MOVE_ROTLEFT ) { |
| 378 | camera.angles[CAMERA_YAW] += 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed; |
| 379 | } |
| 380 | if ( camera.movementflags & MOVE_ROTRIGHT ) { |
| 381 | camera.angles[CAMERA_YAW] -= 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed; |
| 382 | } |
| 383 | if ( camera.movementflags & MOVE_PITCHUP ) { |
| 384 | camera.angles[CAMERA_PITCH] += 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed; |
| 385 | if ( camera.angles[CAMERA_PITCH] > 90 ) { |
| 386 | camera.angles[CAMERA_PITCH] = 90; |
| 387 | } |
| 388 | } |
| 389 | if ( camera.movementflags & MOVE_PITCHDOWN ) { |
| 390 | camera.angles[CAMERA_PITCH] -= 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed; |
| 391 | if ( camera.angles[CAMERA_PITCH] < -90 ) { |
| 392 | camera.angles[CAMERA_PITCH] = -90; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | Camera_updateModelview( camera ); |
| 397 | Camera_Freemove_updateAxes( camera ); |
| 398 | |
| 399 | // Update position |
| 400 | if ( camera.movementflags & MOVE_FORWARD ) { |
| 401 | vector3_add( camera.origin, vector3_scaled( camera.forward, dtime * g_camwindow_globals_private.m_nMoveSpeed ) ); |
| 402 | } |
| 403 | if ( camera.movementflags & MOVE_BACK ) { |
| 404 | vector3_add( camera.origin, vector3_scaled( camera.forward, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) ); |
| 405 | } |
| 406 | if ( camera.movementflags & MOVE_STRAFELEFT ) { |
| 407 | vector3_add( camera.origin, vector3_scaled( camera.right, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) ); |
| 408 | } |
| 409 | if ( camera.movementflags & MOVE_STRAFERIGHT ) { |
| 410 | vector3_add( camera.origin, vector3_scaled( camera.right, dtime * g_camwindow_globals_private.m_nMoveSpeed ) ); |
| 411 | } |
| 412 | if ( camera.movementflags & MOVE_UP ) { |
| 413 | vector3_add( camera.origin, vector3_scaled( g_vector3_axis_z, dtime * g_camwindow_globals_private.m_nMoveSpeed ) ); |
| 414 | } |
| 415 | if ( camera.movementflags & MOVE_DOWN ) { |
| 416 | vector3_add( camera.origin, vector3_scaled( g_vector3_axis_z, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) ); |
| 417 | } |
| 418 | if ( camera.movementflags & MOVE_FOCUS ) { |
| 419 | camera.origin = Camera_getFocusPos( camera ); |
| 420 | } |
| 421 | |
| 422 | Camera_updateModelview( camera ); |
| 423 | } |
| 424 | |
| 425 | void Camera_keyMove( camera_t& camera ){ |
| 426 | camera.m_mouseMove.flush(); |
| 427 | |
| 428 | //globalOutputStream() << "keymove... "; |
| 429 | float time_seconds = camera.m_keycontrol_timer.elapsed_msec() / static_cast<float>( msec_per_sec ); |
| 430 | camera.m_keycontrol_timer.start(); |
| 431 | if ( time_seconds > 0.05f ) { |
| 432 | time_seconds = 0.05f; // 20fps |
| 433 | } |
| 434 | Cam_KeyControl( camera, time_seconds * 5.0f ); |
| 435 | |
| 436 | camera.m_update(); |
| 437 | CameraMovedNotify(); |
| 438 | } |
| 439 | |
| 440 | gboolean camera_keymove( gpointer data ){ |
| 441 | Camera_keyMove( *reinterpret_cast<camera_t*>( data ) ); |
| 442 | return TRUE; |
| 443 | } |
| 444 | |
| 445 | void Camera_setMovementFlags( camera_t& camera, unsigned int mask ){ |
| 446 | if ( ( ~camera.movementflags & mask ) != 0 && camera.movementflags == 0 ) { |
| 447 | camera.m_keymove_handler = g_idle_add( camera_keymove, &camera ); |
| 448 | } |
| 449 | camera.movementflags |= mask; |
| 450 | } |
| 451 | void Camera_clearMovementFlags( camera_t& camera, unsigned int mask ){ |
| 452 | if ( ( camera.movementflags & ~mask ) == 0 && camera.movementflags != 0 ) { |
| 453 | g_source_remove( camera.m_keymove_handler ); |
| 454 | camera.m_keymove_handler = 0; |
| 455 | } |
| 456 | camera.movementflags &= ~mask; |
| 457 | } |
| 458 | |
| 459 | void Camera_MoveForward_KeyDown( camera_t& camera ){ |
| 460 | Camera_setMovementFlags( camera, MOVE_FORWARD ); |
| 461 | } |
| 462 | void Camera_MoveForward_KeyUp( camera_t& camera ){ |
| 463 | Camera_clearMovementFlags( camera, MOVE_FORWARD ); |
| 464 | } |
| 465 | void Camera_MoveBack_KeyDown( camera_t& camera ){ |
| 466 | Camera_setMovementFlags( camera, MOVE_BACK ); |
| 467 | } |
| 468 | void Camera_MoveBack_KeyUp( camera_t& camera ){ |
| 469 | Camera_clearMovementFlags( camera, MOVE_BACK ); |
| 470 | } |
| 471 | |
| 472 | void Camera_MoveLeft_KeyDown( camera_t& camera ){ |
| 473 | Camera_setMovementFlags( camera, MOVE_STRAFELEFT ); |
| 474 | } |
| 475 | void Camera_MoveLeft_KeyUp( camera_t& camera ){ |
| 476 | Camera_clearMovementFlags( camera, MOVE_STRAFELEFT ); |
| 477 | } |
| 478 | void Camera_MoveRight_KeyDown( camera_t& camera ){ |
| 479 | Camera_setMovementFlags( camera, MOVE_STRAFERIGHT ); |
| 480 | } |
| 481 | void Camera_MoveRight_KeyUp( camera_t& camera ){ |
| 482 | Camera_clearMovementFlags( camera, MOVE_STRAFERIGHT ); |
| 483 | } |
| 484 | |
| 485 | void Camera_MoveUp_KeyDown( camera_t& camera ){ |
| 486 | Camera_setMovementFlags( camera, MOVE_UP ); |
| 487 | } |
| 488 | void Camera_MoveUp_KeyUp( camera_t& camera ){ |
| 489 | Camera_clearMovementFlags( camera, MOVE_UP ); |
| 490 | } |
| 491 | void Camera_MoveDown_KeyDown( camera_t& camera ){ |
| 492 | Camera_setMovementFlags( camera, MOVE_DOWN ); |
| 493 | } |
| 494 | void Camera_MoveDown_KeyUp( camera_t& camera ){ |
| 495 | Camera_clearMovementFlags( camera, MOVE_DOWN ); |
| 496 | } |
| 497 | |
| 498 | void Camera_RotateLeft_KeyDown( camera_t& camera ){ |
| 499 | Camera_setMovementFlags( camera, MOVE_ROTLEFT ); |
| 500 | } |
| 501 | void Camera_RotateLeft_KeyUp( camera_t& camera ){ |
| 502 | Camera_clearMovementFlags( camera, MOVE_ROTLEFT ); |
| 503 | } |
| 504 | void Camera_RotateRight_KeyDown( camera_t& camera ){ |
| 505 | Camera_setMovementFlags( camera, MOVE_ROTRIGHT ); |
| 506 | } |
| 507 | void Camera_RotateRight_KeyUp( camera_t& camera ){ |
| 508 | Camera_clearMovementFlags( camera, MOVE_ROTRIGHT ); |
| 509 | } |
| 510 | |
| 511 | void Camera_PitchUp_KeyDown( camera_t& camera ){ |
| 512 | Camera_setMovementFlags( camera, MOVE_PITCHUP ); |
| 513 | } |
| 514 | void Camera_PitchUp_KeyUp( camera_t& camera ){ |
| 515 | Camera_clearMovementFlags( camera, MOVE_PITCHUP ); |
| 516 | } |
| 517 | void Camera_PitchDown_KeyDown( camera_t& camera ){ |
| 518 | Camera_setMovementFlags( camera, MOVE_PITCHDOWN ); |
| 519 | } |
| 520 | void Camera_PitchDown_KeyUp( camera_t& camera ){ |
| 521 | Camera_clearMovementFlags( camera, MOVE_PITCHDOWN ); |
| 522 | } |
| 523 | |
| 524 | void Camera_Focus_KeyDown( camera_t& camera ){ |
| 525 | Camera_setMovementFlags( camera, MOVE_FOCUS ); |
| 526 | } |
| 527 | void Camera_Focus_KeyUp( camera_t& camera ){ |
| 528 | Camera_clearMovementFlags( camera, MOVE_FOCUS ); |
| 529 | } |
| 530 | |
| 531 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveForward_KeyDown> FreeMoveCameraMoveForwardKeyDownCaller; |
| 532 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveForward_KeyUp> FreeMoveCameraMoveForwardKeyUpCaller; |
| 533 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveBack_KeyDown> FreeMoveCameraMoveBackKeyDownCaller; |
| 534 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveBack_KeyUp> FreeMoveCameraMoveBackKeyUpCaller; |
| 535 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveLeft_KeyDown> FreeMoveCameraMoveLeftKeyDownCaller; |
| 536 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveLeft_KeyUp> FreeMoveCameraMoveLeftKeyUpCaller; |
| 537 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveRight_KeyDown> FreeMoveCameraMoveRightKeyDownCaller; |
| 538 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveRight_KeyUp> FreeMoveCameraMoveRightKeyUpCaller; |
| 539 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveUp_KeyDown> FreeMoveCameraMoveUpKeyDownCaller; |
| 540 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveUp_KeyUp> FreeMoveCameraMoveUpKeyUpCaller; |
| 541 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveDown_KeyDown> FreeMoveCameraMoveDownKeyDownCaller; |
| 542 | typedef ReferenceCaller<camera_t, void(), &Camera_MoveDown_KeyUp> FreeMoveCameraMoveDownKeyUpCaller; |
| 543 | |
| 544 | typedef ReferenceCaller<camera_t, void(), &Camera_Focus_KeyDown> FreeMoveCameraFocusKeyDownCaller; |
| 545 | typedef ReferenceCaller<camera_t, void(), &Camera_Focus_KeyUp> FreeMoveCameraFocusKeyUpCaller; |
| 546 | |
| 547 | const float MIN_FOV = 60; |
| 548 | const float MAX_FOV = 179; |
| 549 | const float FOV_STEP = 10; |
| 550 | const float SPEED_MOVE = 32; |
| 551 | const float SPEED_TURN = 22.5; |
| 552 | const float MIN_CAM_SPEED = 10; |
| 553 | const float MAX_CAM_SPEED = 610; |
| 554 | const float CAM_SPEED_STEP = 50; |
| 555 | |
| 556 | void Camera_MoveForward_Discrete( camera_t& camera ){ |
| 557 | Camera_Move_updateAxes( camera ); |
| 558 | Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.forward, SPEED_MOVE ) ) ); |
| 559 | } |
| 560 | void Camera_MoveBack_Discrete( camera_t& camera ){ |
| 561 | Camera_Move_updateAxes( camera ); |
| 562 | Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.forward, -SPEED_MOVE ) ) ); |
| 563 | } |
| 564 | |
| 565 | void Camera_MoveUp_Discrete( camera_t& camera ){ |
| 566 | Vector3 origin( Camera_getOrigin( camera ) ); |
| 567 | origin[2] += SPEED_MOVE; |
| 568 | Camera_setOrigin( camera, origin ); |
| 569 | } |
| 570 | void Camera_MoveDown_Discrete( camera_t& camera ){ |
| 571 | Vector3 origin( Camera_getOrigin( camera ) ); |
| 572 | origin[2] -= SPEED_MOVE; |
| 573 | Camera_setOrigin( camera, origin ); |
| 574 | } |
| 575 | |
| 576 | void Camera_MoveLeft_Discrete( camera_t& camera ){ |
| 577 | Camera_Move_updateAxes( camera ); |
| 578 | Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.right, -SPEED_MOVE ) ) ); |
| 579 | } |
| 580 | void Camera_MoveRight_Discrete( camera_t& camera ){ |
| 581 | Camera_Move_updateAxes( camera ); |
| 582 | Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.right, SPEED_MOVE ) ) ); |
| 583 | } |
| 584 | |
| 585 | void Camera_RotateLeft_Discrete( camera_t& camera ){ |
| 586 | Vector3 angles( Camera_getAngles( camera ) ); |
| 587 | angles[CAMERA_YAW] += SPEED_TURN; |
| 588 | Camera_setAngles( camera, angles ); |
| 589 | } |
| 590 | void Camera_RotateRight_Discrete( camera_t& camera ){ |
| 591 | Vector3 angles( Camera_getAngles( camera ) ); |
| 592 | angles[CAMERA_YAW] -= SPEED_TURN; |
| 593 | Camera_setAngles( camera, angles ); |
| 594 | } |
| 595 | |
| 596 | void Camera_PitchUp_Discrete( camera_t& camera ){ |
| 597 | Vector3 angles( Camera_getAngles( camera ) ); |
| 598 | angles[CAMERA_PITCH] += SPEED_TURN; |
| 599 | if ( angles[CAMERA_PITCH] > 90 ) { |
| 600 | angles[CAMERA_PITCH] = 90; |
| 601 | } |
| 602 | Camera_setAngles( camera, angles ); |
| 603 | } |
| 604 | void Camera_PitchDown_Discrete( camera_t& camera ){ |
| 605 | Vector3 angles( Camera_getAngles( camera ) ); |
| 606 | angles[CAMERA_PITCH] -= SPEED_TURN; |
| 607 | if ( angles[CAMERA_PITCH] < -90 ) { |
| 608 | angles[CAMERA_PITCH] = -90; |
| 609 | } |
| 610 | Camera_setAngles( camera, angles ); |
| 611 | } |
| 612 | |
| 613 | |
| 614 | class RadiantCameraView : public CameraView |
| 615 | { |
| 616 | camera_t& m_camera; |
| 617 | View* m_view; |
| 618 | Callback<void()> m_update; |
| 619 | public: |
| 620 | RadiantCameraView( camera_t& camera, View* view, const Callback<void()>& update ) : m_camera( camera ), m_view( view ), m_update( update ){ |
| 621 | } |
| 622 | void update(){ |
| 623 | m_view->Construct( m_camera.projection, m_camera.modelview, m_camera.width, m_camera.height ); |
| 624 | m_update(); |
| 625 | } |
| 626 | void setModelview( const Matrix4& modelview ){ |
| 627 | m_camera.modelview = modelview; |
| 628 | matrix4_multiply_by_matrix4( m_camera.modelview, g_radiant2opengl ); |
| 629 | matrix4_affine_invert( m_camera.modelview ); |
| 630 | Camera_updateVectors( m_camera ); |
| 631 | update(); |
| 632 | } |
| 633 | void setFieldOfView( float fieldOfView ){ |
| 634 | float farClip = Camera_getFarClipPlane( m_camera ); |
| 635 | m_camera.projection = projection_for_camera( farClip / 4096.0f, farClip, fieldOfView, m_camera.width, m_camera.height ); |
| 636 | update(); |
| 637 | } |
| 638 | }; |
| 639 | |
| 640 | |
| 641 | void Camera_motionDelta( int x, int y, unsigned int state, void* data ){ |
| 642 | camera_t* cam = reinterpret_cast<camera_t*>( data ); |
| 643 | |
| 644 | cam->m_mouseMove.motion_delta( x, y, state ); |
| 645 | |
| 646 | cam->m_strafe_forward_invert = false; |
| 647 | |
| 648 | switch ( g_camwindow_globals_private.m_nStrafeMode ) |
| 649 | { |
| 650 | case 0: |
| 651 | cam->m_strafe = false; |
| 652 | break; |
| 653 | case 1: |
| 654 | cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0 && ( state & GDK_SHIFT_MASK ) == 0; |
| 655 | cam->m_strafe_forward = false; |
| 656 | break; |
| 657 | case 2: |
| 658 | cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0 && ( state & GDK_SHIFT_MASK ) == 0; |
| 659 | cam->m_strafe_forward = cam->m_strafe; |
| 660 | break; |
| 661 | case 4: |
| 662 | cam->m_strafe_forward_invert = true; // fall through |
| 663 | default: /* 3 & 4 */ |
| 664 | cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0; |
| 665 | if ( cam->m_strafe ) { |
| 666 | cam->m_strafe_forward = ( state & GDK_SHIFT_MASK ) != 0; |
| 667 | } |
| 668 | else{ |
| 669 | cam->m_strafe_forward = false; |
| 670 | } |
| 671 | break; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | class CamWnd |
| 680 | { |
| 681 | View m_view; |
| 682 | camera_t m_Camera; |
| 683 | RadiantCameraView m_cameraview; |
| 684 | #if 0 |
| 685 | int m_PositionDragCursorX; |
| 686 | int m_PositionDragCursorY; |
| 687 | #endif |
| 688 | |
| 689 | guint m_freemove_handle_focusout; |
| 690 | |
| 691 | static Shader* m_state_select1; |
| 692 | static Shader* m_state_select2; |
| 693 | |
| 694 | FreezePointer m_freezePointer; |
| 695 | |
| 696 | public: |
| 697 | ui::GLArea m_gl_widget; |
| 698 | ui::Window m_parent{ui::null}; |
| 699 | |
| 700 | SelectionSystemWindowObserver* m_window_observer; |
| 701 | XORRectangle m_XORRectangle; |
| 702 | |
| 703 | DeferredDraw m_deferredDraw; |
| 704 | DeferredMotion m_deferred_motion; |
| 705 | |
| 706 | guint m_selection_button_press_handler; |
| 707 | guint m_selection_button_release_handler; |
| 708 | guint m_selection_motion_handler; |
| 709 | |
| 710 | guint m_freelook_button_press_handler; |
| 711 | |
| 712 | guint m_sizeHandler; |
| 713 | guint m_exposeHandler; |
| 714 | |
| 715 | CamWnd(); |
| 716 | ~CamWnd(); |
| 717 | |
| 718 | bool m_drawing; |
| 719 | void queue_draw(){ |
| 720 | //ASSERT_MESSAGE(!m_drawing, "CamWnd::queue_draw(): called while draw is already in progress"); |
| 721 | if ( m_drawing ) { |
| 722 | return; |
| 723 | } |
| 724 | //globalOutputStream() << "queue... "; |
| 725 | m_deferredDraw.draw(); |
| 726 | } |
| 727 | void draw(); |
| 728 | |
| 729 | static void captureStates(){ |
| 730 | m_state_select1 = GlobalShaderCache().capture( "$CAM_HIGHLIGHT" ); |
| 731 | m_state_select2 = GlobalShaderCache().capture( "$CAM_OVERLAY" ); |
| 732 | } |
| 733 | static void releaseStates(){ |
| 734 | GlobalShaderCache().release( "$CAM_HIGHLIGHT" ); |
| 735 | GlobalShaderCache().release( "$CAM_OVERLAY" ); |
| 736 | } |
| 737 | |
| 738 | camera_t& getCamera(){ |
| 739 | return m_Camera; |
| 740 | } |
| 741 | |
| 742 | void BenchMark(); |
| 743 | void Cam_ChangeFloor( bool up ); |
| 744 | |
| 745 | void DisableFreeMove(); |
| 746 | void EnableFreeMove(); |
| 747 | bool m_bFreeMove; |
| 748 | |
| 749 | CameraView& getCameraView(){ |
| 750 | return m_cameraview; |
| 751 | } |
| 752 | |
| 753 | private: |
| 754 | void Cam_Draw(); |
| 755 | }; |
| 756 | |
| 757 | typedef MemberCaller<CamWnd, void(), &CamWnd::queue_draw> CamWndQueueDraw; |
| 758 | |
| 759 | Shader* CamWnd::m_state_select1 = 0; |
| 760 | Shader* CamWnd::m_state_select2 = 0; |
| 761 | |
| 762 | CamWnd* NewCamWnd(){ |
| 763 | return new CamWnd; |
| 764 | } |
| 765 | void DeleteCamWnd( CamWnd* camwnd ){ |
| 766 | delete camwnd; |
| 767 | } |
| 768 | |
| 769 | void CamWnd_constructStatic(){ |
| 770 | CamWnd::captureStates(); |
| 771 | } |
| 772 | |
| 773 | void CamWnd_destroyStatic(){ |
| 774 | CamWnd::releaseStates(); |
| 775 | } |
| 776 | |
| 777 | static CamWnd* g_camwnd = 0; |
| 778 | |
| 779 | void GlobalCamera_setCamWnd( CamWnd& camwnd ){ |
| 780 | g_camwnd = &camwnd; |
| 781 | } |
| 782 | |
| 783 | |
| 784 | ui::GLArea CamWnd_getWidget( CamWnd& camwnd ){ |
| 785 | return camwnd.m_gl_widget; |
| 786 | } |
| 787 | |
| 788 | ui::Window CamWnd_getParent( CamWnd& camwnd ){ |
| 789 | return camwnd.m_parent; |
| 790 | } |
| 791 | |
| 792 | ToggleShown g_camera_shown( true ); |
| 793 | |
| 794 | void CamWnd_setParent( CamWnd& camwnd, ui::Window parent ){ |
| 795 | camwnd.m_parent = parent; |
| 796 | g_camera_shown.connect( camwnd.m_parent ); |
| 797 | } |
| 798 | |
| 799 | void CamWnd_Update( CamWnd& camwnd ){ |
| 800 | camwnd.queue_draw(); |
| 801 | } |
| 802 | |
| 803 | |
| 804 | |
| 805 | camwindow_globals_t g_camwindow_globals; |
| 806 | |
| 807 | const Vector3& Camera_getOrigin( CamWnd& camwnd ){ |
| 808 | return Camera_getOrigin( camwnd.getCamera() ); |
| 809 | } |
| 810 | |
| 811 | void Camera_setOrigin( CamWnd& camwnd, const Vector3& origin ){ |
| 812 | Camera_setOrigin( camwnd.getCamera(), origin ); |
| 813 | } |
| 814 | |
| 815 | const Vector3& Camera_getAngles( CamWnd& camwnd ){ |
| 816 | return Camera_getAngles( camwnd.getCamera() ); |
| 817 | } |
| 818 | |
| 819 | void Camera_setAngles( CamWnd& camwnd, const Vector3& angles ){ |
| 820 | Camera_setAngles( camwnd.getCamera(), angles ); |
| 821 | } |
| 822 | |
| 823 | |
| 824 | // ============================================================================= |
| 825 | // CamWnd class |
| 826 | |
| 827 | gboolean enable_freelook_button_press( ui::Widget widget, GdkEventButton* event, CamWnd* camwnd ){ |
| 828 | if ( event->type == GDK_BUTTON_PRESS && event->button == 3 && modifiers_for_state( event->state ) == c_modifierNone ) { |
| 829 | camwnd->EnableFreeMove(); |
| 830 | return TRUE; |
| 831 | } |
| 832 | return FALSE; |
| 833 | } |
| 834 | |
| 835 | gboolean disable_freelook_button_press( ui::Widget widget, GdkEventButton* event, CamWnd* camwnd ){ |
| 836 | if ( event->type == GDK_BUTTON_PRESS && event->button == 3 && modifiers_for_state( event->state ) == c_modifierNone ) { |
| 837 | camwnd->DisableFreeMove(); |
| 838 | return TRUE; |
| 839 | } |
| 840 | return FALSE; |
| 841 | } |
| 842 | |
| 843 | #if 0 |
| 844 | gboolean mousecontrol_button_press( ui::Widget widget, GdkEventButton* event, CamWnd* camwnd ){ |
| 845 | if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) { |
| 846 | Cam_MouseControl( camwnd->getCamera(), event->x, widget->allocation.height - 1 - event->y ); |
| 847 | } |
| 848 | return FALSE; |
| 849 | } |
| 850 | #endif |
| 851 | |
| 852 | void camwnd_update_xor_rectangle( CamWnd& self, rect_t area ){ |
| 853 | if ( self.m_gl_widget.visible() ) { |
| 854 | self.m_XORRectangle.set( rectangle_from_area( area.min, area.max, self.getCamera().width, self.getCamera().height ) ); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | |
| 859 | gboolean selection_button_press( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){ |
| 860 | if ( event->type == GDK_BUTTON_PRESS ) { |
| 861 | gtk_widget_grab_focus( widget ); |
| 862 | observer->onMouseDown( WindowVector_forDouble( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) ); |
| 863 | } |
| 864 | return FALSE; |
| 865 | } |
| 866 | |
| 867 | gboolean selection_button_release( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){ |
| 868 | if ( event->type == GDK_BUTTON_RELEASE ) { |
| 869 | observer->onMouseUp( WindowVector_forDouble( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) ); |
| 870 | } |
| 871 | return FALSE; |
| 872 | } |
| 873 | |
| 874 | void selection_motion( gdouble x, gdouble y, guint state, void* data ){ |
| 875 | //globalOutputStream() << "motion... "; |
| 876 | reinterpret_cast<WindowObserver*>( data )->onMouseMotion( WindowVector_forDouble( x, y ), modifiers_for_state( state ) ); |
| 877 | } |
| 878 | |
| 879 | inline WindowVector windowvector_for_widget_centre( ui::Widget widget ){ |
| 880 | auto allocation = widget.dimensions(); |
| 881 | return WindowVector( static_cast<float>( allocation.width / 2 ), static_cast<float>(allocation.height / 2 ) ); |
| 882 | } |
| 883 | |
| 884 | gboolean selection_button_press_freemove( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){ |
| 885 | if ( event->type == GDK_BUTTON_PRESS ) { |
| 886 | observer->onMouseDown( windowvector_for_widget_centre( widget ), button_for_button( event->button ), modifiers_for_state( event->state ) ); |
| 887 | } |
| 888 | return FALSE; |
| 889 | } |
| 890 | |
| 891 | gboolean selection_button_release_freemove( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){ |
| 892 | if ( event->type == GDK_BUTTON_RELEASE ) { |
| 893 | observer->onMouseUp( windowvector_for_widget_centre( widget ), button_for_button( event->button ), modifiers_for_state( event->state ) ); |
| 894 | } |
| 895 | return FALSE; |
| 896 | } |
| 897 | |
| 898 | gboolean selection_motion_freemove( ui::Widget widget, GdkEventMotion *event, WindowObserver* observer ){ |
| 899 | observer->onMouseMotion( windowvector_for_widget_centre( widget ), modifiers_for_state( event->state ) ); |
| 900 | return FALSE; |
| 901 | } |
| 902 | |
| 903 | gboolean wheelmove_scroll( ui::Widget widget, GdkEventScroll* event, CamWnd* camwnd ){ |
| 904 | //gtk_window_set_focus( camwnd->m_parent, camwnd->m_gl_widget ); |
| 905 | gtk_widget_grab_focus( camwnd->m_gl_widget ); |
| 906 | if( !gtk_window_is_active( camwnd->m_parent ) ) |
| 907 | gtk_window_present( camwnd->m_parent ); |
| 908 | |
| 909 | if ( event->direction == GDK_SCROLL_UP ) { |
| 910 | Camera_Freemove_updateAxes( camwnd->getCamera() ); |
| 911 | if( camwnd->m_bFreeMove || !g_camwindow_globals.m_bZoomInToPointer ){ |
| 912 | Camera_setOrigin( *camwnd, vector3_added( Camera_getOrigin( *camwnd ), vector3_scaled( camwnd->getCamera().forward, static_cast<float>( g_camwindow_globals_private.m_nMoveSpeed ) ) ) ); |
| 913 | } |
| 914 | else{ |
| 915 | //Matrix4 maa = matrix4_multiplied_by_matrix4( camwnd->getCamera().projection, camwnd->getCamera().modelview ); |
| 916 | Matrix4 maa = camwnd->getCamera().m_view->GetViewMatrix(); |
| 917 | matrix4_affine_invert( maa ); |
| 918 | |
| 919 | float x = static_cast<float>( event->x ); |
| 920 | float y = static_cast<float>( event->y ); |
| 921 | Vector3 normalized; |
| 922 | |
| 923 | normalized[0] = 2.0f * ( x ) / static_cast<float>( camwnd->getCamera().width ) - 1.0f; |
| 924 | normalized[1] = 2.0f * ( y )/ static_cast<float>( camwnd->getCamera().height ) - 1.0f; |
| 925 | normalized[1] *= -1.f; |
| 926 | normalized[2] = 0.f; |
| 927 | |
| 928 | normalized *= 16.0f; |
| 929 | //globalOutputStream() << normalized << " normalized "; |
| 930 | matrix4_transform_point( maa, normalized ); |
| 931 | //globalOutputStream() << normalized << "\n"; |
| 932 | Vector3 norm = vector3_normalised( normalized - Camera_getOrigin( *camwnd ) ); |
| 933 | //globalOutputStream() << normalized - Camera_getOrigin( *camwnd ) << " normalized - Camera_getOrigin( *camwnd )\n"; |
| 934 | //globalOutputStream() << norm << " norm\n"; |
| 935 | Camera_setOrigin( *camwnd, vector3_added( Camera_getOrigin( *camwnd ), vector3_scaled( norm, static_cast<float>( g_camwindow_globals_private.m_nMoveSpeed ) ) ) ); |
| 936 | } |
| 937 | } |
| 938 | else if ( event->direction == GDK_SCROLL_DOWN ) { |
| 939 | Camera_Freemove_updateAxes( camwnd->getCamera() ); |
| 940 | Camera_setOrigin( *camwnd, vector3_added( Camera_getOrigin( *camwnd ), vector3_scaled( camwnd->getCamera().forward, -static_cast<float>( g_camwindow_globals_private.m_nMoveSpeed ) ) ) ); |
| 941 | } |
| 942 | |
| 943 | return FALSE; |
| 944 | } |
| 945 | |
| 946 | gboolean camera_size_allocate( ui::Widget widget, GtkAllocation* allocation, CamWnd* camwnd ){ |
| 947 | camwnd->getCamera().width = allocation->width; |
| 948 | camwnd->getCamera().height = allocation->height; |
| 949 | Camera_updateProjection( camwnd->getCamera() ); |
| 950 | camwnd->m_window_observer->onSizeChanged( camwnd->getCamera().width, camwnd->getCamera().height ); |
| 951 | camwnd->queue_draw(); |
| 952 | return FALSE; |
| 953 | } |
| 954 | |
| 955 | gboolean camera_expose( ui::Widget widget, GdkEventExpose* event, gpointer data ){ |
| 956 | reinterpret_cast<CamWnd*>( data )->draw(); |
| 957 | return FALSE; |
| 958 | } |
| 959 | |
| 960 | void KeyEvent_connect( const char* name ){ |
| 961 | const KeyEvent& keyEvent = GlobalKeyEvents_find( name ); |
| 962 | keydown_accelerators_add( keyEvent.m_accelerator, keyEvent.m_keyDown ); |
| 963 | keyup_accelerators_add( keyEvent.m_accelerator, keyEvent.m_keyUp ); |
| 964 | } |
| 965 | |
| 966 | void KeyEvent_disconnect( const char* name ){ |
| 967 | const KeyEvent& keyEvent = GlobalKeyEvents_find( name ); |
| 968 | keydown_accelerators_remove( keyEvent.m_accelerator ); |
| 969 | keyup_accelerators_remove( keyEvent.m_accelerator ); |
| 970 | } |
| 971 | |
| 972 | void CamWnd_registerCommands( CamWnd& camwnd ){ |
| 973 | GlobalKeyEvents_insert( "CameraForward", accelerator_null(), |
| 974 | ReferenceCaller<camera_t, void(), Camera_MoveForward_KeyDown>( camwnd.getCamera() ), |
| 975 | ReferenceCaller<camera_t, void(), Camera_MoveForward_KeyUp>( camwnd.getCamera() ) |
| 976 | ); |
| 977 | GlobalKeyEvents_insert( "CameraBack", accelerator_null(), |
| 978 | ReferenceCaller<camera_t, void(), Camera_MoveBack_KeyDown>( camwnd.getCamera() ), |
| 979 | ReferenceCaller<camera_t, void(), Camera_MoveBack_KeyUp>( camwnd.getCamera() ) |
| 980 | ); |
| 981 | GlobalKeyEvents_insert( "CameraLeft", accelerator_null(), |
| 982 | ReferenceCaller<camera_t, void(), Camera_RotateLeft_KeyDown>( camwnd.getCamera() ), |
| 983 | ReferenceCaller<camera_t, void(), Camera_RotateLeft_KeyUp>( camwnd.getCamera() ) |
| 984 | ); |
| 985 | GlobalKeyEvents_insert( "CameraRight", accelerator_null(), |
| 986 | ReferenceCaller<camera_t, void(), Camera_RotateRight_KeyDown>( camwnd.getCamera() ), |
| 987 | ReferenceCaller<camera_t, void(), Camera_RotateRight_KeyUp>( camwnd.getCamera() ) |
| 988 | ); |
| 989 | GlobalKeyEvents_insert( "CameraStrafeRight", accelerator_null(), |
| 990 | ReferenceCaller<camera_t, void(), Camera_MoveRight_KeyDown>( camwnd.getCamera() ), |
| 991 | ReferenceCaller<camera_t, void(), Camera_MoveRight_KeyUp>( camwnd.getCamera() ) |
| 992 | ); |
| 993 | GlobalKeyEvents_insert( "CameraStrafeLeft", accelerator_null(), |
| 994 | ReferenceCaller<camera_t, void(), Camera_MoveLeft_KeyDown>( camwnd.getCamera() ), |
| 995 | ReferenceCaller<camera_t, void(), Camera_MoveLeft_KeyUp>( camwnd.getCamera() ) |
| 996 | ); |
| 997 | GlobalKeyEvents_insert( "CameraUp", accelerator_null(), |
| 998 | ReferenceCaller<camera_t, void(), Camera_MoveUp_KeyDown>( camwnd.getCamera() ), |
| 999 | ReferenceCaller<camera_t, void(), Camera_MoveUp_KeyUp>( camwnd.getCamera() ) |
| 1000 | ); |
| 1001 | GlobalKeyEvents_insert( "CameraDown", accelerator_null(), |
| 1002 | ReferenceCaller<camera_t, void(), Camera_MoveDown_KeyDown>( camwnd.getCamera() ), |
| 1003 | ReferenceCaller<camera_t, void(), Camera_MoveDown_KeyUp>( camwnd.getCamera() ) |
| 1004 | ); |
| 1005 | GlobalKeyEvents_insert( "CameraAngleUp", accelerator_null(), |
| 1006 | ReferenceCaller<camera_t, void(), Camera_PitchUp_KeyDown>( camwnd.getCamera() ), |
| 1007 | ReferenceCaller<camera_t, void(), Camera_PitchUp_KeyUp>( camwnd.getCamera() ) |
| 1008 | ); |
| 1009 | GlobalKeyEvents_insert( "CameraAngleDown", accelerator_null(), |
| 1010 | ReferenceCaller<camera_t, void(), Camera_PitchDown_KeyDown>( camwnd.getCamera() ), |
| 1011 | ReferenceCaller<camera_t, void(), Camera_PitchDown_KeyUp>( camwnd.getCamera() ) |
| 1012 | ); |
| 1013 | |
| 1014 | |
| 1015 | GlobalKeyEvents_insert( "CameraFreeMoveForward", accelerator_null(), |
| 1016 | FreeMoveCameraMoveForwardKeyDownCaller( camwnd.getCamera() ), |
| 1017 | FreeMoveCameraMoveForwardKeyUpCaller( camwnd.getCamera() ) |
| 1018 | ); |
| 1019 | GlobalKeyEvents_insert( "CameraFreeMoveBack", accelerator_null(), |
| 1020 | FreeMoveCameraMoveBackKeyDownCaller( camwnd.getCamera() ), |
| 1021 | FreeMoveCameraMoveBackKeyUpCaller( camwnd.getCamera() ) |
| 1022 | ); |
| 1023 | GlobalKeyEvents_insert( "CameraFreeMoveLeft", accelerator_null(), |
| 1024 | FreeMoveCameraMoveLeftKeyDownCaller( camwnd.getCamera() ), |
| 1025 | FreeMoveCameraMoveLeftKeyUpCaller( camwnd.getCamera() ) |
| 1026 | ); |
| 1027 | GlobalKeyEvents_insert( "CameraFreeMoveRight", accelerator_null(), |
| 1028 | FreeMoveCameraMoveRightKeyDownCaller( camwnd.getCamera() ), |
| 1029 | FreeMoveCameraMoveRightKeyUpCaller( camwnd.getCamera() ) |
| 1030 | ); |
| 1031 | |
| 1032 | GlobalKeyEvents_insert( "CameraFreeMoveForward2", accelerator_null(), |
| 1033 | FreeMoveCameraMoveForwardKeyDownCaller( camwnd.getCamera() ), |
| 1034 | FreeMoveCameraMoveForwardKeyUpCaller( camwnd.getCamera() ) |
| 1035 | ); |
| 1036 | GlobalKeyEvents_insert( "CameraFreeMoveBack2", accelerator_null(), |
| 1037 | FreeMoveCameraMoveBackKeyDownCaller( camwnd.getCamera() ), |
| 1038 | FreeMoveCameraMoveBackKeyUpCaller( camwnd.getCamera() ) |
| 1039 | ); |
| 1040 | GlobalKeyEvents_insert( "CameraFreeMoveLeft2", accelerator_null(), |
| 1041 | FreeMoveCameraMoveLeftKeyDownCaller( camwnd.getCamera() ), |
| 1042 | FreeMoveCameraMoveLeftKeyUpCaller( camwnd.getCamera() ) |
| 1043 | ); |
| 1044 | GlobalKeyEvents_insert( "CameraFreeMoveRight2", accelerator_null(), |
| 1045 | FreeMoveCameraMoveRightKeyDownCaller( camwnd.getCamera() ), |
| 1046 | FreeMoveCameraMoveRightKeyUpCaller( camwnd.getCamera() ) |
| 1047 | ); |
| 1048 | |
| 1049 | GlobalKeyEvents_insert( "CameraFreeMoveUp", accelerator_null(), |
| 1050 | FreeMoveCameraMoveUpKeyDownCaller( camwnd.getCamera() ), |
| 1051 | FreeMoveCameraMoveUpKeyUpCaller( camwnd.getCamera() ) |
| 1052 | ); |
| 1053 | GlobalKeyEvents_insert( "CameraFreeMoveDown", accelerator_null(), |
| 1054 | FreeMoveCameraMoveDownKeyDownCaller( camwnd.getCamera() ), |
| 1055 | FreeMoveCameraMoveDownKeyUpCaller( camwnd.getCamera() ) |
| 1056 | ); |
| 1057 | |
| 1058 | GlobalKeyEvents_insert( "CameraFreeFocus", accelerator_null(), |
| 1059 | FreeMoveCameraFocusKeyDownCaller( camwnd.getCamera() ), |
| 1060 | FreeMoveCameraFocusKeyUpCaller( camwnd.getCamera() ) |
| 1061 | ); |
| 1062 | |
| 1063 | GlobalCommands_insert( "CameraForward", ReferenceCaller<camera_t, void(), Camera_MoveForward_Discrete>( camwnd.getCamera() ) ); |
| 1064 | GlobalCommands_insert( "CameraBack", ReferenceCaller<camera_t, void(), Camera_MoveBack_Discrete>( camwnd.getCamera() ) ); |
| 1065 | GlobalCommands_insert( "CameraLeft", ReferenceCaller<camera_t, void(), Camera_RotateLeft_Discrete>( camwnd.getCamera() ) ); |
| 1066 | GlobalCommands_insert( "CameraRight", ReferenceCaller<camera_t, void(), Camera_RotateRight_Discrete>( camwnd.getCamera() ) ); |
| 1067 | GlobalCommands_insert( "CameraStrafeRight", ReferenceCaller<camera_t, void(), Camera_MoveRight_Discrete>( camwnd.getCamera() ) ); |
| 1068 | GlobalCommands_insert( "CameraStrafeLeft", ReferenceCaller<camera_t, void(), Camera_MoveLeft_Discrete>( camwnd.getCamera() ) ); |
| 1069 | |
| 1070 | GlobalCommands_insert( "CameraUp", ReferenceCaller<camera_t, void(), Camera_MoveUp_Discrete>( camwnd.getCamera() ) ); |
| 1071 | GlobalCommands_insert( "CameraDown", ReferenceCaller<camera_t, void(), Camera_MoveDown_Discrete>( camwnd.getCamera() ) ); |
| 1072 | GlobalCommands_insert( "CameraAngleUp", ReferenceCaller<camera_t, void(), Camera_PitchUp_Discrete>( camwnd.getCamera() ) ); |
| 1073 | GlobalCommands_insert( "CameraAngleDown", ReferenceCaller<camera_t, void(), Camera_PitchDown_Discrete>( camwnd.getCamera() ) ); |
| 1074 | } |
| 1075 | |
| 1076 | void CamWnd_Move_Enable( CamWnd& camwnd ){ |
| 1077 | KeyEvent_connect( "CameraForward" ); |
| 1078 | KeyEvent_connect( "CameraBack" ); |
| 1079 | KeyEvent_connect( "CameraLeft" ); |
| 1080 | KeyEvent_connect( "CameraRight" ); |
| 1081 | KeyEvent_connect( "CameraStrafeRight" ); |
| 1082 | KeyEvent_connect( "CameraStrafeLeft" ); |
| 1083 | KeyEvent_connect( "CameraUp" ); |
| 1084 | KeyEvent_connect( "CameraDown" ); |
| 1085 | KeyEvent_connect( "CameraAngleUp" ); |
| 1086 | KeyEvent_connect( "CameraAngleDown" ); |
| 1087 | } |
| 1088 | |
| 1089 | void CamWnd_Move_Disable( CamWnd& camwnd ){ |
| 1090 | KeyEvent_disconnect( "CameraForward" ); |
| 1091 | KeyEvent_disconnect( "CameraBack" ); |
| 1092 | KeyEvent_disconnect( "CameraLeft" ); |
| 1093 | KeyEvent_disconnect( "CameraRight" ); |
| 1094 | KeyEvent_disconnect( "CameraStrafeRight" ); |
| 1095 | KeyEvent_disconnect( "CameraStrafeLeft" ); |
| 1096 | KeyEvent_disconnect( "CameraUp" ); |
| 1097 | KeyEvent_disconnect( "CameraDown" ); |
| 1098 | KeyEvent_disconnect( "CameraAngleUp" ); |
| 1099 | KeyEvent_disconnect( "CameraAngleDown" ); |
| 1100 | } |
| 1101 | |
| 1102 | void CamWnd_Move_Discrete_Enable( CamWnd& camwnd ){ |
| 1103 | command_connect_accelerator( "CameraForward" ); |
| 1104 | command_connect_accelerator( "CameraBack" ); |
| 1105 | command_connect_accelerator( "CameraLeft" ); |
| 1106 | command_connect_accelerator( "CameraRight" ); |
| 1107 | command_connect_accelerator( "CameraStrafeRight" ); |
| 1108 | command_connect_accelerator( "CameraStrafeLeft" ); |
| 1109 | command_connect_accelerator( "CameraUp" ); |
| 1110 | command_connect_accelerator( "CameraDown" ); |
| 1111 | command_connect_accelerator( "CameraAngleUp" ); |
| 1112 | command_connect_accelerator( "CameraAngleDown" ); |
| 1113 | } |
| 1114 | |
| 1115 | void CamWnd_Move_Discrete_Disable( CamWnd& camwnd ){ |
| 1116 | command_disconnect_accelerator( "CameraForward" ); |
| 1117 | command_disconnect_accelerator( "CameraBack" ); |
| 1118 | command_disconnect_accelerator( "CameraLeft" ); |
| 1119 | command_disconnect_accelerator( "CameraRight" ); |
| 1120 | command_disconnect_accelerator( "CameraStrafeRight" ); |
| 1121 | command_disconnect_accelerator( "CameraStrafeLeft" ); |
| 1122 | command_disconnect_accelerator( "CameraUp" ); |
| 1123 | command_disconnect_accelerator( "CameraDown" ); |
| 1124 | command_disconnect_accelerator( "CameraAngleUp" ); |
| 1125 | command_disconnect_accelerator( "CameraAngleDown" ); |
| 1126 | } |
| 1127 | |
| 1128 | struct CamWnd_Move_Discrete { |
| 1129 | static void Export(const Callback<void(bool)> &returnz) { |
| 1130 | returnz(g_camwindow_globals_private.m_bCamDiscrete); |
| 1131 | } |
| 1132 | |
| 1133 | static void Import(bool value) { |
| 1134 | if (g_camwnd) { |
| 1135 | Import_(*g_camwnd, value); |
| 1136 | } else { |
| 1137 | g_camwindow_globals_private.m_bCamDiscrete = value; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | static void Import_(CamWnd &camwnd, bool value) { |
| 1142 | if ( g_camwindow_globals_private.m_bCamDiscrete ) { |
| 1143 | CamWnd_Move_Discrete_Disable( camwnd ); |
| 1144 | } else { |
| 1145 | CamWnd_Move_Disable( camwnd ); |
| 1146 | } |
| 1147 | |
| 1148 | g_camwindow_globals_private.m_bCamDiscrete = value; |
| 1149 | |
| 1150 | if ( g_camwindow_globals_private.m_bCamDiscrete ) { |
| 1151 | CamWnd_Move_Discrete_Enable( camwnd ); |
| 1152 | } else { |
| 1153 | CamWnd_Move_Enable( camwnd ); |
| 1154 | } |
| 1155 | } |
| 1156 | }; |
| 1157 | |
| 1158 | |
| 1159 | void CamWnd_Add_Handlers_Move( CamWnd& camwnd ){ |
| 1160 | camwnd.m_selection_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( selection_button_press ), camwnd.m_window_observer ); |
| 1161 | camwnd.m_selection_button_release_handler = camwnd.m_gl_widget.connect( "button_release_event", G_CALLBACK( selection_button_release ), camwnd.m_window_observer ); |
| 1162 | camwnd.m_selection_motion_handler = camwnd.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &camwnd.m_deferred_motion ); |
| 1163 | |
| 1164 | camwnd.m_freelook_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( enable_freelook_button_press ), &camwnd ); |
| 1165 | |
| 1166 | if ( g_camwindow_globals_private.m_bCamDiscrete ) { |
| 1167 | CamWnd_Move_Discrete_Enable( camwnd ); |
| 1168 | } |
| 1169 | else |
| 1170 | { |
| 1171 | CamWnd_Move_Enable( camwnd ); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | void CamWnd_Remove_Handlers_Move( CamWnd& camwnd ){ |
| 1176 | g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_press_handler ); |
| 1177 | g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_release_handler ); |
| 1178 | g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_motion_handler ); |
| 1179 | |
| 1180 | g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_freelook_button_press_handler ); |
| 1181 | |
| 1182 | if ( g_camwindow_globals_private.m_bCamDiscrete ) { |
| 1183 | CamWnd_Move_Discrete_Disable( camwnd ); |
| 1184 | } |
| 1185 | else |
| 1186 | { |
| 1187 | CamWnd_Move_Disable( camwnd ); |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | void CamWnd_Add_Handlers_FreeMove( CamWnd& camwnd ){ |
| 1192 | camwnd.m_selection_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( selection_button_press_freemove ), camwnd.m_window_observer ); |
| 1193 | camwnd.m_selection_button_release_handler = camwnd.m_gl_widget.connect( "button_release_event", G_CALLBACK( selection_button_release_freemove ), camwnd.m_window_observer ); |
| 1194 | camwnd.m_selection_motion_handler = camwnd.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( selection_motion_freemove ), camwnd.m_window_observer ); |
| 1195 | |
| 1196 | camwnd.m_freelook_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( disable_freelook_button_press ), &camwnd ); |
| 1197 | |
| 1198 | KeyEvent_connect( "CameraFreeMoveForward" ); |
| 1199 | KeyEvent_connect( "CameraFreeMoveBack" ); |
| 1200 | KeyEvent_connect( "CameraFreeMoveLeft" ); |
| 1201 | KeyEvent_connect( "CameraFreeMoveRight" ); |
| 1202 | |
| 1203 | KeyEvent_connect( "CameraFreeMoveForward2" ); |
| 1204 | KeyEvent_connect( "CameraFreeMoveBack2" ); |
| 1205 | KeyEvent_connect( "CameraFreeMoveLeft2" ); |
| 1206 | KeyEvent_connect( "CameraFreeMoveRight2" ); |
| 1207 | |
| 1208 | KeyEvent_connect( "CameraFreeMoveUp" ); |
| 1209 | KeyEvent_connect( "CameraFreeMoveDown" ); |
| 1210 | |
| 1211 | KeyEvent_connect( "CameraFreeFocus" ); |
| 1212 | } |
| 1213 | |
| 1214 | void CamWnd_Remove_Handlers_FreeMove( CamWnd& camwnd ){ |
| 1215 | KeyEvent_disconnect( "CameraFreeMoveForward" ); |
| 1216 | KeyEvent_disconnect( "CameraFreeMoveBack" ); |
| 1217 | KeyEvent_disconnect( "CameraFreeMoveLeft" ); |
| 1218 | KeyEvent_disconnect( "CameraFreeMoveRight" ); |
| 1219 | |
| 1220 | KeyEvent_disconnect( "CameraFreeMoveForward2" ); |
| 1221 | KeyEvent_disconnect( "CameraFreeMoveBack2" ); |
| 1222 | KeyEvent_disconnect( "CameraFreeMoveLeft2" ); |
| 1223 | KeyEvent_disconnect( "CameraFreeMoveRight2" ); |
| 1224 | |
| 1225 | KeyEvent_disconnect( "CameraFreeMoveUp" ); |
| 1226 | KeyEvent_disconnect( "CameraFreeMoveDown" ); |
| 1227 | |
| 1228 | KeyEvent_disconnect( "CameraFreeFocus" ); |
| 1229 | |
| 1230 | g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_press_handler ); |
| 1231 | g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_release_handler ); |
| 1232 | g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_motion_handler ); |
| 1233 | |
| 1234 | g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_freelook_button_press_handler ); |
| 1235 | } |
| 1236 | |
| 1237 | CamWnd::CamWnd() : |
| 1238 | m_view( true ), |
| 1239 | m_Camera( &m_view, CamWndQueueDraw( *this ) ), |
| 1240 | m_cameraview( m_Camera, &m_view, ReferenceCaller<CamWnd, void(), CamWnd_Update>( *this ) ), |
| 1241 | m_gl_widget( glwidget_new( TRUE ) ), |
| 1242 | m_window_observer( NewWindowObserver() ), |
| 1243 | m_XORRectangle( m_gl_widget ), |
| 1244 | m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ), |
| 1245 | m_deferred_motion( selection_motion, m_window_observer ), |
| 1246 | m_selection_button_press_handler( 0 ), |
| 1247 | m_selection_button_release_handler( 0 ), |
| 1248 | m_selection_motion_handler( 0 ), |
| 1249 | m_freelook_button_press_handler( 0 ), |
| 1250 | m_drawing( false ){ |
| 1251 | m_bFreeMove = false; |
| 1252 | |
| 1253 | GlobalWindowObservers_add( m_window_observer ); |
| 1254 | GlobalWindowObservers_connectWidget( m_gl_widget ); |
| 1255 | |
| 1256 | m_window_observer->setRectangleDrawCallback( ReferenceCaller<CamWnd, void(rect_t), camwnd_update_xor_rectangle>( *this ) ); |
| 1257 | m_window_observer->setView( m_view ); |
| 1258 | |
| 1259 | g_object_ref( m_gl_widget._handle ); |
| 1260 | |
| 1261 | gtk_widget_set_events( m_gl_widget, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK ); |
| 1262 | gtk_widget_set_can_focus( m_gl_widget, true ); |
| 1263 | |
| 1264 | m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( camera_size_allocate ), this ); |
| 1265 | m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( camera_expose ), this ); |
| 1266 | |
| 1267 | Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) ); |
| 1268 | |
| 1269 | CamWnd_registerCommands( *this ); |
| 1270 | |
| 1271 | CamWnd_Add_Handlers_Move( *this ); |
| 1272 | |
| 1273 | m_gl_widget.connect( "scroll_event", G_CALLBACK( wheelmove_scroll ), this ); |
| 1274 | |
| 1275 | AddSceneChangeCallback( ReferenceCaller<CamWnd, void(), CamWnd_Update>( *this ) ); |
| 1276 | |
| 1277 | PressedButtons_connect( g_pressedButtons, m_gl_widget ); |
| 1278 | } |
| 1279 | |
| 1280 | CamWnd::~CamWnd(){ |
| 1281 | if ( m_bFreeMove ) { |
| 1282 | DisableFreeMove(); |
| 1283 | } |
| 1284 | |
| 1285 | CamWnd_Remove_Handlers_Move( *this ); |
| 1286 | |
| 1287 | g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler ); |
| 1288 | g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler ); |
| 1289 | |
| 1290 | m_gl_widget.unref(); |
| 1291 | |
| 1292 | m_window_observer->release(); |
| 1293 | } |
| 1294 | |
| 1295 | class FloorHeightWalker : public scene::Graph::Walker |
| 1296 | { |
| 1297 | float m_current; |
| 1298 | float& m_bestUp; |
| 1299 | float& m_bestDown; |
| 1300 | public: |
| 1301 | FloorHeightWalker( float current, float& bestUp, float& bestDown ) : |
| 1302 | m_current( current ), m_bestUp( bestUp ), m_bestDown( bestDown ){ |
| 1303 | bestUp = g_MaxWorldCoord; |
| 1304 | bestDown = -g_MaxWorldCoord; |
| 1305 | } |
| 1306 | bool pre( const scene::Path& path, scene::Instance& instance ) const { |
| 1307 | if ( path.top().get().visible() |
| 1308 | && Node_isBrush( path.top() ) ) { // this node is a floor |
| 1309 | const AABB& aabb = instance.worldAABB(); |
| 1310 | float floorHeight = aabb.origin.z() + aabb.extents.z(); |
| 1311 | if ( floorHeight > m_current && floorHeight < m_bestUp ) { |
| 1312 | m_bestUp = floorHeight; |
| 1313 | } |
| 1314 | if ( floorHeight < m_current && floorHeight > m_bestDown ) { |
| 1315 | m_bestDown = floorHeight; |
| 1316 | } |
| 1317 | } |
| 1318 | else if( !path.top().get().visible() ){ |
| 1319 | return false; |
| 1320 | } |
| 1321 | return true; |
| 1322 | } |
| 1323 | }; |
| 1324 | |
| 1325 | void CamWnd::Cam_ChangeFloor( bool up ){ |
| 1326 | float current = m_Camera.origin[2] - 48; |
| 1327 | float bestUp; |
| 1328 | float bestDown; |
| 1329 | GlobalSceneGraph().traverse( FloorHeightWalker( current, bestUp, bestDown ) ); |
| 1330 | |
| 1331 | if ( up && bestUp != g_MaxWorldCoord ) { |
| 1332 | current = bestUp; |
| 1333 | } |
| 1334 | if ( !up && bestDown != -g_MaxWorldCoord ) { |
| 1335 | current = bestDown; |
| 1336 | } |
| 1337 | |
| 1338 | m_Camera.origin[2] = current + 48; |
| 1339 | Camera_updateModelview( getCamera() ); |
| 1340 | CamWnd_Update( *this ); |
| 1341 | CameraMovedNotify(); |
| 1342 | } |
| 1343 | |
| 1344 | |
| 1345 | #if 0 |
| 1346 | |
| 1347 | // button_press |
| 1348 | Sys_GetCursorPos( &m_PositionDragCursorX, &m_PositionDragCursorY ); |
| 1349 | |
| 1350 | // motion |
| 1351 | if ( ( m_bFreeMove && ( buttons == ( RAD_CONTROL | RAD_SHIFT ) ) ) |
| 1352 | || ( !m_bFreeMove && ( buttons == ( RAD_RBUTTON | RAD_CONTROL ) ) ) ) { |
| 1353 | Cam_PositionDrag(); |
| 1354 | CamWnd_Update( camwnd ); |
| 1355 | CameraMovedNotify(); |
| 1356 | return; |
| 1357 | } |
| 1358 | |
| 1359 | void CamWnd::Cam_PositionDrag(){ |
| 1360 | int x, y; |
| 1361 | |
| 1362 | Sys_GetCursorPos( m_gl_widget, &x, &y ); |
| 1363 | if ( x != m_PositionDragCursorX || y != m_PositionDragCursorY ) { |
| 1364 | x -= m_PositionDragCursorX; |
| 1365 | vector3_add( m_Camera.origin, vector3_scaled( m_Camera.vright, x ) ); |
| 1366 | y -= m_PositionDragCursorY; |
| 1367 | m_Camera.origin[2] -= y; |
| 1368 | Camera_updateModelview(); |
| 1369 | CamWnd_Update( camwnd ); |
| 1370 | CameraMovedNotify(); |
| 1371 | |
| 1372 | Sys_SetCursorPos( m_gl_widget, m_PositionDragCursorX, m_PositionDragCursorY ); |
| 1373 | } |
| 1374 | } |
| 1375 | #endif |
| 1376 | |
| 1377 | |
| 1378 | // NOTE TTimo if there's an OS-level focus out of the application |
| 1379 | // then we can release the camera cursor grab |
| 1380 | static gboolean camwindow_freemove_focusout( ui::Widget widget, GdkEventFocus* event, gpointer data ){ |
| 1381 | reinterpret_cast<CamWnd*>( data )->DisableFreeMove(); |
| 1382 | return FALSE; |
| 1383 | } |
| 1384 | |
| 1385 | void CamWnd::EnableFreeMove(){ |
| 1386 | //globalOutputStream() << "EnableFreeMove\n"; |
| 1387 | |
| 1388 | ASSERT_MESSAGE( !m_bFreeMove, "EnableFreeMove: free-move was already enabled" ); |
| 1389 | m_bFreeMove = true; |
| 1390 | Camera_clearMovementFlags( getCamera(), MOVE_ALL ); |
| 1391 | |
| 1392 | CamWnd_Remove_Handlers_Move( *this ); |
| 1393 | CamWnd_Add_Handlers_FreeMove( *this ); |
| 1394 | |
| 1395 | gtk_window_set_focus( m_parent, m_gl_widget ); |
| 1396 | m_freemove_handle_focusout = m_gl_widget.connect( "focus_out_event", G_CALLBACK( camwindow_freemove_focusout ), this ); |
| 1397 | /* We chose to replace m_parent by m_gl_widget but NetRadiantCustom does: |
| 1398 | m_freezePointer.freeze_pointer( m_parent, m_gl_widget, Camera_motionDelta, &m_Camera ); */ |
| 1399 | m_freezePointer.freeze_pointer( m_gl_widget, Camera_motionDelta, &m_Camera ); |
| 1400 | |
| 1401 | CamWnd_Update( *this ); |
| 1402 | } |
| 1403 | |
| 1404 | void CamWnd::DisableFreeMove(){ |
| 1405 | //globalOutputStream() << "DisableFreeMove\n"; |
| 1406 | |
| 1407 | ASSERT_MESSAGE( m_bFreeMove, "DisableFreeMove: free-move was not enabled" ); |
| 1408 | m_bFreeMove = false; |
| 1409 | Camera_clearMovementFlags( getCamera(), MOVE_ALL ); |
| 1410 | |
| 1411 | CamWnd_Remove_Handlers_FreeMove( *this ); |
| 1412 | CamWnd_Add_Handlers_Move( *this ); |
| 1413 | |
| 1414 | m_freezePointer.unfreeze_pointer( m_gl_widget, true ); |
| 1415 | |
| 1416 | g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_freemove_handle_focusout ); |
| 1417 | |
| 1418 | CamWnd_Update( *this ); |
| 1419 | } |
| 1420 | |
| 1421 | |
| 1422 | #include "renderer.h" |
| 1423 | |
| 1424 | class CamRenderer : public Renderer |
| 1425 | { |
| 1426 | struct state_type |
| 1427 | { |
| 1428 | state_type() : m_highlight( 0 ), m_state( 0 ), m_lights( 0 ){ |
| 1429 | } |
| 1430 | unsigned int m_highlight; |
| 1431 | Shader* m_state; |
| 1432 | const LightList* m_lights; |
| 1433 | }; |
| 1434 | |
| 1435 | std::vector<state_type> m_state_stack; |
| 1436 | RenderStateFlags m_globalstate; |
| 1437 | Shader* m_state_select0; |
| 1438 | Shader* m_state_select1; |
| 1439 | const Vector3& m_viewer; |
| 1440 | |
| 1441 | public: |
| 1442 | CamRenderer( RenderStateFlags globalstate, Shader* select0, Shader* select1, const Vector3& viewer ) : |
| 1443 | m_globalstate( globalstate ), |
| 1444 | m_state_select0( select0 ), |
| 1445 | m_state_select1( select1 ), |
| 1446 | m_viewer( viewer ){ |
| 1447 | ASSERT_NOTNULL( select0 ); |
| 1448 | ASSERT_NOTNULL( select1 ); |
| 1449 | m_state_stack.push_back( state_type() ); |
| 1450 | } |
| 1451 | |
| 1452 | void SetState( Shader* state, EStyle style ){ |
| 1453 | ASSERT_NOTNULL( state ); |
| 1454 | if ( style == eFullMaterials ) { |
| 1455 | m_state_stack.back().m_state = state; |
| 1456 | } |
| 1457 | } |
| 1458 | EStyle getStyle() const { |
| 1459 | return eFullMaterials; |
| 1460 | } |
| 1461 | void PushState(){ |
| 1462 | m_state_stack.push_back( m_state_stack.back() ); |
| 1463 | } |
| 1464 | void PopState(){ |
| 1465 | ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" ); |
| 1466 | m_state_stack.pop_back(); |
| 1467 | } |
| 1468 | void Highlight( EHighlightMode mode, bool bEnable = true ){ |
| 1469 | if ( bEnable ) { |
| 1470 | m_state_stack.back().m_highlight |= mode; |
| 1471 | } else { |
| 1472 | m_state_stack.back().m_highlight &= ~mode; |
| 1473 | } |
| 1474 | } |
| 1475 | void setLights( const LightList& lights ){ |
| 1476 | m_state_stack.back().m_lights = &lights; |
| 1477 | } |
| 1478 | void addRenderable( const OpenGLRenderable& renderable, const Matrix4& world ){ |
| 1479 | if ( m_state_stack.back().m_highlight & ePrimitive ) { |
| 1480 | m_state_select0->addRenderable( renderable, world, m_state_stack.back().m_lights ); |
| 1481 | } |
| 1482 | if ( m_state_stack.back().m_highlight & eFace ) { |
| 1483 | m_state_select1->addRenderable( renderable, world, m_state_stack.back().m_lights ); |
| 1484 | } |
| 1485 | |
| 1486 | m_state_stack.back().m_state->addRenderable( renderable, world, m_state_stack.back().m_lights ); |
| 1487 | } |
| 1488 | |
| 1489 | void render( const Matrix4& modelview, const Matrix4& projection ){ |
| 1490 | GlobalShaderCache().render( m_globalstate, modelview, projection, m_viewer ); |
| 1491 | } |
| 1492 | }; |
| 1493 | |
| 1494 | /* |
| 1495 | ============== |
| 1496 | Cam_Draw |
| 1497 | ============== |
| 1498 | */ |
| 1499 | /* |
| 1500 | void ShowStatsToggle(){ |
| 1501 | g_camwindow_globals_private.m_showStats ^= 1; |
| 1502 | } |
| 1503 | |
| 1504 | void ShowStatsExport( const Callback<void(bool)> &importer ){ |
| 1505 | importer( g_camwindow_globals_private.m_showStats ); |
| 1506 | } |
| 1507 | |
| 1508 | FreeCaller<void(const Callback<void(bool)>&), ShowStatsExport> g_show_stats_caller; |
| 1509 | Callback<void(const Callback<void(bool)> &)> g_show_stats_callback( g_show_stats_caller ); |
| 1510 | ToggleItem g_show_stats( g_show_stats_callback ); |
| 1511 | */ |
| 1512 | |
| 1513 | void ShowStatsToggle(){ |
| 1514 | g_camwindow_globals_private.m_showStats ^= 1; |
| 1515 | // g_show_stats.update(); |
| 1516 | UpdateAllWindows(); |
| 1517 | } |
| 1518 | typedef FreeCaller<void(), ShowStatsToggle> ShowStatsToggleCaller; |
| 1519 | void ShowStatsExport( const Callback<void(bool)> & importer ){ |
| 1520 | importer( g_camwindow_globals_private.m_showStats ); |
| 1521 | } |
| 1522 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowStatsExport> ShowStatsExportCaller; |
| 1523 | |
| 1524 | ShowStatsExportCaller g_show_stats_caller; |
| 1525 | Callback<void(const Callback<void(bool)> &)> g_show_stats_callback( g_show_stats_caller ); |
| 1526 | ToggleItem g_show_stats( g_show_stats_callback ); |
| 1527 | |
| 1528 | void CamWnd::Cam_Draw(){ |
| 1529 | glViewport( 0, 0, m_Camera.width, m_Camera.height ); |
| 1530 | #if 0 |
| 1531 | GLint viewprt[4]; |
| 1532 | glGetIntegerv( GL_VIEWPORT, viewprt ); |
| 1533 | #endif |
| 1534 | |
| 1535 | // enable depth buffer writes |
| 1536 | glDepthMask( GL_TRUE ); |
| 1537 | glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); |
| 1538 | |
| 1539 | Vector3 clearColour( 0, 0, 0 ); |
| 1540 | if ( m_Camera.draw_mode != cd_lighting ) { |
| 1541 | clearColour = g_camwindow_globals.color_cameraback; |
| 1542 | } |
| 1543 | |
| 1544 | glClearColor( clearColour[0], clearColour[1], clearColour[2], 0 ); |
| 1545 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
| 1546 | |
| 1547 | extern void Renderer_ResetStats(); |
| 1548 | Renderer_ResetStats(); |
| 1549 | extern void Cull_ResetStats(); |
| 1550 | Cull_ResetStats(); |
| 1551 | |
| 1552 | glMatrixMode( GL_PROJECTION ); |
| 1553 | glLoadMatrixf( reinterpret_cast<const float*>( &m_Camera.projection ) ); |
| 1554 | |
| 1555 | glMatrixMode( GL_MODELVIEW ); |
| 1556 | glLoadMatrixf( reinterpret_cast<const float*>( &m_Camera.modelview ) ); |
| 1557 | |
| 1558 | |
| 1559 | // one directional light source directly behind the viewer |
| 1560 | { |
| 1561 | GLfloat inverse_cam_dir[4], ambient[4], diffuse[4]; //, material[4]; |
| 1562 | |
| 1563 | ambient[0] = ambient[1] = ambient[2] = 0.4f; |
| 1564 | ambient[3] = 1.0f; |
| 1565 | diffuse[0] = diffuse[1] = diffuse[2] = 0.4f; |
| 1566 | diffuse[3] = 1.0f; |
| 1567 | //material[0] = material[1] = material[2] = 0.8f; |
| 1568 | //material[3] = 1.0f; |
| 1569 | |
| 1570 | inverse_cam_dir[0] = m_Camera.vpn[0]; |
| 1571 | inverse_cam_dir[1] = m_Camera.vpn[1]; |
| 1572 | inverse_cam_dir[2] = m_Camera.vpn[2]; |
| 1573 | inverse_cam_dir[3] = 0; |
| 1574 | |
| 1575 | glLightfv( GL_LIGHT0, GL_POSITION, inverse_cam_dir ); |
| 1576 | |
| 1577 | glLightfv( GL_LIGHT0, GL_AMBIENT, ambient ); |
| 1578 | glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse ); |
| 1579 | |
| 1580 | glEnable( GL_LIGHT0 ); |
| 1581 | } |
| 1582 | |
| 1583 | |
| 1584 | unsigned int globalstate = RENDER_DEPTHTEST | RENDER_COLOURWRITE | RENDER_DEPTHWRITE | RENDER_ALPHATEST | RENDER_BLEND | RENDER_CULLFACE | RENDER_COLOURARRAY | RENDER_OFFSETLINE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH | RENDER_FOG | RENDER_COLOURCHANGE; |
| 1585 | switch ( m_Camera.draw_mode ) |
| 1586 | { |
| 1587 | case cd_wire: |
| 1588 | break; |
| 1589 | case cd_solid: |
| 1590 | globalstate |= RENDER_FILL |
| 1591 | | RENDER_LIGHTING |
| 1592 | | RENDER_SMOOTH |
| 1593 | | RENDER_SCALED; |
| 1594 | break; |
| 1595 | case cd_texture: |
| 1596 | globalstate |= RENDER_FILL |
| 1597 | | RENDER_LIGHTING |
| 1598 | | RENDER_TEXTURE |
| 1599 | | RENDER_SMOOTH |
| 1600 | | RENDER_SCALED; |
| 1601 | break; |
| 1602 | case cd_lighting: |
| 1603 | globalstate |= RENDER_FILL |
| 1604 | | RENDER_LIGHTING |
| 1605 | | RENDER_TEXTURE |
| 1606 | | RENDER_SMOOTH |
| 1607 | | RENDER_SCALED |
| 1608 | | RENDER_BUMP |
| 1609 | | RENDER_PROGRAM |
| 1610 | | RENDER_SCREEN; |
| 1611 | break; |
| 1612 | default: |
| 1613 | globalstate = 0; |
| 1614 | break; |
| 1615 | } |
| 1616 | |
| 1617 | // if ( !g_xywindow_globals.m_bNoStipple ) { |
| 1618 | globalstate |= RENDER_LINESTIPPLE | RENDER_POLYGONSTIPPLE; |
| 1619 | // } |
| 1620 | |
| 1621 | { |
| 1622 | CamRenderer renderer( globalstate, m_state_select2, m_state_select1, m_view.getViewer() ); |
| 1623 | |
| 1624 | Scene_Render( renderer, m_view ); |
| 1625 | |
| 1626 | renderer.render( m_Camera.modelview, m_Camera.projection ); |
| 1627 | } |
| 1628 | |
| 1629 | // prepare for 2d stuff |
| 1630 | glColor4f( 1, 1, 1, 1 ); |
| 1631 | glDisable( GL_BLEND ); |
| 1632 | glMatrixMode( GL_PROJECTION ); |
| 1633 | glLoadIdentity(); |
| 1634 | glOrtho( 0, (float)m_Camera.width, 0, (float)m_Camera.height, -100, 100 ); |
| 1635 | glScalef( 1, -1, 1 ); |
| 1636 | glTranslatef( 0, -(float)m_Camera.height, 0 ); |
| 1637 | glMatrixMode( GL_MODELVIEW ); |
| 1638 | glLoadIdentity(); |
| 1639 | |
| 1640 | if ( GlobalOpenGL().GL_1_3() ) { |
| 1641 | glClientActiveTexture( GL_TEXTURE0 ); |
| 1642 | glActiveTexture( GL_TEXTURE0 ); |
| 1643 | } |
| 1644 | |
| 1645 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); |
| 1646 | glDisableClientState( GL_NORMAL_ARRAY ); |
| 1647 | glDisableClientState( GL_COLOR_ARRAY ); |
| 1648 | |
| 1649 | glDisable( GL_TEXTURE_2D ); |
| 1650 | glDisable( GL_LIGHTING ); |
| 1651 | glDisable( GL_COLOR_MATERIAL ); |
| 1652 | glDisable( GL_DEPTH_TEST ); |
| 1653 | glColor3f( 1.f, 1.f, 1.f ); |
| 1654 | glLineWidth( 1 ); |
| 1655 | |
| 1656 | // draw the crosshair |
| 1657 | if ( m_bFreeMove ) { |
| 1658 | glBegin( GL_LINES ); |
| 1659 | glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f + 6 ); |
| 1660 | glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f + 2 ); |
| 1661 | glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f - 6 ); |
| 1662 | glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f - 2 ); |
| 1663 | glVertex2f( (float)m_Camera.width / 2.f + 6, (float)m_Camera.height / 2.f ); |
| 1664 | glVertex2f( (float)m_Camera.width / 2.f + 2, (float)m_Camera.height / 2.f ); |
| 1665 | glVertex2f( (float)m_Camera.width / 2.f - 6, (float)m_Camera.height / 2.f ); |
| 1666 | glVertex2f( (float)m_Camera.width / 2.f - 2, (float)m_Camera.height / 2.f ); |
| 1667 | glEnd(); |
| 1668 | } |
| 1669 | |
| 1670 | if ( g_camwindow_globals_private.m_showStats ) { |
| 1671 | glRasterPos3f( 1.0f, static_cast<float>( m_Camera.height ) - GlobalOpenGL().m_font->getPixelDescent(), 0.0f ); |
| 1672 | extern const char* Renderer_GetStats(); |
| 1673 | GlobalOpenGL().drawString( Renderer_GetStats() ); |
| 1674 | |
| 1675 | glRasterPos3f( 1.0f, static_cast<float>( m_Camera.height ) - GlobalOpenGL().m_font->getPixelDescent() - GlobalOpenGL().m_font->getPixelHeight(), 0.0f ); |
| 1676 | extern const char* Cull_GetStats(); |
| 1677 | GlobalOpenGL().drawString( Cull_GetStats() ); |
| 1678 | } |
| 1679 | |
| 1680 | // bind back to the default texture so that we don't have problems |
| 1681 | // elsewhere using/modifying texture maps between contexts |
| 1682 | glBindTexture( GL_TEXTURE_2D, 0 ); |
| 1683 | } |
| 1684 | |
| 1685 | void CamWnd::draw(){ |
| 1686 | m_drawing = true; |
| 1687 | |
| 1688 | //globalOutputStream() << "draw...\n"; |
| 1689 | if ( glwidget_make_current( m_gl_widget ) != FALSE ) { |
| 1690 | if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) { |
| 1691 | GlobalOpenGL_debugAssertNoErrors(); |
| 1692 | Cam_Draw(); |
| 1693 | GlobalOpenGL_debugAssertNoErrors(); |
| 1694 | //qglFinish(); |
| 1695 | |
| 1696 | m_XORRectangle.set( rectangle_t() ); |
| 1697 | } |
| 1698 | |
| 1699 | glwidget_swap_buffers( m_gl_widget ); |
| 1700 | } |
| 1701 | |
| 1702 | m_drawing = false; |
| 1703 | } |
| 1704 | |
| 1705 | void CamWnd::BenchMark(){ |
| 1706 | double dStart = Sys_DoubleTime(); |
| 1707 | for ( int i = 0 ; i < 100 ; i++ ) |
| 1708 | { |
| 1709 | Vector3 angles; |
| 1710 | angles[CAMERA_ROLL] = 0; |
| 1711 | angles[CAMERA_PITCH] = 0; |
| 1712 | angles[CAMERA_YAW] = i * 360.0f / 100.0f; |
| 1713 | Camera_setAngles( *this, angles ); |
| 1714 | } |
| 1715 | double dEnd = Sys_DoubleTime(); |
| 1716 | globalOutputStream() << FloatFormat( dEnd - dStart, 5, 2 ) << " seconds\n"; |
| 1717 | } |
| 1718 | |
| 1719 | |
| 1720 | void GlobalCamera_ResetAngles(){ |
| 1721 | CamWnd& camwnd = *g_camwnd; |
| 1722 | Vector3 angles; |
| 1723 | angles[CAMERA_ROLL] = angles[CAMERA_PITCH] = 0; |
| 1724 | angles[CAMERA_YAW] = 22.5f * floorf( ( Camera_getAngles( camwnd )[CAMERA_YAW] + 11 ) / 22.5f ); |
| 1725 | Camera_setAngles( camwnd, angles ); |
| 1726 | } |
| 1727 | |
| 1728 | #include "select.h" |
| 1729 | |
| 1730 | Vector3 Camera_getFocusPos( camera_t& camera ){ |
| 1731 | Vector3 camorigin( Camera_getOrigin( camera ) ); |
| 1732 | AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) ); |
| 1733 | View& view = *( camera.m_view ); |
| 1734 | #if 0 |
| 1735 | Vector3 angles( Camera_getAngles( camera ) ); |
| 1736 | Vector3 radangles( degrees_to_radians( angles[0] ), degrees_to_radians( angles[1] ), degrees_to_radians( angles[2] ) ); |
| 1737 | Vector3 viewvector; |
| 1738 | viewvector[0] = cos( radangles[1] ) * cos( radangles[0] ); |
| 1739 | viewvector[1] = sin( radangles[1] ) * cos( radangles[0] ); |
| 1740 | viewvector[2] = sin( radangles[0] ); |
| 1741 | #elif 0 |
| 1742 | Vector3 viewvector( -view.GetModelview()[2], -view.GetModelview()[6], -view.GetModelview()[10] ); |
| 1743 | #elif 1 |
| 1744 | Vector3 viewvector( -camera.vpn ); |
| 1745 | #endif |
| 1746 | |
| 1747 | Plane3 frustumPlanes[4]; |
| 1748 | frustumPlanes[0] = plane3_translated( view.getFrustum().left, camorigin - aabb.origin ); |
| 1749 | frustumPlanes[1] = plane3_translated( view.getFrustum().right, camorigin - aabb.origin ); |
| 1750 | frustumPlanes[2] = plane3_translated( view.getFrustum().top, camorigin - aabb.origin ); |
| 1751 | frustumPlanes[3] = plane3_translated( view.getFrustum().bottom, camorigin - aabb.origin ); |
| 1752 | |
| 1753 | float offset = 64.0f; |
| 1754 | |
| 1755 | Vector3 corners[8]; |
| 1756 | aabb_corners( aabb, corners ); |
| 1757 | |
| 1758 | for ( size_t i = 0; i < 4; ++i ){ |
| 1759 | for ( size_t j = 0; j < 8; ++j ){ |
| 1760 | Ray ray( aabb.origin, -viewvector ); |
| 1761 | //Plane3 newplane( frustumPlanes[i].normal(), vector3_dot( frustumPlanes[i].normal(), corners[j] - frustumPlanes[i].normal() * 16.0f ) ); |
| 1762 | Plane3 newplane( frustumPlanes[i].normal(), vector3_dot( frustumPlanes[i].normal(), corners[j] ) ); |
| 1763 | float d = vector3_dot( ray.direction, newplane.normal() ); |
| 1764 | if( d != 0 ){ |
| 1765 | float s = vector3_dot( newplane.normal() * newplane.dist() - ray.origin, newplane.normal() ) / d; |
| 1766 | offset = std::max( offset, s ); |
| 1767 | } |
| 1768 | } |
| 1769 | } |
| 1770 | return ( aabb.origin - viewvector * offset ); |
| 1771 | } |
| 1772 | |
| 1773 | void GlobalCamera_FocusOnSelected(){ |
| 1774 | Camera_setOrigin( *g_camwnd, Camera_getFocusPos( g_camwnd->getCamera() ) ); |
| 1775 | } |
| 1776 | |
| 1777 | void Camera_ChangeFloorUp(){ |
| 1778 | CamWnd& camwnd = *g_camwnd; |
| 1779 | camwnd.Cam_ChangeFloor( true ); |
| 1780 | } |
| 1781 | |
| 1782 | void Camera_ChangeFloorDown(){ |
| 1783 | CamWnd& camwnd = *g_camwnd; |
| 1784 | camwnd.Cam_ChangeFloor( false ); |
| 1785 | } |
| 1786 | |
| 1787 | void Camera_CubeIn(){ |
| 1788 | CamWnd& camwnd = *g_camwnd; |
| 1789 | g_camwindow_globals.m_nCubicScale--; |
| 1790 | if ( g_camwindow_globals.m_nCubicScale < 1 ) { |
| 1791 | g_camwindow_globals.m_nCubicScale = 1; |
| 1792 | } |
| 1793 | Camera_updateProjection( camwnd.getCamera() ); |
| 1794 | CamWnd_Update( camwnd ); |
| 1795 | g_pParentWnd->SetGridStatus(); |
| 1796 | } |
| 1797 | |
| 1798 | void Camera_CubeOut(){ |
| 1799 | CamWnd& camwnd = *g_camwnd; |
| 1800 | g_camwindow_globals.m_nCubicScale++; |
| 1801 | if ( g_camwindow_globals.m_nCubicScale > 46 ) { |
| 1802 | g_camwindow_globals.m_nCubicScale = 46; |
| 1803 | } |
| 1804 | Camera_updateProjection( camwnd.getCamera() ); |
| 1805 | CamWnd_Update( camwnd ); |
| 1806 | g_pParentWnd->SetGridStatus(); |
| 1807 | } |
| 1808 | |
| 1809 | bool Camera_GetFarClip(){ |
| 1810 | return g_camwindow_globals_private.m_bCubicClipping; |
| 1811 | } |
| 1812 | |
| 1813 | ConstReferenceCaller<bool, void(const Callback<void(bool)> &), PropertyImpl<bool>::Export> g_getfarclip_caller( g_camwindow_globals_private.m_bCubicClipping ); |
| 1814 | ToggleItem g_getfarclip_item( g_getfarclip_caller ); |
| 1815 | |
| 1816 | void Camera_SetFarClip( bool value ){ |
| 1817 | CamWnd& camwnd = *g_camwnd; |
| 1818 | g_camwindow_globals_private.m_bCubicClipping = value; |
| 1819 | g_getfarclip_item.update(); |
| 1820 | Camera_updateProjection( camwnd.getCamera() ); |
| 1821 | CamWnd_Update( camwnd ); |
| 1822 | } |
| 1823 | |
| 1824 | struct Camera_FarClip { |
| 1825 | static void Export(const Callback<void(bool)> &returnz) { |
| 1826 | returnz(g_camwindow_globals_private.m_bCubicClipping); |
| 1827 | } |
| 1828 | |
| 1829 | static void Import(bool value) { |
| 1830 | Camera_SetFarClip(value); |
| 1831 | } |
| 1832 | }; |
| 1833 | |
| 1834 | void Camera_ToggleFarClip(){ |
| 1835 | Camera_SetFarClip( !Camera_GetFarClip() ); |
| 1836 | } |
| 1837 | |
| 1838 | |
| 1839 | void CamWnd_constructToolbar( ui::Toolbar toolbar ){ |
| 1840 | toolbar_append_toggle_button( toolbar, "Cubic clip the camera view (Ctrl + \\)", "view_cubicclipping.png", "ToggleCubicClip" ); |
| 1841 | } |
| 1842 | |
| 1843 | void CamWnd_registerShortcuts(){ |
| 1844 | toggle_add_accelerator( "ToggleCubicClip" ); |
| 1845 | |
| 1846 | if ( g_pGameDescription->mGameType == "doom3" ) { |
| 1847 | command_connect_accelerator( "TogglePreview" ); |
| 1848 | } |
| 1849 | |
| 1850 | command_connect_accelerator( "FOVInc" ); |
| 1851 | command_connect_accelerator( "FOVDec" ); |
| 1852 | command_connect_accelerator( "CameraSpeedInc" ); |
| 1853 | command_connect_accelerator( "CameraSpeedDec" ); |
| 1854 | } |
| 1855 | |
| 1856 | |
| 1857 | void GlobalCamera_Benchmark(){ |
| 1858 | CamWnd& camwnd = *g_camwnd; |
| 1859 | camwnd.BenchMark(); |
| 1860 | } |
| 1861 | |
| 1862 | void GlobalCamera_Update(){ |
| 1863 | CamWnd& camwnd = *g_camwnd; |
| 1864 | CamWnd_Update( camwnd ); |
| 1865 | } |
| 1866 | |
| 1867 | camera_draw_mode CamWnd_GetMode(){ |
| 1868 | return camera_t::draw_mode; |
| 1869 | } |
| 1870 | void CamWnd_SetMode( camera_draw_mode mode ){ |
| 1871 | ShaderCache_setBumpEnabled( mode == cd_lighting ); |
| 1872 | camera_t::draw_mode = mode; |
| 1873 | if ( g_camwnd != 0 ) { |
| 1874 | CamWnd_Update( *g_camwnd ); |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | void CamWnd_TogglePreview( void ){ |
| 1879 | // gametype must be doom3 for this function to work |
| 1880 | // if the gametype is not doom3 something is wrong with the |
| 1881 | // global command list or somebody else calls this function. |
| 1882 | ASSERT_MESSAGE( g_pGameDescription->mGameType == "doom3", "CamWnd_TogglePreview called although mGameType is not doom3 compatible" ); |
| 1883 | |
| 1884 | // switch between textured and lighting mode |
| 1885 | CamWnd_SetMode( ( CamWnd_GetMode() == cd_lighting ) ? cd_texture : cd_lighting ); |
| 1886 | } |
| 1887 | |
| 1888 | |
| 1889 | CameraModel* g_camera_model = 0; |
| 1890 | |
| 1891 | void CamWnd_LookThroughCamera( CamWnd& camwnd ){ |
| 1892 | if ( g_camera_model != 0 ) { |
| 1893 | CamWnd_Add_Handlers_Move( camwnd ); |
| 1894 | g_camera_model->setCameraView( 0, Callback<void()>() ); |
| 1895 | g_camera_model = 0; |
| 1896 | Camera_updateModelview( camwnd.getCamera() ); |
| 1897 | Camera_updateProjection( camwnd.getCamera() ); |
| 1898 | CamWnd_Update( camwnd ); |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | inline CameraModel* Instance_getCameraModel( scene::Instance& instance ){ |
| 1903 | return InstanceTypeCast<CameraModel>::cast( instance ); |
| 1904 | } |
| 1905 | |
| 1906 | void CamWnd_LookThroughSelected( CamWnd& camwnd ){ |
| 1907 | if ( g_camera_model != 0 ) { |
| 1908 | CamWnd_LookThroughCamera( camwnd ); |
| 1909 | } |
| 1910 | |
| 1911 | if ( GlobalSelectionSystem().countSelected() != 0 ) { |
| 1912 | scene::Instance& instance = GlobalSelectionSystem().ultimateSelected(); |
| 1913 | CameraModel* cameraModel = Instance_getCameraModel( instance ); |
| 1914 | if ( cameraModel != 0 ) { |
| 1915 | CamWnd_Remove_Handlers_Move( camwnd ); |
| 1916 | g_camera_model = cameraModel; |
| 1917 | g_camera_model->setCameraView( &camwnd.getCameraView(), ReferenceCaller<CamWnd, void(), CamWnd_LookThroughCamera>( camwnd ) ); |
| 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | void GlobalCamera_LookThroughSelected(){ |
| 1923 | CamWnd_LookThroughSelected( *g_camwnd ); |
| 1924 | } |
| 1925 | |
| 1926 | void GlobalCamera_LookThroughCamera(){ |
| 1927 | CamWnd_LookThroughCamera( *g_camwnd ); |
| 1928 | } |
| 1929 | |
| 1930 | struct RenderMode { |
| 1931 | static void Export(const Callback<void(int)> &returnz) { |
| 1932 | switch (CamWnd_GetMode()) { |
| 1933 | case cd_wire: |
| 1934 | returnz(0); |
| 1935 | break; |
| 1936 | case cd_solid: |
| 1937 | returnz(1); |
| 1938 | break; |
| 1939 | case cd_texture: |
| 1940 | returnz(2); |
| 1941 | break; |
| 1942 | case cd_lighting: |
| 1943 | returnz(3); |
| 1944 | break; |
| 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | static void Import(int value) { |
| 1949 | switch (value) { |
| 1950 | case 0: |
| 1951 | CamWnd_SetMode( cd_wire ); |
| 1952 | break; |
| 1953 | case 1: |
| 1954 | CamWnd_SetMode( cd_solid ); |
| 1955 | break; |
| 1956 | case 2: |
| 1957 | CamWnd_SetMode( cd_texture ); |
| 1958 | break; |
| 1959 | case 3: |
| 1960 | CamWnd_SetMode( cd_lighting ); |
| 1961 | break; |
| 1962 | default: |
| 1963 | CamWnd_SetMode( cd_texture ); |
| 1964 | } |
| 1965 | } |
| 1966 | }; |
| 1967 | |
| 1968 | void Camera_constructPreferences( PreferencesPage& page ){ |
| 1969 | page.appendSlider( "FOV", g_camwindow_globals_private.m_nFOV, TRUE, 0, 0, 100, MIN_FOV, MAX_FOV, 1, 10 ); |
| 1970 | page.appendSlider( "Movement Speed", g_camwindow_globals_private.m_nMoveSpeed, TRUE, 0, 0, 100, MIN_CAM_SPEED, MAX_CAM_SPEED, 1, 10 ); |
| 1971 | page.appendCheckBox( "", "Link strafe speed to movement speed", g_camwindow_globals_private.m_bCamLinkSpeed ); |
| 1972 | page.appendSlider( "Rotation Speed", g_camwindow_globals_private.m_nAngleSpeed, TRUE, 0, 0, 3, 1, 180, 1, 10 ); |
| 1973 | page.appendCheckBox( "", "Invert mouse vertical axis", g_camwindow_globals_private.m_bCamInverseMouse ); |
| 1974 | page.appendCheckBox( "", "Zoom In to Mouse pointer", g_camwindow_globals.m_bZoomInToPointer ); |
| 1975 | page.appendCheckBox( |
| 1976 | "", "Discrete movement", |
| 1977 | make_property<CamWnd_Move_Discrete>() |
| 1978 | ); |
| 1979 | page.appendCheckBox( |
| 1980 | "", "Enable far-clip plane", |
| 1981 | make_property<Camera_FarClip>() |
| 1982 | ); |
| 1983 | |
| 1984 | if ( g_pGameDescription->mGameType == "doom3" ) { |
| 1985 | const char* render_mode[] = { "Wireframe", "Flatshade", "Textured", "Lighting" }; |
| 1986 | |
| 1987 | page.appendCombo( |
| 1988 | "Render Mode", |
| 1989 | STRING_ARRAY_RANGE( render_mode ), |
| 1990 | make_property<RenderMode>() |
| 1991 | ); |
| 1992 | } |
| 1993 | else |
| 1994 | { |
| 1995 | const char* render_mode[] = { "Wireframe", "Flatshade", "Textured" }; |
| 1996 | |
| 1997 | page.appendCombo( |
| 1998 | "Render Mode", |
| 1999 | STRING_ARRAY_RANGE( render_mode ), |
| 2000 | make_property<RenderMode>() |
| 2001 | ); |
| 2002 | } |
| 2003 | |
| 2004 | const char* strafe_mode[] = { "None", "Up", "Forward", "Both", "Both Inverted" }; |
| 2005 | |
| 2006 | page.appendCombo( |
| 2007 | "Strafe Mode", |
| 2008 | g_camwindow_globals_private.m_nStrafeMode, |
| 2009 | STRING_ARRAY_RANGE( strafe_mode ) |
| 2010 | ); |
| 2011 | } |
| 2012 | void Camera_constructPage( PreferenceGroup& group ){ |
| 2013 | PreferencesPage page( group.createPage( "Camera", "Camera View Preferences" ) ); |
| 2014 | Camera_constructPreferences( page ); |
| 2015 | } |
| 2016 | void Camera_registerPreferencesPage(){ |
| 2017 | PreferencesDialog_addSettingsPage( makeCallbackF(Camera_constructPage) ); |
| 2018 | } |
| 2019 | |
| 2020 | #include "preferencesystem.h" |
| 2021 | #include "stringio.h" |
| 2022 | #include "dialog.h" |
| 2023 | |
| 2024 | void FOV_increase(){ |
| 2025 | CamWnd& camwnd = *g_camwnd; |
| 2026 | if ( g_camwindow_globals_private.m_nFOV <= ( MAX_FOV - FOV_STEP - 10 ) ) { |
| 2027 | g_camwindow_globals_private.m_nFOV += FOV_STEP; |
| 2028 | } |
| 2029 | else { |
| 2030 | g_camwindow_globals_private.m_nFOV = MAX_FOV - 10; |
| 2031 | } |
| 2032 | Camera_updateProjection( camwnd.getCamera() ); |
| 2033 | CamWnd_Update( camwnd ); |
| 2034 | } |
| 2035 | |
| 2036 | void FOV_decrease(){ |
| 2037 | CamWnd& camwnd = *g_camwnd; |
| 2038 | if ( g_camwindow_globals_private.m_nFOV >= ( MIN_FOV + FOV_STEP ) ) { |
| 2039 | g_camwindow_globals_private.m_nFOV -= FOV_STEP; |
| 2040 | } |
| 2041 | else { |
| 2042 | g_camwindow_globals_private.m_nFOV = MIN_FOV; |
| 2043 | } |
| 2044 | Camera_updateProjection( camwnd.getCamera() ); |
| 2045 | CamWnd_Update( camwnd ); |
| 2046 | } |
| 2047 | |
| 2048 | |
| 2049 | void CameraSpeed_increase(){ |
| 2050 | if ( g_camwindow_globals_private.m_nMoveSpeed <= ( MAX_CAM_SPEED - CAM_SPEED_STEP - 10 ) ) { |
| 2051 | g_camwindow_globals_private.m_nMoveSpeed += CAM_SPEED_STEP; |
| 2052 | } |
| 2053 | else { |
| 2054 | g_camwindow_globals_private.m_nMoveSpeed = MAX_CAM_SPEED - 10; |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | void CameraSpeed_decrease(){ |
| 2059 | if ( g_camwindow_globals_private.m_nMoveSpeed >= ( MIN_CAM_SPEED + CAM_SPEED_STEP ) ) { |
| 2060 | g_camwindow_globals_private.m_nMoveSpeed -= CAM_SPEED_STEP; |
| 2061 | } |
| 2062 | else { |
| 2063 | g_camwindow_globals_private.m_nMoveSpeed = MIN_CAM_SPEED; |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | /// \brief Initialisation for things that have the same lifespan as this module. |
| 2068 | void CamWnd_Construct(){ |
| 2069 | GlobalCommands_insert( "CenterView", makeCallbackF(GlobalCamera_ResetAngles), Accelerator( GDK_KEY_End ) ); |
| 2070 | GlobalCommands_insert( "CameraFocusOnSelected", makeCallbackF( GlobalCamera_FocusOnSelected ), Accelerator( GDK_KEY_Tab ) ); |
| 2071 | |
| 2072 | GlobalToggles_insert( "ToggleCubicClip", makeCallbackF(Camera_ToggleFarClip), ToggleItem::AddCallbackCaller( g_getfarclip_item ), Accelerator( '\\', (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 2073 | GlobalCommands_insert( "CubicClipZoomIn", makeCallbackF(Camera_CubeIn), Accelerator( '[', (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 2074 | GlobalCommands_insert( "CubicClipZoomOut", makeCallbackF(Camera_CubeOut), Accelerator( ']', (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 2075 | |
| 2076 | GlobalCommands_insert( "UpFloor", makeCallbackF(Camera_ChangeFloorUp), Accelerator( GDK_KEY_Prior ) ); |
| 2077 | GlobalCommands_insert( "DownFloor", makeCallbackF(Camera_ChangeFloorDown), Accelerator( GDK_KEY_Next ) ); |
| 2078 | |
| 2079 | GlobalToggles_insert( "ToggleCamera", ToggleShown::ToggleCaller( g_camera_shown ), ToggleItem::AddCallbackCaller( g_camera_shown.m_item ), Accelerator( 'C', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); |
| 2080 | // GlobalCommands_insert( "LookThroughSelected", makeCallbackF(GlobalCamera_LookThroughSelected) ); |
| 2081 | // GlobalCommands_insert( "LookThroughCamera", makeCallbackF(GlobalCamera_LookThroughCamera) ); |
| 2082 | |
| 2083 | if ( g_pGameDescription->mGameType == "doom3" ) { |
| 2084 | GlobalCommands_insert( "TogglePreview", makeCallbackF(CamWnd_TogglePreview), Accelerator( GDK_KEY_F3 ) ); |
| 2085 | } |
| 2086 | |
| 2087 | GlobalCommands_insert( "FOVInc", makeCallbackF(FOV_increase), Accelerator( GDK_KEY_KP_Multiply, (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 2088 | GlobalCommands_insert( "FOVDec", makeCallbackF(FOV_decrease), Accelerator( GDK_KEY_KP_Divide, (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 2089 | |
| 2090 | GlobalCommands_insert( "CameraSpeedInc", makeCallbackF(CameraSpeed_increase), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 2091 | GlobalCommands_insert( "CameraSpeedDec", makeCallbackF(CameraSpeed_decrease), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 2092 | |
| 2093 | GlobalShortcuts_insert( "CameraForward", Accelerator( GDK_KEY_Up ) ); |
| 2094 | GlobalShortcuts_insert( "CameraBack", Accelerator( GDK_KEY_Down ) ); |
| 2095 | GlobalShortcuts_insert( "CameraLeft", Accelerator( GDK_KEY_Left ) ); |
| 2096 | GlobalShortcuts_insert( "CameraRight", Accelerator( GDK_KEY_Right ) ); |
| 2097 | GlobalShortcuts_insert( "CameraStrafeRight", Accelerator( 'D' ) ); |
| 2098 | GlobalShortcuts_insert( "CameraStrafeLeft", Accelerator( 'A' ) ); |
| 2099 | |
| 2100 | GlobalShortcuts_insert( "CameraUp", accelerator_null() ); |
| 2101 | GlobalShortcuts_insert( "CameraDown", accelerator_null() ); |
| 2102 | GlobalShortcuts_insert( "CameraAngleUp", accelerator_null() ); |
| 2103 | GlobalShortcuts_insert( "CameraAngleDown", accelerator_null() ); |
| 2104 | |
| 2105 | GlobalShortcuts_insert( "CameraFreeMoveForward", Accelerator( 'W' ) ); |
| 2106 | GlobalShortcuts_insert( "CameraFreeMoveBack", Accelerator( 'S' ) ); |
| 2107 | GlobalShortcuts_insert( "CameraFreeMoveLeft", Accelerator( 'A' ) ); |
| 2108 | GlobalShortcuts_insert( "CameraFreeMoveRight", Accelerator( 'D' ) ); |
| 2109 | |
| 2110 | GlobalShortcuts_insert( "CameraFreeMoveForward2", Accelerator( GDK_KEY_Up ) ); |
| 2111 | GlobalShortcuts_insert( "CameraFreeMoveBack2", Accelerator( GDK_KEY_Down ) ); |
| 2112 | GlobalShortcuts_insert( "CameraFreeMoveLeft2", Accelerator( GDK_KEY_Left ) ); |
| 2113 | GlobalShortcuts_insert( "CameraFreeMoveRight2", Accelerator( GDK_KEY_Right ) ); |
| 2114 | |
| 2115 | GlobalShortcuts_insert( "CameraFreeMoveUp", accelerator_null() ); |
| 2116 | GlobalShortcuts_insert( "CameraFreeMoveDown", accelerator_null() ); |
| 2117 | |
| 2118 | GlobalShortcuts_insert( "CameraFreeFocus", Accelerator( GDK_KEY_Tab ) ); |
| 2119 | |
| 2120 | GlobalToggles_insert( "ShowStats", makeCallbackF(ShowStatsToggle), ToggleItem::AddCallbackCaller( g_show_stats ) ); |
| 2121 | |
| 2122 | GlobalPreferenceSystem().registerPreference( "ShowStats", make_property_string( g_camwindow_globals_private.m_showStats ) ); |
| 2123 | GlobalPreferenceSystem().registerPreference( "FOV", make_property_string( g_camwindow_globals_private.m_nFOV ) ); |
| 2124 | GlobalPreferenceSystem().registerPreference( "MoveSpeed", make_property_string( g_camwindow_globals_private.m_nMoveSpeed ) ); |
| 2125 | GlobalPreferenceSystem().registerPreference( "CamLinkSpeed", make_property_string( g_camwindow_globals_private.m_bCamLinkSpeed ) ); |
| 2126 | GlobalPreferenceSystem().registerPreference( "AngleSpeed", make_property_string( g_camwindow_globals_private.m_nAngleSpeed ) ); |
| 2127 | GlobalPreferenceSystem().registerPreference( "CamInverseMouse", make_property_string( g_camwindow_globals_private.m_bCamInverseMouse ) ); |
| 2128 | GlobalPreferenceSystem().registerPreference( "CamDiscrete", make_property_string<CamWnd_Move_Discrete>()); |
| 2129 | GlobalPreferenceSystem().registerPreference( "CubicClipping", make_property_string( g_camwindow_globals_private.m_bCubicClipping ) ); |
| 2130 | GlobalPreferenceSystem().registerPreference( "CubicScale", make_property_string( g_camwindow_globals.m_nCubicScale ) ); |
| 2131 | GlobalPreferenceSystem().registerPreference( "SI_Colors4", make_property_string( g_camwindow_globals.color_cameraback ) ); |
| 2132 | GlobalPreferenceSystem().registerPreference( "SI_Colors12", make_property_string( g_camwindow_globals.color_selbrushes3d ) ); |
| 2133 | GlobalPreferenceSystem().registerPreference( "CameraRenderMode", make_property_string<RenderMode>() ); |
| 2134 | GlobalPreferenceSystem().registerPreference( "StrafeMode", make_property_string( g_camwindow_globals_private.m_nStrafeMode ) ); |
| 2135 | GlobalPreferenceSystem().registerPreference( "3DZoomInToPointer", make_property_string( g_camwindow_globals.m_bZoomInToPointer ) ); |
| 2136 | |
| 2137 | CamWnd_constructStatic(); |
| 2138 | |
| 2139 | Camera_registerPreferencesPage(); |
| 2140 | } |
| 2141 | void CamWnd_Destroy(){ |
| 2142 | CamWnd_destroyStatic(); |
| 2143 | } |