Example #1
0
void TransformComponent::AddFromRawData(corgi::EntityRef& entity,
                                        const void* raw_data) {
  auto transform_def = static_cast<const TransformDef*>(raw_data);
  auto pos = transform_def->position();
  auto orientation = transform_def->orientation();
  auto scale = transform_def->scale();
  TransformData* transform_data = AddEntity(entity);
  // TODO: Move vector loading into a function in fplbase.
  if (pos != nullptr) {
    transform_data->position = mathfu::vec3(pos->x(), pos->y(), pos->z());
  }
  if (orientation != nullptr) {
    transform_data->orientation = mathfu::quat::FromEulerAngles(
        mathfu::vec3(orientation->x(), orientation->y(), orientation->z()) *
        kDegreesToRadians);
  }
  if (scale != nullptr) {
    transform_data->scale = mathfu::vec3(scale->x(), scale->y(), scale->z());
  }

  // The physics component is initialized first, so it needs to be updated with
  // the correct initial transform.
  auto physics_component = entity_manager_->GetComponent<PhysicsComponent>();
  if (entity->IsRegisteredForComponent(physics_component->GetComponentId())) {
    physics_component->UpdatePhysicsFromTransform(entity);
  }

  if (transform_def->child_ids() != nullptr) {
    for (size_t i = 0; i < transform_def->child_ids()->size(); i++) {
      auto child_id = transform_def->child_ids()->Get(i);
      // We don't actually add the children until the first update,
      // to give the other entities in our list time to be loaded.
      if (transform_data->child_ids.find(child_id->c_str()) ==
          transform_data->child_ids.end()) {
        transform_data->pending_child_ids.push_back(child_id->c_str());
        transform_data->child_ids.insert(child_id->c_str());
      }
    }
  }
}
Example #2
0
 bool CheckComponentEnd(int comp_len) {
     return CheckComponentEnd(GetComponentId(), component_end, comp_len, *m_AgpErr);
 }
Example #3
0
 int GetComponentId( Entity id )
 {
     return GetComponentId( id, Index<Component,std::tuple<Components...>>::value );
 }