I am trying to write my space simulator. I am using movement controls like move, attitude and orbiting around celestial body, etc. in local reference frame (planetcentric coordinates) that can be moved or rotated in global frame space. Then convert local position/orientatioon to global position/orientation that renderer will use for rendering. I tried to move around but it went erratic/off course, etc. except in quaternion identity (1, 0, 0, 0) and any center position. Here are my global/local frame conversion code.
Thanks.
vec3d_t Frame::fromUniversal(const vec3d_t &upos, double tjd)
{
if (center == nullptr)
return upos;
vec3d_t opos = center->getuPosition(tjd);
quatd_t orot = getOrientation(tjd);
vec3d_t rpos = orot * (upos - opos);
return rpos;
}
quatd_t Frame::fromUniversal(const quatd_t &urot, double tjd)
{
if (center == nullptr)
return urot;
return urot * glm::conjugate(getOrientation(tjd));
}
vec3d_t Frame::toUniversal(const vec3d_t &lpos, double tjd)
{
if (center == nullptr)
return lpos;
vec3d_t opos = center->getuPosition(tjd);
quatd_t orot = getOrientation(tjd);
vec3d_t rpos = opos + (glm::conjugate(orot) * lpos);
return rpos;
}
quatd_t Frame::toUniversal(const quatd_t &lrot, double tjd)
{
if (center == nullptr)
return lrot;
return lrot * getOrientation(tjd);
}