project.m 336 B

12345678910
  1. function W = project(V,MV,P,VP)
  2. V = V * MV' * P';
  3. % WTF! Perspective division is not in the documentation for gluProject:
  4. % http://www.opengl.org/sdk/docs/man2/xhtml/gluProject.xml
  5. V = bsxfun(@rdivide,V,V(:,4));
  6. W = [ ...
  7. VP(1) + (VP(3) * (V(:,1)+1))/2, ...
  8. VP(2) + (VP(4) * (V(:,2)+1))/2, ...
  9. (V(:,3)+1)/2];
  10. end