Exemple #1
0
void Editor::update(){
  Vector2D pos = Input::Mouse::instance()->getMousePos();

  //Translation
  if (Input::Mouse::instance()->isPressed(MB_MIDDLE)){
    Vector3D dir = Vector3D(0,0,-1);
    float length = (pos.y-lastPos_.y)*TRANSLATION_SPEED;
    lastPos_ = pos;
    Matrix trans = Matrix(Matrix::Translation, dir*length);
    Graphic::instance()->getCam().multCamTrafo(trans);
  }
  
  //Rotation
  bool active = Input::Mouse::instance()->isPressed(MB_RIGHT);
  arcball_->update(active,false,pos);
  //Graphic::instance()->setCamRotation(arcball_->getTrafo());
  Graphic::instance()->getCam().multCamTrafo(arcball_->getIncTrafo());
}
Exemple #2
0
void Editor::_keypress(int key){
  if (key == KEY_ESCAPE)
    EXIT();
  if (key == KEY_C){
    Model* mdl = Graphic::instance()->getCurrModel();
    if (!mdl)
      return;
    Model* copy = new Model(*mdl);
    Graphic::instance()->getScene().addModel(copy);
  }
  if (key == KEY_R)
    editMode_ = Rotation;
  if (key == KEY_T)
    editMode_ = Translation;
    //arcball_->update(false,true,Vector2D());
  if (key == KEY_UP){
    Model* mdl = Graphic::instance()->getCurrModel();
    if (!mdl)
      return;
    Matrix oldMat = mdl->getTrafo();
    if (editMode_ == Translation){
      Vector3D translation;
      if (editPlane_ == XZ)
        translation = Vector3D(0,0,-gridStep_);
      else if (editPlane_ == XY)
        translation = Vector3D(0,gridStep_,0);
      else if (editPlane_ == YZ)
        translation = Vector3D(0,gridStep_,0);
      Matrix newMat = Matrix(Matrix::Translation, translation);
      mdl->setTrafo(newMat*oldMat);
    }
    else if (editMode_ == Rotation){
      Matrix newMat;
      if (editPlane_ == XZ)
        newMat = Matrix(Matrix::Rotation, Vector3D(0,1,0), rotationStep_);
      else if (editPlane_ == XY)
        newMat = Matrix(Matrix::Rotation, Vector3D(0,0,1), rotationStep_);
      else if (editPlane_ == YZ)
        newMat = Matrix(Matrix::Rotation, Vector3D(1,0,0), rotationStep_);
      mdl->setTrafo(oldMat*newMat);
    }
  }
  if (key == KEY_DOWN){
    Model* mdl = Graphic::instance()->getCurrModel();
    if (!mdl)
      return;
    Matrix oldMat = mdl->getTrafo();
    if (editMode_ == Translation){
      Vector3D translation;
      if (editPlane_ == XZ)
        translation = Vector3D(0,0,gridStep_);
      else if (editPlane_ == XY)
        translation = Vector3D(0,-gridStep_,0);
      else if (editPlane_ == YZ)
        translation = Vector3D(0,-gridStep_,0);
      Matrix newMat = Matrix(Matrix::Translation, translation);
      mdl->setTrafo(newMat*oldMat);
    }
    else if (editMode_ == Rotation){
      Matrix newMat;
      if (editPlane_ == XZ)
        newMat = Matrix(Matrix::Rotation, Vector3D(0,1,0), -rotationStep_);
      else if (editPlane_ == XY)
        newMat = Matrix(Matrix::Rotation, Vector3D(0,0,1), -rotationStep_);
      else if (editPlane_ == YZ)
        newMat = Matrix(Matrix::Rotation, Vector3D(1,0,0), -rotationStep_);
      mdl->setTrafo(oldMat*newMat);
    }
  }
  if (key == KEY_LEFT){
    Model* mdl = Graphic::instance()->getCurrModel();
    if (!mdl)
      return;
    Matrix oldMat = mdl->getTrafo();
    if (editMode_ == Translation){
      Vector3D translation;
      if (editPlane_ == XZ)
        translation = Vector3D(-gridStep_,0,0);
      else if (editPlane_ == XY)
        translation = Vector3D(-gridStep_,0,0);
      else if (editPlane_ == YZ)
        translation = Vector3D(0,0,gridStep_);
      Matrix newMat = Matrix(Matrix::Translation, translation);
      mdl->setTrafo(newMat*oldMat);
    }
    else if (editMode_ == Rotation){
      Matrix newMat;
      if (editPlane_ == XZ)
        newMat = Matrix(Matrix::Rotation, Vector3D(0,1,0), rotationStep_);
      else if (editPlane_ == XY)
        newMat = Matrix(Matrix::Rotation, Vector3D(0,0,1), rotationStep_);
      else if (editPlane_ == YZ)
        newMat = Matrix(Matrix::Rotation, Vector3D(1,0,0), rotationStep_);
      mdl->setTrafo(oldMat*newMat);
    }
  }
  if (key == KEY_RIGHT){
    Model* mdl = Graphic::instance()->getCurrModel();
    if (!mdl)
      return;
    Matrix oldMat = mdl->getTrafo();
    Matrix newMat;
    if (editMode_ == Translation){
      Vector3D translation;
      if (editPlane_ == XZ)
        translation = Vector3D(gridStep_,0,0);
      else if (editPlane_ == XY)
        translation = Vector3D(gridStep_,0,0);
      else if (editPlane_ == YZ)
        translation = Vector3D(0,0,-gridStep_);
      Matrix newMat = Matrix(Matrix::Translation, translation);
      mdl->setTrafo(newMat*oldMat);
    }
    else if (editMode_ == Rotation){
      Matrix newMat;
      if (editPlane_ == XZ)
        newMat = Matrix(Matrix::Rotation, Vector3D(0,1,0), -rotationStep_);
      else if (editPlane_ == XY)
        newMat = Matrix(Matrix::Rotation, Vector3D(0,0,1), -rotationStep_);
      else if (editPlane_ == YZ)
        newMat = Matrix(Matrix::Rotation, Vector3D(1,0,0), -rotationStep_);
      mdl->setTrafo(oldMat*newMat);
    }
  }
  if (key == KEY_DELETE){
    Model* mdl = Graphic::instance()->getCurrModel();
    if (!mdl)
      return;
    Graphic::instance()->getScene().deleteModel(mdl->getID());
  }
}