ToggleGridSnap command (beware of it)
authordivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Sun, 4 Oct 2009 19:15:55 +0000 (19:15 +0000)
committerdivverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Sun, 4 Oct 2009 19:15:55 +0000 (19:15 +0000)
git-svn-id: svn://svn.icculus.org/netradiant/trunk@401 61c419a2-8eb2-4b30-bcec-8cead039b335

libs/math/vector.h
radiant/grid.cpp
radiant/grid.h
radiant/mainframe.cpp
radiant/selection.cpp
radiant/xywindow.cpp
tools/quake3/q3map2/light.c
tools/quake3/q3map2/light_trace.c
tools/quake3/q3map2/q3map2.h

index 57022db..075c58f 100644 (file)
@@ -105,6 +105,8 @@ template<typename Element, typename OtherElement>
 inline Element float_snapped(const Element& f, const OtherElement& snap)
 {
   //return Element(float_to_integer(f / snap) * snap);
+  if(snap == 0)
+       return f;
   return Element(llrint(f / snap) * snap); // llrint has more significant bits
 }
 
index e93ce40..f25a0d9 100644 (file)
@@ -98,6 +98,8 @@ int g_grid_default = GridDefault_forGridPower(GRIDPOWER_8);
 
 int g_grid_power = GridPower_forGridDefault(g_grid_default);
 
+bool g_grid_snap = true;
+
 int Grid_getPower()
 {
   return g_grid_power;
@@ -110,6 +112,11 @@ inline float GridSize_forGridPower(int gridPower)
 
 float g_gridsize = GridSize_forGridPower(g_grid_power);
 
+float GetSnapGridSize()
+{
+  return g_grid_snap ? g_gridsize : 0;
+}
+
 float GetGridSize()
 {
   return g_gridsize;
@@ -159,6 +166,7 @@ GridMenuItem g_gridMenu256(GRIDPOWER_256);
 
 void setGridPower(GridPower power)
 {
+  g_grid_snap = true;
   g_gridsize = GridSize_forGridPower(power);
 
   g_gridMenu0125.m_item.update();
@@ -178,6 +186,7 @@ void setGridPower(GridPower power)
 
 void GridPrev()
 {
+  g_grid_snap = true;
   if(g_grid_power > GRIDPOWER_0125)
   {
     setGridPower(static_cast<GridPower>(--g_grid_power));
@@ -186,18 +195,26 @@ void GridPrev()
 
 void GridNext()
 {
+  g_grid_snap = true;
   if(g_grid_power < GRIDPOWER_256)
   {
     setGridPower(static_cast<GridPower>(++g_grid_power));
   }
 }
 
+void ToggleGridSnap()
+{
+  g_grid_snap = !g_grid_snap;
+  GridChangeNotify();
+}
 
 void Grid_registerCommands()
 {
   GlobalCommands_insert("GridDown", FreeCaller<GridPrev>(), Accelerator('['));
   GlobalCommands_insert("GridUp", FreeCaller<GridNext>(), Accelerator(']'));
 
+  GlobalCommands_insert("ToggleGridSnap", FreeCaller<ToggleGridSnap>());
+
   GlobalToggles_insert("SetGrid0.125", GridMenuItem::SetCaller(g_gridMenu0125), ToggleItem::AddCallbackCaller(g_gridMenu0125.m_item));
   GlobalToggles_insert("SetGrid0.25", GridMenuItem::SetCaller(g_gridMenu025), ToggleItem::AddCallbackCaller(g_gridMenu025.m_item));
   GlobalToggles_insert("SetGrid0.5", GridMenuItem::SetCaller(g_gridMenu05), ToggleItem::AddCallbackCaller(g_gridMenu05.m_item));
@@ -234,6 +251,7 @@ void Grid_registerShortcuts()
   command_connect_accelerator("ToggleGrid");
   command_connect_accelerator("GridDown");
   command_connect_accelerator("GridUp");
+  command_connect_accelerator("ToggleGridSnap");
 }
 
 void Grid_constructPreferences(PreferencesPage& page)
index cf2671e..42dfd70 100644 (file)
@@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include "signal/signalfwd.h"
 
+float GetSnapGridSize();
 float GetGridSize();
 int Grid_getPower();
 
index 1555fa8..a441e03 100644 (file)
@@ -718,7 +718,7 @@ void PasteToCamera()
   // Work out the delta
   Vector3 mid;
   Select_GetMid(mid);
-  Vector3 delta = vector3_subtracted(vector3_snapped(Camera_getOrigin(camwnd), GetGridSize()), mid);
+  Vector3 delta = vector3_subtracted(vector3_snapped(Camera_getOrigin(camwnd), GetSnapGridSize()), mid);
 
   // Move to camera
   GlobalSelectionSystem().translateSelected(delta);
@@ -3288,7 +3288,7 @@ void MainFrame::SetGridStatus()
 {
   StringOutputStream status(64);
   const char* lock = (GridStatus_getTextureLockEnabled()) ? "ON" : "OFF";
-  status << "G:" << GridStatus_getGridSize()
+  status << (GetSnapGridSize() > 0 ? "G:" : "g:") << GridStatus_getGridSize()
     << "  R:" << GridStatus_getRotateIncrement()
     << "  C:" << GridStatus_getFarClipDistance()
     << "  L:" << lock;
index f4b2118..3b47799 100644 (file)
@@ -318,7 +318,7 @@ public:
     current = vector3_scaled(m_axis, distance_for_axis(m_start, current, m_axis));
 
     translation_local2object(current, current, manip2object);
-    vector3_snap(current, GetGridSize());
+    vector3_snap(current, GetSnapGridSize());
 
     m_translatable.translate(current);
   }
@@ -350,7 +350,7 @@ public:
     current = vector3_subtracted(current, m_start);
 
     translation_local2object(current, current, manip2object);
-    vector3_snap(current, GetGridSize());
+    vector3_snap(current, GetSnapGridSize());
     
     m_translatable.translate(current);
   }
@@ -386,9 +386,9 @@ public:
     Vector3 delta = vector3_subtracted(current, m_start);
 
     translation_local2object(delta, delta, manip2object);
-    vector3_snap(delta, GetGridSize());
+    vector3_snap(delta, GetSnapGridSize());
     
-    Vector3 start(vector3_snapped(m_start, GetGridSize()));
+    Vector3 start(vector3_snapped(m_start, GetSnapGridSize()));
     Vector3 scale(
       start[0] == 0 ? 1 : 1 + delta[0] / start[0],
       start[1] == 0 ? 1 : 1 + delta[1] / start[1],
@@ -424,9 +424,9 @@ public:
     Vector3 delta = vector3_subtracted(current, m_start);
 
     translation_local2object(delta, delta, manip2object);
-    vector3_snap(delta, GetGridSize());
+    vector3_snap(delta, GetSnapGridSize());
     
-    Vector3 start(vector3_snapped(m_start, GetGridSize()));
+    Vector3 start(vector3_snapped(m_start, GetSnapGridSize()));
     Vector3 scale(
       start[0] == 0 ? 1 : 1 + delta[0] / start[0],
       start[1] == 0 ? 1 : 1 + delta[1] / start[1],
@@ -3730,7 +3730,7 @@ void RadiantSelectionSystem::ConstructPivot() const
       m_object_pivot = bounds.origin;
     }
 
-    vector3_snap(m_object_pivot, GetGridSize());
+    vector3_snap(m_object_pivot, GetSnapGridSize());
     m_pivot2world = matrix4_translation_for_vec3(m_object_pivot);
 
     switch(m_manipulator_mode)
index f82b99b..06a9e4a 100644 (file)
@@ -966,7 +966,7 @@ void XYWnd::DropClipPoint(int pointx, int pointy)
   g_clip_viewtype = static_cast<VIEWTYPE>(GetViewType());
   const int nDim = (g_clip_viewtype == YZ ) ? 0 : ( (g_clip_viewtype == XZ) ? 1 : 2 );
   point[nDim] = mid[nDim];
-  vector3_snap(point, GetGridSize());
+  vector3_snap(point, GetSnapGridSize());
   NewClipPoint(point);
 }
 
@@ -1093,8 +1093,8 @@ void XYWnd::NewBrushDrag(int x, int y)
 
   int nDim = (m_viewType == XY) ? 2 : (m_viewType == YZ) ? 0 : 1;
 
-  mins[nDim] = float_snapped(Select_getWorkZone().d_work_min[nDim], GetGridSize());
-  maxs[nDim] = float_snapped(Select_getWorkZone().d_work_max[nDim], GetGridSize());
+  mins[nDim] = float_snapped(Select_getWorkZone().d_work_min[nDim], GetSnapGridSize());
+  maxs[nDim] = float_snapped(Select_getWorkZone().d_work_max[nDim], GetSnapGridSize());
 
   if (maxs[nDim] <= mins[nDim])
     maxs[nDim] = mins[nDim] + GetGridSize();
@@ -1555,18 +1555,18 @@ void XYWnd::XY_SnapToGrid(Vector3& point)
 {
   if (m_viewType == XY)
   {
-    point[0] = float_snapped(point[0], GetGridSize());
-    point[1] = float_snapped(point[1], GetGridSize());
+    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], GetGridSize());
-    point[2] = float_snapped(point[2], GetGridSize());
+    point[1] = float_snapped(point[1], GetSnapGridSize());
+    point[2] = float_snapped(point[2], GetSnapGridSize());
   }
   else
   {
-    point[0] = float_snapped(point[0], GetGridSize());
-    point[2] = float_snapped(point[2], GetGridSize());
+    point[0] = float_snapped(point[0], GetSnapGridSize());
+    point[2] = float_snapped(point[2], GetSnapGridSize());
   }
 }
 
index 218134f..4339286 100644 (file)
@@ -1701,10 +1701,9 @@ void LightWorld( void )
                SetupEnvelopes( qtrue, fastgrid );
                
                Sys_Printf( "--- TraceGrid ---\n" );
-               ps = patchShadows;
-               patchShadows = qfalse; /* patch shadows + lightgrid sampling tends to sample between patch and caulk, so let's turn that off for now FIXME */
+               inGrid = qtrue;
                RunThreadsOnIndividual( numRawGridPoints, qtrue, TraceGrid );
-               patchShadows = ps;
+               inGrid = qfalse;
                Sys_Printf( "%d x %d x %d = %d grid\n",
                        gridBounds[ 0 ], gridBounds[ 1 ], gridBounds[ 2 ], numBSPGridPoints );
                
@@ -1800,10 +1799,9 @@ void LightWorld( void )
                        gridBoundsCulled = 0;
                        
                        Sys_Printf( "--- BounceGrid ---\n" );
-                       ps = patchShadows;
-                       patchShadows = qfalse; /* patch shadows + lightgrid sampling tends to sample between patch and caulk, so let's turn that off for now FIXME */
+                       inGrid = qtrue;
                        RunThreadsOnIndividual( numRawGridPoints, qtrue, TraceGrid );
-                       patchShadows = ps;
+                       inGrid = qfalse;
                        Sys_FPrintf( SYS_VRB, "%9d grid points envelope culled\n", gridEnvelopeCulled );
                        Sys_FPrintf( SYS_VRB, "%9d grid points bounds culled\n", gridBoundsCulled );
                }
index 3bd41b8..5bb9f53 100644 (file)
@@ -73,7 +73,7 @@ traceVert_t;
 typedef struct traceInfo_s
 {
        shaderInfo_t                            *si;
-       int                                                     surfaceNum, castShadows;
+       int                                                     surfaceNum, castShadows, skipGrid;
 }
 traceInfo_t;
 
@@ -144,7 +144,8 @@ static int AddTraceInfo( traceInfo_t *ti )
        {
                if( traceInfos[ num ].si == ti->si &&
                        traceInfos[ num ].surfaceNum == ti->surfaceNum &&
-                       traceInfos[ num ].castShadows == ti->castShadows )
+                       traceInfos[ num ].castShadows == ti->castShadows &&
+                       traceInfos[ num ].skipGrid == ti->skipGrid )
                        return num;
        }
        
@@ -974,6 +975,7 @@ static void PopulateWithBSPModel( bspModel_t *model, m4x4_t transform )
                ti.si = info->si;
                ti.castShadows = info->castShadows;
                ti.surfaceNum = model->firstBSPBrush + i;
+               ti.skipGrid = (ds->surfaceType == MST_PATCH);
                
                /* choose which node (normal or skybox) */
                if( info->parentSurfaceNum >= 0 )
@@ -1143,6 +1145,7 @@ static void PopulateWithPicoModel( int castShadows, picoModel_t *model, m4x4_t t
                /* setup trace info */
                ti.castShadows = castShadows;
                ti.surfaceNum = -1;
+               ti.skipGrid = qtrue; // also ignore picomodels when skipping patches
                
                /* setup trace winding */
                memset( &tw, 0, sizeof( tw ) );
@@ -1426,7 +1429,7 @@ qboolean TraceTriangle( traceInfo_t *ti, traceTriangle_t *tt, trace_t *trace )
                if( ti->castShadows != 1 )
                        return qfalse;
        }
-       
+
        /* receive shadows from same group and worldspawn group */
        else if( trace->recvShadows > 1 )
        {
@@ -1442,6 +1445,13 @@ qboolean TraceTriangle( traceInfo_t *ti, traceTriangle_t *tt, trace_t *trace )
                        return qfalse;
        }
        
+       /* skip patches when doing the grid (FIXME this is an ugly hack) */
+       if( inGrid )
+       {
+               if (ti->skipGrid)
+                       return qfalse;
+       }
+       
        /* begin calculating determinant - also used to calculate u parameter */
        CrossProduct( trace->direction, tt->edge2, pvec );
        
index 49710c1..44425df 100644 (file)
@@ -2223,6 +2223,7 @@ Q_EXTERN float                            gridScale Q_ASSIGN( 1.0f );
 Q_EXTERN float                         gridAmbientScale Q_ASSIGN( 1.0f );
 Q_EXTERN float                         gridDirectionality Q_ASSIGN( 1.0f );
 Q_EXTERN float                         gridAmbientDirectionality Q_ASSIGN( 0.0f );
+Q_EXTERN qboolean                      inGrid Q_ASSIGN(0);
 
 /* ydnar: lightmap gamma/compensation */
 Q_EXTERN float                         lightmapGamma Q_ASSIGN( 1.0f );