Advertisement
Guest User

Untitled

a guest
Oct 27th, 2017
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. BOOL Vox::Project(float objx, float objy, float objz, const mathfu::mat4 projMatrix, const mathfu::mat4 modelMatrix, RECT* viewport, int* winx, int* winy, int* winz)
  2. {
  3.     mathfu::vec4 in;
  4.     mathfu::vec4 out;
  5.     in.x = objx;
  6.     in.y = objy;
  7.     in.z = objz;
  8.     in.w = 1.0f;
  9.     out = modelMatrix * in;
  10.     in = projMatrix * out;
  11.     if (in.z == 0.0f) {
  12.         return FALSE;
  13.     }
  14.     in.x = in.x / in.z;
  15.     in.y = in.y / in.z;
  16.     in.z = in.z / in.z;
  17.     /* Map x, y and z to range 0-1 */
  18.     in.x = in.x * 0.5f + 0.5f;
  19.     in.y = in.y * 0.5f + 0.5f;
  20.     in.z = in.z * 0.5f + 0.5f;
  21.     /* Map x,y to viewport */
  22.     in.x *= viewport->left + viewport->right;
  23.     in.y *= viewport->top + viewport->bottom;
  24.     *winx = int(in.x);
  25.     *winy = int(in.y);
  26.     *winz = int(in.z);
  27.     return TRUE;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement