Пример #1
0
void Curve::Render( RenderVisitor* render )
{
    HELIUM_ASSERT( render );

    DrawArgs* args = render->GetArgs();
    HELIUM_ASSERT( args );

    Helium::BufferedDrawer* drawInterface = render->GetDrawInterface();
    HELIUM_ASSERT( drawInterface );

    const VertexResource* vertices = m_Vertices;

    uint32_t countCurvePoints    = (uint32_t)m_Points.size();
    uint32_t countControlPoints  = GetNumberControlPoints();

    //
    //  Draw start end end locators
    //

    Helium::Color materialColor = GetMaterialColor( s_Material );

    Simd::Matrix44 globalTransform( GetGlobalTransform().array1d );

    if ( !m_Closed )
    {
        Simd::Matrix44 m;

        if ( countCurvePoints > 0 )
        {
            Simd::Vector3 point( &m_Points[ 0 ].x );
            m.MultiplySet( Simd::Matrix44( Simd::Matrix44::INIT_TRANSLATION, point ), globalTransform );
            m_Locator->Draw( drawInterface, args, materialColor, m );
        }

        if ( countCurvePoints > 1 )
        {
            Simd::Vector3 point( &m_Points[ countCurvePoints - 1 ].x );
            m.MultiplySet( Simd::Matrix44( Simd::Matrix44::INIT_TRANSLATION, point ), globalTransform );
            m_Locator->Draw( drawInterface, args, materialColor, m );

            Simd::Vector3 p1( &m_Points[ countCurvePoints - 2 ].x );
            Simd::Vector3 p2( &m_Points[ countCurvePoints - 1 ].x );
            Simd::Vector3 dir = ( p2 - p1 ).GetNormalized();
            AngleAxis angleAxis = AngleAxis::Rotation(
                OutVector,
                Vector3( dir.GetElement( 0 ), dir.GetElement( 1 ), dir.GetElement( 2 ) ) );
            m.SetRotationTranslation(
                Simd::Quat( Simd::Vector3( &angleAxis.axis.x ), angleAxis.angle ),
                p2 - ( dir * ( m_Cone->m_Length * 0.5f ) ) );
            m *= globalTransform;

            m_Cone->Draw( drawInterface, args, materialColor, m );
        }
    }

    if ( countCurvePoints > 0 ) 
    {
        //
        //  Draw Curve
        //
        uint32_t countCurveLines = m_Closed ? countCurvePoints : countCurvePoints - 1;

        if ( countCurveLines > 0 )
        {
            drawInterface->DrawUntextured(
                Helium::RENDERER_PRIMITIVE_TYPE_LINE_STRIP,
                globalTransform,
                vertices->GetBuffer(),
                NULL,
                vertices->GetBaseIndex() + countControlPoints + 1,
                countCurveLines + 1,
                0,
                countCurveLines,
                materialColor,
                Helium::RenderResourceManager::RASTERIZER_STATE_WIREFRAME_DOUBLE_SIDED );
            args->m_LineCount += countCurveLines;
        }

        //
        //  Draw Curve points 
        //
        drawInterface->DrawPoints(
            globalTransform,
            vertices->GetBuffer(),
            vertices->GetBaseIndex() + countControlPoints + 1,
            countCurvePoints,
            materialColor );
    }


    //
    //  Draw Control points
    //

    if ( countControlPoints > 0 )
    {
        //
        // Draw points hull
        //

        if ( m_Type != CurveType::Linear )
        {
            uint32_t countControlLines = m_Closed ? countControlPoints : countControlPoints - 1;

            if ( countControlLines > 0 )
            {
                drawInterface->DrawUntextured(
                    Helium::RENDERER_PRIMITIVE_TYPE_LINE_STRIP,
                    globalTransform,
                    vertices->GetBuffer(),
                    NULL,
                    vertices->GetBaseIndex(),
                    countControlLines + 1,
                    0,
                    countControlLines,
                    s_HullMaterial,
                    Helium::RenderResourceManager::RASTERIZER_STATE_WIREFRAME_DOUBLE_SIDED );
                args->m_LineCount += countControlLines;
            }
        }


        //
        // Draw all points
        //

        drawInterface->DrawPoints(
            globalTransform,
            vertices->GetBuffer(),
            vertices->GetBaseIndex(),
            countControlPoints,
            Viewport::s_ComponentMaterial );


        //
        //  Overdraw selected points
        //
        {
            Helium::Color textColor( 0xffffffff );

            OS_HierarchyNodeDumbPtr::Iterator childItr = GetChildren().Begin();
            OS_HierarchyNodeDumbPtr::Iterator childEnd = GetChildren().End();
            for ( uint32_t i = 0; childItr != childEnd; ++childItr )
            {
                CurveControlPoint* point = Reflect::SafeCast< CurveControlPoint >( *childItr );
                if ( point )
                {
                    if ( point->IsSelected() )
                    {
                        drawInterface->DrawPoints(
                            globalTransform,
                            vertices->GetBuffer(),
                            vertices->GetBaseIndex() + i,
                            1,
                            Viewport::s_SelectedComponentMaterial,
                            Helium::RenderResourceManager::DEPTH_STENCIL_STATE_NONE );
                    }

                    if ( GetControlPointLabel() != ControlPointLabel::None )
                    {
                        tstringstream label;
                        switch ( GetControlPointLabel() )
                        {
                        case ControlPointLabel::CurveAndIndex:
                            label << GetName() << TXT( "[" ) << i << TXT( "]" );
                            break;

                        case ControlPointLabel::IndexOnly:
                            label << "[" << i << "]";
                            break;
                        }

                        Simd::Vector3 position( &point->GetPosition().x );

                        // local to global
                        globalTransform.TransformPoint( position, position );

                        const int32_t offsetX = 0;
                        const int32_t offsetY = 15;

                        drawInterface->DrawProjectedText(
                            position,
                            offsetX,
                            offsetY,
                            String( label.str().c_str() ),
                            textColor,
                            Helium::RenderResourceManager::DEBUG_FONT_SIZE_SMALL );
                    }
                    ++i;
                }
            }
        }

        //
        //  Overdraw highlighted points
        // 
        {
            OS_HierarchyNodeDumbPtr::Iterator childItr = GetChildren().Begin();
            OS_HierarchyNodeDumbPtr::Iterator childEnd = GetChildren().End();
            for ( uint32_t i = 0; childItr != childEnd; ++childItr )
            {
                CurveControlPoint* point = Reflect::SafeCast< CurveControlPoint >( *childItr );
                if ( point )
                {
                    if ( point->IsHighlighted() )
                    {
                        drawInterface->DrawPoints(
                            globalTransform,
                            vertices->GetBuffer(),
                            vertices->GetBaseIndex() + i,
                            1,
                            Viewport::s_HighlightedMaterial,
                            Helium::RenderResourceManager::DEPTH_STENCIL_STATE_NONE );
                    }
                    ++i;
                }
            }
        }
    }

    Base::Render( render );
}
Пример #2
0
/// Update the instance buffer data for a set of graphics scene object sub-meshes.
///
/// @param[in] pContext  Context in which this job is running.
void UpdateGraphicsSceneSubMeshBuffersJob::Run( JobContext* /*pContext*/ )
{
    const GraphicsSceneObject* pSceneObjects = m_parameters.pSceneObjects;
    HELIUM_ASSERT( pSceneObjects );

    const GraphicsSceneObject::SubMeshData* pSubMeshes = m_parameters.pSubMeshes;
    HELIUM_ASSERT( pSubMeshes );

    float32_t* const* ppConstantBufferData = m_parameters.ppConstantBufferData;
    HELIUM_ASSERT( ppConstantBufferData );

    uint_fast32_t subMeshCount = m_parameters.subMeshCount;
    for( uint_fast32_t subMeshIndex = 0;
        subMeshIndex < subMeshCount;
        ++subMeshIndex, ++pSubMeshes, ++ppConstantBufferData )
    {
        float32_t* pConstantBuffer = *ppConstantBufferData;
        if( !pConstantBuffer )
        {
            continue;
        }

        const GraphicsSceneObject::SubMeshData& rSubMesh = *pSubMeshes;

        size_t sceneObjectIndex = rSubMesh.GetSceneObjectId();
        const GraphicsSceneObject& rSceneObject = pSceneObjects[ sceneObjectIndex ];

        const Simd::Matrix44* pBonePalette = rSceneObject.GetBonePalette();

#if L_USE_GRANNY_ANIMATION
        const void* pBoneData = rSceneObject.GetBoneData();
        HELIUM_ASSERT( pBoneData );

        Simd::Matrix44 inverseBoneReferencePose;
#else
        const Simd::Matrix44* pInverseReferencePose = rSceneObject.GetInverseReferencePose();
        HELIUM_ASSERT( pInverseReferencePose );
#endif

        const uint8_t* pSkinningPaletteMap = rSubMesh.GetSkinningPaletteMap();
        HELIUM_ASSERT( pSkinningPaletteMap );

        Simd::Matrix44 skinningMatrix;

        uint_fast8_t boneCount = rSceneObject.GetBoneCount();
        for( uint_fast8_t boneIndex = 0; boneIndex < boneCount; ++boneIndex )
        {
            size_t skinningPaletteIndex = pSkinningPaletteMap[ boneIndex ];
            if( skinningPaletteIndex >= BONE_COUNT_MAX )
            {
                continue;
            }

            float32_t* pSkinningMatrix43 = pConstantBuffer + skinningPaletteIndex * 12;

            const Simd::Matrix44& rBoneTransform = pBonePalette[ boneIndex ];
#if L_USE_GRANNY_ANIMATION
            Granny::GetInverseBoneReferencePose( inverseBoneReferencePose, pBoneData, boneIndex );
            skinningMatrix.MultiplySet( inverseBoneReferencePose, rBoneTransform );
#else
            const Simd::Matrix44& rInverseBoneReferencePose = pInverseReferencePose[ boneIndex ];
            skinningMatrix.MultiplySet( rInverseBoneReferencePose, rBoneTransform );
#endif

            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 0 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 4 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 8 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 12 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 1 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 5 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 9 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 13 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 2 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 6 );
            *( pSkinningMatrix43++ ) = skinningMatrix.GetElement( 10 );
            *pSkinningMatrix43       = skinningMatrix.GetElement( 14 );
        }
    }

    JobManager& rJobManager = JobManager::GetStaticInstance();
    rJobManager.ReleaseJob( this );
}
Пример #3
0
void GraphicsSceneView::SetViewAndProjectionMatrices( const Simd::Matrix44& rView, const Simd::Matrix44& rProjection )
{
	m_bDirtyView = false;

	// Set view matrix and extract "look-at" vectors.
	m_viewMatrix = rView;

#if HELIUM_SIMD_SIZE == 16
	m_origin = Simd::Vector3( rView.GetSimdVector( 3 ) );
	m_forward = Simd::Vector3( rView.GetSimdVector( 2 ) );
	m_up = Simd::Vector3( rView.GetSimdVector( 1 ) );
#else
	m_origin = Simd::Vector3( rView.GetElement( 12 ), rView.GetElement( 13 ), rView.GetElement( 14 ) );
	m_forward = Simd::Vector3( rView.GetElement( 8 ), rView.GetElement( 9 ), rView.GetElement( 10 ) );
	m_up = Simd::Vector3( rView.GetElement( 4 ), rView.GetElement( 5 ), rView.GetElement( 6 ) );
#endif

	// Set projection matrix and recover projection parameters.
	m_projectionMatrix = rProjection;

	const float32_t xScale = rProjection.GetElement( 0 );
	const float32_t yScale = rProjection.GetElement( 5 );
	const float32_t zScale = rProjection.GetElement( 10 );
	const float32_t tScale = rProjection.GetElement( 14 );

	m_horizontalFov = 2.0f * Atan( 1.0f / xScale ) * static_cast<float32_t>( HELIUM_RAD_TO_DEG );
	m_aspectRatio = yScale / xScale;
	m_nearClip = -tScale / zScale;
	m_farClip = tScale / (1.0f - zScale);

	// Compute the inverse view and combined inverse view/projection matrices.
	m_viewMatrix.GetInverse( m_inverseViewMatrix );
	m_inverseViewProjectionMatrix.MultiplySet( m_inverseViewMatrix, m_projectionMatrix );

	// Initialize the view frustum.
	m_frustum.Set( m_inverseViewProjectionMatrix.GetTranspose() );
}