コード例 #1
0
/// This only needs to be done once for all the particles, because the view
/// matrix does not change any between them.  If you were to modify the view
/// matrix at all, you would need to recalculate the camera pos and up vector.
void BillboardMatrixBase::GetCameraPosAndUp(Vector3d& vCameraPos, Vector3d& vCameraUp)
{
   Matrix4d mView;
   glGetDoublev(GL_MODELVIEW_MATRIX, mView.Data());

   // The values in the view matrix for the camera are the negative values of
   // the camera. This is because of the way gluLookAt works; I'm don't fully
   // understand why gluLookAt does what it does, but I know doing this works:)
   // I know that gluLookAt creates a the look vector as (eye - center), the
   // resulting direction vector is a vector from center to eye (the oposite
   // of what are view direction really is).
   vCameraPos = -mView.Column(3);
   vCameraUp  = mView.Row(1);

   // zero the translation in the matrix, so we can use the matrix to transform
   // camera postion to world coordinates using the view matrix
   mView.Column(3, Vector3d());

   // the view matrix is how to get to the gluLookAt pos from what we gave as
   // input for the camera position, so to go the other way we need to reverse
   // the rotation.  Transposing the matrix will do this.
   mView.TransposeRotation();

   // get the correct position of the camera in world space
   vCameraPos = mView * vCameraPos;
}
コード例 #2
0
void ModelDisplayState::RenderStaticModels(RenderOptions& options) const
{
   const std::vector<CompositeModel3d::StaticModelData>& vecStaticModels =
      m_spModel->StaticList();

   ATLASSERT(m_vecStaticModelTextures.size() == vecStaticModels.size());

   for (size_t i=0, iMax = vecStaticModels.size(); i<iMax; i++)
   {
      // enable model texture, if loaded
      if (m_vecStaticModelTextures[i] != NULL)
         m_vecStaticModelTextures[i]->Bind();

      // find mount point and matrix
      const CompositeModel3d::StaticModelData& data = vecStaticModels[i];

      ATLASSERT(data.m_iJointIndex >= 0);
      ATLASSERT(size_t(data.m_iJointIndex) < m_vecJointRenderData.size());

      size_t uiMountIndex = static_cast<size_t>(data.m_iJointIndex);

      Matrix4d matGlobal = m_vecJointRenderData[uiMountIndex].GlobalMatrix();
      matGlobal.Transpose();

      // transform current modelview matrix
      glPushMatrix();

      glMultMatrixd(matGlobal.Data());

      // render model
      data.m_spStatic->Render(options);

      // render mount point
      if (options.Get(RenderOptions::optionModelJoints))
         RenderMountPoint();

      glPopMatrix();
   }
}