Changeset 4834 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons
- Timestamp:
- Jul 11, 2005, 5:47:23 PM (19 years ago)
- Location:
- orxonox/trunk/src/world_entities/weapons
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world_entities/weapons/crosshair.cc
r4832 r4834 43 43 } 44 44 45 46 45 /** 47 46 * destroys a Crosshair … … 68 67 69 68 this->rotation = 0; 70 this-> rotationSpeed = 5;69 this->setRotationSpeed(5); 71 70 this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0); 72 71 … … 155 154 void Crosshair::tick(float dt) 156 155 { 156 // let the crosshair rotate 157 157 this->rotation += dt * rotationSpeed; 158 158 159 159 160 161 } 162 163 /** 164 * draws the crosshair 165 */ 166 void Crosshair::draw() 167 { 168 /* 169 const PNode* camera = State::getInstance()->getCamera(); //!< \todo MUST be different 170 Vector cameraPos = camera->getAbsCoor(); 171 Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor(); 172 Vector view = cameraTargetPos - cameraPos; 173 Vector up = Vector(0, 1, 0); 174 up = camera->getAbsDir().apply(up); 175 Vector h = up.cross(view); 176 Vector v = h.cross(view); 177 h.normalize(); 178 v.normalize(); 179 180 float px = (position2D[0]-GraphicsEngine::getInstance()->getResolutionX()/2)*.05; 181 float py = -(position2D[1]-GraphicsEngine::getInstance()->getResolutionY()/2)*.05; 182 183 glBegin(GL_TRIANGLES); 184 glVertex3f(cameraTargetPos.x - h.x*px - v.x*py, 185 cameraTargetPos.y - h.y*px - v.y*py, 186 cameraTargetPos.z - h.z*px - v.z*py); 187 188 glVertex3f(cameraTargetPos.x - h.x*(px+1) - v.x*py, 189 cameraTargetPos.y - h.y*(px+1) - v.y*py, 190 cameraTargetPos.z - h.z*(px+1) - v.z*py); 191 192 glVertex3f(cameraTargetPos.x - h.x*px - v.x*(py+1), 193 cameraTargetPos.y - h.y*px - v.y*(py+1), 194 cameraTargetPos.z - h.z*px - v.z*(py+1)); 195 196 glEnd(); 197 198 */ 199 200 201 GraphicsEngine::storeMatrices(); 202 203 /// float z; 204 // glReadPixels ((int)position2D[0], GraphicsEngine::getInstance()->getResolutionY()-(int)position2D[1]-1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z); 205 206 207 //cout << z <<" "<< scale << " " << bias<< endl; 208 160 float z; 161 glReadPixels ((int)position2D[0], GraphicsEngine::getInstance()->getResolutionY()-(int)position2D[1]-1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z); 162 //cout << z << endl; 209 163 210 164 GLdouble objX, objY, objZ; … … 221 175 this->setAbsCoor(objX, objY, objZ); 222 176 177 178 } 179 180 /** 181 * draws the crosshair 182 */ 183 void Crosshair::draw() 184 { 185 GraphicsEngine::storeMatrices(); 186 187 188 189 223 190 // glBegin(GL_TRIANGLES); 224 191 // glColor3f(1,0,0); … … 228 195 // glEnd(); 229 196 197 this->debugDraw(); 230 198 231 199 GraphicsEngine::enter2DMode(); … … 253 221 glVertex2f(size, size); 254 222 glEnd(); 255 /* 256 glBegin(GL_QUADS); 257 { 258 glColor4f(1,0,0,1); 259 glVertex2f(position2D[0]-10, position2D[1]-10); 260 glVertex2f(position2D[0]+10, position2D[1]-10); 261 glVertex2f(position2D[0]+10, position2D[1]+10); 262 glVertex2f(position2D[0]-10, position2D[1]+10); 263 264 // glVertex2f(pos[0]-10, pos[1]-10); 265 // glVertex2f(pos[0]-10, pos[1]+10); 266 // glVertex2f(pos[0]+10, pos[1]+10); 267 // glVertex2f(pos[0]+10, pos[1]-10); 268 } 269 glEnd(); 270 */ 223 271 224 GraphicsEngine::leave2DMode(); 272 225 } -
orxonox/trunk/src/world_entities/weapons/weapon.cc
r4832 r4834 16 16 17 17 #include "weapon.h" 18 #include "weapon_manager.h"19 18 19 #include "projectile.h" 20 21 #include "load_param.h" 20 22 #include "vector.h" 21 #include "projectile.h"22 23 #include "list.h" 23 24 #include "state.h" -
orxonox/trunk/src/world_entities/weapons/weapon_manager.cc
r4833 r4834 19 19 #include "weapon_manager.h" 20 20 #include "weapon.h" 21 21 #include "crosshair.h" 22 23 #include "load_param.h" 24 #include "factory.h" 22 25 #include "vector.h" 23 26 #include "list.h" … … 53 56 this->configs[i].slots[j] = NULL; 54 57 } 55 } 56 58 59 // crosshair being a PNode it must not be deleted (this is because PNodes delete themselves.) 60 //delete this->crosshair; 61 } 62 63 /** 64 * initializes the WeaponManager 65 */ 57 66 void WeaponManager::init() 58 67 { … … 66 75 } 67 76 this->currConfID = W_CONFIG0; 68 77 this->crosshair = new Crosshair(); 78 } 79 80 /** 81 * 82 * @param root the XML-element to load from 83 */ 84 void WeaponManager::loadParams(const TiXmlElement* root) 85 { 86 static_cast<BaseObject*>(this)->loadParams(root); 87 88 LoadParam<WeaponManager>(root, "slot-count", this, &WeaponManager::setSlotCount) 89 .describe("how many slots(cannons) the WeaponManager can handle"); 90 91 LOAD_PARAM_START_CYCLE; 92 93 LoadParam<WeaponManager>(root, "Weapons", this, &WeaponManager::loadWeapons) 94 .describe("loads Weapons"); 95 // LoadParam<WeaponManager>(root, "Weapon", this, &WeaponManager::addWeapon); 96 97 LOAD_PARAM_END_CYCLE; 98 } 99 100 /** 101 * loads a Weapon onto the WeaponManager 102 * @param root the XML-element to load the Weapons from 103 */ 104 void WeaponManager::loadWeapons(const TiXmlElement* root) 105 { 106 LOAD_PARAM_START_CYCLE; 107 108 Weapon* newWeapon = dynamic_cast<Weapon*>(Factory::getFirst()->fabricate(element)); 109 110 111 112 LOAD_PARAM_END_CYCLE; 113 } 114 115 116 /** 117 * sets the number of Slots the WeaponManager has 118 * @param nrOfSlots the number of slots 119 */ 120 void WeaponManager::setSlotCount(int nrOfSlots) 121 { 122 this->nrOfSlots = nrOfSlots; 69 123 } 70 124 … … 100 154 } 101 155 102 156 /** 157 * removes a Weapon from the WeaponManager 158 */ 103 159 void WeaponManager::removeWeapon(Weapon* weapon, int configID) 104 160 { … … 163 219 if( firingWeapon != NULL) firingWeapon->fire(); 164 220 } 221 this->crosshair->setRotationSpeed(-500); 165 222 } 166 223 … … 178 235 if( w != NULL) w->tick(dt); 179 236 } 237 238 crosshair->tick(dt); 239 crosshair->setRotationSpeed(5); 180 240 } 181 241 … … 193 253 w->draw(); 194 254 } 255 crosshair->draw(); 195 256 } 196 257 -
orxonox/trunk/src/world_entities/weapons/weapon_manager.h
r4833 r4834 32 32 // FORWARD DECLARATION 33 33 class Weapon; 34 class Crosshair; 34 35 35 36 #define W_MAX_SLOTS 8 … … 71 72 void init(); 72 73 void loadParams(const TiXmlElement* root); 74 void loadWeapons(const TiXmlElement* root); 75 76 void setSlotCount(int nrOfSlots); 73 77 74 78 void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT); … … 81 85 82 86 private: 87 Crosshair* crosshair; //!< an aim. 88 83 89 int nrOfSlots; //<! number of weapon slots a ship has 84 90 int currConfID; //<! the currently selected config
Note: See TracChangeset
for help on using the changeset viewer.