Example #1
0
void Mouse::Move(float x, float y)
{
  if (_window->get_graphics_window())
  {
    LPoint2f position = GetPosition();

    position.set_x(position.get_x() + x);
    position.set_y(position.get_y() + y);
    _window->get_graphics_window()->move_pointer(0, x, y);
  }
}
Example #2
0
LPoint2f Mouse::GetPositionRatio(void) const
{
  LPoint2f position = GetPosition();
  
  if (_window->get_graphics_window())
  {
    int      size_x   = _window->get_graphics_window()->get_x_size();
    int      size_y   = _window->get_graphics_window()->get_y_size();

    position.set_x( ((position.get_x() / size_x) - 0.5) * 2);
    position.set_y(-(((position.get_y() / size_y) - 0.5) * 2));
  }
  return (position);
}
Example #3
0
// Updates the shader inputs that need to be updated every frame.
// Normally, you shouldn't call this, it's being called in a task.
void CCommonFilters::update()
   {
   if(m_configuration["VolumetricLighting"] != NULL)
      {
      NodePath caster =
            static_cast<VolumetricLightingConfiguration*>
            (m_configuration["VolumetricLighting"])->caster;
      LPoint2f casterpos;
      NodePath cameraNp = m_manager.m_camera;
      PT(Camera) camera = DCAST(Camera, cameraNp.node());
      camera->get_lens()->project(caster.get_pos(cameraNp), casterpos);
      m_finalQuad.set_shader_input("casterpos",
                                   LVector4f(casterpos.get_x() * 0.5 + 0.5,
                                              casterpos.get_y() * 0.5 + 0.5,
                                              0,
                                              0));
      }
   }
Example #4
0
void Sunlight::SetSunlightPositionFromTime()
{
  DateTime            current_time = time_manager.GetDateTime();
  DateTime::DayLength day_length   = current_time.GetDayLength();
  float               hour         = current_time.GetHour() + (current_time.GetMinute() / 60.f);
  bool                night        = hour < day_length.begin || hour >= day_length.end;
  float               step         = hour + (hour >= day_length.end ? -day_length.end : (hour < day_length.begin ? 24 - day_length.end : -day_length.begin));
  float               total_steps  = night ? 24 - day_length.length : day_length.length;
  step = !night ? 12 - step : step;
  //cout << "Step at " << hour << ": " << step << " because day length is " << day_length.begin << "/" << day_length.end << endl;
  float               angle        = (180.f/ total_steps) * step;
  LPoint2f            position     = solar_orbit.PointAtAngle(angle * 3.14159265f / 180.f);

  //cout << "SunLightPosition: " << position.get_x() << ',' << position.get_y() << endl;
  sunlight_nodepath.set_x(position.get_x());
  sunlight_nodepath.set_z(position.get_y());
  sunlight_nodepath.set_y(0);
  sunlight_nodepath.look_at(solar_orbit.GetPosition());
}
Example #5
0
void Mouse::Run(void)
{
  PStatCollector collector("Level:Mouse:Run");

  collector.start();
  //if (pointer.get_in_window())
  {
      LPoint2f cursorPos = GetPositionRatio();

    if (cursorPos != _lastMousePos)
    {
      _lastMousePos = cursorPos;
      _pickerRay->set_from_lens(_window->get_camera(0), cursorPos.get_x(), cursorPos.get_y());
      _collisionTraverser.traverse(_window->get_render());
      _collisionHandlerQueue->sort_entries();
      //_hovering.Reset();
      _hovering.hasDynObject = false;
      _hovering.dynObject    = NodePath();
      for (int i = 0 ; i < _collisionHandlerQueue->get_num_entries() ; ++i)
      {
        CollisionEntry* entry = _collisionHandlerQueue->get_entry(i);
        NodePath        into  = entry->get_into_node_path();

        if (into.is_hidden())
          continue ;
        switch (into.get_collide_mask().get_word())
        {
          case ColMask::DynObject:
          if (!(_hovering.hasDynObject))
            _hovering.SetDynObject(into);
          break ;
        }
      }
    }
  }
  collector.stop();
}
Example #6
0
void Mouse::ClosestWaypoint(World* world, short current_floor)
{
  //if (_mouseWatcher->has_mouse())
  {
    PStatCollector collector("Level:Mouse:FindWaypoint"); collector.start();
    PT(CollisionRay)          pickerRay;
    PT(CollisionNode)         pickerNode;
    NodePath                  pickerPath;
    CollisionTraverser        collisionTraverser;
    PT(CollisionHandlerQueue) collisionHandlerQueue = new CollisionHandlerQueue();
    LPoint2f                  cursorPos             = GetPositionRatio();
    static bool               updated               = false;
    static LPoint2f           last_update;

    if (ABS(cursorPos.get_x() - last_update.get_x()) > 0.05 || ABS(cursorPos.get_y() - last_update.get_y()) > 0.05)
      updated         = false;
    if (!(updated == false))
      return ;
    last_update       = cursorPos;
    updated           = true;
    pickerNode        = new CollisionNode("mouseRay2");
    pickerPath        = _camera.attach_new_node(pickerNode);
    pickerRay         = new CollisionRay();
    pickerNode->set_from_collide_mask(CollideMask(ColMask::WpPlane));
    pickerNode->set_into_collide_mask(0);
    pickerRay->set_from_lens(_window->get_camera(0), cursorPos.get_x(), cursorPos.get_y());
    pickerNode->add_solid(pickerRay);

    collisionTraverser.add_collider(pickerPath, collisionHandlerQueue);
    collisionTraverser.traverse(_window->get_render());
    //collisionTraverser.traverse(world->floors[current_floor]);

    collisionHandlerQueue->sort_entries();

    if (_hovering.waypoint_ptr && _hovering.hasWaypoint)
      _hovering.waypoint_ptr->SetSelected(false);
    _hovering.hasWaypoint  = false;
    _hovering.waypoint_ptr = 0;
    for (int i = 0 ; i < collisionHandlerQueue->get_num_entries() ; ++i)
    {
      CollisionTraverser        model_traverser;
      PT(CollisionHandlerQueue) handler_queue = new CollisionHandlerQueue();

      CollisionEntry* entry      = collisionHandlerQueue->get_entry(i);
      NodePath        np         = entry->get_into_node_path();
      MapObject*      map_object = world->GetMapObjectFromNodePath(np);
      LPoint3         pos;
      static LPoint3  spheresize = NodePathSize(world->model_sphere);

      if (!map_object || map_object->nodePath.is_hidden())
        continue ;
      if (map_object->collider.type == Collider::MODEL)
      {
        CollideMask initial_collide_mask = map_object->render.get_collide_mask();

        map_object->render.set_collide_mask(initial_collide_mask | CollideMask(ColMask::WpPlane));
        model_traverser.add_collider(pickerPath, handler_queue);
        model_traverser.traverse(map_object->render);
        map_object->render.set_collide_mask(initial_collide_mask);
        if (handler_queue->get_num_entries() == 0)
          continue ;
        entry = handler_queue->get_entry(0);
      }
      pos = entry->get_surface_point(world->window->get_render()) - spheresize;
      _hovering.waypoint_ptr = world->waypoint_graph.GetClosest(pos);
      if (_hovering.waypoint_ptr)
      {
        _hovering.SetWaypoint(_hovering.waypoint_ptr->nodePath);
        _hovering.waypoint_ptr->SetSelected(true);
      }
      break ;
    }

    // Detaching seems to be causing some memory issues.
    //pickerPath.detach_node();
    collector.stop();
  }
}