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"
30 #include "debugging/debugging.h"
32 #include "iscenegraph.h"
37 #include "renderable.h"
38 #include "preferencesystem.h"
40 #include "signal/signal.h"
41 #include "container/array.h"
45 #include "math/frustum.h"
47 #include "gtkutil/widget.h"
48 #include "gtkutil/button.h"
49 #include "gtkutil/toolbar.h"
50 #include "gtkutil/glwidget.h"
51 #include "gtkutil/xorrectangle.h"
53 #include "selection.h"
54 #include "mainframe.h"
55 #include "preferences.h"
58 #include "windowobservers.h"
59 #include "renderstate.h"
63 Signal0 g_cameraMoved_callbacks;
65 void AddCameraMovedCallback( const SignalHandler& handler ){
66 g_cameraMoved_callbacks.connectLast( handler );
69 void CameraMovedNotify(){
70 g_cameraMoved_callbacks();
74 struct camwindow_globals_private_t
79 bool m_bCamInverseMouse;
81 bool m_bCubicClipping;
85 camwindow_globals_private_t() :
87 m_bCamLinkSpeed( true ),
89 m_bCamInverseMouse( false ),
90 m_bCamDiscrete( true ),
91 m_bCubicClipping( true ),
98 camwindow_globals_private_t g_camwindow_globals_private;
101 const Matrix4 g_opengl2radiant(
108 const Matrix4 g_radiant2opengl(
116 void Camera_mouseMove( camera_t& camera, int x, int y );
118 enum camera_draw_mode
135 Vector3 color; // background
137 Vector3 forward, right; // move matrix (TTimo: used to have up but it was not updated)
138 Vector3 vup, vpn, vright; // view matrix (taken from the modelview matrix)
143 bool m_strafe; // true when in strafemode toggled by the ctrl-key
144 bool m_strafe_forward; // true when in strafemode by ctrl-key and shift is pressed for forward strafing
146 unsigned int movementflags; // movement flags
147 Timer m_keycontrol_timer;
148 guint m_keymove_handler;
153 DeferredMotionDelta m_mouseMove;
155 static void motionDelta( int x, int y, void* data ){
156 Camera_mouseMove( *reinterpret_cast<camera_t*>( data ), x, y );
162 static camera_draw_mode draw_mode;
164 camera_t( View* view, const Callback& update )
172 m_keymove_handler( 0 ),
173 fieldOfView( 90.0f ),
174 m_mouseMove( motionDelta, this ),
180 camera_draw_mode camera_t::draw_mode = cd_texture;
182 inline Matrix4 projection_for_camera( float near_z, float far_z, float fieldOfView, int width, int height ){
183 const float half_width = static_cast<float>( near_z * tan( degrees_to_radians( fieldOfView * 0.5 ) ) );
184 const float half_height = half_width * ( static_cast<float>( height ) / static_cast<float>( width ) );
186 return matrix4_frustum(
196 float Camera_getFarClipPlane( camera_t& camera ){
197 return ( g_camwindow_globals_private.m_bCubicClipping ) ? pow( 2.0, ( g_camwindow_globals.m_nCubicScale + 7 ) / 2.0 ) : 32768.0f;
200 void Camera_updateProjection( camera_t& camera ){
201 float farClip = Camera_getFarClipPlane( camera );
202 camera.projection = projection_for_camera( farClip / 4096.0f, farClip, camera.fieldOfView, camera.width, camera.height );
204 camera.m_view->Construct( camera.projection, camera.modelview, camera.width, camera.height );
207 void Camera_updateVectors( camera_t& camera ){
208 for ( int i = 0 ; i < 3 ; i++ )
210 camera.vright[i] = camera.modelview[( i << 2 ) + 0];
211 camera.vup[i] = camera.modelview[( i << 2 ) + 1];
212 camera.vpn[i] = camera.modelview[( i << 2 ) + 2];
216 void Camera_updateModelview( camera_t& camera ){
217 camera.modelview = g_matrix4_identity;
220 Vector3 radiant_eulerXYZ( 0, -camera.angles[CAMERA_PITCH], camera.angles[CAMERA_YAW] );
222 matrix4_translate_by_vec3( camera.modelview, camera.origin );
223 matrix4_rotate_by_euler_xyz_degrees( camera.modelview, radiant_eulerXYZ );
224 matrix4_multiply_by_matrix4( camera.modelview, g_radiant2opengl );
225 matrix4_affine_invert( camera.modelview );
227 Camera_updateVectors( camera );
229 camera.m_view->Construct( camera.projection, camera.modelview, camera.width, camera.height );
233 void Camera_Move_updateAxes( camera_t& camera ){
234 double ya = degrees_to_radians( camera.angles[CAMERA_YAW] );
236 // the movement matrix is kept 2d
237 camera.forward[0] = static_cast<float>( cos( ya ) );
238 camera.forward[1] = static_cast<float>( sin( ya ) );
239 camera.forward[2] = 0;
240 camera.right[0] = camera.forward[1];
241 camera.right[1] = -camera.forward[0];
244 void Camera_Freemove_updateAxes( camera_t& camera ){
245 camera.right = camera.vright;
246 camera.forward = vector3_negated( camera.vpn );
249 const Vector3& Camera_getOrigin( camera_t& camera ){
250 return camera.origin;
253 void Camera_setOrigin( camera_t& camera, const Vector3& origin ){
254 camera.origin = origin;
255 Camera_updateModelview( camera );
260 const Vector3& Camera_getAngles( camera_t& camera ){
261 return camera.angles;
264 void Camera_setAngles( camera_t& camera, const Vector3& angles ){
265 camera.angles = angles;
266 Camera_updateModelview( camera );
272 void Camera_FreeMove( camera_t& camera, int dx, int dy ){
273 // free strafe mode, toggled by the ctrl key with optional shift for forward movement
274 if ( camera.m_strafe ) {
275 float strafespeed = 0.65f;
277 if ( g_camwindow_globals_private.m_bCamLinkSpeed ) {
278 strafespeed = (float)g_camwindow_globals_private.m_nMoveSpeed / 100;
281 camera.origin -= camera.vright * strafespeed * dx;
282 if ( camera.m_strafe_forward ) {
283 camera.origin += camera.vpn * strafespeed * dy;
286 camera.origin += camera.vup * strafespeed * dy;
289 else // free rotation
291 const float dtime = 0.1f;
293 if ( g_camwindow_globals_private.m_bCamInverseMouse ) {
294 camera.angles[CAMERA_PITCH] -= dy * dtime * g_camwindow_globals_private.m_nAngleSpeed;
297 camera.angles[CAMERA_PITCH] += dy * dtime * g_camwindow_globals_private.m_nAngleSpeed;
300 camera.angles[CAMERA_YAW] += dx * dtime * g_camwindow_globals_private.m_nAngleSpeed;
302 if ( camera.angles[CAMERA_PITCH] > 90 ) {
303 camera.angles[CAMERA_PITCH] = 90;
305 else if ( camera.angles[CAMERA_PITCH] < -90 ) {
306 camera.angles[CAMERA_PITCH] = -90;
309 if ( camera.angles[CAMERA_YAW] >= 360 ) {
310 camera.angles[CAMERA_YAW] -= 360;
312 else if ( camera.angles[CAMERA_YAW] <= 0 ) {
313 camera.angles[CAMERA_YAW] += 360;
317 Camera_updateModelview( camera );
318 Camera_Freemove_updateAxes( camera );
321 void Cam_MouseControl( camera_t& camera, int x, int y ){
326 xf = (float)( x - camera.width / 2 ) / ( camera.width / 2 );
327 yf = (float)( y - camera.height / 2 ) / ( camera.height / 2 );
329 xl = camera.width / 3;
331 yl = camera.height / 3;
334 xf *= 1.0f - fabsf( yf );
349 vector3_add( camera.origin, vector3_scaled( camera.forward, yf * 0.1f * g_camwindow_globals_private.m_nMoveSpeed ) );
350 camera.angles[CAMERA_YAW] += xf * -0.1f * g_camwindow_globals_private.m_nAngleSpeed;
352 Camera_updateModelview( camera );
355 void Camera_mouseMove( camera_t& camera, int x, int y ){
356 //globalOutputStream() << "mousemove... ";
357 Camera_FreeMove( camera, -x, -y );
362 const unsigned int MOVE_NONE = 0;
363 const unsigned int MOVE_FORWARD = 1 << 0;
364 const unsigned int MOVE_BACK = 1 << 1;
365 const unsigned int MOVE_ROTRIGHT = 1 << 2;
366 const unsigned int MOVE_ROTLEFT = 1 << 3;
367 const unsigned int MOVE_STRAFERIGHT = 1 << 4;
368 const unsigned int MOVE_STRAFELEFT = 1 << 5;
369 const unsigned int MOVE_UP = 1 << 6;
370 const unsigned int MOVE_DOWN = 1 << 7;
371 const unsigned int MOVE_PITCHUP = 1 << 8;
372 const unsigned int MOVE_PITCHDOWN = 1 << 9;
373 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;
375 void Cam_KeyControl( camera_t& camera, float dtime ){
377 if ( camera.movementflags & MOVE_ROTLEFT ) {
378 camera.angles[CAMERA_YAW] += 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed;
380 if ( camera.movementflags & MOVE_ROTRIGHT ) {
381 camera.angles[CAMERA_YAW] -= 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed;
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;
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;
396 Camera_updateModelview( camera );
397 Camera_Freemove_updateAxes( camera );
400 if ( camera.movementflags & MOVE_FORWARD ) {
401 vector3_add( camera.origin, vector3_scaled( camera.forward, dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
403 if ( camera.movementflags & MOVE_BACK ) {
404 vector3_add( camera.origin, vector3_scaled( camera.forward, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
406 if ( camera.movementflags & MOVE_STRAFELEFT ) {
407 vector3_add( camera.origin, vector3_scaled( camera.right, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
409 if ( camera.movementflags & MOVE_STRAFERIGHT ) {
410 vector3_add( camera.origin, vector3_scaled( camera.right, dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
412 if ( camera.movementflags & MOVE_UP ) {
413 vector3_add( camera.origin, vector3_scaled( g_vector3_axis_z, dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
415 if ( camera.movementflags & MOVE_DOWN ) {
416 vector3_add( camera.origin, vector3_scaled( g_vector3_axis_z, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
419 Camera_updateModelview( camera );
422 void Camera_keyMove( camera_t& camera ){
423 camera.m_mouseMove.flush();
425 //globalOutputStream() << "keymove... ";
426 float time_seconds = camera.m_keycontrol_timer.elapsed_msec() / static_cast<float>( msec_per_sec );
427 camera.m_keycontrol_timer.start();
428 if ( time_seconds > 0.05f ) {
429 time_seconds = 0.05f; // 20fps
431 Cam_KeyControl( camera, time_seconds * 5.0f );
437 gboolean camera_keymove( gpointer data ){
438 Camera_keyMove( *reinterpret_cast<camera_t*>( data ) );
442 void Camera_setMovementFlags( camera_t& camera, unsigned int mask ){
443 if ( ( ~camera.movementflags & mask ) != 0 && camera.movementflags == 0 ) {
444 camera.m_keymove_handler = g_idle_add( camera_keymove, &camera );
446 camera.movementflags |= mask;
448 void Camera_clearMovementFlags( camera_t& camera, unsigned int mask ){
449 if ( ( camera.movementflags & ~mask ) == 0 && camera.movementflags != 0 ) {
450 g_source_remove( camera.m_keymove_handler );
451 camera.m_keymove_handler = 0;
453 camera.movementflags &= ~mask;
456 void Camera_MoveForward_KeyDown( camera_t& camera ){
457 Camera_setMovementFlags( camera, MOVE_FORWARD );
459 void Camera_MoveForward_KeyUp( camera_t& camera ){
460 Camera_clearMovementFlags( camera, MOVE_FORWARD );
462 void Camera_MoveBack_KeyDown( camera_t& camera ){
463 Camera_setMovementFlags( camera, MOVE_BACK );
465 void Camera_MoveBack_KeyUp( camera_t& camera ){
466 Camera_clearMovementFlags( camera, MOVE_BACK );
469 void Camera_MoveLeft_KeyDown( camera_t& camera ){
470 Camera_setMovementFlags( camera, MOVE_STRAFELEFT );
472 void Camera_MoveLeft_KeyUp( camera_t& camera ){
473 Camera_clearMovementFlags( camera, MOVE_STRAFELEFT );
475 void Camera_MoveRight_KeyDown( camera_t& camera ){
476 Camera_setMovementFlags( camera, MOVE_STRAFERIGHT );
478 void Camera_MoveRight_KeyUp( camera_t& camera ){
479 Camera_clearMovementFlags( camera, MOVE_STRAFERIGHT );
482 void Camera_MoveUp_KeyDown( camera_t& camera ){
483 Camera_setMovementFlags( camera, MOVE_UP );
485 void Camera_MoveUp_KeyUp( camera_t& camera ){
486 Camera_clearMovementFlags( camera, MOVE_UP );
488 void Camera_MoveDown_KeyDown( camera_t& camera ){
489 Camera_setMovementFlags( camera, MOVE_DOWN );
491 void Camera_MoveDown_KeyUp( camera_t& camera ){
492 Camera_clearMovementFlags( camera, MOVE_DOWN );
495 void Camera_RotateLeft_KeyDown( camera_t& camera ){
496 Camera_setMovementFlags( camera, MOVE_ROTLEFT );
498 void Camera_RotateLeft_KeyUp( camera_t& camera ){
499 Camera_clearMovementFlags( camera, MOVE_ROTLEFT );
501 void Camera_RotateRight_KeyDown( camera_t& camera ){
502 Camera_setMovementFlags( camera, MOVE_ROTRIGHT );
504 void Camera_RotateRight_KeyUp( camera_t& camera ){
505 Camera_clearMovementFlags( camera, MOVE_ROTRIGHT );
508 void Camera_PitchUp_KeyDown( camera_t& camera ){
509 Camera_setMovementFlags( camera, MOVE_PITCHUP );
511 void Camera_PitchUp_KeyUp( camera_t& camera ){
512 Camera_clearMovementFlags( camera, MOVE_PITCHUP );
514 void Camera_PitchDown_KeyDown( camera_t& camera ){
515 Camera_setMovementFlags( camera, MOVE_PITCHDOWN );
517 void Camera_PitchDown_KeyUp( camera_t& camera ){
518 Camera_clearMovementFlags( camera, MOVE_PITCHDOWN );
522 typedef ReferenceCaller<camera_t, &Camera_MoveForward_KeyDown> FreeMoveCameraMoveForwardKeyDownCaller;
523 typedef ReferenceCaller<camera_t, &Camera_MoveForward_KeyUp> FreeMoveCameraMoveForwardKeyUpCaller;
524 typedef ReferenceCaller<camera_t, &Camera_MoveBack_KeyDown> FreeMoveCameraMoveBackKeyDownCaller;
525 typedef ReferenceCaller<camera_t, &Camera_MoveBack_KeyUp> FreeMoveCameraMoveBackKeyUpCaller;
526 typedef ReferenceCaller<camera_t, &Camera_MoveLeft_KeyDown> FreeMoveCameraMoveLeftKeyDownCaller;
527 typedef ReferenceCaller<camera_t, &Camera_MoveLeft_KeyUp> FreeMoveCameraMoveLeftKeyUpCaller;
528 typedef ReferenceCaller<camera_t, &Camera_MoveRight_KeyDown> FreeMoveCameraMoveRightKeyDownCaller;
529 typedef ReferenceCaller<camera_t, &Camera_MoveRight_KeyUp> FreeMoveCameraMoveRightKeyUpCaller;
530 typedef ReferenceCaller<camera_t, &Camera_MoveUp_KeyDown> FreeMoveCameraMoveUpKeyDownCaller;
531 typedef ReferenceCaller<camera_t, &Camera_MoveUp_KeyUp> FreeMoveCameraMoveUpKeyUpCaller;
532 typedef ReferenceCaller<camera_t, &Camera_MoveDown_KeyDown> FreeMoveCameraMoveDownKeyDownCaller;
533 typedef ReferenceCaller<camera_t, &Camera_MoveDown_KeyUp> FreeMoveCameraMoveDownKeyUpCaller;
536 #define SPEED_MOVE 32
537 #define SPEED_TURN 22.5
538 #define MIN_CAM_SPEED 10
539 #define MAX_CAM_SPEED 610
540 #define CAM_SPEED_STEP 50
542 void Camera_MoveForward_Discrete( camera_t& camera ){
543 Camera_Move_updateAxes( camera );
544 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.forward, SPEED_MOVE ) ) );
546 void Camera_MoveBack_Discrete( camera_t& camera ){
547 Camera_Move_updateAxes( camera );
548 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.forward, -SPEED_MOVE ) ) );
551 void Camera_MoveUp_Discrete( camera_t& camera ){
552 Vector3 origin( Camera_getOrigin( camera ) );
553 origin[2] += SPEED_MOVE;
554 Camera_setOrigin( camera, origin );
556 void Camera_MoveDown_Discrete( camera_t& camera ){
557 Vector3 origin( Camera_getOrigin( camera ) );
558 origin[2] -= SPEED_MOVE;
559 Camera_setOrigin( camera, origin );
562 void Camera_MoveLeft_Discrete( camera_t& camera ){
563 Camera_Move_updateAxes( camera );
564 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.right, -SPEED_MOVE ) ) );
566 void Camera_MoveRight_Discrete( camera_t& camera ){
567 Camera_Move_updateAxes( camera );
568 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.right, SPEED_MOVE ) ) );
571 void Camera_RotateLeft_Discrete( camera_t& camera ){
572 Vector3 angles( Camera_getAngles( camera ) );
573 angles[CAMERA_YAW] += SPEED_TURN;
574 Camera_setAngles( camera, angles );
576 void Camera_RotateRight_Discrete( camera_t& camera ){
577 Vector3 angles( Camera_getAngles( camera ) );
578 angles[CAMERA_YAW] -= SPEED_TURN;
579 Camera_setAngles( camera, angles );
582 void Camera_PitchUp_Discrete( camera_t& camera ){
583 Vector3 angles( Camera_getAngles( camera ) );
584 angles[CAMERA_PITCH] += SPEED_TURN;
585 if ( angles[CAMERA_PITCH] > 90 ) {
586 angles[CAMERA_PITCH] = 90;
588 Camera_setAngles( camera, angles );
590 void Camera_PitchDown_Discrete( camera_t& camera ){
591 Vector3 angles( Camera_getAngles( camera ) );
592 angles[CAMERA_PITCH] -= SPEED_TURN;
593 if ( angles[CAMERA_PITCH] < -90 ) {
594 angles[CAMERA_PITCH] = -90;
596 Camera_setAngles( camera, angles );
600 class RadiantCameraView : public CameraView
606 RadiantCameraView( camera_t& camera, View* view, const Callback& update ) : m_camera( camera ), m_view( view ), m_update( update ){
609 m_view->Construct( m_camera.projection, m_camera.modelview, m_camera.width, m_camera.height );
612 void setModelview( const Matrix4& modelview ){
613 m_camera.modelview = modelview;
614 matrix4_multiply_by_matrix4( m_camera.modelview, g_radiant2opengl );
615 matrix4_affine_invert( m_camera.modelview );
616 Camera_updateVectors( m_camera );
619 void setFieldOfView( float fieldOfView ){
620 float farClip = Camera_getFarClipPlane( m_camera );
621 m_camera.projection = projection_for_camera( farClip / 4096.0f, farClip, fieldOfView, m_camera.width, m_camera.height );
627 void Camera_motionDelta( int x, int y, unsigned int state, void* data ){
628 camera_t* cam = reinterpret_cast<camera_t*>( data );
630 cam->m_mouseMove.motion_delta( x, y, state );
632 switch ( g_camwindow_globals_private.m_nStrafeMode )
635 cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0;
636 if ( cam->m_strafe ) {
637 cam->m_strafe_forward = ( state & GDK_SHIFT_MASK ) != 0;
640 cam->m_strafe_forward = false;
644 cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0 && ( state & GDK_SHIFT_MASK ) == 0;
645 cam->m_strafe_forward = false;
648 cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0 && ( state & GDK_SHIFT_MASK ) == 0;
649 cam->m_strafe_forward = cam->m_strafe;
658 RadiantCameraView m_cameraview;
660 guint m_freemove_handle_focusout;
662 static Shader* m_state_select1;
663 static Shader* m_state_select2;
665 FreezePointer m_freezePointer;
668 GtkWidget* m_gl_widget;
671 SelectionSystemWindowObserver* m_window_observer;
672 XORRectangle m_XORRectangle;
674 DeferredDraw m_deferredDraw;
675 DeferredMotion m_deferred_motion;
677 guint m_selection_button_press_handler;
678 guint m_selection_button_release_handler;
679 guint m_selection_motion_handler;
681 guint m_freelook_button_press_handler;
684 guint m_exposeHandler;
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 GtkWidget* CamWnd_getWidget( CamWnd& camwnd ){
754 return camwnd.m_gl_widget;
757 GtkWindow* CamWnd_getParent( CamWnd& camwnd ){
758 return camwnd.m_parent;
761 ToggleShown g_camera_shown( true );
763 void CamWnd_setParent( CamWnd& camwnd, GtkWindow* parent ){
764 camwnd.m_parent = parent;
765 g_camera_shown.connect( GTK_WIDGET( 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( GtkWidget* widget, GdkEventButton* event, CamWnd* camwnd ){
797 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
798 camwnd->EnableFreeMove();
804 gboolean disable_freelook_button_press( GtkWidget* widget, GdkEventButton* event, CamWnd* camwnd ){
805 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
806 camwnd->DisableFreeMove();
812 void camwnd_update_xor_rectangle( CamWnd& self, rect_t area ){
813 if ( GTK_WIDGET_VISIBLE( self.m_gl_widget ) ) {
814 self.m_XORRectangle.set( rectangle_from_area( area.min, area.max, self.getCamera().width, self.getCamera().height ) );
819 gboolean selection_button_press( GtkWidget* widget, GdkEventButton* event, WindowObserver* observer ){
820 if ( event->type == GDK_BUTTON_PRESS ) {
821 observer->onMouseDown( WindowVector_forDouble( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
826 gboolean selection_button_release( GtkWidget* widget, GdkEventButton* event, WindowObserver* observer ){
827 if ( event->type == GDK_BUTTON_RELEASE ) {
828 observer->onMouseUp( WindowVector_forDouble( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
833 void selection_motion( gdouble x, gdouble y, guint state, void* data ){
834 //globalOutputStream() << "motion... ";
835 reinterpret_cast<WindowObserver*>( data )->onMouseMotion( WindowVector_forDouble( x, y ), modifiers_for_state( state ) );
838 inline WindowVector windowvector_for_widget_centre( GtkWidget* widget ){
839 return WindowVector( static_cast<float>( widget->allocation.width / 2 ), static_cast<float>( widget->allocation.height / 2 ) );
842 gboolean selection_button_press_freemove( GtkWidget* widget, GdkEventButton* event, WindowObserver* observer ){
843 if ( event->type == GDK_BUTTON_PRESS ) {
844 observer->onMouseDown( windowvector_for_widget_centre( widget ), button_for_button( event->button ), modifiers_for_state( event->state ) );
849 gboolean selection_button_release_freemove( GtkWidget* widget, GdkEventButton* event, WindowObserver* observer ){
850 if ( event->type == GDK_BUTTON_RELEASE ) {
851 observer->onMouseUp( windowvector_for_widget_centre( widget ), button_for_button( event->button ), modifiers_for_state( event->state ) );
856 gboolean selection_motion_freemove( GtkWidget *widget, GdkEventMotion *event, WindowObserver* observer ){
857 observer->onMouseMotion( windowvector_for_widget_centre( widget ), modifiers_for_state( event->state ) );
861 gboolean wheelmove_scroll( GtkWidget* widget, GdkEventScroll* event, CamWnd* camwnd ){
862 if ( event->direction == GDK_SCROLL_UP ) {
863 Camera_Freemove_updateAxes( camwnd->getCamera() );
864 Camera_setOrigin( *camwnd, vector3_added( Camera_getOrigin( *camwnd ), vector3_scaled( camwnd->getCamera().forward, static_cast<float>( g_camwindow_globals_private.m_nMoveSpeed ) ) ) );
866 else if ( event->direction == GDK_SCROLL_DOWN ) {
867 Camera_Freemove_updateAxes( camwnd->getCamera() );
868 Camera_setOrigin( *camwnd, vector3_added( Camera_getOrigin( *camwnd ), vector3_scaled( camwnd->getCamera().forward, -static_cast<float>( g_camwindow_globals_private.m_nMoveSpeed ) ) ) );
874 gboolean camera_size_allocate( GtkWidget* widget, GtkAllocation* allocation, CamWnd* camwnd ){
875 camwnd->getCamera().width = allocation->width;
876 camwnd->getCamera().height = allocation->height;
877 Camera_updateProjection( camwnd->getCamera() );
878 camwnd->m_window_observer->onSizeChanged( camwnd->getCamera().width, camwnd->getCamera().height );
879 camwnd->queue_draw();
883 gboolean camera_expose( GtkWidget* widget, GdkEventExpose* event, gpointer data ){
884 reinterpret_cast<CamWnd*>( data )->draw();
888 void KeyEvent_connect( const char* name ){
889 const KeyEvent& keyEvent = GlobalKeyEvents_find( name );
890 keydown_accelerators_add( keyEvent.m_accelerator, keyEvent.m_keyDown );
891 keyup_accelerators_add( keyEvent.m_accelerator, keyEvent.m_keyUp );
894 void KeyEvent_disconnect( const char* name ){
895 const KeyEvent& keyEvent = GlobalKeyEvents_find( name );
896 keydown_accelerators_remove( keyEvent.m_accelerator );
897 keyup_accelerators_remove( keyEvent.m_accelerator );
900 void CamWnd_registerCommands( CamWnd& camwnd ){
901 GlobalKeyEvents_insert( "CameraForward", Accelerator( GDK_Up ),
902 ReferenceCaller<camera_t, Camera_MoveForward_KeyDown>( camwnd.getCamera() ),
903 ReferenceCaller<camera_t, Camera_MoveForward_KeyUp>( camwnd.getCamera() )
905 GlobalKeyEvents_insert( "CameraBack", Accelerator( GDK_Down ),
906 ReferenceCaller<camera_t, Camera_MoveBack_KeyDown>( camwnd.getCamera() ),
907 ReferenceCaller<camera_t, Camera_MoveBack_KeyUp>( camwnd.getCamera() )
909 GlobalKeyEvents_insert( "CameraLeft", Accelerator( GDK_Left ),
910 ReferenceCaller<camera_t, Camera_RotateLeft_KeyDown>( camwnd.getCamera() ),
911 ReferenceCaller<camera_t, Camera_RotateLeft_KeyUp>( camwnd.getCamera() )
913 GlobalKeyEvents_insert( "CameraRight", Accelerator( GDK_Right ),
914 ReferenceCaller<camera_t, Camera_RotateRight_KeyDown>( camwnd.getCamera() ),
915 ReferenceCaller<camera_t, Camera_RotateRight_KeyUp>( camwnd.getCamera() )
917 GlobalKeyEvents_insert( "CameraStrafeRight", Accelerator( GDK_period ),
918 ReferenceCaller<camera_t, Camera_MoveRight_KeyDown>( camwnd.getCamera() ),
919 ReferenceCaller<camera_t, Camera_MoveRight_KeyUp>( camwnd.getCamera() )
921 GlobalKeyEvents_insert( "CameraStrafeLeft", Accelerator( GDK_comma ),
922 ReferenceCaller<camera_t, Camera_MoveLeft_KeyDown>( camwnd.getCamera() ),
923 ReferenceCaller<camera_t, Camera_MoveLeft_KeyUp>( camwnd.getCamera() )
925 GlobalKeyEvents_insert( "CameraUp", Accelerator( 'D' ),
926 ReferenceCaller<camera_t, Camera_MoveUp_KeyDown>( camwnd.getCamera() ),
927 ReferenceCaller<camera_t, Camera_MoveUp_KeyUp>( camwnd.getCamera() )
929 GlobalKeyEvents_insert( "CameraDown", Accelerator( 'C' ),
930 ReferenceCaller<camera_t, Camera_MoveDown_KeyDown>( camwnd.getCamera() ),
931 ReferenceCaller<camera_t, Camera_MoveDown_KeyUp>( camwnd.getCamera() )
933 GlobalKeyEvents_insert( "CameraAngleDown", Accelerator( 'A' ),
934 ReferenceCaller<camera_t, Camera_PitchDown_KeyDown>( camwnd.getCamera() ),
935 ReferenceCaller<camera_t, Camera_PitchDown_KeyUp>( camwnd.getCamera() )
937 GlobalKeyEvents_insert( "CameraAngleUp", Accelerator( 'Z' ),
938 ReferenceCaller<camera_t, Camera_PitchUp_KeyDown>( camwnd.getCamera() ),
939 ReferenceCaller<camera_t, Camera_PitchUp_KeyUp>( camwnd.getCamera() )
942 GlobalKeyEvents_insert( "CameraFreeMoveForward", Accelerator( GDK_Up ),
943 FreeMoveCameraMoveForwardKeyDownCaller( camwnd.getCamera() ),
944 FreeMoveCameraMoveForwardKeyUpCaller( camwnd.getCamera() )
946 GlobalKeyEvents_insert( "CameraFreeMoveBack", Accelerator( GDK_Down ),
947 FreeMoveCameraMoveBackKeyDownCaller( camwnd.getCamera() ),
948 FreeMoveCameraMoveBackKeyUpCaller( camwnd.getCamera() )
950 GlobalKeyEvents_insert( "CameraFreeMoveLeft", Accelerator( GDK_Left ),
951 FreeMoveCameraMoveLeftKeyDownCaller( camwnd.getCamera() ),
952 FreeMoveCameraMoveLeftKeyUpCaller( camwnd.getCamera() )
954 GlobalKeyEvents_insert( "CameraFreeMoveRight", Accelerator( GDK_Right ),
955 FreeMoveCameraMoveRightKeyDownCaller( camwnd.getCamera() ),
956 FreeMoveCameraMoveRightKeyUpCaller( camwnd.getCamera() )
958 GlobalKeyEvents_insert( "CameraFreeMoveUp", Accelerator( 'D' ),
959 FreeMoveCameraMoveUpKeyDownCaller( camwnd.getCamera() ),
960 FreeMoveCameraMoveUpKeyUpCaller( camwnd.getCamera() )
962 GlobalKeyEvents_insert( "CameraFreeMoveDown", Accelerator( 'C' ),
963 FreeMoveCameraMoveDownKeyDownCaller( camwnd.getCamera() ),
964 FreeMoveCameraMoveDownKeyUpCaller( camwnd.getCamera() )
967 GlobalCommands_insert( "CameraForward", ReferenceCaller<camera_t, Camera_MoveForward_Discrete>( camwnd.getCamera() ), Accelerator( GDK_Up ) );
968 GlobalCommands_insert( "CameraBack", ReferenceCaller<camera_t, Camera_MoveBack_Discrete>( camwnd.getCamera() ), Accelerator( GDK_Down ) );
969 GlobalCommands_insert( "CameraLeft", ReferenceCaller<camera_t, Camera_RotateLeft_Discrete>( camwnd.getCamera() ), Accelerator( GDK_Left ) );
970 GlobalCommands_insert( "CameraRight", ReferenceCaller<camera_t, Camera_RotateRight_Discrete>( camwnd.getCamera() ), Accelerator( GDK_Right ) );
971 GlobalCommands_insert( "CameraStrafeRight", ReferenceCaller<camera_t, Camera_MoveRight_Discrete>( camwnd.getCamera() ), Accelerator( GDK_period ) );
972 GlobalCommands_insert( "CameraStrafeLeft", ReferenceCaller<camera_t, Camera_MoveLeft_Discrete>( camwnd.getCamera() ), Accelerator( GDK_comma ) );
974 GlobalCommands_insert( "CameraUp", ReferenceCaller<camera_t, Camera_MoveUp_Discrete>( camwnd.getCamera() ), Accelerator( 'D' ) );
975 GlobalCommands_insert( "CameraDown", ReferenceCaller<camera_t, Camera_MoveDown_Discrete>( camwnd.getCamera() ), Accelerator( 'C' ) );
976 GlobalCommands_insert( "CameraAngleUp", ReferenceCaller<camera_t, Camera_PitchUp_Discrete>( camwnd.getCamera() ), Accelerator( 'A' ) );
977 GlobalCommands_insert( "CameraAngleDown", ReferenceCaller<camera_t, Camera_PitchDown_Discrete>( camwnd.getCamera() ), Accelerator( 'Z' ) );
980 void CamWnd_Move_Enable( CamWnd& camwnd ){
981 KeyEvent_connect( "CameraForward" );
982 KeyEvent_connect( "CameraBack" );
983 KeyEvent_connect( "CameraLeft" );
984 KeyEvent_connect( "CameraRight" );
985 KeyEvent_connect( "CameraStrafeRight" );
986 KeyEvent_connect( "CameraStrafeLeft" );
987 KeyEvent_connect( "CameraUp" );
988 KeyEvent_connect( "CameraDown" );
989 KeyEvent_connect( "CameraAngleUp" );
990 KeyEvent_connect( "CameraAngleDown" );
993 void CamWnd_Move_Disable( CamWnd& camwnd ){
994 KeyEvent_disconnect( "CameraForward" );
995 KeyEvent_disconnect( "CameraBack" );
996 KeyEvent_disconnect( "CameraLeft" );
997 KeyEvent_disconnect( "CameraRight" );
998 KeyEvent_disconnect( "CameraStrafeRight" );
999 KeyEvent_disconnect( "CameraStrafeLeft" );
1000 KeyEvent_disconnect( "CameraUp" );
1001 KeyEvent_disconnect( "CameraDown" );
1002 KeyEvent_disconnect( "CameraAngleUp" );
1003 KeyEvent_disconnect( "CameraAngleDown" );
1006 void CamWnd_Move_Discrete_Enable( CamWnd& camwnd ){
1007 command_connect_accelerator( "CameraForward" );
1008 command_connect_accelerator( "CameraBack" );
1009 command_connect_accelerator( "CameraLeft" );
1010 command_connect_accelerator( "CameraRight" );
1011 command_connect_accelerator( "CameraStrafeRight" );
1012 command_connect_accelerator( "CameraStrafeLeft" );
1013 command_connect_accelerator( "CameraUp" );
1014 command_connect_accelerator( "CameraDown" );
1015 command_connect_accelerator( "CameraAngleUp" );
1016 command_connect_accelerator( "CameraAngleDown" );
1019 void CamWnd_Move_Discrete_Disable( CamWnd& camwnd ){
1020 command_disconnect_accelerator( "CameraForward" );
1021 command_disconnect_accelerator( "CameraBack" );
1022 command_disconnect_accelerator( "CameraLeft" );
1023 command_disconnect_accelerator( "CameraRight" );
1024 command_disconnect_accelerator( "CameraStrafeRight" );
1025 command_disconnect_accelerator( "CameraStrafeLeft" );
1026 command_disconnect_accelerator( "CameraUp" );
1027 command_disconnect_accelerator( "CameraDown" );
1028 command_disconnect_accelerator( "CameraAngleUp" );
1029 command_disconnect_accelerator( "CameraAngleDown" );
1032 void CamWnd_Move_Discrete_Import( CamWnd& camwnd, bool value ){
1033 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1034 CamWnd_Move_Discrete_Disable( camwnd );
1038 CamWnd_Move_Disable( camwnd );
1041 g_camwindow_globals_private.m_bCamDiscrete = value;
1043 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1044 CamWnd_Move_Discrete_Enable( camwnd );
1048 CamWnd_Move_Enable( camwnd );
1052 void CamWnd_Move_Discrete_Import( bool value ){
1053 if ( g_camwnd != 0 ) {
1054 CamWnd_Move_Discrete_Import( *g_camwnd, value );
1058 g_camwindow_globals_private.m_bCamDiscrete = value;
1064 void CamWnd_Add_Handlers_Move( CamWnd& camwnd ){
1065 camwnd.m_selection_button_press_handler = g_signal_connect( G_OBJECT( camwnd.m_gl_widget ), "button_press_event", G_CALLBACK( selection_button_press ), camwnd.m_window_observer );
1066 camwnd.m_selection_button_release_handler = g_signal_connect( G_OBJECT( camwnd.m_gl_widget ), "button_release_event", G_CALLBACK( selection_button_release ), camwnd.m_window_observer );
1067 camwnd.m_selection_motion_handler = g_signal_connect( G_OBJECT( camwnd.m_gl_widget ), "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &camwnd.m_deferred_motion );
1069 camwnd.m_freelook_button_press_handler = g_signal_connect( G_OBJECT( camwnd.m_gl_widget ), "button_press_event", G_CALLBACK( enable_freelook_button_press ), &camwnd );
1071 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1072 CamWnd_Move_Discrete_Enable( camwnd );
1076 CamWnd_Move_Enable( camwnd );
1080 void CamWnd_Remove_Handlers_Move( CamWnd& camwnd ){
1081 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_press_handler );
1082 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_release_handler );
1083 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_motion_handler );
1085 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_freelook_button_press_handler );
1087 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1088 CamWnd_Move_Discrete_Disable( camwnd );
1092 CamWnd_Move_Disable( camwnd );
1096 void CamWnd_Add_Handlers_FreeMove( CamWnd& camwnd ){
1097 camwnd.m_selection_button_press_handler = g_signal_connect( G_OBJECT( camwnd.m_gl_widget ), "button_press_event", G_CALLBACK( selection_button_press_freemove ), camwnd.m_window_observer );
1098 camwnd.m_selection_button_release_handler = g_signal_connect( G_OBJECT( camwnd.m_gl_widget ), "button_release_event", G_CALLBACK( selection_button_release_freemove ), camwnd.m_window_observer );
1099 camwnd.m_selection_motion_handler = g_signal_connect( G_OBJECT( camwnd.m_gl_widget ), "motion_notify_event", G_CALLBACK( selection_motion_freemove ), camwnd.m_window_observer );
1101 camwnd.m_freelook_button_press_handler = g_signal_connect( G_OBJECT( camwnd.m_gl_widget ), "button_press_event", G_CALLBACK( disable_freelook_button_press ), &camwnd );
1103 KeyEvent_connect( "CameraFreeMoveForward" );
1104 KeyEvent_connect( "CameraFreeMoveBack" );
1105 KeyEvent_connect( "CameraFreeMoveLeft" );
1106 KeyEvent_connect( "CameraFreeMoveRight" );
1107 KeyEvent_connect( "CameraFreeMoveUp" );
1108 KeyEvent_connect( "CameraFreeMoveDown" );
1111 void CamWnd_Remove_Handlers_FreeMove( CamWnd& camwnd ){
1112 KeyEvent_disconnect( "CameraFreeMoveForward" );
1113 KeyEvent_disconnect( "CameraFreeMoveBack" );
1114 KeyEvent_disconnect( "CameraFreeMoveLeft" );
1115 KeyEvent_disconnect( "CameraFreeMoveRight" );
1116 KeyEvent_disconnect( "CameraFreeMoveUp" );
1117 KeyEvent_disconnect( "CameraFreeMoveDown" );
1119 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_press_handler );
1120 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_release_handler );
1121 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_motion_handler );
1123 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_freelook_button_press_handler );
1128 m_Camera( &m_view, CamWndQueueDraw( *this ) ),
1129 m_cameraview( m_Camera, &m_view, ReferenceCaller<CamWnd, CamWnd_Update>( *this ) ),
1130 m_gl_widget( glwidget_new( TRUE ) ),
1131 m_window_observer( NewWindowObserver() ),
1132 m_XORRectangle( m_gl_widget ),
1133 m_deferredDraw( WidgetQueueDrawCaller( *m_gl_widget ) ),
1134 m_deferred_motion( selection_motion, m_window_observer ),
1135 m_selection_button_press_handler( 0 ),
1136 m_selection_button_release_handler( 0 ),
1137 m_selection_motion_handler( 0 ),
1138 m_freelook_button_press_handler( 0 ),
1140 m_bFreeMove = false;
1142 GlobalWindowObservers_add( m_window_observer );
1143 GlobalWindowObservers_connectWidget( m_gl_widget );
1145 m_window_observer->setRectangleDrawCallback( ReferenceCaller1<CamWnd, rect_t, camwnd_update_xor_rectangle>( *this ) );
1146 m_window_observer->setView( m_view );
1148 gtk_widget_ref( m_gl_widget );
1150 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 );
1151 GTK_WIDGET_SET_FLAGS( m_gl_widget, GTK_CAN_FOCUS );
1153 m_sizeHandler = g_signal_connect( G_OBJECT( m_gl_widget ), "size_allocate", G_CALLBACK( camera_size_allocate ), this );
1154 m_exposeHandler = g_signal_connect( G_OBJECT( m_gl_widget ), "expose_event", G_CALLBACK( camera_expose ), this );
1156 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
1158 CamWnd_registerCommands( *this );
1160 CamWnd_Add_Handlers_Move( *this );
1162 g_signal_connect( G_OBJECT( m_gl_widget ), "scroll_event", G_CALLBACK( wheelmove_scroll ), this );
1164 AddSceneChangeCallback( ReferenceCaller<CamWnd, CamWnd_Update>( *this ) );
1166 PressedButtons_connect( g_pressedButtons, m_gl_widget );
1170 if ( m_bFreeMove ) {
1174 CamWnd_Remove_Handlers_Move( *this );
1176 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
1177 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
1179 gtk_widget_unref( m_gl_widget );
1181 m_window_observer->release();
1184 class FloorHeightWalker : public scene::Graph::Walker
1190 FloorHeightWalker( float current, float& bestUp, float& bestDown ) :
1191 m_current( current ), m_bestUp( bestUp ), m_bestDown( bestDown ){
1192 bestUp = g_MaxWorldCoord;
1193 bestDown = -g_MaxWorldCoord;
1195 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1196 if ( path.top().get().visible()
1197 && Node_isBrush( path.top() ) ) { // this node is a floor
1198 const AABB& aabb = instance.worldAABB();
1199 float floorHeight = aabb.origin.z() + aabb.extents.z();
1200 if ( floorHeight > m_current && floorHeight < m_bestUp ) {
1201 m_bestUp = floorHeight;
1203 if ( floorHeight < m_current && floorHeight > m_bestDown ) {
1204 m_bestDown = floorHeight;
1211 void CamWnd::Cam_ChangeFloor( bool up ){
1212 float current = m_Camera.origin[2] - 48;
1215 GlobalSceneGraph().traverse( FloorHeightWalker( current, bestUp, bestDown ) );
1217 if ( up && bestUp != g_MaxWorldCoord ) {
1220 if ( !up && bestDown != -g_MaxWorldCoord ) {
1224 m_Camera.origin[2] = current + 48;
1225 Camera_updateModelview( getCamera() );
1226 CamWnd_Update( *this );
1227 CameraMovedNotify();
1231 // NOTE TTimo if there's an OS-level focus out of the application
1232 // then we can release the camera cursor grab
1233 static gboolean camwindow_freemove_focusout( GtkWidget* widget, GdkEventFocus* event, gpointer data ){
1234 reinterpret_cast<CamWnd*>( data )->DisableFreeMove();
1238 void CamWnd::EnableFreeMove(){
1239 //globalOutputStream() << "EnableFreeMove\n";
1241 ASSERT_MESSAGE( !m_bFreeMove, "EnableFreeMove: free-move was already enabled" );
1243 Camera_clearMovementFlags( getCamera(), MOVE_ALL );
1245 CamWnd_Remove_Handlers_Move( *this );
1246 CamWnd_Add_Handlers_FreeMove( *this );
1248 gtk_window_set_focus( m_parent, m_gl_widget );
1249 m_freemove_handle_focusout = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( camwindow_freemove_focusout ), this );
1250 m_freezePointer.freeze_pointer( m_parent, Camera_motionDelta, &m_Camera );
1252 CamWnd_Update( *this );
1255 void CamWnd::DisableFreeMove(){
1256 //globalOutputStream() << "DisableFreeMove\n";
1258 ASSERT_MESSAGE( m_bFreeMove, "DisableFreeMove: free-move was not enabled" );
1259 m_bFreeMove = false;
1260 Camera_clearMovementFlags( getCamera(), MOVE_ALL );
1262 CamWnd_Remove_Handlers_FreeMove( *this );
1263 CamWnd_Add_Handlers_Move( *this );
1265 m_freezePointer.unfreeze_pointer( m_parent );
1266 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_freemove_handle_focusout );
1268 CamWnd_Update( *this );
1272 #include "renderer.h"
1274 class CamRenderer : public Renderer
1278 state_type() : m_highlight( 0 ), m_state( 0 ), m_lights( 0 ){
1280 unsigned int m_highlight;
1282 const LightList* m_lights;
1285 std::vector<state_type> m_state_stack;
1286 RenderStateFlags m_globalstate;
1287 Shader* m_state_select0;
1288 Shader* m_state_select1;
1289 const Vector3& m_viewer;
1292 CamRenderer( RenderStateFlags globalstate, Shader* select0, Shader* select1, const Vector3& viewer ) :
1293 m_globalstate( globalstate ),
1294 m_state_select0( select0 ),
1295 m_state_select1( select1 ),
1297 ASSERT_NOTNULL( select0 );
1298 ASSERT_NOTNULL( select1 );
1299 m_state_stack.push_back( state_type() );
1302 void SetState( Shader* state, EStyle style ){
1303 ASSERT_NOTNULL( state );
1304 if ( style == eFullMaterials ) {
1305 m_state_stack.back().m_state = state;
1308 const EStyle getStyle() const {
1309 return eFullMaterials;
1312 m_state_stack.push_back( m_state_stack.back() );
1315 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
1316 m_state_stack.pop_back();
1318 void Highlight( EHighlightMode mode, bool bEnable = true ){
1320 ? m_state_stack.back().m_highlight |= mode
1321 : m_state_stack.back().m_highlight &= ~mode;
1323 void setLights( const LightList& lights ){
1324 m_state_stack.back().m_lights = &lights;
1326 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& world ){
1327 if ( m_state_stack.back().m_highlight & ePrimitive ) {
1328 m_state_select0->addRenderable( renderable, world, m_state_stack.back().m_lights );
1330 if ( m_state_stack.back().m_highlight & eFace ) {
1331 m_state_select1->addRenderable( renderable, world, m_state_stack.back().m_lights );
1334 m_state_stack.back().m_state->addRenderable( renderable, world, m_state_stack.back().m_lights );
1337 void render( const Matrix4& modelview, const Matrix4& projection ){
1338 GlobalShaderCache().render( m_globalstate, modelview, projection, m_viewer );
1348 void ShowStatsToggle(){
1349 g_camwindow_globals_private.m_showStats ^= 1;
1351 typedef FreeCaller<ShowStatsToggle> ShowStatsToggleCaller;
1353 void ShowStatsExport( const BoolImportCallback& importer ){
1354 importer( g_camwindow_globals_private.m_showStats );
1356 typedef FreeCaller1<const BoolImportCallback&, ShowStatsExport> ShowStatsExportCaller;
1358 ShowStatsExportCaller g_show_stats_caller;
1359 BoolExportCallback g_show_stats_callback( g_show_stats_caller );
1360 ToggleItem g_show_stats( g_show_stats_callback );
1362 void CamWnd::Cam_Draw(){
1363 glViewport( 0, 0, m_Camera.width, m_Camera.height );
1365 // enable depth buffer writes
1366 glDepthMask( GL_TRUE );
1367 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1369 Vector3 clearColour( 0, 0, 0 );
1370 if ( m_Camera.draw_mode != cd_lighting ) {
1371 clearColour = g_camwindow_globals.color_cameraback;
1374 glClearColor( clearColour[0], clearColour[1], clearColour[2], 0 );
1375 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1377 extern void Renderer_ResetStats();
1378 Renderer_ResetStats();
1379 extern void Cull_ResetStats();
1382 glMatrixMode( GL_PROJECTION );
1383 glLoadMatrixf( reinterpret_cast<const float*>( &m_Camera.projection ) );
1385 glMatrixMode( GL_MODELVIEW );
1386 glLoadMatrixf( reinterpret_cast<const float*>( &m_Camera.modelview ) );
1389 // one directional light source directly behind the viewer
1391 GLfloat inverse_cam_dir[4], ambient[4], diffuse[4]; //, material[4];
1393 ambient[0] = ambient[1] = ambient[2] = 0.4f;
1395 diffuse[0] = diffuse[1] = diffuse[2] = 0.4f;
1397 //material[0] = material[1] = material[2] = 0.8f;
1398 //material[3] = 1.0f;
1400 inverse_cam_dir[0] = m_Camera.vpn[0];
1401 inverse_cam_dir[1] = m_Camera.vpn[1];
1402 inverse_cam_dir[2] = m_Camera.vpn[2];
1403 inverse_cam_dir[3] = 0;
1405 glLightfv( GL_LIGHT0, GL_POSITION, inverse_cam_dir );
1407 glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
1408 glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
1410 glEnable( GL_LIGHT0 );
1414 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;
1415 switch ( m_Camera.draw_mode )
1420 globalstate |= RENDER_FILL
1426 globalstate |= RENDER_FILL
1433 globalstate |= RENDER_FILL
1447 if ( !g_xywindow_globals.m_bNoStipple ) {
1448 globalstate |= RENDER_LINESTIPPLE | RENDER_POLYGONSTIPPLE;
1452 CamRenderer renderer( globalstate, m_state_select2, m_state_select1, m_view.getViewer() );
1454 Scene_Render( renderer, m_view );
1456 renderer.render( m_Camera.modelview, m_Camera.projection );
1459 // prepare for 2d stuff
1460 glColor4f( 1, 1, 1, 1 );
1461 glDisable( GL_BLEND );
1462 glMatrixMode( GL_PROJECTION );
1464 glOrtho( 0, (float)m_Camera.width, 0, (float)m_Camera.height, -100, 100 );
1465 glScalef( 1, -1, 1 );
1466 glTranslatef( 0, -(float)m_Camera.height, 0 );
1467 glMatrixMode( GL_MODELVIEW );
1470 if ( GlobalOpenGL().GL_1_3() ) {
1471 glClientActiveTexture( GL_TEXTURE0 );
1472 glActiveTexture( GL_TEXTURE0 );
1475 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1476 glDisableClientState( GL_NORMAL_ARRAY );
1477 glDisableClientState( GL_COLOR_ARRAY );
1479 glDisable( GL_TEXTURE_2D );
1480 glDisable( GL_LIGHTING );
1481 glDisable( GL_COLOR_MATERIAL );
1482 glDisable( GL_DEPTH_TEST );
1483 glColor3f( 1.f, 1.f, 1.f );
1486 // draw the crosshair
1487 if ( m_bFreeMove ) {
1488 glBegin( GL_LINES );
1489 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f + 6 );
1490 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f + 2 );
1491 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f - 6 );
1492 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f - 2 );
1493 glVertex2f( (float)m_Camera.width / 2.f + 6, (float)m_Camera.height / 2.f );
1494 glVertex2f( (float)m_Camera.width / 2.f + 2, (float)m_Camera.height / 2.f );
1495 glVertex2f( (float)m_Camera.width / 2.f - 6, (float)m_Camera.height / 2.f );
1496 glVertex2f( (float)m_Camera.width / 2.f - 2, (float)m_Camera.height / 2.f );
1500 if ( g_camwindow_globals_private.m_showStats ) {
1501 glRasterPos3f( 1.0f, static_cast<float>( m_Camera.height ) - GlobalOpenGL().m_font->getPixelDescent(), 0.0f );
1502 extern const char* Renderer_GetStats();
1503 GlobalOpenGL().drawString( Renderer_GetStats() );
1505 glRasterPos3f( 1.0f, static_cast<float>( m_Camera.height ) - GlobalOpenGL().m_font->getPixelDescent() - GlobalOpenGL().m_font->getPixelHeight(), 0.0f );
1506 extern const char* Cull_GetStats();
1507 GlobalOpenGL().drawString( Cull_GetStats() );
1510 // bind back to the default texture so that we don't have problems
1511 // elsewhere using/modifying texture maps between contexts
1512 glBindTexture( GL_TEXTURE_2D, 0 );
1515 void CamWnd::draw(){
1518 //globalOutputStream() << "draw...\n";
1519 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
1520 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
1521 GlobalOpenGL_debugAssertNoErrors();
1523 GlobalOpenGL_debugAssertNoErrors();
1526 m_XORRectangle.set( rectangle_t() );
1529 glwidget_swap_buffers( m_gl_widget );
1535 void CamWnd::BenchMark(){
1536 double dStart = Sys_DoubleTime();
1537 for ( int i = 0 ; i < 100 ; i++ )
1540 angles[CAMERA_ROLL] = 0;
1541 angles[CAMERA_PITCH] = 0;
1542 angles[CAMERA_YAW] = static_cast<float>( i * ( 360.0 / 100.0 ) );
1543 Camera_setAngles( *this, angles );
1545 double dEnd = Sys_DoubleTime();
1546 globalOutputStream() << FloatFormat( dEnd - dStart, 5, 2 ) << " seconds\n";
1550 void fill_view_camera_menu( GtkMenu* menu ){
1551 create_check_menu_item_with_mnemonic( menu, "Camera View", "ToggleCamera" );
1554 void GlobalCamera_ResetAngles(){
1555 CamWnd& camwnd = *g_camwnd;
1557 angles[CAMERA_ROLL] = angles[CAMERA_PITCH] = 0;
1558 angles[CAMERA_YAW] = static_cast<float>( 22.5 * floor( ( Camera_getAngles( camwnd )[CAMERA_YAW] + 11 ) / 22.5 ) );
1559 Camera_setAngles( camwnd, angles );
1562 void Camera_ChangeFloorUp(){
1563 CamWnd& camwnd = *g_camwnd;
1564 camwnd.Cam_ChangeFloor( true );
1567 void Camera_ChangeFloorDown(){
1568 CamWnd& camwnd = *g_camwnd;
1569 camwnd.Cam_ChangeFloor( false );
1572 void Camera_CubeIn(){
1573 CamWnd& camwnd = *g_camwnd;
1574 g_camwindow_globals.m_nCubicScale--;
1575 if ( g_camwindow_globals.m_nCubicScale < 1 ) {
1576 g_camwindow_globals.m_nCubicScale = 1;
1578 Camera_updateProjection( camwnd.getCamera() );
1579 CamWnd_Update( camwnd );
1580 g_pParentWnd->SetGridStatus();
1583 void Camera_CubeOut(){
1584 CamWnd& camwnd = *g_camwnd;
1585 g_camwindow_globals.m_nCubicScale++;
1586 if ( g_camwindow_globals.m_nCubicScale > 23 ) {
1587 g_camwindow_globals.m_nCubicScale = 23;
1589 Camera_updateProjection( camwnd.getCamera() );
1590 CamWnd_Update( camwnd );
1591 g_pParentWnd->SetGridStatus();
1594 bool Camera_GetFarClip(){
1595 return g_camwindow_globals_private.m_bCubicClipping;
1598 BoolExportCaller g_getfarclip_caller( g_camwindow_globals_private.m_bCubicClipping );
1599 ToggleItem g_getfarclip_item( g_getfarclip_caller );
1601 void Camera_SetFarClip( bool value ){
1602 CamWnd& camwnd = *g_camwnd;
1603 g_camwindow_globals_private.m_bCubicClipping = value;
1604 g_getfarclip_item.update();
1605 Camera_updateProjection( camwnd.getCamera() );
1606 CamWnd_Update( camwnd );
1609 void Camera_ToggleFarClip(){
1610 Camera_SetFarClip( !Camera_GetFarClip() );
1614 void CamWnd_constructToolbar( GtkToolbar* toolbar ){
1615 toolbar_append_toggle_button( toolbar, "Cubic clip the camera view (\\)", "view_cubicclipping.png", "ToggleCubicClip" );
1618 void CamWnd_registerShortcuts(){
1619 toggle_add_accelerator( "ToggleCubicClip" );
1621 if ( g_pGameDescription->mGameType == "doom3" ) {
1622 command_connect_accelerator( "TogglePreview" );
1625 command_connect_accelerator( "CameraSpeedInc" );
1626 command_connect_accelerator( "CameraSpeedDec" );
1630 void GlobalCamera_Benchmark(){
1631 CamWnd& camwnd = *g_camwnd;
1635 void GlobalCamera_Update(){
1636 CamWnd& camwnd = *g_camwnd;
1637 CamWnd_Update( camwnd );
1640 camera_draw_mode CamWnd_GetMode(){
1641 return camera_t::draw_mode;
1643 void CamWnd_SetMode( camera_draw_mode mode ){
1644 ShaderCache_setBumpEnabled( mode == cd_lighting );
1645 camera_t::draw_mode = mode;
1646 if ( g_camwnd != 0 ) {
1647 CamWnd_Update( *g_camwnd );
1651 void CamWnd_TogglePreview( void ){
1652 // gametype must be doom3 for this function to work
1653 // if the gametype is not doom3 something is wrong with the
1654 // global command list or somebody else calls this function.
1655 ASSERT_MESSAGE( g_pGameDescription->mGameType == "doom3", "CamWnd_TogglePreview called although mGameType is not doom3 compatible" );
1657 // switch between textured and lighting mode
1658 CamWnd_SetMode( ( CamWnd_GetMode() == cd_lighting ) ? cd_texture : cd_lighting );
1662 CameraModel* g_camera_model = 0;
1664 void CamWnd_LookThroughCamera( CamWnd& camwnd ){
1665 if ( g_camera_model != 0 ) {
1666 CamWnd_Add_Handlers_Move( camwnd );
1667 g_camera_model->setCameraView( 0, Callback() );
1669 Camera_updateModelview( camwnd.getCamera() );
1670 Camera_updateProjection( camwnd.getCamera() );
1671 CamWnd_Update( camwnd );
1675 inline CameraModel* Instance_getCameraModel( scene::Instance& instance ){
1676 return InstanceTypeCast<CameraModel>::cast( instance );
1679 void CamWnd_LookThroughSelected( CamWnd& camwnd ){
1680 if ( g_camera_model != 0 ) {
1681 CamWnd_LookThroughCamera( camwnd );
1684 if ( GlobalSelectionSystem().countSelected() != 0 ) {
1685 scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
1686 CameraModel* cameraModel = Instance_getCameraModel( instance );
1687 if ( cameraModel != 0 ) {
1688 CamWnd_Remove_Handlers_Move( camwnd );
1689 g_camera_model = cameraModel;
1690 g_camera_model->setCameraView( &camwnd.getCameraView(), ReferenceCaller<CamWnd, CamWnd_LookThroughCamera>( camwnd ) );
1695 void GlobalCamera_LookThroughSelected(){
1696 CamWnd_LookThroughSelected( *g_camwnd );
1699 void GlobalCamera_LookThroughCamera(){
1700 CamWnd_LookThroughCamera( *g_camwnd );
1704 void RenderModeImport( int value ){
1708 CamWnd_SetMode( cd_wire );
1711 CamWnd_SetMode( cd_solid );
1714 CamWnd_SetMode( cd_texture );
1717 CamWnd_SetMode( cd_lighting );
1720 CamWnd_SetMode( cd_texture );
1723 typedef FreeCaller1<int, RenderModeImport> RenderModeImportCaller;
1725 void RenderModeExport( const IntImportCallback& importer ){
1726 switch ( CamWnd_GetMode() )
1742 typedef FreeCaller1<const IntImportCallback&, RenderModeExport> RenderModeExportCaller;
1744 void Camera_constructPreferences( PreferencesPage& page ){
1745 page.appendSlider( "Movement Speed", g_camwindow_globals_private.m_nMoveSpeed, TRUE, 0, 0, 100, MIN_CAM_SPEED, MAX_CAM_SPEED, 1, 10 );
1746 page.appendCheckBox( "", "Link strafe speed to movement speed", g_camwindow_globals_private.m_bCamLinkSpeed );
1747 page.appendSlider( "Rotation Speed", g_camwindow_globals_private.m_nAngleSpeed, TRUE, 0, 0, 3, 1, 180, 1, 10 );
1748 page.appendCheckBox( "", "Invert mouse vertical axis", g_camwindow_globals_private.m_bCamInverseMouse );
1749 page.appendCheckBox(
1750 "", "Discrete movement",
1751 FreeCaller1<bool, CamWnd_Move_Discrete_Import>(),
1752 BoolExportCaller( g_camwindow_globals_private.m_bCamDiscrete )
1754 page.appendCheckBox(
1755 "", "Enable far-clip plane",
1756 FreeCaller1<bool, Camera_SetFarClip>(),
1757 BoolExportCaller( g_camwindow_globals_private.m_bCubicClipping )
1760 if ( g_pGameDescription->mGameType == "doom3" ) {
1761 const char* render_mode[] = { "Wireframe", "Flatshade", "Textured", "Lighting" };
1765 STRING_ARRAY_RANGE( render_mode ),
1766 IntImportCallback( RenderModeImportCaller() ),
1767 IntExportCallback( RenderModeExportCaller() )
1772 const char* render_mode[] = { "Wireframe", "Flatshade", "Textured" };
1776 STRING_ARRAY_RANGE( render_mode ),
1777 IntImportCallback( RenderModeImportCaller() ),
1778 IntExportCallback( RenderModeExportCaller() )
1782 const char* strafe_mode[] = { "Both", "Forward", "Up" };
1786 g_camwindow_globals_private.m_nStrafeMode,
1787 STRING_ARRAY_RANGE( strafe_mode )
1790 void Camera_constructPage( PreferenceGroup& group ){
1791 PreferencesPage page( group.createPage( "Camera", "Camera View Preferences" ) );
1792 Camera_constructPreferences( page );
1794 void Camera_registerPreferencesPage(){
1795 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Camera_constructPage>() );
1798 #include "preferencesystem.h"
1799 #include "stringio.h"
1802 typedef FreeCaller1<bool, CamWnd_Move_Discrete_Import> CamWndMoveDiscreteImportCaller;
1804 void CameraSpeed_increase(){
1805 if ( g_camwindow_globals_private.m_nMoveSpeed <= ( MAX_CAM_SPEED - CAM_SPEED_STEP - 10 ) ) {
1806 g_camwindow_globals_private.m_nMoveSpeed += CAM_SPEED_STEP;
1809 g_camwindow_globals_private.m_nMoveSpeed = MAX_CAM_SPEED - 10;
1813 void CameraSpeed_decrease(){
1814 if ( g_camwindow_globals_private.m_nMoveSpeed >= ( MIN_CAM_SPEED + CAM_SPEED_STEP ) ) {
1815 g_camwindow_globals_private.m_nMoveSpeed -= CAM_SPEED_STEP;
1818 g_camwindow_globals_private.m_nMoveSpeed = MIN_CAM_SPEED;
1822 /// \brief Initialisation for things that have the same lifespan as this module.
1823 void CamWnd_Construct(){
1824 GlobalCommands_insert( "CenterView", FreeCaller<GlobalCamera_ResetAngles>(), Accelerator( GDK_End ) );
1826 GlobalToggles_insert( "ToggleCubicClip", FreeCaller<Camera_ToggleFarClip>(), ToggleItem::AddCallbackCaller( g_getfarclip_item ), Accelerator( '\\', (GdkModifierType)GDK_CONTROL_MASK ) );
1827 GlobalCommands_insert( "CubicClipZoomIn", FreeCaller<Camera_CubeIn>(), Accelerator( '[', (GdkModifierType)GDK_CONTROL_MASK ) );
1828 GlobalCommands_insert( "CubicClipZoomOut", FreeCaller<Camera_CubeOut>(), Accelerator( ']', (GdkModifierType)GDK_CONTROL_MASK ) );
1830 GlobalCommands_insert( "UpFloor", FreeCaller<Camera_ChangeFloorUp>(), Accelerator( GDK_Prior ) );
1831 GlobalCommands_insert( "DownFloor", FreeCaller<Camera_ChangeFloorDown>(), Accelerator( GDK_Next ) );
1833 GlobalToggles_insert( "ToggleCamera", ToggleShown::ToggleCaller( g_camera_shown ), ToggleItem::AddCallbackCaller( g_camera_shown.m_item ), Accelerator( 'C', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
1834 GlobalCommands_insert( "LookThroughSelected", FreeCaller<GlobalCamera_LookThroughSelected>() );
1835 GlobalCommands_insert( "LookThroughCamera", FreeCaller<GlobalCamera_LookThroughCamera>() );
1837 if ( g_pGameDescription->mGameType == "doom3" ) {
1838 GlobalCommands_insert( "TogglePreview", FreeCaller<CamWnd_TogglePreview>(), Accelerator( GDK_F3 ) );
1841 GlobalCommands_insert( "CameraSpeedInc", FreeCaller<CameraSpeed_increase>(), Accelerator( GDK_KP_Add, (GdkModifierType)GDK_SHIFT_MASK ) );
1842 GlobalCommands_insert( "CameraSpeedDec", FreeCaller<CameraSpeed_decrease>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)GDK_SHIFT_MASK ) );
1844 GlobalShortcuts_insert( "CameraForward", Accelerator( GDK_Up ) );
1845 GlobalShortcuts_insert( "CameraBack", Accelerator( GDK_Down ) );
1846 GlobalShortcuts_insert( "CameraLeft", Accelerator( GDK_Left ) );
1847 GlobalShortcuts_insert( "CameraRight", Accelerator( GDK_Right ) );
1848 GlobalShortcuts_insert( "CameraStrafeRight", Accelerator( GDK_period ) );
1849 GlobalShortcuts_insert( "CameraStrafeLeft", Accelerator( GDK_comma ) );
1851 GlobalShortcuts_insert( "CameraUp", Accelerator( 'D' ) );
1852 GlobalShortcuts_insert( "CameraDown", Accelerator( 'C' ) );
1853 GlobalShortcuts_insert( "CameraAngleUp", Accelerator( 'A' ) );
1854 GlobalShortcuts_insert( "CameraAngleDown", Accelerator( 'Z' ) );
1856 GlobalShortcuts_insert( "CameraFreeMoveForward", Accelerator( GDK_Up ) );
1857 GlobalShortcuts_insert( "CameraFreeMoveBack", Accelerator( GDK_Down ) );
1858 GlobalShortcuts_insert( "CameraFreeMoveLeft", Accelerator( GDK_Left ) );
1859 GlobalShortcuts_insert( "CameraFreeMoveRight", Accelerator( GDK_Right ) );
1861 GlobalToggles_insert( "ShowStats", ShowStatsToggleCaller(), ToggleItem::AddCallbackCaller( g_show_stats ) );
1863 GlobalPreferenceSystem().registerPreference( "ShowStats", BoolImportStringCaller( g_camwindow_globals_private.m_showStats ), BoolExportStringCaller( g_camwindow_globals_private.m_showStats ) );
1864 GlobalPreferenceSystem().registerPreference( "MoveSpeed", IntImportStringCaller( g_camwindow_globals_private.m_nMoveSpeed ), IntExportStringCaller( g_camwindow_globals_private.m_nMoveSpeed ) );
1865 GlobalPreferenceSystem().registerPreference( "CamLinkSpeed", BoolImportStringCaller( g_camwindow_globals_private.m_bCamLinkSpeed ), BoolExportStringCaller( g_camwindow_globals_private.m_bCamLinkSpeed ) );
1866 GlobalPreferenceSystem().registerPreference( "AngleSpeed", IntImportStringCaller( g_camwindow_globals_private.m_nAngleSpeed ), IntExportStringCaller( g_camwindow_globals_private.m_nAngleSpeed ) );
1867 GlobalPreferenceSystem().registerPreference( "CamInverseMouse", BoolImportStringCaller( g_camwindow_globals_private.m_bCamInverseMouse ), BoolExportStringCaller( g_camwindow_globals_private.m_bCamInverseMouse ) );
1868 GlobalPreferenceSystem().registerPreference( "CamDiscrete", makeBoolStringImportCallback( CamWndMoveDiscreteImportCaller() ), BoolExportStringCaller( g_camwindow_globals_private.m_bCamDiscrete ) );
1869 GlobalPreferenceSystem().registerPreference( "CubicClipping", BoolImportStringCaller( g_camwindow_globals_private.m_bCubicClipping ), BoolExportStringCaller( g_camwindow_globals_private.m_bCubicClipping ) );
1870 GlobalPreferenceSystem().registerPreference( "CubicScale", IntImportStringCaller( g_camwindow_globals.m_nCubicScale ), IntExportStringCaller( g_camwindow_globals.m_nCubicScale ) );
1871 GlobalPreferenceSystem().registerPreference( "SI_Colors4", Vector3ImportStringCaller( g_camwindow_globals.color_cameraback ), Vector3ExportStringCaller( g_camwindow_globals.color_cameraback ) );
1872 GlobalPreferenceSystem().registerPreference( "SI_Colors12", Vector3ImportStringCaller( g_camwindow_globals.color_selbrushes3d ), Vector3ExportStringCaller( g_camwindow_globals.color_selbrushes3d ) );
1873 GlobalPreferenceSystem().registerPreference( "CameraRenderMode", makeIntStringImportCallback( RenderModeImportCaller() ), makeIntStringExportCallback( RenderModeExportCaller() ) );
1874 GlobalPreferenceSystem().registerPreference( "StrafeMode", IntImportStringCaller( g_camwindow_globals_private.m_nStrafeMode ), IntExportStringCaller( g_camwindow_globals_private.m_nStrafeMode ) );
1876 CamWnd_constructStatic();
1878 Camera_registerPreferencesPage();
1880 void CamWnd_Destroy(){
1881 CamWnd_destroyStatic();