RCBindVertexShader* DebugGeometry::onPreRender( Renderer& renderer ) { if ( !m_vertexShader ) { return NULL; } Camera& camera = renderer.getActiveCamera(); RCBindVertexShader* comm = new ( renderer() ) RCBindVertexShader( *m_vertexShader, renderer ); { const Matrix& worldMtx = getGlobalMtx(); Matrix worldViewMtx; worldViewMtx.setMul( worldMtx, camera.getViewMtx() ); Matrix worldViewProjMtx; worldViewProjMtx.setMul( worldViewMtx, camera.getProjectionMtx() ); comm->setMtx( "g_mWorldView", worldMtx ); comm->setMtx( "g_mWorldViewProj", worldViewProjMtx ); } return comm; }
void Camera::calculateFrustumAABB( AxisAlignedBox& outAABB ) const { // calculate a bounding box around the frustum in camera's local space AxisAlignedBox localSpaceAABB; { switch( m_projectionType ) { case PT_PERSPECTIVE: { float y = tan( m_fov * 0.5f ) * m_farZPlane; float x = y * m_aspectRatio; localSpaceAABB.min.set( -x, -y, m_nearZPlane ); localSpaceAABB.max.set( x, y, m_farZPlane ); break; } case PT_ORTHO: { float x = m_nearPlaneWidth * 0.5f; float y = m_nearPlaneHeight * 0.5f; localSpaceAABB.min.set( -x, -y, m_nearZPlane ); localSpaceAABB.max.set( x, y, m_farZPlane ); break; } } } // transform the box to global space const Matrix& globalMtx = getGlobalMtx(); localSpaceAABB.transform( globalMtx, outAABB ); }
void Camera::updateViewMtx() { PROFILED(); const Matrix& globalMtx = getGlobalMtx(); MatrixUtils::calculateViewMtx( globalMtx, m_mtxView ); }
void OALSound3D::update(SoundListener& listener) { if (m_oalSource == 0) {return;} D3DXMATRIX mtx = getGlobalMtx(); ALfloat sourceOri[] = {mtx._31, mtx._32, mtx._33, mtx._21, mtx._22, mtx._23}; m_soundSystem.alSource3f(m_oalSource, AL_POSITION, mtx._41, mtx._42, mtx._42); m_soundSystem.alSourcefv(m_oalSource, AL_ORIENTATION, sourceOri); }
void Camera::createRay( float viewportX, float viewportY, Ray& outRay ) { // now I treat the mouse position as if it was located on the near clipping plane Vector mouseOnNearPlane; mouseOnNearPlane.set( viewportX, viewportY, -m_nearZPlane ); // these 3d coords are in the viewport space - now I need to transform them into world space const Matrix& viewMtx = getViewMtx(); const Matrix& projMtx = getProjectionMtx(); Matrix combinedMtx; combinedMtx.setMul( viewMtx, projMtx ); combinedMtx.invert(); // once I have the backwards transformation, I use it on the 3D mouse coord Vector projMouseOnNearPlane; combinedMtx.transform( mouseOnNearPlane, projMouseOnNearPlane ); // now I just need to find the vector between this point and the camera world space position and normalize it, and I should get my direction: const Matrix& globalMtx = getGlobalMtx(); outRay.origin = globalMtx.position(); outRay.direction.setSub( projMouseOnNearPlane, outRay.origin ); outRay.direction.normalize(); }
void DRSpotLight::updateDebugData( float timeElapsed ) { m_geomComp->setExtraTransform( getGlobalMtx() ); }