I am trying using control movements in local frame before converting position and quaternion to global (universal) frame but, something went erratic when move around. It is only working in ecliptic frame (using quaternion identity). Look at my local/global frame conversion code.
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);
}
quatd_t getOrientation(double) const override
{
return quatd_t(vec3d_t(J2000Obliquity, 0, 0));
}
if (mode == tvFreeMode)
{
// free travel mode
// Update current position and attitude in local reference frame
// applying angular velocity to rotation quaternion in local space.
//
// dq/dt = q * w * t/2
// where w = (0, x, y, z)
//
lrot += lrot * wv * (dt / 2.0);
lrot = glm::normalize(lrot);
// lpos -= glm::conjugate(lrot) * tv * dt;
lpos -= (lrot * tv) * dt;
}
// Updating current universal coordinates
updateUniversal();
void Player::updateUniversal()
{
upos = frame->toUniversal(lpos, jdTime);
urot = frame->toUniversal(lrot, jdTime);
}
I tried to use movement controls with using equator frame (23.4 degrees tilt). It went off course when I tried move forward on a side of object but move forward in front of object correctly. When I tried to yaw left/right but it yaw at off course instead, etc… I tried many different solution but can't find correct solution so far.
I tried orbit around object but my up/down arrow works fine but my left/right arrow made object spinning around. With ecliptic plane (quaternion identity, everything works fine.
Does anyone have any solutions with local/universal (global) reference frame conversions?