Global/local reference frames with using quaternions

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);
}

Thanks for one reply. I already found one solution by swapped postion/orientation with global/local frame orientation. I can now move and orbit around planet in planetcentric frame correctly. Yes, I am using GLM extensions with my own typedefs.

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);
    vec3d_t rpos = (upos - opos) * orot;

    return rpos;
}

quatd_t Frame::fromUniversal(const quatd_t &urot, double tjd)
{
    if (center == nullptr)
        return urot;
    // return urot * glm::conjugate(getOrientation(tjd));
    return glm::conjugate(getOrientation(tjd)) * urot;
}

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);
    vec3d_t rpos = opos + (lpos * glm::conjugate(orot));

    return rpos;
}

quatd_t Frame::toUniversal(const quatd_t &lrot, double tjd)
{
    if (center == nullptr)
        return lrot;
    // return lrot * getOrientation(tjd);
    return getOrientation(tjd) * lrot;
}