home *** CD-ROM | disk | FTP | other *** search
- /*
- ** MacWT -- a 3d game engine for the Macintosh
- ** © 1995, Bill Hayden and Nikol Software
- ** Free for non-commercial use - address questions to the e-mail address below
- **
- ** Mail: afn28988@freenet.ufl.edu (Bill Hayden)
- ** MacWT FTP site: ftp.circa.ufl.edu/pub/software/ufmug/mirrors/LocalSW/Hayden/
- ** WWW Page: http://grove.ufl.edu:80/~nikolsw
- **
- ** All of the above addresses are due to changes sometime in 1996, so stay tuned
- **
- ** based on wt, by Chris Laurel
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- */
-
-
- #include <stdlib.h>
- #include <math.h>
- #include "wt.h"
- #include "error.h"
- #include "fixed.h"
- #include "wtmem.h"
- #include "view.h"
- #include "Failure.h"
-
-
- static void SetViewParams(View *view, fixed field_of_view, fixed eye_distance);
-
-
-
-
- static void SetViewParams(View *view, fixed field_of_view, fixed eye_distance)
- {
- view->arc = field_of_view;
- view->eye_distance = eye_distance;
- view->view_plane_size = FLOAT_TO_FIXED(tan(FIXED_TO_FLOAT(field_of_view) / 2.0) *
- FIXED_TO_FLOAT(eye_distance));
- }
-
-
-
- View *CreateView(fixed field_of_view, fixed eye_distance)
- {
- View *view;
-
- if (field_of_view > FIXED_PI)
- return NULL;
-
- view = (View *)malloc(sizeof(View));
- if (view == NULL)
- return NULL;
-
- SetViewParams(view, field_of_view, eye_distance);
-
- return view;
- }
-
-
-
- void SetFieldOfView(View *view, fixed field_of_view)
- {
- if ((view == NULL) || (field_of_view > FIXED_PI))
- return;
-
- SetViewParams(view, field_of_view, view->eye_distance);
- }
-
-
- void SetEyeDistance(View *view, fixed eye_distance)
- {
- if (eye_distance <= FIXED_ZERO)
- return;
-
- SetViewParams(view, view->arc, eye_distance);
- }
-
-
- void SetViewpoint(View *view, fixed x, fixed y, fixed z, fixed angle)
- {
- view->x = x;
- view->y = y;
- view->height = z;
- view->angle = angle;
- }
-
-
- void ShiftViewpoint(View *view, fixed dx, fixed dy, fixed dz, fixed dangle)
- {
- view->x += dx;
- view->y += dy;
- view->height += dz;
- view->angle += dangle;
- }
-
-
-