Beispiel #1
0
void C4FoWAmbient::GetFragTransform(const FLOAT_RECT& vpRect, const C4Rect& clipRect, const C4Rect& outRect, float ambientTransform[6]) const
{
	C4FragTransform trans;
	// Invert Y coordinate
	trans.Scale(1, -1);
	trans.Translate(0, outRect.Hgt);
	// Clip offset
	trans.Translate(-clipRect.x, -clipRect.y);
	// Clip normalization (0,0 -> 1,1)
	trans.Scale(1.0f / clipRect.Wdt, 1.0f / clipRect.Hgt);
	// Viewport normalization
	trans.Scale(vpRect.right - vpRect.left, vpRect.bottom - vpRect.top);
	// Viewport offset
	trans.Translate(vpRect.left, vpRect.top);
	// Landscape normalization
	trans.Scale(1.0f / LandscapeX, 1.0f / LandscapeY);

	// Extract matrix
	trans.Get2x3(ambientTransform);
}
void C4FoWRegion::GetFragTransform(const C4Rect& clipRect, const C4Rect& outRect, float lightTransform[6]) const
{
	const C4Rect& lightRect = getRegion();
	const FLOAT_RECT& vpRect = ViewportRegion;

	C4FragTransform trans;
	// Clip offset
	assert(outRect.Hgt >= clipRect.y + clipRect.Hgt);
	trans.Translate(-clipRect.x, -(outRect.Hgt - clipRect.y - clipRect.Hgt));
	// Clip normalization (0,0 -> 1,1)
	trans.Scale(1.0f / clipRect.Wdt, 1.0f / clipRect.Hgt);
	// Viewport/Landscape normalization
	trans.Scale(vpRect.right - vpRect.left, vpRect.bottom - vpRect.top);
	// Offset between viewport and light texture
	trans.Translate(vpRect.left - lightRect.x, vpRect.top - lightRect.y);
	// Light surface normalization
	trans.Scale(1.0f / pSurface->Wdt, 1.0f / pSurface->Hgt);
	// Light surface Y offset
	trans.Translate(0.0f, 1.0f - (float)(lightRect.Hgt) / (float)pSurface->Hgt);

	// Extract matrix
	trans.Get2x3(lightTransform);
}