<commit_before>#include "Sim.h"


Sim::Sim()
{
    /**
     * Setup Irrlicht stuff
     */
    //device = createDevice( video::EDT_OPENGL, dimension2d<u32>(1280, 960), 16,
      //      false, true, false, &ih);
    SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
    params.AntiAlias = 8;
    params.DriverType = video::EDT_OPENGL;
    params.WindowSize = core::dimension2d<u32>(640, 480);
    params.EventReceiver = &ih;
    device = createDeviceEx(params);
    if (!device){
        Logger::Log("FATAL- Could not create device");
        return;
    }
    device->setWindowCaption(L"MDA Simulator 0.1");

    driver = device->getVideoDriver();
    smgr = device->getSceneManager();
    guienv = device->getGUIEnvironment();

    /**
     * Load textures into the map
     */
    DataStorage::loadTextures(driver);

    /**
     * Loads the nodes into the scene
     */
    ISceneNode *b = smgr->addSphereSceneNode();
    if (!b){
        Logger::Log("Could not create sphere node");
    }else{
        Buoy *ball = new Buoy("ball", b);
        objs.push_back(ball);
    }

    ISceneNode *s = smgr->addCubeSceneNode();
    Sub *sub = new Sub("Sub", s);
    objs.push_back(sub);

    //Light and Fog
    ILightSceneNode* light1 = smgr->addLightSceneNode( 0, core::vector3df(0,500,0), video::SColorf(0.3f,0.3f,0.3f), 50000.0f, 1 );
    driver->setFog(video::SColor(0, 120,140,160), video::EFT_FOG_LINEAR, 20, 250, .001f, false, false);
    ISceneNode * scenenode = smgr->getRootSceneNode();
    scenenode->setMaterialFlag(EMF_FOG_ENABLE, true);
    light1->setMaterialFlag(EMF_FOG_ENABLE, true);

    //Load obstacles (need to be separated so that buoys can move)
    IAnimatedMesh* mesh = smgr->getMesh("assets/obstacles.3ds");
    IMeshSceneNode * node = 0;
    if (mesh)
        node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0);

    if (node)
    {
        node->setMaterialFlag(EMF_FOG_ENABLE, true);
        node->setMaterialFlag(EMF_LIGHTING, true);
        node->setScale(core::vector3df(20,20,20));
    }

    IAnimatedMesh* roomMesh = smgr->getMesh("assets/stadium.3ds");
    IMeshSceneNode * roomNode = 0;
    if (roomMesh)
        roomNode = smgr->addOctreeSceneNode(roomMesh->getMesh(0), 0);


    if (roomNode)
    {
        roomNode->setMaterialFlag(EMF_FOG_ENABLE, true);
        roomNode->setMaterialFlag(EMF_LIGHTING, true);
        roomNode->setScale(core::vector3df(20,20,20));
    }

    scene::ITriangleSelector* selector = 0;

    if (node)
    {
        node->setPosition(core::vector3df(0,0,0));

        selector = smgr->createOctreeTriangleSelector(
                node->getMesh(), node, 128);
        node->setTriangleSelector(selector);
        // We're not done with this selector yet, so don't drop it.
    }

    //ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100.0f, 0.05f);
    ICameraSceneNode* camera = smgr->addCameraSceneNode(s, vector3df(0,10,0), vector3df(0,0,0));
    Logger::Log(s->getPosition());
    cameras[0] = smgr->addCameraSceneNode(s, s->getPosition());
    cameras[1] = smgr->addCameraSceneNode(s, s->getPosition(), vector3df(0,0,0));
    cameras[2] = smgr->addCameraSceneNode(s, s->getPosition(), vector3df(0,0,0));
    s->setPosition(vector3df(-200, 212, 443));

    //device->getCursorControl()->setVisible(false);
    anim = smgr->createCollisionResponseAnimator(
    selector, camera, vector3df(5,5,5),
    vector3df(0,0,0), vector3df(0,0,0));

    if (selector)
    {
        selector->drop(); // As soon as we're done with the selector, drop it.
        camera->addAnimator(anim);
        //anim->drop();  // And likewise, drop the animator when we're done referring to it.
    }


}

//Sim::~Sim(){

//}

int Sim::start(){
    //if the device cannot be created, just exit the program
    if (!device)
        return 1;    

    guienv->addStaticText(L"Hello World!",
        rect<s32>(10,10,260,22), true);

    //Add camera node to a static position. Need to change later to have this on the sub
    cameras[3] = smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

    bool collision;

    // In order to do framerate independent movement, we have to know
    // how long it was since the last frame
    u32 then = device->getTimer()->getTime();

    while(device->run())
    {
        // Work out a frame delta time.
        const u32 now = device->getTimer()->getTime();
        const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
        then = now;


        for (SimObject *so: objs){
            if (so->getName() == "Sub"){
                vector3df acc = so->getAcc();
                //input processing
                if(ih.IsKeyDown(irr::KEY_KEY_W)){
                    acc.X -= 5 * frameDeltaTime;
                }
                else if(ih.IsKeyDown(irr::KEY_KEY_S))
                    acc.X += 5 * frameDeltaTime;
                if(ih.IsKeyDown(irr::KEY_KEY_A))
                    acc.Z -= 5 * frameDeltaTime;
                else if(ih.IsKeyDown(irr::KEY_KEY_D))
                    acc.Z += 5 * frameDeltaTime;
                if (ih.IsKeyDown(irr::KEY_SPACE))
                    acc.Y += 5 * frameDeltaTime;
                else if (ih.IsKeyDown(irr::KEY_LSHIFT))
                    acc.Y -= 5 * frameDeltaTime;

                so->setAcc(acc);

                if (ih.IsKeyDown(irr::KEY_KEY_R)){
                    so->reset();
                }

                vector3df temp = so->getPos();
                temp.X -= 20;
                cameras[0]->setTarget(temp);
                //cameras[0]->setRotation(vector3df(0,0,0));

                temp = so->getPos();
                temp.Y -= 20;
                cameras[1]->setTarget(temp);
                //cameras[1]->setRotation(vector3df(0,0,0));

                temp = so->getPos();
                temp.Z += 20;
                cameras[2]->setTarget(temp);

                temp = so->getPos();
                temp.Z -= 20;
                temp.Y += 20;
                cameras[3]->setPosition(temp);
                cameras[3]->setTarget(so->getPos());
                //Logger::Log(std::to_string(so->getAcc().X));
            }
            so->update();
        }
        //collision check
        collision = Sim::anim->collisionOccurred();
        if (collision)
            Logger::Log("collision");


        driver->setViewPort(rect<s32>(0,0,resX, resY));
        driver->beginScene(true, true, SColor(255,100,101,140));

        smgr->setActiveCamera(cameras[0]);
        driver->setViewPort(rect<s32>(0,0,resX/2,resY/2));
        smgr->drawAll();
        smgr->setActiveCamera(cameras[1]);
        driver->setViewPort(rect<s32>(resX/2,0,resX,resY/2));
        smgr->drawAll();
        smgr->setActiveCamera(cameras[2]);
        driver->setViewPort(rect<s32>(0,resY/2,resX/2,resY));
        smgr->drawAll();
        smgr->setActiveCamera(cameras[3]);
        driver->setViewPort(rect<s32>(resX/2,resY/2,resX,resY));
        smgr->drawAll();
        guienv->drawAll();

        driver->endScene();
    }
    device->closeDevice();
    return 0;
}<commit_msg>wip on collision<commit_after>#include "Sim.h"


Sim::Sim()
{
    /**
     * Setup Irrlicht stuff
     */
    //device = createDevice( video::EDT_OPENGL, dimension2d<u32>(1280, 960), 16,
      //      false, true, false, &ih);
    SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
    params.AntiAlias = 8;
    params.DriverType = video::EDT_OPENGL;
    params.WindowSize = core::dimension2d<u32>(640, 480);
    params.EventReceiver = &ih;
    device = createDeviceEx(params);
    if (!device){
        Logger::Log("FATAL- Could not create device");
        return;
    }
    device->setWindowCaption(L"MDA Simulator 0.1");

    driver = device->getVideoDriver();
    smgr = device->getSceneManager();
    guienv = device->getGUIEnvironment();

    /**
     * Load textures into the map
     */
    DataStorage::loadTextures(driver);

    /**
     * Loads the nodes into the scene
     */
    ISceneNode *b = smgr->addSphereSceneNode();
    if (!b){
        Logger::Log("Could not create sphere node");
    }else{
        Buoy *ball = new Buoy("ball", b);
        objs.push_back(ball);
    }

    ISceneNode *s = smgr->addCubeSceneNode();
    Sub *sub = new Sub("Sub", s);
    objs.push_back(sub);

    //Light and Fog
    ILightSceneNode* light1 = smgr->addLightSceneNode( 0, core::vector3df(0,500,0), video::SColorf(0.3f,0.3f,0.3f), 50000.0f, 1 );
    driver->setFog(video::SColor(0, 120,140,160), video::EFT_FOG_LINEAR, 20, 250, .001f, false, false);
    ISceneNode * scenenode = smgr->getRootSceneNode();
    scenenode->setMaterialFlag(EMF_FOG_ENABLE, true);
    light1->setMaterialFlag(EMF_FOG_ENABLE, true);

    //Load obstacles (need to be separated so that buoys can move)
    IAnimatedMesh* mesh = smgr->getMesh("assets/obstacles.3ds");
    IMeshSceneNode * node = 0;
    if (mesh)
        node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0);

    if (node)
    {
        node->setMaterialFlag(EMF_FOG_ENABLE, true);
        node->setMaterialFlag(EMF_LIGHTING, true);
        node->setScale(core::vector3df(20,20,20));
    }

    IAnimatedMesh* roomMesh = smgr->getMesh("assets/stadium.3ds");
    IMeshSceneNode * roomNode = 0;
    if (roomMesh)
        roomNode = smgr->addOctreeSceneNode(roomMesh->getMesh(0), 0);


    if (roomNode)
    {
        roomNode->setMaterialFlag(EMF_FOG_ENABLE, true);
        roomNode->setMaterialFlag(EMF_LIGHTING, true);
        roomNode->setScale(core::vector3df(20,20,20));
    }

    scene::ITriangleSelector* selector = 0;

    if (node)
    {
        node->setPosition(core::vector3df(0,0,0));

        selector = smgr->createOctreeTriangleSelector(
                node->getMesh(), node, 128);
        node->setTriangleSelector(selector);
        // We're not done with this selector yet, so don't drop it.
    }

    //ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100.0f, 0.05f);
    //ICameraSceneNode* camera = smgr->addCameraSceneNode(s, vector3df(0,10,0), vector3df(0,0,0));
    Logger::Log(s->getPosition());
    cameras[0] = smgr->addCameraSceneNode(s, s->getPosition());
    cameras[1] = smgr->addCameraSceneNode(s, s->getPosition(), vector3df(0,0,0));
    cameras[2] = smgr->addCameraSceneNode(s, s->getPosition(), vector3df(0,0,0));
    s->setPosition(vector3df(-200, 212, 443));

    //First vector input is the radius of the collidable object
    anim = smgr->createCollisionResponseAnimator(
    selector, s, vector3df(7.5f,7.5f,7.5f),
    vector3df(0,0,0), vector3df(0,0,0));

    if (selector)
    {
        selector->drop(); // As soon as we're done with the selector, drop it.
        s->addAnimator(anim);
        //camera->addAnimator(anim);
        //anim->drop();  // And likewise, drop the animator when we're done referring to it.
    }


}

//Sim::~Sim(){

//}

int Sim::start(){
    //if the device cannot be created, just exit the program
    if (!device)
        return 1;    

    guienv->addStaticText(L"Hello World!",
        rect<s32>(10,10,260,22), true);

    //Add camera node to a static position. Need to change later to have this on the sub
    cameras[3] = smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

    bool collision;

    // In order to do framerate independent movement, we have to know
    // how long it was since the last frame
    u32 then = device->getTimer()->getTime();

    while(device->run())
    {
        // Work out a frame delta time.
        const u32 now = device->getTimer()->getTime();
        const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
        then = now;


        for (SimObject *so: objs){
            if (so->getName() == "Sub"){
                vector3df acc = so->getAcc();
                //input processing
                if(ih.IsKeyDown(irr::KEY_KEY_W)){
                    acc.X -= 5 * frameDeltaTime;
                }
                else if(ih.IsKeyDown(irr::KEY_KEY_S))
                    acc.X += 5 * frameDeltaTime;
                if(ih.IsKeyDown(irr::KEY_KEY_A))
                    acc.Z -= 5 * frameDeltaTime;
                else if(ih.IsKeyDown(irr::KEY_KEY_D))
                    acc.Z += 5 * frameDeltaTime;
                if (ih.IsKeyDown(irr::KEY_SPACE))
                    acc.Y += 5 * frameDeltaTime;
                else if (ih.IsKeyDown(irr::KEY_LSHIFT))
                    acc.Y -= 5 * frameDeltaTime;

                so->setAcc(acc);

                if (ih.IsKeyDown(irr::KEY_KEY_R)){
                    so->reset();
                }

                vector3df temp = so->getPos();
                temp.X -= 20;
                cameras[0]->setTarget(temp);
                //cameras[0]->setRotation(vector3df(0,0,0));

                temp = so->getPos();
                temp.Y -= 20;
                cameras[1]->setTarget(temp);
                //cameras[1]->setRotation(vector3df(0,0,0));

                temp = so->getPos();
                temp.Z += 20;
                cameras[2]->setTarget(temp);

                temp = so->getPos();
                temp.Z -= 20;
                temp.Y += 20;
                cameras[3]->setPosition(temp);
                cameras[3]->setTarget(so->getPos());
                //Logger::Log(std::to_string(so->getAcc().X));
            }
            so->update();
        }
        //collision check
        collision = anim->collisionOccurred();
        if (collision)
            Logger::Log("collision");


        driver->setViewPort(rect<s32>(0,0,resX, resY));
        driver->beginScene(true, true, SColor(255,100,101,140));

        smgr->setActiveCamera(cameras[0]);
        driver->setViewPort(rect<s32>(0,0,resX/2,resY/2));
        smgr->drawAll();
        smgr->setActiveCamera(cameras[1]);
        driver->setViewPort(rect<s32>(resX/2,0,resX,resY/2));
        smgr->drawAll();
        smgr->setActiveCamera(cameras[2]);
        driver->setViewPort(rect<s32>(0,resY/2,resX/2,resY));
        smgr->drawAll();
        smgr->setActiveCamera(cameras[3]);
        driver->setViewPort(rect<s32>(resX/2,resY/2,resX,resY));
        smgr->drawAll();
        guienv->drawAll();

        driver->endScene();
    }
    device->closeDevice();
    return 0;
}
{'fraction_non_alphanumeric': 0.15337595728237197, 'fraction_numerical': 0.035902480151759994, 'mean_word_length': 2.2714318547460355, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 190, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4365978', 'n_tokens_mistral': 5033, 'n_tokens_neox': 4663, 'n_words': 874}