Changeset 5750 in orxonox.OLD for trunk/src/world_entities/weapons/aim.cc
- Timestamp:
- Nov 24, 2005, 12:13:22 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/weapons/aim.cc
r5671 r5750 20 20 #include "load_param.h" 21 21 #include "graphics_engine.h" 22 #include "glincl.h"23 22 #include "state.h" 23 #include "list.h" 24 24 #include "material.h" 25 #include "t_animation.h" 26 #include "text.h" 27 28 #include "world_entity.h" 25 29 26 30 using namespace std; … … 30 34 * standart constructor 31 35 */ 32 Aim::Aim ( const TiXmlElement* root)36 Aim::Aim (PNode* source, const TiXmlElement* root) 33 37 { 34 38 this->init(); 39 40 this->source = source; 35 41 36 42 if (root) … … 47 53 if (this->material) 48 54 delete this->material; 55 56 if (this->text != NULL) 57 delete this->text; 49 58 } 50 59 … … 58 67 59 68 this->setLayer(E2D_LAYER_TOP); 60 this->setRotationSpeed( 5);69 this->setRotationSpeed(30.0* (float)rand()/RAND_MAX + 10.0); 61 70 this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0); 62 71 63 //this->setBindNode(this);72 this->setBindNode(this); 64 73 this->material = new Material; 65 } 66 74 this->source = NULL; 75 76 this->anim = new tAnimation<Aim>(this, &Aim::setSize); 77 this->anim->setInfinity(ANIM_INF_CONSTANT); 78 this->anim->addKeyFrame(500, .3, ANIM_LINEAR); 79 this->anim->addKeyFrame(100, .2, ANIM_LINEAR); 80 this->anim->addKeyFrame(50, .01, ANIM_LINEAR); 81 82 this->text = new Text(); 83 this->text->setParent2D(this); 84 this->text->setRelCoor2D(10, -50); 85 this->text->setParentMode2D(E2D_PARENT_MOVEMENT); 86 this->text->setText("Testing"); 87 } 67 88 68 89 void Aim::loadParams(const TiXmlElement* root) … … 80 101 } 81 102 103 void Aim::searchTarget(float range) 104 { 105 tIterator<WorldEntity>* iterator = State::getWorldEntityList()->getIterator(); 106 WorldEntity* entity = iterator->firstElement(); 107 while (likely(entity != NULL)) 108 { 109 if (entity->isA(CL_NPC) && this->source->getAbsCoor().x < entity->getAbsCoor().x && (this->source->getAbsCoor() - entity->getAbsCoor()).len() < range) 110 { 111 if (this->getParent() != entity) 112 { 113 this->anim->replay(); 114 this->setParentSoft(entity, 5); 115 } 116 delete iterator; 117 return; 118 } 119 entity = iterator->nextElement(); 120 } 121 122 delete iterator; 123 } 124 125 82 126 83 127 /** … … 108 152 this->shiftDir2D(dt * rotationSpeed); 109 153 110 111 float z = 0.0f; 112 glReadPixels ((int)this->getAbsCoor2D().x, 113 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1, 114 1, 115 1, 116 GL_DEPTH_COMPONENT, 117 GL_FLOAT, 118 &z); 119 120 121 GLdouble objX=.0, objY=.0, objZ=.0; 122 gluUnProject(this->getAbsCoor2D().x, 123 GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1, 124 .99, // z 125 GraphicsEngine::modMat, 126 GraphicsEngine::projMat, 127 GraphicsEngine::viewPort, 128 &objX, 129 &objY, 130 &objZ ); 131 132 this->setAbsCoor(objX, objY, objZ); 154 char outputText[100]; 155 sprintf(outputText, "%s - distance: %f\n", this->getParent()->getName(), (this->source->getAbsCoor() - this->getAbsCoor()).len()); 156 this->text->setText(outputText); 157 158 159 if (this->source->getAbsCoor().x > this->getAbsCoor().x ) 160 this->searchTarget(1000); 161 // float z = 0.0f; 162 // glReadPixels ((int)this->getAbsCoor2D().x, 163 // GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1, 164 // 1, 165 // 1, 166 // GL_DEPTH_COMPONENT, 167 // GL_FLOAT, 168 // &z); 169 // 170 // 171 // GLdouble objX=.0, objY=.0, objZ=.0; 172 // gluUnProject(this->getAbsCoor2D().x, 173 // GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1, 174 // .99, // z 175 // GraphicsEngine::modMat, 176 // GraphicsEngine::projMat, 177 // GraphicsEngine::viewPort, 178 // &objX, 179 // &objY, 180 // &objZ ); 181 // 182 // this->setAbsCoor(objX, objY, objZ); 133 183 } 134 184 … … 138 188 void Aim::draw() const 139 189 { 190 140 191 glPushMatrix(); 141 192 glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
Note: See TracChangeset
for help on using the changeset viewer.