From: mattn Date: Thu, 10 Jul 2008 08:30:47 +0000 (+0000) Subject: * divVerent's patch for the brush primitives surface dialog (fixed segfault due to... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d2c9e20484ee61c25b60f008bca9753517996deb;p=xonotic%2Fnetradiant.git * divVerent's patch for the brush primitives surface dialog (fixed segfault due to NULL pointer) * Quote http://zerowing.idsoftware.com/pipermail/gtkradiant/2008-July/011094.html : Attached to this message is a patch for a "somewhat working" brush primitives surface dialog. It is an ugly hack, as it converts between fake texdef notations and brush primitives whenever values are needed. Had to fix an accuracy bug: the surface dialog rounded all rotation values to integer angles, which SEVERELY broke things for me (changed the Gtk spin object to use 4 digits, which is enough for me). Also, I changed the fake texdef / brush primitives conversions to use long double internally, as float's roundoff errors were quite visible to me when testing. Hope the remaining roundoff errors from converting back and forth won't kill me, but it worked for a simple map example. Also, I had to separate out "Snap to grid" and "Don't clamp" into two separare options. They now mean: - Snap to grid: snaps drag/etc. actions to the grid - Don't clamp: disable brush point snapping during many operations, like merely shifting brushes, editing texturing parameters, map loading, etc. The reason is that I do need the grid, but I don't want to get my objects messed up by the snapping in my map. As I am using free rotations, this DOES change quite much. The config.py change is needed for compilation on Debian stable; Debian's scons does not use the CFLAGS variable, but just CCFLAGS and CXXFLAGS. In newer scons versions, CFLAGS is _shared_ flags for C and C++, so if you want to require these, you don't need to include the CFLAGS in CXXFLAGS too. git-svn-id: https://zerowing.idsoftware.com/svn/radiant/GtkRadiant/trunk@301 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- diff --git a/config.py b/config.py index f461e02d..48b54c94 100644 --- a/config.py +++ b/config.py @@ -236,7 +236,7 @@ class Config: if ( useZ ): env.Append( LIBS = 'z' ) - env.Append( CFLAGS = baseflags ) + env.Append( CCFLAGS = baseflags ) env.Append( CXXFLAGS = baseflags + [ '-fpermissive', '-fvisibility-inlines-hidden' ] ) env.Append( CPPPATH = [ 'include', 'libs' ] ) env.Append( CPPDEFINES = [ 'Q_NO_STLPORT' ] ) diff --git a/include/isurfaceplugin.h b/include/isurfaceplugin.h index 61e2fdba..c31b5791 100644 --- a/include/isurfaceplugin.h +++ b/include/isurfaceplugin.h @@ -62,6 +62,7 @@ public: face_t *face; // Face of Texdef texdef_t texdef; // Working texdef texdef_t orig_texdef; // Original, for baselining changes + brushprimit_texdef_t orig_bp_texdef; // Original, for undo }; diff --git a/plugins/surface/surfacedialog.cpp b/plugins/surface/surfacedialog.cpp index 591cf7cb..59311bed 100644 --- a/plugins/surface/surfacedialog.cpp +++ b/plugins/surface/surfacedialog.cpp @@ -1027,7 +1027,7 @@ GtkWidget* create_SurfaceInspector (void) gtk_widget_set_sensitive( GTK_WIDGET( vscale_value_spinbutton ), FALSE ); rotate_value_spinbutton_adj = gtk_adjustment_new (0.0, -360.0, 360.0, 1.0, 10.0, 10.0); - rotate_value_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_value_spinbutton_adj), 1, 0); + rotate_value_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_value_spinbutton_adj), 1, 4); gtk_widget_show (rotate_value_spinbutton); gtk_table_attach (GTK_TABLE (table1), rotate_value_spinbutton, 1, 2, 10, 11, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), @@ -1078,7 +1078,7 @@ GtkWidget* create_SurfaceInspector (void) gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (vscale_offset_spinbutton), TRUE); rotate_offset_spinbutton_adj = gtk_adjustment_new (0.0, -360.0, 360.0, 1.0, 10.0, 10.0); - rotate_offset_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_offset_spinbutton_adj), 0, 2); + rotate_offset_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_offset_spinbutton_adj), 0, 4); gtk_widget_show (rotate_offset_spinbutton); gtk_table_attach (GTK_TABLE (table1), rotate_offset_spinbutton, 2, 3, 10, 11, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), @@ -1121,7 +1121,7 @@ GtkWidget* create_SurfaceInspector (void) gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (vscale_step_spinbutton), GTK_UPDATE_IF_VALID); rotate_step_spinbutton_adj = gtk_adjustment_new (0.0, -360.0, 360.0, 1.0, 10.0, 10.0); - rotate_step_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_step_spinbutton_adj), 1, 2); + rotate_step_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_step_spinbutton_adj), 1, 4); gtk_widget_show (rotate_step_spinbutton); gtk_table_attach (GTK_TABLE (table1), rotate_step_spinbutton, 3, 4, 10, 11, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), diff --git a/radiant/brush_primit.cpp b/radiant/brush_primit.cpp index 3ca21352..589ab9b9 100644 --- a/radiant/brush_primit.cpp +++ b/radiant/brush_primit.cpp @@ -186,11 +186,11 @@ void TexMatToFakeTexCoords( vec_t texMat[2][3], float shift[2], float *rot, floa { #ifdef DBG_BP // check this matrix is orthogonal - if (fabs(texMat[0][0]*texMat[0][1]+texMat[1][0]*texMat[1][1])>ZERO_EPSILON) + if (fabs(texMat[0][0]*1.0L*texMat[0][1]+texMat[1][0]*1.0L*texMat[1][1])>ZERO_EPSILON) Sys_Printf("Warning : non orthogonal texture matrix in TexMatToFakeTexCoords\n"); #endif - scale[0]=sqrt(texMat[0][0]*texMat[0][0]+texMat[1][0]*texMat[1][0]); - scale[1]=sqrt(texMat[0][1]*texMat[0][1]+texMat[1][1]*texMat[1][1]); + scale[0]=sqrt(texMat[0][0]*1.0L*texMat[0][0]+texMat[1][0]*1.0L*texMat[1][0]); + scale[1]=sqrt(texMat[0][1]*1.0L*texMat[0][1]+texMat[1][1]*1.0L*texMat[1][1]); #ifdef DBG_BP if (scale[0]face = f; position->brush = b; - position->texdef = f->texdef; - position->orig_texdef = f->texdef; + position->texdef = f->texdef; + if(g_qeglobals.m_bBrushPrimitMode) + { + ConvertTexMatWithQTexture(&f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL); + TexMatToFakeTexCoords(bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale); + position->orig_bp_texdef = bp; + } + position->orig_texdef = position->texdef; prev_pos->next = position; prev_pos = position; position++; @@ -103,7 +110,13 @@ void SI_GetSelFacesTexdef(texdef_to_face_t *allocd_block_texdef) position->face = f; position->brush = b; position->texdef = f->texdef; - position->orig_texdef = f->texdef; + if(g_qeglobals.m_bBrushPrimitMode) + { + ConvertTexMatWithQTexture(&f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL); + TexMatToFakeTexCoords(bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale); + position->orig_bp_texdef = bp; + } + position->orig_texdef = position->texdef; prev_pos = position; for(i=1; iface = f; position->brush = b; position->texdef = f->texdef; - position->orig_texdef = f->texdef; + if(g_qeglobals.m_bBrushPrimitMode) + { + ConvertTexMatWithQTexture(&f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL); + TexMatToFakeTexCoords(bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale); + position->orig_bp_texdef = bp; + } + position->orig_texdef = position->texdef; prev_pos->next = position; prev_pos = position; } @@ -187,7 +206,7 @@ void SI_SetTexdef_FaceList(texdef_to_face_t* texdef_face_list, bool b_SetUndoPoi if (b_isQuake2) SetFaceTexdef_Q2(texdef_to_face->face, &texdef_to_face->orig_texdef, bFit_to_Scale); else - SetFaceTexdef(texdef_to_face->face, &texdef_to_face->orig_texdef, NULL); + SetFaceTexdef(texdef_to_face->face, &texdef_to_face->orig_texdef, &texdef_to_face->orig_bp_texdef, bFit_to_Scale); Undo_Start("set facelist texdefs"); @@ -204,7 +223,11 @@ void SI_SetTexdef_FaceList(texdef_to_face_t* texdef_face_list, bool b_SetUndoPoi if (b_isQuake2) SetFaceTexdef_Q2(texdef_to_face->face, &texdef_to_face->texdef, bFit_to_Scale); else - SetFaceTexdef(texdef_to_face->face, &texdef_to_face->texdef, NULL , bFit_to_Scale); + { + brushprimit_texdef_t brushprimit_texdef; + FakeTexCoordsToTexMat(texdef_to_face->texdef.shift, texdef_to_face->texdef.rotate, texdef_to_face->texdef.scale, brushprimit_texdef.coords); + SetFaceTexdef(texdef_to_face->face, &texdef_to_face->texdef, &brushprimit_texdef , bFit_to_Scale); + } Brush_Build(texdef_to_face->brush); if(bFit_to_Scale) texdef_to_face->texdef = texdef_to_face->face->texdef; @@ -222,7 +245,10 @@ void SI_SetTexdef_FaceList(texdef_to_face_t* texdef_face_list, bool b_SetUndoPoi Undo_End(); // Over-write the orig_texdef list, cementing the change. for(texdef_to_face = texdef_face_list; texdef_to_face; texdef_to_face = texdef_to_face->next) + { texdef_to_face->orig_texdef = texdef_to_face->texdef; + texdef_to_face->orig_bp_texdef = texdef_to_face->face->brushprimit_texdef; + } } } @@ -232,6 +258,7 @@ void SI_SetTexdef_FaceList(texdef_to_face_t* texdef_face_list, bool b_SetUndoPoi void SI_FaceList_FitTexture(texdef_to_face_t* si_texdef_face_list, int nHeight, int nWidth) { texdef_to_face_t* temp_texdef_face_list; + brushprimit_texdef_t bp; if (!si_texdef_face_list) return; @@ -241,6 +268,12 @@ void SI_FaceList_FitTexture(texdef_to_face_t* si_texdef_face_list, int nHeight, Face_FitTexture(temp_texdef_face_list->face, nHeight, nWidth); Brush_Build(temp_texdef_face_list->brush,true,true,false,false); // Write changes to our working Texdef list + + if(g_qeglobals.m_bBrushPrimitMode) + { + ConvertTexMatWithQTexture(&temp_texdef_face_list->face->brushprimit_texdef, QERApp_Shader_ForName( temp_texdef_face_list->face->texdef.GetName() )->getTexture(), &bp, NULL); + TexMatToFakeTexCoords(bp.coords, temp_texdef_face_list->face->texdef.shift, &temp_texdef_face_list->face->texdef.rotate, temp_texdef_face_list->face->texdef.scale); + } temp_texdef_face_list->texdef = temp_texdef_face_list->face->texdef; } diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 6d58e823..ef974f73 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -1501,7 +1501,7 @@ qboolean XYWnd::DragDelta (int x, int y, vec3_t move) for (i=0 ; i<3 ; i++) { delta[i] = xvec[i] * (x - m_nPressx) + yvec[i] * (y - m_nPressy); - if (!g_PrefsDlg.m_bNoClamp) + if (g_PrefsDlg.m_bSnap) { delta[i] = floor(delta[i] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize; } @@ -2135,13 +2135,13 @@ void XYWnd::XY_Init() void XYWnd::SnapToPoint (int x, int y, vec3_t point) { - if (g_PrefsDlg.m_bNoClamp) + if (g_PrefsDlg.m_bSnap) { - XY_ToPoint(x, y, point); + XY_ToGridPoint(x, y, point); } else { - XY_ToGridPoint(x, y, point); + XY_ToPoint(x, y, point); } }