コード例 #1
0
void NGLScene::locators()
{
    ngl::VAOPrimitives* drawPrimitives = ngl::VAOPrimitives::instance();
    ngl::ShaderLib *shader=ngl::ShaderLib::instance();
    (*shader)["Phong"]->use();

    m_track.LeftTracker.m_x = ((320 - m_track.LeftTracker.m_x)/320)*5.f;
    m_track.LeftTracker.m_y = ((240 - m_track.LeftTracker.m_y)/240)*5.f;
    m_track.LeftTracker.m_z = (m_track.LeftTracker.m_z/10000)*5.f;

    m_transform.reset();
    {
        m_transform.setPosition(m_track.LeftTracker);
        loadMatricesToShader();
        drawPrimitives->draw("teapot");
    }

    m_track.RightTracker.m_x = ((320 - m_track.RightTracker.m_x)/320)*5.f;
    m_track.RightTracker.m_y = ((240 - m_track.RightTracker.m_y)/240)*5.f;
    m_track.RightTracker.m_z = (m_track.RightTracker.m_z/10000)*5.f;

    m_transform.reset();
    {
        m_transform.setPosition(m_track.RightTracker);
        loadMatricesToShader();
        drawPrimitives->draw("cube");
    }
}
コード例 #2
0
ファイル: GLWindow.cpp プロジェクト: burakertekin/ClothSim
void GLWindow::paintGL()
{
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["PhongShader"]->use();

  // clear the screen and depth buffer
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      // Rotation based on the mouse position for our global
      // transform
      ngl::Mat4 rotX;
      ngl::Mat4 rotY;
      // create the rotation matrices
      rotX.rotateX(m_spinXFace);
      rotY.rotateY(m_spinYFace);
      // multiply the rotations
      m_mouseGlobalTX=rotY*rotX;
      // add the translations
      m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
      m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
      m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;

      //material setting for the cloth
      shader->setShaderParam3f("material.Ka",0.05,0.05,0.05);
      shader->setShaderParam3f("material.Kd",0.0,0.1,1.0);
      shader->setShaderParam3f("material.Ks",0.01,0.01,0.01);
      shader->setShaderParam1f("material.shininess",100);

      //draw the cloth
      m_transform.reset();
      {
        loadMatricesToShader();
        m_triangleObj->bind();
        m_triangleObj->draw();
        m_triangleObj->unbind();
      }

      //if the collision detection checkbox is checked
      //draw the sphere
      if(myCloth.makeCollide)
        {
          //material setting for the sphere
          shader->setShaderParam3f("material.Ka",0.1,0.1,0.1);
          shader->setShaderParam3f("material.Kd",0.9,0.1,0.1);
          shader->setShaderParam3f("material.Ks",0.8,0.8,0.8);
          shader->setShaderParam1f("material.shininess",100);

          m_transform.reset();
          {
            m_sphere = ngl::VAOPrimitives::instance();
            m_sphere->createSphere("sphere", myCloth.m_sphereRad, 30);
            m_transform.setPosition(myCloth.m_spherePos.m_x, myCloth.m_spherePos.m_y, myCloth.m_spherePos.m_z);
            loadMatricesToShader();
            m_sphere->draw("sphere");
          }
        }
}
コード例 #3
0
ファイル: NGLScene.cpp プロジェクト: NCCA/NGL6Demos
void NGLScene::side(MODE _m)
{
  m_mouseGlobalTX.identity();
  // grab an instance of the shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["nglDiffuseShader"]->use();

  int win=FULLOFFSET;
  if(_m == PANEL)
  {
    win=SIDE;
  }

   // get the VBO instance and draw the built in teapot
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();

  // first draw a top  persp // front //side
  ngl::Vec3 from(0,2,0);
  ngl::Vec3 to(0,0,0);
  ngl::Vec3 up(0,0,-1);
  /// a side view (bottom right)
  m_transformStack.pushTransform();
  {
    from.set(2,0,0);
    up.set(0,1,0);
    m_view=ngl::lookAt(from,to,up);
    m_projection=ngl::ortho(-1,1,-1,1, 0.1f, 100.0f);
    // x,y w/h
    if(_m==PANEL)
    {
      glViewport (m_width/2, 0, m_width/2, m_height/2);
    }
    else
    {
      glViewport(0,0,m_width,m_height);
    }

    // draw
    ngl::Vec3 p=m_panelMouseInfo[win].m_modelPos;

    m_transformStack.setPosition(0,p.m_y,-p.m_x);
    m_transformStack.setScale(p.m_z,p.m_z,p.m_z);


    loadMatricesToShader();
    prim->draw("troll");
    m_transformStack.setRotation(90,90,0);
    m_transformStack.addPosition(0,0,2);
    loadMatricesToShader();
    prim->draw("grid");
  }
  m_transformStack.popTransform();



}
コード例 #4
0
ファイル: NGLDraw.cpp プロジェクト: luisfos/CA1-Remake
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
void NGLDraw::draw()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // now to load the shader and set the values
  // grab an instance of shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["Phong"]->use();

  //compute rotations for X and Y mouse movement
  rotX.rotateX(m_spinXFace);
  rotY.rotateY(m_spinYFace);
  //rotate camera by total mouse transform
  m_mouseGlobalTX=rotY*rotX;




  //broken timer works on ticks
  timer();



  m_view= m_cam->getViewMatrix();
  m_projection= m_cam->getProjectionMatrix();
  // draw grid
  //m_tx.reset();
  shader->setShaderParam4f("Colour",0.0f,0.0f,0.0f,0.0f);
  loadMatricesToShader();
  ngl::VAOPrimitives::instance()->draw("grid");
  loadMatricesToShader();
  ngl::VAOPrimitives::instance()->draw("teapot");


  // draw bases
  m_base0->draw();
  m_base1->draw();
  // draw each minion in array
  for(int i = 0 ; i<m_minions0.size(); i++)
  {
    m_minions0[i].draw();
  }
  for(int i = 0; i<m_minions1.size(); i++)
  {
    m_minions1[i].draw();
  }


}
コード例 #5
0
//----------------------------------------------------------------------------------------------------------------------
void OpenGLWidget::paintGL(){

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //Initialise the model matrix

    glm::mat4 rotx;
    glm::mat4 roty;

    rotx = glm::rotate(rotx, m_spinXFace, glm::vec3(1.0, 0.0, 0.0));
    roty = glm::rotate(roty, m_spinYFace, glm::vec3(0.0, 1.0, 0.0));

    m_mouseGlobalTX = rotx*roty;
    // add the translations
    m_mouseGlobalTX[3][0] = m_modelPos.x;
    m_mouseGlobalTX[3][1] = m_modelPos.y;
    m_mouseGlobalTX[3][2] = m_modelPos.z;
    m_modelMatrix = m_mouseGlobalTX;

    loadMatricesToShader();

    glBindVertexArray(m_model->getVAO());
    glDrawArrays(GL_TRIANGLES, 0, m_model->getNumVerts());
    glBindVertexArray(0);

}
コード例 #6
0
ファイル: NGLScene.cpp プロジェクト: NCCA/NGL6Demos
void NGLScene::render()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // Rotation based on the mouse position for our global transform
   ngl::Transformation trans;
   ngl::Mat4 rotX;
   ngl::Mat4 rotY;
   // create the rotation matrices
   rotX.rotateX(m_spinXFace);
   rotY.rotateY(m_spinYFace);
   // multiply the rotations
   m_mouseGlobalTX=rotY*rotX;
   // add the translations
   m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
   m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
   m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;

  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();

  (*shader)["normalShader"]->use();
  shader->setShaderParam1f("normalSize",m_normalSize);
  loadMatricesToNormalShader();
  prim->draw(m_modelName);
  glPointSize(4.0);
  glLineWidth(4.0);

  (*shader)["Phong"]->use();

  loadMatricesToShader();
  prim->draw(m_modelName);

}
コード例 #7
0
ファイル: NGLScene.cpp プロジェクト: NCCA/NGL6Demos
void NGLScene::render()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // Rotation based on the mouse position for our global transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_spinXFace);
  rotY.rotateY(m_spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;
  loadMatricesToShader();

  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["nglColourShader"]->use();
  shader->setShaderParam4f("Colour",1,1,1,1);
  m_curve->draw();
  glPointSize(4);
  shader->setShaderParam4f("Colour",0,1,0,1);

  m_curve->drawControlPoints();
  glPointSize(1);
  shader->setShaderParam4f("Colour",1,0,0,1);

  m_curve->drawHull();
}
コード例 #8
0
ファイル: NGLScene.cpp プロジェクト: NCCA/MorphObjTBO
void NGLScene::paintGL()
{
  // clear the screen and depth buffer
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glViewport(0,0,m_win.width,m_win.height);
   // Rotation based on the mouse position for our global transform
   ngl::Mat4 rotX;
   ngl::Mat4 rotY;
   // create the rotation matrices
   rotX.rotateX(m_win.spinXFace);
   rotY.rotateY(m_win.spinYFace);
   // multiply the rotations
   m_mouseGlobalTX=rotY*rotX;
   // add the translations
   m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
   m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
   m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;

  loadMatricesToShader();
  // draw the mesh
  m_vaoMesh->bind();
  glBindTexture(GL_TEXTURE_BUFFER, m_tboID);
  m_vaoMesh->draw();
  m_vaoMesh->unbind();
  m_text->setColour(1.0f,1.0f,1.0f);
  QString text=QString("Q-W change Pose one weight %1").arg(m_weight1);

  m_text->renderText(10,18,text);
  text=QString("A-S change Pose two weight %1").arg(m_weight2);
  m_text->renderText(10,34,text);
  m_text->renderText(10,58,"Z trigger Left Punch X trigger Right");
}
コード例 #9
0
ファイル: NGLScene.cpp プロジェクト: NCCA/NGL6Demos
void NGLScene::render()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // grab an instance of the shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["PointLightDiffuse"]->use();
  // Rotation based on the mouse position for our global transform
  ngl::Transformation trans;
  // Rotation based on the mouse position for our global
  // transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_spinXFace);
  rotY.rotateY(m_spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;
   // get the VBO instance and draw the built in teapot
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();
  // draw
  loadMatricesToShader();
  prim->draw("teapot");
}
コード例 #10
0
ファイル: NGLScene.cpp プロジェクト: NCCA/NGL6Demos
void NGLScene::render()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // Rotation based on the mouse position for our global
  // transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_spinXFace);
  rotY.rotateY(m_spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;
  // set this in the TX stack
  loadMatricesToShader();
  // now we bind back our vertex array object and draw
  m_vaoMesh->bind();
  // draw the VAO
  m_vaoMesh->draw();
  if(m_showNormals == true)
  {
    loadMatricesToNormalShader();
    m_vaoMesh->draw();
  }
  // now we are done so unbind
  m_vaoMesh->unbind();
}
コード例 #11
0
ファイル: NGLScene.cpp プロジェクト: NCCA/TessellationShader
void NGLScene::paintGL()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glViewport(0,0,m_width,m_height);
  // grab an instance of the shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["Tess"]->use();

  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_spinXFace);
  rotY.rotateY(m_spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;
  // set this in the TX stack
  loadMatricesToShader();
  m_vao->bind();
  m_vao->draw();
  m_vao->unbind();

  m_text->setColour(1.0f,1.0f,1.0f);
  QString text=QString("1 2 change inner tesselation level  current value %1").arg(m_innerLevel);
  m_text->renderText(10,18,text);
  text=QString("3 4 change outer tesselation level  current value %1").arg(m_outerLevel);
  m_text->renderText(10,34,text);
}
コード例 #12
0
ファイル: NGLScene.cpp プロジェクト: NikithaAnn/working_code
void NGLScene::setTarget()
{
  //This functions draws a cube at the target position
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["nglDiffuseShader"]->use();

  // Rotation based on the mouse position for our global transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_spinXFace);
  rotY.rotateY(m_spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;

  ngl::Mat4 MVP;

   // get the VBO instance and draw the sphere
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();

  m_transform.setPosition(m_Test.m_target);

  //m_mouseGlobalTX.m_m[3][1] = 3.5;
  MVP=m_transform.getMatrix()*m_mouseGlobalTX*m_cam.getVPMatrix();

  loadMatricesToShader();
  shader->setShaderParamFromMat4("MVP",MVP);

  prim->draw("cube");

}
コード例 #13
0
ファイル: NGLScene.cpp プロジェクト: NikithaAnn/working_code
//This is the function that actually draws on screen
void NGLScene::paintGL()
{

  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glViewport(0,0,m_width,m_height);

  // grab an instance of the shader manager
    ngl::ShaderLib *shader=ngl::ShaderLib::instance();
    (*shader)["Phong"]->use();


  //Text stating what to do
  m_text->setColour(ngl::Colour(0.780392, 0.0823529, 0.521569));
  QString text1=QString("Please left click for target position..");
  m_text->renderText(10,18,text1 );


  //Text stating whERE TARGET IS
  m_text->setColour(ngl::Colour(0.878431 ,1 ,1));
  QString text=QString("Target at position X: %1 Y:%2").arg(m_Test.m_target.m_x).arg(m_Test.m_target.m_y);
  m_text->renderText(10,40,text );

  loadMatricesToShader();
  m_Test.m_mainstructure.drawFile(m_spinXFace,m_spinYFace, m_mouseGlobalTX,m_modelPos, m_cam);

  setTarget();

  if(m_wireframe==true)
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  else
  glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

}
コード例 #14
0
ファイル: Sphere.cpp プロジェクト: NCCA/NGL6Demos
void Sphere::draw( const std::string &_shaderName, ngl::TransformStack &_transformStack, const ngl::Mat4 &_globalTx, ngl::Camera *_cam )const
{

  // draw wireframe if hit
  if(m_hit)
  {
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  }
  else
  {
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  }


  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  shader->use(_shaderName);
  // grab an instance of the primitives for drawing
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();

  _transformStack.pushTransform();
  {

    _transformStack.setPosition(m_pos);
    _transformStack.setScale(m_radius,m_radius,m_radius);
    loadMatricesToShader(_transformStack,_globalTx,_cam);
    prim->draw("sphere");
  } // and before a pop
   _transformStack.popTransform();

glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
}
コード例 #15
0
ファイル: NGLScene.cpp プロジェクト: NCCA/NGL6Demos
void NGLScene::render()
{
  // clear the screen and depth buffer
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   ngl::Mat4 rotX;
   ngl::Mat4 rotY;
   // create the rotation matrices
   rotX.rotateX(m_spinXFace);
   rotY.rotateY(m_spinYFace);
   // multiply the rotations
   m_mouseGlobalTX=rotY*rotX;
   // add the translations
   m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
   m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
   m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;

	ngl::ShaderLib *shader=ngl::ShaderLib::instance();
	(*shader)["TextureShader"]->use();
	loadMatricesToShader();
	// draw the mesh
	m_mesh->draw();
	// draw the mesh bounding box
	(*shader)["nglColourShader"]->use();

  if(m_showBBox==true)
  {
    loadMatricesToShader();
    shader->setShaderParam4f("Colour",0,0,1,1);
    m_mesh->drawBBox();
  }
  if(m_showBSphere==true)
  {
    ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();
    shader->setShaderParam4f("Colour",1,1,1,1);
    m_transformStack.pushTransform();
      glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
        m_transformStack.setPosition(m_mesh->getSphereCenter());
        m_transformStack.setScale(m_mesh->getSphereRadius(),m_mesh->getSphereRadius(),m_mesh->getSphereRadius());
        loadMatricesToShader();
        prim->draw("sphere");
      glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    m_transformStack.popTransform();
  }

  //m_text->renderText(10,18,"P toggle bounding Sphere B Toggle Bounding Box");

}
コード例 #16
0
//----------------------------------------------------------------------------------------------------------------------
void grassHair::draw(glm::mat4 _modelMatrix, Camera *_cam, int _numPoints){
    loadMatricesToShader(_modelMatrix,_cam);

//    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    glBindVertexArray(m_VAO);
    glDrawArrays(GL_TRIANGLES, 0, _numPoints);
    glBindVertexArray(0);
}
コード例 #17
0
//----------------------------------------------------------------------------------------------------------------------
void ImportMesh::draw(ngl::Mat4 _mouseGlobalTX, ngl::Camera *_cam){
    //make our shader active
    ngl::ShaderLib *shader=ngl::ShaderLib::instance();
    (*shader)["DeformationShader"]->use();

    loadMatricesToShader(_mouseGlobalTX,_cam);
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    m_VAO->bind();
    m_VAO->draw();
    m_VAO->unbind();
}
コード例 #18
0
ファイル: nglscene.cpp プロジェクト: yanioaioan/QuadTree
void NGLScene::deleteAreaByAreaElements(QuadTree &tree)
{
    ngl::ShaderLib *shader = ngl::ShaderLib::instance ();
     (*shader)["nglDiffuseShader"]->use();

    if (tree.container.size ()!=0)
    {
        //std::vector<Point> collisionAreaPoints(tree.container);

        ngl::Colour collisionAreaColour(ngl::Random::instance ()->randomPositiveNumber (), ngl::Random::instance ()->randomPositiveNumber (), ngl::Random::instance ()->randomPositiveNumber (), 1);
//        for(int i=0;i<tree.container.size ();i++)
        {

            //clear all tree area elements
//            tree.container.clear ();

            loadMatricesToShader (m_transform,m_mouseGlobalTX, m_cam, collisionAreaColour);
            ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance ();
            prim->draw ("cube");
        }

        update ();

    }
    else
    {
        return;
    }



    //Comment out some of the following quadtree collision regions and PushButton on the Gui, to delete some of the 1st level quatree splits (1 of the 4 first quadrants of the quadtree)
    if (tree.ul!=NULL)
    {
//        tree.ul->container.clear ();
        update ();
    }
    if (tree.ur!=NULL)
    {
//        tree.ur->container.clear ();
        update ();
    }
    if (tree.dl!=NULL)
    {
//        tree.dl->container.clear ();
        update ();
    }
    if (tree.dr!=NULL)
    {
//        tree.dr->container.clear ();
        update ();
    }

}
コード例 #19
0
//----------------------------------------------------------------------------------------------------------------------
void GameWorld::draw(ngl::Camera* _cam, ngl::Mat4 _mouseGlobalTX)
{
    ngl::Material a(ngl::Colour(0.2f,0.2f,0.2f, 1.0), ngl::Colour(0.32f,0.31f,0.3f, 1.), ngl::Colour(0.77391f,0.77391f,0.77391f, 1.0));
    a.setSpecularExponent(20.f);
    a.loadToShader("material");
    loadMatricesToShader(_cam, _mouseGlobalTX);
    m_streetMesh->draw();

    ngl::Material b(ngl::Colour(0.2f,0.2f,0.2f, 1.0), ngl::Colour(0.45f,0.45f,0.45f, 1.), ngl::Colour(0.77391f,0.77391f,0.77391f, 1.0));
    b.setSpecularExponent(20.f);
    b.loadToShader("material");
    loadMatricesToShader(_cam, _mouseGlobalTX);
    m_buildingMesh->draw();

    for(unsigned int a=0; a<m_numberOfObstacles; ++a)
    {
        StaticEntity* currentObstacle = m_obstacles[a];
        currentObstacle->draw(_cam, _mouseGlobalTX);
    }

    for(unsigned int a=0; a<m_numberOfRioters; ++a)
    {
        Rioter* currentRioter = m_rioters[a];
        currentRioter->draw(_cam, _mouseGlobalTX);
    }

    m_numberOfSquads = m_squads.size();

    for(unsigned int a=0; a<m_numberOfSquads; ++a)
    {
        Squad* currentSquad = m_squads[a];
        currentSquad->draw(_cam, _mouseGlobalTX);
        if(currentSquad->getSquadState() == squadMove)
        {
            currentSquad->drawTarget(_cam, _mouseGlobalTX);
        }
    }


}
コード例 #20
0
ファイル: NGLScene.cpp プロジェクト: NCCA/Sponza
void NGLScene::paintGL()
{

  // Rotation based on the mouse position for our global transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_win.spinXFace);
  rotY.rotateY(m_win.spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;

  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glViewport(0,0,m_win.width,m_win.height);
  loadMatricesToShader();
  auto end=m_model->numMeshes();
  std::string matName;
  for(unsigned int i=0; i<end; ++i)
  {
    //m_mtl->use(m_model->getMaterial(i));
    mtlItem *currMaterial=m_mtl->find(m_model->getMaterial(i));
    if(currMaterial == nullptr) continue;
    // see if we need to switch the material or not this saves on OpenGL calls and
    // should speed things up
    if(matName !=m_model->getMaterial(i))
    {
      matName=m_model->getMaterial(i);
      switch(m_whichMap)
      {
        case 0 : glBindTexture (GL_TEXTURE_2D,currMaterial->map_KaId); break;
        case 1 : glBindTexture (GL_TEXTURE_2D,currMaterial->map_KdId); break;
        case 2 : glBindTexture (GL_TEXTURE_2D,currMaterial->map_bumpId); break;
        case 3 : glBindTexture (GL_TEXTURE_2D,currMaterial->bumpId); break;
        case 4 : glBindTexture (GL_TEXTURE_2D,currMaterial->map_dId); break;
      }
      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST_MIPMAP_LINEAR);
      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_LINEAR);
      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
      ngl::ShaderLib *shader=ngl::ShaderLib::instance();
      shader->setUniform("ka",currMaterial->Ka.m_x,currMaterial->Ka.m_y,currMaterial->Ka.m_z);
      shader->setUniform("transp",currMaterial->d);
    }
    m_model->draw(i);

  }
}
コード例 #21
0
//----------------------------------------------------------------------------------------------------------------------
void grassHairClipmap::draw(glm::mat4 _modelMatrix, Camera *_cam, int _numPoints){

    m_shaderProgram->use();
    GLuint mapPosLoc = m_shaderProgram->getUniformLoc("map_position");
    glUniform4f(mapPosLoc, (-m_viewPos.x/float(2*512*32)-4), 0, (-m_viewPos.z/float(2*512*32))-4, 0);

    loadMatricesToShader(_modelMatrix,_cam);

    //update the time
    glUniform1f(m_timeLoc,clock()/1000000.0);
    m_grassTexture->bind(10);
    m_heightmapTex->bind(2);


    float sxy=2; //scale x/y
    for (int i=0; i<3; ++i){
        float ox=(int(m_viewPos.x*(1<<i))&511)/float(512*32);
        float oz=(int(m_viewPos.z*(1<<i))&511)/float(512*32);


        glm::vec3 scale(sxy, sxy, sxy);
        GLuint scaleLoc = m_shaderProgram->getUniformLoc("scale");
        glUniform4f(scaleLoc, scale.x, scale.y, scale.z, 1.0);


        for (int k=-2; k<2; ++k) {
            for (int j=-2; j<2; ++j){

                if (i!=2) if (k==-1 || k==0) if (j==-1||j==0) continue;

                glm::vec3 offset(ox+float(j), 0, oz+float(k));
                if (k>=0) offset.z-=1.0/float(32); //adjust offset for proper overlapping
                if (j>=0) offset.x-=1.0/float(32); // adjust offset for proper overlapping

                // render
                GLuint offsetLoc = m_shaderProgram->getUniformLoc("offset");
                glUniform4f(offsetLoc, offset.x, 0.0, offset.z, 0.0);

                glBindVertexArray(m_VAO);
                glPointSize(20.0);
                glDrawArrays(GL_TRIANGLE_STRIP, 0, _numPoints);
                glBindVertexArray(0);
            }
        }
        sxy*=0.5;
    }
}
コード例 #22
0
ファイル: nglscene.cpp プロジェクト: yanioaioan/QuadTree
//Is used to visualize different levels of the QuadTree But it's not quite working at the moment!
void NGLScene::findTreeElements(QuadTree &tree)
{

    if (tree.container.size ()!=0 /*|| tree.dl!=NULL  || tree.dr!=NULL  || tree.ul!=NULL  || tree.ur!=NULL*/)
    {
        ngl::Colour collisionAreaColour(ngl::Random::instance ()->randomPositiveNumber (), ngl::Random::instance ()->randomPositiveNumber (), ngl::Random::instance ()->randomPositiveNumber (), 1);

        std::vector<Point> collisionAreaPoints(tree.container);

        for(int i=0;i<collisionAreaPoints.size ();i++)
        {
            m_transform.setPosition (collisionAreaPoints[i].x ,collisionAreaPoints[i].y, 0);
            m_transform.setScale (0.015,0.015,0.015);

            loadMatricesToShader (m_transform,m_mouseGlobalTX, m_cam, collisionAreaColour);
            ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance ();
            prim->draw ("cube");

        }



    }
    else
    {
        return;
    }


    if (tree.ul!=NULL)
    {
        findTreeElements(*(tree.ul));
    }
    if (tree.ur!=NULL)
    {
        findTreeElements(*(tree.ur));
    }
    if (tree.dl!=NULL)
    {
        findTreeElements(*(tree.dl));
    }
    if (tree.dr!=NULL)
    {
        findTreeElements(*(tree.dr));
    }

}
コード例 #23
0
ファイル: NGLDraw.cpp プロジェクト: NCCA/webgl
void NGLDraw::draw()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // grab an instance of the shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["Skinning"]->use();

  // Rotation based on the mouse position for our global transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_spinXFace);
  rotY.rotateY(m_spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;
  // set this in the TX stack
  loadMatricesToShader();
  std::vector<ngl::Mat4> transforms;
  if(m_animate)
  {
    static float t=0.0;
    t+=0.1;
    float time=float(SDL_GetTicks()/1000.0)*m_mesh.getDuration()/m_mesh.getTicksPerSec();
    std::cout<<time<<"\n";
    m_mesh.boneTransform(time, transforms);
  }
  else
  {
    m_mesh.boneTransform(m_frameTime, transforms);

  }
  unsigned int size=transforms.size();
  for (unsigned int i = 0 ; i < size ; ++i)
  {
    std::string name=boost::str(boost::format("gBones[%d]") % i );
    shader->setUniform(name.c_str(),transforms[i]);
  }

  m_mesh.render();

}
コード例 #24
0
ファイル: NGLScene.cpp プロジェクト: NCCA/NGL6Demos
void NGLScene::render()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // grab an instance of the shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["PerVertASD"]->use();
  // Rotation based on the mouse position for our global transform
  ngl::Transformation trans;
  // Rotation based on the mouse position for our global
  // transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_spinXFace);
  rotY.rotateY(m_spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;
  // get the VBO instance and draw the built in teapot
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();
  // draw
  loadMatricesToShader();
  prim->draw("teapot");
  // now render the text using the QT renderText helper function
   m_text->setColour(ngl::Colour(1,1,1));
   m_text->renderText(10,18,"Use Arrow Keys to move Light i and o to move in and out");
   m_text->setColour(ngl::Colour(1,1,0));

   QString text=QString("Light Position [%1,%2,%3]")
                       .arg(m_lightPosition.m_x,4,'f',1,'0')
                       .arg(m_lightPosition.m_y,4,'f',1,'0')
                       .arg(m_lightPosition.m_z,4,'f',1,'0');
   m_text->renderText(10,36,text );
}
コード例 #25
0
ファイル: NGLScene.cpp プロジェクト: NCCA/PointBake
void NGLScene::paintGL()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glViewport(0,0,m_win.width,m_win.height);
  // Rotation based on the mouse position for our global
  // transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_win.spinXFace);
  rotY.rotateY(m_win.spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;

        // draw the mesh
  loadMatricesToShader();
  m_mesh->draw();

}
コード例 #26
0
ファイル: NGLScene.cpp プロジェクト: NCCA/NGL6Demos
void NGLScene::render()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // grab an instance of the shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["nglDiffuseShader"]->use();

  // Rotation based on the mouse position for our global transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_spinXFace);
  rotY.rotateY(m_spinYFace);
  // multiply the rotations
  m_globalTransformMatrix=rotY*rotX;
  // add the translations
  m_globalTransformMatrix.m_m[3][0] = m_modelPos.m_x;
  m_globalTransformMatrix.m_m[3][1] = m_modelPos.m_y;
  m_globalTransformMatrix.m_m[3][2] = m_modelPos.m_z;
  // set this in the TX stack

   // get the VBO instance and draw the built in teapot
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();
  unsigned int bodies=m_physics->getNumCollisionObjects();
  for(unsigned int i=1; i<bodies; ++i)
  {


    m_bodyTransform=m_physics->getTransformMatrix(i);

    loadMatricesToShader();
    shader->setRegisteredUniform("Colour",0.0f,0.0f,1.0f,1.0f);
    switch(m_physics->getCollisionShape(i))
    {
      case BOX_SHAPE_PROXYTYPE :
      {
        shader->setRegisteredUniform("Colour",1.0f,0.0f,0.0f,1.0f);
        CollisionShape *shapes=CollisionShape::instance();
        float w=shapes->getDim1("car");
        float h=shapes->getDim2("car");
        float d=shapes->getDim3("car");
        ngl::Mat4 s;
        s.scale(w,h,d);
        m_bodyTransform=s*m_bodyTransform;
        loadMatricesToShader();
        prim->draw("cube");
      break;
      }
      case SPHERE_SHAPE_PROXYTYPE :
        shader->setRegisteredUniform("Colour",0.0f,1.0f,0.0f,1.0f);
        prim->draw("sphere");

      break;
      case CAPSULE_SHAPE_PROXYTYPE :
        shader->setRegisteredUniform("Colour",0.0f,0.0f,1.0f,1.0f);
        prim->draw("defaultCap");
      break;

      case CONE_SHAPE_PROXYTYPE :
        shader->setRegisteredUniform("Colour",0.0f,1.0f,1.0f,1.0f);
        prim->draw("cone");
      break;
      case CYLINDER_SHAPE_PROXYTYPE :
        shader->setRegisteredUniform("Colour",1.0f,1.0f,0.0f,1.0f);
        prim->draw("cylinder");
      break;
      case 4 :
         std::string name=m_physics->getBodyNameAtIndex(i);
        if(name =="teapot")
        {
          shader->setRegisteredUniform("Colour",1.0f,1.0f,0.0f,1.0f);
          m_teapotMesh->draw();
        }
        else if(name =="apple")
        {
          shader->setRegisteredUniform("Colour",0.0f,1.0f,0.0f,1.0f);
          m_appleMesh->draw();
        }
      break;
    }
  }
  // draw wheels
  {
    m_bodyTransform.identity();
    shader->setShaderParam4f("Colour",1.0f,1.0f,1.0f,1.0f);

    for(int i=0; i<4; ++i)
    {
      m_bodyTransform=m_car->getWheelTransform(i);
      ngl::Mat4 rotZ;
      rotZ.rotateZ(180);
      ngl::Mat4 rotY;
      rotY.rotateY(90);
      m_bodyTransform=rotZ*rotY*m_bodyTransform;
      loadMatricesToShader();
      prim->draw("wheel");
    }

  }

  shader->setShaderParam4f("Colour",1.0f,1.0f,1.0f,1.0f);

  m_bodyTransform.identity();
  loadMatricesToShader();

  prim->draw("plane");
  m_text->setColour(1,1,1);
  QString text=QString("Number of Bodies=%2").arg(bodies-1);
  m_text->renderText(10,18,text );


}
コード例 #27
0
ファイル: NGLScene.cpp プロジェクト: NCCA/NGL6Demos
void NGLScene::persp(MODE _m)
{
  // grab an instance of the shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["nglDiffuseShader"]->use();

  // Rotation based on the mouse position for our global transform
  // 4 is the panel full screen mode
  int win=FULLOFFSET;
  if(_m == PANEL)
  {
    win=PERSP;
  }
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_panelMouseInfo[win].m_spinXFace);
  rotY.rotateY(m_panelMouseInfo[win].m_spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_panelMouseInfo[win].m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_panelMouseInfo[win].m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_panelMouseInfo[win].m_modelPos.m_z;
  // set this in the TX stack

   // get the VBO instance and draw the built in teapot
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();

  // first draw a top  persp // front //side
  ngl::Vec3 from(0,2,0);
  ngl::Vec3 to(0,0,0);
  ngl::Vec3 up(0,0,-1);
  m_transformStack.pushTransform();
  {
    /// a perspective view (right upper)
    //first set the global mouse rotation for this one
    from.set(0,1,1);
    up.set(0,1,0);
    m_view=ngl::lookAt(from,to,up);
    m_projection=ngl::perspective(45,float(m_width/m_height),0.01,100);
    // x,y w/h
    if(_m==PANEL)
    {
      glViewport (m_width/2, m_height/2, m_width/2, m_height/2);
    }
    else
    {
      glViewport(0,0,m_width,m_height);
    }

    // draw
    loadMatricesToShader();
    prim->draw("troll");
    m_transformStack.setPosition(0,-0.55,0);
    loadMatricesToShader();
    prim->draw("grid");
  }
  m_transformStack.popTransform();

}
コード例 #28
0
ファイル: NGLScene.cpp プロジェクト: NCCA/FBODemos
void NGLScene::paintGL()
{
  //----------------------------------------------------------------------------------------------------------------------
  // draw to our FBO first
  //----------------------------------------------------------------------------------------------------------------------
  // grab an instance of the shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["Phong"]->use();

  // Rotation based on the mouse position for our global transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_win.spinXFace);
  rotY.rotateY(m_win.spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;


  static float rot=0.0;
   // get the VBO instance and draw the built in teapot
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();
  // we are now going to draw to our FBO
  // set the rendering destination to FBO
  glBindFramebuffer(GL_FRAMEBUFFER, m_fboID);
  // set the background colour (using blue to show it up)
  glClearColor(0,0.4f,0.5f,1);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // set our viewport to the size of the texture
  // if we want a different camera we wouldset this here
  glViewport(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
  // rotate the teapot
  m_transform.reset();

  m_transform.setRotation(rot,rot,rot);
  loadMatricesToShader();
  prim->draw("teapot");
  rot+=0.5;

  //----------------------------------------------------------------------------------------------------------------------
  // now we are going to draw to the normal GL buffer and use the texture created
  // in the previous render to draw to our objects
  //----------------------------------------------------------------------------------------------------------------------
  // first bind the normal render buffer
  glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebufferObject());
  // now enable the texture we just rendered to
  glBindTexture(GL_TEXTURE_2D, m_textureID);
  // do any mipmap generation
  glGenerateMipmap(GL_TEXTURE_2D);
  // set the screen for a different clear colour
  glClearColor(0.4f, 0.4f, 0.4f, 1.0f);			   // Grey Background
  // clear this screen
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // get the new shader and set the new viewport size
  shader->use("TextureShader");
  // this takes into account retina displays etc
  glViewport(0, 0, static_cast<GLsizei>(width() * devicePixelRatio()), static_cast<GLsizei>(height() * devicePixelRatio()));
  ngl::Mat4 MVP;
  m_transform.reset();
  MVP= m_project*m_view*m_mouseGlobalTX;
  shader->setUniform("MVP",MVP);
  prim->draw("plane");
  m_transform.setPosition(0,1,0);
  MVP= m_project*m_view*m_mouseGlobalTX*m_transform.getMatrix();
  shader->setUniform("MVP",MVP);
  prim->draw("sphere");
  //----------------------------------------------------------------------------------------------------------------------
 }
コード例 #29
0
ファイル: Axis.cpp プロジェクト: pmatev/NCCA_ribbons
//----------------------------------------------------------------------------------------------------------------------
void Axis::draw()
{
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();
  // grab an instance of the shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();

  (*shader)["Surface"]->use();
  // Rotation based on the mouse position for our global
  // transform
   // set this in the TX stack
  // liberal use of { is encourage after each push

  ngl::TransformStack txStack;
  ngl::Transformation tx;
  txStack.pushTransform();
  {

    // set the global rotation
    txStack.setGlobal(m_tx.getGlobalTransform());

    txStack.pushTransform();
    {
   // liberal use of { is encourage after each push

        /* **** X Axis **** */
        shader->setShaderParam4f("Colour",1,0,0,1);

        txStack.pushTransform();
        {
            txStack.setScale(m_scale,m_scale,m_scale);

//            ngl::Vector world_x_axis = ngl::Vector(1,0,0,0);
//            float angleX = m_vecX.angleBetween(world_x_axis);

            txStack.setRotation(0,-90,0);
            loadMatricesToShader(txStack);
            prim->draw("nglAXISCylinder");
        }
        txStack.popTransform();
        txStack.pushTransform();
        {
            txStack.setScale(m_scale,m_scale,m_scale);
            txStack.setPosition(ngl::Vector(m_scale,0,0));
            txStack.setRotation(0,90,0);
            loadMatricesToShader(txStack);
            prim->draw("nglAXISCone");
        }
        txStack.popTransform();
        txStack.pushTransform();
        {
            txStack.setScale(m_scale,m_scale,m_scale);
            txStack.setPosition(ngl::Vector(-m_scale,0,0));
            txStack.setRotation(0,-90,0);
            loadMatricesToShader(txStack);
            prim->draw("nglAXISCone");
        }
        txStack.popTransform();

        /* ******* Y Axis ****** */
        shader->setShaderParam4f("Colour",0,1,0,1);

        txStack.pushTransform();
        {
            txStack.getCurrentTransform().setScale(m_scale,m_scale,m_scale);
            txStack.getCurrentTransform().setRotation(90,0,0);
            txStack.getCurrentTransform().setPosition(ngl::Vector(0,0,0));
            loadMatricesToShader(txStack);
            prim->draw("nglAXISCylinder");
        }
        txStack.popTransform();
        txStack.pushTransform();
        {
            txStack.getCurrentTransform().setScale(m_scale,m_scale,m_scale);
            txStack.getCurrentTransform().setRotation(-90,0,0);
            txStack.getCurrentTransform().setPosition(ngl::Vector(0,m_scale,0));
            loadMatricesToShader(txStack);
            prim->draw("nglAXISCone");
        }
        txStack.popTransform();
        txStack.pushTransform();
        {
            txStack.getCurrentTransform().setScale(m_scale,m_scale,m_scale);
            txStack.getCurrentTransform().setRotation(90,0,0);
            txStack.getCurrentTransform().setPosition(ngl::Vector(0,-m_scale,0));
            loadMatricesToShader(txStack);
            prim->draw("nglAXISCone");
        }
        txStack.popTransform();

        /* **** Z Axis **** */
        shader->setShaderParam4f("Colour",0,0,1,1);

        txStack.pushTransform();
        {
            txStack.getCurrentTransform().setScale(m_scale,m_scale,m_scale);
            //txStack.getCurrentTransform().setPosition(ngl::Vector(0,0,m_scale));
            txStack.getCurrentTransform().setRotation(0,180,0);
            loadMatricesToShader(txStack);
            prim->draw("nglAXISCylinder");
        }
        txStack.popTransform();
        txStack.pushTransform();
        {
            txStack.getCurrentTransform().setScale(m_scale,m_scale,m_scale);
            txStack.getCurrentTransform().setPosition(ngl::Vector(0,0,m_scale));
            loadMatricesToShader(txStack);
            prim->draw("nglAXISCone");
        }
        txStack.popTransform();
        txStack.pushTransform();
        {
            txStack.getCurrentTransform().setScale(m_scale,m_scale,m_scale);
            txStack.getCurrentTransform().setPosition(ngl::Vector(0,0,-m_scale));
            txStack.getCurrentTransform().setRotation(180,0,0);
            loadMatricesToShader(txStack);
            prim->draw("nglAXISCone");
        }
        txStack.popTransform();


  }
  txStack.popTransform();
}
txStack.popTransform();


}
コード例 #30
0
ファイル: NGLScene.cpp プロジェクト: NCCA/VAOPrimitives
void NGLScene::drawScene(const std::string &_shader)
{
  // grab an instance of the shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)[_shader]->use();
  // clear the screen and depth buffer
  // Rotation based on the mouse position for our global
  // transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_win.spinXFace);
  rotY.rotateY(m_win.spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;

   // get the VBO instance and draw the built in teapot
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();

  m_transform.reset();
  {
    loadMatricesToShader();
    prim->draw("teapot");
  } // and before a pop

  m_transform.reset();
  {
    m_transform.setPosition(-3,0.0,0.0);
    loadMatricesToShader();
    prim->draw("sphere");
  } // and before a pop

  m_transform.reset();
  {
    m_transform.setPosition(3,0.0,0.0);
    loadMatricesToShader();
    prim->draw("cylinder");
  } // and before a pop

  m_transform.reset();
  {
    m_transform.setPosition(0.0,0.0,3.0);
    loadMatricesToShader();
    prim->draw("cube");
  } // and before a pop

  m_transform.reset();
  {
    m_transform.setPosition(-3.0,0.0,3.0);
    loadMatricesToShader();
    prim->draw("torus");
  } // and before a pop

  m_transform.reset();
  {
    m_transform.setPosition(3.0,0.5,3.0);
    loadMatricesToShader();
    prim->draw("icosahedron");
  } // and before a pop

  m_transform.reset();
  {
    m_transform.setPosition(0.0,0.0,-3.0);
    loadMatricesToShader();
    prim->draw("cone");
  } // and before a pop


  m_transform.reset();
  {
    m_transform.setPosition(-3.0,0.5,-3.0);
    loadMatricesToShader();
    prim->draw("tetrahedron");
  } // and before a pop


  m_transform.reset();
  {
    m_transform.setPosition(3.0,0.5,-3.0);
    loadMatricesToShader();
    prim->draw("octahedron");
  } // and before a pop


  m_transform.reset();
  {
    m_transform.setPosition(0.0,0.5,-6.0);
    loadMatricesToShader();
    prim->draw("football");
  } // and before a pop

  m_transform.reset();
  {
    m_transform.setPosition(-3.0,0.5,-6.0);
    m_transform.setRotation(0,180,0);
    loadMatricesToShader();
    prim->draw("disk");
  } // and before a pop


  m_transform.reset();
  {
    m_transform.setPosition(3.0f,0.5f,-6.0f);
    loadMatricesToShader();
    prim->draw("dodecahedron");
  } // and before a pop

  m_transform.reset();
  {
    m_transform.setPosition(1.0f,0.35f,1.0f);
    m_transform.setScale(1.5f,1.5f,1.5f);
    loadMatricesToShader();
    prim->draw("troll");
  } // and before a pop

#ifdef ADDLARGEMODELS
  m_transform.reset();
  {
    m_transform.setPosition(-1.0,-0.5,1.0);
    m_transform.setScale(0.1f,0.1f,0.1f);
    loadMatricesToShader();
    prim->draw("dragon");
  } // and before a pop

  m_transform.reset();
  {
    m_transform.setPosition(-2.5,-0.5,1.0);
    m_transform.setScale(0.1,0.1,0.1);
    loadMatricesToShader();
    prim->draw("buddah");
  } // and before a pop

  m_transform.reset();
  {
    m_transform.setPosition(2.5,-0.5,1.0);
    m_transform.setScale(0.1,0.1,0.1);
    loadMatricesToShader();
    prim->draw("bunny");
  } // and before a pop
#endif

  m_transform.reset();
  {
    m_transform.setPosition(0.0,-0.5,0.0);
    loadMatricesToShader();
    prim->draw("plane");
  } // and before a pop


}