Jump to content
  • Advertisement


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

The Bag

Rotation problems, help please

This topic is 5456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m trying to rotate a sprite, the sprite is rotated fine, but the rest of the world is rotated with it - eg if I press up the sprite moves diagonally instead of straight up. The sprite is held as (no comments about this please, it''s how we have to represent it):
    D3DXVECTOR4 p;
    FLOAT       tu, tv;	
and the drawing code with the rotation in it is:
DrawBitmap(int ID, int x, int y, int left, int top, int width, int height, int angle )
	if( (g_VB[ID] == NULL) || (g_Tex[ID] == NULL) )
		return S_OK;

    CHECK( g_VB[ID]->Lock( 0, 0, (void**)&v, 0 ) );
    v[0].p = D3DXVECTOR4( (float)x,            (float)y+height, 0.0f, 1.0f );
    v[1].p = D3DXVECTOR4( (float)x,            (float)y,              0.0f, 1.0f );
    v[2].p = D3DXVECTOR4( (float)x+width, (float)y+height,  0.0f, 1.0f );
    v[3].p = D3DXVECTOR4( (float)x+width, (float)y,              0.0f, 1.0f );
	float tw = (float)g_TexDesc[ID].Width;
	float th = (float)g_TexDesc[ID].Height;
	v[0].tu = ((float)left)/tw; v[0].tv = ((float)top+height)/th;
	v[1].tu = ((float)left)/tw; v[1].tv = ((float)top)/th;
	v[2].tu = ((float)left+width)/tw; v[2].tv = ((float)top+height)/th;
	v[3].tu = ((float)left+width)/tw; v[3].tv = ((float)top)/th;
	for(int i = 0; i < 4; i++){
		float xr = v[i].p.x * cos_look[angle] - v[i].p.y * sin_look[angle];
		float yr = v[i].p.y * sin_look[angle] + v[i].p.x * cos_look[angle];

		v[i].p.x = xr;
		v[i].p.y = yr;


	m_pd3dDevice->SetTexture( 0, g_Tex[ID] );
	m_pd3dDevice->SetFVF( D3DFVF_VERTEXFOR2D );
		0, g_VB[ID], 0, sizeof(VERTEXFOR2D) );
	m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
	m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
	m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

	m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
	m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
	return S_OK;
How should I be rotating it to avoid this problem or do I need to un-rotate it, as it were, after I draw it.

Share this post

Link to post
Share on other sites
im not 100% sure but dont you have to specify a specific matrix to use so it doesnt transform everything..

im not too sure about 2d images though, try using the
D3DXMatrixRotation function

the D3DX bit kinda means its meant for 3d though i think..lol

im not sure if it works with 2d images though..but im still sure you need to use matrixes to rotate specific objects in a world, well in 3d anyway... Maybe ther is a similar 2d rotation function...

i think in OpenGl you can use glPush and glPop to only move certain things..

lol hope this was helpfull... i like to rant...

[edited by - grofit on November 8, 2003 3:33:12 PM]

Share this post

Link to post
Share on other sites
that''s what I''m using.

What I''m looking for is for the object to be rotated, which it is. The problem is that I''m checking when object move out of the window, & bring them back on the other side - like asteroids. But now the world for that particular object is rotated it''s getting recognised as being out with the window when it crosses the rotated top of the window, which is now rotated diagonally across the window.

I think what I''m really looking for is a way to check the object against the window''s real bounds & not the rotated ones.

And a better way for doing rotation if there is one.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!