MCPcopy Create free account
hub / github.com/carbonengine/trinity / PrepareSpriteVerts

Method PrepareSpriteVerts

trinity/Sprite2d/Tr2Sprite2dScene.cpp:828–923  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

826}
827
828bool Tr2Sprite2dScene::PrepareSpriteVerts(
829 Tr2Sprite2dD3DVertex* destVerts,
830 const Vector2& pos,
831 float width,
832 float height,
833 Tr2SpriteObjectEffect sfx )
834{
835 CCP_STATS_ZONE( __FUNCTION__ );
836
837 if( !TexturesReady() )
838 {
839 CCP_STATS_INC( spriteSceneTextureNotReady );
840 return false;
841 }
842
843 //texture coordinates
844 Vector2 uv[2][4];
845 Vector2 uvInitial[2][4];
846
847 SetSpriteVerticesUVs( uv, width, height );
848 memcpy( uvInitial, uv, sizeof( Vector2 ) * 2 * 4 );
849
850
851 //set vertex data
852 Vector2 verts[4] = {
853 pos,
854 pos + Vector2( width, 0.f ),
855 pos + Vector2( width, height ),
856 pos + Vector2( 0.f, height )
857 };
858
859
860 if( ( sfx == TR2_SFX_BLUR ) || ( sfx == TR2_SFX_GLOW ) )
861 {
862 float textureWidthReciprocal = 1.f;
863 float textureHeightReciprocal = 1.f;
864 if( m_texture[0] )
865 {
866 textureWidthReciprocal = 1.f / m_texture[0]->GetTextureWidth();
867 textureHeightReciprocal = 1.f / m_texture[0]->GetTextureHeight();
868 }
869
870 verts[0].x -= 1;
871 verts[0].y -= 1;
872 uv[0][0].x -= textureWidthReciprocal;
873 uv[0][0].y -= textureHeightReciprocal;
874
875 verts[1].x += 1;
876 verts[1].y -= 1;
877 uv[0][1].x += textureWidthReciprocal;
878 uv[0][1].y -= textureHeightReciprocal;
879
880 verts[2].x += 1;
881 verts[2].y += 1;
882 uv[0][2].x += textureWidthReciprocal;
883 uv[0][2].y += textureHeightReciprocal;
884
885 verts[3].x -= 1;

Callers 1

GatherSpritesMethod · 0.80

Calls 3

PackBlendModeFunction · 0.85
GetTextureWidthMethod · 0.80
GetTextureHeightMethod · 0.80

Tested by

no test coverage detected