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
}
int g_grid_power = GridPower_forGridDefault(g_grid_default);
+bool g_grid_snap = true;
+
int Grid_getPower()
{
return g_grid_power;
float g_gridsize = GridSize_forGridPower(g_grid_power);
+float GetSnapGridSize()
+{
+ return g_grid_snap ? g_gridsize : 0;
+}
+
float GetGridSize()
{
return g_gridsize;
void setGridPower(GridPower power)
{
+ g_grid_snap = true;
g_gridsize = GridSize_forGridPower(power);
g_gridMenu0125.m_item.update();
void GridPrev()
{
+ g_grid_snap = true;
if(g_grid_power > GRIDPOWER_0125)
{
setGridPower(static_cast<GridPower>(--g_grid_power));
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));
command_connect_accelerator("ToggleGrid");
command_connect_accelerator("GridDown");
command_connect_accelerator("GridUp");
+ command_connect_accelerator("ToggleGridSnap");
}
void Grid_constructPreferences(PreferencesPage& page)
#include "signal/signalfwd.h"
+float GetSnapGridSize();
float GetGridSize();
int Grid_getPower();
// 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);
{
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;
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);
}
current = vector3_subtracted(current, m_start);
translation_local2object(current, current, manip2object);
- vector3_snap(current, GetGridSize());
+ vector3_snap(current, GetSnapGridSize());
m_translatable.translate(current);
}
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],
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],
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)
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);
}
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();
{
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());
}
}
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 );
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 );
}
typedef struct traceInfo_s
{
shaderInfo_t *si;
- int surfaceNum, castShadows;
+ int surfaceNum, castShadows, skipGrid;
}
traceInfo_t;
{
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;
}
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 )
/* 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 ) );
if( ti->castShadows != 1 )
return qfalse;
}
-
+
/* receive shadows from same group and worldspawn group */
else if( trace->recvShadows > 1 )
{
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 );
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 );