void CSplinePatch::SetupPatchQuery( float s, float t ) { m_is = (int)s; m_it = (int)t; if( m_is >= m_Width ) { m_is = m_Width - 1; m_fs = 1.0f; } else { m_fs = s - m_is; } if( m_it >= m_Height ) { m_it = m_Height - 1; m_ft = 1.0f; } else { m_ft = t - m_it; } ComputeIndices( ); // The patch equation is: // px = S * M * Gx * M^T * T^T // py = S * M * Gy * M^T * T^T // pz = S * M * Gz * M^T * T^T // where S = [s^3 s^2 s 1], T = [t^3 t^2 t 1] // M is the patch type matrix, in my case I'm using a catmull-rom // G is the array of control points. rows have constant t // We're gonna cache off S * M and M^T * T^T... Vector4D svec, tvec; float fs2 = m_fs * m_fs; svec[0] = fs2 * m_fs; svec[1] = fs2; svec[2] = m_fs; svec[3] = 1.0f; float ft2 = m_ft * m_ft; tvec[0] = ft2 * m_ft; tvec[1] = ft2; tvec[2] = m_ft; tvec[3] = 1.0f; // This sets up the catmull rom matrix based on the blend factor!! // we can go from linear to curvy! s_CatmullRom.Init( -0.5 * m_LinearFactor, 1.5 * m_LinearFactor, -1.5 * m_LinearFactor, 0.5 * m_LinearFactor, m_LinearFactor, -2.5 * m_LinearFactor, 2 * m_LinearFactor, -0.5 * m_LinearFactor, -0.5 * m_LinearFactor, -1 + m_LinearFactor, 1 - 0.5 * m_LinearFactor, 0, 0, 1, 0, 0 ); Vector4DMultiplyTranspose( s_CatmullRom, svec, m_SVec ); Vector4DMultiplyTranspose( s_CatmullRom, tvec, m_TVec ); }
HeightMapPatch::HeightMapPatch(int xStart, int zStart, HeightMapNode* t) : terrain(t), LOD(1), geomorphingScale(1), visible(false), xStart(xStart), zStart(zStart) { xEnd = xStart + PATCH_EDGE_VERTICES; zEnd = zStart + PATCH_EDGE_VERTICES; xEndMinusOne = xEnd - 1; zEndMinusOne = zEnd - 1; edgeLength = (xEndMinusOne - xStart) * t->GetWidthScale(); ComputeIndices(); SetupBoundingBox(); }
void LMDirectionalIntegralDistanceImage::Construct(Image<float> *image, float dx, float dy) { if (abs(dx) > abs(dy)) { ds_ = dy / (dx + 1e-9f); xindexed_ = 1; } else { ds_ = dx / (dy + 1e-9f); xindexed_ = 0; } // Compute secant factor_ = sqrt(ds_*ds_ + 1); ComputeIndices(); ComputeII(image); }
void C_EnergyWave::ComputePoint( float s, float t, Vector& pt, Vector& normal, float& opacity ) { int is = (int)s; int it = (int)t; if( is >= EWAVE_NUM_HORIZONTAL_POINTS ) is -= 1; if( it >= EWAVE_NUM_VERTICAL_POINTS ) it -= 1; int idx[16]; ComputeIndices( is, it, idx ); // The patch equation is: // px = S * M * Gx * M^T * T^T // py = S * M * Gy * M^T * T^T // pz = S * M * Gz * M^T * T^T // where S = [s^3 s^2 s 1], T = [t^3 t^2 t 1] // M is the patch type matrix, in my case I'm using a catmull-rom // G is the array of control points. rows have constant t static VMatrix catmullRom( -0.5, 1.5, -1.5, 0.5, 1, -2.5, 2, -0.5, -0.5, 0, 0.5, 0, 0, 1, 0, 0 ); VMatrix controlPointsX, controlPointsY, controlPointsZ, controlPointsO; Vector pos; for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { const Vector& v = m_EWaveEffect.GetPoint( idx[i * 4 + j] ); controlPointsX[j][i] = v.x; controlPointsY[j][i] = v.y; controlPointsZ[j][i] = v.z; controlPointsO[j][i] = m_EWaveEffect.ComputeOpacity( v, GetAbsOrigin() ); } } float fs = s - is; float ft = t - it; VMatrix temp, mgm[4]; MatrixTranspose( catmullRom, temp ); MatrixMultiply( controlPointsX, temp, mgm[0] ); MatrixMultiply( controlPointsY, temp, mgm[1] ); MatrixMultiply( controlPointsZ, temp, mgm[2] ); MatrixMultiply( controlPointsO, temp, mgm[3] ); MatrixMultiply( catmullRom, mgm[0], mgm[0] ); MatrixMultiply( catmullRom, mgm[1], mgm[1] ); MatrixMultiply( catmullRom, mgm[2], mgm[2] ); MatrixMultiply( catmullRom, mgm[3], mgm[3] ); Vector4D svec, tvec; float ft2 = ft * ft; tvec[0] = ft2 * ft; tvec[1] = ft2; tvec[2] = ft; tvec[3] = 1.0f; float fs2 = fs * fs; svec[0] = fs2 * fs; svec[1] = fs2; svec[2] = fs; svec[3] = 1.0f; Vector4D tmp; Vector4DMultiply( mgm[0], tvec, tmp ); pt[0] = DotProduct4D( tmp, svec ); Vector4DMultiply( mgm[1], tvec, tmp ); pt[1] = DotProduct4D( tmp, svec ); Vector4DMultiply( mgm[2], tvec, tmp ); pt[2] = DotProduct4D( tmp, svec ); Vector4DMultiply( mgm[3], tvec, tmp ); opacity = DotProduct4D( tmp, svec ); if ((s == 0.0f) || (t == 0.0f) || (s == (EWAVE_NUM_HORIZONTAL_POINTS-1.0f)) || (t == (EWAVE_NUM_VERTICAL_POINTS-1.0f)) ) { opacity = 0.0f; } if ((s <= 0.3) || (t < 0.3)) { opacity *= 0.35f; } if ((s == (EWAVE_NUM_HORIZONTAL_POINTS-0.7f)) || (t == (EWAVE_NUM_VERTICAL_POINTS-0.7f)) ) { opacity *= 0.35f; } if (opacity < 0.0f) opacity = 0.0f; else if (opacity > 255.0f) opacity = 255.0f; // Normal computation Vector4D dsvec, dtvec; dsvec[0] = 3.0f * fs2; dsvec[1] = 2.0f * fs; dsvec[2] = 1.0f; dsvec[3] = 0.0f; dtvec[0] = 3.0f * ft2; dtvec[1] = 2.0f * ft; dtvec[2] = 1.0f; dtvec[3] = 0.0f; Vector ds, dt; Vector4DMultiply( mgm[0], tvec, tmp ); ds[0] = DotProduct4D( tmp, dsvec ); Vector4DMultiply( mgm[1], tvec, tmp ); ds[1] = DotProduct4D( tmp, dsvec ); Vector4DMultiply( mgm[2], tvec, tmp ); ds[2] = DotProduct4D( tmp, dsvec ); Vector4DMultiply( mgm[0], dtvec, tmp ); dt[0] = DotProduct4D( tmp, svec ); Vector4DMultiply( mgm[1], dtvec, tmp ); dt[1] = DotProduct4D( tmp, svec ); Vector4DMultiply( mgm[2], dtvec, tmp ); dt[2] = DotProduct4D( tmp, svec ); CrossProduct( ds, dt, normal ); VectorNormalize( normal ); }