static void addToOpenSet (astar_t *astar, int node, int nodeFrom) { coord_t nodeCoord = getCoord (astar->bounds, node); coord_t nodeFromCoord = getCoord (astar->bounds, nodeFrom); if (!exists (astar->open, node)) { astar->cameFrom[node] = nodeFrom; astar->gScores[node] = astar->gScores[nodeFrom] + preciseDistance (nodeFromCoord, nodeCoord); insert (astar->open, node, astar->gScores[node] + estimateDistance (nodeCoord, getCoord (astar->bounds, astar->goal))); } else if (astar->gScores[node] > astar->gScores[nodeFrom] + preciseDistance (nodeFromCoord, nodeCoord)) { astar->cameFrom[node] = nodeFrom; int oldGScore = astar->gScores[node]; astar->gScores[node] = astar->gScores[nodeFrom] + preciseDistance (nodeFromCoord, nodeCoord); double newPri = priorityOf (astar->open, node) - oldGScore + astar->gScores[node]; changePriority (astar->open, node, newPri); } }
void executor(void) { char numOfRobots; ModbusGetCoil(MODBUS_ROBOTS_COIL, &numOfRobots); sendUart1('S'); sendUart1('S'); sendUart1('S'); while(1) { getCoord('V', &bigX, &bigY); // prozivanje velikog bikona SRbits.IPL = 7; ModbusSetRegister(REG_V_X, bigX); ModbusSetRegister(REG_V_Y, bigY); SRbits.IPL = 0; if(numOfRobots == 1) // numOfRobots je binarni broj- 0 -> jedan robot, 1 -> dva robota { getCoord('M', &smallX, &smallY); // prozivanje malog bikona SRbits.IPL = 7; ModbusSetRegister(REG_M_X, smallX); ModbusSetRegister(REG_M_Y, smallY); SRbits.IPL = 0; } } }
bool searchMatrix(vector<vector<int>>& matrix, int target) { int m = matrix.size(); int n = matrix[0].size(); int left = 1, right = m * n; while(left != right) { pair<int, int> l = getCoord(left, m, n); int xleft = l.first, yleft = l.second; pair<int, int> r = getCoord(right, m, n); int xright = r.first, yright = r.second; if(target < matrix[xleft][yleft] || target > matrix[xright][yright]) return false; int mid = (left + right) >> 1; pair<int, int> mi = getCoord(mid, m, n); int x = mi.first, y = mi.second; if(matrix[x][y] < target) { left = mid + 1; } else if(matrix[x][y] == target) { return true; } else { right = mid; } } pair<int, int> sol = getCoord(left, m, n); return matrix[sol.first][sol.second] == target; }
static direction directionWeCameFrom (astar_t *astar, int node, int nodeFrom) { if (nodeFrom == -1) return NO_DIRECTION; return directionOfMove (getCoord (astar->bounds, node), getCoord (astar->bounds, nodeFrom)); }
static int init_astar_object (astar_t* astar, const char *grid, int *solLength, int boundX, int boundY, int start, int end) { *solLength = -1; struct coord_t bounds = {boundX, boundY}; int size = bounds.x * bounds.y; if (start >= size || start < 0 || end >= size || end < 0) return 0; struct coord_t startCoord = getCoord (bounds, start); struct coord_t endCoord = getCoord (bounds, end); if (!contained (bounds, startCoord) || !contained (bounds, endCoord)) return 0; astar->solutionLength = solLength; astar->bounds = bounds; astar->start = start; astar->goal = end; astar->grid = grid; astar->open = createQueue(); if (!astar->open) return 0; astar->closed = (char*)malloc (size); if (!astar->closed) { freeQueue (astar->open); return 0; } astar->gScores = (double*)malloc (size * sizeof (double)); if (!astar->gScores) { freeQueue (astar->open); free (astar->closed); return 0; } astar->cameFrom = (node*)malloc (size * sizeof (int)); if (!astar->cameFrom) { freeQueue (astar->open); free (astar->closed); free (astar->gScores); return 0; } memset (astar->closed, 0, size); astar->gScores[start] = 0; astar->cameFrom[start] = -1; insert (astar->open, astar->start, estimateDistance (startCoord, endCoord)); return 1; }
//met à jour la position du hero void CSatan::update(float elapsedTime) { boost::shared_ptr<IEntity> deadHero(m_deadHero.lock()); if(m_isDead || !deadHero) return; if(m_isTracking) { sf::Vector2f coord = getCoord(); float move = -elapsedTime*m_speed; if(coord.y + move <= deadHero->getCoord().y-50) { deadHero->getModel()->setActive(false); m_isTracking = false; move = deadHero->getCoord().y - coord.y; m_satanModel->setAnim("Hurt"); m_satanModel->setActiveHero(true); } setCoord(sf::Vector2f(coord.x, coord.y + move)); m_satanModel->SetPosition(getCoord()); } else { float x = getCoord().x; float move = elapsedTime*m_speed; sf::FloatRect screenRect = CGameEngine::instance()->getScreenRect(); if(x+move >= screenRect.Right - getDim().x - 50) { move = screenRect.Right - getDim().x - 50 - x; m_speed *= -1.f; } else if(x+move <= screenRect.Left + 50) { move = screenRect.Left + 50 - x; m_speed *= -1.f; } float y = CGameEngine::instance()->getScreenRect().Bottom - getDim().y - 50; float verMove = y -getCoord().y; std::vector<IEntity::SCollisionInfo> collisionResultVec = testVerticalCollision(verMove); foreach(IEntity::SCollisionInfo collisionInfo, collisionResultVec) { onTouch(collisionInfo.otherEntity); } collisionResultVec.clear(); collisionResultVec = testHorizontalCollision(move); foreach(IEntity::SCollisionInfo collisionInfo, collisionResultVec) { onTouch(collisionInfo.otherEntity); }
//Bloque ou non IEntity::CollisionType CPlateform::onTouch(boost::shared_ptr<IEntity> other) { CollisionType colType = NOTHING; if(m_isFloor && m_isRoof) colType = BLOCK; if(m_isFloor && other->getCoord().y + other->getDim().y <= getCoord().y) colType = BLOCK; else if(m_isRoof && other->getCoord().y >= getCoord().y + getDim().y) colType = BLOCK; return colType; }
void Search::SetExample() { // Test changing the missions waypoint count? search_mission.count = 2; search_mission.current_seq = 0; getCoord(15.0); dm_write(DM_KEY_WAYPOINTS_OFFBOARD(offboard), 0, DM_PERSIST_POWER_ON_RESET, &next_point, sizeof(struct mission_item_s)); offboard = (offboard == 0) ? 1 : 0; getCoord(15.0, 90); next_point.nav_cmd = NAV_CMD_WAYPOINT; dm_write(DM_KEY_WAYPOINTS_OFFBOARD(offboard), 1, DM_PERSIST_POWER_ON_RESET, &next_point, sizeof(struct mission_item_s)); offboard = (offboard == 0) ? 1 : 0; orb_publish(ORB_ID(offboard_mission), mission_pub, &search_mission); }
double Cell::phiVal_bcface(VecX<double> &phi, vector<shared_ptr<Boundary> > const &bc, int_2 const &bias) { auto bndr = (prev >= 0) ? -next-1 : -prev-1; auto row = (prev >= 0) ? prev : next; if (bc[bndr]->type == 0) { return bc[bndr]->b_val + phi[row]*bc[bndr]->a_val; } else if (bc[bndr]->type == 1) { auto c0 = grid->listCell[row]; auto norm = vol(); norm = norm/norm.abs(); double dx = norm*(getCoord() - c0->getCoord()); return dx*bc[bndr]->b_val + phi[row]*(1.0 + dx*bc[bndr]->a_val); } else { cout << "Cell (Quad) :: interp :: boundary condition type not recognized " << endl; exit(1); } }
void CDemon::shoot() { if(m_speed > 0) getModel()->setAnim("ShootRight"); else getModel()->setAnim("ShootLeft"); boost::shared_ptr<IModel> model(CGameEngine::instance()->getResEngine()->getModel("FireBall")); boost::shared_ptr<IEntity> fireBall(new CFireBall(m_speed,model)); fireBall->setDim(sf::Vector2f(50,50)); if(m_speed > 0) fireBall->setCoord(getCoord()+sf::Vector2f(getDim().x,25.f)); else fireBall->setCoord(getCoord()+sf::Vector2f(-fireBall->getDim().x,25.f)); CGameEngine::instance()->addEntity(fireBall); }
void FontPanel::addCode(MyGUI::xml::Element* _node, MyGUI::Char _code, MyGUI::IFont* _font) { MyGUI::GlyphInfo* info = _font->getGlyphInfo(_code); MyGUI::xml::Element* node = _node->createChild("Code"); node->addAttribute("index", _code); node->addAttribute("coord", getCoord(info->uvRect, _font->getTextureFont()->getWidth(), _font->getTextureFont()->getHeight(), info->width, _font->getDefaultHeight())); }
void ngbrCellbyDist(Vec3 r, vector<int_8> &ngbrCells, int_8 cp=0) { //cout << "ind = "<< cp << " r = (" << r << " ), size = " << ngbrCells.size() << endl; if (r[0] < 0 || r[1] < 0 || r[2] < 0) return; if (cp >= ngbrCells.size()) return; if (cp < 0) return; if (ngbrCells[cp] >= listCell.size()) return; if (ngbrCells[cp] < 0) return; auto c = listCell[ngbrCells[cp]]; for (auto i = 0; i < c->node.size(); ++i) { auto n = c->node[i]; auto cp2 = listVertex[n]->cell[(i+1)%4]; if (cp2 >= 0) { auto is = std::find(ngbrCells.begin(), ngbrCells.end(), cp2); if (is == ngbrCells.end()) { // new entry ngbrCells.emplace_back(cp2); is = ngbrCells.end()-1; } Vec3 dx = listCell[cp2]->getCoord() - c->getCoord(); dx[0] = r[0] - abs(dx[0])+1e-15; dx[1] = r[1] - abs(dx[1])+1e-15; dx[2] = r[2] - abs(dx[2])+1e-15; ngbrCellbyDist(dx, ngbrCells, is - ngbrCells.begin()); //ngbrCells.size()-1); } } }
RadialDistribution::RadialDistribution(uint dimentions, uint numOfPoints, num distBetwZeroAndEdge, num(*initFunc)(num)) { m_dim = dimentions; m_dist = distBetwZeroAndEdge; m_data = std::vector<num>(numOfPoints); for (uint i = 0; i < GetNumOfPoints(); i++) { m_data[i] = initFunc(getCoord(i)); } }
int CXXSurface::getCoord(const string &type, const int iTriangle, const int corner, double *buffer) { int relevantVector = getReadVectorHandle(type); if (relevantVector<0) return 1; int iVertex = triangles[iTriangle][corner]; return getCoord(relevantVector, iVertex, buffer); }
Vec3 VertexBuffer::calcCenterOfCoords() { Vec3 c(0,0,0); for(int i=0;i<array_len;i++) { c += getCoord(i); } c /= (float)array_len; return c; }
double Point::getDistance(Point *p) { double dist = 0; for (int i = 0; i < 3; i++) dist += pow(getCoord(i) - p->getCoord(i), 2.0); return sqrt(dist); }
num RadialDistribution::CountIntegral() { num h = getStepBetweenPoints(); num res = 0; switch (m_dim) { case 1: res = count_one_dim_int(m_data, getStepBetweenPoints()); break; case 2: for (uint i = 0; i < GetNumOfPoints(); i++) { res += 2 * M_PI * getCoord(i) * m_data[i] * getStepBetweenPoints(); } break; case 3: for (uint i = 0; i < GetNumOfPoints(); i++) { res += 4 * M_PI * getCoord(i) * getCoord(i) * m_data[i] * getStepBetweenPoints(); } break; default: throw new std::string("[RadialDistribution.cpp -- CountIntegral] неизвестная размерность"); break; } return res; }
//Avance la boule de feu void CFireBall::update(float timeElapsed) { sf::Vector2f coord = getCoord(); float move = m_speed * timeElapsed; std::vector<IEntity::SCollisionInfo> collisionResultVec = testHorizontalCollision(move); foreach(IEntity::SCollisionInfo collisionInfo, collisionResultVec) { onTouch(collisionInfo.otherEntity); }
// Write a column permutation explicitly void ColPerm::makeExplicit(Permut& out) const { long sz = getSize(); out.SetLength(sz); for (long k = 0; k < sz; k++) { long i = getCoord(k, dim); long pi_i = at(k); out.at(k) = addCoord(k, dim, pi_i-i); } }
void CDebris::update(float timeElapsed) { m_speed.y = SPEED; sf::Vector2f coord = getCoord(); sf::Vector2f move = m_speed; move *= timeElapsed; std::vector<IEntity::SCollisionInfo> collisionResultVec = testVerticalCollision(move.y); foreach(IEntity::SCollisionInfo collisionInfo, collisionResultVec) { onTouch(collisionInfo.otherEntity); }
void SeparatorV::notifyMouseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { MYGUI_ASSERT(mLeftPanel, "SeparatorV left panel must not be null."); MYGUI_ASSERT(mRightPanel, "SeparatorV left panel must not be null."); if (_id == MyGUI::MouseButton::Left) { mStartLeftPanel = mLeftPanel->getCoord(); mStartRightPanel = mRightPanel->getCoord(); mStartSeparatorV = getCoord(); mStartMousePosition = MyGUI::InputManager::getInstance().getMousePosition(); } }
//--------------------------------------------------------------------------- WorldViewWindow::WorldViewWindow(World* _world) : mRenderTarget(nullptr), mWorld(nullptr), mCamera(nullptr), mViewport(nullptr), mClosing(false) { mWorld = _world; mWorldName = mWorld->getName(); initialiseByAttributes(this); // Read the window's coordinates from the configuration file worldedit.cfg WorldEditSettings& wes = WorldEditSettings::getSingleton(); if(wes.hasSection(mWorldName)) { MyGUI::FloatCoord fcoord; fcoord.left = wes.getSetting<float>("WindowLeft", mWorldName, 0.1f); fcoord.top = wes.getSetting<float>("WindowTop", mWorldName, 0.1f); fcoord.width = wes.getSetting<float>("WindowWidth", mWorldName, 0.5f); fcoord.height = wes.getSetting<float>("WindowHeight", mWorldName, 0.5f); setCoord(fcoord); } else { static int sWindowIndex = 0; MyGUI::FloatPoint newWindowOffset = MyGUI::FloatPoint::parse(getWindow()->getUserString("NewWindowOffset")); MyGUI::FloatCoord fcoord = getCoord(); fcoord.left += newWindowOffset.left * sWindowIndex; fcoord.top += newWindowOffset.top * sWindowIndex; sWindowIndex++; if(fcoord.left < 1.0f && fcoord.top < 1.0f) { fcoord.width = std::min(fcoord.left + fcoord.width, 1.0f) - fcoord.left; fcoord.height = std::min(fcoord.top + fcoord.height, 1.0f) - fcoord.top; setCoord(fcoord); } } getWindow()->eventKeySetFocus += MyGUI::newDelegate(this, &WorldViewWindow::notifyKeySetFocus); // TRM_PT_VIEW_ALL mCanvas->createTexture(MyGUI::Canvas::TRM_PT_VIEW_ALL, MyGUI::TextureUsage::RenderTarget); mCanvas->eventPreTextureChanges += MyGUI::newDelegate(this, &WorldViewWindow::notifyPreTextureChanges); mCanvas->requestUpdateCanvas = MyGUI::newDelegate(this, &WorldViewWindow::requestUpdateCanvas); mCanvas->updateTexture(); updateCaption(); updateViewportAbsCoord(); registerWorldListener(); registerWorldObjectListener(); }
Scheme<double> Cell::phi(vector<shared_ptr<Boundary> > const &bc, int_2 bias) { Scheme<double> sch; if (next < 0 && prev < 0) { sch.push_pair(id, 1.0); } else { // use next and prev to compute phi; if (next >= 0 && prev >= 0) { if (bias == 0) { double dn = abs((grid->listCell[next]->getCoord() - getCoord())*vol()); double dp = abs((grid->listCell[prev]->getCoord() - getCoord())*vol()); sch.push_pair(prev, dn/(dn+dp)); sch.push_pair(next, dp/(dn+dp)); } else if (bias == -1) { sch.push_pair(prev, 1.0); } else if (bias == 1) { sch.push_pair(next, 1.0); } } else { auto bndr = (prev >= 0) ? -next-1 : -prev-1; auto row = (prev >= 0) ? prev : next; if (bc[bndr]->type == 0) { sch.push_constant(bc[bndr]->b_val); sch.push_pair(row, bc[bndr]->a_val); } else if (bc[bndr]->type == 1) { auto c0 = grid->listCell[row]; auto norm = vol(); norm = norm/norm.abs(); double dx = norm*(getCoord() - c0->getCoord()); sch.push_constant(dx*bc[bndr]->b_val); sch.push_pair(row, (1.0 + dx*bc[bndr]->a_val)); } else { cout << "Cell (Quad) :: interp :: boundary condition type not recognized " << endl; exit(1); } } } return sch; }
//gère les colision avec les autre entité IEntity::CollisionType CDemon::onTouch(boost::shared_ptr<IEntity> other) { if(other->className() == "CHero") { if(other->getCoord().y + other->getDim().y < getCoord().y) { CGameEngine::instance()->addScore(other,250); CGameEngine::instance()->deleteEntity(getHandle(),true); other->getHandle().to<CHero>()->bounce(600.f); } } return BLOCK; }
// path interpolation between jump points in here static int nextNodeInSolution (astar_t *astar, int *target, int node) { coord_t c = getCoord (astar->bounds, node); coord_t cTarget = getCoord (astar->bounds, *target); if (c.x < cTarget.x) c.x++; else if (c.x > cTarget.x) c.x--; if (c.y < cTarget.y) c.y++; else if (c.y > cTarget.y) c.y--; node = getIndex (astar->bounds, c); if (node == *target) *target = astar->cameFrom[*target]; return node; }
void CoordEditWindow::drawBack(DrawBuf buf,bool) const { Coord mark_dy=+cfg.mark_dy; MCoord width=+cfg.width; VColor line=+cfg.line; SmoothDrawArt art(buf); Point end=pos.addX(getCoord()); art.path(width,line,pos,end); art.path(width,line,pos.subY(mark_dy),pos.addY(mark_dy)); art.path(width,line,end.subY(mark_dy),end.addY(mark_dy)); }
//--------------------------------------------------------------------------- WorldViewWindow::~WorldViewWindow() { // Write the window's coordinates to the configuration file worldedit.cfg WorldEditSettings& wes = WorldEditSettings::getSingleton(); MyGUI::FloatCoord fcoord = getCoord(); wes.setSetting( "WindowLeft", mWorldName, fcoord.left ); wes.setSetting( "WindowTop", mWorldName, fcoord.top ); wes.setSetting( "WindowWidth", mWorldName, fcoord.width ); wes.setSetting( "WindowHeight", mWorldName, fcoord.height ); if(mCanvas) mCanvas->destroyTexture(); if(mWorld) mWorld->setViewport(nullptr); }
// For each position in the data vector, compute how many slots it should be // shifted inside its small permutation. // Return value is zero if all the shift amounts are zero, nonzero otherwise. long ColPerm::getShiftAmounts(Vec<long>& out) const { long sz = getSize(); out.SetLength(sz); long nonZero = 0; for (long k = 0; k < sz; k++) { long i = getCoord(k, dim); long pi_i = at(k); if (i != pi_i) nonZero = 1; out.at(addCoord(k, dim, pi_i-i)) = i - pi_i; } return nonZero; }
void ZoomAnimation::OnRender() { std::auto_ptr<Surface> pSurface( getSurface()->ZoomSurface( m_curZoom ) ); if(pSurface.get() == 0) { return; } Dim destDim = pSurface->GetDim(); Dim srcDim = getSurface()->GetDim(); Coord srcCoord = getCoord(); // 그림이 확대, 축소되면 이미지 위치로 확대 축소된 값에 따라 변한다. int x = srcCoord.getX() + (srcDim.getW() - destDim.getW() ) / 2; int y = srcCoord.getY() + (srcDim.getH() - destDim.getH() ) / 2; pSurface->SetColorKey(); pSurface->Blit( x, y ); pSurface->Free(); }
double Cell::phiVal_iface(VecX<double> &phi, int_2 const &bias) { if (next < 0 || prev < 0) { cout << "phiVal_iface: should be used on internal faces!" << endl; exit(1); } if (bias == 0) { auto area = vol(); auto xf = getCoord(); auto xp = grid->listCell[prev]->getCoord(); auto xn = grid->listCell[next]->getCoord(); double dn = abs( (xn-xf)*area ); double dp = abs( (xp-xf)*area ); return (phi[prev]*dn + phi[next]*dp)/(dn+dp); } else if (bias < 0) { return phi[prev]; } else { return phi[next]; } }