Ejemplo n.º 1
0
extern brkp *AddBreak( address addr )
{
    brkp        *bp;

    for( bp = BrkList; bp != NULL; bp = bp->next ) {
        if( AddrComp( bp->loc.addr, addr ) == 0 ) {
            DoActPoint( bp, TRUE );
            DbgUpdate( UP_BREAK_CHANGE );
            return( bp );
        }
    }
    bp = AddPoint( addr, MAD_NIL_TYPE_HANDLE, FALSE );
    if( bp == NULL ) return( NULL );
    RecordBreakEvent( bp, B_SET );
    return( bp );
}
Ejemplo n.º 2
0
void FTContour::evaluateCubicCurve(FTPoint A, FTPoint B, FTPoint C, FTPoint D)
{
    for(unsigned int i = 0; i < BEZIER_STEPS; i++)
    {
        float t = static_cast<float>(i) / BEZIER_STEPS;

        FTPoint U = (1.0f - t) * A + t * B;
        FTPoint V = (1.0f - t) * B + t * C;
        FTPoint W = (1.0f - t) * C + t * D;

        FTPoint M = (1.0f - t) * U + t * V;
        FTPoint N = (1.0f - t) * V + t * W;

        AddPoint((1.0f - t) * M + t * N);
    }
}
Ejemplo n.º 3
0
int DBrush::BuildPoints()
{
    ClearPoints();

    if(faceList.size() <= 3)	// if less than 3 faces, there can be no points
        return 0;					// with only 3 faces u can't have a bounded soild

    for(list<DPlane *>::const_iterator p1=faceList.begin(); p1!=faceList.end(); p1++)
    {
        list<DPlane *>::const_iterator p2=p1;
        for(p2++; p2!=faceList.end(); p2++)
        {
            list<DPlane *>::const_iterator p3=p2;
            for(p3++; p3!=faceList.end(); p3++)
            {
                vec3_t pnt;
                if((*p1)->PlaneIntersection(*p2, *p3, pnt))
                {
                    int pos = PointPosition(pnt);

                    if(pos == POINT_IN_BRUSH)
                    {   // ???? shouldn't happen here
                        Sys_Printf("ERROR:: Build Brush Points: Point IN brush!!!\n");
                    }
                    else if(pos == POINT_ON_BRUSH)
                    {   // normal point
                        if(!HasPoint(pnt))
                            AddPoint(pnt);
                        /*						else
                        							Sys_Printf("Duplicate Point Found, pyramids ahoy!!!!!\n");*/
                        // point lies on more that 3 planes
                    }

                    // otherwise point is removed due to another plane..

                    // Sys_Printf("(%f, %f, %f)\n", pnt[0], pnt[1], pnt[2]);
                }
            }
        }
    }

#ifdef _DEBUG
//	Sys_Printf("%i points on brush\n", pointList.size());
#endif

    return pointList.size();
}
Ejemplo n.º 4
0
void Route::CloneTrack( Route *psourceroute, int start_nPoint, int end_nPoint, const wxString & suffix)
{
    if( psourceroute->m_bIsInLayer ) return;

    m_bIsTrack = psourceroute->m_bIsTrack;

    m_RouteNameString = psourceroute->m_RouteNameString + suffix;
    m_RouteStartString = psourceroute->m_RouteStartString;
    m_RouteEndString = psourceroute->m_RouteEndString;

    bool b_splitting = GetnPoints() == 0;

    int startTrkSegNo;
    if( b_splitting ) startTrkSegNo = psourceroute->GetPoint( start_nPoint )->m_GPXTrkSegNo;
    else
        startTrkSegNo = this->GetLastPoint()->m_GPXTrkSegNo;

    int i;
    for( i = start_nPoint; i <= end_nPoint; i++ ) {

        RoutePoint *psourcepoint = psourceroute->GetPoint( i );
        RoutePoint *ptargetpoint = new RoutePoint( psourcepoint->m_lat, psourcepoint->m_lon,
                psourcepoint->GetIconName(), psourcepoint->GetName(), GPX_EMPTY_STRING, false );

        AddPoint( ptargetpoint, false );
        
        //    This is a hack, need to undo the action of Route::AddPoint
        ptargetpoint->m_bIsInRoute = false;
        ptargetpoint->m_bIsInTrack = true;
        
        CloneAddedTrackPoint( m_pLastAddedPoint, psourcepoint );

        int segment_shift = psourcepoint->m_GPXTrkSegNo;

        if(  start_nPoint == 2 ) 
            segment_shift = psourcepoint->m_GPXTrkSegNo - 1; // continue first segment if tracks share the first point

        if( b_splitting )
            m_pLastAddedPoint->m_GPXTrkSegNo = ( psourcepoint->m_GPXTrkSegNo - startTrkSegNo ) + 1;
        else
            m_pLastAddedPoint->m_GPXTrkSegNo = startTrkSegNo + segment_shift;
    }

    FinalizeForRendering();

}
Ejemplo n.º 5
0
void TerrainFunction::ModifyVertex(const vec2& world_flat_pos, vec3& vertex) const {
	const float distance = world_flat_pos.GetDistance(position_);
	if (distance < outer_radius_) {
		// We made it!
		float _scale;
		if (distance <= inner_radius_) {
			// This point is inside, or on, the inner radius.
			_scale = 1;
		} else {
			// We linearly down-scale our method parameter. This does not necessarily mean
			// that the parameter is used in a linear fasion.
			_scale = 1-(distance-inner_radius_)/(outer_radius_-inner_radius_);
		}
		const vec2 relative_normalized_pos = (world_flat_pos - position_) / outer_radius_;
		AddPoint(relative_normalized_pos.x, relative_normalized_pos.y, _scale, distance, vertex);
	}
}
Ejemplo n.º 6
0
int CPointsCollection::EditPoint(int index, double x, double y, BOOL bRescan)
{
	if (index<0 || index>=GetSize()) return -1;
	int ret;
	SSinglePoint ssp(x, y);
	//if bSortX not specified - just replace given point
	RemovePoint(index, FALSE);
	if (!bSortX)
	{
		InsertPoint(index, ssp.x, ssp.y, bRescan);
		ret = index;
	} else
	{
		int res;
		ret = AddPoint(&ssp, bRescan, &res);
	};
	return ret;
}
Ejemplo n.º 7
0
int RotateBlade4Covise(struct covise_info *ci, int nob)
{
	int i, j, ipol, ivx;
	int np, npol, nvx;
	int nstart, nend;
	float rot, roma[2][2];
	float x, y, z;

	np		   = ci->p->nump;
	npol	   = ci->pol->num;
	nvx		   = ci->vx->num;
	rot		   = 2 * M_PI / nob;
	roma[0][0] =  cos(rot);
	roma[0][1] = -sin(rot);
	roma[1][0] =  sin(rot);
	roma[1][1] =  cos(rot);

	for (i = 0; i < nob-1; i++) {
		nstart = i * np;
		nend   = nstart + np;
		// calculate rotated blade point coordinates
		for (j = nstart; j < nend; j++)
		{
			x = ci->p->x[j] * roma[0][0] + ci->p->y[j] * roma[0][1];
			y = ci->p->x[j] * roma[1][0] + ci->p->y[j] * roma[1][1];
			z = ci->p->z[j];
			AddPoint(ci->p, x, y, z);
		}
		// assign rotated polygon vertices
		for (j = i*nvx; j < (i+1)*nvx; j++)
		{
			ivx = ci->vx->list[j] + np;
			Add2Ilist(ci->vx, ivx);
		}
		// assign rotated polygon start vertices
		ipol = ci->pol->list[ci->pol->num-1];
		for (j = 0; j < npol; j++)
		{
			ipol  += 3;
			Add2Ilist(ci->pol, ipol);
		}
	}
	return(ci->p->nump);
}
Ejemplo n.º 8
0
void Route::AssembleRoute( void )
{
    //    iterate over the RoutePointGUIDs
    for( unsigned int ip = 0; ip < RoutePointGUIDList.GetCount(); ip++ ) {
        wxString GUID = RoutePointGUIDList[ip];

        //    And on the RoutePoints themselves
        wxRoutePointListNode *prpnode = pWayPointMan->m_pWayPointList->GetFirst();
        while( prpnode ) {
            RoutePoint *prp = prpnode->GetData();

            if( prp->m_GUID == GUID ) {
                AddPoint( prp );
                break;
            }
            prpnode = prpnode->GetNext(); //RoutePoint
        }
    }
}
Ejemplo n.º 9
0
    bool Mutate() {
        bool dirty = false;

        if (DoMutate(AddPointMutation))
            dirty |= AddPoint();
        if (DoMutate(DelPointMutation))
            dirty |= DelPoint();
        if (DoMutate(AlphaMutation))
            dirty |= Alpha(IntervalRand(Settings::AlphaMin, Settings::AlphaMax));

        if (DoMutate(ComponentMutation)) dirty |= RandomRed();
        if (DoMutate(ComponentMutation)) dirty |= RandomGreen();            
        if (DoMutate(ComponentMutation)) dirty |= RandomBlue();

        for (PointIt it = vertex_.begin(); it != vertex_.end(); ++it)
            dirty |= it->Mutate();

        return dirty;
    }
Ejemplo n.º 10
0
// Add a new point to the class from an 3d-array. Works only if mCopyPtsCoords is set to true
int RandomSampler::AddPoint3d(double nCoordinate[]){

	if(!mCopyPtsCoords)
		return NULL;
	
	std::vector<float> *nCoordinatesVec = new std::vector<float>(3);
	(*nCoordinatesVec)[0] = (float) nCoordinate[0];
	(*nCoordinatesVec)[1] = (float) nCoordinate[1];
	(*nCoordinatesVec)[2] = (float) nCoordinate[2];
	mCopyPtsCoords = false;
	unsigned int toReturn = AddPoint(nCoordinatesVec);

	// No free space available
	if(toReturn == -1)
		delete nCoordinatesVec;

	mCopyPtsCoords = true;
	return toReturn;
}
Ejemplo n.º 11
0
void BattleGroundAB::Update(time_t diff)
{
    BattleGround::Update(diff);
    //If BG-Status = WAIT_JOIN, we must start BG
    if(GetStatus() == STATUS_WAIT_JOIN)
    {

    }
    if(GetStatus() == STATUS_IN_PROGRESS)
    {
        for(int i = 0;i < 5; i++)
            if(m_Points[i])                                 //If point is controled
                AddPoint(m_Points[i], diff);
        if(GetTeamScore(ALLIANCE) >= (2000*1000))           //1 score/per second
            EndBattleGround(ALLIANCE);
        if(GetTeamScore(HORDE) >= (2000*1000))              //1 score/per second
            EndBattleGround(HORDE);
    }
}
Ejemplo n.º 12
0
void FTContour::evaluateQuadraticCurve()
{
    for( unsigned int i = 0; i <= ( 1.0f / BEZIER_STEP_SIZE); i++)
    {
        float bezierValues[2][2];

        float t = static_cast<float>(i) * BEZIER_STEP_SIZE;

        bezierValues[0][0] = (1.0f - t) * controlPoints[0][0] + t * controlPoints[1][0];
        bezierValues[0][1] = (1.0f - t) * controlPoints[0][1] + t * controlPoints[1][1];
    
        bezierValues[1][0] = (1.0f - t) * controlPoints[1][0] + t * controlPoints[2][0];
        bezierValues[1][1] = (1.0f - t) * controlPoints[1][1] + t * controlPoints[2][1];
        
        bezierValues[0][0] = (1.0f - t) * bezierValues[0][0] + t * bezierValues[1][0];
        bezierValues[0][1] = (1.0f - t) * bezierValues[0][1] + t * bezierValues[1][1];
    
        AddPoint( bezierValues[0][0], bezierValues[0][1]);
    }
}
void BuildDelaunayTriangulation(Vertex* pointSet, int numPoints, DelaunayTriangulation* dt)
{
  srand ( time(nullptr) );

  InitSuperSimplex(pointSet, numPoints, dt);
  AddSimplexToDelaunayTriangulation(dt, dt->m_AlphaSimplex);
  
  for (int i = 0; i < numPoints; i++)
  {
    AddPoint(&pointSet[i], dt);
    
    for (int j = 0; j < ArrayListSize(dt->m_Conflicts); j++)
      Push(dt->m_RemovedSimplices, GetFromArrayList(dt->m_Conflicts, j));    
    
    EmptyArrayList(dt->m_Conflicts);
    EmptyArrayList(dt->m_Updates);
    
    ResetNeighbourUpdates(dt->m_NeighbourUpdates);
  }
}
Ejemplo n.º 14
0
static struct dataset *
ReadSet(FILE *f, const char *n, int column, const char *delim)
{
	char buf[BUFSIZ], *p, *t;
	struct dataset *s;
	double d;
	int line;
	int i;

	s = NewSet();
	s->name = strdup(n);
	line = 0;
	while (fgets(buf, sizeof buf, f) != NULL) {
		line++;

		i = strlen(buf);
		while (i > 0 && isspace(buf[i - 1]))
			buf[--i] = '\0';
		for (i = 1, t = strtok(buf, delim);
		     t != NULL && *t != '#';
		     i++, t = strtok(NULL, delim)) {
			if (i == column)
				break;
		}
		if (t == NULL || *t == '#')
			continue;

		d = strtod(t, &p);
		if (p != NULL && *p != '\0')
			errx(2, "Invalid data on line %d in %s", line, n);
		if (*buf != '\0')
			AddPoint(s, d);
	}
	if (s->n < 3) {
		fprintf(stderr,
		    "Dataset %s must contain at least 3 data points\n", n);
		exit (2);
	}
	qsort(s->points, s->n, sizeof *s->points, dbl_cmp);
	return (s);
}
Ejemplo n.º 15
0
void UIView::ConvertStaticMappings(NIBWriter *writer, XIBObject *obj)
{
    if ( !_ignoreUIObject ) writer->_allUIObjects->AddMember(NULL, this);

    if ( _subviews->count() > 0 ) {
        int count = _subviews->count();
        for ( int i = 0; i < count; i ++ ) {
            XIBObject *curObj = _subviews->objectAtIndex(i);
            if ( !curObj->_ignoreUIObject ) writer->_allUIObjects->AddMember(NULL, curObj);
        }
    }

    AddRect(writer, "UIBounds", _bounds);
    AddPoint(writer, "UICenter", _center);
    if ( _contentStretch.x != 0.0f || _contentStretch.y != 0.0f || _contentStretch.width != 0.0f || _contentStretch.height != 0.0f ) {
        AddRect(writer, "UIContentStretch", _contentStretch);
    }

    Map(writer, obj, propertyMappings, numPropertyMappings);
    if ( _subviews->count() > 0 ) AddOutputMember(writer, "UISubviews", _subviews);
    if ( _constraints->count() > 0) AddOutputMember(writer, "UIViewAutolayoutConstraints", _constraints);

    if ( _autoresizeSubviews ) AddBool(writer, "UIAutoresizeSubviews", _autoresizeSubviews);
    if ( _autoresizingMask ) AddInt(writer, "UIAutoresizingMask", _autoresizingMask);
    if ( _clipsToBounds ) AddBool(writer, "UIClipsToBounds", _clipsToBounds);
    if ( _backgroundColor ) AddOutputMember(writer, "UIBackgroundColor", _backgroundColor);
    if ( _contentMode ) AddInt(writer, "UIContentMode", _contentMode);
    if ( _userInteractionDisabled ) AddBool(writer, "UIUserInteractionDisabled", _userInteractionDisabled);
    if ( _hidden ) AddBool(writer, "UIHidden", _hidden);
    if ( !_enabled ) AddBool(writer, "UIDisabled", true);
    if ( _multipleTouchEnabled ) AddBool(writer, "UIMultipleTouchEnabled", _multipleTouchEnabled);
    if ( !_clearsContextBeforeDrawing ) AddBool(writer, "UIClearsContextBeforeDrawing", _clearsContextBeforeDrawing);

    // Metadata
    if ( !_translatesAutoresizeToConstraints || !obj->GetBool("IBViewMetadataTranslatesAutoresizingMaskIntoConstraints", true) ) AddBool(writer, "UIViewDoesNotTranslateAutoresizingMaskIntoConstraints", true);

    if ( _opaque ) obj->AddBool(writer, "UIOpaque", _opaque);

    ObjectConverterSwapper::ConvertStaticMappings(writer, obj);
}
Ejemplo n.º 16
0
void CWaypoints::ReadWPT(const wchar_t * wcFilename)
{
	char buff[1000];
	FILE * pFile = wfopen(wcFilename, L"rt");
	if (pFile)
	{
		std::vector<long> vRecord;
		for (int i = 0; i < 4; ++i)
		{
			if (!fgets(buff, sizeof(buff), pFile))
				break;
		}
		std::vector<std::string> listParts;
		while(fgets(buff, sizeof(buff), pFile))
		{
			std::string strCommand = buff;
			listParts.resize(0);
			std::string::size_type pos = 0;
			std::string::size_type nextpos = 0;
			while ((nextpos = strCommand.find(',', pos)) != std::string::npos)
			{
				listParts.push_back(strCommand.substr(pos, nextpos - pos));
				pos = nextpos + 1;
			}
			listParts.push_back(strCommand.substr(pos));
			if (listParts.size() >= 15)
			{
				double dLatitude = myatof(listParts[2].c_str());
				double dLongitude = myatof(listParts[3].c_str());
				wchar_t buff[1000] = {0};
				MultiByteToWideChar(CP_ACP, 0, listParts[1].c_str(), -1, buff, 1000);
				int iRadius = atoi(listParts[13].c_str());
				int iAltitude = atoi(listParts[14].c_str());
				AddPoint(CPoint(dLongitude, dLatitude, iAltitude, buff), iRadius);
			}
		}
	}
	m_bCanWrite = true;
}
Ejemplo n.º 17
0
int ReadPointStruct(struct Point *p, const char *sec, const char *fn)
{
    int i, num;
    float x, y, z;
    char *tmp;
    char key[127];

    num = 0;
    for (i = 0; ; i++)
    {
        sprintf(key, POINT, i);
        if ((tmp = IHS_GetCFGValue(fn, sec, key)) != NULL)
        {
            sscanf(tmp, "%f, %f, %f", &x, &y, &z);
            free(tmp);
            num = AddPoint(p, x, y, z);
        }
        else
            break;
    }
    return(num);
}
Ejemplo n.º 18
0
void FTContour::AddPoint( float x, float y)
{
    AddPoint( FTPoint( x, y, 0.0f));
}
Ejemplo n.º 19
0
int CEveluation::GetRelatePiece(BYTE position[10][9], int j, int i)
{
	nPosCount = 0;
	BYTE nChessID;
	BYTE flag;
	int x,y;
	
	nChessID = position[i][j];
	switch(nChessID)
	{
	case R_KING:
	case B_KING:
		
		for (y = 0; y < 3; y++)
			for (x = 3; x < 6; x++)
				if (CanTouch(position, j, i, x, y))
					AddPoint(x, y);
		for (y = 7; y < 10; y++)
			for (x = 3; x < 6; x++)
				if (CanTouch(position, j, i, x, y))
					AddPoint(x, y);
		break;
						
	case R_BISHOP:
		
		for (y = 7; y < 10; y++)
			for (x = 3; x < 6; x++)
				if (CanTouch(position, j, i, x, y))
					AddPoint(x, y);
		break;
				
	case B_BISHOP:
		
		for (y = 0; y < 3; y++)
			for (x = 3; x < 6; x++)
				if (CanTouch(position, j, i, x, y))
					AddPoint(x, y);
		break;
				
	case R_ELEPHANT:
	case B_ELEPHANT:
		
		x=j+2;
		y=i+2;
		if(x < 9 && y < 10  && CanTouch(position, j, i, x, y))
			AddPoint(x, y);
		
		x=j+2;
		y=i-2;
		if(x < 9 && y>=0  &&  CanTouch(position, j, i, x, y))
			AddPoint(x, y);
		
		x=j-2;
		y=i+2;
		if(x>=0 && y < 10  && CanTouch(position, j, i, x, y))
			AddPoint(x, y);
		
		x=j-2;
		y=i-2;
		if(x>=0 && y>=0  && CanTouch(position, j, i, x, y))
			AddPoint(x, y);
		break;
		
		case R_HORSE:		
		case B_HORSE:		
			x=j+2;
			y=i+1;
			if((x < 9 && y < 10) &&CanTouch(position, j, i, x, y))
				AddPoint(x, y);
					
					x=j+2;
					y=i-1;
					if((x < 9 && y >= 0) &&CanTouch(position, j, i, x, y))
						AddPoint(x, y);
					
					x=j-2;
					y=i+1;
					if((x >= 0 && y < 10) &&CanTouch(position, j, i, x, y))
						AddPoint(x, y);
					
					x=j-2;
					y=i-1;
					if((x >= 0 && y >= 0) &&CanTouch(position, j, i, x, y))
						AddPoint(x, y);
					
					x=j+1;
					y=i+2;
					if((x < 9 && y < 10) &&CanTouch(position, j, i, x, y))
						AddPoint(x, y);
					x=j-1;
					y=i+2;
					if((x >= 0 && y < 10) &&CanTouch(position, j, i, x, y))
						AddPoint(x, y);
					x=j+1;
					y=i-2;
					if((x < 9 && y >= 0) &&CanTouch(position, j, i, x, y))
						AddPoint(x, y);
					x=j-1;
					y=i-2;
					if((x >= 0 && y >= 0) &&CanTouch(position, j, i, x, y))
						AddPoint(x, y);
					break;
					
				case R_CAR:
				case B_CAR:
					x=j+1;
					y=i;
					while(x < 9)
					{
						if( NOCHESS == position[y][x] )
							AddPoint(x, y);
						else
						{
							AddPoint(x, y);
							break;
						}
						x++;
					}
					
					x = j-1;
					y = i;
					while(x >= 0)
					{
						if( NOCHESS == position[y][x] )
							AddPoint(x, y);
						else
						{
							AddPoint(x, y);
							break;
						}
						x--;
					}
					
					x=j;
					y=i+1;//
					while(y < 10)
					{
						if( NOCHESS == position[y][x])
							AddPoint(x, y);
						else
						{
							AddPoint(x, y);
							break;
						}
						y++;
					}
					
					x = j;
					y = i-1;//よ
					while(y>=0)
					{
						if( NOCHESS == position[y][x])
							AddPoint(x, y);
						else
						{
							AddPoint(x, y);
							break;
						}
						y--;
					}
					break;
					
				case R_PAWN:
					y = i - 1;
					x = j;
					
					if(y >= 0)
						AddPoint(x, y);
					
					if(i < 5)
					{
						y=i;
						x=j+1;
						if(x < 9 )
							AddPoint(x, y);
						x=j-1;
						if(x >= 0 )
							AddPoint(x, y);
					}
					break;
					
				case B_PAWN:
					y = i + 1;
					x = j;
					
					if(y < 10 )
						AddPoint(x, y);
					
					if(i > 4)
					{
						y=i;
						x=j+1;
						if(x < 9)
							AddPoint(x, y);
						x=j-1;
						if(x >= 0)
							AddPoint(x, y);
					}
					break;
					
				case B_CANON:
				case R_CANON:
					
					x=j+1;		//
					y=i;
					flag=FALSE;
					while(x < 9)		
					{
						if( NOCHESS == position[y][x] )
						{
							if(!flag)
								AddPoint(x, y);
						}
						else
						{
							if(!flag)
								flag=TRUE;
							else 
							{
								AddPoint(x, y);
								break;
							}
						}
						x++;
					}
					
					x=j-1;
					flag=FALSE;	
					while(x>=0)
					{
						if( NOCHESS == position[y][x] )
						{
							if(!flag)
								AddPoint(x, y);
						}
						else
						{
							if(!flag)
								flag=TRUE;
							else 
							{
								AddPoint(x, y);
								break;
							}
						}
						x--;
					}
					x=j;	
					y=i+1;
					flag=FALSE;
					while(y < 10)
					{
						if( NOCHESS == position[y][x] )
						{
							if(!flag)
								AddPoint(x, y);
						}
						else
						{
							if(!flag)
								flag=TRUE;
							else 
							{
								AddPoint(x, y);
								break;
							}
						}
						y++;
					}
					
					y=i-1;	//
					flag=FALSE;	
					while(y>=0)
					{
						if( NOCHESS == position[y][x] )
						{
							if(!flag)
								AddPoint(x, y);
						}
						else
						{
							if(!flag)
								flag=TRUE;
							else 
							{
								AddPoint(x, y);
								break;
							}
						}
						y--;
					}
					break;
					
				default:
					break;
					
				}
				return nPosCount ;				
}
Ejemplo n.º 20
0
int main(void)
{
	Display *d;
	Window w;
	XEvent e;
	XWindowAttributes attr;

	int s;


	float x_max, y_max;

	int w_, h_,  delt;

	int i;
	int id1, id2, id3;
//	float kx, ky, kx_0, ky_0, kxa, kya, x, y;
	float kx, ky, kxa, kya, x, y;
	int fl =0;
	int fl1=0;
	int fl2=0;

	int flagg=0;
	FILE *file;
    file=fopen("data.txt","r");


	srand(time(NULL));

	

	if(flagg==1)
	{


	}

	if ( (file=fopen("data.txt", "r")) == NULL)
	{

		return -1;
	}

	/*N=0;
	while (fscanf(file, "%d %d", &i, &j) == 2)
		N++;
	fseek(file, 0L, SEEK_SET);
	* */

	 printf("[PIXEL DATA]\n");
	 /*
	point=(Point*)malloc(N*sizeof(Point));
	for (i=0; i<N; i++)
	{
		fscanf(file, "%f %f", &point[i].x, &point[i].y);
		printf("x, y = %f %f\n", point[i].x, point[i].y);
	}*/
	
	while (fscanf(file, "%f %f", &x, &y) ==2)
		AddPoint(x, y);
	
	printf("N=%d\n", N);
	if (N==0)
	{
		printf("N=0\n");
		exit(0);
	}	
	


	fclose(file);
	
	
/*
	x_min=point[0].x;
	y_min=point[0].y;

	x_max=point[0].x;
	y_max=point[0].y;

	for (i=0; i<N; i++)
	{
		if (point[i].x - x_min < eps)
			x_min=point[i].x;

		if (point[i].y - y_min < eps)
			y_min=point[i].y;

		if (point[i].x - x_max > eps)
			x_max=point[i].x;

		if (point[i].y - y_max > eps)
			y_max=point[i].y;
	}


	printf("\nxmin, ymin = %f %f\n", x_min, y_min);
	printf("xmax, ymax = %f %f\n", x_max, y_max);

	kx_0=float(x_max/x_min);
	ky_0=float(y_max/y_min);

	printf("kx_0, ky_0 = %f %f\n\n", kx_0, ky_0);

    int a,b,c;
    int t=0,q=1,g=2;
    float minn;
	id1=id2=id3=0;
	max=cos(point[0], point[1], point[2]);
	for (i=t; i<N; i++)
	{
		for(j=q;j<N; j++)
		{
			for (k=g;k<N; k++)
			{
			    minn=dist(point[i],point[j]);
			    a=i;b=k;c=j;
			    id1=a; id2=b; id3=c;
			    if((minn-dist(point[i],point[k]))>0)
			    {
                    a=i;b=j;c=k;
			    }
			    if((minn-dist(point[k],point[j]))>0)
			    {
                    a=j;b=i;c=k;
			    }

                if (((cos(point[a], point[b], point[c])-max)  > eps) && (cos(point[a], point[b], point[c])-1>eps))
                {
                    max=cos(point[a], point[b], point[c]);
                    id1=a; id2=b; id3=c;
                    printf("cos=%f\n",cos(point[a], point[b], point[c]));
                    printf("i=%d,j=%d,k=%d\n",id1,id2,id3);
                }
                g++;
			}
			printf("i=%d,j=%d,k=%d\n",id1,id2,id3);
			q++;
		}
		i++;
		}*/

	w_=w0;
	h_=h0;
	
	
	
	refresh(&x_max, &y_max, &id1, &id2, &id3);

	kx=float(w_ / x_max);
	ky=float(h_ / y_max);

	printf("kx, ky = %f, %f\n", kx, ky);

	if ((d = XOpenDisplay(getenv("DISPLAY"))) == NULL) {
			exit(1);
	}

	s = DefaultScreen(d);


	w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, w0, h0, 1,
							   BlackPixel(d, s), WhitePixel(d, s));


	XSelectInput(d, w, ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask );


	XMapWindow(d, w);

	kxa=kya=1;
	while (1)
	{
			XGetWindowAttributes(d, w, &attr);
			w_=attr.width;
			h_=attr.height;
			kx=float(w_ / x_max);
			ky=float(h_ / y_max);

		XNextEvent(d, &e);



		if (e.type==ButtonPress)
		{
			printf("Button Press\n");

			ButPress(10,10,e.xbutton.x,e.xbutton.y,&fl);
			ButPress(10,50,e.xbutton.x,e.xbutton.y,&fl1);
			ButPress(10,90,e.xbutton.x,e.xbutton.y,&fl2);
			if(fl==1||fl1==1||fl2==1)
			{
				printf("fl=%d, fl1=%d, fl2=%d\n", fl, fl1, fl2);
				if(fl==1)
				{
					kxa=kxa-0.02;
					printf("KX ----- %f\n", kxa);
					printf("BUTTON 1\n");
				}
				if(fl1==1)
				{
					kxa=kxa+0.02;
					printf("KX +++++ %f\n", kxa);
					printf("BUTTON 2\n");
				}
				if(fl2==1)
				{
					AddPoint(10, 50);
					refresh(&x_max, &y_max, &id1, &id2, &id3);
				}
			}

		}

		if (e.type==ButtonRelease)
		{
			printf("Button Release\n\n");
			fl=fl2=fl1=0;
			XClearArea(d,w,0,0,attr.width,attr.height,1);
			XEvent ev;
			ev.type=Expose;
			XSendEvent(d,w,1,0,&ev);
		}


		if (e.type == Expose)
		{


			if (kx>ky)
				kx=ky;
			else
				ky=kx;

			kx*=kxa;
			ky*=kya;
			
			printf("kx = %f ky = %f\n", kx, ky);

			if (w_ > h_)
				delt=h_;
			else
				delt=w_;


			DrawButton( d,w,DefaultGC(d, s),10,10,s,fl);
    	    DrawButton( d,w,DefaultGC(d, s),10,50,s,fl1);
    	    DrawButton( d,w,DefaultGC(d, s),10,90,s,fl2);


			for (i=0; i<N; i++)
			XFillRectangle(d, w, DefaultGC(d, s), kx*point[i].x - delt/coef, ky*point[i].y - delt/coef, delt/(coef/2), delt/(coef/2));

			XDrawLine(d, w, DefaultGC(d, s), kx*point[id1].x, ky*point[id1].y, kx*point[id2].x, ky*point[id2].y);
			XDrawLine(d, w, DefaultGC(d, s), kx*point[id2].x, ky*point[id2].y, kx*point[id3].x, ky*point[id3].y);
			XDrawLine(d, w, DefaultGC(d, s), kx*point[id3].x, ky*point[id3].y, kx*point[id1].x, ky*point[id1].y);

		}
		if (e.type == KeyPress)
			break;
  }


	XCloseDisplay(d);

	if (point)
		free(point);

	return 0;
}
Ejemplo n.º 21
0
void CXMLParser::TraverseGetInformation(TiXmlElement* root)
{
	TiXmlElement *childroot=root->FirstChildElement();
	while(childroot!=NULL)
	{
		if(strcmp(childroot->Value(),"VertexBuffer")==0)
		{
			char *pointStr=(char *)childroot->FirstChildElement()->GetText();
			AddPoint(pointStr);
			char *normalStr=(char *)childroot->FirstChildElement()->NextSiblingElement()->GetText();
			AddNormals(normalStr);
		}
		else if(strcmp(childroot->Value(),"Faces")==0)
		{
			TiXmlElement *triangleElem=childroot->FirstChildElement();
			while (triangleElem!=NULL)
			{
				if(strcmp(triangleElem->Value(),"Face")==0)
				{
					TiXmlAttribute *triangleAttribute=triangleElem->FirstAttribute();
					while(triangleAttribute!=NULL)
					{
						if(strcmp(triangleAttribute->Name(),"triangles")==0)
						{
							char *triangleStr=(char *)triangleAttribute->Value();
							if(IsTriangleStrWithSplit(triangleStr)==true)
							{
								AddTriangle(triangleStr);
							}
							else
							{
								AddIdTriangle(triangleStr);
							}
						}
						if(strcmp(triangleAttribute->Name(),"strips")==0)
						{
							char *stripStr=(char *)triangleAttribute->Value();
							AddStrips(stripStr);
						}
						if(strcmp(triangleAttribute->Name(),"fans")==0)
						{
							char *fanStr=(char *)triangleAttribute->Value();
							AddFans(fanStr);
						}
						triangleAttribute=triangleAttribute->Next();
					}
				}
				triangleElem=triangleElem->NextSiblingElement();
			}
		}
		else if(strcmp(childroot->Value(),"Edges")==0)
		{
			TiXmlElement *polyElem=childroot->FirstChildElement();
			while(polyElem!=NULL)
			{
				if(strcmp(polyElem->Value(),"Polyline")==0)
				{
					char *polyStr=(char *)polyElem->FirstAttribute()->Value();
					AddPoly(polyStr);
				}
				polyElem=polyElem->NextSiblingElement();
			}
		}
		/*else if (strcmp(childroot->Value(),"PolygonalLOD")==0)
		{
			TiXmlElement *triangleElem=childroot->FirstChildElement()->FirstChildElement();
			while (triangleElem!=NULL)
			{
				if(strcmp(triangleElem->Value(),"Face")==0)
				{
					TiXmlAttribute *triangleAttribute=triangleElem->FirstAttribute();
					while(triangleAttribute!=NULL)
					{
						if(strcmp(triangleAttribute->Name(),"triangles")==0)
						{
							char *triangleStr=(char *)triangleAttribute->Value();
							if(IsTriangleStrWithSplit(triangleStr)==true)
							{
								AddTriangle(triangleStr);
							}
							else
							{
								AddIdTriangle(triangleStr);
							}
						}
						if(strcmp(triangleAttribute->Name(),"strips")==0)
						{
							char *stripStr=(char *)triangleAttribute->Value();
							AddStrips(stripStr);
						}
						if(strcmp(triangleAttribute->Name(),"fans")==0)
						{
							char *fanStr=(char *)triangleAttribute->Value();
							AddFans(fanStr);
						}
						triangleAttribute=triangleAttribute->Next();
					}
				}
				triangleElem=triangleElem->NextSiblingElement();
			}
		}*/
		childroot=childroot->NextSiblingElement();
	}
}
Ejemplo n.º 22
0
void BattleGroundWS::EventPlayerCapturedFlag(Player *Source)
{
    if (GetStatus() != STATUS_IN_PROGRESS)
        return;

    m_LastCapturedFlagTeam = Source->GetTeam();

    uint32 winner = 0;

    Source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
    if (Source->HasAura(BG_WS_SPELL_FOCUSED_ASSAULT))
        Source->RemoveAurasDueToSpell(BG_WS_SPELL_FOCUSED_ASSAULT);
    if (Source->HasAura(BG_WS_SPELL_BRUTAL_ASSAULT))
        Source->RemoveAurasDueToSpell(BG_WS_SPELL_BRUTAL_ASSAULT);
    if (Source->GetTeam() == ALLIANCE)
    {
        if (!IsHordeFlagPickedup())
            return;
        SetHordeFlagPicker(0);                              // must be before aura remove to prevent 2 events (drop+capture) at the same time
                                                            // horde flag in base (but not respawned yet)
        m_FlagState[BG_TEAM_HORDE] = BG_WS_FLAG_STATE_WAIT_RESPAWN;
                                                            // Drop Horde Flag from Player
        Source->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG);
        if (GetTeamScore(ALLIANCE) < BG_WS_MAX_TEAM_SCORE)
            AddPoint(ALLIANCE, 1);
        PlaySoundToAll(BG_WS_SOUND_FLAG_CAPTURED_ALLIANCE);
        RewardReputationToTeam(BATTLEGROUND_WS, m_ReputationCapture, ALLIANCE);
    }
    else
    {
        if (!IsAllianceFlagPickedup())
            return;
        SetAllianceFlagPicker(0);                           // must be before aura remove to prevent 2 events (drop+capture) at the same time
                                                            // alliance flag in base (but not respawned yet)
        m_FlagState[BG_TEAM_ALLIANCE] = BG_WS_FLAG_STATE_WAIT_RESPAWN;
                                                            // Drop Alliance Flag from Player
        Source->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG);
        if (GetTeamScore(HORDE) < BG_WS_MAX_TEAM_SCORE)
            AddPoint(HORDE, 1);
        PlaySoundToAll(BG_WS_SOUND_FLAG_CAPTURED_HORDE);
        RewardReputationToTeam(BATTLEGROUND_WS, m_ReputationCapture, HORDE);
    }
    //for flag capture is reward 2 honorable kills
    RewardHonorToTeam(GetBonusHonorFromKill(sWorld.getConfig(CONFIG_UINT32_BONUS_HONOR_FLAG_WSG)), Source->GetTeam());
    RewardXpToTeam(0, 0.6f, Source->GetTeam());

    //flag carrier gets another 2 honorable kills
    Source->RewardHonor(NULL, 0, GetBonusHonorFromKill(sWorld.getConfig(CONFIG_UINT32_BONUS_HONOR_FLAG_WSG)));

    // despawn flags
    SpawnEvent(WS_EVENT_FLAG_A, 0, false);
    SpawnEvent(WS_EVENT_FLAG_H, 0, false);

    if (Source->GetTeam() == ALLIANCE)
        SendMessageToAll(LANG_BG_WS_CAPTURED_HF, CHAT_MSG_BG_SYSTEM_ALLIANCE, Source);
    else
        SendMessageToAll(LANG_BG_WS_CAPTURED_AF, CHAT_MSG_BG_SYSTEM_HORDE, Source);

    UpdateFlagState(Source->GetTeam(), 1);                  // flag state none
    UpdateTeamScore(Source->GetTeam());
    // only flag capture should be updated
    UpdatePlayerScore(Source, SCORE_FLAG_CAPTURES, 1);      // +1 flag captures
    Source->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BG_OBJECTIVE_CAPTURE,1);

    if (GetTeamScore(ALLIANCE) == BG_WS_MAX_TEAM_SCORE)
        winner = ALLIANCE;

    if (GetTeamScore(HORDE) == BG_WS_MAX_TEAM_SCORE)
        winner = HORDE;

    if (winner)
    {
        UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE, 0);
        UpdateWorldState(BG_WS_FLAG_UNK_HORDE, 0);
        UpdateWorldState(BG_WS_FLAG_STATE_ALLIANCE, 1);
        UpdateWorldState(BG_WS_FLAG_STATE_HORDE, 1);

        EndBattleGround(winner);
    }
    else
    {
        m_FlagsTimer[GetTeamIndexByTeamId(Source->GetTeam()) ? 0 : 1] = BG_WS_FLAG_RESPAWN_TIME;
    }
}
Ejemplo n.º 23
0
void BattlegroundTP::EventPlayerCapturedFlag(Player *Source)
{
    if (GetStatus() != STATUS_IN_PROGRESS)
        return;

    uint32 winner = 0;

    Source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
    if (Source->GetTeam() == ALLIANCE)
    {
        if (!this->IsHordeFlagPickedup())
            return;
        SetHordeFlagPicker(0);                              // must be before aura remove to prevent 2 events (drop+capture) at the same time
                                                            // horde flag in base (but not respawned yet)
        m_FlagState[BG_TEAM_HORDE] = BG_TP_FLAG_STATE_WAIT_RESPAWN;
                                                            // Drop Horde Flag from Player
        Source->RemoveAurasDueToSpell(BG_TP_SPELL_HORDE_FLAG);
        if (m_FlagDebuffState == 1)
          Source->RemoveAurasDueToSpell(TP_SPELL_FOCUSED_ASSAULT);
        if (m_FlagDebuffState == 2)
          Source->RemoveAurasDueToSpell(TP_SPELL_BRUTAL_ASSAULT);
        if (GetTeamScore(ALLIANCE) < BG_TP_MAX_TEAM_SCORE)
            AddPoint(ALLIANCE, 1);
        PlaySoundToAll(BG_TP_SOUND_FLAG_CAPTURED_ALLIANCE);
        RewardReputationToTeam(890, m_ReputationCapture, ALLIANCE);
    }
    else
    {
        if (!this->IsAllianceFlagPickedup())
            return;
        SetAllianceFlagPicker(0);                           // must be before aura remove to prevent 2 events (drop+capture) at the same time
                                                            // alliance flag in base (but not respawned yet)
        m_FlagState[BG_TEAM_ALLIANCE] = BG_TP_FLAG_STATE_WAIT_RESPAWN;
                                                            // Drop Alliance Flag from Player
        Source->RemoveAurasDueToSpell(BG_TP_SPELL_ALLIANCE_FLAG);
        if (m_FlagDebuffState == 1)
          Source->RemoveAurasDueToSpell(TP_SPELL_FOCUSED_ASSAULT);
        if (m_FlagDebuffState == 2)
          Source->RemoveAurasDueToSpell(TP_SPELL_BRUTAL_ASSAULT);
        if (GetTeamScore(HORDE) < BG_TP_MAX_TEAM_SCORE)
            AddPoint(HORDE, 1);
        PlaySoundToAll(BG_TP_SOUND_FLAG_CAPTURED_HORDE);
        RewardReputationToTeam(889, m_ReputationCapture, HORDE);
    }
    //for flag capture is reward 2 honorable kills
    RewardHonorToTeam(GetBonusHonorFromKill(2), Source->GetTeam());

    SpawnBGObject(BG_TP_OBJECT_H_FLAG, BG_TP_FLAG_RESPAWN_TIME);
    SpawnBGObject(BG_TP_OBJECT_A_FLAG, BG_TP_FLAG_RESPAWN_TIME);

    if (Source->GetTeam() == ALLIANCE)
        SendMessageToAll(LANG_BG_TP_CAPTURED_HF, CHAT_MSG_BG_SYSTEM_ALLIANCE, Source);
    else
        SendMessageToAll(LANG_BG_TP_CAPTURED_AF, CHAT_MSG_BG_SYSTEM_HORDE, Source);

    UpdateFlagState(Source->GetTeam(), 1);                  // flag state none
    UpdateTeamScore(Source->GetTeam());
    // only flag capture should be updated
    UpdatePlayerScore(Source, SCORE_FLAG_CAPTURES, 1);      // +1 flag captures

    // update last flag capture to be used if teamscore is equal
    SetLastFlagCapture(Source->GetTeam());

    if (GetTeamScore(ALLIANCE) == BG_TP_MAX_TEAM_SCORE)
        winner = ALLIANCE;

    if (GetTeamScore(HORDE) == BG_TP_MAX_TEAM_SCORE)
        winner = HORDE;

    if (winner)
    {
        UpdateWorldState(BG_TP_FLAG_UNK_ALLIANCE, 0);
        UpdateWorldState(BG_TP_FLAG_UNK_HORDE, 0);
        UpdateWorldState(BG_TP_FLAG_STATE_ALLIANCE, 1);
        UpdateWorldState(BG_TP_FLAG_STATE_HORDE, 1);
        UpdateWorldState(BG_TP_STATE_TIMER_ACTIVE, 0);

        RewardHonorToTeam(BG_TP_Honor[m_HonorMode][BG_TP_WIN], winner);
        EndBattleground(winner);
    }
    else
    {
        m_FlagsTimer[GetTeamIndexByTeamId(Source->GetTeam()) ? 0 : 1] = BG_TP_FLAG_RESPAWN_TIME;
    }
}
Ejemplo n.º 24
0
LRESULT CIMoteTerminal::OnReceiveSerialData(WPARAM wParam, LPARAM lParam)
{
	//following couple of lines allow us to debug a raw datastream
	char *rxstring = (char *)lParam;
	DWORD numBytesReceived = (DWORD) wParam;
	BufferAppend(rxstring, numBytesReceived);
	delete []rxstring;
	return TRUE;

#if 0
	DWORD i,offset;
	//TRACE("Rx...Buffer = %#X\tNumBytesReceived = %d\n",rxstring,numBytesReceived);
	/*****
	data format for the accelerometer data looks something like:
	0{2 bit addr}{5 data bits} {1}{7 data bits}
	******/
	for(offset=0; offset<numBytesReceived; offset++)
	{
		//find the correct first bytes
		if((rxstring[offset]  & 0xE0) == 0)
		{
			break;
		}
	}
	//offset current points to the correct first element for us to look at
	//start reconstructing the 16 bit numbers and doing the divide
	
	for(i=offset;(i+6)<numBytesReceived; i+=6)
	{	
		static bool init = false;
		POINT point;
		DWORD B,C,D,Tx, Ty,T;
		int Rx, Ry;
		B = ((rxstring[i] & 0x1F)<<7) | (rxstring[i+1] & 0x7F);
		C = ((rxstring[i+2] & 0x1F)<<7) | (rxstring[i+3] & 0x7F);
		D = ((rxstring[i+4] & 0x1F)<<7) | (rxstring[i+5] & 0x7F);
		Tx = B;
		Ty = D-C;
		T = C/2 + D/2 - B/2;

		Rx = ((Tx << 16) / T) - (65536/2);
		Ry = ((Ty << 16) / T) - (65536/2);
		//point.x =(LONG)( (rxstring[byte_index]<<8) + rxstring[byte_index+1]) -(65536/2);
		//point.x = (LONG)( (rxstring[byte_index]<<8) + rxstring[byte_index+1]);
		//TRACE("%d %d = %d\n",rxstring[i], rxstring[i+1], point.x);
		//TRACE("Found T, index %d \n", byte_index);
		//TRACE("Tx = %d, Ty = %d, T = %d, Rx = %d, Ry = %d\n",Tx, Ty, T, Rx, Ry);
		point.x = (LONG) Rx;
		point.y = (LONG) Ry;

		if(!init)
		{
			CIMoteCartesianPlot *pFrame=CreateNewView(0,0xDEADBEEF,0);
			pFrame->SetMappingFunction(-2,2);
			init = true;
		}
		AddPoint(point, 0);
	}
		
	delete rxstring;

	
	return TRUE;
//#endif;
	POINT point;
	static bool bGotBeef = 0;
	static bool bFirstTime = true;
	static unsigned short NumDataBytes;
	static unsigned short NumBytesProcessed;
	//static int MoteIDs[NUMCHANNELS];
	static unsigned short SensorID;
	static unsigned int MoteID;
	static unsigned int SensorType;
	static unsigned int ExtraInfo;
	static unsigned int TimeID;
	static unsigned int ChannelID;
	static unsigned char HeaderIndex;
	static unsigned char Header[16];
	unsigned short *short_ptr;
	unsigned int *int_ptr;
	DWORD byte_index;
	static unsigned char LastByte = 0;
//	unsigned int ProblemIndex;
	unsigned int EmptyChannel;
	static unsigned int NumProblems = 0;
	CString logentry;
	static bool bPrintheader=true;
	CTime time;
	static int Tx, Ty, T, Rx, Ry, Tb, Tc, Td, b0, b1;
	static int CurrentCounter, CurrentByte;
	// Hack, for now statically allocate 
	static unsigned char *CameraBuffer;
	static unsigned int CurrentCameraID;
	static unsigned int CameraBufferIndex;
	static unsigned int SegmentIndex;
	static bool PictureInProgress;
	static unsigned int LastPicID;

#define MAX_PIC_SIZE 80000
#define INVALID_SENSOR 0
#define PH_SENSOR 1
#define PRESSURE_SENSOR 2
#define ACCELEROMETER_SENSOR 3
#define CAMERA_SENSOR 4

#define FIRST_SEGMENT 0x1111
#define MID_SEGMENT 0
#define END_OF_PIC 0xffff

	for(int channel = 0; (channel < NUMCHANNELS) && bFirstTime; channel++) {
		MoteIDs[channel] = 0;
		HeaderIndex = 0;
		CurrentCameraID = 0;
		CameraBuffer = NULL;
		CameraBufferIndex = 0;
		PictureInProgress = false;
	}

	if (bFirstTime) {
		// Figure out the start of the file names
		CFileFind finder;
		CString TempName;
		unsigned int TempID;
		LastPicID = 0;
		BOOL bResult = finder.FindFile("c:\\icam\\*.jpg");

		while (bResult) {
			bResult = finder.FindNextFile();
			TempName = finder.GetFileName();
			if (sscanf((LPCSTR)TempName, "%d.jpg", &TempID) == 1) {
				// valid pic id
				if (LastPicID < TempID) {
					LastPicID = TempID;
				}
			}
		}
		LastPicID++;
	}


	bFirstTime = false;
	TRACE("Rx...Buffer = %#X\tNumBytesReceived = %d\n",rxstring,numBytesReceived);
	byte_index = 0;
	while(byte_index < numBytesReceived) {
		// Look for DEADBEEF, get all header info
		for(; (byte_index < numBytesReceived) && !bGotBeef; byte_index++) {
			switch (HeaderIndex) {
			case 0:
				if (rxstring[byte_index] == 0xEF) {
					HeaderIndex = 1;
				}
				break;
			case 1:
				if (rxstring[byte_index] == 0xBE) {
					HeaderIndex = 2;
				} else {
					HeaderIndex = 0;
				}
				break;
			case 2:
				if (rxstring[byte_index] == 0xAD) {
					HeaderIndex = 3;
				} else {
					HeaderIndex = 0;
				}
				break;
			case 3:
				if (rxstring[byte_index] == 0xDE) {
					HeaderIndex = 4;
				} else {
					HeaderIndex = 0;
				}
				break;
			case 13:
				// Done with header
				CurrentCounter = 0;
				CurrentByte = 0;
				bGotBeef = 1;
				Header[HeaderIndex] = rxstring[byte_index];
				/*
				* Header :
				* DEADBEEF (4B)
				* MOTE ID (4B)
				* Sensor TYPE (2B)
				* LENGTH (2B)
				* Extra Info (2B)
				* 
				*/
				int_ptr = (unsigned int *) &(Header[4]);
				MoteID = *int_ptr;
				short_ptr = (unsigned short *) &(Header[8]);
				SensorType = *short_ptr;
				short_ptr++;
				NumDataBytes = *short_ptr;
				short_ptr++;
				ExtraInfo = *short_ptr;
				NumBytesProcessed = 0;
				ChannelID = NUMCHANNELS;
				EmptyChannel = NUMCHANNELS;

				if (SensorType == CAMERA_SENSOR) {
					// check with segment
					TRACE("Camera seg %x, buf Index %d, NumDataBytes %d\r\n",
						ExtraInfo, CameraBufferIndex, NumDataBytes);
					if (ExtraInfo == FIRST_SEGMENT) {
						// first segment
						CurrentCameraID = MoteID;
						CameraBufferIndex = 0;						
						if (!PictureInProgress) {
							// create buffer
							CameraBuffer = new unsigned char[MAX_PIC_SIZE];
							PictureInProgress = true;
						}
					}
					SegmentIndex = 0;	// Per segment index
					break;	// don't process the channel stuff
				}
				// Find mote channel, 
				for(int channel = 0; channel < NUMCHANNELS; channel++) {
					if (MoteIDs[channel] == MoteID) {
						ChannelID = channel;
						break;
					} else {
						if (MoteIDs[channel] == 0) {
							EmptyChannel = channel;
						}
					}
				}
				

				if (ChannelID == NUMCHANNELS) {
					// Didn't find a channel
					if (EmptyChannel < NUMCHANNELS) {
						// assign the mote id to this channel
						MoteIDs[EmptyChannel] = MoteID;
						ChannelID = EmptyChannel;
						CIMoteCartesianPlot *pFrame=CreateNewView(ChannelID,MoteID,SensorID);
						/*
							Note to LAMA:  below is an example of how to use the setmapping function
							pFrame->SetMappingFunction(slope, offset, minrange, maxrange
						*/
						switch(SensorType) {
							case PH_SENSOR:
								pFrame->SetMappingFunction(0,14);
								rawdata = false;
								break;
							case PRESSURE_SENSOR:
								pFrame->SetMappingFunction(0,20.684);
								//pFrame->SetMappingFunction(0,300);
								rawdata = false;
								break;
							case ACCELEROMETER_SENSOR:
								pFrame->SetMappingFunction(-2,2);
								rawdata = false;
								break;
							default :
								//pFrame->SetMappingFunction(1,1,0,14);
								pFrame->SetMappingFunction(-32768,32768);
						}
						//UpdateAllViews(NULL);
					}  
					/*
					* NOTE: if ChannelID is not assigned, 
					* the processing will remain the same, but the data won't
					* be displayed.
					* TODO : handle later
					*/
				}
				//log transaction info to file here:
				if(bPrintheader)
				{
					logentry.Format("Timestamp, iMoteID, # of Bytes\r\n");
					//logfile<<logentry<<endl;
					SaveLogEntry(&logentry);
					bPrintheader=false;
				}
				time=time.GetCurrentTime();
				//logfile<<time.Format("%c");
				SaveLogEntry(&time.Format("%c"));
				logentry.Format(", %#X, %d\r\n",MoteID, NumDataBytes);
				//logfile<<logentry<<endl;
				SaveLogEntry(&logentry);				
				break;
			default:
				Header[HeaderIndex] = rxstring[byte_index];
				HeaderIndex++;
				break;
			}
		}
		if (!bGotBeef) {
			delete []rxstring;
			return TRUE;
		}
		// Got DEADBEEF, process data
		for(; byte_index <numBytesReceived; byte_index++,NumBytesProcessed ++) {
			if (NumBytesProcessed >= NumDataBytes) {
				// go back to start, look for DEADBEEF again
				bGotBeef = false;
				HeaderIndex = 0;
				TRACE("Mote ID %lx, NumBytes %ld, byte index %d \n", MoteID, NumDataBytes, byte_index);
				//MoteID = 0;
				//NumDataBytes = 0;
				break;
			}
			if (rawdata) {	//RAW_BYTES mode, no processing
				// Assume data is 2 bytes long, and back to back
				if (CurrentByte == 0) {
					b0 = rxstring[byte_index];
					CurrentByte = 1;
				} else {
					b1 = rxstring[byte_index];
					CurrentByte = 0;
					int sample_data;
					sample_data = (b1 <<8) + b0;
					//sample_data -= 0x2000;
					//sample_data = sample_data << 2;
					point.x = (LONG) sample_data;
					point.y = 0;
					//TRACE("sample is %d\r\n", sample_data);
					if (ChannelID < NUMCHANNELS) {
						// valid channel
						AddPoint(point, ChannelID);
					}
				}
			} else {
				if (CurrentByte == 0) {
					b0 = rxstring[byte_index];
					CurrentByte = 1;
					if (SensorType == CAMERA_SENSOR) {
						// just copy data
						CameraBuffer[CameraBufferIndex] = b0;
						SegmentIndex++;
						CameraBufferIndex++;
					}
				} else {
					b1 = rxstring[byte_index];
					CurrentByte = 0;
					switch(SensorType) {
						case PH_SENSOR:
							/*
							* A/D maps 0-5V range to 0-32 K 
							* pH = -7.752 * V + 16.237
							* V = raw_data * 5 / 32768
							* The plot output expects the 0 - 14 range to be represented in -32 - 32 K
							* point.x = (-7.752 * (raw_data * 5/32768) + 16.237) * 64K / 14 - 32K
							*/
							double ph_data;
							ph_data = (b1 <<8) + b0;
							ph_data = -7.752 * (ph_data/ 32768) * 5 + 16.237;
							ph_data = (ph_data * 65536 / 14) - 32768;
							point.x = (LONG) ph_data;
							point.y = 0;
							if (ChannelID < NUMCHANNELS) {
								// valid channel
								AddPoint(point, ChannelID);
							}
							break;
						case PRESSURE_SENSOR:
							/*
							* A/D maps 0-5V range to 0-32 K 
							* The plot output expects the 0 - 20.684 range to be represented in -32 - 32 K
							* point.x = (raw_data * 5/32768) * 64K / 20.684 - 32K
							*/
							int pressure_data;
							pressure_data = (b1 <<8) + b0;
							pressure_data = pressure_data * 2 - 32768;
							point.x = (LONG) pressure_data;
							point.y = 0;
							if (ChannelID < NUMCHANNELS) {
								// valid channel
								AddPoint(point, ChannelID);
							}
							break;
						case ACCELEROMETER_SENSOR:
							// TRACE("CurrentCounter %d, ByteIndex %d \n", CurrentCounter, byte_index);
							switch (CurrentCounter) {
								case 0:
									Tx = (b0 <<8) + b1;;	
									CurrentCounter = 1;
									//TRACE("Found Tx, index %d \n", byte_index);
									break;
								case 1:
									Ty = (b0 <<8) + b1;
									CurrentCounter = 2;
									//TRACE("Found Ty, index %d \n", byte_index);
									break;
								case 2:
									T = (b0 <<8) + b1;
									Rx = ((Tx << 16) / T) - (65536/2);
									Ry = ((Ty << 16) / T) - (65536/2);
									//point.x =(LONG)( (rxstring[byte_index]<<8) + rxstring[byte_index+1]) -(65536/2);
									//point.x = (LONG)( (rxstring[byte_index]<<8) + rxstring[byte_index+1]);
									//TRACE("%d %d = %d\n",rxstring[i], rxstring[i+1], point.x);
									//TRACE("Found T, index %d \n", byte_index);
									//TRACE("Tx = %d, Ty = %d, T = %d, Rx = %d, Ry = %d\n",Tx, Ty, T, Rx, Ry);
									point.x = (LONG) Rx;
									point.y = (LONG) Ry;
									if (ChannelID < NUMCHANNELS) {
										// valid channel
										AddPoint(point, ChannelID);
									}
									CurrentCounter = 0;
									break;
								default:
									break;
							}
							break;
						
						case CAMERA_SENSOR:
							// just copy data
							CameraBuffer[CameraBufferIndex] = b1;
							SegmentIndex++;
							CameraBufferIndex++;
							break;
						
					}
				}
			//for now, just save the point in the x field of the structure
			}
			//NumBytesProcessed += 2;		
		}
		TRACE("NumBytesProcessed %d, NumDataBytes %d\r\n", NumBytesProcessed, NumDataBytes);
		// Check if we reached the end of a picture, write it to file
		if ((SensorType == CAMERA_SENSOR) && (NumBytesProcessed == NumDataBytes) &&
			(ExtraInfo == END_OF_PIC)) {
				// Create output buffer , assume header < 1000
				unsigned char *JpgImage;
				int JpgImageLen;
				JpgImage = new unsigned char[CameraBufferIndex+1000];
				// build jpeg image
				BuildJPG(CameraBuffer, CameraBufferIndex, JpgImage, &JpgImageLen);
				// write to file
				char pszFileName[200];
				CFile PictureFile;
				CFileException fileException;

				sprintf(pszFileName, "c:\\icam\\%d.jpg", LastPicID);
				LastPicID++;

				if ( !PictureFile.Open( pszFileName, CFile::modeCreate |   
									CFile::modeWrite | CFile::typeBinary,
									&fileException ) )
				{
					TRACE( "Can't open file %s, error = %u\n",
								pszFileName, fileException.m_cause );
				}
				//PictureFile.Write(CameraBuffer, CameraBufferIndex);
				PictureFile.Write(JpgImage, JpgImageLen);
				PictureFile.Close();
				TRACE("Wrote Jpeg image raw %d\r\n", CameraBufferIndex);
				
				delete []CameraBuffer;
				delete []JpgImage;
				PictureInProgress = false;
		}
	}
	delete []rxstring;
	return TRUE;
#endif;
}
Ejemplo n.º 25
0
FTContour::FTContour( FT_Vector* contour, char* pointTags, unsigned int numberOfPoints)
{
    for( unsigned int pointIndex = 0; pointIndex < numberOfPoints; ++ pointIndex)
    {
        char pointTag = pointTags[pointIndex];
        
        if( pointTag == FT_Curve_Tag_On || numberOfPoints < 2)
        {
            AddPoint( contour[pointIndex].x, contour[pointIndex].y);
            continue;
        }
        
        FTPoint controlPoint( contour[pointIndex]);
        FTPoint previousPoint = ( 0 == pointIndex)
                                ? FTPoint( contour[numberOfPoints - 1])
                                : pointList[pointList.size() - 1];

        FTPoint nextPoint = ( pointIndex == numberOfPoints - 1)
                            ? pointList[0]
                            : FTPoint( contour[pointIndex + 1]);

        if( pointTag == FT_Curve_Tag_Conic)
        {
            char nextPointTag = ( pointIndex == numberOfPoints - 1)
                                ? pointTags[0]
                                : pointTags[pointIndex + 1];
            
            while( nextPointTag == FT_Curve_Tag_Conic)
            {
                nextPoint = ( controlPoint + nextPoint) * 0.5f;

                controlPoints[0][0] = previousPoint.X(); controlPoints[0][1] = previousPoint.Y();
                controlPoints[1][0] = controlPoint.X();  controlPoints[1][1] = controlPoint.Y();
                controlPoints[2][0] = nextPoint.X();     controlPoints[2][1] = nextPoint.Y();
                
                evaluateQuadraticCurve();
                ++pointIndex;
                
                previousPoint = nextPoint;
                controlPoint = FTPoint( contour[pointIndex]);
                nextPoint = ( pointIndex == numberOfPoints - 1)
                            ? pointList[0]
                            : FTPoint( contour[pointIndex + 1]);
                nextPointTag = ( pointIndex == numberOfPoints - 1)
                               ? pointTags[0]
                               : pointTags[pointIndex + 1];
            }
            
            controlPoints[0][0] = previousPoint.X(); controlPoints[0][1] = previousPoint.Y();
            controlPoints[1][0] = controlPoint.X();  controlPoints[1][1] = controlPoint.Y();
            controlPoints[2][0] = nextPoint.X();     controlPoints[2][1] = nextPoint.Y();
            
            evaluateQuadraticCurve();
            continue;
        }

        if( pointTag == FT_Curve_Tag_Cubic)
        {
            FTPoint controlPoint2 = nextPoint;
            
            FTPoint nextPoint = ( pointIndex == numberOfPoints - 2)
                                ? pointList[0]
                                : FTPoint( contour[pointIndex + 2]);
            
            controlPoints[0][0] = previousPoint.X(); controlPoints[0][1] = previousPoint.Y();
            controlPoints[1][0] = controlPoint.X();  controlPoints[1][1] = controlPoint.Y();
            controlPoints[2][0] = controlPoint2.X(); controlPoints[2][1] = controlPoint2.Y();
            controlPoints[3][0] = nextPoint.X();     controlPoints[3][1] = nextPoint.Y();
        
            evaluateCubicCurve();
            ++pointIndex;
            continue;
        }
    }
}
Ejemplo n.º 26
0
 void AddPoint(const vertex_type& vertex, const texcoord_type& texcoord, const normal_type& normal)
 {
     return AddPoint(vertex, &texcoord, &texcoord + 1, normal);
 }
Ejemplo n.º 27
0
/*
 * GenerateTerrain
 *
 * Create random mountain peaks that are used to generate the
 * background terrain.
 */
void GenerateTerrain ()
{
    int peakx;
    int peaky;
    GList *mountainList = NULL;
    GList *node;
    typMountain *prevMountain;
    typMountain *mtn;
    int i;

    /* --- Compute the peaks --- */
    for (i = 0; i < NUM_PEAKS; i++) {
        peakx = rand () % X_RANGE;
        peaky = rand () % MAX_PEAK;
 
        mountainList = AddMountain (mountainList, peakx, peaky);
    }

    prevMountain = NULL;

    terrainList = AddPoint (terrainList, 0, 0);

    /* --- Compute the lines based on the peaks --- */
    for (node = mountainList; node; node = node->next) {
  
        mtn = (typMountain *) node->data;

        /* --- First mountain --- */
        if (prevMountain == NULL) {
            terrainList = AddPoint (terrainList, mtn->start.x, mtn->start.y);
            terrainList = AddPoint (terrainList, mtn->peak.x, mtn->peak.y);
            prevMountain = mtn;

        /* --- Don't cross paths --- */
        } else if (prevMountain->end.x < mtn->start.x) {
 
            terrainList = AddPoint (terrainList, 
                                    prevMountain->end.x, 
                                    prevMountain->end.y);
            terrainList = AddPoint (terrainList, mtn->start.x, mtn->start.y);
            terrainList = AddPoint (terrainList, mtn->peak.x, mtn->peak.y);
            prevMountain = mtn;

        /* --- previous mountain eats this one --- */
        } else if (prevMountain->end.x > mtn->end.x) {
            
            /* --- Do nothing yet --- */
        } else {

            /* --- Mountains intersect --- */
            terrainList = AddPoint (terrainList, 
                                    (prevMountain->end.x + mtn->start.x) / 2,
                                    (prevMountain->end.x - mtn->start.x) / 2);
            terrainList = AddPoint (terrainList, mtn->peak.x, mtn->peak.y);
            prevMountain = mtn;
        }
    }
    terrainList = AddPoint (terrainList, 
                                    prevMountain->end.x, 
                                    prevMountain->end.y);
    terrainList = AddPoint (terrainList, X_RANGE, 0);
}
Ejemplo n.º 28
0
void box2::FromPoints(vec2 *points, int numpoints)
{
    for (int i = 0; i < numpoints; i++)
        AddPoint(points[i]);
}
Ejemplo n.º 29
0
void BattleGroundWS::EventPlayerCapturedFlag(Player* source)
{
    if (GetStatus() != STATUS_IN_PROGRESS)
        return;

    Team winner = TEAM_NONE;

    source->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT);
    if (source->GetTeam() == ALLIANCE)
    {
        if (!IsHordeFlagPickedUp())
            return;
        ClearHordeFlagCarrier();                            // must be before aura remove to prevent 2 events (drop+capture) at the same time
        // horde flag in base (but not respawned yet)
        m_FlagState[TEAM_INDEX_HORDE] = BG_WS_FLAG_STATE_WAIT_RESPAWN;
        // Drop Horde Flag from Player
        source->RemoveAurasDueToSpell(BG_WS_SPELL_WARSONG_FLAG);
        if (GetTeamScore(ALLIANCE) < BG_WS_MAX_TEAM_SCORE)
            AddPoint(ALLIANCE, 1);
        PlaySoundToAll(BG_WS_SOUND_FLAG_CAPTURED_ALLIANCE);
        RewardReputationToTeam(890, m_ReputationCapture, ALLIANCE);
    }
    else
    {
        if (!IsAllianceFlagPickedUp())
            return;
        ClearAllianceFlagCarrier();                         // must be before aura remove to prevent 2 events (drop+capture) at the same time
        // alliance flag in base (but not respawned yet)
        m_FlagState[TEAM_INDEX_ALLIANCE] = BG_WS_FLAG_STATE_WAIT_RESPAWN;
        // Drop Alliance Flag from Player
        source->RemoveAurasDueToSpell(BG_WS_SPELL_SILVERWING_FLAG);
        if (GetTeamScore(HORDE) < BG_WS_MAX_TEAM_SCORE)
            AddPoint(HORDE, 1);
        PlaySoundToAll(BG_WS_SOUND_FLAG_CAPTURED_HORDE);
        RewardReputationToTeam(889, m_ReputationCapture, HORDE);
    }
    // for flag capture is reward distributed according level range
    RewardHonorToTeam(BG_WSG_FlagCapturedHonor[GetBracketId()], source->GetTeam());

    // despawn flags
    SpawnEvent(WS_EVENT_FLAG_A, 0, false);
    SpawnEvent(WS_EVENT_FLAG_H, 0, false);

    if (source->GetTeam() == ALLIANCE)
        SendMessageToAll(LANG_BG_WS_CAPTURED_HF, CHAT_MSG_BG_SYSTEM_ALLIANCE, source);
    else
        SendMessageToAll(LANG_BG_WS_CAPTURED_AF, CHAT_MSG_BG_SYSTEM_HORDE, source);

    UpdateFlagState(source->GetTeam(), 1);                  // flag state none
    UpdateTeamScore(source->GetTeam());

    // only flag capture should be updated
    UpdatePlayerScore(source, SCORE_FLAG_CAPTURES, 1);      // +1 flag captures

    if (GetTeamScore(ALLIANCE) == BG_WS_MAX_TEAM_SCORE)
        winner = ALLIANCE;

    if (GetTeamScore(HORDE) == BG_WS_MAX_TEAM_SCORE)
        winner = HORDE;

    if (winner)
    {
        UpdateWorldState(BG_WS_FLAG_UNK_ALLIANCE, 0);
        UpdateWorldState(BG_WS_FLAG_UNK_HORDE, 0);
        UpdateWorldState(BG_WS_FLAG_STATE_ALLIANCE, 1);
        UpdateWorldState(BG_WS_FLAG_STATE_HORDE, 1);

        EndBattleGround(winner);
    }
    else
    {
        m_FlagsTimer[GetOtherTeamIndex(GetTeamIndex(source->GetTeam()))] = BG_WS_FLAG_RESPAWN_TIME;
    }
}
Ejemplo n.º 30
0
 void AddTriangle(const vertex_type* v, const texcoord_type* t, const normal_type* n)
 {
     for (unsigned int i = 0; i < 3; ++i)
         AddPoint(v[i], t[i], n[i]);
 }