Jump to content
  • Advertisement
Sign in to follow this  
Kr00pS

Line transformation problem

This topic is 3797 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
Advertisement
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
Sign in to follow this  

  • 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!