home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume21 / rayshade / part01 / src / viewing.c < prev   
Encoding:
C/C++ Source or Header  |  1990-03-21  |  2.2 KB  |  81 lines

  1. /*
  2.  * viewing.c
  3.  *
  4.  * Copyright (C) 1989, Craig E. Kolb
  5.  *
  6.  * This software may be freely copied, modified, and redistributed,
  7.  * provided that this copyright notice is preserved on all copies.
  8.  *
  9.  * There is no warranty or other guarantee of fitness for this software,
  10.  * it is provided solely .  Bug reports or fixes may be sent
  11.  * to the author, who may or may not act on them as he desires.
  12.  *
  13.  * You may not include this software in a program or other software product
  14.  * without supplying the source, or without informing the end-user that the
  15.  * source is available for no extra charge.
  16.  *
  17.  * If you modify this software, you should include a notice giving the
  18.  * name of the person performing the modification, the date of modification,
  19.  * and the reason for such modification.
  20.  *
  21.  * $Id: viewing.c,v 3.0 89/10/27 02:06:08 craig Exp $
  22.  *
  23.  * $Log:    viewing.c,v $
  24.  * Revision 3.0  89/10/27  02:06:08  craig
  25.  * Baseline for first official release.
  26.  * 
  27.  */
  28. #include <math.h>
  29. #include <stdio.h>
  30. #include "constants.h"
  31. #include "typedefs.h"
  32. #include "funcdefs.h"
  33.  
  34. Vector lookp, eyep, up, firstray, scrnx, scrny;
  35. double vfov, hfov, Separation;
  36. int Xres = UNSET, Yres = UNSET, Stereo;
  37. viewing()
  38. {
  39.     Vector gaze;
  40.     double dist, magnitude;
  41.  
  42.     vecsub(lookp, eyep, &gaze);
  43.     firstray = gaze;
  44.  
  45.     dist = normalize(&gaze);
  46.     (void)crossp(&scrnx, &gaze, &up);
  47.     (void)crossp(&scrny, &scrnx, &gaze);
  48.     dist *= 2.0;
  49.  
  50.     /*
  51.      * Add stereo separation if desired.
  52.      */
  53.     if (Stereo) {
  54.         if (Stereo == LEFT)
  55.             magnitude = -.5 * Separation;
  56.         else
  57.             magnitude = .5 * Separation;
  58.         eyep.x += magnitude * scrnx.x;
  59.         eyep.y += magnitude * scrnx.y;
  60.         eyep.z += magnitude * scrnx.z;
  61.         vecsub(lookp, eyep, &firstray);
  62.         gaze = firstray;
  63.         dist = normalize(&gaze);
  64.         (void)crossp(&scrnx, &gaze, &up);
  65.         (void)crossp(&scrny, &scrnx, &gaze);
  66.     }
  67.  
  68.     magnitude = dist * tan(deg2rad(0.5*hfov)) / Xres;
  69.     scrnx.x *= magnitude;
  70.     scrnx.y *= magnitude;
  71.     scrnx.z *= magnitude;
  72.     magnitude = dist * tan(deg2rad(0.5*vfov)) / Yres;
  73.     scrny.x *= magnitude;
  74.     scrny.y *= magnitude;
  75.     scrny.z *= magnitude;
  76.  
  77.     firstray.x += 0.5*Yres*scrny.x - 0.5*Xres*scrnx.x;
  78.     firstray.y += 0.5*Yres*scrny.y - 0.5*Xres*scrnx.y;
  79.     firstray.z += 0.5*Yres*scrny.z - 0.5*Xres*scrnx.z;
  80. }
  81.