Line transformation problem

Started by
1 comment, last by MJP 16 years, 1 month ago
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
Advertisement
line->DrawTransform() .....

The Matrix arguement should look as the following

world * view * projection

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

This topic is closed to new replies.

Advertisement