Example #1
0
	void cFrustum::UpdateSphere()
	{
		// calculate the radius of the frustum sphere
		float fViewLen = mfFarPlane - mfNearPlane;

		float fHeight = fViewLen * tan(mfFOV * 0.5f);
		float fWidth = fHeight * mfAspect;

		// halfway point between near/far planes starting at the origin and extending along the z axis
		cVector3f P(0.0f, 0.0f, mfNearPlane + fViewLen * 0.5f);

		// the calculate far corner of the frustum
		cVector3f Q(fWidth, fHeight, fViewLen);

		// the vector between P and Q
		cVector3f vDiff = P - Q;

		// the radius becomes the length of this vector
		float fRadius = vDiff.Length();

		// get the look vector of the camera from the view matrix
		cVector3f vLookVector = m_mtxModelView.GetForward() * -1;
		
		// calculate the center of the sphere
		cVector3f vCenter = (mvOrigin) + (vLookVector * (fViewLen * 0.5f + mfNearPlane));
		
		mBoundingSphere = cSpheref(vCenter,fRadius);
	}
Example #2
0
	void cFrustum::UpdateSphere()
	{
		float fViewLen = m_fFarPlane - m_fNearPlane;

		float fHeight = fViewLen * tan(m_fFOV * 0.5f);
		float fWidth = fHeight * m_fAspect;

		cVector3f P(0.0f, 0.0f, m_fNearPlane + fViewLen * 0.5f);

		cVector3f Q(fWidth, fHeight, fViewLen);

		cVector3f vDiff = P - Q;

		float fRadius = vDiff.Length();

		cVector3f vLookVector = m_mtxModelView.GetForward() * -1;

		cVector3f vCenter = (m_vOrigin) + (vLookVector * (fViewLen * 0.5f + m_fNearPlane));

		m_BoundingSphere = cSpheref(vCenter, fRadius);
	}