Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
645 B
11
Indexable
Never
// Project vertex from world space to clip space. matrix - MVP matrix.
__inline bool GraphicsProjectVertex(Vertex* vert, float* matrix)
{
	float m[4][4];
	memcpy(&m, matrix, sizeof(m)); // Temporary
	Vertex ret;

	// We treat vertex as float4(pos, 1)
	ret.X = vert->X  * m[0][0] + vert->Y  * m[1][0] + vert->Z * m[2][0] + (1 * m[3][0]);
	ret.Y = vert->X  * m[0][1] + vert->Y * m[1][1] + vert->Z * m[2][1] + (1 * m[3][1]);
	ret.Z = vert->X  * m[0][2] + vert->Y * m[1][2] + vert->Z * m[2][2] + (1 * m[3][2]);
	ret.Q = vert->X  * m[0][3] + vert->Y * m[1][3] + vert->Z * m[2][3] + (1 * m[3][3]);

	*vert = ret;

	return ret.Q >= 0;
}
Leave a Comment