Changeset 2190 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Jul 17, 2004, 12:11:20 PM (20 years ago)
- Location:
- orxonox/trunk
- Files:
-
- 2 deleted
- 18 edited
- 14 copied
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/config.h.in
r1971 r2190 34 34 /* Define to 1 if you have the <memory.h> header file. */ 35 35 #undef HAVE_MEMORY_H 36 37 /* Define to 1 if you have the <SDL/SDL.h> header file. */ 38 #undef HAVE_SDL_SDL_H 36 39 37 40 /* Define to 1 if you have the `sqrt' function. */ -
orxonox/trunk/configure
r2018 r2190 1730 1730 case `uname` in 1731 1731 *MINGW*) 1732 mingw= yes1732 mingw="yes" 1733 1733 MSBITFIELDS="-mms-bitfields" 1734 MWINDOWS="-mwindows" 1734 1735 ;; 1735 1736 *) 1736 mingw= no1737 mingw="no" 1737 1738 ;; 1738 1739 esac … … 4900 4901 fi 4901 4902 fi 4903 4904 ## mingw CHECK 4905 if test $mingw = yes ; then 4906 echo "$as_me:$LINENO: checking for main in -lmingw32" >&5 4907 echo $ECHO_N "checking for main in -lmingw32... $ECHO_C" >&6 4908 if test "${ac_cv_lib_mingw32_main+set}" = set; then 4909 echo $ECHO_N "(cached) $ECHO_C" >&6 4910 else 4911 ac_check_lib_save_LIBS=$LIBS 4912 LIBS="-lmingw32 $LIBS" 4913 cat >conftest.$ac_ext <<_ACEOF 4914 /* confdefs.h. */ 4915 _ACEOF 4916 cat confdefs.h >>conftest.$ac_ext 4917 cat >>conftest.$ac_ext <<_ACEOF 4918 /* end confdefs.h. */ 4919 4920 4921 int 4922 main () 4923 { 4924 main (); 4925 ; 4926 return 0; 4927 } 4928 _ACEOF 4929 rm -f conftest.$ac_objext conftest$ac_exeext 4930 if { (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 4952 else 4953 echo "$as_me: failed program was:" >&5 4954 sed 's/^/| /' conftest.$ac_ext >&5 4955 4956 ac_cv_lib_mingw32_main=no 4957 fi 4958 rm -f conftest.err conftest.$ac_objext \ 4959 conftest$ac_exeext conftest.$ac_ext 4960 LIBS=$ac_check_lib_save_LIBS 4961 fi 4962 echo "$as_me:$LINENO: result: $ac_cv_lib_mingw32_main" >&5 4963 echo "${ECHO_T}$ac_cv_lib_mingw32_main" >&6 4964 if test $ac_cv_lib_mingw32_main = yes; then 4965 FOUND_mingw32=yes 4966 fi 4967 4968 if test $FOUND_mingw32 = "yes"; then 4969 LIBS="$LIBS -lmingw32" 4970 fi 4971 fi 4972 4973 ## SDL CHECK 4974 4975 #checking for SDL libs 4976 4977 for ac_header in SDL/SDL.h 4978 do 4979 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` 4980 if eval "test \"\${$as_ac_Header+set}\" = set"; then 4981 echo "$as_me:$LINENO: checking for $ac_header" >&5 4982 echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 4983 if eval "test \"\${$as_ac_Header+set}\" = set"; then 4984 echo $ECHO_N "(cached) $ECHO_C" >&6 4985 fi 4986 echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 4987 echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 4988 else 4989 # Is the header compilable? 4990 echo "$as_me:$LINENO: checking $ac_header usability" >&5 4991 echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 4992 cat >conftest.$ac_ext <<_ACEOF 4993 /* confdefs.h. */ 4994 _ACEOF 4995 cat confdefs.h >>conftest.$ac_ext 4996 cat >>conftest.$ac_ext <<_ACEOF 4997 /* end confdefs.h. */ 4998 $ac_includes_default 4999 #include <$ac_header> 5000 _ACEOF 5001 rm -f conftest.$ac_objext 5002 if { (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 5024 else 5025 echo "$as_me: failed program was:" >&5 5026 sed 's/^/| /' conftest.$ac_ext >&5 5027 5028 ac_header_compiler=no 5029 fi 5030 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext 5031 echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 5032 echo "${ECHO_T}$ac_header_compiler" >&6 5033 5034 # Is the header present? 5035 echo "$as_me:$LINENO: checking $ac_header presence" >&5 5036 echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 5037 cat >conftest.$ac_ext <<_ACEOF 5038 /* confdefs.h. */ 5039 _ACEOF 5040 cat confdefs.h >>conftest.$ac_ext 5041 cat >>conftest.$ac_ext <<_ACEOF 5042 /* end confdefs.h. */ 5043 #include <$ac_header> 5044 _ACEOF 5045 if { (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 5059 else 5060 ac_cpp_err=yes 5061 fi 5062 if test -z "$ac_cpp_err"; then 5063 ac_header_preproc=yes 5064 else 5065 echo "$as_me: failed program was:" >&5 5066 sed 's/^/| /' conftest.$ac_ext >&5 5067 5068 ac_header_preproc=no 5069 fi 5070 rm -f conftest.err conftest.$ac_ext 5071 echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 5072 echo "${ECHO_T}$ac_header_preproc" >&6 5073 5074 # So? What about this header? 5075 case $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 5078 echo "$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 5080 echo "$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 5085 echo "$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 5087 echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} 5088 { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 5089 echo "$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 5091 echo "$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 5093 echo "$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 5095 echo "$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 ;; 5105 esac 5106 echo "$as_me:$LINENO: checking for $ac_header" >&5 5107 echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 5108 if eval "test \"\${$as_ac_Header+set}\" = set"; then 5109 echo $ECHO_N "(cached) $ECHO_C" >&6 5110 else 5111 eval "$as_ac_Header=\$ac_header_preproc" 5112 fi 5113 echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 5114 echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 5115 5116 fi 5117 if 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 5122 else 5123 { { echo "$as_me:$LINENO: error: cannot find SDL headers" >&5 5124 echo "$as_me: error: cannot find SDL headers" >&2;} 5125 { (exit 1); exit 1; }; } 5126 fi 5127 5128 done 5129 5130 if test $mingw = no ; then 5131 echo "$as_me:$LINENO: checking for main in -lSDL" >&5 5132 echo $ECHO_N "checking for main in -lSDL... $ECHO_C" >&6 5133 if test "${ac_cv_lib_SDL_main+set}" = set; then 5134 echo $ECHO_N "(cached) $ECHO_C" >&6 5135 else 5136 ac_check_lib_save_LIBS=$LIBS 5137 LIBS="-lSDL $LIBS" 5138 cat >conftest.$ac_ext <<_ACEOF 5139 /* confdefs.h. */ 5140 _ACEOF 5141 cat confdefs.h >>conftest.$ac_ext 5142 cat >>conftest.$ac_ext <<_ACEOF 5143 /* end confdefs.h. */ 5144 5145 5146 int 5147 main () 5148 { 5149 main (); 5150 ; 5151 return 0; 5152 } 5153 _ACEOF 5154 rm -f conftest.$ac_objext conftest$ac_exeext 5155 if { (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 5177 else 5178 echo "$as_me: failed program was:" >&5 5179 sed 's/^/| /' conftest.$ac_ext >&5 5180 5181 ac_cv_lib_SDL_main=no 5182 fi 5183 rm -f conftest.err conftest.$ac_objext \ 5184 conftest$ac_exeext conftest.$ac_ext 5185 LIBS=$ac_check_lib_save_LIBS 5186 fi 5187 echo "$as_me:$LINENO: result: $ac_cv_lib_SDL_main" >&5 5188 echo "${ECHO_T}$ac_cv_lib_SDL_main" >&6 5189 if test $ac_cv_lib_SDL_main = yes; then 5190 FOUND_SDL=yes 5191 fi 5192 5193 if test "$FOUND_SDL" = "yes" ; then 5194 LIBS="$LIBS -lSDL" 5195 fi 5196 # checking for Windows sdl library 5197 else 5198 echo "$as_me:$LINENO: checking for main in -lsdlmain" >&5 5199 echo $ECHO_N "checking for main in -lsdlmain... $ECHO_C" >&6 5200 if test "${ac_cv_lib_sdlmain_main+set}" = set; then 5201 echo $ECHO_N "(cached) $ECHO_C" >&6 5202 else 5203 ac_check_lib_save_LIBS=$LIBS 5204 LIBS="-lsdlmain $LIBS" 5205 cat >conftest.$ac_ext <<_ACEOF 5206 /* confdefs.h. */ 5207 _ACEOF 5208 cat confdefs.h >>conftest.$ac_ext 5209 cat >>conftest.$ac_ext <<_ACEOF 5210 /* end confdefs.h. */ 5211 5212 5213 int 5214 main () 5215 { 5216 main (); 5217 ; 5218 return 0; 5219 } 5220 _ACEOF 5221 rm -f conftest.$ac_objext conftest$ac_exeext 5222 if { (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 5244 else 5245 echo "$as_me: failed program was:" >&5 5246 sed 's/^/| /' conftest.$ac_ext >&5 5247 5248 ac_cv_lib_sdlmain_main=no 5249 fi 5250 rm -f conftest.err conftest.$ac_objext \ 5251 conftest$ac_exeext conftest.$ac_ext 5252 LIBS=$ac_check_lib_save_LIBS 5253 fi 5254 echo "$as_me:$LINENO: result: $ac_cv_lib_sdlmain_main" >&5 5255 echo "${ECHO_T}$ac_cv_lib_sdlmain_main" >&6 5256 if test $ac_cv_lib_sdlmain_main = yes; then 5257 FOUND_sdlmain=yes 5258 fi 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 5264 echo $ECHO_N "checking for main in -lsdl... $ECHO_C" >&6 5265 if test "${ac_cv_lib_sdl_main+set}" = set; then 5266 echo $ECHO_N "(cached) $ECHO_C" >&6 5267 else 5268 ac_check_lib_save_LIBS=$LIBS 5269 LIBS="-lsdl $LIBS" 5270 cat >conftest.$ac_ext <<_ACEOF 5271 /* confdefs.h. */ 5272 _ACEOF 5273 cat confdefs.h >>conftest.$ac_ext 5274 cat >>conftest.$ac_ext <<_ACEOF 5275 /* end confdefs.h. */ 5276 5277 5278 int 5279 main () 5280 { 5281 main (); 5282 ; 5283 return 0; 5284 } 5285 _ACEOF 5286 rm -f conftest.$ac_objext conftest$ac_exeext 5287 if { (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 5309 else 5310 echo "$as_me: failed program was:" >&5 5311 sed 's/^/| /' conftest.$ac_ext >&5 5312 5313 ac_cv_lib_sdl_main=no 5314 fi 5315 rm -f conftest.err conftest.$ac_objext \ 5316 conftest$ac_exeext conftest.$ac_ext 5317 LIBS=$ac_check_lib_save_LIBS 5318 fi 5319 echo "$as_me:$LINENO: result: $ac_cv_lib_sdl_main" >&5 5320 echo "${ECHO_T}$ac_cv_lib_sdl_main" >&6 5321 if test $ac_cv_lib_sdl_main = yes; then 5322 FOUND_sdl=yes 5323 fi 5324 5325 if test "$FOUND_sdl" = "yes" ; then 5326 LIBS="$LIBS -lsdl" 5327 fi 5328 fi 5329 5330 #checking for pthread libs 5331 echo "$as_me:$LINENO: checking for main in -lpthread" >&5 5332 echo $ECHO_N "checking for main in -lpthread... $ECHO_C" >&6 5333 if test "${ac_cv_lib_pthread_main+set}" = set; then 5334 echo $ECHO_N "(cached) $ECHO_C" >&6 5335 else 5336 ac_check_lib_save_LIBS=$LIBS 5337 LIBS="-lpthread $LIBS" 5338 cat >conftest.$ac_ext <<_ACEOF 5339 /* confdefs.h. */ 5340 _ACEOF 5341 cat confdefs.h >>conftest.$ac_ext 5342 cat >>conftest.$ac_ext <<_ACEOF 5343 /* end confdefs.h. */ 5344 5345 5346 int 5347 main () 5348 { 5349 main (); 5350 ; 5351 return 0; 5352 } 5353 _ACEOF 5354 rm -f conftest.$ac_objext conftest$ac_exeext 5355 if { (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 5377 else 5378 echo "$as_me: failed program was:" >&5 5379 sed 's/^/| /' conftest.$ac_ext >&5 5380 5381 ac_cv_lib_pthread_main=no 5382 fi 5383 rm -f conftest.err conftest.$ac_objext \ 5384 conftest$ac_exeext conftest.$ac_ext 5385 LIBS=$ac_check_lib_save_LIBS 5386 fi 5387 echo "$as_me:$LINENO: result: $ac_cv_lib_pthread_main" >&5 5388 echo "${ECHO_T}$ac_cv_lib_pthread_main" >&6 5389 if test $ac_cv_lib_pthread_main = yes; then 5390 FOUND_pthread=yes 5391 fi 5392 5393 if test "$FOUND_pthread" = "yes" ; then 5394 LIBS="$LIBS -lpthread" 5395 fi 5396 5397 5398 4902 5399 4903 5400 # FIXME: Replace `main' with a function in `-lm': -
orxonox/trunk/configure.ac
r2018 r2190 11 11 case `uname` in 12 12 *MINGW*) 13 mingw= yes13 mingw="yes" 14 14 MSBITFIELDS="-mms-bitfields" 15 MWINDOWS="-mwindows" 15 16 ;; 16 17 *) 17 mingw= no18 mingw="no" 18 19 ;; 19 20 esac … … 103 104 fi 104 105 106 ## mingw CHECK 107 if 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 112 fi 113 114 ## SDL CHECK 115 116 #checking for SDL libs 117 AC_CHECK_HEADERS(SDL/SDL.h ,, 118 [AC_MSG_ERROR([cannot find SDL headers]) ]) 119 if 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 125 else 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 134 fi 135 136 #checking for pthread libs 137 AC_CHECK_LIB([pthread], [main], FOUND_pthread=yes) 138 if test "$FOUND_pthread" = "yes" ; then 139 LIBS="$LIBS -lpthread" 140 fi 141 142 143 144 105 145 # FIXME: Replace `main' with a function in `-lm': 106 146 AC_CHECK_LIB([m], [main]) -
orxonox/trunk/src/Makefile.am
r2077 r2190 1 1 AM_CXXFLAGS="-I/usr/X11R6/include" 2 AM_LDFLAGS="-L/usr/Mesa-6.0.1/lib -L/usr/X11R6/lib -lXt -lX11" 2 AM_LDFLAGS="-L/usr/Mesa-6.0.1/lib -L/usr/X11R6/lib -lXt -lX11" $(MWINDOWS) 3 3 4 4 #"-O3 -pedantic -fPIC -ffast-math -I/usr/X11R6/include" … … 6 6 7 7 bin_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.cc8 orxonox_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 9 9 10 10 # uncomment the following if bencoder requires the math library 11 # gui_LDADD=-lm11 #orxonox_LDADD=-lm 12 12 13 13 #EXTRA_DIST=orxonox.lsm.in orxonox.spec.in orxonox.texinfo -
orxonox/trunk/src/Makefile.in
r2077 r2190 112 112 target_alias = @target_alias@ 113 113 AM_CXXFLAGS = "-I/usr/X11R6/include" 114 AM_LDFLAGS = "-L/usr/Mesa-6.0.1/lib -L/usr/X11R6/lib -lXt -lX11" 114 AM_LDFLAGS = "-L/usr/Mesa-6.0.1/lib -L/usr/X11R6/lib -lXt -lX11" $(MWINDOWS) 115 115 116 116 117 117 #"-O3 -pedantic -fPIC -ffast-math -I/usr/X11R6/include" 118 118 bin_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.cc119 orxonox_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 120 120 subdir = src 121 121 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 … … 126 126 PROGRAMS = $(bin_PROGRAMS) 127 127 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) 128 am_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) 134 132 orxonox_OBJECTS = $(am_orxonox_OBJECTS) 135 133 orxonox_LDADD = $(LDADD) … … 140 138 depcomp = $(SHELL) $(top_srcdir)/depcomp 141 139 am__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 150 147 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 151 148 $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) … … 200 197 -rm -f *.tab.c 201 198 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@ 204 202 @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@ 208 205 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox.Po@am__quote@ 209 206 @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@ 214 208 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@ 215 209 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/world.Po@am__quote@ … … 414 408 415 409 # uncomment the following if bencoder requires the math library 416 # gui_LDADD=-lm410 #orxonox_LDADD=-lm 417 411 418 412 #EXTRA_DIST=orxonox.lsm.in orxonox.spec.in orxonox.texinfo -
orxonox/trunk/src/data_tank.cc
r1956 r2190 19 19 using namespace std; 20 20 21 float DataTank::xOffset = 0;22 float DataTank::yOffset = 0;23 float DataTank::zOffset = 0;24 25 21 DataTank::DataTank () {} 26 22 DataTank::~DataTank () {} -
orxonox/trunk/src/data_tank.h
r1956 r2190 10 10 ~DataTank (); 11 11 12 static float xOffset;13 static float yOffset;14 static float zOffset;15 16 12 }; 17 13 -
orxonox/trunk/src/orxonox.cc
r2036 r2190 21 21 ### File Specific: 22 22 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" 31 27 #include "world.h" 32 #include " input_output.h"28 #include "camera.h" 33 29 #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> 40 32 41 33 using namespace std; 42 34 43 44 Orxonox::Orxonox () 35 /** 36 \brief create a new Orxonox 37 */ 38 Orxonox::Orxonox () 45 39 { 46 40 pause = false; 47 41 } 48 42 49 50 43 /** 44 \brief remove Orxonox from memory 45 */ 51 46 Orxonox::~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 */ 56 57 Orxonox* 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 73 58 74 59 Orxonox* Orxonox::getInstance (void) … … 79 64 } 80 65 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 */ 73 void 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 */ 92 int 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 */ 127 int 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); 86 158 glEnable(GL_DEPTH_TEST); 87 glutInitWindowSize(500, 500); 88 //glutFullScreen(); 89 glutInitWindowPosition(100, 100); 90 glutCreateWindow("OrxonoX"); 159 glEnable(GL_COLOR); 91 160 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 */ 171 int Orxonox::init_sound () 172 { 173 printf("Not yet implemented\n"); 174 return 0; 175 } 176 177 /** 178 \brief initializes input functions 179 */ 180 int 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 */ 191 int Orxonox::init_networking () 192 { 193 printf("Not yet implemented\n"); 194 return 0; 195 } 196 197 /** 198 \brief initializes and loads resource files 199 */ 200 int Orxonox::init_resources () 201 { 202 printf("Not yet implemented\n"); 203 return 0; 204 } 205 206 /** 207 \brief initializes the world 208 */ 209 int 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 */ 222 void Orxonox::quitGame() 223 { 224 bQuitOrxonox = true; 225 } 226 227 /** 228 \brief this runs all of Orxonox 229 */ 230 void Orxonox::mainLoop() 231 { 232 lastframe = SDL_GetTicks(); 233 bQuitOrxonox = false; 234 // This is where everything is run 235 printf("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(); 197 248 } 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 249 printf("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 */ 256 void 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 */ 264 void Orxonox::synchronize () 265 { 266 // Get remote input 267 // Update synchronizables 268 } 269 270 /** 271 \brief run all input processing 272 */ 273 void Orxonox::handle_input () 274 { 275 // localinput 276 localinput->process(); 277 // remoteinput 278 } 279 280 /** 281 \brief advance the timeline 282 */ 283 void 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 */ 298 void 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 */ 308 bool 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 */ 321 void 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 */ 338 Camera* 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 */ 347 CommandNode* 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 */ 356 World* Orxonox::get_world () 357 { 358 return world; 359 } 330 360 331 361 int main (int argc, char** argv) 332 362 { 363 printf(">>> Starting Orxonox <<<\n"); 333 364 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 339 376 return 0; 340 377 } -
orxonox/trunk/src/orxonox.h
r2036 r2190 1 /*! 2 \file orxonox.h 3 \brief Orxonox core functions 4 */ 1 5 2 6 #ifndef ORXONOX_H 3 7 #define ORXONOX_H 4 8 9 #include <SDL/SDL.h> 10 11 #include "stdincl.h" 12 13 class CommandNode; 14 class WorldEntity; 15 class DataTank; 5 16 class World; 6 class InputOutput; 7 class Player; 17 class Camera; 8 18 9 19 //! Orxonox core singleton class 20 /** 21 */ 10 22 class Orxonox { 11 23 … … 14 26 Orxonox (); 15 27 ~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; 27 39 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(); 32 60 33 static void timeSlice(int value); 61 void event_handler (SDL_Event* event); 62 bool system_command (Command* cmd); 34 63 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(); 50 71 }; 51 72 -
orxonox/trunk/src/player.cc
r2036 r2190 13 13 ### File Specific: 14 14 main-programmer: Patrick Boenzli 15 co-programmer: 15 co-programmer: Christian Meyer 16 16 */ 17 17 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 26 18 #include "player.h" 19 #include "stdincl.h" 20 #include "collision.h" 27 21 28 22 using namespace std; 29 23 30 24 31 Player::Player() 32 : WorldEntity() { 33 //cout << "Player::Player" << endl; 34 xCor = yCor = zCor = 0; 35 shootLaser = new ShootLaser; 36 shootRocket = new ShootRocket; 25 Player::Player(bool isFree) : WorldEntity(isFree) 26 { 37 27 } 38 28 39 29 Player::~Player () 40 30 { 41 //delete shootLaser;42 31 } 43 32 44 45 void Player::setPosition( float x, float y, float z) 33 void Player::post_spawn () 46 34 { 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))); 48 41 } 49 42 50 51 void Player::getPosition(float* x, float* y, float* z) 43 void Player::tick (float time) 52 44 { 53 *x = xCor; *y = yCor; *z = zCor; 45 // movement 46 move (time); 54 47 } 55 48 56 57 void Player::setCollisionRadius(float radius) 49 void Player::hit (WorldEntity* weapon, Vector loc) 58 50 { 59 collisionRadius = radius;60 51 } 61 52 62 63 void Player::goX(float x) 53 void Player::destroy () 64 54 { 65 xCor += x;66 55 } 67 56 68 69 void Player::goY(float y) 57 void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) 70 58 { 71 yCor += y;72 59 } 73 60 74 void Player:: goZ(float z)61 void Player::command (Command* cmd) 75 62 { 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; 77 69 } 78 70 71 void Player::draw () 72 { 73 glMatrixMode(GL_MODELVIEW); 74 glLoadIdentity(); 75 float matrix[4][4]; 79 76 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); 111 91 } 112 92 93 void Player::get_lookat (Location* locbuf) 94 { 95 *locbuf = *get_location(); 96 //locbuf->dist += 5.0; 97 } 113 98 114 //void Player::addIO(InputOutput *io) {} 99 void Player::left_world () 100 { 101 } 115 102 116 117 void Player::paint() 103 void Player::move (float time) 118 104 { 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); 129 128 } 130 129 … … 146 145 147 146 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 */ 1 5 2 6 #ifndef PLAYER_H … … 5 9 #include "world_entity.h" 6 10 7 class ShootLaser; 8 class ShootRocket; 9 10 11 //! Basic controllable WorldEntity 11 12 class Player : public WorldEntity 12 13 { 14 friend class World; 13 15 14 16 public: 15 Player ( );17 Player (bool isFree = false); 16 18 ~Player (); 17 19 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); 22 26 23 float collisionRadius; 27 virtual void draw (); 28 virtual void get_lookat (Location* locbuf); 24 29 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 (); 40 31 41 32 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 44 41 }; 45 42 -
orxonox/trunk/src/stdincl.h
r1956 r2190 5 5 #define null 0 6 6 7 #ifdef __WIN32__ 8 #include <windows.h> 7 9 #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 14 14 main-programmer: Christian Meyer 15 15 co-programmer: ... 16 17 Quaternion code borrowed from an Gamasutra article by Nick Bobick and Ken Shoemake 16 18 */ 17 19 … … 177 179 f = acos( v1 * v2 / (v1.len() * v2.len())); 178 180 return f * 180 / PI; 181 } 182 183 /** 184 \brief creates a multiplicational identity Quaternion 185 */ 186 Quaternion::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 */ 197 Quaternion::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 */ 213 Quaternion::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 */ 251 Quaternion::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 */ 278 Quaternion 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 */ 305 Quaternion 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 */ 318 Quaternion 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 */ 331 Vector 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 */ 345 Quaternion 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 */ 358 Quaternion 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 */ 371 Quaternion 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 */ 382 float 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 */ 393 Quaternion 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 */ 407 void 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 */ 436 Quaternion::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 } 179 480 } 180 481 … … 266 567 267 568 /** 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 */ 574 void 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 */ 601 Rotation 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 /** 268 622 \brief rotates the vector by the given rotation 269 623 \param v: a vector -
orxonox/trunk/src/vector.h
r2043 r2190 12 12 #define PI 3.14159265359f 13 13 14 //! 3D vector14 //! 3D Vector 15 15 /** 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 19 17 */ 20 18 class Vector { … … 42 40 float angle_rad (const Vector& v1, const Vector& v2); 43 41 44 //! 3D rotation 42 //! Quaternion 43 /** 44 Class to handle 3-dimensional rotation efficiently 45 */ 46 class 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) 45 71 /** 46 72 Class to handle 3-dimensional rotations. … … 58 84 ~Rotation () {} 59 85 86 Rotation operator* (const Rotation& r); 87 88 void glmatrix (float* buffer); 60 89 }; 61 90 -
orxonox/trunk/src/world.cc
r2077 r2190 12 12 ### File Specific: 13 13 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" 23 21 #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" 35 24 36 25 using namespace std; … … 38 27 39 28 /** 40 \brief Create a new World29 \brief create a new World 41 30 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 */ 33 World::World () 34 { 35 entities = new List<WorldEntity>(); 36 } 37 38 /** 39 \brief remove the World from memory 40 */ 41 World::~World () 42 { 43 unload (); 44 delete entities; 45 } 46 47 /** 48 \brief checks for collisions 64 49 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 */ 53 void 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 */ 88 void 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 72 155 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 */ 159 void 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 */ 213 void 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 */ 235 void 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 */ 244 void 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); 246 269 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 */ 277 void 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 */ 6 5 7 6 #ifndef WORLD_H 8 7 #define WORLD_H 9 8 10 class Player; 11 class NPC; 12 class Environment;9 #include "stdincl.h" 10 11 class Track; 13 12 class WorldEntity; 14 13 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 25 15 class World { 26 16 … … 29 19 ~World (); 30 20 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); 31 25 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 85 36 private: 86 float surface[120][120]; //!< deprecated: used to build a surface87 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; 93 44 94 45 }; 95 46 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 */ 58 template<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 */ 92 template<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 96 107 #endif -
orxonox/trunk/src/world_entity.cc
r2077 r2190 13 13 ### File Specific: 14 14 main-programmer: Patrick Boenzli 15 co-programmer: ...15 co-programmer: Christian Meyer 16 16 */ 17 17 … … 19 19 20 20 #include "world_entity.h" 21 22 #include " vector.h"21 #include "stdincl.h" 22 #include "collision.h" 23 23 24 24 using namespace std; 25 25 26 27 26 /** 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. 31 35 */ 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 () 36 WorldEntity::WorldEntity (bool isFree) : bFree(isFree) 40 37 { 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; 79 40 } 80 41 81 42 /** 82 \brief gets the speed of the entity, if any 83 \return the speed in points (openGL points) per seconds 43 \brief standard destructor 84 44 */ 85 float WorldEntity::getSpeed()45 WorldEntity::~WorldEntity () 86 46 { 87 return speed;47 if( collisioncluster != NULL) delete collisioncluster; 88 48 } 89 49 90 50 /** 91 \brief sets the health of the entity92 \param health: number for the life count, normaly {0..100} 51 \brief get the Location of the WorldEntity 52 \return a pointer to location 93 53 */ 94 void WorldEntity::setHealth(float health)54 Location* WorldEntity::get_location () 95 55 { 96 this->health = health;56 return &loc; 97 57 } 98 58 99 59 /** 100 \brief gets the health of the entity101 \return number for the life count, normaly {0..100} 60 \brief get the Placement of the WorldEntity 61 \return a pointer to placement 102 62 */ 103 float WorldEntity::getHealth()63 Placement* WorldEntity::get_placement () 104 64 { 105 return health;65 return &place; 106 66 } 107 67 108 68 /** 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 113 71 */ 114 void WorldEntity::tick(float dt) 115 {} 72 bool WorldEntity::isFree () 73 { 74 return bFree; 75 } 116 76 117 77 /** 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 */ 83 void 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 */ 96 void WorldEntity::tick(float time) 97 { 98 } 99 100 /** 101 \brief the entity is drawn onto the screen with this function 119 102 120 103 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. 121 104 */ 122 void WorldEntity::paint() 123 {} 105 void WorldEntity::draw() 106 { 107 } 124 108 125 /* virtual void WorldEntity::actionEvent(Event* event); */126 109 /** 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 130 116 */ 131 void WorldEntity::collide(WorldEntity* we, Vector loc) {}117 void WorldEntity::collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {} 132 118 133 119 /** … … 141 127 142 128 /** 143 \brief this function is called , ifthe entity is to be destroied129 \brief this function is called when the entity is to be destroied 144 130 145 131 This can be called, if eg. something realy bad happens :) … … 147 133 void WorldEntity::destroy() {} 148 134 149 /**150 \brief this function is automatically called before the entity enters the world151 */152 void WorldEntity::entityPreEnter() {}153 135 154 136 /** 155 \brief this function is automatically called after the entity enters the world 156 137 \brief basic initialisation for bound Entities 157 138 */ 158 void WorldEntity::entityPostEnter() {} 139 void WorldEntity::init( Location* spawnloc, WorldEntity* spawnowner) 140 { 141 loc = *spawnloc; 142 owner = spawnowner; 143 } 159 144 160 145 /** 161 \brief this function is automatically called before the entity quits the world 162 146 \brief basic initialisation for free Entities 163 147 */ 164 void WorldEntity::entityPreQuit() {} 148 void WorldEntity::init( Placement* spawnplc, WorldEntity* spawnowner) 149 { 150 place = *spawnplc; 151 owner = spawnowner; 152 } 165 153 166 154 /** 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. 168 159 */ 169 void WorldEntity::entityPostQuit() {} 160 void 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 */ 171 void 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 */ 182 void 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 */ 192 void WorldEntity::left_world () 193 { 194 } -
orxonox/trunk/src/world_entity.h
r2077 r2190 1 1 /*! 2 2 \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 */ 9 5 10 6 #ifndef WORLD_ENTITY_H 11 7 #define WORLD_ENTITY_H 12 8 13 #include " data_tank.h"9 #include "stdincl.h" 14 10 15 class Vector; 16 class Ability; 11 class CollisionCluster; 17 12 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 14 class WorldEntity 15 { 16 friend class World; 25 17 26 18 public: 27 WorldEntity ( );19 WorldEntity (bool isFree = false); 28 20 ~WorldEntity (); 29 21 22 Location* get_location (); 23 Placement* get_placement (); 24 void set_collision (CollisionCluster* newhull); 30 25 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); 40 30 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); 43 40 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 (); 57 42 58 43 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; 66 52 67 68 53 void init( Location* spawnloc, WorldEntity* spawnowner); 54 void init( Placement* spawnplc, WorldEntity* spawnowner); 69 55 }; 70 56
Note: See TracChangeset
for help on using the changeset viewer.