当前位置: 首页>>代码示例>>C++>>正文


C++ TriangleMesh::scale方法代码示例

本文整理汇总了C++中TriangleMesh::scale方法的典型用法代码示例。如果您正苦于以下问题:C++ TriangleMesh::scale方法的具体用法?C++ TriangleMesh::scale怎么用?C++ TriangleMesh::scale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TriangleMesh的用法示例。


在下文中一共展示了TriangleMesh::scale方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: simulateGeometry

void simulateGeometry(size_t frameRate,
                      double minRadius, // in mm
                      double maxRadius, // in mm
                      double simDuration, // in seconds
                      size_t numBubbles, // over lifetime of simulation
                      const std::string &outputDir) {
 
  std::vector<FakeBubbleStats> bubbleStats(numBubbles);
  std::vector<Bubble *> bubbles(numBubbles);
  
  size_t numFrames = ceil(frameRate * simDuration);
  double dt = 1.0 / double(frameRate);
  
  // initialize random bubble stats
  for (size_t i = 0; i < numBubbles; i++) {
    bubbleStats[i].bubbleBirthtime = random_double(0.02, simDuration * 0.95);
    bubbleStats[i].bubbleRadius = random_double(minRadius, maxRadius);
    std::cout << "bubbleRadius: " << bubbleStats[i].bubbleRadius << std::endl;
    
    bubbleStats[i].isBubbleBorn = false;
    bubbleStats[i].isBubbleDead = false;
  }
  
  // initialize bubble objects
  for (size_t i = 0; i < numBubbles; i++) {
    bubbles[i] = new Bubble();
    TriangleMesh *currBubble = new TriangleMesh;
    
    // yep, for now a different copy of each
    currBubble->read(baseDir + "bubble_lr.obj", MFF_OBJ);
    
    // constant is here because starting size of bubbles is 5mm radius
    double ds = bubbleStats[i].bubbleRadius / 5.0;
    
    currBubble->scale(Vector3d(ds, ds, ds));
    
    double dx = random_double(-0.05, +0.05);
    double dz = random_double(-0.05, +0.05);
    Vector3d dpos(dx,0,dz);
    //currBubble->translate(dpos);  // TODO: uncomment this line to randomizing starting position
    
    bubbles[i]->setBubbleMesh(currBubble);
    
  }
  
  std::string solidPrefix = "solid_";
  std::string airPrefix = "air_";
  std::string bubblePrefix = "bubble_";
  
  for (size_t f = 0; f < numFrames; f++) {
    
    double currTime = f * dt;
    
    std::string zeropadFrameNum = ZeroPadNumber(f, 6);

    // add a bit of random vertical motion to the fluid surface
    //airMesh->jitter(Vector3d(0,0.0005,0));
    
    solidMesh->write(outputDir + solidPrefix + zeropadFrameNum + ".obj", MFF_OBJ);
    airMesh->write(outputDir + airPrefix + zeropadFrameNum + ".obj", MFF_OBJ);
    
    // advect all the bubbles for each timestep
    for (size_t b = 0; b < numBubbles; b++) {
      
      if (bubbleStats[b].bubbleBirthtime <= currTime) {
        bubbleStats[b].isBubbleBorn = true;
      }
      
      
      // check whether bubble has peeked above the surface
      if (bubbleStats[b].isBubbleBorn && !bubbleStats[b].isBubbleDead) {
        BoundingBox airbbox, bubbbox;
        airMesh->getBoundingBox(airbbox);
        bubbles[b]->getBubbleMesh()->getBoundingBox(bubbbox);
        
        // rough crappy rule of thumb
        if (bubbbox.GetBoxmax().y() > airbbox.GetBoxmax().y()) {
          // KILL THE BUBBLE!
          bubbleStats[b].isBubbleDead = true;
        }
      }
      
      
      if (bubbleStats[b].isBubbleBorn && !bubbleStats[b].isBubbleDead) {
        
        std::string zeropadBubbleNum = ZeroPadNumber(b, 6);
        bubbles[b]->getBubbleMesh()->write(outputDir + bubblePrefix + zeropadBubbleNum + "_" + zeropadFrameNum + ".obj", MFF_OBJ);
        bubbles[b]->timestep(dt);
      }
      
      
    }
    
    
    
  }
}
开发者ID:phaedon,项目名称:aletler,代码行数:97,代码来源:main.cpp


注:本文中的TriangleMesh::scale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。