README
Path: README
Modified: Fri Mar 26 21:16:37 JST 2004

GLanim

Jun Makino

Introduction

GLanim is a simple sample program to make interactive animations from N-body (mostly with small N, like N=3 to 100 or around) simulation output, using OpenGL and GLUT libraries.

Currently, GLanim consists of two sample programs, associated with test data files.

     threebody.rb + testdata
     testplot2.rb + xxx

threebody.rb shows an encounter between a binary and third body. Mass ratio of the initial binary is 10:1, and the third body has the mass same as the primary of the binary.

Sample MPEG animation created with thie program is at:

grape.astron.s.u-tokyo.ac.jp/pub/people/makino/animations/TNOdemos/anim-long.mpg

Testplot2.rb shows (I believe) a cold-collapse of a 250-body system.

Installing GLanim

They are simple ruby sources. Get the latest tarball from

grape.astron.s.u-tokyo.ac.jp/pub/people/makino/softwares/GLanim

and untar it by

  tar tvzf GLanim-*.tar.gz

at where you want to keep them.

It should create the directory GLanim-* (* is actually the version number) and directoy doc under it. doc/index.html contains this file and other documents.

License

Ruby’s License

www.ruby-lang.org/ja/LICENSE.txt

www.ruby-lang.org/en/LICENSE.txt

Running sample programs

ruby threebody.rb (or testplot2.rb) would run them, if you have all necessary libraries and packages installed.

System requirement

I developed and tested programs on Linux (Vine Linux 2.6). It should work on any Linux distributions or whatever Unix or MS Windows, as long as you can make Ruby and Ruby/OpenGL work.

Installing necessary libraries under Linux/Cygwin

I tested on Linux (Vine 2.6CR1) and some version of Cygwin. On both system things worked fine

Ruby

If you do not have ruby, you need to install it. Download the source from www.ruby-lang.org/en/ (download page: www.ruby-lang.org/en/20020102.html) and take a "stable version". Current samples are tested with version 1.8.1. Installing ruby should be pretty straightforward. If you have sudo working on your machine, you should be able to do:

   tar xvzf ruby-1.8.1.tar.gz
   cd ruby-1.8.1
   ./configure
   make
   sudo make install

If you do not have sudo, you need to replace the last part by "su" and then "make install"

OpenGL

Well, if you have a reasonably recent Linux distribution with XFree86 (version 4.0 or later), necessary GL libraries are most likely already there. If not, it would be probably simpler to update your XFree86 to a newer version than try to install OpenGL for an old version of XFree86.

GLUT

GLUT www.opengl.org/resources/libraries/glut.html is a simple toolkit library on top of OpenGL, which is supposed to make the application program platform independent (i.e., programs which use GLUT functions should be able to run both on Windows and Unix, even though OpenGL implementations on these platforms are not exactly the same).

Some (or many) of Linux distribution seems to come with GLUT installed. Try

      locate libglut.so

and if you find files like

      /usr/X11R6/lib/libglut.so.3
      /usr/X11R6/lib/libglut.so.3.7.1
      /usr/X11R6/lib/libglut.so

then you are done with GLUT. If not, well, you can download the source from

      http://www.opengl.org/resources/libraries/glut/glut_downloads.html

Or you can search for "glut rpm" to see if a rpm file suitable for your system is available or not.

If you decided to install GLUT from the source tar file, probably you want to look at the page: www.linuxforum.com/linux-nvidia-installation/instglut.html

The following is what I did:

    206  18:25   tar xvzf glut*z
    207  18:25   cd glut-3.7
    208  18:25   cd linux
    211  18:26   mv ../Glut.cf Glut.cf.orig
    212  18:26   copy Glut.cf ..
    213  18:26   cd ..
    214  18:26   copy Glut.cf Glut.cf.linux.org
    218  18:29   chmod +w Glut.cf
    219  18:29   locate libGL

 Edit  Glut.cf
       diff -C0 Glut.cf.linux.org Glut.cf
 *** Glut.cf.linux.org   1998-08-08 09:13:27.000000000 +0900
 --- Glut.cf     2004-03-21 18:31:05.000000000 +0900
 ***************
 *** 94,95 ****
 ! OPENGL = $(TOP)/../lib/libMesaGL.so /* modified per Mesa README PFM 6/31/96 */
 ! GLU = $(TOP)/../lib/libMesaGLU.so /* modified per Mesa README PFM 6/31/96 */
 --- 94,103 ----
 !
 ! # Change to remove Mesa references --- JM
 ! #OPENGL = $(TOP)/../lib/libMesaGL.so /* modified per Mesa README PFM 6/31/96 */
 ! #GLU = $(TOP)/../lib/libMesaGLU.so /* modified per Mesa README PFM 6/31/96 */
 !
 ! #OPENGL = /usr/X11R6/lib/libGL.so /* modified per Mesa README PFM 6/31/96 */
 ! #GLU = /usr/X11R6/lib/libGLU.so /* modified per Mesa README PFM 6/31/96 */
 ! OPENGL = -lGL
 ! GLU = -lGLU
 !

    220  18:31   ./mkmkfiles.imake
    221  18:32   cd lib/glut
    223  18:32   copy ../../linux/Makefile .
    224  18:32   mv Makefile Makefile.old
    225  18:32   copy ../../linux/Makefile .
    228  18:33   chmod +w Makefile
 Edit Makefile

     diff -C0 Makefile~ Makefile
 *** Makefile~   1998-08-08 09:13:27.000000000 +0900
 --- Makefile    2004-03-21 18:34:03.000000000 +0900
 ***************
 *** 486,487 ****
 ! OPENGL = $(TOP)/../lib/libMesaGL.so
 ! GLU = $(TOP)/../lib/libMesaGLU.so
 --- 486,489 ----
 ! #OPENGL = $(TOP)/../lib/libMesaGL.so
 ! #GLU = $(TOP)/../lib/libMesaGLU.so
 ! OPENGL = -lGL
 ! GLU = -lGLU
    229  18:34   make
    233  18:35   ln -s libglut.so.3.7 libglut.so
    234  18:35   ln -s libglut.so.3.7 libglut.so.3
    235  18:35   sudo cp -d libglut.* /usr/local/lib
    236  18:35   ls /usr/local/lib/*gl*
    237  18:35   cd ../gle
    238  18:35   make
    239  18:36   gcc -shared -o libgle.so.3.7 *.o
    240  18:36   ln -s libgle.so.3.7 libgle.so
    241  18:36   ln -s libgle.so.3.7 libgle.so.3
    242  18:36   sudo cp -d libgle.* /usr/local/lib
    243  18:36   cd ..
    244  18:36   cd mui
    246  18:36   make
    247  18:36   gcc -shared -o libmui.so.3.7 *.o
    248  18:36   ln -s libmui.so.3.7 libmui.so
    249  18:36   ln -s libmui.so.3.7 libmui.so.3
    250  18:36   sudo cp -d libmui.* /usr/local/lib
    251  18:37   ldconfig
    252  18:37   /sbin/ldconfig
    253  18:37   cd ../../progs/demos/ideas
    257  18:39   make
    258  18:39   ./ideas

Ruby/OpenGL

You need to download the source from raa.ruby-lang.org

raa.ruby-lang.org/list.rhtml?name=opengl

Follow the link at "Homepage:". This page contain some Japanese, but do not worry. Pick the latest one under "OpenGL Module". DO NOT follow the "Download:" link, since the file might not be the latest.

Then, something like the following should work:

   tar xvzf  rbogl-0.*.tgz
   cd opengl
   ruby extconf.rb
   make
   sudo make install

To see if the installation is done correctly or not, try

   cd sample
   ruby planet.rb

   In this sample program, you can use 5 keystrokes (in OpenGL
   graphics window, with title "planet.rb")
      D  do something
      d  do something else
      Y  do yet another something
      y  do yet another something
      ESC: quit program

Installing necessary libraries under Windows

Well, things are lots easier on Windows. If you download the Pragmatic Programmers’ Ruby install kit from

rubyinstaller.sourceforge.net

and run it, it comes with everything (Ruby/OpenGL etc). As the time of this writing, it seems there is some problem with ruby1.8.1 (ruby-181-11.exe). So if it failed to install, try an older version, like 1.8.0. You would still need some Cygwin utilities to untar the files.

Runing GLanim samples

Now you are in the point of being able to run the GLanim samples. Go back to the directory you placed threebody.rb and testplot3.rb, and try

 ruby threebody.rb

This should show the initial frame. To start animation, press mause left button. To quit, q or ESC. For other available commands, please read keyboard function in the main function of threebody.rb

On Windows, you should be able to just click the files in Explorer, if Ruby itself is installed correctly.

Changing the sample programs to match your need

See the main function in threebody.rb for (rudimentary) explanations.

Making (for example) GIF images for GIF/MPEG animations

Yo need to activate the two lines in "display" function (lines with "*" below)

 # for onetrip (useful for making GIF files)
 #*    exit
     elsif $frame <= 0
       $frame = $parray.size - 1
     end
 #   activate the next line (and the above "exit" to make GIF images of
 #   each frames
 #*  system "xwd -nobdrs -name threebody.rb|xwdtopnm|ppmtogif> #{$frame}.gif"

This will create one gif file for each image. You need to use gifmerge or mpeg_encode or whatever to make an animation gif or mpeg file.