Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2190 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
Jul 17, 2004, 12:11:20 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: merged and copied all files from branches/chris into trunk. it all seems to be in propper order.

Location:
orxonox/trunk
Files:
2 deleted
18 edited
14 copied

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/config.h.in

    r1971 r2190  
    3434/* Define to 1 if you have the <memory.h> header file. */
    3535#undef HAVE_MEMORY_H
     36
     37/* Define to 1 if you have the <SDL/SDL.h> header file. */
     38#undef HAVE_SDL_SDL_H
    3639
    3740/* Define to 1 if you have the `sqrt' function. */
  • orxonox/trunk/configure

    r2018 r2190  
    17301730case `uname` in
    17311731  *MINGW*)
    1732     mingw=yes
     1732    mingw="yes"
    17331733    MSBITFIELDS="-mms-bitfields"
     1734    MWINDOWS="-mwindows"
    17341735    ;;
    17351736  *)
    1736     mingw=no
     1737    mingw="no"
    17371738    ;;
    17381739esac
     
    49004901    fi
    49014902fi
     4903
     4904## mingw CHECK
     4905if test $mingw = yes ; then
     4906        echo "$as_me:$LINENO: checking for main in -lmingw32" >&5
     4907echo $ECHO_N "checking for main in -lmingw32... $ECHO_C" >&6
     4908if test "${ac_cv_lib_mingw32_main+set}" = set; then
     4909  echo $ECHO_N "(cached) $ECHO_C" >&6
     4910else
     4911  ac_check_lib_save_LIBS=$LIBS
     4912LIBS="-lmingw32  $LIBS"
     4913cat >conftest.$ac_ext <<_ACEOF
     4914/* confdefs.h.  */
     4915_ACEOF
     4916cat confdefs.h >>conftest.$ac_ext
     4917cat >>conftest.$ac_ext <<_ACEOF
     4918/* end confdefs.h.  */
     4919
     4920
     4921int
     4922main ()
     4923{
     4924main ();
     4925  ;
     4926  return 0;
     4927}
     4928_ACEOF
     4929rm -f conftest.$ac_objext conftest$ac_exeext
     4930if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
     4931  (eval $ac_link) 2>conftest.er1
     4932  ac_status=$?
     4933  grep -v '^ *+' conftest.er1 >conftest.err
     4934  rm -f conftest.er1
     4935  cat conftest.err >&5
     4936  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     4937  (exit $ac_status); } &&
     4938         { ac_try='test -z "$ac_c_werror_flag"
     4939                         || test ! -s conftest.err'
     4940  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     4941  (eval $ac_try) 2>&5
     4942  ac_status=$?
     4943  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     4944  (exit $ac_status); }; } &&
     4945         { ac_try='test -s conftest$ac_exeext'
     4946  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     4947  (eval $ac_try) 2>&5
     4948  ac_status=$?
     4949  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     4950  (exit $ac_status); }; }; then
     4951  ac_cv_lib_mingw32_main=yes
     4952else
     4953  echo "$as_me: failed program was:" >&5
     4954sed 's/^/| /' conftest.$ac_ext >&5
     4955
     4956ac_cv_lib_mingw32_main=no
     4957fi
     4958rm -f conftest.err conftest.$ac_objext \
     4959      conftest$ac_exeext conftest.$ac_ext
     4960LIBS=$ac_check_lib_save_LIBS
     4961fi
     4962echo "$as_me:$LINENO: result: $ac_cv_lib_mingw32_main" >&5
     4963echo "${ECHO_T}$ac_cv_lib_mingw32_main" >&6
     4964if test $ac_cv_lib_mingw32_main = yes; then
     4965  FOUND_mingw32=yes
     4966fi
     4967
     4968        if test $FOUND_mingw32 = "yes"; then
     4969                LIBS="$LIBS -lmingw32"
     4970        fi
     4971fi
     4972
     4973## SDL CHECK
     4974
     4975#checking for SDL libs
     4976
     4977for ac_header in SDL/SDL.h
     4978do
     4979as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
     4980if eval "test \"\${$as_ac_Header+set}\" = set"; then
     4981  echo "$as_me:$LINENO: checking for $ac_header" >&5
     4982echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
     4983if eval "test \"\${$as_ac_Header+set}\" = set"; then
     4984  echo $ECHO_N "(cached) $ECHO_C" >&6
     4985fi
     4986echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
     4987echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
     4988else
     4989  # Is the header compilable?
     4990echo "$as_me:$LINENO: checking $ac_header usability" >&5
     4991echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
     4992cat >conftest.$ac_ext <<_ACEOF
     4993/* confdefs.h.  */
     4994_ACEOF
     4995cat confdefs.h >>conftest.$ac_ext
     4996cat >>conftest.$ac_ext <<_ACEOF
     4997/* end confdefs.h.  */
     4998$ac_includes_default
     4999#include <$ac_header>
     5000_ACEOF
     5001rm -f conftest.$ac_objext
     5002if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
     5003  (eval $ac_compile) 2>conftest.er1
     5004  ac_status=$?
     5005  grep -v '^ *+' conftest.er1 >conftest.err
     5006  rm -f conftest.er1
     5007  cat conftest.err >&5
     5008  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5009  (exit $ac_status); } &&
     5010         { ac_try='test -z "$ac_c_werror_flag"
     5011                         || test ! -s conftest.err'
     5012  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5013  (eval $ac_try) 2>&5
     5014  ac_status=$?
     5015  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5016  (exit $ac_status); }; } &&
     5017         { ac_try='test -s conftest.$ac_objext'
     5018  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5019  (eval $ac_try) 2>&5
     5020  ac_status=$?
     5021  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5022  (exit $ac_status); }; }; then
     5023  ac_header_compiler=yes
     5024else
     5025  echo "$as_me: failed program was:" >&5
     5026sed 's/^/| /' conftest.$ac_ext >&5
     5027
     5028ac_header_compiler=no
     5029fi
     5030rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
     5031echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
     5032echo "${ECHO_T}$ac_header_compiler" >&6
     5033
     5034# Is the header present?
     5035echo "$as_me:$LINENO: checking $ac_header presence" >&5
     5036echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
     5037cat >conftest.$ac_ext <<_ACEOF
     5038/* confdefs.h.  */
     5039_ACEOF
     5040cat confdefs.h >>conftest.$ac_ext
     5041cat >>conftest.$ac_ext <<_ACEOF
     5042/* end confdefs.h.  */
     5043#include <$ac_header>
     5044_ACEOF
     5045if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
     5046  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
     5047  ac_status=$?
     5048  grep -v '^ *+' conftest.er1 >conftest.err
     5049  rm -f conftest.er1
     5050  cat conftest.err >&5
     5051  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5052  (exit $ac_status); } >/dev/null; then
     5053  if test -s conftest.err; then
     5054    ac_cpp_err=$ac_c_preproc_warn_flag
     5055    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
     5056  else
     5057    ac_cpp_err=
     5058  fi
     5059else
     5060  ac_cpp_err=yes
     5061fi
     5062if test -z "$ac_cpp_err"; then
     5063  ac_header_preproc=yes
     5064else
     5065  echo "$as_me: failed program was:" >&5
     5066sed 's/^/| /' conftest.$ac_ext >&5
     5067
     5068  ac_header_preproc=no
     5069fi
     5070rm -f conftest.err conftest.$ac_ext
     5071echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
     5072echo "${ECHO_T}$ac_header_preproc" >&6
     5073
     5074# So?  What about this header?
     5075case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
     5076  yes:no: )
     5077    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
     5078echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
     5079    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
     5080echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
     5081    ac_header_preproc=yes
     5082    ;;
     5083  no:yes:* )
     5084    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
     5085echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
     5086    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
     5087echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
     5088    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
     5089echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
     5090    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
     5091echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
     5092    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
     5093echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
     5094    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
     5095echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
     5096    (
     5097      cat <<\_ASBOX
     5098## ------------------------------------------- ##
     5099## Report this to orxonox-dev@mail.datacore.ch ##
     5100## ------------------------------------------- ##
     5101_ASBOX
     5102    ) |
     5103      sed "s/^/$as_me: WARNING:     /" >&2
     5104    ;;
     5105esac
     5106echo "$as_me:$LINENO: checking for $ac_header" >&5
     5107echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
     5108if eval "test \"\${$as_ac_Header+set}\" = set"; then
     5109  echo $ECHO_N "(cached) $ECHO_C" >&6
     5110else
     5111  eval "$as_ac_Header=\$ac_header_preproc"
     5112fi
     5113echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
     5114echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
     5115
     5116fi
     5117if test `eval echo '${'$as_ac_Header'}'` = yes; then
     5118  cat >>confdefs.h <<_ACEOF
     5119#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
     5120_ACEOF
     5121
     5122else
     5123  { { echo "$as_me:$LINENO: error: cannot find SDL headers" >&5
     5124echo "$as_me: error: cannot find SDL headers" >&2;}
     5125   { (exit 1); exit 1; }; }
     5126fi
     5127
     5128done
     5129
     5130if test $mingw = no ; then
     5131        echo "$as_me:$LINENO: checking for main in -lSDL" >&5
     5132echo $ECHO_N "checking for main in -lSDL... $ECHO_C" >&6
     5133if test "${ac_cv_lib_SDL_main+set}" = set; then
     5134  echo $ECHO_N "(cached) $ECHO_C" >&6
     5135else
     5136  ac_check_lib_save_LIBS=$LIBS
     5137LIBS="-lSDL  $LIBS"
     5138cat >conftest.$ac_ext <<_ACEOF
     5139/* confdefs.h.  */
     5140_ACEOF
     5141cat confdefs.h >>conftest.$ac_ext
     5142cat >>conftest.$ac_ext <<_ACEOF
     5143/* end confdefs.h.  */
     5144
     5145
     5146int
     5147main ()
     5148{
     5149main ();
     5150  ;
     5151  return 0;
     5152}
     5153_ACEOF
     5154rm -f conftest.$ac_objext conftest$ac_exeext
     5155if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
     5156  (eval $ac_link) 2>conftest.er1
     5157  ac_status=$?
     5158  grep -v '^ *+' conftest.er1 >conftest.err
     5159  rm -f conftest.er1
     5160  cat conftest.err >&5
     5161  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5162  (exit $ac_status); } &&
     5163         { ac_try='test -z "$ac_c_werror_flag"
     5164                         || test ! -s conftest.err'
     5165  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5166  (eval $ac_try) 2>&5
     5167  ac_status=$?
     5168  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5169  (exit $ac_status); }; } &&
     5170         { ac_try='test -s conftest$ac_exeext'
     5171  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5172  (eval $ac_try) 2>&5
     5173  ac_status=$?
     5174  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5175  (exit $ac_status); }; }; then
     5176  ac_cv_lib_SDL_main=yes
     5177else
     5178  echo "$as_me: failed program was:" >&5
     5179sed 's/^/| /' conftest.$ac_ext >&5
     5180
     5181ac_cv_lib_SDL_main=no
     5182fi
     5183rm -f conftest.err conftest.$ac_objext \
     5184      conftest$ac_exeext conftest.$ac_ext
     5185LIBS=$ac_check_lib_save_LIBS
     5186fi
     5187echo "$as_me:$LINENO: result: $ac_cv_lib_SDL_main" >&5
     5188echo "${ECHO_T}$ac_cv_lib_SDL_main" >&6
     5189if test $ac_cv_lib_SDL_main = yes; then
     5190  FOUND_SDL=yes
     5191fi
     5192
     5193        if test "$FOUND_SDL" = "yes" ; then
     5194                LIBS="$LIBS -lSDL"
     5195        fi
     5196#   checking for Windows sdl library
     5197else
     5198    echo "$as_me:$LINENO: checking for main in -lsdlmain" >&5
     5199echo $ECHO_N "checking for main in -lsdlmain... $ECHO_C" >&6
     5200if test "${ac_cv_lib_sdlmain_main+set}" = set; then
     5201  echo $ECHO_N "(cached) $ECHO_C" >&6
     5202else
     5203  ac_check_lib_save_LIBS=$LIBS
     5204LIBS="-lsdlmain  $LIBS"
     5205cat >conftest.$ac_ext <<_ACEOF
     5206/* confdefs.h.  */
     5207_ACEOF
     5208cat confdefs.h >>conftest.$ac_ext
     5209cat >>conftest.$ac_ext <<_ACEOF
     5210/* end confdefs.h.  */
     5211
     5212
     5213int
     5214main ()
     5215{
     5216main ();
     5217  ;
     5218  return 0;
     5219}
     5220_ACEOF
     5221rm -f conftest.$ac_objext conftest$ac_exeext
     5222if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
     5223  (eval $ac_link) 2>conftest.er1
     5224  ac_status=$?
     5225  grep -v '^ *+' conftest.er1 >conftest.err
     5226  rm -f conftest.er1
     5227  cat conftest.err >&5
     5228  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5229  (exit $ac_status); } &&
     5230         { ac_try='test -z "$ac_c_werror_flag"
     5231                         || test ! -s conftest.err'
     5232  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5233  (eval $ac_try) 2>&5
     5234  ac_status=$?
     5235  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5236  (exit $ac_status); }; } &&
     5237         { ac_try='test -s conftest$ac_exeext'
     5238  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5239  (eval $ac_try) 2>&5
     5240  ac_status=$?
     5241  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5242  (exit $ac_status); }; }; then
     5243  ac_cv_lib_sdlmain_main=yes
     5244else
     5245  echo "$as_me: failed program was:" >&5
     5246sed 's/^/| /' conftest.$ac_ext >&5
     5247
     5248ac_cv_lib_sdlmain_main=no
     5249fi
     5250rm -f conftest.err conftest.$ac_objext \
     5251      conftest$ac_exeext conftest.$ac_ext
     5252LIBS=$ac_check_lib_save_LIBS
     5253fi
     5254echo "$as_me:$LINENO: result: $ac_cv_lib_sdlmain_main" >&5
     5255echo "${ECHO_T}$ac_cv_lib_sdlmain_main" >&6
     5256if test $ac_cv_lib_sdlmain_main = yes; then
     5257  FOUND_sdlmain=yes
     5258fi
     5259
     5260    if test "$FOUND_sdlmain" = "yes" ; then
     5261        LIBS="$LIBS -lsdlmain"
     5262    fi
     5263        echo "$as_me:$LINENO: checking for main in -lsdl" >&5
     5264echo $ECHO_N "checking for main in -lsdl... $ECHO_C" >&6
     5265if test "${ac_cv_lib_sdl_main+set}" = set; then
     5266  echo $ECHO_N "(cached) $ECHO_C" >&6
     5267else
     5268  ac_check_lib_save_LIBS=$LIBS
     5269LIBS="-lsdl  $LIBS"
     5270cat >conftest.$ac_ext <<_ACEOF
     5271/* confdefs.h.  */
     5272_ACEOF
     5273cat confdefs.h >>conftest.$ac_ext
     5274cat >>conftest.$ac_ext <<_ACEOF
     5275/* end confdefs.h.  */
     5276
     5277
     5278int
     5279main ()
     5280{
     5281main ();
     5282  ;
     5283  return 0;
     5284}
     5285_ACEOF
     5286rm -f conftest.$ac_objext conftest$ac_exeext
     5287if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
     5288  (eval $ac_link) 2>conftest.er1
     5289  ac_status=$?
     5290  grep -v '^ *+' conftest.er1 >conftest.err
     5291  rm -f conftest.er1
     5292  cat conftest.err >&5
     5293  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5294  (exit $ac_status); } &&
     5295         { ac_try='test -z "$ac_c_werror_flag"
     5296                         || test ! -s conftest.err'
     5297  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5298  (eval $ac_try) 2>&5
     5299  ac_status=$?
     5300  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5301  (exit $ac_status); }; } &&
     5302         { ac_try='test -s conftest$ac_exeext'
     5303  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5304  (eval $ac_try) 2>&5
     5305  ac_status=$?
     5306  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5307  (exit $ac_status); }; }; then
     5308  ac_cv_lib_sdl_main=yes
     5309else
     5310  echo "$as_me: failed program was:" >&5
     5311sed 's/^/| /' conftest.$ac_ext >&5
     5312
     5313ac_cv_lib_sdl_main=no
     5314fi
     5315rm -f conftest.err conftest.$ac_objext \
     5316      conftest$ac_exeext conftest.$ac_ext
     5317LIBS=$ac_check_lib_save_LIBS
     5318fi
     5319echo "$as_me:$LINENO: result: $ac_cv_lib_sdl_main" >&5
     5320echo "${ECHO_T}$ac_cv_lib_sdl_main" >&6
     5321if test $ac_cv_lib_sdl_main = yes; then
     5322  FOUND_sdl=yes
     5323fi
     5324
     5325        if test "$FOUND_sdl" = "yes" ; then
     5326                LIBS="$LIBS -lsdl"
     5327        fi
     5328fi
     5329
     5330#checking for pthread libs
     5331echo "$as_me:$LINENO: checking for main in -lpthread" >&5
     5332echo $ECHO_N "checking for main in -lpthread... $ECHO_C" >&6
     5333if test "${ac_cv_lib_pthread_main+set}" = set; then
     5334  echo $ECHO_N "(cached) $ECHO_C" >&6
     5335else
     5336  ac_check_lib_save_LIBS=$LIBS
     5337LIBS="-lpthread  $LIBS"
     5338cat >conftest.$ac_ext <<_ACEOF
     5339/* confdefs.h.  */
     5340_ACEOF
     5341cat confdefs.h >>conftest.$ac_ext
     5342cat >>conftest.$ac_ext <<_ACEOF
     5343/* end confdefs.h.  */
     5344
     5345
     5346int
     5347main ()
     5348{
     5349main ();
     5350  ;
     5351  return 0;
     5352}
     5353_ACEOF
     5354rm -f conftest.$ac_objext conftest$ac_exeext
     5355if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
     5356  (eval $ac_link) 2>conftest.er1
     5357  ac_status=$?
     5358  grep -v '^ *+' conftest.er1 >conftest.err
     5359  rm -f conftest.er1
     5360  cat conftest.err >&5
     5361  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5362  (exit $ac_status); } &&
     5363         { ac_try='test -z "$ac_c_werror_flag"
     5364                         || test ! -s conftest.err'
     5365  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5366  (eval $ac_try) 2>&5
     5367  ac_status=$?
     5368  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5369  (exit $ac_status); }; } &&
     5370         { ac_try='test -s conftest$ac_exeext'
     5371  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     5372  (eval $ac_try) 2>&5
     5373  ac_status=$?
     5374  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     5375  (exit $ac_status); }; }; then
     5376  ac_cv_lib_pthread_main=yes
     5377else
     5378  echo "$as_me: failed program was:" >&5
     5379sed 's/^/| /' conftest.$ac_ext >&5
     5380
     5381ac_cv_lib_pthread_main=no
     5382fi
     5383rm -f conftest.err conftest.$ac_objext \
     5384      conftest$ac_exeext conftest.$ac_ext
     5385LIBS=$ac_check_lib_save_LIBS
     5386fi
     5387echo "$as_me:$LINENO: result: $ac_cv_lib_pthread_main" >&5
     5388echo "${ECHO_T}$ac_cv_lib_pthread_main" >&6
     5389if test $ac_cv_lib_pthread_main = yes; then
     5390  FOUND_pthread=yes
     5391fi
     5392
     5393if test "$FOUND_pthread" = "yes" ; then
     5394    LIBS="$LIBS -lpthread"
     5395fi
     5396
     5397
     5398
    49025399
    49035400# FIXME: Replace `main' with a function in `-lm':
  • orxonox/trunk/configure.ac

    r2018 r2190  
    1111case `uname` in
    1212  *MINGW*)
    13     mingw=yes
     13    mingw="yes"
    1414    MSBITFIELDS="-mms-bitfields"
     15    MWINDOWS="-mwindows"
    1516    ;;
    1617  *)
    17     mingw=no
     18    mingw="no"
    1819    ;;
    1920esac
     
    103104fi
    104105
     106## mingw CHECK
     107if test $mingw = yes ; then
     108        AC_CHECK_LIB([mingw32], [main], FOUND_mingw32=yes)
     109        if test $FOUND_mingw32 = "yes"; then
     110                LIBS="$LIBS -lmingw32"
     111        fi
     112fi
     113
     114## SDL CHECK
     115
     116#checking for SDL libs
     117AC_CHECK_HEADERS(SDL/SDL.h ,,
     118      [AC_MSG_ERROR([cannot find SDL headers]) ])
     119if test $mingw = no ; then
     120        AC_CHECK_LIB([SDL], [main], FOUND_SDL=yes)
     121        if test "$FOUND_SDL" = "yes" ; then
     122                LIBS="$LIBS -lSDL"
     123        fi
     124#   checking for Windows sdl library
     125else
     126    AC_CHECK_LIB([sdlmain], [main], FOUND_sdlmain=yes)
     127    if test "$FOUND_sdlmain" = "yes" ; then
     128        LIBS="$LIBS -lsdlmain"
     129    fi
     130        AC_CHECK_LIB([sdl], [main], FOUND_sdl=yes)
     131        if test "$FOUND_sdl" = "yes" ; then
     132                LIBS="$LIBS -lsdl"
     133        fi
     134fi
     135
     136#checking for pthread libs
     137AC_CHECK_LIB([pthread], [main], FOUND_pthread=yes)
     138if test "$FOUND_pthread" = "yes" ; then
     139    LIBS="$LIBS -lpthread"
     140fi
     141
     142
     143
     144
    105145# FIXME: Replace `main' with a function in `-lm':
    106146AC_CHECK_LIB([m], [main])
  • orxonox/trunk/src/Makefile.am

    r2077 r2190  
    11AM_CXXFLAGS="-I/usr/X11R6/include"
    2 AM_LDFLAGS="-L/usr/Mesa-6.0.1/lib  -L/usr/X11R6/lib -lXt -lX11"
     2AM_LDFLAGS="-L/usr/Mesa-6.0.1/lib  -L/usr/X11R6/lib -lXt -lX11" $(MWINDOWS)
    33
    44#"-O3 -pedantic -fPIC -ffast-math -I/usr/X11R6/include"
     
    66
    77bin_PROGRAMS=orxonox
    8 orxonox_SOURCES=orxonox.cc world.cc environment.cc player.cc npc.cc input_output.cc data_tank.cc ai.cc shoot_laser.cc shoot_rocket.cc world_entity.cc synchronisable.cc vector.cc ability.cc power_up.cc
     8orxonox_SOURCES=orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc
    99
    1010#  uncomment the following if bencoder requires the math library
    11 #gui_LDADD=-lm
     11#orxonox_LDADD=-lm
    1212
    1313#EXTRA_DIST=orxonox.lsm.in orxonox.spec.in orxonox.texinfo
  • orxonox/trunk/src/Makefile.in

    r2077 r2190  
    112112target_alias = @target_alias@
    113113AM_CXXFLAGS = "-I/usr/X11R6/include"
    114 AM_LDFLAGS = "-L/usr/Mesa-6.0.1/lib  -L/usr/X11R6/lib -lXt -lX11"
     114AM_LDFLAGS = "-L/usr/Mesa-6.0.1/lib  -L/usr/X11R6/lib -lXt -lX11" $(MWINDOWS)
    115115
    116116
    117117#"-O3 -pedantic -fPIC -ffast-math -I/usr/X11R6/include"
    118118bin_PROGRAMS = orxonox
    119 orxonox_SOURCES = orxonox.cc world.cc environment.cc player.cc npc.cc input_output.cc data_tank.cc ai.cc shoot_laser.cc shoot_rocket.cc world_entity.cc synchronisable.cc vector.cc ability.cc power_up.cc
     119orxonox_SOURCES = orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc
    120120subdir = src
    121121ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
     
    126126PROGRAMS = $(bin_PROGRAMS)
    127127
    128 am_orxonox_OBJECTS = orxonox.$(OBJEXT) world.$(OBJEXT) \
    129         environment.$(OBJEXT) player.$(OBJEXT) npc.$(OBJEXT) \
    130         input_output.$(OBJEXT) data_tank.$(OBJEXT) ai.$(OBJEXT) \
    131         shoot_laser.$(OBJEXT) shoot_rocket.$(OBJEXT) \
    132         world_entity.$(OBJEXT) synchronisable.$(OBJEXT) \
    133         vector.$(OBJEXT) ability.$(OBJEXT) power_up.$(OBJEXT)
     128am_orxonox_OBJECTS = orxonox.$(OBJEXT) world.$(OBJEXT) player.$(OBJEXT) \
     129        data_tank.$(OBJEXT) world_entity.$(OBJEXT) vector.$(OBJEXT) \
     130        camera.$(OBJEXT) collision.$(OBJEXT) command_node.$(OBJEXT) \
     131        ini_parser.$(OBJEXT) keynames.$(OBJEXT) track.$(OBJEXT)
    134132orxonox_OBJECTS = $(am_orxonox_OBJECTS)
    135133orxonox_LDADD = $(LDADD)
     
    140138depcomp = $(SHELL) $(top_srcdir)/depcomp
    141139am__depfiles_maybe = depfiles
    142 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/ability.Po ./$(DEPDIR)/ai.Po \
    143 @AMDEP_TRUE@    ./$(DEPDIR)/data_tank.Po ./$(DEPDIR)/environment.Po \
    144 @AMDEP_TRUE@    ./$(DEPDIR)/input_output.Po ./$(DEPDIR)/npc.Po \
    145 @AMDEP_TRUE@    ./$(DEPDIR)/orxonox.Po ./$(DEPDIR)/player.Po \
    146 @AMDEP_TRUE@    ./$(DEPDIR)/power_up.Po ./$(DEPDIR)/shoot_laser.Po \
    147 @AMDEP_TRUE@    ./$(DEPDIR)/shoot_rocket.Po \
    148 @AMDEP_TRUE@    ./$(DEPDIR)/synchronisable.Po ./$(DEPDIR)/vector.Po \
    149 @AMDEP_TRUE@    ./$(DEPDIR)/world.Po ./$(DEPDIR)/world_entity.Po
     140@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/camera.Po ./$(DEPDIR)/collision.Po \
     141@AMDEP_TRUE@    ./$(DEPDIR)/command_node.Po \
     142@AMDEP_TRUE@    ./$(DEPDIR)/data_tank.Po ./$(DEPDIR)/ini_parser.Po \
     143@AMDEP_TRUE@    ./$(DEPDIR)/keynames.Po ./$(DEPDIR)/orxonox.Po \
     144@AMDEP_TRUE@    ./$(DEPDIR)/player.Po ./$(DEPDIR)/track.Po \
     145@AMDEP_TRUE@    ./$(DEPDIR)/vector.Po ./$(DEPDIR)/world.Po \
     146@AMDEP_TRUE@    ./$(DEPDIR)/world_entity.Po
    150147CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
    151148        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
     
    200197        -rm -f *.tab.c
    201198
    202 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ability.Po@am__quote@
    203 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ai.Po@am__quote@
     199@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/camera.Po@am__quote@
     200@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/collision.Po@am__quote@
     201@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/command_node.Po@am__quote@
    204202@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/data_tank.Po@am__quote@
    205 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/environment.Po@am__quote@
    206 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/input_output.Po@am__quote@
    207 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/npc.Po@am__quote@
     203@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ini_parser.Po@am__quote@
     204@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keynames.Po@am__quote@
    208205@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox.Po@am__quote@
    209206@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/player.Po@am__quote@
    210 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/power_up.Po@am__quote@
    211 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shoot_laser.Po@am__quote@
    212 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shoot_rocket.Po@am__quote@
    213 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/synchronisable.Po@am__quote@
     207@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/track.Po@am__quote@
    214208@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@
    215209@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/world.Po@am__quote@
     
    414408
    415409#  uncomment the following if bencoder requires the math library
    416 #gui_LDADD=-lm
     410#orxonox_LDADD=-lm
    417411
    418412#EXTRA_DIST=orxonox.lsm.in orxonox.spec.in orxonox.texinfo
  • orxonox/trunk/src/data_tank.cc

    r1956 r2190  
    1919using namespace std;
    2020
    21 float DataTank::xOffset = 0;
    22 float DataTank::yOffset = 0;
    23 float DataTank::zOffset = 0;
    24 
    2521DataTank::DataTank () {}
    2622DataTank::~DataTank () {}
  • orxonox/trunk/src/data_tank.h

    r1956 r2190  
    1010  ~DataTank ();
    1111
    12   static float xOffset;
    13   static float yOffset;
    14   static float zOffset;
    15 
    1612};
    1713
  • orxonox/trunk/src/orxonox.cc

    r2036 r2190  
    2121   ### File Specific:
    2222   main-programmer: Patrick Boenzli
    23    co-programmer:
    24 */
    25 
    26 #include <iostream>
    27 #include <cstdio>
    28 #include <GL/glut.h>
    29 
    30 #include "environment.h"
     23   co-programmer: Christian Meyer
     24*/
     25
     26#include "orxonox.h"
    3127#include "world.h"
    32 #include "input_output.h"
     28#include "camera.h"
    3329#include "data_tank.h"
    34 #include "stdincl.h"
    35 #include "player.h"
    36 #include "npc.h"
    37 #include "shoot_laser.h"
    38 
    39 #include "orxonox.h"
     30#include "command_node.h"
     31#include <string.h>
    4032
    4133using namespace std;
    4234
    43 
    44 Orxonox::Orxonox ()
     35/**
     36        \brief create a new Orxonox
     37*/
     38Orxonox::Orxonox ()
    4539{
    4640  pause = false;
    4741}
    4842
    49 
    50 
     43/**
     44        \brief remove Orxonox from memory
     45*/
    5146Orxonox::~Orxonox ()
    52 {}
    53 
    54 
    55 /* this is a singleton class to prevent dublicates */
     47{
     48        Orxonox::singleton_ref = NULL;
     49        if( world != NULL) delete world;
     50        if( localinput != NULL) delete world;
     51        if( localcamera != NULL) delete localcamera;
     52        if( resources != NULL) delete resources;
     53}
     54
     55
     56/* this is a singleton class to prevent duplicates */
    5657Orxonox* Orxonox::singleton_ref = 0;
    57 World* Orxonox::world = 0;
    58 InputOutput* Orxonox::io = 0;
    59 Player* Orxonox::localPlayer = 0;
    60 bool Orxonox::pause = false;
    61 bool Orxonox::inputEnabled = false;
    62 bool Orxonox::upWeGo = false;
    63 bool Orxonox::downWeGo = false;
    64 bool Orxonox::rightWeGo = false;
    65 bool Orxonox::leftWeGo = false;
    66 bool Orxonox::shoot1 = false;
    67 int Orxonox::fps = 0;
    68 int Orxonox::alpha = 0;
    69 int Orxonox::beta = 0;
    70 //int Orxonox::offsetX = 0;
    71 //int Orxonox::offsetY = 0;
    72 
    7358
    7459Orxonox* Orxonox::getInstance (void)
     
    7964}
    8065
    81 
    82 int Orxonox::globalInit (int argc, char** argv)
    83 {
    84   glutInit(&argc, argv);
    85   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
     66/**
     67        \brief this finds the config file
     68       
     69        Since the config file varies from user to user and since one may want to specify different config files
     70        for certain occasions or platforms this function finds the right config file for every occasion and stores
     71        it's path and name into configfilename
     72*/
     73void Orxonox::get_config_file (int argc, char** argv)
     74{
     75/*      char* path;
     76        #ifdef __WIN32__
     77        path = getenv("");
     78        #else
     79        path = getenv("HOME");
     80        #endif
     81       
     82        if( path != NULL) strcpy (configfilename, path);
     83        else strcpy (configfilename, "./");
     84        strcat (configfilename, "/.orxonox.conf");*/
     85       
     86        strcpy (configfilename, "orxonox.conf");
     87}
     88
     89/**
     90        \brief initialize Orxonox with command line
     91*/
     92int Orxonox::init (int argc, char** argv)
     93{
     94                // parse command line
     95                // config file
     96               
     97        get_config_file (argc, argv);
     98       
     99                // initialize SDL
     100  printf("> Initializing SDL\n");
     101  if( SDL_Init (SDL_INIT_EVERYTHING) == -1)
     102  {
     103    printf ("Could not SDL_Init(): %s\n", SDL_GetError());
     104    return -1;
     105  }
     106 
     107        // initialize everything
     108  printf("> Initializing video\n");
     109        if( init_video () == -1) return -1;
     110  printf("> Initializing sound\n");
     111        if( init_sound () == -1) return -1;
     112  printf("> Initializing input\n");
     113        if( init_input () == -1) return -1;
     114  printf("> Initializing networking\n");
     115        if( init_networking () == -1) return -1;
     116  printf("> Initializing resources\n");
     117        if( init_resources () == -1) return -1;
     118  printf("> Initializing world\n");
     119        if( init_world () == -1) return -1;
     120       
     121        return 0;
     122}
     123
     124/**
     125        \brief initializes SDL and OpenGL
     126*/
     127int Orxonox::init_video ()
     128{
     129  // Set video mode
     130  // TO DO: parse arguments for settings
     131  SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 5);
     132  SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5);
     133  SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5);
     134  SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
     135 
     136  int bpp = 16;
     137  int width = 640;
     138  int height = 480;
     139  Uint32 flags = SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
     140 
     141  if( (screen = SDL_SetVideoMode (width, height, bpp, flags)) == NULL)
     142  {
     143    printf ("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, flags, SDL_GetError());
     144    SDL_Quit();
     145    return -1;
     146  }
     147 
     148  // Set window labeling
     149  // TO DO: Add version information to caption
     150  SDL_WM_SetCaption( "Orxonox", "Orxonox");
     151 
     152  // TO DO: Create a cool icon and use it here
     153  // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); 
     154
     155  // OpenGL stuff
     156  // (Is this all we initialize globally???)
     157  glClearColor(0.0, 0.0, 0.0, 0.0);
    86158  glEnable(GL_DEPTH_TEST);
    87   glutInitWindowSize(500, 500);
    88   //glutFullScreen();
    89   glutInitWindowPosition(100, 100);
    90   glutCreateWindow("OrxonoX");
     159  glEnable(GL_COLOR);
    91160  glShadeModel(GL_FLAT);
    92   /* window event dispatchers */
    93   glutDisplayFunc(display);
    94   glutReshapeFunc(reshape);
    95   glutKeyboardFunc(keyboard);
    96   glutKeyboardUpFunc(upKeyboard);
    97 
    98   glutTimerFunc(1000, timeSlice, 0);
    99   cout << "measuring performance...";
    100 }
    101 
    102 
    103 int Orxonox::menuInit (void)
    104 {
    105   glClearColor(0.0, 0.0, 0.0, 0.0);
    106 }
    107 
    108 
    109 int Orxonox::gameInit (void)
    110 {
    111   glClearColor(0.0, 0.0, 0.0, 0.0);
    112  
    113   /* world init, shouldnt be done here later */
    114   world = new World;
    115   (*world).initEnvironement();
    116   localPlayer = new Player;
    117   localPlayer->setPosition(0.0, -10.0, 3.0);
    118   localPlayer->setCollisionRadius(2.0);
    119   io = new InputOutput(world, localPlayer);
    120   (*world).addPlayer(localPlayer);
    121   Environment *env = new Environment;
    122   (*world).addEnv(env);
    123   NPC* npc = new NPC;
    124   npc->setPosition(3.0, 0.0, 3.0);
    125   npc->setCollisionRadius(1.0);
    126   world->addNPC(npc);
    127 
    128   NPC* npc2 = new NPC;
    129   npc2->setPosition(-2.0, 10.0, 3.0);
    130   npc2->setCollisionRadius(1.0);
    131   world->addNPC(npc2);
    132 
    133   glutSpecialFunc(specFunc);
    134   glutSpecialUpFunc(releaseKey);
    135 
    136   glutIdleFunc(continousRedraw);
    137   //cout << "Orxonox::gameInit" << endl;
    138 }
    139 
    140 
    141 /* this is the time triggered function. heart beat*/
    142 
    143 void Orxonox::timeSlice(int value)
    144 {
    145   cout << "got " << fps << " fps" << endl;
    146   /* this is very very unsafe: io could be uninit */
    147   io->setPlayerStep(19.2/fps); /* set player to propper speed */
    148   localPlayer->shootLaser->setShootStep(20.0/fps); /* set shoot speed */
    149   world->setWorldStep(7.0/fps); /* set the speed of the terrain moving away */
    150   fps = 0;
    151   inputEnabled = true;
    152   glutTimerFunc(1000, timeSlice, 0);
    153 }
    154 
    155 
    156 
    157 void Orxonox::keyboard(unsigned char key, int x, int y)
    158 {
    159   switch(key) {
    160 
    161     /* perspectiv control */
    162   case 'w':
    163     beta -= 1;
    164     break;
    165   case 's':
    166     beta += 1;
    167     break;
    168   case 'a':
    169     alpha -= 1;
    170     break;
    171   case 'd':
    172     alpha += 1;
    173     break;
    174 
    175     /* game controls */
    176   case 'p':
    177     if (pause)
    178       {
    179         cout << "unset pause" << endl;
    180         glutIdleFunc(continousRedraw);
    181         pause = false;
    182       }
    183     else
    184       {
    185         cout << "set pause" << endl;
    186         glutIdleFunc(NULL);
    187         pause = true;
    188       }
    189     break;
    190   case 32:
    191     shoot1 = true;
    192     break;
    193   case 27:
    194   case 'q':
    195     quitGame();
    196     break;
     161 
     162  // create camera
     163  localcamera = new Camera();
     164 
     165  return 0;
     166}
     167
     168/**
     169        \brief initializes the sound engine
     170*/
     171int Orxonox::init_sound ()
     172{
     173        printf("Not yet implemented\n");
     174        return 0;
     175}
     176
     177/**
     178        \brief initializes input functions
     179*/
     180int Orxonox::init_input ()
     181{
     182        // create localinput
     183        localinput = new CommandNode( configfilename);
     184       
     185        return 0;
     186}
     187
     188/**
     189        \brief initializes network system
     190*/
     191int Orxonox::init_networking ()
     192{
     193        printf("Not yet implemented\n");
     194        return 0;
     195}
     196
     197/**
     198        \brief initializes and loads resource files
     199*/
     200int Orxonox::init_resources ()
     201{
     202        printf("Not yet implemented\n");
     203        return 0;
     204}
     205
     206/**
     207        \brief initializes the world
     208*/
     209int Orxonox::init_world ()
     210{
     211        world = new World();
     212       
     213        // TO DO: replace this with a menu/intro
     214        world->load_debug_level();
     215       
     216        return 0;
     217}
     218
     219/**
     220        \brief exits Orxonox
     221*/
     222void Orxonox::quitGame()
     223{
     224        bQuitOrxonox = true;
     225}
     226
     227/**
     228        \brief this runs all of Orxonox
     229*/
     230void Orxonox::mainLoop()
     231{
     232        lastframe = SDL_GetTicks();
     233        bQuitOrxonox = false;
     234  // This is where everything is run
     235printf("Orxonox|Entering main loop\n");
     236  while( !bQuitOrxonox)
     237  {
     238        // Network
     239        synchronize();
     240    // Process input
     241    handle_input();
     242    // Process time
     243    time_slice();
     244    // Process collision
     245    collision();
     246    // Draw
     247    display();
    197248  }
    198 }
    199 
    200 
    201 void Orxonox::upKeyboard(unsigned char key, int x, int y)
    202 {
    203   switch(key) {
    204   case 32:
    205     shoot1 = false;
    206     break;
    207   }
    208 }
    209 
    210 
    211 void Orxonox::quitGame()
    212 {
    213   //cout << "finished garbage colletion, quitting..." << endl;
    214   exit(0);
    215 }
    216 
    217 
    218 void Orxonox::releaseKey(int key, int x, int y)
    219 
    220   switch(key) {
    221   case GLUT_KEY_UP:
    222     upWeGo = false;
    223     break;
    224   case GLUT_KEY_DOWN:
    225     downWeGo = false;
    226     break;
    227   case GLUT_KEY_RIGHT:
    228     rightWeGo = false;
    229     break;
    230   case GLUT_KEY_LEFT:
    231     leftWeGo = false;
    232     break;
    233   }
    234 }
    235 
    236 
    237 /**
    238    \brief special keys function. called by glut
    239    
    240    Here are all special key function defined.
    241 */
    242 void Orxonox::specFunc(int key, int x, int y)
    243 {
    244   switch(key) {
    245     /* spacecraft controls */
    246   case GLUT_KEY_UP:
    247     upWeGo = true;
    248     break;
    249   case GLUT_KEY_DOWN:
    250     downWeGo = true;
    251     break;
    252   case GLUT_KEY_RIGHT:
    253     rightWeGo = true;
    254     break;
    255   case GLUT_KEY_LEFT:
    256     leftWeGo = true;
    257     break;
    258   }
    259 }
    260 
    261 
    262 void Orxonox::display()
    263 {
    264   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    265 
    266   glColor3f(0.0, 0.5, 0.6);
    267   glLoadIdentity();
    268   gluLookAt(0.0, -14.0, 15.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    269   (*world).drawWorld();
    270 
    271   glutSwapBuffers();
    272 }
    273 
    274 
    275 void Orxonox::continousRedraw()
    276 {
    277   /* increment the frames-per-second counter*/
    278   fps++;
    279   /* check for collisions */
    280   world->detectCollision();
    281 
    282   /* check for input to pass it over */
    283   if ( !pause && inputEnabled &&
    284        (rightWeGo || leftWeGo || upWeGo || downWeGo || shoot1))
    285     {
    286       if (upWeGo)
    287         (*io).goUp();
    288       if (downWeGo)
    289       (*io).goDown();
    290       if (rightWeGo)
    291         (*io).goRight();
    292       if (leftWeGo)
    293       (*io).goLeft();
    294       if (shoot1)
    295         (*io).shoot();
    296     }
    297   /* request repaint */
    298   glutPostRedisplay();
    299   //cout << "Orxonox::continousRedraw" << endl;
    300 }
    301 
    302 
    303 void Orxonox::reshape (int w, int h)
    304 {
    305   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
    306   glMatrixMode(GL_PROJECTION);
    307   glLoadIdentity();
    308   glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 200.0);
    309   glMatrixMode(GL_MODELVIEW);
    310   glLoadIdentity(); //pb why a second time?
    311 }
    312 
    313 
    314 void Orxonox::testTheShit()
    315 {
    316   //Player* pl = new Player;
    317   //(*pl).setPosition(1, 1, 1);
    318   //(*world).addPlayer(pl);
    319  
    320   //NPC* nl = new NPC;
    321   //(*world).addNPC(nl);
    322   //(*world).addNPC(nl);
    323   //(*world).addNPC(nl);
    324   //(*world).addNPC(nl);
    325   //(*world).addNPC(nl);
    326   //(*world).addNPC(nl);
    327   //(*world).testThaTest();
    328 }
    329 
     249printf("Orxonox|Exiting the main loop\n");
     250}
     251
     252/**
     253        \brief handles sprecial events from localinput
     254        \param event: an event not handled by the CommandNode
     255*/
     256void Orxonox::event_handler (SDL_Event* event)
     257{
     258        // Handle special events such as reshape, quit, focus changes
     259}
     260
     261/**
     262        \brief synchronize local data with remote data
     263*/
     264void Orxonox::synchronize ()
     265{
     266        // Get remote input
     267        // Update synchronizables
     268}
     269
     270/**
     271        \brief run all input processing
     272*/
     273void Orxonox::handle_input ()
     274{
     275        // localinput
     276                localinput->process();
     277        // remoteinput
     278}
     279
     280/**
     281        \brief advance the timeline
     282*/
     283void Orxonox::time_slice ()
     284{
     285        Uint32 curframe = SDL_GetTicks();
     286        if( !pause)
     287        {
     288                world->time_slice (curframe - lastframe);
     289                world->update ();
     290                localcamera->time_slice (curframe - lastframe);
     291        }
     292        lastframe = curframe;
     293}
     294
     295/**
     296        \brief compute collision detection
     297*/
     298void Orxonox::collision ()
     299{
     300        world->collide ();
     301}
     302
     303/**
     304        \brief handle keyboard commands that are not meant for WorldEntities
     305        \param cmd: the command to handle
     306        \return true if the command was handled by the system or false if it may be passed to the WorldEntities
     307*/
     308bool Orxonox::system_command (Command* cmd)
     309{
     310        if( !strcmp( cmd->cmd, "quit"))
     311        {
     312                if( !cmd->bUp) bQuitOrxonox = true;
     313                return true;
     314        }
     315        return false;
     316}
     317
     318/**
     319        \brief render the current frame
     320*/
     321void Orxonox::display ()
     322{
     323                // clear buffer
     324        glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     325                // set camera
     326        localcamera->apply ();
     327                // draw world
     328        world->draw ();
     329                // draw HUD
     330                // flip buffers
     331        SDL_GL_SwapBuffers();
     332}
     333
     334/**
     335        \brief retrieve a pointer to the local Camera
     336        \return a pointer to localcamera
     337*/
     338Camera* Orxonox::get_camera ()
     339{
     340        return localcamera;
     341}
     342
     343/**
     344        \brief retrieve a pointer to the local CommandNode
     345        \return a pointer to localinput
     346*/
     347CommandNode* Orxonox::get_localinput ()
     348{
     349        return localinput;
     350}
     351
     352/**
     353        \brief retrieve a pointer to the local World
     354        \return a pointer to world
     355*/
     356World* Orxonox::get_world ()
     357{
     358        return world;
     359}
    330360
    331361int main (int argc, char** argv)
    332362
     363        printf(">>> Starting Orxonox <<<\n");
    333364  Orxonox *orx = Orxonox::getInstance();
    334   (*orx).globalInit(argc, argv);
    335   //(*orx).menuInit(); pb: directly jump to the game, no menu
    336   (*orx).gameInit();
    337 
    338   glutMainLoop(); 
     365 
     366  if( (*orx).init(argc, argv) == -1)
     367  {
     368    printf("! Orxonox initialization failed\n");
     369    return -1;
     370  }
     371       
     372  (*orx).mainLoop();
     373
     374  //delete orx;
     375 
    339376  return 0;
    340377}
  • orxonox/trunk/src/orxonox.h

    r2036 r2190  
     1/*!
     2    \file orxonox.h
     3    \brief Orxonox core functions
     4*/
    15
    26#ifndef ORXONOX_H
    37#define ORXONOX_H
    48
     9#include <SDL/SDL.h>
     10
     11#include "stdincl.h"
     12
     13class CommandNode;
     14class WorldEntity;
     15class DataTank;
    516class World;
    6 class InputOutput;
    7 class Player;
     17class Camera;
    818
    9 
     19//! Orxonox core singleton class
     20/**
     21*/
    1022class Orxonox {
    1123
     
    1426  Orxonox ();
    1527  ~Orxonox ();
    16   static World* world;
    17   static InputOutput* io;
    18   static Player* localPlayer;
    19   static bool pause;
    20   static bool inputEnabled;
    21   static bool upWeGo;
    22   static bool downWeGo;
    23   static bool rightWeGo;
    24   static bool leftWeGo;
    25   static bool shoot1;
    26   static int fps;
     28 
     29  char configfilename[256];
     30  World* world;
     31  DataTank* resources;
     32  CommandNode* localinput;
     33  Camera* localcamera;
     34  SDL_Surface* screen;
     35 
     36  bool bQuitOrxonox;
     37  bool pause;
     38        Uint32 lastframe;
    2739
    28   static int alpha;
    29   static int beta;
    30   static int offsetX;
    31   static int offsetY;
     40        void get_config_file (int argc, char** argv);
     41       
     42                // main loop functions
     43  void synchronize ();
     44  void handle_input ();
     45  void time_slice ();
     46  void collision ();
     47  void display ();
     48 
     49        // subsystem initialization
     50  int init_video ();
     51  int init_sound ();
     52  int init_input ();
     53  int init_networking ();
     54  int init_resources ();
     55  int init_world ();
     56 
     57 public:
     58  static Orxonox* getInstance ();
     59  void quitGame();
    3260
    33   static void timeSlice(int value);
     61  void event_handler (SDL_Event* event);
     62  bool system_command (Command* cmd);
    3463
    35  public:
    36   static Orxonox* getInstance (void);
    37 
    38   int globalInit (int argc, char** argv);
    39   int menuInit (void);
    40   int gameInit (void);
    41   void testTheShit(void);
    42   static void display (void);
    43   static void continousRedraw(void);
    44   static void reshape (int w, int h);
    45   static void keyboard(unsigned char key, int x, int y);
    46   static void upKeyboard(unsigned char key, int x, int y);
    47   static void releaseKey(int key, int x, int y);
    48   static void specFunc(int key, int x, int y);
    49   static void quitGame(void);
     64  int init (int argc, char** argv);
     65       
     66        CommandNode* get_localinput();
     67        Camera* get_camera();
     68        World* get_world();
     69       
     70  void mainLoop();
    5071};
    5172
  • orxonox/trunk/src/player.cc

    r2036 r2190  
    1313   ### File Specific:
    1414   main-programmer: Patrick Boenzli
    15    co-programmer:
     15   co-programmer: Christian Meyer
    1616*/
    1717
    18 #include <iostream>
    19 #include <stdlib.h>
    20 #include <GL/glut.h>
    21 
    22 #include "shoot_laser.h"
    23 #include "shoot_rocket.h"
    24 #include "data_tank.h"
    25 
    2618#include "player.h"
     19#include "stdincl.h"
     20#include "collision.h"
    2721
    2822using namespace std;
    2923
    3024
    31 Player::Player()
    32    : WorldEntity() {
    33   //cout << "Player::Player" << endl;
    34   xCor = yCor = zCor = 0;
    35   shootLaser = new ShootLaser;
    36   shootRocket = new ShootRocket;
     25Player::Player(bool isFree) : WorldEntity(isFree)
     26{
    3727}
    3828
    3929Player::~Player ()
    4030{
    41   //delete shootLaser;
    4231}
    4332
    44 
    45 void Player::setPosition( float x, float y, float z)
     33void Player::post_spawn ()
    4634{
    47   xCor = x; yCor = y; zCor = z;
     35        travel_speed = 10.0;
     36        velocity = Vector();
     37        bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
     38        bFire = false;
     39        acceleration = 10.0;
     40        set_collision (new CollisionCluster (1.0, Vector(0,0,0)));
    4841}
    4942
    50 
    51 void Player::getPosition(float* x, float* y, float* z)
     43void Player::tick (float time)
    5244{
    53   *x = xCor; *y = yCor; *z = zCor;
     45        // movement
     46        move (time);
    5447}
    5548
    56 
    57 void Player::setCollisionRadius(float radius)
     49void Player::hit (WorldEntity* weapon, Vector loc)
    5850{
    59   collisionRadius = radius;
    6051}
    6152
    62 
    63 void Player::goX(float x)
     53void Player::destroy ()
    6454{
    65   xCor += x;
    6655}
    6756
    68 
    69 void Player::goY(float y)
     57void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
    7058{
    71   yCor += y;
    7259}
    7360
    74 void Player::goZ(float z)
     61void Player::command (Command* cmd)
    7562{
    76   zCor += z;
     63        printf("Player|recieved command [%s]\n", cmd->cmd);
     64        if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
     65        else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
     66        else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
     67        else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
     68        else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
    7769}
    7870
     71void Player::draw ()
     72{
     73        glMatrixMode(GL_MODELVIEW);
     74        glLoadIdentity();
     75        float matrix[4][4];
    7976
    80 
    81 void Player::shoot(int n)
    82 {
    83 
    84   //  if (shootLaser->inhibitor++ <= 100)
    85   shootLaser->addShoot(xCor, yCor, zCor);
    86   // else if (shootLaser->inhibitor++ <= 200)
    87   shootLaser->addShootExt(xCor, yCor, zCor, .1, .4, .0);
    88   //  else if (shootLaser->inhibitor++ <= 300)
    89   shootLaser->addShootExt(xCor, yCor, zCor, -0.1, .4, .0);
    90   //  else
    91   shootLaser->inhibitor =0;
    92  
    93   //  if (shootRocket->inhibitor++ >=80)
    94   {
    95     shootRocket->addBackParable(xCor, yCor, zCor);
    96     shootRocket->addSideAcc(xCor, yCor, zCor, RIGHT);
    97     shootRocket->addSideAcc(xCor, yCor, zCor, LEFT);
    98     shootRocket->addRotater(xCor, yCor, zCor);
    99     //  if (shootRocket->inhibitor >=90)
    100     //        shootRocket->inhibitor =0;
    101   }
    102   //cout << "Player::shoot" << endl;
    103  
    104   /*
    105   shootLaser->addShoot(xCor, yCor, zCor);
    106   shootLaser->addShootExt(xCor, yCor, zCor, .1, .4, .0);
    107   shootLaser->addShootExt(xCor, yCor, zCor, -0.1, .4, .0);
    108   //shootRocket->addShoot(xCor, yCor, zCor);
    109   //cout << "Player::shoot" << endl;
    110   */
     77        glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z);
     78  get_placement()->w.matrix (matrix);
     79  glMultMatrixf ((float*)matrix);
     80       
     81        glBegin(GL_TRIANGLES);
     82        glColor3f(1,0,0);
     83        glVertex3f(0,0,0.5);
     84        glColor3f(0,1,0);
     85        glVertex3f(-0.5,0,-1);
     86        glColor3f(0,0,1);
     87        glVertex3f(0.5,0,-1);
     88        glEnd();
     89       
     90        printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z);
    11191}
    11292
     93void Player::get_lookat (Location* locbuf)
     94{
     95        *locbuf = *get_location();
     96        //locbuf->dist += 5.0;
     97}
    11398
    114 //void Player::addIO(InputOutput *io) {}
     99void Player::left_world ()
     100{
     101}
    115102
    116 
    117 void Player::paint()
     103void Player::move (float time)
    118104{
    119   //cout << "Player::drawPlayer" << endl;
    120   glPushMatrix();
    121   glTranslatef(xCor, yCor, 3.0);
    122   glScalef(1.0, 3.0, 1.0);
    123   glutWireCube(1.0);
    124   glPopMatrix();
    125   /* draw all the shoots additionaly */
    126   shootLaser->drawShoot();
    127   shootRocket->drawShoot();
    128   //cout << "Player::drawPlayer, end" << endl;
     105        float xAccel, yAccel, zAccel;
     106        xAccel = yAccel = zAccel = 0;
     107        if( bUp) xAccel += acceleration;
     108        if( bDown) xAccel -= acceleration;
     109        if( bLeft) yAccel += acceleration;
     110        if( bRight) yAccel -= acceleration;
     111        if( bAscend) zAccel += acceleration;
     112        if( bDescend) zAccel -= acceleration;
     113       
     114        Vector accel( xAccel, yAccel, zAccel);
     115       
     116        Location* l = get_location();
     117       
     118        // r(t) = r(0) + v(0)*t + 1/2*a*t^2
     119        // r = position
     120        // v = velocity
     121        // a = acceleration
     122       
     123        l->pos = l->pos + velocity*time + (accel*(0.5*time*time));
     124        l->dist += travel_speed * time;
     125       
     126        velocity = velocity + (accel * time);
     127        printf("Player|velocity %f/%f/%f\n", velocity.x, velocity.y, velocity.z);
    129128}
    130129
     
    146145
    147146
    148 
    149 
    150 
    151 
    152 
    153 
    154 
    155 
  • orxonox/trunk/src/player.h

    r2036 r2190  
     1/*!
     2    \file player.h
     3    \brief Implements a basic controllable WorldEntity
     4*/
    15
    26#ifndef PLAYER_H
     
    59#include "world_entity.h"
    610
    7 class ShootLaser;
    8 class ShootRocket;
    9 
    10 
     11//! Basic controllable WorldEntity
    1112class Player : public WorldEntity
    1213{
     14        friend class World;
    1315
    1416 public:
    15   Player ();
     17  Player (bool isFree = false);
    1618  ~Player ();
    1719
    18   /* position of the spacecraft */
    19   float xCor;
    20   float yCor;
    21   float zCor;
     20        virtual void post_spawn ();
     21  virtual void tick (float time);
     22  virtual void hit (WorldEntity* weapon, Vector loc);
     23  virtual void destroy ();
     24  virtual void collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags);
     25        virtual void command (Command* cmd);
    2226 
    23   float collisionRadius;
     27  virtual void draw ();
     28  virtual void get_lookat (Location* locbuf);
    2429
    25 
    26   /* this player wanna shoot? so include a ref to ShootLaser */
    27   ShootLaser* shootLaser;
    28   ShootRocket* shootRocket;
    29 
    30   void setPosition(float x, float y, float z);
    31   void getPosition(float* x, float* y, float* z);
    32   void setCollisionRadius(float radius);
    33   void paint();
    34   void goX(float x);
    35   void goY(float y);
    36   void goZ(float x);
    37   void shoot(int n);
    38   //  void addIO(InputOutput *io);
    39   void drawPlayer(void);
     30        virtual void left_world ();
    4031
    4132 private:
    42 
    43 
     33        bool bUp, bDown, bLeft, bRight, bAscend, bDescend;
     34        bool bFire;
     35        Vector velocity;
     36        float travel_speed;
     37        float acceleration;
     38       
     39        void move (float time);
     40       
    4441};
    4542
  • orxonox/trunk/src/stdincl.h

    r1956 r2190  
    55#define null 0
    66
     7#ifdef __WIN32__
     8#include <windows.h>
    79#endif
     10#include <SDL/SDL.h>
     11#include <GL/gl.h>
     12
     13#include "vector.h"
     14#include "coordinates.h"
     15#include "list.h"
     16#include "message_structures.h"
     17#include "orxonox.h"
     18
     19#endif
  • orxonox/trunk/src/vector.cc

    r2043 r2190  
    1414   main-programmer: Christian Meyer
    1515   co-programmer: ...
     16   
     17   Quaternion code borrowed from an Gamasutra article by Nick Bobick and Ken Shoemake
    1618*/
    1719
     
    177179  f = acos( v1 * v2 / (v1.len() * v2.len()));
    178180  return f * 180 / PI;
     181}
     182
     183/**
     184        \brief creates a multiplicational identity Quaternion
     185*/
     186Quaternion::Quaternion ()
     187{
     188        w = 1;
     189        v = Vector(0,0,0);
     190}
     191
     192/**
     193        \brief turns a rotation along an axis into a Quaternion
     194        \param angle: the amount of radians to rotate
     195        \param axis: the axis to rotate around
     196*/
     197Quaternion::Quaternion (float angle, const Vector& axis)
     198{
     199        w = cos(angle/2);
     200        v = axis * sin(angle/2);
     201}
     202
     203/**
     204        \brief calculates a look_at rotation
     205        \param dir: the direction you want to look
     206        \param up: specify what direction up should be
     207       
     208        Mathematically this determines the rotation a (0,0,1)-Vector has to undergo to point the same way as dir.
     209        If you want to use this with cameras, you'll have to reverse the dir Vector (Vector(0,0,0) - your viewing direction)
     210        or you'll point the wrong way. You can use this for meshes as well (then you do not have to reverse the vector), but keep in mind that if you do that, the model's front
     211        has to point in +z direction, and left and right should be -x or +x respectively or the mesh wont rotate correctly.
     212*/
     213Quaternion::Quaternion (const Vector& dir, const Vector& up)
     214{
     215        Vector z = dir;
     216  z.normalize();
     217  Vector x = up.cross(z);
     218  x.normalize();
     219  Vector y = z.cross(x);
     220 
     221  float m[4][4];
     222  m[0][0] = x.x;
     223  m[0][1] = x.y;
     224  m[0][2] = x.z;
     225  m[0][3] = 0;
     226  m[1][0] = y.x;
     227  m[1][1] = y.y;
     228  m[1][2] = y.z;
     229  m[1][3] = 0;
     230  m[2][0] = z.x;
     231  m[2][1] = z.y;
     232  m[2][2] = z.z;
     233  m[2][3] = 0;
     234  m[3][0] = 0;
     235  m[3][1] = 0;
     236  m[3][2] = 0;
     237  m[3][3] = 1;
     238 
     239  *this = Quaternion (m);
     240}
     241
     242/**
     243        \brief calculates a rotation from euler angles
     244        \param roll: the roll in radians
     245        \param pitch: the pitch in radians
     246        \param yaw: the yaw in radians
     247       
     248        I DO HONESTLY NOT EXACTLY KNOW WHICH ANGLE REPRESENTS WHICH ROTATION. And I do not know in what order they are applied,
     249        I just copy-pasted the code.
     250*/
     251Quaternion::Quaternion (float roll, float pitch, float yaw)
     252{
     253        float cr, cp, cy, sr, sp, sy, cpcy, spsy;
     254       
     255        // calculate trig identities
     256        cr = cos(roll/2);
     257        cp = cos(pitch/2);
     258        cy = cos(yaw/2);
     259       
     260        sr = sin(roll/2);
     261        sp = sin(pitch/2);
     262        sy = sin(yaw/2);
     263       
     264        cpcy = cp * cy;
     265        spsy = sp * sy;
     266       
     267        w = cr * cpcy + sr * spsy;
     268        v.x = sr * cpcy - cr * spsy;
     269        v.y = cr * sp * cy + sr * cp * sy;
     270        v.z = cr * cp * sy - sr * sp * cy;
     271}
     272
     273/**
     274        \brief rotates one Quaternion by another
     275        \param q: another Quaternion to rotate this by
     276        \return a quaternion that represents the first one rotated by the second one (WARUNING: this operation is not commutative! e.g. (A*B) != (B*A))
     277*/
     278Quaternion Quaternion::operator*(const Quaternion& q) const
     279{
     280        float A, B, C, D, E, F, G, H;
     281        Quaternion r;
     282       
     283        A = (w   + v.x)*(q.w   + q.v.x);
     284        B = (v.z - v.y)*(q.v.y - q.v.z);
     285        C = (w   - v.x)*(q.v.y + q.v.z);
     286        D = (v.y + v.z)*(q.w   - q.v.x);
     287        E = (v.x + v.z)*(q.v.x + q.v.y);
     288        F = (v.x - v.z)*(q.v.x - q.v.y);
     289        G = (w   + v.y)*(q.w   - q.v.z);
     290        H = (w   - v.y)*(q.w   + q.v.z);
     291       
     292        r.w = B +  (-E - F + G + H)/2;
     293        r.v.x = A - (E + F + G + H)/2;
     294        r.v.y = C + (E - F + G - H)/2;
     295        r.v.z = D + (E - F - G + H)/2;
     296       
     297        return r;
     298}
     299
     300/**
     301        \brief add two Quaternions
     302        \param q: another Quaternion
     303        \return the sum of both Quaternions
     304*/
     305Quaternion Quaternion::operator+(const Quaternion& q) const
     306{
     307        Quaternion r(*this);
     308        r.w = r.w + q.w;
     309        r.v = r.v + q.v;
     310        return r;
     311}
     312
     313/**
     314        \brief subtract two Quaternions
     315        \param q: another Quaternion
     316        \return the difference of both Quaternions
     317*/
     318Quaternion Quaternion::operator- (const Quaternion& q) const
     319{
     320        Quaternion r(*this);
     321        r.w = r.w - q.w;
     322        r.v = r.v - q.v;
     323        return r;
     324}
     325
     326/**
     327        \brief rotate a Vector by a Quaternion
     328        \param v: the Vector
     329        \return a new Vector representing v rotated by the Quaternion
     330*/
     331Vector Quaternion::apply (Vector& v) const
     332{
     333        Quaternion q;
     334        q.v = v;
     335        q.w = 0;
     336        q = *this * q * conjugate();
     337        return q.v;
     338}
     339
     340/**
     341        \brief multiply a Quaternion with a real value
     342        \param f: a real value
     343        \return a new Quaternion containing the product
     344*/
     345Quaternion Quaternion::operator*(const float& f) const
     346{
     347        Quaternion r(*this);
     348        r.w = r.w*f;
     349        r.v = r.v*f;
     350        return r;
     351}
     352
     353/**
     354        \brief divide a Quaternion by a real value
     355        \param f: a real value
     356        \return a new Quaternion containing the quotient
     357*/
     358Quaternion Quaternion::operator/(const float& f) const
     359{
     360        if( f == 0) return Quaternion();
     361        Quaternion r(*this);
     362        r.w = r.w/f;
     363        r.v = r.v/f;
     364        return r;
     365}
     366
     367/**
     368        \brief calculate the conjugate value of the Quaternion
     369        \return the conjugate Quaternion
     370*/
     371Quaternion Quaternion::conjugate() const
     372{
     373        Quaternion r(*this);
     374        r.v = Vector() - r.v;
     375        return r;
     376}
     377
     378/**
     379        \brief calculate the norm of the Quaternion
     380        \return the norm of The Quaternion
     381*/
     382float Quaternion::norm() const
     383{
     384        return w*w + v.x*v.x + v.y*v.y + v.z*v.z;
     385}
     386
     387/**
     388        \brief calculate the inverse value of the Quaternion
     389        \return the inverse Quaternion
     390       
     391        Note that this is equal to conjugate() if the Quaternion's norm is 1
     392*/
     393Quaternion Quaternion::inverse() const
     394{
     395        float n = norm();
     396        if (n != 0)
     397        {
     398                return conjugate() / norm();
     399        }
     400        else return Quaternion();
     401}
     402
     403/**
     404        \brief convert the Quaternion to a 4x4 rotational glMatrix
     405        \param m: a buffer to store the Matrix in
     406*/
     407void Quaternion::matrix (float m[4][4]) const
     408{
     409        float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
     410
     411        // calculate coefficients
     412        x2 = v.x + v.x;
     413  y2 = v.y + v.y;
     414        z2 = v.z + v.z;
     415        xx = v.x * x2; xy = v.x * y2; xz = v.x * z2;
     416        yy = v.y * y2; yz = v.y * z2; zz = v.z * z2;
     417        wx = w * x2; wy = w * y2; wz = w * z2;
     418       
     419        m[0][0] = 1.0 - (yy + zz); m[1][0] = xy - wz;
     420        m[2][0] = xz + wy; m[3][0] = 0.0;
     421       
     422        m[0][1] = xy + wz; m[1][1] = 1.0 - (xx + zz);
     423        m[2][1] = yz - wx; m[3][1] = 0.0;
     424       
     425        m[0][2] = xz - wy; m[1][2] = yz + wx;
     426        m[2][2] = 1.0 - (xx + yy); m[3][2] = 0.0;
     427       
     428        m[0][3] = 0; m[1][3] = 0;
     429        m[2][3] = 0; m[3][3] = 1;
     430}
     431
     432/**
     433        \brief convert a rotational 4x4 glMatrix into a Quaternion
     434        \param m: a 4x4 matrix in glMatrix order
     435*/
     436Quaternion::Quaternion (float m[4][4])
     437{
     438       
     439  float  tr, s, q[4];
     440  int    i, j, k;
     441
     442  int nxt[3] = {1, 2, 0};
     443
     444  tr = m[0][0] + m[1][1] + m[2][2];
     445
     446        // check the diagonal
     447  if (tr > 0.0)
     448  {
     449    s = sqrt (tr + 1.0);
     450    w = s / 2.0;
     451    s = 0.5 / s;
     452    v.x = (m[1][2] - m[2][1]) * s;
     453    v.y = (m[2][0] - m[0][2]) * s;
     454    v.z = (m[0][1] - m[1][0]) * s;
     455        }
     456        else
     457        {
     458                // diagonal is negative
     459        i = 0;
     460        if (m[1][1] > m[0][0]) i = 1;
     461    if (m[2][2] > m[i][i]) i = 2;
     462    j = nxt[i];
     463    k = nxt[j];
     464
     465    s = sqrt ((m[i][i] - (m[j][j] + m[k][k])) + 1.0);
     466     
     467    q[i] = s * 0.5;
     468           
     469    if (s != 0.0) s = 0.5 / s;
     470       
     471          q[3] = (m[j][k] - m[k][j]) * s;
     472    q[j] = (m[i][j] + m[j][i]) * s;
     473    q[k] = (m[i][k] + m[k][i]) * s;
     474
     475        v.x = q[0];
     476        v.y = q[1];
     477        v.z = q[2];
     478        w = q[3];
     479  }
    179480}
    180481
     
    266567
    267568/**
     569   \brief fills the specified buffer with a 4x4 glmatrix
     570   \param buffer: Pointer to an array of 16 floats
     571   
     572   Use this to get the rotation in a gl-compatible format
     573*/
     574void Rotation::glmatrix (float* buffer)
     575{
     576        buffer[0] = m[0];
     577        buffer[1] = m[3];
     578        buffer[2] = m[6];
     579        buffer[3] = m[0];
     580        buffer[4] = m[1];
     581        buffer[5] = m[4];
     582        buffer[6] = m[7];
     583        buffer[7] = m[0];
     584        buffer[8] = m[2];
     585        buffer[9] = m[5];
     586        buffer[10] = m[8];
     587        buffer[11] = m[0];
     588        buffer[12] = m[0];
     589        buffer[13] = m[0];
     590        buffer[14] = m[0];
     591        buffer[15] = m[1];
     592}
     593
     594/**
     595   \brief multiplies two rotational matrices
     596   \param r: another Rotation
     597   \return the matrix product of the Rotations
     598   
     599   Use this to rotate one rotation by another
     600*/
     601Rotation Rotation::operator* (const Rotation& r)
     602{
     603        Rotation p;
     604       
     605        p.m[0] = m[0]*r.m[0] + m[1]*r.m[3] + m[2]*r.m[6];
     606        p.m[1] = m[0]*r.m[1] + m[1]*r.m[4] + m[2]*r.m[7];
     607        p.m[2] = m[0]*r.m[2] + m[1]*r.m[5] + m[2]*r.m[8];
     608       
     609        p.m[3] = m[3]*r.m[0] + m[4]*r.m[3] + m[5]*r.m[6];
     610        p.m[4] = m[3]*r.m[1] + m[4]*r.m[4] + m[5]*r.m[7];
     611        p.m[5] = m[3]*r.m[2] + m[4]*r.m[5] + m[5]*r.m[8];
     612
     613        p.m[6] = m[6]*r.m[0] + m[7]*r.m[3] + m[8]*r.m[6];
     614        p.m[7] = m[6]*r.m[1] + m[7]*r.m[4] + m[8]*r.m[7];
     615        p.m[8] = m[6]*r.m[2] + m[7]*r.m[5] + m[8]*r.m[8];
     616       
     617        return p;
     618}
     619
     620
     621/**
    268622   \brief rotates the vector by the given rotation
    269623   \param v: a vector
  • orxonox/trunk/src/vector.h

    r2043 r2190  
    1212#define PI 3.14159265359f
    1313
    14 //! 3D vector
     14//! 3D Vector
    1515/**
    16   Class for 3-dimensional vector calculation
    17  
    18   Supports all common vector operations (dot, cross, lenght and so on)
     16        Class to handle 3D Vectors
    1917*/
    2018class Vector {
     
    4240float angle_rad (const Vector& v1, const Vector& v2);
    4341
    44 //! 3D rotation
     42//! Quaternion
     43/**
     44        Class to handle 3-dimensional rotation efficiently
     45*/
     46class Quaternion
     47{
     48 public:
     49        Vector v;       //!< Imaginary Vector
     50        float w; //!< Real part of the number
     51
     52        Quaternion ();
     53        Quaternion (float m[4][4]);
     54        Quaternion (float angle, const Vector& axis);
     55        Quaternion (const Vector& dir, const Vector& up);
     56        Quaternion (float roll, float pitch, float yaw);
     57       
     58        Quaternion operator/ (const float& f) const;
     59        Quaternion operator* (const float& f) const;
     60        Quaternion operator* (const Quaternion& q) const;
     61        Quaternion operator+ (const Quaternion& q) const;
     62        Quaternion operator- (const Quaternion& q) const;
     63        Quaternion conjugate () const;
     64        Quaternion inverse () const;
     65        Vector apply (Vector& f) const;
     66        float norm () const;
     67        void matrix (float m[4][4]) const;
     68};
     69
     70//! 3D rotation (OBSOLETE)
    4571/**
    4672  Class to handle 3-dimensional rotations.
     
    5884  ~Rotation () {}
    5985 
     86  Rotation operator* (const Rotation& r);
     87 
     88  void glmatrix (float* buffer);
    6089};
    6190
  • orxonox/trunk/src/world.cc

    r2077 r2190  
    1212   ### File Specific:
    1313   main-programmer: Patrick Boenzli
    14    co-programmer:
    15 */
    16 
    17 #include <iostream>
    18 #include <stdlib.h>
    19 #include <cmath>
    20 #include <GL/glut.h>
    21 
    22 #include "npc.h"
     14   co-programmer: Christian Meyer
     15*/
     16
     17#include "world.h"
     18#include "world_entity.h"
     19#include "collision.h"
     20#include "track.h"
    2321#include "player.h"
    24 #include "environment.h"
    25 #include "shoot_laser.h"
    26 #include "shoot_rocket.h"
    27 #include "stdincl.h"
    28 #include "data_tank.h"
    29 
    30 #include "list.h"
    31 #include "world_entity.h"
    32 
    33 #include "world.h"
    34 
     22#include "command_node.h"
     23#include "camera.h"
    3524
    3625using namespace std;
     
    3827
    3928/**
    40    \brief Create a new World
     29   \brief create a new World
    4130   
    42    This creates a new, empty world!
    43 */
    44 World::World () {
    45   //lastPlayer = null;
    46   //lastNPC = null;
    47   //lastEnv = null;
    48   primitiveMove = 0;
    49   step = 0;
    50 
    51   //List<int> *list = new List<int>();
    52   npcList = new List<WorldEntity*>();
    53   playerList = new List<WorldEntity*>();
    54   envList = new List<WorldEntity*>();
    55 }
    56 
    57 
    58 World::~World () {}
    59 
    60 
    61 
    62 /**
    63    \brief Load a new World
     31   This creates a new empty world!
     32*/
     33World::World ()
     34{
     35        entities = new List<WorldEntity>();
     36}
     37
     38/**
     39   \brief remove the World from memory
     40*/
     41World::~World ()
     42{
     43        unload ();
     44        delete entities;
     45}
     46
     47/**
     48   \brief checks for collisions
    6449   
    65    Load a new world. The old world (if any) will be unloaded and becomes unrecoverable.
    66 */
    67 void World::loadWorld() {}
    68 
    69 
    70 /**
    71    \brief Unloads a new World
     50   This method runs through all WorldEntities known to the world and checks for collisions between them.
     51   In case of collisions the collide() method of the corresponding entities is called.
     52*/
     53void World::collide ()
     54{
     55        List<WorldEntity> *a, *b;
     56        WorldEntity *aobj, *bobj;
     57       
     58        a = entities->get_next();
     59       
     60        while( a != NULL)
     61        {
     62                aobj = a->get_object();
     63                if( aobj->bCollide && aobj->collisioncluster != NULL)
     64                {
     65                        b = a->get_next();
     66                        while( b != NULL)
     67                        {
     68                                bobj = b->get_object();
     69                                if( bobj->bCollide && bobj->collisioncluster != NULL)
     70                                {
     71                                        unsigned long ahitflg, bhitflg;
     72                                        if( check_collision ( &aobj->place, aobj->collisioncluster, &ahitflg, &bobj->place, bobj->collisioncluster, &bhitflg));
     73                                        {
     74                                                aobj->collide (bobj, ahitflg, bhitflg);
     75                                                bobj->collide (aobj, bhitflg, ahitflg);
     76                                        }
     77                                }
     78                                b = b->get_next();
     79                        }
     80                }
     81                a = a->get_next();
     82        }
     83}
     84
     85/**
     86   \brief runs through all entities calling their draw() methods
     87*/
     88void World::draw ()
     89{
     90        // draw geometry
     91       
     92        // draw entities
     93        List<WorldEntity> *l;
     94        WorldEntity* entity;
     95       
     96        l = entities->get_next(); 
     97        while( l != NULL)
     98        {
     99                entity = l->get_object();
     100                if(     entity->bDraw) entity->draw();
     101          l = l->get_next();
     102        }
     103       
     104        // draw debug coord system
     105        glLoadIdentity();
     106        glBegin(GL_LINES);
     107        for( float x = -128.0; x < 128.0; x += 25.0)
     108        {
     109                for( float y = -128.0; y < 128.0; y += 25.0)
     110                {
     111                        glColor3f(1,0,0);
     112                        glVertex3f(x,y,-128.0);
     113                        glVertex3f(x,y,0.0);
     114                        glColor3f(0.5,0,0);
     115                        glVertex3f(x,y,0.0);
     116                        glVertex3f(x,y,128.0);
     117                }
     118        }
     119        for( float y = -128.0; y < 128.0; y += 25.0)
     120        {
     121                for( float z = -128.0; z < 128.0; z += 25.0)
     122                {
     123                        glColor3f(0,1,0);
     124                        glVertex3f(-128.0,y,z);
     125                        glVertex3f(0.0,y,z);
     126                        glColor3f(0,0.5,0);
     127                        glVertex3f(0.0,y,z);
     128                        glVertex3f(128.0,y,z);
     129                }
     130        }
     131        for( float x = -128.0; x < 128.0; x += 25.0)
     132        {
     133                for( float z = -128.0; z < 128.0; z += 25.0)
     134                {
     135                        glColor3f(0,0,1);
     136                        glVertex3f(x,-128.0,z);
     137                        glVertex3f(x,0.0,z);
     138                        glColor3f(0,0,0.5);
     139                        glVertex3f(x,0.0,z);
     140                        glVertex3f(x,128.0,z);
     141                }
     142        }
     143        //draw track
     144        glColor3f(0,1,1);
     145        for( int i = 0; i < tracklen; i++)
     146        {
     147                glVertex3f(pathnodes[i].x,pathnodes[i].y,pathnodes[i].z);
     148                glVertex3f(pathnodes[(i+1)%tracklen].x,pathnodes[(i+1)%tracklen].y,pathnodes[(i+1)%tracklen].z);
     149        }
     150        glEnd();
     151}
     152
     153/**
     154   \brief updates Placements and notifies entities when they left the world
    72155   
    73    Unloads a world and frees the memory. You cant game until you have a new world loaded.
    74 */
    75 void World::unloadWorld() {}
    76 
    77 
    78 /**
    79    \brief Pause the game
    80    
    81    Pauses the game until the pause is released. During this time nothing moves at all and nothing is calculated. Use it if you have to go out of the game to read some mails...
    82 */
    83 void World::pauseWorld() {}
    84 
    85 
    86 /**
    87    \brief Save the game to file
    88    \param filename: the filename where the savegame should be saved to
    89    
    90    Saves the state of the game to a file. The state is catched like in a multiplayer game over a synchronisable interface.
    91 */
    92 void World::saveGameState(char* filename) {}
    93 
    94 
    95 
    96 /**
    97    \brief Add Player
    98    \param player A reference to the new player object
    99    
    100    Add a new Player to the game. Player has to be initialised previously
    101 */
    102 bool World::addPlayer(Player* player)
    103 {
    104   WorldEntity *we;
    105   playerList->add(we);
    106   /*
    107   playerList* listMember = new playerList;
    108   listMember->player = player;
    109   if ( lastPlayer != null )
    110     {
    111       listMember->number = lastPlayer->number + 1;
    112       listMember->next = lastPlayer;
    113     }
    114   else
    115     {
    116       listMember->number = 0;
    117       listMember->next = null;
    118     }
    119   lastPlayer = listMember;
    120   */
    121 }
    122 
    123 /**
    124    \brief Remove Player
    125    \param player A reference to the new npc object
    126    
    127    Remove a new Player to the game. This kills the player objects.
    128 */
    129 bool World::removePlayer(Player* player) {
    130   playerList->remove(player, LIST_FIND_BW);
    131 }
    132 
    133 /**
    134    \brief Returns the player-entity controlled by the local gamer
    135    \return pointer to player object
    136    
    137    Remove a new Player to the game. This kills the player objects.
    138 */
    139 Player* World::getLocalPlayer()
    140 {
    141   return localPlayer;
    142 }
    143 
    144 
    145 /**
    146    \brief Add Non-Player-Character
    147    \param player A reference to the new npc object
    148    
    149    Add a new Non-Player-Character to the game. Player has to be initialised previously
    150 */
    151 bool World::addNPC(NPC* npc)
    152 {
    153   npcList->add(npc, LIST_ADD_NEXT);
    154   /*
    155   npcList* listMember = new npcList;
    156   listMember->npc = npc;
    157   if ( lastNPC != null )
    158     {
    159       listMember->number = lastNPC->number + 1;
    160       listMember->next = lastNPC;
    161     }
    162   else
    163     {
    164       listMember->number = 0;
    165       listMember->next = null;
    166     }
    167   lastNPC = listMember;
    168   */
    169 }
    170 
    171 
    172 /**
    173    \brief Remove Non-Player Character
    174    \param player A reference to the npc object
    175    
    176    Remove a Non-Player-Character to the game.
    177 */
    178 bool World::removeNPC(NPC* npc)
    179 {
    180   npcList->remove(npc, LIST_FIND_FW);
    181   /*
    182   npcList* npcRef = lastNPC;
    183   npcList* lastRef = lastNPC;
    184   while ( npcRef != null )
    185     {
    186       if ( npcRef->npc == npc ) {
    187         cout <
    188 < "found" << endl;
    189         if ( npcRef == lastRef ) {
    190           lastNPC = lastNPC->next;
    191           delete npcRef;
    192           npcRef = lastNPC;
    193           lastRef = lastNPC;
    194         }
    195         else {
    196           lastRef->next = npcRef->next;
    197           delete npcRef;
    198           npcRef = lastRef->next;
    199         }
    200         cout << "killed ..." << endl;
    201       }
    202       else {
    203         lastRef = npcRef;
    204         npcRef = npcRef->next;
    205       }
    206     }
    207   cout << "npc left" << endl;
    208   */
    209 }
    210 
    211 
    212 
    213 /**
    214    \brief Add environmental object
    215    \param player A reference to the new env object
    216    
    217    Add a new Environment to the world. Env has to be initialised before.
    218 */
    219 bool World::addEnv(Environment* env)
    220 {
    221   /*
    222   envList* listMember = new envList;
    223   listMember->env = env;
    224   if ( lastEnv != null )
    225     {
    226       listMember->number = lastEnv->number + 1;
    227       listMember->next = lastEnv;
    228     }
    229   else
    230     {
    231       listMember->number = 0;
    232       listMember->next = null;
    233     }
    234   lastEnv = listMember;
    235   */
    236 }
    237 
    238 /**
    239    \brief Remove an environmental object
    240    \param player A reference to the env object
    241    
    242    Remove a environment from the game.
    243 */
    244 bool World::removeEnv(Environment* env)
    245 {
     156   This runs trough all WorldEntities and maps Locations to Placements if they are bound, checks
     157   whether they left the level boundaries and calls appropriate functions.
     158*/
     159void World::update ()
     160{
     161        List<WorldEntity> *l;
     162        WorldEntity* entity;
     163        Location* loc;
     164        Placement* plc;
     165        Uint32 t;
     166       
     167        l = entities->get_next(); 
     168        while( l != NULL)
     169        {
     170                entity = l->get_object();
     171               
     172                if( !entity->isFree())
     173                {
     174                        loc = entity->get_location();
     175                        plc = entity->get_placement();
     176                        t = loc->part;
     177                       
     178                        if( t >= tracklen)
     179                        {
     180                                printf("An entity is out of the game area\n");
     181                                entity->left_world ();
     182                        }
     183                        else
     184                        {
     185                                while( track[t].map_coords( loc, plc))
     186                                {
     187                                        track[t].post_leave (entity);
     188                                        if( loc->part >= tracklen)
     189                                        {
     190                                                printf("An entity has left the game area\n");
     191                                                entity->left_world ();
     192                                                break;
     193                                        }
     194                                        track[loc->part].post_enter (entity);
     195                                }
     196                        }
     197                }
     198                else
     199                {
     200                        // TO DO: implement check whether this particular free entity is out of the game area
     201                        // TO DO: call function to notify the entity that it left the game area
     202                }
     203               
     204          l = l->get_next();
     205        }
     206       
     207}
     208
     209/**
     210  \brief relays the passed time since the last frame to entities and Track parts
     211        \param deltaT: the time passed since the last frame in milliseconds
     212*/
     213void World::time_slice (Uint32 deltaT)
     214{
     215        List<WorldEntity> *l;
     216        WorldEntity* entity;
     217        float seconds = deltaT;
     218       
     219        seconds /= 1000;
     220       
     221        l = entities->get_next(); 
     222        while( l != NULL)
     223        {
     224                entity = l->get_object();
     225                entity->tick (seconds);
     226          l = l->get_next();
     227        }
     228       
     229        for( int i = 0; i < tracklen; i++) track[i].tick (seconds);
     230}
     231
     232/**
     233        \brief removes level data from memory
     234*/
     235void World::unload()
     236{
     237        if( pathnodes) delete []pathnodes;
     238        if( track) delete []pathnodes;
     239}
     240
     241/**
     242        \brief loads a simple level for testing purposes
     243*/
     244void World::load_debug_level()
     245{
     246        // create some path nodes
     247        pathnodes = new Vector[6];
     248        pathnodes[0] = Vector(0, 0, 0);
     249        pathnodes[1] = Vector(-100, 40, 0);
     250        pathnodes[2] = Vector(-100, 140, 0);
     251        pathnodes[3] = Vector(0, 180, 0);
     252        pathnodes[4] = Vector(100, 140, 0);
     253        pathnodes[5] = Vector(100, 40, 0);     
     254       
     255        // create the tracks
     256        tracklen = 6;
     257        track = new Track[6];
     258        for( int i = 0; i < tracklen; i++)
     259        {
     260                track[i] = Track( i, (i+1)%tracklen, &pathnodes[i], &pathnodes[(i+1)%tracklen]);
     261        }
     262       
     263        // create a player
     264        WorldEntity* myPlayer = (WorldEntity*) spawn<Player>();
     265       
     266        // bind input
     267  Orxonox *orx = Orxonox::getInstance();
     268  orx->get_localinput()->bind (myPlayer);
    246269 
    247 }
    248 
    249 
    250 
    251 
    252 /**
    253    \brief Draws the World and all Objects contained
    254    
    255    Calls the draw function of all: Objects, Players, Environement. This is the core of all graphics here.
    256 */
    257 void World::drawWorld(void)
    258 {
    259 
    260   glLoadIdentity();
    261   gluLookAt(0.0, -14.0 + DataTank::yOffset, 15.0, 0.0, 0.0 + DataTank::yOffset, 0.0, 0.0, 1.0, 0.0);
    262   /* first draw all players */
    263 
    264 
    265   /*
    266   playerList* tmpPlayer = lastPlayer;
    267   Player* player = tmpPlayer->player;
    268   while( tmpPlayer != null )
    269     {
    270       tmpPlayer->player->paint();
    271       tmpPlayer = tmpPlayer->next;
    272     }
    273   */
    274   /* second draw all npcs */
    275   /*
    276   npcList* tmpNPC = lastNPC;
    277   while( tmpNPC != null )
    278     {
    279       (*tmpNPC->npc).paint();
    280       tmpNPC = tmpNPC->next;
    281     }
    282   */
    283 
    284   /* now draw the rest of the world: environement */
    285   /*
    286   envList* tmpEnv = lastEnv;
    287   while( tmpEnv != null )
    288     {
    289       (*tmpEnv->env).drawEnvironment();
    290       tmpEnv = tmpEnv->next;
    291     }
    292   */
    293 
    294   /* draw the ground grid  */
    295   glColor3f(0.0, 1.0, 0.0);
    296   glBegin(GL_LINES);
    297   /* for the moment, we've got only pseudo moving ground */
    298   for (int y = 0; y < 60; y += 2)
    299     {
    300       for (int x = 0; x < 60; x += 2)
    301         {
    302           glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]);
    303           glVertex3f((float)(x - 28), (float)(y - 30), surface[x+2][y]);
    304         }
    305     }
    306   glEnd();
    307  
    308   glBegin(GL_LINES);
    309   for (int x = 0; x < 60; x += 2)
    310     {
    311       for (int y = 0; y < 60; y += 2)
    312         {
    313           glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]);
    314           glVertex3f((float)(x - 30), (float)(y - 28), surface[x][y+2]);
    315         }
    316     }
    317   glEnd();
    318 
    319   //primitiveMove+=0.07;
    320   DataTank::yOffset += step;
    321 
    322   /*
    323   tmpPlayer = lastPlayer;
    324   while( tmpPlayer != null )
    325     {
    326       tmpPlayer->player->yCor += step;
    327       tmpPlayer = tmpPlayer->next;
    328     }
    329   */
    330 
    331 }
    332 
    333 
    334 void World::initEnvironement()
    335 {
    336 
    337  for (int x = 0; x < 60; x += 2)
    338     {
    339       for (int y = 0; y < 60; y += 2)
    340         {
    341           surface[x][y] = 0;
    342         }
    343     }
    344 }
    345 
    346 
    347 void World::setWorldStep(float step)
    348 {
    349   //cout << "World::setWorldStep(" << step << ");" << endl;
    350   this->step = step;
    351   //cout << "setting speed to " << step << endl;
    352 }
    353 
    354 
    355 
    356 /**
    357    \brief Updates the world and all its objects
    358    
    359    Calculates the new state of the world. User-input and AI of
    360    the enemies are accounted for.
    361 */
    362 void World::updateWorld(void)
    363 {
    364  
    365 
    366 }
    367 
    368 
    369 /* collision detection */
    370 /* fix: bad efficency: stupid brute force */
    371 
    372 void World::detectCollision()
    373 {
    374   /*
    375   //cout << "World::detectCollision" << endl;
    376   float xOff, yOff, zOff, radius;
    377   npcList* tmpNPC, *tmpRef;
    378   */
    379   //cout << "World::detectCollsions" << endl;
    380   /* first: check if any player's shoots trigger a collision */
    381   /*
    382   playerList* tmpPlayer = lastPlayer;
    383   Player* player = tmpPlayer->player;
    384   int state;
    385   while( tmpPlayer != null )
    386     {
    387       tmpNPC = lastNPC;
    388       while( tmpNPC != null )
    389         {
    390           //cout << "npc != null" << endl;
    391           radius = tmpNPC->npc->collisionRadius;
    392           //cout << "worki" << endl;
    393           ShootLaser::shoot* shoota = tmpPlayer->player->shootLaser->lastShoot;
    394           while( shoota != null )
    395             {
    396               xOff = shoota->xCor - tmpNPC->npc->xCor;
    397               yOff = shoota->yCor - tmpNPC->npc->yCor;
    398               zOff = shoota->zCor - tmpNPC->npc->zCor;
    399               if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius )
    400                 {
    401                   //cout << "COLLISION " << endl;
    402                   int state = tmpNPC->npc->hit();
    403   */
    404                   /* state is a value that marks if the ship dies or not */
    405                   /* if state == 0 the ship dies and we have to remove it */
    406                   /*
    407                   if ( state == 0 ) {
    408                     tmpRef = tmpNPC;
    409                     tmpNPC = tmpNPC->next;
    410                     removeNPC(tmpRef->npc);
    411                     break;
    412                   }
    413                  
    414                 }
    415               shoota = shoota->next;
    416             }
    417           //cout << "changing npc..." << endl;
    418           tmpNPC = tmpNPC->next;
    419           //cout << "..changing npc done" << endl;
    420         }
    421       //cout << "changing play..." << endl;
    422       tmpPlayer = tmpPlayer->next;
    423       //cout << "changing play done" << endl;
    424      
    425     }
    426                   */
    427   //cout << "World::detectCollisions middle" << endl;
    428 
    429   /* second: check if any player hits an enemy */
    430 /*
    431   tmpPlayer = lastPlayer;
    432   while( tmpPlayer != null )
    433     {
    434       tmpNPC = lastNPC;
    435       while( tmpNPC != null )
    436         {
    437           radius = tmpNPC->npc->collisionRadius + tmpPlayer->player->collisionRadius;
    438           xOff = tmpPlayer->player->xCor - tmpNPC->npc->xCor;
    439           yOff = tmpPlayer->player->yCor - tmpNPC->npc->yCor;
    440           zOff = tmpPlayer->player->zCor - tmpNPC->npc->zCor;
    441           if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius ) {
    442             //cout << "COLLISION " << endl;
    443             tmpNPC->npc->hit();
    444           }
    445          
    446           tmpNPC = tmpNPC->next;
    447         }
    448      
    449       tmpPlayer = tmpPlayer->next;
    450     }
    451  
    452  
    453 */
    454   /* third: check if any enemy shoots a player */
    455 
    456   //cout << "World::detectCollisions end" << endl;
    457 }
    458 
    459 
    460 
    461 /**
    462    \brief Routine for testing purposes.
    463    
    464    testing, testing, testing...
    465 */
    466 void World::testThaTest(void)
    467 {
    468 /*
    469   cout << "World::testThaTest() called" << endl;
    470 
    471   cout << "addPlayer test..." << endl;
    472   playerList* pl = lastPlayer;
    473   while ( pl != null )
    474     {
    475       cout << "player " << pl->number << " was found" << endl;
    476       pl = pl->next;
    477     }
    478 
    479 
    480   cout << "addNPC test..." << endl;
    481   npcList* nl = lastNPC;
    482   while ( nl != null )
    483     {
    484       cout << "npc " << nl->number << " was found" << endl;
    485       nl = nl->next;
    486     }
    487 
    488 
    489 
    490   cout << "addEnv test..." << endl;
    491   envList* en = lastEnv;
    492   while ( en != null )
    493     {
    494       cout << "env " << en->number << " was found" << endl;
    495       en = en->next;
    496     }
    497 */
    498 }
     270        // bind camera
     271        orx->get_camera()->bind (myPlayer);
     272}
     273
     274/**
     275        \brief calls the correct mapping function to convert a given "look at"-Location to a Camera Placement
     276*/
     277void World::calc_camera_pos (Location* loc, Placement* plc)
     278{
     279  track[loc->part].map_camera (loc, plc);
     280}
  • orxonox/trunk/src/world.h

    r2077 r2190  
    1 /**
    2   Class representating the game-world
    3  
    4   It contains a list of players (if multiplayer game), a list of Non-Player-Characters (nps), a list of Environment Entities. All this things together are building the orxonox-world. This class also handels the story-line (track), the world start/stop, init/uninit abilities. It is the middle point of every orxonox world.
    5 */
     1/*!
     2    \file world.h
     3    \brief Holds and manages all game data
     4*/
    65
    76#ifndef WORLD_H
    87#define WORLD_H
    98
    10 class Player;
    11 class NPC;
    12 class Environment;
     9#include "stdincl.h"
     10
     11class Track;
    1312class WorldEntity;
    1413
    15 template<class T> class List;
    16 
    17 
    18 
    19 //! World Class
    20 /**
    21   Class for World representation
    22  
    23   It contains a list of players (if multiplayer game), a list of Non-Player-Characters (nps), a list of Environment Entities. All this things together are building the orxonox-world. This class also handels the story-line (track), the world start/stop, init/uninit abilities. It is the middle point of every orxonox world.
    24 */
     14//! The game environment
    2515class World {
    2616
     
    2919  ~World ();
    3020
     21        template<typename T>
     22          T* spawn(Location* loc, WorldEntity* owner);  // template to be able to spawn any derivation of WorldEntity
     23        template<typename T>
     24          T* spawn(Placement* plc, WorldEntity* owner);
    3125
    32 
    33   float primitiveMove; //!< deprecated, do not use
    34 
    35   Player *localPlayer; //!< a pointer to the local player object
    36   Player *player1;     //!< a pointer to the second player object
    37   Player *player2;     //!< a pointer to the third player object
    38 
    39   /*
    40   struct playerList {
    41     playerList* next;
    42     Player* player;
    43     int number;
    44   };
    45   playerList* lastPlayer;
    46 
    47   struct npcList {
    48     npcList* next;
    49     NPC* npc;
    50     int number;
    51   };
    52   npcList* lastNPC;
    53 
    54   struct envList {
    55     envList* next;
    56     Environment* env;
    57     int number;
    58   };
    59   envList* lastEnv;
    60   */
    61 
    62 
    63   void loadWorld();
    64   void unloadWorld();
    65   void pauseWorld();
    66   void saveGameState(char* filename);
    67  
    68 
    69   bool addPlayer(Player* player);
    70   bool removePlayer(Player* player);
    71   Player* getLocalPlayer();
    72   bool addNPC(NPC* npc);
    73   bool removeNPC(NPC* npc);
    74   bool addEnv(Environment* env);
    75   bool removeEnv(Environment* env);
    76 
    77  
    78   void drawWorld(void);
    79   void initEnvironement(void);
    80   void setWorldStep(float step);
    81   void updateWorld(void);
    82   void detectCollision(void);
    83   void testThaTest(void);
    84 
     26        void time_slice (Uint32 deltaT);
     27        void collide ();
     28        void draw ();
     29        void update (); // maps Locations to Placements
     30        void calc_camera_pos (Location* loc, Placement* plc);
     31       
     32        void unload ();
     33       
     34        void load_debug_level ();
     35       
    8536 private:
    86   float surface[120][120]; //!< deprecated: used to build a surface
    87   float step; //!< this is the step
    88 
    89   List<WorldEntity*> *playerList; //!< the list of players, usualy very short
    90   List<WorldEntity*> *npcList;  //!< list of non player characters (npc)
    91   List<WorldEntity*> *envList;  //!< list of environment objects
    92 
     37 
     38        List<WorldEntity>* entities;
     39       
     40                // base level data
     41        Track* track;
     42        Uint32 tracklen;
     43        Vector* pathnodes;
    9344
    9445};
    9546
     47/**
     48    \brief spawn a new WorldEntity at a Location
     49    \param loc: the Location where the Entity should be spawned
     50    \param owner: a pointer to the parent of the Entity
     51    \return a pointer to the new WorldEntity or NULL if there was an error
     52   
     53    You can use this function to spawn any derivation of WorldEntity you want, just specify the desired
     54    class within the template specification brackets. Do not attempt to spawn any classes that have NOT been
     55    derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn()
     56    works with both free and bound WorldEntities.
     57*/
     58template<typename T> T* World::spawn(Location* loc = NULL, WorldEntity* owner = NULL)
     59{
     60        Location zeroloc;
     61        T* entity = new T();
     62        entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
     63        if( loc == NULL)
     64        {
     65                zeroloc.dist = 0;
     66                zeroloc.part = 0;
     67                zeroloc.pos = Vector();
     68                zeroloc.rot = Quaternion();
     69                loc = &zeroloc;
     70        }
     71        entity->init (loc, owner);
     72        if (entity->bFree)
     73        {
     74                track[loc->part].map_coords( loc, entity->get_placement());
     75        }
     76        entity->post_spawn ();
     77        return entity;
     78}
     79
     80/**
     81    \brief spawn a new WorldEntity at a Placement
     82    \param lplc: the placement where the Entity should be spawned
     83    \param owner: a pointer to the parent of the Entity
     84    \return a pointer to the new WorldEntity or NULL if there was an error
     85   
     86    You can use this function to spawn any FREE derivation of WorldEntity you want, just specify the desired
     87    class within the template specification brackets. Do not attempt to spawn any classes that have NOT been
     88    derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn()
     89    works with free WorldEntities only, you will provoke an error message if you try to spawn a bound Entity with
     90    a Placement.
     91*/
     92template<typename T> T* World::spawn(Placement* plc, WorldEntity* owner = NULL)
     93{
     94        T* entity = new T();
     95        entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
     96        entity->init (plc, owner);
     97        if (!entity->bFree)
     98        {
     99                printf("Can't spawn unfree entity with placement\n");
     100                entities->remove( (WorldEntity*)entity, LIST_FIND_FW);
     101                return NULL;
     102        }
     103        entity->post_spawn ();
     104        return entity;
     105}
     106
    96107#endif
  • orxonox/trunk/src/world_entity.cc

    r2077 r2190  
    1313   ### File Specific:
    1414   main-programmer: Patrick Boenzli
    15    co-programmer: ...
     15   co-programmer: Christian Meyer
    1616*/
    1717
     
    1919
    2020#include "world_entity.h"
    21 
    22 #include "vector.h"
     21#include "stdincl.h"
     22#include "collision.h"
    2323
    2424using namespace std;
    2525
    26 
    2726/**
    28    \brief
    29    \param v:
    30    \return
     27   \brief standard constructor
     28   
     29   Every derived contructor HAS to call the previous one supplying the isFree parameter. This is necessary to distunguish
     30   between free and bound entities. The difference between them is simply the fact that the movement of a free entity is
     31   not bound to the track of a world. Use this to implement projectile or effect classes that do not have to travel along the track.
     32   To specify an entity to be free or bound set the default parameter in the declaration of the constructor.
     33   Theoretically you should never have to call the constructor of an Entity directly, for it is called by the spawn() function of the World
     34   class. So if you want to create a new entity at any time, call World::spawn(). It will handle everything that is necessary.
    3135*/
    32 
    33 /**
    34    \brief Constructor
    35 
    36    This Constructor initializises the all WorldEntities. Everything, that is a part of the game-world is a child of WorldEntity. This class implements empty functions for all sort of operation a WorldEntity has to or can implement.
    37 This is some sort of standard interface to all WorldEntities...
    38 */
    39 WorldEntity::WorldEntity ()
     36WorldEntity::WorldEntity (bool isFree) : bFree(isFree)
    4037{
    41   health = 100;
    42   speed = 0;
    43 }
    44 
    45 
    46 WorldEntity::~WorldEntity () {}
    47 
    48 /**
    49    \brief sets the position of this entity
    50    \param position: Vector, pointing (from 0,0,0) to the new position
    51 */
    52 void WorldEntity::setPosition(Vector* position) {}
    53 
    54 /**
    55    \brief gets the postion of this entity
    56    \return a Vector, pointing (from 0,0,0) to the new position
    57 */
    58 Vector* getPosition() {}
    59 
    60 /**
    61    \brief sets orientation of this entity
    62    \param orientation: vector specifying in which direction the entity looks
    63 */
    64 void WorldEntity::setOrientation(Vector* orientation) {}
    65 
    66 /**
    67    \brief gets orientation of this entity
    68    \return vector specifying in which direction the entity looks
    69 */
    70 Vector* WorldEntity::getOrientation() {}
    71 
    72 /**
    73    \brief sets the speed of the entity, if any
    74    \param speed: the speed in points (openGL points) per seconds
    75 */
    76 void WorldEntity::setSpeed(float speed)
    77 {
    78   this->speed = speed;
     38        collisioncluster = NULL;
     39        owner = NULL;
    7940}
    8041
    8142/**
    82    \brief gets the speed of the entity, if any
    83    \return the speed in points (openGL points) per seconds
     43        \brief standard destructor
    8444*/
    85 float WorldEntity::getSpeed()
     45WorldEntity::~WorldEntity ()
    8646{
    87   return speed;
     47        if( collisioncluster != NULL) delete collisioncluster;
    8848}
    8949
    9050/**
    91    \brief sets the health of the entity
    92    \param health: number for the life count, normaly {0..100}
     51        \brief get the Location of the WorldEntity
     52        \return a pointer to location
    9353*/
    94 void WorldEntity::setHealth(float health)
     54Location* WorldEntity::get_location ()
    9555{
    96   this->health = health;
     56        return &loc;
    9757}
    9858
    9959/**
    100    \brief gets the health of the entity
    101    \return number for the life count, normaly {0..100}
     60        \brief get the Placement of the WorldEntity
     61        \return a pointer to placement
    10262*/
    103 float WorldEntity::getHealth()
     63Placement* WorldEntity::get_placement ()
    10464{
    105   return health;
     65        return &place;
    10666}
    10767
    10868/**
    109    \brief this method is called every tick
    110    \param time: the time since the last frame was painted
    111 
    112    This function is called before every repaint of the world, to update every time dependent variable of the entity. If the entity moves, it has to calculate the new position every tick here in this function. Do not use this for animations.
     69        \brief query whether the WorldEntity in question is free
     70        \return true if the WorldEntity is free or false if it isn't
    11371*/
    114 void WorldEntity::tick(float dt)
    115 {}
     72bool WorldEntity::isFree ()
     73{
     74  return bFree;
     75}
    11676
    11777/**
    118    \brief the entity is painted to the screen with this function
     78        \brief set the WorldEntity's collision hull
     79        \param newhull: a pointer to a completely assembled CollisionCluster
     80       
     81        Any previously assigned collision hull will be deleted on reassignment
     82*/
     83void WorldEntity::set_collision (CollisionCluster* newhull)
     84{
     85        if( newhull == NULL) return;
     86        if( collisioncluster != NULL) delete collisioncluster;
     87        collisioncluster = newhull;
     88}
     89
     90/**
     91        \brief this method is called every frame
     92        \param time: the time in seconds that has passed since the last tick
     93       
     94        Handle all stuff that should update with time inside this method (movement, animation, etc.)
     95*/
     96void WorldEntity::tick(float time)
     97{
     98}
     99
     100/**
     101   \brief the entity is drawn onto the screen with this function
    119102
    120103   This is a central function of an entity: call it to let the entity painted to the screen. Just override this function with whatever you want to be drawn.
    121104*/
    122 void WorldEntity::paint()
    123 {}
     105void WorldEntity::draw()
     106{
     107}
    124108
    125 /* virtual void WorldEntity::actionEvent(Event* event); */
    126109/**
    127    \brief this function is called, when two entities collide
    128    \param we: the world entity, with whom it collides
    129    \param loc: place where the collision happens
     110        \brief this function is called, when two entities collide
     111        \param other: the world entity with whom it collides
     112        \param ownhitflags: flags to the CollisionCluster subsections that registered an impact
     113        \param otherhitflags: flags to the CollisionCluster subsections of the other entity that registered an impact
     114
     115        Implement behaviour like damage application or other miscellaneous collision stuff in this function
    130116*/
    131 void WorldEntity::collide(WorldEntity* we, Vector loc) {}
     117void WorldEntity::collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {}
    132118
    133119/**
     
    141127
    142128/**
    143    \brief this function is called, if the entity is to be destroied
     129   \brief this function is called when the entity is to be destroied
    144130   
    145131   This can be called, if eg. something realy bad happens :)
     
    147133void WorldEntity::destroy() {}
    148134
    149 /**
    150    \brief this function is automatically called before the entity enters the world
    151 */
    152 void WorldEntity::entityPreEnter() {}
    153135
    154136/**
    155    \brief this function is automatically called after the entity enters the world
    156 
     137        \brief basic initialisation for bound Entities
    157138*/
    158 void WorldEntity::entityPostEnter() {}
     139void WorldEntity::init( Location* spawnloc, WorldEntity* spawnowner)
     140{
     141        loc = *spawnloc;
     142        owner = spawnowner;
     143}
    159144
    160145/**
    161    \brief this function is automatically called before the entity quits the world
    162 
     146        \brief basic initialisation for free Entities
    163147*/
    164 void WorldEntity::entityPreQuit() {}
     148void WorldEntity::init( Placement* spawnplc, WorldEntity* spawnowner)
     149{
     150        place = *spawnplc;
     151        owner = spawnowner;
     152}
    165153
    166154/**
    167    \brief this function is automatically called after the entity quits the world
     155        \brief this is called immediately after the Entity has been constructed and initialized
     156       
     157        Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here.
     158        DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted.
    168159*/
    169 void WorldEntity::entityPostQuit() {}
     160void WorldEntity::post_spawn ()
     161{
     162}
     163
     164/**
     165        \brief this handles incoming command messages
     166        \param cmd: a pointer to the incoming Command structure
     167       
     168        Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used
     169        to send commands from one WorldEntity to another.
     170*/
     171void WorldEntity::command (Command* cmd)
     172{
     173}
     174
     175/**
     176        \brief this is called by the local Camera to determine the point it should look at on the WorldEntity
     177        \param locbuf: a pointer to the buffer to fill with a location to look at
     178       
     179        You may put any Location you want into locbuf, the Camera will determine via the corresponding Track how
     180        to look at the location you return with this.
     181*/
     182void WorldEntity::get_lookat (Location* locbuf)
     183{
     184}
     185
     186/**
     187        \brief this method is called by the world if the WorldEntity leaves valid gamespace
     188       
     189        For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a
     190        place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy).
     191*/
     192void WorldEntity::left_world ()
     193{
     194}
  • orxonox/trunk/src/world_entity.h

    r2077 r2190  
    11/*!
    22    \file world_entity.h
    3     \brief A base class for all objects in the world
    4    
    5     This is the base class of all objects in the game-world. If you want to have an object in the world, that can realy interact with other objects and that is also dispbayable etc. you have to extend this class and override the needed functions.
    6 */
    7 
    8 
     3    \brief Definition of the basic WorldEntity
     4*/
    95
    106#ifndef WORLD_ENTITY_H
    117#define WORLD_ENTITY_H
    128
    13 #include "data_tank.h"
     9#include "stdincl.h"
    1410
    15 class Vector;
    16 class Ability;
     11class CollisionCluster;
    1712
    18 //! WorldEntity
    19 /**
    20   A base class for all objects in the world
    21 
    22   This is the base class of all objects in the game-world. If you want to have an object in the world, that can realy interact with other objects and that is also dispbayable etc. you have to extend this class and override the needed functions.
    23 */
    24 class WorldEntity {
     13//! Basic class from which all interactive stuff in the world is derived from
     14class WorldEntity
     15{       
     16        friend class World;
    2517
    2618 public:
    27   WorldEntity ();
     19  WorldEntity (bool isFree = false);
    2820  ~WorldEntity ();
    2921
     22        Location* get_location ();
     23        Placement* get_placement ();
     24        void set_collision (CollisionCluster* newhull);
    3025
    31   void setPosition(Vector* position);
    32   Vector* getPosition();
    33   void setOrientation(Vector* orientation);
    34   Vector* getOrientation();
    35   void setSpawnPoint(Vector* place);
    36   void setSpeed(float speed);
    37   float getSpeed();
    38   void setHealth(float health);
    39   float getHealth();
     26        bool isFree ();
     27       
     28  //void addAbility(Ability* ability);
     29  //void removeAbility(Ability* ability);
    4030
    41   void addAbility(Ability* ability);
    42   void removeAbility(Ability* ability);
     31        virtual void post_spawn ();
     32  virtual void tick (float time);
     33  virtual void hit (WorldEntity* weapon, Vector loc);
     34  virtual void destroy ();
     35  virtual void collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags);
     36        virtual void command (Command* cmd);
     37 
     38  virtual void draw ();
     39  virtual void get_lookat (Location* locbuf);
    4340
    44   virtual void tick(float dt);
    45   virtual void paint();
    46   /* virtual void actionEvent(Event* event); */
    47   virtual void collide(WorldEntity* we, Vector loc);
    48   virtual void hit(WorldEntity* weapon, Vector loc);
    49   virtual void destroy();
    50 
    51   virtual void entityPreEnter();
    52   virtual void entityPostEnter();
    53   virtual void entityPreQuit();
    54   virtual void entityPostQuit();
    55 
    56  
     41        virtual void left_world ();
    5742
    5843 private:
    59   Vector* position;    //!< position of the entity
    60   Vector* orientation; //!< orientation of the entity
    61   /* List of abilities */
    62   float health; //!< health of the entity, if any
    63   float speed; //!< speed of the entity if any
    64   /* entity can be in the air or at ground: */
    65   int airGround; //!< is it air or bound to the ground (ground=0, air=1)
     44  const bool bFree;     
     45  bool bCollide;
     46  bool bDraw;
     47 
     48        WorldEntity* owner;
     49        CollisionCluster* collisioncluster;
     50        Placement place;
     51        Location loc;
    6652
    67  
    68 
     53        void init( Location* spawnloc, WorldEntity* spawnowner);
     54        void init( Placement* spawnplc, WorldEntity* spawnowner);
    6955};
    7056
Note: See TracChangeset for help on using the changeset viewer.