Exemplo n.º 1
0
/**
 * @methodOf lights 
 */
function update_light_transform(obj) {

    if (obj.type != "LAMP")
        throw "Wrong light object";

    var light = obj.light;
    if (!light)
        return;

    var quat = m_tsr.get_quat_view(obj.render.world_tsr);
    m_util.quat_to_dir(quat, m_util.AXIS_Y, light.direction);
    m_vec3.normalize(light.direction, light.direction);

    if (light.type == "SUN") {
        var prev_angle = Math.acos(m_vec3.dot(light.prev_direction, m_util.VEC3_UNIT));
        var new_angle  = Math.acos(m_vec3.dot(light.direction, m_util.VEC3_UNIT));
        var floor_prev = Math.floor(prev_angle / 0.025);
        var floor_new  = Math.floor(new_angle / 0.025);

        if (floor_prev != floor_new)
            light.need_sun_fog_update = true;
        else
            light.need_sun_fog_update = false;
    }

    m_vec3.copy(light.direction, light.prev_direction);
}
Exemplo n.º 2
0
/**
 * Find minimum/maximum extent in direction dir
 */
function find_min_max_extent(exts, dir) {
    var dir_n = m_vec3.normalize(dir, m_vec3.create());

    var min = exts[0];
    var max = exts[0];
    for (var i = 1; i < exts.length; i++) {
        var proj = m_vec3.dot(exts[i], dir_n);

        if (proj < m_vec3.dot(min, dir_n))
            min = exts[i];

        if (proj > m_vec3.dot(max, dir_n))
            max = exts[i];
    }

    return [min, max];
}
Exemplo n.º 3
0
exports.get_frustum_mec = function(corners) {
    // left bottom near
    var p0 = corners.subarray(0, 3);
    // right top near
    var p1 = corners.subarray(6, 9);
    // left bottom far
    var p2 = corners.subarray(12, 15);
    // right top far
    var p3 = corners.subarray(18, 21);

    // basis vector: l
    var l = m_vec3.subtract(p1, p0, _vec3_tmp);
    m_vec3.normalize(l, l);

    // basis vector: m
    var normal = m_util.get_plane_normal(p0, p1, p2, _vec3_tmp2);
    var m = m_vec3.cross(normal, l, normal);
    m_vec3.normalize(m, m);

    // transform points coordinates for new 2D Cartesian coordinate system
    // q0 - center of the new system (former p0);
    // NOTE: using gl_matrix vec3 for simplicity
    var q0 = m_vec3.create();

    var q1 = m_vec3.create();
    m_vec3.subtract(p1, p0, _vec3_tmp3);
    q1[0] = m_vec3.dot(_vec3_tmp3, l);
    q1[1] = m_vec3.dot(_vec3_tmp3, m);

    var q2 = m_vec3.create();
    m_vec3.subtract(p2, p0, _vec3_tmp3);
    q2[0] = m_vec3.dot(_vec3_tmp3, l);
    q2[1] = m_vec3.dot(_vec3_tmp3, m);

    var q3 = m_vec3.create();
    m_vec3.subtract(p3, p0, _vec3_tmp3);
    q3[0] = m_vec3.dot(_vec3_tmp3, l);
    q3[1] = m_vec3.dot(_vec3_tmp3, m);

    var bs = exports.zero_bounding_sphere();
    bs = get_mec_2d([q0, q1, q2, q3], bs);

    var center_origin = m_vec3.scale(l, bs.center[0], _vec3_tmp3);
    m_vec3.scaleAndAdd(center_origin, m, bs.center[1], center_origin);
    m_vec3.add(center_origin, p0, bs.center);

    return bs;
}