diff options
author | Simon Rettberg | 2020-12-02 08:23:52 +0100 |
---|---|---|
committer | Simon Rettberg | 2020-12-02 08:23:52 +0100 |
commit | 2954208d00d422b34fa3a69631b0a091f17a349d (patch) | |
tree | b4322e320155656af133b8f47025d00b17a68f64 | |
parent | Update to 5.43 (diff) | |
download | xscreensaver-2954208d00d422b34fa3a69631b0a091f17a349d.tar.gz xscreensaver-2954208d00d422b34fa3a69631b0a091f17a349d.tar.xz xscreensaver-2954208d00d422b34fa3a69631b0a091f17a349d.zip |
5.44
82 files changed, 7663 insertions, 1258 deletions
diff --git a/Makefile.in b/Makefile.in index e0795b2..52f1b4f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -69,6 +69,10 @@ tar:: rm -f configure ; \ $(MAKE2) configure ; \ $(MAKE2) version-date distdepend ; \ + $(MAKE2) _tar + +_tar: + @ \ VERS=`sed -n 's/[^0-9]*\([0-9]\.[0-9][^. ]*\).*/\1/p' utils/version.h` ; \ NAME="xscreensaver-$$VERS" ; \ rm -rf $$NAME ; ln -s . $$NAME ; \ @@ -46,6 +46,20 @@ XScreenSaver has an extensive manual -- please read it! =============================================================================== +5.44 * New hacks, `gibson', `etruscanvenus' and `scooter'. + * BSOD supports Tivo and Nintendo. + * New color options in `romanboy', `projectiveplane', `hypertorus' + and `klein'. + * macOS: Fixed "Use random screen saver" on macOS 10.15. + * iOS: Supports dark mode. + * iOS: Fixed image loading on iOS 13. + * iOS: Fixed rotation on iOS 13 (Apple incompatibly breaks rotation + every two years as a matter of policy). + * Performance tweaks for `eruption', `fireworkx', `halftone', `halo', + `moire2', `rd-bomb'. + * X11: Always use $HOME/.xscreensaver, not getpwuid's directory. + * Various bug fixes. + 5.43 * New hacks, `GravityWell', `DeepStars'. * GLPlanet now supports the Mercator projection. * Bouncing Cow has mathematically ideal cows (spherical, frictionless). diff --git a/README.hacking b/README.hacking index 451aec1..f2958b4 100644 --- a/README.hacking +++ b/README.hacking @@ -90,7 +90,7 @@ The XScreenSaver API state machine. You may not store global state in global variables, or in function-local - static variables. All of your runtime state must be encapsulted in the + static variables. All of your runtime state must be encapsulated in the "state" object created by your "init" function. If you use global or static variables, your screen saver will not work properly on macOS. diff --git a/driver/Makefile.in b/driver/Makefile.in index 4ca00b6..7baf504 100644 --- a/driver/Makefile.in +++ b/driver/Makefile.in @@ -301,7 +301,7 @@ install-program: $(EXES) echo $$inst xscreensaver $(install_prefix)$(bindir)/xscreensaver ; \ $$inst xscreensaver $(install_prefix)$(bindir)/xscreensaver @for exe in xscreensaver-command xscreensaver-demo \ - xscreensaver-getimage @EXES_OSX@ ; do \ + xscreensaver-getimage @EXES_OSX@ @EXES_SYSTEMD@ ; do \ echo $(INSTALL_PROGRAM) $$exe $(install_prefix)$(bindir)/$$exe ; \ $(INSTALL_PROGRAM) $$exe $(install_prefix)$(bindir)/$$exe ; \ done @@ -633,7 +633,9 @@ clean: distclean: clean -rm -f Makefile XScreenSaver.ad \ - TAGS *~ "#"* screensaver-properties.desktop + TAGS *~ "#"* screensaver-properties.desktop \ + xscreensaver-demo.glade2 \ + xscreensaver.pam # Adds all current dependencies to Makefile depend: XScreenSaver_ad.h XScreenSaver_Xm_ad.h @@ -651,9 +653,10 @@ distdepend: check_men update_ad_version XScreenSaver_ad.h XScreenSaver_Xm_ad.h $(DEPEND) -w 0 -f - \ -s '# DO NOT DELETE: updated by make distdepend' $(DEPEND_FLAGS) -- \ $(INCLUDES_1) $(DEFS) $(DEPEND_DEFINES) $(CFLAGS) $(X_CFLAGS) -- \ - $(SAVER_SRCS_1) $(MOTIF_SRCS) $(GTK_SRCS) $(GETIMG_SRCS_1) \ - $(PWENT_SRCS) $(LOCK_SRCS_1) $(DEMO_SRCS_1) $(CMD_SRCS) \ - $(SYSTEMD_SRCS) $(TEST_SRCS) 2>/dev/null | \ + $(SAVER_SRCS_1) $(SYSTEMD_SRCS) $(MOTIF_SRCS) $(GTK_SRCS) \ + $(PWENT_SRCS) $(PWHELPER_SRCS) $(KERBEROS_SRCS) $(PAM_SRCS) \ + $(LOCK_SRCS_1) $(DEMO_SRCS_1) $(CMD_SRCS) $(GETIMG_SRCS_1) \ + $(PDF2JPEG_SRCS) $(TEST_SRCS) 2>/dev/null | \ sort -d | \ ( \ awk '/^# .*Makefile.in ---/,/^# DO .*distdepend/' < Makefile.in ; \ @@ -866,7 +869,7 @@ test-mlstring.o: mlstring.c test-mlstring: test-mlstring.o $(CC) -DTEST $(LDFLAGS) -o $@ test-mlstring.o $(SAVER_LIBS) -TEST_FADE_OBJS = test-fade.o $(UTILS_SRC)/fade.o $(DEMO_UTIL_OBJS) +TEST_FADE_OBJS = test-fade.o $(UTILS_BIN)/fade.o $(DEMO_UTIL_OBJS) test-fade: test-fade.o $(UTILS_BIN)/fade.o $(CC) $(LDFLAGS) -o $@ $(TEST_FADE_OBJS) $(SAVER_LIBS) @@ -923,11 +926,19 @@ lock.o: $(srcdir)/types.h lock.o: $(UTILS_SRC)/resources.h lock.o: $(srcdir)/xscreensaver.h mlstring.o: $(srcdir)/mlstring.h +passwd-helper.o: ../config.h +passwd-helper.o: $(srcdir)/prefs.h +passwd-helper.o: $(srcdir)/types.h +passwd-helper.o: $(srcdir)/xscreensaver.h +passwd-kerberos.o: ../config.h passwd.o: $(srcdir)/auth.h passwd.o: ../config.h passwd.o: $(srcdir)/prefs.h passwd.o: $(srcdir)/types.h passwd.o: $(srcdir)/xscreensaver.h +passwd-pam.o: $(srcdir)/auth.h +passwd-pam.o: ../config.h +passwd-pam.o: $(srcdir)/types.h passwd-pwent.o: ../config.h prefs.o: ../config.h prefs.o: $(srcdir)/prefs.h diff --git a/driver/XScreenSaver.ad.in b/driver/XScreenSaver.ad.in index 5deb334..cfdd1a2 100644 --- a/driver/XScreenSaver.ad.in +++ b/driver/XScreenSaver.ad.in @@ -4,8 +4,8 @@ ! a screen saver and locker for the X window system ! by Jamie Zawinski ! -! version 5.43 -! 09-Jul-2019 +! version 5.44 +! 20-Mar-2020 ! ! See "man xscreensaver" for more info. The latest version is always ! available at https://www.jwz.org/xscreensaver/ @@ -323,7 +323,7 @@ XScreenSaver.bourneShell: /bin/sh *passwd.user.label: Username: *splash.heading.label: XScreenSaver %s -*splash.body.label: Copyright \251 1991-2019 by +*splash.body.label: Copyright \251 1991-2020 by *splash.body2.label: Jamie Zawinski <jwz@jwz.org> *splash.demo.label: Settings *splash.help.label: Help @@ -445,6 +445,7 @@ XScreenSaver.bourneShell: /bin/sh @GL_KLUDGE@ GL: menger -root \n\ @GL_KLUDGE@ GL: molecule -root \n\ rotzoomer -root \n\ + scooter -root \n\ speedmine -root \n\ @GL_KLUDGE@ GL: starwars -root \n\ @GL_KLUDGE@ GL: stonerview -root \n\ @@ -577,7 +578,9 @@ XScreenSaver.bourneShell: /bin/sh @GL_KLUDGE@ GL: razzledazzle -root \n\ vfeedback -root \n\ @GL_KLUDGE@ GL: deepstars -root \n\ -@GL_KLUDGE@ GL: gravitywell -root \n +@GL_KLUDGE@ GL: gravitywell -root \n\ +@GL_KLUDGE@ GL: etruscanvenus -root \n\ +@GL_KLUDGE@ GL: gibson -root \n @@ -613,6 +616,7 @@ XScreenSaver.bourneShell: /bin/sh *hacks.dnalogo.name: DNA Logo *hacks.dymaxionmap.name: DymaxionMap *hacks.energystream.name: EnergyStream +*hacks.etruscanvenus.name: EtruscanVenus *hacks.euler2d.name: Euler2D *hacks.fadeplot.name: FadePlot *hacks.filmleader.name: FilmLeader diff --git a/driver/demo-Gtk.c b/driver/demo-Gtk.c index be4a238..da98c53 100644 --- a/driver/demo-Gtk.c +++ b/driver/demo-Gtk.c @@ -1,5 +1,5 @@ /* demo-Gtk.c --- implements the interactive demo-mode and options dialogs. - * xscreensaver, Copyright (c) 1993-2019 Jamie Zawinski <jwz@jwz.org> + * xscreensaver, Copyright (c) 1993-2020 Jamie Zawinski <jwz@jwz.org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -550,7 +550,10 @@ warning_dialog (GtkWidget *parent, const char *message, if (!parent || !GET_WINDOW (parent)) /* too early to pop up transient dialogs */ { - fprintf (stderr, "%s: too early for dialog?\n", progname); + fprintf (stderr, + "%s: too early for warning dialog?" + "\n\n\t%s\n\n", + progname, message); free(msg); return False; } @@ -1043,7 +1046,9 @@ await_xscreensaver (state *s) strcat (buf, STFU _("You are running as root. This usually means that xscreensaver\n" "was unable to contact your X server because access control is\n" - "turned on. Try running this command:\n" + "turned on." +/* + " Try running this command:\n" "\n" " xhost +localhost\n" "\n" @@ -1053,9 +1058,10 @@ await_xscreensaver (state *s) "on to this machine to access your screen, which might be\n" "considered a security problem. Please read the xscreensaver\n" "manual and FAQ for more information.\n" + */ "\n" "You shouldn't run X as root. Instead, you should log in as a\n" - "normal user, and `su' as necessary.")); + "normal user, and `sudo' as necessary.")); else strcat (buf, _("Please check your $PATH and permissions.")); @@ -4422,7 +4428,8 @@ kde_screensaver_active_p (void) FILE *p = popen ("dcop kdesktop KScreensaverIface isEnabled 2>/dev/null", "r"); char buf[255]; - fgets (buf, sizeof(buf)-1, p); + if (!p) return False; + if (!fgets (buf, sizeof(buf)-1, p)) return False; pclose (p); if (!strcmp (buf, "true\n")) return True; @@ -4433,7 +4440,11 @@ kde_screensaver_active_p (void) static void kill_kde_screensaver (void) { - system ("dcop kdesktop KScreensaverIface enable false"); + /* Use empty body to kill warning from gcc -Wall with + "warning: ignoring return value of 'system', + declared with attribute warn_unused_result" + */ + if (system ("dcop kdesktop KScreensaverIface enable false")) {} } diff --git a/driver/lock.c b/driver/lock.c index 7696f30..d36481e 100644 --- a/driver/lock.c +++ b/driver/lock.c @@ -1400,6 +1400,8 @@ destroy_passwd_window (saver_info *si) memset (pw, 0, sizeof(*pw)); free (pw); si->pw_data = 0; + + si->unlock_dismiss_time = time((time_t *) 0); } @@ -2216,6 +2218,7 @@ Bool unlock_p (saver_info *si) { saver_preferences *p = &si->prefs; + time_t now = time ((time_t *) 0); if (!si->unlock_cb) { @@ -2225,6 +2228,18 @@ unlock_p (saver_info *si) raise_window (si, True, True, True); + /* If your cat is sitting on the return key, don't thrash the window. + Only one failed/cancelled unlock per 2 seconds. + */ + if (si->unlock_dismiss_time >= now - 1) + { + if (p->verbose_p) + fprintf (stderr, "%s: unlock: thrashing: RET held down?\n", blurb()); + XSync (si->dpy, False); +# undef sleep + sleep (2); /* This is less than ideal, but fine */ + } + xss_authenticate(si, p->verbose_p); return (si->unlock_state == ul_success); diff --git a/driver/passwd.c b/driver/passwd.c index f443726..68e1a0b 100644 --- a/driver/passwd.c +++ b/driver/passwd.c @@ -1,5 +1,5 @@ /* passwd.c --- verifying typed passwords with the OS. - * xscreensaver, Copyright (c) 1993-2018 Jamie Zawinski <jwz@jwz.org> + * xscreensaver, Copyright (c) 1993-2019 Jamie Zawinski <jwz@jwz.org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -251,7 +251,7 @@ do_syslog (saver_info *si, Bool verbose_p) { # ifdef HAVE_SYSLOG struct passwd *pw = getpwuid (getuid ()); - char *d = DisplayString (si->dpy); + char *d = (si->dpy ? DisplayString (si->dpy) : 0); char *u = (pw && pw->pw_name ? pw->pw_name : "???"); int opt = 0; int fac = 0; @@ -324,8 +324,9 @@ xss_authenticate(saver_info *si, Bool verbose_p) si->cached_passwd && !*si->cached_passwd) { - fprintf (stderr, "%s: assuming null password means cancel.\n", - blurb()); + if (verbose_p) + fprintf (stderr, "%s: assuming null password means cancel.\n", + blurb()); si->unlock_state = ul_cancel; } @@ -354,11 +355,11 @@ xss_authenticate(saver_info *si, Bool verbose_p) { /* If any auth method gets a cancel or timeout, don't try the next auth method! We're done! */ - fprintf (stderr, - "%s: authentication via %s %s.\n", - blurb(), methods[i].name, - (si->unlock_state == ul_cancel - ? "cancelled" : "timed out")); + if (verbose_p) + fprintf (stderr, "%s: authentication via %s %s.\n", + blurb(), methods[i].name, + (si->unlock_state == ul_cancel + ? "cancelled" : "timed out")); goto DONE; } } diff --git a/driver/prefs.c b/driver/prefs.c index 8fb029e..94e7a0c 100644 --- a/driver/prefs.c +++ b/driver/prefs.c @@ -1,5 +1,5 @@ /* dotfile.c --- management of the ~/.xscreensaver file. - * xscreensaver, Copyright (c) 1998-2018 Jamie Zawinski <jwz@jwz.org> + * xscreensaver, Copyright (c) 1998-2020 Jamie Zawinski <jwz@jwz.org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -136,33 +136,34 @@ init_file_name (void) if (!file) { uid_t uid = getuid (); - struct passwd *p = getpwuid (uid); + const char *home = getenv("HOME"); - if (i_am_a_nobody (uid)) - /* If we're running as nobody, then use root's .xscreensaver file - (since ~root/.xscreensaver and ~nobody/.xscreensaver are likely - to be different -- if we didn't do this, then xscreensaver-demo - would appear to have no effect when the luser is running as root.) - */ - uid = 0; - - p = getpwuid (uid); - - if (!p || !p->pw_name || !*p->pw_name) - { - fprintf (stderr, "%s: couldn't get user info of uid %d\n", - blurb(), getuid ()); - file = ""; - } - else if (!p->pw_dir || !*p->pw_dir) + if (i_am_a_nobody (uid) || !home || !*home) { - fprintf (stderr, "%s: couldn't get home directory of \"%s\"\n", - blurb(), (p->pw_name ? p->pw_name : "???")); - file = ""; + /* If we're running as nobody, then use root's .xscreensaver file + (since ~root/.xscreensaver and ~nobody/.xscreensaver are likely + to be different -- if we didn't do this, then xscreensaver-demo + would appear to have no effect when the luser is running as root.) + */ + struct passwd *p = getpwuid (uid); + uid = 0; + if (!p || !p->pw_name || !*p->pw_name) + { + fprintf (stderr, "%s: couldn't get user info of uid %d\n", + blurb(), getuid ()); + } + else if (!p->pw_dir || !*p->pw_dir) + { + fprintf (stderr, "%s: couldn't get home directory of \"%s\"\n", + blurb(), (p->pw_name ? p->pw_name : "???")); + } + else + { + home = p->pw_dir; + } } - else + if (home && *home) { - const char *home = p->pw_dir; const char *name = ".xscreensaver"; file = (char *) malloc(strlen(home) + strlen(name) + 2); strcpy(file, home); @@ -170,6 +171,10 @@ init_file_name (void) strcat(file, "/"); strcat(file, name); } + else + { + file = ""; + } } if (file && *file) @@ -1653,7 +1658,7 @@ stop_the_insanity (saver_preferences *p) if (p->watchdog_timeout > 57000) p->watchdog_timeout = 57000; /* 57 secs */ if (p->pointer_hysteresis < 0) p->pointer_hysteresis = 0; - if (p->pointer_hysteresis > 100) p->pointer_hysteresis = 100; +/* if (p->pointer_hysteresis > 100) p->pointer_hysteresis = 100; */ if (p->auth_warning_slack < 0) p->auth_warning_slack = 0; if (p->auth_warning_slack > 300) p->auth_warning_slack = 300; diff --git a/driver/subprocs.c b/driver/subprocs.c index d500f70..e251842 100644 --- a/driver/subprocs.c +++ b/driver/subprocs.c @@ -264,8 +264,8 @@ make_job (pid_t pid, int screen, const char *cmd) clean_job_list(); AGAIN: - while (isspace(*in)) in++; /* skip whitespace */ - while (!isspace(*in) && *in != ':') { + while (*in && isspace(*in)) in++; /* skip whitespace */ + while (*in && !isspace(*in) && *in != ':') { if (*in == '=') got_eq = 1; *out++ = *in++; /* snarf first token */ } @@ -277,7 +277,7 @@ make_job (pid_t pid, int screen, const char *cmd) goto AGAIN; } - while (isspace(*in)) in++; /* skip whitespace */ + while (*in && isspace(*in)) in++; /* skip whitespace */ *out = 0; job->name = strdup(name); diff --git a/driver/timers.c b/driver/timers.c index ea97f34..5aa568c 100644 --- a/driver/timers.c +++ b/driver/timers.c @@ -1,5 +1,5 @@ /* timers.c --- detecting when the user is idle, and other timer-related tasks. - * xscreensaver, Copyright (c) 1991-2017 Jamie Zawinski <jwz@jwz.org> + * xscreensaver, Copyright (c) 1991-2019 Jamie Zawinski <jwz@jwz.org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -311,6 +311,12 @@ activate_lock_timer (XtPointer closure, XtIntervalId *id) if (p->verbose_p) fprintf (stderr, "%s: timed out; activating lock.\n", blurb()); + + if (!si->locked_p) + /* So that "xscreensaver-command -watch" reports the time that the + screen was locked, instead of duplicating the blank time. */ + si->blank_time = time ((time_t *) 0); + set_locked_p (si, True); } diff --git a/driver/types.h b/driver/types.h index 35992ae..ebea9e0 100644 --- a/driver/types.h +++ b/driver/types.h @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1993-2019 Jamie Zawinski <jwz@jwz.org> +/* xscreensaver, Copyright (c) 1993-2020 Jamie Zawinski <jwz@jwz.org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -275,6 +275,7 @@ struct saver_info { int unlock_failures; /* Counts failed login attempts while the screen is locked. */ time_t unlock_failure_time; /* Time of first failed login attempt. */ + time_t unlock_dismiss_time; /* Time lock dialog most recently dismissed. */ char *unlock_typeahead; /* If the screen is locked, and the user types a character, we assume that it is the first diff --git a/driver/windows.c b/driver/windows.c index b7bea52..9e47c45 100644 --- a/driver/windows.c +++ b/driver/windows.c @@ -1,5 +1,5 @@ /* windows.c --- turning the screen black; dealing with visuals, virtual roots. - * xscreensaver, Copyright (c) 1991-2019 Jamie Zawinski <jwz@jwz.org> + * xscreensaver, Copyright (c) 1991-2020 Jamie Zawinski <jwz@jwz.org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -1463,6 +1463,7 @@ resize_screensaver_window (saver_info *si) if (ssi->cmap) XInstallColormap (si->dpy, ssi->cmap); XMapRaised (si->dpy, ssi->screensaver_window); + XSync (si->dpy, False); if (! ssi->pid) spawn_screenhack (ssi); @@ -1586,6 +1587,7 @@ raise_window (saver_info *si, if (!dont_clear || ssi->stderr_overlay_window) clear_stderr (ssi); XMapRaised (si->dpy, ssi->screensaver_window); + XSync (si->dpy, False); #ifdef HAVE_MIT_SAVER_EXTENSION if (ssi->server_mit_saver_window && window_exists_p (si->dpy, ssi->server_mit_saver_window)) @@ -1792,15 +1794,18 @@ unblank_screen (saver_info *si) { Window focus = 0; int revert_to; + XSync (si->dpy, False); XGetInputFocus (si->dpy, &focus, &revert_to); if (focus && focus != PointerRoot && focus != None) { + XErrorHandler old_handler = XSetErrorHandler (BadWindow_ehandler); XWindowAttributes xgwa; xgwa.colormap = 0; - XGetWindowAttributes (si->dpy, focus, &xgwa); - if (xgwa.colormap && + if (XGetWindowAttributes (si->dpy, focus, &xgwa) && + xgwa.colormap && xgwa.colormap != DefaultColormapOfScreen (xgwa.screen)) XInstallColormap (si->dpy, xgwa.colormap); + XSetErrorHandler (old_handler); } } diff --git a/driver/xscreensaver-getimage-file b/driver/xscreensaver-getimage-file index ba1ef30..3a5c7f4 100755 --- a/driver/xscreensaver-getimage-file +++ b/driver/xscreensaver-getimage-file @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# Copyright © 2001-2018 Jamie Zawinski <jwz@jwz.org>. +# Copyright © 2001-2020 Jamie Zawinski <jwz@jwz.org>. # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that @@ -53,7 +53,7 @@ BEGIN { eval 'use LWP::Simple;' } my $progname = $0; $progname =~ s@.*/@@g; -my ($version) = ('$Revision: 1.52 $' =~ m/\s(\d[.\d]+)\s/s); +my ($version) = ('$Revision: 1.53 $' =~ m/\s(\d[.\d]+)\s/s); my $verbose = 0; @@ -1256,6 +1256,7 @@ sub main() { elsif (m/^--?no-spotlight$/s) { $use_spotlight_p = 0; } elsif (m/^--?cache$/s) { $cache_p = 1; } elsif (m/^--?no-?cache$/s) { $cache_p = 0; } + elsif (m/^--?flush-?cache$/s) { $feed_max_age = $cache_max_age = 0; } elsif (m/^--?cocoa$/) { $cocoa_id = shift @ARGV; } elsif (m/^--?abs(olute)?$/) { $abs_p = 1; } elsif (m/^-./) { usage; } diff --git a/driver/xscreensaver-text b/driver/xscreensaver-text index e965bed..eca1fbf 100755 --- a/driver/xscreensaver-text +++ b/driver/xscreensaver-text @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# Copyright © 2005-2017 Jamie Zawinski <jwz@jwz.org> +# Copyright © 2005-2019 Jamie Zawinski <jwz@jwz.org> # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that @@ -37,7 +37,7 @@ use Text::Wrap qw(wrap); #use bytes; # This breaks shit. my $progname = $0; $progname =~ s@.*/@@g; -my ($version) = ('$Revision: 1.46 $' =~ m/\s(\d[.\d]+)\s/s); +my ($version) = ('$Revision: 1.48 $' =~ m/\s(\d[.\d]+)\s/s); my $verbose = 0; my $http_proxy = undef; @@ -344,6 +344,11 @@ sub output() { last if ($truncate_lines && $lines > $truncate_lines); } close $pipe; + + # I don't understand why we must do this here, but must not do this + # in the 'file' branch above, which reads the file with :raw... + utf8::decode ($body); # Pack multi-byte UTF-8 back into wide chars. + $body = reformat_text ($body); print STDOUT $body; } else { @@ -573,9 +578,10 @@ sub reformat_rss($) { foreach (@items) { $i++; - my ($title, $body1, $body2, $body3); + my ($title, $author, $body1, $body2, $body3); $title = $3 if (m@<((TITLE) [^<>\s]*)[^<>]*>\s*(.*?)\s*</\1>@xsi); + $author= $3 if (m@<((DC:CREATOR) [^<>\s]*)[^<>]*>\s*(.*?)\s*</\1>@xsi); $body1 = $3 if (m@<((DESCRIPTION) [^<>\s]*)[^<>]*>\s*(.*?)\s*</\1>@xsi); $body2 = $3 if (m@<((CONTENT) [^<>\s]*)[^<>]*>\s*(.*?)\s*</\1>@xsi); $body3 = $3 if (m@<((SUMMARY) [^<>\s]*)[^<>]*>\s*(.*?)\s*</\1>@xsi); @@ -602,10 +608,19 @@ sub reformat_rss($) { } $title = rss_field_to_html ($title || ''); + $author= rss_field_to_html ($author || ''); $body1 = rss_field_to_html ($body1 || ''); $title = '' if ($body1 eq $title); # Identical in Twitter's atom feed. + # Omit author if it's in the title or body + $author = '' if ($author && + ($title =~ m/\Q$author\E/si || + $body1 =~ m/\Q$author\E/si)); + + $title = $author if ($author && !$title); + $title = "$author: $title" if ($author && $title); + $out .= reformat_html ("$title<P>$body1", $wiki_p ? 'wiki' : 'rss'); $out .= "\n"; } diff --git a/driver/xscreensaver.c b/driver/xscreensaver.c index 2add3b8..40f8207 100644 --- a/driver/xscreensaver.c +++ b/driver/xscreensaver.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1991-2019 Jamie Zawinski <jwz@jwz.org> +/* xscreensaver, Copyright (c) 1991-2020 Jamie Zawinski <jwz@jwz.org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -443,6 +443,11 @@ saver_ehandler (Display *dpy, XErrorEvent *error) } +#ifdef __GNUC__ /* Silence warning */ +static void startup_ehandler (String, String, String, String, String *, + Cardinal *) __attribute__((noreturn)); +#endif /* __GNUC__ */ + /* This error handler is used only while the X connection is being set up; after we've got a connection, we don't use this handler again. The only reason for having this is so that we can present a more idiot-proof error @@ -1561,6 +1566,7 @@ main (int argc, char **argv) if (ssi->real_screen_p) if (ensure_no_screensaver_running (si->dpy, si->screens[i].screen)) exit (1); + ssi->current_hack = -1; } lock_initialization (si, &argc, argv); @@ -1590,6 +1596,8 @@ main (int argc, char **argv) initialize_stderr (si); handle_signals (si); + store_saver_status (si); /* for xscreensaver-command -status */ + # ifdef HAVE_LIBSYSTEMD /* Launch it in the background */ si->systemd_pid = fork_and_exec_1 (si, 0, "xscreensaver-systemd"); # endif @@ -1904,13 +1912,13 @@ handle_clientmessage (saver_info *si, XEvent *event, Bool until_idle_p) "suspending."); si->selection_mode = 0; si->demoing_p = False; - si->emergency_lock_p = True; si->throttled_p = True; /* When suspending, immediately lock, if locking enabled. */ # ifndef NO_LOCKING if (p->lock_p && !si->locked_p && !si->locking_disabled_p) { + si->emergency_lock_p = True; if (p->verbose_p) fprintf (stderr, "%s: locking.\n", blurb()); set_locked_p (si, True); diff --git a/hacks/Makefile.in b/hacks/Makefile.in index 63e69be..7acaeb3 100644 --- a/hacks/Makefile.in +++ b/hacks/Makefile.in @@ -122,7 +122,7 @@ SRCS = attraction.c blitspin.c bouboule.c braid.c bubbles.c \ boxfit.c interaggregate.c celtic.c cwaves.c m6502.c \ asm6502.c abstractile.c lcdscrub.c hexadrop.c \ tessellimage.c delaunay.c recanim.c binaryring.c \ - glitchpeg.c vfeedback.c webcollage-cocoa.m \ + glitchpeg.c vfeedback.c scooter.c webcollage-cocoa.m \ webcollage-helper-cocoa.m testx11.c SCRIPTS = vidwhacker webcollage ljlatest @@ -164,7 +164,7 @@ OBJS = attraction.o blitspin.o bouboule.o braid.o bubbles.o \ webcollage-cocoa.o webcollage-helper-cocoa.o m6502.o \ asm6502.o abstractile.o lcdscrub.o hexadrop.o \ tessellimage.o delaunay.o recanim.o binaryring.o \ - glitchpeg.o vfeedback.o testx11.o + glitchpeg.o vfeedback.o scooter.o testx11.o EXES = attraction blitspin bouboule braid decayscreen deco \ drift flame galaxy grav greynetic halo \ @@ -186,7 +186,7 @@ EXES = attraction blitspin bouboule braid decayscreen deco \ pacman fuzzyflakes anemotaxis memscroller substrate \ intermomentary fireworkx fiberlamp boxfit interaggregate \ celtic cwaves m6502 abstractile lcdscrub hexadrop \ - tessellimage binaryring glitchpeg vfeedback \ + tessellimage binaryring glitchpeg vfeedback scooter \ @JPEG_EXES@ JPEG_EXES = webcollage-helper @@ -245,7 +245,7 @@ MEN = anemone.man apollonian.man attraction.man \ intermomentary.man fireworkx.man fiberlamp.man boxfit.man \ interaggregate.man celtic.man cwaves.man abstractile.man \ lcdscrub.man hexadrop.man tessellimage.man binaryring.man \ - glitchpeg.man vfeedback.man + glitchpeg.man vfeedback.man scooter.man RETIRED_MEN = ant.man bubbles.man critical.man flag.man forest.man \ laser.man lightning.man lisa.man lissie.man lmorph.man \ @@ -291,7 +291,10 @@ install-program:: $(EXES) done install-scripts: $(SCRIPTS) munge-scripts - @for program in $(SCRIPTS); do \ + @if [ ! -d $(install_prefix)$(HACKDIR) ]; then \ + $(INSTALL_DIRS) $(install_prefix)$(HACKDIR) ; \ + fi ; \ + for program in $(SCRIPTS); do \ if [ -r $$program ] ; then \ p=$$program ; \ else \ @@ -814,8 +817,8 @@ halftone: halftone.o $(HACK_OBJS) $(COL) metaballs: metaballs.o $(HACK_OBJS) $(CC_HACK) -o $@ $@.o $(HACK_OBJS) $(HACK_LIBS) -eruption: eruption.o $(HACK_OBJS) - $(CC_HACK) -o $@ $@.o $(HACK_OBJS) $(HACK_LIBS) +eruption: eruption.o $(HACK_OBJS) $(SHM) + $(CC_HACK) -o $@ $@.o $(HACK_OBJS) $(SHM) $(HACK_LIBS) $(THRL) popsquares: popsquares.o $(HACK_OBJS) $(DBE) $(COL) $(CC_HACK) -o $@ $@.o $(HACK_OBJS) $(DBE) $(COL) $(HACK_LIBS) @@ -1030,6 +1033,9 @@ pacman: pacman.o $(PACOBJS) $(XLOCK_OBJS) $(PNG) fiberlamp: fiberlamp.o $(XLOCK_OBJS) $(CC_HACK) -o $@ $@.o $(XLOCK_OBJS) $(HACK_LIBS) +scooter: scooter.o $(XLOCK_OBJS) + $(CC_HACK) -o $@ $@.o $(XLOCK_OBJS) $(HACK_LIBS) + # These are not like the others. # xsublim: xsublim.o $(HACK_OBJS_1) @@ -1655,6 +1661,7 @@ eruption.o: $(UTILS_SRC)/hsv.h eruption.o: $(UTILS_SRC)/resources.h eruption.o: $(UTILS_SRC)/usleep.h eruption.o: $(UTILS_SRC)/visual.h +eruption.o: $(UTILS_SRC)/xshm.h eruption.o: $(UTILS_SRC)/yarandom.h euler2d.o: ../config.h euler2d.o: $(srcdir)/fps.h @@ -2711,6 +2718,21 @@ rotzoomer.o: $(UTILS_SRC)/usleep.h rotzoomer.o: $(UTILS_SRC)/visual.h rotzoomer.o: $(UTILS_SRC)/xshm.h rotzoomer.o: $(UTILS_SRC)/yarandom.h +scooter.o: ../config.h +scooter.o: $(srcdir)/fps.h +scooter.o: $(srcdir)/recanim.h +scooter.o: $(srcdir)/screenhackI.h +scooter.o: $(UTILS_SRC)/colors.h +scooter.o: $(UTILS_SRC)/erase.h +scooter.o: $(UTILS_SRC)/font-retry.h +scooter.o: $(UTILS_SRC)/grabscreen.h +scooter.o: $(UTILS_SRC)/hsv.h +scooter.o: $(UTILS_SRC)/resources.h +scooter.o: $(UTILS_SRC)/usleep.h +scooter.o: $(UTILS_SRC)/visual.h +scooter.o: $(UTILS_SRC)/yarandom.h +scooter.o: $(srcdir)/xlockmoreI.h +scooter.o: $(srcdir)/xlockmore.h screenhack.o: ../config.h screenhack.o: $(srcdir)/fps.h screenhack.o: $(srcdir)/recanim.h diff --git a/hacks/analogtv-cli.c b/hacks/analogtv-cli.c index d70db1b..aeec901 100644 --- a/hacks/analogtv-cli.c +++ b/hacks/analogtv-cli.c @@ -1,4 +1,4 @@ -/* xanalogtv-cli, Copyright (c) 2018 Jamie Zawinski <jwz@jwz.org> +/* xanalogtv-cli, Copyright (c) 2018-2019 Jamie Zawinski <jwz@jwz.org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -15,7 +15,7 @@ * --duration Length in seconds of MP4. * --powerup Do the power-on animation at the beginning. * --logo FILE Small image overlayed onto the colorbars image. - * --audio FILE Add a soundtrack. Must be as long or longer. + * --audio FILE Add a soundtrack. * * Created: 10-Dec-2018 by jwz. */ @@ -573,7 +573,8 @@ analogtv_write_mp4 (struct state *st, const char *outfile, " -map 0:v:0" " -map 1:a:0" " -acodec aac" - " -shortest", + /* Truncate or pad audio to length of video */ + " -filter_complex '[1:0] apad' -shortest", audiofile); sprintf (cmd + strlen(cmd), " -c:v libx264" @@ -642,10 +643,11 @@ analogtv_convert (const char *infile, const char *outfile, unsigned long curticks = 0; time_t lastlog = time((time_t *)0); int frames_left; + int channel_changes = 0; int fps = 30; if (verbose_p) - fprintf (stderr, "%s: progname: loaded %s %dx%d\n", + fprintf (stderr, "%s: loaded %s %dx%d\n", progname, infile, ximage->width, ximage->height); flip_ximage (ximage); @@ -663,12 +665,30 @@ analogtv_convert (const char *infile, const char *outfile, calloc (st->output_frame->height, st->output_frame->bytes_per_line); { - char *s1, *s2; - st->framefile_fmt = malloc (strlen(outfile) + 100); + char *s0, *slash, *dot; + st->framefile_fmt = calloc (1, strlen(outfile) + 100); + + s0 = st->framefile_fmt; strcpy (st->framefile_fmt, outfile); - s1 = strrchr (st->framefile_fmt, '/'); - s2 = strrchr (st->framefile_fmt, '.'); - if (s2 && s2 > s1) *s2 = 0; + + slash = strrchr (st->framefile_fmt, '/'); + dot = strrchr (st->framefile_fmt, '.'); + if (dot && dot > slash) *dot = 0; + + /* Make tmp files be dotfiles */ + if (slash) { + memmove (slash+1, slash, strlen(slash)+1); + slash[1] = '.'; + } else { + memmove (s0+1, s0, strlen(s0)+1); + s0[0] = '.'; + } + + /* Can't have percents in the tmp file names */ + for (s0 = (slash ? slash : s0); *s0; s0++) { + if (*s0 == '%') *s0 = '_'; + } + sprintf (st->framefile_fmt + strlen(st->framefile_fmt), ".%08x.%%06d.png", (random() % 0xFFFFFFFF)); } @@ -677,7 +697,7 @@ analogtv_convert (const char *infile, const char *outfile, int x, y; st->logo = file_to_ximage (0, 0, logofile); if (verbose_p) - fprintf (stderr, "%s: progname: loaded %s %dx%d\n", + fprintf (stderr, "%s: loaded %s %dx%d\n", progname, logofile, st->logo->width, st->logo->height); flip_ximage (st->logo); /* Pull the alpha out of the logo and make a separate mask ximage. */ @@ -799,6 +819,8 @@ analogtv_convert (const char *infile, const char *outfile, st->curinputi=0; st->cs = &st->chansettings[st->curinputi]; + + /* First channel (initial unadulterated image) stays for this long */ frames_left = fps * (2 + frand(1.5)); st->tv->powerup=0.0; @@ -832,17 +854,35 @@ analogtv_convert (const char *infile, const char *outfile, frames_left--; if (frames_left <= 0) { - frames_left = fps * (0.5 + frand(2.5)); - if (st->curinputi != 0 && !(random() % 3)) { - st->curinputi = 0; /* unadulterated image */ + channel_changes++; + + if (channel_changes == 1) { + /* Second channel has short duration */ + frames_left = fps * (0.25 + frand(0.5)); } else { + frames_left = fps * (0.5 + frand(2.5)); + } + + if (channel_changes == 2) { + /* Always use the unadulterated image for the third channel: + So the effect is, plain, brief blip, plain, then random. */ + st->curinputi = 0; + } else if (st->curinputi != 0 && !(random() % 3)) { + /* Use the unadulterated image 1/3 of the time */ + st->curinputi = 0; + } else { + /* Otherwise random */ st->curinputi = 1 + (random() % (N_CHANNELS - 1)); } st->cs = &st->chansettings[st->curinputi]; /* Set channel change noise flag */ st->tv->channel_change_cycles=200000; + + if (verbose_p) + fprintf (stderr, "%s: %.1f: channel %d\n", + progname, curticks/1000.0, st->curinputi); } for (i=0; i<MAX_MULTICHAN; i++) { diff --git a/hacks/barcode.c b/hacks/barcode.c index 2ce609e..1f56013 100644 --- a/hacks/barcode.c +++ b/hacks/barcode.c @@ -101,14 +101,17 @@ static const char *words[] = "abstraction", "acid", "addiction", + "affluenza", "alertness", "Algeria", + "antifa", "anxiety", "aorta", "argyle socks", "attrition", "axis of evil", "bamboo", + "banana slug", "bangle", "bankruptcy", "baptism", @@ -122,6 +125,7 @@ static const char *words[] = "boobs", "booty", "bread", + "brogrammers", "bubba", "burrito", "California", @@ -131,8 +135,10 @@ static const char *words[] = "carnage", "children", "chocolate", + "chupacabra", "CLONE", "cock", + "congress", "constriction", "contrition", "cop", @@ -153,10 +159,10 @@ static const char *words[] = "despair", "desperation", "disease", - "disease", + "DNA Lounge", "doberman", "DOOM", - "dreams", + "dot com", "dreams", "drugs", "easy", @@ -175,9 +181,10 @@ static const char *words[] = "flatulence", "fluff", "fnord", + "followers", + "frak", "freedom", "fruit", - "fruit", "futility", "gerbils", "GOD", @@ -198,8 +205,12 @@ static const char *words[] = "icepick", "identity", "ignorance", + "illuminati", "importance", "individuality", + "influence", + "influencers", + "influenza", "inkling", "insurrection", "intoxicant", @@ -215,6 +226,7 @@ static const char *words[] = "lattice", "lawyer", "lemming", + "likes", "liquidation", "lobbyist", "love", @@ -224,9 +236,11 @@ static const char *words[] = "malfunction", "marmot", "marshmallow", + "measles", "merit", "merkin", "mescaline", + "methane", "milk", "mischief", "mistrust", @@ -281,6 +295,7 @@ static const char *words[] = "respect", "revolution", "roadrunner", + "rootkit", "rule", "savor", "scab", @@ -290,6 +305,7 @@ static const char *words[] = "security", "sediment", "self worth", + "shadow profile", "sickness", "silicone", "slack", @@ -316,17 +332,21 @@ static const char *words[] = "terrorism", "terrorist", "the impossible", + "the panopticon", "the unknown", "toast", "topography", "truism", + "truthiness", "turgid", + "twits", "underbrush", "underling", "unguent", "unusual", "uplink", "urge", + "vaccines", "valor", "variance", "vaudeville", @@ -334,6 +354,7 @@ static const char *words[] = "vegetarian", "venom", "verifiability", + "very fine people", "viagra", "vibrator", "victim", @@ -351,7 +372,6 @@ static const char *words[] = "words", "worm", "worship", - "worship", "Xanax", "Xerxes", "Xhosa", diff --git a/hacks/bsod.c b/hacks/bsod.c index 040db54..ffde1a6 100644 --- a/hacks/bsod.c +++ b/hacks/bsod.c @@ -1554,7 +1554,7 @@ windows_ransomware (Display *dpy, Window window) const time_t stage1_deadline = now + 259200 - advance_deadline; /* 3 days */ const time_t stage2_deadline = now + 604800 - advance_deadline; /* 7 days */ char stage1_deadline_str[25], stage2_deadline_str[25]; - char countdown_str[16]; + char countdown_str[20]; int countdown_d, countdown_h, countdown_m, countdown_s, countdown_r; int line_height = bst->font->ascent + bst->font->descent; int line_height1 = bst->fontA->ascent + bst->fontA->descent; @@ -2528,7 +2528,7 @@ macsbug (Display *dpy, Window window) if (xoff < 0) xoff = 0; if (yoff < 0) yoff = 0; - BSOD_MARGINS (bst, xoff, yoff); + BSOD_MARGINS (bst, xoff, xoff); BSOD_COLOR (bst, bc, bg); BSOD_RECT (bst, True, 0, 0, bst->xgwa.width, bst->xgwa.height); @@ -2552,7 +2552,9 @@ macsbug (Display *dpy, Window window) BSOD_MOVETO (bst, xoff + col_right + char_width, yoff + body_top + line_height); - BSOD_MARGINS (bst, xoff + col_right + char_width, yoff); + BSOD_MARGINS (bst, + xoff + col_right + char_width, + xoff + col_right + char_width); BSOD_TEXT (bst, LEFT, body); BSOD_RECT (bst, False, xoff-2, yoff, page_right+4, page_bottom); /* again */ @@ -3265,28 +3267,21 @@ sparc_solaris (Display *dpy, Window window) Pixmap pixmap = image_data_to_pixmap (dpy, window, sun_png, sizeof(sun_png), &pix_w, &pix_h, &mask); -# if 0 - if (pixmap && - pix_w < bst->xgwa.width / 2 && - pix_h < bst->xgwa.height / 2) - { - int i, n = 1; - if (bst->xgwa.width > 2560) n++; /* Retina displays */ - for (i = 0; i < n; i++) - { - pixmap = double_pixmap (dpy, bst->xgwa.visual, - bst->xgwa.depth, pixmap, pix_w, pix_h); - mask = double_pixmap (dpy, bst->xgwa.visual, 1, mask, pix_w, pix_h); - pix_w *= 2; - pix_h *= 2; - } - } -# endif char_width = (bst->font->per_char ? bst->font->per_char['n'-bst->font->min_char_or_byte2].width : bst->font->min_bounds.width); + if (pixmap) + while (pix_w < char_width * 4) + { + pixmap = double_pixmap (dpy, bst->xgwa.visual, + bst->xgwa.depth, pixmap, pix_w, pix_h); + mask = double_pixmap (dpy, bst->xgwa.visual, 1, mask, pix_w, pix_h); + pix_w *= 2; + pix_h *= 2; + } + bst->pixmap = pixmap; bst->mask = mask; @@ -3384,13 +3379,13 @@ sparc_solaris (Display *dpy, Window window) BSOD_PIXMAP (bst, 0, 0, pix_w, pix_h, ~0, ~0); BSOD_MARGINS (bst, - bst->left_margin + char_width * 12, - bst->top_margin); + bst->left_margin + pix_w + char_width * 2, + bst->left_margin + pix_w + char_width * 2); BSOD_TEXT (bst, LEFT, "SPARCstation IPC, Keyboard Present\n" "ROM Rev. 2.9, 16 MB memory installed, Serial #12648190.\n" "Ethernet address 8:0:20:37:1:87, Host ID: 52c0fefe.\n"); - BSOD_MARGINS (bst, bst->left_margin, bst->top_margin); + BSOD_MARGINS (bst, bst->left_margin, bst->left_margin); BSOD_TEXT (bst, LEFT, "\n\n\033"); BSOD_PAUSE (bst, 3000000); @@ -5653,6 +5648,121 @@ dvd (Display *dpy, Window window) } +static struct bsod_state * +tivo (Display *dpy, Window window) +{ + struct bsod_state *bst = make_bsod_state (dpy, window, "tivo", "Tivo"); + int char_width = + (bst->font->per_char + ? bst->font->per_char['n'-bst->font->min_char_or_byte2].width + : bst->font->min_bounds.width); + int line_height = bst->font->ascent + bst->font->descent; + + int left = (bst->xgwa.width - char_width * 44) / 2; + int top = (bst->xgwa.height - line_height * 15) / 2; + if (left < 0) left = 0; + if (top < 0) top = 0; + + XClearWindow (dpy, window); + + BSOD_MARGINS (bst, left, left); + BSOD_MOVETO (bst, left, top); + + BSOD_FONT (bst, 1); + BSOD_TEXT (bst, LEFT, "\nA severe error has occurred.\n\n"); + BSOD_FONT (bst, 0); + BSOD_TEXT (bst, LEFT, + "Please leave the Receiver plugged in and connected\n" + "to the phone line for the next three hours while the\n" + "Receiver attempts to repair itself."); + BSOD_FONT (bst, 1); + BSOD_TEXT (bst, LEFT, + "\n\n" + "DO NOT UNPLUG OR RESTART\nTHE RECEIVER.\n\n"); + BSOD_FONT (bst, 0); + BSOD_TEXT (bst, LEFT, + "If, after three hours, the Receiver does not restart\n" + "itself, call Customer Care."); + + BSOD_PAUSE (bst, 1000000 * 60); + return bst; +} + + +/* Error message for corrupted (and therefore presumed bootleg) cartridges. + */ +static struct bsod_state * +nintendo (Display *dpy, Window window) +{ + struct bsod_state *bst = make_bsod_state (dpy, window, + "nintendo", "Nintendo"); + unsigned long bg = get_pixel_resource (dpy, bst->xgwa.colormap, + "nintendo.background", + "Nintendo.Background"); + unsigned long bg2 = get_pixel_resource (dpy, bst->xgwa.colormap, + "nintendo.background2", + "Nintendo.Background"); + unsigned long fg = get_pixel_resource (dpy, bst->xgwa.colormap, + "nintendo.foreground", + "Nintendo.Foreground"); + int char_width = + (bst->font->per_char + ? bst->font->per_char['n'-bst->font->min_char_or_byte2].width + : bst->font->min_bounds.width); + int line_height = bst->font->ascent + bst->font->descent; + + int left = (bst->xgwa.width - char_width * 30) / 2; + int top = (bst->xgwa.height - line_height * 9) / 2; + int left2 = left - char_width * 4; + int top2 = top - line_height; + if (left < 0) left = 0; + if (top < 0) top = 0; + if (left2 < 0) left2 = 0; + if (top2 < 0) top2 = 0; + if (left2 > char_width * 8) left2 = char_width * 8; + if (top2 > line_height * 10) top2 = line_height * 10; + + XClearWindow (dpy, window); + + BSOD_COLOR (bst, bg2, bg); + BSOD_RECT (bst, True, left2, top2 - line_height*2, + bst->xgwa.width - left2*2, + bst->xgwa.height - top2*2 + line_height*2); + + BSOD_MARGINS (bst, left, left); + BSOD_MOVETO (bst, left, top - line_height/2); + + BSOD_FONT (bst, 1); + BSOD_COLOR (bst, bg, bg2); + + /* a variant crash has a second box above the English text that says: + + 警告 + ビデオゲームのコピーは法律で禁じられています。 + 詳しくは取扱説明書をご覧になってください。 + + but BSOD_TEXT doesn't do Xft, and more importantly, "PxPlus IBM VGA8" + doesn't contain Japanese characters. + */ + + BSOD_TEXT (bst, CENTER, "WARNING"); + BSOD_FONT (bst, 0); + BSOD_COLOR (bst, fg, bg2); + BSOD_TEXT (bst, LEFT, + "\n\n" + "IT IS A SERIOUS CRIME\n" + "TO COPY VIDEO GAMES\n" + "ACCORDING TO COPYRIGHT LAW.\n" + "PLEASE REFER TO\n" + "YOUR NINTENDO GAME\n" + "INSTRUCTION BOOKLET\n" + "FOR FURTHER INFORMATION."); + + BSOD_PAUSE (bst, 1000000 * 60); + return bst; +} + + /* An Android phone boot loader, by jwz. */ static struct bsod_state * @@ -5930,6 +6040,8 @@ static const struct { { "VMware", vmware }, { "Encom", encom }, { "DVD", dvd }, + { "Tivo", tivo }, + { "Nintendo", nintendo }, }; @@ -6247,10 +6359,12 @@ static const char *bsod_defaults [] = { "*doNvidia: True", "*doATM: True", "*doGLaDOS: True", - "*doAndroid: True", + "*doAndroid: False", "*doVMware: True", "*doEncom: True", "*doDVD: True", + "*doTivo: True", + "*doNintendo: True", ".foreground: White", ".background: Black", @@ -6362,6 +6476,13 @@ static const char *bsod_defaults [] = { ".vmware.foreground2: Yellow", ".vmware.background: #a700a8", /* purple */ + ".tivo.background: #339020", + ".tivo.foreground: #B8E6BA", + + ".nintendo.background: #F76D0A", + ".nintendo.background2: #085C89", + ".nintendo.foreground: #EEAACF", + "*dontClearRoot: True", ANALOGTV_DEFAULTS @@ -6370,6 +6491,8 @@ static const char *bsod_defaults [] = { "*useSHM: True", #endif + ".lowrez: false", /* This is required on macOS */ + "*fontB: ", "*fontC: ", @@ -6400,6 +6523,11 @@ static const char *bsod_defaults [] = { ".ransomware.fontB: Arial 9, Helvetica 9", ".ransomware.fontC: Arial Bold 11, Arial-BoldMT 11, Helvetica Bold 11", + ".tivo.font: Helvetica-Bold 13", + ".tivo.fontB: Helvetica-Bold 17", + + ".nintendo.font: PxPlus IBM VGA8 18, Courier-Bold 18", + # elif defined(HAVE_ANDROID) "*font: PxPlus IBM VGA8 16", @@ -6424,6 +6552,11 @@ static const char *bsod_defaults [] = { ".ransomware.fontB: -*-helvetica-medium-r-*-*-*-80-*-*-*-*-*-*", ".ransomware.fontC: -*-helvetica-bold-r-*-*-*-100-*-*-*-*-*-*", + ".tivo.font: -*-helvetica-medium-r-*-*-*-180-*-*-*-*-*-*", + ".tivo.fontB: -*-helvetica-bold-r-*-*-*-240-*-*-*-*-*-*", + + ".nintendo.font: PxPlus IBM VGA8 18", + # elif defined(HAVE_COCOA) "*font: PxPlus IBM VGA8 8, Courier Bold 9", @@ -6455,10 +6588,16 @@ static const char *bsod_defaults [] = { ".win10.fontB: Arial 100, Helvetica 100", ".win10.fontC: Arial 16, Helvetica 16", - ".ransomware.font: Arial 24, Helvetica 24", - ".ransomware.bigFont: Arial 24, Helvetica 24", - ".ransomware.fontB: Arial 16, Helvetica 16", - ".ransomware.fontC: Arial Bold 24, Helvetica Bold 24", + ".ransomware.font: Arial 24, Helvetica 24", + ".ransomware.bigFont: Arial 24, Helvetica 24", + ".ransomware.fontB: Arial 16, Helvetica 16", + ".ransomware.fontC: Arial Bold 24, Helvetica Bold 24", + + ".tivo.font: Helvetica 36", + ".tivo.fontB: Helvetica 48", + + ".nintendo.font: PxPlus IBM VGA8 12, Courier Bold 12", + ".nintendo.bigFont: PxPlus IBM VGA8 48, Courier Bold 48", # else /* X11 */ @@ -6506,6 +6645,11 @@ static const char *bsod_defaults [] = { ".ransomware.fontB: -*-helvetica-medium-r-*-*-*-140-*-*-*-*-*-*", ".ransomware.fontC: -*-helvetica-bold-r-*-*-*-180-*-*-*-*-*-*", + ".tivo.font: -*-helvetica-medium-r-*-*-*-180-*-*-*-*-*-*", + ".tivo.fontB: -*-helvetica-bold-r-*-*-*-240-*-*-*-*-*-*", + + ".nintendo.font: -*-courier-bold-r-*-*-*-180-*-*-m-*-*-*", + ".nintendo.bigFont: -*-courier-bold-r-*-*-*-360-*-*-m-*-*-*", # endif /* X11 */ @@ -6580,8 +6724,12 @@ static const XrmOptionDescRec bsod_options [] = { { "-no-vmware", ".doVMware", XrmoptionNoArg, "False" }, { "-encom", ".doEncom", XrmoptionNoArg, "True" }, { "-no-encom", ".doEncom", XrmoptionNoArg, "False" }, - { "-dvd", ".doDVD", XrmoptionNoArg, "True" }, - { "-no-dvd", ".doDVD", XrmoptionNoArg, "False" }, + { "-dvd", ".doDVD", XrmoptionNoArg, "True" }, + { "-no-dvd", ".doDVD", XrmoptionNoArg, "False" }, + { "-tivo", ".doTivo", XrmoptionNoArg, "True" }, + { "-no-tivo", ".doTivo", XrmoptionNoArg, "False" }, + { "-nintendo", ".doNintendo", XrmoptionNoArg, "True" }, + { "-no-nintendo", ".doNintendo", XrmoptionNoArg, "False" }, ANALOGTV_OPTIONS { 0, 0, 0, 0 } }; diff --git a/hacks/compile_axp.com b/hacks/compile_axp.com index 9fab007..caf116c 100644 --- a/hacks/compile_axp.com +++ b/hacks/compile_axp.com @@ -111,6 +111,7 @@ $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) RORSCHACH.C $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) ROTOR.C $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) ROTZOOMER.C +$ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) SCOOTER.C $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) SCREENHACK.C $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) SHADEBOBS.C $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) SIERPINSKI.C diff --git a/hacks/compile_decc.com b/hacks/compile_decc.com index 9fab007..caf116c 100644 --- a/hacks/compile_decc.com +++ b/hacks/compile_decc.com @@ -111,6 +111,7 @@ $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) RORSCHACH.C $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) ROTOR.C $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) ROTZOOMER.C +$ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) SCOOTER.C $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) SCREENHACK.C $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) SHADEBOBS.C $ CC/DECC/PREFIX=ALL/DEFINE=(VMS,HAVE_CONFIG_H,STANDALONE)/INCL=([],[-],[-.UTILS]) SIERPINSKI.C diff --git a/hacks/config/README b/hacks/config/README index 58c4195..5ba2e7b 100644 --- a/hacks/config/README +++ b/hacks/config/README @@ -4,8 +4,8 @@ a screen saver and locker for the X window system by Jamie Zawinski - version 5.43 - 09-Jul-2019 + version 5.44 + 20-Mar-2020 https://www.jwz.org/xscreensaver/ diff --git a/hacks/config/bsod.xml b/hacks/config/bsod.xml index 0d18218..6a3ac4a 100644 --- a/hacks/config/bsod.xml +++ b/hacks/config/bsod.xml @@ -24,7 +24,7 @@ <vgroup> <boolean id="amiga" _label="AmigaDOS" arg-unset="-no-amiga"/> <boolean id="glados" _label="GLaDOS" arg-unset="-no-glados"/> - <boolean id="android" _label="Android" arg-unset="-no-android"/> + <boolean id="android" _label="Android" arg-set="-android"/> <boolean id="apple2" _label="Apple ][" arg-unset="-no-apple2"/> <boolean id="ransomware" _label="Ransomware" arg-unset="-no-ransomware"/> </vgroup> @@ -43,19 +43,21 @@ <boolean id="encom" _label="Encom" arg-unset="-no-encom"/> </vgroup> <vgroup> - <boolean id="vms" _label="VMS" arg-unset="-no-vms"/> <boolean id="hvx" _label="HVX/GCOS6" arg-unset="-no-hvx"/> <boolean id="blitdamage" _label="NCD X Terminal " arg-unset="-no-blitdamage"/> <boolean id="atm" _label="ATM" arg-unset="-no-atm"/> <boolean id="dvd" _label="DVD" arg-unset="-no-dvd"/> + <boolean id="nintendo" _label="Nintendo" arg-unset="-no-nintendo"/> </vgroup> <vgroup> + <boolean id="tivo" _label="Tivo" arg-unset="-no-tivo"/> + <boolean id="vms" _label="VMS" arg-unset="-no-vms"/> <boolean id="bsd" _label="BSD" arg-set="-bsd"/> <boolean id="linux" _label="Linux (fsck)" arg-unset="-no-linux"/> <boolean id="sparclinux" _label="Linux (sparc)" arg-set="-sparclinux"/> - <boolean id="hppalinux" _label="Linux (hppa)" arg-unset="-no-hppalinux"/> </vgroup> <vgroup> + <boolean id="hppalinux" _label="Linux (hppa)" arg-unset="-no-hppalinux"/> <boolean id="solaris" _label="Solaris" arg-unset="-no-solaris"/> <boolean id="sco" _label="SCO" arg-unset="-no-sco"/> <boolean id="hpux" _label="HPUX" arg-unset="-no-hpux"/> diff --git a/hacks/config/deepstars.xml b/hacks/config/deepstars.xml index e1118e2..d690d2d 100644 --- a/hacks/config/deepstars.xml +++ b/hacks/config/deepstars.xml @@ -19,6 +19,8 @@ _label="Smear" _low-label="Low" _high-label="High" low="0.1" high="5.0" default="1.0"/> + <boolean id="showfps" _label="Show frame rate" arg-set="-fps"/> + <xscreensaver-updater /> <_description> diff --git a/hacks/config/dnalogo.xml b/hacks/config/dnalogo.xml index ac10f15..48cd2ee 100644 --- a/hacks/config/dnalogo.xml +++ b/hacks/config/dnalogo.xml @@ -33,18 +33,6 @@ DNA Lounge San Francisco, CA 94103 -Codeword - - Restaurant -- Bar -- Nightclub -- Cafe -- Est. 2015. - - 917 Folsom Street - San Francisco, CA - 94107 - - https://www.dnalounge.com/ - http://www.dnapizza.com/ - https://www.codeword-sf.com/ - Written by Jamie Zawinski; 2001. </_description> </screensaver> diff --git a/hacks/config/etruscanvenus.xml b/hacks/config/etruscanvenus.xml new file mode 100644 index 0000000..090b102 --- /dev/null +++ b/hacks/config/etruscanvenus.xml @@ -0,0 +1,143 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<screensaver name="etruscanvenus" _label="EtruscanVenus" gl="yes"> + + <video href="https://www.youtube.com/watch?v=p3MgGyie6-I"/> + + <command arg="-root"/> + + <hgroup> + <select id="view-mode"> + <option id="walk" _label="Random motion"/> + <option id="walk" _label="Walk" arg-set="-view-mode walk"/> + <option id="turn" _label="Turn" arg-set="-view-mode turn"/> + </select> + + <boolean id="orientation-marks" _label="Show orientation marks" + arg-set="-orientation-marks"/> + </hgroup> + + <hgroup> + <boolean id="deform" _label="Deform the surface" + arg-unset="-no-deform"/> + + <number id="deform-speed" type="slider" arg="-deformation-speed %" + _label="Deformation speed" + _low-label="1.0" _high-label="100.0" + low="1.0" high="100.0" default="10.0"/> + + <number id="init-deform" type="slider" arg="-initial-deformation %" + _label="Initial deformation" + _low-label="0.0" _high-label="3999.0" + low="0.0" high="3999.0" default="0.0"/> + </hgroup> + + + <hgroup> + + <vgroup> + <select id="display-mode"> + <option id="random" _label="Random surface"/> + <option id="wire" _label="Wireframe mesh" arg-set="-mode wireframe"/> + <option id="surface" _label="Solid surface" arg-set="-mode surface"/> + <option id="transparent" _label="Transparent surface" arg-set="-mode transparent"/> + </select> + + <select id="appearance"> + <option id="random" _label="Random pattern"/> + <option id="solid" _label="Solid object" arg-set="-appearance solid"/> + <option id="bands" _label="Distance bands" arg-set="-appearance distance-bands"/> + <option id="bands" _label="Direction bands" arg-set="-appearance direction-bands"/> + </select> + + <select id="colors"> + <option id="random" _label="Random coloration"/> + <option id="twosided" _label="One-sided" arg-set="-colors one-sided"/> + <option id="twosided" _label="Two-sided" arg-set="-colors two-sided"/> + <option id="rainbow" _label="Distance colors" arg-set="-colors distance"/> + <option id="rainbow" _label="Direction colors" arg-set="-colors direction"/> + </select> + + <boolean id="change-colors" _label="Change colors" + arg-unset="-no-change-colors"/> + + <select id="projection"> + <option id="random" _label="Random Projection"/> + <option id="perspective" _label="Perspective" arg-set="-projection perspective"/> + <option id="orthographic" _label="Orthographic" arg-set="-projection orthographic"/> + </select> + </vgroup> + + <vgroup> + <number id="speed-x" type="slider" arg="-speed-x %" + _label="X rotation speed" + _low-label="-4.0" _high-label="4.0" + low="-4.0" high="4.0" default="1.1"/> + + <number id="speed-y" type="slider" arg="-speed-y %" + _label="Y rotation speed" + _low-label="-4.0" _high-label="4.0" + low="-4.0" high="4.0" default="1.3"/> + + <number id="speed-z" type="slider" arg="-speed-z %" + _label="Z rotation speed" + _low-label="-4.0" _high-label="4.0" + low="-4.0" high="4.0" default="1.5"/> + </vgroup> + + <vgroup> + <number id="walk-direction" type="slider" arg="-walk-direction %" + _label="Walking direction" + _low-label="-180.0" _high-label="180.0" + low="-180.0" high="180.0" default="83.0"/> + + <number id="walk-speed" type="slider" arg="-walk-speed %" + _label="Walking speed" + _low-label="1.0" _high-label="100.0" + low="1.0" high="100.0" default="20.0"/> + + <number id="delay" type="slider" arg="-delay %" + _label="Frame rate" _low-label="Low" _high-label="High" + low="0" high="100000" default="10000" + convert="invert"/> + </vgroup> + + <vgroup> + <xscreensaver-updater /> + <boolean id="showfps" _label="Show frame rate" arg-set="-fps"/> + </vgroup> + + </hgroup> + + <_description> +A 3D immersion of of a Klein bottle that smoothly deforms between the +Etruscan Venus surface, the Roman surface, the Boy surface, and the +Ida surface. Topologically, all surfaces are Klein bottles, even the +Roman and Boy surfaces, which are doubly covered and therefore appear +to be an immersed real projective plane. + +You can walk on the Klein bottle or rotate it in 3D. Since all the +surfaces except the Ida surfaces have points where the surface normal +is not well defined for some points, walking is performed on the Ida +surface. Furthermore, it is possible to smoothly deform the surface +between the Etruscan Venus surface, the Roman surface, the Boy +surface, and the Ida surface surface while turning it. + +Inspired by George K. Francis's book "A Topological Picturebook", +Springer, 1987, George K. Francis's paper "The Etruscan Venus" in +P. Concus, R. Finn, and D. A. Hoffman: "Geometric Analysis and +Computer Graphics", Springer, 1991, and a video entitled "The Etruscan +Venus" by Donna J. Cox, George K. Francis, and Raymond L. Idaszak, +presented at SIGGRAPH 1989. + +https://en.wikipedia.org/wiki/Boy%27s_surface +https://en.wikipedia.org/wiki/Roman_surface +https://en.wikipedia.org/wiki/Klein_bottle +http://mathworld.wolfram.com/BoySurface.html +http://mathworld.wolfram.com/RomanSurface.html +http://mathworld.wolfram.com/EtruscanVenusSurface.html +http://mathworld.wolfram.com/IdaSurface.html + +Written by Carsten Steger; 2020. + </_description> +</screensaver> diff --git a/hacks/config/gibson.xml b/hacks/config/gibson.xml new file mode 100644 index 0000000..3e69a9c --- /dev/null +++ b/hacks/config/gibson.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> + +<screensaver name="gibson" _label="Gibson" gl="yes"> + + <command arg="-root"/> + + <video href="https://www.youtube.com/watch?v=_gOhMR3TrHA"/> + + <hgroup> + <vgroup> + <number id="delay" type="slider" arg="-delay %" + _label="Frame rate" _low-label="Low" _high-label="High" + low="0" high="100000" default="20000" + convert="invert"/> + + <number id="speed" type="slider" arg="-speed %" + _label="Glyph speed" _low-label="Slow" _high-label="Fast" + low="0.1" high="8.0" default="1.0"/> + </vgroup> + <vgroup> + <number id="grid-width" type="spinbutton" arg="-grid-width %" + _label="Grid width" low="1" high="20" default="6"/> + + <number id="grid-depth" type="spinbutton" arg="-grid-depth %" + _label="Grid depth" low="1" high="20" default="6"/> + </vgroup> + <vgroup> + <number id="grid-height" type="spinbutton" arg="-grid-height %" + _label="Tower depth" low="1" high="20" default="7"/> + + <number id="spacing" type="spinbutton" arg="-spacing %" + _label="Tower spacing" low="1" high="5" default="2.0"/> + + <number id="columns" type="spinbutton" arg="-columns %" + _label="Text columns" low="1" high="20" default="5"/> + </vgroup> + </hgroup> + + <hgroup> + <boolean id="tex" _label="Textured" arg-unset="-no-texture"/> + <boolean id="wire" _label="Wireframe" arg-set="-wireframe"/> + <boolean id="showfps" _label="Show frame rate" arg-set="-fps"/> + <xscreensaver-updater /> + </hgroup> + + <_description> +Hacking the Gibson, as per the 1995 classic film, HACKERS. + +Cereal Killer: "Oh yeah, you want a seriously righteous hack, you score +one of those Gibsons, man. You know, supercomputers they use to like, +do physics, and look for oil and stuff?" + +Phantom Phreak: "Ain't no way, man, security's too tight. The big iron?" + +Zero Cool: "Maybe. But, if I were gonna hack some heavy metal, I'd, uh, +work my way back through some low security, and try the back door." + +Cereal Killer: "Yeah but oh man, wouldn't you just love to get one of +those Gibsons, baby? Ooooh!" + +Phantom Phreak: "Yo, who ate all of my fries?" + +Written by Jamie Zawinski; 2020. + </_description> +</screensaver> diff --git a/hacks/config/hypertorus.xml b/hacks/config/hypertorus.xml index a82e090..899d0cb 100644 --- a/hacks/config/hypertorus.xml +++ b/hacks/config/hypertorus.xml @@ -40,10 +40,14 @@ </select> <select id="colors"> - <option id="twosided" _label="Two-sided" arg-set="-twosided"/> + <option id="onesided" _label="One-sided" arg-set="-onesided"/> + <option id="twosided" _label="Two-sided" arg-set="-twosided"/> <option id="colorwheel" _label="Color wheel"/> </select> + <boolean id="change-colors" _label="Change colors" + arg-set="-change-colors"/> + <select id="projection3d"> <option id="perspective-3d" _label="Perspective 3D"/> <option id="orthographic-3d" _label="Orthographic 3D" diff --git a/hacks/config/klein.xml b/hacks/config/klein.xml index 8a93c9e..4880eb0 100644 --- a/hacks/config/klein.xml +++ b/hacks/config/klein.xml @@ -8,10 +8,10 @@ <hgroup> <select id="kleinbottle"> - <option id="random" _label="Random shape"/> - <option id="figure-8" _label="Figure 8" arg-set="-klein-bottle figure-8"/> - <option id="squeezed-torus" _label="Squeezed torus" arg-set="-klein-bottle squeezed-torus"/> - <option id="lawson" _label="Lawson" arg-set="-klein-bottle lawson"/> + <option id="random" _label="Random shape"/> + <option id="figure-8" _label="Figure 8" arg-set="-klein-bottle figure-8"/> + <option id="pinched-torus" _label="Pinched torus" arg-set="-klein-bottle pinched-torus"/> + <option id="lawson" _label="Lawson" arg-set="-klein-bottle lawson"/> </select> <select id="view-mode"> @@ -41,11 +41,15 @@ <select id="colors"> <option id="random" _label="Random coloration"/> + <option id="twosided" _label="One-sided" arg-set="-colors one-sided"/> <option id="twosided" _label="Two-sided" arg-set="-colors two-sided"/> <option id="rainbow" _label="Rainbow colors" arg-set="-colors rainbow"/> <option id="depth" _label="4d depth colors" arg-set="-colors depth"/> </select> + <boolean id="change-colors" _label="Change colors" + arg-set="-change-colors"/> + <select id="projection3d"> <option id="random" _label="Random 3D"/> <option id="perspective-3d" _label="Perspective 3D" arg-set="-projection-3d perspective"/> diff --git a/hacks/config/projectiveplane.xml b/hacks/config/projectiveplane.xml index fa9dfb8..996d010 100644 --- a/hacks/config/projectiveplane.xml +++ b/hacks/config/projectiveplane.xml @@ -23,12 +23,16 @@ <select id="colors"> <option id="random" _label="Random coloration"/> + <option id="twosided" _label="One-sided" arg-set="-colors one-sided"/> <option id="twosided" _label="Two-sided" arg-set="-colors two-sided"/> <option id="rainbow" _label="Distance colors" arg-set="-colors distance"/> <option id="rainbow" _label="Direction colors" arg-set="-colors direction"/> <option id="depth" _label="4d depth colors" arg-set="-colors depth"/> </select> + <boolean id="change-colors" _label="Change colors" + arg-set="-change-colors"/> + <select id="projection3d"> <option id="random" _label="Random 3D"/> <option id="perspective-3d" _label="Perspective 3D" arg-set="-projection-3d perspective"/> diff --git a/hacks/config/razzledazzle.xml b/hacks/config/razzledazzle.xml index 1af07df..043788e 100644 --- a/hacks/config/razzledazzle.xml +++ b/hacks/config/razzledazzle.xml @@ -29,7 +29,7 @@ low="1.0" high="10.0" default="5.0"/> <number id="thickness" type="slider" arg="-thickness %" - _label="Lines" _low-label="Thick" _high-label="Thin" + _label="Lines" _low-label="Thin" _high-label="Thick" low="0.05" high="1.0" default="0.1"/> <select id="object"> diff --git a/hacks/config/romanboy.xml b/hacks/config/romanboy.xml index b2f6cb4..941317c 100644 --- a/hacks/config/romanboy.xml +++ b/hacks/config/romanboy.xml @@ -55,11 +55,15 @@ <select id="colors"> <option id="random" _label="Random coloration"/> + <option id="twosided" _label="One-sided" arg-set="-colors one-sided"/> <option id="twosided" _label="Two-sided" arg-set="-colors two-sided"/> <option id="rainbow" _label="Distance colors" arg-set="-colors distance"/> <option id="rainbow" _label="Direction colors" arg-set="-colors direction"/> </select> + <boolean id="change-colors" _label="Change colors" + arg-set="-change-colors"/> + <select id="projection"> <option id="random" _label="Random Projection"/> <option id="perspective" _label="Perspective" arg-set="-projection perspective"/> diff --git a/hacks/config/scooter.xml b/hacks/config/scooter.xml new file mode 100644 index 0000000..72fe9b3 --- /dev/null +++ b/hacks/config/scooter.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> + +<screensaver name="scooter" _label="Scooter" gl="no"> + + <command arg="-root"/> + + <video href="https://www.youtube.com/watch?v=Qqzk1BldlXg"/> + + <hgroup> + <vgroup> + <number id="delay" type="slider" arg="-delay %" + _label="Frame rate" _low-label="Low" _high-label="High" + low="0" high="100000" default="20000" + convert="invert"/> + <number id="cycles" type="slider" arg="-cycles %" + _label="Boat Speed" _low-label="Very slow" _high-label="Very fast" + low="0" high="1000" default="5"/> + <number id="count" type="slider" arg="-count %" + _label="Number of doors" _low-label="4" _high-label="40" + low="4" high="40" default="24"/> + </vgroup> + <vgroup> + <number id="size" type="slider" arg="-size %" + _label="Number of stars" _low-label="1" _high-label="200" + low="0" high="200" default="100"/> + <number id="ncolors" type="slider" arg="-ncolors %" + _label="Number of colors" _low-label="Mono" _high-label="Colorful" + low="0" high="200" default="200"/> + + <boolean id="showfps" _label="Show frame rate" arg-set="-fps"/> + + <xscreensaver-updater /> + </vgroup> + </hgroup> + + <_description> +Zooming down a tunnel in a star field. Originally an Amiga hack. + +Written by Sven Thoennissen; 2001. +Ported by EoflaOE; 2019. + </_description> +</screensaver> diff --git a/hacks/drift.c b/hacks/drift.c index e88986b..376d926 100644 --- a/hacks/drift.c +++ b/hacks/drift.c @@ -631,7 +631,8 @@ draw_drift(ModeInfo * mi) if (dp->total_points++ > dp->fractal_len) { draw_flush(mi, dp, window); if (0 == --dp->nfractals) { - dp->erase_countdown = 4 * 1000000 / MI_PAUSE(mi); + dp->erase_countdown = 4 * 1000000 / + ((MI_PAUSE(mi) == 0) ? 1 : MI_PAUSE(mi)); return; } initfractal(mi); diff --git a/hacks/eruption.c b/hacks/eruption.c index 3f68cf7..a4cfc25 100644 --- a/hacks/eruption.c +++ b/hacks/eruption.c @@ -10,13 +10,24 @@ * * Module - "eruption.c" * + * [01-2015] - Dave Odell <dmo2118@gmail.com>: Performance tweaks. Also, click-for-explosion. * [02-2003] - W.P. van Paassen: Improvements, added some code of jwz from the pyro hack for a spherical distribution of the particles * [01-2003] - W.P. van Paassen: Port to X for use with XScreenSaver, the shadebob hack by Shane Smit was used as a template * [04-2002] - W.P. van Paassen: Creation for the Demo Effects Collection (http://demo-effects.sourceforge.net) */ +#include <assert.h> #include <math.h> #include "screenhack.h" +#include "xshm.h" + +#ifdef HAVE_INTTYPES_H +# include <inttypes.h> +#else +typedef unsigned long uint32_t; +typedef unsigned short uint16_t; +typedef unsigned char uint8_t; +#endif /*#define VERBOSE*/ @@ -42,7 +53,7 @@ struct state { PARTICLE *particles; unsigned short iWinWidth, iWinHeight; - unsigned char **fire; + unsigned char *fire; unsigned short nParticleCount; unsigned char xdelta, ydelta, decay; signed char gravity; @@ -53,6 +64,7 @@ struct state { signed short iColorCount; unsigned long *aiColorVals; XImage *pImage; + XShmSegmentInfo shm_info; int draw_i; }; @@ -85,12 +97,18 @@ static void init_particle(struct state *st, PARTICLE* particle, unsigned short x particle->dead = 0; } +#define X_PAD 1 /* Could be more if anybody wants the blur to fall off the left/right edges. */ +#define Y_PAD 1 + + static void Execute( struct state *st ) { + XImage *img = st->pImage; int i, j; - unsigned int temp; + size_t fire_pitch = st->iWinWidth + X_PAD * 2; + unsigned char *line0, *line1, *line2; - /* move and draw particles into st->fire array */ + /* move particles */ for (i = 0; i < st->nParticleCount; i++) { @@ -141,74 +159,123 @@ static void Execute( struct state *st ) /* particle cools off */ st->particles[i].colorindex--; - - /* draw particle */ - if (st->iWinHeight <= 2 || st->iWinWidth <= 2) continue; - st->fire[st->particles[i].ypos][st->particles[i].xpos] = st->particles[i].colorindex; - st->fire[st->particles[i].ypos][st->particles[i].xpos - 1] = st->particles[i].colorindex; - st->fire[st->particles[i].ypos + 1][st->particles[i].xpos] = st->particles[i].colorindex; - st->fire[st->particles[i].ypos - 1][st->particles[i].xpos] = st->particles[i].colorindex; - st->fire[st->particles[i].ypos][st->particles[i].xpos + 1] = st->particles[i].colorindex; } } - - /* create st->fire effect */ - for (i = 0; i < st->iWinHeight; i++) + + /* draw particles into st->fire array */ + for( i = 0; i < st->nParticleCount; i++ ) { - for (j = 0; j < st->iWinWidth; j++) - { - if (j + 1 >= st->iWinWidth) - temp = 0; - else - temp = st->fire[i][j + 1]; + PARTICLE *p = &st->particles[i]; + if( !p->dead && p->ypos >= -Y_PAD + 1 && p->ypos < st->iWinHeight + Y_PAD - 1 ) + { + /* draw particle */ + unsigned char *center = st->fire + (p->ypos - -Y_PAD) * fire_pitch + (p->xpos + X_PAD); + unsigned char color = p->colorindex; + *center = color; + center[-1] = color; + if (p->ypos < st->iWinHeight + Y_PAD - 2) + center[fire_pitch] = color; + if (p->ypos >= -Y_PAD + 2) + center[-fire_pitch] = color; + center[1] = color; + } + } - if (j - 1 >= 0) - temp += st->fire[i][j - 1]; + line0 = st->fire + X_PAD; + line1 = line0 + fire_pitch; + line2 = line1 + fire_pitch; - if (i - 1 >= 0) - { - temp += st->fire[i - 1][j]; - if (j - 1 >= 0) - temp += st->fire[i - 1][j - 1]; - if (j + 1 < st->iWinWidth) - temp += st->fire[i - 1][j + 1]; - } - - if (i + 1 < st->iWinHeight) - { - temp += st->fire[i + 1][j]; - if (j + 1 < st->iWinWidth) - temp += st->fire[i + 1][j + 1]; - if (j - 1 >= 0) - temp += st->fire[i + 1][j - 1]; - } - - temp >>= 3; - - if (temp > st->decay) - { - temp -= st->decay; - } - else - temp = 0; - - st->fire[i][j] = temp; - } + /* create st->fire effect */ + + switch( img->bits_per_pixel ) + { + case 8: + case 16: + case 32: + break; + default: + memset( img->data, 0, img->bytes_per_line * img->height ); + break; } - - memset( st->pImage->data, 0, st->pImage->bytes_per_line * st->pImage->height ); - - /* draw st->fire array to screen */ - for (i = 0; i < st->iWinHeight; ++i) + + for( i = -Y_PAD + 1; i < st->iWinHeight + Y_PAD - 1; i++ ) { - for (j = 0; j < st->iWinWidth; ++j) - { - if (st->fire[i][j] > 0) - XPutPixel( st->pImage, j, i, st->aiColorVals[ st->fire[i][j] ] ); - } + const int j0 = -X_PAD + 1; + + unsigned + t0 = line0[j0 - 1] + line1[j0 - 1] + line2[j0 - 1], + t1 = line0[j0] + line1[j0] + line2[j0]; + + unsigned j1 = st->iWinWidth + X_PAD; + + /* This is basically like the GIMP's "Convolution Matrix" filter, with + the following settings: + Matrix: + | 1 1 1 | Divisor = 8 + | 1 0 1 | Offset = -eruption.cooloff + | 1 1 1 | + Except that the effect is applied to each pixel individually, in order + from left-to-right, then top-to-bottom, resulting in a slight smear + going rightwards and downwards. + */ + + for( j = j0 + 1; j != j1; j++ ) + { + unsigned t2 = line0[j] + line1[j] + line2[j]; + unsigned char *px = line1 + j - 1; + int temp; + t1 -= *px; + temp = t0 + t1 + t2 - st->decay; + temp = temp >= 0 ? temp >> 3 : 0; + *px = temp; + t0 = t1 + temp; + t1 = t2; + } + + if( i >= 0 && i < st->iWinHeight ) + { + /* draw st->fire array to screen */ + void *out_ptr = img->data + img->bytes_per_line * i; + + switch( img->bits_per_pixel ) + { + case 32: + { + uint32_t *out = (uint32_t *)out_ptr; + for( j = 0; j < st->iWinWidth; ++j ) + out[j] = st->aiColorVals[ line1[j] ]; + } + break; + case 16: + { + uint16_t *out = (uint16_t *)out_ptr; + for( j = 0; j < st->iWinWidth; ++j ) + out[j] = st->aiColorVals[ line1[j] ]; + } + break; + case 8: + { + uint8_t *out = (uint8_t *)out_ptr; + for( j = 0; j < st->iWinWidth; ++j ) + out[j] = st->aiColorVals[ line1[j] ]; + } + break; + default: + for( j = 0; j < st->iWinWidth; ++j ) + { + if( line1[j] ) + XPutPixel( img, j, i, st->aiColorVals[ line1[j] ] ); + } + break; + } + } + + line0 += fire_pitch; + line1 += fire_pitch; + line2 += fire_pitch; } - XPutImage( st->dpy, st->window, st->gc, st->pImage, - 0,0,0,0, st->iWinWidth, st->iWinHeight ); + put_xshm_image( st->dpy, st->window, st->gc, st->pImage, + 0,0,0,0, st->iWinWidth, st->iWinHeight, &st->shm_info ); } static unsigned long * SetPalette(struct state *st) @@ -294,43 +361,41 @@ static unsigned long * SetPalette(struct state *st) } -static void Initialize( struct state *st ) +static void DestroyImage (struct state *st) { - XGCValues gcValues; - XWindowAttributes XWinAttribs; - int /*iBitsPerPixel,*/ i; + free (st->fire); + destroy_xshm_image (st->dpy, st->pImage, &st->shm_info); +} - /* Create the Image for drawing */ - XGetWindowAttributes( st->dpy, st->window, &XWinAttribs ); +static void CreateImage( struct state *st, XWindowAttributes *XWinAttribs ) +{ + /* Create the Image for drawing */ - /* Find the preferred bits-per-pixel. (jwz) */ - { - int pfvc = 0; - XPixmapFormatValues *pfv = XListPixmapFormats( st->dpy, &pfvc ); - for( i=0; i<pfvc; i++ ) - if( pfv[ i ].depth == XWinAttribs.depth ) - { - /*iBitsPerPixel = pfv[ i ].bits_per_pixel;*/ - break; - } - if( pfv ) - XFree (pfv); - } + /* Must be NULL because of how DestroyImage works. */ + assert( !st->fire ); - /* Create the GC. */ - st->gc = XCreateGC( st->dpy, st->window, 0, &gcValues ); + st->pImage = create_xshm_image( st->dpy, XWinAttribs->visual, + XWinAttribs->depth, ZPixmap, &st->shm_info, + XWinAttribs->width, XWinAttribs->height ); + + memset( (st->pImage)->data, 0, + (st->pImage)->bytes_per_line * (st->pImage)->height); - st->pImage = XCreateImage( st->dpy, XWinAttribs.visual, XWinAttribs.depth, ZPixmap, 0, NULL, - XWinAttribs.width, XWinAttribs.height, BitmapPad( st->dpy ), 0 ); - (st->pImage)->data = calloc((st->pImage)->bytes_per_line, (st->pImage)->height); + st->iWinWidth = XWinAttribs->width; + st->iWinHeight = XWinAttribs->height; + + /* create st->fire array */ + st->fire = calloc( (st->iWinHeight + Y_PAD * 2) * (st->iWinWidth + X_PAD * 2), sizeof(unsigned char)); +} - st->iWinWidth = XWinAttribs.width; - st->iWinHeight = XWinAttribs.height; +static void Initialize( struct state *st, XWindowAttributes *XWinAttribs ) +{ + XGCValues gcValues; + + /* Create the GC. */ + st->gc = XCreateGC( st->dpy, st->window, 0, &gcValues ); - /* create st->fire array */ - st->fire = calloc( st->iWinHeight, sizeof(unsigned char*)); - for (i = 0; i < st->iWinHeight; ++i) - st->fire[i] = calloc( st->iWinWidth, sizeof(unsigned char)); + CreateImage (st, XWinAttribs); /*create st->particles */ st->particles = malloc (st->nParticleCount * sizeof(PARTICLE)); @@ -361,6 +426,7 @@ eruption_init (Display *dpy, Window window) st->decay = 0; if (st->decay > 10) st->decay = 10; + st->decay <<= 3; st->gravity = get_integer_resource(st->dpy, "gravity", "Integer" ); if (st->gravity < -5) @@ -378,7 +444,9 @@ eruption_init (Display *dpy, Window window) printf( "%s: Allocated %d st->particles\n", progclass, st->nParticleCount ); #endif /* VERBOSE */ - Initialize( st ); + XGetWindowAttributes( st->dpy, st->window, &XWinAttribs ); + + Initialize( st, &XWinAttribs ); st->ydelta = 0; while (sum < (st->iWinHeight >> 1) - SPREAD) @@ -399,12 +467,10 @@ eruption_init (Display *dpy, Window window) cache(st); - XGetWindowAttributes( st->dpy, st->window, &XWinAttribs ); XFreeColors( st->dpy, XWinAttribs.colormap, st->aiColorVals, st->iColorCount, 0 ); free( st->aiColorVals ); st->aiColorVals = SetPalette( st ); XClearWindow( st->dpy, st->window ); - memset( st->pImage->data, 0, st->pImage->bytes_per_line * st->pImage->height ); st->draw_i = -1; @@ -412,6 +478,23 @@ eruption_init (Display *dpy, Window window) } +static void +new_eruption (struct state *st, unsigned short xcenter, unsigned short ycenter) +{ + for (st->draw_i = 0; st->draw_i < st->nParticleCount; st->draw_i++) + init_particle(st, st->particles + st->draw_i, xcenter, ycenter); + st->draw_i = 0; +} + + +static void +random_eruption (struct state *st) +{ + /* compute random center */ + new_eruption (st, random() % st->iWinWidth, random() % st->iWinHeight); +} + + static unsigned long eruption_draw (Display *dpy, Window window, void *closure) { @@ -419,14 +502,7 @@ eruption_draw (Display *dpy, Window window, void *closure) if( st->draw_i < 0 || st->draw_i++ >= st->cycles ) { - /* compute random center */ - unsigned short xcenter, ycenter; - xcenter = random() % st->iWinWidth; - ycenter = random() % st->iWinHeight; - - for (st->draw_i = 0; st->draw_i < st->nParticleCount; st->draw_i++) - init_particle(st, st->particles + st->draw_i, xcenter, ycenter); - st->draw_i = 0; + random_eruption (st); } Execute( st ); @@ -451,31 +527,33 @@ eruption_reshape (Display *dpy, Window window, void *closure, { struct state *st = (struct state *) closure; XWindowAttributes XWinAttribs; - int i; - for (i = 0; i < st->iWinHeight; ++i) - free (st->fire[i]); + DestroyImage (st); + st->fire = NULL; - st->iWinWidth = w; - st->iWinHeight = h; - - free (st->fire); - st->fire = calloc( st->iWinHeight, sizeof(unsigned char*)); - for (i = 0; i < st->iWinHeight; ++i) - st->fire[i] = calloc( st->iWinWidth, sizeof(unsigned char)); - - XDestroyImage( st->pImage ); XGetWindowAttributes( st->dpy, st->window, &XWinAttribs ); - st->pImage = XCreateImage( st->dpy, XWinAttribs.visual, XWinAttribs.depth, ZPixmap, 0, NULL, - XWinAttribs.width, XWinAttribs.height, BitmapPad( st->dpy ), 0 ); - (st->pImage)->data = calloc((st->pImage)->bytes_per_line, (st->pImage)->height); - + XWinAttribs.width = w; + XWinAttribs.height = h; + CreateImage (st, &XWinAttribs); st->draw_i = -1; } static Bool eruption_event (Display *dpy, Window window, void *closure, XEvent *event) { + struct state *st = (struct state *) closure; + + if (event->type == ButtonPress) + { + new_eruption (st, event->xbutton.x, event->xbutton.y); + return True; + } + else if (screenhack_event_helper (dpy, window, event)) + { + random_eruption (st); + return True; + } + return False; } @@ -483,12 +561,8 @@ static void eruption_free (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; - int i; - XDestroyImage (st->pImage); + DestroyImage (st); free (st->aiColorVals); - for (i = 0; i < st->iWinHeight; ++i) - free (st->fire[i]); - free (st->fire); free (st->particles); XFreeGC (dpy, st->gc); free (st); @@ -506,6 +580,8 @@ static const char *eruption_defaults [] = { "*cooloff: 2", "*gravity: 1", "*heat: 256", + ".lowrez: true", /* Too slow on Retina screens otherwise */ + "*useSHM: True", 0 }; @@ -517,6 +593,10 @@ static XrmOptionDescRec eruption_options [] = { { "-cooloff", ".cooloff", XrmoptionSepArg, 0 }, { "-gravity", ".gravity", XrmoptionSepArg, 0 }, { "-heat", ".heat", XrmoptionSepArg, 0 }, +#ifdef HAVE_XSHM_EXTENSION + { "-shm", ".useSHM", XrmoptionNoArg, "True" }, + { "-no-shm", ".useSHM", XrmoptionNoArg, "False" }, +#endif { 0, 0, 0, 0 } }; diff --git a/hacks/filmleader.c b/hacks/filmleader.c index 2aabb9d..c242083 100644 --- a/hacks/filmleader.c +++ b/hacks/filmleader.c @@ -546,13 +546,22 @@ static const char *filmleader_defaults [] = { # endif -# ifdef USE_IPHONE + /* Note: these font sizes aren't relative to screen pixels, but to the + 712 x Y or X x 712 canvas that we draw in, which is then scaled to + the size of the screen by analogtv. */ +# ifdef USE_IPHONE "*numberFont: Helvetica Bold 120", "*numberFont2: Helvetica 36", "*numberFont3: Helvetica 28", -# else /* X11, Cocoa or Android */ +# elif defined(HAVE_COCOA) + /* Need to double these because ANALOGTV_DEFAULTS sets lowrez: true */ + "*numberFont: Helvetica Bold 240", + "*numberFont2: Helvetica 72", + "*numberFont3: Helvetica 56", + +# else /* X11 or Android */ "*numberFont: -*-helvetica-bold-r-*-*-*-1700-*-*-*-*-*-*", "*numberFont2: -*-helvetica-medium-r-*-*-*-500-*-*-*-*-*-*", diff --git a/hacks/fireworkx.c b/hacks/fireworkx.c index 57ba128..12d9864 100644 --- a/hacks/fireworkx.c +++ b/hacks/fireworkx.c @@ -862,6 +862,7 @@ static const char *fireworkx_defaults [] = "*flash: True", "*shoot: False", "*verbose: False", + ".lowrez: true", /* Too slow on Retina screens otherwise */ 0 }; diff --git a/hacks/glx/Makefile.in b/hacks/glx/Makefile.in index 482bed3..7ddb223 100644 --- a/hacks/glx/Makefile.in +++ b/hacks/glx/Makefile.in @@ -137,7 +137,8 @@ SRCS = xscreensaver-gl-helper.c normals.c erase-gl.c fps-gl.c \ raverhoop.c hydrostat.c discoball.c cubetwist.c cubestack.c \ splodesic.c hexstrut.c vigilance.c seccam.c esper.c \ razzledazzle.c ships.c peepers.c crumbler.c quickhull.c \ - maze3d.c handsy.c handsy_model.c gravitywell.c deepstars.c + maze3d.c handsy.c handsy_model.c gravitywell.c deepstars.c \ + gibson.c etruscanvenus.c OBJS = xscreensaver-gl-helper.o normals.o erase-gl.o fps-gl.o \ atlantis.o b_draw.o b_lockglue.o b_sphere.o bubble3d.o \ @@ -184,7 +185,8 @@ OBJS = xscreensaver-gl-helper.o normals.o erase-gl.o fps-gl.o \ raverhoop.o hydrostat.o discoball.o cubetwist.o cubestack.o \ splodesic.o hexstrut.o vigilance.o seccam.o esper.o \ razzledazzle.o ships.o peepers.o crumbler.o quickhull.o \ - maze3d.o handsy.o handsy_model.o gravitywell.o deepstars.o + maze3d.o handsy.o handsy_model.o gravitywell.o deepstars.o \ + gibson.o etruscanvenus.o GL_EXES = cage gears moebius pipes sproingies stairs superquadrics \ morph3d rubik atlantis lament bubble3d glplanet pulsar \ @@ -205,7 +207,7 @@ GL_EXES = cage gears moebius pipes sproingies stairs superquadrics \ splitflap dymaxionmap unicrud energystream raverhoop \ hydrostat discoball cubetwist cubestack splodesic \ hexstrut vigilance esper razzledazzle peepers crumbler \ - maze3d handsy gravitywell deepstars + maze3d handsy gravitywell deepstars gibson etruscanvenus GLE_EXES = extrusion SUID_EXES = sonar SETCAP_EXES = sonar @@ -273,7 +275,7 @@ GL_MEN = atlantis.man boxed.man bubble3d.man cage.man circuit.man \ discoball.man cubetwist.man cubestack.man splodesic.man \ hexstrut.man vigilance.man esper.man razzledazzle.man \ peepers.man crumbler.man maze3d.man handsy.man \ - gravitywell.man deepstars.man + gravitywell.man deepstars.man gibson.man etruscanvenus.man MEN = @GL_MEN@ RETIRED_MEN = glforestfire.man EXTRAS = README Makefile.in dxf2gl.pl vrml2gl.pl wfront2gl.pl \ @@ -791,6 +793,9 @@ projectiveplane: projectiveplane.o $(HACK_TRACK_OBJS) romanboy: romanboy.o $(HACK_TRACK_OBJS) $(CC_HACK) -o $@ $@.o $(HACK_TRACK_OBJS) $(HACK_LIBS) +etruscanvenus: etruscanvenus.o $(HACK_TRACK_OBJS) + $(CC_HACK) -o $@ $@.o $(HACK_TRACK_OBJS) $(HACK_LIBS) + glmatrix: glmatrix.o $(PNG) $(HACK_OBJS) $(CC_HACK) -o $@ $@.o $(PNG) $(HACK_OBJS) $(PNG_LIBS) @@ -1033,6 +1038,9 @@ gravitywell: gravitywell.o $(HACK_TRACK_OBJS) deepstars: deepstars.o $(HACK_TRACK_OBJS) $(CC_HACK) -o $@ $@.o $(HACK_TRACK_OBJS) $(HACK_LIBS) +gibson: gibson.o $(PNG) $(HACK_TRACK_OBJS) + $(CC_HACK) -o $@ $@.o $(PNG) $(HACK_TRACK_OBJS) $(PNG_LIBS) + ############################################################################## # # DO NOT DELETE: updated by make distdepend @@ -1731,6 +1739,23 @@ esper.o: $(UTILS_SRC)/xshm.h esper.o: $(UTILS_SRC)/yarandom.h esper.o: $(HACK_SRC)/xlockmoreI.h esper.o: $(HACK_SRC)/xlockmore.h +etruscanvenus.o: ../../config.h +etruscanvenus.o: $(srcdir)/curlicue.h +etruscanvenus.o: $(HACK_SRC)/fps.h +etruscanvenus.o: $(srcdir)/gltrackball.h +etruscanvenus.o: $(HACK_SRC)/recanim.h +etruscanvenus.o: $(HACK_SRC)/screenhackI.h +etruscanvenus.o: $(UTILS_SRC)/colors.h +etruscanvenus.o: $(UTILS_SRC)/erase.h +etruscanvenus.o: $(UTILS_SRC)/font-retry.h +etruscanvenus.o: $(UTILS_SRC)/grabscreen.h +etruscanvenus.o: $(UTILS_SRC)/hsv.h +etruscanvenus.o: $(UTILS_SRC)/resources.h +etruscanvenus.o: $(UTILS_SRC)/usleep.h +etruscanvenus.o: $(UTILS_SRC)/visual.h +etruscanvenus.o: $(UTILS_SRC)/yarandom.h +etruscanvenus.o: $(HACK_SRC)/xlockmoreI.h +etruscanvenus.o: $(HACK_SRC)/xlockmore.h extrusion-helix2.o: ../../config.h extrusion-helix2.o: $(srcdir)/extrusion.h extrusion-helix3.o: ../../config.h @@ -1966,6 +1991,23 @@ gflux.o: $(UTILS_SRC)/visual.h gflux.o: $(UTILS_SRC)/yarandom.h gflux.o: $(HACK_SRC)/xlockmoreI.h gflux.o: $(HACK_SRC)/xlockmore.h +gibson.o: ../../config.h +gibson.o: $(HACK_SRC)/fps.h +gibson.o: $(HACK_SRC)/recanim.h +gibson.o: $(srcdir)/rotator.h +gibson.o: $(HACK_SRC)/screenhackI.h +gibson.o: $(srcdir)/texfont.h +gibson.o: $(UTILS_SRC)/colors.h +gibson.o: $(UTILS_SRC)/erase.h +gibson.o: $(UTILS_SRC)/font-retry.h +gibson.o: $(UTILS_SRC)/grabscreen.h +gibson.o: $(UTILS_SRC)/hsv.h +gibson.o: $(UTILS_SRC)/resources.h +gibson.o: $(UTILS_SRC)/usleep.h +gibson.o: $(UTILS_SRC)/visual.h +gibson.o: $(UTILS_SRC)/yarandom.h +gibson.o: $(HACK_SRC)/xlockmoreI.h +gibson.o: $(HACK_SRC)/xlockmore.h glblur.o: ../../config.h glblur.o: $(HACK_SRC)/fps.h glblur.o: $(srcdir)/gltrackball.h diff --git a/hacks/glx/deepstars.c b/hacks/glx/deepstars.c index b477e00..f415f18 100644 --- a/hacks/glx/deepstars.c +++ b/hacks/glx/deepstars.c @@ -11,13 +11,13 @@ #ifdef STANDALONE #define DEFAULTS "*delay: 30000 \n" \ - "*showFPS: False \n" \ - "*suppressRotationAnimation: True\n" \ + "*showFPS: False \n" \ + "*suppressRotationAnimation: True\n" \ # define release_deepstars 0 -# include "xlockmore.h" /* from the xscreensaver distribution */ +# include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ -# include "xlock.h" /* from the xlockmore distribution */ +# include "xlock.h" /* from the xlockmore distribution */ #endif /* !STANDALONE */ #ifdef USE_GL /* whole file */ diff --git a/hacks/glx/etruscanvenus.c b/hacks/glx/etruscanvenus.c new file mode 100644 index 0000000..71af80a --- /dev/null +++ b/hacks/glx/etruscanvenus.c @@ -0,0 +1,1825 @@ +/* etruscanvenus --- Shows a 3d immersion of a Klein bottle that + rotates in 3d or on which you can walk and that can deform smoothly + between the Etruscan Venus surface, the Roman surface, the Boy + surface surface, and the Ida surface. */ + +#if 0 +static const char sccsid[] = "@(#)etruscanvenus.c 1.1 05/01/20 xlockmore"; +#endif + +/* Copyright (c) 2019-2020 Carsten Steger <carsten@mirsanmir.org>. */ + +/* + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appear in all copies and that + * both that copyright notice and this permission notice appear in + * supporting documentation. + * + * This file is provided AS IS with no warranties of any kind. The author + * shall have no liability with respect to the infringement of copyrights, + * trade secrets or any patents by this file or any part thereof. In no + * event will the author be liable for any lost revenue or profits or + * other special, indirect and consequential damages. + * + * REVISION HISTORY: + * C. Steger - 05/01/20: Initial version + */ + +/* + * This program shows a 3d immersion of a Klein bottle that smoothly + * deforms between the Etruscan Venus surface, the Roman surface, the + * Boy surface, and the Ida surface. You can walk on the Klein bottle + * or turn it in 3d. Topologically, all surfaces are Klein bottles, + * even the Roman and Boy surfaces, which are doubly covered and + * therefore appear to be an immersed real projective plane. The + * smooth deformation between these surfaces was constructed by George + * K. Francis. + * + * The Klein bottle is a non-orientable surface. To make this + * apparent, the two-sided color mode can be used. Alternatively, + * orientation markers (curling arrows) can be drawn as a texture map + * on the surface of the Klein bottle. While walking on the Klein + * bottle, you will notice that the orientation of the curling arrows + * changes (which it must because the Klein bottle is non-orientable). + * Since all the surfaces except the Ida surface have points where the + * surface normal is not well defined for some points, walking is only + * performed on the Ida surface. + * + * As mentioned above, the Roman and Boy surfaces are doubly covered + * and therefore appear to be an immersed real projective plane. + * Since some of the parameter names are based on this interpretation + * of the surface, the geometry of the real projective plane will be + * briefly disussed. The real projective plane is a model for the + * projective geometry in 2d space. One point can be singled out as + * the origin. A line can be singled out as the line at infinity, + * i.e., a line that lies at an infinite distance to the origin. The + * line at infinity is topologically a circle. Points on the line at + * infinity are also used to model directions in projective geometry. + * Direction and distance bands refer to this interpretation of the + * surface. If direction bands are used, the bands extend from the + * origin of the projective plane in different directions to the line + * at infinity and back to the origin. If distance bands are used, + * the bands lie at constant distances to the origin. The same + * interpretation is used for distance and direction colors. Although + * there is no conceptually equivalent geometric interpretation for + * the two Klein bottle surfaces (the Etruscan Venus and Ida + * surfaces), the smooth deformation between the surfaces results in a + * natural extension of these concepts to the Klein bottle surfaces. + * + * The immersed surfaces can be projected to the screen either + * perspectively or orthographically. When using the walking mode, + * perspective projection to the screen will be used. + * + * There are three display modes for the Klein bottle: mesh + * (wireframe), solid, or transparent. Furthermore, the appearance of + * the surface can be as a solid object or as a set of see-through + * bands. The bands can be distance bands or direction bands, as + * explained above. + * + * The colors with with the Klein bottle is drawn can be set to + * one-sided, two-sided, distance, or direction. In one-sided mode, + * the surface is drawn with the same color on both sides of the + * underlying triangles. In two-sided mode, the surface is drawn with + * red on one side of the underlying triangles and green on the other + * side. Since the surface actually only has one side, the color + * jumps from red to green along a line on the surface. This mode + * enables you to see that the surface is non-orientable. In distance + * mode, the surface is displayed with fully saturated colors that + * depend on the distance of the points on the projective plane to the + * origin, as described above. If the surface is displayed as + * distance bands, each band will be displayed with a different color. + * In direction mode, the surface is displayed with fully saturated + * colors that depend on the angle of the points on the projective + * plane with respect to the origin (see above for an explanation). + * If the surface is displayed as direction bands, each band will be + * displayed with a different color. The colors used to color the + * surface can either be static or can be changed dynamically. + * + * The rotation speed for each of the three coordinate axes around + * which the Klein bottle rotates can be chosen. + * + * Furthermore, in the walking mode the walking direction in the 2d + * base square of the surface and the walking speed can be chosen. + * The walking direction is measured as an angle in degrees in the 2d + * square that forms the coordinate system of the surface. A value of + * 0 or 180 means that the walk is along a circle at a randomly chosen + * distance from the origin (parallel to a distance band). A value of + * 90 or 270 means that the walk is directly along a direction band. + * Any other value results in a curved path along the surface. As + * noted above, walking is performed only on the Ida surface. + * + * By default, the immersion of the Klein bottle smoothly deforms + * between the Etruscan Venus surface, the Roman surface, the Boy + * surface, and the Ida surface. It is possible to choose the speed + * of the deformation. Furthermore, it is possible to switch the + * deformation off. It is also possible to determine the initial + * deformation of the immersion. This is mostly useful if the + * deformation is switched off, in which case it will determine the + * appearance of the surface. A value of 0 corresponds to the + * Etruscan Venus surface, a value of 1000 to the Roman surface, a + * value of 2000 to the Boy surface, and a value of 3000 to the Ida + * surface. + * + * This program is inspired by George K. Francis's book "A Topological + * Picturebook", Springer, 1987, by George K. Francis's paper "The + * Etruscan Venus" in P. Concus, R. Finn, and D. A. Hoffman: + * "Geometric Analysis and Computer Graphics", Springer, 1991, and by + * a video entitled "The Etruscan Venus" by Donna J. Cox, George + * K. Francis, and Raymond L. Idaszak, presented at SIGGRAPH 1989. + */ + +#include "curlicue.h" + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define DISP_WIREFRAME 0 +#define DISP_SURFACE 1 +#define DISP_TRANSPARENT 2 +#define NUM_DISPLAY_MODES 3 + +#define APPEARANCE_SOLID 0 +#define APPEARANCE_DISTANCE_BANDS 1 +#define APPEARANCE_DIRECTION_BANDS 2 +#define NUM_APPEARANCES 3 + +#define COLORS_ONESIDED 0 +#define COLORS_TWOSIDED 1 +#define COLORS_DISTANCE 2 +#define COLORS_DIRECTION 3 +#define NUM_COLORS 4 + +#define VIEW_WALK 0 +#define VIEW_TURN 1 +#define NUM_VIEW_MODES 2 + +#define DISP_PERSPECTIVE 0 +#define DISP_ORTHOGRAPHIC 1 +#define NUM_DISP_MODES 2 + +#define DEF_DISPLAY_MODE "random" +#define DEF_APPEARANCE "random" +#define DEF_COLORS "random" +#define DEF_VIEW_MODE "random" +#define DEF_MARKS "False" +#define DEF_CHANGE_COLORS "True" +#define DEF_DEFORM "True" +#define DEF_PROJECTION "random" +#define DEF_SPEEDX "1.1" +#define DEF_SPEEDY "1.3" +#define DEF_SPEEDZ "1.5" +#define DEF_WALK_DIRECTION "83.0" +#define DEF_WALK_SPEED "20.0" +#define DEF_DEFORM_SPEED "10.0" +#define DEF_INIT_DEFORM "0.0" + +#ifdef STANDALONE +# define DEFAULTS "*delay: 10000 \n" \ + "*showFPS: False \n" \ + +# define release_etruscanvenus 0 +# include "xlockmore.h" /* from the xscreensaver distribution */ +#else /* !STANDALONE */ +# include "xlock.h" /* from the xlockmore distribution */ +#endif /* !STANDALONE */ + +#ifdef USE_GL + +#ifndef HAVE_JWXYZ +# include <X11/keysym.h> +#endif + +#include "gltrackball.h" + +#include <float.h> + + +#ifdef USE_MODULES +ModStruct etruscanvenus_description = +{"etruscanvenus", "init_etruscanvenus", "draw_etruscanvenus", + NULL, "draw_etruscanvenus", "change_etruscanvenus", + "free_etruscanvenus", &etruscanvenus_opts, 25000, 1, 1, 1, 1.0, 4, "", + "Rotate a 3d immersion of a Klein bottle in 3d or walk on it", + 0, NULL}; + +#endif + + +static char *mode; +static char *appear; +static char *color_mode; +static char *view_mode; +static Bool marks; +static Bool deform; +static Bool change_colors; +static char *proj; +static float speed_x; +static float speed_y; +static float speed_z; +static float walk_direction; +static float walk_speed; +static float deform_speed; +static float init_deform; + + +static XrmOptionDescRec opts[] = +{ + {"-mode", ".displayMode", XrmoptionSepArg, 0 }, + {"-wireframe", ".displayMode", XrmoptionNoArg, "wireframe" }, + {"-surface", ".displayMode", XrmoptionNoArg, "surface" }, + {"-transparent", ".displayMode", XrmoptionNoArg, "transparent" }, + {"-appearance", ".appearance", XrmoptionSepArg, 0 }, + {"-solid", ".appearance", XrmoptionNoArg, "solid" }, + {"-distance-bands", ".appearance", XrmoptionNoArg, "distance-bands" }, + {"-direction-bands", ".appearance", XrmoptionNoArg, "direction-bands" }, + {"-colors", ".colors", XrmoptionSepArg, 0 }, + {"-onesided-colors", ".colors", XrmoptionNoArg, "one-sided" }, + {"-twosided-colors", ".colors", XrmoptionNoArg, "two-sided" }, + {"-distance-colors", ".colors", XrmoptionNoArg, "distance" }, + {"-direction-colors", ".colors", XrmoptionNoArg, "direction" }, + {"-change-colors", ".changeColors", XrmoptionNoArg, "on"}, + {"+change-colors", ".changeColors", XrmoptionNoArg, "off"}, + {"-view-mode", ".viewMode", XrmoptionSepArg, 0 }, + {"-walk", ".viewMode", XrmoptionNoArg, "walk" }, + {"-turn", ".viewMode", XrmoptionNoArg, "turn" }, + {"-deform", ".deform", XrmoptionNoArg, "on"}, + {"+deform", ".deform", XrmoptionNoArg, "off"}, + {"-orientation-marks", ".marks", XrmoptionNoArg, "on"}, + {"+orientation-marks", ".marks", XrmoptionNoArg, "off"}, + {"-projection", ".projection", XrmoptionSepArg, 0 }, + {"-perspective", ".projection", XrmoptionNoArg, "perspective" }, + {"-orthographic", ".projection", XrmoptionNoArg, "orthographic" }, + {"-speed-x", ".speedx", XrmoptionSepArg, 0 }, + {"-speed-y", ".speedy", XrmoptionSepArg, 0 }, + {"-speed-z", ".speedz", XrmoptionSepArg, 0 }, + {"-walk-direction", ".walkDirection", XrmoptionSepArg, 0 }, + {"-walk-speed", ".walkSpeed", XrmoptionSepArg, 0 }, + {"-deformation-speed", ".deformSpeed", XrmoptionSepArg, 0 }, + {"-initial-deformation", ".initDeform", XrmoptionSepArg, 0 }, + {"-etruscan-venus", ".initDeform", XrmoptionNoArg, "0.0" }, + {"-roman", ".initDeform", XrmoptionNoArg, "1000.0" }, + {"-boy", ".initDeform", XrmoptionNoArg, "2000.0" }, + {"-ida", ".initDeform", XrmoptionNoArg, "3000.0" }, +}; + +static argtype vars[] = +{ + { &mode, "displayMode", "DisplayMode", DEF_DISPLAY_MODE, t_String }, + { &appear, "appearance", "Appearance", DEF_APPEARANCE, t_String }, + { &color_mode, "colors", "Colors", DEF_COLORS, t_String }, + { &change_colors, "changeColors", "ChangeColors", DEF_CHANGE_COLORS, t_Bool }, + { &view_mode, "viewMode", "ViewMode", DEF_VIEW_MODE, t_String }, + { &deform, "deform", "Deform", DEF_DEFORM, t_Bool }, + { &marks, "marks", "Marks", DEF_MARKS, t_Bool }, + { &proj, "projection", "Projection", DEF_PROJECTION, t_String }, + { &speed_x, "speedx", "Speedx", DEF_SPEEDX, t_Float}, + { &speed_y, "speedy", "Speedy", DEF_SPEEDY, t_Float}, + { &speed_z, "speedz", "Speedz", DEF_SPEEDZ, t_Float}, + { &walk_direction, "walkDirection", "WalkDirection", DEF_WALK_DIRECTION, t_Float}, + { &walk_speed, "walkSpeed", "WalkSpeed", DEF_WALK_SPEED, t_Float}, + { &deform_speed, "deformSpeed", "DeformSpeed", DEF_DEFORM_SPEED, t_Float}, + { &init_deform, "initDeform", "InitDeform", DEF_INIT_DEFORM, t_Float }, +}; + +ENTRYPOINT ModeSpecOpt etruscanvenus_opts = +{sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, NULL}; + + +/* Offset by which we walk above the surface */ +#define DELTAY 0.01 + +/* Color change speeds */ +#define DRHO 0.7 +#define DSIGMA 1.1 +#define DTAU 1.7 + +/* Number of subdivisions of the surface */ +#define NUMU 192 +#define NUMV 128 + +/* Number of subdivisions per band */ +#define NUMBDIR 8 +#define NUMBDIST 4 + +/* Constants that are used to calculate the approximate center of the + surface in the z direction. */ +#define Z1 (0.8141179221194051) +#define Z2 (0.1359276851926206) +#define Z3 (1.1581097545867050) +#define Z4 (0.7186549129158579) +#define Z5 (2.5393401559381240) + +/* Constants that are used to calculate the approximate radius of the + surface. */ +#define R1 (1.308007044714129) +#define R2 (4.005205981405042) +#define R3 (-2.893994600199527) +#define R4 (-1.266709537162707) + + +typedef struct { + GLint WindH, WindW; + GLXContext *glx_context; + /* Options */ + int display_mode; + int appearance; + int colors; + Bool change_colors; + int view; + int projection; + Bool marks; + /* 3D rotation angles */ + float alpha, beta, delta; + /* Color rotation angles */ + float rho, sigma, tau; + /* Movement parameters */ + float umove, vmove, dumove, dvmove; + int side; + /* Deformation parameters */ + float dd; + int defdir; + /* The viewing offset in 3d */ + float offset3d[3]; + /* The 3d coordinates of the surface and their derivatives */ + float *ev; + float *evn; + /* The precomputed colors of the surface */ + float *col; + /* The precomputed texture coordinates of the surface */ + float *tex; + /* The "curlicue" texture */ + GLuint tex_name; + /* Aspect ratio of the current window */ + float aspect; + /* Trackball states */ + trackball_state *trackball; + Bool button_pressed; + /* A random factor to modify the rotation speeds */ + float speed_scale; +} etruscanvenusstruct; + +static etruscanvenusstruct *etruscanvenus = (etruscanvenusstruct *) NULL; + + +/* Add a rotation around the x-axis to the matrix m. */ +static void rotatex(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][1]; + v = m[i][2]; + m[i][1] = c*u+s*v; + m[i][2] = -s*u+c*v; + } +} + + +/* Add a rotation around the y-axis to the matrix m. */ +static void rotatey(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][0]; + v = m[i][2]; + m[i][0] = c*u-s*v; + m[i][2] = s*u+c*v; + } +} + + +/* Add a rotation around the z-axis to the matrix m. */ +static void rotatez(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][0]; + v = m[i][1]; + m[i][0] = c*u+s*v; + m[i][1] = -s*u+c*v; + } +} + + +/* Compute the rotation matrix m from the rotation angles. */ +static void rotateall(float al, float be, float de, float m[3][3]) +{ + int i, j; + + for (i=0; i<3; i++) + for (j=0; j<3; j++) + m[i][j] = (i==j); + rotatex(m,al); + rotatey(m,be); + rotatez(m,de); +} + + +/* Multiply two rotation matrices: o=m*n. */ +static void mult_rotmat(float m[3][3], float n[3][3], float o[3][3]) +{ + int i, j, k; + + for (i=0; i<3; i++) + { + for (j=0; j<3; j++) + { + o[i][j] = 0.0; + for (k=0; k<3; k++) + o[i][j] += m[i][k]*n[k][j]; + } + } +} + + +/* Compute a 3D rotation matrix from a unit quaternion. */ +static void quat_to_rotmat(float p[4], float m[3][3]) +{ + double al, be, de; + double r00, r01, r02, r12, r22; + + r00 = 1.0-2.0*(p[1]*p[1]+p[2]*p[2]); + r01 = 2.0*(p[0]*p[1]+p[2]*p[3]); + r02 = 2.0*(p[2]*p[0]-p[1]*p[3]); + r12 = 2.0*(p[1]*p[2]+p[0]*p[3]); + r22 = 1.0-2.0*(p[1]*p[1]+p[0]*p[0]); + + al = atan2(-r12,r22)*180.0/M_PI; + be = atan2(r02,sqrt(r00*r00+r01*r01))*180.0/M_PI; + de = atan2(-r01,r00)*180.0/M_PI; + + rotateall(al,be,de,m); +} + + +/* Compute a fully saturated and bright color based on an angle and, + optionally, a color rotation matrix. */ +static void color(etruscanvenusstruct *ev, double angle, float mat[3][3], + float col[4]) +{ + int s; + double t, ca, sa; + float m; + + if (!ev->change_colors) + { + if (ev->colors == COLORS_ONESIDED || ev->colors == COLORS_TWOSIDED) + return; + + if (angle >= 0.0) + angle = fmod(angle,2.0*M_PI); + else + angle = fmod(angle,-2.0*M_PI); + s = floor(angle/(M_PI/3)); + t = angle/(M_PI/3)-s; + if (s >= 6) + s = 0; + switch (s) + { + case 0: + col[0] = 1.0; + col[1] = t; + col[2] = 0.0; + break; + case 1: + col[0] = 1.0-t; + col[1] = 1.0; + col[2] = 0.0; + break; + case 2: + col[0] = 0.0; + col[1] = 1.0; + col[2] = t; + break; + case 3: + col[0] = 0.0; + col[1] = 1.0-t; + col[2] = 1.0; + break; + case 4: + col[0] = t; + col[1] = 0.0; + col[2] = 1.0; + break; + case 5: + col[0] = 1.0; + col[1] = 0.0; + col[2] = 1.0-t; + break; + } + } + else /* ev->change_colors */ + { + if (ev->colors == COLORS_ONESIDED || ev->colors == COLORS_TWOSIDED) + { + col[0] = mat[0][2]; + col[1] = mat[1][2]; + col[2] = mat[2][2]; + } + else + { + ca = cos(angle); + sa = sin(angle); + col[0] = ca*mat[0][0]+sa*mat[0][1]; + col[1] = ca*mat[1][0]+sa*mat[1][1]; + col[2] = ca*mat[2][0]+sa*mat[2][1]; + } + m = 0.5f/fmaxf(fmaxf(fabsf(col[0]),fabsf(col[1])),fabsf(col[2])); + col[0] = m*col[0]+0.5f; + col[1] = m*col[1]+0.5f; + col[2] = m*col[2]+0.5f; + } + if (ev->display_mode == DISP_TRANSPARENT) + col[3] = 0.7; + else + col[3] = 1.0; +} + + +/* Set up the surface colors and texture. */ +static void setup_etruscan_venus_color_texture(ModeInfo *mi, double umin, + double umax, double vmin, + double vmax, int numu, int numv) +{ + int i, j, k; + double u, v, ur, vr, vc; + etruscanvenusstruct *ev = &etruscanvenus[MI_SCREEN(mi)]; + + ur = umax-umin; + vr = vmax-vmin; + for (i=0; i<=numv; i++) + { + for (j=0; j<=numu; j++) + { + k = i*(numu+1)+j; + u = ur*j/numu+umin; + if (ev->appearance == APPEARANCE_DISTANCE_BANDS) + v = -vr*i/numv+vmin; + else + v = vr*i/numv+vmin; + if (!ev->change_colors) + { + if (ev->colors == COLORS_DISTANCE) + { + if (ev->appearance == APPEARANCE_DISTANCE_BANDS) + vc = -4.0*v; + else + vc = 4.0*v; + if (vc >= 4.0*M_PI) + vc -= 4.0*M_PI; + if (vc >= 2.0*M_PI) + vc = 4.0*M_PI-vc; + color(ev,vc,NULL,&ev->col[4*k]); + } + else /* ev->colors == COLORS_DIRECTION */ + { + color(ev,u,NULL,&ev->col[4*k]); + } + } + ev->tex[2*k+0] = 48*u/(2.0*M_PI); + if (ev->appearance == APPEARANCE_DISTANCE_BANDS) + ev->tex[2*k+1] = 64*v/(2.0*M_PI)-0.5; + else + ev->tex[2*k+1] = 64*v/(2.0*M_PI); + } + } +} + + +/* Draw a 3d immersion of the surface. */ +static int etruscan_venus(ModeInfo *mi, double umin, double umax, + double vmin, double vmax, int numu, int numv) +{ + int polys = 0; + static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; + static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; + static const GLfloat mat_diff_oneside[] = { 0.9, 0.4, 0.3, 1.0 }; + static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_oneside[] = { 0.9, 0.4, 0.3, 0.7 }; + float mat_diff_dyn[4], mat_diff_dyn_compl[4]; + float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[3][3], matc[3][3]; + int i, j, k, l, m, o; + double u, v, ur, vr, oz, vc; + double xx[3], xxu[3], xxv[3]; + double r, s, t; + double dd, bb, ll, db, dl, radius; + double cv, sv, c2v, s2v, cu, su, c2u, s2u, c3u, s3u; + double bosqrt2, b2osqrt2, b3osqrt2, nom, den, nomv, denu, denv, den2; + double f, fx, fy, fz, x, y, z; + double fu, fv, fxu, fxv, fyu, fyv, fzv, xu, xv, yu, yv, zu, zv; + float qu[4], r1[3][3], r2[3][3]; + etruscanvenusstruct *ev = &etruscanvenus[MI_SCREEN(mi)]; + + dd = ev->dd; + if (dd < 1.0) + { + bb = 0.0; + ll = dd; + } + else if (dd < 2.0) + { + bb = dd-1.0; + ll = 1.0; + } + else if (dd < 3.0) + { + bb = 1.0; + ll = 3.0-dd; + } + else /* dd < 4.0 */ + { + bb = 4.0-dd; + ll = 0.0; + } + db = ((6.0*bb-15.0)*bb+10.0)*bb*bb*bb; + dl = ((6.0*ll-15.0)*ll+10.0)*ll*ll*ll; + /* Calculate the approximate center of the surface in the z direction. */ + oz = (Z1*(sin(0.5*M_PI*pow(dl,Z3))+Z2*sin(1.5*M_PI*pow(dl,Z3)))* + exp(Z4*pow(db,Z5))); + /* Calculate the approximate radius of the surface. */ + r = R1+(db-0.5)*(dl-0.5)+R2*exp(R3*(1.0-db))*exp(R4*dl); + radius = 0.8/r; + + if (ev->change_colors) + rotateall(ev->rho,ev->sigma,ev->tau,matc); + + if (ev->view == VIEW_WALK) + { + u = ev->umove; + v = ev->vmove; + u = 0.5*u; + bosqrt2 = db/M_SQRT2; + b2osqrt2 = 2.0*bosqrt2; + b3osqrt2 = 3.0*bosqrt2; + cu = cos(u); + su = sin(u); + c2u = cos(2.0*u); + s2u = sin(2.0*u); + c3u = cos(3.0*u); + s3u = sin(3.0*u); + cv = cos(v); + sv = sin(v); + c2v = cos(2.0*v); + s2v = sin(2.0*v); + nom = (1.0-dl+dl*cv); + den = (1.0-bosqrt2*s3u*s2v); + f = nom/den; + fx = c2u*cv+cu*sv; + fy = s2u*cv-su*sv; + fz = M_SQRT2*cv; + x = f*fx; + y = f*fy; + z = f*fz; + nomv = -dl*sv; + denu = -b3osqrt2*c3u*s2v; + denv = -b2osqrt2*s3u*c2v; + den2 = 1.0/(den*den); + fu = -nom*denu*den2; + fv = (den*nomv-nom*denv)*den2; + fxu = -su*sv-2.0*s2u*cv; + fxv = cu*cv-c2u*sv; + fyu = 2.0*c2u*cv-cu*sv; + fyv = -s2u*sv-su*cv; + fzv = -M_SQRT2*sv; + xu = fu*fx+f*fxu; + xv = fv*fx+f*fxv; + yu = fu*fy+f*fyu; + yv = fv*fy+f*fyv; + zu = fu*fz; + zv = fv*fz+f*fzv; + xx[0] = x; + xx[1] = y; + xx[2] = z-oz; + n[0] = yu*zv-zu*yv; + n[1] = zu*xv-xu*zv; + n[2] = xu*yv-yu*xv; + t = n[0]*n[0]+n[1]*n[1]+n[2]*n[2]; + /* Avoid degenerate tangential plane basis vectors as much as + possible. */ + if (t < FLT_EPSILON) + { + u += 0.01; + v += 0.01; + cu = cos(u); + su = sin(u); + c2u = cos(2.0*u); + s2u = sin(2.0*u); + c3u = cos(3.0*u); + s3u = sin(3.0*u); + cv = cos(v); + sv = sin(v); + c2v = cos(2.0*v); + s2v = sin(2.0*v); + nom = (1.0-dl+dl*cv); + den = (1.0-bosqrt2*s3u*s2v); + f = nom/den; + fx = c2u*cv+cu*sv; + fy = s2u*cv-su*sv; + fz = M_SQRT2*cv; + nomv = -dl*sv; + denu = -b3osqrt2*c3u*s2v; + denv = -b2osqrt2*s3u*c2v; + den2 = 1.0/(den*den); + fu = -nom*denu*den2; + fv = (den*nomv-nom*denv)*den2; + fxu = -su*sv-2.0*s2u*cv; + fxv = cu*cv-c2u*sv; + fyu = 2.0*c2u*cv-cu*sv; + fyv = -s2u*sv-su*cv; + fzv = -M_SQRT2*sv; + xu = fu*fx+f*fxu; + xv = fv*fx+f*fxv; + yu = fu*fy+f*fyu; + yv = fv*fy+f*fyv; + zu = fu*fz; + zv = fv*fz+f*fzv; + } + xxu[0] = xu; + xxu[1] = yu; + xxu[2] = zu; + xxv[0] = xv; + xxv[1] = yv; + xxv[2] = zv; + for (l=0; l<3; l++) + { + p[l] = xx[l]*radius; + pu[l] = xxu[l]*radius; + pv[l] = xxv[l]*radius; + } + n[0] = pu[1]*pv[2]-pu[2]*pv[1]; + n[1] = pu[2]*pv[0]-pu[0]*pv[2]; + n[2] = pu[0]*pv[1]-pu[1]*pv[0]; + t = 1.0/(ev->side*4.0*sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2])); + n[0] *= t; + n[1] *= t; + n[2] *= t; + pm[0] = 0.5*pu[0]*ev->dumove+pv[0]*ev->dvmove; + pm[1] = 0.5*pu[1]*ev->dumove+pv[1]*ev->dvmove; + pm[2] = 0.5*pu[2]*ev->dumove+pv[2]*ev->dvmove; + t = 1.0/(4.0*sqrt(pm[0]*pm[0]+pm[1]*pm[1]+pm[2]*pm[2])); + pm[0] *= t; + pm[1] *= t; + pm[2] *= t; + b[0] = n[1]*pm[2]-n[2]*pm[1]; + b[1] = n[2]*pm[0]-n[0]*pm[2]; + b[2] = n[0]*pm[1]-n[1]*pm[0]; + t = 1.0/(4.0*sqrt(b[0]*b[0]+b[1]*b[1]+b[2]*b[2])); + b[0] *= t; + b[1] *= t; + b[2] *= t; + + /* Compute alpha, beta, gamma from the three basis vectors. + | -b[0] -b[1] -b[2] | + m = | n[0] n[1] n[2] | + | -pm[0] -pm[1] -pm[2] | + */ + ev->alpha = atan2(-n[2],-pm[2])*180/M_PI; + ev->beta = atan2(-b[2],sqrt(b[0]*b[0]+b[1]*b[1]))*180/M_PI; + ev->delta = atan2(b[1],-b[0])*180/M_PI; + + /* Compute the rotation that rotates the surface in 3D. */ + rotateall(ev->alpha,ev->beta,ev->delta,mat); + + u = ev->umove; + v = ev->vmove; + u = 0.5*u; + bosqrt2 = db/M_SQRT2; + b2osqrt2 = 2.0*bosqrt2; + b3osqrt2 = 3.0*bosqrt2; + cu = cos(u); + su = sin(u); + c2u = cos(2.0*u); + s2u = sin(2.0*u); + s3u = sin(3.0*u); + cv = cos(v); + sv = sin(v); + s2v = sin(2.0*v); + nom = (1.0-dl+dl*cv); + den = (1.0-bosqrt2*s3u*s2v); + f = nom/den; + fx = c2u*cv+cu*sv; + fy = s2u*cv-su*sv; + fz = M_SQRT2*cv; + x = f*fx; + y = f*fy; + z = f*fz; + xx[0] = x; + xx[1] = y; + xx[2] = z-oz; + for (l=0; l<3; l++) + { + r = 0.0; + for (m=0; m<3; m++) + r += mat[l][m]*xx[m]; + p[l] = r*radius; + } + + ev->offset3d[0] = -p[0]; + ev->offset3d[1] = -p[1]-DELTAY; + ev->offset3d[2] = -p[2]; + } + else + { + /* Compute the rotation that rotates the surface in 3D, including the + trackball rotations. */ + rotateall(ev->alpha,ev->beta,ev->delta,r1); + + gltrackball_get_quaternion(ev->trackball,qu); + quat_to_rotmat(qu,r2); + + mult_rotmat(r2,r1,mat); + } + + if (!ev->change_colors) + { + if (ev->colors == COLORS_ONESIDED) + { + glColor3fv(mat_diff_oneside); + if (ev->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_trans_oneside); + } + else + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_oneside); + } + } + else if (ev->colors == COLORS_TWOSIDED) + { + glColor3fv(mat_diff_red); + if (ev->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + } + else + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + } + } + } + else /* ev->change_colors */ + { + color(ev,0.0,matc,mat_diff_dyn); + if (ev->colors == COLORS_ONESIDED) + { + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + } + else if (ev->colors == COLORS_TWOSIDED) + { + mat_diff_dyn_compl[0] = 1.0f-mat_diff_dyn[0]; + mat_diff_dyn_compl[1] = 1.0f-mat_diff_dyn[1]; + mat_diff_dyn_compl[2] = 1.0f-mat_diff_dyn[2]; + mat_diff_dyn_compl[3] = mat_diff_dyn[3]; + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn_compl); + } + } + glBindTexture(GL_TEXTURE_2D,ev->tex_name); + + ur = umax-umin; + vr = vmax-vmin; + + /* Set up the surface coordinates and normals. */ + if (ev->appearance == APPEARANCE_DISTANCE_BANDS) + { + for (i=0; i<=numv; i++) + { + if ((i & (NUMBDIST-1)) >= NUMBDIST/4+1 && + (i & (NUMBDIST-1)) < 3*NUMBDIST/4) + continue; + for (j=0; j<=numu; j++) + { + o = i*(numu+1)+j; + u = ur*j/numu+umin; + v = -vr*i/numv+vmin; + if (ev->change_colors) + { + /* Compute the colors dynamically. */ + if (ev->colors == COLORS_DISTANCE) + { + vc = -4.0*v; + if (vc >= 4.0*M_PI) + vc -= 4.0*M_PI; + if (vc >= 2.0*M_PI) + vc = 4.0*M_PI-vc; + color(ev,vc,matc,&ev->col[4*o]); + } + else if (ev->colors == COLORS_DIRECTION) + { + color(ev,u,matc,&ev->col[4*o]); + } + } + u = 0.5*u; + bosqrt2 = db/M_SQRT2; + b2osqrt2 = 2.0*bosqrt2; + b3osqrt2 = 3.0*bosqrt2; + cu = cos(u); + su = sin(u); + c2u = cos(2.0*u); + s2u = sin(2.0*u); + c3u = cos(3.0*u); + s3u = sin(3.0*u); + cv = cos(v); + sv = sin(v); + c2v = cos(2.0*v); + s2v = sin(2.0*v); + nom = (1.0-dl+dl*cv); + den = (1.0-bosqrt2*s3u*s2v); + f = nom/den; + fx = c2u*cv+cu*sv; + fy = s2u*cv-su*sv; + fz = M_SQRT2*cv; + x = f*fx; + y = f*fy; + z = f*fz; + nomv = -dl*sv; + denu = -b3osqrt2*c3u*s2v; + denv = -b2osqrt2*s3u*c2v; + den2 = 1.0/(den*den); + fu = -nom*denu*den2; + fv = (den*nomv-nom*denv)*den2; + fxu = -su*sv-2.0*s2u*cv; + fxv = cu*cv-c2u*sv; + fyu = 2.0*c2u*cv-cu*sv; + fyv = -s2u*sv-su*cv; + fzv = -M_SQRT2*sv; + xu = fu*fx+f*fxu; + xv = fv*fx+f*fxv; + yu = fu*fy+f*fyu; + yv = fv*fy+f*fyv; + zu = fu*fz; + zv = fv*fz+f*fzv; + xx[0] = x; + xx[1] = y; + xx[2] = z-oz; + n[0] = yu*zv-zu*yv; + n[1] = zu*xv-xu*zv; + n[2] = xu*yv-yu*xv; + t = n[0]*n[0]+n[1]*n[1]+n[2]*n[2]; + /* Avoid degenerate tangential plane basis vectors as much as + possible. */ + if (t < FLT_EPSILON) + { + u += 0.01; + v += 0.01; + cu = cos(u); + su = sin(u); + c2u = cos(2.0*u); + s2u = sin(2.0*u); + c3u = cos(3.0*u); + s3u = sin(3.0*u); + cv = cos(v); + sv = sin(v); + c2v = cos(2.0*v); + s2v = sin(2.0*v); + nom = (1.0-dl+dl*cv); + den = (1.0-bosqrt2*s3u*s2v); + f = nom/den; + fx = c2u*cv+cu*sv; + fy = s2u*cv-su*sv; + fz = M_SQRT2*cv; + nomv = -dl*sv; + denu = -b3osqrt2*c3u*s2v; + denv = -b2osqrt2*s3u*c2v; + den2 = 1.0/(den*den); + fu = -nom*denu*den2; + fv = (den*nomv-nom*denv)*den2; + fxu = -su*sv-2.0*s2u*cv; + fxv = cu*cv-c2u*sv; + fyu = 2.0*c2u*cv-cu*sv; + fyv = -s2u*sv-su*cv; + fzv = -M_SQRT2*sv; + xu = fu*fx+f*fxu; + xv = fv*fx+f*fxv; + yu = fu*fy+f*fyu; + yv = fv*fy+f*fyv; + zu = fu*fz; + zv = fv*fz+f*fzv; + } + xxu[0] = xu; + xxu[1] = yu; + xxu[2] = zu; + xxv[0] = xv; + xxv[1] = yv; + xxv[2] = zv; + for (l=0; l<3; l++) + { + r = 0.0; + s = 0.0; + t = 0.0; + for (m=0; m<3; m++) + { + r += mat[l][m]*xx[m]; + s += mat[l][m]*xxu[m]; + t += mat[l][m]*xxv[m]; + } + p[l] = r*radius+ev->offset3d[l]; + pu[l] = s*radius; + pv[l] = t*radius; + } + n[0] = pu[1]*pv[2]-pu[2]*pv[1]; + n[1] = pu[2]*pv[0]-pu[0]*pv[2]; + n[2] = pu[0]*pv[1]-pu[1]*pv[0]; + t = 1.0/sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); + n[0] *= t; + n[1] *= t; + n[2] *= t; + ev->ev[3*o+0] = p[0]; + ev->ev[3*o+1] = p[1]; + ev->ev[3*o+2] = p[2]; + ev->evn[3*o+0] = n[0]; + ev->evn[3*o+1] = n[1]; + ev->evn[3*o+2] = n[2]; + } + } + } + else /* ev->appearance != APPEARANCE_DISTANCE_BANDS */ + { + for (j=0; j<=numu; j++) + { + if (ev->appearance == APPEARANCE_DIRECTION_BANDS && + ((j & (NUMBDIR-1)) >= NUMBDIR/2+1)) + continue; + for (i=0; i<=numv; i++) + { + o = i*(numu+1)+j; + u = ur*j/numu+umin; + v = vr*i/numv+vmin; + if (ev->change_colors) + { + /* Compute the colors dynamically. */ + if (ev->colors == COLORS_DISTANCE) + { + vc = 4.0*v; + if (vc >= 4.0*M_PI) + vc -= 4.0*M_PI; + if (vc >= 2.0*M_PI) + vc = 4.0*M_PI-vc; + color(ev,vc,matc,&ev->col[4*o]); + } + else if (ev->colors == COLORS_DIRECTION) + { + color(ev,u,matc,&ev->col[4*o]); + } + } + u = 0.5*u; + bosqrt2 = db/M_SQRT2; + b2osqrt2 = 2.0*bosqrt2; + b3osqrt2 = 3.0*bosqrt2; + cu = cos(u); + su = sin(u); + c2u = cos(2.0*u); + s2u = sin(2.0*u); + c3u = cos(3.0*u); + s3u = sin(3.0*u); + cv = cos(v); + sv = sin(v); + c2v = cos(2.0*v); + s2v = sin(2.0*v); + nom = (1.0-dl+dl*cv); + den = (1.0-bosqrt2*s3u*s2v); + f = nom/den; + fx = c2u*cv+cu*sv; + fy = s2u*cv-su*sv; + fz = M_SQRT2*cv; + x = f*fx; + y = f*fy; + z = f*fz; + nomv = -dl*sv; + denu = -b3osqrt2*c3u*s2v; + denv = -b2osqrt2*s3u*c2v; + den2 = 1.0/(den*den); + fu = -nom*denu*den2; + fv = (den*nomv-nom*denv)*den2; + fxu = -su*sv-2.0*s2u*cv; + fxv = cu*cv-c2u*sv; + fyu = 2.0*c2u*cv-cu*sv; + fyv = -s2u*sv-su*cv; + fzv = -M_SQRT2*sv; + xu = fu*fx+f*fxu; + xv = fv*fx+f*fxv; + yu = fu*fy+f*fyu; + yv = fv*fy+f*fyv; + zu = fu*fz; + zv = fv*fz+f*fzv; + xx[0] = x; + xx[1] = y; + xx[2] = z-oz; + n[0] = yu*zv-zu*yv; + n[1] = zu*xv-xu*zv; + n[2] = xu*yv-yu*xv; + t = n[0]*n[0]+n[1]*n[1]+n[2]*n[2]; + /* Avoid degenerate tangential plane basis vectors as much as + possible. */ + if (t < FLT_EPSILON) + { + u += 0.01; + v += 0.01; + cu = cos(u); + su = sin(u); + c2u = cos(2.0*u); + s2u = sin(2.0*u); + c3u = cos(3.0*u); + s3u = sin(3.0*u); + cv = cos(v); + sv = sin(v); + c2v = cos(2.0*v); + s2v = sin(2.0*v); + nom = (1.0-dl+dl*cv); + den = (1.0-bosqrt2*s3u*s2v); + f = nom/den; + fx = c2u*cv+cu*sv; + fy = s2u*cv-su*sv; + fz = M_SQRT2*cv; + nomv = -dl*sv; + denu = -b3osqrt2*c3u*s2v; + denv = -b2osqrt2*s3u*c2v; + den2 = 1.0/(den*den); + fu = -nom*denu*den2; + fv = (den*nomv-nom*denv)*den2; + fxu = -su*sv-2.0*s2u*cv; + fxv = cu*cv-c2u*sv; + fyu = 2.0*c2u*cv-cu*sv; + fyv = -s2u*sv-su*cv; + fzv = -M_SQRT2*sv; + xu = fu*fx+f*fxu; + xv = fv*fx+f*fxv; + yu = fu*fy+f*fyu; + yv = fv*fy+f*fyv; + zu = fu*fz; + zv = fv*fz+f*fzv; + } + xxu[0] = xu; + xxu[1] = yu; + xxu[2] = zu; + xxv[0] = xv; + xxv[1] = yv; + xxv[2] = zv; + for (l=0; l<3; l++) + { + r = 0.0; + s = 0.0; + t = 0.0; + for (m=0; m<3; m++) + { + r += mat[l][m]*xx[m]; + s += mat[l][m]*xxu[m]; + t += mat[l][m]*xxv[m]; + } + p[l] = r*radius+ev->offset3d[l]; + pu[l] = s*radius; + pv[l] = t*radius; + } + n[0] = pu[1]*pv[2]-pu[2]*pv[1]; + n[1] = pu[2]*pv[0]-pu[0]*pv[2]; + n[2] = pu[0]*pv[1]-pu[1]*pv[0]; + t = 1.0/sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); + n[0] *= t; + n[1] *= t; + n[2] *= t; + ev->ev[3*o+0] = p[0]; + ev->ev[3*o+1] = p[1]; + ev->ev[3*o+2] = p[2]; + ev->evn[3*o+0] = n[0]; + ev->evn[3*o+1] = n[1]; + ev->evn[3*o+2] = n[2]; + } + } + } + + if (ev->appearance == APPEARANCE_DISTANCE_BANDS) + { + for (i=0; i<numv; i++) + { + if ((i & (NUMBDIST-1)) >= NUMBDIST/4 && + (i & (NUMBDIST-1)) < 3*NUMBDIST/4) + continue; + if (ev->display_mode == DISP_WIREFRAME) + glBegin(GL_QUAD_STRIP); + else + glBegin(GL_TRIANGLE_STRIP); + for (j=0; j<=numu; j++) + { + for (k=0; k<=1; k++) + { + l = (i+k); + m = j; + o = l*(numu+1)+m; + glTexCoord2fv(&ev->tex[2*o]); + if (ev->colors != COLORS_ONESIDED && ev->colors != COLORS_TWOSIDED) + { + glColor3fv(&ev->col[4*o]); + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + &ev->col[4*o]); + } + glNormal3fv(&ev->evn[3*o]); + glVertex3fv(&ev->ev[3*o]); + polys++; + } + } + glEnd(); + } + } + else /* ev->appearance != APPEARANCE_DISTANCE_BANDS */ + { + for (j=0; j<numu; j++) + { + if (ev->appearance == APPEARANCE_DIRECTION_BANDS && + ((j & (NUMBDIR-1)) >= NUMBDIR/2)) + continue; + if (ev->display_mode == DISP_WIREFRAME) + glBegin(GL_QUAD_STRIP); + else + glBegin(GL_TRIANGLE_STRIP); + for (i=0; i<=numv; i++) + { + for (k=0; k<=1; k++) + { + l = i; + m = (j+k); + o = l*(numu+1)+m; + glTexCoord2fv(&ev->tex[2*o]); + if (ev->colors != COLORS_ONESIDED && ev->colors != COLORS_TWOSIDED) + { + glColor3fv(&ev->col[4*o]); + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + &ev->col[4*o]); + } + glNormal3fv(&ev->evn[3*o]); + glVertex3fv(&ev->ev[3*o]); + polys++; + } + } + glEnd(); + } + } + + polys /= 2; + return polys; +} + + +/* Generate a texture image that shows the orientation reversal. */ +static void gen_texture(ModeInfo *mi) +{ + etruscanvenusstruct *ev = &etruscanvenus[MI_SCREEN(mi)]; + + glGenTextures(1,&ev->tex_name); + glBindTexture(GL_TEXTURE_2D,ev->tex_name); + glPixelStorei(GL_UNPACK_ALIGNMENT,1); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); + glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE,TEX_DIMENSION,TEX_DIMENSION,0, + GL_LUMINANCE,GL_UNSIGNED_BYTE,texture); +} + + +static void init(ModeInfo *mi) +{ + static const GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; + static const GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; + static const GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + static const GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; + static const GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + etruscanvenusstruct *ev = &etruscanvenus[MI_SCREEN(mi)]; + + if (deform_speed == 0.0) + deform_speed = 10.0; + + if (init_deform < 0.0) + init_deform = 0.0; + if (init_deform >= 4000.0) + init_deform = 0.0; + + if (walk_speed == 0.0) + walk_speed = 20.0; + + if (ev->view == VIEW_TURN) + { + ev->alpha = frand(360.0); + ev->beta = frand(360.0); + ev->delta = frand(360.0); + } + else + { + ev->alpha = 0.0; + ev->beta = 0.0; + ev->delta = 0.0; + } + ev->umove = frand(2.0*M_PI); + ev->vmove = frand(2.0*M_PI); + ev->dumove = 0.0; + ev->dvmove = 0.0; + ev->side = 1; + + ev->dd = init_deform*0.001; + ev->defdir = 1; + + ev->rho = frand(360.0); + ev->sigma = frand(360.0); + ev->tau = frand(360.0); + + ev->offset3d[0] = 0.0; + ev->offset3d[1] = 0.0; + ev->offset3d[2] = -2.0; + + gen_texture(mi); + setup_etruscan_venus_color_texture(mi,0.0,2.0*M_PI,0.0,2.0*M_PI,NUMU,NUMV); + + if (ev->marks) + glEnable(GL_TEXTURE_2D); + else + glDisable(GL_TEXTURE_2D); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (ev->projection == DISP_PERSPECTIVE || ev->view == VIEW_WALK) + { + if (ev->view == VIEW_WALK) + gluPerspective(60.0,1.0,0.01,10.0); + else + gluPerspective(60.0,1.0,0.1,10.0); + } + else + { + glOrtho(-1.0,1.0,-1.0,1.0,0.1,10.0); + } + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + +# ifdef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */ + if (ev->display_mode == DISP_WIREFRAME) + ev->display_mode = DISP_SURFACE; +# endif + + if (ev->display_mode == DISP_SURFACE) + { + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glShadeModel(GL_SMOOTH); + glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); + glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); + glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); + glLightfv(GL_LIGHT0,GL_POSITION,light_position); + glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular); + glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,50.0); + glDepthMask(GL_TRUE); + glDisable(GL_BLEND); + } + else if (ev->display_mode == DISP_TRANSPARENT) + { + glDisable(GL_DEPTH_TEST); + glShadeModel(GL_SMOOTH); + glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); + glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); + glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); + glLightfv(GL_LIGHT0,GL_POSITION,light_position); + glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular); + glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,50.0); + glDepthMask(GL_FALSE); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA,GL_ONE); + } + else /* ev->display_mode == DISP_WIREFRAME */ + { + glDisable(GL_DEPTH_TEST); + glShadeModel(GL_FLAT); + glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); + glDisable(GL_LIGHTING); + glDisable(GL_LIGHT0); + glDisable(GL_BLEND); + } +} + + +/* Redisplay the Klein bottle. */ +static void display_etruscanvenus(ModeInfo *mi) +{ + etruscanvenusstruct *ev = &etruscanvenus[MI_SCREEN(mi)]; + + if (!ev->button_pressed) + { + if (deform) + { + ev->dd += ev->defdir*deform_speed*0.001; + if (ev->dd < 0.0) + ev->dd += 4.0; + if (ev->dd >= 4.0) + ev->dd -= 4.0; + /* Randomly change the deformation direction at one of the four + surface types in 10% of the cases. */ + if (fabs(round(ev->dd)-ev->dd) <= deform_speed*0.0005) + { + if (LRAND() % 10 == 0) + ev->defdir = -ev->defdir; + } + } + if (ev->view == VIEW_TURN) + { + ev->alpha += speed_x*ev->speed_scale; + if (ev->alpha >= 360.0) + ev->alpha -= 360.0; + ev->beta += speed_y*ev->speed_scale; + if (ev->beta >= 360.0) + ev->beta -= 360.0; + ev->delta += speed_z*ev->speed_scale; + if (ev->delta >= 360.0) + ev->delta -= 360.0; + } + if (ev->view == VIEW_WALK) + { + ev->dumove = cos(walk_direction*M_PI/180.0)*walk_speed*M_PI/4096.0; + ev->dvmove = sin(walk_direction*M_PI/180.0)*walk_speed*M_PI/4096.0; + ev->umove += ev->dumove; + if (ev->umove >= 2.0*M_PI) + { + ev->umove -= 2.0*M_PI; + ev->vmove = 2.0*M_PI-ev->vmove; + ev->side = -ev->side; + } + if (ev->umove < 0.0) + { + ev->umove += 2.0*M_PI; + ev->vmove = 2.0*M_PI-ev->vmove; + ev->side = -ev->side; + } + ev->vmove += ev->dvmove; + if (ev->vmove >= 2.0*M_PI) + ev->vmove -= 2.0*M_PI; + if (ev->vmove < 0.0) + ev->vmove += 2.0*M_PI; + } + if (ev->change_colors) + { + ev->rho += DRHO; + if (ev->rho >= 360.0) + ev->rho -= 360.0; + ev->sigma += DSIGMA; + if (ev->sigma >= 360.0) + ev->sigma -= 360.0; + ev->tau += DTAU; + if (ev->tau >= 360.0) + ev->tau -= 360.0; + } + } + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (ev->projection == DISP_PERSPECTIVE || ev->view == VIEW_WALK) + { + if (ev->view == VIEW_WALK) + gluPerspective(60.0,ev->aspect,0.01,10.0); + else + gluPerspective(60.0,ev->aspect,0.1,10.0); + } + else + { + if (ev->aspect >= 1.0) + glOrtho(-ev->aspect,ev->aspect,-1.0,1.0,0.1,10.0); + else + glOrtho(-1.0,1.0,-1.0/ev->aspect,1.0/ev->aspect,0.1,10.0); + } + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + mi->polygon_count = etruscan_venus(mi,0.0,2.0*M_PI,0.0,2.0*M_PI,NUMU,NUMV); +} + + +ENTRYPOINT void reshape_etruscanvenus(ModeInfo *mi, int width, int height) +{ + etruscanvenusstruct *ev = &etruscanvenus[MI_SCREEN(mi)]; + int y = 0; + + if (width > height * 5) { /* tiny window: show middle */ + height = width; + y = -height/2; + } + + ev->WindW = (GLint)width; + ev->WindH = (GLint)height; + glViewport(0,y,width,height); + ev->aspect = (GLfloat)width/(GLfloat)height; +} + + +ENTRYPOINT Bool etruscanvenus_handle_event(ModeInfo *mi, XEvent *event) +{ + etruscanvenusstruct *ev = &etruscanvenus[MI_SCREEN(mi)]; + + if (event->xany.type == ButtonPress && event->xbutton.button == Button1) + { + ev->button_pressed = True; + gltrackball_start(ev->trackball, event->xbutton.x, event->xbutton.y, + MI_WIDTH(mi), MI_HEIGHT(mi)); + return True; + } + else if (event->xany.type == ButtonRelease && + event->xbutton.button == Button1) + { + ev->button_pressed = False; + return True; + } + else if (event->xany.type == MotionNotify && ev->button_pressed) + { + gltrackball_track(ev->trackball, event->xmotion.x, event->xmotion.y, + MI_WIDTH(mi), MI_HEIGHT(mi)); + return True; + } + + return False; +} + + +/* + *----------------------------------------------------------------------------- + *----------------------------------------------------------------------------- + * Xlock hooks. + *----------------------------------------------------------------------------- + *----------------------------------------------------------------------------- + */ + +/* + *----------------------------------------------------------------------------- + * Initialize etruscanvenus. Called each time the window changes. + *----------------------------------------------------------------------------- + */ + +ENTRYPOINT void init_etruscanvenus(ModeInfo *mi) +{ + etruscanvenusstruct *ev; + + MI_INIT (mi, etruscanvenus); + ev = &etruscanvenus[MI_SCREEN(mi)]; + + ev->ev = calloc(3*(NUMU+1)*(NUMV+1),sizeof(float)); + ev->evn = calloc(3*(NUMU+1)*(NUMV+1),sizeof(float)); + ev->col = calloc(4*(NUMU+1)*(NUMV+1),sizeof(float)); + ev->tex = calloc(2*(NUMU+1)*(NUMV+1),sizeof(float)); + + ev->trackball = gltrackball_init(True); + ev->button_pressed = False; + + /* Set the display mode. */ + if (!strcasecmp(mode,"random")) + { + ev->display_mode = random() % NUM_DISPLAY_MODES; + } + else if (!strcasecmp(mode,"wireframe")) + { + ev->display_mode = DISP_WIREFRAME; + } + else if (!strcasecmp(mode,"surface")) + { + ev->display_mode = DISP_SURFACE; + } + else if (!strcasecmp(mode,"transparent")) + { + ev->display_mode = DISP_TRANSPARENT; + } + else + { + ev->display_mode = random() % NUM_DISPLAY_MODES; + } + + ev->marks = marks; + + /* Orientation marks don't make sense in wireframe mode. */ + if (ev->display_mode == DISP_WIREFRAME) + ev->marks = False; + + /* Set the appearance. */ + if (!strcasecmp(appear,"random")) + { + ev->appearance = random() % NUM_APPEARANCES; + } + else if (!strcasecmp(appear,"solid")) + { + ev->appearance = APPEARANCE_SOLID; + } + else if (!strcasecmp(appear,"distance-bands")) + { + ev->appearance = APPEARANCE_DISTANCE_BANDS; + } + else if (!strcasecmp(appear,"direction-bands")) + { + ev->appearance = APPEARANCE_DIRECTION_BANDS; + } + else + { + ev->appearance = random() % NUM_APPEARANCES; + } + + /* Set the color mode. */ + if (!strcasecmp(color_mode,"random")) + { + ev->colors = random() % NUM_COLORS; + } + else if (!strcasecmp(color_mode,"one-sided")) + { + ev->colors = COLORS_ONESIDED; + } + else if (!strcasecmp(color_mode,"two-sided")) + { + ev->colors = COLORS_TWOSIDED; + } + else if (!strcasecmp(color_mode,"distance")) + { + ev->colors = COLORS_DISTANCE; + } + else if (!strcasecmp(color_mode,"direction")) + { + ev->colors = COLORS_DIRECTION; + } + else + { + ev->colors = random() % NUM_COLORS; + } + + ev->change_colors = change_colors; + + /* Set the view mode. */ + if (!strcasecmp(view_mode,"random")) + { + /* Select the walking mode only in 10% of the cases. */ + if (LRAND() % 10 == 0) + ev->view = VIEW_WALK; + else + ev->view = VIEW_TURN; + } + else if (!strcasecmp(view_mode,"walk")) + { + ev->view = VIEW_WALK; + } + else if (!strcasecmp(view_mode,"turn")) + { + ev->view = VIEW_TURN; + } + else + { + /* Select the walking mode only in 10% of the cases. */ + if (LRAND() % 10 == 0) + ev->view = VIEW_WALK; + else + ev->view = VIEW_TURN; + } + + if (ev->view == VIEW_WALK) + { + /* Walking only works on the Ida surface. Therefore, set the initial + deformation to the Ida surface and switch off the deformation. */ + init_deform = 3000.0; + deform = False; + } + + /* Set the 3d projection mode. */ + if (!strcasecmp(proj,"random")) + { + /* Orthographic projection only makes sense in turn mode. */ + if (ev->view == VIEW_TURN) + ev->projection = random() % NUM_DISP_MODES; + else + ev->projection = DISP_PERSPECTIVE; + } + else if (!strcasecmp(proj,"perspective")) + { + ev->projection = DISP_PERSPECTIVE; + } + else if (!strcasecmp(proj,"orthographic")) + { + ev->projection = DISP_ORTHOGRAPHIC; + } + else + { + /* Orthographic projection only makes sense in turn mode. */ + if (ev->view == VIEW_TURN) + ev->projection = random() % NUM_DISP_MODES; + else + ev->projection = DISP_PERSPECTIVE; + } + + /* Make multiple screens rotate at slightly different rates. */ + ev->speed_scale = 0.9+frand(0.3); + + if ((ev->glx_context = init_GL(mi)) != NULL) + { + reshape_etruscanvenus(mi,MI_WIDTH(mi),MI_HEIGHT(mi)); + glDrawBuffer(GL_BACK); + init(mi); + } + else + { + MI_CLEARWINDOW(mi); + } +} + +/* + *----------------------------------------------------------------------------- + * Called by the mainline code periodically to update the display. + *----------------------------------------------------------------------------- + */ +ENTRYPOINT void draw_etruscanvenus(ModeInfo *mi) +{ + Display *display = MI_DISPLAY(mi); + Window window = MI_WINDOW(mi); + etruscanvenusstruct *ev; + + if (etruscanvenus == NULL) + return; + ev = &etruscanvenus[MI_SCREEN(mi)]; + + MI_IS_DRAWN(mi) = True; + if (!ev->glx_context) + return; + + glXMakeCurrent(display, window, *ev->glx_context); + + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + glLoadIdentity(); + + display_etruscanvenus(mi); + + if (MI_IS_FPS(mi)) + do_fps (mi); + + glFlush(); + + glXSwapBuffers(display,window); +} + + +/* + *----------------------------------------------------------------------------- + * The display is being taken away from us. Free up malloc'ed + * memory and X resources that we've alloc'ed. + *----------------------------------------------------------------------------- + */ + +ENTRYPOINT void free_etruscanvenus(ModeInfo *mi) +{ + etruscanvenusstruct *ev = &etruscanvenus[MI_SCREEN(mi)]; + + if (!ev->glx_context) return; + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *ev->glx_context); + + if (ev->ev) free(ev->ev); + if (ev->evn) free(ev->evn); + if (ev->col) free(ev->col); + if (ev->tex) free(ev->tex); + gltrackball_free(ev->trackball); + if (ev->tex_name) glDeleteTextures(1, &ev->tex_name); +} + +#ifndef STANDALONE +ENTRYPOINT void change_etruscanvenus(ModeInfo *mi) +{ + etruscanvenusstruct *ev = &etruscanvenus[MI_SCREEN(mi)]; + + if (!ev->glx_context) + return; + + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *ev->glx_context); + init(mi); +} +#endif /* !STANDALONE */ + +XSCREENSAVER_MODULE ("EtruscanVenus", etruscanvenus) + +#endif /* USE_GL */ diff --git a/hacks/glx/etruscanvenus.man b/hacks/glx/etruscanvenus.man new file mode 100644 index 0000000..a96bd23 --- /dev/null +++ b/hacks/glx/etruscanvenus.man @@ -0,0 +1,372 @@ +.TH XScreenSaver 1 "" "X Version 11" +.SH NAME +etruscanvenus - Draws a 3d immersion of a Klein bottle that smoothly +deforms between the Etruscan Venus surface, the Roman surface, the Boy +surface surface, and the Ida surface. +.SH SYNOPSIS +.B etruscanvenus +[\-display \fIhost:display.screen\fP] +[\-install] +[\-visual \fIvisual\fP] +[\-window] +[\-root] +[\-delay \fIusecs\fP] +[\-fps] +[\-mode \fIdisplay-mode\fP] +[\-wireframe] +[\-surface] +[\-transparent] +[\-appearance \fIappearance\fP] +[\-solid] +[\-distance-bands] +[\-direction-bands] +[\-colors \fIcolor-scheme\fP] +[\-onesided-colors] +[\-twosided-colors] +[\-distance-colors] +[\-direction-colors] +[\-no-change-colors] +[\-view-mode \fIview-mode\fP] +[\-walk] +[\-turn] +[\-no-deform] +[\-deformation-speed \fIfloat\fP] +[\-initial-deformation \fIfloat\fP] +[\-etruscan-venus] +[\-roman] +[\-boy] +[\-ida] +[\-orientation-marks] +[\-projection \fImode\fP] +[\-perspective] +[\-orthographic] +[\-speed-x \fIfloat\fP] +[\-speed-y \fIfloat\fP] +[\-speed-z \fIfloat\fP] +[\-walk-direction \fIfloat\fP] +[\-walk-speed \fIfloat\fP] +.SH DESCRIPTION +The \fIetruscanvenus\fP program shows a 3d immersion of a Klein bottle +that smoothly deforms between the Etruscan Venus surface, the Roman +surface, the Boy surface, and the Ida surface. You can walk on the +Klein bottle or turn it in 3d. Topologically, all surfaces are Klein +bottles, even the Roman and Boy surfaces, which are doubly covered and +therefore appear to be an immersed real projective plane. The smooth +deformation between these surfaces was constructed by George +K. Francis. +.PP +The Klein bottle is a non-orientable surface. To make this apparent, +the two-sided color mode can be used. Alternatively, orientation +markers (curling arrows) can be drawn as a texture map on the surface +of the Klein bottle. While walking on the Klein bottle, you will +notice that the orientation of the curling arrows changes (which it +must because the Klein bottle is non-orientable). Since all the +surfaces except the Ida surface have points where the surface normal +is not well defined for some points, walking is only performed on the +Ida surface. +.PP +As mentioned above, the Roman and Boy surfaces are doubly covered and +therefore appear to be an immersed real projective plane. Since some +of the parameter names are based on this interpretation of the +surface, the geometry of the real projective plane will be briefly +disussed. The real projective plane is a model for the projective +geometry in 2d space. One point can be singled out as the origin. A +line can be singled out as the line at infinity, i.e., a line that +lies at an infinite distance to the origin. The line at infinity is +topologically a circle. Points on the line at infinity are also used +to model directions in projective geometry. Direction and distance +bands refer to this interpretation of the surface. If direction bands +are used, the bands extend from the origin of the projective plane in +different directions to the line at infinity and back to the origin. +If distance bands are used, the bands lie at constant distances to the +origin. The same interpretation is used for distance and direction +colors. Although there is no conceptually equivalent geometric +interpretation for the two Klein bottle surfaces (the Etruscan Venus +and Ida surfaces), the smooth deformation between the surfaces results +in a natural extension of these concepts to the Klein bottle surfaces. +.PP +The immersed surfaces can be projected to the screen either +perspectively or orthographically. When using the walking mode, +perspective projection to the screen will be used. +.PP +There are three display modes for the Klein bottle: mesh (wireframe), +solid, or transparent. Furthermore, the appearance of the surface can +be as a solid object or as a set of see-through bands. The bands can +be distance bands or direction bands, as explained above. +.PP +The colors with with the surface is drawn can be set to one-sided, +two-sided, distance, or direction. In one-sided mode, the surface is +drawn with the same color on both sides of the underlying triangles. +In two-sided mode, the surface is drawn with one color on one side of +the underlying triangles and the complementary color on the other +side. Since the surface actually only has one side, the color jumps +from red to green along a line on the surface. This mode enables you +to see that the surface is non-orientable. In distance mode, the +surface is displayed with fully saturated colors that depend on the +distance of the points on the projective plane to the origin, as +described above. If the surface is displayed as distance bands, each +band will be displayed with a different color. In direction mode, the +surface is displayed with fully saturated colors that depend on the +angle of the points on the projective plane with respect to the origin +(see above for an explanation). If the surface is displayed as +direction bands, each band will be displayed with a different color. +The colors used to color the surface can either be static or can be +changed dynamically. +.PP +The rotation speed for each of the three coordinate axes around which +the Klein bottle rotates can be chosen. +.PP +Furthermore, in the walking mode the walking direction in the 2d base +square of the surface and the walking speed can be chosen. The +walking direction is measured as an angle in degrees in the 2d square +that forms the coordinate system of the surface. A value of 0 or 180 +means that the walk is along a circle at a randomly chosen distance +from the origin (parallel to a distance band). A value of 90 or 270 +means that the walk is directly along a direction band. Any other +value results in a curved path along the surface. As noted above, +walking is performed only on the Ida surface. +.PP +By default, the immersion of the Klein bottle smoothly deforms between +the Etruscan Venus surface, the Roman surface, the Boy surface, and +the Ida surface. It is possible to choose the speed of the +deformation. Furthermore, it is possible to switch the deformation +off. It is also possible to determine the initial deformation of the +immersion. This is mostly useful if the deformation is switched off, +in which case it will determine the appearance of the surface. A +value of 0 corresponds to the Etruscan Venus surface, a value of 1000 +to the Roman surface, a value of 2000 to the Boy surface, and a value +of 3000 to the Ida surface. +.PP +This program is inspired by George K. Francis's book "A Topological +Picturebook", Springer, 1987, by George K. Francis's paper "The +Etruscan Venus" in P. Concus, R. Finn, and D. A. Hoffman: "Geometric +Analysis and Computer Graphics", Springer, 1991, and by a video +entitled "The Etruscan Venus" by Donna J. Cox, George K. Francis, and +Raymond L. Idaszak, presented at SIGGRAPH 1989. +.SH OPTIONS +.I etruscanvenus +accepts the following options: +.TP 8 +.B \-window +Draw on a newly-created window. This is the default. +.TP 8 +.B \-root +Draw on the root window. +.TP 8 +.B \-install +Install a private colormap for the window. +.TP 8 +.B \-visual \fIvisual\fP +Specify which visual to use. Legal values are the name of a visual +class, or the id number (decimal or hex) of a specific visual. +.TP 8 +.B \-delay \fImicroseconds\fP +How much of a delay should be introduced between steps of the +animation. Default 10000, or 1/100th second. +.TP 8 +.B \-fps +Display the current frame rate, CPU load, and polygon count. +.PP +The following four options are mutually exclusive. They determine how +the Klein bottle is displayed. +.TP 8 +.B \-mode random +Display the Klein bottle in a random display mode (default). +.TP 8 +.B \-mode wireframe \fP(Shortcut: \fB\-wireframe\fP) +Display the Klein bottle as a wireframe mesh. +.TP 8 +.B \-mode surface \fP(Shortcut: \fB\-surface\fP) +Display the Klein bottle as a solid surface. +.TP 8 +.B \-mode transparent \fP(Shortcut: \fB\-transparent\fP) +Display the Klein bottle as a transparent surface. +.PP +The following four options are mutually exclusive. They determine the +appearance of the Klein bottle. +.TP 8 +.B \-appearance random +Display the Klein bottle with a random appearance (default). +.TP 8 +.B \-appearance solid \fP(Shortcut: \fB\-solid\fP) +Display the Klein bottle as a solid object. +.TP 8 +.B \-appearance distance-bands \fP(Shortcut: \fB\-distance-bands\fP) +Display the Klein bottle as see-through bands that lie at increasing +distances from the origin (see above for an explanation). +.PP +.TP 8 +.B \-appearance direction-bands \fP(Shortcut: \fB\-direction-bands\fP) +Display the Klein bottle as see-through bands that lie at increasing +angles with respect to the origin (see above for an explanation). +.PP +The following five options are mutually exclusive. They determine how +to color the Klein bottle. +.TP 8 +.B \-colors random +Display the Klein bottle with a random color scheme (default). +.TP 8 +.B \-colors onesided \fP(Shortcut: \fB\-onesided-colors\fP) +Display the Klein bottle with a single color. +.TP 8 +.B \-colors twosided \fP(Shortcut: \fB\-twosided-colors\fP) +Display the Klein bottle with two colors: one color on one "side" and +the complementary color on the "other side." +.TP 8 +.B \-colors distance \fP(Shortcut: \fB\-distance-colors\fP) +Display the Klein bottle with fully saturated colors that depend on +the distance of the points on the projective plane to the origin (see +above for an explanation). If the Klein bottle is displayed as +distance bands, each band will be displayed with a different color. +.TP 8 +.B \-colors direction \fP(Shortcut: \fB\-direction-colors\fP) +Display the Klein bottle with fully saturated colors that depend on +the angle of the points on the projective plane with respect to the +origin (see above for an explanation). If the Klein bottle is +displayed as direction bands, each band will be displayed with a +different color. +.PP +The following options determine whether the colors with which the +Klein bottle are displayed are static or are changing dynamically. +.TP 8 +.B \-change-colors +Change the colors with which the Klein bottle is displayed +dynamically (default). +.TP 8 +.B \-no-change-colors +Use static colors to display the Klein bottle. +.PP +The following three options are mutually exclusive. They determine +how to view the Klein bottle. +.TP 8 +.B \-view-mode random +View the Klein bottle in a random view mode (default). The walking +mode will be randomly selected in approximately 10% of the cases. +.TP 8 +.B \-view-mode turn \fP(Shortcut: \fB\-turn\fP) +View the Klein bottle while it turns in 3d. +.TP 8 +.B \-view-mode walk \fP(Shortcut: \fB\-walk\fP) +View the Klein bottle as if walking on its surface. +.PP +The following options determine whether the surface is being deformed. +.TP 8 +.B \-deform +Deform the surface smoothly between the Etruscan Venus surface, the +Roman surface, the Boy surface surface, and the Ida surface (default). +.TP 8 +.B \-no-deform +Don't deform the surface. +.PP +The following option determines the deformation speed. +.TP 8 +.B \-deformation-speed \fIfloat\fP +The deformation speed is measured in percent of some sensible maximum +speed (default: 10.0). +.PP +The following options determine the initial deformation of the +surface. As described above, this is mostly useful if +\fB\-no-deform\fP is specified. +.TP 8 +.B \-initial-deformation \fIfloat\fP +The initial deformation is specified as a number between 0 and 4000. +A value of 0 corresponds to the Etruscan Venus surface, a value of +1000 to the Roman surface, a value of 2000 to the Boy surface, and a +value of 3000 to the Ida surface. The default value is 0. +.TP 8 +.B \-etruscan-venus +This is a shortcut for \fB\-initial-deformation 0\fP. +.TP 8 +.B \-roman +This is a shortcut for \fB\-initial-deformation 1000\fP. +.TP 8 +.B \-boy +This is a shortcut for \fB\-initial-deformation 2000\fP. +.TP 8 +.B \-ida +This is a shortcut for \fB\-initial-deformation 3000\fP. +.PP +The following options determine whether orientation marks are shown on +the Klein bottle. +.TP 8 +.B \-orientation-marks +Display orientation marks on the Klein bottle. +.TP 8 +.B \-no-orientation-marks +Don't display orientation marks on the Klein bottle (default). +.PP +The following three options are mutually exclusive. They determine +how the Klain bottle is projected from 3d to 2d (i.e., to the screen). +.TP 8 +.B \-projection random +Project the Klein bottle from 3d to 2d using a random projection mode +(default). +.TP 8 +.B \-projection perspective \fP(Shortcut: \fB\-perspective\fP) +Project the Klein bottle from 3d to 2d using a perspective projection. +.TP 8 +.B \-projection orthographic \fP(Shortcut: \fB\-orthographic\fP) +Project the Klein bottle from 3d to 2d using an orthographic +projection. +.PP +The following three options determine the rotation speed of the Klein +bottle around the three possible axes. The rotation speed is measured +in degrees per frame. The speeds should be set to relatively small +values, e.g., less than 4 in magnitude. In walk mode, all speeds are +ignored. +.TP 8 +.B \-speed-x \fIfloat\fP +Rotation speed around the x axis (default: 1.1). +.TP 8 +.B \-speed-y \fIfloat\fP +Rotation speed around the y axis (default: 1.3). +.TP 8 +.B \-speed-z \fIfloat\fP +Rotation speed around the z axis (default: 1.5). +.PP +The following two options determine the walking speed and direction. +.TP 8 +.B \-walk-direction \fIfloat\fP +The walking direction is measured as an angle in degrees in the 2d +square that forms the coordinate system of the surface of the Klein +bottle (default: 83.0). A value of 0 or 180 means that the walk is +along a circle at a randomly chosen distance from the origin (parallel +to a distance band). A value of 90 or 270 means that the walk is +directly along a direction band. Any other value results in a curved +path along the surface. As noted above, walking is performed only on +the Ida surface. +.TP 8 +.B \-walk-speed \fIfloat\fP +The walking speed is measured in percent of some sensible maximum +speed (default: 20.0). +.SH INTERACTION +If you run this program in standalone mode in its turn mode, you can +rotate the Klein bottle by dragging the mouse while pressing the left +mouse button. This rotates the Klein bottle in 3d. To examine the +Klein bottle at your leisure, it is best to set all speeds to 0. +Otherwise, the Klein bottle will rotate while the left mouse button is +not pressed. This kind of interaction is not available in the walk +mode. +.SH ENVIRONMENT +.PP +.TP 8 +.B DISPLAY +to get the default host and display number. +.TP 8 +.B XENVIRONMENT +to get the name of a resource file that overrides the global resources +stored in the RESOURCE_MANAGER property. +.SH SEE ALSO +.BR X (1), +.BR xscreensaver (1) +.SH COPYRIGHT +Copyright \(co 2019-2020 by Carsten Steger. Permission to use, copy, +modify, distribute, and sell this software and its documentation for +any purpose is hereby granted without fee, provided that the above +copyright notice appear in all copies and that both that copyright +notice and this permission notice appear in supporting documentation. +No representations are made about the suitability of this software for +any purpose. It is provided "as is" without express or implied +warranty. +.SH AUTHOR +Carsten Steger <carsten@mirsanmir.org>, 05-jan-2020. diff --git a/hacks/glx/gibson.c b/hacks/glx/gibson.c new file mode 100644 index 0000000..8f99040 --- /dev/null +++ b/hacks/glx/gibson.c @@ -0,0 +1,1335 @@ +/* gibson, Copyright (c) 2020 Jamie Zawinski <jwz@jwz.org> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. No representations are made about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * Hacking the Gibson, as per the 1995 classic film, HACKERS. + * + * In the movie, this was primarily a practical effect: the towers were + * edge-lit etched perspex, each about four feet tall. + */ + +#define TOWER_FONT "-*-helvetica-bold-r-normal-*-*-480-*-*-*-*-*-*" + +#define DEFAULTS "*delay: 20000 \n" \ + "*groundColor: #8A2BE2" "\n" \ + "*towerColor: #4444FF" "\n" \ + "*towerText: #DDDDFF" "\n" \ + "*towerText2: #FF0000" "\n" \ + "*towerFont: " TOWER_FONT "\n" \ + "*showFPS: False \n" \ + "*wireframe: False \n" \ + +# define release_gibson 0 +#undef countof +#define countof(x) (sizeof((x))/sizeof((*x))) + +#include "xlockmore.h" +#include "colors.h" +#include "rotator.h" +#include "texfont.h" +#include <ctype.h> + +#ifdef USE_GL /* whole file */ + + +#define DEF_SPEED "1.0" +#define DEF_TEXTURE "True" +#define DEF_GRID_WIDTH "6" +#define DEF_GRID_HEIGHT "7" +#define DEF_GRID_DEPTH "6" +#define DEF_GRID_SPACING "2.0" +#define DEF_COLUMNS "5" + +#define GROUND_QUAD_SIZE 30 + +typedef struct { + GLfloat x, y, h; + GLuint fg_dlists[5], bg_dlists[5]; + int fg_polys, bg_polys; + unsigned int face_mode; /* 5 bit field */ +} tower; + +typedef struct { + GLXContext *glx_context; + Bool button_down_p; + rotator *rot, *rot2; + GLfloat xscroll, yscroll; + GLfloat oxscroll, oyscroll; + + GLuint ground_dlist; + GLuint tower_dlist; + int ground_polys, tower_polys; + GLfloat ground_y; + GLfloat billboard_y; + const char *billboard_text; + + int ntowers; + tower *towers; + GLfloat tower_color[4]; + GLfloat tower_color2[4]; + GLfloat edge_color[4]; + GLfloat bg_color[4]; + Bool startup_p; + + struct { + GLuint texid; + XCharStruct metrics; + int width, height; + texture_font_data *font_data; + int ascent, descent, em_width; + char *text; + } text[2]; + +} gibson_configuration; + +static gibson_configuration *ccs = NULL; + +static GLfloat speed; +static Bool do_tex; +static int grid_width; +static int grid_height; +static int grid_depth; +static GLfloat grid_spacing; +static int columns; + +static XrmOptionDescRec opts[] = { + { "-speed", ".speed", XrmoptionSepArg, 0 }, + { "-texture", ".texture", XrmoptionNoArg, "True" }, + { "+texture", ".texture", XrmoptionNoArg, "False" }, + { "-grid-width", ".gridWidth", XrmoptionSepArg, 0 }, + { "-grid-height", ".gridHeight", XrmoptionSepArg, 0 }, + { "-grid-depth", ".gridDepth", XrmoptionSepArg, 0 }, + { "-spacing", ".gridSpacing", XrmoptionSepArg, 0 }, + { "-columns", ".columns", XrmoptionSepArg, 0 }, +}; + +static argtype vars[] = { + {&speed, "speed", "Speed", DEF_SPEED, t_Float}, + {&do_tex, "texture", "Texture", DEF_TEXTURE, t_Bool}, + {&grid_width, "gridWidth", "GridWidth", DEF_GRID_WIDTH, t_Int}, + {&grid_height, "gridHeight", "GridHeight", DEF_GRID_HEIGHT, t_Int}, + {&grid_depth, "gridDepth", "GridDepth", DEF_GRID_DEPTH, t_Int}, + {&grid_spacing, "gridSpacing", "GridSpacing", DEF_GRID_SPACING, t_Float}, + {&columns, "columns", "Columns", DEF_COLUMNS, t_Int}, +}; + +ENTRYPOINT ModeSpecOpt gibson_opts = { + countof(opts), opts, countof(vars), vars, NULL}; + + +ENTRYPOINT void +reshape_gibson (ModeInfo *mi, int width, int height) +{ + GLfloat h = (GLfloat) height / (GLfloat) width; + int y = 0; + + glViewport (0, y, (GLint) width, (GLint) height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); +# ifdef DEBUG + gluPerspective (30, 1/h, 1, 100); +# else + gluPerspective (100, 1/h/4, + 1.0, + 20 * grid_depth * 1.5 * (1 + grid_spacing)); +# endif + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt( 0, 0, 1, + 0, 0, 0, + 0, 1, 0); + + glClear(GL_COLOR_BUFFER_BIT); +} + + +/* Copied from gltrackball.c */ +static void +adjust_for_device_rotation (double *x, double *y, double *w, double *h) +{ + int rot = (int) current_device_rotation(); + int swap; + + while (rot <= -180) rot += 360; + while (rot > 180) rot -= 360; + + if (rot > 135 || rot < -135) /* 180 */ + { + *x = *w - *x; + *y = *h - *y; + } + else if (rot > 45) /* 90 */ + { + swap = *x; *x = *y; *y = swap; + swap = *w; *w = *h; *h = swap; + *x = *w - *x; + } + else if (rot < -45) /* 270 */ + { + swap = *x; *x = *y; *y = swap; + swap = *w; *w = *h; *h = swap; + *y = *h - *y; + } +} + + +ENTRYPOINT Bool +gibson_handle_event (ModeInfo *mi, XEvent *event) +{ + gibson_configuration *bp = &ccs[MI_SCREEN(mi)]; + double w = MI_WIDTH(mi); + double h = MI_HEIGHT(mi); + double xoff = 0, yoff = 0; + + if (event->xany.type == ButtonPress || + event->xany.type == ButtonRelease) + { + double x = event->xbutton.x; + double y = event->xbutton.y; + adjust_for_device_rotation (&x, &y, &w, &h); + xoff = (x / w) - 0.5; + yoff = (event->xbutton.y / h) - 0.5; + bp->button_down_p = (event->xany.type == ButtonPress); + bp->oxscroll = xoff; + bp->oyscroll = yoff; + + return True; + } + else if (event->xany.type == MotionNotify) + { + double x = event->xmotion.x; + double y = event->xmotion.y; + adjust_for_device_rotation (&x, &y, &w, &h); + xoff = (x / w) - 0.5; + yoff = (y / h) - 0.5; + if (bp->button_down_p) + { + bp->xscroll += xoff - bp->oxscroll; + bp->yscroll += yoff - bp->oyscroll; + bp->oxscroll = xoff; + bp->oyscroll = yoff; + } + return True; + } + + return False; +} + + +static void +parse_color (ModeInfo *mi, char *key, GLfloat color[4]) +{ + XColor xcolor; + char *string = get_string_resource (mi->dpy, key, "Color"); + if (!XParseColor (mi->dpy, mi->xgwa.colormap, string, &xcolor)) + { + fprintf (stderr, "%s: unparsable color in %s: %s\n", progname, + key, string); + exit (1); + } + free (string); + + color[0] = xcolor.red / 65536.0; + color[1] = xcolor.green / 65536.0; + color[2] = xcolor.blue / 65536.0; + color[3] = 1; +} + + +static int +draw_ground (ModeInfo *mi) +{ + int wire = MI_IS_WIREFRAME(mi); + int polys = 0; + int x, y; + int cells = 20; + GLfloat color[4]; + GLfloat color0[4]; + GLfloat cell_size = 1.0; + GLfloat z = -0.005; + + parse_color (mi, "groundColor", color); + parse_color (mi, "towerColor", color0); + color0[0] *= 0.05; + color0[1] *= 0.05; + color0[2] *= 0.3; + color0[3] = 1; + + if (!wire) + { + GLfloat fog_color[4] = { 0, 0, 0, 1 }; + + glFogi (GL_FOG_MODE, GL_EXP2); + glFogfv (GL_FOG_COLOR, fog_color); + glFogf (GL_FOG_DENSITY, 0.015); + glFogf (GL_FOG_START, -cells/2 * cell_size); + glEnable (GL_FOG); + } + + glPushMatrix(); + glScalef (1.0/cells, 1.0/cells, 1); + glTranslatef (-cells/2.0, -cells/2.0, 0); + glTranslatef (0.5, 0, 0); + + glBegin (GL_QUADS); /* clipping quad */ + glColor4fv (color0); + glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color0); + + glVertex3f (0, 0, z); + glVertex3f (cells * cell_size, 0, z); + glVertex3f (cells * cell_size, cells * cell_size, z); + glVertex3f (0, cells * cell_size, z); + glEnd(); + polys++; + + glColor4fv (color); + glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); + + for (y = 0; y < cells; y++) + for (x = 0; x < cells; x++) + { + GLfloat a = 0; + GLfloat b = 1.0/3; + GLfloat c = 2.0/3; + GLfloat d = 1.0; + GLfloat w = 0.02; + + glPushMatrix(); + glTranslatef (x, y, 0); + + glNormal3f (0, 0, 1); + + switch (random() % 4) { + case 0: + glRotatef (90, 0, 0, 1); + glTranslatef (0, -1, 0); + break; + case 1: + glRotatef (-90, 0, 0, 1); + glTranslatef (-1, 0, 0); + break; + case 2: + glRotatef (180, 0, 0, 1); + glTranslatef (-1, -1, 0); + break; + default: break; + } + + switch (random() % 2) { + case 0: + glScalef (-1, -1, 1); + glTranslatef (-1, -1, 0); + break; + default: break; + } + + switch (random() % 2) { + case 0: + + glBegin (wire ? GL_LINE_LOOP : GL_QUAD_STRIP); + glVertex3f (a, b+w, 0); + glVertex3f (a, b-w, 0); polys++; + glVertex3f (b+w, a, 0); polys++; + glVertex3f (b-w, a, 0); polys++; + glEnd(); + + glBegin (wire ? GL_LINE_LOOP : GL_QUAD_STRIP); + glVertex3f (a, c+w, 0); + glVertex3f (a, c-w, 0); polys++; + glVertex3f (b+w, c+w, 0); polys++; + glVertex3f (b, c-w, 0); polys++; + glVertex3f (c+w, b+w, 0); polys++; + glVertex3f (c-w, b, 0); polys++; + glVertex3f (c+w, a, 0); polys++; + glVertex3f (c-w, a, 0); polys++; + glEnd(); + +/* + glBegin (wire ? GL_LINE_LOOP : GL_QUAD_STRIP); + glVertex3f (c+w, d, 0); + glVertex3f (c-w, d, 0); polys++; + glVertex3f (d, c+w, 0); polys++; + glVertex3f (d, c-w, 0); polys++; + glEnd(); +*/ + break; + + default: + glBegin (wire ? GL_LINE_LOOP : GL_QUAD_STRIP); + glVertex3f (a+w, d, 0); + glVertex3f (a, d, 0); polys++; + glVertex3f (a+w, d, 0); + glVertex3f (a, d-w, 0); polys++; + glVertex3f (b+w, c-w, 0); polys++; + glVertex3f (b-w, c-w, 0); polys++; + glVertex3f (b+w, a, 0); polys++; + glVertex3f (b-w, a, 0); polys++; + glEnd(); + + glBegin (wire ? GL_LINE_LOOP : GL_QUAD_STRIP); + glVertex3f (b+w, d, 0); + glVertex3f (b-w, d, 0); polys++; + glVertex3f (c+w, c-w, 0); polys++; + glVertex3f (c-w, c-w, 0); polys++; + glVertex3f (c+w, a, 0); polys++; + glVertex3f (c-w, a, 0); polys++; + glEnd(); + break; + } + + glPopMatrix(); + } + glPopMatrix(); + + if (!wire) + { + glDisable (GL_BLEND); + glDisable (GL_FOG); + } + + return polys; +} + + +/* qsort comparator for sorting towers by y position */ +static int +cmp_towers (const void *aa, const void *bb) +{ + const tower *a = (tower *) aa; + const tower *b = (tower *) bb; + return ((int) (b->y * 10000) - + (int) (a->y * 10000)); +} + + +static GLfloat +ease_fn (GLfloat r) +{ + return cos ((r/2 + 1) * M_PI) + 1; /* Smooth curve up, end at slope 1. */ +} + + +static GLfloat +ease_ratio (GLfloat r) +{ + GLfloat ease = 0.5; + if (r <= 0) return 0; + else if (r >= 1) return 1; + else if (r <= ease) return ease * ease_fn (r / ease); + else if (r > 1-ease) return 1 - ease * ease_fn ((1 - r) / ease); + else return r; +} + + +/* Draws the text quads on the face. + First pass is for the small background text, second is for the big block. + */ +static int +draw_tower_face_text (ModeInfo *mi, GLfloat height, Bool which) +{ + gibson_configuration *bp = &ccs[MI_SCREEN(mi)]; + int wire = MI_IS_WIREFRAME(mi); + int polys = 0; + Bool wire2 = False; /* Debugging quads */ + Bool bg_p = (which == 1 && do_tex && !wire); + + glColor4fv (which ? bp->tower_color2 : bp->tower_color); + glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, + which ? bp->tower_color2 : bp->tower_color); + + /* The texture is a tex_width x tex_height rectangle, of which we + only use the rbearing+lbearing x ascent+descent sub-rectangle. + Texture coordinates reference the tex_width x tex_height rectangle + as a 0.0 - 1.0 coordinate. + */ + int n = which ? 1 : 0; + GLfloat twratio = ((bp->text[n].metrics.rbearing + + bp->text[n].metrics.lbearing) / + (GLfloat) bp->text[n].width); + GLfloat thratio = ((bp->text[n].metrics.ascent + + bp->text[n].metrics.descent) / + (GLfloat) bp->text[n].height); + GLfloat aspect = ((bp->text[n].ascent + bp->text[n].descent) / + (GLfloat) bp->text[n].em_width); + + GLfloat sx = 1.0 / (which ? 1 : columns); + GLfloat sy = (which + ? height * 0.8 + : sx * 4); /* Tweaked to match gluPerspective */ + + GLfloat lines_in_tex = ((bp->text[n].metrics.ascent + + bp->text[n].metrics.descent) / + (GLfloat) + (bp->text[n].ascent + bp->text[n].descent)); + GLfloat tex_lines = (which ? 3 : 8); /* Put this many lines in each quad */ + + GLfloat tsx = sx * twratio; + GLfloat tsy = sy * thratio * tex_lines / lines_in_tex * aspect; + GLfloat x1, tx1; + GLfloat margin = 0.2; + GLfloat m2 = margin/2 / (which ? 1 : columns); + GLfloat m3 = m2 / (which ? 1 : height); + GLfloat h2 = height * (which ? 1-margin : 1); + + glBindTexture (GL_TEXTURE_2D, bp->text[n].texid); + + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + if (!wire && !wire2 && !bg_p) glBegin (GL_QUADS); + for (x1 = 0, tx1 = 0; x1 < 1.0; x1 += sx, tx1 += tsx) + { + GLfloat x2 = x1 + sx; + GLfloat tx2 = tx1 + tsx; + GLfloat y2, ty2; + GLfloat z = (which ? 0.05 : 0); + + tx1 = 0; + tx2 = twratio; + + for (y2 = h2, ty2 = thratio; + y2 > 0; + y2 -= sy, ty2 -= tsy) + { + GLfloat y1 = y2 - sy * (1-margin); + GLfloat ty1 = ty2 - tsy; + GLfloat toff = frand ((bp->text[n].metrics.ascent + + bp->text[n].metrics.descent) + * 0.8); + + if (y1 < 0) /* Clip the panel to the bottom of the tower face */ + { + tsy = y2 / (y2 - y1); + y1 = 0; + } + + ty1 = toff; + ty2 = ty1 + tsy; + + if (wire2 && which) glColor3f (1,0,0); + if (wire || wire2 || bg_p) + glBegin (!wire && (wire2 || bg_p) ? GL_QUADS : GL_LINE_LOOP); + glTexCoord2f(tx1, ty2); glVertex3f (x1+m2, y1+m3, z); + glTexCoord2f(tx2, ty2); glVertex3f (x2-m2, y1+m3, z); + glTexCoord2f(tx2, ty1); glVertex3f (x2-m2, y2-m3, z); + glTexCoord2f(tx1, ty1); glVertex3f (x1+m2, y2-m3, z); + if (wire || wire2 || bg_p) + glEnd(); + polys++; + + if (bg_p) + { + GLfloat bg[4] = { 1, 1, 1, 0.2 }; + z -= 0.1; + m2 -= 0.03; + m3 -= 0.03; + glColor4fv (bg); + glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, bg); + } + + if ((wire2 || bg_p) && !wire) + { + if (do_tex) glDisable(GL_TEXTURE_2D); + glBegin (bg_p ? GL_QUADS : GL_LINE_LOOP); + glVertex3f (x1+m2, y1+m3, z); + glVertex3f (x2-m2, y1+m3, z); + glVertex3f (x2-m2, y2-m3, z); + glVertex3f (x1+m2, y2-m3, z); + glEnd(); + polys++; + if (do_tex) glEnable(GL_TEXTURE_2D); + } + + if (which) break; + } + } + if (!wire && !wire2 && !bg_p) glEnd(); + + return polys; +} + + +/* Draws the wall of the face, and the edges, then the text quads on it. + */ +static int +draw_tower_face (ModeInfo *mi, GLfloat height, int mode) +{ + gibson_configuration *bp = &ccs[MI_SCREEN(mi)]; + int wire = MI_IS_WIREFRAME(mi); + int polys = 0; + + switch (mode) { + case 0: + if (! wire) + { + GLfloat m = 0.015; + GLfloat z = -0.0005; + if (do_tex) glDisable (GL_TEXTURE_2D); + + glNormal3f (0, 0, 1); + + glColor4fv (bp->bg_color); + glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, + bp->bg_color); + + glBegin (GL_QUADS); + glVertex3f (0, 0, z*2); /* background */ + glVertex3f (1, 0, z*2); + glVertex3f (1, height, z*2); + glVertex3f (0, height, z*2); + polys++; + glEnd(); + + glColor4fv (bp->edge_color); + glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, + bp->edge_color); + + glBegin (GL_QUADS); + glVertex3f (0, 0, z); /* left */ + glVertex3f (m, 0, z); + glVertex3f (m, height, z); + glVertex3f (0, height, z); + polys++; + + glVertex3f (1-m, 0, 0); /* right */ + glVertex3f (1, 0, 0); + glVertex3f (1, height, z); + glVertex3f (1-m, height, z); + polys++; + + glVertex3f (m, 0, 0); /* bottom */ + glVertex3f (1-m, 0, 0); + glVertex3f (1-m, m, 0); + glVertex3f (m, m, 0); + polys++; + + glVertex3f (m, height-m, z); /* top */ + glVertex3f (1-m, height-m, z); + glVertex3f (1-m, height, z); + glVertex3f (m, height, z); + polys++; + glEnd(); + + if (do_tex) glEnable (GL_TEXTURE_2D); + } + break; + case 1: + polys += draw_tower_face_text (mi, height, 0); + break; + case 2: + polys += draw_tower_face_text (mi, height * 0.7, 1); + break; + default: + abort(); + break; + } + + return polys; +} + + +/* Mode 0: draws 5 sides of the box + Mode 1: just background text + Mode 2: just foreground text + */ +static int +draw_tower (ModeInfo *mi, tower *t, int mode, int face) +{ + GLfloat height = grid_height; + + int polys = 0; + + glPushMatrix(); + glTranslatef (-0.5, 0.5, 0); + + if (face == 0 || face == -1) + { + glPushMatrix(); /* top */ + glTranslatef (0, 0, height); + polys += draw_tower_face (mi, 1.0, mode); + glPopMatrix(); + } + + if (face == 1 || face == -1) + { + glPushMatrix(); /* left */ + glRotatef ( 90, 1, 0, 0); + glRotatef (-90, 0, 1, 0); + glTranslatef (-1, 0, 0); + polys += draw_tower_face (mi, height, mode); + glPopMatrix(); + } + + if (face == 2 || face == -1) + { + glPushMatrix(); /* back */ + glRotatef ( 90, 1, 0, 0); + glRotatef (180, 0, 1, 0); + glTranslatef (-1, 0, 1); + polys += draw_tower_face (mi, height, mode); + glPopMatrix(); + } + + if (face == 3 || face == -1) + { + glPushMatrix(); /* right */ + glRotatef ( 90, 1, 0, 0); + glRotatef ( 90, 0, 1, 0); + glTranslatef (0, 0, 1); + polys += draw_tower_face (mi, height, mode); + glPopMatrix(); + } + + if (face == 4 || face == -1) + { + glPushMatrix(); /* front */ + glRotatef ( 90, 1, 0, 0); + polys += draw_tower_face (mi, height, mode); + glPopMatrix(); + } + + if (face < -1 || face > 4) abort(); + + glPopMatrix(); + return polys; +} + + +static void +animate_towers (ModeInfo *mi) +{ + gibson_configuration *bp = &ccs[MI_SCREEN(mi)]; + int ii; + GLfloat min = -3; + GLfloat max = grid_depth * (1 + grid_spacing) - grid_spacing - 1; + GLfloat yspeed = speed * 0.05; + + for (ii = 0; ii < 20; ii++) + { + int jj, kk; + + /* randomly trade two towers' fg dlists */ + if (0 == (random() % 20)) + { + int i = random() % bp->ntowers; + int j = random() % bp->ntowers; + int k = random() % countof(bp->towers[i].fg_dlists); + GLuint d1 = bp->towers[i].bg_dlists[k]; + GLuint d2 = bp->towers[j].bg_dlists[k]; + bp->towers[i].bg_dlists[k] = d2; + bp->towers[j].bg_dlists[k] = d1; + } + + /* randomly trade two towers' bg dlists */ + if (1) /* (0 == (random() % 3)) */ + { + int i = random() % bp->ntowers; + int j = random() % bp->ntowers; + int k = random() % countof(bp->towers[i].fg_dlists); + GLuint d1 = bp->towers[i].fg_dlists[k]; + GLuint d2 = bp->towers[j].fg_dlists[k]; + bp->towers[i].fg_dlists[k] = d2; + bp->towers[j].fg_dlists[k] = d1; + } + + /* Randomize whether it's displaying fg text or bg text */ + for (jj = 0; jj < bp->ntowers; jj++) + for (kk = 0; kk < countof(bp->towers[jj].fg_dlists); kk++) + { + /* Re-choose every N frames. Display fg 1 in M. */ + int frames = 500; + int fg_chance = (kk == 0 ? 100000 : 10); + unsigned int o = !!(bp->towers[jj].face_mode & (1 << kk)); + unsigned int n = !!((random() % frames) ? o : + (0 == (random() % fg_chance))); + bp->towers[jj].face_mode = + ((bp->towers[jj].face_mode & ~(1 << kk)) | (n << kk)); + } + } + + for (ii = 0; ii < bp->ntowers; ii++) + { + tower *t = &bp->towers[ii]; + t->h += speed * 0.01; + if (t->h > 1) t->h = 1; + + t->y -= yspeed; + + if (t->y < min) + { + t->h = 0; + t->y = max; + } + } + + /* Sorting by depth improves frame rate slightly. */ + qsort (bp->towers, bp->ntowers, sizeof(*bp->towers), cmp_towers); + + bp->ground_y -= yspeed / GROUND_QUAD_SIZE; + if (bp->ground_y < 1) + bp->ground_y += 1; + + bp->billboard_y -= yspeed; + if (bp->billboard_y < min || !bp->billboard_text) + { + const char *const ss[] = { + "ACCESS GRANTED", + "ACCESS GRANTED", + "ACCESS DENIED", + "ACCESS DENIED", + "ACCESS DENIED", + "ACCESS DENIED", + "ACCESS DENIED", + "PASSWORD ACCEPTED", + " GIVE ME\nA COOKIE", + "MESS WITH THE BEST\n DIE LIKE THE REST", + }; + + bp->billboard_y = max * (1 + frand(8)); + bp->billboard_text = ss[random() % countof(ss)]; + } +} + + +static int +draw_billboard (ModeInfo *mi) +{ + gibson_configuration *bp = &ccs[MI_SCREEN(mi)]; + int polys = 0; + int wire = MI_IS_WIREFRAME(mi); + GLfloat w, h, s, margin, margin2; + XCharStruct metrics; + int ascent, descent; + texture_font_data *font = bp->text[1].font_data; + GLfloat color[4]; + GLfloat y = grid_height * 0.3; + + texture_string_metrics (font, bp->billboard_text, + &metrics, &ascent, &descent); + w = metrics.lbearing + metrics.rbearing; + h = metrics.ascent + metrics.descent; + s = 1.0 / w; + s *= 0.95; + + margin = w * 0.1; + margin2 = margin * 1.7; + + glPushMatrix(); + + glTranslatef (-0.5, bp->billboard_y, y); + glRotatef (90, 1, 0, 0); + glScalef (s, s * 1.5, s); + + memcpy (color, bp->tower_color2, sizeof(color)); + color[3] = 0.6; + glColor4fv (color); + glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); + + if (do_tex && !wire) + glDisable (GL_TEXTURE_2D); + + glBegin (wire ? GL_LINE_LOOP : GL_QUADS); + glNormal3f (0, 0, 1); + glVertex3f (-margin, -margin2, 0); + glVertex3f (-margin, h+margin2, 0); + glVertex3f (w+margin, h+margin2, 0); + glVertex3f (w+margin, -margin2, 0); + glEnd(); + polys++; + + if (do_tex && !wire) + { + color[3] = 1; + glColor4fv (color); + glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); + glEnable (GL_TEXTURE_2D); + glTranslatef (-metrics.lbearing, metrics.descent, 0); + print_texture_string (font, bp->billboard_text); + polys++; + } + + glPopMatrix(); + return polys; +} + + +static void +init_text (ModeInfo *mi) +{ + gibson_configuration *bp = &ccs[MI_SCREEN(mi)]; + int lines = 20; + int i; + char *s; + + const char *const ss[] = { + "\n" + "ACCESS TO THIS COMPUTER AND\n" + "ITS DATA IS RESTRICTED TO\n" + "AUTHORIZED PERSONNEL ONLY\n" + "\n", + "\n" + " PASSWORD ACCEPTED\n" + " GOD\n" + "\n", + "PERSONNEL >>>\n", + "SEA ROUTINGS >>>\n", + "GARBAGE >>>\n", + "COMP. SERVICING >>>\n", + "COMPANY BUDGETS >>>\n", + "SCIENTIFIC BUDGETS >>>\n", + "COMPANY POLICIES >>>\n", + "ANNUAL RETURNS >>>\n", + "MINE RESEARCH >>>\n", + "CENTRAL LIBRARY >>>\n", + "QUANTATIVE SPEC. >>>\n", + "PAYMENT LEVELS >>>\n", + "CENTRAL SERVER >>>\n", + "GARBAGE >>>\n", + "KNMTS. DVPNT. >>>\n", + "LICENSING >>>\n", + "RELATIONS >>>\n", + "TIME SHEET RECS. >>>\n", + "RD. PRT. ROUTINGS >>>\n", + "RECRUITMENT >>>\n", + "TNKR. EXPENDITURE >>>\n", + "MINE DEVELOPMENT >>>\n", + "GARBAGE >>>\n", + "ANNUAL BUDGETS >>>\n", + "OIL LOCATIONS >>>\n", + "TIME SHEET RECS. >>>\n", + "RD. PRT. ROUTINGS >>>\n", + "KINEMATICS >>>\n", + "TPS. REPORTS >>>\n", + "BLAST FRNC. STATUS >>>\n", + "ACCOUNTANTS >>>\n", + "SHIPPING FORCASTS >>>\n", + "INDST. REPORTS >>>\n", + "EXPLOR. DVLT. >>>\n", + "WRHSE. EXPEND. >>>\n", + "GARBAGE >>>\n", + "RELOCATIONS >>>\n", + "AIRFREIGHT STATUS >>>\n", + "TPGC. EXPEND. >>>\n", + "SEA-BOARD LAWS >>>\n", + "COMPOSITE PLANTS >>>\n", + "NUCLEAR RESEARCH >>>\n", + "BALLAST REPORTS >>>\n", + "\n" + "CONFIDENTAL\n" + "FILES\n" + "DO NOT DELETE\n" + "BEFORE FINAL\n" + "BACKUP IS COMPLETED\n" + "\n", + "\n" + "FILE 1\n" + "WAITING FOR BACK-UP\n" + "\n" + "FILE 2\n" + "WAITING FOR BACK-UP\n" + "\n" + "FILE 3\n" + "WAITING FOR BACK-UP\n" + "\n" + "FILE 4\n" + "WAITING FOR BACK-UP\n" + "\n" + }; + + + bp->text[1].text = s = calloc (countof(ss) * 2 * 40, 1); + for (i = 0; i < countof(ss); i++) + { + int n = random() % countof(ss); + strcat (s, ss[n]); + s += strlen(s); + } + + bp->text[0].text = s = calloc (lines * 40, 1); + for (i = 0; i < lines; i++) + { + switch (random() % 11) { + case 0: sprintf (s, "%X\n", random() % 0xFFFFFFFF); break; + case 1: sprintf (s, "%X\n", random() % 0xFFFFFF); break; + case 2: sprintf (s, "%X\n", random() % 0xFFFF); break; + case 3: sprintf (s, "%d\n", random() % 0xFFFFFF); break; + case 4: sprintf (s, "%d\n", random() % 0xFFFF); break; + case 5: sprintf (s, "%d\n", random() % 0xFFF); break; + case 6: strcat (s, "00000000\n"); break; + case 7: sprintf (s, "{{{{{{{{\n"); break; + case 8: sprintf (s, "[][][][][][]\n"); break; + case 9: sprintf (s, "DEFAULT\n"); break; + case 10: sprintf (s, "\n"); break; + } + s += strlen(s); + } +} + + +static void +init_textures (ModeInfo *mi) +{ + gibson_configuration *bp = &ccs[MI_SCREEN(mi)]; + int i; + for (i = 0; i < countof(bp->text); i++) + { + glGenTextures (1, &bp->text[i].texid); + glBindTexture (GL_TEXTURE_2D, bp->text[i].texid); + texture_string_metrics (bp->text[i].font_data, " ", + &bp->text[i].metrics, + &bp->text[i].ascent, + &bp->text[i].descent); + bp->text[i].em_width = bp->text[i].metrics.width; + string_to_texture (bp->text[i].font_data, bp->text[i].text, + &bp->text[i].metrics, + &bp->text[i].width, + &bp->text[i].height); + } + glBindTexture (GL_TEXTURE_2D, 0); +} + + +ENTRYPOINT void +init_gibson (ModeInfo *mi) +{ + gibson_configuration *bp; + + MI_INIT (mi, ccs); + + bp = &ccs[MI_SCREEN(mi)]; + + if ((bp->glx_context = init_GL(mi)) != NULL) { + reshape_gibson (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); + } + + parse_color (mi, "towerText", bp->tower_color); + parse_color (mi, "towerText2", bp->tower_color2); + parse_color (mi, "towerColor", bp->bg_color); + memcpy (bp->edge_color, bp->bg_color, sizeof(bp->tower_color)); + bp->edge_color [3] = 0.7; + bp->bg_color [3] = 1.0; + bp->tower_color [3] = 1.0; + bp->tower_color2[3] = 1.0; + + if (grid_spacing < 1) grid_spacing = 1; + if (grid_width < 1) grid_width = 1; + if (grid_height < 1) grid_height = 1; + if (grid_depth < 1) grid_depth = 1; + if (columns < 1) columns = 1; + bp->ntowers = grid_width * grid_depth; + bp->towers = (tower *) calloc (sizeof(tower), bp->ntowers); + bp->startup_p = True; + + { + double wander_speed = 0.007 * speed; + double tilt_speed = 0.01 * speed; + bp->rot = make_rotator (0, 0, 0, 0, wander_speed, True); + bp->rot2 = make_rotator (0, 0, 0, 0, tilt_speed, True); + } + + bp->text[0].font_data = load_texture_font (mi->dpy, "towerFont"); + bp->text[1].font_data = load_texture_font (mi->dpy, "towerFont"); + init_text (mi); + init_textures (mi); + + bp->ground_dlist = glGenLists (1); + glNewList (bp->ground_dlist, GL_COMPILE); + bp->ground_polys = draw_ground (mi); + glEndList (); + + bp->tower_dlist = glGenLists (1); + glNewList (bp->tower_dlist, GL_COMPILE); + bp->tower_polys = draw_tower (mi, &bp->towers[0], 0, -1); + glEndList (); + + { + int x, y; + GLfloat ww = grid_width * (1 + grid_spacing) - grid_spacing; + GLfloat hh = grid_depth * (1 + grid_spacing) - grid_spacing; + for (y = 0; y < grid_depth; y++) + for (x = 0; x < grid_width; x++) + { + int i; + tower *t = &bp->towers[y * grid_width + x]; + t->x = (x * ww / (grid_width - 1)) - ww/2; + t->y = (y * hh / grid_depth) + 6; + t->h = 0 - y / (GLfloat) grid_depth / 2; + + for (i = 0; i < countof(t->fg_dlists); i++) + { + t->bg_dlists[i] = glGenLists (1); + glNewList (t->bg_dlists[i], GL_COMPILE); + t->bg_polys = draw_tower (mi, t, 1, i); + glEndList (); + + t->fg_dlists[i] = glGenLists (1); + glNewList (t->fg_dlists[i], GL_COMPILE); + t->fg_polys += draw_tower (mi, t, 2, i); + glEndList (); + } + } + } + + animate_towers (mi); +} + + +ENTRYPOINT void +draw_gibson (ModeInfo *mi) +{ + gibson_configuration *bp = &ccs[MI_SCREEN(mi)]; + Display *dpy = MI_DISPLAY(mi); + Window window = MI_WINDOW(mi); + int wire = MI_IS_WIREFRAME(mi); + GLfloat s; + int i; + + static const GLfloat bspec[4] = {1.0, 1.0, 1.0, 1.0}; + static const GLfloat bshiny = 128.0; + GLfloat bcolor[4] = { 0.7, 0.7, 1.0, 1.0 }; + + if (!bp->glx_context) + return; + + mi->polygon_count = 0; + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *bp->glx_context); + + glShadeModel (GL_SMOOTH); + glEnable (GL_NORMALIZE); + glEnable (GL_CULL_FACE); + glDisable (GL_TEXTURE_2D); + glEnable (GL_DEPTH_TEST); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if (!wire) + { + GLfloat pos[4] = {0.4, 0.2, 0.4, 0.0}; + GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; + GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; + GLfloat spc[4] = {1.0, 1.0, 1.0, 1.0}; + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glLightfv(GL_LIGHT0, GL_AMBIENT, amb); + glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); + glLightfv(GL_LIGHT0, GL_SPECULAR, spc); + } + + glPushMatrix (); + + glRotatef(current_device_rotation(), 0, 0, 1); + +# ifdef DEBUG + s = 0.02; +# else + s = 10; +# endif + + glScalef (s, s, s); + + glTranslatef (0, -1, 0); + +# ifndef DEBUG + glRotatef (-82, 1, 0, 0); + + { + double maxx = 40; /* up/down */ + double maxy = 1.5; /* tilt */ + double maxz = 100; /* left/right */ + + double x, y, z; + double minh = -(grid_height / 2.0); + double maxh = -(grid_height / 20.0); + + get_position (bp->rot, &x, &y, &z, !bp->button_down_p); + x -= 0.5; + z = minh + (z * (maxh - minh)); + glTranslatef(x * grid_spacing * 0.005, 0, z); + + get_position (bp->rot2, &x, &y, &z, !bp->button_down_p); + + z += (bp->xscroll / 2.0); + x += (bp->yscroll / 2.0); + + glRotatef (maxx/2 - x*maxx, 1, 0, 0); + glRotatef (maxy/2 - y*maxy, 0, 1, 0); + glRotatef (maxz/2 - z*maxz, 0, 0, 1); + } +# endif /* DEBUG */ + + glPushMatrix(); + glScalef (GROUND_QUAD_SIZE, GROUND_QUAD_SIZE, 1); + + glTranslatef (0, bp->ground_y - 1.5, 0); + glCallList (bp->ground_dlist); + mi->polygon_count += bp->ground_polys; + + glTranslatef (0, 1, 0); + glCallList (bp->ground_dlist); + mi->polygon_count += bp->ground_polys; + glPopMatrix(); + + glMaterialfv (GL_FRONT, GL_SPECULAR, bspec); + glMateriali (GL_FRONT, GL_SHININESS, bshiny); + glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, bcolor); + + glPushMatrix(); + + if (grid_width & 1) /* Stay between towers */ + glTranslatef ((grid_spacing + 1) / 2.0, 0, 0); + + + if (!wire) + { + GLfloat fog_color[4] = { 0, 0, 0, 1 }; + glFogfv (GL_FOG_COLOR, fog_color); + /* I so don't understand how to choose the fog parameters. */ + glFogi (GL_FOG_MODE, GL_LINEAR); + glFogf (GL_FOG_START, 0); + glFogf (GL_FOG_END, 100); + glEnable (GL_FOG); + } + + /* Clear the floor under the tower bases */ + + { + GLfloat color0[4] = { 0, 0, 0, 1 }; + GLfloat z = 0.01; + + if (do_tex && !wire) glDisable (GL_TEXTURE_2D); + glColor4fv (color0); + glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color0); + glDisable (GL_BLEND); + glDisable (GL_DEPTH_TEST); + + for (i = 0; i < bp->ntowers; i++) + { + tower *t = &bp->towers[i]; + glPushMatrix(); + glTranslatef (t->x, t->y, 0); + + glNormal3f (0, 0, 1); + glBegin (wire ? GL_LINE_LOOP : GL_QUADS); /* clipping quad */ + glVertex3f (-0.5, -0.5, z); + glVertex3f ( 0.5, -0.5, z); + glVertex3f ( 0.5, 0.5, z); + glVertex3f (-0.5, 0.5, z); + glEnd(); + mi->polygon_count++; + glPopMatrix(); + } + } + + glEnable (GL_DEPTH_TEST); + + if (!wire) + { + if (do_tex) + { + glEnable (GL_TEXTURE_2D); + enable_texture_string_parameters(); + } + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE); + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + glDisable (GL_CULL_FACE); + if (bp->startup_p) + glEnable (GL_DEPTH_TEST); + else + glDisable (GL_DEPTH_TEST); + } + + /* Draw the towers */ + + for (i = 0; i < bp->ntowers; i++) + { + tower *t = &bp->towers[i]; + glPushMatrix(); + glTranslatef (t->x, t->y-1, -grid_height * ease_ratio (1 - t->h)); + + glCallList (bp->tower_dlist); + mi->polygon_count += bp->tower_polys; + + if (wire || do_tex) + { + int j; + for (j = 0; j < countof(t->fg_dlists); j++) + { + if (! (t->face_mode & (1 << j))) + { + glCallList (t->bg_dlists[j]); + mi->polygon_count += t->bg_polys; + } + else + { + glCallList (t->fg_dlists[j]); + mi->polygon_count += t->fg_polys; + } + } + } + glPopMatrix(); + } + + glPopMatrix(); + + mi->polygon_count += draw_billboard (mi); + glPopMatrix(); + + if (!bp->button_down_p) + animate_towers (mi); + + if (bp->startup_p && bp->towers[bp->ntowers-1].h >= 1) + bp->startup_p = False; + + if (mi->fps_p) do_fps (mi); + glFinish(); + + glXSwapBuffers(dpy, window); +} + + +ENTRYPOINT void +free_gibson (ModeInfo *mi) +{ + int i, j; + gibson_configuration *bp = &ccs[MI_SCREEN(mi)]; + if (!bp->glx_context) return; + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *bp->glx_context); + + if (bp->towers) free (bp->towers); + if (bp->rot) free_rotator (bp->rot); + if (bp->rot2) free_rotator (bp->rot2); + if (glIsList(bp->ground_dlist)) glDeleteLists(bp->ground_dlist, 1); + if (glIsList(bp->tower_dlist)) glDeleteLists(bp->tower_dlist, 1); + for (i = 0; i < countof(bp->text); i++) + { + if (bp->text[i].font_data) free_texture_font (bp->text[i].font_data); + if (bp->text[i].text) free (bp->text[i].text); + } + for (i = 0; i < bp->ntowers; i++) + { + for (j = 0; j < countof(bp->towers[i].fg_dlists); j++) + { + if (glIsList(bp->towers[i].fg_dlists[j])) + glDeleteLists(bp->towers[i].fg_dlists[j], 1); + if (glIsList(bp->towers[i].bg_dlists[j])) + glDeleteLists(bp->towers[i].bg_dlists[j], 1); + } + } +} + + +XSCREENSAVER_MODULE ("Gibson", gibson) +/* Greets to Crash Override, The Phantom Freak, and also Joey */ + +#endif /* USE_GL */ diff --git a/hacks/glx/gibson.man b/hacks/glx/gibson.man new file mode 100644 index 0000000..a57e018 --- /dev/null +++ b/hacks/glx/gibson.man @@ -0,0 +1,88 @@ +.TH XScreenSaver 1 "" "X Version 11" +.SH NAME +Hacking the Gibson - screen saver. +.SH SYNOPSIS +.B gibson +[\-display \fIhost:display.screen\fP] +[\-visual \fIvisual\fP] +[\-window] +[\-root] +[\-delay \fInumber\fP] +[\-speed \fInumber\fP] +[\-grid-width \fInumber\fP] +[\-grid-depth \fInumber\fP] +[\-grid-height \fInumber\fP] +[\-grid-spacing \fInumber\fP] +[\-columns \fInumber\fP] +[\-no-texture] +[\-wireframe] +[\-fps] +.SH DESCRIPTION +Hacking the Gibson, as per the 1995 classic film, \fIHACKERS\fP. + +"Hackers penetrate and ravage delicate public and privately owned +computer systems, infecting them with viruses, and stealing materials +for their own ends. These people, they are terrorists." +.SH OPTIONS +.TP 8 +.B \-visual \fIvisual\fP +Specify which visual to use. Legal values are the name of a visual class, +or the id number (decimal or hex) of a specific visual. +.TP 8 +.B \-window +Draw on a newly-created window. This is the default. +.TP 8 +.B \-root +Draw on the root window. +.TP 8 +.B \-delay \fInumber\fP +Per-frame delay, in microseconds. Default: 20000 (0.02 seconds). +.TP 8 +.B \-speed \fInumber\fP +Animation speed. 2.0 means twice as fast, 0.5 means half as fast. +.TP 8 +.B \-grid-width \fInumber\fP +Number of towers across. 1 - 20. Default: 10. +.TP 8 +.B \-grid-depth \fInumber\fP +Number of towers deep. 1 - 20. Default: 10. +.TP 8 +.B \-grid-height \fInumber\fP +Height of the towers. 1 - 20. Default: 7. +.TP 8 +.B \-grid-spacing \fInumber\fP +Space between towers. 1 - 5. Default: 2.0. +.TP 8 +.B \-columns \fInumber\fP +Columns of text on the towers. 1 - 20. Default: 6. +.TP 8 +.B \-texture | \-no-texture +Whether to draw text. Default true. +.TP 8 +.B \-wireframe | \-no-wireframe +Render in wireframe instead of solid. +.TP 8 +.B \-fps | \-no-fps +Whether to show a frames-per-second display at the bottom of the screen. +.SH ENVIRONMENT +.PP +.TP 8 +.B DISPLAY +to get the default host and display number. +.TP 8 +.B XENVIRONMENT +to get the name of a resource file that overrides the global resources +stored in the RESOURCE_MANAGER property. +.SH SEE ALSO +.BR X (1), +.BR xscreensaver (1) +.SH COPYRIGHT +Copyright \(co 2020 by Jamie Zawinski. Permission to use, copy, modify, +distribute, and sell this software and its documentation for any purpose is +hereby granted without fee, provided that the above copyright notice appear +in all copies and that both that copyright notice and this permission notice +appear in supporting documentation. No representations are made about the +suitability of this software for any purpose. It is provided "as is" without +express or implied warranty. +.SH AUTHOR +Jamie Zawinski. diff --git a/hacks/glx/glhanoi.c b/hacks/glx/glhanoi.c index 46cdc68..11ac75f 100644 --- a/hacks/glx/glhanoi.c +++ b/hacks/glx/glhanoi.c @@ -1424,13 +1424,14 @@ static GLubyte *makeTexture(glhcfg *glhanoi, int x_size, int y_size, int z_size, tex_col_t *), tex_col_t * colours) { int i, j, k; - GLubyte *textureData; + GLuint *textureData; GLuint *texturePtr; double x, y, z; double xi, yi, zi; + /* As we use GL_RGBA format, we must assign 4 bytes per element */ if((textureData = - calloc(x_size * y_size * z_size, sizeof(GLubyte))) == NULL) { + calloc(x_size * y_size * z_size, sizeof(*texturePtr))) == NULL) { return NULL; } @@ -1439,7 +1440,7 @@ static GLubyte *makeTexture(glhcfg *glhanoi, int x_size, int y_size, int z_size, zi = 1.0 / z_size; z = 0.0; - texturePtr = (void *)textureData; + texturePtr = textureData; for(k = 0; k < z_size; k++, z += zi) { y = 0.0; for(j = 0; j < y_size; j++, y += yi) { @@ -1450,7 +1451,7 @@ static GLubyte *makeTexture(glhcfg *glhanoi, int x_size, int y_size, int z_size, } } } - return textureData; + return (GLubyte *)textureData; } static void freeTexCols(tex_col_t*p) diff --git a/hacks/glx/glmatrix.c b/hacks/glx/glmatrix.c index 1e1c4f6..a638583 100644 --- a/hacks/glx/glmatrix.c +++ b/hacks/glx/glmatrix.c @@ -251,7 +251,7 @@ reset_strip (ModeInfo *mi, strip *s) if (do_clock && !time_displayed_p && (i < GRID_SIZE-5) && /* display approx. once per 5 strips */ - !(random() % (GRID_SIZE-5)*5)) + !(random() % ((GRID_SIZE-5)*5))) { int j; char text[80]; diff --git a/hacks/glx/gravitywell.c b/hacks/glx/gravitywell.c index 7078764..90edcf0 100644 --- a/hacks/glx/gravitywell.c +++ b/hacks/glx/gravitywell.c @@ -430,6 +430,8 @@ draw_row (ModeInfo *mi, int w, int y, Bool swap) polys += 1; ci = EASE (bp->vtx[vp + 2] / MAX_MASS_COLOR) * bp->ncolors; + if (ci < 0) ci = 0; + if (ci >= bp->ncolors) ci = bp->ncolors - 1; bp->col[cp] = bp->colors[ci].red / 65536.0; bp->col[cp+1] = bp->colors[ci].green / 65536.0; bp->col[cp+2] = bp->colors[ci].blue / 65536.0; @@ -452,6 +454,8 @@ draw_row (ModeInfo *mi, int w, int y, Bool swap) bp->vtx[vp + 2] = gridp[x * GRID_SEG + i]; ci = EASE (bp->vtx[vp + 2] / MAX_MASS_COLOR) * bp->ncolors; + if (ci < 0) ci = 0; + if (ci >= bp->ncolors) ci = bp->ncolors - 1; bp->col[cp] = bp->colors[ci].red / 65536.0; bp->col[cp+1] = bp->colors[ci].green / 65536.0; bp->col[cp+2] = bp->colors[ci].blue / 65536.0; @@ -689,6 +693,8 @@ draw_gw (ModeInfo *mi) GLfloat th, color[4]; int ci; ci = EASE (s->depth / MAX_MASS_COLOR) * bp->ncolors; + if (ci < 0) ci = 0; + if (ci >= bp->ncolors) ci = bp->ncolors - 1; color[0] = bp->colors[ci].red / 65536.0; color[1] = bp->colors[ci].green / 65536.0; color[2] = bp->colors[ci].blue / 65536.0; diff --git a/hacks/glx/hypertorus.c b/hacks/glx/hypertorus.c index 8aa8d4d..41f4e0a 100644 --- a/hacks/glx/hypertorus.c +++ b/hacks/glx/hypertorus.c @@ -1,10 +1,10 @@ /* hypertorus --- Shows a hypertorus that rotates in 4d */ #if 0 -static const char sccsid[] = "@(#)hypertorus.c 1.2 05/09/28 xlockmore"; +static const char sccsid[] = "@(#)hypertorus.c 1.2 28/09/05 xlockmore"; #endif -/* Copyright (c) 2003-2009 Carsten Steger <carsten@mirsanmir.org>. */ +/* Copyright (c) 2003-2020 Carsten Steger <carsten@mirsanmir.org>. */ /* * Permission to use, copy, modify, and distribute this software and its @@ -25,30 +25,44 @@ static const char sccsid[] = "@(#)hypertorus.c 1.2 05/09/28 xlockmore"; * and trackball support * C. Steger - 07/01/23: Improved 4d trackball support * C. Steger - 09/08/22: Removed check-config.pl warnings + * C. Steger - 11/01/20: Added the changing colors mode. */ /* - * This program shows the Clifford torus as it rotates in 4d. The Clifford - * torus is a torus lies on the "surface" of the hypersphere in 4d. The - * program projects the 4d torus to 3d using either a perspective or an - * orthographic projection. Of the two alternatives, the perspecitve - * projection looks much more appealing. In orthographic projections the - * torus degenerates into a doubly covered cylinder for some angles. The - * projected 3d torus can then be projected to the screen either perspectively - * or orthographically. There are three display modes for the torus: mesh - * (wireframe), solid, or transparent. Furthermore, the appearance of the - * torus can be as a solid object or as a set of see-through bands or - * see-through spirals. Finally, the colors with with the torus is drawn can - * be set to either two-sided or to colorwheel. In the first case, the torus - * is drawn with red on the outside and green on the inside. This mode - * enables you to see that the torus turns inside-out as it rotates in 4d. - * The second mode draws the torus in a fully saturated color wheel. This - * gives a very nice effect when combined with the see-through bands or - * see-through spirals mode. The rotation speed for each of the six planes - * around which the torus rotates can be chosen. This program is very much - * inspired by Thomas Banchoff's book "Beyond the Third Dimension: Geometry, - * Computer Graphics, and Higher Dimensions", Scientific American Library, - * 1990. + * This program shows the Clifford torus as it rotates in 4d. The + * Clifford torus is a torus lies on the "surface" of the hypersphere + * in 4d. The program projects the 4d torus to 3d using either a + * perspective or an orthographic projection. Of the two + * alternatives, the perspective projection looks much more appealing. + * In orthographic projections the torus degenerates into a doubly + * covered cylinder for some angles. The projected 3d torus can then + * be projected to the screen either perspectively or + * orthographically. + * + * There are three display modes for the torus: mesh (wireframe), + * solid, or transparent. Furthermore, the appearance of the torus + * can be as a solid object or as a set of see-through bands or + * see-through spirals. Finally, the colors with with the torus is + * drawn can be set to one-sided, two-sided, or to a color wheel. The + * colors can be static or changing dynamically. In one-sided color + * mode, the torus is drawn with the same color on the inside and the + * outside. In two-sided color mode, the torus is drawn with red on + * the outside and green on the inside if static colors are used. If + * changing colors are used, dynamically varying complementary colors + * are used for the two sides. This mode enables you to see that the + * 3d projection of the torus turns inside-out as it rotates in 4d. + * The color wheel mode draws the torus with a fully saturated color + * wheel. If changing colors are used, the colors of the color wheel + * are varying dynamically. The color wheel mode gives a very nice + * effect when combined with the see-through bands or see-through + * spirals mode. + * + * Finally, the rotation speed for each of the six planes around which + * the torus rotates can be chosen. + * + * This program is inspired by Thomas Banchoff's book "Beyond the + * Third Dimension: Geometry, Computer Graphics, and Higher + * Dimensions", Scientific American Library, 1990. */ #ifndef M_PI @@ -63,8 +77,9 @@ static const char sccsid[] = "@(#)hypertorus.c 1.2 05/09/28 xlockmore"; #define APPEARANCE_BANDS 1 #define APPEARANCE_SPIRALS 2 -#define COLORS_TWOSIDED 0 -#define COLORS_COLORWHEEL 1 +#define COLORS_ONESIDED 0 +#define COLORS_TWOSIDED 1 +#define COLORS_COLORWHEEL 2 #define DISP_3D_PERSPECTIVE 0 #define DISP_3D_ORTHOGRAPHIC 1 @@ -75,6 +90,7 @@ static const char sccsid[] = "@(#)hypertorus.c 1.2 05/09/28 xlockmore"; #define DEF_DISPLAY_MODE "surface" #define DEF_APPEARANCE "bands" #define DEF_COLORS "colorwheel" +#define DEF_CHANGE_COLORS "False" #define DEF_PROJECTION_3D "perspective" #define DEF_PROJECTION_4D "perspective" #define DEF_SPEEDWX "1.1" @@ -117,6 +133,7 @@ static int appearance; static int num_spirals; static char *color_mode; static int colors; +static Bool change_colors; static char *proj_3d; static int projection_3d; static char *proj_4d; @@ -146,8 +163,11 @@ static XrmOptionDescRec opts[] = {"-spirals-4", ".appearance", XrmoptionNoArg, "spirals-4" }, {"-spirals-8", ".appearance", XrmoptionNoArg, "spirals-8" }, {"-spirals-16", ".appearance", XrmoptionNoArg, "spirals-16" }, + {"-onesided", ".colors", XrmoptionNoArg, "onesided" }, {"-twosided", ".colors", XrmoptionNoArg, "twosided" }, {"-colorwheel", ".colors", XrmoptionNoArg, "colorwheel" }, + {"-change-colors", ".changeColors", XrmoptionNoArg, "on"}, + {"+change-colors", ".changeColors", XrmoptionNoArg, "off"}, {"-perspective-3d", ".projection3d", XrmoptionNoArg, "perspective" }, {"-orthographic-3d", ".projection3d", XrmoptionNoArg, "orthographic" }, {"-perspective-4d", ".projection4d", XrmoptionNoArg, "perspective" }, @@ -162,43 +182,28 @@ static XrmOptionDescRec opts[] = static argtype vars[] = { - { &mode, "displayMode", "DisplayMode", DEF_DISPLAY_MODE, t_String }, - { &appear, "appearance", "Appearance", DEF_APPEARANCE, t_String }, - { &color_mode, "colors", "Colors", DEF_COLORS, t_String }, - { &proj_3d, "projection3d", "Projection3d", DEF_PROJECTION_3D, t_String }, - { &proj_4d, "projection4d", "Projection4d", DEF_PROJECTION_4D, t_String }, - { &speed_wx, "speedwx", "Speedwx", DEF_SPEEDWX, t_Float}, - { &speed_wy, "speedwy", "Speedwy", DEF_SPEEDWY, t_Float}, - { &speed_wz, "speedwz", "Speedwz", DEF_SPEEDWZ, t_Float}, - { &speed_xy, "speedxy", "Speedxy", DEF_SPEEDXY, t_Float}, - { &speed_xz, "speedxz", "Speedxz", DEF_SPEEDXZ, t_Float}, - { &speed_yz, "speedyz", "Speedyz", DEF_SPEEDYZ, t_Float} -}; - -static OptionStruct desc[] = -{ - { "-wireframe", "display the torus as a wireframe mesh" }, - { "-surface", "display the torus as a solid surface" }, - { "-transparent", "display the torus as a transparent surface" }, - { "-solid", "display the torus as a solid object" }, - { "-bands", "display the torus as see-through bands" }, - { "-spirals-{1,2,4,8,16}", "display the torus as see-through spirals" }, - { "-twosided", "display the torus with two colors" }, - { "-colorwheel", "display the torus with a smooth color wheel" }, - { "-perspective-3d", "project the torus perspectively from 3d to 2d" }, - { "-orthographic-3d", "project the torus orthographically from 3d to 2d" }, - { "-perspective-4d", "project the torus perspectively from 4d to 3d" }, - { "-orthographic-4d", "project the torus orthographically from 4d to 3d" }, - { "-speed-wx <arg>", "rotation speed around the wx plane" }, - { "-speed-wy <arg>", "rotation speed around the wy plane" }, - { "-speed-wz <arg>", "rotation speed around the wz plane" }, - { "-speed-xy <arg>", "rotation speed around the xy plane" }, - { "-speed-xz <arg>", "rotation speed around the xz plane" }, - { "-speed-yz <arg>", "rotation speed around the yz plane" } + { &mode, "displayMode", "DisplayMode", DEF_DISPLAY_MODE, t_String }, + { &appear, "appearance", "Appearance", DEF_APPEARANCE, t_String }, + { &color_mode, "colors", "Colors", DEF_COLORS, t_String }, + { &change_colors, "changeColors", "ChangeColors", DEF_CHANGE_COLORS, t_Bool }, + { &proj_3d, "projection3d", "Projection3d", DEF_PROJECTION_3D, t_String }, + { &proj_4d, "projection4d", "Projection4d", DEF_PROJECTION_4D, t_String }, + { &speed_wx, "speedwx", "Speedwx", DEF_SPEEDWX, t_Float}, + { &speed_wy, "speedwy", "Speedwy", DEF_SPEEDWY, t_Float}, + { &speed_wz, "speedwz", "Speedwz", DEF_SPEEDWZ, t_Float}, + { &speed_xy, "speedxy", "Speedxy", DEF_SPEEDXY, t_Float}, + { &speed_xz, "speedxz", "Speedxz", DEF_SPEEDXZ, t_Float}, + { &speed_yz, "speedyz", "Speedyz", DEF_SPEEDYZ, t_Float} }; ENTRYPOINT ModeSpecOpt hypertorus_opts = -{sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc}; +{sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, NULL}; + + +/* Color change speeds */ +#define DRHO 0.7 +#define DSIGMA 1.1 +#define DTAU 1.7 typedef struct { @@ -206,15 +211,15 @@ typedef struct { GLXContext *glx_context; /* 4D rotation angles */ float alpha, beta, delta, zeta, eta, theta; + /* Color rotation angles */ + float rho, sigma, tau; /* Aspect ratio of the current window */ float aspect; /* Trackball states */ trackball_state *trackballs[2]; int current_trackball; Bool button_pressed; - float speed_scale; - } hypertorusstruct; static hypertorusstruct *hyper = (hypertorusstruct *) NULL; @@ -352,6 +357,77 @@ static void rotateall(float al, float be, float de, float ze, float et, } +/* Add a rotation around the x-axis to the matrix m. */ +static void rotatex(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][1]; + v = m[i][2]; + m[i][1] = c*u+s*v; + m[i][2] = -s*u+c*v; + } +} + + +/* Add a rotation around the y-axis to the matrix m. */ +static void rotatey(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][0]; + v = m[i][2]; + m[i][0] = c*u-s*v; + m[i][2] = s*u+c*v; + } +} + + +/* Add a rotation around the z-axis to the matrix m. */ +static void rotatez(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][0]; + v = m[i][1]; + m[i][0] = c*u+s*v; + m[i][1] = -s*u+c*v; + } +} + + +/* Compute the 3d rotation matrix m from the 3d rotation angles. */ +static void rotateall3d(float al, float be, float de, float m[3][3]) +{ + int i, j; + + for (i=0; i<3; i++) + for (j=0; j<3; j++) + m[i][j] = (i==j); + rotatex(m,al); + rotatey(m,be); + rotatez(m,de); +} + + /* Multiply two rotation matrices: o=m*n. */ static void mult_rotmat(float m[4][4], float n[4][4], float o[4][4]) { @@ -400,62 +476,84 @@ static void quats_to_rotmat(float p[4], float q[4], float m[4][4]) /* Compute a fully saturated and bright color based on an angle. */ -static void color(double angle) +static void color(double angle, float mat[3][3], float col[4]) { int s; - double t; - float color[4]; + double t, ca, sa; + float m; - if (colors != COLORS_COLORWHEEL) - return; + if (!change_colors) + { + if (colors == COLORS_ONESIDED || colors == COLORS_TWOSIDED) + return; - if (angle >= 0.0) - angle = fmod(angle,2*M_PI); - else - angle = fmod(angle,-2*M_PI); - s = floor(angle/(M_PI/3)); - t = angle/(M_PI/3)-s; - if (s >= 6) - s = 0; - switch (s) + if (angle >= 0.0) + angle = fmod(angle,2*M_PI); + else + angle = fmod(angle,-2*M_PI); + s = floor(angle/(M_PI/3)); + t = angle/(M_PI/3)-s; + if (s >= 6) + s = 0; + switch (s) + { + case 0: + col[0] = 1.0; + col[1] = t; + col[2] = 0.0; + break; + case 1: + col[0] = 1.0-t; + col[1] = 1.0; + col[2] = 0.0; + break; + case 2: + col[0] = 0.0; + col[1] = 1.0; + col[2] = t; + break; + case 3: + col[0] = 0.0; + col[1] = 1.0-t; + col[2] = 1.0; + break; + case 4: + col[0] = t; + col[1] = 0.0; + col[2] = 1.0; + break; + case 5: + col[0] = 1.0; + col[1] = 0.0; + col[2] = 1.0-t; + break; + } + } + else /* change_colors */ { - case 0: - color[0] = 1.0; - color[1] = t; - color[2] = 0.0; - break; - case 1: - color[0] = 1.0-t; - color[1] = 1.0; - color[2] = 0.0; - break; - case 2: - color[0] = 0.0; - color[1] = 1.0; - color[2] = t; - break; - case 3: - color[0] = 0.0; - color[1] = 1.0-t; - color[2] = 1.0; - break; - case 4: - color[0] = t; - color[1] = 0.0; - color[2] = 1.0; - break; - case 5: - color[0] = 1.0; - color[1] = 0.0; - color[2] = 1.0-t; - break; + if (colors == COLORS_ONESIDED || colors == COLORS_TWOSIDED) + { + col[0] = mat[0][2]; + col[1] = mat[1][2]; + col[2] = mat[2][2]; + } + else + { + ca = cos(angle); + sa = sin(angle); + col[0] = ca*mat[0][0]+sa*mat[0][1]; + col[1] = ca*mat[1][0]+sa*mat[1][1]; + col[2] = ca*mat[2][0]+sa*mat[2][1]; + } + m = 0.5f/fmaxf(fmaxf(fabsf(col[0]),fabsf(col[1])),fabsf(col[2])); + col[0] = m*col[0]+0.5f; + col[1] = m*col[1]+0.5f; + col[2] = m*col[2]+0.5f; } if (display_mode == DISP_TRANSPARENT) - color[3] = 0.7; + col[3] = 0.7; else - color[3] = 1.0; - glColor3fv(color); - glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,color); + col[3] = 1.0; } @@ -464,14 +562,17 @@ static void color(double angle) power of 2. Similarly, the banded appearance will only work correctly if numu and numv are divisible by 4. */ static int hypertorus(ModeInfo *mi, double umin, double umax, double vmin, - double vmax, int numu, int numv) + double vmax, int numu, int numv) { int polys = 0; - static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; - static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; - static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; - static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; - float p[3], pu[3], pv[3], n[3], mat[4][4]; + static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; + static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; + static const GLfloat mat_diff_oneside[] = { 0.9, 0.4, 0.3, 1.0 }; + static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_oneside[] = { 0.9, 0.4, 0.3, 0.7 }; + float mat_diff_dyn[4], mat_diff_dyn_compl[4]; + float p[3], pu[3], pv[3], n[3], mat[4][4], matc[3][3], col[4]; int i, j, k, l, m, b, skew; double u, v, ur, vr; double cu, su, cv, sv; @@ -480,6 +581,9 @@ static int hypertorus(ModeInfo *mi, double umin, double umax, double vmin, float q1[4], q2[4], r1[4][4], r2[4][4]; hypertorusstruct *hp = &hyper[MI_SCREEN(mi)]; + if (change_colors) + rotateall3d(hp->rho,hp->sigma,hp->tau,matc); + rotateall(hp->alpha,hp->beta,hp->delta,hp->zeta,hp->eta,hp->theta,r1); gltrackball_get_quaternion(hp->trackballs[0],q1); @@ -488,31 +592,56 @@ static int hypertorus(ModeInfo *mi, double umin, double umax, double vmin, mult_rotmat(r2,r1,mat); - if (colors != COLORS_COLORWHEEL) + if (!change_colors) { - glColor3fv(mat_diff_red); - if (display_mode == DISP_TRANSPARENT) + if (colors == COLORS_ONESIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + glColor3fv(mat_diff_oneside); + if (display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_trans_oneside); + } + else + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_oneside); + } } - else + else if (colors == COLORS_TWOSIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + glColor3fv(mat_diff_red); + if (display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + } + else + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + } } } - -#if 0 /* #### not working */ -# ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ + else /* change_colors */ { - GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi); - int o = (int) current_device_rotation(); - if (o != 0 && o != 180 && o != -180) - glScalef (1/h, 1/h, 1/h); + color(0.0,matc,mat_diff_dyn); + if (colors == COLORS_ONESIDED) + { + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + } + else if (colors == COLORS_TWOSIDED) + { + mat_diff_dyn_compl[0] = 1.0f-mat_diff_dyn[0]; + mat_diff_dyn_compl[1] = 1.0f-mat_diff_dyn[1]; + mat_diff_dyn_compl[2] = 1.0f-mat_diff_dyn[2]; + mat_diff_dyn_compl[3] = mat_diff_dyn[3]; + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn_compl); + } } -# endif -#endif skew = num_spirals; ur = umax-umin; @@ -538,11 +667,16 @@ static int hypertorus(ModeInfo *mi, double umin, double umax, double vmin, { u += 4.0*skew/numv*v; b = ((i/4)&(skew-1))*(numu/(4*skew)); - color(ur*4*b/numu+umin); + color(ur*4*b/numu+umin,matc,col); } else { - color(u); + color(u,matc,col); + } + if (colors == COLORS_COLORWHEEL) + { + glColor3fv(col); + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,col); } cu = cos(u); su = sin(u); @@ -631,6 +765,10 @@ static void init(ModeInfo *mi) hp->eta = 0.0; hp->theta = 0.0; + hp->rho = frand(360.0); + hp->sigma = frand(360.0); + hp->tau = frand(360.0); + glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (projection_3d == DISP_3D_PERSPECTIVE) @@ -718,6 +856,19 @@ static void display_hypertorus(ModeInfo *mi) hp->theta += speed_yz * hp->speed_scale; if (hp->theta >= 360.0) hp->theta -= 360.0; + + if (change_colors) + { + hp->rho += DRHO; + if (hp->rho >= 360.0) + hp->rho -= 360.0; + hp->sigma += DSIGMA; + if (hp->sigma >= 360.0) + hp->sigma -= 360.0; + hp->tau += DTAU; + if (hp->tau >= 360.0) + hp->tau -= 360.0; + } } glMatrixMode(GL_PROJECTION); @@ -736,10 +887,6 @@ static void display_hypertorus(ModeInfo *mi) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - /* Let's keep a constant aspect ratio rather than stretching with the - shape of the window */ - glScalef (hp->WindH / (GLfloat) hp->WindW, 1, 1); - mi->polygon_count = hypertorus(mi,0.0,2.0*M_PI,0.0,2.0*M_PI,64,64); } @@ -747,19 +894,11 @@ static void display_hypertorus(ModeInfo *mi) ENTRYPOINT void reshape_hypertorus(ModeInfo *mi, int width, int height) { hypertorusstruct *hp = &hyper[MI_SCREEN(mi)]; - double h = (GLfloat) height / (GLfloat) width; - int y = 0; - - if (width > height * 5) { /* tiny window: show middle */ - height = width * 9/16; - y = -height/2; - h = height / (GLfloat) width; - } hp->WindW = (GLint)width; hp->WindH = (GLint)height; - glViewport(0,y,width,height); - hp->aspect = h; + glViewport(0,0,width,height); + hp->aspect = (GLfloat)width/(GLfloat)height; } @@ -910,7 +1049,11 @@ ENTRYPOINT void init_hypertorus(ModeInfo *mi) } /* Set the color mode. */ - if (!strcasecmp(color_mode,"twosided")) + if (!strcasecmp(color_mode,"onesided")) + { + colors = COLORS_ONESIDED; + } + else if (!strcasecmp(color_mode,"twosided")) { colors = COLORS_TWOSIDED; } diff --git a/hacks/glx/hypertorus.man b/hacks/glx/hypertorus.man index 8c7075f..8f0837e 100644 --- a/hacks/glx/hypertorus.man +++ b/hacks/glx/hypertorus.man @@ -16,8 +16,10 @@ hypertorus - Draws a hypertorus that rotates in 4d [\-solid] [\-bands] [\-spirals-{1,2,4,8,16}] +[\-onesided] [\-twosided] [\-colorwheel] +[\-change-colors] [\-perspective-3d] [\-orthographic-3d] [\-perspective-4d] @@ -37,18 +39,28 @@ alternatives, the perspective projection looks much more appealing. In orthographic projections the torus degenerates into a doubly covered cylinder for some angles. The projected 3d torus can then be projected to the screen either perspectively or orthographically. +.PP There are three display modes for the torus: mesh (wireframe), solid, or transparent. Furthermore, the appearance of the torus can be as a solid object or as a set of see-through bands or see-through spirals. -Finally, the colors with with the torus is drawn can be set to either -two-sided or to a color wheel. In the first case, the torus is drawn -with red on the outside and green on the inside. This mode enables -you to see that the torus turns inside-out as it rotates in 4d. The -second mode draws the torus with a fully saturated color wheel. This -gives a very nice effect when combined with the see-through bands or -see-through spirals mode. The rotation speed for each of the six -planes around which the torus rotates can be chosen. This program is -very much inspired by Thomas Banchoff's book "Beyond the Third +Finally, the colors with with the torus is drawn can be set to +one-sided, two-sided, or to a color wheel. The colors can be static +or changing dynamically. In one-sided color mode, the torus is drawn +with the same color on the inside and the outside. In two-sided color +mode, the torus is drawn with red on the outside and green on the +inside if static colors are used. If changing colors are used, +dynamically varying complementary colors are used for the two sides. +This mode enables you to see that the 3d projection of the torus turns +inside-out as it rotates in 4d. The color wheel mode draws the torus +with a fully saturated color wheel. If changing colors are used, the +colors of the color wheel are varying dynamically. The color wheel +mode gives a very nice effect when combined with the see-through bands +or see-through spirals mode. +.PP +Finally, the rotation speed for each of the six planes around which +the torus rotates can be chosen. +.PP +This program is inspired by Thomas Banchoff's book "Beyond the Third Dimension: Geometry, Computer Graphics, and Higher Dimensions", Scientific American Library, 1990. .SH OPTIONS @@ -97,18 +109,31 @@ Display the torus as see-through bands (default). Display the torus as see-through spirals with the indicated number of spirals. .PP -The following two options are mutually exclusive. They determine how -to color the torus. +The following three options are mutually exclusive. They determine +how to color the torus. +.TP 8 +.B \-onesided +Display the torus with a single color. .TP 8 .B \-twosided -Display the torus with two colors: red on the outside and green on -the inside. +Display the torus with two colors: one color on the outside and the +complementary on the inside. For static colors, the colors are red +and green. .TP 8 .B \-colorwheel Display the torus with a fully saturated color wheel (default). If -the torus is displayed as see-through bands each band will be +the torus is displayed as see-through bands, each band will be displayed with a different color. Likewise, if the torus is displayed -as see-through spirals each spiral will receive a different color. +as see-through spirals, each spiral will receive a different color. +.PP +The following options determine whether the colors with which the +torus is displayed are static or are changing dynamically. +.TP 8 +.B \-change-colors +Change the colors with which the torus is displayed dynamically. +.TP 8 +.B \-no-change-colors +Use static colors to display the torus (default). .PP The following two options are mutually exclusive. They determine how the torus is projected from 3d to 2d (i.e., to the screen). @@ -158,9 +183,9 @@ Display the current frame rate, CPU load, and polygon count. .SH INTERACTION If you run this program in standalone mode you can rotate the hypertorus by dragging the mouse while pressing the left mouse button. -This rotates the hypertorus in 3D, i.e., around the wx, wy, and wz +This rotates the hypertorus in 3d, i.e., around the wx, wy, and wz planes. If you press the shift key while dragging the mouse with the -left button pressed the hypertorus is rotated in 4D, i.e., around the +left button pressed the hypertorus is rotated in 4d, i.e., around the xy, xz, and yz planes. To examine the hypertorus at your leisure, it is best to set all speeds to 0. Otherwise, the hypertorus will rotate while the left mouse button is not pressed. @@ -177,12 +202,13 @@ stored in the RESOURCE_MANAGER property. .BR X (1), .BR xscreensaver (1) .SH COPYRIGHT -Copyright \(co 2003-2005 by Carsten Steger. Permission to use, copy, modify, -distribute, and sell this software and its documentation for any purpose is -hereby granted without fee, provided that the above copyright notice appear -in all copies and that both that copyright notice and this permission notice -appear in supporting documentation. No representations are made about the -suitability of this software for any purpose. It is provided "as is" without -express or implied warranty. +Copyright \(co 2003-2020 by Carsten Steger. Permission to use, copy, +modify, distribute, and sell this software and its documentation for +any purpose is hereby granted without fee, provided that the above +copyright notice appear in all copies and that both that copyright +notice and this permission notice appear in supporting documentation. +No representations are made about the suitability of this software for +any purpose. It is provided "as is" without express or implied +warranty. .SH AUTHOR -Carsten Steger <carsten@mirsanmir.org>, 28-sep-2005. +Carsten Steger <carsten@mirsanmir.org>, 11-jan-2020. diff --git a/hacks/glx/klein.c b/hacks/glx/klein.c index 0fac5d2..7be5157 100644 --- a/hacks/glx/klein.c +++ b/hacks/glx/klein.c @@ -2,10 +2,10 @@ can walk */ #if 0 -static const char sccsid[] = "@(#)klein.c 1.1 08/10/04 xlockmore"; +static const char sccsid[] = "@(#)klein.c 1.1 04/10/08 xlockmore"; #endif -/* Copyright (c) 2005-2014 Carsten Steger <carsten@mirsanmir.org>. */ +/* Copyright (c) 2005-2020 Carsten Steger <carsten@mirsanmir.org>. */ /* * Permission to use, copy, modify, and distribute this software and its @@ -21,61 +21,83 @@ static const char sccsid[] = "@(#)klein.c 1.1 08/10/04 xlockmore"; * other special, indirect and consequential damages. * * REVISION HISTORY: - * C. Steger - 08/10/04: Initial version - * C. Steger - 09/08/03: Changes to the parameter handling - * C. Steger - 13/12/25: Added the squeezed torus Klein bottle - * C. Steger - 14/10/03: Moved the curlicue texture to curlicue.h + * C. Steger - 04/10/08: Initial version + * C. Steger - 03/08/09: Changes to the parameter handling + * C. Steger - 25/12/13: Added the squeezed torus Klein bottle + * C. Steger - 03/10/14: Moved the curlicue texture to curlicue.h + * C. Steger - 11/01/20: Added the changing colors mode. */ /* - * This program shows three different Klein bottles in 4d: the figure-8 Klein - * bottle, the squeezed torus Klein bottle, or the Lawson Klein bottle. You - * can walk on the Klein bottle, see it turn in 4d, or walk on it while it - * turns in 4d. The figure-8 Klein bottle is well known in its 3d form. The - * 4d form used in this program is an extension of the 3d form to 4d that - * does not intersect itself in 4d (which can be seen in the depth colors - * mode). The squeezed torus Klein bottle also does not intersect itself in - * 4d (which can be seen in the depth colors mode). The Lawson Klein bottle, - * on the other hand, does intersect itself in 4d. Its primary use is that - * it has a nice appearance for walking and for turning in 3d. The Klein - * bottle is a non-orientable surface. To make this apparent, the two-sided - * color mode can be used. Alternatively, orientation markers (curling - * arrows) can be drawn as a texture map on the surface of the Klein bottle. - * While walking on the Klein bottle, you will notice that the orientation - * of the curling arrows changes (which it must because the Klein bottle is - * non-orientable). The program projects the 4d Klein bottle to 3d using - * either a perspective or an orthographic projection. Which of the two - * alternatives looks more appealing depends on the viewing mode and the - * Klein bottle. For example, the Lawson Klein bottle looks nicest when - * projected perspectively. The figure-8 Klein bottle, on the other - * hand, looks nicer while walking when projected orthographically from 4d. - * For the squeezed torus Klein bottle, both projection modes give equally - * acceptable projections. The projected Klein bottle can then be projected - * to the screen either perspectively or orthographically. When using the - * walking modes, perspective projection to the screen should be used. There - * are three display modes for the Klein bottle: mesh (wireframe), solid, or - * transparent. Furthermore, the appearance of the Klein bottle can be as - * a solid object or as a set of see-through bands. Finally, the colors - * with with the Klein bottle is drawn can be set to two-sided, rainbow, or - * depth. In the first case, the Klein bottle is drawn with red on one - * "side" and green on the "other side". Of course, the Klein bottle only - * has one side, so the color jumps from red to green along a curve on the - * surface of the Klein bottle. This mode enables you to see that the Klein - * bottle is non-orientable. The second mode draws the Klein bottle with - * fully saturated rainbow colors. This gives a very nice effect when - * combined with the see-through bands mode or with the orientation markers - * drawn. The third mode draws the Klein bottle with colors that are chosen - * according to the 4d "depth" of the points. This mode enables you to see - * that the figure-8 and squeezed torus Klein bottles do not intersect - * themselves in 4d, while the Lawson Klein bottle does intersect itself. - * The rotation speed for each of the six planes around which the Klein - * bottle rotates can be chosen. For the walk-and-turn more, only the - * rotation speeds around the true 4d planes are used (the xy, xz, and yz - * planes). Furthermore, in the walking modes the walking direction in the - * 2d base square of the Klein bottle and the walking speed can be chosen. - * This program is somewhat inspired by Thomas Banchoff's book "Beyond the - * Third Dimension: Geometry, Computer Graphics, and Higher Dimensions", - * Scientific American Library, 1990. + * This program shows three different Klein bottles in 4d: the + * figure-8 Klein bottle, the pinched torus Klein bottle, or the + * Lawson Klein bottle. You can walk on the Klein bottle, see it turn + * in 4d, or walk on it while it turns in 4d. The figure-8 Klein + * bottle is well known in its 3d form. The 4d form used in this + * program is an extension of the 3d form to 4d that does not + * intersect itself in 4d (which can be seen in the depth colors mode + * when using static colors). The pinched torus Klein bottle also + * does not intersect itself in 4d (which can be seen in the depth + * colors mode when using static colors). The Lawson Klein bottle, on + * the other hand, does intersect itself in 4d. Its primary use is + * that it has a nice appearance for walking and for turning in 3d. + * + * The Klein bottle is a non-orientable surface. To make this + * apparent, the two-sided color mode can be used. Alternatively, + * orientation markers (curling arrows) can be drawn as a texture map + * on the surface of the Klein bottle. While walking on the Klein + * bottle, you will notice that the orientation of the curling arrows + * changes (which it must because the Klein bottle is non-orientable). + * + * The program projects the 4d Klein bottle to 3d using either a + * perspective or an orthographic projection. Which of the two + * alternatives looks more appealing depends on the viewing mode and + * the Klein bottle. For example, the Lawson Klein bottle looks + * nicest when projected perspectively. The figure-8 Klein bottle, on + * the other hand, looks nicer while walking when projected + * orthographically from 4d. For the pinched torus Klein bottle, both + * projection modes give equally acceptable projections. + * + * The projected Klein bottle can then be projected to the screen + * either perspectively or orthographically. When using the walking + * modes, perspective projection to the screen should be used. + * + * There are three display modes for the Klein bottle: mesh + * (wireframe), solid, or transparent. Furthermore, the appearance of + * the Klein bottle can be as a solid object or as a set of + * see-through bands. Finally, the colors with with the Klein bottle + * is drawn can be set to one-sided, two-sided, rainbow, or depth. In + * one-sided mode, the Klein bottle is drawn with the same color on + * both "sides." In two-sided mode (using static colors), the Klein + * bottle is drawn with red on one "side" and green on the "other + * side." Of course, the Klein bottle only has one side, so the color + * jumps from red to green along a curve on the surface of the Klein + * bottle. This mode enables you to see that the Klein bottle is + * non-orientable. If changing colors are used in two-sided mode, + * changing complementary colors are used on the respective "sides." + * The rainbow color mode (using static colors) draws the Klein bottle + * with a color wheel of fully saturated rainbow colors. If changing + * colors are used, the color wheel's colors change dynamically. The + * rainbow color mode gives a very nice effect when combined with the + * see-through bands mode or with the orientation markers drawn. The + * depth color mode draws the Klein bottle with colors that are chosen + * according to the 4d "depth" of the points. If static colors are + * used, this mode enables you to see that the figure-8 and pinched + * torus Klein bottles do not intersect themselves in 4d, while the + * Lawson Klein bottle does intersect itself. + * + * The rotation speed for each of the six planes around which the + * Klein bottle rotates can be chosen. For the walk-and-turn mode, + * only the rotation speeds around the true 4d planes are used (the + * xy, xz, and yz planes). + * + * Furthermore, in the walking modes the walking direction in the 2d + * base square of the Klein bottle and the walking speed can be + * chosen. + * + * This program is somewhat inspired by Thomas Banchoff's book "Beyond + * the Third Dimension: Geometry, Computer Graphics, and Higher + * Dimensions", Scientific American Library, 1990. */ #include "curlicue.h" @@ -84,54 +106,56 @@ static const char sccsid[] = "@(#)klein.c 1.1 08/10/04 xlockmore"; #define M_PI 3.14159265358979323846 #endif -#define KLEIN_BOTTLE_FIGURE_8 0 -#define KLEIN_BOTTLE_SQUEEZED_TORUS 1 -#define KLEIN_BOTTLE_LAWSON 2 -#define NUM_KLEIN_BOTTLES 3 - -#define DISP_WIREFRAME 0 -#define DISP_SURFACE 1 -#define DISP_TRANSPARENT 2 -#define NUM_DISPLAY_MODES 3 - -#define APPEARANCE_SOLID 0 -#define APPEARANCE_BANDS 1 -#define NUM_APPEARANCES 2 - -#define COLORS_TWOSIDED 0 -#define COLORS_RAINBOW 1 -#define COLORS_DEPTH 2 -#define NUM_COLORS 3 - -#define VIEW_WALK 0 -#define VIEW_TURN 1 -#define VIEW_WALKTURN 2 -#define NUM_VIEW_MODES 3 - -#define DISP_3D_PERSPECTIVE 0 -#define DISP_3D_ORTHOGRAPHIC 1 -#define NUM_DISP_3D_MODES 2 - -#define DISP_4D_PERSPECTIVE 0 -#define DISP_4D_ORTHOGRAPHIC 1 -#define NUM_DISP_4D_MODES 2 - -#define DEF_KLEIN_BOTTLE "random" -#define DEF_DISPLAY_MODE "random" -#define DEF_APPEARANCE "random" -#define DEF_COLORS "random" -#define DEF_VIEW_MODE "random" -#define DEF_MARKS "False" -#define DEF_PROJECTION_3D "random" -#define DEF_PROJECTION_4D "random" -#define DEF_SPEEDWX "1.1" -#define DEF_SPEEDWY "1.3" -#define DEF_SPEEDWZ "1.5" -#define DEF_SPEEDXY "1.7" -#define DEF_SPEEDXZ "1.9" -#define DEF_SPEEDYZ "2.1" -#define DEF_WALK_DIRECTION "7.0" -#define DEF_WALK_SPEED "20.0" +#define KLEIN_BOTTLE_FIGURE_8 0 +#define KLEIN_BOTTLE_PINCHED_TORUS 1 +#define KLEIN_BOTTLE_LAWSON 2 +#define NUM_KLEIN_BOTTLES 3 + +#define DISP_WIREFRAME 0 +#define DISP_SURFACE 1 +#define DISP_TRANSPARENT 2 +#define NUM_DISPLAY_MODES 3 + +#define APPEARANCE_SOLID 0 +#define APPEARANCE_BANDS 1 +#define NUM_APPEARANCES 2 + +#define COLORS_ONESIDED 0 +#define COLORS_TWOSIDED 1 +#define COLORS_RAINBOW 2 +#define COLORS_DEPTH 3 +#define NUM_COLORS 4 + +#define VIEW_WALK 0 +#define VIEW_TURN 1 +#define VIEW_WALKTURN 2 +#define NUM_VIEW_MODES 3 + +#define DISP_3D_PERSPECTIVE 0 +#define DISP_3D_ORTHOGRAPHIC 1 +#define NUM_DISP_3D_MODES 2 + +#define DISP_4D_PERSPECTIVE 0 +#define DISP_4D_ORTHOGRAPHIC 1 +#define NUM_DISP_4D_MODES 2 + +#define DEF_KLEIN_BOTTLE "random" +#define DEF_DISPLAY_MODE "random" +#define DEF_APPEARANCE "random" +#define DEF_COLORS "random" +#define DEF_VIEW_MODE "random" +#define DEF_MARKS "False" +#define DEF_CHANGE_COLORS "False" +#define DEF_PROJECTION_3D "random" +#define DEF_PROJECTION_4D "random" +#define DEF_SPEEDWX "1.1" +#define DEF_SPEEDWY "1.3" +#define DEF_SPEEDWZ "1.5" +#define DEF_SPEEDXY "1.7" +#define DEF_SPEEDXZ "1.9" +#define DEF_SPEEDYZ "2.1" +#define DEF_WALK_DIRECTION "7.0" +#define DEF_WALK_SPEED "20.0" #ifdef STANDALONE # define DEFAULTS "*delay: 10000 \n" \ @@ -168,6 +192,7 @@ static char *appear; static char *color_mode; static char *view_mode; static Bool marks; +static Bool change_colors; static char *proj_3d; static char *proj_4d; static float speed_wx; @@ -184,7 +209,7 @@ static XrmOptionDescRec opts[] = { {"-klein-bottle", ".kleinBottle", XrmoptionSepArg, 0 }, {"-figure-8", ".kleinBottle", XrmoptionNoArg, "figure-8" }, - {"-squeezed-torus", ".kleinBottle", XrmoptionNoArg, "squeezed-torus" }, + {"-pinched-torus", ".kleinBottle", XrmoptionNoArg, "pinched-torus" }, {"-lawson", ".kleinBottle", XrmoptionNoArg, "lawson" }, {"-mode", ".displayMode", XrmoptionSepArg, 0 }, {"-wireframe", ".displayMode", XrmoptionNoArg, "wireframe" }, @@ -194,15 +219,18 @@ static XrmOptionDescRec opts[] = {"-solid", ".appearance", XrmoptionNoArg, "solid" }, {"-bands", ".appearance", XrmoptionNoArg, "bands" }, {"-colors", ".colors", XrmoptionSepArg, 0 }, + {"-onesided", ".colors", XrmoptionNoArg, "one-sided" }, {"-twosided", ".colors", XrmoptionNoArg, "two-sided" }, {"-rainbow", ".colors", XrmoptionNoArg, "rainbow" }, {"-depth", ".colors", XrmoptionNoArg, "depth" }, + {"-change-colors", ".changeColors", XrmoptionNoArg, "on"}, + {"+change-colors", ".changeColors", XrmoptionNoArg, "off"}, {"-view-mode", ".viewMode", XrmoptionSepArg, 0 }, {"-walk", ".viewMode", XrmoptionNoArg, "walk" }, {"-turn", ".viewMode", XrmoptionNoArg, "turn" }, {"-walk-turn", ".viewMode", XrmoptionNoArg, "walk-turn" }, - {"-orientation-marks", ".marks", XrmoptionNoArg, "on"}, - {"+orientation-marks", ".marks", XrmoptionNoArg, "off"}, + {"-orientation-marks", ".marks", XrmoptionNoArg, "on"}, + {"+orientation-marks", ".marks", XrmoptionNoArg, "off"}, {"-projection-3d", ".projection3d", XrmoptionSepArg, 0 }, {"-perspective-3d", ".projection3d", XrmoptionNoArg, "perspective" }, {"-orthographic-3d", ".projection3d", XrmoptionNoArg, "orthographic" }, @@ -225,6 +253,7 @@ static argtype vars[] = { &mode, "displayMode", "DisplayMode", DEF_DISPLAY_MODE, t_String }, { &appear, "appearance", "Appearance", DEF_APPEARANCE, t_String }, { &color_mode, "colors", "Colors", DEF_COLORS, t_String }, + { &change_colors, "changeColors", "ChangeColors", DEF_CHANGE_COLORS, t_Bool }, { &view_mode, "viewMode", "ViewMode", DEF_VIEW_MODE, t_String }, { &marks, "marks", "Marks", DEF_MARKS, t_Bool }, { &proj_3d, "projection3d", "Projection3d", DEF_PROJECTION_3D, t_String }, @@ -246,12 +275,17 @@ ENTRYPOINT ModeSpecOpt klein_opts = /* Radius of the figure-8 Klein bottle */ #define FIGURE_8_RADIUS 2.0 -/* Radius of the squeezed torus Klein bottle */ -#define SQUEEZED_TORUS_RADIUS 2.0 +/* Radius of the pinched torus Klein bottle */ +#define PINCHED_TORUS_RADIUS 2.0 /* Offset by which we walk above the Klein bottle */ #define DELTAY 0.02 +/* Color change speeds */ +#define DRHO 0.7 +#define DSIGMA 1.1 +#define DTAU 1.7 + /* Number of subdivisions of the Klein bottle */ #define NUMU 128 #define NUMV 128 @@ -268,11 +302,14 @@ typedef struct { int display_mode; int appearance; int colors; + Bool change_colors; int view; int projection_3d; int projection_4d; /* 4D rotation angles */ float alpha, beta, delta, zeta, eta, theta; + /* Color rotation angles */ + float rho, sigma, tau; /* Movement parameters */ float umove, vmove, dumove, dvmove; int side; @@ -451,6 +488,77 @@ static void rotateall4d(float ze, float et, float th, float m[4][4]) } +/* Add a rotation around the x-axis to the matrix m. */ +static void rotatex(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][1]; + v = m[i][2]; + m[i][1] = c*u+s*v; + m[i][2] = -s*u+c*v; + } +} + + +/* Add a rotation around the y-axis to the matrix m. */ +static void rotatey(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][0]; + v = m[i][2]; + m[i][0] = c*u-s*v; + m[i][2] = s*u+c*v; + } +} + + +/* Add a rotation around the z-axis to the matrix m. */ +static void rotatez(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][0]; + v = m[i][1]; + m[i][0] = c*u+s*v; + m[i][1] = -s*u+c*v; + } +} + + +/* Compute the 3d rotation matrix m from the 3d rotation angles. */ +static void rotateall3d(float al, float be, float de, float m[3][3]) +{ + int i, j; + + for (i=0; i<3; i++) + for (j=0; j<3; j++) + m[i][j] = (i==j); + rotatex(m,al); + rotatey(m,be); + rotatez(m,de); +} + + /* Multiply two rotation matrices: o=m*n. */ static void mult_rotmat(float m[4][4], float n[4][4], float o[4][4]) { @@ -499,54 +607,79 @@ static void quats_to_rotmat(float p[4], float q[4], float m[4][4]) /* Compute a fully saturated and bright color based on an angle. */ -static void color(kleinstruct *kb, double angle, float col[4]) +static void color(kleinstruct *kb, double angle, float mat[3][3], float col[4]) { int s; - double t; + double t, ca, sa; + float m; - if (kb->colors == COLORS_TWOSIDED) - return; + if (!kb->change_colors) + { + if (kb->colors == COLORS_ONESIDED || kb->colors == COLORS_TWOSIDED) + return; - if (angle >= 0.0) - angle = fmod(angle,2.0*M_PI); - else - angle = fmod(angle,-2.0*M_PI); - s = floor(angle/(M_PI/3)); - t = angle/(M_PI/3)-s; - if (s >= 6) - s = 0; - switch (s) - { - case 0: - col[0] = 1.0; - col[1] = t; - col[2] = 0.0; - break; - case 1: - col[0] = 1.0-t; - col[1] = 1.0; - col[2] = 0.0; - break; - case 2: - col[0] = 0.0; - col[1] = 1.0; - col[2] = t; - break; - case 3: - col[0] = 0.0; - col[1] = 1.0-t; - col[2] = 1.0; - break; - case 4: - col[0] = t; - col[1] = 0.0; - col[2] = 1.0; - break; - case 5: - col[0] = 1.0; - col[1] = 0.0; - col[2] = 1.0-t; - break; + if (angle >= 0.0) + angle = fmod(angle,2.0*M_PI); + else + angle = fmod(angle,-2.0*M_PI); + s = floor(angle/(M_PI/3)); + t = angle/(M_PI/3)-s; + if (s >= 6) + s = 0; + switch (s) + { + case 0: + col[0] = 1.0; + col[1] = t; + col[2] = 0.0; + break; + case 1: + col[0] = 1.0-t; + col[1] = 1.0; + col[2] = 0.0; + break; + case 2: + col[0] = 0.0; + col[1] = 1.0; + col[2] = t; + break; + case 3: + col[0] = 0.0; + col[1] = 1.0-t; + col[2] = 1.0; + break; + case 4: + col[0] = t; + col[1] = 0.0; + col[2] = 1.0; + break; + case 5: + col[0] = 1.0; + col[1] = 0.0; + col[2] = 1.0-t; + break; + } + } + else /* kb->change_colors */ + { + if (kb->colors == COLORS_ONESIDED || kb->colors == COLORS_TWOSIDED) + { + col[0] = mat[0][2]; + col[1] = mat[1][2]; + col[2] = mat[2][2]; + } + else + { + ca = cos(angle); + sa = sin(angle); + col[0] = ca*mat[0][0]+sa*mat[0][1]; + col[1] = ca*mat[1][0]+sa*mat[1][1]; + col[2] = ca*mat[2][0]+sa*mat[2][1]; + } + m = 0.5f/fmaxf(fmaxf(fabsf(col[0]),fabsf(col[1])),fabsf(col[2])); + col[0] = m*col[0]+0.5f; + col[1] = m*col[1]+0.5f; + col[2] = m*col[2]+0.5f; } if (kb->display_mode == DISP_TRANSPARENT) col[3] = 0.7; @@ -573,10 +706,13 @@ static void setup_figure8(ModeInfo *mi, double umin, double umax, double vmin, k = i*(NUMV+1)+j; u = -ur*j/NUMU+umin; v = vr*i/NUMV+vmin; - if (kb->colors == COLORS_DEPTH) - color(kb,(cos(u)+1.0)*M_PI*2.0/3.0,kb->col[k]); - else - color(kb,v,kb->col[k]); + if (!kb->change_colors) + { + if (kb->colors == COLORS_DEPTH) + color(kb,(cos(u)+1.0)*M_PI*2.0/3.0,NULL,kb->col[k]); + else if (kb->colors == COLORS_RAINBOW) + color(kb,v,NULL,kb->col[k]); + } kb->tex[k][0] = -32*u/(2.0*M_PI); kb->tex[k][1] = 32*v/(2.0*M_PI); cu = cos(u); @@ -612,9 +748,9 @@ static void setup_figure8(ModeInfo *mi, double umin, double umax, double vmin, } -/* Set up the squeezed torus Klein bottle coordinates, colors, and texture. */ -static void setup_squeezed_torus(ModeInfo *mi, double umin, double umax, - double vmin, double vmax) +/* Set up the pinched torus Klein bottle coordinates, colors, and texture. */ +static void setup_pinched_torus(ModeInfo *mi, double umin, double umax, + double vmin, double vmax) { int i, j, k, l; double u, v, ur, vr; @@ -630,10 +766,13 @@ static void setup_squeezed_torus(ModeInfo *mi, double umin, double umax, k = i*(NUMV+1)+j; u = -ur*j/NUMU+umin; v = vr*i/NUMV+vmin; - if (kb->colors == COLORS_DEPTH) - color(kb,(sin(u)*sin(0.5*v)+1.0)*M_PI*2.0/3.0,kb->col[k]); - else - color(kb,v,kb->col[k]); + if (!kb->change_colors) + { + if (kb->colors == COLORS_DEPTH) + color(kb,(sin(u)*sin(0.5*v)+1.0)*M_PI*2.0/3.0,NULL,kb->col[k]); + else if (kb->colors == COLORS_RAINBOW) + color(kb,v,NULL,kb->col[k]); + } kb->tex[k][0] = -32*u/(2.0*M_PI); kb->tex[k][1] = 32*v/(2.0*M_PI); cu = cos(u); @@ -642,23 +781,23 @@ static void setup_squeezed_torus(ModeInfo *mi, double umin, double umax, sv = sin(v); cv2 = cos(0.5*v); sv2 = sin(0.5*v); - kb->x[k][0] = (SQUEEZED_TORUS_RADIUS+cu)*cv; - kb->x[k][1] = (SQUEEZED_TORUS_RADIUS+cu)*sv; + kb->x[k][0] = (PINCHED_TORUS_RADIUS+cu)*cv; + kb->x[k][1] = (PINCHED_TORUS_RADIUS+cu)*sv; kb->x[k][2] = su*cv2; kb->x[k][3] = su*sv2; kb->xu[k][0] = -su*cv; kb->xu[k][1] = -su*sv; kb->xu[k][2] = cu*cv2; kb->xu[k][3] = cu*sv2; - kb->xv[k][0] = -(SQUEEZED_TORUS_RADIUS+cu)*sv; - kb->xv[k][1] = (SQUEEZED_TORUS_RADIUS+cu)*cv; + kb->xv[k][0] = -(PINCHED_TORUS_RADIUS+cu)*sv; + kb->xv[k][1] = (PINCHED_TORUS_RADIUS+cu)*cv; kb->xv[k][2] = -0.5*su*sv2; kb->xv[k][3] = 0.5*su*cv2; for (l=0; l<4; l++) { - kb->x[k][l] /= SQUEEZED_TORUS_RADIUS+1.25; - kb->xu[k][l] /= SQUEEZED_TORUS_RADIUS+1.25; - kb->xv[k][l] /= SQUEEZED_TORUS_RADIUS+1.25; + kb->x[k][l] /= PINCHED_TORUS_RADIUS+1.25; + kb->xu[k][l] /= PINCHED_TORUS_RADIUS+1.25; + kb->xv[k][l] /= PINCHED_TORUS_RADIUS+1.25; } } } @@ -683,10 +822,13 @@ static void setup_lawson(ModeInfo *mi, double umin, double umax, double vmin, k = i*(NUMU+1)+j; u = -ur*j/NUMU+umin; v = vr*i/NUMV+vmin; - if (kb->colors == COLORS_DEPTH) - color(kb,(sin(u)*cos(0.5*v)+1.0)*M_PI*2.0/3.0,kb->col[k]); - else - color(kb,v,kb->col[k]); + if (!kb->change_colors) + { + if (kb->colors == COLORS_DEPTH) + color(kb,(sin(u)*cos(0.5*v)+1.0)*M_PI*2.0/3.0,NULL,kb->col[k]); + else if (kb->colors == COLORS_RAINBOW) + color(kb,v,NULL,kb->col[k]); + } kb->tex[k][0] = -32*u/(2.0*M_PI); kb->tex[k][1] = 32*v/(2.0*M_PI); cu = cos(u); @@ -717,19 +859,25 @@ static int figure8(ModeInfo *mi, double umin, double umax, double vmin, double vmax) { int polys = 0; - static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; - static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; - static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; - static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; - float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[4][4]; + static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; + static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; + static const GLfloat mat_diff_oneside[] = { 0.9, 0.4, 0.3, 1.0 }; + static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_oneside[] = { 0.9, 0.4, 0.3, 0.7 }; + float mat_diff_dyn[4], mat_diff_dyn_compl[4]; + float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[4][4], matc[3][3]; int i, j, k, l, m, o; - double u, v; + double u, v, ur, vr; double xx[4], xxu[4], xxv[4], y[4], yu[4], yv[4]; double q, r, s, t; double cu, su, cv, sv, cv2, sv2, c2u, s2u; float q1[4], q2[4], r1[4][4], r2[4][4]; kleinstruct *kb = &klein[MI_SCREEN(mi)]; + if (kb->change_colors) + rotateall3d(kb->rho,kb->sigma,kb->tau,matc); + if (kb->view == VIEW_WALK || kb->view == VIEW_WALKTURN) { /* Compute the rotation that rotates the Klein bottle in 4D without the @@ -931,22 +1079,60 @@ static int figure8(ModeInfo *mi, double umin, double umax, double vmin, } } - if (kb->colors == COLORS_TWOSIDED) + if (!kb->change_colors) { - glColor3fv(mat_diff_red); - if (kb->display_mode == DISP_TRANSPARENT) + if (kb->colors == COLORS_ONESIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + glColor3fv(mat_diff_oneside); + if (kb->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_trans_oneside); + } + else + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_oneside); + } } - else + else if (kb->colors == COLORS_TWOSIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + glColor3fv(mat_diff_red); + if (kb->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + } + else + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + } + } + } + else /* kb->change_colors */ + { + color(kb,0.0,matc,mat_diff_dyn); + if (kb->colors == COLORS_ONESIDED) + { + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + } + else if (kb->colors == COLORS_TWOSIDED) + { + mat_diff_dyn_compl[0] = 1.0f-mat_diff_dyn[0]; + mat_diff_dyn_compl[1] = 1.0f-mat_diff_dyn[1]; + mat_diff_dyn_compl[2] = 1.0f-mat_diff_dyn[2]; + mat_diff_dyn_compl[3] = mat_diff_dyn[3]; + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn_compl); } } glBindTexture(GL_TEXTURE_2D,kb->tex_name); + ur = umax-umin; + vr = vmax-vmin; for (i=0; i<NUMU; i++) { if (kb->appearance == APPEARANCE_BANDS && ((i & (NUMB-1)) >= NUMB/2)) @@ -964,7 +1150,20 @@ static int figure8(ModeInfo *mi, double umin, double umax, double vmin, o = l*(NUMV+1)+m; glNormal3fv(kb->pn[o]); glTexCoord2fv(kb->tex[o]); - if (kb->colors != COLORS_TWOSIDED) + if (kb->change_colors) + { + if (kb->colors == COLORS_DEPTH) + { + u = -ur*m/NUMU+umin; + color(kb,(cos(u)+1.0)*M_PI*2.0/3.0,matc,kb->col[o]); + } + else if (kb->colors == COLORS_RAINBOW) + { + v = vr*l/NUMV+vmin; + color(kb,v,matc,kb->col[o]); + } + } + if (kb->colors != COLORS_ONESIDED && kb->colors != COLORS_TWOSIDED) { glColor3fv(kb->col[o]); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,kb->col[o]); @@ -980,24 +1179,30 @@ static int figure8(ModeInfo *mi, double umin, double umax, double vmin, } -/* Draw a squeezed torus Klein bottle projected into 3D. */ -static int squeezed_torus(ModeInfo *mi, double umin, double umax, double vmin, - double vmax) +/* Draw a pinched torus Klein bottle projected into 3D. */ +static int pinched_torus(ModeInfo *mi, double umin, double umax, double vmin, + double vmax) { int polys = 0; - static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; - static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; - static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; - static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; - float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[4][4]; + static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; + static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; + static const GLfloat mat_diff_oneside[] = { 0.9, 0.4, 0.3, 1.0 }; + static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_oneside[] = { 0.9, 0.4, 0.3, 0.7 }; + float mat_diff_dyn[4], mat_diff_dyn_compl[4]; + float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[4][4], matc[3][3]; int i, j, k, l, m, o; - double u, v; + double u, v, ur, vr; double xx[4], xxu[4], xxv[4], y[4], yu[4], yv[4]; double q, r, s, t; double cu, su, cv, sv, cv2, sv2; float q1[4], q2[4], r1[4][4], r2[4][4]; kleinstruct *kb = &klein[MI_SCREEN(mi)]; + if (kb->change_colors) + rotateall3d(kb->rho,kb->sigma,kb->tau,matc); + if (kb->view == VIEW_WALK || kb->view == VIEW_WALKTURN) { /* Compute the rotation that rotates the Klein bottle in 4D without the @@ -1012,23 +1217,23 @@ static int squeezed_torus(ModeInfo *mi, double umin, double umax, double vmin, sv = sin(v); cv2 = cos(0.5*v); sv2 = sin(0.5*v); - xx[0] = (SQUEEZED_TORUS_RADIUS+cu)*cv; - xx[1] = (SQUEEZED_TORUS_RADIUS+cu)*sv; + xx[0] = (PINCHED_TORUS_RADIUS+cu)*cv; + xx[1] = (PINCHED_TORUS_RADIUS+cu)*sv; xx[2] = su*cv2; xx[3] = su*sv2; xxu[0] = -su*cv; xxu[1] = -su*sv; xxu[2] = cu*cv2; xxu[3] = cu*sv2; - xxv[0] = -(SQUEEZED_TORUS_RADIUS+cu)*sv; - xxv[1] = (SQUEEZED_TORUS_RADIUS+cu)*cv; + xxv[0] = -(PINCHED_TORUS_RADIUS+cu)*sv; + xxv[1] = (PINCHED_TORUS_RADIUS+cu)*cv; xxv[2] = -0.5*su*sv2; xxv[3] = 0.5*su*cv2; for (l=0; l<4; l++) { - xx[l] /= SQUEEZED_TORUS_RADIUS+1.25; - xxu[l] /= SQUEEZED_TORUS_RADIUS+1.25; - xxv[l] /= SQUEEZED_TORUS_RADIUS+1.25; + xx[l] /= PINCHED_TORUS_RADIUS+1.25; + xxu[l] /= PINCHED_TORUS_RADIUS+1.25; + xxv[l] /= PINCHED_TORUS_RADIUS+1.25; } for (l=0; l<4; l++) { @@ -1103,12 +1308,12 @@ static int squeezed_torus(ModeInfo *mi, double umin, double umax, double vmin, sv = sin(v); cv2 = cos(0.5*v); sv2 = sin(0.5*v); - xx[0] = (SQUEEZED_TORUS_RADIUS+cu)*cv; - xx[1] = (SQUEEZED_TORUS_RADIUS+cu)*sv; + xx[0] = (PINCHED_TORUS_RADIUS+cu)*cv; + xx[1] = (PINCHED_TORUS_RADIUS+cu)*sv; xx[2] = su*cv2; xx[3] = su*sv2; for (l=0; l<4; l++) - xx[l] /= SQUEEZED_TORUS_RADIUS+1.25; + xx[l] /= PINCHED_TORUS_RADIUS+1.25; for (l=0; l<4; l++) { r = 0.0; @@ -1193,22 +1398,60 @@ static int squeezed_torus(ModeInfo *mi, double umin, double umax, double vmin, } } - if (kb->colors == COLORS_TWOSIDED) + if (!kb->change_colors) { - glColor3fv(mat_diff_red); - if (kb->display_mode == DISP_TRANSPARENT) + if (kb->colors == COLORS_ONESIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + glColor3fv(mat_diff_oneside); + if (kb->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_trans_oneside); + } + else + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_oneside); + } } - else + else if (kb->colors == COLORS_TWOSIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + glColor3fv(mat_diff_red); + if (kb->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + } + else + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + } + } + } + else /* kb->change_colors */ + { + color(kb,0.0,matc,mat_diff_dyn); + if (kb->colors == COLORS_ONESIDED) + { + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + } + else if (kb->colors == COLORS_TWOSIDED) + { + mat_diff_dyn_compl[0] = 1.0f-mat_diff_dyn[0]; + mat_diff_dyn_compl[1] = 1.0f-mat_diff_dyn[1]; + mat_diff_dyn_compl[2] = 1.0f-mat_diff_dyn[2]; + mat_diff_dyn_compl[3] = mat_diff_dyn[3]; + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn_compl); } } glBindTexture(GL_TEXTURE_2D,kb->tex_name); + ur = umax-umin; + vr = vmax-vmin; for (i=0; i<NUMU; i++) { if (kb->appearance == APPEARANCE_BANDS && ((i & (NUMB-1)) >= NUMB/2)) @@ -1226,7 +1469,20 @@ static int squeezed_torus(ModeInfo *mi, double umin, double umax, double vmin, o = l*(NUMV+1)+m; glNormal3fv(kb->pn[o]); glTexCoord2fv(kb->tex[o]); - if (kb->colors != COLORS_TWOSIDED) + if (kb->change_colors) + { + v = vr*l/NUMV+vmin; + if (kb->colors == COLORS_DEPTH) + { + u = -ur*m/NUMU+umin; + color(kb,(sin(u)*sin(0.5*v)+1.0)*M_PI*2.0/3.0,matc,kb->col[o]); + } + else if (kb->colors == COLORS_RAINBOW) + { + color(kb,v,matc,kb->col[o]); + } + } + if (kb->colors != COLORS_ONESIDED && kb->colors != COLORS_TWOSIDED) { glColor3fv(kb->col[o]); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,kb->col[o]); @@ -1247,19 +1503,25 @@ static int lawson(ModeInfo *mi, double umin, double umax, double vmin, double vmax) { int polys = 0; - static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; - static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; - static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; - static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; - float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[4][4]; + static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; + static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; + static const GLfloat mat_diff_oneside[] = { 0.9, 0.4, 0.3, 1.0 }; + static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_oneside[] = { 0.9, 0.4, 0.3, 0.7 }; + float mat_diff_dyn[4], mat_diff_dyn_compl[4]; + float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[4][4], matc[3][3]; int i, j, k, l, m, o; - double u, v; + double u, v, ur, vr; double cu, su, cv, sv, cv2, sv2; double xx[4], xxu[4], xxv[4], y[4], yu[4], yv[4]; double q, r, s, t; float q1[4], q2[4], r1[4][4], r2[4][4]; kleinstruct *kb = &klein[MI_SCREEN(mi)]; + if (kb->change_colors) + rotateall3d(kb->rho,kb->sigma,kb->tau,matc); + if (kb->view == VIEW_WALK || kb->view == VIEW_WALKTURN) { /* Compute the rotation that rotates the Klein bottle in 4D without the @@ -1447,22 +1709,60 @@ static int lawson(ModeInfo *mi, double umin, double umax, double vmin, } } - if (kb->colors == COLORS_TWOSIDED) + if (!kb->change_colors) { - glColor3fv(mat_diff_red); - if (kb->display_mode == DISP_TRANSPARENT) + if (kb->colors == COLORS_ONESIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + glColor3fv(mat_diff_oneside); + if (kb->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_trans_oneside); + } + else + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_oneside); + } } - else + else if (kb->colors == COLORS_TWOSIDED) + { + glColor3fv(mat_diff_red); + if (kb->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + } + else + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + } + } + } + else /* kb->change_colors */ + { + color(kb,0.0,matc,mat_diff_dyn); + if (kb->colors == COLORS_ONESIDED) + { + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + } + else if (kb->colors == COLORS_TWOSIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + mat_diff_dyn_compl[0] = 1.0f-mat_diff_dyn[0]; + mat_diff_dyn_compl[1] = 1.0f-mat_diff_dyn[1]; + mat_diff_dyn_compl[2] = 1.0f-mat_diff_dyn[2]; + mat_diff_dyn_compl[3] = mat_diff_dyn[3]; + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn_compl); } } glBindTexture(GL_TEXTURE_2D,kb->tex_name); + ur = umax-umin; + vr = vmax-vmin; for (i=0; i<NUMV; i++) { if (kb->appearance == APPEARANCE_BANDS && ((i & (NUMB-1)) >= NUMB/2)) @@ -1480,7 +1780,20 @@ static int lawson(ModeInfo *mi, double umin, double umax, double vmin, o = l*(NUMU+1)+m; glNormal3fv(kb->pn[o]); glTexCoord2fv(kb->tex[o]); - if (kb->colors != COLORS_TWOSIDED) + if (kb->change_colors) + { + v = vr*l/NUMV+vmin; + if (kb->colors == COLORS_DEPTH) + { + u = -ur*m/NUMU+umin; + color(kb,(sin(u)*cos(0.5*v)+1.0)*M_PI*2.0/3.0,matc,kb->col[o]); + } + else if (kb->colors == COLORS_RAINBOW) + { + color(kb,v,matc,kb->col[o]); + } + } + if (kb->colors != COLORS_ONESIDED && kb->colors != COLORS_TWOSIDED) { glColor3fv(kb->col[o]); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,kb->col[o]); @@ -1509,7 +1822,7 @@ static void gen_texture(ModeInfo *mi) glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); - glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,TEX_DIMENSION,TEX_DIMENSION,0, + glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE,TEX_DIMENSION,TEX_DIMENSION,0, GL_LUMINANCE,GL_UNSIGNED_BYTE,texture); } @@ -1540,7 +1853,7 @@ static void init(ModeInfo *mi) } kb->zeta = 0.0; if (kb->bottle_type == KLEIN_BOTTLE_FIGURE_8 || - kb->bottle_type == KLEIN_BOTTLE_SQUEEZED_TORUS) + kb->bottle_type == KLEIN_BOTTLE_PINCHED_TORUS) kb->eta = 0.0; else kb->eta = 45.0; @@ -1551,6 +1864,10 @@ static void init(ModeInfo *mi) kb->dvmove = 0.0; kb->side = 1; + kb->rho = frand(360.0); + kb->sigma = frand(360.0); + kb->tau = frand(360.0); + if (kb->bottle_type == KLEIN_BOTTLE_FIGURE_8) { kb->offset4d[0] = 0.0; @@ -1565,7 +1882,7 @@ static void init(ModeInfo *mi) kb->offset3d[2] = -1.9; kb->offset3d[3] = 0.0; } - else if (kb->bottle_type == KLEIN_BOTTLE_SQUEEZED_TORUS) + else if (kb->bottle_type == KLEIN_BOTTLE_PINCHED_TORUS) { kb->offset4d[0] = 0.0; kb->offset4d[1] = 0.0; @@ -1598,8 +1915,8 @@ static void init(ModeInfo *mi) gen_texture(mi); if (kb->bottle_type == KLEIN_BOTTLE_FIGURE_8) setup_figure8(mi,0.0,2.0*M_PI,0.0,2.0*M_PI); - else if (kb->bottle_type == KLEIN_BOTTLE_SQUEEZED_TORUS) - setup_squeezed_torus(mi,0.0,2.0*M_PI,0.0,2.0*M_PI); + else if (kb->bottle_type == KLEIN_BOTTLE_PINCHED_TORUS) + setup_pinched_torus(mi,0.0,2.0*M_PI,0.0,2.0*M_PI); else /* kb->bottle_type == KLEIN_BOTTLE_LAWSON */ setup_lawson(mi,0.0,2.0*M_PI,0.0,2.0*M_PI); @@ -1736,6 +2053,18 @@ static void display_klein(ModeInfo *mi) if (kb->umove < 0.0) kb->umove += 2.0*M_PI; } + if (kb->change_colors) + { + kb->rho += DRHO; + if (kb->rho >= 360.0) + kb->rho -= 360.0; + kb->sigma += DSIGMA; + if (kb->sigma >= 360.0) + kb->sigma -= 360.0; + kb->tau += DTAU; + if (kb->tau >= 360.0) + kb->tau -= 360.0; + } } glMatrixMode(GL_PROJECTION); @@ -1760,8 +2089,8 @@ static void display_klein(ModeInfo *mi) if (kb->bottle_type == KLEIN_BOTTLE_FIGURE_8) mi->polygon_count = figure8(mi,0.0,2.0*M_PI,0.0,2.0*M_PI); - else if (kb->bottle_type == KLEIN_BOTTLE_SQUEEZED_TORUS) - mi->polygon_count = squeezed_torus(mi,0.0,2.0*M_PI,0.0,2.0*M_PI); + else if (kb->bottle_type == KLEIN_BOTTLE_PINCHED_TORUS) + mi->polygon_count = pinched_torus(mi,0.0,2.0*M_PI,0.0,2.0*M_PI); else /* kb->bottle_type == KLEIN_BOTTLE_LAWSON */ mi->polygon_count = lawson(mi,0.0,2.0*M_PI,0.0,2.0*M_PI); } @@ -1874,9 +2203,9 @@ ENTRYPOINT void init_klein(ModeInfo *mi) { kb->bottle_type = KLEIN_BOTTLE_FIGURE_8; } - else if (!strcasecmp(klein_bottle,"squeezed-torus")) + else if (!strcasecmp(klein_bottle,"pinched-torus")) { - kb->bottle_type = KLEIN_BOTTLE_SQUEEZED_TORUS; + kb->bottle_type = KLEIN_BOTTLE_PINCHED_TORUS; } else if (!strcasecmp(klein_bottle,"lawson")) { @@ -1936,6 +2265,10 @@ ENTRYPOINT void init_klein(ModeInfo *mi) { kb->colors = random() % NUM_COLORS; } + else if (!strcasecmp(color_mode,"one-sided")) + { + kb->colors = COLORS_ONESIDED; + } else if (!strcasecmp(color_mode,"two-sided")) { kb->colors = COLORS_TWOSIDED; @@ -1953,6 +2286,8 @@ ENTRYPOINT void init_klein(ModeInfo *mi) kb->colors = random() % NUM_COLORS; } + kb->change_colors = change_colors; + /* Set the view mode. */ if (!strcasecmp(view_mode,"random")) { diff --git a/hacks/glx/klein.man b/hacks/glx/klein.man index 1b456bc..342c11f 100644 --- a/hacks/glx/klein.man +++ b/hacks/glx/klein.man @@ -12,7 +12,7 @@ klein - Draws a 4d Klein bottle. [\-fps] [\-klein-bottle \fIbottle-name\fP] [-figure-8] -[-squeezed-torus] +[-pinched-torus] [-lawson] [\-mode \fIdisplay-mode\fP] [\-wireframe] @@ -22,9 +22,11 @@ klein - Draws a 4d Klein bottle. [\-solid] [\-bands] [\-colors \fIcolor-scheme\fP] +[\-onesided] [\-twosided] [\-rainbow] [\-depth] +[\-change-colors] [\-view-mode \fIview-mode\fP] [\-walk] [\-turn] @@ -46,56 +48,72 @@ klein - Draws a 4d Klein bottle. [\-walk-speed \fIfloat\fP] .SH DESCRIPTION The \fIklein\fP program shows three different Klein bottles in 4d: the -figure-8 Klein bottle, the squeezed torus Klein bottle, or the Lawson +figure-8 Klein bottle, the pinched torus Klein bottle, or the Lawson Klein bottle. You can walk on the Klein bottle, see it turn in 4d, or walk on it while it turns in 4d. The figure-8 Klein bottle is well known in its 3d form. The 4d form used in this program is an extension of the 3d form to 4d that does not intersect itself in 4d -(which can be seen in the depth colors mode). The squeezed torus -Klein bottle also does not intersect itself in 4d (which can be seen -in the depth colors mode). The Lawson Klein bottle, on the other -hand, does intersect itself in 4d. Its primary use is that it has a -nice appearance for walking and for turning in 3d. The Klein bottle -is a non-orientable surface. To make this apparent, the two-sided -color mode can be used. Alternatively, orientation markers (curling -arrows) can be drawn as a texture map on the surface of the Klein -bottle. While walking on the Klein bottle, you will notice that the -orientation of the curling arrows changes (which it must because the -Klein bottle is non-orientable). The program projects the 4d Klein -bottle to 3d using either a perspective or an orthographic projection. -Which of the two alternatives looks more appealing depends on the -viewing mode and the Klein bottle. For example, the Lawson Klein -bottle looks nicest when projected perspectively. The figure-8 Klein -bottle, on the other hand, looks nicer while walking when projected -orthographically from 4d. For the squeezed torus Klein bottle, both -projection modes give equally acceptable projections. The projected -Klein bottle can then be projected to the screen either perspectively -or orthographically. When using the walking modes, perspective -projection to the screen should be used. There are three display -modes for the Klein bottle: mesh (wireframe), solid, or transparent. -Furthermore, the appearance of the Klein bottle can be as a solid -object or as a set of see-through bands. Finally, the colors with -with the Klein bottle is drawn can be set to two-sided, rainbow, or -depth. In the first case, the Klein bottle is drawn with red on one -"side" and green on the "other side". Of course, the Klein bottle +(which can be seen in the depth colors mode when using static colors). +The pinched torus Klein bottle also does not intersect itself in 4d +(which can be seen in the depth colors mode when using static colors). +The Lawson Klein bottle, on the other hand, does intersect itself in +4d. Its primary use is that it has a nice appearance for walking and +for turning in 3d. +.PP +The Klein bottle is a non-orientable surface. To make this apparent, +the two-sided color mode can be used. Alternatively, orientation +markers (curling arrows) can be drawn as a texture map on the surface +of the Klein bottle. While walking on the Klein bottle, you will +notice that the orientation of the curling arrows changes (which it +must because the Klein bottle is non-orientable). +.PP +The program projects the 4d Klein bottle to 3d using either a +perspective or an orthographic projection. Which of the two +alternatives looks more appealing depends on the viewing mode and the +Klein bottle. For example, the Lawson Klein bottle looks nicest when +projected perspectively. The figure-8 Klein bottle, on the other +hand, looks nicer while walking when projected orthographically from +4d. For the pinched torus Klein bottle, both projection modes give +equally acceptable projections. +.PP +The projected Klein bottle can then be projected to the screen either +perspectively or orthographically. When using the walking modes, +perspective projection to the screen should be used. +.PP +There are three display modes for the Klein bottle: mesh (wireframe), +solid, or transparent. Furthermore, the appearance of the Klein +bottle can be as a solid object or as a set of see-through bands. +Finally, the colors with with the Klein bottle is drawn can be set to +one-sided, two-sided, rainbow, or depth. In one-sided mode, the Klein +bottle is drawn with the same color on both "sides." In two-sided +mode (using static colors), the Klein bottle is drawn with red on one +"side" and green on the "other side." Of course, the Klein bottle only has one side, so the color jumps from red to green along a curve on the surface of the Klein bottle. This mode enables you to see that -the Klein bottle is non-orientable. The second mode draws the Klein -bottle with fully saturated rainbow colors. This gives a very nice -effect when combined with the see-through bands mode or with the -orientation markers drawn. The third mode draws the Klein bottle with -colors that are chosen according to the 4d "depth" of the points. -This mode enables you to see that the figure-8 and squeezed torus -Klein bottles do not intersect themselves in 4d, while the Lawson -Klein bottle does intersect itself. The rotation speed for each of -the six planes around which the Klein bottle rotates can be chosen. -For the walk-and-turn mode, only the rotation speeds around the true -4d planes are used (the xy, xz, and yz planes). Furthermore, in the -walking modes the walking direction in the 2d base square of the Klein -bottle and the walking speed can be chosen. This program is somewhat -inspired by Thomas Banchoff's book "Beyond the Third Dimension: -Geometry, Computer Graphics, and Higher Dimensions", Scientific -American Library, 1990. +the Klein bottle is non-orientable. If changing colors are used in +two-sided mode, changing complementary colors are used on the +respective "sides." The rainbow color mode (using static colors) +draws the Klein bottle with a color wheel of fully saturated rainbow +colors. If changing colors are used, the color wheel's colors change +dynamically. The rainbow color mode gives a very nice effect when +combined with the see-through bands mode or with the orientation +markers drawn. The depth color mode draws the Klein bottle with +colors that are chosen according to the 4d "depth" of the points. If +static colors are used, this mode enables you to see that the figure-8 +and pinched torus Klein bottles do not intersect themselves in 4d, +while the Lawson Klein bottle does intersect itself. +.PP +The rotation speed for each of the six planes around which the Klein +bottle rotates can be chosen. For the walk-and-turn mode, only the +rotation speeds around the true 4d planes are used (the xy, xz, and yz +planes). +.PP +Furthermore, in the walking modes the walking direction in the 2d base +square of the Klein bottle and the walking speed can be chosen. +.PP +This program is somewhat inspired by Thomas Banchoff's book "Beyond +the Third Dimension: Geometry, Computer Graphics, and Higher +Dimensions", Scientific American Library, 1990. .SH OPTIONS .I klein accepts the following options: @@ -129,8 +147,8 @@ Display a random Klein bottle (default). .B \-klein-bottle figure-8 \fP(Shortcut: \fB\-figure-8\fP) Display the figure-8 Klein bottle. .TP 8 -.B \-klein-bottle squeezed-torus \fP(Shortcut: \fB\-squeezed-torus\fP) -Display the squeezed torus Klein bottle. +.B \-klein-bottle pinched-torus \fP(Shortcut: \fB\-pinched-torus\fP) +Display the pinched torus Klein bottle. .TP 8 .B \-klein-bottle lawson \fP(Shortcut: \fB\-lawson\fP) Display the Lawson Klein bottle. @@ -162,15 +180,19 @@ Display the Klein bottle as a solid object. .B \-appearance bands \fP(Shortcut: \fB\-bands\fP) Display the Klein bottle as see-through bands. .PP -The following four options are mutually exclusive. They determine +The following five options are mutually exclusive. They determine how to color the Klein bottle. .TP 8 .B \-colors random Display the Klein bottle with a random color scheme (default). .TP 8 -.B \-colors twosided \fP(Shortcut: \fB\-twosided\fP) -Display the Klein bottle with two colors: red on one "side" and green -on the "other side". +.B \-colors one-sided \fP(Shortcut: \fB\-onesided\fP) +Display the Klein bottle with a single color. +.TP 8 +.B \-colors two-sided \fP(Shortcut: \fB\-twosided\fP) +Display the Klein bottle with two colors: one color one "side" and the +complementary color on the "other side." For static colors, the +colors are red and green. .TP 8 .B \-colors rainbow \fP(Shortcut: \fB\-rainbow\fP) Display the Klein bottle with fully saturated rainbow colors. If the @@ -181,6 +203,16 @@ displayed with a different color. Display the Klein bottle with colors chosen depending on the 4d "depth" of the points. .PP +The following options determine whether the colors with which the +Klein bottle is displayed are static or are changing dynamically. +.TP 8 +.B \-change-colors +Change the colors with which the Klein bottle is displayed +dynamically. +.TP 8 +.B \-no-change-colors +Use static colors to display the Klein bottle (default). +.PP The following four options are mutually exclusive. They determine how to view the Klein bottle. .TP 8 @@ -296,7 +328,7 @@ stored in the RESOURCE_MANAGER property. .BR X (1), .BR xscreensaver (1) .SH COPYRIGHT -Copyright \(co 2005-2014 by Carsten Steger. Permission to use, copy, +Copyright \(co 2005-2020 by Carsten Steger. Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright @@ -305,4 +337,4 @@ No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Carsten Steger <carsten@mirsanmir.org>, 03-oct-2014. +Carsten Steger <carsten@mirsanmir.org>, 11-jan-2020. diff --git a/hacks/glx/polytopes.c b/hacks/glx/polytopes.c index c704722..333fcde 100644 --- a/hacks/glx/polytopes.c +++ b/hacks/glx/polytopes.c @@ -4,7 +4,7 @@ static const char sccsid[] = "@(#)polytopes.c 1.2 05/09/28 xlockmore"; #endif -/* Copyright (c) 2003-2009 Carsten Steger <carsten@mirsanmir.org>. */ +/* Copyright (c) 2003-2019 Carsten Steger <carsten@mirsanmir.org>. */ /* * Permission to use, copy, modify, and distribute this software and its @@ -2862,16 +2862,10 @@ static void display_polytopes(ModeInfo *mi) ENTRYPOINT void reshape_polytopes(ModeInfo *mi, int width, int height) { polytopesstruct *pp = &poly[MI_SCREEN(mi)]; - int y = 0; - - if (width > height * 5) { /* tiny window: show middle */ - height = width; - y = -height/2; - } pp->WindW = (GLint)width; pp->WindH = (GLint)height; - glViewport(0,y,width,height); + glViewport(0,0,width,height); pp->aspect = (GLfloat)width/(GLfloat)height; } diff --git a/hacks/glx/projectiveplane.c b/hacks/glx/projectiveplane.c index 3a052ea..5f42d60 100644 --- a/hacks/glx/projectiveplane.c +++ b/hacks/glx/projectiveplane.c @@ -2,10 +2,10 @@ that rotates in 4d or on which you can walk */ #if 0 -static const char sccsid[] = "@(#)projectiveplane.c 1.1 14/01/01 xlockmore"; +static const char sccsid[] = "@(#)projectiveplane.c 1.1 03/01/14 xlockmore"; #endif -/* Copyright (c) 2005-2014 Carsten Steger <carsten@mirsanmir.org>. */ +/* Copyright (c) 2013-2020 Carsten Steger <carsten@mirsanmir.org>. */ /* * Permission to use, copy, modify, and distribute this software and its @@ -21,8 +21,9 @@ static const char sccsid[] = "@(#)projectiveplane.c 1.1 14/01/01 xlockmore"; * other special, indirect and consequential damages. * * REVISION HISTORY: - * C. Steger - 14/01/03: Initial version - * C. Steger - 14/10/03: Moved the curlicue texture to curlicue.h + * C. Steger - 03/01/14: Initial version + * C. Steger - 03/10/14: Moved the curlicue texture to curlicue.h + * C. Steger - 06/01/20: Added the changing colors mode. */ /* @@ -30,12 +31,13 @@ static const char sccsid[] = "@(#)projectiveplane.c 1.1 14/01/01 xlockmore"; * You can walk on the projective plane, see it turn in 4d, or walk on * it while it turns in 4d. The fact that the surface is an embedding * of the real projective plane in 4d can be seen in the depth colors - * mode: set all rotation speeds to 0 and the projection mode to 4d - * orthographic projection. In its default orientation, the embedding - * of the real projective plane will then project to the Roman - * surface, which has three lines of self-intersection. However, at - * the three lines of self-intersection the parts of the surface that - * intersect have different colors, i.e., different 4d depths. + * mode (using static colors): set all rotation speeds to 0 and the + * projection mode to 4d orthographic projection. In its default + * orientation, the embedding of the real projective plane will then + * project to the Roman surface, which has three lines of + * self-intersection. However, at the three lines of + * self-intersection the parts of the surface that intersect have + * different colors, i.e., different 4d depths. * * The real projective plane is a non-orientable surface. To make * this apparent, the two-sided color mode can be used. @@ -48,33 +50,35 @@ static const char sccsid[] = "@(#)projectiveplane.c 1.1 14/01/01 xlockmore"; * The real projective plane is a model for the projective geometry in * 2d space. One point can be singled out as the origin. A line can * be singled out as the line at infinity, i.e., a line that lies at - * an infinite distance to the origin. The line at infinity is - * topologically a circle. Points on the line at infinity are also - * used to model directions in projective geometry. The origin can be - * visualized in different manners. When using distance colors, the + * an infinite distance to the origin. The line at infinity, like all + * lines in the projective plane, is topologically a circle. Points + * on the line at infinity are also used to model directions in + * projective geometry. The origin can be visualized in different + * manners. When using distance colors (and using static colors), the * origin is the point that is displayed as fully saturated red, which * is easier to see as the center of the reddish area on the * projective plane. Alternatively, when using distance bands, the - * origin is the center of the only band that projects to a disc. + * origin is the center of the only band that projects to a disk. * When using direction bands, the origin is the point where all * direction bands collapse to a point. Finally, when orientation * markers are being displayed, the origin the the point where all * orientation markers are compressed to a point. The line at * infinity can also be visualized in different ways. When using - * distance colors, the line at infinity is the line that is displayed - * as fully saturated magenta. When two-sided colors are used, the - * line at infinity lies at the points where the red and green "sides" - * of the projective plane meet (of course, the real projective plane - * only has one side, so this is a design choice of the - * visualization). Alternatively, when orientation markers are being - * displayed, the line at infinity is the place where the orientation - * markers change their orientation. + * distance colors (and using static colors), the line at infinity is + * the line that is displayed as fully saturated magenta. When + * two-sided (and static) colors are used, the line at infinity lies + * at the points where the red and green "sides" of the projective + * plane meet (of course, the real projective plane only has one side, + * so this is a design choice of the visualization). Alternatively, + * when orientation markers are being displayed, the line at infinity + * is the place where the orientation markers change their + * orientation. * * Note that when the projective plane is displayed with bands, the * orientation markers are placed in the middle of the bands. For * distance bands, the bands are chosen in such a way that the band at * the origin is only half as wide as the remaining bands, which - * results in a disc being displayed at the origin that has the same + * results in a disk being displayed at the origin that has the same * diameter as the remaining bands. This choice, however, also * implies that the band at infinity is half as wide as the other * bands. Since the projective plane is attached to itself (in a @@ -119,33 +123,37 @@ static const char sccsid[] = "@(#)projectiveplane.c 1.1 14/01/01 xlockmore"; * projective plane is non-orientable. * * Finally, the colors with with the projective plane is drawn can be - * set to two-sided, distance, direction, or depth. In two-sided - * mode, the projective plane is drawn with red on one "side" and - * green on the "other side". As described above, the projective - * plane only has one side, so the color jumps from red to green along - * the line at infinity. This mode enables you to see that the - * projective plane is non-orientable. In distance mode, the - * projective plane is displayed with fully saturated colors that - * depend on the distance of the points on the projective plane to the - * origin. The origin is displayed in red, the line at infinity is - * displayed in magenta. If the projective plane is displayed as - * distance bands, each band will be displayed with a different color. - * In direction mode, the projective plane is displayed with fully + * set to one-sided, two-sided, distance, direction, or depth. In + * one-sided mode, the projective plane is drawn with the same color + * on both "sides." In two-sided mode (using static colors), the + * projective plane is drawn with red on one "side" and green on the + * "other side." As described above, the projective plane only has + * one side, so the color jumps from red to green along the line at + * infinity. This mode enables you to see that the projective plane + * is non-orientable. If changing colors are used in two-sided mode, + * changing complementary colors are used on the respective "sides." + * In distance mode, the projective plane is displayed with fully + * saturated colors that depend on the distance of the points on the + * projective plane to the origin. If static colors are used, the + * origin is displayed in red, while the line at infinity is displayed + * in magenta. If the projective plane is displayed as distance + * bands, each band will be displayed with a different color. In + * direction mode, the projective plane is displayed with fully * saturated colors that depend on the angle of the points on the * projective plane with respect to the origin. Angles in opposite * directions to the origin (e.g., 15 and 205 degrees) are displayed * in the same color since they are projectively equivalent. If the * projective plane is displayed as direction bands, each band will be * displayed with a different color. Finally, in depth mode the - * projective plane with colors chosen depending on the 4d "depth" - * (i.e., the w coordinate) of the points on the projective plane at - * its default orientation in 4d. As discussed above, this mode - * enables you to see that the projective plane does not intersect - * itself in 4d. + * projective plane is displayed with colors chosen depending on the + * 4d "depth" (i.e., the w coordinate) of the points on the projective + * plane at its default orientation in 4d. As discussed above, this + * mode enables you to see that the projective plane does not + * intersect itself in 4d. * * The rotation speed for each of the six planes around which the * projective plane rotates can be chosen. For the walk-and-turn - * more, only the rotation speeds around the true 4d planes are used + * mode, only the rotation speeds around the true 4d planes are used * (the xy, xz, and yz planes). * * Furthermore, in the walking modes the walking direction in the 2d @@ -180,11 +188,12 @@ static const char sccsid[] = "@(#)projectiveplane.c 1.1 14/01/01 xlockmore"; #define APPEARANCE_DIRECTION_BANDS 2 #define NUM_APPEARANCES 3 -#define COLORS_TWOSIDED 0 -#define COLORS_DISTANCE 1 -#define COLORS_DIRECTION 2 -#define COLORS_DEPTH 3 -#define NUM_COLORS 4 +#define COLORS_ONESIDED 0 +#define COLORS_TWOSIDED 1 +#define COLORS_DISTANCE 2 +#define COLORS_DIRECTION 3 +#define COLORS_DEPTH 4 +#define NUM_COLORS 5 #define VIEW_WALK 0 #define VIEW_TURN 1 @@ -204,6 +213,7 @@ static const char sccsid[] = "@(#)projectiveplane.c 1.1 14/01/01 xlockmore"; #define DEF_COLORS "random" #define DEF_VIEW_MODE "random" #define DEF_MARKS "False" +#define DEF_CHANGE_COLORS "False" #define DEF_PROJECTION_3D "random" #define DEF_PROJECTION_4D "random" #define DEF_SPEEDWX "1.1" @@ -252,6 +262,7 @@ static char *appear; static char *color_mode; static char *view_mode; static Bool marks; +static Bool change_colors; static char *proj_3d; static char *proj_4d; static float speed_wx; @@ -275,16 +286,19 @@ static XrmOptionDescRec opts[] = {"-distance-bands", ".appearance", XrmoptionNoArg, "distance-bands" }, {"-direction-bands", ".appearance", XrmoptionNoArg, "direction-bands" }, {"-colors", ".colors", XrmoptionSepArg, 0 }, + {"-onesided-colors", ".colors", XrmoptionNoArg, "one-sided" }, {"-twosided-colors", ".colors", XrmoptionNoArg, "two-sided" }, {"-distance-colors", ".colors", XrmoptionNoArg, "distance" }, {"-direction-colors", ".colors", XrmoptionNoArg, "direction" }, {"-depth-colors", ".colors", XrmoptionNoArg, "depth" }, + {"-change-colors", ".changeColors", XrmoptionNoArg, "on"}, + {"+change-colors", ".changeColors", XrmoptionNoArg, "off"}, {"-view-mode", ".viewMode", XrmoptionSepArg, 0 }, {"-walk", ".viewMode", XrmoptionNoArg, "walk" }, {"-turn", ".viewMode", XrmoptionNoArg, "turn" }, {"-walk-turn", ".viewMode", XrmoptionNoArg, "walk-turn" }, - {"-orientation-marks", ".marks", XrmoptionNoArg, "on"}, - {"+orientation-marks", ".marks", XrmoptionNoArg, "off"}, + {"-orientation-marks", ".marks", XrmoptionNoArg, "on"}, + {"+orientation-marks", ".marks", XrmoptionNoArg, "off"}, {"-projection-3d", ".projection3d", XrmoptionSepArg, 0 }, {"-perspective-3d", ".projection3d", XrmoptionNoArg, "perspective" }, {"-orthographic-3d", ".projection3d", XrmoptionNoArg, "orthographic" }, @@ -306,6 +320,7 @@ static argtype vars[] = { &mode, "displayMode", "DisplayMode", DEF_DISPLAY_MODE, t_String }, { &appear, "appearance", "Appearance", DEF_APPEARANCE, t_String }, { &color_mode, "colors", "Colors", DEF_COLORS, t_String }, + { &change_colors, "changeColors", "ChangeColors", DEF_CHANGE_COLORS, t_Bool }, { &view_mode, "viewMode", "ViewMode", DEF_VIEW_MODE, t_String }, { &marks, "marks", "Marks", DEF_MARKS, t_Bool }, { &proj_3d, "projection3d", "Projection3d", DEF_PROJECTION_3D, t_String }, @@ -327,6 +342,11 @@ ENTRYPOINT ModeSpecOpt projectiveplane_opts = /* Offset by which we walk above the projective plane */ #define DELTAY 0.01 +/* Color change speeds */ +#define DRHO 0.7 +#define DSIGMA 1.1 +#define DTAU 1.7 + /* Number of subdivisions of the projective plane */ #define NUMU 128 #define NUMV 128 @@ -342,12 +362,15 @@ typedef struct { int display_mode; int appearance; int colors; + Bool change_colors; int view; Bool marks; int projection_3d; int projection_4d; /* 4D rotation angles */ float alpha, beta, delta, zeta, eta, theta; + /* Color rotation angles */ + float rho, sigma, tau; /* Movement parameters */ float umove, vmove, dumove, dvmove; int side, dir; @@ -526,6 +549,77 @@ static void rotateall4d(float ze, float et, float th, float m[4][4]) } +/* Add a rotation around the x-axis to the matrix m. */ +static void rotatex(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][1]; + v = m[i][2]; + m[i][1] = c*u+s*v; + m[i][2] = -s*u+c*v; + } +} + + +/* Add a rotation around the y-axis to the matrix m. */ +static void rotatey(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][0]; + v = m[i][2]; + m[i][0] = c*u-s*v; + m[i][2] = s*u+c*v; + } +} + + +/* Add a rotation around the z-axis to the matrix m. */ +static void rotatez(float m[3][3], float phi) +{ + float c, s, u, v; + int i; + + phi *= M_PI/180.0; + c = cos(phi); + s = sin(phi); + for (i=0; i<3; i++) + { + u = m[i][0]; + v = m[i][1]; + m[i][0] = c*u+s*v; + m[i][1] = -s*u+c*v; + } +} + + +/* Compute the 3d rotation matrix m from the 3d rotation angles. */ +static void rotateall3d(float al, float be, float de, float m[3][3]) +{ + int i, j; + + for (i=0; i<3; i++) + for (j=0; j<3; j++) + m[i][j] = (i==j); + rotatex(m,al); + rotatey(m,be); + rotatez(m,de); +} + + /* Multiply two rotation matrices: o=m*n. */ static void mult_rotmat(float m[4][4], float n[4][4], float o[4][4]) { @@ -574,54 +668,80 @@ static void quats_to_rotmat(float p[4], float q[4], float m[4][4]) /* Compute a fully saturated and bright color based on an angle. */ -static void color(projectiveplanestruct *pp, double angle, float col[4]) +static void color(projectiveplanestruct *pp, double angle, float mat[3][3], + float col[4]) { int s; - double t; + double t, ca, sa; + float m; - if (pp->colors == COLORS_TWOSIDED) - return; + if (!pp->change_colors) + { + if (pp->colors == COLORS_ONESIDED || pp->colors == COLORS_TWOSIDED) + return; - if (angle >= 0.0) - angle = fmod(angle,2.0*M_PI); - else - angle = fmod(angle,-2.0*M_PI); - s = floor(angle/(M_PI/3)); - t = angle/(M_PI/3)-s; - if (s >= 6) - s = 0; - switch (s) - { - case 0: - col[0] = 1.0; - col[1] = t; - col[2] = 0.0; - break; - case 1: - col[0] = 1.0-t; - col[1] = 1.0; - col[2] = 0.0; - break; - case 2: - col[0] = 0.0; - col[1] = 1.0; - col[2] = t; - break; - case 3: - col[0] = 0.0; - col[1] = 1.0-t; - col[2] = 1.0; - break; - case 4: - col[0] = t; - col[1] = 0.0; - col[2] = 1.0; - break; - case 5: - col[0] = 1.0; - col[1] = 0.0; - col[2] = 1.0-t; - break; + if (angle >= 0.0) + angle = fmod(angle,2.0*M_PI); + else + angle = fmod(angle,-2.0*M_PI); + s = floor(angle/(M_PI/3)); + t = angle/(M_PI/3)-s; + if (s >= 6) + s = 0; + switch (s) + { + case 0: + col[0] = 1.0; + col[1] = t; + col[2] = 0.0; + break; + case 1: + col[0] = 1.0-t; + col[1] = 1.0; + col[2] = 0.0; + break; + case 2: + col[0] = 0.0; + col[1] = 1.0; + col[2] = t; + break; + case 3: + col[0] = 0.0; + col[1] = 1.0-t; + col[2] = 1.0; + break; + case 4: + col[0] = t; + col[1] = 0.0; + col[2] = 1.0; + break; + case 5: + col[0] = 1.0; + col[1] = 0.0; + col[2] = 1.0-t; + break; + } + } + else /* pp->change_colors */ + { + if (pp->colors == COLORS_ONESIDED || pp->colors == COLORS_TWOSIDED) + { + col[0] = mat[0][2]; + col[1] = mat[1][2]; + col[2] = mat[2][2]; + } + else + { + ca = cos(angle); + sa = sin(angle); + col[0] = ca*mat[0][0]+sa*mat[0][1]; + col[1] = ca*mat[1][0]+sa*mat[1][1]; + col[2] = ca*mat[2][0]+sa*mat[2][1]; + } + m = 0.5f/fmaxf(fmaxf(fabsf(col[0]),fabsf(col[1])),fabsf(col[2])); + col[0] = m*col[0]+0.5f; + col[1] = m*col[1]+0.5f; + col[2] = m*col[2]+0.5f; } if (pp->display_mode == DISP_TRANSPARENT) col[3] = 0.7; @@ -635,7 +755,7 @@ static void setup_projective_plane(ModeInfo *mi, double umin, double umax, double vmin, double vmax) { int i, j, k; - double u, v, ur, vr; + double u, v, w, ur, vr; double cu, su, cv2, sv2, cv4, sv4, c2u, s2u; projectiveplanestruct *pp = &projectiveplane[MI_SCREEN(mi)]; @@ -658,12 +778,16 @@ static void setup_projective_plane(ModeInfo *mi, double umin, double umax, sv2 = sin(0.5*v); cv4 = cos(0.25*v); sv4 = sin(0.25*v); - if (pp->colors == COLORS_DEPTH) - color(pp,((su*su*sv4*sv4-cv4*cv4)+1.0)*M_PI*2.0/3.0,pp->col[k]); - else if (pp->colors == COLORS_DIRECTION) - color(pp,2.0*M_PI+fmod(2.0*u,2.0*M_PI),pp->col[k]); - else /* pp->colors == COLORS_DISTANCE */ - color(pp,v*(5.0/6.0),pp->col[k]); + w = 0.5*(su*su*sv4*sv4-cv4*cv4); + if (!pp->change_colors) + { + if (pp->colors == COLORS_DEPTH) + color(pp,(2.0*w+1.0)*M_PI*2.0/3.0,NULL,pp->col[k]); + else if (pp->colors == COLORS_DIRECTION) + color(pp,2.0*M_PI+fmod(2.0*u,2.0*M_PI),NULL,pp->col[k]); + else /* pp->colors == COLORS_DISTANCE */ + color(pp,v*(5.0/6.0),NULL,pp->col[k]); + } pp->tex[k][0] = -32*u/(2.0*M_PI); if (pp->appearance != APPEARANCE_DISTANCE_BANDS) pp->tex[k][1] = 32*v/(2.0*M_PI); @@ -672,7 +796,7 @@ static void setup_projective_plane(ModeInfo *mi, double umin, double umax, pp->x[k][0] = 0.5*s2u*sv4*sv4; pp->x[k][1] = 0.5*su*sv2; pp->x[k][2] = 0.5*cu*sv2; - pp->x[k][3] = 0.5*(su*su*sv4*sv4-cv4*cv4); + pp->x[k][3] = w; /* Avoid degenerate tangential plane basis vectors. */ if (v < FLT_EPSILON) v = FLT_EPSILON; @@ -697,19 +821,25 @@ static int projective_plane(ModeInfo *mi, double umin, double umax, double vmin, double vmax) { int polys = 0; - static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; - static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; - static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; - static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; - float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[4][4]; + static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; + static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; + static const GLfloat mat_diff_oneside[] = { 0.9, 0.4, 0.3, 1.0 }; + static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_oneside[] = { 0.9, 0.4, 0.3, 0.7 }; + float mat_diff_dyn[4], mat_diff_dyn_compl[4]; + float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[4][4], matc[3][3]; int i, j, k, l, m, o; - double u, v; + double u, v, ur, vr; double xx[4], xxu[4], xxv[4], y[4], yu[4], yv[4]; double q, r, s, t; double cu, su, cv2, sv2, cv4, sv4, c2u, s2u; float q1[4], q2[4], r1[4][4], r2[4][4]; projectiveplanestruct *pp = &projectiveplane[MI_SCREEN(mi)]; + if (pp->change_colors) + rotateall3d(pp->rho,pp->sigma,pp->tau,matc); + if (pp->view == VIEW_WALK || pp->view == VIEW_WALKTURN) { /* Compute the rotation that rotates the projective plane in 4D without @@ -904,22 +1034,60 @@ static int projective_plane(ModeInfo *mi, double umin, double umax, } } - if (pp->colors == COLORS_TWOSIDED) + if (!pp->change_colors) { - glColor3fv(mat_diff_red); - if (pp->display_mode == DISP_TRANSPARENT) + if (pp->colors == COLORS_ONESIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + glColor3fv(mat_diff_oneside); + if (pp->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_trans_oneside); + } + else + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_oneside); + } } - else + else if (pp->colors == COLORS_TWOSIDED) + { + glColor3fv(mat_diff_red); + if (pp->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + } + else + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + } + } + } + else /* pp->change_colors */ + { + color(pp,0.0,matc,mat_diff_dyn); + if (pp->colors == COLORS_ONESIDED) + { + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + } + else if (pp->colors == COLORS_TWOSIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + mat_diff_dyn_compl[0] = 1.0f-mat_diff_dyn[0]; + mat_diff_dyn_compl[1] = 1.0f-mat_diff_dyn[1]; + mat_diff_dyn_compl[2] = 1.0f-mat_diff_dyn[2]; + mat_diff_dyn_compl[3] = mat_diff_dyn[3]; + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn_compl); } } glBindTexture(GL_TEXTURE_2D,pp->tex_name); + ur = umax-umin; + vr = vmax-vmin; if (pp->appearance != APPEARANCE_DIRECTION_BANDS) { for (i=0; i<NUMV; i++) @@ -940,7 +1108,24 @@ static int projective_plane(ModeInfo *mi, double umin, double umax, o = l*(NUMU+1)+m; glNormal3fv(pp->pn[o]); glTexCoord2fv(pp->tex[o]); - if (pp->colors != COLORS_TWOSIDED) + if (pp->change_colors) + { + if (pp->colors == COLORS_DEPTH) + { + color(pp,(2.0*pp->x[o][3]+1.0)*M_PI*2.0/3.0,matc,pp->col[o]); + } + else if (pp->colors == COLORS_DIRECTION) + { + u = -ur*m/NUMU+umin; + color(pp,2.0*M_PI+fmod(2.0*u,2.0*M_PI),matc,pp->col[o]); + } + else if (pp->colors == COLORS_DISTANCE) + { + v = vr*l/NUMV+vmin; + color(pp,v*(5.0/6.0),matc,pp->col[o]); + } + } + if (pp->colors != COLORS_ONESIDED && pp->colors != COLORS_TWOSIDED) { glColor3fv(pp->col[o]); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,pp->col[o]); @@ -971,7 +1156,24 @@ static int projective_plane(ModeInfo *mi, double umin, double umax, o = l*(NUMU+1)+m; glNormal3fv(pp->pn[o]); glTexCoord2fv(pp->tex[o]); - if (pp->colors != COLORS_TWOSIDED) + if (pp->change_colors) + { + if (pp->colors == COLORS_DEPTH) + { + color(pp,(2.0*pp->x[o][3]+1.0)*M_PI*2.0/3.0,matc,pp->col[o]); + } + else if (pp->colors == COLORS_DIRECTION) + { + u = ur*m/NUMU+umin; + color(pp,2.0*M_PI+fmod(2.0*u,2.0*M_PI),matc,pp->col[o]); + } + else if (pp->colors == COLORS_DISTANCE) + { + v = vr*l/NUMV+vmin; + color(pp,v*(5.0/6.0),matc,pp->col[o]); + } + } + if (pp->colors != COLORS_ONESIDED && pp->colors != COLORS_TWOSIDED) { glColor3fv(pp->col[o]); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,pp->col[o]); @@ -1002,7 +1204,7 @@ static void gen_texture(ModeInfo *mi) glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); - glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,TEX_DIMENSION,TEX_DIMENSION,0, + glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE,TEX_DIMENSION,TEX_DIMENSION,0, GL_LUMINANCE,GL_UNSIGNED_BYTE,texture); } @@ -1047,6 +1249,10 @@ static void init(ModeInfo *mi) else pp->dir = -1; + pp->rho = frand(360.0); + pp->sigma = frand(360.0); + pp->tau = frand(360.0); + pp->offset4d[0] = 0.0; pp->offset4d[1] = 0.0; pp->offset4d[2] = 0.0; @@ -1205,6 +1411,18 @@ static void display_projectiveplane(ModeInfo *mi) if (pp->umove < 0.0) pp->umove += 2.0*M_PI; } + if (pp->change_colors) + { + pp->rho += DRHO; + if (pp->rho >= 360.0) + pp->rho -= 360.0; + pp->sigma += DSIGMA; + if (pp->sigma >= 360.0) + pp->sigma -= 360.0; + pp->tau += DTAU; + if (pp->tau >= 360.0) + pp->tau -= 360.0; + } } glMatrixMode(GL_PROJECTION); @@ -1383,6 +1601,10 @@ ENTRYPOINT void init_projectiveplane(ModeInfo *mi) { pp->colors = random() % NUM_COLORS; } + else if (!strcasecmp(color_mode,"one-sided")) + { + pp->colors = COLORS_ONESIDED; + } else if (!strcasecmp(color_mode,"two-sided")) { pp->colors = COLORS_TWOSIDED; @@ -1404,6 +1626,8 @@ ENTRYPOINT void init_projectiveplane(ModeInfo *mi) pp->colors = random() % NUM_COLORS; } + pp->change_colors = change_colors; + /* Set the view mode. */ if (!strcasecmp(view_mode,"random")) { diff --git a/hacks/glx/projectiveplane.man b/hacks/glx/projectiveplane.man index 8adea81..7df253d 100644 --- a/hacks/glx/projectiveplane.man +++ b/hacks/glx/projectiveplane.man @@ -19,9 +19,11 @@ projectiveplane - Draws a 4d embedding of the real projective plane. [\-distance-bands] [\-direction-bands] [\-colors \fIcolor-scheme\fP] +[\-onesided-colors] [\-twosided-colors] [\-distance-colors] [\-direction-colors] +[\-change-colors] [\-depth-colors] [\-view-mode \fIview-mode\fP] [\-walk] @@ -47,12 +49,13 @@ The \fIprojectiveplane\fP program shows a 4d embedding of the real projective plane. You can walk on the projective plane, see it turn in 4d, or walk on it while it turns in 4d. The fact that the surface is an embedding of the real projective plane in 4d can be seen in the -depth colors mode: set all rotation speeds to 0 and the projection -mode to 4d orthographic projection. In its default orientation, the -embedding of the real projective plane will then project to the Roman -surface, which has three lines of self-intersection. However, at the -three lines of self-intersection the parts of the surface that -intersect have different colors, i.e., different 4d depths. +depth colors mode (using static colors): set all rotation speeds to 0 +and the projection mode to 4d orthographic projection. In its default +orientation, the embedding of the real projective plane will then +project to the Roman surface, which has three lines of +self-intersection. However, at the three lines of self-intersection +the parts of the surface that intersect have different colors, i.e., +different 4d depths. .PP The real projective plane is a non-orientable surface. To make this apparent, the two-sided color mode can be used. Alternatively, @@ -65,26 +68,27 @@ non-orientable). The real projective plane is a model for the projective geometry in 2d space. One point can be singled out as the origin. A line can be singled out as the line at infinity, i.e., a line that lies at an -infinite distance to the origin. The line at infinity is -topologically a circle. Points on the line at infinity are also used -to model directions in projective geometry. The origin can be -visualized in different manners. When using distance colors, the -origin is the point that is displayed as fully saturated red, which is -easier to see as the center of the reddish area on the projective -plane. Alternatively, when using distance bands, the origin is the -center of the only band that projects to a disk. When using direction -bands, the origin is the point where all direction bands collapse to a -point. Finally, when orientation markers are being displayed, the -origin the the point where all orientation markers are compressed to a -point. The line at infinity can also be visualized in different ways. -When using distance colors, the line at infinity is the line that is -displayed as fully saturated magenta. When two-sided colors are used, -the line at infinity lies at the points where the red and green -"sides" of the projective plane meet (of course, the real projective -plane only has one side, so this is a design choice of the -visualization). Alternatively, when orientation markers are being -displayed, the line at infinity is the place where the orientation -markers change their orientation. +infinite distance to the origin. The line at infinity, like all lines +in the projective plane, is topologically a circle. Points on the +line at infinity are also used to model directions in projective +geometry. The origin can be visualized in different manners. When +using distance colors (and using static colors), the origin is the +point that is displayed as fully saturated red, which is easier to see +as the center of the reddish area on the projective plane. +Alternatively, when using distance bands, the origin is the center of +the only band that projects to a disk. When using direction bands, +the origin is the point where all direction bands collapse to a point. +Finally, when orientation markers are being displayed, the origin the +the point where all orientation markers are compressed to a point. +The line at infinity can also be visualized in different ways. When +using distance colors (and using static colors), the line at infinity +is the line that is displayed as fully saturated magenta. When +two-sided (and static) colors are used, the line at infinity lies at +the points where the red and green "sides" of the projective plane +meet (of course, the real projective plane only has one side, so this +is a design choice of the visualization). Alternatively, when +orientation markers are being displayed, the line at infinity is the +place where the orientation markers change their orientation. .PP Note that when the projective plane is displayed with bands, the orientation markers are placed in the middle of the bands. For @@ -134,27 +138,32 @@ origin) is a Moebius strip, which also shows that the projective plane is non-orientable. .PP Finally, the colors with with the projective plane is drawn can be set -to two-sided, distance, direction, or depth. In two-sided mode, the -projective plane is drawn with red on one "side" and green on the -"other side". As described above, the projective plane only has one -side, so the color jumps from red to green along the line at infinity. -This mode enables you to see that the projective plane is -non-orientable. In distance mode, the projective plane is displayed -with fully saturated colors that depend on the distance of the points -on the projective plane to the origin. The origin is displayed in -red, the line at infinity is displayed in magenta. If the projective -plane is displayed as distance bands, each band will be displayed with -a different color. In direction mode, the projective plane is -displayed with fully saturated colors that depend on the angle of the -points on the projective plane with respect to the origin. Angles in -opposite directions to the origin (e.g., 15 and 205 degrees) are -displayed in the same color since they are projectively equivalent. -If the projective plane is displayed as direction bands, each band -will be displayed with a different color. Finally, in depth mode the -projective plane with colors chosen depending on the 4d "depth" (i.e., -the w coordinate) of the points on the projective plane at its default -orientation in 4d. As discussed above, this mode enables you to see -that the projective plane does not intersect itself in 4d. +to one-sided, two-sided, distance, direction, or depth. In one-sided +mode, the projective plane is drawn with the same color on both +"sides." In two-sided mode (using static colors), the projective +plane is drawn with red on one "side" and green on the "other side." +As described above, the projective plane only has one side, so the +color jumps from red to green along the line at infinity. This mode +enables you to see that the projective plane is non-orientable. If +changing colors are used in two-sided mode, changing complementary +colors are used on the respective "sides." In distance mode, the +projective plane is displayed with fully saturated colors that depend +on the distance of the points on the projective plane to the origin. +If static colors are used, the origin is displayed in red, while the +line at infinity is displayed in magenta. If the projective plane is +displayed as distance bands, each band will be displayed with a +different color. In direction mode, the projective plane is displayed +with fully saturated colors that depend on the angle of the points on +the projective plane with respect to the origin. Angles in opposite +directions to the origin (e.g., 15 and 205 degrees) are displayed in +the same color since they are projectively equivalent. If the +projective plane is displayed as direction bands, each band will be +displayed with a different color. Finally, in depth mode the +projective plane is displayed with colors chosen depending on the 4d +"depth" (i.e., the w coordinate) of the points on the projective plane +at its default orientation in 4d. As discussed above, this mode +enables you to see that the projective plane does not intersect itself +in 4d. .PP The rotation speed for each of the six planes around which the projective plane rotates can be chosen. For the walk-and-turn mode, @@ -238,18 +247,23 @@ to color the projective plane. .B \-colors random Display the projective plane with a random color scheme (default). .TP 8 +.B \-colors onesided \fP(Shortcut: \fB\-onesided-colors\fP) +Display the projective plane with a single color. +.TP 8 .B \-colors twosided \fP(Shortcut: \fB\-twosided-colors\fP) -Display the projective plane with two colors: red on one "side" and -green on the "other side." Note that the line at infinity lies at the +Display the projective plane with two colors: one color one "side" and +the complementary color on the "other side." For static colors, the +colors are red and green. Note that the line at infinity lies at the points where the red and green "sides" of the projective plane meet, i.e., where the orientation of the projective plane reverses. .TP 8 .B \-colors distance \fP(Shortcut: \fB\-distance-colors\fP) Display the projective plane with fully saturated colors that depend on the distance of the points on the projective plane to the origin. -The origin is displayed in red, the line at infinity is displayed in -magenta. If the projective plane is displayed as distance bands, each -band will be displayed with a different color. +For static colors, the origin is displayed in red, while the line at +infinity is displayed in magenta. If the projective plane is +displayed as distance bands, each band will be displayed with a +different color. .TP 8 .B \-colors direction \fP(Shortcut: \fB\-direction-colors\fP) Display the projective plane with fully saturated colors that depend @@ -264,6 +278,16 @@ Display the projective plane with colors chosen depending on the 4d "depth" (i.e., the w coordinate) of the points on the projective plane at its default orientation in 4d. .PP +The following options determine whether the colors with which the +projective plane is displayed are static or are changing dynamically. +.TP 8 +.B \-change-colors +Change the colors with which the projective plane is displayed +dynamically. +.TP 8 +.B \-no-change-colors +Use static colors to display the projective plane (default). +.PP The following four options are mutually exclusive. They determine how to view the projective plane. .TP 8 @@ -388,7 +412,7 @@ stored in the RESOURCE_MANAGER property. .BR X (1), .BR xscreensaver (1) .SH COPYRIGHT -Copyright \(co 2005-2014 by Carsten Steger. Permission to use, copy, +Copyright \(co 2013-2020 by Carsten Steger. Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright @@ -397,4 +421,4 @@ No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Carsten Steger <carsten@mirsanmir.org>, 03-oct-2014. +Carsten Steger <carsten@mirsanmir.org>, 06-jan-2020. diff --git a/hacks/glx/romanboy.c b/hacks/glx/romanboy.c index e906082..6957556 100644 --- a/hacks/glx/romanboy.c +++ b/hacks/glx/romanboy.c @@ -3,10 +3,10 @@ smoothly between the Roman surface and the Boy surface. */ #if 0 -static const char sccsid[] = "@(#)romanboy.c 1.1 14/10/03 xlockmore"; +static const char sccsid[] = "@(#)romanboy.c 1.1 03/10/14 xlockmore"; #endif -/* Copyright (c) 2013-2014 Carsten Steger <carsten@mirsanmir.org>. */ +/* Copyright (c) 2014-2020 Carsten Steger <carsten@mirsanmir.org>. */ /* * Permission to use, copy, modify, and distribute this software and its @@ -22,15 +22,16 @@ static const char sccsid[] = "@(#)romanboy.c 1.1 14/10/03 xlockmore"; * other special, indirect and consequential damages. * * REVISION HISTORY: - * C. Steger - 14/10/03: Initial version + * C. Steger - 03/10/14: Initial version + * C. Steger - 06/01/20: Added the changing colors mode. */ /* - * This program shows a 3d immersion of the real projective plane - * that smoothly deforms between the Roman surface and the Boy - * surface. You can walk on the projective plane or turn in 3d. The - * smooth deformation (homotopy) between these two famous immersions - * of the real projective plane was constructed by Franois Apry. + * This program shows a 3d immersion of the real projective plane that + * smoothly deforms between the Roman surface and the Boy surface. + * You can walk on the projective plane or turn in 3d. The smooth + * deformation (homotopy) between these two famous immersions of the + * real projective plane was constructed by Franois Apry. * * The real projective plane is a non-orientable surface. To make * this apparent, the two-sided color mode can be used. @@ -43,10 +44,11 @@ static const char sccsid[] = "@(#)romanboy.c 1.1 14/10/03 xlockmore"; * The real projective plane is a model for the projective geometry in * 2d space. One point can be singled out as the origin. A line can * be singled out as the line at infinity, i.e., a line that lies at - * an infinite distance to the origin. The line at infinity is - * topologically a circle. Points on the line at infinity are also - * used to model directions in projective geometry. The origin can be - * visualized in different manners. When using distance colors, the + * an infinite distance to the origin. The line at infinity, like all + * lines in the projective plane, is topologically a circle. Points + * on the line at infinity are also used to model directions in + * projective geometry. The origin can be visualized in different + * manners. When using distance colors (and using static colors), the * origin is the point that is displayed as fully saturated red, which * is easier to see as the center of the reddish area on the * projective plane. Alternatively, when using distance bands, the @@ -56,14 +58,15 @@ static const char sccsid[] = "@(#)romanboy.c 1.1 14/10/03 xlockmore"; * markers are being displayed, the origin the the point where all * orientation markers are compressed to a point. The line at * infinity can also be visualized in different ways. When using - * distance colors, the line at infinity is the line that is displayed - * as fully saturated magenta. When two-sided colors are used, the - * line at infinity lies at the points where the red and green "sides" - * of the projective plane meet (of course, the real projective plane - * only has one side, so this is a design choice of the - * visualization). Alternatively, when orientation markers are being - * displayed, the line at infinity is the place where the orientation - * markers change their orientation. + * distance colors (and using static colors), the line at infinity is + * the line that is displayed as fully saturated magenta. When + * two-sided (and static) colors are used, the line at infinity lies + * at the points where the red and green "sides" of the projective + * plane meet (of course, the real projective plane only has one side, + * so this is a design choice of the visualization). Alternatively, + * when orientation markers are being displayed, the line at infinity + * is the place where the orientation markers change their + * orientation. * * Note that when the projective plane is displayed with bands, the * orientation markers are placed in the middle of the bands. For @@ -100,24 +103,28 @@ static const char sccsid[] = "@(#)romanboy.c 1.1 14/10/03 xlockmore"; * projective plane is non-orientable. * * Finally, the colors with with the projective plane is drawn can be - * set to two-sided, distance, or direction. In two-sided mode, the - * projective plane is drawn with red on one "side" and green on the - * "other side". As described above, the projective plane only has - * one side, so the color jumps from red to green along the line at - * infinity. This mode enables you to see that the projective plane - * is non-orientable. In distance mode, the projective plane is - * displayed with fully saturated colors that depend on the distance - * of the points on the projective plane to the origin. The origin is - * displayed in red, the line at infinity is displayed in magenta. If - * the projective plane is displayed as distance bands, each band will - * be displayed with a different color. In direction mode, the - * projective plane is displayed with fully saturated colors that - * depend on the angle of the points on the projective plane with - * respect to the origin. Angles in opposite directions to the origin - * (e.g., 15 and 205 degrees) are displayed in the same color since - * they are projectively equivalent. If the projective plane is - * displayed as direction bands, each band will be displayed with a - * different color. + * set to one-sided, two-sided, distance, or direction. In one-sided + * mode, the projective plane is drawn with the same color on both + * "sides." In two-sided mode (using static colors), the projective + * plane is drawn with red on one "side" and green on the "other + * side." As described above, the projective plane only has one side, + * so the color jumps from red to green along the line at infinity. + * This mode enables you to see that the projective plane is + * non-orientable. If changing colors are used in two-sided mode, + * changing complementary colors are used on the respective "sides." + * In distance mode, the projective plane is displayed with fully + * saturated colors that depend on the distance of the points on the + * projective plane to the origin. If static colors are used, the + * origin is displayed in red, while the line at infinity is displayed + * in magenta. If the projective plane is displayed as distance + * bands, each band will be displayed with a different color. In + * direction mode, the projective plane is displayed with fully + * saturated colors that depend on the angle of the points on the + * projective plane with respect to the origin. Angles in opposite + * directions to the origin (e.g., 15 and 205 degrees) are displayed + * in the same color since they are projectively equivalent. If the + * projective plane is displayed as direction bands, each band will be + * displayed with a different color. * * The rotation speed for each of the three coordinate axes around * which the projective plane rotates can be chosen. @@ -172,10 +179,11 @@ static const char sccsid[] = "@(#)romanboy.c 1.1 14/10/03 xlockmore"; #define APPEARANCE_DIRECTION_BANDS 2 #define NUM_APPEARANCES 3 -#define COLORS_TWOSIDED 0 -#define COLORS_DISTANCE 1 -#define COLORS_DIRECTION 2 -#define NUM_COLORS 3 +#define COLORS_ONESIDED 0 +#define COLORS_TWOSIDED 1 +#define COLORS_DISTANCE 2 +#define COLORS_DIRECTION 3 +#define NUM_COLORS 4 #define VIEW_WALK 0 #define VIEW_TURN 1 @@ -190,6 +198,7 @@ static const char sccsid[] = "@(#)romanboy.c 1.1 14/10/03 xlockmore"; #define DEF_COLORS "random" #define DEF_VIEW_MODE "random" #define DEF_MARKS "False" +#define DEF_CHANGE_COLORS "False" #define DEF_DEFORM "True" #define DEF_PROJECTION "random" #define DEF_SPEEDX "1.1" @@ -239,6 +248,7 @@ static char *color_mode; static char *view_mode; static Bool marks; static Bool deform; +static Bool change_colors; static char *proj; static float speed_x; static float speed_y; @@ -261,16 +271,19 @@ static XrmOptionDescRec opts[] = {"-distance-bands", ".appearance", XrmoptionNoArg, "distance-bands" }, {"-direction-bands", ".appearance", XrmoptionNoArg, "direction-bands" }, {"-colors", ".colors", XrmoptionSepArg, 0 }, + {"-onesided-colors", ".colors", XrmoptionNoArg, "one-sided" }, {"-twosided-colors", ".colors", XrmoptionNoArg, "two-sided" }, {"-distance-colors", ".colors", XrmoptionNoArg, "distance" }, {"-direction-colors", ".colors", XrmoptionNoArg, "direction" }, + {"-change-colors", ".changeColors", XrmoptionNoArg, "on"}, + {"+change-colors", ".changeColors", XrmoptionNoArg, "off"}, {"-view-mode", ".viewMode", XrmoptionSepArg, 0 }, {"-walk", ".viewMode", XrmoptionNoArg, "walk" }, {"-turn", ".viewMode", XrmoptionNoArg, "turn" }, - {"-deform", ".deform", XrmoptionNoArg, "on"}, - {"+deform", ".deform", XrmoptionNoArg, "off"}, - {"-orientation-marks", ".marks", XrmoptionNoArg, "on"}, - {"+orientation-marks", ".marks", XrmoptionNoArg, "off"}, + {"-deform", ".deform", XrmoptionNoArg, "on"}, + {"+deform", ".deform", XrmoptionNoArg, "off"}, + {"-orientation-marks", ".marks", XrmoptionNoArg, "on"}, + {"+orientation-marks", ".marks", XrmoptionNoArg, "off"}, {"-projection", ".projection", XrmoptionSepArg, 0 }, {"-perspective", ".projection", XrmoptionNoArg, "perspective" }, {"-orthographic", ".projection", XrmoptionNoArg, "orthographic" }, @@ -291,6 +304,7 @@ static argtype vars[] = { &mode, "displayMode", "DisplayMode", DEF_DISPLAY_MODE, t_String }, { &appear, "appearance", "Appearance", DEF_APPEARANCE, t_String }, { &color_mode, "colors", "Colors", DEF_COLORS, t_String }, + { &change_colors, "changeColors", "ChangeColors", DEF_CHANGE_COLORS, t_Bool }, { &view_mode, "viewMode", "ViewMode", DEF_VIEW_MODE, t_String }, { &deform, "deform", "Deform", DEF_DEFORM, t_Bool }, { &marks, "marks", "Marks", DEF_MARKS, t_Bool }, @@ -312,6 +326,11 @@ ENTRYPOINT ModeSpecOpt romanboy_opts = /* Offset by which we walk above the projective plane */ #define DELTAY 0.01 +/* Color change speeds */ +#define DRHO 0.7 +#define DSIGMA 1.1 +#define DTAU 1.7 + /* Number of subdivisions of the projective plane */ #define NUMU 64 #define NUMV 128 @@ -327,11 +346,14 @@ typedef struct { int display_mode; int appearance; int colors; + Bool change_colors; int view; int projection; Bool marks; /* 3D rotation angles */ float alpha, beta, delta; + /* Color rotation angles */ + float rho, sigma, tau; /* Movement parameters */ float umove, vmove, dumove, dvmove; int side, dir; @@ -472,54 +494,80 @@ static void quat_to_rotmat(float p[4], float m[3][3]) /* Compute a fully saturated and bright color based on an angle. */ -static void color(romanboystruct *pp, double angle, float col[4]) +static void color(romanboystruct *pp, double angle, float mat[3][3], + float col[4]) { int s; - double t; + double t, ca, sa; + float m; - if (pp->colors == COLORS_TWOSIDED) - return; + if (!pp->change_colors) + { + if (pp->colors == COLORS_ONESIDED || pp->colors == COLORS_TWOSIDED) + return; - if (angle >= 0.0) - angle = fmod(angle,2.0*M_PI); - else - angle = fmod(angle,-2.0*M_PI); - s = floor(angle/(M_PI/3)); - t = angle/(M_PI/3)-s; - if (s >= 6) - s = 0; - switch (s) + if (angle >= 0.0) + angle = fmod(angle,2.0*M_PI); + else + angle = fmod(angle,-2.0*M_PI); + s = floor(angle/(M_PI/3)); + t = angle/(M_PI/3)-s; + if (s >= 6) + s = 0; + switch (s) + { + case 0: + col[0] = 1.0; + col[1] = t; + col[2] = 0.0; + break; + case 1: + col[0] = 1.0-t; + col[1] = 1.0; + col[2] = 0.0; + break; + case 2: + col[0] = 0.0; + col[1] = 1.0; + col[2] = t; + break; + case 3: + col[0] = 0.0; + col[1] = 1.0-t; + col[2] = 1.0; + break; + case 4: + col[0] = t; + col[1] = 0.0; + col[2] = 1.0; + break; + case 5: + col[0] = 1.0; + col[1] = 0.0; + col[2] = 1.0-t; + break; + } + } + else /* pp->change_colors */ { - case 0: - col[0] = 1.0; - col[1] = t; - col[2] = 0.0; - break; - case 1: - col[0] = 1.0-t; - col[1] = 1.0; - col[2] = 0.0; - break; - case 2: - col[0] = 0.0; - col[1] = 1.0; - col[2] = t; - break; - case 3: - col[0] = 0.0; - col[1] = 1.0-t; - col[2] = 1.0; - break; - case 4: - col[0] = t; - col[1] = 0.0; - col[2] = 1.0; - break; - case 5: - col[0] = 1.0; - col[1] = 0.0; - col[2] = 1.0-t; - break; + if (pp->colors == COLORS_ONESIDED || pp->colors == COLORS_TWOSIDED) + { + col[0] = mat[0][2]; + col[1] = mat[1][2]; + col[2] = mat[2][2]; + } + else + { + ca = cos(angle); + sa = sin(angle); + col[0] = ca*mat[0][0]+sa*mat[0][1]; + col[1] = ca*mat[1][0]+sa*mat[1][1]; + col[2] = ca*mat[2][0]+sa*mat[2][1]; + } + m = 0.5f/fmaxf(fmaxf(fabsf(col[0]),fabsf(col[1])),fabsf(col[2])); + col[0] = m*col[0]+0.5f; + col[1] = m*col[1]+0.5f; + col[2] = m*col[2]+0.5f; } if (pp->display_mode == DISP_TRANSPARENT) col[3] = 0.7; @@ -550,10 +598,13 @@ static void setup_roman_boy_color_texture(ModeInfo *mi, double umin, else u = ur*j/numu+umin; v = vr*i/numv+vmin; - if (pp->colors == COLORS_DIRECTION) - color(pp,2.0*M_PI-fmod(2.0*u,2.0*M_PI),&pp->col[4*k]); - else /* pp->colors == COLORS_DISTANCE */ - color(pp,v*(5.0/6.0),&pp->col[4*k]); + if (!pp->change_colors) + { + if (pp->colors == COLORS_DIRECTION) + color(pp,2.0*M_PI-fmod(2.0*u,2.0*M_PI),NULL,&pp->col[4*k]); + else /* pp->colors == COLORS_DISTANCE */ + color(pp,v*(5.0/6.0),NULL,&pp->col[4*k]); + } pp->tex[2*k+0] = -16*g*u/(2.0*M_PI); if (pp->appearance == APPEARANCE_DISTANCE_BANDS) pp->tex[2*k+1] = 32*v/(2.0*M_PI)-0.5; @@ -569,11 +620,14 @@ static int roman_boy(ModeInfo *mi, double umin, double umax, double vmin, double vmax, int numu, int numv) { int polys = 0; - static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; - static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; - static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; - static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; - float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[3][3]; + static const GLfloat mat_diff_red[] = { 1.0, 0.0, 0.0, 1.0 }; + static const GLfloat mat_diff_green[] = { 0.0, 1.0, 0.0, 1.0 }; + static const GLfloat mat_diff_oneside[] = { 0.9, 0.4, 0.3, 1.0 }; + static const GLfloat mat_diff_trans_red[] = { 1.0, 0.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_green[] = { 0.0, 1.0, 0.0, 0.7 }; + static const GLfloat mat_diff_trans_oneside[] = { 0.9, 0.4, 0.3, 0.7 }; + float mat_diff_dyn[4], mat_diff_dyn_compl[4]; + float p[3], pu[3], pv[3], pm[3], n[3], b[3], mat[3][3], matc[3][3]; int i, j, k, l, m, o, g; double u, v, ur, vr, oz; double xx[3], xxu[3], xxv[3]; @@ -591,6 +645,10 @@ static int roman_boy(ModeInfo *mi, double umin, double umax, r = 1.0+d*d*(1.0/2.0+d*d*(1.0/6.0+d*d*(1.0/3.0))); radius = 1.0/r; oz = 0.5*r; + + if (pp->change_colors) + rotateall(pp->rho,pp->sigma,pp->tau,matc); + if (pp->view == VIEW_WALK) { u = pp->umove; @@ -740,18 +798,54 @@ static int roman_boy(ModeInfo *mi, double umin, double umax, mult_rotmat(r2,r1,mat); } - if (pp->colors == COLORS_TWOSIDED) + if (!pp->change_colors) { - glColor3fv(mat_diff_red); - if (pp->display_mode == DISP_TRANSPARENT) + if (pp->colors == COLORS_ONESIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + glColor3fv(mat_diff_oneside); + if (pp->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_trans_oneside); + } + else + { + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, + mat_diff_oneside); + } } - else + else if (pp->colors == COLORS_TWOSIDED) { - glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); - glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + glColor3fv(mat_diff_red); + if (pp->display_mode == DISP_TRANSPARENT) + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_trans_green); + } + else + { + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_red); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_green); + } + } + } + else /* pp->change_colors */ + { + color(pp,0.0,matc,mat_diff_dyn); + if (pp->colors == COLORS_ONESIDED) + { + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + } + else if (pp->colors == COLORS_TWOSIDED) + { + mat_diff_dyn_compl[0] = 1.0f-mat_diff_dyn[0]; + mat_diff_dyn_compl[1] = 1.0f-mat_diff_dyn[1]; + mat_diff_dyn_compl[2] = 1.0f-mat_diff_dyn[2]; + mat_diff_dyn_compl[3] = mat_diff_dyn[3]; + glColor3fv(mat_diff_dyn); + glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn); + glMaterialfv(GL_BACK,GL_AMBIENT_AND_DIFFUSE,mat_diff_dyn_compl); } } glBindTexture(GL_TEXTURE_2D,pp->tex_name); @@ -772,6 +866,14 @@ static int roman_boy(ModeInfo *mi, double umin, double umax, o = i*(numu+1)+j; u = ur*j/numu+umin; v = vr*i/numv+vmin; + if (pp->change_colors) + { + /* Compute the colors dynamically. */ + if (pp->colors == COLORS_DIRECTION) + color(pp,2.0*M_PI-fmod(2.0*u,2.0*M_PI),matc,&pp->col[4*o]); + else if (pp->colors == COLORS_DISTANCE) + color(pp,v*(5.0/6.0),matc,&pp->col[4*o]); + } if (g & 1) v = 0.5*M_PI-0.25*v; else @@ -872,6 +974,14 @@ static int roman_boy(ModeInfo *mi, double umin, double umax, o = i*(numu+1)+j; u = -ur*j/numu+umin; v = vr*i/numv+vmin; + if (pp->change_colors) + { + /* Compute the colors dynamically. */ + if (pp->colors == COLORS_DIRECTION) + color(pp,2.0*M_PI-fmod(2.0*u,2.0*M_PI),matc,&pp->col[4*o]); + else if (pp->colors == COLORS_DISTANCE) + color(pp,v*(5.0/6.0),matc,&pp->col[4*o]); + } if (g & 1) v = 0.5*M_PI-0.25*v; else @@ -981,7 +1091,7 @@ static int roman_boy(ModeInfo *mi, double umin, double umax, m = j; o = l*(numu+1)+m; glTexCoord2fv(&pp->tex[2*o]); - if (pp->colors != COLORS_TWOSIDED) + if (pp->colors != COLORS_ONESIDED && pp->colors != COLORS_TWOSIDED) { glColor3fv(&pp->col[4*o]); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, @@ -1013,7 +1123,7 @@ static int roman_boy(ModeInfo *mi, double umin, double umax, m = (j+k); o = l*(numu+1)+m; glTexCoord2fv(&pp->tex[2*o]); - if (pp->colors != COLORS_TWOSIDED) + if (pp->colors != COLORS_ONESIDED && pp->colors != COLORS_TWOSIDED) { glColor3fv(&pp->col[4*o]); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, @@ -1046,7 +1156,7 @@ static void gen_texture(ModeInfo *mi) glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); - glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,TEX_DIMENSION,TEX_DIMENSION,0, + glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE,TEX_DIMENSION,TEX_DIMENSION,0, GL_LUMINANCE,GL_UNSIGNED_BYTE,texture); } @@ -1096,6 +1206,10 @@ static void init(ModeInfo *mi) pp->dd = init_deform*0.001; pp->defdir = -1; + pp->rho = frand(360.0); + pp->sigma = frand(360.0); + pp->tau = frand(360.0); + pp->offset3d[0] = 0.0; pp->offset3d[1] = 0.0; pp->offset3d[2] = -1.8; @@ -1241,6 +1355,18 @@ static void display_romanboy(ModeInfo *mi) if (pp->umove < 0.0) pp->umove += 2.0*M_PI; } + if (pp->change_colors) + { + pp->rho += DRHO; + if (pp->rho >= 360.0) + pp->rho -= 360.0; + pp->sigma += DSIGMA; + if (pp->sigma >= 360.0) + pp->sigma -= 360.0; + pp->tau += DTAU; + if (pp->tau >= 360.0) + pp->tau -= 360.0; + } } glMatrixMode(GL_PROJECTION); @@ -1269,16 +1395,10 @@ static void display_romanboy(ModeInfo *mi) ENTRYPOINT void reshape_romanboy(ModeInfo *mi, int width, int height) { romanboystruct *pp = &romanboy[MI_SCREEN(mi)]; - int y = 0; - - if (width > height * 5) { /* tiny window: show middle */ - height = width; - y = -height/2; - } pp->WindW = (GLint)width; pp->WindH = (GLint)height; - glViewport(0,y,width,height); + glViewport(0,0,width,height); pp->aspect = (GLfloat)width/(GLfloat)height; } @@ -1402,6 +1522,10 @@ ENTRYPOINT void init_romanboy(ModeInfo *mi) { pp->colors = random() % NUM_COLORS; } + else if (!strcasecmp(color_mode,"one-sided")) + { + pp->colors = COLORS_ONESIDED; + } else if (!strcasecmp(color_mode,"two-sided")) { pp->colors = COLORS_TWOSIDED; @@ -1419,6 +1543,8 @@ ENTRYPOINT void init_romanboy(ModeInfo *mi) pp->colors = random() % NUM_COLORS; } + pp->change_colors = change_colors; + /* Set the view mode. */ if (!strcasecmp(view_mode,"random")) { diff --git a/hacks/glx/romanboy.man b/hacks/glx/romanboy.man index 2957a0e..e4e947b 100644 --- a/hacks/glx/romanboy.man +++ b/hacks/glx/romanboy.man @@ -20,9 +20,11 @@ smoothly deforms between the Roman surface and the Boy surface. [\-distance-bands] [\-direction-bands] [\-colors \fIcolor-scheme\fP] +[\-onesided-colors] [\-twosided-colors] [\-distance-colors] [\-direction-colors] +[\-change-colors] [\-view-mode \fIview-mode\fP] [\-walk] [\-turn] @@ -59,26 +61,27 @@ non-orientable). The real projective plane is a model for the projective geometry in 2d space. One point can be singled out as the origin. A line can be singled out as the line at infinity, i.e., a line that lies at an -infinite distance to the origin. The line at infinity is -topologically a circle. Points on the line at infinity are also used -to model directions in projective geometry. The origin can be -visualized in different manners. When using distance colors, the -origin is the point that is displayed as fully saturated red, which is -easier to see as the center of the reddish area on the projective -plane. Alternatively, when using distance bands, the origin is the -center of the only band that projects to a disk. When using direction -bands, the origin is the point where all direction bands collapse to a -point. Finally, when orientation markers are being displayed, the -origin the the point where all orientation markers are compressed to a -point. The line at infinity can also be visualized in different ways. -When using distance colors, the line at infinity is the line that is -displayed as fully saturated magenta. When two-sided colors are used, -the line at infinity lies at the points where the red and green -"sides" of the projective plane meet (of course, the real projective -plane only has one side, so this is a design choice of the -visualization). Alternatively, when orientation markers are being -displayed, the line at infinity is the place where the orientation -markers change their orientation. +infinite distance to the origin. The line at infinity, like all lines +in the projective plane, is topologically a circle. Points on the +line at infinity are also used to model directions in projective +geometry. The origin can be visualized in different manners. When +using distance colors (and using static colors), the origin is the +point that is displayed as fully saturated red, which is easier to see +as the center of the reddish area on the projective plane. +Alternatively, when using distance bands, the origin is the center of +the only band that projects to a disk. When using direction bands, +the origin is the point where all direction bands collapse to a point. +Finally, when orientation markers are being displayed, the origin the +the point where all orientation markers are compressed to a point. +The line at infinity can also be visualized in different ways. When +using distance colors (and using static colors), the line at infinity +is the line that is displayed as fully saturated magenta. When +two-sided (and static) colors are used, the line at infinity lies at +the points where the red and green "sides" of the projective plane +meet (of course, the real projective plane only has one side, so this +is a design choice of the visualization). Alternatively, when +orientation markers are being displayed, the line at infinity is the +place where the orientation markers change their orientation. .PP Note that when the projective plane is displayed with bands, the orientation markers are placed in the middle of the bands. For @@ -114,23 +117,27 @@ origin) is a Moebius strip, which also shows that the projective plane is non-orientable. .PP Finally, the colors with with the projective plane is drawn can be set -to two-sided, distance, or direction. In two-sided mode, the -projective plane is drawn with red on one "side" and green on the -"other side". As described above, the projective plane only has one -side, so the color jumps from red to green along the line at infinity. -This mode enables you to see that the projective plane is -non-orientable. In distance mode, the projective plane is displayed -with fully saturated colors that depend on the distance of the points -on the projective plane to the origin. The origin is displayed in -red, the line at infinity is displayed in magenta. If the projective -plane is displayed as distance bands, each band will be displayed with -a different color. In direction mode, the projective plane is -displayed with fully saturated colors that depend on the angle of the -points on the projective plane with respect to the origin. Angles in -opposite directions to the origin (e.g., 15 and 205 degrees) are -displayed in the same color since they are projectively equivalent. -If the projective plane is displayed as direction bands, each band -will be displayed with a different color. +to one-sided, two-sided, distance, or direction. In one-sided mode, +the projective plane is drawn with the same color on both "sides." In +two-sided mode (using static colors), the projective plane is drawn +with red on one "side" and green on the "other side." As described +above, the projective plane only has one side, so the color jumps from +red to green along the line at infinity. This mode enables you to see +that the projective plane is non-orientable. If changing colors are +used in two-sided mode, changing complementary colors are used on the +respective "sides." In distance mode, the projective plane is +displayed with fully saturated colors that depend on the distance of +the points on the projective plane to the origin. If static colors +are used, the origin is displayed in red, while the line at infinity +is displayed in magenta. If the projective plane is displayed as +distance bands, each band will be displayed with a different color. +In direction mode, the projective plane is displayed with fully +saturated colors that depend on the angle of the points on the +projective plane with respect to the origin. Angles in opposite +directions to the origin (e.g., 15 and 205 degrees) are displayed in +the same color since they are projectively equivalent. If the +projective plane is displayed as direction bands, each band will be +displayed with a different color. .PP The rotation speed for each of the three coordinate axes around which the projective plane rotates can be chosen. @@ -230,18 +237,23 @@ to color the projective plane. .B \-colors random Display the projective plane with a random color scheme (default). .TP 8 +.B \-colors onesided \fP(Shortcut: \fB\-onesided-colors\fP) +Display the projective plane with a single color. +.TP 8 .B \-colors twosided \fP(Shortcut: \fB\-twosided-colors\fP) -Display the projective plane with two colors: red on one "side" and -green on the "other side." Note that the line at infinity lies at the +Display the projective plane with two colors: one color one "side" and +the complementary color on the "other side." For static colors, the +colors are red and green. Note that the line at infinity lies at the points where the red and green "sides" of the projective plane meet, i.e., where the orientation of the projective plane reverses. .TP 8 .B \-colors distance \fP(Shortcut: \fB\-distance-colors\fP) Display the projective plane with fully saturated colors that depend on the distance of the points on the projective plane to the origin. -The origin is displayed in red, the line at infinity is displayed in -magenta. If the projective plane is displayed as distance bands, each -band will be displayed with a different color. +For static colors, the origin is displayed in red, while the line at +infinity is displayed in magenta. If the projective plane is +displayed as distance bands, each band will be displayed with a +different color. .TP 8 .B \-colors direction \fP(Shortcut: \fB\-direction-colors\fP) Display the projective plane with fully saturated colors that depend @@ -251,6 +263,16 @@ degrees) are displayed in the same color since they are projectively equivalent. If the projective plane is displayed as direction bands, each band will be displayed with a different color. .PP +The following options determine whether the colors with which the +projective plane is displayed are static or are changing dynamically. +.TP 8 +.B \-change-colors +Change the colors with which the projective plane is displayed +dynamically. +.TP 8 +.B \-no-change-colors +Use static colors to display the projective plane (default). +.PP The following three options are mutually exclusive. They determine how to view the projective plane. .TP 8 @@ -378,7 +400,7 @@ stored in the RESOURCE_MANAGER property. .BR X (1), .BR xscreensaver (1) .SH COPYRIGHT -Copyright \(co 2013-2014 by Carsten Steger. Permission to use, copy, +Copyright \(co 2013-2020 by Carsten Steger. Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright @@ -387,4 +409,4 @@ No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Carsten Steger <carsten@mirsanmir.org>, 03-oct-2014. +Carsten Steger <carsten@mirsanmir.org>, 06-jan-2020. diff --git a/hacks/glx/sonar-icmp.c b/hacks/glx/sonar-icmp.c index 961dcf5..658074b 100644 --- a/hacks/glx/sonar-icmp.c +++ b/hacks/glx/sonar-icmp.c @@ -1,4 +1,4 @@ -/* sonar, Copyright (c) 1998-2019 Jamie Zawinski and Stephen Martin +/* sonar, Copyright (c) 1998-2020 Jamie Zawinski and Stephen Martin * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -939,6 +939,7 @@ send_ping (ping_data *pd, const sonar_bogie *b) struct ICMP *icmph; const char *token = "org.jwz.xscreensaver.sonar"; char *host_id; + struct timeval tval; unsigned long pcktsiz = (sizeof(struct ICMP) + sizeof(struct timeval) + sizeof(socklen_t) + pb->addrlen + @@ -956,12 +957,16 @@ send_ping (ping_data *pd, const sonar_bogie *b) ICMP_CHECKSUM(icmph) = 0; ICMP_ID(icmph) = pd->pid; ICMP_SEQ(icmph) = pd->seq++; + /* struct timeval needs alignment, so we first use aligned buffer for + gettimeofday() and later copy the result to packet buffer + */ # ifdef GETTIMEOFDAY_TWO_ARGS - gettimeofday((struct timeval *) &packet[sizeof(struct ICMP)], + gettimeofday((struct timeval *) &tval, (struct timezone *) 0); # else - gettimeofday((struct timeval *) &packet[sizeof(struct ICMP)]); + gettimeofday((struct timeval *) &tval); # endif + memcpy(&packet[sizeof(struct ICMP)], &tval, sizeof tval); /* We store the sockaddr of the host we're pinging in the packet, and parse that out of the return packet later (see get_ping() for why). @@ -1068,7 +1073,7 @@ get_ping (sonar_sensor_data *ssd) int result; u_char packet[1024]; struct timeval now; - struct timeval *then; + struct timeval then; struct ip *ip; int iphdrlen; struct ICMP *icmph; @@ -1132,7 +1137,10 @@ get_ping (sonar_sensor_data *ssd) ip = (struct ip *) packet; iphdrlen = IP_HDRLEN(ip) << 2; icmph = (struct ICMP *) &packet[iphdrlen]; - then = (struct timeval *) &packet[iphdrlen + sizeof(struct ICMP)]; + /* struct timeval data in packet is not aligned, move the data to + the aligned buffer + */ + memcpy(&then, &packet[iphdrlen + sizeof(struct ICMP)], sizeof then); /* Ignore anything but ICMP Replies */ @@ -1221,7 +1229,7 @@ get_ping (sonar_sensor_data *ssd) bl = new; { - double msec = delta(then, &now) / 1000.0; + double msec = delta(&then, &now) / 1000.0; if (pd->times_p) { @@ -1694,7 +1702,7 @@ sonar_init_ping (Display *dpy, char **error_ret, char **desc_ret, fprintf (stderr, "%s: unable to open icmp socket\n", progname); /* Disavow privs */ - setuid(getuid()); + if (setuid(getuid()) == -1) abort(); pd->pid = getpid() & 0xFFFF; pd->seq = 0; diff --git a/hacks/glx/sonar.c b/hacks/glx/sonar.c index ddbb79f..e4e0b86 100644 --- a/hacks/glx/sonar.c +++ b/hacks/glx/sonar.c @@ -1,4 +1,4 @@ -/* sonar, Copyright (c) 1998-2018 Jamie Zawinski and Stephen Martin +/* sonar, Copyright (c) 1998-2020 Jamie Zawinski and Stephen Martin * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -935,7 +935,11 @@ init_sensor (ModeInfo *mi) ping_arg, ping_timeout, resolve_p, times_p, debug_p); else - setuid(getuid()); /* Disavow privs if not pinging. */ + { /* Disavow privs if not pinging. */ + if (setuid(getuid()) == -1) abort(); + } + + setuid(getuid()); sp->start_time = double_time (); /* for error message timing */ diff --git a/hacks/glx/starwars.c b/hacks/glx/starwars.c index bccd568..0f1457a 100644 --- a/hacks/glx/starwars.c +++ b/hacks/glx/starwars.c @@ -69,6 +69,7 @@ #define DEF_LINES "125" #define DEF_STEPS "35" #define DEF_SPIN "0.03" +#define DEF_SATURATION "0.3" #define DEF_SIZE "-1" #define DEF_COLUMNS "-1" #define DEF_LINE_WRAP "True" @@ -130,6 +131,7 @@ static sws_configuration *scs = NULL; static int max_lines; static int scroll_steps; static float star_spin; +static float star_saturation; static float font_size; static int target_columns; static int wrap_p; @@ -145,9 +147,11 @@ static XrmOptionDescRec opts[] = { {"-lines", ".lines", XrmoptionSepArg, 0 }, {"-steps", ".steps", XrmoptionSepArg, 0 }, {"-spin", ".spin", XrmoptionSepArg, 0 }, + {"-saturation", ".saturation",XrmoptionSepArg, 0 }, {"-size", ".size", XrmoptionSepArg, 0 }, {"-columns", ".columns", XrmoptionSepArg, 0 }, /*{"-font", ".font", XrmoptionSepArg, 0 },*/ + {"-program", ".program", XrmoptionSepArg, 0 }, {"-fade", ".fade", XrmoptionNoArg, "True" }, {"-no-fade", ".fade", XrmoptionNoArg, "False" }, {"-textures", ".textures", XrmoptionNoArg, "True" }, @@ -170,6 +174,7 @@ static argtype vars[] = { {&max_lines, "lines", "Integer", DEF_LINES, t_Int}, {&scroll_steps, "steps", "Integer", DEF_STEPS, t_Int}, {&star_spin, "spin", "Float", DEF_SPIN, t_Float}, + {&star_saturation,"saturation","Float", DEF_SATURATION,t_Float}, {&font_size, "size", "Float", DEF_SIZE, t_Float}, {&target_columns, "columns", "Integer", DEF_COLUMNS, t_Int}, {&wrap_p, "lineWrap", "Boolean", DEF_LINE_WRAP, t_Bool}, @@ -587,9 +592,10 @@ init_stars (ModeInfo *mi, int width, int height) glBegin (GL_POINTS); for (i = 0; i < nstars / steps; i++) { - glColor3f (0.6 + frand(0.3), - 0.6 + frand(0.3), - 0.6 + frand(0.3)); + GLfloat brightness = 0.9 - star_saturation; + glColor3f (brightness + frand(star_saturation), + brightness + frand(star_saturation), + brightness + frand(star_saturation)); glVertex2f (2 * size * (0.5 - frand(1.0)), 2 * size * (0.5 - frand(1.0))); } diff --git a/hacks/halftone.c b/hacks/halftone.c index ecdd84f..c4e2667 100644 --- a/hacks/halftone.c +++ b/hacks/halftone.c @@ -387,6 +387,7 @@ static const char *halftone_defaults [] = { #ifdef HAVE_MOBILE "*ignoreRotation: True", #endif + ".lowrez: true", /* Too slow on Retina screens otherwise */ 0 }; diff --git a/hacks/halo.c b/hacks/halo.c index c4d5ada..c45a99e 100644 --- a/hacks/halo.c +++ b/hacks/halo.c @@ -409,6 +409,8 @@ static const char *halo_defaults [] = { #ifdef HAVE_MOBILE "*ignoreRotation: True", #endif + ".lowrez: true", /* Too slow on Retina screens otherwise */ + /* But that looks crappy too. It's bad either way. */ 0 }; diff --git a/hacks/images/Makefile b/hacks/images/Makefile index 9f3d47c..4b0a239 100644 --- a/hacks/images/Makefile +++ b/hacks/images/Makefile @@ -39,6 +39,8 @@ gen/%_png.h: %.png clean: $(RM) -r gen +distclean:: clean + echo_tarfiles: @echo $(TARFILES) diff --git a/hacks/images/Makefile.in b/hacks/images/Makefile.in index 497ebfc..9a0375b 100644 --- a/hacks/images/Makefile.in +++ b/hacks/images/Makefile.in @@ -39,6 +39,8 @@ gen/%_png.h: %.png clean: $(RM) -r gen +distclean:: clean + echo_tarfiles: @echo $(TARFILES) diff --git a/hacks/moire2.c b/hacks/moire2.c index caf47c3..e69ad47 100644 --- a/hacks/moire2.c +++ b/hacks/moire2.c @@ -329,7 +329,7 @@ moire2_free (Display *dpy, Window window, void *closure) } static const char *moire2_defaults [] = { - ".lowrez: true", + ".lowrez: true", /* Too slow on Retina screens otherwise */ ".background: black", ".foreground: white", "*delay: 50000", diff --git a/hacks/munch.c b/hacks/munch.c index fe8f60f..c45e37f 100644 --- a/hacks/munch.c +++ b/hacks/munch.c @@ -1,6 +1,8 @@ /* Munching Squares and Mismunch * * Portions copyright 1992-2014 Jamie Zawinski <jwz@jwz.org> + * Portions Copyright 1997, Tim Showalter + * Portions Copyright 2004 Steven Hazel <sah@thalassocracy.org> * * Permission to use, copy, modify, distribute, and sell this * software and its documentation for any purpose is hereby @@ -10,16 +12,6 @@ * representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or * implied warranty. - * - * Portions Copyright 1997, Tim Showalter - * - * Permission is granted to copy, modify, and use this as long - * as this notice remains intact. No warranties are expressed or - * implied. CMU Sucks. - * - * Portions Copyright 2004 Steven Hazel <sah@thalassocracy.org> - * - * (The "mismunch" part). * * "munch.c" and "mismunch.c" merged by jwz, 29-Aug-2008. * diff --git a/hacks/munge-ad.pl b/hacks/munge-ad.pl index 7504d2c..8199b2f 100755 --- a/hacks/munge-ad.pl +++ b/hacks/munge-ad.pl @@ -57,7 +57,6 @@ my %disable = ( # Parse the RETIRED_EXES variable from the Makefiles to populate %disable. -# Duplicated in ../OSX/build-fntable.pl. # sub parse_makefiles() { foreach my $mf ( "Makefile.in", "glx/Makefile.in" ) { diff --git a/hacks/rd-bomb.c b/hacks/rd-bomb.c index 9628619..4b7131d 100644 --- a/hacks/rd-bomb.c +++ b/hacks/rd-bomb.c @@ -489,12 +489,21 @@ rd_draw (Display *dpy, Window win, void *closure) struct state *st = (struct state *) closure; Bool bump = False; + /* Let's compute N frames at once. This speeds up the progress of + the animation and the seething, but doesn't appreciably affect the + frame rate or CPU utilization. */ + int ii; + int chunk = 3; + for (ii = 0; ii < chunk; ii++) { + int i, j; pixack_frame(st, st->pd); + if (ii == chunk-1) { /* Only need to putimage on the final frame */ for (i = 0; i < st->array_width; i += st->width) for (j = 0; j < st->array_height; j += st->height) put_xshm_image(st->dpy, st->window, st->gc, st->image, 0, 0, i+st->array_x, j+st->array_y, st->width, st->height, &st->shm_info); + } st->array_x += st->array_dx; st->array_y += st->array_dy; @@ -526,6 +535,7 @@ rd_draw (Display *dpy, Window win, void *closure) } st->frame++; + } return st->delay; } diff --git a/hacks/recanim.c b/hacks/recanim.c index 69bf385..bd88b4b 100644 --- a/hacks/recanim.c +++ b/hacks/recanim.c @@ -1,4 +1,4 @@ -/* recanim, Copyright (c) 2014-2018 Jamie Zawinski <jwz@jwz.org> +/* recanim, Copyright (c) 2014-2020 Jamie Zawinski <jwz@jwz.org> * Record animation frames of the running screenhack. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -427,7 +427,9 @@ screenhack_record_anim_free (record_anim_state *st) st->fps, progname, type, st->fps); if (soundtrack) sprintf (cmd + strlen(cmd), - " -i '%s' -map 0:v:0 -map 1:a:0 -acodec aac", + " -i '%s' -map 0:v:0 -map 1:a:0 -acodec aac" + /* Truncate or pad audio to length of video */ + " -filter_complex '[1:0] apad' -shortest", soundtrack); sprintf (cmd + strlen(cmd), " -c:v libx264" @@ -439,7 +441,11 @@ screenhack_record_anim_free (record_anim_state *st) /*" 2>&-"*/, fn); fprintf (stderr, "%s: exec: %s\n", progname, cmd); - system (cmd); + /* Use empty body to kill warning from gcc -Wall with + "warning: ignoring return value of 'system', + declared with attribute warn_unused_result" + */ + if (system (cmd)) {} if (stat (fn, &s)) { diff --git a/hacks/scooter.c b/hacks/scooter.c new file mode 100644 index 0000000..9a66da6 --- /dev/null +++ b/hacks/scooter.c @@ -0,0 +1,957 @@ +/* -*- Mode: C; tab-width: 4 -*- */ +/* scooter -- a journey through space tunnel and stars */ + +/* + * scooter.c + * + * Copyright (c) 2001 Sven Thoennissen <posse@gmx.net> + * + * This program is based on the original "scooter", a blanker module from the + * Nightshift screensaver which is part of EGS (Enhanced Graphics System) on + * the Amiga computer. EGS has been developed by VIONA Development. + * + * + * (now the obligatory stuff) + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appear in all copies and that + * both that copyright notice and this permission notice appear in + * supporting documentation. + * + * This file is provided AS IS with no warranties of any kind. The author + * shall have no liability with respect to the infringement of copyrights, + * trade secrets or any patents by this file or any part thereof. In no + * event will the author be liable for any lost revenue or profits or + * other special, indirect and consequential damages. + * + * Changes: + * + * ??/??/2001 (Sven Thoennissen <posse@gmx.net>): Initial release + * 05/08/2019 (EoflaOE <eoflaoevicecity@gmail.com>): Ported to XScreenSaver + */ + +#ifdef STANDALONE +#define MODE_scooter +#define PROGCLASS "Scooter" +#define HACK_INIT init_scooter +#define HACK_DRAW draw_scooter +#define scooter_opts xlockmore_opts +#define DEFAULTS "*delay: 20000 \n" \ + "*count: 24 \n" \ + "*cycles: 5 \n" \ + "*size: 100 \n" \ + "*ncolors: 200 \n" \ + "*fullrandom: True \n" \ + "*verbose: False \n" \ + "*fpsSolid: true \n" \ + "*lowrez: True \n" +# define reshape_scooter 0 +# define scooter_handle_event 0 +#include "xlockmore.h" /* in xscreensaver distribution */ +#else /* STANDALONE */ +#include "xlock.h" /* in xlockmore distribution */ +#endif /* STANDALONE */ + +#ifdef MODE_scooter + +ModeSpecOpt scooter_opts = +{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL}; + +#ifdef USE_MODULES +ModStruct scooter_description = +{"scooter", "init_scooter", "draw_scooter", "release_scooter", + "refresh_scooter", "change_scooter", (char *) NULL, &scooter_opts, + 20000, 24, 5, 100, 64, 1.0, "", + "Shows a journey through space tunnel and stars", 0, NULL}; +/* + * count = number of doors + * cycles = speed (see MIN/MAX_SPEED below) + * size = number of stars + * + */ +#endif + +typedef struct { + int x, y, z; +} Vec3D; + +typedef struct { + int x, y, z; +} Angle3D; + +typedef struct { + int r, g, b; +} ColorRGB; + +typedef struct { + XPoint lefttop, rightbottom; +} Rect; + +typedef struct { + Vec3D coords[4]; /* lefttop, righttop, rightbottom, leftbottom */ + int zelement; + unsigned long color; + char freecolor; + char pad; +} Door; + +typedef struct { + int xpos, ypos; + int width, height; + int zelement; + short draw; +} Star; + +/* define this to see a pixel for each zelement */ +/* +#define _DRAW_ZELEMENTS +*/ + +typedef struct { + Vec3D pos; + Angle3D angle; +} ZElement; + +typedef struct { + Star *stars; + Door *doors; + ZElement *zelements; + int doorcount, ztotal, speed; + int zelements_per_door, zelement_distance, spectator_zelement; + int projnorm_z, rotationDuration, rotationStep, starcount; + Angle3D currentRotation, rotationDelta; + + /* doors color cycling stuff */ + ColorRGB begincolor, endcolor; + int colorcount, colorsteps; + + /* scale all stars and doors to window dimensions */ + float aspect_scale; + + Bool halt_scooter; +} scooterstruct; + +static scooterstruct *scooters = (scooterstruct *) NULL; + +#define MIN_DOORS 4 + +#define MIN_SPEED 1 +#define MAX_SPEED 10 + +#define SPACE_XY_FACTOR 10 + +#define DOOR_WIDTH (600*SPACE_XY_FACTOR) +#define DOOR_HEIGHT (400*SPACE_XY_FACTOR) + +/* stars distance from doors center */ +#define STAR_MIN_X (1000*SPACE_XY_FACTOR) +#define STAR_MIN_Y (750*SPACE_XY_FACTOR) +#define STAR_MAX_X (10000*SPACE_XY_FACTOR) +#define STAR_MAX_Y (7500*SPACE_XY_FACTOR) + +/* star size (random) */ +#define STAR_SIZE_MIN (2*SPACE_XY_FACTOR) +#define STAR_SIZE_MAX (64*SPACE_XY_FACTOR) + +/* greater values make scooter run harder curves, smaller values produce calm curves */ +#define DOOR_CURVEDNESS 14 + +/* 3d->2d projection (greater values create more fish-eye effect) */ +#define PROJECTION_DEGREE 2.4 + +/* this is my resolution at which scooter is in its original size, producing a 4:3 aspect ratio. + * all variables in this module are adjusted for this screen size; if scooter is run + * in windows with different size, it knows how to rescale itself. + */ +#define ASPECT_SCREENWIDTH 1152 +#define ASPECT_SCREENHEIGHT 864 + +/* we define our own sin/cos macros to be faaast ;-) (good old Amiga times) */ +#define SINUSTABLE_SIZE 0x8000 +#define SINUSTABLE_MASK 0x7fff +#define SIN(a) sintable[a & SINUSTABLE_MASK] +#define COS(a) sintable[(a+(SINUSTABLE_SIZE/4)) & SINUSTABLE_MASK] + +/* signum function */ +#define SGN(a) (a < 0 ? -1 : 1) + +static float *sintable = (float *) NULL; + +static void +randomcolor(ColorRGB *col) +{ + unsigned long n; + +/* col->r = NRAND(65536); + col->g = NRAND(65536); + col->b = NRAND(65536); +*/ +/* col->r = LRAND() & 0xffff; + col->g = LRAND() & 0xffff; + col->b = LRAND() & 0xffff; +*/ + /* this seems best */ + n = NRAND(0x1000000); + col->r = (n>>16)<<8; + col->g = ((n>>8) & 0xff)<<8; + col->b = (n & 0xff)<<8; +} + +static void +initdoorcolors(scooterstruct *sp) +{ + /* prepare initial values for nextdoorcolor() */ + + randomcolor(&sp->endcolor); + + sp->colorcount = 0; + sp->colorsteps = 0; +} + +static void nextdoorcolor(ModeInfo *mi, Door *door) +{ + scooterstruct *sp = &scooters[MI_SCREEN(mi)]; + Display *display = MI_DISPLAY(mi); + XColor xcol; + +/* comment this to color the doors from xlock's palette (created with saturation value) */ +#if 1 + if (door->freecolor) { + XFreeColors(display, MI_COLORMAP(mi), &(door->color), 1, 0); + door->freecolor = 0; + } + if (MI_NPIXELS(mi) <= 2) { + door->color = MI_WHITE_PIXEL(mi); + return; + } + + if (sp->colorcount >= sp->colorsteps) { + + /* init next color ramp */ + + sp->colorcount = 0; + sp->colorsteps = 8 + NRAND(32); + sp->begincolor = sp->endcolor; + randomcolor(&sp->endcolor); + } + + /* compute next color values */ + + xcol.red = sp->begincolor.r + ((sp-> endcolor.r - sp->begincolor.r) * + sp->colorcount / sp->colorsteps); + xcol.green = sp->begincolor.g + ((sp-> endcolor.g - sp->begincolor.g) * + sp->colorcount / sp->colorsteps); + xcol.blue = sp->begincolor.b + ((sp-> endcolor.b - sp->begincolor.b) * + sp->colorcount / sp->colorsteps); + xcol.pixel = 0; + xcol.flags = DoRed | DoGreen | DoBlue; + + sp->colorcount++; + + if (!XAllocColor(display, MI_COLORMAP(mi), &xcol)) { + /* fail safe */ + door->color = MI_WHITE_PIXEL(mi); + door->freecolor = 0; + } else { + door->color = xcol.pixel; + door->freecolor = 1; + } +#else + if (MI_NPIXELS(mi) > 2) { + if (++colorcount >= MI_NPIXELS(mi)) + colorcount = 0; + door->color = MI_PIXEL(mi,colorcount); + } else + door->color = MI_WHITE_PIXEL(mi); + return; +#endif +} + +static void +free_scooter(scooterstruct *sp) +{ + if (sp->doors != NULL) { + free(sp->doors); + sp->doors = (Door *) NULL; + } + if (sp->stars != NULL) { + free(sp->stars); + sp->stars = (Star *) NULL; + } + if (sp->zelements != NULL) { + free(sp->zelements); + sp->zelements = (ZElement *) NULL; + } +} + +static void release_scooter(ModeInfo *mi) +{ + if (scooters != NULL) { + int screen; + + for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) + free_scooter(&scooters[screen]); + free(scooters); + scooters = (scooterstruct *) NULL; + } + if (sintable != NULL) { + free(sintable); + sintable = (float *) NULL; + } +} + +static void init_scooter(ModeInfo *mi) +{ + int i; + scooterstruct *sp; + + if (scooters == NULL) { + if ((scooters = (scooterstruct *) calloc(MI_NUM_SCREENS(mi), + sizeof (scooterstruct))) == NULL) + return; + } + sp = &scooters[MI_SCREEN(mi)]; + sp->doorcount = MAX(MI_COUNT(mi),MIN_DOORS); + sp->speed = MI_CYCLES(mi); + sp->starcount = MI_SIZE(mi); + if (sp->starcount < 1) + sp->starcount = 1; + if (sp->speed < MIN_SPEED) + sp->speed = MIN_SPEED; + if (sp->speed > MAX_SPEED) + sp->speed = MAX_SPEED; + sp->zelements_per_door = 60; + sp->zelement_distance = 300; + sp->ztotal = sp->doorcount * sp->zelements_per_door; + /* sp->z_maxdepth = sp->ztotal * sp->zelement_distance; */ + if (sp->starcount > sp->ztotal) + sp->starcount = sp->ztotal; + + sp->halt_scooter = False; + + initdoorcolors(sp); + free_scooter(sp); + if (sintable == NULL) { + if ((sintable = (float *) malloc(sizeof(float) * + SINUSTABLE_SIZE)) == NULL) { + release_scooter(mi); + return; + } + } + for (i = 0; i < SINUSTABLE_SIZE; i++) { + sintable[i] = SINF(M_PI*2/SINUSTABLE_SIZE*i); + } + + if ((sp->doors = (Door *) malloc(sizeof(Door) * + sp->doorcount)) == NULL) { + return; + } + + if ((sp->zelements = (ZElement *) malloc(sizeof(ZElement) * + sp->ztotal)) == NULL) { + free_scooter(sp); + return; + } + for (i = 0; i < sp->doorcount; i++) { + sp->doors[i].zelement = + (sp->zelements_per_door * (i + 1)) - 1; + sp->doors[i].freecolor = 0; + nextdoorcolor(mi, &sp->doors[i]); + } + + for (i = 0; i < sp->ztotal; i++) { + sp->zelements[i].angle.x = 0; + sp->zelements[i].angle.y = 0; + sp->zelements[i].angle.z = 0; + } + + if ((sp->stars = (Star *) malloc(sizeof(Star) * + sp->starcount)) == NULL) { + free_scooter(sp); + return; + } + for (i = 0; i < sp->starcount; i++) { + sp->stars[i].zelement = sp->ztotal * i / sp->starcount; + sp->stars[i].draw = 0; + } + + sp->projnorm_z = 50 * 240; + sp->spectator_zelement = sp->zelements_per_door; + + sp->currentRotation.x = 0; + sp->currentRotation.y = 0; + sp->currentRotation.z = 0; + + sp->rotationDelta.x = 0; + sp->rotationDelta.y = 0; + sp->rotationDelta.z = 0; + + sp->rotationDuration = 1; + sp->rotationStep = 0; +} + +static void cleardoors(ModeInfo *mi) +{ + /* MI_CLEARWINDOW(mi);*/ + XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi)); +} + +/* Should be taken care of already... but just in case */ +#if !defined( __GNUC__ ) && !defined(__cplusplus) && !defined(c_plusplus) +#undef inline +#define inline /* */ +#endif +static inline float +projection (scooterstruct *sp, int zval) +{ + return (sp->projnorm_z / (PROJECTION_DEGREE * zval)); +/* this is another formula. it is not limited to z>0 but it pulls too strong towards the screen center */ +/* return (sp->projnorm_z * pow(1.22,-(zval/200*PROJ_CURVEDNESS)))*/ +} + +/* + + y + + ^ + | z + | . + | / + | / + | / + |/ +-+------------> x +/| + + rotation angles: + a = alpha (x-rotation), b = beta (y-rotation), c = gamma (z-rotation) + + x-axis rotation: + ( z )' = ( cos(a) -sin(a) ) ( z ) + ( y ) ( sin(a) cos(a) ) ( y ) + + y-axis rotation: + ( z )' = ( cos(b) -sin(b) ) ( z ) + ( x ) ( sin(b) cos(b) ) ( x ) + + z-axis rotation: + ( x )' = ( cos(c) -sin(c) ) ( x ) + ( y ) ( sin(c) cos(c) ) ( y ) +*/ + +static void +rotate_3d(Vec3D *src, Vec3D *dest, Angle3D *angle) +{ + Vec3D tmp; + float cosa = COS(angle->x), + cosb = COS(angle->y), + cosc = COS(angle->z), + sina = SIN(angle->x), + sinb = SIN(angle->y), + sinc = SIN(angle->z); + + /* rotate around X, Y and Z axis (see formulae above) */ + + /* X axis */ + tmp.z = src->z; + tmp.y = src->y; + dest->z = (int) (tmp.z * cosa - tmp.y * sina); + dest->y = (int) (tmp.z * sina + tmp.y * cosa); + + /* Y axis */ + tmp.z = dest->z; + tmp.x = src->x; + dest->z = (int) (tmp.z * cosb - tmp.x * sinb); + dest->x = (int) (tmp.z * sinb + tmp.x * cosb); + + /* Z axis */ + tmp.x = dest->x; + tmp.y = dest->y; + dest->x = (int) (tmp.x * cosc - tmp.y * sinc); + dest->y = (int) (tmp.x * sinc + tmp.y * cosc); +} + +static void calc_new_element(ModeInfo *mi) +{ + scooterstruct *sp = &scooters[MI_SCREEN(mi)]; + float rot = SIN((SINUSTABLE_SIZE/2)* + sp->rotationStep/sp->rotationDuration); + + /* change current rotation 3D angle */ + + if (sp->rotationStep++ >= sp->rotationDuration) { + + int fps = 1000000/MI_DELAY(mi); /* frames per second as timebase */ + + /* one rotation interval takes 10-30 seconds at speed 1. + */ + sp->rotationDuration = 10*fps + NRAND(20*fps); + + /* -DOOR_CURVEDNESS <= delta <= +DOOR_CURVEDNESS */ + sp->rotationDelta.x = + NRAND(DOOR_CURVEDNESS*2+1) - DOOR_CURVEDNESS; + sp->rotationDelta.y = + NRAND(DOOR_CURVEDNESS*2+1) - DOOR_CURVEDNESS; + sp->rotationDelta.z = + NRAND(DOOR_CURVEDNESS*2+1) - DOOR_CURVEDNESS; + + sp->rotationStep = 0; + } + + sp->currentRotation.x += (int) (rot * sp->rotationDelta.x); + sp->currentRotation.y += (int) (rot * sp->rotationDelta.y); + sp->currentRotation.z += (int) (rot * sp->rotationDelta.z); + + sp->currentRotation.x &= SINUSTABLE_MASK; + sp->currentRotation.y &= SINUSTABLE_MASK; + sp->currentRotation.z &= SINUSTABLE_MASK; +} + +static void shift_elements(ModeInfo *mi) +{ + scooterstruct *sp = &scooters[MI_SCREEN(mi)]; + int i, iprev; + Vec3D tmpvec; + Angle3D tmpangle; + + /* shift angles from zelements */ + + for (i = sp->speed; i < sp->ztotal; i++) { + sp->zelements[i - sp->speed].angle = sp->zelements[i].angle; + } + for (i = sp->ztotal - sp->speed; i < sp->ztotal; i++) { + calc_new_element(mi); + sp->zelements[i].angle = sp->currentRotation; + } + + /* calculate new 3D-coords from ALL zelements */ + + sp->zelements[sp->spectator_zelement].pos.x = 0; + sp->zelements[sp->spectator_zelement].pos.y = 0; + sp->zelements[sp->spectator_zelement].pos.z = + sp->zelement_distance * sp->spectator_zelement; + + for (i = sp->spectator_zelement - 1; i >= 0; --i) { + iprev = i + 1; + + tmpvec.x = 0; + tmpvec.y = 0; + tmpvec.z = - sp->zelement_distance; + tmpangle.x = sp->zelements[i].angle.x - + sp->zelements[sp->spectator_zelement].angle.x; + tmpangle.y = sp->zelements[i].angle.y - + sp->zelements[sp->spectator_zelement].angle.y; + tmpangle.z = sp->zelements[i].angle.z - + sp->zelements[sp->spectator_zelement].angle.z; + rotate_3d(&tmpvec, &(sp->zelements[i].pos), &tmpangle); + sp->zelements[i].pos.x += sp->zelements[iprev].pos.x; + sp->zelements[i].pos.y += sp->zelements[iprev].pos.y; + sp->zelements[i].pos.z += sp->zelements[iprev].pos.z; + } + + for (i = sp->spectator_zelement + 1; i < sp->ztotal; i++) { + iprev = i - 1; + + tmpvec.x = 0; + tmpvec.y = 0; + tmpvec.z = sp->zelement_distance; + tmpangle.x = sp->zelements[i].angle.x - + sp->zelements[sp->spectator_zelement].angle.x; + tmpangle.y = sp->zelements[i].angle.y - + sp->zelements[sp->spectator_zelement].angle.y; + tmpangle.z = sp->zelements[i].angle.z - + sp->zelements[sp->spectator_zelement].angle.z; + rotate_3d(&tmpvec, &(sp->zelements[i].pos), &tmpangle); + sp->zelements[i].pos.x += sp->zelements[iprev].pos.x; + sp->zelements[i].pos.y += sp->zelements[iprev].pos.y; + sp->zelements[i].pos.z += sp->zelements[iprev].pos.z; + } + + + /* shift doors and wrap around */ + + for (i = 0; i < sp->doorcount; i++) { + if ((sp->doors[i].zelement -= sp->speed) < 0) { + sp->doors[i].zelement += sp->ztotal; + nextdoorcolor(mi,&sp->doors[i]); + } + } + + /* shift stars */ + + for (i = 0; i < sp->starcount; i++) { + if ((sp->stars[i].zelement -= sp->speed) < 0) { + int rnd; + + sp->stars[i].zelement += sp->ztotal; + sp->stars[i].draw = 1; + + /* make sure new stars are outside doors */ + + rnd = NRAND(2*(STAR_MAX_X - STAR_MIN_X)) - + (STAR_MAX_X - STAR_MIN_X); + sp->stars[i].xpos = rnd + (STAR_MIN_X * SGN(rnd)); + + rnd = NRAND(2*(STAR_MAX_Y - STAR_MIN_Y)) - + (STAR_MAX_Y - STAR_MIN_Y); + sp->stars[i].ypos = rnd + (STAR_MIN_Y * SGN(rnd)); + + rnd = NRAND(STAR_SIZE_MAX - STAR_SIZE_MIN) + + STAR_SIZE_MIN; + sp->stars[i].width = rnd; + sp->stars[i].height = rnd * 3 / 4; + } + } +} + +static void door_3d(scooterstruct *sp, Door *door) +{ + ZElement *ze = &sp->zelements[door->zelement]; + Vec3D src; + Angle3D tmpangle; + + tmpangle.x = ze->angle.x - + sp->zelements[sp->spectator_zelement].angle.x; + tmpangle.y = ze->angle.y - + sp->zelements[sp->spectator_zelement].angle.y; + tmpangle.z = ze->angle.z - + sp->zelements[sp->spectator_zelement].angle.z; + + /* calculate 3d coords of all 4 edges */ + + src.x = -DOOR_WIDTH/2; + src.y = DOOR_HEIGHT/2; + src.z = 0; + rotate_3d(&src, &(door->coords[0]), &tmpangle); + door->coords[0].x += ze->pos.x; + door->coords[0].y += ze->pos.y; + door->coords[0].z += ze->pos.z; + + src.x = DOOR_WIDTH/2; + rotate_3d(&src, &(door->coords[1]), &tmpangle); + door->coords[1].x += ze->pos.x; + door->coords[1].y += ze->pos.y; + door->coords[1].z += ze->pos.z; + + src.y = -DOOR_HEIGHT/2; + rotate_3d(&src, &(door->coords[2]), &tmpangle); + door->coords[2].x += ze->pos.x; + door->coords[2].y += ze->pos.y; + door->coords[2].z += ze->pos.z; + + src.x = -DOOR_WIDTH/2; + rotate_3d(&src, &(door->coords[3]), &tmpangle); + door->coords[3].x += ze->pos.x; + door->coords[3].y += ze->pos.y; + door->coords[3].z += ze->pos.z; +} + +/* + * clip the line p1-p2 at the given rectangle + * + */ +static int clipline(XPoint *p1, XPoint *p2, Rect *rect) +{ + XPoint new1, new2, tmp; + float m; + + new1 = *p1; + new2 = *p2; + + /* entire line may not need clipping */ + + if (((new1.x >= rect->lefttop.x) && (new1.x <= rect->rightbottom.x)) + || ((new1.y >= rect->lefttop.y) && (new1.y <= rect->rightbottom.y)) + || ((new2.x >= rect->lefttop.x) && (new2.x <= rect->rightbottom.x)) + || ((new2.y >= rect->lefttop.y) && (new2.y <= rect->rightbottom.y))) + return 1; + + + /* first: clip y dimension */ + + /* p1 is above p2 */ + if (new1.y > new2.y) { + tmp = new1; + new1 = new2; + new2 = tmp; + } + + /* line could be totally out of view */ + if ((new2.y < rect->lefttop.y) || (new1.y > rect->rightbottom.y)) + return 0; + + m = (new2.x == new1.x) ? 0 : + ((float)(new2.y - new1.y) / (new2.x - new1.x)); + + if (new1.y < rect->lefttop.y) { + if (m) + new1.x += (int) ((rect->lefttop.y - new1.y)/m); + new1.y = rect->lefttop.y; + } + if (new2.y > rect->rightbottom.y) { + if (m) + new2.x -= (int) ((new2.y - rect->rightbottom.y)/m); + new2.y = rect->rightbottom.y; + } + + + /* clip x dimension */ + + /* p1 is left to p2 */ + if (new1.x > new2.x) { + tmp = new1; + new1 = new2; + new2 = tmp; + } + + if ((new2.x < rect->lefttop.x) || (new1.x > rect->rightbottom.x)) + return 0; + + m = (new2.x == new1.x) ? 0 : + ((float)(new2.y - new1.y) / (new2.x - new1.x)); + + if (new1.x < rect->lefttop.x) { + new1.y += (int) ((rect->lefttop.y - new1.y)*m); + new1.x = rect->lefttop.x; + } + if (new2.y > rect->rightbottom.y) { + new2.y -= (int) ((new2.y - rect->rightbottom.y)*m); + new2.x = rect->rightbottom.x; + } + + + /* push values */ + + *p1 = new1; + *p2 = new2; + + return 1; +} + +static void drawdoors(ModeInfo *mi) +{ + scooterstruct *sp = &scooters[MI_SCREEN(mi)]; + Display *display = MI_DISPLAY(mi); + Window window = MI_WINDOW(mi); + GC gc = MI_GC(mi); + int width = MI_WIDTH(mi), height = MI_HEIGHT(mi), + midx = width/2, midy = height/2; + int i, j; + Rect rect = { {0,0}, {0,0} }; + + rect.rightbottom.x = width - 1; + rect.rightbottom.y = height - 1; + XSetLineAttributes(display, gc, 2, LineSolid, CapNotLast, JoinRound); + +#ifdef _DRAW_ZELEMENTS + XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); + for (i= sp->spectator_zelement; i<ztotal; i++) { + register float proj; + XPoint p; + + proj = projection(sp, zelements[i].pos.z) * sp->aspect_scale; + p.x = midx + (sp->zelements[i].pos.x * proj / SPACE_XY_FACTOR); + p.y = midy - (sp->zelements[i].pos.y * proj / SPACE_XY_FACTOR); + XDrawPoint(display, window, gc, p.x, p.y); + } +#endif + + for (i = 0; i < sp->doorcount; i++) { + + register float proj; + XPoint lines[4], clip1, clip2; + + door_3d(sp, &sp->doors[i]); + + for (j=0; j<4; j++) { + if (sp->doors[i].coords[j].z <= 0) break; + + proj = projection(sp, sp->doors[i].coords[j].z) * sp->aspect_scale; + lines[j].x = midx + (int) (sp->doors[i].coords[j].x * + proj / SPACE_XY_FACTOR); + lines[j].y = midy - (int) (sp->doors[i].coords[j].y * + proj / SPACE_XY_FACTOR); + } + if (j<4) continue; + + XSetForeground(display, gc, sp->doors[i].color); + + for (j=0; j<4; j++) { + clip1 = lines[j]; + clip2 = lines[(j+1)%4]; + if (clipline(&clip1, &clip2, &rect)) + XDrawLine(display, window, gc, clip1.x, clip1.y, clip2.x, clip2.y); + } + } +} + +ENTRYPOINT void drawstars(ModeInfo *mi) +{ + scooterstruct *sp = &scooters[MI_SCREEN(mi)]; + Display *display = MI_DISPLAY(mi); + Window window = MI_WINDOW(mi); + GC gc = MI_GC(mi); + int width = MI_WIDTH(mi), height = MI_HEIGHT(mi), + midx = width/2, midy = height/2; + int i; + + for (i = 0; i < sp->starcount; i++) { + + float proj; + ZElement *ze = &sp->zelements[sp->stars[i].zelement]; + Vec3D tmpvec, coords; + Angle3D tmpangle; + XPoint lefttop, rightbottom; + + if (!sp->stars[i].draw) continue; + + + /* rotate star around its z-element, then add its position */ + + tmpangle.x = ze->angle.x - + sp->zelements[sp->spectator_zelement].angle.x; + tmpangle.y = ze->angle.y - + sp->zelements[sp->spectator_zelement].angle.y; + tmpangle.z = ze->angle.z - + sp->zelements[sp->spectator_zelement].angle.z; + + tmpvec.x = sp->stars[i].xpos; + tmpvec.y = sp->stars[i].ypos; + tmpvec.z = 0; + rotate_3d(&tmpvec, &coords, &tmpangle); + coords.x += ze->pos.x; + coords.y += ze->pos.y; + coords.z += ze->pos.z; + + if (coords.z <= 0) continue; + + + /* projection and clipping (trivial for a rectangle) */ + + proj = projection(sp, coords.z) * sp->aspect_scale; + + lefttop.x = midx + (int) ((coords.x - sp->stars[i].width/2) * + proj / SPACE_XY_FACTOR); + lefttop.y = midy - (int) ((coords.y + sp->stars[i].height/2) * + proj / SPACE_XY_FACTOR); + if (lefttop.x < 0) + lefttop.x = 0; + else if (lefttop.x >= width) + continue; + if (lefttop.y < 0) + lefttop.y = 0; + else if (lefttop.y >= height) + continue; + + rightbottom.x = midx + (int) ((coords.x + sp->stars[i].width/2) * + proj / SPACE_XY_FACTOR); + rightbottom.y = midy - (int) ((coords.y - sp->stars[i].height/2) * + proj / SPACE_XY_FACTOR); + if (rightbottom.x < 0) + continue; + else if (rightbottom.x >= width) + rightbottom.x = width - 1; + if (rightbottom.y < 0) + continue; + else if (rightbottom.y >= height) + rightbottom.y = height - 1; + + + /* in white color, small stars look darker than big stars */ + + XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); + + if ((lefttop.x == rightbottom.x) && + (lefttop.y == rightbottom.y)) { + /* star is exactly 1 pixel */ + XDrawPoint(display, window, gc, lefttop.x, lefttop.y); + } else if ((rightbottom.x - lefttop.x) + + (rightbottom.y - lefttop.y) == 1) { + /* star is 2 pixels wide or high */ + XDrawPoint(display, window, gc, + lefttop.x, lefttop.y); + XDrawPoint(display, window, gc, + rightbottom.x, rightbottom.y); + } else if ((rightbottom.x - lefttop.x == 1) && + (rightbottom.y - lefttop.y == 1)) { + + /* star is exactly 2x2 pixels. + * a 2x2 rectangle should be drawn faster by plotting all 4 pixels + * than by filling a rectangle (is this really so under X ?) + */ + + XDrawPoint(display, window, gc, + lefttop.x, lefttop.y); + XDrawPoint(display, window, gc, + rightbottom.x, lefttop.y); + XDrawPoint(display, window, gc, + lefttop.x, rightbottom.y); + XDrawPoint(display, window, gc, + rightbottom.x, rightbottom.y); + } else { + XFillRectangle(display, window, gc, + lefttop.x, lefttop.y, + rightbottom.x - lefttop.x, + rightbottom.y - lefttop.y); + } + } +} + +ENTRYPOINT void draw_scooter(ModeInfo *mi) +{ + scooterstruct *sp; + + if (scooters == NULL) + return; + sp = &scooters[MI_SCREEN(mi)]; + if (sp->doors == NULL) + return; + + cleardoors(mi); + + shift_elements(mi); + + /* With these scale factors, all doors are sized correctly for any window dimension. + * If aspect ratio is not 4:3, the smaller part of the window is used, e.g.: + * window = 1000x600 + * => door scale factor is like in a 800x600 window (not 1000x750) + */ + + if ((float)MI_WIDTH(mi)/MI_HEIGHT(mi) >= + (float)ASPECT_SCREENWIDTH/ASPECT_SCREENHEIGHT) { + /* window is wider than or equal 4:3 */ + sp->aspect_scale = (float)MI_HEIGHT(mi) / ASPECT_SCREENHEIGHT; + } else { + /* window is higher than 4:3 */ + sp->aspect_scale = (float)MI_WIDTH(mi) / ASPECT_SCREENWIDTH; + } + + drawstars(mi); + + drawdoors(mi); +} + +#if 0 +ENTRYPOINT void refresh_scooter(ModeInfo *mi) +{ + /* MI_CLEARWINDOW(mi); */ + XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi)); +} + +ENTRYPOINT void change_scooter(ModeInfo *mi) +{ + scooterstruct *sp; + + if (scooters == NULL) + return; + sp = &scooters[MI_SCREEN(mi)]; + + sp->halt_scooter = !sp->halt_scooter; +} +#endif + +#define free_scooter 0 +XSCREENSAVER_MODULE ("Scooter", scooter) + +#endif /* MODE_scooter */ diff --git a/hacks/scooter.man b/hacks/scooter.man new file mode 100644 index 0000000..492eb00 --- /dev/null +++ b/hacks/scooter.man @@ -0,0 +1,79 @@ +.TH XScreenSaver 1 "14-Mar-01" "X Version 11" +.SH NAME +scooter - shows a journey through space tunnel and stars +.SH SYNOPSIS +.B scooter +[\-display \fIhost:display.screen\fP] +[\-mono] +[\-delay \fImillisecs\fP] +[\-cycles \fIcycles\fP] +[\-count \fIcount\fP] +[\-size \fIsize\fP] +[\-ncolors \fIcolors\fP] +[\-window] [\-root] [\-install | \-noinstall] [\-visual \fIvisual\fP] +[\-fps | \-no\-fps] +[\-pair] +.SH DESCRIPTION +\fIscooter\fP is a screensaver that shows endless journey through space tunnel and stars. +.SH OPTIONS +.I scooter +accepts the following options: +.TP 8 +.B \-window +Draw on a newly-created window. This is the default. +.TP 8 +.B \-root +Draw on the root window. +.TP 8 +.B \-install +Install a private colormap for the window. +.TP 8 +.B \-visual \fIvisual\fP +Specify which visual to use. Legal values are the name of a visual class, +or the id number (decimal or hex) of a specific visual. +.TP 8 +.B \-delay \fImilliseconds\fP +How much of a delay should be introduced between steps of the animation. +Default 10, or about 1/100th second. +.TP 8 +.B \-cycles \fIcycles\fP +How fast/slow the screensaver is. \fIcycles\fP takes number of cycles. The default is 5 cycles. +.TP 8 +.B \-count \fIcount\fP +Specifies how many doors in a tunnel can be rendered. Minimum is 4. Default is 24. +.TP 8 +.B \-size \fIsize\fP +Specifies how many stars outside the tunnel can be rendered. Default is 100. +.TP 8 +.B \-ncolors \fIcolors\fP +Specifies number of colors. A number that is less than or equals 2 means monochrome. \-mono achieves the same thing. +.TP 8 +.B \-pair +Start screensaver in pairs (Not recommended) +.TP 8 +.B \-fps +Display the current frame rate and CPU load. +.SH ENVIRONMENT +.PP +.TP 8 +.B DISPLAY +to get the default host and display number. +.TP 8 +.B XENVIRONMENT +to get the name of a resource file that overrides the global resources +stored in the RESOURCE_MANAGER property. +.SH SEE ALSO +.BR X (1), +.BR xscreensaver (1), +.BR xscreensaver\-demo (1), +.BR xscreensaver\-getimage (1) +.SH COPYRIGHT +Copyright \(co 2001 by Sven Thoennissen. Permission to use, copy, modify, +distribute, and sell this software and its documentation for any purpose is +hereby granted without fee, provided that the above copyright notice appear +in all copies and that both that copyright notice and this permission notice +appear in supporting documentation. No representations are made about the +suitability of this software for any purpose. It is provided "as is" without +express or implied warranty. +.SH AUTHOR +Sven Thoennissen <posse@gmx.net> diff --git a/hacks/screenhack.c b/hacks/screenhack.c index fdd2e43..f292538 100644 --- a/hacks/screenhack.c +++ b/hacks/screenhack.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992-2017 Jamie Zawinski <jwz@jwz.org> +/* xscreensaver, Copyright (c) 1992-2020 Jamie Zawinski <jwz@jwz.org> * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -265,7 +265,7 @@ MapNotify_event_p (Display *dpy, XEvent *event, XPointer window) } -static Atom XA_WM_PROTOCOLS, XA_WM_DELETE_WINDOW; +static Atom XA_WM_PROTOCOLS, XA_WM_DELETE_WINDOW, XA_NET_WM_PID; /* Dead-trivial event handling: exits if "q" or "ESC" are typed. Exit if the WM_PROTOCOLS WM_DELETE_WINDOW ClientMessage is received. @@ -691,6 +691,7 @@ init_window (Display *dpy, Widget toplevel, const char *title) XWindowAttributes xgwa; XtPopup (toplevel, XtGrabNone); XtVaSetValues (toplevel, XtNtitle, title, NULL); + long pid = getpid(); /* Select KeyPress, and announce that we accept WM_DELETE_WINDOW. */ @@ -702,6 +703,8 @@ init_window (Display *dpy, Widget toplevel, const char *title) XChangeProperty (dpy, window, XA_WM_PROTOCOLS, XA_ATOM, 32, PropModeReplace, (unsigned char *) &XA_WM_DELETE_WINDOW, 1); + XChangeProperty (dpy, window, XA_NET_WM_PID, XA_CARDINAL, 32, + PropModeReplace, (unsigned char *)&pid, 1); } @@ -767,6 +770,7 @@ main (int argc, char **argv) XA_WM_PROTOCOLS = XInternAtom (dpy, "WM_PROTOCOLS", False); XA_WM_DELETE_WINDOW = XInternAtom (dpy, "WM_DELETE_WINDOW", False); + XA_NET_WM_PID = XInternAtom (dpy, "_NET_WM_PID", False); { char *v = (char *) strdup(strchr(screensaver_id, ' ')); diff --git a/hacks/webcollage b/hacks/webcollage index 5cc1196..47f86fe 100755 --- a/hacks/webcollage +++ b/hacks/webcollage @@ -3701,6 +3701,7 @@ sub update_imagemap($$$$$$$$) { </HEAD> <BODY> <DIV CLASS="webcollage_frame"> + <DIV CLASS="webcollage_box"></DIV> </DIV> </BODY> </HTML> diff --git a/hacks/xlockmore.c b/hacks/xlockmore.c index addfd4c..5ddf175 100644 --- a/hacks/xlockmore.c +++ b/hacks/xlockmore.c @@ -263,6 +263,13 @@ xlockmore_release_screens (ModeInfo *mi) } +static Bool +xlockmore_got_init (ModeInfo *mi) +{ + return mi->xlmft->got_init & (1ul << mi->screen_number); +} + + static void xlockmore_free_screens (ModeInfo *mi) { @@ -279,7 +286,8 @@ xlockmore_free_screens (ModeInfo *mi) int old_screen = mi->screen_number; for (mi->screen_number = 0; mi->screen_number < XLOCKMORE_NUM_SCREENS; ++mi->screen_number) { - xlmft->hack_free (mi); + if (xlockmore_got_init(mi)) + xlmft->hack_free (mi); /* got_init is reset in xlockmore_release_screens. */ } mi->screen_number = old_screen; } @@ -401,7 +409,7 @@ xlockmore_init (Display *dpy, Window window, const int size = XLOCKMORE_NUM_SCREENS; int i; for (i = 0; i < size; i++) { - if (! (xlmft->live_displays & (1 << i))) + if (! (xlmft->live_displays & (1ul << i))) break; } if (i >= size) abort(); @@ -571,16 +579,11 @@ xlockmore_clear (ModeInfo *mi) static void xlockmore_do_init (ModeInfo *mi) { - mi->xlmft->got_init |= 1 << mi->screen_number; xlockmore_clear (mi); mi->xlmft->hack_init (mi); -} - -static Bool -xlockmore_got_init (ModeInfo *mi) -{ - return mi->xlmft->got_init & (1 << mi->screen_number); + /* Do this last, so MI_INIT gets the old got_init. */ + mi->xlmft->got_init |= 1ul << mi->screen_number; } @@ -682,10 +685,13 @@ xlockmore_event (Display *dpy, Window window, void *closure, XEvent *event) if (screenhack_event_helper (mi->dpy, mi->window, event)) { /* If a clear is in progress, don't interrupt or restart it. */ - if (mi->needs_clear) + if (mi->needs_clear) { + if (mi->xlmft->hack_free) + mi->xlmft->hack_free (mi); mi->xlmft->got_init &= ~(1ul << mi->screen_number); - else + } else { mi->xlmft->hack_init (mi); + } return True; } } @@ -714,8 +720,10 @@ xlockmore_free (Display *dpy, Window window, void *closure) xlockmore_free returns. Thus, hack_free has to happen now, rather than after the final screen has been released. */ - if (mi->xlmft->hack_free) + if (mi->xlmft->hack_free && xlockmore_got_init(mi)) { mi->xlmft->hack_free (mi); + mi->xlmft->got_init &= ~(1ul << mi->screen_number); + } /* Find us in live_displays and clear that slot. */ assert (mi->xlmft->live_displays & (1ul << mi->screen_number)); @@ -761,8 +769,8 @@ xlockmore_mi_init (ModeInfo *mi, size_t state_size, void **state_array) /* Find the appropriate state object, clear it, and we're done. */ { - if (xlmft->hack_free) - xlmft->hack_free (mi); + if (xlmft->hack_free && xlockmore_got_init(mi)) + xlmft->hack_free (mi); /* Don't reset the got_init bit from MI_INIT. */ memset ((char *)(*xlmft->state_array) + mi->screen_number * state_size, 0, state_size); } diff --git a/hacks/xlyap.c b/hacks/xlyap.c index 9f1305b..4b4ad0c 100644 --- a/hacks/xlyap.c +++ b/hacks/xlyap.c @@ -1865,7 +1865,7 @@ xlyap_draw (Display *dpy, Window window, void *closure) } } - for (i = 0; i < 1000; i++) + for (i = 0; i < 2000; i++) if (complyap(st) == TRUE) { st->run = 0; diff --git a/hacks/xmatrix.c b/hacks/xmatrix.c index 45c5f9d..70f6516 100644 --- a/hacks/xmatrix.c +++ b/hacks/xmatrix.c @@ -1311,7 +1311,7 @@ hack_text (m_state *state) /* Stupid iPhone X bezel. #### This is the worst of all possible ways to do this! But how else? */ - if (state->xgwa.width == 2436 || state->xgwa.height == 2436) + if (state->xgwa.width == 1218 || state->xgwa.height == 1218) switch (state->mode) { case TRACE_TEXT_A: @@ -1319,7 +1319,7 @@ hack_text (m_state *state) case KNOCK: case NMAP: { - int off = 5 * (state->small_p ? 2 : 1); + int off = 2 * (state->small_p ? 2 : 1); if (state->xgwa.width > state->xgwa.height) { state->typing_left_margin += off; diff --git a/jwxyz/jwxyz-android.c b/jwxyz/jwxyz-android.c index 2b74b79..85ce924 100644 --- a/jwxyz/jwxyz-android.c +++ b/jwxyz/jwxyz-android.c @@ -1138,8 +1138,9 @@ jwxyz_gl_copy_area (Display *dpy, Drawable src, Drawable dst, GC gc, bind_drawable_fbo (rh, dst); finish_bind_drawable (dpy, dst); - jwxyz_gl_copy_area_write_tex_image (dpy, gc, src_x, src_y, width, height, - dst_x, dst_y); + jwxyz_gl_copy_area_write_tex_image (dpy, gc, src_x, src_y, + jwxyz_drawable_depth (src), + width, height, dst_x, dst_y); #else // Kumppa: 0.17 FPS diff --git a/jwxyz/jwxyz-gl.c b/jwxyz/jwxyz-gl.c index 369d16f..f1c13da 100644 --- a/jwxyz/jwxyz-gl.c +++ b/jwxyz/jwxyz-gl.c @@ -544,7 +544,7 @@ visual (Display *dpy) */ static void * -enqueue (Display *dpy, Drawable d, GC gc, int mode, size_t count, +enqueue (Display *dpy, Drawable d, GC gc, GLenum mode, size_t count, unsigned long pixel) { if (dpy->queue_size && @@ -947,7 +947,8 @@ jwxyz_gl_copy_area_read_tex_image (Display *dpy, unsigned src_height, } void -jwxyz_gl_copy_area_write_tex_image (Display *dpy, GC gc, int src_x, int src_y, +jwxyz_gl_copy_area_write_tex_image (Display *dpy, GC gc, + int src_x, int src_y, int src_depth, unsigned int width, unsigned int height, int dst_x, int dst_y) { @@ -964,7 +965,7 @@ jwxyz_gl_copy_area_write_tex_image (Display *dpy, GC gc, int src_x, int src_y, glBindTexture (dpy->gl_texture_target, dpy->textures[texture_rgba]); jwxyz_gl_draw_image (dpy, gc, dpy->gl_texture_target, tex_w, tex_h, - 0, 0, gc->depth, width, height, dst_x, dst_y, False); + 0, 0, src_depth, width, height, dst_x, dst_y, False); clear_texture (dpy); } @@ -1291,10 +1292,32 @@ FillPolygon (Display *dpy, Drawable d, GC gc, #define degrees(RAD) ((RAD) * 180.0 / M_PI) static void -arc_xy(GLfloat *p, double cx, double cy, double w2, double h2, double theta) +arc_xy (GLfloat *p, GLfloat cx, GLfloat cy, GLfloat w2, GLfloat h2, + GLfloat theta) { - p[0] = cos(theta) * w2 + cx; - p[1] = -sin(theta) * h2 + cy; + p[0] = cx + cosf(theta) * w2; + p[1] = cy - sinf(theta) * h2; +} + +static void +arc_xy2 (GLfloat *p, GLfloat cx, GLfloat cy, GLfloat w2, GLfloat h2, + GLfloat theta, GLfloat gglw) +{ + // The inner/outer contour of the stroke of an ellipse is not itself an + // ellipse. + + GLfloat ct = cosf(theta), st = sinf(theta); + + GLfloat w2st = w2 * st, h2ct = h2 * ct; + GLfloat w2ct = w2 * ct, h2st = h2 * st; + + GLfloat d = gglw / sqrtf(w2st * w2st + h2ct * h2ct); + GLfloat dh2ct = d * h2ct, dw2st = d * w2st; + + p[0] = cx + w2ct + dh2ct; + p[1] = cy - (h2st + dw2st); + p[2] = cx + w2ct - dh2ct; + p[3] = cy - (h2st - dw2st); } static unsigned @@ -1306,48 +1329,17 @@ mod_neg(int a, unsigned b) return a < 0 ? (b - 1) - (-(a + 1) % b) : a % b; } -/* TODO: Fill in arcs with line width > 1 */ static int draw_arc (Display *dpy, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height, int angle1, int angle2, Bool fill_p) { - int gglw = gc->gcv.line_width; - - if (fill_p || gglw <= 1) { - draw_arc_gl (dpy, d, gc, x, y, width, height, angle1, angle2, fill_p); - } - else { - int w1, w2, h1, h2, gglwh; - w1 = width + gglw; - h1 = height + gglw; - h2 = height - gglw; - w2 = width - gglw; - gglwh = gglw / 2; - int x1 = x - gglwh; - int x2 = x + gglwh; - int y1 = y - gglwh; - int y2 = y + gglwh; - //draw_arc_gl (dpy, d, gc, x, y, width, height, angle1, angle2, fill_p); - draw_arc_gl (dpy, d, gc, x1, y1, w1, h1, angle1, angle2, fill_p); - draw_arc_gl (dpy, d, gc, x2, y2, w2, h2, angle1, angle2, fill_p); - } - return 0; -} - - -int -draw_arc_gl (Display *dpy, Drawable d, GC gc, int x, int y, - unsigned int width, unsigned int height, - int angle1, int angle2, Bool fill_p) -{ - set_fg_gc(dpy, d, gc); - - /* Let's say the number of line segments needed to make a convincing circle is - 4*sqrt(radius). (But these arcs aren't necessarily circular arcs...) */ + /* Let's say the number of line segments needed to make a convincing circle + is 4*sqrt(radius). (But these arcs aren't necessarily circular arcs...) + */ - double w2 = width * 0.5f, h2 = height * 0.5f; - double a, b; /* Semi-major/minor axes. */ + GLfloat w2 = width * 0.5f, h2 = height * 0.5f; + GLfloat a, b; /* Semi-major/minor axes. */ if(w2 > h2) { a = w2; b = h2; @@ -1355,30 +1347,30 @@ draw_arc_gl (Display *dpy, Drawable d, GC gc, int x, int y, a = h2; b = w2; } - - const double two_pi = 2 * M_PI; - double amb = a - b, apb = a + b; - double h = (amb * amb) / (apb * apb); - // TODO: Math cleanup. - double C_approx = M_PI * apb * (1 + 3 * h / (10 + sqrtf(4 - 3 * h))); - double segments_f = 4 * sqrtf(C_approx / (2 * M_PI)); + const GLfloat tau = 2 * M_PI; + + GLfloat amb = a - b, apb = a + b; + GLfloat h = (amb * amb) / (apb * apb); + GLfloat D_approx = apb * (1 + 3 * h / (10 + sqrtf(4 - 3 * h))); + // From Ramanujan, "Modular Equations and Approximations to π". + // double C_approx = D_approx * M_PI; + GLfloat segments_f = sqrtf(8 * D_approx); // TODO: Explain how drawing works what with the points of overlapping arcs // matching up. - -#if 1 + unsigned segments_360 = segments_f; - + /* TODO: angle2 == 0. This is a tilted square with CapSquare. */ /* TODO: color, thick lines, CapNotLast for thin lines */ /* TODO: Transformations. */ - double segment_angle = two_pi / segments_360; + GLfloat segment_angle = tau / segments_360; const unsigned deg64 = 360 * 64; - const double rad_from_deg64 = two_pi / deg64; - + const GLfloat rad_from_deg64 = tau / deg64; + if (angle2 < 0) { angle1 += angle2; angle2 = -angle2; @@ -1388,79 +1380,128 @@ draw_arc_gl (Display *dpy, Drawable d, GC gc, int x, int y, if (angle2 > deg64) angle2 = deg64; // TODO: Handle circles special. - - double + + GLfloat angle1_f = angle1 * rad_from_deg64, angle2_f = angle2 * rad_from_deg64; - - if (angle2_f > two_pi) // TODO: Move this up. - angle2_f = two_pi; - - double segment1_angle_part = fmodf(angle1_f, segment_angle); - - unsigned segment1 = ((angle1_f - segment1_angle_part) / segment_angle) + 1.5; - double angle_2r = angle2_f - segment1_angle_part; + if (angle2_f > tau) // TODO: Move this up. + angle2_f = tau; + + GLfloat segment0_angle_part = fmodf(angle1_f, segment_angle); + + unsigned segment0 = ((angle1_f - segment0_angle_part) / segment_angle) + 1.5; + + GLfloat angle_2r = angle2_f - segment0_angle_part; unsigned segments = angle_2r / segment_angle; - + GLfloat cx = x + w2, cy = y + h2; - GLfloat *data = malloc((segments + 3) * sizeof(GLfloat) * 2); // TODO: Check result. - - GLfloat *data_ptr = data; + /* TODO: It would probably be better for vertices at the corners of the + elliptical sector/arc to be the intersection between a ray extending from + the ellipse center along one of the specified angles and one of the line + segments following the outline of the 360-degree ellipse, rather than + what it is now. + */ + if (fill_p) { - data_ptr[0] = cx; - data_ptr[1] = cy; + GLfloat *data = enqueue (dpy, d, gc, GL_TRIANGLE_STRIP, segments + 5, + gc->gcv.foreground); + GLfloat *data_ptr = data; + + unsigned segment1 = segment0 + segments / 2; + unsigned ds = segment1 - segment0 + 1; + unsigned ds2 = ds / 2; + + if (ds & 1) { + arc_xy (data_ptr, cx, cy, w2, h2, (segment0 + ds2) * segment_angle); + data_ptr += 2; + } + + unsigned s = ds2; + while (s) { + --s; + arc_xy (data_ptr, cx, cy, w2, h2, (segment0 + s) * segment_angle); + arc_xy (data_ptr + 2, cx, cy, w2, h2, + (segment1 - s) * segment_angle); + data_ptr += 4; + } + + arc_xy (data_ptr, cx, cy, w2, h2, angle1_f); + data_ptr[2] = cx; + data_ptr[3] = cy; + data_ptr[4] = cx; + data_ptr[5] = cy; + arc_xy (data_ptr + 6, cx, cy, w2, h2, angle1_f + angle2_f); + data_ptr += 8; + + unsigned segment2 = segment0 + segments; + ds = segment2 - segment1; + ds2 = ds / 2; + + for (s = 0; s != ds2; ++s) { + arc_xy (data_ptr, cx, cy, w2, h2, (segment1 + s) * segment_angle); + arc_xy (data_ptr + 2, cx, cy, w2, h2, + (segment2 - s - 1) * segment_angle); + data_ptr += 4; + } + + if (ds & 1) { + arc_xy (data_ptr, cx, cy, w2, h2, (segment1 + ds2) * segment_angle); + data_ptr += 2; + } + + finish_triangle_strip (dpy, data); + } else if (!gc->gcv.line_width) { + set_fg_gc(dpy, d, gc); + + GLfloat *data = malloc((segments + 2) * sizeof(GLfloat) * 2); // TODO: Check result. + GLfloat *data_ptr = data; + + arc_xy (data_ptr, cx, cy, w2, h2, angle1_f); data_ptr += 2; - } - - arc_xy (data_ptr, cx, cy, w2, h2, angle1_f); - data_ptr += 2; - - for (unsigned s = 0; s != segments; ++s) { - // TODO: Make sure values of theta for the following arc_xy call are between - // angle1_f and angle1_f + angle2_f. - arc_xy (data_ptr, cx, cy, w2, h2, (segment1 + s) * segment_angle); + + for (unsigned s = 0; s != segments; ++s) { + // TODO: Make sure values of theta for the following arc_xy call are between + // angle1_f and angle1_f + angle2_f. + arc_xy (data_ptr, cx, cy, w2, h2, (segment0 + s) * segment_angle); + data_ptr += 2; + } + + arc_xy (data_ptr, cx, cy, w2, h2, angle1_f + angle2_f); data_ptr += 2; - } - - arc_xy (data_ptr, cx, cy, w2, h2, angle1_f + angle2_f); - data_ptr += 2; - glDisableClientState (GL_TEXTURE_COORD_ARRAY); - glEnableClientState (GL_VERTEX_ARRAY); - - vertex_pointer (dpy, GL_FLOAT, 0, data); - glDrawArrays (fill_p ? GL_TRIANGLE_FAN : GL_LINE_STRIP, - 0, - (GLsizei)((data_ptr - data) / 2)); + glDisableClientState (GL_TEXTURE_COORD_ARRAY); + glEnableClientState (GL_VERTEX_ARRAY); - free(data); - -#endif - -#if 0 - unsigned segments = segments_f * (fabs(angle2) / (360 * 64)); - - glBegin (fill_p ? GL_TRIANGLE_FAN : GL_LINE_STRIP); - - if (fill_p /* && gc->gcv.arc_mode == ArcPieSlice */) - glVertex2f (cx, cy); - - /* TODO: This should fix the middle points of the arc so that the starting and ending points are OK. */ - - float to_radians = 2 * M_PI / (360 * 64); - float theta = angle1 * to_radians, d_theta = angle2 * to_radians / segments; - - for (unsigned s = 0; s != segments + 1; ++s) /* TODO: This is the right number of segments, yes? */ - { - glVertex2f(cos(theta) * w2 + cx, -sin(theta) * h2 + cy); - theta += d_theta; + vertex_pointer (dpy, GL_FLOAT, 0, data); + glDrawArrays (fill_p ? GL_TRIANGLE_FAN : GL_LINE_STRIP, + 0, + (GLsizei)((data_ptr - data) / 2)); + + free(data); + } else { + GLfloat gglw = gc->gcv.line_width * 0.5f; + + GLfloat *data = enqueue (dpy, d, gc, GL_TRIANGLE_STRIP, 2 * segments + 4, + gc->gcv.foreground); + GLfloat *data_ptr = data; + + arc_xy2 (data_ptr, cx, cy, w2, h2, angle1_f, gglw); + data_ptr += 4; + + for (unsigned s = 0; s != segments; ++s) { + arc_xy2 (data_ptr, cx, cy, w2, h2, (segment0 + s) * segment_angle, + gglw); + data_ptr += 4; + } + + arc_xy2 (data_ptr, cx, cy, w2, h2, angle1_f + angle2_f, gglw); + data_ptr += 4; + + finish_triangle_strip (dpy, data); } - - glEnd (); -#endif - + return 0; } diff --git a/jwxyz/jwxyzI.h b/jwxyz/jwxyzI.h index 6a38d2e..f7560f7 100644 --- a/jwxyz/jwxyzI.h +++ b/jwxyz/jwxyzI.h @@ -165,6 +165,7 @@ extern void jwxyz_gl_copy_area_read_tex_image (Display *dpy, int dst_x, int dst_y); extern void jwxyz_gl_copy_area_write_tex_image (Display *dpy, GC gc, int src_x, int src_y, + int src_depth, unsigned int width, unsigned int height, int dst_x, int dst_y); diff --git a/po/POTFILES.in b/po/POTFILES.in index 38a89ef..d785843 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,4 +1,4 @@ -# Auto-generated: Tue Jul 9 20:31:29 PDT 2019 +# Auto-generated: Fri Mar 20 18:40:22 PDT 2020 driver/demo-Gtk-conf.c driver/demo-Gtk.c driver/screensaver-properties.desktop.in @@ -71,6 +71,7 @@ hacks/config/engine.xml hacks/config/epicycle.xml hacks/config/eruption.xml hacks/config/esper.xml +hacks/config/etruscanvenus.xml hacks/config/euler2d.xml hacks/config/extrusion.xml hacks/config/fadeplot.xml @@ -94,6 +95,7 @@ hacks/config/gears.xml hacks/config/geodesic.xml hacks/config/geodesicgears.xml hacks/config/gflux.xml +hacks/config/gibson.xml hacks/config/glblur.xml hacks/config/glcells.xml hacks/config/gleidescope.xml @@ -203,6 +205,7 @@ hacks/config/rotzoomer.xml hacks/config/rubik.xml hacks/config/rubikblocks.xml hacks/config/sballs.xml +hacks/config/scooter.xml hacks/config/shadebobs.xml hacks/config/sierpinski.xml hacks/config/sierpinski3d.xml @@ -92,6 +92,7 @@ $ ripples :== $'mydir'ripples $ rocks :== $'mydir'rocks $ rorschach :== $'mydir'rorschach $ rotzoomer :== $'mydir'rotzoomer +$ scooter :== $'mydir'scooter $ shadebobs :== $'mydir'shadebobs $ sierpinski :== $'mydir'sierpinski $ slidescreen :== $'mydir'slidescreen diff --git a/utils/version.h b/utils/version.h index b01396c..7a20c66 100644 --- a/utils/version.h +++ b/utils/version.h @@ -1,2 +1,2 @@ static const char screensaver_id[] = - "@(#)xscreensaver 5.43 (09-Jul-2019), by Jamie Zawinski (jwz@jwz.org)"; + "@(#)xscreensaver 5.44 (20-Mar-2020), by Jamie Zawinski (jwz@jwz.org)"; diff --git a/xscreensaver.spec b/xscreensaver.spec index 3fc0527..84931b5 100644 --- a/xscreensaver.spec +++ b/xscreensaver.spec @@ -1,5 +1,5 @@ %define name xscreensaver -%define version 5.43 +%define version 5.44 Summary: X screen saver and locker Name: %{name} |