Пример #1
0
//! the assign texture button
void Menu::assignTexture(Gui::GuiElement* elem){
  //Dialog
  Dialog* dia = new Dialog();
  //Textures
  ListBox* lb = new ListBox();
  lb->setPosition(Vector2D(50, 100));
  lb->setSpan(Vector2D(400,600));
  vector<Texture*> textures = Graphic::instance()->getScene().getTextures();
  for (unsigned i = 0; i < textures.size(); i++){
    lb->addEntry(textures[i]->getName());
  }
  dia->addElement(lb);
  //Texture stages
  DropDownButton* stages = new DropDownButton();
  stages->setPosition(Vector2D(500, 680));
  dia->addUnscaledElement(stages);
  stages->calcDDPos(1);
  stages->setText("Stage 0");
  stages->addEntry("Stage 0");
  stages->addEntry("Stage 1");
  stages->addEntry("Stage 2");
  stages->addEntry("Stage 3");
  stages->addEntry("Stage 4");
  stages->addEntry("Stage 5");
  stages->addEntry("Stage 6");
  stages->addEntry("Stage 7");
  //OK button
  PDButton* ok = new PDButton();
  ok->setPosition(Vector2D(575, 50));
  ok->setSpan(Vector2D(75,18));
  ok->setText("  OK");
  ok->setCbFunc(assignTextureDialog);
  dia->addUnscaledElement(ok);
  CGE::Engine::instance()->addGuiListener(dia);
}
Пример #2
0
Editor::Editor(){
  arcball_ = new CGE::Arcball();
  lastPos_ = Vector2D();
  gridStep_ = 8;
  gridOffset_ = 4;
  rotationStep_ = (float)M_PI/2.0f;
  editPlane_ = XZ;
  editMode_ = Translation;
  std::string path = Filesystem::getCwd();
  std::cerr << path;
  std::ifstream in((path+"/data/attributes.dat").c_str());
  assert(in);
  std::string attrib;
  char buffer[1024];
  while(in >> attrib){
    if (attrib[0] == '#'){
      in.getline(buffer, 1024);
      continue;
    }
    int value;
    in >> value;
    aTov_[attrib] = value;
    vToa_[value] = attrib;
  }
}
Пример #3
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());
}
Пример #4
0
//! Constructor
ListBox::ListBox(){
  type_ = ListBoxT;
  pos_ = Vector2D(112, 84);
  span_ = Vector2D(800,600);
  bgColor_ = Color(0.0,0.0,0.0,0.8f);
  selected_ = -1;
  selColor_ = Vector3D(0.0,1.0,0.0);
  handleClicks_ = NULL;
  scroll_ = 0;
}
Пример #5
0
//! The add model callback
void Menu::addModel(Gui::GuiElement* elem){
  //Dialog
  Dialog* dia = new Dialog();
  //Meshes
  ListBox* lb = new ListBox();
  lb->setPosition(Vector2D(50, 100));
  lb->setSpan(Vector2D(400,600));
  vector<Mesh*> meshes = Graphic::instance()->getScene().getMeshes();
  for (unsigned i = 0; i < meshes.size(); i++){
    lb->addEntry(meshes[i]->getName());
  }
  dia->addElement(lb);
  //OK button
  PDButton* ok = new PDButton();
  ok->setPosition(Vector2D(575, 50));
  ok->setSpan(Vector2D(75,18));
  ok->setText("  OK");
  ok->setCbFunc(setModel);
  dia->addUnscaledElement(ok);
  CGE::Engine::instance()->addGuiListener(dia);
}
Пример #6
0
void Menu::options(Gui::GuiElement* elem){
  //Dialog
  Dialog* dia = new Dialog();
  CGE::Engine::instance()->addGuiListener(dia);

  //The plane chooser
  DropDownButton* planes = new DropDownButton();
  planes->setPosition(Vector2D(20, 680));
  dia->addUnscaledElement(planes);
  planes->calcDDPos(1);
  Editor::Plane plane = Editor::instance()->getEditPlane();
  string label;
  if (plane == Editor::XZ)
    label = "XZ Plane";
  else if (plane == Editor::XY)
    label = "XY Plane";
  else if (plane == Editor::YZ)
    label = "YZ Plane";
  planes->setText(label);
  planes->addEntry("XZ Plane");
  planes->addEntry("XY Plane");
  planes->addEntry("YZ Plane");

  //The translation step
  InputField* input = new InputField();
  input->setPosition(Vector2D(20, 650));
  float step = Editor::instance()->getGridStep();
  input->setText(toStr(step));
  dia->addUnscaledElement(input);

  //OK button
  PDButton* ok = new PDButton();
  ok->setPosition(Vector2D(575, 50));
  ok->setSpan(Vector2D(75,18));
  ok->setText("  OK");
  ok->setCbFunc(changeOptions);
  dia->addUnscaledElement(ok);
}
Пример #7
0
std::vector<double> CanonicalAverager::calculate_weights(const std::vector<double> &energies, const CGE &cge, double beta) {
    // Assume that the CGE only has one dimension (which is the only thing implemented at the moment)
    assert(cge.get_ge().get_current_histogram().get_shape().size() == 1);
    return calculate_weights(energies, cge.get_binner(), cge.get_ge().get_estimate().get_lnG(), cge.get_ge().get_estimate().get_lnG_support(), beta);
}
Пример #8
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());
  }
}
Пример #9
0
//! load the scene
void Scene::load(const std::string& filename){
  TR_USE(CGE_Scene);
  ifstream in(filename.c_str(), ios::binary);
  if (!in)
    return;
  std::string cwd = CGE::Filesystem::getCwd();
  cwd += "\\";
  char buffer[256];
  //version
  in.read((char*)&version_, sizeof(version_));
  //read and rebuild meshes
  unsigned size;
  in.read((char*)&size, sizeof(size));
  for (unsigned i = 0; i < size; i++){
    unsigned length;
    in.read((char*)&length, sizeof(length));
    in.read(buffer, length*sizeof(char));
    buffer[length] = '\0';
    string name = string(buffer);
#ifdef UNIX
    Utilities::replaceWith(name, '\\', '/');
#endif
    Mesh* msh = new Mesh();
    if (!msh->loadFromFile(cwd+name)){
      TR_ERROR("cannot load file %s", filename.c_str());
      return;
    }
    buffer[length] = -52;
    msh->buildVBO();
    meshes_.push_back(msh);
  }
  //read and rebuild textures
  in.read((char*)&size, sizeof(size));
  for (unsigned i = 0; i < size; i++){
    unsigned length;
    in.read((char*)&length, sizeof(length));
    //CGE::Log << in.bad() << " " << in.eof();
    in.read(buffer, length*sizeof(char));
    buffer[length] = '\0';
    string name = string(buffer);
#ifdef UNIX
    Utilities::replaceWith(name, '\\', '/');
#endif
    Texture* tex = Texture::create(cwd+name);
    textures_.push_back(tex);
  }
  //read lights
  in.read((char*)&size, sizeof(size));
  for (unsigned i = 0; i < size; ++i){
    char type;
    in.read(&type, 1);
    Vec4f pos;
    in.read((char*)pos.data, 4 * sizeof(float));
    Light* lt = new Light((Light::Type)type, pos);
    Vec3f dir;
    in.read((char*)dir.data, 3 * sizeof(float));
    lt->setDirection(dir);
    float flt;
    in.read((char*)&flt, sizeof(float));
    lt->setCutoff(flt);
    Color c;
    in.read((char*)c.array, 4 * sizeof(float));
    lt->setColor(c);
    in.read((char*)&flt, sizeof(float));
    lt->setAttenuation(flt);
    mLights.push_back(lt);
  }
  //read models
  in.read((char*)&size, sizeof(size));
  for (unsigned i = 0; i < size; i++){
    //model id
    unsigned id;
    in.read((char*)&id, sizeof(id));
    CGE::SceneNode::setIDCount(max(id+1, CGE::SceneNode::getIDCount()));
    //mesh link
    unsigned idx;
    in.read((char*)&idx, sizeof(idx));
    Mesh* msh = meshes_[idx];
    Model* mdl = new Model(msh);
    mdl->setID(id);
    mNodes.push_back(mdl);
    //texture links
    for (int i = 0; i < MAX_TEXTURES; i++){
      in.read((char*)&idx, sizeof(idx));
      if (idx != UINT_MAX){
        Texture* tex = textures_[idx];
        mdl->assignTexture(tex,i);
      }
    }
    //trafo
    float mat[16];
    in.read((char*)mat, 16*sizeof(float));
    mdl->setTrafo(Matrix(mat));
    //attributes
    for (int i = 0; i < MAX_ATTRIBS; i++){
      int attrib;
      in.read((char*)&attrib, sizeof(attrib));
      mdl->setAttrib(i, attrib);
    }
  }
  in.close();
}
Пример #10
0
//! the model properties callback
void Menu::properties(Gui::GuiElement* elem){
  //Dialog
  Dialog* dia = new Dialog();
  CGE::Engine::instance()->addGuiListener(dia);
  //Assign texture button
  PDButton* assTex = new PDButton();
  assTex->setPosition(Vector2D(20, 730));
  assTex->setText("Assign Texture");
  assTex->setCbFunc(assignTexture);
  dia->addUnscaledElement(assTex);

  Model* mdl = Graphic::instance()->getCurrModel();
  
  //Attributes
  InputField* in = new InputField();
  in->setPosition(Vector2D(20, 690));
  if (!mdl)
    in->setText("-1");
  else
    in->setText(Editor::instance()->attribString(mdl->getAttrib(0)));
  dia->addUnscaledElement(in);
  
  in = new InputField();
  in->setPosition(Vector2D(20, 660));
  if (!mdl)
    in->setText("-1");
  else
    in->setText(Editor::instance()->attribString(mdl->getAttrib(1)));
  dia->addUnscaledElement(in);

  in = new InputField();
  in->setPosition(Vector2D(20, 630));
  if (!mdl)
    in->setText("-1");
  else
    in->setText(Editor::instance()->attribString(mdl->getAttrib(2)));
  dia->addUnscaledElement(in);

  in = new InputField();
  in->setPosition(Vector2D(20, 600));
  if (!mdl)
    in->setText("-1");
  else
    in->setText(Editor::instance()->attribString(mdl->getAttrib(3)));
  dia->addUnscaledElement(in);

  in = new InputField();
  in->setPosition(Vector2D(20, 570));
  if (!mdl)
    in->setText("-1");
  else
    in->setText(Editor::instance()->attribString(mdl->getAttrib(4)));
  dia->addUnscaledElement(in);

  in = new InputField();
  in->setPosition(Vector2D(20, 540));
  if (!mdl)
    in->setText("-1");
  else
    in->setText(Editor::instance()->attribString(mdl->getAttrib(5)));
  dia->addUnscaledElement(in);

  in = new InputField();
  in->setPosition(Vector2D(20, 510));
  if (!mdl)
    in->setText("-1");
  else
    in->setText(Editor::instance()->attribString(mdl->getAttrib(6)));
  dia->addUnscaledElement(in);

  in = new InputField();
  in->setPosition(Vector2D(20, 480));
  if (!mdl)
    in->setText("-1");
  else
    in->setText(Editor::instance()->attribString(mdl->getAttrib(7)));
  dia->addUnscaledElement(in);
  
  //Close button
  PDButton* close = new PDButton();
  close->setPosition(Vector2D(575, 50));
  close->setSpan(Vector2D(75,18));
  close->setText(" Close");
  close->setCbFunc(evaluateAttribs);
  dia->addUnscaledElement(close);
}