本文整理汇总了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);
}
}
示例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_);
}
}