Beispiel #1
0
void ScissorsSetUp()
{
	// Set up scissors
	float3 tolight = lightposn-camera.position;
	float len = magnitude(tolight);
	//if(len < lightradius * 2.0f) 
	if(len < lightradius * 1.1f) 
	{
		ScissorsRestore();
		return;
	}
	float3 clocal = rotate(Inverse(camera.orientation), tolight) * (len-lightradius*lightradius/len);  // in camera space center of 2d circle where lightsphere is tangent to rays from cameraposition
	float3 c = camera.position + tolight * (1-lightradius*lightradius/(len*len));  // in world space center of 2d circle where lightsphere is tangent to rays from cameraposition
	float  r = lightradius/len*sqrtf(len*len-lightradius*lightradius); // radius of 2d circle with normal 'tolight', centered at c and tangent to lightsphere 
	float3 xvec = safenormalize(cross(tolight,camera.orientation.ydir())); // if working in camera space would have used float3(0,1.0f,0) 
	float3 yvec = safenormalize(cross(camera.orientation.xdir(),tolight)); // float3(1.0f,0,0) in cam
	if(scissordebug) r*=0.5; // this should chop area extents by 1/2
	float3 cr = c+xvec*r;
	float3 cl = c-xvec*r;
	float3 ct = c+yvec*r;
	float3 cb = c-yvec*r;

	clippedcount++;
	RECT rect;
	float3 cz = camera.orientation.zdir();
	scissor_left   = rect.left  = (dot(cl-camera.position,cz)>=0)? 0     : clamp((int) camera.MapToScreen(cl).x  ,0,Width);
	scissor_right  = rect.right = (dot(cr-camera.position,cz)>=0)? Width : clamp((int) camera.MapToScreen(cr).x  ,rect.left,Width);
	scissor_top    = rect.top   = (dot(ct-camera.position,cz)>=0)? 0     : clamp(Height-(int) camera.MapToScreen(ct).y  ,0,Height);
	scissor_bottom = rect.bottom= (dot(cb-camera.position,cz)>=0)? Height: clamp(Height-(int) camera.MapToScreen(cb).y  ,rect.top,Height);
	if(scissortest)g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE ,TRUE);
	g_pd3dDevice->SetScissorRect(&rect);
}
Beispiel #2
0
Face FaceNewTri(const float3 &v0,const float3 &v1,const float3 &v2)
{
	Face f;
    f.vertex = {v0,v1,v2};
	f.xyz() = safenormalize(cross(v1 - v0, v2 - v1));
	f.w = -dot(f.xyz(), (v0 + v1 + v2) / 3.0f);
	f.gu = safenormalize(v1-v0);
	f.gv = safenormalize(cross(f.xyz(), f.gu));
	return f;
}