[1883] | 1 | |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
[2036] | 13 | ### File Specific |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
| 15 | co-programmer: |
---|
[1883] | 16 | */ |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | #include "environment.h" |
---|
[2816] | 20 | #include "stdincl.h" |
---|
| 21 | #include "world_entity.h" |
---|
| 22 | #include "vector.h" |
---|
[3484] | 23 | #include "objModel.h" |
---|
[1883] | 24 | |
---|
| 25 | using namespace std; |
---|
| 26 | |
---|
| 27 | |
---|
[3542] | 28 | CREATE_FACTORY(Environment); |
---|
[1942] | 29 | |
---|
[2816] | 30 | Environment::Environment () : WorldEntity() |
---|
[1883] | 31 | { |
---|
[3746] | 32 | this->model = (Model*) ResourceManager::getInstance()->load("cube", RP_LEVEL); |
---|
| 33 | // this->model = new OBJModel("../data/models/fighter.obj"); |
---|
[1883] | 34 | } |
---|
| 35 | |
---|
[3542] | 36 | Environment::Environment ( TiXmlElement* root) |
---|
| 37 | { |
---|
[3557] | 38 | assert( root != NULL); |
---|
| 39 | |
---|
[3542] | 40 | char* temp; |
---|
| 41 | const char* string = grabParameter( root, "name"); |
---|
[3557] | 42 | |
---|
[3542] | 43 | if( string == NULL) |
---|
| 44 | { |
---|
[3557] | 45 | PRINTF0("Environment is missing a proper 'name'\n"); |
---|
[3542] | 46 | string = "Unknown"; |
---|
[3557] | 47 | this->setName( string); |
---|
[3542] | 48 | } |
---|
| 49 | else |
---|
| 50 | { |
---|
[3557] | 51 | this->setName( string); |
---|
[3542] | 52 | } |
---|
| 53 | |
---|
| 54 | this->model = NULL; |
---|
| 55 | string = grabParameter( root, "model"); |
---|
| 56 | if( string != NULL) |
---|
[3746] | 57 | this->model = (Model*) ResourceManager::getInstance()->load( string, RP_LEVEL); |
---|
[3542] | 58 | else |
---|
| 59 | { |
---|
[3557] | 60 | PRINTF0("Environment is missing a proper 'model'\n"); |
---|
[3746] | 61 | this->model = (Model*) ResourceManager::getInstance()->load( "cube", RP_LEVEL); |
---|
[3542] | 62 | } |
---|
| 63 | if( this->model == NULL) |
---|
| 64 | { |
---|
[3557] | 65 | PRINTF0("Environment model '%s' could not be loaded\n", string); |
---|
[3542] | 66 | } |
---|
| 67 | |
---|
| 68 | double buff[3]; |
---|
| 69 | |
---|
| 70 | string = grabParameter( root, "position"); |
---|
[3557] | 71 | if( string != NULL && sscanf( string, "%lf,%lf,%lf", &(buff[0]), &(buff[1]), &(buff[2])) == 3) |
---|
[3542] | 72 | { |
---|
| 73 | Vector* es = new Vector( buff[0], buff[1], buff[2]); |
---|
| 74 | this->setAbsCoor(es); |
---|
| 75 | delete es; |
---|
| 76 | } |
---|
| 77 | else |
---|
| 78 | { |
---|
[3557] | 79 | PRINTF0("Environment is missing a proper 'position'\n"); |
---|
[3542] | 80 | Vector* es = new Vector(); |
---|
| 81 | this->setAbsCoor(es); |
---|
| 82 | delete es; |
---|
| 83 | } |
---|
[3557] | 84 | |
---|
[3542] | 85 | string = grabParameter( root, "orientation"); |
---|
[3557] | 86 | if( string != NULL && sscanf( string, "%lf,%lf,%lf", &(buff[0]), &(buff[1]), &(buff[2])) == 3) |
---|
[3542] | 87 | { |
---|
| 88 | Quaternion* qs = new Quaternion( buff[0], buff[1], buff[2]); |
---|
| 89 | this->setAbsDir(qs); |
---|
| 90 | delete qs; |
---|
| 91 | } |
---|
| 92 | else |
---|
| 93 | { |
---|
[3557] | 94 | PRINTF0("Environment is missing a proper 'orientation'\n"); |
---|
[3542] | 95 | Quaternion* qs = new Quaternion (); |
---|
| 96 | this->setAbsDir(qs); |
---|
| 97 | delete qs; |
---|
| 98 | } |
---|
| 99 | } |
---|
[1883] | 100 | |
---|
[3365] | 101 | Environment::~Environment () |
---|
| 102 | { |
---|
[3605] | 103 | |
---|
[3365] | 104 | } |
---|
[1883] | 105 | |
---|
[2816] | 106 | void Environment::tick (float time) {} |
---|
[1883] | 107 | |
---|
[3605] | 108 | void Environment::hit (WorldEntity* weapon, Vector* loc) {} |
---|
[2816] | 109 | |
---|
| 110 | void Environment::destroy () {} |
---|
| 111 | |
---|
| 112 | void Environment::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {} |
---|
| 113 | |
---|
| 114 | void Environment::draw () |
---|
| 115 | { |
---|
| 116 | glMatrixMode(GL_MODELVIEW); |
---|
[3605] | 117 | glPushMatrix(); |
---|
[2816] | 118 | float matrix[4][4]; |
---|
| 119 | |
---|
[3365] | 120 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 121 | //rotate |
---|
[3433] | 122 | this->getAbsDir().matrix (matrix); |
---|
[3365] | 123 | glMultMatrixf((float*)matrix); |
---|
[2816] | 124 | |
---|
[3365] | 125 | this->model->draw(); |
---|
[3605] | 126 | |
---|
| 127 | glPopMatrix(); |
---|
[2816] | 128 | } |
---|
| 129 | |
---|