void Shot::simulate(const float& i_seconds) { InternalMessage("Model","Shot::simulate entering") ; // mark the shot object for destruction getControlerSet()->addObjectToDestroy(getTrait()->getObject()) ; InternalMessage("Model","Shot::simulate leaving") ; }
void WithLifetime::simulate(const float& i_seconds) { InternalMessage("WithLifetime","Logic::WithLifetime::simulate entering") ; getTrait()->removeLifeTime(Duration::Second(i_seconds)) ; if (getTrait()->getLifeTimeInSeconds() < 0) { InternalMessage("WithLifetime","Logic::WithLifetime::simulate destroying object") ; // mark the object for destruction getObject()->destroyObject() ; } InternalMessage("WithLifetime","Logic::WithLifetime::simulate leaving") ; }
void Quadmesh::setShaderVariableFromFloatTrait(OpenGLShaderProgram *shader, const char *key) { OpenGLShaderProgram::Uniform variable(*shader, key); float value = getTrait(key).getValue(); if (variable.uniformID < 0) { return; } else { variable.set(value); } }
void Oriented::onUpdate() { m_node->setOrientation(getTrait()->getOrientation().getQuaternion()) ; m_node->_update(true,false) ; InternalMessage("Display", "modification of scene node " + m_node->getName() + " with orientation " + ::Ogre::StringConverter::toString(m_node->getOrientation()) ) ; }
void Positionned::onUpdate() { /// on le replace par rapport à son parent m_node->setPosition(convert(getTrait()->getPosition())) ; m_node->_update(true,false) ; InternalMessage("Display", "modification of scene node " + m_node->getName() + " with position " + ::Ogre::StringConverter::toString(m_node->getPosition())) ; }
void Collision::onInit() { InternalMessage("Model","Collision::onInit entering") ; m_beam = NULL ; m_destroyable = NULL ; /* if one object is a laser beam - destroy it and if the other is destroyable - manage damage */ LaserBeam* beam1 = getTrait()->getObject1()->getTrait<LaserBeam>() ; LaserBeam* beam2 = getTrait()->getObject2()->getTrait<LaserBeam>() ; Destroyable* destroyable1 = getTrait()->getObject1()->getTrait<Destroyable>() ; Destroyable* destroyable2 = getTrait()->getObject2()->getTrait<Destroyable>() ; if (beam1) { m_beam = beam1 ; getTrait()->getObject1()->destroyObject() ; } if (beam2) { m_beam = beam2 ; getTrait()->getObject2()->destroyObject() ; } if (destroyable1) { m_destroyable = destroyable1 ; } if (destroyable2) { m_destroyable = destroyable2 ; } // handle beam/destroyable collision if (m_beam && m_destroyable) { InternalMessage("Model","Collision::onInit damaging " + Kernel::toString(m_beam->getEnergy().Joule())) ; m_destroyable->damage(m_beam->getEnergy()) ; Kernel::Object* hit = m_destroyable->getObject()->createObject() ; hit->addTrait(new Hit()) ; Position position(getRelativePosition(getObject(),m_destroyable->getObject())) ; InternalMessage("Model","Collision::onInit creating hit at " + ::Ogre::StringConverter::toString(position.Meter())) ; hit->addTrait(new Positioned(position)) ; hit->addTrait(new WithLifetime(Duration::Second(0))) ; hit->addTrait(new Sized(Distance(Distance::_Meter,60))) ; hit->addTrait(new Oriented(Orientation(position))) ; } InternalMessage("Model","Collision::onInit leaving") ; }
void EndOfSimulation::onInit() { InternalMessage("Model","EndOfSimulation::onInit entering") ; const std::set<Kernel::Object*>& roots = getTrait()->getObject() ->getModel()->getRoots() ; for(std::set<Kernel::Object*>::const_iterator root = roots.begin() ; root != roots.end() ; ++root) { (*root)->destroyObject() ; } InternalMessage("Model","EndOfSimulation::onInit leaving") ; }
void Quadmesh::setShaderVariableFromColorTrait(OpenGLShaderProgram *shader, const char *key) { OpenGLShaderProgram::Uniform variable(*shader, key); Colour solidColor = Colour::fromString(getTrait(key).toString()); float r = solidColor.getFloatRed(); float g = solidColor.getFloatGreen(); float b = solidColor.getFloatBlue(); float a = solidColor.getFloatAlpha(); if (variable.uniformID < 0) { return; } else { variable.set(r, g, b, a); } }
void ForceGenerator::prepare() { /// set a force on it's body if (m_object) { Ogre::Vector3 force = getTrait()->getAppliedForce().Newton() ; InternalMessage("Physic","Physic::ForceGenerator::prepare " + Kernel::toString(getObject()->getIdentifier()) + " force = " + Kernel::toString(force.x) + "," + Kernel::toString(force.y) + "," + Kernel::toString(force.z) + " applied on object " + Kernel::toString(m_object->getObject()->getIdentifier())) ; m_object->getBody()->addForce((dReal)(force.x), (dReal)(force.y), (dReal)(force.z)) ; } }
void AgentVehicle::onUpdate() { // last updated elementary trait will tell us what to update const Kernel::TypeIdentifier& latest = getTrait()->getLatestUpdatedTrait() ; if (latest == getClassTypeIdentifier(Model::Positionned)) { m_vehicle->setPosition(getPosition()) ; } else if (latest == getClassTypeIdentifier(Model::Mobile)) { m_vehicle->setSpeed(getSpeed()) ; m_vehicle->setMaxSpeed(std::max(m_vehicle->getMaxSpeed(),m_vehicle->getSpeed().length())) ; m_vehicle->setOrientation(getOrientation()) ; } else if (latest == getClassTypeIdentifier(Model::Solid)) { m_vehicle->setSize(getSize()) ; } }
void Solid::onInit() { InternalMessage("Display","Entering Solid::onInit") ; Positionned* positionned(getView<Positionned>()) ; positionned->_init() ; // build 3D object m_mesh = this->getViewPoint()->getManager() ->createEntity(Utility::getUniqueName(), getTrait()->getMesh().getName()) ; // put it on the node positionned->getNode()->attachObject(m_mesh) ; // reset scale factor positionned->getNode()->setScale(::Ogre::Vector3(1.0/conversion_factor, 1.0/conversion_factor, 1.0/conversion_factor)) ; InternalMessage("Display","Leaving Solid::onInit") ; }
void Destroyable::simulate(const float& i_seconds) { if (getTrait()->getLife() <= 0 && !m_marked_to_destroy) { InternalMessage("Model","Logic::Destroyable destroying object") ; // create explosion Solid* solid = getObject()->getTrait<Solid>() ; Distance explosion_radius ; if (solid) explosion_radius = 4*solid->getRadius() ; Duration explosion_duration(Duration::Second(1)) ; getObject()->addTrait(new Explosion(explosion_radius,explosion_duration)) ; // add a life time trait getObject()->addTrait(new WithLifetime(explosion_duration)) ; m_marked_to_destroy = true ; } }
/*! @pre Parent Positionned View is init. */ void Positionned::onInit() { InternalMessage("Display","Entering Positionned::init") ; Model::Positionned* positionned_ancestor = getObject()->getAncestor<Model::Positionned>() ; if (positionned_ancestor) { Positionned* parent_node(positionned_ancestor->getView<Positionned>(getViewPoint())) ; m_node = static_cast<SceneNode*>(parent_node->getNode()->createChild()) ; InternalMessage("Display", "creating scene node " + m_node->getName() + " with parent " + parent_node->m_node->getName() + " with position " + ::Ogre::StringConverter::toString(m_node->getPosition())) ; m_node->setPosition(convert(getTrait()->getPosition())) ; InternalMessage("Display", "modification of scene node " + m_node->getName() + " with position " + ::Ogre::StringConverter::toString(m_node->getPosition())) ; } else { InternalMessage("Display","root node") ; m_node = this->getViewPoint()->getManager()->getRootSceneNode() ; getViewPoint()->setRootObject(getObject()) ; } InternalMessage("Display","Leaving Positionned::init") ; }
/*! @pre Parent Positionned View is init. */ void Oriented::onInit() { InternalMessage("Display","Entering Positionned::init") ; Model::Positionned* model_positionned = getObject()->getTrait<Model::Positionned>() ; if (model_positionned) { Positionned* positionned( model_positionned ->getView<Positionned>(getViewPoint())) ; if (positionned) { positionned->_init() ; m_node = positionned->getNode() ; InternalMessage("Display", "intitalising scene node " + m_node->getName() + " with orientation " + ::Ogre::StringConverter::toString(m_node->getOrientation())) ; m_node->setOrientation(getTrait()->getOrientation().getQuaternion()) ; InternalMessage("Display", "modification of scene node " + m_node->getName() + " with orientation " + ::Ogre::StringConverter::toString(m_node->getOrientation())) ; } } InternalMessage("Display","Leaving Positionned::init") ; }
Component *Quadmesh::getController() { Array<PropertyComponent*> props; if (vertexPositionsFunction) { /* don't expose resolution control if reading from a table */ props.add(new SliderPropertyComponent(getTrait("resolution"), "resolution", 3, 512, 1)); } props.add(new BooleanPropertyComponent(getTrait("renderAsWireframe"), "renderAsWireframe", "")); props.add(getColorChoicePropertyComponent(getTrait("solidColor"), "solidColor")); props.add(new BooleanPropertyComponent(getTrait("drawMesh"), "drawMesh", "")); props.add(new SliderPropertyComponent(getTrait("meshOutlinesWidth"), "meshOutlinesWidth", 0.01, 0.5, 0.01)); props.add(new SliderPropertyComponent(getTrait("meshOutlinesSoftness"), "meshOutlinesSoftness", 0.01, 1.0, 0.01)); PropertyPanel *propertyPanel = new PropertyPanel; propertyPanel->addProperties(props); propertyPanel->setBounds(0, 0, 256, propertyPanel->getTotalContentHeight()); return propertyPanel; }
void Quadmesh::valueChanged(Value &value) { if (getTrait("renderAsWireframe").refersToSameSourceAs(value)) { if (getTrait("renderAsWireframe").getValue()) { lastSolidColorName = getTrait("solidColor").getValue(); setTrait("solidColor", lastWiredColorName); shaderController->loadFromGlsl(BinaryData::QuadmeshWireframeShader_glsl); shaderController->compileShader(); } else { lastWiredColorName = getTrait("solidColor").getValue(); setTrait("solidColor", lastSolidColorName); shaderController->loadFromGlsl(BinaryData::QuadmeshSurfaceShader_glsl); shaderController->compileShader(); } } else if (getTrait("resolution").refersToSameSourceAs(value)) { if (vertexPositionsFunction) { Nu = Nv = int(getTrait("resolution").getValue()); evaluateVertexData(); } } }
Kernel::Object* Listener::getObject() const { return getTrait()->getObject() ; }
Kernel::Object* Engine::getObject() const { getTrait()->getObject() ; }
AbstractDataTrait* DataTraitsList::getTrait(const std::type_info& type) { return getTrait(DataTypeId::getId(type)); }
void onInit() { value = getTrait()->getValue() ; ++init_number ; }
bool State::call(const Kernel::TypeIdentifier& trait_type, const std::string& command) { Kernel::Log::Block temp("State","State::call command=" + command) ; // check for aliases std::map<std::string,std::string>::const_iterator finder = m_aliases.find(command) ; if (finder != m_aliases.end()) { return call(trait_type,finder->second) ; } InternalMessage("State","State::call command is not an alias") ; // parse the command std::string::size_type position_of_parenthesis = command.find('(') ; if (position_of_parenthesis != std::string::npos) { std::string command_name = command.substr(0,position_of_parenthesis) ; InternalMessage("State","State::call command name=" + command_name) ; if (command_name == "pop") { State* parent = getObject()->getAncestor<State>() ; if (parent) { parent->popState() ; return true ; } } else { // look for ',' std::string::size_type position_of_comma = command.find(',',position_of_parenthesis) ; if (position_of_comma != std::string::npos) { std::string object_name = command.substr(position_of_parenthesis+1, position_of_comma-position_of_parenthesis-1) ; std::string trait_name = command.substr(position_of_comma+1, command.length()-position_of_comma-2) ; InternalMessage("State","State::call object name=" + object_name) ; InternalMessage("State","State::call trait name=" + trait_name) ; std::auto_ptr<Active> active(getTrait(trait_name)) ; Kernel::Object* object = Kernel::Object::get(object_name) ; if (object && active.get()) { if (command_name == "push") { pushState(object,active.release()) ; return true ; } else if (command_name == "change") { changeState(object,active.release()) ; return true ; } } ErrorMessage("State::call invalid command " + command) ; } } } // not executed InternalMessage("State","State::call command name not executed") ; return false ; }
Kernel::Object* BackgroundSound::getObject() const { return getTrait()->getObject() ; }