Changeset 2447 for code/branches/objecthierarchy2
- Timestamp:
- Dec 14, 2008, 8:13:43 PM (16 years ago)
- Location:
- code/branches/objecthierarchy2/src/orxonox/objects
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/src/orxonox/objects/Scene.cc
r2361 r2447 33 33 #include <OgreSceneManagerEnumerator.h> 34 34 #include <OgreSceneNode.h> 35 #include <OgreLight.h>36 35 37 36 #include "core/CoreIncludes.h" … … 48 47 49 48 this->setScene(this); 50 this->bShadows_ = false;49 this->bShadows_ = true; 51 50 52 51 if (Core::showsGraphics()) … … 69 68 this->rootSceneNode_ = this->sceneManager_->getRootSceneNode(); 70 69 } 71 72 // test test test73 if (Core::showsGraphics() && this->sceneManager_)74 {75 Ogre::Light* light;76 light = this->sceneManager_->createLight("Light-1");77 light->setType(Ogre::Light::LT_DIRECTIONAL);78 light->setDiffuseColour(ColourValue(1.0, 0.9, 0.6, 1.0));79 light->setSpecularColour(ColourValue(1.0, 0.9, 0.6, 1.0));80 light->setDirection(1, -0.3, 0.3);81 }82 // test test test83 70 84 71 this->registerVariables(); … … 116 103 REGISTERSTRING(this->skybox_, direction::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox)); 117 104 REGISTERDATA(this->ambientLight_, direction::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight)); 105 REGISTERDATA(this->bShadows_, direction::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyShadows)); 118 106 } 119 107 -
code/branches/objecthierarchy2/src/orxonox/objects/Scene.h
r2171 r2447 75 75 void networkcallback_applyAmbientLight() 76 76 { this->setAmbientLight(this->ambientLight_); } 77 void networkcallback_applyShadows() 78 { this->setShadow(this->bShadows_); } 77 79 78 80 Ogre::SceneManager* sceneManager_; -
code/branches/objecthierarchy2/src/orxonox/objects/gametypes/Gametype.cc
r2438 r2447 149 149 void Gametype::pawnKilled(Pawn* victim, Pawn* killer) 150 150 { 151 if (victim )151 if (victim && victim->getPlayer()) 152 152 { 153 153 std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.find(victim->getPlayer()); 154 it->second = PlayerState::Dead; 155 156 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator()); 157 if (victim->getCamera()) 158 { 159 entity->setPosition(victim->getCamera()->getWorldPosition()); 160 entity->setOrientation(victim->getCamera()->getWorldOrientation()); 154 if (it != this->players_.end()) 155 { 156 it->second = PlayerState::Dead; 157 158 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator()); 159 if (victim->getCamera()) 160 { 161 entity->setPosition(victim->getCamera()->getWorldPosition()); 162 entity->setOrientation(victim->getCamera()->getWorldOrientation()); 163 } 164 else 165 { 166 entity->setPosition(victim->getWorldPosition()); 167 entity->setOrientation(victim->getWorldOrientation()); 168 } 169 it->first->startControl(entity); 161 170 } 162 171 else 163 { 164 entity->setPosition(victim->getWorldPosition()); 165 entity->setOrientation(victim->getWorldOrientation()); 166 } 167 it->first->startControl(entity); 172 COUT(2) << "Warning: Killed Pawn was not in the playerlist" << std::endl; 168 173 } 169 174 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.cc
r2438 r2447 81 81 if (this->isInitialized()) 82 82 { 83 this->bDestroyWhenPlayerLeft_ = false; 84 83 85 if (this->bHasLocalController_ && this->bHasHumanController_) 84 86 this->stopLocalHumanControl(); 85 87 88 if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this) 89 this->getPlayer()->stopControl(this, false); 90 86 91 if (this->hud_) 87 92 delete this->hud_; … … 89 94 if (this->camera_) 90 95 delete this->camera_; 91 92 if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)93 this->getPlayer()->stopControl(this, false);94 96 } 95 97 } … … 231 233 void ControllableEntity::startLocalHumanControl() 232 234 { 233 this->camera_ = new Camera(this); 234 this->camera_->requestFocus(); 235 if (this->cameraPositionTemplate_ != "") 236 this->addTemplate(this->cameraPositionTemplate_); 237 if (this->cameraPositions_.size() > 0) 238 this->cameraPositions_.front()->attachCamera(this->camera_); 239 else 240 this->attach(this->camera_); 241 242 if (this->hudtemplate_ != "") 243 { 244 this->hud_ = new OverlayGroup(this); 245 this->hud_->addTemplate(this->hudtemplate_); 246 this->hud_->setOwner(this); 235 if (!this->camera_) 236 { 237 this->camera_ = new Camera(this); 238 this->camera_->requestFocus(); 239 if (this->cameraPositionTemplate_ != "") 240 this->addTemplate(this->cameraPositionTemplate_); 241 if (this->cameraPositions_.size() > 0) 242 this->cameraPositions_.front()->attachCamera(this->camera_); 243 else 244 this->attach(this->camera_); 245 } 246 247 if (!this->hud_) 248 { 249 if (this->hudtemplate_ != "") 250 { 251 this->hud_ = new OverlayGroup(this); 252 this->hud_->addTemplate(this->hudtemplate_); 253 this->hud_->setOwner(this); 254 } 247 255 } 248 256 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Light.cc
r2254 r2447 36 36 37 37 #include "util/String.h" 38 #include "util/Convert.h" 38 #include "util/Exception.h" 39 #include "core/Core.h" 39 40 #include "core/CoreIncludes.h" 40 41 #include "core/XMLPort.h" … … 43 44 namespace orxonox 44 45 { 45 unsigned int Light::lightCounter_s = 0;46 47 46 CreateFactory(Light); 48 47 … … 51 50 RegisterObject(Light); 52 51 53 if (this->getScene() && this->getScene()->getSceneManager()) 54 this->light_ = this->getScene()->getSceneManager()->createLight("Light" + convertToString(Light::lightCounter_s++)); 55 this->getNode()->attachObject(this->light_); 52 this->light_ = 0; 53 this->diffuse_ = ColourValue::White; 54 this->specular_ = ColourValue::White; 55 this->type_ = Ogre::Light::LT_POINT; 56 this->attenuation_ = Vector4(100000, 1, 0, 0); 57 this->spotlightRange_ = Vector3(40.0f, 30.0f, 1.0f); 58 59 if (Core::showsGraphics()) 60 { 61 if (!this->getScene()) 62 ThrowException(AbortLoading, "Can't create Light, no scene given."); 63 if (!this->getScene()->getSceneManager()) 64 ThrowException(AbortLoading, "Can't create Light, no scene manager given."); 65 66 if (this->getScene() && this->getScene()->getSceneManager()) 67 { 68 this->light_ = this->getScene()->getSceneManager()->createLight("Light" + getUniqueNumberString()); 69 this->light_->setDirection(WorldEntity::FRONT); 70 this->getNode()->attachObject(this->light_); 71 72 this->updateType(); 73 this->updateDiffuseColour(); 74 this->updateSpecularColour(); 75 this->updateAttenuation(); 76 this->updateSpotlightRange(); 77 } 78 } 56 79 57 80 this->registerVariables(); … … 71 94 SUPER(Light, XMLPort, xmlelement, mode); 72 95 73 XMLPortParam(Light, "type", setTypeString, getTypeString, xmlelement, mode).defaultValues("point"); 74 XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "diffuse", setDiffuseColour, getDiffuseColour, xmlelement, mode, const ColourValue&); 75 XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "specular", setSpecularColour, getSpecularColour, xmlelement, mode, const ColourValue&); 76 XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "direction", setDirection, getDirection, xmlelement, mode, const Vector3&); 96 XMLPortParam(Light, "type", setTypeString, getTypeString, xmlelement, mode).defaultValues("point"); 97 XMLPortParam(Light, "diffuse", setDiffuseColour, getDiffuseColour, xmlelement, mode).defaultValues(ColourValue::White); 98 XMLPortParam(Light, "specular", setSpecularColour, getSpecularColour, xmlelement, mode).defaultValues(ColourValue::White); 99 XMLPortParam(Light, "attenuation", setAttenuation, getAttenuation, xmlelement, mode).defaultValues(Vector4(100000, 1, 0, 0)); 100 XMLPortParam(Light, "spotlightrange", setSpotlightRange, getSpotlightRange, xmlelement, mode).defaultValues(Vector3(40.0f, 30.0f, 1.0f)); 77 101 } 78 102 79 103 void Light::registerVariables() 80 104 { 81 REGISTERDATA(this->type_, direction::toclient, new NetworkCallback<Light>(this, &Light::changedType)); 82 REGISTERDATA(this->light_->getDiffuseColour(), direction::toclient); 83 REGISTERDATA(this->light_->getSpecularColour(), direction::toclient); 84 REGISTERDATA(this->light_->getDirection(), direction::toclient); 105 REGISTERDATA(this->type_, direction::toclient, new NetworkCallback<Light>(this, &Light::updateType)); 106 REGISTERDATA(this->diffuse_, direction::toclient, new NetworkCallback<Light>(this, &Light::updateDiffuseColour)); 107 REGISTERDATA(this->specular_, direction::toclient, new NetworkCallback<Light>(this, &Light::updateSpecularColour)); 108 REGISTERDATA(this->attenuation_, direction::toclient, new NetworkCallback<Light>(this, &Light::updateAttenuation)); 109 REGISTERDATA(this->spotlightRange_, direction::toclient, new NetworkCallback<Light>(this, &Light::updateSpotlightRange)); 85 110 } 86 111 87 const std::string& Light::getName() const112 void Light::updateDiffuseColour() 88 113 { 89 114 if (this->light_) 90 return this->light_->getName(); 91 else 92 return BLANKSTRING; 115 this->light_->setDiffuseColour(this->diffuse_); 93 116 } 94 117 95 void Light:: setDiffuseColour(const ColourValue& colour)118 void Light::updateSpecularColour() 96 119 { 97 120 if (this->light_) 98 this->light_->set DiffuseColour(colour);121 this->light_->setSpecularColour(this->specular_); 99 122 } 100 123 101 const ColourValue& Light::getDiffuseColour() const124 void Light::updateAttenuation() 102 125 { 103 if (this->light_) 104 return this->light_->getDiffuseColour(); 105 else 106 return ColourValue::White; 126 if (this->light_ && this->type_ != Ogre::Light::LT_DIRECTIONAL) 127 this->light_->setAttenuation(this->attenuation_.x, this->attenuation_.y, this->attenuation_.z, this->attenuation_.w); 107 128 } 108 129 109 void Light:: setSpecularColour(const ColourValue& colour)130 void Light::updateSpotlightRange() 110 131 { 111 if (this->light_) 112 this->light_->setSpecularColour(colour); 113 } 114 115 const ColourValue& Light::getSpecularColour() const 116 { 117 if (this->light_) 118 return this->light_->getSpecularColour(); 119 else 120 return ColourValue::White; 121 } 122 123 void Light::setDirection(const Vector3& direction) 124 { 125 if (this->light_) 126 this->light_->setDirection(direction); 127 } 128 129 const Vector3& Light::getDirection() const 130 { 131 if (this->light_) 132 return this->light_->getDirection(); 133 else 134 return Vector3::ZERO; 132 if (this->light_ && this->type_ == Ogre::Light::LT_SPOTLIGHT) 133 this->light_->setSpotlightRange(Degree(this->spotlightRange_.x), Degree(this->spotlightRange_.y), this->spotlightRange_.z); 135 134 } 136 135 … … 157 156 case Ogre::Light::LT_POINT: 158 157 default: 159 return "poin T";158 return "point"; 160 159 } 161 160 } 162 161 163 void Light:: changedType()162 void Light::updateType() 164 163 { 165 164 if (this->light_) 165 { 166 166 this->light_->setType(this->type_); 167 168 if (this->type_ != Ogre::Light::LT_DIRECTIONAL) 169 this->updateAttenuation(); 170 if (this->type_ == Ogre::Light::LT_SPOTLIGHT) 171 this->updateSpotlightRange(); 172 } 167 173 } 168 174 -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Light.h
r2087 r2447 54 54 { return this->light_; } 55 55 56 const std::string& getName() const;57 58 56 inline void setType(Ogre::Light::LightTypes type) 59 { this->type_ = type; this-> changedType(); }60 Ogre::Light::LightTypes getType() const57 { this->type_ = type; this->updateType(); } 58 inline Ogre::Light::LightTypes getType() const 61 59 { return this->type_; } 62 60 63 void setDiffuseColour(const ColourValue& colour); 64 const ColourValue& getDiffuseColour() const; 61 inline void setDiffuseColour(const ColourValue& colour) 62 { this->diffuse_ = colour; this->updateDiffuseColour(); } 63 inline const ColourValue& getDiffuseColour() const 64 { return this->diffuse_; } 65 65 66 void setSpecularColour(const ColourValue& colour); 67 const ColourValue& getSpecularColour() const; 66 inline void setSpecularColour(const ColourValue& colour) 67 { this->specular_ = colour; this->updateSpecularColour(); } 68 inline const ColourValue& getSpecularColour() const 69 { return this->specular_; } 68 70 69 void setDirection(const Vector3& direction); 70 const Vector3& getDirection() const; 71 /** 72 @brief Sets the attenuation parameters of the light source i.e. how it diminishes with distance. 73 74 @param attenuation.x range (The absolute upper range of the light in world units) 75 @param attenuation.y constant (The constant factor in the attenuation formula: 1.0 means never attenuate, 0.0 is complete attenuation) 76 @param attenuation.z linear (The linear factor in the attenuation formula: 1 means attenuate evenly over the distance) 77 @param attenuation.w quadratic (The quadratic factor in the attenuation formula: adds a curvature to the attenuation formula) 78 79 Quote from the Ogre API: 80 Lights normally get fainter the further they are away. Also, each light is given a maximum range beyond which it cannot affect any objects. 81 Light attenuation is not applicable to directional lights since they have an infinite range and constant intensity. 82 This follows a standard attenuation approach - see any good 3D text for the details of what they mean since i don't have room here! 83 84 Quote from the Ogre wiki: 85 "Using these numbers, the light has 100% intensity at 0 distance, and 86 trails off to near black at a distance equal to the Range. Keep in mind 87 that most of the light falls in the first 20% of the range." 88 89 Range Constant Linear Quadratic 90 3250, 1.0, 0.0014, 0.000007 91 600, 1.0, 0.007, 0.0002 92 325, 1.0, 0.014, 0.0007 93 200, 1.0, 0.022, 0.0019 94 160, 1.0, 0.027, 0.0028 95 100, 1.0, 0.045, 0.0075 96 65, 1.0, 0.07, 0.017 97 50, 1.0, 0.09, 0.032 98 32, 1.0, 0.14, 0.07 99 20, 1.0, 0.22, 0.20 100 13, 1.0, 0.35, 0.44 101 7, 1.0, 0.7, 1.8 102 */ 103 inline void setAttenuation(const Vector4& attenuation) 104 { this->attenuation_ = attenuation; this->updateAttenuation(); } 105 inline const Vector4& getAttenuation() const 106 { return this->attenuation_; } 107 108 /** 109 @brief Sets the range of a spotlight, i.e. the angle of the inner and outer cones and the rate of falloff between them. 110 111 @param spotlightRange.x innerAngle (The angle covered by the bright inner cone) 112 @param spotlightRange.x outerAngle (The angle covered by the outer cone) 113 @param spotlightRange.x falloff (The rate of falloff between the inner and outer cones. 1.0 means a linear falloff, less means slower falloff, higher means faster falloff.) 114 */ 115 inline void setSpotlightRange(const Vector3& spotlightRange) 116 { this->spotlightRange_ = spotlightRange; this->updateSpotlightRange(); } 117 inline const Vector3& getSpotlightRange() const 118 { return this->spotlightRange_; } 71 119 72 120 private: … … 74 122 std::string getTypeString() const; 75 123 76 void changedType(); 124 void updateType(); 125 void updateDiffuseColour(); 126 void updateSpecularColour(); 127 void updateAttenuation(); 128 void updateSpotlightRange(); 77 129 78 static unsigned int lightCounter_s;79 130 Ogre::Light* light_; 80 131 Ogre::Light::LightTypes type_; 81 132 ColourValue diffuse_; 133 ColourValue specular_; 134 Vector4 attenuation_; 135 Vector3 spotlightRange_; 82 136 }; 83 137 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Model.cc
r2171 r2447 41 41 { 42 42 RegisterObject(Model); 43 44 this->bCastShadows_ = true; 43 45 44 46 this->registerVariables(); -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Pawn.cc
r2438 r2447 180 180 effect->setOrientation(this->getOrientation()); 181 181 effect->setDestroyAfterLife(true); 182 effect->setSource("Orxonox/explosion2 ");182 effect->setSource("Orxonox/explosion2b"); 183 183 effect->setLifetime(4.0f); 184 184 }
Note: See TracChangeset
for help on using the changeset viewer.