home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacWT 0.9 / wt Source / view.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-10  |  2.1 KB  |  99 lines  |  [TEXT/CWIE]

  1. /*
  2. **  MacWT -- a 3d game engine for the Macintosh
  3. **  © 1995, Bill Hayden and Nikol Software
  4. **  Free for non-commercial use - address questions to the e-mail address below
  5. **
  6. **  Mail:           afn28988@freenet.ufl.edu (Bill Hayden)
  7. **    MacWT FTP site: ftp.circa.ufl.edu/pub/software/ufmug/mirrors/LocalSW/Hayden/
  8. **  WWW Page:       http://grove.ufl.edu:80/~nikolsw
  9. **
  10. **    All of the above addresses are due to changes sometime in 1996, so stay tuned
  11. **
  12. **  based on wt, by Chris Laurel
  13. **
  14. **  This program is distributed in the hope that it will be useful,
  15. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. */
  18.  
  19.  
  20. #include <stdlib.h>
  21. #include <math.h>
  22. #include "wt.h"
  23. #include "error.h"
  24. #include "fixed.h"
  25. #include "wtmem.h"
  26. #include "view.h"
  27. #include "Failure.h"
  28.  
  29.  
  30. static void SetViewParams(View *view, fixed field_of_view, fixed eye_distance);
  31.  
  32.  
  33.  
  34.  
  35. static void SetViewParams(View *view, fixed field_of_view, fixed eye_distance)
  36. {
  37.     view->arc = field_of_view;
  38.     view->eye_distance = eye_distance;
  39.     view->view_plane_size = FLOAT_TO_FIXED(tan(FIXED_TO_FLOAT(field_of_view) / 2.0) *
  40.                                              FIXED_TO_FLOAT(eye_distance));
  41. }
  42.  
  43.  
  44.  
  45. View *CreateView(fixed field_of_view, fixed eye_distance)
  46. {
  47.     View *view;
  48.  
  49.     if (field_of_view > FIXED_PI)
  50.         return NULL;
  51.  
  52.     view = (View *)malloc(sizeof(View));
  53.     if (view == NULL)
  54.         return NULL;
  55.  
  56.     SetViewParams(view, field_of_view, eye_distance);
  57.  
  58.     return view;
  59. }
  60.  
  61.  
  62.  
  63. void SetFieldOfView(View *view, fixed field_of_view)
  64. {
  65.     if ((view == NULL) || (field_of_view > FIXED_PI))
  66.         return;
  67.      
  68.     SetViewParams(view, field_of_view, view->eye_distance);
  69. }
  70.  
  71.  
  72. void SetEyeDistance(View *view, fixed eye_distance)
  73. {
  74.     if (eye_distance <= FIXED_ZERO)
  75.         return;
  76.  
  77.     SetViewParams(view, view->arc, eye_distance);
  78. }
  79.  
  80.  
  81. void SetViewpoint(View *view, fixed x, fixed y, fixed z, fixed angle)
  82. {
  83.     view->x = x;
  84.     view->y = y;
  85.     view->height = z;
  86.     view->angle = angle;
  87. }
  88.  
  89.  
  90. void ShiftViewpoint(View *view, fixed dx, fixed dy, fixed dz, fixed dangle)
  91. {
  92.     view->x += dx;
  93.     view->y += dy;
  94.     view->height += dz;
  95.     view->angle += dangle;
  96. }
  97.  
  98.  
  99.