コード例 #1
0
ファイル: graphics_gl2.cpp プロジェクト: Alexander-Eck/vdrift
static bool Cull(const Frustum & f, const Drawable & d)
{
	const float radius = d.GetRadius();
	Vec3 center = d.GetObjectCenter();
	d.GetTransform().TransformVectorOut(center[0], center[1], center[2]);
	for (int i = 0; i < 6; i++)
	{
		const float rd =
			f.frustum[i][0] * center[0] +
			f.frustum[i][1] * center[1] +
			f.frustum[i][2] * center[2] +
			f.frustum[i][3];
		if (rd <= -radius)
			return true;
	}
	return false;
}
コード例 #2
0
bool RenderInputScene::FrustumCull(const Drawable & d) const
{
	const float radius = d.GetRadius();
	if (radius > 0.0)
	{
		// get object center in world space
		Vec3 objpos = d.GetObjectCenter();
		d.GetTransform().TransformVectorOut(objpos[0], objpos[1], objpos[2]);

		// get distance to camera
		const float dx = objpos[0] - cam_position[0];
		const float dy = objpos[1] - cam_position[1];
		const float dz = objpos[2] - cam_position[2];
		const float rc = dx * dx + dy * dy + dz * dz;

		// test against camera position (assuming near plane is zero)
		if (rc < radius * radius)
			return false;

		// test against camera far plane
		const float temp_lod_far = lod_far + radius;
		if (rc > temp_lod_far * temp_lod_far)
			return true;

		// test against all frustum planes
		for (int i = 0; i < 6; i++)
		{
			const float rd = frustum.frustum[i][0] * objpos[0] +
				frustum.frustum[i][1] * objpos[1] +
				frustum.frustum[i][2] * objpos[2] +
				frustum.frustum[i][3];
			if (rd <= -radius)
				return true;
		}
	}
	return false;
}