Example #1
0
Float
simplex_noise<Float,N>::sample(
	vector const &in)
{
	Float res = static_cast<Float>(0);
	vector tmp = stretch_m() * in;
	for(typename vector::iterator it = tmp.begin(); it != tmp.end(); ++it)
	{
		*it = std::floor(*it);
	}
	vector floored(tmp);
	tmp = inv_m() * tmp;
	tmp = in - tmp;
	vector offset(tmp);
	tmp = stretch_m() * tmp;

	corner_array c = corners(tmp);
	for (typename corner_array::const_iterator v = c.begin(); v != c.end(); ++v)
	{
		vector t(in - inv_m() * (floored + *v));
		res +=
			contrib(t, floored + *v);
	}

	// FIXME: replace this magic number with something sensible
	return static_cast<Float>(40.0) * res;
}
  ToolResult MouseDown(const PosInfo& info) override{
    Canvas& canvas = info.canvas;
    HotSpot hotSpot(floored(info.pos));

    if (info.modifiers.LeftMouse()){
      // Command for setting the hot spot to the current frame.

      auto frameIndex = canvas.GetSelectedFrame();
      const Image& frame = canvas.GetFrame(frameIndex);
      m_command.Set(set_frame_hotspot_command(frameIndex, New(hotSpot),
        Old(frame.GetHotSpot())));
      m_hotSpot = hotSpot;
      return ToolResult::COMMIT;
    }
    else if (info.modifiers.RightMouse()){
      // Command for setting the hot-spot to all frames.

      auto commands = make_vector(up_to(canvas.GetNumFrames()),
        [&](const auto& i){
          const Image& frame = canvas.GetFrame(i);
          return set_frame_hotspot_command(i,
            New(hotSpot),
            Old(frame.GetHotSpot()));});

      m_hotSpot = hotSpot;
      m_command.Set(perhaps_bunch(CommandType::FRAME,
        bunch_name("Set frame hot spots"),
        std::move(commands)));
      return ToolResult::COMMIT;
    }
    else{
      return ToolResult::NONE;
    }
  }