Changeset 10677 in orxonox.OLD for branches/adm/src/world_entities
- Timestamp:
- Jun 7, 2007, 5:38:00 PM (18 years ago)
- Location:
- branches/adm/src/world_entities/npcs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/adm/src/world_entities/npcs/adm_turret.cc
r10666 r10677 22 22 #include "loading/load_param.h" 23 23 #include "debug.h" 24 #include "loading/load_param_xml.h" 24 25 25 26 ObjectListDefinition(AdmTurret); … … 54 55 } 55 56 } 56 57 void AdmTurret::init() 58 { 59 this->registerObject(this, AdmTurret::_objectList); 60 61 // load the 3 parts of the turret 62 // this-> loadModel ("...", , ) 63 // this-> loadModel ("...", , ) 64 // this-> loadModel ("...", , ) 65 66 //Cannon Node: 2 Cannons fixed left and right of the main turret 67 this->cannonNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 68 this->cannonNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 69 this->cannonNode.setParent(this); 70 // this->cannonNode.setRelCoor( , , ) 71 72 //Sensor Node: Sensor rotating independently from main turret (like Radar) 73 this->sensorNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 74 this->sensorNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 75 this->sensorNode.setParent(this); 76 // this->sensorNode.setRelCoor( , , ) 77 78 // initialise Weapons here 79 } 80 57 /** 58 * XML Loader 59 */ 81 60 void AdmTurret::loadParams(const TiXmlElement* root) 82 61 { … … 86 65 87 66 LoadParam(root, "target", this, AdmTurret, setTarget) 88 .describe(" the filename of the World Entity, that is to be shot at")67 .describe("The filename of the World Entity, that is to be shot at") 89 68 .defaultValues(""); 90 } 91 } 92 93 void AdmTurret::tick(float dt) 94 { 95 } 96 97 void AdmTurret::draw() const 98 { 99 } 100 101 void AdmTurret::collidesWith(WorldEntity* entity, const Vector& location) 102 { 103 } 104 105 void AdmTurret::activate() 106 { 107 } 108 109 void AdmTurret::deactivate() 110 { 111 } 112 69 70 LoadParamXML(root, "Cannons", this, AdmTurret, addCannons) 71 .describe("add cannons to ADM"); 72 LoadParamXML(root, "Sensor", this, AdmTurret, addSensor) 73 .describe("add sensor to ADM"); 74 75 } 76 } 77 78 /** 79 * Sets Target onto the World Entity with filename "target", given as String 80 */ 113 81 void AdmTurret::setTarget(const std::string& target) 114 82 { … … 120 88 else 121 89 { 122 PRINTF(2)("ERROR ADMTURRET : Target %s does not exist\n", target.c_str()); 123 } 90 PRINTF(1)("ERROR ADMTURRET : Target %s does not exist\n", target.c_str()); 91 } 92 } 93 94 void AdmTurret::init() 95 { 96 this->registerObject(this, AdmTurret::_objectList); 97 98 99 // this-> loadModel ("models/guns/turret1.obj", ,1 ) 100 101 102 //Cannon Node: 2 Cannons fixed left and right of the main turret 103 104 // this->sensor.setRelCoor( , , ) 105 106 // initialise Weapons here 107 } 108 109 void AdmTurret::tick(float dt) 110 { 111 WorldEntity::tick(dt); 112 113 //rotate sensor 2PI/sec 114 this->sensor->setAbsDir( this->sensor->getAbsDir() * Quaternion( PI*2*dt, Vector( 0, 1, 0 ) ) ); 115 116 117 Vector playerPos = this->myTarget->getAbsCoor(); 118 this->moveTowards( playerPos - ( this->cannons->getAbsCoor() ), dt); 119 } 120 121 void AdmTurret::draw() const 122 { 123 WorldEntity::draw(); 124 125 126 glMatrixMode(GL_MODELVIEW); 127 glPushMatrix(); 128 129 glPushAttrib(GL_ENABLE_BIT); 130 131 glDisable(GL_LIGHTING); 132 glDisable(GL_TEXTURE_2D); 133 glDisable(GL_BLEND); 134 glLineWidth(2.0); 135 136 137 Vector mp = this->cannons->getAbsCoor(); 138 Vector op = this->cannons->getAbsDir().apply( Vector(-1, 0, 0) ); 139 op *= 100; 140 op += mp; 141 142 glColor3f(1.0, 0.0, 0.0 ); 143 glBegin(GL_LINE_STRIP); 144 glVertex3f(mp.x, mp.y, mp.z); 145 glVertex3f(op.x, op.y, op.z); 146 glEnd(); 147 148 op = this->myTarget->getAbsCoor() - ( this->cannons->getAbsCoor() ); 149 op += mp; 150 151 glColor3f(0.0, 1.0, 0.0 ); 152 glBegin(GL_LINE_STRIP); 153 glVertex3f(mp.x, mp.y, mp.z); 154 glVertex3f(op.x, op.y, op.z); 155 glEnd(); 156 157 glPopAttrib(); 158 glPopMatrix(); 159 160 } 161 162 void AdmTurret::collidesWith(WorldEntity* entity, const Vector& location) 163 { 164 } 165 166 void AdmTurret::activate() 167 { 168 } 169 170 void AdmTurret::deactivate() 171 { 124 172 } 125 173 … … 146 194 //pj->activate(); 147 195 } 196 197 void AdmTurret::addCannons( const TiXmlElement * root ) 198 { 199 this->cannons = new WorldEntity(); 200 this->cannons->setParent(this); 201 this->cannons->loadParams( root ); 202 203 this->cannons->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 204 this->cannons->addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 205 206 this->cannons->toList( getOMListNumber() ); 207 } 208 209 void AdmTurret::addSensor( const TiXmlElement * root ) 210 { 211 this->sensor = new WorldEntity(); 212 this->sensor->setParent(this); 213 this->sensor->loadParams( root ); 214 215 this->sensor->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 216 this->sensor->addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 217 this->sensor->toList( getOMListNumber() ); 218 } 219 220 void AdmTurret::moveTowards( Vector targetDir, float dt ) 221 { 222 223 if(false){ 224 225 226 Quaternion cur = this->getAbsDir(); 227 228 Quaternion ry( dt, cur.apply( Vector( 0, 1, 0 ) ) ); 229 230 Quaternion tmp1 = cur * ry; 231 Quaternion tmp2 = cur * ry.inverse(); 232 233 if ( tmp1.apply( Vector(1, 0, 0) ).dot(targetDir) < tmp2.apply( Vector(1, 0, 0)).dot(targetDir) ) 234 cur = tmp1; 235 else 236 cur = tmp2; 237 238 this->setAbsDir( cur ); 239 } 240 241 { 242 //targetDir = this->getAbsDir().apply( targetDir ); 243 Quaternion cur = this->cannons->getAbsDir(); 244 //Quaternion rx( dt, Vector( 0, 0, 1 ) ); 245 Quaternion rx( dt, Vector( 0, 0, 1 ) ); 246 247 Quaternion tmp1 = cur * rx; 248 Quaternion tmp2 = cur * rx.inverse(); 249 250 Quaternion dec; 251 if ( tmp1.apply( Vector(-1, 0, 0) ).dot(targetDir) < tmp2.apply( Vector(-1, 0, 0) ).dot(targetDir) ) 252 dec = tmp1; 253 else 254 dec = tmp2; 255 256 float dp = dec.apply( Vector(-1, 0, 0) ).dot(Vector(0, 1, 0)); 257 if ( true /*dp > -0.9 && dp < 0.9*/ ) 258 { 259 cur = dec; 260 } 261 262 this->cannons->setAbsDir( cur ); 263 } 264 265 266 } -
branches/adm/src/world_entities/npcs/adm_turret.h
r10664 r10677 33 33 34 34 private: 35 PNode cannonNode;36 PNode sensorNode;35 WorldEntity* cannons; 36 WorldEntity* sensor; 37 37 WorldEntity* myTarget; 38 38 bool isVisible(const WorldEntity myTarget); 39 39 float aim(const WorldEntity Target); 40 40 void fire(); 41 42 void addCannons(const TiXmlElement* root); 43 void addSensor(const TiXmlElement* root); 44 45 void moveTowards( Vector targetDir, float dt ); 41 46 42 47 };
Note: See TracChangeset
for help on using the changeset viewer.