From: divverent Date: Sun, 4 Oct 2009 19:15:55 +0000 (+0000) Subject: ToggleGridSnap command (beware of it) X-Git-Tag: svn-r421~19 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=commitdiff_plain;h=04a61593c35c583ea966469d10dd92040cd7da64 ToggleGridSnap command (beware of it) git-svn-id: svn://svn.icculus.org/netradiant/trunk@401 61c419a2-8eb2-4b30-bcec-8cead039b335 --- diff --git a/libs/math/vector.h b/libs/math/vector.h index 57022dbb..075c58fe 100644 --- a/libs/math/vector.h +++ b/libs/math/vector.h @@ -105,6 +105,8 @@ template 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 } diff --git a/radiant/grid.cpp b/radiant/grid.cpp index e93ce401..f25a0d92 100644 --- a/radiant/grid.cpp +++ b/radiant/grid.cpp @@ -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(--g_grid_power)); @@ -186,18 +195,26 @@ void GridPrev() void GridNext() { + g_grid_snap = true; if(g_grid_power < GRIDPOWER_256) { setGridPower(static_cast(++g_grid_power)); } } +void ToggleGridSnap() +{ + g_grid_snap = !g_grid_snap; + GridChangeNotify(); +} void Grid_registerCommands() { GlobalCommands_insert("GridDown", FreeCaller(), Accelerator('[')); GlobalCommands_insert("GridUp", FreeCaller(), Accelerator(']')); + GlobalCommands_insert("ToggleGridSnap", FreeCaller()); + 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) diff --git a/radiant/grid.h b/radiant/grid.h index cf2671e9..42dfd703 100644 --- a/radiant/grid.h +++ b/radiant/grid.h @@ -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(); diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 1555fa82..a441e03c 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -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; diff --git a/radiant/selection.cpp b/radiant/selection.cpp index f4b21186..3b477990 100644 --- a/radiant/selection.cpp +++ b/radiant/selection.cpp @@ -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) diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index f82b99ba..06a9e4a8 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -966,7 +966,7 @@ void XYWnd::DropClipPoint(int pointx, int pointy) g_clip_viewtype = static_cast(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()); } } diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index 218134f9..4339286c 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -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 ); } diff --git a/tools/quake3/q3map2/light_trace.c b/tools/quake3/q3map2/light_trace.c index 3bd41b88..5bb9f530 100644 --- a/tools/quake3/q3map2/light_trace.c +++ b/tools/quake3/q3map2/light_trace.c @@ -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 ); diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 49710c10..44425df0 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -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 );