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
83 bool m_bCamInverseMouse;
85 bool m_bCubicClipping;
89 camwindow_globals_private_t() :
92 m_bCamLinkSpeed( true ),
94 m_bCamInverseMouse( false ),
95 m_bCamDiscrete( true ),
96 m_bCubicClipping( false ),
103 camwindow_globals_private_t g_camwindow_globals_private;
106 const Matrix4 g_opengl2radiant(
113 const Matrix4 g_radiant2opengl(
121 void Camera_mouseMove( camera_t& camera, int x, int y );
123 enum camera_draw_mode
140 Vector3 color; // background
142 Vector3 forward, right; // move matrix (TTimo: used to have up but it was not updated)
143 Vector3 vup, vpn, vright; // view matrix (taken from the modelview matrix)
148 bool m_strafe; // true when in strafemode toggled by the ctrl-key
149 bool m_strafe_forward; // true when in strafemode by ctrl-key and shift is pressed for forward strafing
151 unsigned int movementflags; // movement flags
152 Timer m_keycontrol_timer;
153 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 );
163 Callback<void()> m_update;
165 static camera_draw_mode draw_mode;
167 camera_t( View* view, const Callback<void()>& update )
174 projection( g_matrix4_identity ),
175 modelview( g_matrix4_identity ),
177 m_keycontrol_timer(),
178 m_keymove_handler( 0 ),
179 m_mouseMove( motionDelta, this ),
185 camera_draw_mode camera_t::draw_mode = cd_texture;
187 inline Matrix4 projection_for_camera( float near_z, float far_z, float fieldOfView, int width, int height ){
188 const float half_width = static_cast<float>( near_z * tan( degrees_to_radians( fieldOfView * 0.5 ) ) );
189 const float half_height = half_width * ( static_cast<float>( height ) / static_cast<float>( width ) );
191 return matrix4_frustum(
201 float Camera_getFarClipPlane( camera_t& camera ){
202 return ( g_camwindow_globals_private.m_bCubicClipping ) ? pow( 2.0, ( g_camwindow_globals.m_nCubicScale + 7 ) / 2.0 ) : 32768.0f;
205 void Camera_updateProjection( camera_t& camera ){
206 float farClip = Camera_getFarClipPlane( camera );
207 camera.projection = projection_for_camera( farClip / 4096.0f, farClip, (float)g_camwindow_globals_private.m_nFOV, camera.width, camera.height );
209 camera.m_view->Construct( camera.projection, camera.modelview, camera.width, camera.height );
212 void Camera_updateVectors( camera_t& camera ){
213 for ( int i = 0 ; i < 3 ; i++ )
215 camera.vright[i] = camera.modelview[( i << 2 ) + 0];
216 camera.vup[i] = camera.modelview[( i << 2 ) + 1];
217 camera.vpn[i] = camera.modelview[( i << 2 ) + 2];
221 void Camera_updateModelview( camera_t& camera ){
222 camera.modelview = g_matrix4_identity;
225 Vector3 radiant_eulerXYZ( 0, -camera.angles[CAMERA_PITCH], camera.angles[CAMERA_YAW] );
227 matrix4_translate_by_vec3( camera.modelview, camera.origin );
228 matrix4_rotate_by_euler_xyz_degrees( camera.modelview, radiant_eulerXYZ );
229 matrix4_multiply_by_matrix4( camera.modelview, g_radiant2opengl );
230 matrix4_affine_invert( camera.modelview );
232 Camera_updateVectors( camera );
234 camera.m_view->Construct( camera.projection, camera.modelview, camera.width, camera.height );
238 void Camera_Move_updateAxes( camera_t& camera ){
239 double ya = degrees_to_radians( camera.angles[CAMERA_YAW] );
241 // the movement matrix is kept 2d
242 camera.forward[0] = static_cast<float>( cos( ya ) );
243 camera.forward[1] = static_cast<float>( sin( ya ) );
244 camera.forward[2] = 0;
245 camera.right[0] = camera.forward[1];
246 camera.right[1] = -camera.forward[0];
249 void Camera_Freemove_updateAxes( camera_t& camera ){
250 camera.right = camera.vright;
251 camera.forward = vector3_negated( camera.vpn );
254 const Vector3& Camera_getOrigin( camera_t& camera ){
255 return camera.origin;
258 void Camera_setOrigin( camera_t& camera, const Vector3& origin ){
259 camera.origin = origin;
260 Camera_updateModelview( camera );
265 const Vector3& Camera_getAngles( camera_t& camera ){
266 return camera.angles;
269 void Camera_setAngles( camera_t& camera, const Vector3& angles ){
270 camera.angles = angles;
271 Camera_updateModelview( camera );
277 void Camera_FreeMove( camera_t& camera, int dx, int dy ){
278 // free strafe mode, toggled by the ctrl key with optional shift for forward movement
279 if ( camera.m_strafe ) {
280 float strafespeed = 0.65f;
282 if ( g_camwindow_globals_private.m_bCamLinkSpeed ) {
283 strafespeed = (float)g_camwindow_globals_private.m_nMoveSpeed / 100;
286 camera.origin -= camera.vright * strafespeed * dx;
287 if ( camera.m_strafe_forward ) {
288 camera.origin += camera.vpn * strafespeed * dy;
291 camera.origin += camera.vup * strafespeed * dy;
294 else // free rotation
296 const float dtime = 0.1f;
298 if ( g_camwindow_globals_private.m_bCamInverseMouse ) {
299 camera.angles[CAMERA_PITCH] -= dy * dtime * g_camwindow_globals_private.m_nAngleSpeed;
302 camera.angles[CAMERA_PITCH] += dy * dtime * g_camwindow_globals_private.m_nAngleSpeed;
305 camera.angles[CAMERA_YAW] += dx * dtime * g_camwindow_globals_private.m_nAngleSpeed;
307 if ( camera.angles[CAMERA_PITCH] > 90 ) {
308 camera.angles[CAMERA_PITCH] = 90;
310 else if ( camera.angles[CAMERA_PITCH] < -90 ) {
311 camera.angles[CAMERA_PITCH] = -90;
314 if ( camera.angles[CAMERA_YAW] >= 360 ) {
315 camera.angles[CAMERA_YAW] -= 360;
317 else if ( camera.angles[CAMERA_YAW] <= 0 ) {
318 camera.angles[CAMERA_YAW] += 360;
322 Camera_updateModelview( camera );
323 Camera_Freemove_updateAxes( camera );
326 void Cam_MouseControl( camera_t& camera, int x, int y ){
327 float xf = (float)( x - camera.width / 2 ) / ( camera.width / 2 );
328 float yf = (float)( y - camera.height / 2 ) / ( camera.height / 2 );
330 xf *= 1.0f - fabsf( yf );
345 vector3_add( camera.origin, vector3_scaled( camera.forward, yf * 0.1f * g_camwindow_globals_private.m_nMoveSpeed ) );
346 camera.angles[CAMERA_YAW] += xf * -0.1f * g_camwindow_globals_private.m_nAngleSpeed;
348 Camera_updateModelview( camera );
351 void Camera_mouseMove( camera_t& camera, int x, int y ){
352 //globalOutputStream() << "mousemove... ";
353 Camera_FreeMove( camera, -x, -y );
358 const unsigned int MOVE_NONE = 0;
359 const unsigned int MOVE_FORWARD = 1 << 0;
360 const unsigned int MOVE_BACK = 1 << 1;
361 const unsigned int MOVE_ROTRIGHT = 1 << 2;
362 const unsigned int MOVE_ROTLEFT = 1 << 3;
363 const unsigned int MOVE_STRAFERIGHT = 1 << 4;
364 const unsigned int MOVE_STRAFELEFT = 1 << 5;
365 const unsigned int MOVE_UP = 1 << 6;
366 const unsigned int MOVE_DOWN = 1 << 7;
367 const unsigned int MOVE_PITCHUP = 1 << 8;
368 const unsigned int MOVE_PITCHDOWN = 1 << 9;
369 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;
371 void Cam_KeyControl( camera_t& camera, float dtime ){
373 if ( camera.movementflags & MOVE_ROTLEFT ) {
374 camera.angles[CAMERA_YAW] += 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed;
376 if ( camera.movementflags & MOVE_ROTRIGHT ) {
377 camera.angles[CAMERA_YAW] -= 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed;
379 if ( camera.movementflags & MOVE_PITCHUP ) {
380 camera.angles[CAMERA_PITCH] += 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed;
381 if ( camera.angles[CAMERA_PITCH] > 90 ) {
382 camera.angles[CAMERA_PITCH] = 90;
385 if ( camera.movementflags & MOVE_PITCHDOWN ) {
386 camera.angles[CAMERA_PITCH] -= 15 * dtime * g_camwindow_globals_private.m_nAngleSpeed;
387 if ( camera.angles[CAMERA_PITCH] < -90 ) {
388 camera.angles[CAMERA_PITCH] = -90;
392 Camera_updateModelview( camera );
393 Camera_Freemove_updateAxes( camera );
396 if ( camera.movementflags & MOVE_FORWARD ) {
397 vector3_add( camera.origin, vector3_scaled( camera.forward, dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
399 if ( camera.movementflags & MOVE_BACK ) {
400 vector3_add( camera.origin, vector3_scaled( camera.forward, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
402 if ( camera.movementflags & MOVE_STRAFELEFT ) {
403 vector3_add( camera.origin, vector3_scaled( camera.right, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
405 if ( camera.movementflags & MOVE_STRAFERIGHT ) {
406 vector3_add( camera.origin, vector3_scaled( camera.right, dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
408 if ( camera.movementflags & MOVE_UP ) {
409 vector3_add( camera.origin, vector3_scaled( g_vector3_axis_z, dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
411 if ( camera.movementflags & MOVE_DOWN ) {
412 vector3_add( camera.origin, vector3_scaled( g_vector3_axis_z, -dtime * g_camwindow_globals_private.m_nMoveSpeed ) );
415 Camera_updateModelview( camera );
418 void Camera_keyMove( camera_t& camera ){
419 camera.m_mouseMove.flush();
421 //globalOutputStream() << "keymove... ";
422 float time_seconds = camera.m_keycontrol_timer.elapsed_msec() / static_cast<float>( msec_per_sec );
423 camera.m_keycontrol_timer.start();
424 if ( time_seconds > 0.05f ) {
425 time_seconds = 0.05f; // 20fps
427 Cam_KeyControl( camera, time_seconds * 5.0f );
433 gboolean camera_keymove( gpointer data ){
434 Camera_keyMove( *reinterpret_cast<camera_t*>( data ) );
438 void Camera_setMovementFlags( camera_t& camera, unsigned int mask ){
439 if ( ( ~camera.movementflags & mask ) != 0 && camera.movementflags == 0 ) {
440 camera.m_keymove_handler = g_idle_add( camera_keymove, &camera );
442 camera.movementflags |= mask;
444 void Camera_clearMovementFlags( camera_t& camera, unsigned int mask ){
445 if ( ( camera.movementflags & ~mask ) == 0 && camera.movementflags != 0 ) {
446 g_source_remove( camera.m_keymove_handler );
447 camera.m_keymove_handler = 0;
449 camera.movementflags &= ~mask;
452 void Camera_MoveForward_KeyDown( camera_t& camera ){
453 Camera_setMovementFlags( camera, MOVE_FORWARD );
455 void Camera_MoveForward_KeyUp( camera_t& camera ){
456 Camera_clearMovementFlags( camera, MOVE_FORWARD );
458 void Camera_MoveBack_KeyDown( camera_t& camera ){
459 Camera_setMovementFlags( camera, MOVE_BACK );
461 void Camera_MoveBack_KeyUp( camera_t& camera ){
462 Camera_clearMovementFlags( camera, MOVE_BACK );
465 void Camera_MoveLeft_KeyDown( camera_t& camera ){
466 Camera_setMovementFlags( camera, MOVE_STRAFELEFT );
468 void Camera_MoveLeft_KeyUp( camera_t& camera ){
469 Camera_clearMovementFlags( camera, MOVE_STRAFELEFT );
471 void Camera_MoveRight_KeyDown( camera_t& camera ){
472 Camera_setMovementFlags( camera, MOVE_STRAFERIGHT );
474 void Camera_MoveRight_KeyUp( camera_t& camera ){
475 Camera_clearMovementFlags( camera, MOVE_STRAFERIGHT );
478 void Camera_MoveUp_KeyDown( camera_t& camera ){
479 Camera_setMovementFlags( camera, MOVE_UP );
481 void Camera_MoveUp_KeyUp( camera_t& camera ){
482 Camera_clearMovementFlags( camera, MOVE_UP );
484 void Camera_MoveDown_KeyDown( camera_t& camera ){
485 Camera_setMovementFlags( camera, MOVE_DOWN );
487 void Camera_MoveDown_KeyUp( camera_t& camera ){
488 Camera_clearMovementFlags( camera, MOVE_DOWN );
491 void Camera_RotateLeft_KeyDown( camera_t& camera ){
492 Camera_setMovementFlags( camera, MOVE_ROTLEFT );
494 void Camera_RotateLeft_KeyUp( camera_t& camera ){
495 Camera_clearMovementFlags( camera, MOVE_ROTLEFT );
497 void Camera_RotateRight_KeyDown( camera_t& camera ){
498 Camera_setMovementFlags( camera, MOVE_ROTRIGHT );
500 void Camera_RotateRight_KeyUp( camera_t& camera ){
501 Camera_clearMovementFlags( camera, MOVE_ROTRIGHT );
504 void Camera_PitchUp_KeyDown( camera_t& camera ){
505 Camera_setMovementFlags( camera, MOVE_PITCHUP );
507 void Camera_PitchUp_KeyUp( camera_t& camera ){
508 Camera_clearMovementFlags( camera, MOVE_PITCHUP );
510 void Camera_PitchDown_KeyDown( camera_t& camera ){
511 Camera_setMovementFlags( camera, MOVE_PITCHDOWN );
513 void Camera_PitchDown_KeyUp( camera_t& camera ){
514 Camera_clearMovementFlags( camera, MOVE_PITCHDOWN );
518 typedef ReferenceCaller<camera_t, void(), &Camera_MoveForward_KeyDown> FreeMoveCameraMoveForwardKeyDownCaller;
519 typedef ReferenceCaller<camera_t, void(), &Camera_MoveForward_KeyUp> FreeMoveCameraMoveForwardKeyUpCaller;
520 typedef ReferenceCaller<camera_t, void(), &Camera_MoveBack_KeyDown> FreeMoveCameraMoveBackKeyDownCaller;
521 typedef ReferenceCaller<camera_t, void(), &Camera_MoveBack_KeyUp> FreeMoveCameraMoveBackKeyUpCaller;
522 typedef ReferenceCaller<camera_t, void(), &Camera_MoveLeft_KeyDown> FreeMoveCameraMoveLeftKeyDownCaller;
523 typedef ReferenceCaller<camera_t, void(), &Camera_MoveLeft_KeyUp> FreeMoveCameraMoveLeftKeyUpCaller;
524 typedef ReferenceCaller<camera_t, void(), &Camera_MoveRight_KeyDown> FreeMoveCameraMoveRightKeyDownCaller;
525 typedef ReferenceCaller<camera_t, void(), &Camera_MoveRight_KeyUp> FreeMoveCameraMoveRightKeyUpCaller;
526 typedef ReferenceCaller<camera_t, void(), &Camera_MoveUp_KeyDown> FreeMoveCameraMoveUpKeyDownCaller;
527 typedef ReferenceCaller<camera_t, void(), &Camera_MoveUp_KeyUp> FreeMoveCameraMoveUpKeyUpCaller;
528 typedef ReferenceCaller<camera_t, void(), &Camera_MoveDown_KeyDown> FreeMoveCameraMoveDownKeyDownCaller;
529 typedef ReferenceCaller<camera_t, void(), &Camera_MoveDown_KeyUp> FreeMoveCameraMoveDownKeyUpCaller;
532 const float MIN_FOV = 60;
533 const float MAX_FOV = 179;
534 const float FOV_STEP = 10;
535 const float SPEED_MOVE = 32;
536 const float SPEED_TURN = 22.5;
537 const float MIN_CAM_SPEED = 10;
538 const float MAX_CAM_SPEED = 610;
539 const float CAM_SPEED_STEP = 50;
541 void Camera_MoveForward_Discrete( camera_t& camera ){
542 Camera_Move_updateAxes( camera );
543 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.forward, SPEED_MOVE ) ) );
545 void Camera_MoveBack_Discrete( camera_t& camera ){
546 Camera_Move_updateAxes( camera );
547 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.forward, -SPEED_MOVE ) ) );
550 void Camera_MoveUp_Discrete( camera_t& camera ){
551 Vector3 origin( Camera_getOrigin( camera ) );
552 origin[2] += SPEED_MOVE;
553 Camera_setOrigin( camera, origin );
555 void Camera_MoveDown_Discrete( camera_t& camera ){
556 Vector3 origin( Camera_getOrigin( camera ) );
557 origin[2] -= SPEED_MOVE;
558 Camera_setOrigin( camera, origin );
561 void Camera_MoveLeft_Discrete( camera_t& camera ){
562 Camera_Move_updateAxes( camera );
563 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.right, -SPEED_MOVE ) ) );
565 void Camera_MoveRight_Discrete( camera_t& camera ){
566 Camera_Move_updateAxes( camera );
567 Camera_setOrigin( camera, vector3_added( Camera_getOrigin( camera ), vector3_scaled( camera.right, SPEED_MOVE ) ) );
570 void Camera_RotateLeft_Discrete( camera_t& camera ){
571 Vector3 angles( Camera_getAngles( camera ) );
572 angles[CAMERA_YAW] += SPEED_TURN;
573 Camera_setAngles( camera, angles );
575 void Camera_RotateRight_Discrete( camera_t& camera ){
576 Vector3 angles( Camera_getAngles( camera ) );
577 angles[CAMERA_YAW] -= SPEED_TURN;
578 Camera_setAngles( camera, angles );
581 void Camera_PitchUp_Discrete( camera_t& camera ){
582 Vector3 angles( Camera_getAngles( camera ) );
583 angles[CAMERA_PITCH] += SPEED_TURN;
584 if ( angles[CAMERA_PITCH] > 90 ) {
585 angles[CAMERA_PITCH] = 90;
587 Camera_setAngles( camera, angles );
589 void Camera_PitchDown_Discrete( camera_t& camera ){
590 Vector3 angles( Camera_getAngles( camera ) );
591 angles[CAMERA_PITCH] -= SPEED_TURN;
592 if ( angles[CAMERA_PITCH] < -90 ) {
593 angles[CAMERA_PITCH] = -90;
595 Camera_setAngles( camera, angles );
599 class RadiantCameraView : public CameraView
603 Callback<void()> m_update;
605 RadiantCameraView( camera_t& camera, View* view, const Callback<void()>& update ) : m_camera( camera ), m_view( view ), m_update( update ){
608 m_view->Construct( m_camera.projection, m_camera.modelview, m_camera.width, m_camera.height );
611 void setModelview( const Matrix4& modelview ){
612 m_camera.modelview = modelview;
613 matrix4_multiply_by_matrix4( m_camera.modelview, g_radiant2opengl );
614 matrix4_affine_invert( m_camera.modelview );
615 Camera_updateVectors( m_camera );
618 void setFieldOfView( float fieldOfView ){
619 float farClip = Camera_getFarClipPlane( m_camera );
620 m_camera.projection = projection_for_camera( farClip / 4096.0f, farClip, fieldOfView, m_camera.width, m_camera.height );
626 void Camera_motionDelta( int x, int y, unsigned int state, void* data ){
627 camera_t* cam = reinterpret_cast<camera_t*>( data );
629 cam->m_mouseMove.motion_delta( x, y, state );
631 switch ( g_camwindow_globals_private.m_nStrafeMode )
634 cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0;
635 if ( cam->m_strafe ) {
636 cam->m_strafe_forward = ( state & GDK_SHIFT_MASK ) != 0;
639 cam->m_strafe_forward = false;
643 cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0 && ( state & GDK_SHIFT_MASK ) == 0;
644 cam->m_strafe_forward = false;
647 cam->m_strafe = ( state & GDK_CONTROL_MASK ) != 0 && ( state & GDK_SHIFT_MASK ) == 0;
648 cam->m_strafe_forward = cam->m_strafe;
657 RadiantCameraView m_cameraview;
659 int m_PositionDragCursorX;
660 int m_PositionDragCursorY;
663 guint m_freemove_handle_focusout;
665 static Shader* m_state_select1;
666 static Shader* m_state_select2;
668 FreezePointer m_freezePointer;
671 ui::GLArea m_gl_widget;
672 ui::Window m_parent{ui::null};
674 SelectionSystemWindowObserver* m_window_observer;
675 XORRectangle m_XORRectangle;
677 DeferredDraw m_deferredDraw;
678 DeferredMotion m_deferred_motion;
680 guint m_selection_button_press_handler;
681 guint m_selection_button_release_handler;
682 guint m_selection_motion_handler;
684 guint m_freelook_button_press_handler;
687 guint m_exposeHandler;
694 //ASSERT_MESSAGE(!m_drawing, "CamWnd::queue_draw(): called while draw is already in progress");
698 //globalOutputStream() << "queue... ";
699 m_deferredDraw.draw();
703 static void captureStates(){
704 m_state_select1 = GlobalShaderCache().capture( "$CAM_HIGHLIGHT" );
705 m_state_select2 = GlobalShaderCache().capture( "$CAM_OVERLAY" );
707 static void releaseStates(){
708 GlobalShaderCache().release( "$CAM_HIGHLIGHT" );
709 GlobalShaderCache().release( "$CAM_OVERLAY" );
712 camera_t& getCamera(){
717 void Cam_ChangeFloor( bool up );
719 void DisableFreeMove();
720 void EnableFreeMove();
723 CameraView& getCameraView(){
731 typedef MemberCaller<CamWnd, void(), &CamWnd::queue_draw> CamWndQueueDraw;
733 Shader* CamWnd::m_state_select1 = 0;
734 Shader* CamWnd::m_state_select2 = 0;
739 void DeleteCamWnd( CamWnd* camwnd ){
743 void CamWnd_constructStatic(){
744 CamWnd::captureStates();
747 void CamWnd_destroyStatic(){
748 CamWnd::releaseStates();
751 static CamWnd* g_camwnd = 0;
753 void GlobalCamera_setCamWnd( CamWnd& camwnd ){
758 ui::GLArea CamWnd_getWidget( CamWnd& camwnd ){
759 return camwnd.m_gl_widget;
762 ui::Window CamWnd_getParent( CamWnd& camwnd ){
763 return camwnd.m_parent;
766 ToggleShown g_camera_shown( true );
768 void CamWnd_setParent( CamWnd& camwnd, ui::Window parent ){
769 camwnd.m_parent = parent;
770 g_camera_shown.connect( camwnd.m_parent );
773 void CamWnd_Update( CamWnd& camwnd ){
779 camwindow_globals_t g_camwindow_globals;
781 const Vector3& Camera_getOrigin( CamWnd& camwnd ){
782 return Camera_getOrigin( camwnd.getCamera() );
785 void Camera_setOrigin( CamWnd& camwnd, const Vector3& origin ){
786 Camera_setOrigin( camwnd.getCamera(), origin );
789 const Vector3& Camera_getAngles( CamWnd& camwnd ){
790 return Camera_getAngles( camwnd.getCamera() );
793 void Camera_setAngles( CamWnd& camwnd, const Vector3& angles ){
794 Camera_setAngles( camwnd.getCamera(), angles );
798 // =============================================================================
801 gboolean enable_freelook_button_press( ui::Widget widget, GdkEventButton* event, CamWnd* camwnd ){
802 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
803 camwnd->EnableFreeMove();
809 gboolean disable_freelook_button_press( ui::Widget widget, GdkEventButton* event, CamWnd* camwnd ){
810 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
811 camwnd->DisableFreeMove();
818 gboolean mousecontrol_button_press( ui::Widget widget, GdkEventButton* event, CamWnd* camwnd ){
819 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
820 Cam_MouseControl( camwnd->getCamera(), event->x, widget->allocation.height - 1 - event->y );
826 void camwnd_update_xor_rectangle( CamWnd& self, rect_t area ){
827 if ( self.m_gl_widget.visible() ) {
828 self.m_XORRectangle.set( rectangle_from_area( area.min, area.max, self.getCamera().width, self.getCamera().height ) );
833 gboolean selection_button_press( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){
834 if ( event->type == GDK_BUTTON_PRESS ) {
835 observer->onMouseDown( WindowVector_forDouble( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
840 gboolean selection_button_release( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){
841 if ( event->type == GDK_BUTTON_RELEASE ) {
842 observer->onMouseUp( WindowVector_forDouble( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
847 void selection_motion( gdouble x, gdouble y, guint state, void* data ){
848 //globalOutputStream() << "motion... ";
849 reinterpret_cast<WindowObserver*>( data )->onMouseMotion( WindowVector_forDouble( x, y ), modifiers_for_state( state ) );
852 inline WindowVector windowvector_for_widget_centre( ui::Widget widget ){
853 auto allocation = widget.dimensions();
854 return WindowVector( static_cast<float>( allocation.width / 2 ), static_cast<float>(allocation.height / 2 ) );
857 gboolean selection_button_press_freemove( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){
858 if ( event->type == GDK_BUTTON_PRESS ) {
859 observer->onMouseDown( windowvector_for_widget_centre( widget ), button_for_button( event->button ), modifiers_for_state( event->state ) );
864 gboolean selection_button_release_freemove( ui::Widget widget, GdkEventButton* event, WindowObserver* observer ){
865 if ( event->type == GDK_BUTTON_RELEASE ) {
866 observer->onMouseUp( windowvector_for_widget_centre( widget ), button_for_button( event->button ), modifiers_for_state( event->state ) );
871 gboolean selection_motion_freemove( ui::Widget widget, GdkEventMotion *event, WindowObserver* observer ){
872 observer->onMouseMotion( windowvector_for_widget_centre( widget ), modifiers_for_state( event->state ) );
876 gboolean wheelmove_scroll( ui::Widget widget, GdkEventScroll* event, CamWnd* camwnd ){
877 if ( event->direction == GDK_SCROLL_UP ) {
878 Camera_Freemove_updateAxes( camwnd->getCamera() );
879 Camera_setOrigin( *camwnd, vector3_added( Camera_getOrigin( *camwnd ), vector3_scaled( camwnd->getCamera().forward, static_cast<float>( g_camwindow_globals_private.m_nMoveSpeed ) ) ) );
881 else if ( event->direction == GDK_SCROLL_DOWN ) {
882 Camera_Freemove_updateAxes( camwnd->getCamera() );
883 Camera_setOrigin( *camwnd, vector3_added( Camera_getOrigin( *camwnd ), vector3_scaled( camwnd->getCamera().forward, -static_cast<float>( g_camwindow_globals_private.m_nMoveSpeed ) ) ) );
889 gboolean camera_size_allocate( ui::Widget widget, GtkAllocation* allocation, CamWnd* camwnd ){
890 camwnd->getCamera().width = allocation->width;
891 camwnd->getCamera().height = allocation->height;
892 Camera_updateProjection( camwnd->getCamera() );
893 camwnd->m_window_observer->onSizeChanged( camwnd->getCamera().width, camwnd->getCamera().height );
894 camwnd->queue_draw();
898 gboolean camera_expose( ui::Widget widget, GdkEventExpose* event, gpointer data ){
899 reinterpret_cast<CamWnd*>( data )->draw();
903 void KeyEvent_connect( const char* name ){
904 const KeyEvent& keyEvent = GlobalKeyEvents_find( name );
905 keydown_accelerators_add( keyEvent.m_accelerator, keyEvent.m_keyDown );
906 keyup_accelerators_add( keyEvent.m_accelerator, keyEvent.m_keyUp );
909 void KeyEvent_disconnect( const char* name ){
910 const KeyEvent& keyEvent = GlobalKeyEvents_find( name );
911 keydown_accelerators_remove( keyEvent.m_accelerator );
912 keyup_accelerators_remove( keyEvent.m_accelerator );
915 void CamWnd_registerCommands( CamWnd& camwnd ){
916 GlobalKeyEvents_insert( "CameraForward", Accelerator( GDK_KEY_Up ),
917 ReferenceCaller<camera_t, void(), Camera_MoveForward_KeyDown>( camwnd.getCamera() ),
918 ReferenceCaller<camera_t, void(), Camera_MoveForward_KeyUp>( camwnd.getCamera() )
920 GlobalKeyEvents_insert( "CameraBack", Accelerator( GDK_KEY_Down ),
921 ReferenceCaller<camera_t, void(), Camera_MoveBack_KeyDown>( camwnd.getCamera() ),
922 ReferenceCaller<camera_t, void(), Camera_MoveBack_KeyUp>( camwnd.getCamera() )
924 GlobalKeyEvents_insert( "CameraLeft", Accelerator( GDK_KEY_Left ),
925 ReferenceCaller<camera_t, void(), Camera_RotateLeft_KeyDown>( camwnd.getCamera() ),
926 ReferenceCaller<camera_t, void(), Camera_RotateLeft_KeyUp>( camwnd.getCamera() )
928 GlobalKeyEvents_insert( "CameraRight", Accelerator( GDK_KEY_Right ),
929 ReferenceCaller<camera_t, void(), Camera_RotateRight_KeyDown>( camwnd.getCamera() ),
930 ReferenceCaller<camera_t, void(), Camera_RotateRight_KeyUp>( camwnd.getCamera() )
932 GlobalKeyEvents_insert( "CameraStrafeRight", Accelerator( GDK_KEY_period ),
933 ReferenceCaller<camera_t, void(), Camera_MoveRight_KeyDown>( camwnd.getCamera() ),
934 ReferenceCaller<camera_t, void(), Camera_MoveRight_KeyUp>( camwnd.getCamera() )
936 GlobalKeyEvents_insert( "CameraStrafeLeft", Accelerator( GDK_KEY_comma ),
937 ReferenceCaller<camera_t, void(), Camera_MoveLeft_KeyDown>( camwnd.getCamera() ),
938 ReferenceCaller<camera_t, void(), Camera_MoveLeft_KeyUp>( camwnd.getCamera() )
940 GlobalKeyEvents_insert( "CameraUp", Accelerator( 'D' ),
941 ReferenceCaller<camera_t, void(), Camera_MoveUp_KeyDown>( camwnd.getCamera() ),
942 ReferenceCaller<camera_t, void(), Camera_MoveUp_KeyUp>( camwnd.getCamera() )
944 GlobalKeyEvents_insert( "CameraDown", Accelerator( 'C' ),
945 ReferenceCaller<camera_t, void(), Camera_MoveDown_KeyDown>( camwnd.getCamera() ),
946 ReferenceCaller<camera_t, void(), Camera_MoveDown_KeyUp>( camwnd.getCamera() )
948 GlobalKeyEvents_insert( "CameraAngleDown", Accelerator( 'A' ),
949 ReferenceCaller<camera_t, void(), Camera_PitchDown_KeyDown>( camwnd.getCamera() ),
950 ReferenceCaller<camera_t, void(), Camera_PitchDown_KeyUp>( camwnd.getCamera() )
952 GlobalKeyEvents_insert( "CameraAngleUp", Accelerator( 'Z' ),
953 ReferenceCaller<camera_t, void(), Camera_PitchUp_KeyDown>( camwnd.getCamera() ),
954 ReferenceCaller<camera_t, void(), Camera_PitchUp_KeyUp>( camwnd.getCamera() )
957 GlobalKeyEvents_insert( "CameraFreeMoveForward", Accelerator( GDK_KEY_Up ),
958 FreeMoveCameraMoveForwardKeyDownCaller( camwnd.getCamera() ),
959 FreeMoveCameraMoveForwardKeyUpCaller( camwnd.getCamera() )
961 GlobalKeyEvents_insert( "CameraFreeMoveBack", Accelerator( GDK_KEY_Down ),
962 FreeMoveCameraMoveBackKeyDownCaller( camwnd.getCamera() ),
963 FreeMoveCameraMoveBackKeyUpCaller( camwnd.getCamera() )
965 GlobalKeyEvents_insert( "CameraFreeMoveLeft", Accelerator( GDK_KEY_Left ),
966 FreeMoveCameraMoveLeftKeyDownCaller( camwnd.getCamera() ),
967 FreeMoveCameraMoveLeftKeyUpCaller( camwnd.getCamera() )
969 GlobalKeyEvents_insert( "CameraFreeMoveRight", Accelerator( GDK_KEY_Right ),
970 FreeMoveCameraMoveRightKeyDownCaller( camwnd.getCamera() ),
971 FreeMoveCameraMoveRightKeyUpCaller( camwnd.getCamera() )
974 GlobalKeyEvents_insert( "CameraFreeMoveForward2", Accelerator( GDK_Up ),
975 FreeMoveCameraMoveForwardKeyDownCaller( camwnd.getCamera() ),
976 FreeMoveCameraMoveForwardKeyUpCaller( camwnd.getCamera() )
978 GlobalKeyEvents_insert( "CameraFreeMoveBack2", Accelerator( GDK_Down ),
979 FreeMoveCameraMoveBackKeyDownCaller( camwnd.getCamera() ),
980 FreeMoveCameraMoveBackKeyUpCaller( camwnd.getCamera() )
982 GlobalKeyEvents_insert( "CameraFreeMoveLeft2", Accelerator( GDK_Left ),
983 FreeMoveCameraMoveLeftKeyDownCaller( camwnd.getCamera() ),
984 FreeMoveCameraMoveLeftKeyUpCaller( camwnd.getCamera() )
986 GlobalKeyEvents_insert( "CameraFreeMoveRight2", Accelerator( GDK_Right ),
987 FreeMoveCameraMoveRightKeyDownCaller( camwnd.getCamera() ),
988 FreeMoveCameraMoveRightKeyUpCaller( camwnd.getCamera() )
991 GlobalKeyEvents_insert( "CameraFreeMoveUp", Accelerator( 'D' ),
992 FreeMoveCameraMoveUpKeyDownCaller( camwnd.getCamera() ),
993 FreeMoveCameraMoveUpKeyUpCaller( camwnd.getCamera() )
995 GlobalKeyEvents_insert( "CameraFreeMoveDown", Accelerator( 'C' ),
996 FreeMoveCameraMoveDownKeyDownCaller( camwnd.getCamera() ),
997 FreeMoveCameraMoveDownKeyUpCaller( camwnd.getCamera() )
1000 GlobalCommands_insert( "CameraForward", ReferenceCaller<camera_t, void(), Camera_MoveForward_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_Up ) );
1001 GlobalCommands_insert( "CameraBack", ReferenceCaller<camera_t, void(), Camera_MoveBack_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_Down ) );
1002 GlobalCommands_insert( "CameraLeft", ReferenceCaller<camera_t, void(), Camera_RotateLeft_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_Left ) );
1003 GlobalCommands_insert( "CameraRight", ReferenceCaller<camera_t, void(), Camera_RotateRight_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_Right ) );
1004 GlobalCommands_insert( "CameraStrafeRight", ReferenceCaller<camera_t, void(), Camera_MoveRight_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_period ) );
1005 GlobalCommands_insert( "CameraStrafeLeft", ReferenceCaller<camera_t, void(), Camera_MoveLeft_Discrete>( camwnd.getCamera() ), Accelerator( GDK_KEY_comma ) );
1007 GlobalCommands_insert( "CameraUp", ReferenceCaller<camera_t, void(), Camera_MoveUp_Discrete>( camwnd.getCamera() ), Accelerator( 'D' ) );
1008 GlobalCommands_insert( "CameraDown", ReferenceCaller<camera_t, void(), Camera_MoveDown_Discrete>( camwnd.getCamera() ), Accelerator( 'C' ) );
1009 GlobalCommands_insert( "CameraAngleUp", ReferenceCaller<camera_t, void(), Camera_PitchUp_Discrete>( camwnd.getCamera() ), Accelerator( 'A' ) );
1010 GlobalCommands_insert( "CameraAngleDown", ReferenceCaller<camera_t, void(), Camera_PitchDown_Discrete>( camwnd.getCamera() ), Accelerator( 'Z' ) );
1013 void CamWnd_Move_Enable( CamWnd& camwnd ){
1014 KeyEvent_connect( "CameraForward" );
1015 KeyEvent_connect( "CameraBack" );
1016 KeyEvent_connect( "CameraLeft" );
1017 KeyEvent_connect( "CameraRight" );
1018 KeyEvent_connect( "CameraStrafeRight" );
1019 KeyEvent_connect( "CameraStrafeLeft" );
1020 KeyEvent_connect( "CameraUp" );
1021 KeyEvent_connect( "CameraDown" );
1022 KeyEvent_connect( "CameraAngleUp" );
1023 KeyEvent_connect( "CameraAngleDown" );
1026 void CamWnd_Move_Disable( CamWnd& camwnd ){
1027 KeyEvent_disconnect( "CameraForward" );
1028 KeyEvent_disconnect( "CameraBack" );
1029 KeyEvent_disconnect( "CameraLeft" );
1030 KeyEvent_disconnect( "CameraRight" );
1031 KeyEvent_disconnect( "CameraStrafeRight" );
1032 KeyEvent_disconnect( "CameraStrafeLeft" );
1033 KeyEvent_disconnect( "CameraUp" );
1034 KeyEvent_disconnect( "CameraDown" );
1035 KeyEvent_disconnect( "CameraAngleUp" );
1036 KeyEvent_disconnect( "CameraAngleDown" );
1039 void CamWnd_Move_Discrete_Enable( CamWnd& camwnd ){
1040 command_connect_accelerator( "CameraForward" );
1041 command_connect_accelerator( "CameraBack" );
1042 command_connect_accelerator( "CameraLeft" );
1043 command_connect_accelerator( "CameraRight" );
1044 command_connect_accelerator( "CameraStrafeRight" );
1045 command_connect_accelerator( "CameraStrafeLeft" );
1046 command_connect_accelerator( "CameraUp" );
1047 command_connect_accelerator( "CameraDown" );
1048 command_connect_accelerator( "CameraAngleUp" );
1049 command_connect_accelerator( "CameraAngleDown" );
1052 void CamWnd_Move_Discrete_Disable( CamWnd& camwnd ){
1053 command_disconnect_accelerator( "CameraForward" );
1054 command_disconnect_accelerator( "CameraBack" );
1055 command_disconnect_accelerator( "CameraLeft" );
1056 command_disconnect_accelerator( "CameraRight" );
1057 command_disconnect_accelerator( "CameraStrafeRight" );
1058 command_disconnect_accelerator( "CameraStrafeLeft" );
1059 command_disconnect_accelerator( "CameraUp" );
1060 command_disconnect_accelerator( "CameraDown" );
1061 command_disconnect_accelerator( "CameraAngleUp" );
1062 command_disconnect_accelerator( "CameraAngleDown" );
1065 struct CamWnd_Move_Discrete {
1066 static void Export(const Callback<void(bool)> &returnz) {
1067 returnz(g_camwindow_globals_private.m_bCamDiscrete);
1070 static void Import(bool value) {
1072 Import_(*g_camwnd, value);
1074 g_camwindow_globals_private.m_bCamDiscrete = value;
1078 static void Import_(CamWnd &camwnd, bool value) {
1079 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1080 CamWnd_Move_Discrete_Disable( camwnd );
1082 CamWnd_Move_Disable( camwnd );
1085 g_camwindow_globals_private.m_bCamDiscrete = value;
1087 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1088 CamWnd_Move_Discrete_Enable( camwnd );
1090 CamWnd_Move_Enable( camwnd );
1096 void CamWnd_Add_Handlers_Move( CamWnd& camwnd ){
1097 camwnd.m_selection_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( selection_button_press ), camwnd.m_window_observer );
1098 camwnd.m_selection_button_release_handler = camwnd.m_gl_widget.connect( "button_release_event", G_CALLBACK( selection_button_release ), camwnd.m_window_observer );
1099 camwnd.m_selection_motion_handler = camwnd.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &camwnd.m_deferred_motion );
1101 camwnd.m_freelook_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( enable_freelook_button_press ), &camwnd );
1103 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1104 CamWnd_Move_Discrete_Enable( camwnd );
1108 CamWnd_Move_Enable( camwnd );
1112 void CamWnd_Remove_Handlers_Move( CamWnd& camwnd ){
1113 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_press_handler );
1114 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_release_handler );
1115 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_motion_handler );
1117 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_freelook_button_press_handler );
1119 if ( g_camwindow_globals_private.m_bCamDiscrete ) {
1120 CamWnd_Move_Discrete_Disable( camwnd );
1124 CamWnd_Move_Disable( camwnd );
1128 void CamWnd_Add_Handlers_FreeMove( CamWnd& camwnd ){
1129 camwnd.m_selection_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( selection_button_press_freemove ), camwnd.m_window_observer );
1130 camwnd.m_selection_button_release_handler = camwnd.m_gl_widget.connect( "button_release_event", G_CALLBACK( selection_button_release_freemove ), camwnd.m_window_observer );
1131 camwnd.m_selection_motion_handler = camwnd.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( selection_motion_freemove ), camwnd.m_window_observer );
1133 camwnd.m_freelook_button_press_handler = camwnd.m_gl_widget.connect( "button_press_event", G_CALLBACK( disable_freelook_button_press ), &camwnd );
1135 KeyEvent_connect( "CameraFreeMoveForward" );
1136 KeyEvent_connect( "CameraFreeMoveBack" );
1137 KeyEvent_connect( "CameraFreeMoveLeft" );
1138 KeyEvent_connect( "CameraFreeMoveRight" );
1140 KeyEvent_connect( "CameraFreeMoveForward2" );
1141 KeyEvent_connect( "CameraFreeMoveBack2" );
1142 KeyEvent_connect( "CameraFreeMoveLeft2" );
1143 KeyEvent_connect( "CameraFreeMoveRight2" );
1145 KeyEvent_connect( "CameraFreeMoveUp" );
1146 KeyEvent_connect( "CameraFreeMoveDown" );
1149 void CamWnd_Remove_Handlers_FreeMove( CamWnd& camwnd ){
1150 KeyEvent_disconnect( "CameraFreeMoveForward" );
1151 KeyEvent_disconnect( "CameraFreeMoveBack" );
1152 KeyEvent_disconnect( "CameraFreeMoveLeft" );
1153 KeyEvent_disconnect( "CameraFreeMoveRight" );
1155 KeyEvent_disconnect( "CameraFreeMoveForward2" );
1156 KeyEvent_disconnect( "CameraFreeMoveBack2" );
1157 KeyEvent_disconnect( "CameraFreeMoveLeft2" );
1158 KeyEvent_disconnect( "CameraFreeMoveRight2" );
1160 KeyEvent_disconnect( "CameraFreeMoveUp" );
1161 KeyEvent_disconnect( "CameraFreeMoveDown" );
1163 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_press_handler );
1164 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_button_release_handler );
1165 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_selection_motion_handler );
1167 g_signal_handler_disconnect( G_OBJECT( camwnd.m_gl_widget ), camwnd.m_freelook_button_press_handler );
1172 m_Camera( &m_view, CamWndQueueDraw( *this ) ),
1173 m_cameraview( m_Camera, &m_view, ReferenceCaller<CamWnd, void(), CamWnd_Update>( *this ) ),
1174 m_gl_widget( glwidget_new( TRUE ) ),
1175 m_window_observer( NewWindowObserver() ),
1176 m_XORRectangle( m_gl_widget ),
1177 m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ),
1178 m_deferred_motion( selection_motion, m_window_observer ),
1179 m_selection_button_press_handler( 0 ),
1180 m_selection_button_release_handler( 0 ),
1181 m_selection_motion_handler( 0 ),
1182 m_freelook_button_press_handler( 0 ),
1184 m_bFreeMove = false;
1186 GlobalWindowObservers_add( m_window_observer );
1187 GlobalWindowObservers_connectWidget( m_gl_widget );
1189 m_window_observer->setRectangleDrawCallback( ReferenceCaller<CamWnd, void(rect_t), camwnd_update_xor_rectangle>( *this ) );
1190 m_window_observer->setView( m_view );
1192 g_object_ref( m_gl_widget._handle );
1194 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 );
1195 gtk_widget_set_can_focus( m_gl_widget, true );
1197 m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( camera_size_allocate ), this );
1198 m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( camera_expose ), this );
1200 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
1202 CamWnd_registerCommands( *this );
1204 CamWnd_Add_Handlers_Move( *this );
1206 m_gl_widget.connect( "scroll_event", G_CALLBACK( wheelmove_scroll ), this );
1208 AddSceneChangeCallback( ReferenceCaller<CamWnd, void(), CamWnd_Update>( *this ) );
1210 PressedButtons_connect( g_pressedButtons, m_gl_widget );
1214 if ( m_bFreeMove ) {
1218 CamWnd_Remove_Handlers_Move( *this );
1220 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
1221 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
1223 m_gl_widget.unref();
1225 m_window_observer->release();
1228 class FloorHeightWalker : public scene::Graph::Walker
1234 FloorHeightWalker( float current, float& bestUp, float& bestDown ) :
1235 m_current( current ), m_bestUp( bestUp ), m_bestDown( bestDown ){
1236 bestUp = g_MaxWorldCoord;
1237 bestDown = -g_MaxWorldCoord;
1239 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1240 if ( path.top().get().visible()
1241 && Node_isBrush( path.top() ) ) { // this node is a floor
1242 const AABB& aabb = instance.worldAABB();
1243 float floorHeight = aabb.origin.z() + aabb.extents.z();
1244 if ( floorHeight > m_current && floorHeight < m_bestUp ) {
1245 m_bestUp = floorHeight;
1247 if ( floorHeight < m_current && floorHeight > m_bestDown ) {
1248 m_bestDown = floorHeight;
1255 void CamWnd::Cam_ChangeFloor( bool up ){
1256 float current = m_Camera.origin[2] - 48;
1259 GlobalSceneGraph().traverse( FloorHeightWalker( current, bestUp, bestDown ) );
1261 if ( up && bestUp != g_MaxWorldCoord ) {
1264 if ( !up && bestDown != -g_MaxWorldCoord ) {
1268 m_Camera.origin[2] = current + 48;
1269 Camera_updateModelview( getCamera() );
1270 CamWnd_Update( *this );
1271 CameraMovedNotify();
1278 Sys_GetCursorPos( &m_PositionDragCursorX, &m_PositionDragCursorY );
1281 if ( ( m_bFreeMove && ( buttons == ( RAD_CONTROL | RAD_SHIFT ) ) )
1282 || ( !m_bFreeMove && ( buttons == ( RAD_RBUTTON | RAD_CONTROL ) ) ) ) {
1284 CamWnd_Update( camwnd );
1285 CameraMovedNotify();
1289 void CamWnd::Cam_PositionDrag(){
1292 Sys_GetCursorPos( m_gl_widget, &x, &y );
1293 if ( x != m_PositionDragCursorX || y != m_PositionDragCursorY ) {
1294 x -= m_PositionDragCursorX;
1295 vector3_add( m_Camera.origin, vector3_scaled( m_Camera.vright, x ) );
1296 y -= m_PositionDragCursorY;
1297 m_Camera.origin[2] -= y;
1298 Camera_updateModelview();
1299 CamWnd_Update( camwnd );
1300 CameraMovedNotify();
1302 Sys_SetCursorPos( m_gl_widget, m_PositionDragCursorX, m_PositionDragCursorY );
1308 // NOTE TTimo if there's an OS-level focus out of the application
1309 // then we can release the camera cursor grab
1310 static gboolean camwindow_freemove_focusout( ui::Widget widget, GdkEventFocus* event, gpointer data ){
1311 reinterpret_cast<CamWnd*>( data )->DisableFreeMove();
1315 void CamWnd::EnableFreeMove(){
1316 //globalOutputStream() << "EnableFreeMove\n";
1318 ASSERT_MESSAGE( !m_bFreeMove, "EnableFreeMove: free-move was already enabled" );
1320 Camera_clearMovementFlags( getCamera(), MOVE_ALL );
1322 CamWnd_Remove_Handlers_Move( *this );
1323 CamWnd_Add_Handlers_FreeMove( *this );
1325 gtk_window_set_focus( m_parent, m_gl_widget );
1326 m_freemove_handle_focusout = m_gl_widget.connect( "focus_out_event", G_CALLBACK( camwindow_freemove_focusout ), this );
1327 m_freezePointer.freeze_pointer( m_gl_widget, Camera_motionDelta, &m_Camera );
1329 CamWnd_Update( *this );
1332 void CamWnd::DisableFreeMove(){
1333 //globalOutputStream() << "DisableFreeMove\n";
1335 ASSERT_MESSAGE( m_bFreeMove, "DisableFreeMove: free-move was not enabled" );
1336 m_bFreeMove = false;
1337 Camera_clearMovementFlags( getCamera(), MOVE_ALL );
1339 CamWnd_Remove_Handlers_FreeMove( *this );
1340 CamWnd_Add_Handlers_Move( *this );
1342 m_freezePointer.unfreeze_pointer( m_gl_widget );
1343 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_freemove_handle_focusout );
1345 CamWnd_Update( *this );
1349 #include "renderer.h"
1351 class CamRenderer : public Renderer
1355 state_type() : m_highlight( 0 ), m_state( 0 ), m_lights( 0 ){
1357 unsigned int m_highlight;
1359 const LightList* m_lights;
1362 std::vector<state_type> m_state_stack;
1363 RenderStateFlags m_globalstate;
1364 Shader* m_state_select0;
1365 Shader* m_state_select1;
1366 const Vector3& m_viewer;
1369 CamRenderer( RenderStateFlags globalstate, Shader* select0, Shader* select1, const Vector3& viewer ) :
1370 m_globalstate( globalstate ),
1371 m_state_select0( select0 ),
1372 m_state_select1( select1 ),
1374 ASSERT_NOTNULL( select0 );
1375 ASSERT_NOTNULL( select1 );
1376 m_state_stack.push_back( state_type() );
1379 void SetState( Shader* state, EStyle style ){
1380 ASSERT_NOTNULL( state );
1381 if ( style == eFullMaterials ) {
1382 m_state_stack.back().m_state = state;
1385 EStyle getStyle() const {
1386 return eFullMaterials;
1389 m_state_stack.push_back( m_state_stack.back() );
1392 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
1393 m_state_stack.pop_back();
1395 void Highlight( EHighlightMode mode, bool bEnable = true ){
1397 m_state_stack.back().m_highlight |= mode;
1399 m_state_stack.back().m_highlight &= ~mode;
1402 void setLights( const LightList& lights ){
1403 m_state_stack.back().m_lights = &lights;
1405 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& world ){
1406 if ( m_state_stack.back().m_highlight & ePrimitive ) {
1407 m_state_select0->addRenderable( renderable, world, m_state_stack.back().m_lights );
1409 if ( m_state_stack.back().m_highlight & eFace ) {
1410 m_state_select1->addRenderable( renderable, world, m_state_stack.back().m_lights );
1413 m_state_stack.back().m_state->addRenderable( renderable, world, m_state_stack.back().m_lights );
1416 void render( const Matrix4& modelview, const Matrix4& projection ){
1417 GlobalShaderCache().render( m_globalstate, modelview, projection, m_viewer );
1427 void ShowStatsToggle(){
1428 g_camwindow_globals_private.m_showStats ^= 1;
1431 void ShowStatsExport( const Callback<void(bool)> &importer ){
1432 importer( g_camwindow_globals_private.m_showStats );
1435 FreeCaller<void(const Callback<void(bool)>&), ShowStatsExport> g_show_stats_caller;
1436 Callback<void(const Callback<void(bool)> &)> g_show_stats_callback( g_show_stats_caller );
1437 ToggleItem g_show_stats( g_show_stats_callback );
1439 void CamWnd::Cam_Draw(){
1440 glViewport( 0, 0, m_Camera.width, m_Camera.height );
1443 glGetIntegerv( GL_VIEWPORT, viewprt );
1446 // enable depth buffer writes
1447 glDepthMask( GL_TRUE );
1448 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1450 Vector3 clearColour( 0, 0, 0 );
1451 if ( m_Camera.draw_mode != cd_lighting ) {
1452 clearColour = g_camwindow_globals.color_cameraback;
1455 glClearColor( clearColour[0], clearColour[1], clearColour[2], 0 );
1456 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1458 extern void Renderer_ResetStats();
1459 Renderer_ResetStats();
1460 extern void Cull_ResetStats();
1463 glMatrixMode( GL_PROJECTION );
1464 glLoadMatrixf( reinterpret_cast<const float*>( &m_Camera.projection ) );
1466 glMatrixMode( GL_MODELVIEW );
1467 glLoadMatrixf( reinterpret_cast<const float*>( &m_Camera.modelview ) );
1470 // one directional light source directly behind the viewer
1472 GLfloat inverse_cam_dir[4], ambient[4], diffuse[4]; //, material[4];
1474 ambient[0] = ambient[1] = ambient[2] = 0.4f;
1476 diffuse[0] = diffuse[1] = diffuse[2] = 0.4f;
1478 //material[0] = material[1] = material[2] = 0.8f;
1479 //material[3] = 1.0f;
1481 inverse_cam_dir[0] = m_Camera.vpn[0];
1482 inverse_cam_dir[1] = m_Camera.vpn[1];
1483 inverse_cam_dir[2] = m_Camera.vpn[2];
1484 inverse_cam_dir[3] = 0;
1486 glLightfv( GL_LIGHT0, GL_POSITION, inverse_cam_dir );
1488 glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
1489 glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
1491 glEnable( GL_LIGHT0 );
1495 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;
1496 switch ( m_Camera.draw_mode )
1501 globalstate |= RENDER_FILL
1507 globalstate |= RENDER_FILL
1514 globalstate |= RENDER_FILL
1528 if ( !g_xywindow_globals.m_bNoStipple ) {
1529 globalstate |= RENDER_LINESTIPPLE | RENDER_POLYGONSTIPPLE;
1533 CamRenderer renderer( globalstate, m_state_select2, m_state_select1, m_view.getViewer() );
1535 Scene_Render( renderer, m_view );
1537 renderer.render( m_Camera.modelview, m_Camera.projection );
1540 // prepare for 2d stuff
1541 glColor4f( 1, 1, 1, 1 );
1542 glDisable( GL_BLEND );
1543 glMatrixMode( GL_PROJECTION );
1545 glOrtho( 0, (float)m_Camera.width, 0, (float)m_Camera.height, -100, 100 );
1546 glScalef( 1, -1, 1 );
1547 glTranslatef( 0, -(float)m_Camera.height, 0 );
1548 glMatrixMode( GL_MODELVIEW );
1551 if ( GlobalOpenGL().GL_1_3() ) {
1552 glClientActiveTexture( GL_TEXTURE0 );
1553 glActiveTexture( GL_TEXTURE0 );
1556 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1557 glDisableClientState( GL_NORMAL_ARRAY );
1558 glDisableClientState( GL_COLOR_ARRAY );
1560 glDisable( GL_TEXTURE_2D );
1561 glDisable( GL_LIGHTING );
1562 glDisable( GL_COLOR_MATERIAL );
1563 glDisable( GL_DEPTH_TEST );
1564 glColor3f( 1.f, 1.f, 1.f );
1567 // draw the crosshair
1568 if ( m_bFreeMove ) {
1569 glBegin( GL_LINES );
1570 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f + 6 );
1571 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f + 2 );
1572 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f - 6 );
1573 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f - 2 );
1574 glVertex2f( (float)m_Camera.width / 2.f + 6, (float)m_Camera.height / 2.f );
1575 glVertex2f( (float)m_Camera.width / 2.f + 2, (float)m_Camera.height / 2.f );
1576 glVertex2f( (float)m_Camera.width / 2.f - 6, (float)m_Camera.height / 2.f );
1577 glVertex2f( (float)m_Camera.width / 2.f - 2, (float)m_Camera.height / 2.f );
1581 if ( g_camwindow_globals_private.m_showStats ) {
1582 glRasterPos3f( 1.0f, static_cast<float>( m_Camera.height ) - GlobalOpenGL().m_font->getPixelDescent(), 0.0f );
1583 extern const char* Renderer_GetStats();
1584 GlobalOpenGL().drawString( Renderer_GetStats() );
1586 glRasterPos3f( 1.0f, static_cast<float>( m_Camera.height ) - GlobalOpenGL().m_font->getPixelDescent() - GlobalOpenGL().m_font->getPixelHeight(), 0.0f );
1587 extern const char* Cull_GetStats();
1588 GlobalOpenGL().drawString( Cull_GetStats() );
1591 // bind back to the default texture so that we don't have problems
1592 // elsewhere using/modifying texture maps between contexts
1593 glBindTexture( GL_TEXTURE_2D, 0 );
1596 void CamWnd::draw(){
1599 //globalOutputStream() << "draw...\n";
1600 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
1601 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
1602 GlobalOpenGL_debugAssertNoErrors();
1604 GlobalOpenGL_debugAssertNoErrors();
1607 m_XORRectangle.set( rectangle_t() );
1610 glwidget_swap_buffers( m_gl_widget );
1616 void CamWnd::BenchMark(){
1617 double dStart = Sys_DoubleTime();
1618 for ( int i = 0 ; i < 100 ; i++ )
1621 angles[CAMERA_ROLL] = 0;
1622 angles[CAMERA_PITCH] = 0;
1623 angles[CAMERA_YAW] = i * 360.0f / 100.0f;
1624 Camera_setAngles( *this, angles );
1626 double dEnd = Sys_DoubleTime();
1627 globalOutputStream() << FloatFormat( dEnd - dStart, 5, 2 ) << " seconds\n";
1631 void fill_view_camera_menu( ui::Menu menu ){
1632 create_check_menu_item_with_mnemonic( menu, "Camera View", "ToggleCamera" );
1635 void GlobalCamera_ResetAngles(){
1636 CamWnd& camwnd = *g_camwnd;
1638 angles[CAMERA_ROLL] = angles[CAMERA_PITCH] = 0;
1639 angles[CAMERA_YAW] = 22.5f * floorf( ( Camera_getAngles( camwnd )[CAMERA_YAW] + 11 ) / 22.5f );
1640 Camera_setAngles( camwnd, angles );
1643 void Camera_ChangeFloorUp(){
1644 CamWnd& camwnd = *g_camwnd;
1645 camwnd.Cam_ChangeFloor( true );
1648 void Camera_ChangeFloorDown(){
1649 CamWnd& camwnd = *g_camwnd;
1650 camwnd.Cam_ChangeFloor( false );
1653 void Camera_CubeIn(){
1654 CamWnd& camwnd = *g_camwnd;
1655 g_camwindow_globals.m_nCubicScale--;
1656 if ( g_camwindow_globals.m_nCubicScale < 1 ) {
1657 g_camwindow_globals.m_nCubicScale = 1;
1659 Camera_updateProjection( camwnd.getCamera() );
1660 CamWnd_Update( camwnd );
1661 g_pParentWnd->SetGridStatus();
1664 void Camera_CubeOut(){
1665 CamWnd& camwnd = *g_camwnd;
1666 g_camwindow_globals.m_nCubicScale++;
1667 if ( g_camwindow_globals.m_nCubicScale > 46 ) {
1668 g_camwindow_globals.m_nCubicScale = 46;
1670 Camera_updateProjection( camwnd.getCamera() );
1671 CamWnd_Update( camwnd );
1672 g_pParentWnd->SetGridStatus();
1675 bool Camera_GetFarClip(){
1676 return g_camwindow_globals_private.m_bCubicClipping;
1679 ConstReferenceCaller<bool, void(const Callback<void(bool)> &), PropertyImpl<bool>::Export> g_getfarclip_caller( g_camwindow_globals_private.m_bCubicClipping );
1680 ToggleItem g_getfarclip_item( g_getfarclip_caller );
1682 void Camera_SetFarClip( bool value ){
1683 CamWnd& camwnd = *g_camwnd;
1684 g_camwindow_globals_private.m_bCubicClipping = value;
1685 g_getfarclip_item.update();
1686 Camera_updateProjection( camwnd.getCamera() );
1687 CamWnd_Update( camwnd );
1690 struct Camera_FarClip {
1691 static void Export(const Callback<void(bool)> &returnz) {
1692 returnz(g_camwindow_globals_private.m_bCubicClipping);
1695 static void Import(bool value) {
1696 Camera_SetFarClip(value);
1700 void Camera_ToggleFarClip(){
1701 Camera_SetFarClip( !Camera_GetFarClip() );
1705 void CamWnd_constructToolbar( ui::Toolbar toolbar ){
1706 toolbar_append_toggle_button( toolbar, "Cubic clip the camera view (Ctrl + \\)", "view_cubicclipping.png", "ToggleCubicClip" );
1709 void CamWnd_registerShortcuts(){
1710 toggle_add_accelerator( "ToggleCubicClip" );
1712 if ( g_pGameDescription->mGameType == "doom3" ) {
1713 command_connect_accelerator( "TogglePreview" );
1716 command_connect_accelerator( "FOVInc" );
1717 command_connect_accelerator( "FOVDec" );
1718 command_connect_accelerator( "CameraSpeedInc" );
1719 command_connect_accelerator( "CameraSpeedDec" );
1723 void GlobalCamera_Benchmark(){
1724 CamWnd& camwnd = *g_camwnd;
1728 void GlobalCamera_Update(){
1729 CamWnd& camwnd = *g_camwnd;
1730 CamWnd_Update( camwnd );
1733 camera_draw_mode CamWnd_GetMode(){
1734 return camera_t::draw_mode;
1736 void CamWnd_SetMode( camera_draw_mode mode ){
1737 ShaderCache_setBumpEnabled( mode == cd_lighting );
1738 camera_t::draw_mode = mode;
1739 if ( g_camwnd != 0 ) {
1740 CamWnd_Update( *g_camwnd );
1744 void CamWnd_TogglePreview( void ){
1745 // gametype must be doom3 for this function to work
1746 // if the gametype is not doom3 something is wrong with the
1747 // global command list or somebody else calls this function.
1748 ASSERT_MESSAGE( g_pGameDescription->mGameType == "doom3", "CamWnd_TogglePreview called although mGameType is not doom3 compatible" );
1750 // switch between textured and lighting mode
1751 CamWnd_SetMode( ( CamWnd_GetMode() == cd_lighting ) ? cd_texture : cd_lighting );
1755 CameraModel* g_camera_model = 0;
1757 void CamWnd_LookThroughCamera( CamWnd& camwnd ){
1758 if ( g_camera_model != 0 ) {
1759 CamWnd_Add_Handlers_Move( camwnd );
1760 g_camera_model->setCameraView( 0, Callback<void()>() );
1762 Camera_updateModelview( camwnd.getCamera() );
1763 Camera_updateProjection( camwnd.getCamera() );
1764 CamWnd_Update( camwnd );
1768 inline CameraModel* Instance_getCameraModel( scene::Instance& instance ){
1769 return InstanceTypeCast<CameraModel>::cast( instance );
1772 void CamWnd_LookThroughSelected( CamWnd& camwnd ){
1773 if ( g_camera_model != 0 ) {
1774 CamWnd_LookThroughCamera( camwnd );
1777 if ( GlobalSelectionSystem().countSelected() != 0 ) {
1778 scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
1779 CameraModel* cameraModel = Instance_getCameraModel( instance );
1780 if ( cameraModel != 0 ) {
1781 CamWnd_Remove_Handlers_Move( camwnd );
1782 g_camera_model = cameraModel;
1783 g_camera_model->setCameraView( &camwnd.getCameraView(), ReferenceCaller<CamWnd, void(), CamWnd_LookThroughCamera>( camwnd ) );
1788 void GlobalCamera_LookThroughSelected(){
1789 CamWnd_LookThroughSelected( *g_camwnd );
1792 void GlobalCamera_LookThroughCamera(){
1793 CamWnd_LookThroughCamera( *g_camwnd );
1797 static void Export(const Callback<void(int)> &returnz) {
1798 switch (CamWnd_GetMode()) {
1814 static void Import(int value) {
1817 CamWnd_SetMode( cd_wire );
1820 CamWnd_SetMode( cd_solid );
1823 CamWnd_SetMode( cd_texture );
1826 CamWnd_SetMode( cd_lighting );
1829 CamWnd_SetMode( cd_texture );
1834 void Camera_constructPreferences( PreferencesPage& page ){
1835 page.appendSlider( "FOV", g_camwindow_globals_private.m_nFOV, TRUE, 0, 0, 100, MIN_FOV, MAX_FOV, 1, 10 );
1836 page.appendSlider( "Movement Speed", g_camwindow_globals_private.m_nMoveSpeed, TRUE, 0, 0, 100, MIN_CAM_SPEED, MAX_CAM_SPEED, 1, 10 );
1837 page.appendCheckBox( "", "Link strafe speed to movement speed", g_camwindow_globals_private.m_bCamLinkSpeed );
1838 page.appendSlider( "Rotation Speed", g_camwindow_globals_private.m_nAngleSpeed, TRUE, 0, 0, 3, 1, 180, 1, 10 );
1839 page.appendCheckBox( "", "Invert mouse vertical axis", g_camwindow_globals_private.m_bCamInverseMouse );
1840 page.appendCheckBox(
1841 "", "Discrete movement",
1842 make_property<CamWnd_Move_Discrete>()
1844 page.appendCheckBox(
1845 "", "Enable far-clip plane",
1846 make_property<Camera_FarClip>()
1849 if ( g_pGameDescription->mGameType == "doom3" ) {
1850 const char* render_mode[] = { "Wireframe", "Flatshade", "Textured", "Lighting" };
1854 STRING_ARRAY_RANGE( render_mode ),
1855 make_property<RenderMode>()
1860 const char* render_mode[] = { "Wireframe", "Flatshade", "Textured" };
1864 STRING_ARRAY_RANGE( render_mode ),
1865 make_property<RenderMode>()
1869 const char* strafe_mode[] = { "Both", "Forward", "Up" };
1873 g_camwindow_globals_private.m_nStrafeMode,
1874 STRING_ARRAY_RANGE( strafe_mode )
1877 void Camera_constructPage( PreferenceGroup& group ){
1878 PreferencesPage page( group.createPage( "Camera", "Camera View Preferences" ) );
1879 Camera_constructPreferences( page );
1881 void Camera_registerPreferencesPage(){
1882 PreferencesDialog_addSettingsPage( makeCallbackF(Camera_constructPage) );
1885 #include "preferencesystem.h"
1886 #include "stringio.h"
1889 void FOV_increase(){
1890 CamWnd& camwnd = *g_camwnd;
1891 if ( g_camwindow_globals_private.m_nFOV <= ( MAX_FOV - FOV_STEP - 10 ) ) {
1892 g_camwindow_globals_private.m_nFOV += FOV_STEP;
1895 g_camwindow_globals_private.m_nFOV = MAX_FOV - 10;
1897 Camera_updateProjection( camwnd.getCamera() );
1898 CamWnd_Update( camwnd );
1901 void FOV_decrease(){
1902 CamWnd& camwnd = *g_camwnd;
1903 if ( g_camwindow_globals_private.m_nFOV >= ( MIN_FOV + FOV_STEP ) ) {
1904 g_camwindow_globals_private.m_nFOV -= FOV_STEP;
1907 g_camwindow_globals_private.m_nFOV = MIN_FOV;
1909 Camera_updateProjection( camwnd.getCamera() );
1910 CamWnd_Update( camwnd );
1914 void CameraSpeed_increase(){
1915 if ( g_camwindow_globals_private.m_nMoveSpeed <= ( MAX_CAM_SPEED - CAM_SPEED_STEP - 10 ) ) {
1916 g_camwindow_globals_private.m_nMoveSpeed += CAM_SPEED_STEP;
1919 g_camwindow_globals_private.m_nMoveSpeed = MAX_CAM_SPEED - 10;
1923 void CameraSpeed_decrease(){
1924 if ( g_camwindow_globals_private.m_nMoveSpeed >= ( MIN_CAM_SPEED + CAM_SPEED_STEP ) ) {
1925 g_camwindow_globals_private.m_nMoveSpeed -= CAM_SPEED_STEP;
1928 g_camwindow_globals_private.m_nMoveSpeed = MIN_CAM_SPEED;
1932 /// \brief Initialisation for things that have the same lifespan as this module.
1933 void CamWnd_Construct(){
1934 GlobalCommands_insert( "CenterView", makeCallbackF(GlobalCamera_ResetAngles), Accelerator( GDK_KEY_End ) );
1936 GlobalToggles_insert( "ToggleCubicClip", makeCallbackF(Camera_ToggleFarClip), ToggleItem::AddCallbackCaller( g_getfarclip_item ), Accelerator( '\\', (GdkModifierType)GDK_CONTROL_MASK ) );
1937 GlobalCommands_insert( "CubicClipZoomIn", makeCallbackF(Camera_CubeIn), Accelerator( '[', (GdkModifierType)GDK_CONTROL_MASK ) );
1938 GlobalCommands_insert( "CubicClipZoomOut", makeCallbackF(Camera_CubeOut), Accelerator( ']', (GdkModifierType)GDK_CONTROL_MASK ) );
1940 GlobalCommands_insert( "UpFloor", makeCallbackF(Camera_ChangeFloorUp), Accelerator( GDK_KEY_Prior ) );
1941 GlobalCommands_insert( "DownFloor", makeCallbackF(Camera_ChangeFloorDown), Accelerator( GDK_KEY_Next ) );
1943 GlobalToggles_insert( "ToggleCamera", ToggleShown::ToggleCaller( g_camera_shown ), ToggleItem::AddCallbackCaller( g_camera_shown.m_item ), Accelerator( 'C', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
1944 GlobalCommands_insert( "LookThroughSelected", makeCallbackF(GlobalCamera_LookThroughSelected) );
1945 GlobalCommands_insert( "LookThroughCamera", makeCallbackF(GlobalCamera_LookThroughCamera) );
1947 if ( g_pGameDescription->mGameType == "doom3" ) {
1948 GlobalCommands_insert( "TogglePreview", makeCallbackF(CamWnd_TogglePreview), Accelerator( GDK_KEY_F3 ) );
1951 GlobalCommands_insert( "FOVInc", makeCallbackF(FOV_increase), Accelerator( GDK_KEY_KP_Multiply, (GdkModifierType)GDK_SHIFT_MASK ) );
1952 GlobalCommands_insert( "FOVDec", makeCallbackF(FOV_decrease), Accelerator( GDK_KEY_KP_Divide, (GdkModifierType)GDK_SHIFT_MASK ) );
1954 GlobalCommands_insert( "CameraSpeedInc", makeCallbackF(CameraSpeed_increase), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)GDK_SHIFT_MASK ) );
1955 GlobalCommands_insert( "CameraSpeedDec", makeCallbackF(CameraSpeed_decrease), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)GDK_SHIFT_MASK ) );
1957 GlobalShortcuts_insert( "CameraForward", Accelerator( GDK_KEY_Up ) );
1958 GlobalShortcuts_insert( "CameraBack", Accelerator( GDK_KEY_Down ) );
1959 GlobalShortcuts_insert( "CameraLeft", Accelerator( GDK_KEY_Left ) );
1960 GlobalShortcuts_insert( "CameraRight", Accelerator( GDK_KEY_Right ) );
1961 GlobalShortcuts_insert( "CameraStrafeRight", Accelerator( GDK_KEY_period ) );
1962 GlobalShortcuts_insert( "CameraStrafeLeft", Accelerator( GDK_KEY_comma ) );
1964 GlobalShortcuts_insert( "CameraUp", accelerator_null() );
1965 GlobalShortcuts_insert( "CameraDown", accelerator_null() );
1966 GlobalShortcuts_insert( "CameraAngleUp", accelerator_null() );
1967 GlobalShortcuts_insert( "CameraAngleDown", accelerator_null() );
1969 GlobalShortcuts_insert( "CameraFreeMoveForward", Accelerator( GDK_Up ) );
1970 GlobalShortcuts_insert( "CameraFreeMoveBack", Accelerator( GDK_Down ) );
1971 GlobalShortcuts_insert( "CameraFreeMoveLeft", Accelerator( GDK_Left ) );
1972 GlobalShortcuts_insert( "CameraFreeMoveRight", Accelerator( GDK_Right ) );
1974 GlobalShortcuts_insert( "CameraFreeMoveForward2", Accelerator( GDK_Up ) );
1975 GlobalShortcuts_insert( "CameraFreeMoveBack2", Accelerator( GDK_Down ) );
1976 GlobalShortcuts_insert( "CameraFreeMoveLeft2", Accelerator( GDK_Left ) );
1977 GlobalShortcuts_insert( "CameraFreeMoveRight2", Accelerator( GDK_Right ) );
1979 GlobalToggles_insert( "ShowStats", makeCallbackF(ShowStatsToggle), ToggleItem::AddCallbackCaller( g_show_stats ) );
1981 GlobalPreferenceSystem().registerPreference( "ShowStats", make_property_string( g_camwindow_globals_private.m_showStats ) );
1982 GlobalPreferenceSystem().registerPreference( "FOV", make_property_string( g_camwindow_globals_private.m_nFOV ) );
1983 GlobalPreferenceSystem().registerPreference( "MoveSpeed", make_property_string( g_camwindow_globals_private.m_nMoveSpeed ) );
1984 GlobalPreferenceSystem().registerPreference( "CamLinkSpeed", make_property_string( g_camwindow_globals_private.m_bCamLinkSpeed ) );
1985 GlobalPreferenceSystem().registerPreference( "AngleSpeed", make_property_string( g_camwindow_globals_private.m_nAngleSpeed ) );
1986 GlobalPreferenceSystem().registerPreference( "CamInverseMouse", make_property_string( g_camwindow_globals_private.m_bCamInverseMouse ) );
1987 GlobalPreferenceSystem().registerPreference( "CamDiscrete", make_property_string<CamWnd_Move_Discrete>());
1988 GlobalPreferenceSystem().registerPreference( "CubicClipping", make_property_string( g_camwindow_globals_private.m_bCubicClipping ) );
1989 GlobalPreferenceSystem().registerPreference( "CubicScale", make_property_string( g_camwindow_globals.m_nCubicScale ) );
1990 GlobalPreferenceSystem().registerPreference( "SI_Colors4", make_property_string( g_camwindow_globals.color_cameraback ) );
1991 GlobalPreferenceSystem().registerPreference( "SI_Colors12", make_property_string( g_camwindow_globals.color_selbrushes3d ) );
1992 GlobalPreferenceSystem().registerPreference( "CameraRenderMode", make_property_string<RenderMode>() );
1993 GlobalPreferenceSystem().registerPreference( "StrafeMode", make_property_string( g_camwindow_globals_private.m_nStrafeMode ) );
1995 CamWnd_constructStatic();
1997 Camera_registerPreferencesPage();
1999 void CamWnd_Destroy(){
2000 CamWnd_destroyStatic();