void ScalarFiniteElement<D> :: CalcDShape (const IntegrationPoint & ip, FlatMatrixFixWidth<D> dshape) const { static bool firsttime = true; if (firsttime) { cout << "WARNING: CalcDShape not overloaded for class, using numerical differentiation " << typeid(this).name() << ", ndof = " << ndof << endl; firsttime = false; } int nd = GetNDof(); int sdim = D; double eps = 2e-5; ArrayMem<double, 100> hm1(nd), hm2(nd), hm3(nd), hm4(nd); FlatVector<> shape1(nd, &hm1[0]), shape2(nd, &hm2[0]), shape3(nd, &hm3[0]), shape4(nd, &hm4[0]); for (int i = 0; i < sdim; i++) { IntegrationPoint ip1 = ip; IntegrationPoint ip2 = ip; ip1(i) -= eps; ip2(i) += eps; CalcShape (ip1, shape1); CalcShape (ip2, shape2); ip1(i) -= eps; ip2(i) += eps; CalcShape (ip1, shape3); CalcShape (ip2, shape4); for (int j = 0; j < nd; j++) dshape(j, i) = 2/(3*eps) * (shape2(j) - shape1(j)) -1/(12*eps) * (shape4(j) - shape3(j)); } }
void TERRAIN::GenerateRandomTerrain(int numPatches) { try { Release(); //Create two heightmaps and multiply them m_pHeightMap = new HEIGHTMAP(m_size, 20.0f); HEIGHTMAP hm2(m_size, 2.0f); m_pHeightMap->CreateRandomHeightMap(rand()%2000, 1.0f, 0.7f, 7); hm2.CreateRandomHeightMap(rand()%2000, 2.5f, 0.8f, 3); hm2.Cap(hm2.m_maxHeight * 0.4f); *m_pHeightMap *= hm2; hm2.Release(); //Add objects HEIGHTMAP hm3(m_size, 1.0f); hm3.CreateRandomHeightMap(rand()%1000, 5.5f, 0.9f, 7); for(int y=0;y<m_size.y;y++) for(int x=0;x<m_size.x;x++) { if(m_pHeightMap->GetHeight(x, y) == 0.0f && hm3.GetHeight(x, y) > 0.7f && rand()%6 == 0) AddObject(0, INTPOINT(x, y)); //Tree else if(m_pHeightMap->GetHeight(x, y) >= 1.0f && hm3.GetHeight(x, y) > 0.9f && rand()%20 == 0) AddObject(1, INTPOINT(x, y)); //Stone } hm3.Release(); InitPathfinding(); CreatePatches(numPatches); CalculateAlphaMaps(); CalculateLightMap(false); } catch(...) { debug.Print("Error in TERRAIN::GenerateRandomTerrain()"); } }
void TERRAIN::GenerateRandomTerrain(int numPatches) { try { Release(); //Create two heightmaps and multiply them m_pHeightMap = new HEIGHTMAP(m_size, 15.0f); HEIGHTMAP hm2(m_size, 30.0f); m_pHeightMap->CreateRandomHeightMap(rand()%2000, 2.5f, 0.5f, 8); hm2.CreateRandomHeightMap(rand()%2000, 2.5f, 0.7f, 3); hm2.Cap(hm2.m_maxHeight * 0.4f); *m_pHeightMap *= hm2; hm2.Release(); CreatePatches(numPatches); } catch(...) { debug.Print("Error in TERRAIN::GenerateRandomTerrain()"); } }