| 1 | /* |
|---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2004 orx |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 9 | any later version. |
|---|
| 10 | |
|---|
| 11 | This program is distributed in the hope that it will be useful, |
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | GNU General Public License for more details. |
|---|
| 15 | |
|---|
| 16 | You should have received a copy of the GNU General Public License |
|---|
| 17 | along with this program; if not, write to the Free Software Foundation, |
|---|
| 18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | ### File Specific: |
|---|
| 22 | main-programmer: Patrick Boenzli |
|---|
| 23 | co-programmer: Christian Meyer |
|---|
| 24 | */ |
|---|
| 25 | |
|---|
| 26 | #include "orxonox.h" |
|---|
| 27 | |
|---|
| 28 | #include "world.h" |
|---|
| 29 | #include "data_tank.h" |
|---|
| 30 | #include "command_node.h" |
|---|
| 31 | #include "game_loader.h" |
|---|
| 32 | #include "graphics_engine.h" |
|---|
| 33 | #include "resource_manager.h" |
|---|
| 34 | |
|---|
| 35 | #include <string.h> |
|---|
| 36 | int verbose = 4; |
|---|
| 37 | |
|---|
| 38 | using namespace std; |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | \brief create a new Orxonox |
|---|
| 42 | */ |
|---|
| 43 | Orxonox::Orxonox () |
|---|
| 44 | { |
|---|
| 45 | pause = false; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | /** |
|---|
| 49 | \brief remove Orxonox from memory |
|---|
| 50 | */ |
|---|
| 51 | Orxonox::~Orxonox () |
|---|
| 52 | { |
|---|
| 53 | Orxonox::singletonRef = NULL; |
|---|
| 54 | if( world != NULL) delete world; |
|---|
| 55 | if( localinput != NULL) delete world; |
|---|
| 56 | if( resources != NULL) delete resources; |
|---|
| 57 | delete GraphicsEngine::getInstance(); // deleting the Graphics |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | /** \brief this is a singleton class to prevent duplicates */ |
|---|
| 61 | Orxonox* Orxonox::singletonRef = 0; |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | \returns reference or new Object of Orxonox if not existent. |
|---|
| 65 | */ |
|---|
| 66 | Orxonox* Orxonox::getInstance (void) |
|---|
| 67 | { |
|---|
| 68 | if (singletonRef == NULL) |
|---|
| 69 | singletonRef = new Orxonox(); |
|---|
| 70 | return singletonRef; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | \brief this finds the config file |
|---|
| 75 | |
|---|
| 76 | Since the config file varies from user to user and since one may want to specify different config files |
|---|
| 77 | for certain occasions or platforms this function finds the right config file for every occasion and stores |
|---|
| 78 | it's path and name into configfilename |
|---|
| 79 | */ |
|---|
| 80 | void Orxonox::getConfigFile (int argc, char** argv) |
|---|
| 81 | { |
|---|
| 82 | strcpy (configfilename, "orxonox.conf"); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | /** |
|---|
| 86 | \brief initialize Orxonox with command line |
|---|
| 87 | */ |
|---|
| 88 | int Orxonox::init (int argc, char** argv) |
|---|
| 89 | { |
|---|
| 90 | // parse command line |
|---|
| 91 | // config file |
|---|
| 92 | |
|---|
| 93 | getConfigFile (argc, argv); |
|---|
| 94 | SDL_Init (SDL_INIT_TIMER); |
|---|
| 95 | // initialize everything |
|---|
| 96 | if( initVideo() == -1) return -1; |
|---|
| 97 | if( initSound() == -1) return -1; |
|---|
| 98 | printf("> Initializing input\n"); |
|---|
| 99 | if( initInput() == -1) return -1; |
|---|
| 100 | printf("> Initializing networking\n"); |
|---|
| 101 | if( initNetworking () == -1) return -1; |
|---|
| 102 | printf("> Initializing resources\n"); |
|---|
| 103 | if( initResources () == -1) return -1; |
|---|
| 104 | //printf("> Initializing world\n"); |
|---|
| 105 | //if( init_world () == -1) return -1; PB: world will be initialized when started |
|---|
| 106 | |
|---|
| 107 | return 0; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | /** |
|---|
| 111 | \brief initializes SDL and OpenGL |
|---|
| 112 | */ |
|---|
| 113 | int Orxonox::initVideo() |
|---|
| 114 | { |
|---|
| 115 | PRINTF(3)("> Initializing video\n"); |
|---|
| 116 | |
|---|
| 117 | GraphicsEngine::getInstance(); |
|---|
| 118 | |
|---|
| 119 | return 0; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | /** |
|---|
| 124 | \brief initializes the sound engine |
|---|
| 125 | */ |
|---|
| 126 | int Orxonox::initSound() |
|---|
| 127 | { |
|---|
| 128 | printf("> Initializing sound\n"); |
|---|
| 129 | // SDL_Init(SDL_INIT_AUDIO); |
|---|
| 130 | printf("Not yet implemented\n"); |
|---|
| 131 | return 0; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | /** |
|---|
| 136 | \brief initializes input functions |
|---|
| 137 | */ |
|---|
| 138 | int Orxonox::initInput() |
|---|
| 139 | { |
|---|
| 140 | // create localinput |
|---|
| 141 | localinput = new CommandNode( configfilename); |
|---|
| 142 | |
|---|
| 143 | return 0; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | /** |
|---|
| 148 | \brief initializes network system |
|---|
| 149 | */ |
|---|
| 150 | int Orxonox::initNetworking() |
|---|
| 151 | { |
|---|
| 152 | printf("Not yet implemented\n"); |
|---|
| 153 | return 0; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | /** |
|---|
| 158 | \brief initializes and loads resource files |
|---|
| 159 | */ |
|---|
| 160 | int Orxonox::initResources() |
|---|
| 161 | { |
|---|
| 162 | // printf("Not yet implemented\n"); |
|---|
| 163 | PRINT(3)("initializing ResourceManager\n"); |
|---|
| 164 | resourceManager = ResourceManager::getInstance(); |
|---|
| 165 | resourceManager->setDataDir("../data/"); |
|---|
| 166 | return 0; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | /** |
|---|
| 171 | \brief initializes the world |
|---|
| 172 | */ |
|---|
| 173 | int Orxonox::initWorld() |
|---|
| 174 | { |
|---|
| 175 | //world = new World(); |
|---|
| 176 | |
|---|
| 177 | // TO DO: replace this with a menu/intro |
|---|
| 178 | //world->load_debug_level(); |
|---|
| 179 | |
|---|
| 180 | return 0; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | /** |
|---|
| 185 | \brief starts the orxonox game or menu |
|---|
| 186 | |
|---|
| 187 | here is the central orxonox state manager. There are currently two states |
|---|
| 188 | - menu |
|---|
| 189 | - game-play |
|---|
| 190 | both states manage their states themselfs again. |
|---|
| 191 | */ |
|---|
| 192 | void Orxonox::start() |
|---|
| 193 | { |
|---|
| 194 | |
|---|
| 195 | this->gameLoader = GameLoader::getInstance(); |
|---|
| 196 | this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
|---|
| 197 | this->gameLoader->init(); |
|---|
| 198 | this->gameLoader->start(); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | /** |
|---|
| 203 | \brief exits Orxonox |
|---|
| 204 | */ |
|---|
| 205 | void Orxonox::quitGame() |
|---|
| 206 | { |
|---|
| 207 | bQuitOrxonox = true; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | /** |
|---|
| 213 | \brief handles sprecial events from localinput |
|---|
| 214 | \param event: an event not handled by the CommandNode |
|---|
| 215 | */ |
|---|
| 216 | void Orxonox::eventHandler(SDL_Event* event) |
|---|
| 217 | { |
|---|
| 218 | // Handle special events such as reshape, quit, focus changes |
|---|
| 219 | switch (event->type) |
|---|
| 220 | { |
|---|
| 221 | case SDL_VIDEORESIZE: |
|---|
| 222 | GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
|---|
| 223 | tmpGEngine->resolutionChanged(&event->resize); |
|---|
| 224 | break; |
|---|
| 225 | } |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | /** |
|---|
| 230 | \brief handle keyboard commands that are not meant for WorldEntities |
|---|
| 231 | \param cmd: the command to handle |
|---|
| 232 | \return true if the command was handled by the system or false if it may be passed to the WorldEntities |
|---|
| 233 | */ |
|---|
| 234 | bool Orxonox::systemCommand(Command* cmd) |
|---|
| 235 | { |
|---|
| 236 | /* |
|---|
| 237 | if( !strcmp( cmd->cmd, "quit")) |
|---|
| 238 | { |
|---|
| 239 | if( !cmd->bUp) this->gameLoader->stop(); |
|---|
| 240 | return true; |
|---|
| 241 | } |
|---|
| 242 | return false; |
|---|
| 243 | */ |
|---|
| 244 | return false; |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | /** |
|---|
| 248 | \brief retrieve a pointer to the local CommandNode |
|---|
| 249 | \return a pointer to localinput |
|---|
| 250 | */ |
|---|
| 251 | CommandNode* Orxonox::getLocalInput() |
|---|
| 252 | { |
|---|
| 253 | return localinput; |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | /** |
|---|
| 258 | \brief retrieve a pointer to the local World |
|---|
| 259 | \return a pointer to world |
|---|
| 260 | */ |
|---|
| 261 | World* Orxonox::getWorld() |
|---|
| 262 | { |
|---|
| 263 | return world; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | /** |
|---|
| 267 | \return The reference of the SDL-screen of orxonox |
|---|
| 268 | */ |
|---|
| 269 | SDL_Surface* Orxonox::getScreen () |
|---|
| 270 | { |
|---|
| 271 | return this->screen; |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | /** |
|---|
| 277 | \brief main function |
|---|
| 278 | |
|---|
| 279 | here the journey begins |
|---|
| 280 | */ |
|---|
| 281 | int main(int argc, char** argv) |
|---|
| 282 | { |
|---|
| 283 | |
|---|
| 284 | /* reading arguments |
|---|
| 285 | |
|---|
| 286 | currently supported arguments are: |
|---|
| 287 | <no args> :: just starts orxonox |
|---|
| 288 | --benchmark :: start the benchmark without starting orxonox |
|---|
| 289 | |
|---|
| 290 | this is a preselection: it matches to one of the start* functions, the |
|---|
| 291 | finetuning is made in those functions. |
|---|
| 292 | */ |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | int i; |
|---|
| 296 | for(i = 0; i < argc; ++i) |
|---|
| 297 | { |
|---|
| 298 | if(! strcmp( "--help", argv[i])) return startHelp(); |
|---|
| 299 | else if(! strcmp( "--benchmark", argv[i])) return startBenchmarks(); |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | PRINTF(2)("Orxonox does not understand the arguments"); |
|---|
| 303 | return startOrxonox(argc, argv); |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | int startHelp() |
|---|
| 309 | { |
|---|
| 310 | printf("orxonox: starts the orxonox game - rules\n"); |
|---|
| 311 | printf("usage: orxonox [arg]\n\n"); |
|---|
| 312 | printf("valid options:\n"); |
|---|
| 313 | printf(" --benchmark\tstarts the orxonox benchmark\n"); |
|---|
| 314 | printf(" --help \tshows this menu\n"); |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | int startOrxonox(int argc, char** argv) |
|---|
| 319 | { |
|---|
| 320 | printf(">>> Starting Orxonox <<<\n"); |
|---|
| 321 | Orxonox *orx = Orxonox::getInstance(); |
|---|
| 322 | |
|---|
| 323 | if((*orx).init(argc, argv) == -1) |
|---|
| 324 | { |
|---|
| 325 | printf("! Orxonox initialization failed\n"); |
|---|
| 326 | return -1; |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | orx->start(); |
|---|
| 330 | |
|---|
| 331 | //delete orx; |
|---|
| 332 | |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | #include "list.h" |
|---|
| 337 | #include "world_entity.h" |
|---|
| 338 | #include "vector.h" |
|---|
| 339 | #include "player.h" |
|---|
| 340 | #include "base_object.h" |
|---|
| 341 | #include "primitive.h" |
|---|
| 342 | #include <asm/msr.h> |
|---|
| 343 | #include <linux/timex.h> |
|---|
| 344 | |
|---|
| 345 | |
|---|
| 346 | #define LIST_MAX 10000 |
|---|
| 347 | #define VECTOR_MAX 1000000 |
|---|
| 348 | #define ITERATIONS 10000 |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | int startBenchmarks() |
|---|
| 352 | { |
|---|
| 353 | |
|---|
| 354 | printf("===========================================================\n"); |
|---|
| 355 | printf("= BENCHMARKS =\n"); |
|---|
| 356 | printf("===========================================================\n"); |
|---|
| 357 | printf(" the author is not paying any attention to cacheing effects\n"); |
|---|
| 358 | printf(" of the CPU.\n\n"); |
|---|
| 359 | printf("[title]\t\t\t\t\t [cycles]\t[loops]\n\n"); |
|---|
| 360 | // printf("------------------------------------------------------------\n\n"); |
|---|
| 361 | |
|---|
| 362 | // first measure the time overhead: |
|---|
| 363 | unsigned long ini, end, dt, tmp; |
|---|
| 364 | rdtscl(ini); rdtscl(end); |
|---|
| 365 | dt = end - ini; |
|---|
| 366 | |
|---|
| 367 | int type = -1; |
|---|
| 368 | /* type -1 == all |
|---|
| 369 | type 0 == framework |
|---|
| 370 | type 1 == vector |
|---|
| 371 | type 2 == quaternion |
|---|
| 372 | */ |
|---|
| 373 | if(type == 0 || type == -1) |
|---|
| 374 | { |
|---|
| 375 | /* framework test*/ |
|---|
| 376 | |
|---|
| 377 | printf("Generating Objects:\t\t\t\t\t%i\n", ITERATIONS); |
|---|
| 378 | /* ************WorldEntity class test************** */ |
|---|
| 379 | WorldEntity* w = NULL; |
|---|
| 380 | int i = 0; |
|---|
| 381 | unsigned long mittel = 0; |
|---|
| 382 | |
|---|
| 383 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 384 | { |
|---|
| 385 | rdtscl(ini); |
|---|
| 386 | |
|---|
| 387 | WorldEntity* w = new WorldEntity(); |
|---|
| 388 | |
|---|
| 389 | rdtscl(end); |
|---|
| 390 | delete w; |
|---|
| 391 | mittel += (end - ini - dt); |
|---|
| 392 | } |
|---|
| 393 | float mi = mittel / (float)ITERATIONS; |
|---|
| 394 | printf(" Generate a WorldEntity object:\t\t%11.2f\n", mi); |
|---|
| 395 | |
|---|
| 396 | mittel = 0; |
|---|
| 397 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 398 | { |
|---|
| 399 | rdtscl(ini); |
|---|
| 400 | |
|---|
| 401 | WorldEntity* w = new Primitive(P_SPHERE); |
|---|
| 402 | |
|---|
| 403 | rdtscl(end); |
|---|
| 404 | delete w; |
|---|
| 405 | mittel += (end - ini - dt); |
|---|
| 406 | } |
|---|
| 407 | mi = mittel / (float)ITERATIONS; |
|---|
| 408 | printf(" Generate a Primitive object:\t\t%11.2f\n", mi); |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | mittel = 0; |
|---|
| 412 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 413 | { |
|---|
| 414 | rdtscl(ini); |
|---|
| 415 | |
|---|
| 416 | Vector* v = new Vector(); |
|---|
| 417 | |
|---|
| 418 | rdtscl(end); |
|---|
| 419 | delete v; |
|---|
| 420 | mittel += (end - ini - dt); |
|---|
| 421 | } |
|---|
| 422 | mi = mittel / (float)ITERATIONS; |
|---|
| 423 | printf(" Generate a Vector object:\t\t%11.2f\n", mi); |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | mittel = 0; |
|---|
| 427 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 428 | { |
|---|
| 429 | rdtscl(ini); |
|---|
| 430 | |
|---|
| 431 | Quaternion* q = new Quaternion(); |
|---|
| 432 | |
|---|
| 433 | rdtscl(end); |
|---|
| 434 | delete q; |
|---|
| 435 | mittel += (end - ini - dt); |
|---|
| 436 | } |
|---|
| 437 | mi = mittel / (float)ITERATIONS; |
|---|
| 438 | printf(" Generate a Quaternion object:\t\t%11.2f\n", mi); |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | printf("\nCalling function inline &| virtual, \t\t\t%i\n", ITERATIONS); |
|---|
| 444 | mittel = 0; |
|---|
| 445 | w = new WorldEntity(); |
|---|
| 446 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 447 | { |
|---|
| 448 | rdtscl(ini); |
|---|
| 449 | |
|---|
| 450 | w->tick(0.0f); |
|---|
| 451 | |
|---|
| 452 | rdtscl(end); |
|---|
| 453 | mittel += (end - ini - dt); |
|---|
| 454 | } |
|---|
| 455 | //delete w; |
|---|
| 456 | mi = mittel / (float)ITERATIONS; |
|---|
| 457 | printf(" Virt funct tick() of WE: \t\t%11.2f\n", mi); |
|---|
| 458 | |
|---|
| 459 | |
|---|
| 460 | mittel = 0; |
|---|
| 461 | WorldEntity wo; |
|---|
| 462 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 463 | { |
|---|
| 464 | rdtscl(ini); |
|---|
| 465 | |
|---|
| 466 | wo.tick(0.0f); |
|---|
| 467 | |
|---|
| 468 | rdtscl(end); |
|---|
| 469 | mittel += (end - ini - dt); |
|---|
| 470 | } |
|---|
| 471 | //delete w; |
|---|
| 472 | mi = mittel / (float)ITERATIONS; |
|---|
| 473 | printf(" Inl virt funct tick() of WE v2: \t%11.2f\n", mi); |
|---|
| 474 | |
|---|
| 475 | |
|---|
| 476 | mittel = 0; |
|---|
| 477 | BaseObject* bo = new BaseObject(); |
|---|
| 478 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 479 | { |
|---|
| 480 | rdtscl(ini); |
|---|
| 481 | |
|---|
| 482 | bo->isFinalized(); |
|---|
| 483 | |
|---|
| 484 | rdtscl(end); |
|---|
| 485 | mittel += (end - ini - dt); |
|---|
| 486 | } |
|---|
| 487 | //delete w; |
|---|
| 488 | mi = mittel / (float)ITERATIONS; |
|---|
| 489 | printf(" Inl funct BaseObject::isFinazlized(): \t%11.2f\n", mi); |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | tList<WorldEntity>* list = new tList<WorldEntity>(); |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | /* ************Primitvie class test************** */ |
|---|
| 496 | list = new tList<WorldEntity>(); |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | mittel = 0; |
|---|
| 501 | w = new Primitive(P_SPHERE); |
|---|
| 502 | for(i = 0; i < ITERATIONS; ++i) |
|---|
| 503 | { |
|---|
| 504 | rdtscl(ini); |
|---|
| 505 | |
|---|
| 506 | w->tick(0.0f); |
|---|
| 507 | |
|---|
| 508 | rdtscl(end); |
|---|
| 509 | mittel += (end - ini - dt); |
|---|
| 510 | } |
|---|
| 511 | mi = mittel / (float)ITERATIONS; |
|---|
| 512 | printf(" Call function tick() of Prim:\t\t%11.2f\n", mi); |
|---|
| 513 | |
|---|
| 514 | |
|---|
| 515 | } |
|---|
| 516 | if(type == 1 || type == -1) |
|---|
| 517 | { |
|---|
| 518 | printf("\nDoing some simple vector operations: \t\t\t%i\n", VECTOR_MAX); |
|---|
| 519 | /* vector test */ |
|---|
| 520 | Vector* a = new Vector(1.3, 5.3, 4.1); |
|---|
| 521 | Vector* b = new Vector(0.4, 2.5, 6.2); |
|---|
| 522 | Vector* c = new Vector(); |
|---|
| 523 | |
|---|
| 524 | unsigned long mittel, ini, end; |
|---|
| 525 | float mi; |
|---|
| 526 | int i = 0; |
|---|
| 527 | // addition |
|---|
| 528 | mittel = 0; |
|---|
| 529 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 530 | { |
|---|
| 531 | rdtscl(ini); |
|---|
| 532 | |
|---|
| 533 | *c = *a + *b; |
|---|
| 534 | |
|---|
| 535 | rdtscl(end); |
|---|
| 536 | mittel += (end - ini - dt); |
|---|
| 537 | } |
|---|
| 538 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 539 | printf(" Addition of two vectors:\t\t%11.2f\n", mi); |
|---|
| 540 | |
|---|
| 541 | // multiplikation |
|---|
| 542 | |
|---|
| 543 | mittel = 0; |
|---|
| 544 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 545 | { |
|---|
| 546 | rdtscl(ini); |
|---|
| 547 | |
|---|
| 548 | *c = a->cross( *b); |
|---|
| 549 | |
|---|
| 550 | rdtscl(end); |
|---|
| 551 | mittel += (end - ini - dt); |
|---|
| 552 | } |
|---|
| 553 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 554 | printf(" CrossMult of two vectors:\t\t%11.2f\n", mi); |
|---|
| 555 | |
|---|
| 556 | if(type == 1 || type == -1) |
|---|
| 557 | { |
|---|
| 558 | /* quaternion test */ |
|---|
| 559 | printf("\nDoing some simple quaternion operations: \t\t%i\n", VECTOR_MAX); |
|---|
| 560 | /* vector test */ |
|---|
| 561 | Quaternion* a = new Quaternion(); |
|---|
| 562 | Quaternion* b = new Quaternion(); |
|---|
| 563 | Quaternion* c = new Quaternion(); |
|---|
| 564 | |
|---|
| 565 | unsigned long mittel, ini, end; |
|---|
| 566 | float mi; |
|---|
| 567 | int i = 0; |
|---|
| 568 | // quaternion generieren mit spez konstruktor |
|---|
| 569 | mittel = 0; |
|---|
| 570 | Vector* qa = new Vector(4.6, 9.3, 0.4); |
|---|
| 571 | Vector* qb = new Vector(3.5, 6.1, 4.3); |
|---|
| 572 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 573 | { |
|---|
| 574 | rdtscl(ini); |
|---|
| 575 | |
|---|
| 576 | Quaternion* qu = new Quaternion(*qa, *qb); |
|---|
| 577 | |
|---|
| 578 | rdtscl(end); |
|---|
| 579 | delete qu; |
|---|
| 580 | mittel += (end - ini - dt); |
|---|
| 581 | } |
|---|
| 582 | delete a; |
|---|
| 583 | delete b; |
|---|
| 584 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 585 | printf(" Gen. quatern. betw. two vectors:\t%11.2f\n", mi); |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | // multiplication |
|---|
| 589 | mittel = 0; |
|---|
| 590 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 591 | { |
|---|
| 592 | rdtscl(ini); |
|---|
| 593 | |
|---|
| 594 | *c = *a * *b; |
|---|
| 595 | |
|---|
| 596 | rdtscl(end); |
|---|
| 597 | mittel += (end - ini - dt); |
|---|
| 598 | } |
|---|
| 599 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 600 | printf(" Multiplying two quat.(=rot): a * b\t%11.2f\n", mi); |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | // rotating a vector by a quaternion |
|---|
| 605 | mittel = 0; |
|---|
| 606 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 607 | { |
|---|
| 608 | rdtscl(ini); |
|---|
| 609 | |
|---|
| 610 | *qa = a->apply(*qb); |
|---|
| 611 | |
|---|
| 612 | rdtscl(end); |
|---|
| 613 | mittel += (end - ini - dt); |
|---|
| 614 | } |
|---|
| 615 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 616 | printf(" Rot a vec by a quat: q->apply(v)\t%11.2f\n", mi); |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | // generate rotation matrix |
|---|
| 621 | mittel = 0; |
|---|
| 622 | float matrix[4][4]; |
|---|
| 623 | for(i = 0; i < VECTOR_MAX; ++i) |
|---|
| 624 | { |
|---|
| 625 | rdtscl(ini); |
|---|
| 626 | |
|---|
| 627 | a->matrix(matrix); |
|---|
| 628 | |
|---|
| 629 | rdtscl(end); |
|---|
| 630 | mittel += (end - ini - dt); |
|---|
| 631 | } |
|---|
| 632 | mi = mittel / (float)VECTOR_MAX; |
|---|
| 633 | printf(" Generate rot matrix: q->matrix(m)\t%11.2f\n", mi); |
|---|
| 634 | } |
|---|
| 635 | } |
|---|
| 636 | } |
|---|