MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/PhysX / BuildFrustum

Method BuildFrustum

physx/samples/samplebase/SampleCamera.cpp:183–364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183void Camera::BuildFrustum()
184{
185 if(mFreezeFrustum)
186 return;
187
188 // PT: a better way is to extract the planes from the view-proj matrix but it has some subtle differences with D3D/GL.
189 // Building the frustum explicitly is just easier here (although not as efficient)
190
191 const PxReal ratio = mViewport.computeRatio();
192
193 const PxReal Tan = tanf(degtorad(0.5f * mFOV)) / ratio;
194
195 const PxReal nearCoeff = mNearPlane * Tan;
196 const PxReal farCoeff = mFarPlane * Tan;
197
198 const PxReal rightCoeff = ratio;
199 const PxReal upCoeff = 1.0f;
200
201 const PxTransform& view = getViewMatrix();
202 PxMat33 mat33(view.q);
203 PxVec3 right = mat33[0];
204 PxVec3 up = mat33[1];
205 PxVec3 forward =-mat33[2];
206
207 mFrustum[0] = mPos + forward*mNearPlane - right*nearCoeff*rightCoeff + up*nearCoeff*upCoeff;
208 mFrustum[1] = mPos + forward*mNearPlane - right*nearCoeff*rightCoeff - up*nearCoeff*upCoeff;
209 mFrustum[2] = mPos + forward*mNearPlane + right*nearCoeff*rightCoeff - up*nearCoeff*upCoeff;
210 mFrustum[3] = mPos + forward*mNearPlane + right*nearCoeff*rightCoeff + up*nearCoeff*upCoeff;
211
212 mFrustum[4] = mPos + forward*mFarPlane - right*farCoeff*rightCoeff + up*farCoeff*upCoeff;
213 mFrustum[5] = mPos + forward*mFarPlane - right*farCoeff*rightCoeff - up*farCoeff*upCoeff;
214 mFrustum[6] = mPos + forward*mFarPlane + right*farCoeff*rightCoeff - up*farCoeff*upCoeff;
215 mFrustum[7] = mPos + forward*mFarPlane + right*farCoeff*rightCoeff + up*farCoeff*upCoeff;
216
217 if(1)
218 {
219 mPlanes[0] = PxPlane(mFrustum[4], mFrustum[1], mFrustum[5]);
220 mPlanes[1] = PxPlane(mFrustum[6], mFrustum[3], mFrustum[7]);
221 mPlanes[2] = PxPlane(mFrustum[4], mFrustum[7], mFrustum[3]);
222 mPlanes[3] = PxPlane(mFrustum[1], mFrustum[6], mFrustum[5]);
223 mPlanes[4] = PxPlane(mFrustum[0], mFrustum[2], mFrustum[1]);
224 mPlanes[5] = PxPlane(mFrustum[5], mFrustum[7], mFrustum[4]);
225
226 {
227 for(int i=0;i<6;i++)
228 {
229 mPlanes[i].n = -mPlanes[i].n;
230 mPlanes[i].d = -mPlanes[i].d;
231 }
232 }
233 }
234
235 if(0)
236 {
237 //
238 const PxVec3 axisX(1.0f, 0.0f, 0.0f);
239 const PxVec3 axisY(0.0f, 1.0f, 0.0f);
240 const PxVec3 axisZ(0.0f, 0.0f, 1.0f);

Callers 1

onRenderMethod · 0.80

Calls 9

degtoradFunction · 0.85
convertProjMatrixFunction · 0.85
convertViewMatrixFunction · 0.85
computeRatioMethod · 0.80
PxPlaneClass · 0.50
PxQuatClass · 0.50
rotateMethod · 0.45
dotMethod · 0.45
normalizeMethod · 0.45

Tested by

no test coverage detected