// -------------------------------------------------------------------------- // // void Test_Mathutils::testElementwiseVectorVectorDoubleSubtraction() { // Setup. std::vector<double> vec0(4); vec0[0] = 1.1; vec0[1] = 2.2; vec0[2] = 3.3; vec0[3] = -7.7; std::vector<double> vec1(4); vec1[0] = 2.1; vec1[1] = 3.2; vec1[2] = -4.3; vec1[3] = -11.7; // Take a reference. const std::vector<double> ref = vec0; const std::vector<double> ref1 = vec1; // Call. vsub(vec0, ref1); // Check. CPPUNIT_ASSERT_EQUAL(static_cast<int>(vec0.size()), static_cast<int>(ref.size())); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[0], ref[0]-vec1[0], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[1], ref[1]-vec1[1], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[2], ref[2]-vec1[2], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[3], ref[3]-vec1[3], EPS ); }
// -------------------------------------------------------------------------- // // void Test_Mathutils::testVectorNormalization() { // Setup. std::vector<double> vec0(4); vec0[0] = 1.1; vec0[1] = 2.2; vec0[2] = 3.3; vec0[3] = 7.7; const double norm0 = vec0[0] + vec0[1] + vec0[2] + vec0[3]; std::vector<double> vec1(4); vec1[0] = 2.1; vec1[1] = 3.2; vec1[2] = 4.3; vec1[3] = 11.7; const double norm1 = vec1[0] + vec1[1] + vec1[2] + vec1[3]; // Take a reference. const std::vector<double> ref = vec0; const std::vector<double> ref1 = vec1; // Call. vnormalize(vec0, ref1); // Check. CPPUNIT_ASSERT_EQUAL(static_cast<int>(vec0.size()), static_cast<int>(ref.size())); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[0], ref[0]*norm1/norm0, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[1], ref[1]*norm1/norm0, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[2], ref[2]*norm1/norm0, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[3], ref[3]*norm1/norm0, EPS ); }
// -------------------------------------------------------------------------- // // void Test_Mathutils::testElementwiseVectorVectorIntSubtraction() { // Setup. std::vector<int> vec0(4); vec0[0] = 1; vec0[1] = 2; vec0[2] = 3; vec0[3] = -7; std::vector<int> vec1(4); vec1[0] = 2; vec1[1] = 3; vec1[2] = -4; vec1[3] = -11; // Take a reference. const std::vector<int> ref = vec0; const std::vector<int> ref1 = vec1; // Call. vsub(vec0, ref1); // Check. CPPUNIT_ASSERT_EQUAL(static_cast<int>(vec0.size()), static_cast<int>(ref.size())); CPPUNIT_ASSERT_EQUAL( vec0[0], ref[0]-vec1[0] ); CPPUNIT_ASSERT_EQUAL( vec0[1], ref[1]-vec1[1] ); CPPUNIT_ASSERT_EQUAL( vec0[2], ref[2]-vec1[2] ); CPPUNIT_ASSERT_EQUAL( vec0[3], ref[3]-vec1[3] ); }
// -------------------------------------------------------------------------- // // void Test_Mathutils::testElementwiseVectorVectorSubtractionDoubleOperator() { // Setup. std::vector<double> vec0(4); vec0[0] = 1.1; vec0[1] = 2.2; vec0[2] = 3.3; vec0[3] = -7.7; std::vector<double> vec1(4); vec1[0] = 2.1; vec1[1] = 3.2; vec1[2] = -4.3; vec1[3] = -11.7; // Call. std::vector<double> v1 = vec0-vec1; // Check. CPPUNIT_ASSERT_EQUAL(static_cast<int>(v1.size()), static_cast<int>(vec0.size())); CPPUNIT_ASSERT_DOUBLES_EQUAL( v1[0], vec0[0]-vec1[0], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( v1[1], vec0[1]-vec1[1], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( v1[2], vec0[2]-vec1[2], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( v1[3], vec0[3]-vec1[3], EPS ); }
// -------------------------------------------------------------------------- // // void Test_Mathutils::testElementwiseVectorVectorSubtractionIntOperator() { // Setup. std::vector<int> vec0(4); vec0[0] = 1; vec0[1] = 2; vec0[2] = 3; vec0[3] = -7; std::vector<int> vec1(4); vec1[0] = 2; vec1[1] = 3; vec1[2] = -4; vec1[3] = -11; // Call. std::vector<int> v1 = vec0-vec1; // Check. CPPUNIT_ASSERT_EQUAL(static_cast<int>(v1.size()), static_cast<int>(vec0.size())); CPPUNIT_ASSERT_EQUAL( v1[0], vec0[0]-vec1[0] ); CPPUNIT_ASSERT_EQUAL( v1[1], vec0[1]-vec1[1] ); CPPUNIT_ASSERT_EQUAL( v1[2], vec0[2]-vec1[2] ); CPPUNIT_ASSERT_EQUAL( v1[3], vec0[3]-vec1[3] ); }
/* ============= FillBuffer ============= */ void CollisionElementPolygon::FillBuffer( const Vec2& lightPosition, const Vec2& size, LBuffer *buffer, LBufferCacheEntity *cache ) { if( this->pointsResult.size() < 2 ) { return; } PointList::const_iterator iter = this->pointsResult.begin() + 1, iterEnd = this->pointsResult.end(), iterPrev = this->pointsResult.begin(); for(; iter != iterEnd; ++iter ) { Vec2 pointCurrent( iter->x, -iter->y ); Vec2 pointPrev( iterPrev->x, -iterPrev->y ); Vec2 vec( pointCurrent - pointPrev ); vec.Rotate90CCW(); if( vec.Dot( lightPosition - pointCurrent ) < 0.0f ) { //this->AddEdgeToBuffer( lightPosition, buffer, pointCurrent, pointPrev, cache ); Vec2 vec0( pointCurrent - pointPrev ), vec1( pointPrev - pointCurrent ) ; vec0.NormalizeFast(); vec1.NormalizeFast(); vec.NormalizeFast(); //vec *= ( 1.0f + this->epsilon ); //углубляем ребро на 1+epsilon vec0 *= ( 1.0f + this->epsilon ); //удлинняем ребро на 1+epsilon vec1 *= ( 1.0f + this->epsilon ); Vec2 resVec0 = pointCurrent + vec0 + vec; Vec2 resVec1 = pointPrev + vec1 + vec; this->AddEdgeToBuffer( lightPosition, buffer, resVec0, resVec1, cache ); } iterPrev = iter; } }//FillBuffer
/* * Constructor for the player; initialize everything here. * The side your AI is * on (BLACK or WHITE) is passed in as "side". The constructor must finish * within 30 seconds. */ Player::Player(Side side) { // Will be set to true in test_minimax.cpp, will take effect in doMove() testingMinimax = false; // 0=random; 1=weighted; 2=minimax with alpha-beta; // 3=mobility (switch to minimaxPlayer at end); // 4=minimaxPlayer; 5=alternating this->method = METHOD; this->myBoard = Board(); this->mySide = side; if (side == BLACK) { this->otherSide = WHITE; } else { this->otherSide = BLACK; } // set up for chosen method if (method == 0) {// RANDOM METHOD srand(time(NULL)); } else if (method == 1) {// WEIGHT METHOD if (debug) { std::cerr << "Setting up weights. "; } int arr0[8] = {100, -10, 11, 6, 6, 11, -10, 100}; int arr1[8] = {-10, -20, 1, 2, 2, 1, -20, -10}; int arr2[8] = {10, 1, 5, 4, 4, 5, 1, 10}; int arr3[8] = {6, 2, 4, 2, 2, 4, 2, 6}; std::vector<int> vec0(arr0, arr0 + 7); std::vector<int> vec1(arr1, arr1 + 7); std::vector<int> vec2(arr2, arr2 + 7); std::vector<int> vec3(arr3, arr3 + 7); this->weights.push_back(vec0); this->weights.push_back(vec1); this->weights.push_back(vec2); this->weights.push_back(vec3); this->weights.push_back(vec3); this->weights.push_back(vec2); this->weights.push_back(vec1); this->weights.push_back(vec0); } else { this->depth = DEPTH; this->switcher = 0; } }
// -------------------------------------------------------------------------- // // void Test_Mathutils::testElementwiseVectorDoubleSquare() { // Setup. std::vector<double> vec0(4); vec0[0] = 1.1; vec0[1] = 2.2; vec0[2] = 3.3; vec0[3] = -7.7; // Take a reference. const std::vector<double> ref = vec0; // Call. vsquare(vec0); // Check. CPPUNIT_ASSERT_EQUAL(static_cast<int>(vec0.size()), static_cast<int>(ref.size())); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[0], ref[0]*ref[0], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[1], ref[1]*ref[1], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[2], ref[2]*ref[2], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( vec0[3], ref[3]*ref[3], EPS ); }
btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btVector3& localDir) const { switch (m_shapeType) { case SPHERE_SHAPE_PROXYTYPE: { return btVector3(0,0,0); } case BOX_SHAPE_PROXYTYPE: { btBoxShape* convexShape = (btBoxShape*)this; const btVector3& halfExtents = convexShape->getImplicitShapeDimensions(); #if defined( __APPLE__ ) && (defined( BT_USE_SSE )||defined( BT_USE_NEON )) #if defined( BT_USE_SSE ) return btVector3( _mm_xor_ps( _mm_and_ps( localDir.mVec128, (__m128){-0.0f, -0.0f, -0.0f, -0.0f }), halfExtents.mVec128 )); #elif defined( BT_USE_NEON ) return btVector3( (float32x4_t) (((uint32x4_t) localDir.mVec128 & (uint32x4_t){ 0x80000000, 0x80000000, 0x80000000, 0x80000000}) ^ (uint32x4_t) halfExtents.mVec128 )); #else #error unknown vector arch #endif #else return btVector3(btFsels(localDir.x(), halfExtents.x(), -halfExtents.x()), btFsels(localDir.y(), halfExtents.y(), -halfExtents.y()), btFsels(localDir.z(), halfExtents.z(), -halfExtents.z())); #endif } case TRIANGLE_SHAPE_PROXYTYPE: { btTriangleShape* triangleShape = (btTriangleShape*)this; btVector3 dir(localDir.getX(),localDir.getY(),localDir.getZ()); btVector3* vertices = &triangleShape->m_vertices1[0]; btVector3 dots = dir.dot3(vertices[0], vertices[1], vertices[2]); btVector3 sup = vertices[dots.maxAxis()]; return btVector3(sup.getX(),sup.getY(),sup.getZ()); } case CYLINDER_SHAPE_PROXYTYPE: { btCylinderShape* cylShape = (btCylinderShape*)this; //mapping of halfextents/dimension onto radius/height depends on how cylinder local orientation is (upAxis) btVector3 halfExtents = cylShape->getImplicitShapeDimensions(); btVector3 v(localDir.getX(),localDir.getY(),localDir.getZ()); int cylinderUpAxis = cylShape->getUpAxis(); int XX(1),YY(0),ZZ(2); switch (cylinderUpAxis) { case 0: { XX = 1; YY = 0; ZZ = 2; } break; case 1: { XX = 0; YY = 1; ZZ = 2; } break; case 2: { XX = 0; YY = 2; ZZ = 1; } break; default: btAssert(0); break; }; btScalar radius = halfExtents[XX]; btScalar halfHeight = halfExtents[cylinderUpAxis]; btVector3 tmp; btScalar d ; btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]); if (s != btScalar(0.0)) { d = radius / s; tmp[XX] = v[XX] * d; tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; tmp[ZZ] = v[ZZ] * d; return btVector3(tmp.getX(),tmp.getY(),tmp.getZ()); } else { tmp[XX] = radius; tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; tmp[ZZ] = btScalar(0.0); return btVector3(tmp.getX(),tmp.getY(),tmp.getZ()); } } case CAPSULE_SHAPE_PROXYTYPE: { btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ()); btCapsuleShape* capsuleShape = (btCapsuleShape*)this; btScalar halfHeight = capsuleShape->getHalfHeight(); int capsuleUpAxis = capsuleShape->getUpAxis(); btScalar radius = capsuleShape->getRadius(); btVector3 supVec(0,0,0); btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); btVector3 vec = vec0; btScalar lenSqr = vec.length2(); if (lenSqr < btScalar(0.0001)) { vec.setValue(1,0,0); } else { btScalar rlen = btScalar(1.) / btSqrt(lenSqr ); vec *= rlen; } btVector3 vtx; btScalar newDot; { btVector3 pos(0,0,0); pos[capsuleUpAxis] = halfHeight; //vtx = pos +vec*(radius); vtx = pos +vec*(radius) - vec * capsuleShape->getMarginNV(); newDot = vec.dot(vtx); if (newDot > maxDot) { maxDot = newDot; supVec = vtx; } } { btVector3 pos(0,0,0); pos[capsuleUpAxis] = -halfHeight; //vtx = pos +vec*(radius); vtx = pos +vec*(radius) - vec * capsuleShape->getMarginNV(); newDot = vec.dot(vtx); if (newDot > maxDot) { maxDot = newDot; supVec = vtx; } } return btVector3(supVec.getX(),supVec.getY(),supVec.getZ()); } case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE: { btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this; btVector3* points = convexPointCloudShape->getUnscaledPoints (); int numPoints = convexPointCloudShape->getNumPoints (); return convexHullSupport (localDir, points, numPoints,convexPointCloudShape->getLocalScalingNV()); } case CONVEX_HULL_SHAPE_PROXYTYPE: { btConvexHullShape* convexHullShape = (btConvexHullShape*)this; btVector3* points = convexHullShape->getUnscaledPoints(); int numPoints = convexHullShape->getNumPoints (); return convexHullSupport (localDir, points, numPoints,convexHullShape->getLocalScalingNV()); } default: #ifndef __SPU__ return this->localGetSupportingVertexWithoutMargin (localDir); #else btAssert (0); #endif } // should never reach here btAssert (0); return btVector3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f)); }
int MapgenMath::generateTerrain() { MapNode n_air(CONTENT_AIR, LIGHT_SUN), n_water_source(c_water_source, LIGHT_SUN); MapNode n_stone(c_stone, LIGHT_SUN); u32 index = 0; v3s16 em = vm->m_area.getExtent(); #if 1 /* debug v3f vec0 = (v3f(node_min.X, node_min.Y, node_min.Z) - center) * scale ; errorstream << " X=" << node_min.X << " Y=" << node_min.Y << " Z=" << node_min.Z //<< " N="<< mengersponge(vec0.X, vec0.Y, vec0.Z, distance, iterations) << " N=" << (*func)(vec0.X, vec0.Y, vec0.Z, distance, iterations) << " Sc=" << scale << " gen=" << params["generator"].asString() << " J=" << Json::FastWriter().write(params) << std::endl; */ for (s16 z = node_min.Z; z <= node_max.Z; z++) { for (s16 x = node_min.X; x <= node_max.X; x++, index++) { //Biome *biome = bmgr->biomes[biomemap[index]]; u32 i = vm->m_area.index(x, node_min.Y, z); for (s16 y = node_min.Y; y <= node_max.Y; y++) { v3f vec = (v3f(x, y, z) - center) * scale ; double d = (*func)(vec.X, vec.Y, vec.Z, distance, iterations); if ((!invert && d > 0) || (invert && d == 0) ) { if (vm->m_data[i].getContent() == CONTENT_IGNORE) // vm->m_data[i] = (y > water_level + biome->filler) ? // MapNode(biome->c_filler) : n_stone; vm->m_data[i] = n_stone; } else if (y <= water_level) { vm->m_data[i] = n_water_source; } else { vm->m_data[i] = n_air; } vm->m_area.add_y(em, i, 1); } } } #endif #if 0 // mandelbulber, unfinished but works sFractal par; par.doubles.N = 10; par.doubles.power = 9.0; par.doubles.foldingSphericalFixed = 1.0; par.doubles.foldingSphericalMin = 0.5; //no par.formula = smoothMandelbox; par.doubles.N = 40; invert = 0;//no par.mandelbox.doubles.sharpness = 3.0; par.mandelbox.doubles.scale = 1; par.mandelbox.doubles.sharpness = 2; par.mandelbox.doubles.foldingLimit = 1.0; par.mandelbox.doubles.foldingValue = 2; //ok par.formula = mandelboxVaryScale4D; par.doubles.N = 50; scale = 5; invert = 1; //ok par.mandelbox.doubles.vary4D.scaleVary = 0.1; par.mandelbox.doubles.vary4D.fold = 1; par.mandelbox.doubles.vary4D.rPower = 1; par.mandelbox.doubles.vary4D.minR = 0.5; par.mandelbox.doubles.vary4D.wadd = 0; par.doubles.constantFactor = 1.0; par.formula = menger_sponge; par.doubles.N = 15; invert = 0; size = 30000; center = v3f(-size / 2, -size + (-2 * -invert), 2); scale = (double)1 / size; //ok //double tresh = 1.5; //par.formula = mandelbulb2; par.doubles.N = 10; scale = (double)1/size; invert=1; center = v3f(5,-size-5,0); //ok //par.formula = hypercomplex; par.doubles.N = 20; scale = 0.0001; invert=1; center = v3f(0,-10001,0); //(double)50 / max_r; //no par.formula = trig_DE; par.doubles.N = 5; scale = (double)10; invert=1; //no par.formula = trig_optim; scale = (double)10; par.doubles.N = 4; //par.formula = mandelbulb2; scale = (double)1/10000; par.doubles.N = 10; invert = 1; center = v3f(1,-4201,1); //ok // no par.formula = tglad; //par.formula = xenodreambuie; par.juliaMode = 1; par.doubles.julia.x = -1; par.doubles.power = 2.0; center=v3f(-size/2,-size/2-5,5); //ok par.mandelbox.doubles.vary4D.scaleVary = 0.1; par.mandelbox.doubles.vary4D.fold = 1; par.mandelbox.doubles.vary4D.minR = 0.5; par.mandelbox.doubles.vary4D.rPower = 1; par.mandelbox.doubles.vary4D.wadd = 0; //no par.formula = mandelboxVaryScale4D; par.doubles.cadd = -1.3; //par.formula = aexion; // ok but center //par.formula = benesi; par.doubles.N = 10; center = v3f(0,0,0); invert = 0; //ok // par.formula = bristorbrot; //ok v3f vec0(node_min.X, node_min.Y, node_min.Z); vec0 = (vec0 - center) * scale ; errorstream << " X=" << node_min.X << " Y=" << node_min.Y << " Z=" << node_min.Z << " N=" << Compute<normal>(CVector3(vec0.X, vec0.Y, vec0.Z), par) //<<" F="<< Compute<fake_AO>(CVector3(node_min.X,node_min.Y,node_min.Z), par) //<<" L="<<node_min.getLength()<< " -="<<node_min.getLength() - Compute<normal>(CVector3(node_min.X,node_min.Y,node_min.Z), par) << " Sc=" << scale << std::endl; for (s16 z = node_min.Z; z <= node_max.Z; z++) for (s16 y = node_min.Y; y <= node_max.Y; y++) { u32 i = vm->m_area.index(node_min.X, y, z); for (s16 x = node_min.X; x <= node_max.X; x++) { v3f vec(x, y, z); vec = (vec - center) * scale ; //double d = Compute<fake_AO>(CVector3(x,y,z), par); double d = Compute<normal>(CVector3(vec.X, vec.Y, vec.Z), par); //if (d>0) // errorstream << " d=" << d <<" v="<< vec.getLength()<< " -="<< vec.getLength() - d <<" yad=" //<< Compute<normal>(CVector3(x,y,z), par) //<< std::endl; if ((!invert && d > 0) || (invert && d == 0)/*&& vec.getLength() - d > tresh*/ ) { if (vm->m_data[i].getContent() == CONTENT_IGNORE) vm->m_data[i] = n_stone; } else { vm->m_data[i] = n_air; } i++; } } #endif return 0; }
void CSpeedTreeWrapper::RenderLeaves(void) const { #ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_LeafGeometry, -1, -1, 0); #endif m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_LeafGeometry); // update the LOD level vertex arrays we need #if defined(WRAPPER_USE_GPU_LEAF_PLACEMENT) && defined(WRAPPER_USE_GPU_WIND) // do nothing #else #if !defined WRAPPER_USE_NO_WIND || defined WRAPPER_USE_CPU_LEAF_PLACEMENT // might need to draw 2 LOD's for (unsigned int i = 0; i < 2; ++i) { // reference to leaves structure const CSpeedTreeRT::SGeometry::SLeaf* pLeaf = (i == 0) ? &m_pGeometryCache->m_sLeaves0 : &m_pGeometryCache->m_sLeaves1; int unLod = pLeaf->m_nDiscreteLodLevel; #if defined WRAPPER_USE_GPU_LEAF_PLACEMENT if (pLeaf->m_bIsActive && !m_pLeavesUpdatedByCpu[unLod]) { // update the centers SFVFLeafVertex* pVertex = NULL; m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast<void**>(&pVertex), 0); for (unsigned int unLeaf = 0; unLeaf < pLeaf->m_usLeafCount; ++unLeaf) { D3DXVECTOR3 vecCenter(&(pLeaf->m_pCenterCoords[unLeaf * 3])); (pVertex++)->m_vPosition = vecCenter; // vertex 0 (pVertex++)->m_vPosition = vecCenter; // vertex 1 (pVertex++)->m_vPosition = vecCenter; // vertex 2 (pVertex++)->m_vPosition = vecCenter; // vertex 0 (pVertex++)->m_vPosition = vecCenter; // vertex 2 (pVertex++)->m_vPosition = vecCenter; // vertex 3 } m_pLeafVertexBuffer[unLod]->Unlock( ); m_pLeavesUpdatedByCpu[unLod] = true; } #else if (pLeaf->m_bIsActive) { // update the vertices SFVFLeafVertex* pVertex = NULL; m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast<void**>(&pVertex),0); for (unsigned int unLeaf = 0; unLeaf < pLeaf->m_usLeafCount; ++unLeaf) { D3DXVECTOR3 vecCenter(&(pLeaf->m_pCenterCoords[unLeaf * 3])); D3DXVECTOR3 vec0(&pLeaf->m_pLeafMapCoords[unLeaf][0]); D3DXVECTOR3 vec1(&pLeaf->m_pLeafMapCoords[unLeaf][4]); D3DXVECTOR3 vec2(&pLeaf->m_pLeafMapCoords[unLeaf][8]); D3DXVECTOR3 vec3(&pLeaf->m_pLeafMapCoords[unLeaf][12]); (pVertex++)->m_vPosition = vecCenter + vec0; // vertex 0 (pVertex++)->m_vPosition = vecCenter + vec1; // vertex 1 (pVertex++)->m_vPosition = vecCenter + vec2; // vertex 2 (pVertex++)->m_vPosition = vecCenter + vec0; // vertex 0 (pVertex++)->m_vPosition = vecCenter + vec2; // vertex 2 (pVertex++)->m_vPosition = vecCenter + vec3; // vertex 3 } m_pLeafVertexBuffer[unLod]->Unlock( ); } #endif } #endif #endif PositionTree( ); // might need to draw 2 LOD's for (unsigned int unLeafLevel = 0; unLeafLevel < 2; ++unLeafLevel) { const CSpeedTreeRT::SGeometry::SLeaf* pLeaf = (unLeafLevel == 0) ? &m_pGeometryCache->m_sLeaves0 : pLeaf = &m_pGeometryCache->m_sLeaves1; int unLod = pLeaf->m_nDiscreteLodLevel; // if this LOD is active and has leaves, draw it if (unLod > -1 && pLeaf->m_bIsActive && pLeaf->m_usLeafCount > 0) { m_pDx->SetStreamSource(0, m_pLeafVertexBuffer[unLod], 0, sizeof(SFVFLeafVertex)); m_pDx->SetRenderState(D3DRS_ALPHAREF, DWORD(pLeaf->m_fAlphaTestValue)); m_pDx->DrawPrimitive(D3DPT_TRIANGLELIST, 0, pLeaf->m_usLeafCount * 2); } } }
void CKWResearchWorkDoc::OnHelpTest() { // TODO: Add your command handler code here vector<Point_3> SamplePoints; GeometryAlgorithm::SampleCircle(Point_3(0,0,0),0.3,20,SamplePoints); FILE* pfile=fopen("circle0.contour","w"); for (unsigned int i=0;i<SamplePoints.size();i++) { fprintf(pfile,"%.3f %.3f %.3f\n",SamplePoints.at(i).x(),SamplePoints.at(i).y(),SamplePoints.at(i).z()); } fclose(pfile); Polygon_2 PolyTest; PolyTest.push_back(Point_2(0,0)); PolyTest.push_back(Point_2(1,1)); PolyTest.push_back(Point_2(2,0)); PolyTest.push_back(Point_2(2,2)); PolyTest.push_back(Point_2(0,2)); Point_2 ResultPoint; bool bResult=GeometryAlgorithm::GetArbiPointInPolygon(PolyTest,ResultPoint); DBWindowWrite("result point: %f %f\n",ResultPoint.x(),ResultPoint.y()); SparseMatrix LHMatrix(2); LHMatrix.m = 3; LHMatrix[0][0] = 2; LHMatrix[0][1] = -1; LHMatrix[0][2] = 1; LHMatrix[1][1] = 1; LHMatrix[1][2] = 1; SparseMatrix LHMatrixAT(LHMatrix.NCols()); CMath MathCompute; MathCompute.TAUCSFactorize(LHMatrix,LHMatrixAT); vector<vector<double>> RightMatB,ResultMat; vector<double> BRow; BRow.push_back(5);BRow.push_back(3); RightMatB.push_back(BRow); BRow.clear(); BRow.push_back(10);BRow.push_back(1); RightMatB.push_back(BRow); BRow.clear(); MathCompute.TAUCSComputeLSE(LHMatrixAT,RightMatB,ResultMat); return; int iVer=this->Mesh.size_of_vertices(); int iEdge=this->Mesh.size_of_halfedges(); int iFacet=this->Mesh.size_of_facets(); Polygon_2 BoundingPolygon0; Polygon_2 BoundingPolygon1; bool bSimple0=BoundingPolygon0.is_simple(); bool bSimple1=BoundingPolygon1.is_simple(); bool bConvex0=BoundingPolygon0.is_convex(); bool bConvex1=BoundingPolygon1.is_convex(); bool bOrien0=BoundingPolygon0.is_clockwise_oriented(); bool bOrien1=BoundingPolygon1.is_clockwise_oriented(); BoundingPolygon0.reverse_orientation(); BoundingPolygon1.reverse_orientation(); //float? bool bIntersect=CGAL::do_intersect(BoundingPolygon0,BoundingPolygon1); bool bCW=BoundingPolygon0.is_clockwise_oriented(); bool bConvex=BoundingPolygon0.is_convex(); Plane_3 plane(1,1,1,0); vector<vector<Point_3>> IntersectCurves; int iNum=GeometryAlgorithm::GetMeshPlaneIntersection(this->Mesh,plane,IntersectCurves); CMath CMathTest; CMathTest.testTAUCS(); // Vector_3 vec0(Point_3(0,0,1),Point_3(0,0,0)); Vector_3 vec0(Point_3(0,0,0),Point_3(0,0,1)); // Vector_3 vec0(0,0,1); // Vector_3 vec1(0,-1,-1); Vector_3 vec1(Point_3(0,0,0),Point_3(0,-1,-1)); double dAngle=GeometryAlgorithm::GetAngleBetweenTwoVectors3d(vec0,vec1); vector<double> number; number.push_back(2); number.push_back(4); number.push_back(4); number.push_back(4); number.push_back(5); number.push_back(5); number.push_back(7); number.push_back(9); double dderi=GeometryAlgorithm::GetDerivation(number); Point_3 center(0,0,0); Sphere_3 sphere(center,1); Line_3 line(Point_3(0,2,1),Point_3(0,2,-1)); vector<Point_3> points; GeometryAlgorithm::GetLineSphereIntersection(line,sphere,points); vector<Point_3> Group0,Group1; vector<Int_Int_Pair> GroupResult; Group0.push_back(Point_3(3,3,2)); Group0.push_back(Point_3(5,3,2)); Group0.push_back(Point_3(2,3,2)); Group0.push_back(Point_3(6,3,2)); Group0.push_back(Point_3(4,3,2)); Group0.push_back(Point_3(1,3,2)); Group1.push_back(Point_3(3,4,2)); Group1.push_back(Point_3(1,4,2)); Group1.push_back(Point_3(6,4,2)); Group1.push_back(Point_3(2,4,2)); Group1.push_back(Point_3(5,4,2)); Group1.push_back(Point_3(4,4,2)); vector<Point_3> vecMidPoint; GeometryAlgorithm::GroupNearestPoints(Group0,Group1,GroupResult,vecMidPoint);// vector<Point_3> OriginalCurve; OriginalCurve.push_back(Point_3(-1,0,2)); OriginalCurve.push_back(Point_3(1,0,2)); OriginalCurve.push_back(Point_3(1,0,0)); OriginalCurve.push_back(Point_3(-1,0,0)); vector<Point_3> NewCurve=OriginalCurve; vector<int> HandleInd; HandleInd.push_back(0); HandleInd.push_back(1); vector<Point_3> NewPos; NewPos.push_back(Point_3(-1,0,3)); NewPos.push_back(Point_3(1,0,3)); // CCurveDeform::ClosedCurveNaiveLaplacianDeform(NewCurve,HandleInd,NewPos,1); vector<vector<float>> MatrixA,MatrixB,Result; vector<float> CurrentRow; CurrentRow.push_back(2);CurrentRow.push_back(0);CurrentRow.push_back(1); MatrixA.push_back(CurrentRow); CurrentRow.clear(); CurrentRow.push_back(3);CurrentRow.push_back(1);CurrentRow.push_back(2); MatrixA.push_back(CurrentRow); CurrentRow.clear(); CurrentRow.push_back(0);CurrentRow.push_back(1);CurrentRow.push_back(0); MatrixA.push_back(CurrentRow); CurrentRow.clear(); CurrentRow.push_back(1);CurrentRow.push_back(3);CurrentRow.push_back(0); MatrixB.push_back(CurrentRow); CurrentRow.clear(); CurrentRow.push_back(2);CurrentRow.push_back(0);CurrentRow.push_back(2); MatrixB.push_back(CurrentRow); CurrentRow.clear(); CurrentRow.push_back(1);CurrentRow.push_back(0);CurrentRow.push_back(1); MatrixB.push_back(CurrentRow); CurrentRow.clear(); int iANonZeroSize=0; for (unsigned int i=0;i<MatrixA.size();i++) { for (unsigned int j=0;j<MatrixA.front().size();j++) { if (MatrixA.at(i).at(j)!=0) { iANonZeroSize++; } } } KW_SparseMatrix A(MatrixA.size(),MatrixA.front().size(),iANonZeroSize); for (unsigned int i=0;i<MatrixA.size();i++) { for (unsigned int j=0;j<MatrixA.front().size();j++) { if (MatrixA.at(i).at(j)!=0) { A.fput(i,j,MatrixA.at(i).at(j)); } } } int iBNonZeroSize=0; for (unsigned int i=0;i<MatrixB.size();i++) { for (unsigned int j=0;j<MatrixB.front().size();j++) { if (MatrixB.at(i).at(j)!=0) { iBNonZeroSize++; } } } KW_SparseMatrix B(MatrixB.size(),MatrixB.front().size(),iBNonZeroSize); for (unsigned int i=0;i<MatrixB.size();i++) { for (unsigned int j=0;j<MatrixB.front().size();j++) { if (MatrixB.at(i).at(j)!=0) { B.fput(i,j,MatrixB.at(i).at(j)); } } } KW_SparseMatrix C(A.m,B.n,0); KW_SparseMatrix::KW_multiply(A,B,C); int iIndex=0; Result.clear(); for (int i=0;i<C.m;i++) { vector<float> CurrentRow; for (int j=0;j<C.n;j++) { iIndex=0; while (iIndex<C.vol) { if (C.indx[iIndex]==i&&C.jndx[iIndex]==j) { break; } iIndex++; } if (iIndex!=C.vol) { CurrentRow.push_back(C.array[iIndex]); } else { CurrentRow.push_back(0); } } Result.push_back(CurrentRow); } }
int MapgenMath::generateTerrain() { MapNode n_ice(c_ice); u32 index = 0; v3POS em = vm->m_area.getExtent(); auto zstride_1d = csize.X * (csize.Y + 1); /* debug v3f vec0 = (v3f(node_min.X, node_min.Y, node_min.Z) - center) * scale ; errorstream << " X=" << node_min.X << " Y=" << node_min.Y << " Z=" << node_min.Z //<< " N="<< mengersponge(vec0.X, vec0.Y, vec0.Z, distance, iterations) << " N=" << (*func)(vec0.X, vec0.Y, vec0.Z, distance, iterations) << " Sc=" << scale << " gen=" << params["generator"].asString() << " J=" << Json::FastWriter().write(params) << std::endl; */ //errorstream << Json::StyledWriter().write( mg_params->params ).c_str()<< std::endl; //errorstream << " iterations="<<iterations<< " scale="<<scale <<" invert="<<invert<< std::endl; #if USE_MANDELBULBER v3f vec0(node_min.X, node_min.Y, node_min.Z); vec0 = (vec0 - center) * scale; /* errorstream << " X=" << node_min.X << " Y=" << node_min.Y << " Z=" << node_min.Z << " N=" << Compute<normal_mode>(CVector3(vec0.X, vec0.Y, vec0.Z), mg_params->par) //<<" F="<< Compute<fake_AO>(CVector3(node_min.X,node_min.Y,node_min.Z), par) //<<" L="<<node_min.getLength()<< " -="<<node_min.getLength() - Compute<normal_mode>(CVector3(node_min.X,node_min.Y,node_min.Z), par) << " Sc=" << scale << " internal=" << internal << std::endl; */ #endif double d = 0; for (s16 z = node_min.Z; z <= node_max.Z; z++) { for (s16 x = node_min.X; x <= node_max.X; x++, index++) { s16 heat = m_emerge->env->m_use_weather ? m_emerge->env->getServerMap().updateBlockHeat(m_emerge->env, v3POS(x,node_max.Y,z), nullptr, &heat_cache) : 0; u32 i = vm->m_area.index(x, node_min.Y, z); for (s16 y = node_min.Y; y <= node_max.Y; y++) { v3f vec = (v3f(x, y, z) - center) * scale ; if (invert_xy) std::swap(vec.X, vec.Y); if (invert_yz) std::swap(vec.Y, vec.Z); #if USE_MANDELBULBER if (!internal) d = Compute<normal_mode>(CVector3(vec.X, vec.Y, vec.Z), mg_params->par); else #endif if (internal) d = (*func)(vec.X, vec.Y, vec.Z, scale.X, iterations); if ((!invert && d > 0) || (invert && d == 0) ) { if (!vm->m_data[i]) { //vm->m_data[i] = (y > water_level + biome->filler) ? // MapNode(biome->c_filler) : n_stone; if (invert) { int index3 = (z - node_min.Z) * zstride_1d + (y - node_min.Y) * ystride + (x - node_min.X); vm->m_data[i] = Mapgen_features::layers_get(index3); } else { vm->m_data[i] = layers_get(d, result_max); } // vm->m_data[i] = (y > water_level + biome->filler) ? // MapNode(biome->c_filler) : layers_get(d, result_max); } } else if (y <= water_level) { vm->m_data[i] = (heat < 0 && y > heat/3) ? n_ice : n_water; } else { vm->m_data[i] = n_air; } vm->m_area.add_y(em, i, 1); } } } return 0; }