Node *AbsoluteTransformator::toAbsolute(Node *relativeRoot, glm::mat4 transform) { if (relativeRoot == nullptr) new Group(); glm::mat4 newTransform = relativeRoot->transform() * transform; Node *absoluteRoot; if (relativeRoot->children().size() > 0) { Group *absoluteGroup = new Group(); for (auto child : relativeRoot->children()) { Node *absoluteChild = toAbsolute(static_cast<Node *>(child), newTransform); if (absoluteChild != nullptr) { absoluteGroup->append(absoluteChild); } } absoluteRoot = absoluteGroup; } else { PolygonalDrawable *poly = dynamic_cast<PolygonalDrawable *>(relativeRoot); if (poly == nullptr) { absoluteRoot = new Group(); } else { auto relativeGeometry = poly->geometry(); auto vertices = relativeGeometry->copyVertices(); auto absoluteGeometry = new TriangleObject(); p_TriangleList triangles = absoluteGeometry->triangles(); for (auto index : relativeGeometry->indices()) { glm::vec4 homogenous = newTransform * glm::vec4(vertices.at(index), 1.0f); triangles->push_back(homogenous.xyz * (1 / homogenous.w)); } absoluteRoot = absoluteGeometry; } } absoluteRoot->setName(relativeRoot->name()); absoluteRoot->setReferenceFrame(Node::RF_Absolute); return absoluteRoot; }
void CommandParser::do_cd(){ int len; if (!is_loaded){ vd_puts("FILE SYSTEM NOT LOADED\n"); return ; } if(flpchange){ uloadfs(); } if ( strlen(first_arg) == 0){ vd_puts("Current Dir:"); vd_puts(curr_dir); return; } toAbsolute(first_arg); if ( ispresent(first_arg) == -1 ){ vd_puts( "THE DIRECTORY SEEMS TO BE ON A HOLIDAY !!\n" ); errormessage(geterror()); return; } if ( !is_dir(first_arg) ){ vd_puts( "The Specified File is not a directory\n" ); return; } strcpy(curr_dir,first_arg); }
void CurveWidget::mouseReleaseEvent(QMouseEvent *mouseEvent) { if (mouseEvent->button() == Qt::LeftButton) { leftPressed = false; if (mousePressBeginPoint != mousePressEndPoint) { center = (toAbsolute(mouseEvent->pos()) + toAbsolute(mousePressBeginPoint)) / 2; qreal aspectRatio = static_cast<qreal>(buffer.width()) / buffer.height(); qreal newScale; int aWidth = qAbs(mousePressBeginPoint.x() - mousePressEndPoint.x()); int aHeight = qAbs(mousePressBeginPoint.y() - mousePressEndPoint.y()); if (aspectRatio * aHeight > aWidth) { newScale = scale * (static_cast<qreal>(buffer.width()) / aWidth); } else { newScale = scale * (static_cast<qreal>(buffer.height()) / aHeight); } scale = qMin(newScale, MAX_SCALE); } } else if (mouseEvent->button() == Qt::RightButton) { rightPressed = false; if (mousePressBeginPoint != mousePressEndPoint) { center = (toAbsolute(mouseEvent->pos()) + toAbsolute(mousePressBeginPoint)) / 2; qreal aspectRatio = static_cast<qreal>(buffer.width()) / buffer.height(); qreal newScale; int aWidth = qAbs(mousePressBeginPoint.x() - mousePressEndPoint.x()); int aHeight = qAbs(mousePressBeginPoint.y() - mousePressEndPoint.y()); if (aspectRatio * aHeight > aWidth) { newScale = scale / (static_cast<qreal>(buffer.width()) / aWidth); } else { newScale = scale / (static_cast<qreal>(buffer.height()) / aHeight); } scale = qMax(newScale, MIN_SCALE); } } updatePlot(); }
int rmrf(char* file, int end) { char* oldPath = toAbsolute(file); char* orig = file; char* base = basename(file); struct stat* buff = malloc(sizeof(struct stat)); int i = stat(oldPath, buff); if(i) { fprintf(stderr, "ERROR: Couln't stat file: %s\n\t%s\n", oldPath, strerror(errno)); return EACCES == errno ? E_PERMISSION : E_NONEXIST; } if(S_ISDIR(buff->st_mode)) { DIR *dp; struct dirent *d; dp = opendir(oldPath); if (dp == NULL) { perror("open"); exit(1); } char* nPCP = malloc(sizeof(oldPath) + 250); strcpy(nPCP, oldPath); strcat(nPCP, "/"); char* suffix = nPCP+strlen(oldPath)+1; end = end == 0 ? strlen(oldPath) - strlen(base) : end; while (d = readdir(dp)) { if(!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) continue; strcpy(suffix,d->d_name); if(d->d_type == 4){ rmrf(nPCP, end); continue; } char* sop = malloc(strlen(file) + strlen(d->d_name) + 1); strcpy(sop, file); strcat(sop,"/"); strcat(sop, d->d_name); int l = unlink(sop); if(l){ fprintf(stderr, "ERROR: %s\n", strerror(errno)); return errno == ENOENT ? E_NONEXIST : E_PERMISSION; } free(sop); } closedir(dp); rmdir(oldPath); return SUCCESS; } rmf(oldPath); }
int rmf(char* file) { char* oldPath = toAbsolute(file); int l = unlink(oldPath); if(l){ fprintf(stderr, "ERROR: %s\n", strerror(errno)); return errno == ENOENT ? E_NONEXIST : E_PERMISSION; } if(oldPath == file) free(oldPath); return SUCCESS; }
Node *AbsoluteTransformator::toAbsoluteIgnoreRootTransform(Node *relativeRoot) { return toAbsolute(relativeRoot, relativeRoot->transformInverse()); }
Tial::VFS::NativeFSDriver::NativeFSDriver(const Utility::NativePath &nativeDirectory, const std::string &name) : Driver(_prepareName(name, nativeDirectory)), nativeDirectory(toAbsolute(nativeDirectory)) { assert(this->nativeDirectory.absolute()); }
void CommandParser::executeCommand(int cmd){ switch(cmd){ case WRI : toAbsolute(first_arg); do_wri(first_arg); break; case LIST : toAbsolute(first_arg); do_list(first_arg); break; case SHOW : toAbsolute(first_arg); do_show(first_arg); break; case APP : toAbsolute(first_arg); do_app(first_arg); break; case CD : do_cd(); break; case HELP : if (strlen(first_arg) == 0) do_helpd(); else do_help(first_arg); break; case MKFS : do_mkfs(); break; case REN : toAbsolute(first_arg); do_ren(first_arg , second_arg); break; case FINFO: toAbsolute(first_arg); do_info(first_arg); break; case LINK : toAbsolute(first_arg); toAbsolute(second_arg); do_link(first_arg , second_arg); break; case QUIT : do_quit();break; case CP : toAbsolute(first_arg); toAbsolute(second_arg); do_cp(first_arg , second_arg); break; case LOAD : do_load(); break; case ULOAD: do_uload(); break; case RF : toAbsolute(first_arg); do_rf(first_arg); break; case RMD : toAbsolute(first_arg); do_rmd(first_arg); break; case MKD : toAbsolute(first_arg); do_mkd(first_arg); break; case CHOWN : toAbsolute(first_arg); do_chown(first_arg,second_arg); break ; case CHPERM : toAbsolute(first_arg); do_chperm(first_arg,second_arg); break; case ADDUSER : do_adduser() ; break; case CLS : clrscr(); break; case REBOOT : // break; default: if ( strlen(command) ) vd_puts("Invalid Command\n"); } }