Esempio n. 1
0
void wrl::atom::save(app::node node)
{
    const vec3 x = xvector(default_M);
    const vec3 y = yvector(default_M);
    const vec3 z = zvector(default_M);
    const vec3 p = wvector(default_M);

    const quat q(mat3(x, y, z));

    // Add the entity transform to this element.

    app::node n;

    n = app::node("rot_x"); n.set_f(q[0]); n.insert(node);
    n = app::node("rot_y"); n.set_f(q[1]); n.insert(node);
    n = app::node("rot_z"); n.set_f(q[2]); n.insert(node);
    n = app::node("rot_w"); n.set_f(q[3]); n.insert(node);

    n = app::node("pos_x"); n.set_f(p[0]); n.insert(node);
    n = app::node("pos_y"); n.set_f(p[1]); n.insert(node);
    n = app::node("pos_z"); n.set_f(p[2]); n.insert(node);

    if (body_id)
    {
        n = app::node("body");
        n.set_i(body_id);
        n.insert(node);
    }

    save_params(node);
}
Esempio n. 2
0
void wrl::constraint::calc_pos(double& x, double& y, const vec3& p,
                               const vec3& v) const
{
    double t = (wvector(T) * zvector(T) - p * zvector(T)) / (v * zvector(T));
    vec3 q = p + v * t - wvector(T);

    double xx = q * xvector(T);
    double yy = q * yvector(T);

    x = snap(xx, grid_d);
    y = snap(yy, grid_d);
}
Esempio n. 3
0
void wrl::constraint::calc_rot(double& a, double& d, const vec3& p,
                               const vec3& v) const
{
    double t = (wvector(T) * zvector(T) - p * zvector(T)) / (v * zvector(T));
    vec3 q = p + v * t - wvector(T);

    double aa = to_degrees(atan2(q * yvector(T), q * xvector(T)));
    double dd = length(q);

    a = snap(aa, double(grid_a));
    d = snap(dd,       (grid_d));
}
Esempio n. 4
0
/*
 * Set the time for the globe.  The globe will orient itself to properly
 * reflect the indicate date and time, including seasonal shift of the
 * polar axis and time of day.
 *
 * \param time A time value (assumed to be Greenwich Mean Time).
 */
void vtIcoGlobe::SetTime(const vtTime &time)
{
    float second_of_day = (float) time.GetSecondOfDay();
    float fraction_of_day = second_of_day / (24 * 60 * 60);
    float rotation = fraction_of_day * PI2f;

    // match with actual globe
    rotation += PID2f;

    FMatrix4 tmp, m4;
    m4.Identity();

    if (m_bTilt)
    {
        FPoint3 xvector(1,0,0), seasonal_axis;

        // Seasonal axis rotation (days since winter solstice, approximate)
        float season = (time.GetTM().tm_yday + 10) / 365.0f * PI2f;
        tmp.AxisAngle(FPoint3(0,1,0), season);
        tmp.Transform(xvector, seasonal_axis);

        // The earth's axis is tilted with respect to the plane of its orbit
        // at an angle of about 23.4 degrees.  Tilting the northern
        // hemisphere away from the sun (-tilt) puts this at the winter
        // solstice.
        float tilt = 23.4 / 180.0f * PIf;
        tmp.AxisAngle(seasonal_axis, -tilt);
        m4.PreMult(tmp);
    }

    // rotation around axis
    tmp.AxisAngle(FPoint3(0,1,0), rotation);
    m4.PreMult(tmp);

    // store rotation to a quaternion
    FMatrix3 m3 = m4;
    m_Rotation.SetFromMatrix(m3);

    // don't do time rotation on unfolded(ing) globes
    if (!m_bUnfolded)
        m_top->SetTransform1(m4);
}
Esempio n. 5
0
bool wrl::constraint::point(const vec3& p, const vec3& v, mat4& A)
{
    if (to_degrees(acos(mouse_v * v)) > 1.0)
    {
        if (mode)
        {
            double a;
            double d;

            calc_rot(a, d, p, v);

            if (fabs(a - mouse_a) > 0.0 || fabs(d - mouse_d) > 0.0)
            {
                A = translation( wvector(T))
                    *    rotation( zvector(T), to_radians(a - mouse_a))
                    * translation(-wvector(T));

                return true;
            }
        }
        else
        {
            double x;
            double y;

            calc_pos(x, y, p, v);

            if (fabs(x - mouse_x) > 0.0 || fabs(y - mouse_y) > 0.0)
            {
                A = translation(xvector(T) * (x - mouse_x)
                                + yvector(T) * (y - mouse_y));
                return true;
            }
        }
    }
    return false;
}