home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglw.zip / mapping.c < prev    next >
C/C++ Source or Header  |  1997-02-13  |  870b  |  46 lines

  1. #include "vogl.h"
  2.  
  3. static    float    Vcx, Vcy, Vsx, Vsy;
  4.  
  5. /*
  6.  * calcW2Vcoeffs
  7.  *
  8.  *    Calculate the linear coeffs defining the mapping of world
  9.  *    space to actual device space
  10.  */
  11. void
  12. CalcW2Vcoeffs()
  13. {
  14.     Vcx = (float)(vdevice.maxVx + vdevice.minVx) * 0.5;
  15.     Vcy = (float)(vdevice.maxVy + vdevice.minVy) * 0.5;
  16.  
  17.     Vsx = (float)(vdevice.maxVx - vdevice.minVx) * 0.5;
  18.     Vsy = (float)(vdevice.maxVy - vdevice.minVy) * 0.5;
  19. }
  20.  
  21. /*
  22.  * WtoVx
  23.  *
  24.  * return the Screen X coordinate corresponding to world point 'p' 
  25.  * (does the perspective division as well)
  26.  */
  27. int
  28. WtoVx(p)
  29.     float    p[];
  30. {
  31.     return((int)(p[0] * Vsx / p[3] + Vcx + 0.5));
  32. }
  33.  
  34. /*
  35.  * WtoVy
  36.  *
  37.  * return the Screen Y coordinate corresponding to world point 'p' 
  38.  * (does the perspective division as well)
  39.  */
  40. int
  41. WtoVy(p)
  42.     float    p[];
  43. {
  44.     return((int)(p[1] * Vsy / p[3] + Vcy + 0.5));
  45. }
  46.