Sign in to follow this  

Line transformation problem

This topic is 3579 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 ! To represent the bullets in my game (2D), I was thinking that a line was enough and I've true. The problem is the rotation of my line, currently I'm using this code to render my bullets:
	D3DXVECTOR2 vertices[3];
	
	vertices[0] = D3DXVECTOR2(m_Position.x, m_Position.y);
	vertices[1] = D3DXVECTOR2(m_Position.x+6, m_Position.y+6);

	m_BulletView->Begin();
	m_BulletView->Draw(vertices, 2, D3DCOLOR_XRGB(0, 255, 0));
	m_BulletView->End();
If I want a rotation, the docs say "before calling Draw, transform your vertices". I don't know how. So I tried DrawTransform() with this code:
	D3DXVECTOR3 vertices[3];
	
	vertices[0] = D3DXVECTOR3(m_Position.x, m_Position.y, 0.0f);
	vertices[1] = D3DXVECTOR3(m_Position.x+6, m_Position.y+6, 0.0f);

	D3DXVECTOR2 rot_center;

	rot_center.x = (m_Position.x + 16);
	rot_center.y = (m_Position.y + 16);

	D3DXMATRIX rot_mat;

	D3DXMatrixTransformation2D(&rot_mat, NULL, 0, NULL, &rot_center, m_Angle, NULL);

	m_BulletView->Begin();
	m_BulletView->DrawTransform(vertices, 2, &rot_mat, D3DCOLOR_XRGB(0, 255, 0));
	m_BulletView->End();
Didn't work. Help please ! Thanks for all

Share this post


Link to post
Share on other sites
I would try doing your rotation and translation in one go, like this:



D3DXVECTOR3 vertices[3];

vertices[0] = D3DXVECTOR3(0, 0, 0.0f);
vertices[1] = D3DXVECTOR3(6, 6, 0.0f);

D3DXVECTOR2 rot_center;

rot_center.x = (16);
rot_center.y = (16);

D3DXMATRIX rot_mat;

D3DXMatrixTransformation2D(&rot_mat, NULL, 0, NULL, &rot_center, m_Angle, &m_Position);

m_BulletView->Begin();
m_BulletView->DrawTransform(vertices, 2, &rot_mat, D3DCOLOR_XRGB(0, 255, 0));
m_BulletView->End();





Just be aware that if you always want the line to to start at m_position, you should rotate your line about (0,0).

Share this post


Link to post
Share on other sites

This topic is 3579 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this