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


C++ Space::step方法代码示例

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


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

示例1: main

int main() {
    // cp::Vect is a 2D vector.
    Vect gravity(0, -100);

    // Create an empty space.
    Space space;
    space.setGravity(gravity);

    // Add a static line segment shape for ground.
    // We'll make it slightly tilted so the ball will roll off.
    // We attach it to space.staticBody to tell Chipmunk it shouldn't be movable.
    auto ground = make_shared<SegmentShape>(space.staticBody,
                                            Vect(-20, 5), Vect(20, -5), 0);
    ground->setFriction(1);
    space.add(ground);

    // Now let's make a ball that falls onto the line and rolls off.
    // First we need to make a Body to hold the physical properties of the object.
    // These include the mass, position, velocity, angle, etc. of the object.
    // Then we attach collision shapes to the cpBody to give it a size and shape.

    const Float radius = 5;
    const Float mass = 1;

    // The moment of inertia is like mass for rotation
    // Use the cp::momentFor*() functions to help you approximate it.
    const Float moment = momentForCircle(mass, 0, radius);

    auto ballBody = make_shared<Body>(mass, moment);
    space.add(ballBody);
    ballBody->setPosition(Vect(0, 15));

    // Now we create the collision shape for the ball.
    // You can create multiple collision shapes that point to the same body.
    // They will all be attached to the body and move arount to follow it.
    auto ballShape = make_shared<CircleShape>(ballBody, radius);
    space.add(ballShape);
    ballShape->setFriction(0.7);

    // Now that it's all set up, we simulate all the objects in the space by
    // stepping forward through time in small increments called steps.
    // It is *highly* recommended to use a fixed size time step.
    Float timeStep = 1.0/60.0;
    for (Float time = 0; time < 2; time += timeStep) {
        Vect pos = ballBody->getPosition();
        Vect vel = ballBody->getVelocity();
        cout << setprecision(2) << fixed
             << "Time is "          << setw(5) << time << ". "
             << "ballBody is at "   << setw(5) << pos << ". "
             << "It's velocity is " << setw(5) << vel << endl;
        space.step(timeStep);
    }
}
开发者ID:jhasse,项目名称:chipmunkpp,代码行数:53,代码来源:test.cpp

示例2: step

  void step(const float delta_time)
  {
    space_.step(delta_time);
    earth_.step(delta_time);
    if (time_ < time_ed_)
    {
      time_ += delta_time;

      Easing easing;
      easing.ease(cloud_alpha_, time_, cloud_alpha_st_, cloud_alpha_ed_, time_ed_);
    }
  }
开发者ID:limebreaker,项目名称:KONAHEN,代码行数:12,代码来源:nn_gameworld.hpp


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