Changeset 301

Show
Ignore:
Timestamp:
07/10/08 03:30:47 (3 months ago)
Author:
mattn
Message:

* 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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • GtkRadiant/trunk/config.py

    r247 r301  
    237237                        env.Append( LIBS = 'z' ) 
    238238 
    239                 env.Append( CFLAGS = baseflags ) 
     239                env.Append( CCFLAGS = baseflags ) 
    240240                env.Append( CXXFLAGS = baseflags + [ '-fpermissive', '-fvisibility-inlines-hidden' ] ) 
    241241                env.Append( CPPPATH = [ 'include', 'libs' ] ) 
  • GtkRadiant/trunk/include/isurfaceplugin.h

    r195 r301  
    6363  texdef_t texdef;  // Working texdef 
    6464  texdef_t orig_texdef;  // Original, for baselining changes 
     65  brushprimit_texdef_t orig_bp_texdef; // Original, for undo 
    6566}; 
    6667 
  • GtkRadiant/trunk/plugins/surface/surfacedialog.cpp

    r283 r301  
    10281028 
    10291029  rotate_value_spinbutton_adj = gtk_adjustment_new (0.0, -360.0, 360.0, 1.0, 10.0, 10.0); 
    1030   rotate_value_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_value_spinbutton_adj), 1, 0); 
     1030  rotate_value_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_value_spinbutton_adj), 1, 4); 
    10311031  gtk_widget_show (rotate_value_spinbutton); 
    10321032  gtk_table_attach (GTK_TABLE (table1), rotate_value_spinbutton, 1, 2, 10, 11, 
     
    10791079 
    10801080  rotate_offset_spinbutton_adj = gtk_adjustment_new (0.0, -360.0, 360.0, 1.0, 10.0, 10.0); 
    1081   rotate_offset_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_offset_spinbutton_adj), 0, 2); 
     1081  rotate_offset_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_offset_spinbutton_adj), 0, 4); 
    10821082  gtk_widget_show (rotate_offset_spinbutton); 
    10831083  gtk_table_attach (GTK_TABLE (table1), rotate_offset_spinbutton, 2, 3, 10, 11, 
     
    11221122 
    11231123  rotate_step_spinbutton_adj = gtk_adjustment_new (0.0, -360.0, 360.0, 1.0, 10.0, 10.0); 
    1124   rotate_step_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_step_spinbutton_adj), 1, 2); 
     1124  rotate_step_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_step_spinbutton_adj), 1, 4); 
    11251125  gtk_widget_show (rotate_step_spinbutton); 
    11261126  gtk_table_attach (GTK_TABLE (table1), rotate_step_spinbutton, 3, 4, 10, 11, 
  • GtkRadiant/trunk/radiant/brush_primit.cpp

    r299 r301  
    187187#ifdef DBG_BP 
    188188        // check this matrix is orthogonal 
    189         if (fabs(texMat[0][0]*texMat[0][1]+texMat[1][0]*texMat[1][1])>ZERO_EPSILON) 
     189        if (fabs(texMat[0][0]*1.0L*texMat[0][1]+texMat[1][0]*1.0L*texMat[1][1])>ZERO_EPSILON) 
    190190                Sys_Printf("Warning : non orthogonal texture matrix in TexMatToFakeTexCoords\n"); 
    191191#endif 
    192         scale[0]=sqrt(texMat[0][0]*texMat[0][0]+texMat[1][0]*texMat[1][0]); 
    193         scale[1]=sqrt(texMat[0][1]*texMat[0][1]+texMat[1][1]*texMat[1][1]); 
     192        scale[0]=sqrt(texMat[0][0]*1.0L*texMat[0][0]+texMat[1][0]*1.0L*texMat[1][0]); 
     193        scale[1]=sqrt(texMat[0][1]*1.0L*texMat[0][1]+texMat[1][1]*1.0L*texMat[1][1]); 
    194194#ifdef DBG_BP 
    195195        if (scale[0]<ZERO_EPSILON || scale[1]<ZERO_EPSILON) 
     
    211211        } 
    212212        else 
    213         *rot = RAD2DEG( atan2( texMat[1][0], texMat[0][0] ) ); 
     213        *rot = RAD2DEG( atan2( texMat[1][0]*1.0L, texMat[0][0]*1.0L ) ); 
    214214        shift[0] = -texMat[0][2]; 
    215215        shift[1] = texMat[1][2]; 
     
    220220void FakeTexCoordsToTexMat( float shift[2], float rot, float scale[2], vec_t texMat[2][3] ) 
    221221{ 
    222         texMat[0][0] = scale[0] * cos( DEG2RAD( rot ) ); 
    223         texMat[1][0] = scale[0] * sin( DEG2RAD( rot ) ); 
    224         texMat[0][1] = -1.0f * scale[1] * sin( DEG2RAD( rot ) ); 
    225         texMat[1][1] = scale[1] * cos( DEG2RAD( rot ) ); 
     222        texMat[0][0] = scale[0] *1.0L* cos( DEG2RAD( 1.0L*rot ) ); 
     223        texMat[1][0] = scale[0] *1.0L* sin( DEG2RAD( 1.0L*rot ) ); 
     224        texMat[0][1] = -scale[1] *1.0L* sin( DEG2RAD( 1.0L*rot ) ); 
     225        texMat[1][1] = scale[1] *1.0L* cos( DEG2RAD( 1.0L*rot ) ); 
    226226        texMat[0][2] = -shift[0]; 
    227227        texMat[1][2] = shift[1]; 
  • GtkRadiant/trunk/radiant/drag.cpp

    r289 r301  
    771771                { 
    772772                        move[i] = drag_xvec[i]*(x - pressx)     + drag_yvec[i]*(y - pressy); 
    773                         if (!g_PrefsDlg.m_bNoClamp) 
     773                        if (g_PrefsDlg.m_bSnap) 
    774774                        { 
    775775                                move[i] = floor(move[i]/g_qeglobals.d_gridsize+0.5)*g_qeglobals.d_gridsize; 
  • GtkRadiant/trunk/radiant/mainframe.cpp

    r289 r301  
    38253825  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), (g_PrefsDlg.m_bGLLighting) ? TRUE : FALSE); 
    38263826  item  = GTK_WIDGET (g_object_get_data (G_OBJECT (m_pWidget), "menu_snaptogrid")); 
    3827   gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), (!g_PrefsDlg.m_bNoClamp) ? TRUE : FALSE); 
     3827  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), (g_PrefsDlg.m_bSnap) ? TRUE : FALSE); 
    38283828 
    38293829  item = GTK_WIDGET (g_object_get_data (G_OBJECT (m_pWidget), "tb_view_cubicclipping")); 
     
    46594659    g_bIgnoreCommands++; 
    46604660    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), 
    4661                                     (!g_PrefsDlg.m_bNoClamp) ? TRUE : FALSE); 
     4661                                    (g_PrefsDlg.m_bSnap) ? TRUE : FALSE); 
    46624662    g_bIgnoreCommands--; 
    46634663  } 
     
    56875687void MainFrame::OnSnaptogrid() 
    56885688{ 
    5689   g_PrefsDlg.m_bNoClamp ^= 1; 
     5689  g_PrefsDlg.m_bSnap ^= 1; 
    56905690  g_PrefsDlg.SavePrefs (); 
    56915691 
    56925692  GtkWidget *item = GTK_WIDGET (g_object_get_data (G_OBJECT (m_pWidget), "menu_snaptogrid")); 
    56935693  g_bIgnoreCommands++; 
    5694   gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), g_PrefsDlg.m_bNoClamp ? FALSE : TRUE); 
     5694  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), g_PrefsDlg.m_bSnap ? TRUE : FALSE); 
    56955695  g_bIgnoreCommands--; 
    56965696} 
  • GtkRadiant/trunk/radiant/preferences.cpp

    r298 r301  
    9797#define PLUGINTOOLBAR_KEY "PluginToolBar" 
    9898#define NOCLAMP_KEY             "NoClamp" 
     99#define SNAP_KEY                "Snap" 
    99100#define PREFAB_KEY              "PrefabPath" 
    100101#define USERINI_KEY             "UserINIPath" 
     
    636637  m_bPluginToolbar = TRUE; 
    637638  m_bNoClamp = FALSE; 
     639  m_bSnap = TRUE; 
    638640  m_strUserPath = ""; 
    639641  m_nRotation = 0; 
     
    23372339  AddDialogData (check, &m_bNoClamp, DLG_CHECK_BOOL); 
    23382340 
     2341  // Snap to grid 
     2342  check = gtk_check_button_new_with_label (_("Snap to grid")); 
     2343  gtk_widget_show (check); 
     2344  gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0); 
     2345  AddDialogData (check, &m_bSnap, DLG_CHECK_BOOL); 
     2346 
    23392347  // Select patch by bounding box 
    23402348  check = gtk_check_button_new_with_label (_("Select patches by bounding box")); 
     
    29072915 
    29082916  mLocalPrefs.GetPref(NOCLAMP_KEY,            &m_bNoClamp,                    FALSE); 
     2917  mLocalPrefs.GetPref(SNAP_KEY,               &m_bSnap,                       TRUE); 
    29092918  mLocalPrefs.GetPref(USERINI_KEY,            &m_strUserPath,                 ""); 
    29102919  mLocalPrefs.GetPref(ROTATION_KEY,           &m_nRotation,                   45); 
  • GtkRadiant/trunk/radiant/preferences.h

    r297 r301  
    580580  bool  m_bNoClamp; 
    581581        //++timo this is most likely broken, I don't know what it's supposed to do 
     582  bool  m_bSnap; 
    582583  Str   m_strUserPath; 
    583584  int   m_nRotation; 
  • GtkRadiant/trunk/radiant/select.cpp

    r289 r301  
    736736        int             i; 
    737737 
    738   if (g_PrefsDlg.m_bNoClamp) 
     738  if (!g_PrefsDlg.m_bSnap) 
    739739  { 
    740740    Select_GetTrueMid(mid); 
  • GtkRadiant/trunk/radiant/surfaceplugin.cpp

    r297 r301  
    7474  brush_t       *b; 
    7575  texdef_to_face_t *position, *prev_pos; 
     76  brushprimit_texdef_t bp; 
    7677 
    7778  if(selected_brushes.next != &selected_brushes) 
     
    8687            position->face = f; 
    8788            position->brush = b; 
    88             position->texdef = f->texdef; 
    89             position->orig_texdef = f->texdef; 
     89                        position->texdef = f->texdef; 
     90                        if(g_qeglobals.m_bBrushPrimitMode) 
     91                        { 
     92                                ConvertTexMatWithQTexture(&f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL); 
     93                                TexMatToFakeTexCoords(bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale); 
     94                                position->orig_bp_texdef = bp; 
     95                        } 
     96                        position->orig_texdef = position->texdef; 
    9097            prev_pos->next = position; 
    9198            prev_pos = position; 
     
    104111    position->brush = b; 
    105112    position->texdef = f->texdef; 
    106     position->orig_texdef = f->texdef; 
     113        if(g_qeglobals.m_bBrushPrimitMode) 
     114        { 
     115                ConvertTexMatWithQTexture(&f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL); 
     116                TexMatToFakeTexCoords(bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale); 
     117                position->orig_bp_texdef = bp; 
     118        } 
     119    position->orig_texdef = position->texdef; 
    107120    prev_pos = position; 
    108121    for(i=1; i<g_ptrSelectedFaces.GetSize(); i++) 
     
    114127      position->brush = b; 
    115128      position->texdef = f->texdef; 
    116       position->orig_texdef = f->texdef; 
     129          if(g_qeglobals.m_bBrushPrimitMode) 
     130          { 
     131                  ConvertTexMatWithQTexture(&f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL); 
     132                  TexMatToFakeTexCoords(bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale); 
     133                  position->orig_bp_texdef = bp; 
     134          } 
     135      position->orig_texdef = position->texdef; 
    117136      prev_pos->next = position; 
    118137      prev_pos = position; 
     
    188207        SetFaceTexdef_Q2(texdef_to_face->face, &texdef_to_face->orig_texdef, bFit_to_Scale); 
    189208      else 
    190         SetFaceTexdef(texdef_to_face->face, &texdef_to_face->orig_texdef, NULL); 
     209        SetFaceTexdef(texdef_to_face->face, &texdef_to_face->orig_texdef, &texdef_to_face->orig_bp_texdef, bFit_to_Scale); 
    191210 
    192211      Undo_Start("set facelist texdefs"); 
     
    205224      SetFaceTexdef_Q2(texdef_to_face->face, &texdef_to_face->texdef,  bFit_to_Scale); 
    206225    else 
    207       SetFaceTexdef(texdef_to_face->face, &texdef_to_face->texdef, NULL , bFit_to_Scale); 
     226        { 
     227          brushprimit_texdef_t brushprimit_texdef; 
     228          FakeTexCoordsToTexMat(texdef_to_face->texdef.shift, texdef_to_face->texdef.rotate, texdef_to_face->texdef.scale, brushprimit_texdef.coords); 
     229      SetFaceTexdef(texdef_to_face->face, &texdef_to_face->texdef, &brushprimit_texdef , bFit_to_Scale); 
     230        } 
    208231    Brush_Build(texdef_to_face->brush); 
    209232    if(bFit_to_Scale) 
     
    223246        // Over-write the orig_texdef list, cementing the change. 
    224247        for(texdef_to_face = texdef_face_list; texdef_to_face; texdef_to_face = texdef_to_face->next) 
     248        { 
    225249          texdef_to_face->orig_texdef = texdef_to_face->texdef; 
     250          texdef_to_face->orig_bp_texdef = texdef_to_face->face->brushprimit_texdef; 
     251        } 
    226252      } 
    227253  } 
     
    233259{ 
    234260  texdef_to_face_t* temp_texdef_face_list; 
     261  brushprimit_texdef_t bp; 
    235262 
    236263  if (!si_texdef_face_list) 
     
    242269    Brush_Build(temp_texdef_face_list->brush,true,true,false,false); 
    243270    // Write changes to our working Texdef list 
     271         
     272        if(g_qeglobals.m_bBrushPrimitMode) 
     273        { 
     274                ConvertTexMatWithQTexture(&temp_texdef_face_list->face->brushprimit_texdef, QERApp_Shader_ForName( temp_texdef_face_list->face->texdef.GetName() )->getTexture(), &bp, NULL); 
     275                TexMatToFakeTexCoords(bp.coords, temp_texdef_face_list->face->texdef.shift, &temp_texdef_face_list->face->texdef.rotate, temp_texdef_face_list->face->texdef.scale); 
     276        } 
    244277    temp_texdef_face_list->texdef = temp_texdef_face_list->face->texdef; 
    245278  } 
  • GtkRadiant/trunk/radiant/xywindow.cpp

    r289 r301  
    15021502  { 
    15031503    delta[i] = xvec[i] * (x - m_nPressx) + yvec[i] * (y - m_nPressy); 
    1504     if (!g_PrefsDlg.m_bNoClamp) 
     1504    if (g_PrefsDlg.m_bSnap) 
    15051505    { 
    15061506      delta[i] = floor(delta[i] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize; 
     
    21362136void XYWnd::SnapToPoint (int x, int y, vec3_t point) 
    21372137{ 
    2138   if (g_PrefsDlg.m_bNoClamp) 
     2138  if (g_PrefsDlg.m_bSnap) 
     2139  { 
     2140    XY_ToGridPoint(x, y, point); 
     2141  } 
     2142  else 
    21392143  { 
    21402144    XY_ToPoint(x, y, point); 
    2141   } 
    2142   else 
    2143   { 
    2144     XY_ToGridPoint(x, y, point); 
    21452145  } 
    21462146}