Exemple #1
0
void pixel_drawSquareWaveAlongAxis(AccelStepper *longAxis, AccelStepper *wideAxis, int waveAmplitude, int waveLength, int totalWaves, int waveNo)
{
    if (waveNo == 0)
    {
        // first one, half a line and an along
        //Serial.println(F("First wave half"));
        if (lastWaveWasTop) {
            moveAxis(wideAxis, waveAmplitude/2);
            moveAxis(longAxis, waveLength);
        }
        else {
            moveAxis(wideAxis, 0-(waveAmplitude/2));
            moveAxis(longAxis, waveLength);
        }
        pixel_flipWaveDirection();
    }
    else if (waveNo == totalWaves)
    {
        // last one, half a line with no along
        if (lastWaveWasTop) {
            moveAxis(wideAxis, waveAmplitude/2);
        }
        else {
            moveAxis(wideAxis, 0-(waveAmplitude/2));
        }
    }
    else
    {
        // intervening lines - full lines, and an along
        if (lastWaveWasTop) {
            moveAxis(wideAxis, waveAmplitude);
            moveAxis(longAxis, waveLength);
        }
        else {
            moveAxis(wideAxis, 0-waveAmplitude);
            moveAxis(longAxis, waveLength);
        }
        pixel_flipWaveDirection();
    }
}
void InteractiveMarkerControl::handleMouseMovement( ViewportMouseEvent& event )
{
  // handle mouse movement
  float width = event.viewport->getActualWidth() - 1;
  float height = event.viewport->getActualHeight() - 1;

  Ogre::Ray mouse_ray = event.viewport->getCamera()->getCameraToViewportRay( (event.x + .5) / width,
                                                                             (event.y + .5) / height );

  Ogre::Ray last_mouse_ray =
    event.viewport->getCamera()->getCameraToViewportRay(
      (event.last_x + .5) / width, (event.last_y + .5) / height);

  //convert rays into reference frame
  mouse_ray.setOrigin( reference_node_->convertWorldToLocalPosition( mouse_ray.getOrigin() ) );
  mouse_ray.setDirection( reference_node_->convertWorldToLocalOrientation( Ogre::Quaternion::IDENTITY ) * mouse_ray.getDirection() );

  last_mouse_ray.setOrigin( reference_node_->convertWorldToLocalPosition( last_mouse_ray.getOrigin() ) );
  last_mouse_ray.setDirection( reference_node_->convertWorldToLocalOrientation( Ogre::Quaternion::IDENTITY ) * last_mouse_ray.getDirection() );

  switch (interaction_mode_)
  {
  case visualization_msgs::InteractiveMarkerControl::MOVE_AXIS:
    moveAxis( mouse_ray, event );
    break;

  case visualization_msgs::InteractiveMarkerControl::MOVE_PLANE:
    movePlane( mouse_ray );
    break;

  case visualization_msgs::InteractiveMarkerControl::MOVE_ROTATE:
    moveRotate( mouse_ray );
    break;

  case visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS:
    rotate(mouse_ray);
    break;

  default:
    break;
  }
}
Exemple #3
0
void
ClipGrabber::mouseMoveEvent(QMouseEvent* const event,
			    Camera* const camera)
{
  if (!m_pressed)
    return;
  
  QPoint delta = event->pos() - m_prevPos;

  Vec voxelScaling = Global::voxelScaling();

  Vec tang = m_tang;
  Vec xaxis = m_xaxis;
  Vec yaxis = m_yaxis;
  tang = Matrix::rotateVec(m_xform, tang);
  xaxis = Matrix::rotateVec(m_xform, xaxis);
  yaxis = Matrix::rotateVec(m_xform, yaxis);

  if (event->buttons() != Qt::LeftButton)
    {
      tang = VECDIVIDE(tang, voxelScaling);
      xaxis = VECDIVIDE(xaxis, voxelScaling);
      yaxis = VECDIVIDE(yaxis, voxelScaling);

      Vec trans(delta.x(), -delta.y(), 0.0f);
      
      // Scale to fit the screen mouse displacement
      trans *= 2.0 * tan(camera->fieldOfView()/2.0) *
	             fabs((camera->frame()->coordinatesOf(Vec(0,0,0))).z) /
	             camera->screenHeight();

      // Transform to world coordinate system.
      trans = camera->frame()->orientation().rotate(trans);

      Vec voxelScaling = Global::voxelScaling();
      trans = VECDIVIDE(trans, voxelScaling);

      if (event->modifiers() & Qt::ControlModifier ||
	  event->modifiers() & Qt::MetaModifier)
	{
	  if (moveAxis() < MoveY0)
	    {
	      float vx = trans*m_xaxis;
	      if (moveAxis() == MoveX0)
		setScale1(scale1() + 0.05*vx);
	      else
		setScale1(scale1() - 0.05*vx);
	    }
	  else if (moveAxis() < MoveZ)
	    {
	      float vy = trans*m_yaxis;
	      if (moveAxis() == MoveY0)
		setScale2(scale2() + 0.05*vy);
	      else
		setScale2(scale2() - 0.05*vy);
	    }
	}
      else
	{
	  if (moveAxis() < MoveY0)
	    {
	      float vx = trans*xaxis;
	      trans = vx*xaxis;
	    }
	  else if (moveAxis() < MoveZ)
	    {
	      float vy = trans*yaxis;
	      trans = vy*yaxis;
	    }
	  else if (moveAxis() == MoveZ)
	    {
	      float vz = trans*tang;
	      trans = vz*tang;
	    }
	  
	  translate(trans);
	}
    }
  else
    {
      Vec axis;
      if (moveAxis() < MoveY0) axis = xaxis;
      else if (moveAxis() < MoveZ) axis = yaxis;
      else if (moveAxis() == MoveZ) axis = tang;

      Vec voxelScaling = Global::voxelScaling();
      Vec pos = VECPRODUCT(position(), voxelScaling);
      pos = Matrix::xformVec(m_xform, pos);

      float r = size();
      Vec trans(delta.x(), -delta.y(), 0.0f);

      Vec p0 = camera->projectedCoordinatesOf(pos); p0 = Vec(p0.x, p0.y, 0);
      Vec c0 = pos + r*axis;
      c0 = camera->projectedCoordinatesOf(c0); c0 = Vec(c0.x, c0.y, 0);
      Vec perp = c0-p0;
      perp = Vec(-perp.y, perp.x, 0);
      perp.normalize();

      float angle = perp * trans;
      rotate(axis, angle);
    }

  m_prevPos = event->pos();
}
void Sim::move() {
	ball->move();
	moveAxis();
}