コード例 #1
0
ファイル: Frustum.c プロジェクト: RealityFactory/Genesis3D
//================================================================================
//	Frustum_TransformToWorldSpace
//================================================================================
void Frustum_TransformToWorldSpace(const Frustum_Info *In, const geCamera *Camera, Frustum_Info *Out)
{
    int32		i;
	GFX_Plane	*pPlane1, *pPlane2;

	assert(In != Out);

	pPlane1 = (GFX_Plane*)In->Planes;
	pPlane2 = Out->Planes;

	// Rotate all the planes
	for (i=0; i<In->NumPlanes; i++, pPlane1++, pPlane2++)
	{
		pPlane2->Type = pPlane1->Type;
		
		SetWorldspaceClipPlane(pPlane1, Camera, pPlane2);
		pPlane2->Dist = geVec3d_DotProduct(geCamera_GetPov(Camera), &pPlane2->Normal) - CLIP_PLANE_EPSILON;

		if (pPlane1->Dist)		// Add the original dist back in
		{
			geVec3d		Vect;

			geVec3d_Clear(&Vect);
			geVec3d_AddScaled(&Vect, &pPlane1->Normal, pPlane1->Dist, &Vect);

			BackRotateVector(&Vect, &Vect, geCamera_GetCameraSpaceXForm(Camera));

			pPlane2->Dist += geVec3d_DotProduct(&pPlane2->Normal, &Vect);
		}
	}
	Out->NumPlanes = In->NumPlanes;

	// Get BBox info for fast BBox rejection against frustum...
	SetUpFrustumBBox(Out);
}
コード例 #2
0
void
Projector::SetUpFrustum()
{
    double  angle, s, c;
    Vec3    normal;

    angle = XAngle();
    s = sin(angle);
    c = cos(angle);

    // Left clip plane
    normal.x = (float) s;
    normal.y = (float) 0;
    normal.z = (float) c;
    view_planes[0].normal   = normal;
    view_planes[0].distance = CLIP_PLANE_EPSILON;
    SetWorldspaceClipPlane(normal, world_planes[0]);

    // Right clip plane
    normal.x = (float) -s;
    view_planes[1].normal   = normal;
    view_planes[1].distance = CLIP_PLANE_EPSILON;
    SetWorldspaceClipPlane(normal, world_planes[1]);

    angle = YAngle();
    s = sin(angle);
    c = cos(angle);

    // Bottom clip plane
    normal.x = (float) 0;
    normal.y = (float) s;
    normal.z = (float) c;
    view_planes[2].normal   = normal;
    view_planes[2].distance = CLIP_PLANE_EPSILON;
    SetWorldspaceClipPlane(normal, world_planes[2]);

    // Top clip plane
    normal.y = (float) -s;
    view_planes[3].normal   = normal;
    view_planes[3].distance = CLIP_PLANE_EPSILON;
    SetWorldspaceClipPlane(normal, world_planes[3]);
}
コード例 #3
0
ファイル: Frustum.c プロジェクト: RealityFactory/Genesis3D
//================================================================================
//	Frustum_RotateToWorldSpace
//================================================================================
void Frustum_RotateToWorldSpace(Frustum_Info *In, geCamera *Camera, Frustum_Info *Out)
{
    int32		i;
	GFX_Plane	*pPlane1, *pPlane2;

	assert(In != Out);

	pPlane1 = In->Planes;
	pPlane2 = Out->Planes;

	// Rotate all the planes
	for (i=0; i<In->NumPlanes; i++, pPlane1++, pPlane2++)
	{
		pPlane2->Type = pPlane1->Type;
		
		SetWorldspaceClipPlane(pPlane1, Camera, pPlane2);
		pPlane2->Dist = 0.0f;		// We are just rotating, so set dist to 0

		if (pPlane1->Dist)		// Add the original dist back in
		{
			geVec3d		Vect;

			geVec3d_Clear(&Vect);
			geVec3d_AddScaled(&Vect, &pPlane1->Normal, pPlane1->Dist, &Vect);

			BackRotateVector(&Vect, &Vect, geCamera_GetCameraSpaceXForm(Camera));

			pPlane2->Dist += geVec3d_DotProduct(&pPlane2->Normal, &Vect);
		}
	}

	Out->NumPlanes = In->NumPlanes;

	// Get BBox info for fast BBox rejection against frustum...
	SetUpFrustumBBox(Out);
}