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 && modifiers_for_state( event->state ) == c_modifierNone ) {
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 && modifiers_for_state( event->state ) == c_modifierNone ) {
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;
1251 else if( !path.top().get().visible() ){
1258 void CamWnd::Cam_ChangeFloor( bool up ){
1259 float current = m_Camera.origin[2] - 48;
1262 GlobalSceneGraph().traverse( FloorHeightWalker( current, bestUp, bestDown ) );
1264 if ( up && bestUp != g_MaxWorldCoord ) {
1267 if ( !up && bestDown != -g_MaxWorldCoord ) {
1271 m_Camera.origin[2] = current + 48;
1272 Camera_updateModelview( getCamera() );
1273 CamWnd_Update( *this );
1274 CameraMovedNotify();
1281 Sys_GetCursorPos( &m_PositionDragCursorX, &m_PositionDragCursorY );
1284 if ( ( m_bFreeMove && ( buttons == ( RAD_CONTROL | RAD_SHIFT ) ) )
1285 || ( !m_bFreeMove && ( buttons == ( RAD_RBUTTON | RAD_CONTROL ) ) ) ) {
1287 CamWnd_Update( camwnd );
1288 CameraMovedNotify();
1292 void CamWnd::Cam_PositionDrag(){
1295 Sys_GetCursorPos( m_gl_widget, &x, &y );
1296 if ( x != m_PositionDragCursorX || y != m_PositionDragCursorY ) {
1297 x -= m_PositionDragCursorX;
1298 vector3_add( m_Camera.origin, vector3_scaled( m_Camera.vright, x ) );
1299 y -= m_PositionDragCursorY;
1300 m_Camera.origin[2] -= y;
1301 Camera_updateModelview();
1302 CamWnd_Update( camwnd );
1303 CameraMovedNotify();
1305 Sys_SetCursorPos( m_gl_widget, m_PositionDragCursorX, m_PositionDragCursorY );
1311 // NOTE TTimo if there's an OS-level focus out of the application
1312 // then we can release the camera cursor grab
1313 static gboolean camwindow_freemove_focusout( ui::Widget widget, GdkEventFocus* event, gpointer data ){
1314 reinterpret_cast<CamWnd*>( data )->DisableFreeMove();
1318 void CamWnd::EnableFreeMove(){
1319 //globalOutputStream() << "EnableFreeMove\n";
1321 ASSERT_MESSAGE( !m_bFreeMove, "EnableFreeMove: free-move was already enabled" );
1323 Camera_clearMovementFlags( getCamera(), MOVE_ALL );
1325 CamWnd_Remove_Handlers_Move( *this );
1326 CamWnd_Add_Handlers_FreeMove( *this );
1328 gtk_window_set_focus( m_parent, m_gl_widget );
1329 m_freemove_handle_focusout = m_gl_widget.connect( "focus_out_event", G_CALLBACK( camwindow_freemove_focusout ), this );
1330 /* We chose to replace m_parent by m_gl_widget but NetRadiantCustom does:
1331 m_freezePointer.freeze_pointer( m_parent, m_gl_widget, Camera_motionDelta, &m_Camera ); */
1332 m_freezePointer.freeze_pointer( m_gl_widget, Camera_motionDelta, &m_Camera );
1334 CamWnd_Update( *this );
1337 void CamWnd::DisableFreeMove(){
1338 //globalOutputStream() << "DisableFreeMove\n";
1340 ASSERT_MESSAGE( m_bFreeMove, "DisableFreeMove: free-move was not enabled" );
1341 m_bFreeMove = false;
1342 Camera_clearMovementFlags( getCamera(), MOVE_ALL );
1344 CamWnd_Remove_Handlers_FreeMove( *this );
1345 CamWnd_Add_Handlers_Move( *this );
1347 m_freezePointer.unfreeze_pointer( m_gl_widget, true );
1349 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_freemove_handle_focusout );
1351 CamWnd_Update( *this );
1355 #include "renderer.h"
1357 class CamRenderer : public Renderer
1361 state_type() : m_highlight( 0 ), m_state( 0 ), m_lights( 0 ){
1363 unsigned int m_highlight;
1365 const LightList* m_lights;
1368 std::vector<state_type> m_state_stack;
1369 RenderStateFlags m_globalstate;
1370 Shader* m_state_select0;
1371 Shader* m_state_select1;
1372 const Vector3& m_viewer;
1375 CamRenderer( RenderStateFlags globalstate, Shader* select0, Shader* select1, const Vector3& viewer ) :
1376 m_globalstate( globalstate ),
1377 m_state_select0( select0 ),
1378 m_state_select1( select1 ),
1380 ASSERT_NOTNULL( select0 );
1381 ASSERT_NOTNULL( select1 );
1382 m_state_stack.push_back( state_type() );
1385 void SetState( Shader* state, EStyle style ){
1386 ASSERT_NOTNULL( state );
1387 if ( style == eFullMaterials ) {
1388 m_state_stack.back().m_state = state;
1391 EStyle getStyle() const {
1392 return eFullMaterials;
1395 m_state_stack.push_back( m_state_stack.back() );
1398 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
1399 m_state_stack.pop_back();
1401 void Highlight( EHighlightMode mode, bool bEnable = true ){
1403 m_state_stack.back().m_highlight |= mode;
1405 m_state_stack.back().m_highlight &= ~mode;
1408 void setLights( const LightList& lights ){
1409 m_state_stack.back().m_lights = &lights;
1411 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& world ){
1412 if ( m_state_stack.back().m_highlight & ePrimitive ) {
1413 m_state_select0->addRenderable( renderable, world, m_state_stack.back().m_lights );
1415 if ( m_state_stack.back().m_highlight & eFace ) {
1416 m_state_select1->addRenderable( renderable, world, m_state_stack.back().m_lights );
1419 m_state_stack.back().m_state->addRenderable( renderable, world, m_state_stack.back().m_lights );
1422 void render( const Matrix4& modelview, const Matrix4& projection ){
1423 GlobalShaderCache().render( m_globalstate, modelview, projection, m_viewer );
1433 void ShowStatsToggle(){
1434 g_camwindow_globals_private.m_showStats ^= 1;
1437 void ShowStatsExport( const Callback<void(bool)> &importer ){
1438 importer( g_camwindow_globals_private.m_showStats );
1441 FreeCaller<void(const Callback<void(bool)>&), ShowStatsExport> g_show_stats_caller;
1442 Callback<void(const Callback<void(bool)> &)> g_show_stats_callback( g_show_stats_caller );
1443 ToggleItem g_show_stats( g_show_stats_callback );
1446 void ShowStatsToggle(){
1447 g_camwindow_globals_private.m_showStats ^= 1;
1448 // g_show_stats.update();
1451 typedef FreeCaller<void(), ShowStatsToggle> ShowStatsToggleCaller;
1452 void ShowStatsExport( const Callback<void(bool)> & importer ){
1453 importer( g_camwindow_globals_private.m_showStats );
1455 typedef FreeCaller<void(const Callback<void(bool)> &), ShowStatsExport> ShowStatsExportCaller;
1457 ShowStatsExportCaller g_show_stats_caller;
1458 Callback<void(const Callback<void(bool)> &)> g_show_stats_callback( g_show_stats_caller );
1459 ToggleItem g_show_stats( g_show_stats_callback );
1461 void CamWnd::Cam_Draw(){
1462 glViewport( 0, 0, m_Camera.width, m_Camera.height );
1465 glGetIntegerv( GL_VIEWPORT, viewprt );
1468 // enable depth buffer writes
1469 glDepthMask( GL_TRUE );
1470 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1472 Vector3 clearColour( 0, 0, 0 );
1473 if ( m_Camera.draw_mode != cd_lighting ) {
1474 clearColour = g_camwindow_globals.color_cameraback;
1477 glClearColor( clearColour[0], clearColour[1], clearColour[2], 0 );
1478 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1480 extern void Renderer_ResetStats();
1481 Renderer_ResetStats();
1482 extern void Cull_ResetStats();
1485 glMatrixMode( GL_PROJECTION );
1486 glLoadMatrixf( reinterpret_cast<const float*>( &m_Camera.projection ) );
1488 glMatrixMode( GL_MODELVIEW );
1489 glLoadMatrixf( reinterpret_cast<const float*>( &m_Camera.modelview ) );
1492 // one directional light source directly behind the viewer
1494 GLfloat inverse_cam_dir[4], ambient[4], diffuse[4]; //, material[4];
1496 ambient[0] = ambient[1] = ambient[2] = 0.4f;
1498 diffuse[0] = diffuse[1] = diffuse[2] = 0.4f;
1500 //material[0] = material[1] = material[2] = 0.8f;
1501 //material[3] = 1.0f;
1503 inverse_cam_dir[0] = m_Camera.vpn[0];
1504 inverse_cam_dir[1] = m_Camera.vpn[1];
1505 inverse_cam_dir[2] = m_Camera.vpn[2];
1506 inverse_cam_dir[3] = 0;
1508 glLightfv( GL_LIGHT0, GL_POSITION, inverse_cam_dir );
1510 glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
1511 glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
1513 glEnable( GL_LIGHT0 );
1517 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;
1518 switch ( m_Camera.draw_mode )
1523 globalstate |= RENDER_FILL
1529 globalstate |= RENDER_FILL
1536 globalstate |= RENDER_FILL
1550 // if ( !g_xywindow_globals.m_bNoStipple ) {
1551 globalstate |= RENDER_LINESTIPPLE | RENDER_POLYGONSTIPPLE;
1555 CamRenderer renderer( globalstate, m_state_select2, m_state_select1, m_view.getViewer() );
1557 Scene_Render( renderer, m_view );
1559 renderer.render( m_Camera.modelview, m_Camera.projection );
1562 // prepare for 2d stuff
1563 glColor4f( 1, 1, 1, 1 );
1564 glDisable( GL_BLEND );
1565 glMatrixMode( GL_PROJECTION );
1567 glOrtho( 0, (float)m_Camera.width, 0, (float)m_Camera.height, -100, 100 );
1568 glScalef( 1, -1, 1 );
1569 glTranslatef( 0, -(float)m_Camera.height, 0 );
1570 glMatrixMode( GL_MODELVIEW );
1573 if ( GlobalOpenGL().GL_1_3() ) {
1574 glClientActiveTexture( GL_TEXTURE0 );
1575 glActiveTexture( GL_TEXTURE0 );
1578 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1579 glDisableClientState( GL_NORMAL_ARRAY );
1580 glDisableClientState( GL_COLOR_ARRAY );
1582 glDisable( GL_TEXTURE_2D );
1583 glDisable( GL_LIGHTING );
1584 glDisable( GL_COLOR_MATERIAL );
1585 glDisable( GL_DEPTH_TEST );
1586 glColor3f( 1.f, 1.f, 1.f );
1589 // draw the crosshair
1590 if ( m_bFreeMove ) {
1591 glBegin( GL_LINES );
1592 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f + 6 );
1593 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f + 2 );
1594 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f - 6 );
1595 glVertex2f( (float)m_Camera.width / 2.f, (float)m_Camera.height / 2.f - 2 );
1596 glVertex2f( (float)m_Camera.width / 2.f + 6, (float)m_Camera.height / 2.f );
1597 glVertex2f( (float)m_Camera.width / 2.f + 2, (float)m_Camera.height / 2.f );
1598 glVertex2f( (float)m_Camera.width / 2.f - 6, (float)m_Camera.height / 2.f );
1599 glVertex2f( (float)m_Camera.width / 2.f - 2, (float)m_Camera.height / 2.f );
1603 if ( g_camwindow_globals_private.m_showStats ) {
1604 glRasterPos3f( 1.0f, static_cast<float>( m_Camera.height ) - GlobalOpenGL().m_font->getPixelDescent(), 0.0f );
1605 extern const char* Renderer_GetStats();
1606 GlobalOpenGL().drawString( Renderer_GetStats() );
1608 glRasterPos3f( 1.0f, static_cast<float>( m_Camera.height ) - GlobalOpenGL().m_font->getPixelDescent() - GlobalOpenGL().m_font->getPixelHeight(), 0.0f );
1609 extern const char* Cull_GetStats();
1610 GlobalOpenGL().drawString( Cull_GetStats() );
1613 // bind back to the default texture so that we don't have problems
1614 // elsewhere using/modifying texture maps between contexts
1615 glBindTexture( GL_TEXTURE_2D, 0 );
1618 void CamWnd::draw(){
1621 //globalOutputStream() << "draw...\n";
1622 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
1623 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
1624 GlobalOpenGL_debugAssertNoErrors();
1626 GlobalOpenGL_debugAssertNoErrors();
1629 m_XORRectangle.set( rectangle_t() );
1632 glwidget_swap_buffers( m_gl_widget );
1638 void CamWnd::BenchMark(){
1639 double dStart = Sys_DoubleTime();
1640 for ( int i = 0 ; i < 100 ; i++ )
1643 angles[CAMERA_ROLL] = 0;
1644 angles[CAMERA_PITCH] = 0;
1645 angles[CAMERA_YAW] = i * 360.0f / 100.0f;
1646 Camera_setAngles( *this, angles );
1648 double dEnd = Sys_DoubleTime();
1649 globalOutputStream() << FloatFormat( dEnd - dStart, 5, 2 ) << " seconds\n";
1653 void GlobalCamera_ResetAngles(){
1654 CamWnd& camwnd = *g_camwnd;
1656 angles[CAMERA_ROLL] = angles[CAMERA_PITCH] = 0;
1657 angles[CAMERA_YAW] = 22.5f * floorf( ( Camera_getAngles( camwnd )[CAMERA_YAW] + 11 ) / 22.5f );
1658 Camera_setAngles( camwnd, angles );
1663 void GlobalCamera_FocusOnSelected(){
1664 CamWnd& camwnd = *g_camwnd;
1666 Vector3 angles( Camera_getAngles( camwnd ) );
1667 Vector3 radangles( degrees_to_radians( angles[0] ), degrees_to_radians( angles[1] ), degrees_to_radians( angles[2] ) );
1669 viewvector[0] = cos( radangles[1] ) * cos( radangles[0] );
1670 viewvector[1] = sin( radangles[1] ) * cos( radangles[0] );
1671 viewvector[2] = sin( radangles[0] );
1673 Vector3 camorigin( Camera_getOrigin( camwnd ) );
1675 AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) );
1677 View& view = *( camwnd.getCamera().m_view );
1679 Plane3 frustumPlanes[4];
1680 frustumPlanes[0] = plane3_translated( view.getFrustum().left, camorigin - aabb.origin );
1681 frustumPlanes[1] = plane3_translated( view.getFrustum().right, camorigin - aabb.origin );
1682 frustumPlanes[2] = plane3_translated( view.getFrustum().top, camorigin - aabb.origin );
1683 frustumPlanes[3] = plane3_translated( view.getFrustum().bottom, camorigin - aabb.origin );
1685 float offset = 64.0f;
1688 aabb_corners( aabb, corners );
1690 for ( size_t i = 0; i < 4; ++i ){
1691 for ( size_t j = 0; j < 8; ++j ){
1692 Ray ray( aabb.origin, -viewvector );
1693 //Plane3 newplane( frustumPlanes[i].normal(), vector3_dot( frustumPlanes[i].normal(), corners[j] - frustumPlanes[i].normal() * 16.0f ) );
1694 Plane3 newplane( frustumPlanes[i].normal(), vector3_dot( frustumPlanes[i].normal(), corners[j] ) );
1695 float d = vector3_dot( ray.direction, newplane.normal() );
1697 float s = vector3_dot( newplane.normal() * newplane.dist() - ray.origin, newplane.normal() ) / d;
1698 offset = std::max( offset, s );
1702 Camera_setOrigin( camwnd, aabb.origin - viewvector * offset );
1705 void Camera_ChangeFloorUp(){
1706 CamWnd& camwnd = *g_camwnd;
1707 camwnd.Cam_ChangeFloor( true );
1710 void Camera_ChangeFloorDown(){
1711 CamWnd& camwnd = *g_camwnd;
1712 camwnd.Cam_ChangeFloor( false );
1715 void Camera_CubeIn(){
1716 CamWnd& camwnd = *g_camwnd;
1717 g_camwindow_globals.m_nCubicScale--;
1718 if ( g_camwindow_globals.m_nCubicScale < 1 ) {
1719 g_camwindow_globals.m_nCubicScale = 1;
1721 Camera_updateProjection( camwnd.getCamera() );
1722 CamWnd_Update( camwnd );
1723 g_pParentWnd->SetGridStatus();
1726 void Camera_CubeOut(){
1727 CamWnd& camwnd = *g_camwnd;
1728 g_camwindow_globals.m_nCubicScale++;
1729 if ( g_camwindow_globals.m_nCubicScale > 46 ) {
1730 g_camwindow_globals.m_nCubicScale = 46;
1732 Camera_updateProjection( camwnd.getCamera() );
1733 CamWnd_Update( camwnd );
1734 g_pParentWnd->SetGridStatus();
1737 bool Camera_GetFarClip(){
1738 return g_camwindow_globals_private.m_bCubicClipping;
1741 ConstReferenceCaller<bool, void(const Callback<void(bool)> &), PropertyImpl<bool>::Export> g_getfarclip_caller( g_camwindow_globals_private.m_bCubicClipping );
1742 ToggleItem g_getfarclip_item( g_getfarclip_caller );
1744 void Camera_SetFarClip( bool value ){
1745 CamWnd& camwnd = *g_camwnd;
1746 g_camwindow_globals_private.m_bCubicClipping = value;
1747 g_getfarclip_item.update();
1748 Camera_updateProjection( camwnd.getCamera() );
1749 CamWnd_Update( camwnd );
1752 struct Camera_FarClip {
1753 static void Export(const Callback<void(bool)> &returnz) {
1754 returnz(g_camwindow_globals_private.m_bCubicClipping);
1757 static void Import(bool value) {
1758 Camera_SetFarClip(value);
1762 void Camera_ToggleFarClip(){
1763 Camera_SetFarClip( !Camera_GetFarClip() );
1767 void CamWnd_constructToolbar( ui::Toolbar toolbar ){
1768 toolbar_append_toggle_button( toolbar, "Cubic clip the camera view (Ctrl + \\)", "view_cubicclipping.png", "ToggleCubicClip" );
1771 void CamWnd_registerShortcuts(){
1772 toggle_add_accelerator( "ToggleCubicClip" );
1774 if ( g_pGameDescription->mGameType == "doom3" ) {
1775 command_connect_accelerator( "TogglePreview" );
1778 command_connect_accelerator( "FOVInc" );
1779 command_connect_accelerator( "FOVDec" );
1780 command_connect_accelerator( "CameraSpeedInc" );
1781 command_connect_accelerator( "CameraSpeedDec" );
1785 void GlobalCamera_Benchmark(){
1786 CamWnd& camwnd = *g_camwnd;
1790 void GlobalCamera_Update(){
1791 CamWnd& camwnd = *g_camwnd;
1792 CamWnd_Update( camwnd );
1795 camera_draw_mode CamWnd_GetMode(){
1796 return camera_t::draw_mode;
1798 void CamWnd_SetMode( camera_draw_mode mode ){
1799 ShaderCache_setBumpEnabled( mode == cd_lighting );
1800 camera_t::draw_mode = mode;
1801 if ( g_camwnd != 0 ) {
1802 CamWnd_Update( *g_camwnd );
1806 void CamWnd_TogglePreview( void ){
1807 // gametype must be doom3 for this function to work
1808 // if the gametype is not doom3 something is wrong with the
1809 // global command list or somebody else calls this function.
1810 ASSERT_MESSAGE( g_pGameDescription->mGameType == "doom3", "CamWnd_TogglePreview called although mGameType is not doom3 compatible" );
1812 // switch between textured and lighting mode
1813 CamWnd_SetMode( ( CamWnd_GetMode() == cd_lighting ) ? cd_texture : cd_lighting );
1817 CameraModel* g_camera_model = 0;
1819 void CamWnd_LookThroughCamera( CamWnd& camwnd ){
1820 if ( g_camera_model != 0 ) {
1821 CamWnd_Add_Handlers_Move( camwnd );
1822 g_camera_model->setCameraView( 0, Callback<void()>() );
1824 Camera_updateModelview( camwnd.getCamera() );
1825 Camera_updateProjection( camwnd.getCamera() );
1826 CamWnd_Update( camwnd );
1830 inline CameraModel* Instance_getCameraModel( scene::Instance& instance ){
1831 return InstanceTypeCast<CameraModel>::cast( instance );
1834 void CamWnd_LookThroughSelected( CamWnd& camwnd ){
1835 if ( g_camera_model != 0 ) {
1836 CamWnd_LookThroughCamera( camwnd );
1839 if ( GlobalSelectionSystem().countSelected() != 0 ) {
1840 scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
1841 CameraModel* cameraModel = Instance_getCameraModel( instance );
1842 if ( cameraModel != 0 ) {
1843 CamWnd_Remove_Handlers_Move( camwnd );
1844 g_camera_model = cameraModel;
1845 g_camera_model->setCameraView( &camwnd.getCameraView(), ReferenceCaller<CamWnd, void(), CamWnd_LookThroughCamera>( camwnd ) );
1850 void GlobalCamera_LookThroughSelected(){
1851 CamWnd_LookThroughSelected( *g_camwnd );
1854 void GlobalCamera_LookThroughCamera(){
1855 CamWnd_LookThroughCamera( *g_camwnd );
1859 static void Export(const Callback<void(int)> &returnz) {
1860 switch (CamWnd_GetMode()) {
1876 static void Import(int value) {
1879 CamWnd_SetMode( cd_wire );
1882 CamWnd_SetMode( cd_solid );
1885 CamWnd_SetMode( cd_texture );
1888 CamWnd_SetMode( cd_lighting );
1891 CamWnd_SetMode( cd_texture );
1896 void Camera_constructPreferences( PreferencesPage& page ){
1897 page.appendSlider( "FOV", g_camwindow_globals_private.m_nFOV, TRUE, 0, 0, 100, MIN_FOV, MAX_FOV, 1, 10 );
1898 page.appendSlider( "Movement Speed", g_camwindow_globals_private.m_nMoveSpeed, TRUE, 0, 0, 100, MIN_CAM_SPEED, MAX_CAM_SPEED, 1, 10 );
1899 page.appendCheckBox( "", "Link strafe speed to movement speed", g_camwindow_globals_private.m_bCamLinkSpeed );
1900 page.appendSlider( "Rotation Speed", g_camwindow_globals_private.m_nAngleSpeed, TRUE, 0, 0, 3, 1, 180, 1, 10 );
1901 page.appendCheckBox( "", "Invert mouse vertical axis", g_camwindow_globals_private.m_bCamInverseMouse );
1902 page.appendCheckBox(
1903 "", "Discrete movement",
1904 make_property<CamWnd_Move_Discrete>()
1906 page.appendCheckBox(
1907 "", "Enable far-clip plane",
1908 make_property<Camera_FarClip>()
1911 if ( g_pGameDescription->mGameType == "doom3" ) {
1912 const char* render_mode[] = { "Wireframe", "Flatshade", "Textured", "Lighting" };
1916 STRING_ARRAY_RANGE( render_mode ),
1917 make_property<RenderMode>()
1922 const char* render_mode[] = { "Wireframe", "Flatshade", "Textured" };
1926 STRING_ARRAY_RANGE( render_mode ),
1927 make_property<RenderMode>()
1931 const char* strafe_mode[] = { "Both", "Forward", "Up" };
1935 g_camwindow_globals_private.m_nStrafeMode,
1936 STRING_ARRAY_RANGE( strafe_mode )
1939 void Camera_constructPage( PreferenceGroup& group ){
1940 PreferencesPage page( group.createPage( "Camera", "Camera View Preferences" ) );
1941 Camera_constructPreferences( page );
1943 void Camera_registerPreferencesPage(){
1944 PreferencesDialog_addSettingsPage( makeCallbackF(Camera_constructPage) );
1947 #include "preferencesystem.h"
1948 #include "stringio.h"
1951 void FOV_increase(){
1952 CamWnd& camwnd = *g_camwnd;
1953 if ( g_camwindow_globals_private.m_nFOV <= ( MAX_FOV - FOV_STEP - 10 ) ) {
1954 g_camwindow_globals_private.m_nFOV += FOV_STEP;
1957 g_camwindow_globals_private.m_nFOV = MAX_FOV - 10;
1959 Camera_updateProjection( camwnd.getCamera() );
1960 CamWnd_Update( camwnd );
1963 void FOV_decrease(){
1964 CamWnd& camwnd = *g_camwnd;
1965 if ( g_camwindow_globals_private.m_nFOV >= ( MIN_FOV + FOV_STEP ) ) {
1966 g_camwindow_globals_private.m_nFOV -= FOV_STEP;
1969 g_camwindow_globals_private.m_nFOV = MIN_FOV;
1971 Camera_updateProjection( camwnd.getCamera() );
1972 CamWnd_Update( camwnd );
1976 void CameraSpeed_increase(){
1977 if ( g_camwindow_globals_private.m_nMoveSpeed <= ( MAX_CAM_SPEED - CAM_SPEED_STEP - 10 ) ) {
1978 g_camwindow_globals_private.m_nMoveSpeed += CAM_SPEED_STEP;
1981 g_camwindow_globals_private.m_nMoveSpeed = MAX_CAM_SPEED - 10;
1985 void CameraSpeed_decrease(){
1986 if ( g_camwindow_globals_private.m_nMoveSpeed >= ( MIN_CAM_SPEED + CAM_SPEED_STEP ) ) {
1987 g_camwindow_globals_private.m_nMoveSpeed -= CAM_SPEED_STEP;
1990 g_camwindow_globals_private.m_nMoveSpeed = MIN_CAM_SPEED;
1994 /// \brief Initialisation for things that have the same lifespan as this module.
1995 void CamWnd_Construct(){
1996 GlobalCommands_insert( "CenterView", makeCallbackF(GlobalCamera_ResetAngles), Accelerator( GDK_KEY_End ) );
1997 GlobalCommands_insert( "CameraFocusOnSelected", makeCallbackF( GlobalCamera_FocusOnSelected ), Accelerator( GDK_Tab ) );
1999 GlobalToggles_insert( "ToggleCubicClip", makeCallbackF(Camera_ToggleFarClip), ToggleItem::AddCallbackCaller( g_getfarclip_item ), Accelerator( '\\', (GdkModifierType)GDK_CONTROL_MASK ) );
2000 GlobalCommands_insert( "CubicClipZoomIn", makeCallbackF(Camera_CubeIn), Accelerator( '[', (GdkModifierType)GDK_CONTROL_MASK ) );
2001 GlobalCommands_insert( "CubicClipZoomOut", makeCallbackF(Camera_CubeOut), Accelerator( ']', (GdkModifierType)GDK_CONTROL_MASK ) );
2003 GlobalCommands_insert( "UpFloor", makeCallbackF(Camera_ChangeFloorUp), Accelerator( GDK_KEY_Prior ) );
2004 GlobalCommands_insert( "DownFloor", makeCallbackF(Camera_ChangeFloorDown), Accelerator( GDK_KEY_Next ) );
2006 GlobalToggles_insert( "ToggleCamera", ToggleShown::ToggleCaller( g_camera_shown ), ToggleItem::AddCallbackCaller( g_camera_shown.m_item ), Accelerator( 'C', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
2007 // GlobalCommands_insert( "LookThroughSelected", makeCallbackF(GlobalCamera_LookThroughSelected) );
2008 // GlobalCommands_insert( "LookThroughCamera", makeCallbackF(GlobalCamera_LookThroughCamera) );
2010 if ( g_pGameDescription->mGameType == "doom3" ) {
2011 GlobalCommands_insert( "TogglePreview", makeCallbackF(CamWnd_TogglePreview), Accelerator( GDK_KEY_F3 ) );
2014 GlobalCommands_insert( "FOVInc", makeCallbackF(FOV_increase), Accelerator( GDK_KEY_KP_Multiply, (GdkModifierType)GDK_SHIFT_MASK ) );
2015 GlobalCommands_insert( "FOVDec", makeCallbackF(FOV_decrease), Accelerator( GDK_KEY_KP_Divide, (GdkModifierType)GDK_SHIFT_MASK ) );
2017 GlobalCommands_insert( "CameraSpeedInc", makeCallbackF(CameraSpeed_increase), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)GDK_SHIFT_MASK ) );
2018 GlobalCommands_insert( "CameraSpeedDec", makeCallbackF(CameraSpeed_decrease), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)GDK_SHIFT_MASK ) );
2020 GlobalShortcuts_insert( "CameraForward", Accelerator( GDK_KEY_Up ) );
2021 GlobalShortcuts_insert( "CameraBack", Accelerator( GDK_KEY_Down ) );
2022 GlobalShortcuts_insert( "CameraLeft", Accelerator( GDK_KEY_Left ) );
2023 GlobalShortcuts_insert( "CameraRight", Accelerator( GDK_KEY_Right ) );
2024 GlobalShortcuts_insert( "CameraStrafeRight", Accelerator( GDK_KEY_period ) );
2025 GlobalShortcuts_insert( "CameraStrafeLeft", Accelerator( GDK_KEY_comma ) );
2027 GlobalShortcuts_insert( "CameraUp", accelerator_null() );
2028 GlobalShortcuts_insert( "CameraDown", accelerator_null() );
2029 GlobalShortcuts_insert( "CameraAngleUp", accelerator_null() );
2030 GlobalShortcuts_insert( "CameraAngleDown", accelerator_null() );
2032 GlobalShortcuts_insert( "CameraFreeMoveForward", Accelerator( GDK_Up ) );
2033 GlobalShortcuts_insert( "CameraFreeMoveBack", Accelerator( GDK_Down ) );
2034 GlobalShortcuts_insert( "CameraFreeMoveLeft", Accelerator( GDK_Left ) );
2035 GlobalShortcuts_insert( "CameraFreeMoveRight", Accelerator( GDK_Right ) );
2037 GlobalShortcuts_insert( "CameraFreeMoveForward2", Accelerator( GDK_Up ) );
2038 GlobalShortcuts_insert( "CameraFreeMoveBack2", Accelerator( GDK_Down ) );
2039 GlobalShortcuts_insert( "CameraFreeMoveLeft2", Accelerator( GDK_Left ) );
2040 GlobalShortcuts_insert( "CameraFreeMoveRight2", Accelerator( GDK_Right ) );
2042 GlobalToggles_insert( "ShowStats", makeCallbackF(ShowStatsToggle), ToggleItem::AddCallbackCaller( g_show_stats ) );
2044 GlobalPreferenceSystem().registerPreference( "ShowStats", make_property_string( g_camwindow_globals_private.m_showStats ) );
2045 GlobalPreferenceSystem().registerPreference( "FOV", make_property_string( g_camwindow_globals_private.m_nFOV ) );
2046 GlobalPreferenceSystem().registerPreference( "MoveSpeed", make_property_string( g_camwindow_globals_private.m_nMoveSpeed ) );
2047 GlobalPreferenceSystem().registerPreference( "CamLinkSpeed", make_property_string( g_camwindow_globals_private.m_bCamLinkSpeed ) );
2048 GlobalPreferenceSystem().registerPreference( "AngleSpeed", make_property_string( g_camwindow_globals_private.m_nAngleSpeed ) );
2049 GlobalPreferenceSystem().registerPreference( "CamInverseMouse", make_property_string( g_camwindow_globals_private.m_bCamInverseMouse ) );
2050 GlobalPreferenceSystem().registerPreference( "CamDiscrete", make_property_string<CamWnd_Move_Discrete>());
2051 GlobalPreferenceSystem().registerPreference( "CubicClipping", make_property_string( g_camwindow_globals_private.m_bCubicClipping ) );
2052 GlobalPreferenceSystem().registerPreference( "CubicScale", make_property_string( g_camwindow_globals.m_nCubicScale ) );
2053 GlobalPreferenceSystem().registerPreference( "SI_Colors4", make_property_string( g_camwindow_globals.color_cameraback ) );
2054 GlobalPreferenceSystem().registerPreference( "SI_Colors12", make_property_string( g_camwindow_globals.color_selbrushes3d ) );
2055 GlobalPreferenceSystem().registerPreference( "CameraRenderMode", make_property_string<RenderMode>() );
2056 GlobalPreferenceSystem().registerPreference( "StrafeMode", make_property_string( g_camwindow_globals_private.m_nStrafeMode ) );
2058 CamWnd_constructStatic();
2060 Camera_registerPreferencesPage();
2062 void CamWnd_Destroy(){
2063 CamWnd_destroyStatic();