home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / endo / viewcnst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  4.7 KB  |  99 lines

  1. /*************************************************************************
  2.  *                                                                       *
  3.  *  Copyright (c) 1992, 1993 Ronald Joe Record                           *
  4.  *                                                                       *
  5.  *  All rights reserved. No part of this program or publication may be   *
  6.  *  reproduced, transmitted, transcribed, stored in a retrieval system,  *
  7.  *  or translated into any language or computer language, in any form or *
  8.  *  by any means, electronic, mechanical, magnetic, optical, chemical,   *
  9.  *  biological, or otherwise, without the prior written permission of:   *
  10.  *                                                                       *
  11.  *      Ronald Joe Record (408) 458-3718                                 *
  12.  *      212 Owen St., Santa Cruz, California 95062 USA                   *
  13.  *                                                                       *
  14.  *************************************************************************/
  15.  
  16. /*************************************************************************
  17.  *                                                                       *
  18.  *     Copyright (c) 1989                  Hiram Clawson                 *
  19.  *                                                                       *
  20.  *  All rights reserved. No part of this program or publication may be   *
  21.  *  reproduced, transmitted, transcribed, stored in a retrieval system,  *
  22.  *  or translated into any language or computer language, in any form or *
  23.  *  by any means, electronic, mechanical, magnetic, optical, chemical,   *
  24.  *  biological, or otherwise, without the prior written permission of:   *
  25.  *                                                                       *
  26.  *              Hiram Clawson                        (408) 429-5647      *
  27.  *              P. O. Box 3178, Santa Cruz, California 95063-3178 USA    *
  28.  *                                                                       *
  29.  *************************************************************************/
  30. /*************************************************************************
  31.  *        viewcnst.c: Setup viewing constants for the 3D plotting system *
  32.  *                                                                       *
  33.  *                Written by Hiram Clawson.                              *
  34.  *                Ported to X11 by Ronald Joe Record.                    *
  35.  *************************************************************************/
  36.  
  37. #include "globals.h"
  38.  
  39. void view_point_constants()
  40. {
  41.     triple v_view_upper_right;
  42.     double length_view_upper_right;
  43.  
  44. /*
  45.     following subroutine computes constants of viewing situation
  46.     must be done each time the viewing situation changes
  47.     (When the viewing window moves, or the viewpoint is moved (FOV change))
  48. */
  49.     v_view_center.x =    window_center.x - view_point.x;
  50.     v_view_center.y =    window_center.y - view_point.y;
  51.     v_view_center.z =    window_center.z - view_point.z;
  52.  
  53.     v_center_right.x =    window_right.x - window_center.x;
  54.     v_center_right.y =    window_right.y - window_center.y;
  55.     v_center_right.z =    window_right.z - window_center.z;
  56.  
  57.     v_view_upper_right.x =    window_upper_right.x - view_point.x;
  58.     v_view_upper_right.y =    window_upper_right.y - view_point.y;
  59.     v_view_upper_right.z =    window_upper_right.z - view_point.z;
  60.  
  61.     length_view_center = sqrt(     (v_view_center.x * v_view_center.x) +
  62.                     (v_view_center.y * v_view_center.y) +
  63.                     (v_view_center.z * v_view_center.z) );
  64.  
  65.     length_center_right = sqrt(    (v_center_right.x * v_center_right.x) +
  66.                     (v_center_right.y * v_center_right.y) +
  67.                     (v_center_right.z * v_center_right.z) );
  68.  
  69.     length_view_upper_right = sqrt(
  70.             (v_view_upper_right.x * v_view_upper_right.x) +
  71.             (v_view_upper_right.y * v_view_upper_right.y) +
  72.             (v_view_upper_right.z * v_view_upper_right.z) );
  73.  
  74.     v_center_top.x = window_top.x - window_center.x;
  75.     v_center_top.y = window_top.y - window_center.y;
  76.     v_center_top.z = window_top.z - window_center.z;
  77.  
  78.     length_center_top = sqrt (
  79.             (v_center_top.x * v_center_top.x) +
  80.             (v_center_top.y * v_center_top.y) +
  81.             (v_center_top.z * v_center_top.z) ); 
  82. /*      establish scale between 3D space units and pixel units on the screen */
  83.         _3D_units_per_ypixel = (length_center_top/2.0) / screen_center.y;
  84. /*
  85.     the angle between v_view_center and v_view_upper_right will be the
  86.     maximum angle from the center that can be plotted (some points will miss
  87.     because that is the upper right corner)
  88. */
  89.     cosine_half_field_of_view = ( (v_view_center.x * v_view_upper_right.x) +
  90.                 (v_view_center.y * v_view_upper_right.y) +
  91.                 (v_view_center.z * v_view_upper_right.z) ) /
  92.                 (length_view_center * length_view_upper_right);
  93.  
  94.     field_of_view = 2.0 * acos( cosine_half_field_of_view );
  95.  
  96.     return;
  97.  
  98. }    /* end of view_point_constants */
  99.