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


C++ Universe::add_object方法代码示例

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


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

示例1: test_02

void test_02() {

    // Create a universe
    Universe universe;

    // Add a bunch of objects
    Object* A = new Object;
    A->set_velocity(0, 1);
    for ( int ii = 0; ii < 10; ++ii) {
        A->set_position(ii, ii);
        universe.add_object(A);
    }

    std::cout << "Initial conditions: \n";
    debug_display_world(universe);

    // Iterate the engine a few times
    for (int ii = 0; ii < 5; ++ii) {
        universe.physics_runtime_iteration();

        std::cout << "\nIteration " << ii << ":\n";
        debug_display_world(universe);
    }

}
开发者ID:zwyber,项目名称:pie,代码行数:25,代码来源:testing.cpp

示例2: test_004

void test_004 () {
    Universe universe;


    Object* A = new Object;
    Object* B = new Object;

    universe.add_object(A);
    universe.add_object(B);

    A->set_position(5, 2);
    B->set_position(3, 1);
    A->set_mass(-1.5);
    vec2d acceleration = universe.physics.acceleration(A,B);

    A->calc_new_pos_vel(universe.objects, universe.physics);

    std::cout << "Acceleration of ObjectA With Respect to ObjectB =" << acceleration[0] << "," << acceleration[1] << std::endl;

    debug_display_world(universe);

}
开发者ID:zwyber,项目名称:pie,代码行数:22,代码来源:testing.cpp

示例3: test_03

void test_03 () {

    // Create a universe
    Universe universe;

    // Create two objects
    Object* A = new Object;
    Object* B = new Object;

    // Set them apart, and on a collision course
    A->set_position(2, 0);
    A->set_velocity(-1, 0);
    A->set_radius(1);

    B->set_position(-2, 0);
    B->set_velocity(1, 0.1);
    B->set_radius(2);

    // Add them to the universe
    universe.add_object(A);
    universe.add_object(B);

    // Open a file
    std::ofstream outputfile;
    outputfile.open("test_03.csv");

    // Start to iterate 10000 cycles
    for (int ii = 0; ii < 10000; ++ii) {
        // Output the positions of the two objects to a file
        vec2d posA = A->get_position();
        vec2d posB = B->get_position();
        outputfile << posA[0] << "," << posA[1] << "," << posB[0] << "," << posB[1] << ";" << std::endl;

        // Iterate the physics
        universe.physics_runtime_iteration();
    }

}
开发者ID:zwyber,项目名称:pie,代码行数:38,代码来源:testing.cpp

示例4: addRandomObjects

void addRandomObjects(Universe &universe, unsigned seed, int objectAmount){
    if(!seed){
        srand(time(NULL));
    }else{
        srand(seed);
    }
    std::array<double,2> radiusLim = {0.2, 0.3};
    std::array<double,2> massLim = {0.1, 3};
    std::array<double,2> velocityLim = {-1, 1};
    for(int ii = 0; ii < objectAmount; ii++){
        Object* A = new Object;
        A->set_mass((std::rand()/(double)RAND_MAX)*(massLim[1]-massLim[0])+massLim[0]);
        A->set_velocity((std::rand()/(double)RAND_MAX)*(velocityLim[1]-velocityLim[0])+velocityLim[0],(std::rand()/(double)RAND_MAX)*(velocityLim[1]-velocityLim[0])+velocityLim[0]);
        A->set_radius((std::rand()/(double)RAND_MAX)*(radiusLim[1]-radiusLim[0])+radiusLim[0]);
        A->bouncyness = std::rand()/(double)RAND_MAX;
        std::array<double,2> xLim = {-universe.width/2+A->get_radius(), universe.width/2-A->get_radius()};
        std::array<double,2> yLim = {-universe.height/2+A->get_radius(), universe.height/2-A->get_radius()};
        do{
            A->set_position((std::rand()/(double)RAND_MAX)*(xLim[1]-xLim[0])+xLim[0], (std::rand()/(double)RAND_MAX)*(yLim[1]-yLim[0])+yLim[0]);
        }while(CollidesWithAny(A, universe));
        universe.add_object(A);
    }
}
开发者ID:zwyber,项目名称:pie,代码行数:23,代码来源:testing.cpp

示例5: test_00

void test_00 () {

    // Show the user we are running test 00
    std::cout << "Running test_00..." << std::endl << std::endl;

    // Make the universe
    Universe universe;

    // Open a new scope when creating objects, see below why
    Object* A;
    Object* B;
    {
        // Generate a few objects
        A = new Object;
        B = new Object;

        // Give them new positions
        A->set_position(1, 1);
        B->set_position(-1, 2);

        // Add the objects to the universe
        universe.add_object(A);
        universe.add_object(B);
    }

    // Show a few things about the world we just created
    debug_display_world(universe);

    std::cout << "\nUpdating the positions\n";

    // So to update the position you have to do this
    A->set_position(2, 2);
    A->set_velocity(3, 1);

    B->set_position(-2, -2);
    B->set_velocity(-1, -2);

    // Display the world to the commandline
    debug_display_world(universe);

    // Now let's try to remove an object
    std::cout << "\n Removing A" << std::endl;


    debug_display_world(universe);

    // Now create a new object
    std::cout << "\n Adding another object C " << std::endl;
    Object* C;
    {
        C = new Object;
        C->set_position(0.5, 0.5);
        universe.add_object(C);
    }

    // And show the mapping and world
    debug_display_world(universe);

    std::cout << "\n Removing B" << std::endl;

    universe.remove_object(B);
    debug_display_world(universe);
}
开发者ID:zwyber,项目名称:pie,代码行数:63,代码来源:testing.cpp


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