Exemplo n.º 1
0
void TSRODERigidBody::AddWorldSphereCollision( TSRPhysicsWorld* _pWorldInterface, const TSRVector3& _vCenter, float _fRadius, float _fDensity )
{
    TSRODEPhysicsWorld* _pWorld = ( TSRODEPhysicsWorld* ) _pWorldInterface;
    TSRMatrix4 geomWorldMatrix = TSRMatrix4::Identity;
    geomWorldMatrix.GetLoc() = _vCenter;
    TSRMatrix4 bodyWorldMatrix;
    const float* pBodyPosition = dBodyGetPosition( m_BodyID );
    const float* pBodyRotation = dBodyGetRotation( m_BodyID );
    ODEToMatrix4( bodyWorldMatrix, pBodyPosition, pBodyRotation );
    TSRMatrix4 invBodyTransform;
    Matrix4Inverse( bodyWorldMatrix, invBodyTransform );
    TSRMatrix4 bodyToGeomMatrix;
    bodyToGeomMatrix = geomWorldMatrix * invBodyTransform;
    AddSphereGeometry( _pWorld, bodyToGeomMatrix, _fRadius, _fDensity );

}
Exemplo n.º 2
0
void TSRODERigidBody::AddWorldOBBCollision( TSRPhysicsWorld* _pWorldInterface, const TSRMatrix4& _worldTransform, const TSRVector3& _vObbMin, const TSRVector3& _vObbMax, float _fDensity )
{
	TSRODEPhysicsWorld* _pWorld = ( TSRODEPhysicsWorld* ) _pWorldInterface;
    TSRMatrix4 geomWorldMatrix = _worldTransform;
    TSRVector3 obbExtents;
    WorldOBBMinMaxToWorldOBBExtents( _worldTransform, _vObbMin, _vObbMax, geomWorldMatrix, obbExtents );
    TSRMatrix4 bodyWorldMatrix;
    const float* pBodyPosition = dBodyGetPosition( m_BodyID );
    const float* pBodyRotation = dBodyGetRotation( m_BodyID );
    ODEToMatrix4( bodyWorldMatrix, pBodyPosition, pBodyRotation );
    TSRMatrix4 invBodyTransform;
    Matrix4Inverse( bodyWorldMatrix, invBodyTransform );
    TSRMatrix4 bodyToGeomMatrix;
    bodyToGeomMatrix = geomWorldMatrix * invBodyTransform;
    AddBoxGeometry( _pWorld, bodyToGeomMatrix, obbExtents, _fDensity );

}
Exemplo n.º 3
0
void TSRODERigidBody::AddWorldCylinderCollision( TSRPhysicsWorld* _pWorldInterface, const TSRMatrix4& _worldTransform, const TSRVector3& _vObbMin, const TSRVector3& _vObbMax, float _fDensity, float _fRadius, float _fLength )
{
	TSRODEPhysicsWorld* _pWorld = ( TSRODEPhysicsWorld* ) _pWorldInterface;
    TSRMatrix4 geomWorldMatrix=_worldTransform;
    TSRVector3 obbExtents;
    //float rd = ( _vObbMax.y - _vObbMin.y ) * 0.5f * _worldTransform.GetLocalY().Mag();
    WorldOBBMinMaxToWorldOBBExtents( _worldTransform, _vObbMin, _vObbMax, geomWorldMatrix, obbExtents );
    TSRMatrix4 bodyWorldMatrix;
    const float* pBodyPosition = dBodyGetPosition( m_BodyID );
    const float* pBodyRotation = dBodyGetRotation( m_BodyID );
    ODEToMatrix4( bodyWorldMatrix, pBodyPosition, pBodyRotation );
    TSRMatrix4 invBodyTransform;
    Matrix4Inverse( bodyWorldMatrix, invBodyTransform );
    TSRMatrix4 bodyToGeomMatrix;
    bodyToGeomMatrix = geomWorldMatrix * invBodyTransform;
    bodyToGeomMatrix.Rotate( 0.0f, PI * 0.5f, 0.0f );
    AddCylinderGeometry( _pWorld, bodyToGeomMatrix, _fRadius, _fLength, _fDensity );
    //AddBoxGeometry(bodyToGeomMatrix,obbExtents,density);

}
Exemplo n.º 4
0
/**
 ****************************************************************************************************
	\fn			void UnitTest( void )
	\brief		The unit test of Matrix class
	\param		NONE
	\return		NONE
 ****************************************************************************************************
*/
void GameEngine::Math::Matrix::UnitTest( void )
{
	FUNCTION_START;

	Matrix matrix2x2( 2, 2 );

	// Check creation
	for( UINT8 i = 0; i < 2; ++i )
	{
		for( UINT8 j = 0; j < 2; ++j )
			assert( matrix2x2(i, j) == 0 );
	}

	// Check matrix identity
	matrix2x2(0, 0) = 1;
	matrix2x2(0, 1) = 2;
	matrix2x2(1, 0) = 3;
	matrix2x2(1, 1) = 4;
	Matrix identityMatrix( 2, 2 );
	identityMatrix(0, 0) = 1;
	identityMatrix(1, 1) = 1;
	Matrix m( 2, 2 );
	m = matrix2x2.Identity();
	assert( matrix2x2.Identity() == identityMatrix );

	// Check matrix transpose
	Matrix matrix2x3( 2, 3 );
	matrix2x3( 0, 0 ) = 1;
	matrix2x3( 0, 1 ) = 2;
	matrix2x3( 0, 2 ) = 3;
	matrix2x3( 1, 0 ) = 4;
	matrix2x3( 1, 1 ) = 5;
	matrix2x3( 1, 2 ) = 6;
	matrix2x3.Transpose();
	Matrix matrix3x2( 3, 2 );
	matrix3x2( 0, 0 ) = 1;
	matrix3x2( 0, 1 ) = 4;
	matrix3x2( 1, 0 ) = 2;
	matrix3x2( 1, 1 ) = 5;
	matrix3x2( 2, 0 ) = 3;
	matrix3x2( 2, 1 ) = 6;
	assert( matrix2x3 == matrix3x2 );

	// Check matrix 3x3 inverse
	Matrix matrix3x3( 3, 3 );
	matrix3x3( 0, 0 ) = 2;
	matrix3x3( 0, 1 ) = -1;
	matrix3x3( 0, 2 ) = 3;
	matrix3x3( 1, 0 ) = 1;
	matrix3x3( 1, 1 ) = 6;
	matrix3x3( 1, 2 ) = -4;
	matrix3x3( 2, 0 ) = 5;
	matrix3x3( 2, 1 ) = 0;
	matrix3x3( 2, 2 ) = 8;
	Matrix matrix3x3Inverse( 3, 3 );
	Matrix3Inverse( matrix3x3, matrix3x3Inverse );
	assert( (matrix3x3 * matrix3x3Inverse) == matrix3x3.Identity() );

	// Check matrix 4x4 inverse
	Matrix matrix4x4( 4, 4 );
	matrix4x4( 0, 0 ) = 2;
	matrix4x4( 0, 1 ) = 3;
	matrix4x4( 0, 2 ) = 4;
	matrix4x4( 0, 3 ) = 5;
	matrix4x4( 1, 0 ) = 5;
	matrix4x4( 1, 1 ) = 7;
	matrix4x4( 1, 2 ) = 9;
	matrix4x4( 1, 3 ) = 9;
	matrix4x4( 2, 0 ) = 5;
	matrix4x4( 2, 1 ) = 8;
	matrix4x4( 2, 2 ) = 7;
	matrix4x4( 2, 3 ) = 4;
	matrix4x4( 3, 0 ) = 4;
	matrix4x4( 3, 1 ) = 3;
	matrix4x4( 3, 2 ) = 3;
	matrix4x4( 3, 3 ) = 2;
	Matrix matrix4x4Inverse( 4, 4 );
	Matrix4Inverse( matrix4x4, matrix4x4Inverse );
	Matrix matrix4x4Result( 4, 4 );
	matrix4x4Result = matrix4x4 * matrix4x4Inverse;
	assert( (matrix4x4 * matrix4x4Inverse) == matrix4x4.Identity() );

	FUNCTION_FINISH;
}
Exemplo n.º 5
0
//#ifndef OPENGL_RENDERER
/// do the lighting using the deferred shading system, uses GBuffer and lighting in screen space is done is a post step
void TSRLightingManager::RenderAllLightsPassesDeferred( TSRGBufferPass* _pGBuffer, TSRSceneWorldInterface* _pWorld )
{
    /// set the gbuffer component to start doing the lighting
    TSRGlobalConstants.m_DiffuseTexture.Set( _pGBuffer->m_pColorTarget );
    TSRGlobalConstants.m_SpecularTexture.Set( _pGBuffer->m_pSpecularTarget );
    TSRGlobalConstants.m_NormalTexture.Set( _pGBuffer->m_pNormalTarget );
    TSRGlobalConstants.m_DepthTexture.Set( _pGBuffer->m_pDepthTarget );

    /// set the inverse view projection matrix
    TSRMatrix4 viewProj;

    const TSRMatrix4& view = _pWorld->GetMainCamera()->GetViewMatrix();
    const TSRMatrix4& proj = _pWorld->GetMainCamera()->GetProjectionMatrix();

    TSRMaterial whiteMaterial;
    TSRGlobalConstants.SetMaterial( whiteMaterial );

    _pWorld->GetMainCamera()->ComputeViewProjMatrix( viewProj );

    TSRMatrix4 invViewProj;
    Matrix4Inverse( viewProj, invViewProj );
    _pGBuffer->m_InverseViewProjection.Set( invViewProj );

    TSRMatrix4 invView;
    TSRMatrix4 invProj;

    Matrix4Inverse( view, invView );
    _pGBuffer->m_InverseView.Set( invView );
    _pGBuffer->m_CameraView.Set( view );

    Matrix4Inverse( proj, invProj );
    _pGBuffer->m_InverseProjection.Set( invProj );

    Graphics()->SetDepthStencilState( Graphics()->m_DepthTestDisabledWriteDisabled );
    
    if ( m_SceneLightsContext.GetDirectionalLightsCount() > 0 )
    {
        TSRGlobalConstants.SetLight( 0, *m_SceneLightsContext.m_DirectionalLights[ 0 ] );
        TSRImmediateDraw::RenderFullScreenQuad( ( m_EffectsDisabledMask & TWISTER_SHADER_FLAG_SHADOWMAP ) ? m_pMainLightShader : m_pMainLightAndShadowShader );
    }

    Graphics()->SetBlendState( Graphics()->m_BlendAdditiveColor );
    /// additional directional lights..
    for ( unsigned int i = 1; i < m_SceneLightsContext.GetDirectionalLightsCount(); i++ )
    {
        TSRGlobalConstants.SetLight( 0, *m_SceneLightsContext.m_DirectionalLights[ i ] );
        TSRImmediateDraw::RenderFullScreenQuad( m_pDirectionalLightShader );
    }
    
    TSRVector3& vCameraSide =  _pWorld->GetMainCamera()->m_Side;
    TSRVector3& vCameraUp =  _pWorld->GetMainCamera()->m_Up;
    TSRVector3& vCameraFwd =  _pWorld->GetMainCamera()->m_Fwd;

    /// point lights
    TSRVector3 vCameraPosition = _pWorld->GetMainCamera()->m_Loc;
    m_pPointLightShader->Activate();
    for ( unsigned int i = 0; i < m_SceneLightsContext.GetPointLightsCount(); i++ )
    {
        PointLightData& currLight = *m_SceneLightsContext.m_PointLights[ i ];
        TSRGlobalConstants.SetLight( 0, currLight );
        TSRVector3& vLightPosition = ( TSRVector3& ) currLight.m_Position;
        float fRadius = currLight.m_Radius.x;
        TSRGlobalConstants.PushMatrix();
        TSRGlobalConstants.Translate( vLightPosition.x, vLightPosition.y, vLightPosition.z );
        //TSRImmediateDraw::BillBoardCircle( vCameraSide, vCameraUp, vCameraFwd, fRadius * 1.1f );
        TSRVector3 vCameraToLightDirection =  vLightPosition - _pWorld->GetMainCamera()->m_Loc;
		vCameraToLightDirection.Normalize();

		if ( vCameraToLightDirection.Dot( vCameraFwd ) < 0.0f )
        {
            Graphics()->SetRasterizerState( Graphics()->m_FillDoubleSidedState );
            TSRDebugDraw::RenderSphere( fRadius, m_pPointLightShader );
            Graphics()->SetRasterizerState( Graphics()->m_FillSolidState );
        }
        else
        {
            TSRImmediateDraw::BillBoardCircle( vCameraSide, vCameraUp, vCameraFwd, fRadius * 1.1f );
        }

        TSRGlobalConstants.PopMatrix();

    }

    

    /// spot lights..
    for ( unsigned int i = 0; i < m_SceneLightsContext.GetSpotLightsCount(); i++ )
    {
        SpotLightData& currSpot = *m_SceneLightsContext.m_SpotLights[ i ];
        TSRGlobalConstants.SetLight( 0, currSpot );
        /*Vector4& Position = currSpot.m_Position;
        TSRGlobalConstants.PushMatrix();
        TSRGlobalConstants.Translate( Position.x, Position.y, Position.z );
        Vector3 direction = currSpot.m_Direction;
        float angle = acosf( currSpot.m_SpotAngles.y );
        float length = 1000.0f * cosf( angle );
        float radius = 1000.0f * sinf( angle );
        m_pSpotLightShader->Activate();
       // TSRDebugDraw::RenderCone( length, radius, direction );
        TSRGlobalConstants.PopMatrix(); //*/
        TSRImmediateDraw::RenderFullScreenQuad( m_pSpotLightShader );
    }
    //*/
   // Graphics()->SetDepthStencilState( Graphics()->m_DefaultDepthStencilState );

    /// this sets the light, so that the blended stuff coming later would have the first lights context used
    SetShaderConstants( m_SceneLightsContext );
    
}