Esempio n. 1
0
void LineClipping_Clip(const struct LineClipping_Rectangle *r,
	struct LineClipping_Segment *s, 
	int *done)
{
	const int maxIter = 4;
	int outcode0, outcode1, i;
	double x, y;
	
	/*Cohen-Sutherland line clipping algorithm*/
	outcode0 = Outcode(s->x0, s->y0, r);
	outcode1 = Outcode(s->x1, s->y1, r);
	i = 0;
	while (! Inside(outcode0, outcode1) && ! SameSide(outcode0, outcode1) && (i < maxIter)) {
		if (outcode0 != 0) {
			GetIntersection(r, s, outcode0, &x, &y);
			s->x0 = x;
			s->y0 = y;
			outcode0 = Outcode(x, y, r);
		} else {
			GetIntersection(r, s, outcode1, &x, &y);
			s->x1 = x;
			s->y1 = y;
			outcode1 = Outcode(x, y, r);
		}
		i++;
	}
	assert(i < maxIter);
	*done = Inside(outcode0, outcode1);
}
Esempio n. 2
0
bool C4Network2IO::Execute(int iTimeout, pollfd *)
{
    tLastExecute = C4TimeMilliseconds::Now();

    // check for timeout
    CheckTimeout();

    // ping all open connections
    if (!Inside(tLastPing, tLastExecute - C4NetPingFreq, tLastExecute))
    {
        Ping();
        tLastPing = tLastExecute;
    }

    // do statistics
    if (!Inside(tLastStatistic, tLastExecute - C4NetStatisticsFreq, tLastExecute))
    {
        GenerateStatistics(tLastExecute - tLastStatistic);
        tLastStatistic = tLastExecute;
    }

    // resources
    ::Network.ResList.OnTimer();

    // ok
    return true;
}
void C4EditCursor::FrameSelection()
{
	ClearSelection();
	C4Object *cobj; C4ObjectLink *clnk;
	for (clnk=::Objects.First; clnk && (cobj=clnk->Obj); clnk=clnk->Next)
		if (cobj->Status) if (cobj->OCF & OCF_NotContained)
			{
				if (Inside(cobj->GetX(),Min(X,X2),Max(X,X2)) && Inside(cobj->GetY(),Min(Y,Y2),Max(Y,Y2)))
					AddToSelection(cobj);
			}
	OnSelectionChanged();
}
Esempio n. 4
0
static bool FnLayerSetPixel(C4PropList * _this, int32_t x, int32_t y, const C4Value& fg_value_c4v, const C4Value& bg_value_c4v)
{
	// Layer script function: Set pixel at position x,y to to_value in _this layer
	C4MapScriptLayer *layer = _this->GetMapScriptLayer();
	if (!layer) return false;
	uint8_t fg, bg;

	if (fg_value_c4v.GetType() == C4V_Nil)
	{
		fg = layer->GetPix(x,y,0);
	}
	else
	{
		const C4Value& val = fg_value_c4v;
		C4String *str = val.getStr();
		if (str != NULL)
		{
			if (!TexColSingle(str->GetCStr(), fg))
				throw C4AulExecError("MapLayer::SetPixel: Trying to set invalid pixel value.");
		}
		else
		{
			if (!Inside(val.getInt(), 0, 255))
				throw C4AulExecError("MapLayer::SetPixel: Trying to set invalid pixel value.");
			fg = val.getInt();
		}
	}

	if (bg_value_c4v.GetType() == C4V_Nil)
	{
		bg = layer->GetBackPix(x,y,0);
	}
	else
	{
		const C4Value& val = bg_value_c4v;
		C4String *str = val.getStr();
		if (str != NULL)
		{
			if (!TexColSingle(str->GetCStr(), bg))
				throw C4AulExecError("MapLayer::SetPixel: Trying to set invalid pixel value.");
		}
		else
		{
			if (!Inside(val.getInt(), 0, 255))
				throw C4AulExecError("MapLayer::SetPixel: Trying to set invalid pixel value.");
			bg = val.getInt();
		}
	}
			
	return layer->SetPix(x,y,fg,bg);
}
Esempio n. 5
0
global func CyclopsExecuteIdle(fx)
{
	if (!Inside(fx.cyclops->GetX()-fx.home_x, -5,5) || !Inside(fx.cyclops->GetY()-fx.home_y, -15,15))
	{
		fx.cyclops->SetCommand("MoveTo", nil, fx.home_x, fx.home_y);
	}
	else
	{
		fx.cyclops->SetCommand("None");
		fx.cyclops->SetComDir(COMD_Stop);
		fx.cyclops->SetDir(fx.home_dir);
	}
	return true;
}
Esempio n. 6
0
	void Is_draw_active(float _icon_pos_y)//Insideがtrueのときさらに判定
	{

		if (Inside(_icon_pos_y, -185, -215))
		{   
		   judge_num =JUDGE::EXCELENT;
		}
		else if (Inside(_icon_pos_y, -165, -185) || Inside(_icon_pos_y, -215, -235))
		{
			judge_num = JUDGE::GOOD;
		}
		else judge_num= JUDGE::BAD;

	}
Esempio n. 7
0
void C4FacetEx::DrawBolt(int iX1, int iY1, int iX2, int iY2, BYTE bCol,
                         BYTE bCol2) {
  if (!lpDDraw || !Surface || !Wdt || !Hgt) return;
  // Scroll position
  iX1 -= TargetX;
  iY1 -= TargetY;
  iX2 -= TargetX;
  iY2 -= TargetY;
  // Facet bounds
  if (!Inside(iX1, 0, Wdt - 1) && !Inside(iX2, 0, Wdt - 1)) return;
  if (!Inside(iY1, 0, Hgt - 1) && !Inside(iY2, 0, Hgt - 1)) return;
  iX1 += X;
  iX2 += X;
  iY1 += Y;
  iY2 += Y;
  // Draw bolt
  int pvtx[2 * 4];
  pvtx[0] = iX1;
  pvtx[1] = iY1;
  pvtx[2] = iX2;
  pvtx[3] = iY2;
#ifdef C4ENGINE
  pvtx[4] = iX2 + SafeRandom(DrawBoltR1) - DrawBoltR2;
  pvtx[5] = iY2 + SafeRandom(DrawBoltR1) - DrawBoltR2;
  pvtx[6] = iX1 + SafeRandom(DrawBoltR1) - DrawBoltR2;
  pvtx[7] = iY1 + SafeRandom(DrawBoltR1) - DrawBoltR2;
#else
  pvtx[4] = iX2 + X % 3 - 1;
  pvtx[5] = iY2 + X % 3 - 1;
  pvtx[6] = iX1 + Y % 3 - 1;
  pvtx[7] = iY1 + Y % 3 - 1;
#endif
  // Draw in surface
  DWORD dwClr1 = lpDDraw->Pal.GetClr(bCol), dwClr2;
  DWORD dwClr3 = lpDDraw->Pal.GetClr(bCol2), dwClr4;
  /*if (DDrawCfg.NoBoxFades)
          {*/
  dwClr2 = dwClr1;
  dwClr4 = dwClr3;
  /*}
else
  {
  DWORD dwClr2=dwClr1|0xff000000; ...this leads to black and white lightning
bolts. Who wants that?
  DWORD dwClr4=dwClr3|0xff000000;
  }*/
  lpDDraw->DrawQuadDw(Surface, pvtx, dwClr1, dwClr3, dwClr4, dwClr2);
}
Esempio n. 8
0
func Intro_Stop()
{
	// Lava gets quiet after intro
	var lava = FindObject(Find_ID(BoilingLava));
	if (lava) lava->SetIntensity(25);
	// if players got stuck somewhere, unstick them
	for (var i=0; i<GetPlayerCount(C4PT_User); ++i)
	{
		var plr = GetPlayerByIndex(i, C4PT_User);
		var crew = GetCrew(plr);
		if (crew && !Inside(crew->GetX(),125,170))
		{
			crew->SetPosition(135+Random(25), 860);
		}
		crew->Extinguish();
		crew->DoEnergy(100);
	}
	this.dialogue->SetInteraction(true);
	this.dialogue->AddAttention();
	SetPlayerZoomByViewRange(NO_OWNER, 400,300, PLRZOOM_Set);
	
	// Turn and relocate the airplane to make starting it easier.
	var plane = FindObject(Find_ID(Airplane));
	if (plane)
	{
		plane->FaceLeft();
		plane->SetR(-90);
		plane->SetPosition(1387, 345);
	}
	return true;
}
bool C4MapScriptAlgoPolygon::operator () (int32_t x, int32_t y, uint8_t& fg, uint8_t& bg) const
{
	// Evaluate MAPALGO_Polygon at x,y: Return 1 for pixels within the polygon or its borders, 0 otherwise
	int32_t crossings = 0;
	for (size_t i=0; i<poly.size(); ++i)
	{
		Pt pt1 = poly[i];
		Pt pt2 = poly[(i+1)%poly.size()];
		// check border line distance
		int32_t pdx = pt2.x-pt1.x, pdy = pt2.y-pt1.y, dx = x-pt1.x, dy = y-pt1.y;
		if (i!=poly.size()-1 || !open)
		{
			int64_t d = dx*pdy-dy*pdx;
			int32_t lsq = (pdx*pdx+pdy*pdy);
			if (d*d < wdt*wdt*lsq) // check distance perpendicular to line
			{
				if (Inside(dx*pdx+dy*pdy, 0, lsq)) // check if point lies within pt1 and pt2
					return true; // x/y lies on this line
			}
		}
		// check point distance
		if (dx*dx+dy*dy < wdt*wdt) return true; // x/y lies close to edge point
		// filling of polygon: point is contained if it crosses an off number of borders
		if (!empty && (pt1.y<=y) != (pt2.y<=y)) // crossing vertically?
		{
			// does line pt1-pt2 intersect line (x,y)-(inf,y)?
			crossings += (dx>dy*pdx/pdy);
		}
	}
	// x/y lies inside polygon
	return (crossings % 2)==1;
}
Esempio n. 10
0
vector<int> Floor::ComputeShortestPath(int start, int end) const {
	int cur = start;
	vector<int> moves;
	while (cur != end) {
		int move = 0;
		double cur_dist = Distance(cur, end);

		if (cur_dist == NumCells()) {
			return moves;
		}

		for (int a = 0; a < 4; a++) {
			Coord pos = GetCell(cur) + Compass::DIRECTIONS[a];
			int next = cur;
			if (Inside(pos))
				next = GetIndex(pos);

			double dist = Distance(next, end);

			if (dist < cur_dist) {
				move = a;
				cur = next;
				break;
			}
		}
		moves.push_back(move);
	}
	return moves;
}
Esempio n. 11
0
private func FitsInElevator(pObject)
{
  // Fahrzeuge, die eine Extra Aufzugsaktion haben, sollten immer passen
  if(pObject->~FitsInElevator()) return(1);//ObjectSetAction(pObject, "Elevator")) return(1);
  // Alle (ungedrehten) Vertices des Objekts prüfen
  var vertexCount = GetDefCoreVal("Vertices", "DefCore", pObject->GetID());
  for (var i = 0; i < vertexCount; i++) 
  {
    var vertexX = GetDefCoreVal("VertexX", "DefCore", pObject->GetID(), i);
    var vertexY = GetDefCoreVal("VertexY", "DefCore", pObject->GetID(), i);
    // Passt nicht
    if (!Inside(vertexX, -12, 11) || !Inside(vertexY, -20, 16)) return(0);
  }
  // Passt
  return(1);  
}
Esempio n. 12
0
C4Graph::ValueType C4TableGraph::GetValue(TimeType iAtTime) const {
  // must be inside buffer
  assert(Inside(iAtTime, GetStartTime(), GetEndTime() - 1));
  // query it - can't be negative if inside start/end-time
  return pAveragedValues[(iAtTime - iInitialStartTime) % iBackLogLength] *
         fMultiplier;
}
Esempio n. 13
0
 const typename Inside::member_type& get()
 {
   auto _this = Outside(this->t);
   auto get_this = _this.get();
   auto get_that = Inside(get_this);
   return get_that.get();
 }
int TextArea::MouseMove( float x, float y )
{
    if (do_highlight == 0) return 0;
    if (Inside( x, y, 5 ) == 0) return 0;
    cur_highlighted = LocateCount( y );
    return 1;
}
int TextArea::MouseMoveClick( float x, float y )
{
    if (scroll_start == 0 && Inside( x, y, 4 ) == 0) return 0;
    if (scroll_start == 0) scroll_start = y;
    scroll_cur = y;
    return 1;
}
Esempio n. 16
0
bool
AbstractAirspace::Inside(const AircraftState &state) const
{
  return altitude_base.IsBelow(state) &&
         altitude_top.IsAbove(state) &&
         Inside(state.location);
}
Esempio n. 17
0
bool TCheckbox::Click(int state, int x, int y) {
	if (active && visible && Inside(x, y, mouseRect)) {
		if (state) checked = !checked;
		return true;
	}
	return false;
}
//#####################################################################
// Function Calculate_Signed_Distance
//#####################################################################
template<class T> T POINT_SIMPLICES_1D<T>:: 
Calculate_Signed_Distance(const TV& location,T thickness_over_two) const
{
    T distance;
    Closest_Point_On_Boundary(location,0,thickness_over_two,0,&distance);
    if(Inside(location,thickness_over_two)) distance*=-1;
    return distance;
}
Esempio n. 19
0
 const typename Outside::object_type set(const typename Inside::member_type& a)
 {
   auto _this = Outside(this->t);
   
   auto get_this = _this.get();
   auto mod_that = Inside(get_this).set(a);
   return _this.set(mod_that);
 }
Esempio n. 20
0
/*
* Implementation of the clipping algortihim
* outputVertexes - The vertexes that will be output
  inputVertacies - The vertacies passed into the algorithim
  Edge - The edge we are clipping on
*/
void clipper::ClipSide(std::vector<EnumTypes::Vertex>* outputVertexes, std::vector<EnumTypes::Vertex> inputVertacies, EnumTypes::Line* Edge)
{
	//Each interation update the start vertex, end, and intersection of the given bvetacie and the edge
	EnumTypes::Vertex start, end, intersection;

	//Get the last vertacie
	if (inputVertacies.size() != 0)
	{
		start = inputVertacies.at(inputVertacies.size() - 1);
	}

	//Loop through all of the input vertacies
	for (int x = 0; x < inputVertacies.size(); x++)
	{
		end = inputVertacies.at(x);

		//If the start point is inside
		if (Inside(end, *Edge))
		{
			if (Inside(start, *Edge))
			{
				addVertexOutput(&end, outputVertexes);
			}
			else
			{
				EnumTypes::Line *tLine = new EnumTypes::Line(&start, &end, true);
				Intersect(*tLine, *Edge, &intersection);
				delete tLine;
				addVertexOutput(&intersection, outputVertexes);
				addVertexOutput(&end, outputVertexes);
			}
		}
		else
		{
			if (Inside(start, *Edge))
			{
				EnumTypes::Line *tLine = new EnumTypes::Line(&start, &end, true);
				Intersect(*tLine, *Edge, &intersection);
				delete tLine;
				addVertexOutput(&intersection, outputVertexes);
			}
		}
		start = end;
	}
}
Esempio n. 21
0
Block* Block::GetBlock(const dReal* AABB){
	if (Inside(AABB)){
		return GetBlockChild(AABB);	// Child or this will have a good block
	}
	else if (Parent){
		return Parent->GetBlock(AABB);	// Parent has a good block
	}
	else return this;	// We are at the root, so we have little choice
}
Esempio n. 22
0
void Slider::Handle (Event& e) {
    if (e.eventType == DownEvent) {
	if (Inside(e)) {
	    Slide(e);
	} else {
	    Jump(e);
	}
	interactor->Adjust(*shown);
    }
}
Esempio n. 23
0
Clik  cCaseX11Xml::clik_in()
{
   while (1)
   {
      Clik aClk = mW.clik_in();
      if (Inside(Pt2di(aClk._pt)))
         return aClk;
   }
   return mW.clik_in();
}
Esempio n. 24
0
private func CheckStuck()
{
  var pClonk,iYChange,iX,iY;
  // Alle feststeckenden Clonks in der Nähe suchen
  for (pClonk in FindObjects(Find_InRect(-20,-20,40,40), Find_OCF(OCF_CrewMember),Find_NoContainer()))
  {
    iX=GetX(pClonk);
    iY=GetY(pClonk);
    while(Stuck(pClonk) && Inside(GetY(pClonk)-GetY(),-20,20))
    {
      if(!(iYChange=BoundBy(GetY(pClonk)-GetY(),-1,1))) iYChange=1;
      // Zur Sicherheit...
      if(!Inside(GetY(pClonk)+iYChange,-100,LandscapeHeight())) break;
      SetPosition(GetX(pClonk),GetY(pClonk)+iYChange,pClonk);
    }
    // verschieben fehlgeschlagen: rückgängig machen
    if(Stuck(pClonk)) SetPosition(iX,iY,pClonk);
  }
}
Esempio n. 25
0
void C4GameSaveSavegame::AdjustCore(C4Scenario &rC4S)
{
	// Determine save game index from trailing number in group file name
	int iSaveGameIndex = GetTrailingNumber(GetFilenameOnly(pSaveGroup->GetFullName().getData()));
	// Looks like a decent index: set numbered icon
	if (Inside(iSaveGameIndex, 1, 10))
		rC4S.Head.Icon = 2 + (iSaveGameIndex - 1);
	// Else: set normal script icon
	else
		rC4S.Head.Icon = 29;
}
Esempio n. 26
0
Spectrum ProjectionLight::Projection(const Vector3f &w) const {
    Vector3f wl = WorldToLight(w);
    // Discard directions behind projection light
    if (wl.z < hither) return 0;

    // Project point onto projection plane and compute light
    Point3f p = lightProjection(Point3f(wl.x, wl.y, wl.z));
    if (!Inside(Point2f(p.x, p.y), screenBounds)) return 0.f;
    if (!projectionMap) return 1;
    Point2f st = Point2f(screenBounds.Offset(Point2f(p.x, p.y)));
    return Spectrum(projectionMap->Lookup(st), SpectrumType::Illuminant);
}
void CAIVolume::EnumerateSearchNodes(uint32* aiSearchNodes, uint32* pcSearchNodes, const uint32 nMaxSearchNodes) const
{
	for ( uint32 iNode = 0 ; iNode < g_pAINodeMgr->GetNumNodes() && *pcSearchNodes < nMaxSearchNodes ; iNode++ )
	{
		CAINode* pNode = g_pAINodeMgr->GetNode(iNode);

		if ( pNode && pNode->IsSearchable() && Inside(pNode->GetPos(), 53.0f) )
		{
			aiSearchNodes[(*pcSearchNodes)++] = pNode->GetID();
		}
	}
}
Esempio n. 28
0
bool TIconButton::Click(int state, int x, int y) {
	if (Inside(x, y, mouseRect)) {
		focus = true;
		if (state) {
			value++;
			if (value > maximum)
				value = 0;
		}
		return true;
	}
	return false;
}
Esempio n. 29
0
  inline bool Inside( const AABB &bbox )
  {
    if ( !Inside( bbox.m_Center ) ) return false;

    for ( int i = 0; i < 3; i++ )
    {
      if ( m_MaxCorner[ i ] < bbox.m_MaxCorner[ i ] )
        return false;
      if ( bbox.m_MinCorner[ i ] > m_MinCorner[ i ] )
        return false;
    }
    return true;
  }
Esempio n. 30
0
bool ClrByOwner(DWORD &dwClr) // new style, based on Microsoft Knowledge Base Article - 29240
{
	int H,L,S;
	WORD R,G,B;
	BYTE cMax,cMin;
	WORD  Rdelta,Gdelta,Bdelta;
	// get RGB
	R = GetRedValue(dwClr);
	G = GetGreenValue(dwClr);
	B = GetBlueValue(dwClr);
	// calculate lightness
	cMax = std::max<int>(std::max<int>(R,G),B);
	cMin = std::min<int>(std::min<int>(R,G),B);
	L = ( ((cMax+cMin)*HLSMAX) + RGBMAX )/(2*RGBMAX);
	// achromatic case
	if (cMax == cMin)
	{
		S = 0;
		H = (HLSMAX*2/3);
	}
	// chromatic case
	else
	{
		// saturation
		if (L <= (HLSMAX/2))
			S = ( ((cMax-cMin)*HLSMAX) + ((cMax+cMin)/2) ) / (cMax+cMin);
		else
			S = ( ((cMax-cMin)*HLSMAX) + ((2*RGBMAX-cMax-cMin)/2) )
			    / (2*RGBMAX-cMax-cMin);
		// hue
		Rdelta = ( ((cMax-R)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin);
		Gdelta = ( ((cMax-G)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin);
		Bdelta = ( ((cMax-B)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin);
		if (R == cMax)
			H = Bdelta - Gdelta;
		else if (G == cMax)
			H = (HLSMAX/3) + Rdelta - Bdelta;
		else
			H = ((2*HLSMAX)/3) + Gdelta - Rdelta;
		if (H < 0)
			H += HLSMAX;
		if (H > HLSMAX)
			H -= HLSMAX;
	}
	// Not blue
	if (!(Inside(H, 145, 175) && (S > 100))) return false;
	// It's blue: make it gray
	BYTE b = GetBlueValue(dwClr);
	dwClr = RGBA(b, b, b, 0) | (dwClr & 0xff000000);
	return true;
}