2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
25 // Leonardo Zide (leo@lokigames.com)
28 #include "camwindow.h"
31 #include <gdk/gdkkeysyms.h>
33 #include "debugging/debugging.h"
35 #include "iscenegraph.h"
40 #include "renderable.h"
41 #include "preferencesystem.h"
43 #include "signal/signal.h"
44 #include "container/array.h"
48 #include "math/frustum.h"
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"
56 #include "selection.h"
57 #include "mainframe.h"
58 #include "preferences.h"
61 #include "windowobservers.h"
62 #include "renderstate.h"
66 Signal0 g_cameraMoved_callbacks;
68 void AddCameraMovedCallback( const SignalHandler& handler ){
69 g_cameraMoved_callbacks.connectLast( handler );
72 void CameraMovedNotify(){
73 g_cameraMoved_callbacks();
77 struct camwindow_globals_private_t
82 bool m_bCamInverseMouse;
84 bool m_bCubicClipping;
88 camwindow_globals_private_t() :
90 m_bCamLinkSpeed( true ),
92 m_bCamInverseMouse( false ),
93 m_bCamDiscrete( true ),
94 m_bCubicClipping( true ),
101 camwindow_globals_private_t g_camwindow_globals_private;
104 const Matrix4 g_opengl2radiant(
111 const Matrix4 g_radiant2opengl(
119 void Camera_mouseMove( camera_t& camera, int x, int y );
121 enum camera_draw_mode
138 Vector3 color; // background
140 Vector3 forward, right; // move matrix (TTimo: used to have up but it was not updated)
141 Vector3 vup, vpn, vright; // view matrix (taken from the modelview matrix)
146 bool m_strafe; // true when in strafemode toggled by the ctrl-key
147 bool m_strafe_forward; // true when in strafemode by ctrl-key and shift is pressed for forward strafing
149 unsigned int movementflags; // movement flags
150 Timer m_keycontrol_timer;
151 guint m_keymove_handler;
156 DeferredMotionDelta m_mouseMove;
158 static void motionDelta( int x, int y, void* data ){
159 Camera_mouseMove( *reinterpret_cast<camera_t*>( data ), x, y );
165 static camera_draw_mode draw_mode;
167 camera_t( View* view, const Callback& update )
175 m_keymove_handler( 0 ),
176 fieldOfView( 90.0f ),
177 m_mouseMove( motionDelta, this ),
183 camera_draw_mode camera_t::draw_mode = cd_texture;
185 inline Matrix4 projection_for_camera( float near_z, float far_z, float fieldOfView, int width, int height ){
186 const float half_width = static_cast<float>( near_z * tan( degrees_to_radians( fieldOfView * 0.5 ) ) );
187 const float half_height = half_width * ( static_cast<float>( height ) / static_cast<float>( width ) );
189 return matrix4_frustum(
199 float Camera_getFarClipPlane( camera_t& camera ){
200 return ( g_camwindow_globals_private.m_bCubicClipping ) ? pow( 2.0, ( g_camwindow_globals.m_nCubicScale + 7 ) / 2.0 ) : 32768.0f;
203 void Camera_updateProjection( camera_t& camera ){
204 float farClip = Camera_getFarClipPlane( camera );
205 camera.projection = projection_for_camera( farClip / 4096.0f, farClip, camera.fieldOfView, camera.width, camera.height );
207 camera.m_view->Construct( camera.projection, camera.modelview, camera.width, camera.height );
210 void Camera_updateVectors( camera_t& camera ){
211 for ( int i = 0 ; i < 3 ; i++ )
213 camera.vright[i] = camera.modelview[( i << 2 ) + 0];
214 camera.vup[i] = camera.modelview[( i << 2 ) + 1];
215 camera.vpn[i] = camera.modelview[( i << 2 ) + 2];
219 void Camera_updateModelview( camera_t& camera ){
220 camera.modelview = g_matrix4_identity;
223 Vector3 radiant_eulerXYZ( 0, -camera.angles[CAMERA_PITCH], camera.angles[CAMERA_YAW] );
225 matrix4_translate_by_vec3( camera.modelview, camera.origin );
226 matrix4_rotate_by_euler_xyz_degrees( camera.modelview, radiant_eulerXYZ );
227 matrix4_multiply_by_matrix4( camera.modelview, g_radiant2opengl );
228 matrix4_affine_invert( camera.modelview );
230 Camera_updateVectors( camera );
232 camera.m_view->Construct( camera.projection, camera.modelview, camera.width, camera.height );
236 void Camera_Move_updateAxes( camera_t& camera ){
237 double ya = degrees_to_radians( camera.angles[CAMERA_YAW] );
239 // the movement matrix is kept 2d
240 camera.forward[0] = static_cast<float>( cos( ya ) );
241 camera.forward[1] = static_cast<float>( sin( ya ) );
242 camera.forward[2] = 0;
243 camera.right[0] = camera.forward[1];
244 camera.right[1] = -camera.forward[0];
247 void Camera_Freemove_updateAxes( camera_t& camera ){
248 camera.right = camera.vright;
249 camera.forward = vector3_negated( camera.vpn );
252 const Vector3& Camera_getOrigin( camera_t& camera ){
253 return camera.origin;
256 void Camera_setOrigin( camera_t& camera, const Vector3& origin ){
257 camera.origin = origin;
258 Camera_updateModelview( camera );
263 const Vector3& Camera_getAngles( camera_t& camera ){
264 return camera.angles;
267 void Camera_setAngles( camera_t& camera, const Vector3& angles ){
268 camera.angles = angles;
269 Camera_updateModelview( camera );
275 void Camera_FreeMove( camera_t& camera, int dx, int dy ){
276 // free strafe mode, toggled by the ctrl key with optional shift for forward movement
277 if ( camera.m_strafe ) {
278 float strafespeed = 0.65f;
280 if ( g_camwindow_globals_private.m_bCamLinkSpeed ) {
281 strafespeed = (float)g_camwindow_globals_private.m_nMoveSpeed / 100;
284 camera.origin -= camera.vright * strafespeed * dx;
285 if ( camera.m_strafe_forward ) {
286 camera.origin += camera.vpn * strafespeed * dy;
289 camera.origin += camera.vup * strafespeed * dy;
292 else // free rotation
294 const float dtime = 0.1f;
296 if ( g_camwindow_globals_private.m_bCamInverseMouse ) {
297 camera.angles[CAMERA_PITCH] -= dy * dtime * g_camwindow_globals_private.m_nAngleSpeed;
300 camera.angles[CAMERA_PITCH] += dy * dtime * g_camwindow_globals_private.m_nAngleSpeed;
303 camera.angles[CAMERA_YAW] += dx * dtime * g_camwindow_globals_private.m_nAngleSpeed;
305 if ( camera.angles[CAMERA_PITCH] > 90 ) {
306 camera.angles[CAMERA_PITCH] = 90;
308 else if ( camera.angles[CAMERA_PITCH] < -90 ) {
309 camera.angles[CAMERA_PITCH] = -90;
312 if ( camera.angles[CAMERA_YAW] >= 360 ) {
313 camera.angles[CAMERA_YAW] -= 360;
315 else if ( camera.angles[CAMERA_YAW] <= 0 ) {
316 camera.angles[CAMERA_YAW] += 360;
320 Camera_updateModelview( camera );
321 Camera_Freemove_updateAxes( camera );
324 void Cam_MouseControl( camera_t& camera, int x, int y ){
325 float xf = (float)( x - camera.width / 2 ) / ( camera.width / 2 );
326 float yf = (float)( y - camera.height / 2 ) / ( camera.height / 2 );
328 xf *= 1.0f - fabsf( yf );
343 vector3_add( camera.origin, vector3_scaled( camera.forward, yf * 0.1f * g_camwindow_globals_private.m_nMoveSpeed ) );
344 camera.angles[CAMERA_YAW] += xf * -0.1f * g_camwindow_globals_private.m_nAngleSpeed;
346 Camera_updateModelview( camera );
349 void Camera_mouseMove( camera_t& camera, int x, int y ){
350 //globalOutputStream() << "mousemove... ";
351 Camera_FreeMove( camera, -x, -y );
356 const unsigned int MOVE_NONE = 0;
357 const unsigned int MOVE_FORWARD = 1 << 0;
358 const unsigned int MOVE_BACK = 1 << 1;
359 const unsigned int MOVE_ROTRIGHT = 1 << 2;
360 const unsigned int MOVE_ROTLEFT = 1 << 3;
361 const unsigned int MOVE_STRAFERIGHT = 1 << 4;
362 const unsigned int MOVE_STRAFELEFT = 1 << 5;
363 const unsigned int MOVE_UP = 1 << 6;
364 const unsigned int MOVE_DOWN = 1 << 7;
365 const unsigned int MOVE_PITCHUP = 1 << 8;
366 const unsigned int MOVE_PITCHDOWN = 1 << 9;
367 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;
369 void Cam_KeyControl( camera_t& camera, float dtime ){
371 if ( camera.movementflags & MOVE_ROTLEFT ) {
372 camera.angles[CAMERA_YAW] += 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed;
374 if ( camera.movementflags & MOVE_ROTRIGHT ) {
375 camera.angles[CAMERA_YAW] -= 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed;
377 if ( camera.movementflags & MOVE_PITCHUP ) {
378 camera.angles[CAMERA_PITCH] += 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed;
379 if ( camera.angles[CAMERA_PITCH] > 90 ) {
380 camera.angles[CAMERA_PITCH] = 90;
383 if ( camera.movementflags & MOVE_PITCHDOWN ) {
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;
390 Camera_updateModelview( camera );
391 Camera_Freemove_updateAxes( camera );
394 if ( camera.movementflags & MOVE_FORWARD ) {
395 vector3_add( camera.origin, vector3_scaled( camera.forward, dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
397 if ( camera.movementflags & MOVE_BACK ) {
398 vector3_add( camera.origin, vector3_scaled( camera.forward, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
400 if ( camera.movementflags & MOVE_STRAFELEFT ) {
401 vector3_add( camera.origin, vector3_scaled( camera.right, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
403 if ( camera.movementflags & MOVE_STRAFERIGHT ) {
404 vector3_add( camera.origin, vector3_scaled( camera.right, dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
406 if ( camera.movementflags & MOVE_UP ) {
407 vector3_add( camera.origin, vector3_scaled( g_vector3_axis_z, dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
409 if ( camera.movementflags & MOVE_DOWN ) {
410 vector3_add( camera.origin, vector3_scaled( g_vector3_axis_z, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
413 Camera_updateModelview( camera );
416 void Camera_keyMove( camera_t& camera ){
417 camera.m_mouseMove.flush();
419 //globalOutputStream() << "keymove... ";
420 float time_seconds = camera.m_keycontrol_timer.elapsed_msec() / static_cast<float>( msec_per_sec );
421 camera.m_keycontrol_timer.start();
422 if ( time_seconds > 0.05f ) {
423 time_seconds = 0.05f; // 20fps
425 Cam_KeyControl( camera, time_seconds * 5.0f );
431 gboolean camera_keymove( gpointer data ){
432 Camera_keyMove( *reinterpret_cast<camera_t*>( data ) );
436 void Camera_setMovementFlags( camera_t& camera, unsigned int mask ){
437 if ( ( ~camera.movementflags & mask ) != 0 && camera.movementflags == 0 ) {
438 camera.m_keymove_handler = g_idle_add( camera_keymove, &camera );
440 camera.movementflags |= mask;
442 void Camera_clearMovementFlags( camera_t& camera, unsigned int mask ){
443 if ( ( camera.movementflags & ~mask ) == 0 && camera.movementflags != 0 ) {
444 g_source_remove( camera.m_keymove_handler );
445 camera.m_keymove_handler = 0;
447 camera.movementflags &= ~mask;
450 void Camera_MoveForward_KeyDown( camera_t& camera ){
451 Camera_setMovementFlags( camera, MOVE_FORWARD );
453 void Camera_MoveForward_KeyUp( camera_t& camera ){
454 Camera_clearMovementFlags( camera, MOVE_FORWARD );
456 void Camera_MoveBack_KeyDown( camera_t& camera ){
457 Camera_setMovementFlags( camera, MOVE_BACK );
459 void Camera_MoveBack_KeyUp( camera_t& camera ){
460 Camera_clearMovementFlags( camera, MOVE_BACK );
463 void Camera_MoveLeft_KeyDown( camera_t& camera ){
464 Camera_setMovementFlags( camera, MOVE_STRAFELEFT );
466 void Camera_MoveLeft_KeyUp( camera_t& camera ){
467 Camera_clearMovementFlags( camera, MOVE_STRAFELEFT );
469 void Camera_MoveRight_KeyDown( camera_t& camera ){
470 Camera_setMovementFlags( camera, MOVE_STRAFERIGHT );
472 void Camera_MoveRight_KeyUp( camera_t& camera ){
473 Camera_clearMovementFlags( camera, MOVE_STRAFERIGHT );
476 void Camera_MoveUp_KeyDown( camera_t& camera ){
477 Camera_setMovementFlags( camera, MOVE_UP );
479 void Camera_MoveUp_KeyUp( camera_t& camera ){
480 Camera_clearMovementFlags( camera, MOVE_UP );
482 void Camera_MoveDown_KeyDown( camera_t& camera ){
483 Camera_setMovementFlags( camera, MOVE_DOWN );
485 void Camera_MoveDown_KeyUp( camera_t& camera ){
486 Camera_clearMovementFlags( camera, MOVE_DOWN );
489 void Camera_RotateLeft_KeyDown( camera_t& camera ){
490 Camera_setMovementFlags( camera, MOVE_ROTLEFT );
492 void Camera_RotateLeft_KeyUp( camera_t& camera ){
493 Camera_clearMovementFlags( camera, MOVE_ROTLEFT );
495 void Camera_RotateRight_KeyDown( camera_t& camera ){
496 Camera_setMovementFlags( camera, MOVE_ROTRIGHT );
498 void Camera_RotateRight_KeyUp( camera_t& camera ){
499 Camera_clearMovementFlags( camera, MOVE_ROTRIGHT );
502 void Camera_PitchUp_KeyDown( camera_t& camera ){
503 Camera_setMovementFlags( camera, MOVE_PITCHUP );
505 void Camera_PitchUp_KeyUp( camera_t& camera ){
506 Camera_clearMovementFlags( camera, MOVE_PITCHUP );
508 void Camera_PitchDown_KeyDown( camera_t& camera ){
509 Camera_setMovementFlags( camera, MOVE_PITCHDOWN );
511 void Camera_PitchDown_KeyUp( camera_t& camera ){
512 Camera_clearMovementFlags( camera, MOVE_PITCHDOWN );
516 typedef ReferenceCaller<camera_t, &Camera_MoveForward_KeyDown> FreeMoveCameraMoveForwardKeyDownCaller;
517 typedef ReferenceCaller<camera_t, &Camera_MoveForward_KeyUp> FreeMoveCameraMoveForwardKeyUpCaller;
518 typedef ReferenceCaller<camera_t, &Camera_MoveBack_KeyDown> FreeMoveCameraMoveBackKeyDownCaller;
519 typedef ReferenceCaller<camera_t, &Camera_MoveBack_KeyUp> FreeMoveCameraMoveBackKeyUpCaller;
520 typedef ReferenceCaller<camera_t, &Camera_MoveLeft_KeyDown> FreeMoveCameraMoveLeftKeyDownCaller;
521 typedef ReferenceCaller<camera_t, &Camera_MoveLeft_KeyUp> FreeMoveCameraMoveLeftKeyUpCaller;
522 typedef ReferenceCaller<camera_t, &Camera_MoveRight_KeyDown> FreeMoveCameraMoveRightKeyDownCaller;
523 typedef ReferenceCaller<camera_t, &Camera_MoveRight_KeyUp> FreeMoveCameraMoveRightKeyUpCaller;
524 typedef ReferenceCaller<camera_t, &Camera_MoveUp_KeyDown> FreeMoveCameraMoveUpKeyDownCaller;
525 typedef ReferenceCaller<camera_t, &Camera_MoveUp_KeyUp> FreeMoveCameraMoveUpKeyUpCaller;
526 typedef ReferenceCaller<camera_t, &Camera_MoveDown_KeyDown> FreeMoveCameraMoveDownKeyDownCaller;
527 typedef ReferenceCaller<camera_t, &Camera_MoveDown_KeyUp> FreeMoveCameraMoveDownKeyUpCaller;
530 #define SPEED_MOVE 32
531 #define SPEED_TURN 22.5
532 #define MIN_CAM_SPEED 10
533 #define MAX_CAM_SPEED 610
534 #define CAM_SPEED_STEP 50
536 void Camera_MoveForward_Discrete( camera_t& camera ){
537 Camera_Move_updateAxes( camera );
538 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.forward, SPEED_MOVE ) ) );
540 void Camera_MoveBack_Discrete( camera_t& camera ){
541 Camera_Move_updateAxes( camera );
542 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.forward, -SPEED_MOVE ) ) );
545 void Camera_MoveUp_Discrete( camera_t& camera ){
546 Vector3 origin( Camera_getOrigin( camera ) );
547 origin[2] += SPEED_MOVE;
548 Camera_setOrigin( camera, origin );
550 void Camera_MoveDown_Discrete( camera_t& camera ){
551 Vector3 origin( Camera_getOrigin( camera ) );
552 origin[2] -= SPEED_MOVE;
553 Camera_setOrigin( camera, origin );
556 void Camera_MoveLeft_Discrete( camera_t& camera ){
557 Camera_Move_updateAxes( camera );
558 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.right, -SPEED_MOVE ) ) );
560 void Camera_MoveRight_Discrete( camera_t& camera ){
561 Camera_Move_updateAxes( camera );
562 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.right, SPEED_MOVE ) ) );
565 void Camera_RotateLeft_Discrete( camera_t& camera ){
566 Vector3 angles( Camera_getAngles( camera ) );
567 angles[CAMERA_YAW] += SPEED_TURN;
568 Camera_setAngles( camera, angles );
570 void Camera_RotateRight_Discrete( camera_t& camera ){
571 Vector3 angles( Camera_getAngles( camera ) );
572 angles[CAMERA_YAW] -= SPEED_TURN;
573 Camera_setAngles( camera, angles );
576 void Camera_PitchUp_Discrete( camera_t& camera ){
577 Vector3 angles( Camera_getAngles( camera ) );
578 angles[CAMERA_PITCH] += SPEED_TURN;
579 if ( angles[CAMERA_PITCH] > 90 ) {
580 angles[CAMERA_PITCH] = 90;
582 Camera_setAngles( camera, angles );
584 void Camera_PitchDown_Discrete( camera_t& camera ){
585 Vector3 angles( Camera_getAngles( camera ) );
586 angles[CAMERA_PITCH] -= SPEED_TURN;
587 if ( angles[CAMERA_PITCH] < -90 ) {
588 angles[CAMERA_PITCH] = -90;
590 Camera_setAngles( camera, angles );
594 class RadiantCameraView : public CameraView
600 RadiantCameraView( camera_t& camera, View* view, const Callback& update ) : m_camera( camera ), m_view( view ), m_update( update ){
603 m_view->Construct( m_camera.projection, m_camera.modelview, m_camera.width, m_camera.height );
606 void setModelview( const Matrix4& modelview ){
607 m_camera.modelview = modelview;
608 matrix4_multiply_by_matrix4( m_camera.modelview, g_radiant2opengl );
609 matrix4_affine_invert( m_camera.modelview );
610 Camera_updateVectors( m_camera );
613 void setFieldOfView( float fieldOfView ){
614 float farClip = Camera_getFarClipPlane( m_camera );
615 m_camera.projection = projection_for_camera( farClip / 4096.0f, farClip, fieldOfView, m_camera.width, m_camera.height );
621 void Camera_motionDelta( int x, int y, unsigned int state, void* data ){
622 camera_t* cam = reinterpret_cast<camera_t*>( data );
624 cam->m_mouseMove.motion_delta( x, y, state );
626 switch ( g_camwindow_globals_private.m_nStrafeMode )
629 cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0;
630 if ( cam->m_strafe ) {
631 cam->m_strafe_forward = ( state & GDK_SHIFT_MASK ) != 0;
634 cam->m_strafe_forward = false;
638 cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0 && ( state & GDK_SHIFT_MASK ) == 0;
639 cam->m_strafe_forward = false;
642 cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0 && ( state & GDK_SHIFT_MASK ) == 0;
643 cam->m_strafe_forward = cam->m_strafe;
652 RadiantCameraView m_cameraview;
654 int m_PositionDragCursorX;
655 int m_PositionDragCursorY;
658 guint m_freemove_handle_focusout;
660 static Shader* m_state_select1;
661 static Shader* m_state_select2;
663 FreezePointer m_freezePointer;
666 ui::GLArea m_gl_widget;
667 ui::Window m_parent{ui::null};
669 SelectionSystemWindowObserver* m_window_observer;
670 XORRectangle m_XORRectangle;
672 DeferredDraw m_deferredDraw;
673 DeferredMotion m_deferred_motion;
675 guint m_selection_button_press_handler;
676 guint m_selection_button_release_handler;
677 guint m_selection_motion_handler;
679 guint m_freelook_button_press_handler;
682 guint m_exposeHandler;
689 //ASSERT_MESSAGE(!m_drawing, "CamWnd::queue_draw(): called while draw is already in progress");
693 //globalOutputStream() << "queue... ";
694 m_deferredDraw.draw();
698 static void captureStates(){
699 m_state_select1 = GlobalShaderCache().capture( "$CAM_HIGHLIGHT" );
700 m_state_select2 = GlobalShaderCache().capture( "$CAM_OVERLAY" );
702 static void releaseStates(){
703 GlobalShaderCache().release( "$CAM_HIGHLIGHT" );
704 GlobalShaderCache().release( "$CAM_OVERLAY" );
707 camera_t& getCamera(){
712 void Cam_ChangeFloor( bool up );
714 void DisableFreeMove();
715 void EnableFreeMove();
718 CameraView& getCameraView(){
726 typedef MemberCaller<CamWnd, &CamWnd::queue_draw> CamWndQueueDraw;
728 Shader* CamWnd::m_state_select1 = 0;
729 Shader* CamWnd::m_state_select2 = 0;
734 void DeleteCamWnd( CamWnd* camwnd ){
738 void CamWnd_constructStatic(){
739 CamWnd::captureStates();
742 void CamWnd_destroyStatic(){
743 CamWnd::releaseStates();
746 static CamWnd* g_camwnd = 0;
748 void GlobalCamera_setCamWnd( CamWnd& camwnd ){
753 ui::GLArea CamWnd_getWidget( CamWnd& camwnd ){
754 return camwnd.m_gl_widget;
757 ui::Window CamWnd_getParent( CamWnd& camwnd ){
758 return camwnd.m_parent;
761 ToggleShown g_camera_shown( true );
763 void CamWnd_setParent( CamWnd& camwnd, ui::Window parent ){
764 camwnd.m_parent = parent;
765 g_camera_shown.connect( camwnd.m_parent );
768 void CamWnd_Update( CamWnd& camwnd ){
774 camwindow_globals_t g_camwindow_globals;
776 const Vector3& Camera_getOrigin( CamWnd& camwnd ){
777 return Camera_getOrigin( camwnd.getCamera() );
780 void Camera_setOrigin( CamWnd& camwnd, const Vector3& origin ){
781 Camera_setOrigin( camwnd.getCamera(), origin );
784 const Vector3& Camera_getAngles( CamWnd& camwnd ){
785 return Camera_getAngles( camwnd.getCamera() );
788 void Camera_setAngles( CamWnd& camwnd, const Vector3& angles ){
789 Camera_setAngles( camwnd.getCamera(), angles );
793 // =============================================================================
796 gboolean enable_freelook_button_press( ui::Widget widget, GdkEventButton* event, CamWnd* camwnd ){
797 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
798 camwnd->EnableFreeMove();
804 gboolean disable_freelook_button_press( ui::Widget widget, GdkEventButton* event, CamWnd* camwnd ){
805 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
806 camwnd->DisableFreeMove();
813 gboolean mousecontrol_button_press( ui::Widget widget, GdkEventButton* event, CamWnd* camwnd ){
814 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
815 Cam_MouseControl( camwnd->getCamera(), event->x, widget->allocation.height - 1 - event->y );
821 void camwnd_update_xor_rectangle( CamWnd& self, rect_t area ){
822 if ( self.m_gl_widget.visible() ) {
823 self.m_XORRectangle.set( rectangle_from_area( area.min, area.max, self.getCamera().width, self.getCamera().height ) );
828 gboolean selection_button_press( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){
829 if ( event->type == GDK_BUTTON_PRESS ) {
830 observer->onMouseDown( WindowVector_forDouble( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
835 gboolean selection_button_release( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){
836 if ( event->type == GDK_BUTTON_RELEASE ) {
837 observer->onMouseUp( WindowVector_forDouble( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
842 void selection_motion( gdouble x, gdouble y, guint state, void* data ){
843 //globalOutputStream() << "motion... ";
844 reinterpret_cast<WindowObserver*>( data )->onMouseMotion( WindowVector_forDouble( x, y ), modifiers_for_state( state ) );
847 inline WindowVector windowvector_for_widget_centre( ui::Widget widget ){
848 auto allocation = widget.dimensions();
849 return WindowVector( static_cast<float>( allocation.width / 2 ), static_cast<float>(allocation.height / 2 ) );
852 gboolean selection_button_press_freemove( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){
853 if ( event->type == GDK_BUTTON_PRESS ) {
854 observer->onMouseDown( windowvector_for_widget_centre( widget ), button_for_button( event->button ), modifiers_for_state( event->state ) );
859 gboolean selection_button_release_freemove( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){
860 if ( event->type == GDK_BUTTON_RELEASE ) {
861 observer->onMouseUp( windowvector_for_widget_centre( widget ), button_for_button( event->button ), modifiers_for_state( event->state ) );
866 gboolean selection_motion_freemove( ui::Widget widget, GdkEventMotion *event, WindowObserver* observer ){
867 observer->onMouseMotion( windowvector_for_widget_centre( widget ), modifiers_for_state( event->state ) );
871 gboolean wheelmove_scroll( ui::Widget widget, GdkEventScroll* event, CamWnd* camwnd ){
872 if ( event->direction == GDK_SCROLL_UP ) {
873 Camera_Freemove_updateAxes( camwnd->getCamera() );
874 Camera_setOrigin( *camwnd, vector3_added( Camera_getOrigin( *camwnd ), vector3_scaled( camwnd->getCamera().forward, static_cast<float>( g_camwindow_globals_private.m_nMoveSpeed ) ) ) );
876 else if ( event->direction == GDK_SCROLL_DOWN ) {
877 Camera_Freemove_updateAxes( camwnd->getCamera() );
878 Camera_setOrigin( *camwnd, vector3_added( Camera_getOrigin( *camwnd ), vector3_scaled( camwnd->getCamera().forward, -static_cast<float>( g_camwindow_globals_private.m_nMoveSpeed ) ) ) );
884 gboolean camera_size_allocate( ui::Widget widget, GtkAllocation* allocation, CamWnd* camwnd ){
885 camwnd->getCamera().width = allocation->width;
886 camwnd->getCamera().height = allocation->height;
887 Camera_updateProjection( camwnd->getCamera() );
888 camwnd->m_window_observer->onSizeChanged( camwnd->getCamera().width, camwnd->getCamera().height );
889 camwnd->queue_draw();
893 gboolean camera_expose( ui::Widget widget, GdkEventExpose* event, gpointer data ){
894 reinterpret_cast<CamWnd*>( data )->draw();
898 void KeyEvent_connect( const char* name ){
899 const KeyEvent& keyEvent = GlobalKeyEvents_find( name );
900 keydown_accelerators_add( keyEvent.m_accelerator, keyEvent.m_keyDown );
901 keyup_accelerators_add( keyEvent.m_accelerator, keyEvent.m_keyUp );
904 void KeyEvent_disconnect( const char* name ){
905 const KeyEvent& keyEvent = GlobalKeyEvents_find( name );
906 keydown_accelerators_remove( keyEvent.m_accelerator );
907 keyup_accelerators_remove( keyEvent.m_accelerator );
910 void CamWnd_registerCommands( CamWnd& camwnd ){
911 GlobalKeyEvents_insert( "CameraForward", Accelerator( GDK_KEY_Up ),
912 ReferenceCaller<camera_t, Camera_MoveForward_KeyDown>( camwnd.getCamera() ),
913 ReferenceCaller<camera_t, Camera_MoveForward_KeyUp>( camwnd.getCamera() )
915 GlobalKeyEvents_insert( "CameraBack", Accelerator( GDK_KEY_Down ),
916 ReferenceCaller<camera_t, Camera_MoveBack_KeyDown>( camwnd.getCamera() ),
917 ReferenceCaller<camera_t, Camera_MoveBack_KeyUp>( camwnd.getCamera() )
919 GlobalKeyEvents_insert( "CameraLeft", Accelerator( GDK_KEY_Left ),
920 ReferenceCaller<camera_t, Camera_RotateLeft_KeyDown>( camwnd.getCamera() ),
921 ReferenceCaller<camera_t, Camera_RotateLeft_KeyUp>( camwnd.getCamera() )
923 GlobalKeyEvents_insert( "CameraRight", Accelerator( GDK_KEY_Right ),
924 ReferenceCaller<camera_t, Camera_RotateRight_KeyDown>( camwnd.getCamera() ),
925 ReferenceCaller<camera_t, Camera_RotateRight_KeyUp>( camwnd.getCamera() )
927 GlobalKeyEvents_insert( "CameraStrafeRight", Accelerator( GDK_KEY_period ),
928 ReferenceCaller<camera_t, Camera_MoveRight_KeyDown>( camwnd.getCamera() ),
929 ReferenceCaller<camera_t, Camera_MoveRight_KeyUp>( camwnd.getCamera() )
931 GlobalKeyEvents_insert( "CameraStrafeLeft", Accelerator( GDK_KEY_comma ),
932 ReferenceCaller<camera_t, Camera_MoveLeft_KeyDown>( camwnd.getCamera() ),
933 ReferenceCaller<camera_t, Camera_MoveLeft_KeyUp>( camwnd.getCamera() )
935 GlobalKeyEvents_insert( "CameraUp", Accelerator( 'D' ),
936 ReferenceCaller<camera_t, Camera_MoveUp_KeyDown>( camwnd.getCamera() ),
937 ReferenceCaller<camera_t, Camera_MoveUp_KeyUp>( camwnd.getCamera() )
939 GlobalKeyEvents_insert( "CameraDown", Accelerator( 'C' ),
940 ReferenceCaller<camera_t, Camera_MoveDown_KeyDown>( camwnd.getCamera() ),
941 ReferenceCaller<camera_t, Camera_MoveDown_KeyUp>( camwnd.getCamera() )
943 GlobalKeyEvents_insert( "CameraAngleDown", Accelerator( 'A' ),
944 ReferenceCaller<camera_t, Camera_PitchDown_KeyDown>( camwnd.getCamera() ),
945 ReferenceCaller<camera_t, Camera_PitchDown_KeyUp>( camwnd.getCamera() )
947 GlobalKeyEvents_insert( "CameraAngleUp", Accelerator( 'Z' ),
948 ReferenceCaller<camera_t, Camera_PitchUp_KeyDown>( camwnd.getCamera() ),
949 ReferenceCaller<camera_t, Camera_PitchUp_KeyUp>( camwnd.getCamera() )
952 GlobalKeyEvents_insert( "CameraFreeMoveForward", Accelerator( GDK_KEY_Up ),
953 FreeMoveCameraMoveForwardKeyDownCaller( camwnd.getCamera() ),
954 FreeMoveCameraMoveForwardKeyUpCaller( camwnd.getCamera() )
956 GlobalKeyEvents_insert( "CameraFreeMoveBack", Accelerator( GDK_KEY_Down ),
957 FreeMoveCameraMoveBackKeyDownCaller( camwnd.getCamera() ),
958 FreeMoveCameraMoveBackKeyUpCaller( camwnd.getCamera() )
960 GlobalKeyEvents_insert( "CameraFreeMoveLeft", Accelerator( GDK_KEY_Left ),
961 FreeMoveCameraMoveLeftKeyDownCaller( camwnd.getCamera() ),
962 FreeMoveCameraMoveLeftKeyUpCaller( camwnd.getCamera() )
964 GlobalKeyEvents_insert( "CameraFreeMoveRight", Accelerator( GDK_KEY_Right ),
965 FreeMoveCameraMoveRightKeyDownCaller( camwnd.getCamera() ),
966 FreeMoveCameraMoveRightKeyUpCaller( camwnd.getCamera() )
968 GlobalKeyEvents_insert( "CameraFreeMoveUp", Accelerator( 'D' ),
969 FreeMoveCameraMoveUpKeyDownCaller( camwnd.getCamera() ),
970 FreeMoveCameraMoveUpKeyUpCaller( camwnd.getCamera() )
972 GlobalKeyEvents_insert( "CameraFreeMoveDown", Accelerator( 'C' ),
973 FreeMoveCameraMoveDownKeyDownCaller( camwnd.getCamera() ),
974 FreeMoveCameraMoveDownKeyUpCaller( camwnd.getCamera() )
977 GlobalCommands_insert( "CameraForward", ReferenceCaller<camera_t, Camera_MoveForward_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_Up ) );
978 GlobalCommands_insert( "CameraBack", ReferenceCaller<camera_t, Camera_MoveBack_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_Down ) );
979 GlobalCommands_insert( "CameraLeft", ReferenceCaller<camera_t, Camera_RotateLeft_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_Left ) );
980 GlobalCommands_insert( "CameraRight", ReferenceCaller<camera_t, Camera_RotateRight_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_Right ) );
981 GlobalCommands_insert( "CameraStrafeRight", ReferenceCaller<camera_t, Camera_MoveRight_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_period ) );
982 GlobalCommands_insert( "CameraStrafeLeft", ReferenceCaller<camera_t, Camera_MoveLeft_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_comma ) );
984 GlobalCommands_insert( "CameraUp", ReferenceCaller<camera_t, Camera_MoveUp_Discrete>( camwnd.getCamera() ), Accelerator( 'D' ) );
985 GlobalCommands_insert( "CameraDown", ReferenceCaller<camera_t, Camera_MoveDown_Discrete>( camwnd.getCamera() ), Accelerator( 'C' ) );
986 GlobalCommands_insert( "CameraAngleUp", ReferenceCaller<camera_t, Camera_PitchUp_Discrete>( camwnd.getCamera() ), Accelerator( 'A' ) );
987 GlobalCommands_insert( "CameraAngleDown", ReferenceCaller<camera_t, Camera_PitchDown_Discrete>( camwnd.getCamera() ), Accelerator( 'Z' ) );
990 void CamWnd_Move_Enable( CamWnd& camwnd ){
991 KeyEvent_connect( "CameraForward" );
992 KeyEvent_connect( "CameraBack" );
993 KeyEvent_connect( "CameraLeft" );
994 KeyEvent_connect( "CameraRight" );
995 KeyEvent_connect( "CameraStrafeRight" );
996 KeyEvent_connect( "CameraStrafeLeft" );
997 KeyEvent_connect( "CameraUp" );
998 KeyEvent_connect( "CameraDown" );
999 KeyEvent_connect( "CameraAngleUp" );
1000 KeyEvent_connect( "CameraAngleDown" );
1003 void CamWnd_Move_Disable( CamWnd& camwnd ){
1004 KeyEvent_disconnect( "CameraForward" );
1005 KeyEvent_disconnect( "CameraBack" );
1006 KeyEvent_disconnect( "CameraLeft" );
1007 KeyEvent_disconnect( "CameraRight" );
1008 KeyEvent_disconnect( "CameraStrafeRight" );
1009 KeyEvent_disconnect( "CameraStrafeLeft" );
1010 KeyEvent_disconnect( "CameraUp" );
1011 KeyEvent_disconnect( "CameraDown" );
1012 KeyEvent_disconnect( "CameraAngleUp" );
1013 KeyEvent_disconnect( "CameraAngleDown" );
1016 void CamWnd_Move_Discrete_Enable( CamWnd& camwnd ){
1017 command_connect_accelerator( "CameraForward" );
1018 command_connect_accelerator( "CameraBack" );
1019 command_connect_accelerator( "CameraLeft" );
1020 command_connect_accelerator( "CameraRight" );
1021 command_connect_accelerator( "CameraStrafeRight" );
1022 command_connect_accelerator( "CameraStrafeLeft" );
1023 command_connect_accelerator( "CameraUp" );
1024 command_connect_accelerator( "CameraDown" );
1025 command_connect_accelerator( "CameraAngleUp" );
1026 command_connect_accelerator( "CameraAngleDown" );
1029 void CamWnd_Move_Discrete_Disable( CamWnd& camwnd ){
1030 command_disconnect_accelerator( "CameraForward" );
1031 command_disconnect_accelerator( "CameraBack" );
1032 command_disconnect_accelerator( "CameraLeft" );
1033 command_disconnect_accelerator( "CameraRight" );
1034 command_disconnect_accelerator( "CameraStrafeRight" );
1035 command_disconnect_accelerator( "CameraStrafeLeft" );
1036 command_disconnect_accelerator( "CameraUp" );
1037 command_disconnect_accelerator( "CameraDown" );
1038 command_disconnect_accelerator( "CameraAngleUp" );
1039 command_disconnect_accelerator( "CameraAngleDown" );
1042 void CamWnd_Move_Discrete_Import( CamWnd& camwnd, bool value ){
1043 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1044 CamWnd_Move_Discrete_Disable( camwnd );
1048 CamWnd_Move_Disable( camwnd );
1051 g_camwindow_globals_private.m_bCamDiscrete = value;
1053 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1054 CamWnd_Move_Discrete_Enable( camwnd );
1058 CamWnd_Move_Enable( camwnd );
1062 void CamWnd_Move_Discrete_Import( bool value ){
1063 if ( g_camwnd != 0 ) {
1064 CamWnd_Move_Discrete_Import( *g_camwnd, value );
1068 g_camwindow_globals_private.m_bCamDiscrete = value;
1074 void CamWnd_Add_Handlers_Move( CamWnd& camwnd ){
1075 camwnd.m_selection_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( selection_button_press ), camwnd.m_window_observer );
1076 camwnd.m_selection_button_release_handler = camwnd.m_gl_widget.connect( "button_release_event", G_CALLBACK( selection_button_release ), camwnd.m_window_observer );
1077 camwnd.m_selection_motion_handler = camwnd.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &camwnd.m_deferred_motion );
1079 camwnd.m_freelook_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( enable_freelook_button_press ), &camwnd );
1081 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1082 CamWnd_Move_Discrete_Enable( camwnd );
1086 CamWnd_Move_Enable( camwnd );
1090 void CamWnd_Remove_Handlers_Move( CamWnd& camwnd ){
1091 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_press_handler );
1092 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_release_handler );
1093 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_motion_handler );
1095 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_freelook_button_press_handler );
1097 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1098 CamWnd_Move_Discrete_Disable( camwnd );
1102 CamWnd_Move_Disable( camwnd );
1106 void CamWnd_Add_Handlers_FreeMove( CamWnd& camwnd ){
1107 camwnd.m_selection_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( selection_button_press_freemove ), camwnd.m_window_observer );
1108 camwnd.m_selection_button_release_handler = camwnd.m_gl_widget.connect( "button_release_event", G_CALLBACK( selection_button_release_freemove ), camwnd.m_window_observer );
1109 camwnd.m_selection_motion_handler = camwnd.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( selection_motion_freemove ), camwnd.m_window_observer );
1111 camwnd.m_freelook_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( disable_freelook_button_press ), &camwnd );
1113 KeyEvent_connect( "CameraFreeMoveForward" );
1114 KeyEvent_connect( "CameraFreeMoveBack" );
1115 KeyEvent_connect( "CameraFreeMoveLeft" );
1116 KeyEvent_connect( "CameraFreeMoveRight" );
1117 KeyEvent_connect( "CameraFreeMoveUp" );
1118 KeyEvent_connect( "CameraFreeMoveDown" );
1121 void CamWnd_Remove_Handlers_FreeMove( CamWnd& camwnd ){
1122 KeyEvent_disconnect( "CameraFreeMoveForward" );
1123 KeyEvent_disconnect( "CameraFreeMoveBack" );
1124 KeyEvent_disconnect( "CameraFreeMoveLeft" );
1125 KeyEvent_disconnect( "CameraFreeMoveRight" );
1126 KeyEvent_disconnect( "CameraFreeMoveUp" );
1127 KeyEvent_disconnect( "CameraFreeMoveDown" );
1129 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_press_handler );
1130 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_release_handler );
1131 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_motion_handler );
1133 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_freelook_button_press_handler );
1138 m_Camera( &m_view, CamWndQueueDraw( *this ) ),
1139 m_cameraview( m_Camera, &m_view, ReferenceCaller<CamWnd, CamWnd_Update>( *this ) ),
1140 m_gl_widget( glwidget_new( TRUE ) ),
1141 m_window_observer( NewWindowObserver() ),
1142 m_XORRectangle( m_gl_widget ),
1143 m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ),
1144 m_deferred_motion( selection_motion, m_window_observer ),
1145 m_selection_button_press_handler( 0 ),
1146 m_selection_button_release_handler( 0 ),
1147 m_selection_motion_handler( 0 ),
1148 m_freelook_button_press_handler( 0 ),
1150 m_bFreeMove = false;
1152 GlobalWindowObservers_add( m_window_observer );
1153 GlobalWindowObservers_connectWidget( m_gl_widget );
1155 m_window_observer->setRectangleDrawCallback( ReferenceCaller1<CamWnd, rect_t, camwnd_update_xor_rectangle>( *this ) );
1156 m_window_observer->setView( m_view );
1158 g_object_ref( m_gl_widget._handle );
1160 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 );
1161 gtk_widget_set_can_focus( m_gl_widget, true );
1163 m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( camera_size_allocate ), this );
1164 m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( camera_expose ), this );
1166 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
1168 CamWnd_registerCommands( *this );
1170 CamWnd_Add_Handlers_Move( *this );
1172 m_gl_widget.connect( "scroll_event", G_CALLBACK( wheelmove_scroll ), this );
1174 AddSceneChangeCallback( ReferenceCaller<CamWnd, CamWnd_Update>( *this ) );
1176 PressedButtons_connect( g_pressedButtons, m_gl_widget );
1180 if ( m_bFreeMove ) {
1184 CamWnd_Remove_Handlers_Move( *this );
1186 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
1187 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
1189 m_gl_widget.unref();
1191 m_window_observer->release();
1194 class FloorHeightWalker : public scene::Graph::Walker
1200 FloorHeightWalker( float current, float& bestUp, float& bestDown ) :
1201 m_current( current ), m_bestUp( bestUp ), m_bestDown( bestDown ){
1202 bestUp = g_MaxWorldCoord;
1203 bestDown = -g_MaxWorldCoord;
1205 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1206 if ( path.top().get().visible()
1207 && Node_isBrush( path.top() ) ) { // this node is a floor
1208 const AABB& aabb = instance.worldAABB();
1209 float floorHeight = aabb.origin.z() + aabb.extents.z();
1210 if ( floorHeight > m_current && floorHeight < m_bestUp ) {
1211 m_bestUp = floorHeight;
1213 if ( floorHeight < m_current && floorHeight > m_bestDown ) {
1214 m_bestDown = floorHeight;
1221 void CamWnd::Cam_ChangeFloor( bool up ){
1222 float current = m_Camera.origin[2] - 48;
1225 GlobalSceneGraph().traverse( FloorHeightWalker( current, bestUp, bestDown ) );
1227 if ( up && bestUp != g_MaxWorldCoord ) {
1230 if ( !up && bestDown != -g_MaxWorldCoord ) {
1234 m_Camera.origin[2] = current + 48;
1235 Camera_updateModelview( getCamera() );
1236 CamWnd_Update( *this );
1237 CameraMovedNotify();
1244 Sys_GetCursorPos( &m_PositionDragCursorX, &m_PositionDragCursorY );
1247 if ( ( m_bFreeMove && ( buttons == ( RAD_CONTROL | RAD_SHIFT ) ) )
1248 || ( !m_bFreeMove && ( buttons == ( RAD_RBUTTON | RAD_CONTROL ) ) ) ) {
1250 CamWnd_Update( camwnd );
1251 CameraMovedNotify();
1255 void CamWnd::Cam_PositionDrag(){
1258 Sys_GetCursorPos( GTK_WINDOW( m_gl_widget ), &x, &y );
1259 if ( x != m_PositionDragCursorX || y != m_PositionDragCursorY ) {
1260 x -= m_PositionDragCursorX;
1261 vector3_add( m_Camera.origin, vector3_scaled( m_Camera.vright, x ) );
1262 y -= m_PositionDragCursorY;
1263 m_Camera.origin[2] -= y;
1264 Camera_updateModelview();
1265 CamWnd_Update( camwnd );
1266 CameraMovedNotify();
1268 Sys_SetCursorPos( GTK_WINDOW( m_parent ), m_PositionDragCursorX, m_PositionDragCursorY );
1274 // NOTE TTimo if there's an OS-level focus out of the application
1275 // then we can release the camera cursor grab
1276 static gboolean camwindow_freemove_focusout( ui::Widget widget, GdkEventFocus* event, gpointer data ){
1277 reinterpret_cast<CamWnd*>( data )->DisableFreeMove();
1281 void CamWnd::EnableFreeMove(){
1282 //globalOutputStream() << "EnableFreeMove\n";
1284 ASSERT_MESSAGE( !m_bFreeMove, "EnableFreeMove: free-move was already enabled" );
1286 Camera_clearMovementFlags( getCamera(), MOVE_ALL );
1288 CamWnd_Remove_Handlers_Move( *this );
1289 CamWnd_Add_Handlers_FreeMove( *this );
1291 gtk_window_set_focus( m_parent, m_gl_widget );
1292 m_freemove_handle_focusout = m_gl_widget.connect( "focus_out_event", G_CALLBACK( camwindow_freemove_focusout ), this );
1293 m_freezePointer.freeze_pointer( m_parent, Camera_motionDelta, &m_Camera );
1295 CamWnd_Update( *this );
1298 void CamWnd::DisableFreeMove(){
1299 //globalOutputStream() << "DisableFreeMove\n";
1301 ASSERT_MESSAGE( m_bFreeMove, "DisableFreeMove: free-move was not enabled" );
1302 m_bFreeMove = false;
1303 Camera_clearMovementFlags( getCamera(), MOVE_ALL );
1305 CamWnd_Remove_Handlers_FreeMove( *this );
1306 CamWnd_Add_Handlers_Move( *this );
1308 m_freezePointer.unfreeze_pointer( m_parent );
1309 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_freemove_handle_focusout );
1311 CamWnd_Update( *this );
1315 #include "renderer.h"
1317 class CamRenderer : public Renderer
1321 state_type() : m_highlight( 0 ), m_state( 0 ), m_lights( 0 ){
1323 unsigned int m_highlight;
1325 const LightList* m_lights;
1328 std::vector<state_type> m_state_stack;
1329 RenderStateFlags m_globalstate;
1330 Shader* m_state_select0;
1331 Shader* m_state_select1;
1332 const Vector3& m_viewer;
1335 CamRenderer( RenderStateFlags globalstate, Shader* select0, Shader* select1, const Vector3& viewer ) :
1336 m_globalstate( globalstate ),
1337 m_state_select0( select0 ),
1338 m_state_select1( select1 ),
1340 ASSERT_NOTNULL( select0 );
1341 ASSERT_NOTNULL( select1 );
1342 m_state_stack.push_back( state_type() );
1345 void SetState( Shader* state, EStyle style ){
1346 ASSERT_NOTNULL( state );
1347 if ( style == eFullMaterials ) {
1348 m_state_stack.back().m_state = state;
1351 EStyle getStyle() const {
1352 return eFullMaterials;
1355 m_state_stack.push_back( m_state_stack.back() );
1358 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
1359 m_state_stack.pop_back();
1361 void Highlight( EHighlightMode mode, bool bEnable = true ){
1363 ? m_state_stack.back().m_highlight |= mode
1364 : m_state_stack.back().m_highlight &= ~mode;
1366 void setLights( const LightList& lights ){
1367 m_state_stack.back().m_lights = &lights;
1369 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& world ){
1370 if ( m_state_stack.back().m_highlight & ePrimitive ) {
1371 m_state_select0->addRenderable( renderable, world, m_state_stack.back().m_lights );
1373 if ( m_state_stack.back().m_highlight & eFace ) {
1374 m_state_select1->addRenderable( renderable, world, m_state_stack.back().m_lights );
1377 m_state_stack.back().m_state->addRenderable( renderable, world, m_state_stack.back().m_lights );
1380 void render( const Matrix4& modelview, const Matrix4& projection ){
1381 GlobalShaderCache().render( m_globalstate, modelview, projection, m_viewer );
1391 void ShowStatsToggle(){
1392 g_camwindow_globals_private.m_showStats ^= 1;
1394 typedef FreeCaller<ShowStatsToggle> ShowStatsToggleCaller;
1396 void ShowStatsExport( const BoolImportCallback& importer ){
1397 importer( g_camwindow_globals_private.m_showStats );
1399 typedef FreeCaller1<const BoolImportCallback&, ShowStatsExport> ShowStatsExportCaller;
1401 ShowStatsExportCaller g_show_stats_caller;
1402 BoolExportCallback g_show_stats_callback( g_show_stats_caller );
1403 ToggleItem g_show_stats( g_show_stats_callback );
1405 void CamWnd::Cam_Draw(){
1406 glViewport( 0, 0, m_Camera.width, m_Camera.height );
1409 glGetIntegerv( GL_VIEWPORT, viewprt );
1412 // enable depth buffer writes
1413 glDepthMask( GL_TRUE );
1414 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1416 Vector3 clearColour( 0, 0, 0 );
1417 if ( m_Camera.draw_mode != cd_lighting ) {
1418 clearColour = g_camwindow_globals.color_cameraback;
1421 glClearColor( clearColour[0], clearColour[1], clearColour[2], 0 );
1422 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1424 extern void Renderer_ResetStats();
1425 Renderer_ResetStats();
1426 extern void Cull_ResetStats();
1429 glMatrixMode( GL_PROJECTION );
1430 glLoadMatrixf( reinterpret_cast<const float*>( &m_Camera.projection ) );
1432 glMatrixMode( GL_MODELVIEW );
1433 glLoadMatrixf( reinterpret_cast<const float*>( &m_Camera.modelview ) );
1436 // one directional light source directly behind the viewer
1438 GLfloat inverse_cam_dir[4], ambient[4], diffuse[4]; //, material[4];
1440 ambient[0] = ambient[1] = ambient[2] = 0.4f;
1442 diffuse[0] = diffuse[1] = diffuse[2] = 0.4f;
1444 //material[0] = material[1] = material[2] = 0.8f;
1445 //material[3] = 1.0f;
1447 inverse_cam_dir[0] = m_Camera.vpn[0];
1448 inverse_cam_dir[1] = m_Camera.vpn[1];
1449 inverse_cam_dir[2] = m_Camera.vpn[2];
1450 inverse_cam_dir[3] = 0;
1452 glLightfv( GL_LIGHT0, GL_POSITION, inverse_cam_dir );
1454 glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
1455 glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
1457 glEnable( GL_LIGHT0 );
1461 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;
1462 switch ( m_Camera.draw_mode )
1467 globalstate |= RENDER_FILL
1473 globalstate |= RENDER_FILL
1480 globalstate |= RENDER_FILL
1494 if ( !g_xywindow_globals.m_bNoStipple ) {
1495 globalstate |= RENDER_LINESTIPPLE | RENDER_POLYGONSTIPPLE;
1499 CamRenderer renderer( globalstate, m_state_select2, m_state_select1, m_view.getViewer() );
1501 Scene_Render( renderer, m_view );
1503 renderer.render( m_Camera.modelview, m_Camera.projection );
1506 // prepare for 2d stuff
1507 glColor4f( 1, 1, 1, 1 );
1508 glDisable( GL_BLEND );
1509 glMatrixMode( GL_PROJECTION );
1511 glOrtho( 0, (float)m_Camera.width, 0, (float)m_Camera.height, -100, 100 );
1512 glScalef( 1, -1, 1 );
1513 glTranslatef( 0, -(float)m_Camera.height, 0 );
1514 glMatrixMode( GL_MODELVIEW );
1517 if ( GlobalOpenGL().GL_1_3() ) {
1518 glClientActiveTexture( GL_TEXTURE0 );
1519 glActiveTexture( GL_TEXTURE0 );
1522 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1523 glDisableClientState( GL_NORMAL_ARRAY );
1524 glDisableClientState( GL_COLOR_ARRAY );
1526 glDisable( GL_TEXTURE_2D );
1527 glDisable( GL_LIGHTING );
1528 glDisable( GL_COLOR_MATERIAL );
1529 glDisable( GL_DEPTH_TEST );
1530 glColor3f( 1.f, 1.f, 1.f );
1533 // draw the crosshair
1534 if ( m_bFreeMove ) {
1535 glBegin( GL_LINES );
1536 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f + 6 );
1537 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f + 2 );
1538 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f - 6 );
1539 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f - 2 );
1540 glVertex2f( (float)m_Camera.width / 2.f + 6, (float)m_Camera.height / 2.f );
1541 glVertex2f( (float)m_Camera.width / 2.f + 2, (float)m_Camera.height / 2.f );
1542 glVertex2f( (float)m_Camera.width / 2.f - 6, (float)m_Camera.height / 2.f );
1543 glVertex2f( (float)m_Camera.width / 2.f - 2, (float)m_Camera.height / 2.f );
1547 if ( g_camwindow_globals_private.m_showStats ) {
1548 glRasterPos3f( 1.0f, static_cast<float>( m_Camera.height ) - GlobalOpenGL().m_font->getPixelDescent(), 0.0f );
1549 extern const char* Renderer_GetStats();
1550 GlobalOpenGL().drawString( Renderer_GetStats() );
1552 glRasterPos3f( 1.0f, static_cast<float>( m_Camera.height ) - GlobalOpenGL().m_font->getPixelDescent() - GlobalOpenGL().m_font->getPixelHeight(), 0.0f );
1553 extern const char* Cull_GetStats();
1554 GlobalOpenGL().drawString( Cull_GetStats() );
1557 // bind back to the default texture so that we don't have problems
1558 // elsewhere using/modifying texture maps between contexts
1559 glBindTexture( GL_TEXTURE_2D, 0 );
1562 void CamWnd::draw(){
1565 //globalOutputStream() << "draw...\n";
1566 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
1567 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
1568 GlobalOpenGL_debugAssertNoErrors();
1570 GlobalOpenGL_debugAssertNoErrors();
1573 m_XORRectangle.set( rectangle_t() );
1576 glwidget_swap_buffers( m_gl_widget );
1582 void CamWnd::BenchMark(){
1583 double dStart = Sys_DoubleTime();
1584 for ( int i = 0 ; i < 100 ; i++ )
1587 angles[CAMERA_ROLL] = 0;
1588 angles[CAMERA_PITCH] = 0;
1589 angles[CAMERA_YAW] = static_cast<float>( i * ( 360.0 / 100.0 ) );
1590 Camera_setAngles( *this, angles );
1592 double dEnd = Sys_DoubleTime();
1593 globalOutputStream() << FloatFormat( dEnd - dStart, 5, 2 ) << " seconds\n";
1597 void fill_view_camera_menu( ui::Menu menu ){
1598 create_check_menu_item_with_mnemonic( menu, "Camera View", "ToggleCamera" );
1601 void GlobalCamera_ResetAngles(){
1602 CamWnd& camwnd = *g_camwnd;
1604 angles[CAMERA_ROLL] = angles[CAMERA_PITCH] = 0;
1605 angles[CAMERA_YAW] = static_cast<float>( 22.5 * floor( ( Camera_getAngles( camwnd )[CAMERA_YAW] + 11 ) / 22.5 ) );
1606 Camera_setAngles( camwnd, angles );
1609 void Camera_ChangeFloorUp(){
1610 CamWnd& camwnd = *g_camwnd;
1611 camwnd.Cam_ChangeFloor( true );
1614 void Camera_ChangeFloorDown(){
1615 CamWnd& camwnd = *g_camwnd;
1616 camwnd.Cam_ChangeFloor( false );
1619 void Camera_CubeIn(){
1620 CamWnd& camwnd = *g_camwnd;
1621 g_camwindow_globals.m_nCubicScale--;
1622 if ( g_camwindow_globals.m_nCubicScale < 1 ) {
1623 g_camwindow_globals.m_nCubicScale = 1;
1625 Camera_updateProjection( camwnd.getCamera() );
1626 CamWnd_Update( camwnd );
1627 g_pParentWnd->SetGridStatus();
1630 void Camera_CubeOut(){
1631 CamWnd& camwnd = *g_camwnd;
1632 g_camwindow_globals.m_nCubicScale++;
1633 if ( g_camwindow_globals.m_nCubicScale > 23 ) {
1634 g_camwindow_globals.m_nCubicScale = 23;
1636 Camera_updateProjection( camwnd.getCamera() );
1637 CamWnd_Update( camwnd );
1638 g_pParentWnd->SetGridStatus();
1641 bool Camera_GetFarClip(){
1642 return g_camwindow_globals_private.m_bCubicClipping;
1645 BoolExportCaller g_getfarclip_caller( g_camwindow_globals_private.m_bCubicClipping );
1646 ToggleItem g_getfarclip_item( g_getfarclip_caller );
1648 void Camera_SetFarClip( bool value ){
1649 CamWnd& camwnd = *g_camwnd;
1650 g_camwindow_globals_private.m_bCubicClipping = value;
1651 g_getfarclip_item.update();
1652 Camera_updateProjection( camwnd.getCamera() );
1653 CamWnd_Update( camwnd );
1656 void Camera_ToggleFarClip(){
1657 Camera_SetFarClip( !Camera_GetFarClip() );
1661 void CamWnd_constructToolbar( ui::Toolbar toolbar ){
1662 toolbar_append_toggle_button( toolbar, "Cubic clip the camera view (\\)", "view_cubicclipping.png", "ToggleCubicClip" );
1665 void CamWnd_registerShortcuts(){
1666 toggle_add_accelerator( "ToggleCubicClip" );
1668 if ( g_pGameDescription->mGameType == "doom3" ) {
1669 command_connect_accelerator( "TogglePreview" );
1672 command_connect_accelerator( "CameraSpeedInc" );
1673 command_connect_accelerator( "CameraSpeedDec" );
1677 void GlobalCamera_Benchmark(){
1678 CamWnd& camwnd = *g_camwnd;
1682 void GlobalCamera_Update(){
1683 CamWnd& camwnd = *g_camwnd;
1684 CamWnd_Update( camwnd );
1687 camera_draw_mode CamWnd_GetMode(){
1688 return camera_t::draw_mode;
1690 void CamWnd_SetMode( camera_draw_mode mode ){
1691 ShaderCache_setBumpEnabled( mode == cd_lighting );
1692 camera_t::draw_mode = mode;
1693 if ( g_camwnd != 0 ) {
1694 CamWnd_Update( *g_camwnd );
1698 void CamWnd_TogglePreview( void ){
1699 // gametype must be doom3 for this function to work
1700 // if the gametype is not doom3 something is wrong with the
1701 // global command list or somebody else calls this function.
1702 ASSERT_MESSAGE( g_pGameDescription->mGameType == "doom3", "CamWnd_TogglePreview called although mGameType is not doom3 compatible" );
1704 // switch between textured and lighting mode
1705 CamWnd_SetMode( ( CamWnd_GetMode() == cd_lighting ) ? cd_texture : cd_lighting );
1709 CameraModel* g_camera_model = 0;
1711 void CamWnd_LookThroughCamera( CamWnd& camwnd ){
1712 if ( g_camera_model != 0 ) {
1713 CamWnd_Add_Handlers_Move( camwnd );
1714 g_camera_model->setCameraView( 0, Callback() );
1716 Camera_updateModelview( camwnd.getCamera() );
1717 Camera_updateProjection( camwnd.getCamera() );
1718 CamWnd_Update( camwnd );
1722 inline CameraModel* Instance_getCameraModel( scene::Instance& instance ){
1723 return InstanceTypeCast<CameraModel>::cast( instance );
1726 void CamWnd_LookThroughSelected( CamWnd& camwnd ){
1727 if ( g_camera_model != 0 ) {
1728 CamWnd_LookThroughCamera( camwnd );
1731 if ( GlobalSelectionSystem().countSelected() != 0 ) {
1732 scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
1733 CameraModel* cameraModel = Instance_getCameraModel( instance );
1734 if ( cameraModel != 0 ) {
1735 CamWnd_Remove_Handlers_Move( camwnd );
1736 g_camera_model = cameraModel;
1737 g_camera_model->setCameraView( &camwnd.getCameraView(), ReferenceCaller<CamWnd, CamWnd_LookThroughCamera>( camwnd ) );
1742 void GlobalCamera_LookThroughSelected(){
1743 CamWnd_LookThroughSelected( *g_camwnd );
1746 void GlobalCamera_LookThroughCamera(){
1747 CamWnd_LookThroughCamera( *g_camwnd );
1751 void RenderModeImport( int value ){
1755 CamWnd_SetMode( cd_wire );
1758 CamWnd_SetMode( cd_solid );
1761 CamWnd_SetMode( cd_texture );
1764 CamWnd_SetMode( cd_lighting );
1767 CamWnd_SetMode( cd_texture );
1770 typedef FreeCaller1<int, RenderModeImport> RenderModeImportCaller;
1772 void RenderModeExport( const IntImportCallback& importer ){
1773 switch ( CamWnd_GetMode() )
1789 typedef FreeCaller1<const IntImportCallback&, RenderModeExport> RenderModeExportCaller;
1791 void Camera_constructPreferences( PreferencesPage& page ){
1792 page.appendSlider( "Movement Speed", g_camwindow_globals_private.m_nMoveSpeed, TRUE, 0, 0, 100, MIN_CAM_SPEED, MAX_CAM_SPEED, 1, 10 );
1793 page.appendCheckBox( "", "Link strafe speed to movement speed", g_camwindow_globals_private.m_bCamLinkSpeed );
1794 page.appendSlider( "Rotation Speed", g_camwindow_globals_private.m_nAngleSpeed, TRUE, 0, 0, 3, 1, 180, 1, 10 );
1795 page.appendCheckBox( "", "Invert mouse vertical axis", g_camwindow_globals_private.m_bCamInverseMouse );
1796 page.appendCheckBox(
1797 "", "Discrete movement",
1798 FreeCaller1<bool, CamWnd_Move_Discrete_Import>(),
1799 BoolExportCaller( g_camwindow_globals_private.m_bCamDiscrete )
1801 page.appendCheckBox(
1802 "", "Enable far-clip plane",
1803 FreeCaller1<bool, Camera_SetFarClip>(),
1804 BoolExportCaller( g_camwindow_globals_private.m_bCubicClipping )
1807 if ( g_pGameDescription->mGameType == "doom3" ) {
1808 const char* render_mode[] = { "Wireframe", "Flatshade", "Textured", "Lighting" };
1812 STRING_ARRAY_RANGE( render_mode ),
1813 IntImportCallback( RenderModeImportCaller() ),
1814 IntExportCallback( RenderModeExportCaller() )
1819 const char* render_mode[] = { "Wireframe", "Flatshade", "Textured" };
1823 STRING_ARRAY_RANGE( render_mode ),
1824 IntImportCallback( RenderModeImportCaller() ),
1825 IntExportCallback( RenderModeExportCaller() )
1829 const char* strafe_mode[] = { "Both", "Forward", "Up" };
1833 g_camwindow_globals_private.m_nStrafeMode,
1834 STRING_ARRAY_RANGE( strafe_mode )
1837 void Camera_constructPage( PreferenceGroup& group ){
1838 PreferencesPage page( group.createPage( "Camera", "Camera View Preferences" ) );
1839 Camera_constructPreferences( page );
1841 void Camera_registerPreferencesPage(){
1842 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Camera_constructPage>() );
1845 #include "preferencesystem.h"
1846 #include "stringio.h"
1849 typedef FreeCaller1<bool, CamWnd_Move_Discrete_Import> CamWndMoveDiscreteImportCaller;
1851 void CameraSpeed_increase(){
1852 if ( g_camwindow_globals_private.m_nMoveSpeed <= ( MAX_CAM_SPEED - CAM_SPEED_STEP - 10 ) ) {
1853 g_camwindow_globals_private.m_nMoveSpeed += CAM_SPEED_STEP;
1856 g_camwindow_globals_private.m_nMoveSpeed = MAX_CAM_SPEED - 10;
1860 void CameraSpeed_decrease(){
1861 if ( g_camwindow_globals_private.m_nMoveSpeed >= ( MIN_CAM_SPEED + CAM_SPEED_STEP ) ) {
1862 g_camwindow_globals_private.m_nMoveSpeed -= CAM_SPEED_STEP;
1865 g_camwindow_globals_private.m_nMoveSpeed = MIN_CAM_SPEED;
1869 /// \brief Initialisation for things that have the same lifespan as this module.
1870 void CamWnd_Construct(){
1871 GlobalCommands_insert( "CenterView", FreeCaller<GlobalCamera_ResetAngles>(), Accelerator( GDK_KEY_End ) );
1873 GlobalToggles_insert( "ToggleCubicClip", FreeCaller<Camera_ToggleFarClip>(), ToggleItem::AddCallbackCaller( g_getfarclip_item ), Accelerator( '\\', (GdkModifierType)GDK_CONTROL_MASK ) );
1874 GlobalCommands_insert( "CubicClipZoomIn", FreeCaller<Camera_CubeIn>(), Accelerator( '[', (GdkModifierType)GDK_CONTROL_MASK ) );
1875 GlobalCommands_insert( "CubicClipZoomOut", FreeCaller<Camera_CubeOut>(), Accelerator( ']', (GdkModifierType)GDK_CONTROL_MASK ) );
1877 GlobalCommands_insert( "UpFloor", FreeCaller<Camera_ChangeFloorUp>(), Accelerator( GDK_KEY_Prior ) );
1878 GlobalCommands_insert( "DownFloor", FreeCaller<Camera_ChangeFloorDown>(), Accelerator( GDK_KEY_Next ) );
1880 GlobalToggles_insert( "ToggleCamera", ToggleShown::ToggleCaller( g_camera_shown ), ToggleItem::AddCallbackCaller( g_camera_shown.m_item ), Accelerator( 'C', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
1881 GlobalCommands_insert( "LookThroughSelected", FreeCaller<GlobalCamera_LookThroughSelected>() );
1882 GlobalCommands_insert( "LookThroughCamera", FreeCaller<GlobalCamera_LookThroughCamera>() );
1884 if ( g_pGameDescription->mGameType == "doom3" ) {
1885 GlobalCommands_insert( "TogglePreview", FreeCaller<CamWnd_TogglePreview>(), Accelerator( GDK_KEY_F3 ) );
1888 GlobalCommands_insert( "CameraSpeedInc", FreeCaller<CameraSpeed_increase>(), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)GDK_SHIFT_MASK ) );
1889 GlobalCommands_insert( "CameraSpeedDec", FreeCaller<CameraSpeed_decrease>(), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)GDK_SHIFT_MASK ) );
1891 GlobalShortcuts_insert( "CameraForward", Accelerator( GDK_KEY_Up ) );
1892 GlobalShortcuts_insert( "CameraBack", Accelerator( GDK_KEY_Down ) );
1893 GlobalShortcuts_insert( "CameraLeft", Accelerator( GDK_KEY_Left ) );
1894 GlobalShortcuts_insert( "CameraRight", Accelerator( GDK_KEY_Right ) );
1895 GlobalShortcuts_insert( "CameraStrafeRight", Accelerator( GDK_KEY_period ) );
1896 GlobalShortcuts_insert( "CameraStrafeLeft", Accelerator( GDK_KEY_comma ) );
1898 GlobalShortcuts_insert( "CameraUp", Accelerator( 'D' ) );
1899 GlobalShortcuts_insert( "CameraDown", Accelerator( 'C' ) );
1900 GlobalShortcuts_insert( "CameraAngleUp", Accelerator( 'A' ) );
1901 GlobalShortcuts_insert( "CameraAngleDown", Accelerator( 'Z' ) );
1903 GlobalShortcuts_insert( "CameraFreeMoveForward", Accelerator( GDK_KEY_Up ) );
1904 GlobalShortcuts_insert( "CameraFreeMoveBack", Accelerator( GDK_KEY_Down ) );
1905 GlobalShortcuts_insert( "CameraFreeMoveLeft", Accelerator( GDK_KEY_Left ) );
1906 GlobalShortcuts_insert( "CameraFreeMoveRight", Accelerator( GDK_KEY_Right ) );
1908 GlobalToggles_insert( "ShowStats", ShowStatsToggleCaller(), ToggleItem::AddCallbackCaller( g_show_stats ) );
1910 GlobalPreferenceSystem().registerPreference( "ShowStats", BoolImportStringCaller( g_camwindow_globals_private.m_showStats ), BoolExportStringCaller( g_camwindow_globals_private.m_showStats ) );
1911 GlobalPreferenceSystem().registerPreference( "MoveSpeed", IntImportStringCaller( g_camwindow_globals_private.m_nMoveSpeed ), IntExportStringCaller( g_camwindow_globals_private.m_nMoveSpeed ) );
1912 GlobalPreferenceSystem().registerPreference( "CamLinkSpeed", BoolImportStringCaller( g_camwindow_globals_private.m_bCamLinkSpeed ), BoolExportStringCaller( g_camwindow_globals_private.m_bCamLinkSpeed ) );
1913 GlobalPreferenceSystem().registerPreference( "AngleSpeed", IntImportStringCaller( g_camwindow_globals_private.m_nAngleSpeed ), IntExportStringCaller( g_camwindow_globals_private.m_nAngleSpeed ) );
1914 GlobalPreferenceSystem().registerPreference( "CamInverseMouse", BoolImportStringCaller( g_camwindow_globals_private.m_bCamInverseMouse ), BoolExportStringCaller( g_camwindow_globals_private.m_bCamInverseMouse ) );
1915 GlobalPreferenceSystem().registerPreference( "CamDiscrete", makeBoolStringImportCallback( CamWndMoveDiscreteImportCaller() ), BoolExportStringCaller( g_camwindow_globals_private.m_bCamDiscrete ) );
1916 GlobalPreferenceSystem().registerPreference( "CubicClipping", BoolImportStringCaller( g_camwindow_globals_private.m_bCubicClipping ), BoolExportStringCaller( g_camwindow_globals_private.m_bCubicClipping ) );
1917 GlobalPreferenceSystem().registerPreference( "CubicScale", IntImportStringCaller( g_camwindow_globals.m_nCubicScale ), IntExportStringCaller( g_camwindow_globals.m_nCubicScale ) );
1918 GlobalPreferenceSystem().registerPreference( "SI_Colors4", Vector3ImportStringCaller( g_camwindow_globals.color_cameraback ), Vector3ExportStringCaller( g_camwindow_globals.color_cameraback ) );
1919 GlobalPreferenceSystem().registerPreference( "SI_Colors12", Vector3ImportStringCaller( g_camwindow_globals.color_selbrushes3d ), Vector3ExportStringCaller( g_camwindow_globals.color_selbrushes3d ) );
1920 GlobalPreferenceSystem().registerPreference( "CameraRenderMode", makeIntStringImportCallback( RenderModeImportCaller() ), makeIntStringExportCallback( RenderModeExportCaller() ) );
1921 GlobalPreferenceSystem().registerPreference( "StrafeMode", IntImportStringCaller( g_camwindow_globals_private.m_nStrafeMode ), IntExportStringCaller( g_camwindow_globals_private.m_nStrafeMode ) );
1923 CamWnd_constructStatic();
1925 Camera_registerPreferencesPage();
1927 void CamWnd_Destroy(){
1928 CamWnd_destroyStatic();