Пример #1
0
/*
==============
sdDeployMaskEditSession::SetMaskState
==============
*/
bool sdDeployMaskEditSession::SetMaskState( const idVec3& position, bool save, bool state ) {
	sdDeployMaskInstance* mask = GetMask( position );
	if ( mask == NULL ) {
		return false;
	}

	sdDeployMask::extents_t extents;
	GetExtents( position, *mask, extents );

	bool changed = false;

	for ( int i = extents.minx; i <= extents.maxx; i++ ) {
		for ( int j = extents.miny; j <= extents.maxy; j++ ) {
			if ( ( mask->GetState( i, j ) != 0 ) == state ) {
				continue;
			}
			changed = true;
			mask->SetState( i, j, state );
		}
	}

	if ( changed && save ) {
		mask->WriteTGA();
	}

	return changed;
}
void
avtMultiResolutionPartitionStrategy::FindBoxes(int level, int cell)
{
    int  i;

    RegionDescription &rd = reg_desc[level][cell];
    if (rd.allOn)
    {
        int extents[6];
        GetExtents(level, cell, extents);
        AddBox(extents);
    }
    else if (rd.someOn)
    {
        // Note: assume level > 0, because level 0 cells are always all on 
        // or all off.
        int subcells[8];
        GetSubCells(level, cell, subcells);
        bool allOn[8];
        bool someOn[8];
        for (i = 0 ; i < 8 ; i++)
        {
            allOn[i]  = reg_desc[level-1][subcells[i]].allOn;
            someOn[i] = reg_desc[level-1][subcells[i]].someOn;
        }

        SearchFor2x2Box(allOn, someOn, level-1, subcells);
        SearchFor2x1Line(allOn, someOn, level-1, subcells);
        for (i = 0 ; i < 8 ; i++)
        {
            if (someOn[i])
                FindBoxes(level-1, subcells[i]);
        }
    }
}
Пример #3
0
bool vtStructureArray::WriteXML(const char* filename, bool bGZip) const
{
	VTLOG("WriteXML(%s)\n", filename);

	// Avoid trouble with '.' and ',' in Europe
	LocaleWrap normal_numbers(LC_NUMERIC, "C");

	GZOutput out(bGZip);
	if (!gfopen(out, filename))
	{
		throw xh_io_exception("Could not open output file", xh_location(filename),
				"XML Writer");
	}

	gfprintf(out, "<?xml version=\"1.0\"?>\n");
	gfprintf(out, "\n");

	gfprintf(out, "<StructureCollection xmlns=\"http://www.openplans.net\"\n"
		"\t\t\t\t\t xmlns:gml=\"http://www.opengis.net/gml\"\n"
		"\t\t\t\t\t xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
		"\t\t\t\t\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
		"\t\t\t\t\t xsi:schemaLocation=\"http://www.openplans.net/buildings.xsd\">\n");
	gfprintf(out, "\n");

	// Write the extents (required by gml:StructureCollection)
	DRECT ext;
	GetExtents(ext);
	gfprintf(out, "\t<gml:boundedBy>\n");
	gfprintf(out, "\t\t<gml:Box>\n");
	gfprintf(out, "\t\t\t<gml:coordinates>");
	gfprintf(out, "%.9lf,%.9lf %.9lf,%.9lf", ext.left, ext.bottom, ext.right, ext.top);
	gfprintf(out, "</gml:coordinates>\n");
	gfprintf(out, "\t\t</gml:Box>\n");
	gfprintf(out, "\t</gml:boundedBy>\n");
	gfprintf(out, "\n");

	// Write projection
	char *wkt;
	OGRErr err = m_proj.exportToWkt(&wkt);
	if (err != OGRERR_NONE)
	{
		throw xh_io_exception("Couldn't write CRS to file", xh_location(filename),
				"XML Writer");
	}
	gfprintf(out, "\t<SRS>%s</SRS>\n", wkt);
	gfprintf(out, "\n");
	OGRFree(wkt);

	bool bDegrees = (m_proj.IsGeographic() == 1);

	for (uint i = 0; i < GetSize(); i++)
	{
		vtStructure *str = GetAt(i);
		str->WriteXML(out, bDegrees);
	}
	gfprintf(out, "</StructureCollection>\n");
	gfclose(out);
	return true;
}
Пример #4
0
bool vtBuilding::GetBaseLevelCenter(DPoint2 &p) const
{
	DRECT rect;
	if (!GetExtents(rect))
		return false;
	rect.GetCenter(p);
	return true;
}
void 
avtMultiResolutionPartitionStrategy::Make2x1Line(int level, int c1, int c2)
{
    int extents[6];
    GetExtents(level, c1, extents);

    int e2[6];
    GetExtents(level, c2, e2);
    extents[0] = (extents[0] < e2[0] ? extents[0] : e2[0]);
    extents[1] = (extents[1] > e2[1] ? extents[1] : e2[1]);
    extents[2] = (extents[2] < e2[2] ? extents[2] : e2[2]);
    extents[3] = (extents[3] > e2[3] ? extents[3] : e2[3]);
    extents[4] = (extents[4] < e2[4] ? extents[4] : e2[4]);
    extents[5] = (extents[5] > e2[5] ? extents[5] : e2[5]);

    AddBox(extents);
}
Пример #6
0
    CAABB3::CollisionInfo CAABB3::GetCollisionInfo(const CAABB3& _rAABB, const Core::CVector3& _rMovementVector) const
	{
        Core::CVector3 OtherPosition = _rAABB.GetCenter();
        Core::CVector3 OtherExtents  = _rAABB.GetExtents();
        Core::CVector3 Position      = GetCenter();
        Core::CVector3 Extents       = GetExtents();

        float ScaleX = 1.0f / _rMovementVector[0];
        float ScaleY = 1.0f / _rMovementVector[1];
        float ScaleZ = 1.0f / _rMovementVector[2];

        float SignX = Algo::Sign(ScaleX);
        float SignY = Algo::Sign(ScaleY);
        float SignZ = Algo::Sign(ScaleZ);

        float NearTimeX = (Position[0] - SignX * (Extents[0] + OtherExtents[0]) - OtherPosition[0]) * ScaleX;
        float NearTimeY = (Position[1] - SignY * (Extents[1] + OtherExtents[1]) - OtherPosition[1]) * ScaleY;
        float NearTimeZ = (Position[2] - SignZ * (Extents[2] + OtherExtents[2]) - OtherPosition[2]) * ScaleZ;

        float FarTimeX  = (Position[0] + SignX * (Extents[0] + OtherExtents[0]) - OtherPosition[0]) * ScaleX;
        float FarTimeY  = (Position[1] + SignY * (Extents[1] + OtherExtents[1]) - OtherPosition[1]) * ScaleY;
        float FarTimeZ  = (Position[2] + SignZ * (Extents[2] + OtherExtents[2]) - OtherPosition[2]) * ScaleZ;

        float HitTime = 1.0f;

        if (!(NearTimeX > FarTimeY ||
              NearTimeX > FarTimeZ ||
              NearTimeY > FarTimeX ||
              NearTimeY > FarTimeZ ||
              NearTimeZ > FarTimeX ||
              NearTimeZ > FarTimeY
              ))
        {
            float NearTime = Algo::Max(Algo::Max(NearTimeX, NearTimeY), NearTimeZ);
            float FarTime  = Algo::Min(Algo::Min(FarTimeX, FarTimeY), FarTimeZ);

            if (!(NearTime >= 1.0f || FarTime <= 0.0f))
            {
                HitTime = Algo::Clamp(NearTime - 0.0001f, 0.0f, 1.0f);
            }
        }

        
        CollisionInfo Info;
        Info.m_Time   = HitTime;

        if (NearTimeX > NearTimeY)
        {
            Info.m_Normal[0] = -SignX;
        }
        else
        {
            Info.m_Normal[1] = -SignY;
        }


        return Info;
	}
void 
avtMultiResolutionPartitionStrategy::Make2x2Box(int level, int *cellids)
{
    int extents[6];
    GetExtents(level, cellids[0], extents);
    for (int i = 1 ; i < 4 ; i++)
    {
        int e2[6];
        GetExtents(level, cellids[i], e2);
        extents[0] = (extents[0] < e2[0] ? extents[0] : e2[0]);
        extents[1] = (extents[1] > e2[1] ? extents[1] : e2[1]);
        extents[2] = (extents[2] < e2[2] ? extents[2] : e2[2]);
        extents[3] = (extents[3] > e2[3] ? extents[3] : e2[3]);
        extents[4] = (extents[4] < e2[4] ? extents[4] : e2[4]);
        extents[5] = (extents[5] > e2[5] ? extents[5] : e2[5]);
    }
    AddBox(extents);
}
Пример #8
0
void BoxCollider::Rebuild (Model* mesh, Transform* transform)
{
	if (!_isGenerated) {
		return;
	}

	/*
	 * Compute mesh extents
	*/

	glm::vec3 extents = GetExtents (mesh, transform);

	/*
	 * Bullet box shape is created based on half of the extents
	*/

	btVector3 halfExtents = btVector3 (
		extents.x / 2.0f,
		extents.y / 2.0f,
		extents.z / 2.0f
	);

	_collisionShape = new btBoxShape (halfExtents);
}
Пример #9
0
//  ---------------------------------------------------------------------------
CUI_RESULTTYPE	CUIPolyString_Impl::SetPosition(float x, float y)
{
	// apply the new coords to the polygons
	int32 i, v;

	if (!m_Valid) return CUIR_INVALID_POLYSTRING;
	
	float dx = x - m_X;
	float dy = y - m_Y;
		
	for (i=0; i<m_Length; i++) {
		for (v=0; v<4; v++) {
			m_pPolys[i].verts[v].x += dx;
			m_pPolys[i].verts[v].y += dy;
		}
	}
	
	m_X = x;
	m_Y = y;

	GetExtents(&m_Rect);
	
	return CUIR_OK;
}	
Пример #10
0
/*
==============
sdDeployMaskEditSession::UpdateProjection
==============
*/
void sdDeployMaskEditSession::UpdateProjection( const idVec3& position ) {
	if ( !decalMaterial ) {
		return;
	}

	if ( decalHandle == -1 ) {
		decalHandle = gameLocal.RegisterLoggedDecal( decalMaterial );
	}
	gameLocal.ResetLoggedDecal( decalHandle );

	gameDecalInfo_t* decalInfo = gameLocal.GetLoggedDecal( decalHandle );

	sdDeployMaskInstance* mask = GetMask( position );
	const sdHeightMapInstance* heightMap = GetHeightMap( position );

	if ( mask != NULL && mask->IsValid() && heightMap != NULL ) {
		sdDeployMask::extents_t extents;
		GetExtents( position, *mask, extents );

		float depth = 512.0f;

		int maxX, maxY;
		mask->GetDimensions( maxX, maxY );

		sdDeployMask::extents_t expandedExtents;

		expandedExtents.minx = Max( 0, extents.minx - 2 );
		expandedExtents.miny = Max( 0, extents.miny - 2 );

		expandedExtents.maxx = Min( maxX, extents.maxx + 2 );
		expandedExtents.maxy = Min( maxY, extents.maxy + 2 );

		idList< const idMaterial* > megaTextureMaterials;
		const idStrList& megaTextureMaterialNames = gameLocal.GetMapInfo().GetMegatextureMaterials();
		for ( int i = 0; i < megaTextureMaterialNames.Num(); i++ ) {
			megaTextureMaterials.Append( declHolder.FindMaterial( megaTextureMaterialNames[ i ] ) );
		}

		idFixedWinding winding;
		
		int spawnID = WORLD_SPAWN_ID;

		for ( int i = expandedExtents.minx; i <= expandedExtents.maxx; i++ ) {
			for ( int j = expandedExtents.miny; j <= expandedExtents.maxy; j++ ) {
				gameDecalInfo_t* info = decalInfo;
				if ( !info ) {
					continue;
				}

				sdDeployMask::extents_t localExtents;
				localExtents.minx = i;
				localExtents.maxx = i;
				localExtents.miny = j;
				localExtents.maxy = j;

				idBounds bounds;
				mask->GetBounds( localExtents, bounds, heightMap );

				idVec3 top = bounds.GetCenter();
				top[ 2 ] = bounds.GetMaxs()[ 2 ];				

				deployResult_t localResult = mask->IsValid( localExtents );

				idVec4 localColor;
				switch ( localResult ) {
					case DR_CLEAR:
						localColor = colorGreen;
						break;
					default:
					case DR_FAILED:
						localColor = colorDkRed;
						break;
				}

				if ( !( ( i >= extents.minx ) && ( i <= extents.maxx ) && ( j >= extents.miny ) && ( j <= extents.maxy ) ) ) {
					localColor.x *= 0.3f;
					localColor.y *= 0.3f;
					localColor.z *= 0.3f;
				}

				winding.Clear();
				winding += idVec5( idVec3( bounds.GetMins()[ 0 ], bounds.GetMins()[ 1 ], bounds.GetMins()[ 2 ] - depth ), idVec2( 0.0f, 0.0f ) );
				winding += idVec5( idVec3( bounds.GetMins()[ 0 ], bounds.GetMaxs()[ 1 ], bounds.GetMins()[ 2 ] - depth ), idVec2( 0.0f, 1.0f ) );
				winding += idVec5( idVec3( bounds.GetMaxs()[ 0 ], bounds.GetMaxs()[ 1 ], bounds.GetMins()[ 2 ] - depth ), idVec2( 1.0f, 1.0f ) );
				winding += idVec5( idVec3( bounds.GetMaxs()[ 0 ], bounds.GetMins()[ 1 ], bounds.GetMins()[ 2 ] - depth ), idVec2( 1.0f, 0.0f ) );

				gameRenderWorld->AddToProjectedDecal( winding, top + idVec3( 0, 0, 64.f + depth ), true, localColor, info->renderEntity.hModel, spawnID, megaTextureMaterials.Begin(), megaTextureMaterials.Num() );
			}
		}
	}
}
Пример #11
0
//	---------------------------------------------------------------------------
//	---------------------------------------------------------------------------
//  ---------------------------------------------------------------------------
CUI_RESULTTYPE CUIPolyString_Impl::ApplyFont(
	CUIFont* pFont, 
	int16 index, 
	int16 num,
	bool  bProcessRemainder)
{
	uint8		cidx;
	uint8		*pFontMap;

	int32		i, len, storedWidth; 
	int32		w,h;
	int32		delta;

	uint32		texturew, textureh;
	uint32		fontFlags;

	bool 		draw,drawblank;

	float		pstrx, pstry;
  	float		cx, cy;
	float		spacing, em, bold;

	const char* str;
	
	HTEXTURE	pFontTex;

	LT_POLYGT4* pArray;

	// sanity checks
	if (!pDrawPrimInternal) return CUIR_ILT_DRAWPRIM_ERROR;
	if (!pFont) return CUIR_NO_FONT;

	if (pFont->IsProportional() && !pFont->GetFontTable())
		return CUIR_INVALID_FONT;

	pFontTex		= pFont->GetTexture();
	storedWidth		= m_CharScreenWidth;//pFont->GetCharScreenWidth();
	w				= storedWidth;					// padding
  	h				= m_CharScreenHeight;//pFont->GetCharScreenHeight(); // padding
	pFontMap		= pFont->GetFontMap();
  	spacing			= pFont->GetDefSpacingH();

	pTexInterface->GetTextureDims(pFontTex, texturew, textureh);
  
	// get some coords
	this->GetPosition(&cx, &cy);
	pstrx = cx;
	pstry = cy;
	
	// set flag attrs.
	fontFlags = pFont->GetAttributes();
	em   = 0;
	bold = 0;
	if (fontFlags & CUI_FONT_ITALIC) em    =	pFont->GetDefSlant();
	if (fontFlags & CUI_FONT_BOLD )  bold  =	pFont->GetDefBold();
	
	// are we applying to all of the string or only part?
  	len = m_Length;
	if (num == 0) num = (uint16)len;
	num = (index + num > len) ? (len) : (index+num);
	
	str      = m_pChars + index;
	pArray	 = m_pPolys;	

	// place this character next to the previous one
	if (index > 0) cx = (int16)(pArray[index-1].verts[1].x + spacing);		
	
	// the main polygon texturing loop 
  	for (i=index; i<num; i++) {

		draw		= true;
		drawblank	= false;

		// apply the font map(if any)
		//if (pFontMap) cidx = pFontMap[*str];
		//else		  cidx = (*str);
		cidx = (*str);

		// handle chars that shouldn't be subtracted (newlines, tabs, etc.)
		switch (cidx) {
			
			case 10:
				draw = false;
				break;

			case 32:
				drawblank = true;
				break;

			default:

				if (!pFontMap) {
					// if there's no fontmap, turn ascii into indices
					//cidx = (*str);
					cidx -= 33;
					if (cidx > 93) draw = false;
				}	
				else {
					cidx = pFontMap[cidx];
				}
		}
		
		if (!draw || drawblank) {			
			// draw a blank, transparent poly for a space
			w = storedWidth;
			this->MakeBlankPoly(&pArray[i]);
		}
		
		if (draw && !drawblank) {
			// set the UV coords
			MapCharacter(pFont, cidx, &pArray[i], &w, texturew, textureh);
		}
		else {
			if (!drawblank) w = 0 - (int16)(bold + spacing);
		}
    	
		// apply the new XYZ coords
		SetPolyXYZ(&pArray[i], cx, cy, w, h, em, bold);

		// increment the x position for the next char.
		cx = cx + int16(w + bold + spacing);			

		// increment our string pointer
    	str++;
  	}  	
	
	// move the polys we did not process so there won't be gaps or overlaps
	// in the string

	if (bProcessRemainder) {	
		if (num<len) {			
			delta = (int32) (pArray[num-1].verts[1].x - pArray[num].verts[0].x);
			
			for (i=num; i<len; i++) {
				pArray[i].verts[0].x += delta;
				pArray[i].verts[1].x += delta;
				pArray[i].verts[2].x += delta;
				pArray[i].verts[3].x += delta;
			}
		}
	}

	// get the extents of the new polystring
	GetExtents(&m_Rect);

	return CUIR_OK;
}