tweak VIEWTYPE related code

This commit is contained in:
Garux 2019-08-23 14:40:45 +03:00
parent 15cf9d0b55
commit 1e0f7ba781
7 changed files with 48 additions and 121 deletions

View File

@ -38,17 +38,7 @@
#include "funchandlers.h"
SignalHandlerResult DTreePlanter::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
if ( button != c_buttonLeft ) {
return SIGNAL_CONTINUE_EMISSION;
}
VIEWTYPE vt = GlobalRadiant().XYWindow_getViewType();
switch ( vt ) {
case XY:
break;
case YZ:
case XZ:
default:
if ( button != c_buttonLeft || GlobalRadiant().XYWindow_getViewType() != XY ) {
return SIGNAL_CONTINUE_EMISSION;
}

View File

@ -111,6 +111,9 @@ enum VIEWTYPE
XY = 2
};
#define NDIM1NDIM2( viewtype ) const int nDim1 = ( viewtype == YZ ) ? 1 : 0, \
nDim2 = ( viewtype == XY ) ? 1 : 2;
// the radiant core API
struct _QERFuncTable_1
{

View File

@ -395,19 +395,6 @@ void Brush_ConstructIcosahedron( Brush& brush, const AABB& bounds, std::size_t s
} //namespace icosahedron
int GetViewAxis(){
switch ( GlobalXYWnd_getCurrentViewType() )
{
case XY:
return 2;
case XZ:
return 1;
case YZ:
return 0;
}
return 2;
}
void Brush_ConstructPrefab( Brush& brush, EBrushPrefab type, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection ){
switch ( type )
{
@ -420,7 +407,7 @@ void Brush_ConstructPrefab( Brush& brush, EBrushPrefab type, const AABB& bounds,
break;
case eBrushPrism:
{
int axis = GetViewAxis();
const int axis = GlobalXYWnd_getCurrentViewType();
StringOutputStream command;
command << c_brushPrism_name << " -sides " << Unsigned( sides ) << " -axis " << axis;
UndoableCommand undo( command.c_str() );
@ -1483,7 +1470,7 @@ BrushPrefab( EBrushPrefab type )
: m_type( type ){
}
void set(){
DoSides( m_type, GetViewAxis() );
DoSides( m_type, GlobalXYWnd_getCurrentViewType() );
}
typedef MemberCaller<BrushPrefab, &BrushPrefab::set> SetCaller;
};

View File

@ -1352,15 +1352,7 @@ CSGToolDialog g_csgtool_dialog;
#if 0
DoubleVector3 getExclusion(){
if( gtk_toggle_button_get_active( g_csgtool_dialog.radProj ) ){
if( GlobalXYWnd_getCurrentViewType() == YZ ){
return DoubleVector3( 1, 0, 0 );
}
else if( GlobalXYWnd_getCurrentViewType() == XZ ){
return DoubleVector3( 0, 1, 0 );
}
else if( GlobalXYWnd_getCurrentViewType() == XY ){
return DoubleVector3( 0, 0, 1 );
}
return DoubleVector3( g_vector3_axes[GlobalXYWnd_getCurrentViewType()] );
}
if( gtk_toggle_button_get_active( g_csgtool_dialog.radCam ) ){
Vector3 angles( Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
@ -1424,7 +1416,7 @@ void CSGdlg_getSettings( HollowSettings& settings, const CSGToolDialog& dialog )
settings.m_offset = static_cast<float>( gtk_spin_button_get_value( dialog.spin ) );
settings.m_exclusionAxis = g_vector3_identity;
if( gtk_toggle_button_get_active( dialog.radProj ) ){
settings.m_exclusionAxis[ static_cast<int>( GlobalXYWnd_getCurrentViewType() ) ] = 1;
settings.m_exclusionAxis = g_vector3_axes[GlobalXYWnd_getCurrentViewType()];
}
else if( gtk_toggle_button_get_active( dialog.radCam ) ){
settings.m_exclusionAxis = Camera_getViewVector( *g_pParentWnd->GetCamWnd() );

View File

@ -132,8 +132,7 @@ void CPointMsg::DropHighlight(){
}
void CPointMsg::Draw2D( VIEWTYPE vt ){
int nDim1 = ( vt == YZ ) ? 1 : 0;
int nDim2 = ( vt == XY ) ? 1 : 2;
NDIM1NDIM2( vt )
glPointSize( 4 );
glColor3f( 1.0f,0.0f,0.0f );
glBegin( GL_POINTS );
@ -205,8 +204,7 @@ void CWindingMsg::DropHighlight(){
void CWindingMsg::Draw2D( VIEWTYPE vt ){
int i;
int nDim1 = ( vt == YZ ) ? 1 : 0;
int nDim2 = ( vt == XY ) ? 1 : 2;
NDIM1NDIM2( vt )
glColor3f( 1.0f,0.f,0.0f );
glPointSize( 4 );

View File

@ -2065,10 +2065,8 @@ void RegionOff(){
}
void RegionXY(){
const VIEWTYPE viewtype = GlobalXYWnd_getCurrentViewType();
const int nDim1 = ( viewtype == YZ ) ? 1 : 0;
const int nDim2 = ( viewtype == XY ) ? 1 : 2;
const int nDim = static_cast<int>( viewtype );
const int nDim = GlobalXYWnd_getCurrentViewType();
NDIM1NDIM2( nDim );
const XYWnd& wnd = *( g_pParentWnd->ActiveXY() );
Vector3 min, max;
min[nDim1] = wnd.GetOrigin()[nDim1] - 0.5f * wnd.Width() / wnd.Scale();

View File

@ -267,8 +267,7 @@ void XYWnd::ZoomInWithMouse( int pointx, int pointy ){
ZoomIn();
if ( g_xywindow_globals.m_bZoomInToPointer && old_scale != Scale() ) {
const float scale_diff = 1.0 / old_scale - 1.0 / Scale();
int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
int nDim2 = ( m_viewType == XY ) ? 1 : 2;
NDIM1NDIM2( m_viewType )
Vector3 origin = GetOrigin();
origin[nDim1] += scale_diff * ( pointx - 0.5 * Width() );
origin[nDim2] -= scale_diff * ( pointy - 0.5 * Height() );
@ -278,8 +277,7 @@ void XYWnd::ZoomInWithMouse( int pointx, int pointy ){
void XYWnd::FocusOnBounds( const AABB& bounds ){
SetOrigin( bounds.origin );
int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
int nDim2 = ( m_viewType == XY ) ? 1 : 2;
NDIM1NDIM2( m_viewType )
SetScale( std::min( Width() / ( 3.f * std::max( 128.f, bounds.extents[ nDim1 ] ) ),
Height() / ( 3.f * std::max( 128.f, bounds.extents[ nDim2 ] ) ) ) );
@ -531,8 +529,7 @@ void XYWnd::overlayDraw(){
}
{
int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
int nDim2 = ( m_viewType == XY ) ? 1 : 2;
NDIM1NDIM2( m_viewType )
glMatrixMode( GL_PROJECTION );
glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
@ -783,8 +780,7 @@ void XYWnd::SetOrigin( const Vector3& origin ){
}
void XYWnd::Scroll( int x, int y ){
int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
int nDim2 = ( m_viewType == XY ) ? 1 : 2;
NDIM1NDIM2( m_viewType )
m_vOrigin[nDim1] += x / m_fScale;
m_vOrigin[nDim2] += y / m_fScale;
@ -799,10 +795,8 @@ FBO* XYWnd::fbo_get(){
void XYWnd::SetCustomPivotOrigin( int pointx, int pointy ){
Vector3 point;
XY_ToPoint( pointx, pointy, point );
VIEWTYPE viewtype = GetViewType();
const int nDim = ( viewtype == YZ ) ? 0 : ( ( viewtype == XZ ) ? 1 : 2 );
bool set[3] = { true, true, true };
set[nDim] = false;
set[GetViewType()] = false;
GlobalSelectionSystem().setCustomTransformOrigin( point, set );
SceneChangeNotify();
@ -830,18 +824,18 @@ void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
//xywnd->XY_SnapToGrid( point );
vector3_subtract( point, Camera_getOrigin( camwnd ) );
int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
if ( point[n1] || point[n2] ) {
const VIEWTYPE viewtype = xywnd->GetViewType();
NDIM1NDIM2( viewtype )
const int nAngle = ( viewtype == XY ) ? CAMERA_YAW : CAMERA_PITCH;
if ( point[nDim2] || point[nDim1] ) {
Vector3 angles( Camera_getAngles( camwnd ) );
angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[nDim2], point[nDim1] ) ) );
if( angles[CAMERA_YAW] < 0 )
angles[CAMERA_YAW] = angles[CAMERA_YAW] + 360;
if ( nAngle == CAMERA_PITCH ){
if( fabs( angles[CAMERA_PITCH] ) > 90 ){
angles[CAMERA_PITCH] = ( angles[CAMERA_PITCH] > 0 ) ? ( -angles[CAMERA_PITCH] + 180 ) : ( -angles[CAMERA_PITCH] - 180 );
if( xywnd->GetViewType() == YZ ){
if( viewtype == YZ ){
if( angles[CAMERA_YAW] < 180 ){
angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW];
}
@ -851,7 +845,7 @@ void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
}
}
else{
if( xywnd->GetViewType() == YZ ){
if( viewtype == YZ ){
if( angles[CAMERA_YAW] > 180 ){
angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW];
}
@ -900,7 +894,7 @@ void XYWnd::NewBrushDrag( int x, int y, bool square, bool cube ){
XY_ToPoint( x, y, maxs );
XY_SnapToGrid( maxs );
const int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
const int nDim = GetViewType();
mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
@ -910,11 +904,12 @@ void XYWnd::NewBrushDrag( int x, int y, bool square, bool cube ){
}
if( square || cube ){
const float squaresize = std::max( fabs( maxs[(nDim + 1) % 3] - mins[(nDim + 1) % 3] ), fabs( maxs[(nDim + 2) % 3] - mins[(nDim + 2) % 3] ) );
maxs[(nDim + 1) % 3] = ( maxs[(nDim + 1) % 3] - mins[(nDim + 1) % 3] ) > 0.f ? ( mins[(nDim + 1) % 3] + squaresize ) : ( mins[(nDim + 1) % 3] - squaresize );
maxs[(nDim + 2) % 3] = ( maxs[(nDim + 2) % 3] - mins[(nDim + 2) % 3] ) > 0.f ? ( mins[(nDim + 2) % 3] + squaresize ) : ( mins[(nDim + 2) % 3] - squaresize );
NDIM1NDIM2( nDim )
const float squaresize = std::max( fabs( maxs[nDim1] - mins[nDim1] ), fabs( maxs[nDim2] - mins[nDim2] ) );
for( auto i : { nDim1, nDim2 } )
maxs[i] = mins[i] + std::copysign( squaresize, maxs[i] - mins[i] );
if( cube ){
maxs[nDim] = ( maxs[nDim] - mins[nDim] ) > 0.f ? ( mins[nDim] + squaresize ) : ( mins[nDim] - squaresize );
maxs[nDim] = mins[nDim] + squaresize;
}
}
@ -1297,37 +1292,17 @@ inline float normalised_to_world( float normalised, float world_origin, float no
// TTimo: watch it, this doesn't init one of the 3 coords
void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
if ( m_viewType == XY ) {
point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
}
else if ( m_viewType == YZ ) {
point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
}
else
{
point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
}
const float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
const float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
NDIM1NDIM2( m_viewType )
point[nDim1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[nDim1], normalised2world_scale_x );
point[nDim2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[nDim2], normalised2world_scale_y );
}
void XYWnd::XY_SnapToGrid( Vector3& point ){
if ( m_viewType == XY ) {
point[0] = float_snapped( point[0], GetSnapGridSize() );
point[1] = float_snapped( point[1], GetSnapGridSize() );
}
else if ( m_viewType == YZ ) {
point[1] = float_snapped( point[1], GetSnapGridSize() );
point[2] = float_snapped( point[2], GetSnapGridSize() );
}
else
{
point[0] = float_snapped( point[0], GetSnapGridSize() );
point[2] = float_snapped( point[2], GetSnapGridSize() );
}
NDIM1NDIM2( m_viewType )
point[nDim1] = float_snapped( point[nDim1], GetSnapGridSize() );
point[nDim2] = float_snapped( point[nDim2], GetSnapGridSize() );
}
@ -1411,8 +1386,7 @@ void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHe
void BackgroundImage::set( const VIEWTYPE viewtype ){
const AABB bounds = GlobalSelectionSystem().getBoundsSelected();
const int nDim1 = ( viewtype == YZ ) ? 1 : 0;
const int nDim2 = ( viewtype == XY ) ? 1 : 2;
NDIM1NDIM2( viewtype )
if( !( bounds.extents[nDim1] > 0 && bounds.extents[nDim2] > 0 ) ){
gtk_MessageBox( GTK_WIDGET( MainFrame_getWindow() ), "Select some objects to get the bounding box for image.\n",
"No selection", eMB_OK, eMB_ICONERROR );
@ -1476,8 +1450,7 @@ double two_to_the_power( int power ){
void XYWnd::XY_DrawAxis( void ){
const char g_AxisName[3] = { 'X', 'Y', 'Z' };
const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
NDIM1NDIM2( m_viewType )
const float w = ( m_nWidth / 2 / m_fScale );
const float h = ( m_nHeight / 2 / m_fScale );
@ -1556,8 +1529,7 @@ void XYWnd::XY_DrawGrid( void ) {
w = ( m_nWidth / 2 / m_fScale );
h = ( m_nHeight / 2 / m_fScale );
const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
NDIM1NDIM2( m_viewType )
xb = m_vOrigin[nDim1] - w;
if ( xb < g_region_mins[nDim1] ) {
@ -1780,8 +1752,7 @@ void XYWnd::XY_DrawBlockGrid(){
w = ( m_nWidth / 2 / m_fScale );
h = ( m_nHeight / 2 / m_fScale );
int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
int nDim2 = ( m_viewType == XY ) ? 1 : 2;
NDIM1NDIM2( m_viewType )
xb = m_vOrigin[nDim1] - w;
if ( xb < g_region_mins[nDim1] ) {
@ -2117,8 +2088,7 @@ void XYWnd::updateProjection(){
// note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
void XYWnd::updateModelview(){
int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
int nDim2 = ( m_viewType == XY ) ? 1 : 2;
NDIM1NDIM2( m_viewType )
// translation
m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
@ -2219,8 +2189,7 @@ void XYWnd::XY_Draw(){
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glScalef( m_fScale, m_fScale, 1 );
int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
int nDim2 = ( m_viewType == XY ) ? 1 : 2;
NDIM1NDIM2( m_viewType )
glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
glDisable( GL_LINE_STIPPLE );
@ -2339,7 +2308,7 @@ void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
xywnd->XY_ToPoint( x, y, point );
xywnd->XY_SnapToGrid( point );
int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
const int nDim = xywnd->GetViewType();
float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
point[nDim] = float_snapped( fWorkMid, GetGridSize() );
}
@ -2348,19 +2317,9 @@ void XYWnd::OnEntityCreate( const char* item ){
Vector3 point;
XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
Vector3 offset( 0, 0, 0 );
float offset_for_multiple = ( GetSnapGridSize() < 8.f ? 8.f : GetSnapGridSize() ) * g_entityCreationOffset;
switch ( m_viewType )
{
case XY:
case XZ:
offset[0] = 1.f;
break;
default: //case YZ:
offset[1] = 1.f;
break;
}
point += offset * offset_for_multiple;
const float offset = std::max( 8.f, GetSnapGridSize() ) * g_entityCreationOffset;
NDIM1NDIM2( m_viewType )
point += g_vector3_axes[nDim1] * offset;
Entity_createFromSelection( item, point );
}