Ejemplo n.º 1
0
void RSObject::CreateShadowTexture()
{
#define EFFECTIVE_SIZE	0.99f
#define SHADOW_COLOR	0xa0a0a0

	rtexture rt;
	rt.New(256,256,RTEXTUREFORMAT_24);
	rt.Fill(0xffffff);

	rmatrix44 tm;

	int i,j,k;
	float f_max=m_BoundingSphereRadiusXY;

	tm=ScaleMatrix44(128.0f*EFFECTIVE_SIZE/f_max)
		*ViewMatrix44(rvector(0,0,0),rvector(1,2,-1),rvector(0,1,0))
		*TranslateMatrix44(128,128,0);

	for(i=0;i<nMesh;i++)
	{
		CMesh *mesh=meshes+i;
		for(j=0;j<mesh->nFaces;j++)
		{
			CFaces *faces=mesh->faceshead+j;
			for(k=0;k<faces->ni;k+=3)
			{
				rvector a=TransformVector(*(rvector*)(&faces->tnlvertices[faces->indicies[k]].x),tm);
				rvector b=TransformVector(*(rvector*)(&faces->tnlvertices[faces->indicies[k+1]].x),tm);
				rvector c=TransformVector(*(rvector*)(&faces->tnlvertices[faces->indicies[k+2]].x),tm);
#define CHECK(x) _ASSERT((x>=0)&&(x<256))

				rt.FillTriangle(a.x,a.y,b.x,b.y,c.x,c.y,SHADOW_COLOR);
				CHECK(a.x);CHECK(a.y);
				CHECK(b.x);CHECK(b.y);
				CHECK(c.x);CHECK(c.y);
			}
		}
	}

	rtexture newrt1;newrt1.CreateAsHalf(&rt);		// 128
	rtexture newrt2;newrt2.CreateAsHalf(&newrt1);	// 64

	newrt2.FillBoundary(0xffffff);
	newrt2.SaveAsBMP("testtest.bmp");

	m_hShadowTexture=RSCreateTexture(
		newrt2.GetWidth(),newrt2.GetHeight(),
		(char*)newrt2.GetData(),NULL,true,"Object:ShadowTexture");
}
Ejemplo n.º 2
0
	const matrix44 GetTransform(const AABB &aabb){
		return TranslateMatrix44( GetCenter(aabb) )*ScaleMatrix44( GetDim(aabb) );
	}