#!/bin/bash
#####################################################################
#  Autor: Antonio Castro Snurmacher  (1.998)
#
#       pov (ver 1.0)
#
#       Esta versin esta dedicada a su inclusin en la
#       revista LinuxFocus   (freeware)
#
#  Este programa puede ser utilizado, distribuido, y modificado
#  libremente pero siempre se deber respetar la propiedad
#  intelectual de su autor. Esta cabecera debe ser conservada
#  tal cual en todas las modificaciones.
#
#  En caso de traduccin deber conservarse el texto original de
#  esta cabecera y aadirse la traduccin a continuacin de ella.
#
#  El autor renuncia a todo tipo de beneficio econmico y no se hace
#  responsable de los posibles perjuicios derivados del uso del mismo.
#
#  E-mail (acastro@ctv.es)
#
#####################################################################
#  Author: Antonio Castro Snurmacher  (1.998)
#
#       pov (ver 1.0)
#
#       This version has been written to be included in
#       the LinuxFocus magazine   (freeware)
#
#  This program can be used, distributed, and modified
#  freely but always has to respect the intellectual
#  property of the author. This header should be kept
#  untouched in every modification.
#
#  In case of translation the text of this header should be kept
#  and the translation will be added after it.
#
#  The author renounces to any kind of economic benefit
#  and he is not responsible for any damage derived from
#  the use of this script.
#
#  E-mail (acastro@ctv.es)
#
#####################################################################
usage(){
   echo "Usage: pov (project) (size=0..6) (quality=1..11)"
   echo
   echo "0) 40x30     (STD/20) No backup"
   echo "1) 80x60     (STD/10) No backup"
   echo "2) 100x75    (STD/8)  No backup"
   echo "3) 200x150   (STD/4)"
   echo "4) 266x200   (STD/3)"
   echo "5) 320x200 *"
   echo "6) 400x300   (STD/2)"
   echo "7) 640x480 *"
   echo "8) 800x600 *   (STD)"
   echo "9) 1024x768 *"
   echo
   echo "The projects should be located in the directory pointed by"
   echo "${HOMEPOV} and will use the same name for it and for"
   echo "the main source file *.pov"
   echo "(STD) is the standard resolution chosen."
   echo
   exit 1
}

newversion(){
mv ${PREFIX}.pov.8.gz ${PREFIX}.pov.9.gz 2> /dev/null
mv ${PREFIX}.pov.7.gz ${PREFIX}.pov.8.gz 2> /dev/null
mv ${PREFIX}.pov.6.gz ${PREFIX}.pov.7.gz 2> /dev/null
mv ${PREFIX}.pov.5.gz ${PREFIX}.pov.6.gz 2> /dev/null
mv ${PREFIX}.pov.4.gz ${PREFIX}.pov.5.gz 2> /dev/null
mv ${PREFIX}.pov.3 ${PREFIX}.pov.4 2> /dev/null
mv ${PREFIX}.pov.2 ${PREFIX}.pov.3 2> /dev/null
mv ${PREFIX}.pov.1 ${PREFIX}.pov.2 2> /dev/null
cp ${PREFIX}.pov   ${PREFIX}.pov.1
gzip ${PREFIX}.pov.4 2> /dev/null
}

#################################################
size(){
   export SAVE="yes"
   case  $1 in
      0) Width=40 ; Height=30; SAVE="no" ;;
      1) Width=80 ; Height=60  SAVE="no" ;;
      2) Width=100; Height=75  SAVE="no" ;;
      3) Width=200; Height=150;;
      4) Width=266; Height=200;;
      5) Width=320; Height=200;;
      6) Width=400 ;Height=300;;
      7) Width=640 ;Height=480;;
      8) Width=800 ;Height=600;;
      9) Width=1024;Height=768;;
      *) usage
   esac
}

quality(){
   case $1 in
        1) ;;
        2) ;;
        3) ;;
        4) ;;
        5) ;;
        6) ;;
        7) ;;
        8) ;;
        9) ;;
        10) ;;
        11) ;;
       *) usage
   esac
   export Quality=$1
}

####################### main ##############################
export HOMEPOV=`pwd`
export PROYECT=$1
export PREFIX=${HOMEPOV}/${PROYECT}
if [ $# != 3 ]
   then usage
fi
# change this:
export POVRAY=/usr/local/povray31g/povray31
#
size $2
quality $3
if [ $SAVE = "yes" ]
   then newversion
fi
cat <<-FIN > ${PREFIX}.ini
   Width=$Width
   Height=$Height
   Quality=$Quality
   Library_Path=${POVRAY}/include
   Input_File_Name=${PREFIX}.pov
   Output_to_File=on
   Output_File_Type=t
   Output_File_Name=${PREFIX}.tga
   verbose=on
   Post_Scene_Command=xv ${PREFIX}.tga
FIN
#   Output_File_Type=t
## Others height performace options ##
#   Antialias_Depth=3
#   Antialias=On
#   Antialias_Threshold=0.1
#   Jitter_Amount=0.5
#   Jitter=On

# Low priority, maybe I want to do other things.
nice -20 x-povray ${PREFIX}.ini

if [ $SAVE != "yes" ]
    then echo "Warning !! There is no backup of this version."

fi

