void ofApp::setup(){ setupTcpServer(); setupArrays(); setupSound(); setupChannels(); for (int i = 0; i < channels.size(); i++) { channel *channel = channels[i]; movingFrameBoard *mfb = new movingFrameBoard(&channel->mFbo); movingFrameBoards.push_back(mfb); chessBoard1 *cb1 = new chessBoard1(&channel->mFbo); chessBoard1s.push_back(cb1); testBoard *tb = new testBoard(&channel->mFbo); testBoards.push_back(tb); oneColorBoard *ocb = new oneColorBoard(&channel->mFbo); oneColorBoards.push_back(ocb); chessBoard2 *cb2 = new chessBoard2(&channel->mFbo); chessBoard2s.push_back(cb2); } }
void mainLoop(const char* configFile, int generations) { // need a pair of arrays, one to hold grid and the other to hold updates //(unless we invent a more complex datastructure/algorithm to allow in-place // modification of the array) ARRAY2D arrays[2] = {0}; // keep track of which array is active, the other is used for updates int active = 0; int i; // bounds on the rows this node handles int upper, lower; setupArrays(configFile, arrays, &upper, &lower); // loop over number of generations for(i = 0; i < generations; i++) { display(arrays[active], i); // calculate updates timestep(arrays[active], arrays[!active], lower, upper); // swap arrays active = !active; updateOtherProcesses(upper, lower, arrays[active]); } display(arrays[active], i); // cleanup freeArray(arrays[0]); freeArray(arrays[1]); }
CPetText::CPetText(uint count) : _stringsMerged(false), _maxCharsPerLine(-1), _lineCount(0), _linesStart(-1), _unused1(0), _unused2(0), _unused3(0), _backR(0xff), _backG(0xff), _backB(0xff), _textR(0), _textG(0), _textB(200), _fontNumber(0), _npcFlag(0), _npcId(0), _hasBorder(true), _scrollTop(0), _textCursor(nullptr) { setupArrays(count); }
std::vector<std::shared_ptr<Mesh>> Mesh::createSphere() { auto m = std::shared_ptr<Mesh>(new Mesh()); int stacks = 100; int slices = 100; float radius = 1.0; for (int i = 0; i <= stacks; ++i) { float V = i / (float)stacks; float phi = V * glm::pi <float>(); for (int j = 0; j <= slices; ++j) { float U = j / (float)slices; float theta = U * (glm::pi <float>() * 2); float x = cosf(theta) * sinf(phi); float y = cosf(phi); float z = sinf(theta) * sinf(phi); m->vertices.push_back({ glm::vec3(x, y, z) * radius }); } } for (int i = 0; i < slices * stacks + slices; ++i) { m->indices.push_back(i); m->indices.push_back(i + slices + 1); m->indices.push_back(i + slices); m->indices.push_back(i + slices + 1); m->indices.push_back(i); m->indices.push_back(i + 1); } m->calculateNormals(); m->setupArrays(); return { m }; }
bool ofxParticleEmitter::loadFromXml( const std::string& filename ) { bool ok = false; settings = new ofxXmlSettings(); ok = settings->loadFile( filename ); if ( ok ) { parseParticleConfig(); setupArrays(); ok = active = true; } delete settings; settings = NULL; return ok; }
std::vector<std::shared_ptr<Mesh>> Mesh::createPostprocessingQuad() { auto m = std::shared_ptr<Mesh>(new Mesh()); m->vertices.push_back({ glm::vec3(-1.f, 1.f, 0.f), glm::vec3(), glm::vec2(0.f, 1.f) }); m->vertices.push_back({ glm::vec3(-1.f, -1.f, 0.f), glm::vec3(), glm::vec2(0.f, 0.f) }); m->vertices.push_back({ glm::vec3(1.f, -1.f, 0.f), glm::vec3(), glm::vec2(1.f, 0.f) }); m->vertices.push_back({ glm::vec3(-1.f, 1.f, 0.f), glm::vec3(), glm::vec2(0.f, 1.f) }); m->vertices.push_back({ glm::vec3(1.f, -1.f, 0.f), glm::vec3(), glm::vec2(1.f, 0.f) }); m->vertices.push_back({ glm::vec3(1.f, 1.f, 0.f), glm::vec3(), glm::vec2(1.f, 1.f) }); for (size_t i = 0; i < m->vertices.size(); ++i) { m->indices.push_back(i); } m->setupArrays(); return { m }; }
std::vector<std::shared_ptr<Mesh>> Mesh::createCube() { auto m = std::shared_ptr<Mesh>(new Mesh()); glm::vec3 norm_z_p(0.f, 0.f, 1.f); glm::vec3 norm_z_m(0.f, 0.f, -1.f); glm::vec3 norm_x_p(1.f, 0.f, 0.f); glm::vec3 norm_x_m(-1.f, 0.f, 0.f); glm::vec3 norm_y_p(0.f, 1.f, 0.f); glm::vec3 norm_y_m(0.f, -1.f, 0.f); glm::vec3 v_ppp(1.f, 1.f, 1.f); glm::vec3 v_ppm(1.f, 1.f, -1.f); glm::vec3 v_pmp(1.f, -1.f, 1.f); glm::vec3 v_pmm(1.f, -1.f, -1.f); glm::vec3 v_mpp(-1.f, 1.f, 1.f); glm::vec3 v_mpm(-1.f, 1.f, -1.f); glm::vec3 v_mmp(-1.f, -1.f, 1.f); glm::vec3 v_mmm(-1.f, -1.f, -1.f); glm::vec2 t_00(0.f, 0.f); glm::vec2 t_01(0.f, 1.f); glm::vec2 t_10(1.f, 0.f); glm::vec2 t_11(1.f, 1.f); // Front m->vertices.push_back({ v_mmp, norm_z_p, t_00 }); m->vertices.push_back({ v_pmp, norm_z_p, t_10 }); m->vertices.push_back({ v_ppp, norm_z_p, t_11 }); m->vertices.push_back({ v_ppp, norm_z_p, t_11 }); m->vertices.push_back({ v_mpp, norm_z_p, t_01 }); m->vertices.push_back({ v_mmp, norm_z_p, t_00 }); // Back m->vertices.push_back({ v_mmm, norm_z_m, t_00 }); m->vertices.push_back({ v_ppm, norm_z_m, t_11 }); m->vertices.push_back({ v_pmm, norm_z_m, t_10 }); m->vertices.push_back({ v_ppm, norm_z_m, t_11 }); m->vertices.push_back({ v_mmm, norm_z_m, t_00 }); m->vertices.push_back({ v_mpm, norm_z_m, t_01 }); // Left m->vertices.push_back({ v_mpp, norm_x_m, t_10 }); m->vertices.push_back({ v_mpm, norm_x_m, t_11 }); m->vertices.push_back({ v_mmm, norm_x_m, t_01 }); m->vertices.push_back({ v_mmm, norm_x_m, t_01 }); m->vertices.push_back({ v_mmp, norm_x_m, t_00 }); m->vertices.push_back({ v_mpp, norm_x_m, t_10 }); // Right m->vertices.push_back({ v_ppp, norm_x_p, t_10 }); m->vertices.push_back({ v_pmm, norm_x_p, t_01 }); m->vertices.push_back({ v_ppm, norm_x_p, t_11 }); m->vertices.push_back({ v_pmm, norm_x_p, t_01 }); m->vertices.push_back({ v_ppp, norm_x_p, t_10 }); m->vertices.push_back({ v_pmp, norm_x_p, t_00 }); // Top m->vertices.push_back({ v_mpm, norm_y_p, t_01 }); m->vertices.push_back({ v_ppp, norm_y_p, t_10 }); m->vertices.push_back({ v_ppm, norm_y_p, t_11 }); m->vertices.push_back({ v_ppp, norm_y_p, t_10 }); m->vertices.push_back({ v_mpm, norm_y_p, t_01 }); m->vertices.push_back({ v_mpp, norm_y_p, t_00 }); // Bottom m->vertices.push_back({ v_mmm, norm_y_m, t_01 }); m->vertices.push_back({ v_pmm, norm_y_m, t_11 }); m->vertices.push_back({ v_pmp, norm_y_m, t_10 }); m->vertices.push_back({ v_pmp, norm_y_m, t_10 }); m->vertices.push_back({ v_mmp, norm_y_m, t_00 }); m->vertices.push_back({ v_mmm, norm_y_m, t_01 }); for (size_t i = 0; i < m->vertices.size(); ++i) { m->indices.push_back(i); } m->setupArrays(); return { m }; }
std::vector<std::shared_ptr<Mesh>> Mesh::createTerrain() { auto m = std::shared_ptr<Mesh>(new Mesh()); int num_vertices = Settings::TerrainSize; float ter_from = -1.f; float ter_to = 1.f; float ter_s = ter_to - ter_from; noise::module::Perlin perlin; for (int i = 0; i <= num_vertices; ++i) { for (int j = 0; j <= num_vertices; ++j) { float x = (i * ter_s / num_vertices) + ter_from; float y = (j * ter_s / num_vertices) + ter_from; Vertex v; float z = 0.05f * static_cast<float>(perlin.GetValue(x + 1.0, y + 1.0, 0.5)); v.position = glm::vec3(x, y, z); v.normal = glm::vec3(0.f, 0.f, 0.f); //v.texture_coords = glm::vec2(j & 1 ? 1.f : 2.f, i & 1 ? 2.f : 1.f); v.texture_coords = glm::vec2(j, i); m->vertices.push_back(v); } } int n = Settings::TerrainSize; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { m->indices.push_back((i + 0) * (n + 1) + j + 0); m->indices.push_back((i + 1) * (n + 1) + j + 0); m->indices.push_back((i + 0) * (n + 1) + j + 1); m->indices.push_back((i + 0) * (n + 1) + j + 1); m->indices.push_back((i + 1) * (n + 1) + j + 0); m->indices.push_back((i + 1) * (n + 1) + j + 1); } } m->calculateNormals(); // Nowa tekstura for (int i = 0; i < 500; ++i) { int x = rand() % n; int y = rand() % n; int id = (x * n + y) * 6; int new_base = m->vertices.size(); auto v1 = m->vertices[m->indices[id + 0]]; auto v2 = m->vertices[m->indices[id + 2]]; auto v3 = m->vertices[m->indices[id + 1]]; auto v4 = m->vertices[m->indices[id + 5]]; auto change_coords = [](auto &v) { v.texture_coords.x = static_cast<int>(v.texture_coords.x) & 1 ? 1.f : 0.f; v.texture_coords.y = static_cast<int>(v.texture_coords.y) & 1 ? 1.f : 0.f; }; change_coords(v1); change_coords(v2); change_coords(v3); change_coords(v4); m->vertices.push_back(v1); m->vertices.push_back(v2); m->vertices.push_back(v3); m->vertices.push_back(v4); m->indices[id + 0] = new_base + 0; m->indices[id + 1] = new_base + 2; m->indices[id + 2] = new_base + 1; m->indices[id + 3] = new_base + 1; m->indices[id + 4] = new_base + 2; m->indices[id + 5] = new_base + 3; } m->setupArrays(); return { m }; }