void HalfEdge::draw() {
	glBegin(GL_LINES);
	glColor3f(0.2,0.9,0.2);
	glVertex2d(getPos(0.0)[0], getPos(0.0)[1]);
	glVertex2d(getPos(1.0)[0], getPos(1.0)[1]);
	cout << getPos(0.0) << " " << getPos(1.0) << endl;
	glEnd();
}
void UpdateStatsPacket::writeStatsForObject(unsigned int networkId, std::unordered_map<ObjectAttributeIndex, double> attributes) {
    /* acquire values */
    unsigned char blockMask = 0;
    unsigned int valueMasks[8] = { 0 };
    std::pair<ObjectAttributeIndex, double> values[8][32];
    for(auto attribute : attributes) {
        auto index = attribute.first;
        blockMask |= index.getMajorMask();
        valueMasks[index.major] |= index.getMinorMask();
        values[index.major][index.minor] = attribute;
    }
    /* compress/encode */
    this->write<unsigned char>(blockMask);
    this->write<unsigned int>(networkId);
    for(unsigned char blockIndex = 0; blockIndex < 8; blockIndex++) {
        unsigned char currentBlockMask = 1 << blockIndex;
        if(!(currentBlockMask & blockMask)) {
            continue;
        }
        unsigned int blockValueMask = valueMasks[blockIndex];
        this->write<unsigned int>(blockValueMask);
        int blockSizePos = getPos();
        this->write<unsigned char>(0);
        for(unsigned char valueIndex = 0; valueIndex < 32; valueIndex++) {
            unsigned int currentValueMask = 1 << valueIndex;
            if(!(blockValueMask & currentValueMask)) {
                continue;
            }
            std::pair<ObjectAttributeIndex, double> attribute = values[blockIndex][valueIndex];
            if(attribute.first.type == FLOAT_VALUE) {
                this->writeEncoded<float>(attribute.second);
            } else {
                this->writeEncoded<unsigned long long>(attribute.second);
            }
        }
        this->writeAt<unsigned char>(getPos() - blockSizePos - 1, blockSizePos);
    }
}
void Kruskal(LGraph G)
{
	int p1, p2;
	int m, n;
	int index = 0;
	int vends[MAXN] = {0};	//用于保存"已有最小生成树"中每个顶点在该最小树中的终点。
							//for ex:已经有一条边AB了,那么vends[A.pos] = B.pos
	EData rets[MAXN];		//结果数组,保存生成树的边
	EData *edges;			//图对应的所有边
	
	edges = get_edges(G);
	sort_edges(edges, G.edgnum);

	for (int i = 0; i < G.edgnum; ++i)
	{
		p1 = getPos(G, edges[i].start);
		p2 = getPos(G, edges[i].end);

		m = get_end(vends, p1);
		n = get_end(vends, p2);
		//m != n说明没有形成环
		if (m != n)
		{
			vends[m] = n;
			rets[index++] = edges[i];
		}
	}
	free(edges);

	int length = 0;
	for (int i = 0; i < index; ++i)
		length += rets[i].weight;
	printf("Kruskal = %d: ", length);
	for (int i = 0; i < index; ++i)
		printf("(%c, %c) ", rets[i].start, rets[i].end);
	printf("\n");
	
}
void BZSpriteStarHolder::onUpdate()
{
	BZSpriteCommon::onUpdate();

	switch (_getState())
	{
	case ESHS_Blank:
		break;
	case ESHS_Filling:
		{
			int n = 0;
			CASprite* psprsRemoved[256];
			CAObject* pobj;
			CCARRAY_FOREACH(_pieces, pobj)
			{
				CASprite* pspr = (CASprite*)pobj;
				float p0 = pspr->getAnimationPercent(this->layer()->getTimeNow());
				float p = p0 + 0.1f;
				if (p > 1.0f) p = 1.0f;

				CCPoint pos;
				CCPoint posBegin = pspr->getPos();
				CCPoint posTo = getPos();
				pos.x = posBegin.x + (posTo.x - posBegin.x) * p;
				pos.y = posBegin.y + (posTo.y - posBegin.y) * p;

				_Info("star (%.2f) (%.2f,%.2f) (%.2f,%.2f) (%.2f,%.2f)", p0, pos.x, pos.y, posBegin.x, posBegin.y, posTo.x, posTo.y);

				pspr->setPos(pos);
				if (pspr->isAnimationDone())
				{
					pspr->setPos(posTo);
					pspr->killMyself();
					psprsRemoved[n++] = pspr;

					this->setState("on");
					_setState(ESHS_Filled);
				}
			}
			while (n > 0)
			{
				CASprite* pspr = psprsRemoved[n - 1];
				_pieces->removeObject(pspr);
				n--;
			}
		}
		break;
	case ESHS_Filled:
		break;
	}
Exemple #5
0
Math::Vector3d Actor::getWorldPos() const {
	if (! isAttached())
		return getPos();

	EMICostume * cost = static_cast<EMICostume *>(_attachedActor->getCurrentCostume());
	assert(cost != NULL);

	Math::Matrix4 attachedToWorld;
	attachedToWorld.setPosition(_attachedActor->getPos());
	attachedToWorld.buildFromPitchYawRoll(_attachedActor->getPitch(), _attachedActor->getYaw(), _attachedActor->getRoll());

	// If we were attached to a joint, factor in the joint's position & rotation,
	// relative to its actor.
	if (cost->_emiSkel && cost->_emiSkel->_obj) {
		Joint * j = cost->_emiSkel->_obj->getJointNamed(_attachedJoint);
		const Math::Matrix4 & jointToAttached = j->_finalMatrix;
		attachedToWorld = attachedToWorld * jointToAttached;
	}

	Math::Vector3d myPos = getPos();
	attachedToWorld.transform(&myPos, true);
	return myPos;
}
Exemple #6
0
//==========================================================
// Name :
// Desc : カメラ
//==========================================================
void CObj3dCar::camera()
{
	D3DXVECTOR3 rot = getRot();
	D3DXVECTOR3 pos = getPos();

	//Tamama
	_eye.x=pos.x-sinf(rot.y)*10;
	_eye.y=3.0f;
	_eye.z=pos.z-cosf(rot.y)*10;

	_at.x=pos.x;
	_at.y=1.0f;
	_at.z=pos.z;
}
Exemple #7
0
float TouchEvent::getHandOrientation() const
{
    if (getSource() == Event::TOUCH) {
        if (m_bHasHandOrientation) {
            return m_HandOrientation;
        } else {
            glm::vec2 screenCenter = Player::get()->getRootNode()->getSize()/2.f;
            return getAngle(getPos()-screenCenter);
        }
    } else {
        throw Exception(AVG_ERR_UNSUPPORTED,
                "TouchEvent::getHandOrientation: Only supported for touch events.");
    }
}
Exemple #8
0
bool RigidBody::getAtomPos(Vector3d& pos, Atom* atom) {
    std::vector<Atom*>::iterator i;
    i = find(atoms_.begin(), atoms_.end(), atom);
    if (i != atoms_.end()) {
        //RigidBody class makes sure refCoords_ and atoms_ match each other 
        Vector3d ref = body2Lab(refCoords_[i - atoms_.begin()]);
        pos = getPos() + ref;
        return true;
    } else {
        std::cerr << "Atom " << atom->getGlobalIndex() 
                      <<" does not belong to Rigid body "<< getGlobalIndex() << std::endl; 
        return false;
    }
}
Exemple #9
0
int Graph::rmVertex(Vertex const &v) {
    int vpos = getPos(v);
    if(vpos < getVertexSize()) {
        vector<Vertex *>::iterator iv = _vertexList.begin() + vpos;
        Vertex *tmp = *iv;
        vector<Edge *> adjEdge = tmp->getAdj();
        for(auto edge : adjEdge) {
            rmEdge(*edge);
        }
        _vertexList.erase(iv);
        delete tmp;
    }
    return vpos;
}
Exemple #10
0
int Graph::rmEdge(Edge const &e) {
    int epos = getPos(e);
    if(epos < getEdgeSize()) {
        vector<Edge *>::iterator iv = _edgeList.begin() + epos;
        Edge *tmp = *iv;
        Vertex *v = tmp->getVertex();
        Vertex *w = tmp->getOther(*v);
        v->rmAdjEdge(*tmp);
        w->rmAdjEdge(*tmp);
        _edgeList.erase(iv);
        delete tmp;
    }
    return epos;
}
 bool isRectangleCover(vector<vector<int>>& rectangles) {
     int n = rectangles.size();
     if (n == 0) {
         return false;
     }
     vector<Rect> rects;
     for (int i = 0; i < n; ++i) {
         rects.emplace_back(rectangles[i]);
     }
     Rect r = rects[0];
     for (int i = 1; i < n; ++i) {
         r.bottom = min(r.bottom, rects[i].bottom);
         r.left = min(r.left, rects[i].left);
         r.top = max(r.top, rects[i].top);
         r.right = max(r.right, rects[i].right);
     }
     unordered_map<u64, int> hit_map;
     for (auto& a : rects) {
         hit_map[getP(a.bottom, a.left)]++;
         hit_map[getP(a.bottom, a.right)]++;
         hit_map[getP(a.top, a.left)]++;
         hit_map[getP(a.top, a.right)]++;
     }
     for (auto& pair : hit_map) {
         int y, x;
         getPos(pair.first, &y, &x);
         if ((y == r.bottom || y == r.top) && (x == r.left || x == r.right)) {
             if (pair.second != 1) {
                 printf("y = %d, x = %d, count = %d\n", y, x, pair.second);
                 return false;
             }
         } else {
             if (pair.second != 2 && pair.second != 4) {
                 printf("t2, y = %d, x = %d, count = %d\n", y, x, pair.second);
                 return false;
             }
         }
     }
     u64 total_area = (u64)(r.top - r.bottom) * (r.right - r.left);
     u64 sum_area = 0;
     for (auto& r : rects) {
         u64 a = (u64)(r.top - r.bottom) * (r.right - r.left);
         if (a + sum_area < sum_area) {
             return false;
         }
         sum_area += a;
     }
     printf("sum_area = %lld, total_area = %lld\n", sum_area, total_area);
     return sum_area == total_area;
 }
Exemple #12
0
/**
    \fn open
    \brief dtor
*/
bool tsPacket::open(const char *filenames,FP_TYPE append)
{
    _file=new fileParser();
    if(!_file->open(filenames,&append))
    {
        printf("[DmxPS] cannot open %s\n",filenames);
        delete _file;
        _file=NULL;
        return false;
    }
    _size=_file->getSize();

    // Detect TS1/TS2...
        printf("[TsPacket] Detecting TS/TS2...\n");

        uint8_t r;
        int tryMe=250;
        while(tryMe--)
        {
            r=_file->read8i();
            if(r==TS_MARKER) break;
            if(_file->end()) 
            {
                tryMe=0;
            }
        }
        if(!tryMe) 
        {
            printf("[TsPacket] Cannot sync ???\n");
            return true;
        }
        uint64_t startPos=getPos()-1;
        int score1,score2;

        setPos(startPos);
        score1=score(_file,20,0);
        setPos(startPos);
        score2=score(_file,20,4);
        printf("[TsPacket] Score : 188:%d, 192:%d out of 20\n",score1,score2);
        if(score2 && score2>score1)
        {
            printf("[TsPacket] Probably TS2 (192)...\n");
            extraCrap=4;
        }else
        {
            printf("[TsPacket] Probably TS1 (188)...\n");
        }
        setPos(0);
        return true;
}
Exemple #13
0
void CGrenade::update()
{
	CBullet::update();

	m_fGravity += GRENADEGRAVITY;

	m_vMoveVector.y += m_fGravity;

	if(m_eState == StateB_Life)
	if(getPos().y>GRENADEGROUND)
	{
		m_eState = StateB_Crash;
	}
}
void Stream::copyTo(Stream *stream, int64_t numBytes) {
	const int block_size = 512;
	char data[block_size];
	size_t copied = 0;

	size_t amount = (numBytes == -1) ? (getSize() - getPos()) : (size_t) numBytes;
	for (size_t i=0; i<amount; i+=block_size) {
		size_t blockSize = (i + block_size) <= amount ? block_size : amount-i;
	
		read(data, blockSize);
		copied += blockSize;
		stream->write(data, blockSize);
	}
}
bool FT_EDS_Door::appendDE(edsId id, edsType type, uint8_t* data, uint16_t len)
{
    unsigned int pos = getPos(id);
    if(0==pos)
        return false;

	uint32_t offsetOld = read32(pos+6);
	if(0==offsetOld)
	{
		return updateDE(id, type, data, len);
	}

	if(type != EDS_BYTE_ARRAY || read16(pos+2) != EDS_BYTE_ARRAY)
	{
		return false;
	}

	if(checkKey(id, data, len))
	{
		//Only add data once!
		return true;
	}

	uint16_t lenOld = read16(pos+4);
	uint32_t point  = read32(pos+6);

	if(point != posFreeData)
	{
		//Only allow the last data to grow,
		//the others has data before or after!
		return false;
	}

	lenOld += len;
    write16(pos+4, (uint16_t)lenOld);  //deLen

	point -= len;
	write32(pos+6, point); //deData

	for( unsigned int i=0 ; i<len ; i++ )
	{
		EEPROM.write(point+i, data[i]);
	}

	posFreeData = point;
    //write16(pos+2, (uint16_t)type); //deType

	return true;
}
//[sky] 召唤士兵(每个士兵都是一个独立的个体不同以召唤兽或者宠物)
int SceneArchitecture::summonSoldiers(DWORD id, Cmd::petType type, WORD num, DWORD sid, const char * name, DWORD anpcid,zPos pos,BYTE dir)
{
	zNpcB *base = npcbm.get(id);
	zNpcB *abase = NULL;
	if (anpcid>0) abase = npcbm.get(anpcid);
	if (NULL == base) return false;

	t_NpcDefine define;
	define.id = base->id;
	strncpy(define.name,base->name,MAX_NAMESIZE-1);
	if (pos.x != 0 && pos.y !=0)
		define.pos = pos;
	else
		define.pos = getPos();
	define.num = 1;
	define.interval = 5;
	define.initstate = zSceneEntry::SceneEntry_Normal;
	define.width = 6;
	define.height = 6;
	define.pos -= zPos(define.width/2,define.height/2);
	define.scriptID = sid;
	scene->initRegion(define.region,define.pos,define.width,define.height);

	int NewNum = 0;
	SceneNpc * newPet = NULL;

	for( int i=0; i< num; i++ )
	{
		newPet = scene->summonOneNpc<SceneNpc>(define,pos,base,dupIndex,0,abase,dir,this);

		if (newPet)
		{
			//sky 设置召唤出来的士兵的阵营和召唤者一样
			newPet->BattCampID = this->BattCampID;

			if (name&&(0!=strncmp(name,"",MAX_NAMESIZE)))
				strncpy(newPet->name,name,MAX_NAMESIZE-1);

			SceneNpcManager::getMe().addSpecialNpc(newPet);

			newPet->aif = newPet->aif | AIF_ACTIVE_MODE;
			newPet->setDir(dir);
			newPet->setSpeedRate( 2.0 );
			NewNum++;
		}
	}

	return NewNum;
}
void CBaseChar::colliderUpdate()
{
	switch(m_eCollider)
	{
	case Coll_Air:

		if(getPos().y > GROUNDPOS)
		{
			m_eCollider = Coll_Ground;
			setPos(ccp(getPos().x,GROUNDPOS));
			m_faddGrivity=0;
			m_vMoveVector.y =0;
		}
		else
		{
			m_faddGrivity += CHARGRAVITY;
		}
		break;
	case Coll_Ground:
		m_faddGrivity = 0;
		m_vMoveVector.y = 0;
		setPos(ccp(getPos().x,GROUNDPOS));
		break;
	case Coll_Box:
		m_faddGrivity = 0;
		m_vMoveVector.y = 0;
		setPos(ccp(getPos().x,BOXPOS));
		break;
	case Coll_Jump:
		m_vMoveVector.y = -JUMPPOWER;
		m_eCollider = Coll_Air;
		break;
	}

	m_vMoveVector.y += m_faddGrivity;
}
Exemple #18
0
void Balaenidae::getViewPort(Vec3f &Up, Vec3f &position, Vec3f &forward)
{
    position = getPos();
    forward = getForward();
    Up = toVectorInFixedSystem(0.0f, 1.0f, 0.0f,0,0);

    Vec3f orig;


    forward = forward.normalize();
    orig = position;
    Up[0]=Up[2]=0;Up[1]=100;// poner en 4 si queres que este un toque arriba desde atras.
    position = position - 400*forward + Up;
    forward = orig-position;
}
Exemple #19
0
 void draw(const struct EmbStitchList_ * a, const struct EmbStitchList_ * b, const float intensity) {
     if (EM_NORMAL != a->stitch.flags && EM_NORMAL != b->stitch.flags) {
         return;
     }
     // The circles for the two stitches are only drawn if the flag is "EM_NORMAL",
     // thereby we avoid drawing circles for intermediate jumps, trims etc.
     if (isNormal(a)) {
         cv::circle(img, getPos(a), std::round(radius*scale), cv::Scalar(intensity), -1);
         cv::circle(mask, getPos(a), std::round(radius*scale), 255, 0);
     }
     if (isNormal(b)) {
         cv::circle(img, getPos(b), std::round(radius*scale), cv::Scalar(intensity), -1);
         cv::circle(mask, getPos(b), std::round(radius*scale), 255, -1);
     }
     cv::line(img, getPos(a), getPos(b), cv::Scalar(intensity), std::round(scale * lineWidth));
     cv::line(mask, getPos(a), getPos(b), 255, std::round(scale * lineWidth));
 }
Exemple #20
0
/*			private			*/
void GrowingLimb::onUpdate()
{
	if (fruit)
	{
		if (!fruit->isDetached())
		{
			fruit->transform().setPosition(getPos() + je::lengthdir(transform().getScale().x * TreeSize * length, -transform().getRotation()));
		}
		else
		{
			fruit = nullptr;
		}
	}
	else if (children.empty() && !leaves.empty() && je::random(3000) == 0)
	{
		fruit = new Fruit(level, getPos() + je::lengthdir(transform().getScale().x * TreeSize * length, -transform().getRotation()));
		level->addEntity(fruit);
	}

	for (sf::Sprite& leaf : leaves)
	{
		leaf.setPosition(je::lengthdir(transform().getScale().x * TreeSize * length, transform().getRotation()));
	}
}
Exemple #21
0
	LineString Bezier3::getLineString(const double start, const double end, const uint32 quality) const
	{
		const double length = end - start;
		const double d = length / (quality + 1);

		LineString pts(quality + 2);
		Vec2* pDst = pts.data();

		for (uint32 i = 0; i <= (quality + 1); ++i)
		{
			*pDst++ = getPos(start + d * i);
		}

		return pts;
	}
Exemple #22
0
void oak::Window::showFullScreen(bool fullscreen)
{
    makeCurrent();
    if (fullscreen)
    {
        getPos(&_lastX, &_lastY);
        getSize(&_lastWidth, &_lastHeight);
        glutFullScreen();
    }
    else
    {
        setSize(_lastWidth, _lastHeight);
        setPos(_lastX, _lastY);
    }
}
Exemple #23
0
// ojo, no pinta cuando distance es mayor que 1. Testear esto!!!!!!!!!!!!!!
bool RailPen::move(int distance, Sim * sim){
	Point p = getPos();
	if(getMode() == PAINTING){
		if(distance>0){
			for(int n= 0; n<distance;n++){
				Rail * newRail = makeNewRail(sim->railMap.getRailAt(p.row, p.col));
				sim->railMap.setRail(p.row, p.col, newRail);

				ForkRail *rf = dynamic_cast<ForkRail *>(newRail);
				if(rf){
					sim->addFork(rf);
				}

				Point lastPoint = getPos();
				Dir lastDir = getLastDir();
				Dir backDir = -lastDir; 
				lastPoint.move(backDir);
				Rail * lastRail = sim->railMap.getRailAt(lastPoint.row, lastPoint.col);
				if(lastRail){
					newRail->linkRailAt(backDir, lastRail);
				}
			 	forward();	
			}
		}else{
			for(int n=0; n>distance;n--){
				Point p = getPos();
				sim->railMap.setRail(p.row, p.col, 0);
				backwards();
			}
		}
	}else{
		pos.move(dir, distance);
		lastDir=dir;
	}
	return true;
}
/**
 * If this is a &gt;&gt;&gt; substitution, use ruleToUse to fill in
 * the substitution.  Otherwise, just use the superclass function.
 * @param number The number being formatted
 * @toInsertInto The string to insert the result of this substitution
 * into
 * @param pos The position of the rule text in toInsertInto
 */
void
ModulusSubstitution::doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t _pos) const
{
    // if this isn't a >>> substitution, just use the inherited version
    // of this function (which uses either a rule set or a DecimalFormat
    // to format its substitution value)
    if (ruleToUse == NULL) {
        NFSubstitution::doSubstitution(number, toInsertInto, _pos);

        // a >>> substitution goes straight to a particular rule to
        // format the substitution value
    } else {
        int64_t numberToFormat = transformNumber(number);
        ruleToUse->doFormat(numberToFormat, toInsertInto, _pos + getPos());
    }
}
Exemple #25
0
void HandGUI::draw(tank::Camera const& cam)
{
    for (unsigned int i = 0; i < 6; ++i)
    {
        cardSlots_[i].draw(cam);

        if (summoner_->getField().isActive(i))
        {
            tank::Vectorf pos = getPos() + tank::Vectorf{
                        static_cast<float>(settings::cardSpace * i), 0.f};

            overlay_.setPos(pos);
            overlay_.draw(cam);
        }
    }
}
Exemple #26
0
void TouchManager::touchesEnded(const ds::ui::TouchEvent &event) {
	for (auto touchIt = event.getTouches().begin(); touchIt != event.getTouches().end(); ++touchIt) {
		int fingerId = touchIt->getId() + MOUSE_RESERVED_IDS;

		if(mDiscardTouchMap[fingerId]){
			continue;
		}

		ci::Vec2f touchPos = touchIt->getPos();
		if(mOverrideTranslation && !event.getInWorldSpace()){
			overrideTouchTranslation(touchPos);
		}

		inputEnded(fingerId, touchPos);
	}
}
Exemple #27
0
bool		readInteger(void)
{
  int		nTmp;

  readWs();
  nTmp = getPos();
  if (readEOFAt(nTmp) == false && isdigit(getByte(nTmp)))
    {
      nTmp = nTmp + 1;
      while (readEOFAt(nTmp) == false && isdigit(getByte(nTmp)))
	nTmp = nTmp + 1;
      setPos(nTmp);
      return (true);
    }
  return (false);
}
std::string GlobSessionPacket::toStr() const
{
	std::string globStr = SessionPacket::toStr() + "GlobSessionPacket:\n";

	for (std::vector<SessionPacket*>::const_iterator cit = m_pPackets.begin(); cit != m_pPackets.end(); cit++)
	{
		globStr += "\n* ";
		globStr += (*cit)->toStr();
		globStr += "\n";
	}

	globStr += str(boost::format("Glob functions: getPos(): %1%, getLength(): %2%, getAdjust(): %3%, getRev(): %4%, getRemoteRev(): %5%\n") 
					% getPos() % getLength() % getAdjust() % getRev() % getRemoteRev());
	
	return globStr;
}
Exemple #29
0
bool		readUntil(char cC, char cInhibitor)
{
  int		nSave;

  readWs();
  nSave = getPos();
  while (readEOF() == false)
    {
      readChar(cInhibitor);
      if (readChar(cC) == true)
	return (true);
      incPos();
    }
  setPos(nSave);
  return (false);
}
/*send information about how to draw itself*/
void LevelObject::redrawForClients(Game* game,MyLevel* level,bool checkChanges) {
	bool changesCheck= !checkChanges || changed();
	if(changesCheck){
		if(level->posInWindow(getPos())){
			std::stringstream msj;
			b2Vec2 corner;
			this->copyCorner(corner);
			msj<<MOVE<<" "<<getId()<<" "<<level->posToString(corner);
			game->notify(new MessageSent(msj.str(),0));
		}else{
			std::stringstream msj;
			msj<<MOVE<<" "<<getId()<<" 27 15";
			game->notify(new MessageSent(msj.str(),0));
		}
	}
}