// move object o in the direction it's facing void moveObject(object *o) { // If object is ship, adjust for player controls if (o->type == SHIP) { // Acceleration if (o->state & OBJ_ACCELERATING) { vector acc = scaleVec(&(o->dir), o->spd*dtheta); if (lengthVec(&acc) < MAXSPEED) o->vel = addVec(&(o->vel), &acc); } // Turning if (o->state & OBJ_TURNING_LEFT) { turnObject(o, o->turn*dtheta); } else if (o->state & OBJ_TURNING_RIGHT) { turnObject(o, o->turn*-dtheta); } } // If object is gib, rotate it if (o->type == GIB) turnObject(o, o->turn*dtheta); // translate object and wrap its position if necessary vector x = scaleVec(&(o->vel), dtheta); o->pos = addVec(&(o->pos), &x); wrapPosition(o); }
std::shared_ptr<TextField> TextField::create(std::shared_ptr<Skin> skin, std::shared_ptr<WrappableText> default_text, std::shared_ptr<WrappableText> typed_text, glm::vec4 background_color, float padding, float screen_width, float screen_height, float x_pos, float y_pos, float width, float height, const unsigned int layer) { auto vertex_data = VertexData(); vertex_data.addVec(VertexData::DATA_TYPE::GEOMETRY, generateRect(screen_width, screen_height, 0, 0, width, height)); vertex_data.addVec(VertexData::DATA_TYPE::TEX_COORDS, basisTexCoords()); default_text->setSize(width - (2.0 * padding), height - (2.0 * padding)); typed_text->setSize(width - (2.0 * padding), height - (2.0 * padding)); typed_text->setText(""); auto field = std::make_shared<TextField>(default_text, typed_text, vertex_data, skin, layer); field->setColor(background_color); field->setAnchorPoint(glm::vec2(x_pos, y_pos)); field->setWidth(width); field->setHeight(height); field->setTextPadding(padding); return field; }
void myConvKernel_naive() { float *filterOutput_buf = (float*) _mm_malloc(sizeof(float) * outputSize, 512); assert(filterOutput_buf != NULL); memset(outputPlanes, 0, outputSize * nOutputPlanes); #pragma omp parallel { int tid = omp_get_thread_num(); int nthreads = omp_get_num_threads(); int ioHeight_spos = BLOCK_LOW(tid, nthreads, ioHeight); int ioHeight_epos = BLOCK_LOW(tid + 1, nthreads, ioHeight); int oS_spos = ioHeight_spos * ioWidth; int oS_size = (ioHeight_epos - ioHeight_spos) * ioWidth; for (int opIndex = 0; opIndex < nOutputPlanes; opIndex++) { float *filterOutput = filterOutput_buf; float *outputPlane = outputPlanes + opIndex * outputSize; for (int ipIndex = 0; ipIndex < nInputPlanes; ipIndex++) { int wMatIndex = nInputPlanes * opIndex + ipIndex; float *inputPlane = inputPlanes + ipIndex * paddedInSize; float *weightMatrix = weights + wMatIndex * wSize; convolve3x3withPad( inputPlane, filterOutput, weightMatrix, ioHeight_spos, ioHeight_epos ); addVec(oS_size, filterOutput + oS_spos, outputPlane + oS_spos); } } #pragma omp barrier #pragma omp for for (int opIndex = 0; opIndex < nOutputPlanes; opIndex++) { int wMatIndex = nInputPlanes * opIndex; float *outputPlane = outputPlanes + opIndex * outputSize; addBias(outputSize, (float)(biases[opIndex]), outputPlane); scaleIfLessThanX(outputSize, outputPlane, 0.0, 0.1); } } _mm_free(filterOutput_buf); }
Block2(Vec3 n1, Vec3 n2, int_4 nx, int_4 ny):Grid(nx*ny*4) { Vec3 del = (n2 - n1); addVertex({ {n1[0], n1[1], n1[2]} ,{n2[0], n1[1], n1[2]} ,{n2[0], n2[1], n1[2]} ,{n1[0], n2[1], n1[2]} }); addCell({0,1,2,3}); (*listCell.rbegin())->convertToSimpleBlock({nx,ny}); setCurrentLevels(); makeFace(); //setQuadBoundary(); cout << "Block2: Cells: " << listCell.size(); cout << " Faces: " << nFace << endl; addVec("u"); }
Block2(initializer_list<double> n1, initializer_list<double > n2, int_4 nx, int_4 ny):Grid() { Vec3 node1 = n1; Vec3 node2 = n2; Vec3 del = (node2 - node1); meanD = min(del[0]/double(nx), del[1]/double(ny)); addVertex({ {node1[0], node1[1], node1[2]} ,{node2[0], node1[1], node1[2]} ,{node2[0], node2[1], node1[2]} ,{node1[0], node2[1], node1[2]} }); addCell({0,1,2,3}); (*listCell.rbegin())->convertToSimpleBlock({nx,ny}); setCurrentLevels(); makeFace(); //setQuadBoundary(); cout << "Block2: Cells: " << listCell.size(); cout << " Faces: " << nFace << endl; addVec("u"); //, "v", "w"}); }
vector localToWorld(vector *v, object *o) { vector r = rotateVec(v, o->ang); r = addVec(&r, &(o->pos)); return r; }