Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 16874

World coordinates to screen coordinates

$
0
0

I am trying to convert world coordinates to screen coordinates. 

The problem is that it works when clicking near the centre of the window, but it becomes more and more incorrect the closer the click is toward the edge of the window.

I'm using the code:


vertex_3 get2dPoint(float(&point3D)[4], float(&mat)[16], int width, int height)
{
	float out[4];

	multiply_4x4_matrix_by_4_vector(mat, point3D, out);

	return  vertex_3(
		round(((1.0f + out[0]) * 0.5) * (float)width),
		round(((1.0f - out[1]) * 0.5) * (float)height), 
		0);
}

 

void multiply_4x4_matrix_by_4_vector(float(&in_a)[16], float(&in_b)[4], float(&out)[4 …

Viewing all articles
Browse latest Browse all 16874

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>