Example #1
0
void AppEnv::mouseMoveCallback(GLFWwindow* window, const double x_pos, const double y_pos) {
  auto* const obj = static_cast<AppEnv*>(glfwGetWindowUserPointer(window));
    
  obj->mouse_current_pos_ = screenPosition(Vec2f(x_pos - obj->viewport_ofs_.x(), y_pos - obj->viewport_ofs_.y()),
                                           obj->current_window_size_,
                                           Vec2f(obj->viewport_size_.x(), obj->viewport_size_.y()));
  // TIPS:Yは上下が逆
  obj->mouse_current_pos_.y() = -obj->mouse_current_pos_.y();

  if (!obj->mouse_left_press_ && !obj->mouse_right_press_) return;

  obj->mouse_last_pos_ = obj->mouse_pos_;
  obj->mouse_pos_ << x_pos, y_pos;
}
	Vector3f AbstractViewer::Project(const Nz::Vector3f& worldPosition) const
	{
		Vector4f pos4D(worldPosition, 1.f);
		pos4D = GetViewMatrix() * pos4D;
		pos4D = GetProjectionMatrix() * pos4D;
		pos4D /= pos4D.w;

		Rectf viewport = Rectf(GetViewport());

		Nz::Vector3f screenPosition(pos4D.x * 0.5f + 0.5f, -pos4D.y * 0.5f + 0.5f, pos4D.z * 0.5f + 0.5f);
		screenPosition.x = screenPosition.x * viewport.width + viewport.x;
		screenPosition.y = screenPosition.y * viewport.height + viewport.y;

		return screenPosition;
	}
Example #3
0
void AppEnv::mouseButtonCallback(GLFWwindow* window, const int button, const int action, const int mods) {
  auto* const obj = static_cast<AppEnv*>(glfwGetWindowUserPointer(window));

  // ボタン入力情報を生成
  switch (action) {
  case GLFW_PRESS:
    obj->push_buttons_[obj->buttons_page_].insert(std::set<int>::value_type(button));
    obj->press_buttons_.insert(std::set<int>::value_type(button));
    break;

  case GLFW_RELEASE:
    obj->pull_buttons_[obj->buttons_page_].insert(std::set<int>::value_type(button));
    obj->press_buttons_.erase(button);
    break;
  }
    
  double x_pos, y_pos;
  glfwGetCursorPos(obj->window_(), &x_pos, &y_pos);

  // TIPS:位置はmouseMoveCallbackで更新される
#if 0
  obj->mouse_current_pos_ = screenPosition(Vec2f(x_pos, y_pos), obj->current_window_size_);
  // TIPS:Yは上下が逆
  obj->mouse_current_pos_.y() = -obj->mouse_current_pos_.y();
#endif
    
  switch (button) {
  case GLFW_MOUSE_BUTTON_LEFT:
    obj->mouse_left_press_ = (action == GLFW_PRESS) ? true : false;
    obj->mouse_pos_ << x_pos, y_pos;
    break;

  case GLFW_MOUSE_BUTTON_RIGHT:
    obj->mouse_right_press_ = (action == GLFW_PRESS) ? true : false;
    obj->mouse_pos_ << x_pos, y_pos;
    break;
  }
}