コード例 #1
0
ファイル: GlUtils.cpp プロジェクト: Cherum/OculusRiftInAction
void GlUtils::draw3dGrid() {
  using namespace gl;

  GL_CHECK_ERROR;
  static GeometryPtr g;
  if (!g) {
    Mesh m;
    for (int i = 0; i < 5; ++i) {
      float offset = ((float) i * 0.2f) + 0.2f;
      glm::vec3 zOffset(0, 0, offset);
      glm::vec3 xOffset(offset, 0, 0);
      m.addVertex(-X_AXIS + zOffset);
      m.addVertex(X_AXIS + zOffset);
      m.addVertex(-X_AXIS - zOffset);
      m.addVertex(X_AXIS - zOffset);
      m.addVertex(-Z_AXIS + xOffset);
      m.addVertex(Z_AXIS + xOffset);
      m.addVertex(-Z_AXIS - xOffset);
      m.addVertex(Z_AXIS - xOffset);
    }
    m.addVertex(X_AXIS);
    m.addVertex(-X_AXIS);
    m.addVertex(Z_AXIS);
    m.addVertex(-Z_AXIS);
    g = m.getGeometry(GL_LINES);
  }
  ProgramPtr program = getProgram(Resource::SHADERS_SIMPLE_VS, Resource::SHADERS_COLORED_FS);
  GL_CHECK_ERROR;
  program->use();
  GL_CHECK_ERROR;
  program->setUniform("Color", glm::vec4(Colors::gray,1));
  GL_CHECK_ERROR;
  renderGeometry(g, program);
  GL_CHECK_ERROR;
}
コード例 #2
0
ファイル: GlUtils.cpp プロジェクト: Cherum/OculusRiftInAction
void GlUtils::renderBunny() {
  static GeometryPtr bunnyGeometry =
      getMesh(Resource::MESHES_BUNNY2_CTM).getGeometry();
  ProgramPtr program = GlUtils::getProgram(
      Resource::SHADERS_LITCOLORED_VS,
      Resource::SHADERS_LITCOLORED_FS);
  program->use();
  program->setUniform("Color", glm::vec4(1));
  renderGeometry(bunnyGeometry, program);
}
コード例 #3
0
ファイル: GlUtils.cpp プロジェクト: Cherum/OculusRiftInAction
void GlUtils::draw3dVector(glm::vec3 vec, const glm::vec3 & col) {
  Mesh m;
  m.color = Colors::gray;

  m.addVertex(glm::vec3());
  m.addVertex(glm::vec3(vec.x, 0, vec.z));

  m.addVertex(glm::vec3(vec.x, 0, vec.z));
  m.addVertex(vec);

  m.fillColors(true);
  m.color = col;
  m.addVertex(vec);
  m.addVertex(glm::vec3());

  m.fillColors();
  static GeometryPtr g = m.getGeometry(GL_LINES);
  g->updateVertices(m.buildVertices());

  ProgramPtr program = getProgram(
      Resource::SHADERS_COLORED_VS,
      Resource::SHADERS_COLORED_FS);
  program->use();
  renderGeometry(g, program);
  gl::Program::clear();


//  lineWidth(1.0f);
//  float len = glm::length(vec);
//  if (len > 1.0f) {
//    vec /= len;
//  }
//  gl::Program::clear();
//
//  glLineWidth(2.0f + len);
//  glBegin(GL_LINES);
//  gl::color(col);
//  gl::vertex();
//  gl::vertex();
//  glEnd();
//
//  glLineWidth(1.0f);
//  glBegin(GL_LINE_STRIP);
//  gl::color(Colors::gray);
//  gl::vertex(glm::vec3());
//  gl::vertex(glm::vec3(vec.x, 0, vec.z));
//  gl::vertex(vec);
//  glEnd();
}
コード例 #4
0
ファイル: GlUtils.cpp プロジェクト: Kittnz/OculusRiftInAction
void GlUtils::drawAngleTicks() {
  using namespace gl;
  static GeometryPtr g;
  if (!g) {
    float offsets[] = { //
      (float) tan( PI / 6.0f), // 30 degrees
      (float) tan( PI / 4.0f), // 45 degrees
      (float) tan( PI / 3.0f) // 60 degrees
    };
    Mesh m;
    // 43.9 degrees puts tick on the inner edge of the screen
    // 42.6 degrees is the effective fov for wide screen
    // 43.9 degrees puts tick on the inner edge of the screen
    m.addVertex(glm::vec3(-2, 0, 0));
    m.addVertex(glm::vec3(2, 0, 0));
    m.addVertex(glm::vec3(0, -2, 0));
    m.addVertex(glm::vec3(0, 2, 0));
    // By keeping the camera locked at 1 unit away from the origin, all our
    // distances can be computed as tan(angle)
    for (float offset : offsets) {
      m.addVertex(glm::vec3(offset, -0.05, 0));
      m.addVertex(glm::vec3(offset, 0.05, 0));
      m.addVertex(glm::vec3(-offset, -0.05, 0));
      m.addVertex(glm::vec3(-offset, 0.05, 0));
    }
    for (float offset : offsets) {
      m.addVertex(glm::vec3(-0.05, offset, 0));
      m.addVertex(glm::vec3(0.05, offset, 0));
      m.addVertex(glm::vec3(-0.05, -offset, 0));
      m.addVertex(glm::vec3(0.05, -offset, 0));
    }
    g = m.getGeometry(GL_LINES);
  }

  // Fix the modelview at exactly 1 unit away from the origin, no rotation
  gl::Stacks::modelview().push(glm::mat4(1)).translate(glm::vec3(0, 0, -1));
  ProgramPtr program = getProgram(Resource::SHADERS_SIMPLE_VS, Resource::SHADERS_COLORED_FS);
  program->use();
  renderGeometry(g, program);
  gl::Stacks::modelview().pop();
}
コード例 #5
0
ファイル: GlUtils.cpp プロジェクト: Cherum/OculusRiftInAction
void GlUtils::renderArtificialHorizon(float alpha) {
  static GeometryPtr geometry;
  if (!geometry) {
    Mesh mesh;
    MatrixStack & m = mesh.getModel();

    m.push();
    {
      m.top() = glm::translate(glm::mat4(), glm::vec3(0, 0, 1.01));
      mesh.getColor() = Colors::yellow;
      mesh.addQuad(0.5, 0.05f);
      mesh.fillColors(true);
      mesh.getColor() = Colors::lightGray;
      glm::vec2 bar(0.5, 0.025);
      glm::vec2 smallBar(0.3, 0.015);
      for (int i = 1; i <= 4; ++i) {
        float angle = i * (TAU / 18.0f);
        m.identity().rotate(angle, GlUtils::X_AXIS).translate(
            GlUtils::Z_AXIS);
        mesh.addQuad(bar);
        m.identity().rotate(HALF_TAU, GlUtils::Y_AXIS).rotate(angle,
            GlUtils::X_AXIS).translate(GlUtils::Z_AXIS);
        mesh.addQuad(bar);
        m.identity().rotate(HALF_TAU, GlUtils::Z_AXIS).rotate(angle,
            GlUtils::X_AXIS).translate(GlUtils::Z_AXIS);
        mesh.addQuad(bar);
        m.identity().rotate(HALF_TAU, GlUtils::Z_AXIS).rotate(HALF_TAU,
            GlUtils::Y_AXIS).rotate(angle, GlUtils::X_AXIS).translate(
            GlUtils::Z_AXIS);
        mesh.addQuad(bar);

        angle -= (TAU / 36.0f);
        m.identity().rotate(angle, GlUtils::X_AXIS).translate(
            GlUtils::Z_AXIS);
        mesh.addQuad(smallBar);
        m.identity().rotate(HALF_TAU, GlUtils::Y_AXIS).rotate(angle,
            GlUtils::X_AXIS).translate(GlUtils::Z_AXIS);
        mesh.addQuad(smallBar);
        m.identity().rotate(HALF_TAU, GlUtils::Z_AXIS).rotate(angle,
            GlUtils::X_AXIS).translate(GlUtils::Z_AXIS);
        mesh.addQuad(smallBar);
        m.identity().rotate(HALF_TAU, GlUtils::Z_AXIS).rotate(HALF_TAU,
            GlUtils::Y_AXIS).rotate(angle, GlUtils::X_AXIS).translate(
            GlUtils::Z_AXIS);
        mesh.addQuad(smallBar);
      }
    }
    m.pop();
    mesh.fillNormals(true);

    const Mesh & hemi = getMesh(Resource::MESHES_HEMI_CTM);
    m.top() = glm::rotate(glm::mat4(), -QUARTER_TAU, GlUtils::X_AXIS);
    mesh.getColor() = Colors::cyan;
    mesh.addMesh(hemi, true);

    m.top() = glm::rotate(glm::mat4(), QUARTER_TAU, GlUtils::X_AXIS);
    mesh.getColor() = Colors::orange;
    mesh.addMesh(hemi);
    {
      set<int> poleIndices;
      for (size_t i = 0; i < mesh.positions.size(); ++i) {
        const glm::vec4 & v = mesh.positions[i];
        if (abs(v.x) < EPSILON && abs(v.z) < EPSILON) {
          poleIndices.insert(i);
        }
      }
      for (size_t i = 0; i < mesh.indices.size(); i += 3) {
        bool black = false;
        for (size_t j = i; j < i + 3; ++j) {
          if (poleIndices.count(mesh.indices[j])) {
            black = true;
            break;
          }
        }
        if (black) {
          for (size_t j = i; j < i + 3; ++j) {
            mesh.colors[mesh.indices[j]] = Colors::grey;
          }
        }
      }
    }
    geometry = mesh.getGeometry();
  }
  ProgramPtr program = getProgram(
      Resource::SHADERS_LITCOLORED_VS,
      Resource::SHADERS_LITCOLORED_FS);
  program->use();
  program->setUniform("ForceAlpha", alpha);
  renderGeometry(geometry, program);
}