MTV Collision::getCollision(const sf::Sprite& object1,Entity::ENTITY_SHAPE shape1,const sf::Sprite& object2,Entity::ENTITY_SHAPE shape2){ //Use Separating Axis Theorem to determine whether two objects are overlapping //See documentation for full explanation of this algorithm //Get the oriented bounding box in world coordinates (includes rotation) of objects OBB obb1 = getOBB(object1); OBB obb2 = getOBB(object2); float rot = object1.getRotation(); double overlap = LONG_MAX; maths::Vector2 smallest(0,0); std::vector<maths::Vector2> axis1; std::vector<maths::Vector2> axis2; maths::Vector2 circleCentre1; maths::Vector2 circleCentre2; sf::FloatRect gbounds1 = object1.getGlobalBounds(); sf::FloatRect gbounds2 = object2.getGlobalBounds(); //Find all the axes to check using SAT based on shapes of objects //Works with squares/rectangles or circles //Rectangles only need 2 axes because they have 2 sets of parallel lines if(shape1 == Entity::SHAPE_CIRCLE && shape2 == Entity::SHAPE_CIRCLE){ //If both shapes are circles, the only axis needed is the axis between centres of circles circleCentre1 = maths::Vector2(gbounds1.left + gbounds1.width / 2, gbounds1.top + gbounds1.height / 2); circleCentre2 = maths::Vector2(gbounds2.left + gbounds2.width / 2, gbounds2.top + gbounds2.height / 2); axis1.push_back(maths::Vector2(circleCentre1 - circleCentre2).normalise()); }else if(shape1 != shape2){ //if one shape is circle and one shape is rectangle maths::Vector2 circleCentre; sf::FloatRect squareRect; float rotation; //First get the unrotated bounding box and centre of the circle of the 2 objects if(shape1 == Entity::SHAPE_CIRCLE){ circleCentre = maths::Vector2(gbounds1.left + gbounds1.width / 2, gbounds1.top + gbounds1.height / 2); circleCentre1 = circleCentre; squareRect = getOriginalBoundingBox(object2); rotation = object2.getRotation(); }else if(shape2 == Entity::SHAPE_CIRCLE){ circleCentre = maths::Vector2(gbounds2.left + gbounds2.width / 2, gbounds2.top + gbounds2.height / 2); circleCentre2 = circleCentre; squareRect = getOriginalBoundingBox(object1); rotation = object1.getRotation(); } maths::Vector2 squareCentre(squareRect.left + squareRect.width / 2, squareRect.top + squareRect.height / 2); OBB* square = (shape1 == Entity::SHAPE_SQUARE ? &obb1 : &obb2); maths::Vector2 relativeCircleCentre = circleCentre.rotate(-rotation, squareCentre); //get circle centre in relation to the rotated square bool vertice = false; maths::Vector2 axis; maths::Vector2 topLeft(squareRect.left, squareRect.top); maths::Vector2 topRight(squareRect.left + squareRect.width, squareRect.top); maths::Vector2 botLeft(squareRect.left, squareRect.top + squareRect.height); maths::Vector2 botRight(squareRect.left + squareRect.width, squareRect.top + squareRect.height); //Get the closest vertex of the rectangle to the circle centre. //The axis to check is the vector between these 2 points. if(circleCentre.x < topLeft.x){ if(circleCentre.y < topLeft.y){ vertice = true; axis = topLeft; }else if(circleCentre.y > botLeft.y){ vertice = true; axis = botLeft; }else{ axis = maths::Vector2(topLeft - botLeft).normalise(); } }else if(circleCentre.x > topRight.x){ if(circleCentre.y < topLeft.y){ vertice = true; axis = topRight; }else if(circleCentre.y > botLeft.y){ vertice = true; axis = botRight; }else{ axis = maths::Vector2(topRight - botRight).normalise(); } }else{ if(circleCentre.y < topLeft.y){ axis = maths::Vector2(topRight - topLeft).normalise(); }else if(circleCentre.y > botLeft.y){ axis = maths::Vector2(botLeft - botRight).normalise(); }else{ //contains point! } } if(vertice){ axis1.push_back(maths::Vector2(circleCentre - axis).normalise()); }else{ axis1.push_back(maths::Vector2(topRight - topLeft).normalise()); axis1.push_back(maths::Vector2(topRight - botRight).normalise()); } }else{ //If both shapes are rectangles //Get vectors for sides of shapes maths::Vector2 Xside1(obb1.bot_left - obb1.bot_right); maths::Vector2 Yside1(obb1.top_left - obb1.bot_left); maths::Vector2 Xside2(obb2.bot_left - obb2.bot_right); maths::Vector2 Yside2(obb2.top_left - obb2.bot_left); //Axes requires are perpendicular to the sides of the shape //Vector2.perpendicular() normalises for greater accuracy axis1.push_back(Xside1.perpendicular()); axis1.push_back(Yside1.perpendicular()); axis2.push_back(Xside2.perpendicular()); axis2.push_back(Yside2.perpendicular()); } //We have all the axes to check. //Now find details on collisions with projections. for(int i=0;i<axis1.size();i++){ //Get projection of axis for both shapes maths::Vector2 axis = axis1[i]; Projection projection1 = project(obb1, axis); if(shape1 == Entity::SHAPE_CIRCLE){ float radius = gbounds1.width / 2; projection1 = projectCircle(circleCentre1, radius, axis); } Projection projection2 = project(obb2, axis); if (shape2 == Entity::SHAPE_CIRCLE){ float radius = gbounds2.width / 2; projection2 = projectCircle(circleCentre2, radius, axis); } //If a projection does not overlap, we know the objects do not collide so we can exit the function. //Otherwise, the MTV (minimum translation vector required to make the objects not collide) is calculated. if(!projection1.overlap(projection2)){ return MTV::NONE; }else{ //The axis with the smallest overlap is the axis used to calculate MTV, so record it. double o = projection1.getOverlap(projection2); if(o < overlap){ overlap = o; //set smallest overlap smallest = axis; //set smallest separation vector } } } //Repeat the same process as above with the other set of axes. for(int i=0;i<axis2.size();i++){ maths::Vector2 axis = axis2[i]; Projection projection1 = project(obb1, axis); if(shape1 == Entity::SHAPE_CIRCLE){ float radius = gbounds1.width/2; projection1 = projectCircle(circleCentre1, radius, axis); } Projection projection2 = project(obb2,axis); if(shape2 == Entity::SHAPE_CIRCLE){ float radius = gbounds2.width / 2; projection2 = projectCircle(circleCentre2, radius, axis); } if(!projection1.overlap(projection2)){ return MTV::NONE; }else{ double o = projection1.getOverlap(projection2); if(o < overlap){ overlap = o; smallest = axis; } } } //Get the vector from the centre of object 2 to the centre of object 1 maths::Vector2 centre1 = maths::Vector2(gbounds1.left + gbounds1.width / 2, gbounds1.top + gbounds1.height / 2); maths::Vector2 centre2 = maths::Vector2(gbounds2.left + gbounds2.width / 2, gbounds2.top + gbounds2.height / 2); maths::Vector2 between = centre1 - centre2; //If the separation vector is in the opposite direction of 'between', flip it round by negating it if(between.dot(smallest) < 0){ smallest = -smallest; } MTV mtv(overlap, smallest); return mtv; }
// Create a new instance of the default project. auto_release_ptr<Project> DefaultProjectFactory::create() { // Create a project. auto_release_ptr<Project> project(ProjectFactory::create("default")); // Add default configurations to the project. project->add_default_configurations(); // Create a scene. auto_release_ptr<Scene> scene(SceneFactory::create()); // Create an assembly. auto_release_ptr<Assembly> assembly( AssemblyFactory::create("assembly", ParamArray())); // Create an instance of the assembly and insert it into the scene. scene->assembly_instances().insert( AssemblyInstanceFactory::create( "assembly_inst", ParamArray(), *assembly, Transformd(Matrix4d::identity()))); // Insert the assembly into the scene. scene->assemblies().insert(assembly); // // Camera. // { // Create a pinhole camera. // Film dimensions are 0.980 in × 0.735 in (24.892 mm x 18.669 mm). // Reference: http://en.wikipedia.org/wiki/Aspect_ratio_(image). ParamArray params; params.insert("film_dimensions", "0.024892 0.018669"); params.insert("focal_length", "0.035"); auto_release_ptr<Camera> camera( PinholeCameraFactory().create("camera", params)); // Attach the camera to the scene. scene->set_camera(camera); } // // Frame. // { // Create a frame. ParamArray params; params.insert("camera", scene->get_camera()->get_name()); params.insert("resolution", "640 480"); params.insert("color_space", "srgb"); auto_release_ptr<Frame> frame(FrameFactory::create("beauty", params)); // Attach the frame to the project. project->set_frame(frame); } // Attach the scene to the project. project->set_scene(scene); // Return the newly created project. return project; }
static void _shatter_device_spell(int cmd, variant *res) { switch (cmd) { case SPELL_NAME: var_set_string(res, "Shatter Device"); break; case SPELL_DESC: var_set_string(res, "Destroy a magical device in your inventory for various effects."); break; case SPELL_CAST: { int item; object_type *o_ptr; var_set_bool(res, FALSE); item_tester_hook = item_tester_hook_recharge; if (!get_item(&item, "Shatter which device?", "You have nothing to shatter.", USE_INVEN)) return; o_ptr = &inventory[item]; var_set_bool(res, TRUE); if (_object_is_(o_ptr, TV_STAFF, SV_STAFF_DESTRUCTION)) { if (destroy_area(py, px, 15 + p_ptr->lev + randint0(11), 4 * p_ptr->lev)) msg_print("The dungeon collapses..."); else msg_print("The dungeon trembles."); } else if ( _object_is_(o_ptr, TV_STAFF, SV_STAFF_HEALING) || _object_is_(o_ptr, TV_ROD, SV_ROD_HEALING) || _object_is_(o_ptr, TV_ROD, SV_ROD_RESTORATION) ) { msg_print("You feel life flow through your body!"); restore_level(); (void)set_poisoned(0, TRUE); (void)set_blind(0, TRUE); (void)set_confused(0, TRUE); (void)set_image(0, TRUE); (void)set_stun(0, TRUE); (void)set_cut(0, TRUE); (void)do_res_stat(A_STR); (void)do_res_stat(A_CON); (void)do_res_stat(A_DEX); (void)do_res_stat(A_WIS); (void)do_res_stat(A_INT); (void)do_res_stat(A_CHR); update_stuff(); hp_player(5000); } else if (_object_is_(o_ptr, TV_ROD, SV_ROD_TELEPORT_AWAY)) { banish_monsters(p_ptr->lev * 4); } else { project(0, 5, py, px, k_info[o_ptr->k_idx].level * 16, _object_dam_type(o_ptr), PROJECT_STOP | PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL, -1); } inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); break; } default: default_spell(cmd, res); break; } }
bool VACVariable::averaging() { Cost Top = wcsp->getUb(); bool change = false; EnumeratedVariable* x; EnumeratedVariable* y; Constraint* ctr = NULL; ConstraintList::iterator itc = getConstrs()->begin(); if(itc != getConstrs()->end()) ctr = (*itc).constr; while(ctr) { if(ctr->arity() == 2 && !ctr->isSep()) { BinaryConstraint* bctr = (BinaryConstraint*) ctr; x = (EnumeratedVariable*) bctr->getVarDiffFrom( (Variable*) this ); for (iterator it = begin(); it != end(); ++it) { Cost cu = getCost(*it); Cost cmin = Top; for (iterator itx = x->begin(); itx != x->end(); ++itx) { Cost cbin = bctr->getCost(this,x,*it,*itx); if(cbin < cmin) cmin = cbin; } assert(cmin < Top); Double mean = to_double(cmin + cu) / 2.; Double extc = to_double(cu) - mean; if(abs(extc) >= 1) { Cost costi = (Long) extc; for (iterator itx = x->begin(); itx != x->end(); ++itx) { bctr->addcost(this,x,*it,*itx,costi); } if(mean > to_double(cu)) project(*it, -costi); else extend(*it, costi); change = true; } } } else if(ctr->arity() == 3 && !ctr->isSep()) { TernaryConstraint* tctr = (TernaryConstraint*) ctr; x = (EnumeratedVariable*) tctr->getVar( 0 ); if(x == this) x = (EnumeratedVariable*) tctr->getVar( 1 ); y = (EnumeratedVariable*) tctr->getVarDiffFrom((Variable*) this, (Variable*)x); for (iterator it = begin(); it != end(); ++it) { Cost cu = getCost(*it); Cost cmin = Top; for (iterator itx = x->begin(); itx != x->end(); ++itx) { for (iterator ity = y->begin(); ity != y->end(); ++ity) { Cost ctern = tctr->getCost(this,x,y,*it,*itx,*ity); if(ctern < cmin) cmin = ctern; }} assert(cmin < Top); Double mean = to_double(cmin + cu) / 2.; Double extc = to_double(cu) - mean; if(abs(extc) >= 1) { Cost costi = (Long) extc; for (iterator itx = x->begin(); itx != x->end(); ++itx) { for (iterator ity = y->begin(); ity != y->end(); ++ity) { tctr->addCost(this,x,y,*it,*itx,*ity,costi); }} if(mean > to_double(cu)) project(*it, -costi); else extend(*it, costi); change = true; } } } else if(ctr->arity() >= 4 && ctr->extension() && !ctr->isSep()) { NaryConstraint* nctr = (NaryConstraint*) ctr; for (iterator it = begin(); it != end(); ++it) { Cost cu = getCost(*it); Cost cmin = Top; int tindex = nctr->getIndex(this); String tuple; Cost cost; Long nbtuples = 0; nctr->first(); while (nctr->next(tuple,cost)) { nbtuples++; if (toValue(tuple[tindex] - CHAR_FIRST)==(*it) && cost < cmin) cmin = cost; } if (nctr->getDefCost() < cmin && nbtuples < nctr->getDomainSizeProduct()) cmin = nctr->getDefCost(); // assert(cmin < Top); Double mean = to_double(cmin + cu) / 2.; Double extc = to_double(cu) - mean; if(abs(extc) >= 1) { Cost costi = (Cost) extc; if(nctr->getDefCost() < Top) { nctr->firstlex(); while( nctr->nextlex(tuple,cost) ) { if (toValue(tuple[tindex] - CHAR_FIRST)==(*it)) { if(cost + costi < Top) nctr->setTuple(tuple, cost + costi); else nctr->setTuple(tuple, Top); } } nctr->setDefCost(Top); } else { nctr->first(); while( nctr->next(tuple,cost) ) { if (toValue(tuple[tindex] - CHAR_FIRST)==(*it)) { if(cost + costi < Top) nctr->addtoTuple(tuple, costi); else nctr->setTuple(tuple, Top); } } } if(mean > to_double(cu)) project(*it, -costi); else extend(*it, costi); change = true; } } } ++itc; if(itc != getConstrs()->end()) ctr = (*itc).constr; else ctr = NULL; } return change; }
void VisualStudioProvider::createProjectFile(const std::string &name, const std::string &uuid, const BuildSetup &setup, const std::string &moduleDir, const StringList &includeList, const StringList &excludeList) { const std::string projectFile = setup.outputDir + '/' + name + getProjectExtension(); std::ofstream project(projectFile.c_str()); if (!project) error("Could not open \"" + projectFile + "\" for writing"); project << "<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n" "<VisualStudioProject\n" "\tProjectType=\"Visual C++\"\n" "\tVersion=\"" << _version << ".00\"\n" "\tName=\"" << name << "\"\n" "\tProjectGUID=\"{" << uuid << "}\"\n" "\tRootNamespace=\"" << name << "\"\n" "\tKeyword=\"Win32Proj\"\n"; project << "\tTargetFrameworkVersion=\"131072\"\n"; project << "\t>\n" "\t<Platforms>\n" "\t\t<Platform Name=\"Win32\" />\n" "\t\t<Platform Name=\"x64\" />\n" "\t</Platforms>\n" "\t<Configurations>\n"; // Check for project-specific warnings: std::map< std::string, std::list<std::string> >::iterator warningsIterator = _projectWarnings.find(name); if (setup.devTools || setup.tests || name == setup.projectName) { std::string libraries; for (StringList::const_iterator i = setup.libraries.begin(); i != setup.libraries.end(); ++i) libraries += ' ' + *i + ".lib"; // Win32 outputConfiguration(project, setup, libraries, "Debug", "Win32", "", true); outputConfiguration(project, setup, libraries, "Analysis", "Win32", "", true); outputConfiguration(project, setup, libraries, "LLVM", "Win32", "", true); outputConfiguration(project, setup, libraries, "Release", "Win32", "", true); // x64 // For 'x64' we must disable NASM support. Usually we would need to disable the "nasm" feature for that and // re-create the library list, BUT since NASM doesn't link any additional libraries, we can just use the // libraries list created for IA-32. If that changes in the future, we need to adjust this part! outputConfiguration(project, setup, libraries, "Debug", "x64", "64", false); outputConfiguration(project, setup, libraries, "Analysis", "x64", "64", false); outputConfiguration(project, setup, libraries, "LLVM", "Win32", "64", false); outputConfiguration(project, setup, libraries, "Release", "x64", "64", false); } else { bool enableLanguageExtensions = find(_enableLanguageExtensions.begin(), _enableLanguageExtensions.end(), name) != _enableLanguageExtensions.end(); bool disableEditAndContinue = find(_disableEditAndContinue.begin(), _disableEditAndContinue.end(), name) != _disableEditAndContinue.end(); std::string warnings = ""; if (warningsIterator != _projectWarnings.end()) for (StringList::const_iterator i = warningsIterator->second.begin(); i != warningsIterator->second.end(); ++i) warnings += *i + ';'; std::string toolConfig; toolConfig = (!warnings.empty() ? "DisableSpecificWarnings=\"" + warnings + "\"" : ""); toolConfig += (disableEditAndContinue ? "DebugInformationFormat=\"3\" " : ""); toolConfig += (enableLanguageExtensions ? "DisableLanguageExtensions=\"false\" " : ""); // Win32 outputConfiguration(setup, project, toolConfig, "Debug", "Win32", ""); outputConfiguration(setup, project, toolConfig, "Analysis", "Win32", ""); outputConfiguration(setup, project, toolConfig, "LLVM", "Win32", ""); outputConfiguration(setup, project, toolConfig, "Release", "Win32", ""); outputConfiguration(setup, project, toolConfig, "Debug", "x64", "64"); outputConfiguration(setup, project, toolConfig, "Analysis", "x64", "64"); outputConfiguration(setup, project, toolConfig, "LLVM", "x64", "64"); outputConfiguration(setup, project, toolConfig, "Release", "x64", "64"); } project << "\t</Configurations>\n" "\t<Files>\n"; std::string modulePath; if (!moduleDir.compare(0, setup.srcDir.size(), setup.srcDir)) { modulePath = moduleDir.substr(setup.srcDir.size()); if (!modulePath.empty() && modulePath.at(0) == '/') modulePath.erase(0, 1); } if (modulePath.size()) addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix + '/' + modulePath); else addFilesToProject(moduleDir, project, includeList, excludeList, setup.filePrefix); // Output auto-generated test runner if (setup.tests) { project << "\t\t<File RelativePath=\"test_runner.cpp\" />\n"; } project << "\t</Files>\n" "</VisualStudioProject>\n"; }
bool QmakeAndroidBuildApkStep::init(QList<const BuildStep *> &earlierSteps) { if (AndroidManager::checkForQt51Files(project()->projectDirectory())) emit addOutput(tr("Found old folder \"android\" in source directory. Qt 5.2 does not use that folder by default."), ErrorOutput); if (!AndroidBuildApkStep::init(earlierSteps)) return false; QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target()->kit()); if (!version) return false; QString command = version->qmakeProperty("QT_HOST_BINS"); if (!command.endsWith(QLatin1Char('/'))) command += QLatin1Char('/'); command += QLatin1String("androiddeployqt"); if (Utils::HostOsInfo::isWindowsHost()) command += QLatin1String(".exe"); QString deploymentMethod; if (m_deployAction == MinistroDeployment) deploymentMethod = QLatin1String("ministro"); else if (m_deployAction == DebugDeployment) deploymentMethod = QLatin1String("debug"); else if (m_deployAction == BundleLibrariesDeployment) deploymentMethod = QLatin1String("bundled"); ProjectExplorer::BuildConfiguration *bc = buildConfiguration(); QString outputDir = bc->buildDirectory().appendPath(QLatin1String(Constants::ANDROID_BUILDDIRECTORY)).toString(); const auto *pro = static_cast<QmakeProjectManager::QmakeProject *>(project()); const QmakeProjectManager::QmakeProFileNode *node = pro->rootProjectNode()->findProFileFor(proFilePathForInputFile()); m_skipBuilding = !node; if (m_skipBuilding) return true; QString inputFile = node->singleVariableValue(QmakeProjectManager::AndroidDeploySettingsFile); if (inputFile.isEmpty()) { m_skipBuilding = true; return true; } QStringList arguments; arguments << QLatin1String("--input") << inputFile << QLatin1String("--output") << outputDir << QLatin1String("--deployment") << deploymentMethod << QLatin1String("--android-platform") << AndroidManager::buildTargetSDK(target()) << QLatin1String("--jdk") << AndroidConfigurations::currentConfig().openJDKLocation().toString(); if (m_verbose) arguments << QLatin1String("--verbose"); if (m_useGradle) arguments << QLatin1String("--gradle"); else arguments << QLatin1String("--ant") << AndroidConfigurations::currentConfig().antToolPath().toString(); QStringList argumentsPasswordConcealed = arguments; if (version->qtVersion() >= QtSupport::QtVersionNumber(5, 6, 0)) { if (bc->buildType() == ProjectExplorer::BuildConfiguration::Debug) arguments << QLatin1String("--gdbserver"); else arguments << QLatin1String("--no-gdbserver"); } if (m_signPackage) { arguments << QLatin1String("--sign") << m_keystorePath.toString() << m_certificateAlias << QLatin1String("--storepass") << m_keystorePasswd; argumentsPasswordConcealed << QLatin1String("--sign") << QLatin1String("******") << QLatin1String("--storepass") << QLatin1String("******"); if (!m_certificatePasswd.isEmpty()) { arguments << QLatin1String("--keypass") << m_certificatePasswd; argumentsPasswordConcealed << QLatin1String("--keypass") << QLatin1String("******"); } } ProjectExplorer::ProcessParameters *pp = processParameters(); setupProcessParameters(pp, bc, arguments, command); // Generate arguments with keystore password concealed ProjectExplorer::ProcessParameters pp2; setupProcessParameters(&pp2, bc, argumentsPasswordConcealed, command); m_command = pp2.effectiveCommand(); m_argumentsPasswordConcealed = pp2.prettyArguments(); return true; }
Utils::FileName QmakeAndroidBuildApkStep::androidPackageSourceDir() const { QmakeProjectManager::QmakeProject *pro = static_cast<QmakeProjectManager::QmakeProject *>(project()); const QmakeProjectManager::QmakeProFileNode *node = pro->rootProjectNode()->findProFileFor(proFilePathForInputFile()); if (!node) return Utils::FileName(); QFileInfo sourceDirInfo(node->singleVariableValue(QmakeProjectManager::AndroidPackageSourceDir)); return Utils::FileName::fromString(sourceDirInfo.canonicalFilePath()); }
MLIB_INLINE L mlib::Plane<PLANE,P,V,L>::project(const L& l) const { return L(project(l.point()), project(l.vector())); }