# 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.

## 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 on other sites
line->DrawTransform() .....

The Matrix arguement should look as the following

world * view * projection

##### 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).

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631781
• Total Posts
3002319
×