Archived

This topic is now archived and is closed to further replies.

russian-bear

need optimazation help

Recommended Posts

Hi! I have a function where a sprite will show up on the other side of the screen if it reaches past a screen edge. In other words the sprite wraps around the screen. No this is how the code for that looks:
          
#define LEFT_BOUND	-400.0f	

#define RIGHT_BOUND	400.0f	

#define TOP_BOUND	300.0f

#define BOTTOM_BOUND	-300.0f	



// this is a snip from the sprite render function



if ( m_bWrap ) 
	{
		// Check screen edges

		if( m_vPos.x < ( LEFT_BOUND + m_fSize / 2.0f ) )
		{
			D3DXMatrixTranslation( &matTrans, 
				m_vPos.x + RIGHT_BOUND * 2.0f, 
				m_vPos.y, 
				0.0f );
			D3DXMatrixRotationZ( &matRot, m_fRotation );
			D3DXMatrixScaling( &matScale, m_fScale, m_fScale, 0.0f );
			D3DXMatrixMultiply( &matFinal, &matScale, &matRot );
			D3DXMatrixMultiply( &matFinal, &matFinal, &matTrans );
			m_pDevice->SetTransform( D3DTS_WORLD, &matFinal );
			m_pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );

		}
		else if( m_vPos.x > ( RIGHT_BOUND - m_fSize / 2.0f ) ) 
		{
			D3DXMatrixTranslation( &matTrans, 
				m_vPos.x + LEFT_BOUND * 2.0f, 
				m_vPos.y, 
				0.0f );
			D3DXMatrixRotationZ( &matRot, m_fRotation );
			D3DXMatrixScaling( &matScale, m_fScale, m_fScale, 0.0f );
			D3DXMatrixMultiply( &matFinal, &matScale, &matRot );
			D3DXMatrixMultiply( &matFinal, &matFinal, &matTrans );
			m_pDevice->SetTransform( D3DTS_WORLD, &matFinal );
			m_pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );
		}

		if( m_vPos.y < ( BOTTOM_BOUND + m_fSize / 2.0f ) )
		{
			D3DXMatrixTranslation( &matTrans, 
				m_vPos.x, 
				m_vPos.y + TOP_BOUND * 2.0f, 
				0.0f );
			D3DXMatrixRotationZ( &matRot, m_fRotation );
			D3DXMatrixScaling( &matScale, m_fScale, m_fScale, 0.0f );
			D3DXMatrixMultiply( &matFinal, &matScale, &matRot );
			D3DXMatrixMultiply( &matFinal, &matFinal, &matTrans );
			m_pDevice->SetTransform( D3DTS_WORLD, &matFinal );
			m_pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );
		}
		else if( m_vPos.y > ( TOP_BOUND - m_fSize / 2.0f ) ) 
		{
			D3DXMatrixTranslation( &matTrans, 
				m_vPos.x, 
				m_vPos.y + BOTTOM_BOUND * 2.0f, 
				0.0f );
			D3DXMatrixRotationZ( &matRot, m_fRotation );
			D3DXMatrixScaling( &matScale, m_fScale, m_fScale, 0.0f );
			D3DXMatrixMultiply( &matFinal, &matScale, &matRot );
			D3DXMatrixMultiply( &matFinal, &matFinal, &matTrans );
			m_pDevice->SetTransform( D3DTS_WORLD, &matFinal );
			m_pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );
		}

		// Check screen corners

		if( m_vPos.x < ( LEFT_BOUND + m_fSize / 2.0f ) && 
			m_vPos.y > ( TOP_BOUND - m_fSize / 2.0f ) )
		{
			D3DXMatrixTranslation( &matTrans, 
				m_vPos.x + RIGHT_BOUND * 2.0f, 
				m_vPos.y + BOTTOM_BOUND * 2.0f, 
				0.0f );
			D3DXMatrixRotationZ( &matRot, m_fRotation );
			D3DXMatrixScaling( &matScale, m_fScale, m_fScale, 0.0f );
			D3DXMatrixMultiply( &matFinal, &matScale, &matRot );
			D3DXMatrixMultiply( &matFinal, &matFinal, &matTrans );
			m_pDevice->SetTransform( D3DTS_WORLD, &matFinal );
			m_pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );
		}
		else if( m_vPos.x > ( RIGHT_BOUND - m_fSize / 2.0f ) &&
				m_vPos.y > ( TOP_BOUND - m_fSize / 2.0f ) ) 
		{
			D3DXMatrixTranslation( &matTrans, 
				m_vPos.x + LEFT_BOUND * 2.0f, 
				m_vPos.y + BOTTOM_BOUND * 2.0f, 
				0.0f );
			D3DXMatrixRotationZ( &matRot, m_fRotation );
			D3DXMatrixScaling( &matScale, m_fScale, m_fScale, 0.0f );
			D3DXMatrixMultiply( &matFinal, &matScale, &matRot );
			D3DXMatrixMultiply( &matFinal, &matFinal, &matTrans );
			m_pDevice->SetTransform( D3DTS_WORLD, &matFinal );
			m_pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );
		}
		else if( m_vPos.x < ( LEFT_BOUND + m_fSize / 2.0f ) && 
				m_vPos.y < ( BOTTOM_BOUND + m_fSize / 2.0f ) )
		{
			D3DXMatrixTranslation( &matTrans, 
				m_vPos.x + RIGHT_BOUND * 2.0f, 
				m_vPos.y + TOP_BOUND * 2.0f, 
				0.0f );
			D3DXMatrixRotationZ( &matRot, m_fRotation );
			D3DXMatrixScaling( &matScale, m_fScale, m_fScale, 0.0f );
			D3DXMatrixMultiply( &matFinal, &matScale, &matRot );
			D3DXMatrixMultiply( &matFinal, &matFinal, &matTrans );
			m_pDevice->SetTransform( D3DTS_WORLD, &matFinal );
			m_pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );
		}
		else if( m_vPos.x > ( RIGHT_BOUND - m_fSize / 2.0f ) &&
				m_vPos.y < ( BOTTOM_BOUND + m_fSize / 2.0f ) )
		{
			D3DXMatrixTranslation( &matTrans, 
				m_vPos.x + LEFT_BOUND * 2.0f, 
				m_vPos.y + TOP_BOUND * 2.0f, 
				0.0f );
			D3DXMatrixRotationZ( &matRot, m_fRotation );
			D3DXMatrixScaling( &matScale, m_fScale, m_fScale, 0.0f );
			D3DXMatrixMultiply( &matFinal, &matScale, &matRot );
			D3DXMatrixMultiply( &matFinal, &matFinal, &matTrans );
			m_pDevice->SetTransform( D3DTS_WORLD, &matFinal );
			m_pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );
		}
	}

          
Its a monster i know.... but please if you no how to make this in a more simple way please help me. I use 2 poly textured quads for my sprites. [edited by - russian-bear on April 28, 2002 8:59:29 PM] [edited by - russian-bear on April 28, 2002 8:59:53 PM] [edited by - russian-bear on April 28, 2002 9:00:12 PM] [edited by - russian-bear on April 28, 2002 9:00:51 PM]

Share this post


Link to post
Share on other sites
Hmm.....
If im reading your mask right you have writtent that: 'if the object is outside the left side and outside the right side then do whatever' ..... isn't that imposible? The object cant be on the two sides of the screen at the same time.

I might be wrong...

[edited by - russian-bear on April 29, 2002 7:55:19 AM]

Share this post


Link to post
Share on other sites
LOL, oops. Do you think you could explkain what your program is doing exactly?

What I was trying to say was if it''s inside the left and right. Your way seems to check if it''s just to the right or to the left (which should be everything)

Share this post


Link to post
Share on other sites