Jump to content

Recommended Posts

Posted

This is the code I used for the latest zombie vid. I don't think I will ever need it again, but pasting it here just in case.

#include "UltraEngine.h"

using namespace UltraEngine;

std::vector<shared_ptr<Model> > zombies;
std::set<iVec2> coords;

void Spawn(shared_ptr<World> world)
{
    int n = Random(1, 4);
    auto mdl = LoadModel(world, "Models/Zombies/zombie" + String(n) + ".mdl");

    int r = 8;

    iVec2 c;
    while (true)
    {
        c.x = Random(-r, r);
        c.y = Random(-r, r);
        if ((c.x == 0 and c.y == 0) or coords.find(c) != coords.end()) continue;
        break;
    }
    coords.insert(c);
    mdl->SetPosition(c.x, 0, c.y);
    mdl->SetRotation(0, ATan(float(c.x), float(c.y)), 0);
    mdl->Translate(Random(-0.25, 0.25), 0, Random(-0.25, 0.25), true);
    mdl->Sync();
    mdl->Animate("idle");
    mdl->SetHidden(true);
    zombies.push_back(mdl);
}

int main(int argc, const char* argv[])
{
    auto cl = ParseCommandLine(argc, argv);

    //Load FreeImage plugin (optional)
    auto fiplugin = LoadPlugin("Plugins/FITextureLoader");

    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1920, 1080, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create a world
    auto world = CreateWorld();

    //Get the headset
    auto hmd = GetHmd(world);

    //Load the map
    WString mapname = "Maps/start.ultra";
    if (cl["map"].is_string()) mapname = std::string(cl["map"]);
    auto scene = LoadMap(world, mapname);

    auto mdl = LoadModel(world, "Models/Zombies/zombie4.mdl");
    mdl->Animate("idle");
    mdl->SetPosition(0, 0, 1);

    zombies.push_back(mdl);

    for (int n = 0; n < 200; ++n)
    {
        Spawn(world);
    }

    int n = 0;
    bool hit = false;

    auto last = Millisecs();

    bool start = false;

    auto light = CreateDirectionalLight(world);
    light->SetRotation(55, 35, 0);
    light->SetColor(2);
    light->SetShadowMapSize(2048);

    world->SetIblIntensity(0.25);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        if (start)
        {
            auto now = Millisecs();
            if (now - last > 100)
            {
                last = now;
                ++n;
                if (n < zombies.size())
                {
                    zombies[n]->SetHidden(false);
                    //zombies[n]->Animate("idle", 1, 0);
                }
            }
        }
        else
        {
            if (hmd->controllers[0]->ButtonDown(VRBUTTON_TRIGGER) or hmd->controllers[1]->ButtonDown(VRBUTTON_TRIGGER)) start = true;
        }
        
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Let's build cool stuff and have fun. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...