home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-27 | 55.2 KB | 2,073 lines |
- Newsgroups: comp.sources.misc
- From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Subject: v27i018: sfs - Space Flight Simulator, Part18/21
- Message-ID: <1991Dec24.191925.21134@sparky.imd.sterling.com>
- X-Md4-Signature: c08ed3bc3c8e1479e10d43492aebb243
- Date: Tue, 24 Dec 1991 19:19:25 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Posting-number: Volume 27, Issue 18
- Archive-name: sfs/part18
- Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X11,
-
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file sfs/sfs/sfs.h continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 18; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping sfs/sfs/sfs.h'
- else
- echo 'x - continuing file sfs/sfs/sfs.h'
- sed 's/^X//' << 'SHAR_EOF' >> 'sfs/sfs/sfs.h' &&
- X
- X
- SHAR_EOF
- echo 'File sfs/sfs/sfs.h is complete' &&
- chmod 0644 sfs/sfs/sfs.h ||
- echo 'restore of sfs/sfs/sfs.h failed'
- Wc_c="`wc -c < 'sfs/sfs/sfs.h'`"
- test 12242 -eq "$Wc_c" ||
- echo 'sfs/sfs/sfs.h: original size 12242, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/sfs/sfs.mak ==============
- if test -f 'sfs/sfs/sfs.mak' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/sfs/sfs.mak (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/sfs/sfs.mak (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs.mak' &&
- PROJ =SFS
- DEBUG =0
- CC =qcl
- CFLAGS_G = /AS /W1 /Ze /I..\..\include /DDEBUG /DSPAWN
- CFLAGS_D = /Zd /Gi$(PROJ).mdt /Od
- CFLAGS_R = /Od /Gs /DNDEBUG
- CFLAGS =$(CFLAGS_G) $(CFLAGS_R)
- LFLAGS_G = /CP:0xffff /NOI /SE:0x80 /ST:0x1000
- LFLAGS_D = /INCR
- LFLAGS_R =
- LFLAGS =$(LFLAGS_G) $(LFLAGS_R)
- RUNFLAGS =
- OBJS_EXT =
- LIBS_EXT =
- X
- all: $(PROJ).exe
- X
- sfs.obj: sfs.c
- X
- $(PROJ).exe: sfs.obj $(OBJS_EXT)
- X echo >NUL @<<$(PROJ).crf
- sfs.obj +
- $(OBJS_EXT)
- $(PROJ).exe
- X
- $(LIBS_EXT);
- <<
- X link $(LFLAGS) @$(PROJ).crf
- X
- run: $(PROJ).exe
- X $(PROJ) $(RUNFLAGS)
- X
- SHAR_EOF
- chmod 0644 sfs/sfs/sfs.mak ||
- echo 'restore of sfs/sfs/sfs.mak failed'
- Wc_c="`wc -c < 'sfs/sfs/sfs.mak'`"
- test 546 -eq "$Wc_c" ||
- echo 'sfs/sfs/sfs.mak: original size 546, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/sfs/sfs_di.c ==============
- if test -f 'sfs/sfs/sfs_di.c' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/sfs/sfs_di.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/sfs/sfs_di.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_di.c' &&
- /***************************************************************
- X
- X sfs_di.c Multiple Display Routines for
- X Space Flight Simulator
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ***************************************************************/
- X
- #include "stdio.h"
- #include "ctype.h"
- #include "bw.h"
- #include "gr.h"
- #include "kb.h"
- #include "ui.h"
- #include "as.h"
- #include "sfs.h"
- X
- #ifdef __STDC__
- #include "malloc.h"
- #else
- extern char * malloc();
- #define size_t int
- #define time_t long
- #endif
- X
- /***************************************************************
- X
- X di_init()
- X
- ***************************************************************/
- X
- di_init( sorbit_array, n_orbits, d_array, n_displays, t_array )
- X struct sfs_orbit **sorbit_array;
- X int n_orbits;
- X struct sfs_display ***d_array;
- X int *n_displays;
- X char ***t_array;
- X {
- X register int c, d;
- X int n;
- X int x_foci, x_active, x_new;
- X
- X /* first determine the number of active orbits */
- X
- X x_active = 0;
- X for ( c = 0; c < n_orbits; ++c )
- X {
- X if ( sorbit_array[ c ] != NULL )
- X {
- X ++x_active;
- X }
- X }
- X
- X /* now determine number of foci */
- X
- X x_foci = 0;
- X for ( c = 0; c < n_orbits; ++c )
- X {
- X if ( sorbit_array[ c ] != NULL )
- X {
- X x_new = TRUE;
- X for ( d = 0; d < c; ++d )
- X {
- X if ( sorbit_array[ d ] != NULL )
- X {
- X if ( sorbit_array[ d ]->aorbit->focus ==
- X sorbit_array[ c ]->aorbit->focus )
- X {
- X x_new = FALSE;
- X }
- X }
- X }
- X if ( x_new == TRUE )
- X {
- X ++x_foci;
- X }
- X }
- X }
- X
- X /* now calculate total number of displays: one visual for each orbit,
- X then a ground track and a distant perspective display for each focus */
- X
- X *n_displays = x_active + ( 2 * x_foci );
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "Displays: %d total from %d orbits with %d foci",
- X *n_displays, x_active, x_foci );
- X bw_debug( bw_ebuf );
- #endif
- X
- X /* allocate memory for d_array */
- X
- X if ( ( *d_array = (struct sfs_display **)
- X malloc( sizeof( struct sfs_display *) * *n_displays ) ) == NULL )
- X {
- X bw_error( DI_MEMERR );
- X sfs_exit();
- X exit( 0 );
- X }
- X
- X /* allocate memory for each structure within d_array */
- X
- X for ( c = 0; c < *n_displays; ++c )
- X {
- X if ( ( (*d_array)[ c ] = (struct sfs_display *)
- X malloc( sizeof( struct sfs_display ) ) ) == NULL )
- X {
- X bw_error( DI_DSMEMERR );
- X sfs_exit();
- X exit( 0 );
- X }
- X }
- X
- X /* from now on, use n as the counter for the display being constructed */
- X /* fill in the visual simulation displays */
- X
- X n = 0;
- X for ( c = 0; c < n_orbits; ++c )
- X {
- X if ( sorbit_array[ c ] != NULL )
- X {
- X (*d_array)[ n ]->type = SFSD_VISUAL;
- X (*d_array)[ n ]->elements
- X = VI_ORBOUTLINE | VI_GRIDFRONT | VI_SURFRONT | VI_STITLE;
- X (*d_array)[ n ]->orbit = c;
- X ++n;
- X }
- X }
- X
- X /* fill in the ground track displays */
- X
- X for ( c = 0; c < n_orbits; ++c )
- X {
- X if ( sorbit_array[ c ] != NULL )
- X {
- X x_new = TRUE;
- X for ( d = 0; d < c; ++d )
- X {
- X if ( sorbit_array[ d ] != NULL )
- X {
- X if ( sorbit_array[ d ]->aorbit->focus ==
- X sorbit_array[ c ]->aorbit->focus )
- X {
- X x_new = FALSE;
- X }
- X }
- X }
- X if ( x_new == TRUE )
- X {
- X (*d_array)[ n ]->type = SFSD_GROUND;
- X (*d_array)[ n ]->elements
- X = VI_ORBOUTLINE | VI_GRIDFRONT | VI_SURFRONT;
- X (*d_array)[ n ]->orbit = c;
- X (*d_array)[ n ]->focus = sorbit_array[ c ]->aorbit->focus;
- X ++n;
- X }
- X }
- X }
- X
- X /* fill in the perspective displays */
- X
- X for ( c = 0; c < n_orbits; ++c )
- X {
- X if ( sorbit_array[ c ] != NULL )
- X {
- X x_new = TRUE;
- X for ( d = 0; d < c; ++d )
- X {
- X if ( sorbit_array[ d ] != NULL )
- X {
- X if ( sorbit_array[ d ]->aorbit->focus ==
- X sorbit_array[ c ]->aorbit->focus )
- X {
- X x_new = FALSE;
- X }
- X }
- X }
- X if ( x_new == TRUE )
- X {
- X (*d_array)[ n ]->type = SFSD_PERSP;
- X (*d_array)[ n ]->elements
- X = VI_ORBOUTLINE | VI_GRIDFRONT | VI_SURFRONT;
- X (*d_array)[ n ]->orbit = c;
- X (*d_array)[ n ]->focus = sorbit_array[ c ]->aorbit->focus;
- X ++n;
- X }
- X }
- X }
- X
- X /* allocate memory for t_array */
- X
- X if ( ( *t_array = (char **)
- X malloc( sizeof(char *) * *n_displays ) ) == NULL )
- X {
- X bw_error( DI_DMEMERR );
- X sfs_exit();
- X exit( 0 );
- X }
- X
- X /* now allocate memory for and write each title */
- X
- X for ( c = 0; c < *n_displays; ++c )
- X {
- X switch ( (*d_array)[ c ]->type )
- X {
- X case SFSD_VISUAL:
- X sprintf( bw_ebuf, VIS_TITLE,
- X sorbit_array[ (*d_array)[ c ]->orbit ]->aorbit->focus->name,
- X sorbit_array[ (*d_array)[ c ]->orbit ]->name,
- X (*d_array)[ c ]->orbit + 1 );
- X break;
- X case SFSD_PERSP:
- X sprintf( bw_ebuf, PER_TITLE,
- X sorbit_array[ (*d_array)[ c ]->orbit ]->aorbit->focus->adjective );
- X break;
- X case SFSD_GROUND:
- X sprintf( bw_ebuf, GTR_TITLE,
- X sorbit_array[ (*d_array)[ c ]->orbit ]->aorbit->focus->adjective );
- X break;
- X default:
- #ifdef DEBUG
- X sprintf( bw_ebuf, "di_init() received incorrect type %d",
- X (*d_array)[ c ]->type );
- X bw_error( bw_ebuf );
- #endif
- X break;
- X }
- X
- X if ( ( (*t_array)[ c ] = (char *)
- X malloc( strlen( bw_ebuf ) + 2 ) ) == NULL )
- X {
- X bw_error( DI_DMEMERR );
- X sfs_exit();
- X exit( 0 );
- X }
- X strcpy( (*t_array)[ c ], bw_ebuf );
- X }
- X
- X }
- X
- SHAR_EOF
- chmod 0644 sfs/sfs/sfs_di.c ||
- echo 'restore of sfs/sfs/sfs_di.c failed'
- Wc_c="`wc -c < 'sfs/sfs/sfs_di.c'`"
- test 6336 -eq "$Wc_c" ||
- echo 'sfs/sfs/sfs_di.c: original size 6336, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/sfs/sfs_ft.c ==============
- if test -f 'sfs/sfs/sfs_ft.c' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/sfs/sfs_ft.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/sfs/sfs_ft.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_ft.c' &&
- /***************************************************************
- X
- X sfs_ft.c Forward Track Routines for
- X Space Flight Simulator
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ***************************************************************/
- X
- #include "stdio.h"
- #include "ctype.h"
- #include "bw.h"
- #include "gr.h"
- #include "kb.h"
- #include "ui.h"
- #include "as.h"
- #include "sfs.h"
- X
- static double x_lat, x_lon;
- static long x_r, x_n;
- X
- ft_init( sorbit_array, orbit, poll )
- X struct sfs_orbit **sorbit_array;
- X int orbit;
- X int (*poll)();
- X {
- X register int c;
- X
- X sprintf( bw_ebuf, FT_NOTICE, orbit + 1 );
- #ifdef OLD_DEBUG
- X bw_debug( bw_ebuf );
- #else
- X bw_message( bw_ebuf );
- #endif
- X
- X sorbit_array[ orbit ]->ft_inc = sorbit_array[ orbit ]->aorbit->period / (double) FT_POINTS;
- X
- X sorbit_array[ orbit ]->ft_t = sfs_insertion;
- X sorbit_array[ orbit ]->last_time = sorbit_array[ orbit ]->ft_t;
- X
- X for ( c = 0; c < FT_POINTS; ++c )
- X {
- X
- X or_ssp( sorbit_array[ orbit ]->aorbit, sorbit_array[ orbit ]->ft_t, &x_lat, &x_lon, &x_r, &x_n );
- X sorbit_array[ orbit ]->ft_buffer[ c ].latitude = x_lat;
- X sorbit_array[ orbit ]->ft_buffer[ c ].longitude = x_lon;
- X sorbit_array[ orbit ]->ft_buffer[ c ].altitude = x_r;
- X sorbit_array[ orbit ]->ft_t += sorbit_array[ orbit ]->ft_inc;
- X
- X /* call poll function */
- X
- X (*poll) ();
- X
- X }
- X
- X sorbit_array[ orbit ]->ft_bufstart = 0;
- X sorbit_array[ orbit ]->ft_bufpos = FT_POINTS - 1;
- X
- X }
- X
- ft_calc( newtime, sorbit_array, orbit, poll )
- X long newtime;
- X struct sfs_orbit **sorbit_array;
- X int orbit;
- X int (*poll)();
- X {
- X register int c;
- X int number;
- X
- X number = ( newtime - sorbit_array[ orbit ]->last_time )
- X / sorbit_array[ orbit ]->ft_inc;
- X
- X sprintf( bw_ebuf, FT_CALC, orbit );
- X bw_message( bw_ebuf );
- X
- X for ( c = 0; c < number; c++ )
- X {
- X
- X or_ssp( sorbit_array[ orbit ]->aorbit, sorbit_array[ orbit ]->ft_t,
- X &x_lat, &x_lon, &x_r, &x_n );
- X sorbit_array[ orbit ]->ft_buffer[ sorbit_array[ orbit ]->ft_bufpos ].latitude = x_lat;
- X sorbit_array[ orbit ]->ft_buffer[ sorbit_array[ orbit ]->ft_bufpos ].longitude = x_lon;
- X sorbit_array[ orbit ]->ft_buffer[ sorbit_array[ orbit ]->ft_bufpos ].altitude = x_r;
- X sorbit_array[ orbit ]->last_time += sorbit_array[ orbit ]->ft_inc;
- X sorbit_array[ orbit ]->ft_t += sorbit_array[ orbit ]->ft_inc;
- X ++sorbit_array[ orbit ]->ft_bufpos;
- X if ( sorbit_array[ orbit ]->ft_bufpos == FT_POINTS )
- X {
- X sorbit_array[ orbit ]->ft_bufpos = 0;
- X }
- X ++sorbit_array[ orbit ]->ft_bufstart;
- X if ( sorbit_array[ orbit ]->ft_bufstart == FT_POINTS )
- X {
- X sorbit_array[ orbit ]->ft_bufstart = 0;
- X }
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "Calculating forward track for orbit %d, position %d of %d",
- X orbit, c, number );
- X bw_message( bw_ebuf );
- #endif
- X
- X /* call poll function */
- X
- X (*poll) ();
- X
- X }
- X }
- X
- ft_plot( sorbit_array, orbit )
- X struct sfs_orbit **sorbit_array;
- X int orbit;
- X {
- X register int c;
- X
- X c = sorbit_array[ orbit ]->ft_bufstart;
- X while ( c != sorbit_array[ orbit ]->ft_bufpos )
- X {
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "Draw forward track, point %d, lat %.2lf, lon %.2lf",
- X c,
- X sorbit_array[ orbit ]->ft_buffer[ c ].latitude,
- X sorbit_array[ orbit ]->ft_buffer[ c ].longitude );
- X bw_debug( bw_ebuf );
- #endif
- X
- X /* Draw the point simply by displaying a line to itself */
- X
- X gt_line( sorbit_array[ orbit ]->ft_buffer[ c ].latitude,
- X sorbit_array[ orbit ]->ft_buffer[ c ].longitude,
- X sorbit_array[ orbit ]->ft_buffer[ c ].latitude,
- X sorbit_array[ orbit ]->ft_buffer[ c ].longitude,
- X cl_orbits[ orbit % 6 ], SOLID );
- X
- X ++c;
- X if ( c == FT_POINTS )
- X {
- X c = 0;
- X }
- X }
- X }
- X
- X
- X
- SHAR_EOF
- chmod 0644 sfs/sfs/sfs_ft.c ||
- echo 'restore of sfs/sfs/sfs_ft.c failed'
- Wc_c="`wc -c < 'sfs/sfs/sfs_ft.c'`"
- test 4733 -eq "$Wc_c" ||
- echo 'sfs/sfs/sfs_ft.c: original size 4733, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/sfs/sfs_gt.c ==============
- if test -f 'sfs/sfs/sfs_gt.c' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/sfs/sfs_gt.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/sfs/sfs_gt.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_gt.c' &&
- /***************************************************************
- X
- X sfs_gt.c Ground Track Routines for SFS
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ***************************************************************/
- X
- #include "stdio.h"
- #include "ctype.h"
- #include "bw.h"
- #include "gr.h"
- #include "kb.h"
- #include "ui.h"
- #include "as.h"
- #include "sfs.h"
- X
- #ifdef __STDC__
- #include "stdlib.h"
- #endif
- X
- #define GT_DIVIDEND 4 /* Size of gt display on x should be this */
- #define GT_DIVISOR 2 /* ...divided by this (5/2 = 2.5 * y size */
- X
- static int gt_dready; /* Data ready */
- static int gt_xsize; /* Size of ground track map, x */
- static int gt_ysize; /* Size of ground track map, y */
- static int gt_mapbase; /* Bottom of gt map */
- static int gt_mapedge; /* Left edge of groundtrack map */
- X
- /***************************************************************
- X
- X gt_init()
- X
- X This function provides all necessary initialization
- X for the ground track system.
- X
- ***************************************************************/
- X
- gt_init( sorbit_array, orbit )
- X struct sfs_orbit **sorbit_array;
- X int orbit;
- X {
- X sorbit_array[ orbit ]->gt_bufstart
- X = sorbit_array[ orbit ]->gt_bufpos = 0;
- X gt_dready = FALSE;
- X }
- X
- /***************************************************************
- X
- X gt_update()
- X
- X This function updates the ground track circular buffer
- X by adding a new pair of latitude and longitude
- X coordinates to the buffer.
- X
- ***************************************************************/
- X
- gt_update( newtime, sorbit_array, n_orbits )
- X long newtime;
- X struct sfs_orbit **sorbit_array;
- X int n_orbits;
- X {
- X register int orbit;
- X static double lat, lon;
- X static long r, n;
- X
- X for ( orbit = 0; orbit < n_orbits; ++orbit )
- X {
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "DEBUG: update orbit %d", orbit );
- X bw_message( bw_ebuf );
- #endif
- X
- X if ( sorbit_array[ orbit ] != NULL )
- X {
- X or_ssp( sorbit_array[ orbit ]->aorbit, newtime, &lat, &lon, &r, &n );
- X sorbit_array[ orbit ]->gt_buffer[ sorbit_array[ orbit ]->gt_bufpos ][ 0 ] = lat;
- X sorbit_array[ orbit ]->gt_buffer[ sorbit_array[ orbit ]->gt_bufpos ][ 1 ] = lon;
- X ++sorbit_array[ orbit ]->gt_bufpos;
- X if ( sorbit_array[ orbit ]->gt_bufpos == GT_POINTS )
- X {
- X sorbit_array[ orbit ]->gt_bufpos = 0;
- X }
- X if ( sorbit_array[ orbit ]->gt_bufpos == sorbit_array[ orbit ]->gt_bufstart )
- X {
- X ++sorbit_array[ orbit ]->gt_bufstart;
- X if ( sorbit_array[ orbit ]->gt_bufstart == GT_POINTS )
- X {
- X sorbit_array[ orbit ]->gt_bufstart = 0;
- X }
- X }
- X } /* end if orbit != NULL */
- X } /* end for orbits loop */
- X gt_dready = TRUE;
- X
- #ifdef OLD_DEBUG
- X bw_debug( "Orbits updated" );
- #endif
- X }
- X
- /***************************************************************
- X
- X gt_draw()
- X
- X This function draws the ground track screen.
- X It is called by fo_draw().
- X
- ***************************************************************/
- X
- gt_draw( display, uiwind, focus, elements, redraw_screen,
- X s_start, s_end, sorbit_array, n_orbits )
- X struct sfs_display *display;
- X struct uiwindow *uiwind;
- X struct as_focus *focus; /* orbital focus to display */
- X unsigned int elements;
- X int redraw_screen;
- X struct spj_pt *s_start, *s_end;
- X struct sfs_orbit **sorbit_array;
- X int n_orbits;
- X {
- X register int orbit;
- X int x, y;
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "gt_draw(): %d %d %d %d", uiwind->u_x1, uiwind->u_y1,
- X uiwind->u_x2, uiwind->u_y2 );
- X bw_debug( bw_ebuf );
- #endif
- X
- X bw_message( GT_DRAW );
- X
- X if ( redraw_screen == TRUE )
- X {
- X
- X /* Prepare the screen */
- X
- X gt_prep( uiwind );
- X display->gt_xsize = gt_xsize;
- X display->gt_ysize = gt_ysize;
- X display->gt_mapbase = gt_mapbase;
- X display->gt_mapedge = gt_mapedge;
- X
- #ifdef OLD_DEBUG
- X bw_debug( "Ready to draw grid" );
- #endif
- X
- X /* Draw the surface features */
- X
- X gt_plot( s_start, s_end, cl_surface, SOLID );
- X
- X /* Display the point data if toggled */
- X
- #ifdef USEPOINTS
- X if ( ( elements & VI_POINTS ) > 0 )
- X {
- X gt_plot( p_start, p_end, cl_grid, SOLID );
- X }
- #endif
- X
- X /* Display the point titles if toggled */
- X
- #ifdef USEPOINTS
- X if ( ( elements & VI_PTITLES ) > 0 )
- X {
- X gt_titles( uiwind, p_start, p_end, cl_mback, cl_mfore );
- X }
- #endif
- X
- X /* Show toggle status */
- X
- X el_show( GR_PRIMARY, uiwind, elements );
- X
- X /* Title the screen */
- X
- X sprintf( bw_ebuf, GT_WTITLE,
- X focus->adjective );
- X ui_wtitle( uiwind, bw_ebuf );
- X
- X }
- X
- X else
- X {
- X gt_xsize = display->gt_xsize;
- X gt_ysize = display->gt_ysize;
- X gt_mapbase = display->gt_mapbase;
- X gt_mapedge = display->gt_mapedge;
- X }
- X
- X /* Show the ground track */
- X
- X for ( orbit = 0; orbit < n_orbits; ++orbit )
- X {
- X if ( ( sorbit_array[ orbit ] != NULL )
- X && ( sorbit_array[ orbit ]->aorbit->focus == focus ))
- X {
- X gt_track( sorbit_array, orbit, cl_orbits[ orbit % 6 ] );
- X } /* end if orbit != NULL */
- X } /* end for orbit loop */
- X
- X }
- X
- /***************************************************************
- X
- X gt_prep()
- X
- X This routine draws the panel at the bottom of the screen
- X which contains various parameters and is used when the
- X ground track display is in effect. The routine is called
- X by gt_draw().
- X
- ***************************************************************/
- X
- gt_prep( uiwind )
- X struct uiwindow *uiwind;
- X {
- X register int c;
- X int inc;
- X double x;
- X int x_xmax, x_ymax;
- X
- #ifdef OLD_DEBUG
- X bw_debug( "gt_prep(): enter" );
- #endif
- X
- X /*** Blank the entire window area */
- X
- X ui_fbox( uiwind->u_x1, uiwind->u_y1,
- X uiwind->u_x2, uiwind->u_y2, BLACK, SOLID );
- X
- X /*** First determine if x or y axis must be scaled */
- X
- X x_xmax = uiwind->u_x2 - uiwind->u_x1;
- X x_ymax = uiwind->u_y2 - uiwind->u_y1;
- X
- X if ( ( x_xmax / 2 ) >
- X ( ( x_ymax * gr_pysize ) / gr_pxsize )
- X )
- X
- X { /* TRUE = scale x */
- X
- #ifdef OLD_DEBUG
- X bw_debug( "Scaling x" );
- #endif
- X
- X gt_ysize = x_ymax;
- X gt_xsize = 2 * (( gt_ysize * gr_pysize ) / gr_pxsize );
- X
- X /*** Calculate gt_mapedge */
- X
- X gt_mapedge = uiwind->u_x1 +
- X ( ( x_xmax - gt_xsize ) / 2 );
- X
- X /*** Calculate gt_mapbase */
- X
- X gt_mapbase = uiwind->u_y1;
- X
- X /*** Draw lines demarcating the display within the window */
- X
- X gr_line( GR_PRIMARY, gt_mapedge, gt_mapbase, gt_mapedge,
- X uiwind->u_y2, cl_grid, SOLID );
- X
- X gr_line( GR_PRIMARY, gt_mapedge + gt_xsize, gt_mapbase,
- X gt_mapedge + gt_xsize, uiwind->u_y2,
- X cl_grid, SOLID );
- X
- X }
- X
- X else /* FALSE = scale y */
- X {
- X
- #ifdef OLD_DEBUG
- X bw_debug( "Scaling y" );
- #endif
- X
- X gt_xsize = x_xmax;
- X gt_ysize = (( gt_xsize * gr_pxsize ) / gr_pysize ) / 2;
- X
- X /*** Calculate gt_mapedge */
- X
- X gt_mapedge = uiwind->u_x1;
- X
- X /*** Calculate gt_mapbase */
- X
- X gt_mapbase = uiwind->u_y1 +
- X ( ( x_ymax - gt_ysize ) / 2 );
- X
- X /*** Draw lines demarcating the display within the window */
- X
- X gr_line( GR_PRIMARY, uiwind->u_x1, gt_mapbase, uiwind->u_x2,
- X gt_mapbase, cl_grid, SOLID );
- X
- X gr_line( GR_PRIMARY, uiwind->u_x1, gt_mapbase + gt_ysize,
- X uiwind->u_x2, gt_mapbase + gt_ysize,
- X cl_grid, SOLID );
- X
- X }
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "x_size %d, y_size %d, mapedge %d, mapbase %d",
- X gt_xsize, gt_ysize, gt_mapedge, gt_mapbase );
- X bw_debug( bw_ebuf );
- #endif
- X
- X /*** Now draw the latitude and longitude lines. We must draw
- X only a quarter of a line at a time, or gt_line will
- X reject the request. */
- X
- X for ( x = -75.0; x < 90.0; x += 15.0 ) /* latitudes */
- X {
- X gt_line( x, -180.0, x, -90.0, cl_grid, GRID );
- X gt_line( x, -90.0, x, 0.0, cl_grid, GRID );
- X gt_line( x, 0.0, x, 90.0, cl_grid, GRID );
- X gt_line( x, 90.0, x, 180.0, cl_grid, GRID );
- X }
- X
- X for ( x = -165.0; x < 180.0; x += 15.0 ) /* longitudes */
- X {
- X gt_line( -90.0, x, -45.0, x, cl_grid, GRID );
- X gt_line( -45.0, x, 0.0, x, cl_grid, GRID );
- X gt_line( 0.0, x, 45.0, x, cl_grid, GRID );
- X gt_line( 45.0, x, 90.0, x, cl_grid, GRID );
- X }
- X
- #ifdef OLD_DEBUG
- X bw_debug( "end of gt_prep() " );
- #endif
- X
- X }
- X
- /***************************************************************
- X
- X gt_plot()
- X
- X This routine plots a set of coordinates on the ground
- X track map. It is called by gt_draw().
- X
- ***************************************************************/
- X
- gt_plot( start, end, color, style )
- X struct spj_pt *start, *end;
- X int color, style;
- X {
- X struct spj_pt *current;
- X double prevx, prevy;
- X
- X current = start->next;
- X
- #ifdef OLD_DEBUG
- X bw_debug( "DEBUG: Plotting" );
- #endif
- X
- X prevx = current->longitude;
- X prevy = current->latitude;
- X while ( current != end )
- X {
- X if ( current->code < 1000 )
- X {
- X gt_line( current->latitude, current->longitude,
- X prevy, prevx, color, style );
- X }
- X prevx = current->longitude;
- X prevy = current->latitude;
- X current = current->next;
- X }
- X
- #ifdef OLD_DEBUG
- X bw_message( " " );
- #endif
- X }
- X
- gt_titles( uiwind, start, end, background, foreground )
- X struct uiwindow *uiwind;
- X struct spj_pt *start, *end;
- X int background, foreground;
- X {
- X struct spj_pt *current;
- X int x, y;
- X
- X /* Turn clipping on */
- X
- X gr_clip( GR_PRIMARY, TRUE, gt_mapedge, gt_mapbase,
- X gt_mapedge + gt_xsize, uiwind->u_y2 );
- X
- X current = start;
- X while( current != end )
- X {
- X x = ( current->longitude + 180.0 ) * ( gt_xsize / 360.0 );
- X y = ( current->latitude + 90.0 ) * ( gt_ysize / 180.0 );
- X x = gt_mapedge + x;
- X
- X gr_text( GR_PRIMARY,
- X x + 3,
- X y - ( ui_grwind->fysize / 2 ),
- X current->name, foreground, background );
- X
- X current = current->next;
- X }
- X
- X /* Turn clipping off */
- X
- X gr_clip( GR_PRIMARY, FALSE, 0, 0, 0, 0 );
- X
- X }
- X
- /***************************************************************
- X
- X gt_track()
- X
- X This routine draws the spacecraft ground-track path on
- X the ground track map. It is called by gt_draw().
- X
- ***************************************************************/
- X
- gt_track( sorbit_array, orbit, color )
- X struct sfs_orbit **sorbit_array;
- X int orbit, color;
- X {
- X int current;
- X
- X if ( gt_dready != TRUE )
- X {
- X bw_error( GTERR_NODATA );
- X return BW_ERROR;
- X }
- X
- X current = sorbit_array[ orbit ]->gt_bufstart + 1;
- X if ( current == GT_POINTS )
- X {
- X current = 0;
- X }
- X
- #ifdef OLD_DEBUG
- X bw_message( "DEBUG: Tracking " );
- #endif
- X
- X while ( current != sorbit_array[ orbit ]->gt_bufpos )
- X {
- X if ( current == 0 )
- X {
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "gt_track from x = %.2lf y = %.2lf, to x = %.2lf y = %.2lf, color = %d, style = %d,",
- X sorbit_array[ orbit ]->gt_buffer[ GT_POINTS - 1 ][ 0 ],
- X sorbit_array[ orbit ]->gt_buffer[ GT_POINTS - 1 ][ 1 ],
- X sorbit_array[ orbit ]->gt_buffer[ current ][ 0 ],
- X sorbit_array[ orbit ]->gt_buffer[ current ][ 1 ],
- X color, SOLID );
- X bw_debug( bw_ebuf );
- #endif
- X gt_line( sorbit_array[ orbit ]->gt_buffer[ GT_POINTS - 1 ][ 0 ],
- X sorbit_array[ orbit ]->gt_buffer[ GT_POINTS - 1 ][ 1 ],
- X sorbit_array[ orbit ]->gt_buffer[ current ][ 0 ],
- X sorbit_array[ orbit ]->gt_buffer[ current ][ 1 ],
- X color, SOLID );
- X }
- X else
- X {
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "gt_track from x = %.2lf y = %.2lf, to x = %.2lf y = %.2lf, color = %d, style = %d,",
- X sorbit_array[ orbit ]->gt_buffer[ current - 1 ][ 0 ],
- X sorbit_array[ orbit ]->gt_buffer[ current - 1 ][ 1 ],
- X sorbit_array[ orbit ]->gt_buffer[ current ][ 0 ],
- X sorbit_array[ orbit ]->gt_buffer[ current ][ 1 ],
- X color, SOLID );
- X bw_debug( bw_ebuf );
- #endif
- X gt_line( sorbit_array[ orbit ]->gt_buffer[ current - 1 ][ 0 ],
- X sorbit_array[ orbit ]->gt_buffer[ current - 1 ][ 1 ],
- X sorbit_array[ orbit ]->gt_buffer[ current ][ 0 ],
- X sorbit_array[ orbit ]->gt_buffer[ current ][ 1 ],
- X color, SOLID );
- X }
- X ++current;
- X if ( current == GT_POINTS )
- X {
- X current = 0;
- X }
- X }
- X
- X /* Now plot the forward track */
- X
- X ft_plot( sorbit_array, orbit );
- X
- X }
- X
- /***************************************************************
- X
- X gt_line()
- X
- X This routine draws a single line on the ground
- X track map.
- X
- ***************************************************************/
- X
- gt_line( fromlat, fromlon, tolat, tolon, color, style )
- X double fromlat, fromlon, tolat, tolon;
- X int color, style;
- X {
- X int x1, y1, x2, y2;
- X
- #ifdef DEBUG
- X if ( ( fromlat < -90.0 ) || ( fromlat > 90.0 ))
- X {
- X sprintf( bw_ebuf, "gt_line received from latitude %.2lf", fromlat );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( tolat < -90.0 ) || ( tolat > 90.0 ))
- X {
- X sprintf( bw_ebuf, "gt_line received to latitude %.2lf", tolat );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( fromlon < -180.0 ) || ( fromlon > 180.0 ))
- X {
- X sprintf( bw_ebuf, "gt_line received from longitude %.2lf", fromlon );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( tolon < -180.0 ) || ( tolon > 180.0 ))
- X {
- X sprintf( bw_ebuf, "gt_line received to longitude %.2lf", tolon );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "DEBUG from x = %.2lf, from y = %.2lf, to x = %.2lf, to y = %.2lf, color = %d, style = %d,",
- X fromlon,
- X fromlat,
- X tolon,
- X tolat,
- X color, style );
- X bw_debug( bw_ebuf );
- #endif
- X
- X x1 = (( fromlon + 180.0 ) * ( gt_xsize / 360.0 ));
- X x2 = (( tolon + 180.0 ) * ( gt_xsize / 360.0 ));
- X
- X if ( abs( x1 - x2 ) > ( gt_xsize / 3 ) )
- X {
- #ifdef OLD_DEBUG
- X sprintf( sfs_tbuf, "DEBUG: gt_line() failed: x1 = %d, x2 = %d",
- X x1, x2 );
- X bw_debug( sfs_tbuf );
- X sprintf( sfs_tbuf, "DEBUG: gt_line() #2: abs() = %d, gt_xsize = %d, gt_xsize / 3 = %d",
- X abs( x1 - x2), gt_xsize, (gt_xsize / 3) );
- X bw_debug( sfs_tbuf );
- #endif
- X return;
- X }
- X
- X y1 = (( fromlat + 90.0 ) * ( gt_ysize / 180.0 ));
- X y2 = (( tolat + 90.0 ) * ( gt_ysize / 180.0 ));
- X
- X if ( abs( y1 - y2 ) > ( gt_ysize / 3 ) )
- X {
- #ifdef OLD_DEBUG
- X sprintf( sfs_tbuf, "gt_line() failed: y1 = %d, y2 = %d",
- X y1, y2 );
- X bw_debug( sfs_tbuf );
- #endif
- X return;
- X }
- X
- #ifdef OLD_DEBUG
- X sprintf( sfs_tbuf, "DEBUG x1 = %d, y1 = %d, x2 = %d, y2 = %d, color = %d, style = %d,",
- X gt_mapedge + x1,
- X gt_mapbase + y1,
- X gt_mapedge + x2,
- X gt_mapbase + y2,
- X color, style );
- X bw_debug( sfs_tbuf );
- #endif
- X
- X gr_line( GR_PRIMARY,
- X gt_mapedge + x1,
- X gt_mapbase + y1,
- X gt_mapedge + x2,
- X gt_mapbase + y2,
- X color, style );
- X }
- SHAR_EOF
- chmod 0644 sfs/sfs/sfs_gt.c ||
- echo 'restore of sfs/sfs/sfs_gt.c failed'
- Wc_c="`wc -c < 'sfs/sfs/sfs_gt.c'`"
- test 15884 -eq "$Wc_c" ||
- echo 'sfs/sfs/sfs_gt.c: original size 15884, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/sfs/sfs_pe.c ==============
- if test -f 'sfs/sfs/sfs_pe.c' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/sfs/sfs_pe.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/sfs/sfs_pe.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_pe.c' &&
- /***************************************************************
- X
- X sfs_pe.c Distant Perspective Display Routines for
- X Space Flight Simulator
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ***************************************************************/
- X
- #include "stdio.h"
- #include "ctype.h"
- #include "bw.h"
- #include "gr.h"
- #include "kb.h"
- #include "ui.h"
- #include "as.h"
- #include "sfs.h"
- X
- #define USEHIDDEN /* use hidden buffer to draw perspective */
- #define PE_VLAT 0.0
- #define PE_VLON 0.0
- #define PE_ROT 0.0
- X
- /***************************************************************
- X
- X pe_calc()
- X
- ***************************************************************/
- X
- pe_calc( sorbit_array, n_orbits, poll )
- X struct sfs_orbit **sorbit_array;
- X int n_orbits;
- X int (*poll)();
- X {
- X register int orbit, c;
- X static double x_lat, x_lon;
- X double save_lif;
- X static long x_r, x_t, x_n;
- X
- X for ( orbit = 0; orbit < n_orbits; ++orbit )
- X {
- X
- X if ( sorbit_array[ orbit ] != NULL )
- X {
- X
- X sprintf( bw_ebuf, PE_CALC,
- X orbit + 1 );
- X bw_message( bw_ebuf );
- X
- X save_lif = sorbit_array[ orbit ]->aorbit->lif;
- X sorbit_array[ orbit ]->aorbit->lif = 0.0;
- X
- X sorbit_array[ orbit ]->pe_inc = sorbit_array[ orbit ]->aorbit->period / PE_POINTS;
- X
- X x_t = 1;
- X
- X for ( c = 0; c < PE_POINTS; ++c )
- X {
- X
- X or_ssp( sorbit_array[ orbit ]->aorbit, x_t,
- X &x_lat, &x_lon, &x_r, &x_n );
- X
- X sorbit_array[ orbit ]->pe_buffer[ c ].altitude = x_r;
- X sorbit_array[ orbit ]->pe_buffer[ c ].latitude = x_lat;
- X sorbit_array[ orbit ]->pe_buffer[ c ].longitude = x_lon;
- X
- X x_t += sorbit_array[ orbit ]->pe_inc;
- X
- X /* call poll function */
- X
- X (*poll) ();
- X
- X } /* end for point++ */
- X
- X sorbit_array[ orbit ]->aorbit->lif = save_lif;
- X
- X } /* end if orbit != NULL */
- X
- X } /* end while ++orbit */
- X } /* end of function
- X
- /***************************************************************
- X
- X pe_draw()
- X
- ***************************************************************/
- X
- pe_draw( uiwind, focus, sorbit_array, n_orbits, o_start, o_end, newtime, elements )
- X struct uiwindow *uiwind; /* ui window to draw in */
- X struct as_focus *focus; /* orbital focus to display */
- X struct sfs_orbit **sorbit_array; /* array of orbits */
- X int n_orbits; /* number of orbits in array */
- X struct spj_pt *o_start, *o_end; /* start, end orb display pattern */
- X long newtime; /* current time */
- X int elements; /* elements to draw */
- X {
- X register int orbit;
- X static double vlat, vlon, rotation;
- X static double distance;
- X static double vert_degrees; /* calculate vertical degrees */
- X double max_ap;
- X int l, c, selected;
- X int x_screen;
- X
- X /*** inform the viewer */
- X
- X bw_message( PE_DRAW );
- X
- X /*** initial screen setup */
- X
- #ifdef USEHIDDEN
- X if ( gr_screens > 1 )
- X {
- X x_screen = GR_HIDDEN;
- X }
- X else
- X {
- X x_screen = GR_PRIMARY;
- X }
- X ui_setscreen( x_screen );
- #else
- X x_screen = GR_PRIMARY;
- #endif
- X
- X /* calculate vertical degrees */
- X
- X vert_degrees = HORDEGS * ( ( ( uiwind->u_y2 - (double) uiwind->u_y1 )
- X * ( gr_pysize / (double) gr_pxsize ) )
- X / ( uiwind->u_x2 - (double) uiwind->u_x1 ) );
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "Vert degrees: %.0lf", vert_degrees );
- X bw_debug( bw_ebuf );
- #endif
- X
- X /* Clear the display area */
- X
- X ui_fbox( uiwind->u_x1, uiwind->u_y1,
- X uiwind->u_x2, uiwind->u_y2,
- X BLACK, SOLID );
- X
- X /* Calculate viewer latitude, longitude, rotation, and distance of display */
- X
- X vlat = PE_VLAT;
- X vlon = PE_VLON;
- X rotation = PE_ROT;
- X max_ap = 1.0;
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "pe_draw(): n_orbits %d", n_orbits );
- X bw_debug( bw_ebuf );
- #endif
- X
- X /* find the largest apoapsis among all selected orbits */
- X
- X selected = n_orbits + 1;
- X for ( orbit = 0; orbit < n_orbits; ++orbit )
- X {
- X if ( ( sorbit_array[ orbit ] != NULL )
- X && ( sorbit_array[ orbit ]->aorbit->focus == focus ))
- X {
- X
- X selected = orbit; /* make sure we find at least
- X one selected orbit */
- X if ( max_ap < sorbit_array[ orbit ]->aorbit->apoapsis )
- X {
- X max_ap = sorbit_array[ orbit ]->aorbit->apoapsis;
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "pe_draw(): orbit %d, apoapsis = %.2g km",
- X orbit,
- X sorbit_array[ orbit ]->aorbit->apoapsis );
- X bw_debug( bw_ebuf );
- #endif
- X }
- X } /* if orbit selected */
- X } /* for loop */
- X
- #ifdef DEBUG
- X if ( selected == ( n_orbits + 1 ) )
- X {
- X bw_error( "[pr:] pe_draw(): no orbits initialized" );
- X return BW_ERROR;
- X }
- #endif
- X
- X /* initial distance is max_ap plus focal radius */
- X
- X distance = max_ap + sorbit_array[ selected ]->aorbit->focus->radius;
- X
- X /* increase distance until the entire image will fit in the screen */
- X
- X while( spj_angrad( distance, max_ap + sorbit_array[ selected ]->aorbit->focus->radius )
- X > ( vert_degrees / 2.0 ) )
- X {
- X
- X distance *= 2.0;
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "pe_draw(): distance %.0lf km; ang. radius %.2lf deg",
- X distance, spj_angrad( distance, sorbit_array[ selected ]->aorbit->focus->radius ));
- X bw_debug( bw_ebuf );
- #endif
- X
- X }
- X
- X /* Show the orbits */
- X
- X pe_plot( x_screen, uiwind, sorbit_array, n_orbits, vlat, vlon, rotation,
- X distance, o_start, o_end, newtime, focus );
- X
- X /*** Show crosshairs */
- X
- #ifdef BLOCKEDOUT
- X pe_crosshair( uiwind, HORDEGS, x_screen );
- #endif
- X
- X /* Show toggle status */
- X
- X el_show( x_screen, uiwind, elements );
- X
- X /*** blit and return screen to original state */
- X
- #ifdef USEHIDDEN
- X if ( gr_screens > 1 )
- X {
- X gr_blit( GR_HIDDEN, GR_PRIMARY, uiwind->u_x1, uiwind->u_y1,
- X uiwind->u_x2, uiwind->u_y2 );
- X }
- X ui_setscreen( GR_PRIMARY );
- #endif
- X
- X /* Title the screen */
- X
- X sprintf( bw_ebuf, PE_WTITLE,
- X focus->name,
- X distance, sorbit_array[ selected ]->pe_inc );
- X ui_wtitle( uiwind, bw_ebuf );
- X
- X }
- X
- /***************************************************************
- X
- X pe_plot()
- X
- X This routine draws all orbits as they appear in space.
- X
- ***************************************************************/
- X
- pe_plot( screen, uiwind, sorbit_array, n_orbits, vlat, vlon, rotation, vdis,
- X o_start, o_end, newtime, focus )
- X int screen;
- X struct uiwindow *uiwind; /* ui window to draw in */
- X struct sfs_orbit **sorbit_array;
- X int n_orbits;
- X double vlat, vlon, rotation;
- X double vdis;
- X struct spj_pt *o_start, *o_end; /* start, end orb display pattern */
- X long newtime;
- X struct as_focus *focus;
- X {
- X register int orbit, c;
- X static double x, y;
- X static int v;
- X double prevx, prevy;
- X int prevv;
- X static struct uiwindow *oldwind = NULL; /* save window pointer to avoid recalculation */
- X static int x_midx, x_midy; /* x, y mid points of window */
- X static double x_xfactor, x_yfactor; /* factors for x, y expansion in window */
- X static double vert_degrees; /* calculate vertical degrees */
- X int selected;
- X long x_tio; /* time into orbit */
- X
- X /* set up the window if necessary */
- X
- X if ( uiwind != oldwind )
- X {
- X x_xfactor = ( uiwind->u_x2 - (double) uiwind->u_x1 ) / HORDEGS;
- X vert_degrees = HORDEGS * ( ( ( uiwind->u_y2 - (double) uiwind->u_y1 )
- X * ( gr_pysize / (double) gr_pxsize ) )
- X / ( uiwind->u_x2 - (double) uiwind->u_x1 ) );
- X x_yfactor = ( uiwind->u_y2 - (double) uiwind->u_y1 ) / vert_degrees;
- X x_midx = uiwind->u_x1 + (( uiwind->u_x2 - (double) uiwind->u_x1 ) / 2.0 );
- X x_midy = uiwind->u_y1 + (( uiwind->u_y2 - (double) uiwind->u_y1 ) / 2.0 );
- X oldwind = uiwind;
- X }
- X
- X /* Show the far side of each orbit */
- X
- X selected = n_orbits + 1;
- X for ( orbit = 0; orbit < n_orbits; ++orbit )
- X {
- X if ( ( sorbit_array[ orbit ] != NULL )
- X && ( sorbit_array[ orbit ]->aorbit->focus == focus ))
- X {
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "Draw far side, orbit %d", orbit );
- X bw_debug( bw_ebuf );
- #endif
- X selected = orbit;
- X x_tio = newtime % (long) sorbit_array[ orbit ]->aorbit->period;
- X pe_show( screen, sorbit_array, orbit, x_tio,
- X vlat, vlon, vdis, rotation,
- X x_xfactor, x_yfactor, x_midx, x_midy,
- X SPJ_FARSIDE, cl_orbits[ orbit % 6 ], SOLID );
- X }
- X }
- X
- X /* Show the orb of the planet */
- X
- X pe_orb( uiwind, screen,
- X sorbit_array[ selected ]->aorbit->focus->radius,
- X vdis, cl_grid, x_midx, x_midy, x_xfactor, x_yfactor );
- X
- X /* Now show the near side of each orbit */
- X
- X for ( orbit = 0; orbit < n_orbits; ++orbit )
- X {
- X if ( ( sorbit_array[ orbit ] != NULL )
- X && ( sorbit_array[ orbit ]->aorbit->focus == focus ))
- X {
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "Draw near side, orbit %d", orbit );
- X bw_debug( bw_ebuf );
- #endif
- X x_tio = newtime % (long) sorbit_array[ orbit ]->aorbit->period;
- X pe_show( screen, sorbit_array, orbit, x_tio,
- X vlat, vlon, vdis, rotation,
- X x_xfactor, x_yfactor, x_midx, x_midy,
- X SPJ_NEARSIDE, cl_orbits[ orbit % 6 ], SOLID );
- X }
- X }
- X
- X }
- X
- /***************************************************************
- X
- X pe_show()
- X
- X This routine draws the front or back side of a specific
- X orbit as it appears in space.
- X
- ***************************************************************/
- X
- pe_show( screen, sorbit_array, orbit, tio, vlat, vlon, vdis, rotation,
- X xfactor, yfactor, midx, midy,
- X side, color, style )
- X int screen;
- X struct sfs_orbit **sorbit_array;
- X int orbit;
- X long tio;
- X double vlat, vlon, vdis, rotation;
- X double xfactor, yfactor;
- X int midx, midy;
- X int side;
- X int color, style;
- X {
- X register int c;
- X static double x, y;
- X double prevx, prevy;
- X static int s;
- X int x_noline;
- X
- X spj_point( sorbit_array[ orbit ]->pe_buffer[ 0 ].latitude,
- X sorbit_array[ orbit ]->pe_buffer[ 0 ].longitude,
- X sorbit_array[ orbit ]->pe_buffer[ 0 ].altitude,
- X vlat, vlon, vdis, rotation, side,
- X &x, &y, &s );
- X prevx = x;
- X prevy = y;
- X x_noline = TRUE;
- X
- X c = 0;
- X while ( c < PE_POINTS )
- X {
- X
- X s = 255;
- X
- X /* Get coordinates for the point */
- X
- X spj_point( sorbit_array[ orbit ]->pe_buffer[ c ].latitude,
- X sorbit_array[ orbit ]->pe_buffer[ c ].longitude,
- X sorbit_array[ orbit ]->pe_buffer[ c ].altitude,
- X vlat, vlon, vdis, rotation, side,
- X &x, &y, &s );
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "sp_show(): x = %.2lf, prevx = %.2lf, y = %.2lf, prevy = %.2lf",
- X x, prevx, y, prevy );
- X bw_debug( bw_ebuf );
- #endif
- X
- X /* show the point */
- X
- X if ( s == side )
- X {
- X if ( ( ( c * sorbit_array[ orbit ]->pe_inc ) < tio )
- X && ( x_noline != TRUE ) )
- X {
- X gr_line( screen,
- X midx + ( (int) ( x * xfactor )),
- X midy + ( (int) ( y * yfactor )),
- X midx + ( (int) ( prevx * xfactor )),
- X midy + ( (int) ( prevy * yfactor )),
- X color, SOLID );
- X x_noline = FALSE;
- X }
- X else
- X {
- X gr_pixel( screen,
- X midx + ( (int) ( x * xfactor )),
- X midy + ( (int) ( y * yfactor )),
- X color );
- X x_noline = FALSE;
- X }
- X }
- X
- X /* point is not on the side selected; thus set x_noline */
- X
- X else
- X {
- X x_noline = TRUE;
- X }
- X
- X /* save x and y values and increment the counter */
- X
- X prevx = x;
- X prevy = y;
- X ++c;
- X }
- X
- X }
- X
- /***************************************************************
- X
- X pe_orb()
- X
- X This routine draws the orb of the planet for the
- X distant perspective display.
- X
- ***************************************************************/
- X
- pe_orb( uiwind, screen, radius, distance, color, midx, midy,
- X xfactor, yfactor )
- X struct uiwindow *uiwind; /* ui window to draw in */
- X int screen;
- X double radius, distance;
- X int color;
- X int midx, midy;
- X double xfactor, yfactor;
- X {
- X double x_angrad; /* angular radius */
- X int x_yrad; /* radius on y axis */
- X
- X /*** 1. Calculate angular radius and y axis radius */
- X
- X x_angrad = spj_angrad( distance, radius );
- X x_yrad = (int) ( x_angrad * yfactor );
- X
- #ifdef DEBUG
- X if ( x_yrad < 1 )
- X {
- X sprintf( bw_ebuf, "pe_orb(): x_yrad = %d", x_yrad );
- X bw_error( bw_ebuf );
- X }
- #endif
- X
- X /*** 1. Blank the orb area */
- X
- X gr_circle( screen, midx, midy, x_yrad, WHITE, SOLID );
- X gr_circle( screen, midx, midy, x_yrad, BLACK, SOLID );
- X
- X /*** 2. Show the orb outline */
- X
- X gr_circle( screen, midx, midy, x_yrad, color, HOLLOW );
- X
- X }
- X
- pe_crosshair( uiwind, hor_deg, screen )
- X struct uiwindow *uiwind; /* ui window for display */
- X double hor_deg; /* degrees of horizontal axis */
- X int screen; /* screen to draw to */
- X {
- X static double vert_degrees; /* calculate vertical degrees */
- X int x_midx, x_midy; /* mid points of x, y axes */
- X register int x_deg; /* counter for degrees */
- X int x_xsize, x_ysize; /* total x and y sizes of display */
- X
- X /* calculate vertical degrees */
- X
- X vert_degrees = hor_deg * ( ( ( uiwind->u_y2 - (double) uiwind->u_y1 )
- X * ( gr_pysize / (double) gr_pxsize ) )
- X / ( uiwind->u_x2 - (double) uiwind->u_x1 ) );
- X
- X /* calculate mid points */
- X
- X x_midx = uiwind->u_x1 + (( uiwind->u_x2 - (double) uiwind->u_x1 ) / 2.0 );
- X x_midy = uiwind->u_y1 + (( uiwind->u_y2 - (double) uiwind->u_y1 ) / 2.0 );
- X x_xsize = uiwind->u_x2 - uiwind->u_x1;
- X x_ysize = uiwind->u_y2 - uiwind->u_y1;
- X
- X /* show vertical crosshairs */
- X
- X gr_line( screen, x_midx, uiwind->u_y1, x_midx, uiwind->u_y2,
- X cl_marker, GRID );
- X for ( x_deg = 10; x_deg < ( hor_deg / 2 ); x_deg += 10 )
- X {
- X gr_line( screen,
- X (int) ( x_midx + (( x_deg * x_xsize ) / hor_deg )),
- X uiwind->u_y1,
- X (int) ( x_midx + (( x_deg * x_xsize ) / hor_deg )),
- X uiwind->u_y2,
- X cl_marker, GRID );
- X gr_line( screen,
- X (int) ( x_midx - (( x_deg * x_xsize ) / hor_deg )),
- X uiwind->u_y1,
- X (int) ( x_midx - (( x_deg * x_xsize ) / hor_deg )),
- X uiwind->u_y2,
- X cl_marker, GRID );
- X }
- X
- X /* show horizontal crosshairs */
- X
- X gr_line( screen, uiwind->u_x1, x_midy, uiwind->u_x2, x_midy,
- X cl_marker, GRID );
- X for ( x_deg = 10; x_deg < ( vert_degrees / 2 ); x_deg += 10 )
- X {
- X gr_line( screen,
- X uiwind->u_x1,
- X (int) ( x_midy + (( x_deg * x_ysize ) / vert_degrees )),
- X uiwind->u_x2,
- X (int) ( x_midy + (( x_deg * x_ysize ) / vert_degrees )),
- X cl_marker, GRID );
- X gr_line( screen,
- X uiwind->u_x1,
- X (int) ( x_midy - (( x_deg * x_ysize ) / vert_degrees )),
- X uiwind->u_x2,
- X (int) ( x_midy - (( x_deg * x_ysize ) / vert_degrees )),
- X cl_marker, GRID );
- X }
- X
- X }
- X
- X
- /***************************************************************
- X
- X el_toggle() Toggle Simulation Elements
- X
- ***************************************************************/
- X
- el_toggle( command, elements )
- X int command; /* command (letter) entered */
- X int *elements; /* pointer to simulation elements */
- X {
- X register int c;
- X
- X c = toupper( command );
- X
- X switch( c )
- X {
- X case 'O':
- X if ( ( *elements & VI_ORBOUTLINE ) > 0 )
- X {
- X *elements &= ~( VI_ORBOUTLINE );
- X }
- X else
- X {
- X *elements |= VI_ORBOUTLINE;
- X }
- X break;
- X case 'C':
- X if ( ( *elements & VI_CROSSH ) > 0 )
- X {
- X *elements &= ~( VI_CROSSH );
- X }
- X else
- X {
- X *elements |= VI_CROSSH;
- X }
- X break;
- X case 'G':
- X if ( ( *elements & VI_GRIDFRONT ) > 0 )
- X {
- X *elements = (*elements) & ~( VI_GRIDFRONT );
- X }
- X else
- X {
- X *elements = (*elements) | VI_GRIDFRONT;
- X }
- X break;
- X case 'S':
- X if ( ( *elements & VI_SURFRONT ) > 0 )
- X {
- X *elements &= ~( VI_SURFRONT );
- X }
- X else
- X {
- X *elements |= VI_SURFRONT;
- X }
- X break;
- X }
- X }
- X
- /***************************************************************
- X
- X el_show() Show Toggle Elements
- X
- ***************************************************************/
- X
- el_show( screen, uiwind, elements )
- X int screen;
- X struct uiwindow *uiwind;
- X unsigned int elements;
- X {
- X char x_buf[ 64 ];
- X int x, y, l;
- X
- X /* calculate initial position of display streng */
- X
- X sprintf( x_buf, "%s: MMMMM", SFS_TOGGLE );
- X l = gr_strlen( x_buf );
- X x = uiwind->u_x2 - ( l + 2 );
- X y = uiwind->u_y2 - ( ui_grwind->fysize + 2 );
- X
- X /* blank the area */
- X
- X gr_rectangle( screen, x - 2, y - 1, x + l, y + ui_grwind->fysize + 1,
- X cl_mback, SOLID );
- X
- X /* display string without toggles */
- X
- X sprintf( x_buf, "%s: ", SFS_TOGGLE );
- X gr_text( screen, x, y, x_buf, cl_mfore, cl_mback );
- X
- X /* increment x to first toggle position */
- X
- X l = gr_strlen( x_buf );
- X x += l;
- X
- X /* show grid toggle status */
- X
- X if ( ( elements & VI_GRIDFRONT ) > 0 )
- X {
- X gr_text( screen, x, y, "G", cl_mfore, cl_mback );
- X }
- X else
- X {
- X gr_text( screen, x, y, "G", cl_mback, cl_mfore );
- X }
- X
- X /* increment x to next character position */
- X
- X x += gr_strlen( "G" ) + 2;
- X
- X /* show surface toggle status */
- X
- X if ( ( elements & VI_SURFRONT ) > 0 )
- X {
- X gr_text( screen, x, y, "S", cl_mfore, cl_mback );
- X }
- X else
- X {
- X gr_text( screen, x, y, "S", cl_mback, cl_mfore );
- X }
- X
- X /* increment x to next character position */
- X
- X x += gr_strlen( "S" ) + 2;
- X
- X /* show orb toggle status */
- X
- X if ( ( elements & VI_ORBOUTLINE ) > 0 )
- X {
- X gr_text( screen, x, y, "O", cl_mfore, cl_mback );
- X }
- X else
- X {
- X gr_text( screen, x, y, "O", cl_mback, cl_mfore );
- X }
- X
- X /* increment x to next character position */
- X
- X x += gr_strlen( "O" ) + 2;
- X
- X /* show crosshair toggle status */
- X
- X if ( ( elements & VI_CROSSH ) > 0 )
- X {
- X gr_text( screen, x, y, "C", cl_mfore, cl_mback );
- X }
- X else
- X {
- X gr_text( screen, x, y, "C", cl_mback, cl_mfore );
- X }
- X
- X }
- X
- X
- SHAR_EOF
- chmod 0644 sfs/sfs/sfs_pe.c ||
- echo 'restore of sfs/sfs/sfs_pe.c failed'
- Wc_c="`wc -c < 'sfs/sfs/sfs_pe.c'`"
- test 19001 -eq "$Wc_c" ||
- echo 'sfs/sfs/sfs_pe.c: original size 19001, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/sfs/sfs_pr.c ==============
- if test -f 'sfs/sfs/sfs_pr.c' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/sfs/sfs_pr.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/sfs/sfs_pr.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_pr.c' &&
- /***************************************************************
- X
- X sfs_pr.c Program Interpreter for
- X Space Flight Simulator
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ***************************************************************/
- X
- #include "stdio.h"
- #include "time.h"
- #include "ctype.h"
- #include "bw.h"
- #include "gr.h"
- #include "kb.h"
- #include "ui.h"
- #include "as.h"
- #include "sfs.h"
- X
- #ifdef __STDC__
- #include "malloc.h"
- #include "stdlib.h"
- #else
- extern char * malloc();
- #define size_t int
- #define time_t long
- #endif
- X
- #define FDFILESIZE 128
- #define FILE_DELIMITER ";---------------------------------------\n"
- X
- extern double atof();
- extern int atoi();
- extern long atol();
- extern struct as_focus * pr_getfd();
- extern char *fntolc();
- X
- #define MAXARGS 4
- X
- static char arguments[ MAXARGS ][ 64 ];
- X
- sfs_pr( filename, pr_name, sorbit_array, n_orbits )
- X char *filename; /* name of program file */
- X char *pr_name; /* buffer for program name */
- X struct sfs_orbit **sorbit_array; /* pointer to array of sfs orbit structures */
- X int n_orbits; /* number of orbit structures in arrays */
- X {
- X FILE *data;
- X static char buffer[ 128 ];
- X register int orbit;
- X static char fdfile[ FDFILESIZE ];
- X
- X /* set up a default focal data file */
- X
- X strcpy( fdfile, DEFAULTFD ); /* default focal data file */
- X
- X /* deallocate any allocated orbit memory */
- X
- X for ( orbit = 0; orbit < n_orbits; ++orbit )
- X {
- X if ( sorbit_array[ orbit ] != NULL )
- X {
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "Freeing memory for orbit %d", orbit );
- X bw_debug( bw_ebuf );
- #endif
- X
- X free( sorbit_array[ orbit ]->aorbit->focus->name );
- X free( sorbit_array[ orbit ]->aorbit->focus->adjective );
- X free( sorbit_array[ orbit ]->aorbit->focus->fdfile );
- X free( sorbit_array[ orbit ]->aorbit->focus );
- X free( sorbit_array[ orbit ]->aorbit );
- X free( sorbit_array[ orbit ]->name );
- X free( sorbit_array[ orbit ] );
- X sorbit_array[ orbit ] = NULL;
- X }
- X }
- X
- X /* Open the program file */
- X
- X if ( ( data = fopen( filename, "rb" )) == NULL )
- X {
- X sprintf( bw_ebuf, PRERR_OPEN, filename );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X
- X /* Get the program name -- always first line of file */
- X
- X as_fgets( pr_name, 127, data );
- X pr_stripcr( pr_name );
- X
- X /* Inform the viewer */
- X
- X sprintf( bw_ebuf, PR_NOTICE,
- X filename, pr_name );
- X bw_message( bw_ebuf );
- X
- X /* Parse each line of the file */
- X
- X while( feof( data ) == FALSE )
- X {
- X as_fgets( buffer, 127, data );
- X if ( feof( data ) == FALSE )
- X {
- X pr_parse( buffer, fdfile, sorbit_array, n_orbits );
- SHAR_EOF
- true || echo 'restore of sfs/sfs/sfs_pr.c failed'
- fi
- echo 'End of part 18'
- echo 'File sfs/sfs/sfs_pr.c is continued in part 19'
- echo 19 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-