Replace gluProject with own implementation
parent
32ce75e858
commit
6b954fd7af
|
@ -1298,30 +1298,22 @@ void Renderer::addAnnotation(vector<Annotation>& annotations,
|
|||
float size,
|
||||
bool special)
|
||||
{
|
||||
double winX, winY, winZ;
|
||||
GLint view[4] = { 0, 0, windowWidth, windowHeight };
|
||||
float depth = (float) (pos.x() * modelMatrix[2] +
|
||||
pos.y() * modelMatrix[6] +
|
||||
pos.z() * modelMatrix[10]);
|
||||
if (gluProject(pos.x(), pos.y(), pos.z(),
|
||||
modelMatrix,
|
||||
projMatrix,
|
||||
view,
|
||||
&winX, &winY, &winZ) != GL_FALSE)
|
||||
Vector3d win;
|
||||
Vector3d posd = pos.cast<double>();
|
||||
if (Project(posd, modelMatrix, projMatrix, view, win))
|
||||
{
|
||||
double depth = pos.x() * modelMatrix(2, 0) +
|
||||
pos.y() * modelMatrix(2, 1) +
|
||||
pos.z() * modelMatrix(2, 2);
|
||||
win.z() = -depth;
|
||||
|
||||
Annotation a;
|
||||
if (special)
|
||||
{
|
||||
if (markerRep == nullptr)
|
||||
a.labelText = labelText;
|
||||
}
|
||||
else
|
||||
{
|
||||
a.labelText = labelText;
|
||||
}
|
||||
if (!special || markerRep == nullptr)
|
||||
a.labelText = labelText;
|
||||
a.markerRep = markerRep;
|
||||
a.color = color;
|
||||
a.position = Vector3f((float) winX, (float) winY, -depth);
|
||||
a.position = win.cast<float>();
|
||||
a.halign = halign;
|
||||
a.valign = valign;
|
||||
a.size = size;
|
||||
|
@ -2522,8 +2514,8 @@ void Renderer::draw(const Observer& observer,
|
|||
|
||||
// Get the model matrix *before* translation. We'll use this for
|
||||
// positioning star and planet labels.
|
||||
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
|
||||
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
|
||||
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix.data());
|
||||
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix.data());
|
||||
|
||||
clearSortedAnnotations();
|
||||
|
||||
|
|
|
@ -719,8 +719,8 @@ class Renderer
|
|||
|
||||
std::vector<LightSource> lightSourceList;
|
||||
|
||||
double modelMatrix[16];
|
||||
double projMatrix[16];
|
||||
Eigen::Matrix4d modelMatrix;
|
||||
Eigen::Matrix4d projMatrix;
|
||||
|
||||
bool useCompressedTextures{ false };
|
||||
unsigned int textureResolution;
|
||||
|
|
|
@ -62,6 +62,31 @@ LookAt(const Eigen::Matrix<T, 3, 1>& from, const Eigen::Matrix<T, 3, 1>& to, con
|
|||
return Eigen::Quaternion<T>(m).conjugate();
|
||||
}
|
||||
|
||||
/*! Project to screen space
|
||||
*/
|
||||
template<class T> bool
|
||||
Project(const Eigen::Matrix<T, 3, 1>& from,
|
||||
const Eigen::Matrix<T, 4, 4>& modelViewMatrix,
|
||||
const Eigen::Matrix<T, 4, 4>& projMatrix,
|
||||
const int viewport[4],
|
||||
Eigen::Matrix<T, 3, 1>& to)
|
||||
{
|
||||
Eigen::Matrix<T, 4, 1> in(from.x(), from.y(), from.z(), T(1.0));
|
||||
Eigen::Matrix<T, 4, 1> out = projMatrix * modelViewMatrix * in;
|
||||
if (out.w() == T(0.0))
|
||||
return false;
|
||||
|
||||
out = out.array() / out.w();
|
||||
// Map x, y and z to range 0-1
|
||||
out = T(0.5) + out.array() * T(0.5);
|
||||
// Map x,y to viewport
|
||||
out.x() = viewport[0] + out.x() * viewport[2];
|
||||
out.y() = viewport[1] + out.y() * viewport[3];
|
||||
|
||||
to = { out.x(), out.y(), out.z() };
|
||||
return true;
|
||||
}
|
||||
|
||||
}; // namespace celmath
|
||||
|
||||
#endif // _CELMATH_GEOMUTIL_H_
|
||||
|
|
Loading…
Reference in New Issue