void rspfFilter::createMatrix(NEWMAT::Matrix& m, long width, double middle, double scale)const { NEWMAT::ColumnVector colVec(width); NEWMAT::RowVector rowVec(width); double t = 0.0; double val = 0.0; if(width == 1) { t = 0; val = filter(t, getSupport()); colVec[0] = val; rowVec[0] = val; } else { for(long index = 0; index < width; index++) { t = (double)index/(double)(width-1); t = middle + (t - .5)*scale; val = filter(t, getSupport()); colVec[index] = val; rowVec[index] = val; } } // do the outer product to construct the // filter matrix m = colVec * rowVec; }
bool Film::operator == (const Film& f) { return ((this->AbstractMedia::operator ==(f)) && (getRealisateur() == f.getRealisateur()) && (getScenariste() == f.getScenariste()) && (getActeursPrincipaux() == f.getActeursPrincipaux()) && (getType() == f.getType()) && (getDuree() == f.getDuree()) && (getSupport() == f.getSupport())); }
//************************************************************************************************** ossimRefPtr<ossimImageData> ossimScaleFilter::getTile( const ossimIrect& tileRect, ossim_uint32 resLevel) { if((!isSourceEnabled())|| (!theInputConnection)|| ((m_ScaleFactor.x == 1.0)&& (m_ScaleFactor.y == 1.0)&& (m_BlurFactor == 1.0))) { return ossimImageSourceFilter::getTile(tileRect, resLevel); } if(!m_Tile.valid()) { allocate(); } if(!m_Tile) { return ossimImageSourceFilter::getTile(tileRect, resLevel); } m_Tile->makeBlank(); ossimIrect imageRect = tileRect*m_InverseScaleFactor; m_Tile->setImageRectangle(tileRect); m_BlankTile->setImageRectangle(tileRect); double xSupport; double ySupport; getSupport(xSupport, ySupport); ossimIpt deltaPt; deltaPt.x = (ossim_int32)ceil(xSupport); deltaPt.y = (ossim_int32)ceil(ySupport); imageRect = ossimIrect(imageRect.ul().x - (deltaPt.x), imageRect.ul().y - (deltaPt.y), imageRect.lr().x + (deltaPt.x), imageRect.lr().y + (deltaPt.y)); runFilter(imageRect, tileRect); m_Tile->validate(); return m_Tile; }
bool VACBinaryConstraint::revise (VACVariable* var, Value v) { bool wipeout = false; VACVariable* xi = (VACVariable*) getVar(0); VACVariable* xj = (VACVariable*) getVar(1); Value sup = getSupport(var,v); Value minsup = sup; if(var != xi) { xi = (VACVariable*)getVar(1); xj = (VACVariable*)getVar(0); } Cost cost, minCost = wcsp->getUb(); if(xj->canbe(sup)) { if(xj->getVACCost(sup) != MIN_COST) { wipeout = xj->removeVAC(sup); } else { if (getVACCost(xi,xj,v,sup) == MIN_COST) { return false; } } } for (EnumeratedVariable::iterator it = xj->lower_bound(sup); it != xj->end(); ++it) { Value w = *it; if(xj->getVACCost(w) != MIN_COST) { wipeout = xj->removeVAC(w); xj->queueVAC(); } else { cost = getVACCost(xi,xj,v, w); if (cost == MIN_COST) { setSupport(xi,v,w); return false; } else if (cost < minCost) { minCost = cost; minsup = w; } } } for (EnumeratedVariable::iterator it = xj->begin(); it != xj->lower_bound(sup); ++it) { Value w = *it; if(xj->getVACCost(w) != MIN_COST) { wipeout = xj->removeVAC(w); xj->queueVAC(); } else { cost = getVACCost(xi,xj,v, w); if (cost == MIN_COST) { setSupport(xi,v,w); return false; } else if (cost < minCost) { minCost = cost; minsup = w; } } } setSupport(xi,v,minsup); return true; }
QLabel * ColumnarTableWidget::createLabel(const QString & text,const QString & style) const { // /// remove line breaks and leading/trailing spaces QString str = text.trimmed(); str = str.replace(QRegularExpression("\\r|\\n")," "); QLabel * l; if (! style.isEmpty()) { l = new QLabel(getSupport()->scanAndStyle(str,style)); } else { l = new QLabel(str); } return l; }
void Film::sauvegarde(QXmlStreamWriter & stream) { qDebug()<<"Sauvegade de "<<nom(); stream.writeStartElement("media"); stream.writeTextElement("nom", nom()); stream.writeTextElement("genre", genre()); stream.writeTextElement("date", date().toString("d/M/yyyy")); stream.writeTextElement("vue", QString::number(isFini())); stream.writeTextElement("url", url().toString()); stream.writeTextElement("type", getType()); stream.writeTextElement("realisateur", getRealisateur()); stream.writeTextElement("scenariste", getScenariste()); stream.writeTextElement("support", QString::number(getSupport())); stream.writeTextElement("duree", getDuree().toString()); foreach(QString jupiter, getActeursPrincipaux()) { stream.writeTextElement("acteur", jupiter); }
NEWMAT::RowVector *rspfFilter::newVector(long width, double middle, double scale)const { NEWMAT::RowVector *result = new NEWMAT::RowVector(width); double t = 0.0; double val = 0.0; for(long index = 0; index < width; index++) { t = (double)index/(double)(width-1); t = middle + (t- .5)*scale; val = filter(t, getSupport()); (*result)[index] = val; } return result; }
void VACVariable::VACextend (Value v, const Cost c) { decreaseCost(v,c); if (v == maxCostValue) queueNC(); assert(canbe(getSupport())); // if(cannotbe(getSupport()) || getCost(getSupport())>MIN_COST) { // TO BE REMOVED ??? // Value newSupport = getInf(); // Cost minCost = getCost(newSupport); // EnumeratedVariable::iterator iter = begin(); // for (++iter; minCost > MIN_COST && iter != end(); ++iter) { // Cost cost = getCost(*iter); // if (cost < minCost) { // minCost = cost; // newSupport = *iter; // } // } // assert(canbe(newSupport)); // // cout << "setsupport " << wcspIndex << " " << newSupport << endl; // setSupport(newSupport); // } }
void MtxLP::getSupport(strvec& support, int kind) const{ strvec cnames = getColNames(kind); getSupport(support, cnames, kind); }
bool SteerLib::GJK_EPA::EPA(std::vector<Util::Vector> shape1, std::vector<Util::Vector> shape2, std::vector<Util::Vector> simplex, float& depth, Util::Vector& mtv) { float DEPTHTOLERANCE = .01f; while(true) { //CONDITION? int index = simplex.size()-1; float penDepth; Util::Vector addSimplex; float closest; Util::Vector closestVector; Util::Vector edge; edge = simplex[index] - simplex[0]; closestVector = tripleProduct(edge, simplex[index], edge); //std::cout << closestVector; closestVector = closestVector / closestVector.norm(); //normalize vector //std::cout << closestVector << std::endl; closest = dotProduct(simplex[index], closestVector); for(int i=0; i < simplex.size()-1; i++) { //std::cout << simplex.size() << std::endl; //std::cout << simplex[i] << std::endl; Util::Vector testVector; float testDepth; edge = simplex[i+1] - simplex[i]; testVector = tripleProduct(edge, simplex[i], edge); //std::cout << testVector; testVector = testVector / testVector.norm(); //normalize vector //std::cout << testVector << std::endl; testDepth = dotProduct(simplex[i], testVector); if(testDepth < closest) { closest = testDepth; closestVector = testVector; index = i; } } addSimplex = getSupport(shape1, closestVector) - getSupport(shape2, closestVector*-1); penDepth = dotProduct(addSimplex, closestVector); //std::cout << closestVector << addSimplex << std::endl << std::endl; if(penDepth <= DEPTHTOLERANCE) { depth = penDepth; mtv = closestVector; return true; } if(index == simplex.size()-1) { if(simplex[simplex.size()-1] == addSimplex || simplex[0] == addSimplex) { depth = penDepth; mtv = closestVector; return true; } simplex.push_back(addSimplex); } else { std::vector<Util::Vector>::iterator it = simplex.begin(); for(int i=0; i <= index; i++) { it++; } //std::cout << *it << std::endl; if(*it == addSimplex || (*(it-1) == addSimplex)) { depth = penDepth; mtv = closestVector; return true; } simplex.insert(it, addSimplex); } } }
bool SteerLib::GJK_EPA::GJK(std::vector<Util::Vector> shape1, std::vector<Util::Vector> shape2, std::vector<Util::Vector>& simplex) { std::vector<std::vector<Util::Vector>> decomp1, decomp2; convexDecomp(decomp1, shape1); convexDecomp(decomp2, shape2); for(int i=0; i<decomp1.size(); i++) { for(int j=0; j<decomp2.size(); j++) { /*for(int k=0; k<decomp1.at(i).size(); k++) { std::cout << decomp1.at(i).at(k) << " "; } std::cout << std::endl; for(int k=0; k<decomp2.at(j).size(); k++) { std::cout << decomp2.at(j).at(k) << " "; } std::cout << std::endl;*/ Util::Vector v1, v2, v3; Util::Vector arbitraryVector = Util::Vector(1,0,0); //pick point on Minkowski difference v1 = getSupport(decomp1.at(i), arbitraryVector) - getSupport(decomp2.at(j), arbitraryVector*-1); //std::cout << getSupport(decomp1.at(i), arbitraryVector) << " " << getSupport(decomp2.at(j), arbitraryVector*-1) << std::endl; //std::cout << v1 << std::endl; //projection along v1 closest to origin arbitraryVector = v1*-1; v2 = getSupport(decomp1.at(i), arbitraryVector) - getSupport(decomp2.at(j), arbitraryVector*-1); //std::cout << v2 << std::endl; if(dotProduct(v2, arbitraryVector) <= 0) { //point added to simplex does not pass the origin, no intersect continue; } //find new vertex for simplex in direction of the origin arbitraryVector = tripleProduct(v1-v2, v2*-1, v1-v2); //std::cout << "new normal " << arbitraryVector << std::endl; if(arbitraryVector == Util::Vector(0,0,0)) { //these points are aligned with the origin float tempDot = dotProduct(v2-v1, v1*-1); float squaredLength = (v2.x-v1.x)*(v2.x-v1.x) + (v2.z-v1.z)*(v2.z-v1.z); if(tempDot < 0 || tempDot > squaredLength) //origin is not between the points, no intersect continue; } v3 = getSupport(decomp1.at(i), arbitraryVector) - getSupport(decomp2.at(j), arbitraryVector*-1); //std::cout << v3 << std::endl; while(true) { //CONDITION? //if(fabsf(v2.length() - v3.length()) <= EQUIVALENCERANGE || v1.length() - v3.length() <= EQUIVALENCERANGE) { if(v2 == v3 || v1 == v3) { //if the vertex closest to the origin is already in the simplex, no intersect break; } //std::cout << dotProduct(v3, arbitraryVector) << " " << " " << std::endl; if(dotProduct(v3, arbitraryVector) <= 0) //new point for simplex does not pass the origin, no intersect break; /*float findOrigin1, findOrigin2; //used to determine what partition of the extended edge minkowski difference that the origin is in findOrigin1 = dotProduct(v1-v3, v3*-1); std::cout << v1-v3 << std::endl; findOrigin2 = dotProduct(v2-v3, v3*-1); if(findOrigin1<0 && findOrigin2<0) //origin is outside simplex, no intersect break; else if(findOrigin1>=0 && findOrigin2>=0) { //origin is in simplex, shapes intersect std::vector<Util::Vector> returnSimplex; returnSimplex.push_back(v1); returnSimplex.push_back(v2); returnSimplex.push_back(v3); simplex = returnSimplex; std::cout << v1 << v2 << v3 << std::endl; for(int k=0; k<decomp1.at(i).size(); k++) { std::cout << decomp1.at(i).at(k) << " "; } std::cout << std::endl; for(int k=0; k<decomp2.at(j).size(); k++) { std::cout << decomp2.at(j).at(k) << " "; } return true; } if(findOrigin1>=0 && findOrigin2<0) { //keep v1, discard v2 v2 = v3; } else if(findOrigin1<0 && findOrigin2>=0) { //keep v2, discard v1 v1 = v2; v2 = v3; }*/ Util::Vector edge1, edge2; edge1 = v1-v3; edge2 = v2-v3; Util::Vector edge1Perp, edge2Perp; edge1Perp = Util::Vector(edge1.z*-1, 0, edge1.x); if(edge1Perp * edge2 > 0) edge1Perp = Util::Vector(edge1.z, 0, edge1.x*-1); edge2Perp = Util::Vector(edge2.z*-1, 0, edge2.x); if(edge2Perp * edge1 > 0) edge2Perp = Util::Vector(edge2.z, 0, edge2.x*-1); Util::Vector findOrigin1, findOrigin2; //std::cout << v1<<v2<<v3<< std::endl; findOrigin1 = edge1Perp; findOrigin2 = edge2Perp; /*findOrigin1 = tripleProduct(v1-v3, v2-v3, v2-v3); findOrigin2 = tripleProduct(v2-v3, v1-v3, v1-v3);*/ //std::cout << findOrigin1 << " " << findOrigin2 << std::endl; if(findOrigin1*(v3*-1)<=0 && findOrigin2*(v3*-1)<=0) { //simplex contains origin, intersects std::vector<Util::Vector> returnSimplex; returnSimplex.push_back(v1); returnSimplex.push_back(v2); returnSimplex.push_back(v3); simplex = returnSimplex; std::cout << v1 << v2 << v3 << std::endl; /*for(int k=0; k<decomp1.at(i).size(); k++) { std::cout << decomp1.at(i).at(k) << " "; } std::cout << std::endl; for(int k=0; k<decomp2.at(j).size(); k++) { std::cout << decomp2.at(j).at(k) << " "; }*/ return true; } else if(findOrigin1*(v3*-1)>0 && findOrigin2*(v3*-1)>0) { break; } else if(findOrigin1*(v3*-1)>0) { v2 = v3; } else { v1 = v2; v2 = v3; } arbitraryVector = tripleProduct(v1-v2, v2*-1, v1-v2); v3 = getSupport(decomp1.at(i), arbitraryVector) - getSupport(decomp2.at(j), arbitraryVector*-1); //std::cout << v1 << v2 << v3 << std::endl; } } } return false; }
void BattleItem::update(GameState &state, unsigned int ticks) { item->update(state, ticks); // May have exploded if (!tileObject) { return; } if (ticksUntilCollapse > 0) { if (ticksUntilCollapse > ticks) { ticksUntilCollapse -= ticks; } else { ticksUntilCollapse = 0; collapse(); } } if (!falling) { return; } if (ownerInvulnerableTicks > 0) { if (ownerInvulnerableTicks > ticks) { ownerInvulnerableTicks -= ticks; } else { ownerInvulnerableTicks = 0; } } if (collisionIgnoredTicks > 0) { if (collisionIgnoredTicks > ticks) { collisionIgnoredTicks -= ticks; } else { collisionIgnoredTicks = 0; } } int remainingTicks = ticks; auto previousPosition = position; auto newPosition = position; while (remainingTicks-- > 0) { velocity.z -= FALLING_ACCELERATION_ITEM; newPosition += this->velocity / (float)TICK_SCALE / VELOCITY_SCALE_BATTLE; } // Check if new position is valid // FIXME: Collide with units but not with us bool collision = false; auto c = checkItemCollision(previousPosition, newPosition); if (c) { collision = true; // If colliding with anything but ground, bounce back once switch (c.obj->getType()) { case TileObject::Type::Unit: case TileObject::Type::LeftWall: case TileObject::Type::RightWall: case TileObject::Type::Feature: if (!bounced) { // If bounced do not try to find support this time collision = false; bounced = true; newPosition = previousPosition; velocity.x = -velocity.x / 4; velocity.y = -velocity.y / 4; velocity.z = std::abs(velocity.z / 4); break; } // Intentional fall-through case TileObject::Type::Ground: // Let item fall so that it can collide with scenery or ground if falling on top of // it newPosition = {previousPosition.x, previousPosition.y, std::min(newPosition.z, previousPosition.z)}; break; default: LogError("What the hell is this item colliding with? Type is %d", (int)c.obj->getType()); break; } } // If moved but did not find support - check if within level bounds and set position if (newPosition != previousPosition) { auto mapSize = this->tileObject->map.size; // Collision with ceiling if (newPosition.z >= mapSize.z) { collision = true; newPosition.z = mapSize.z - 0.01f; velocity = {0.0f, 0.0f, 0.0f}; } // Collision with map edge if (newPosition.x < 0 || newPosition.y < 0 || newPosition.y >= mapSize.y || newPosition.x >= mapSize.x || newPosition.y >= mapSize.y) { collision = true; velocity.x = -velocity.x / 4; velocity.y = -velocity.y / 4; velocity.z = 0; newPosition = previousPosition; } // Fell below 0??? if (newPosition.z < 0) { LogError("Item at %f %f fell off the end of the world!?", newPosition.x, newPosition.y); die(state, false); return; } setPosition(newPosition); } if (collision) { if (findSupport()) { getSupport(); auto tile = tileObject->getOwningTile(); if (tile->objectDropSfx) { fw().soundBackend->playSample(tile->objectDropSfx, getPosition(), 0.25f); } } } }