Advertisement Jump to content
Sign in to follow this  

Rotating Sprite Problem

This topic is 3643 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

I am trying to rotate a sprite but I can't get it to work properly, everything seems to rotate around the screen's corner.

void Direct3D::draw_sprite(Object &object)
	float world_coordinates_per_pixel = 1/32.0f;
	SpriteInstance sprite_instance = object.get_sprite_instance();
	LPDIRECT3DTEXTURE9 texture = sprite_instance.get_sprite()->get_texture();
	D3DXMATRIX matrix;

							   0, 20, 
							   0, 15,
							   0, 1);
	d3d_device->SetTransform(D3DTS_PROJECTION, &matrix);

	d3d_device->SetTransform(D3DTS_VIEW, &matrix);


	RECT frame = get_frame(sprite_instance);

	b2Vec2 translation_scale = b2Vec2(1.0f/world_coordinates_per_pixel,

	D3DXVECTOR3 center;
	center = get_center(sprite_instance.get_size()/2); 

	D3DXVECTOR3 position;
	position.x = object.object_body->GetPosition().x;
	position.y = object.object_body->GetPosition().y;
	position.z = 1.0f;

	position.x *= translation_scale.x;
	position.y *= translation_scale.y;
	position.z *= 1;

    d3d_sprite->Draw(texture, &frame, &center, &position, 0xFFFFFFFF);

RECT Direct3D::get_frame(SpriteInstance &sprite)
	RECT frame;

	frame.left = sprite.get_column() * sprite.get_size();
	frame.right = frame.left + sprite.get_size(); = sprite.get_row() * sprite.get_size();
	frame.bottom = + sprite.get_size();

	return frame;

D3DXVECTOR3 Direct3D::get_center(float center)
	return D3DXVECTOR3(center,center,0);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!