Ejemplo n.º 1
0
function limit_object_position(obj) {
    var bb = m_trans.get_object_bounding_box(obj);

    var obj_parent = m_obj.get_parent(obj);
    if (obj_parent && m_obj.is_armature(obj_parent))
        // get translation from the parent (armature) of the animated object
        var obj_pos = m_trans.get_translation(obj_parent, _vec3_tmp);
    else
        var obj_pos = m_trans.get_translation(obj, _vec3_tmp);

    if (bb.max_x > WALL_X_MAX)
        obj_pos[0] -= bb.max_x - WALL_X_MAX;
    else if (bb.min_x < WALL_X_MIN)
        obj_pos[0] += WALL_X_MIN - bb.min_x;

    if (bb.max_y > WALL_Y_MAX)
        obj_pos[1] -= bb.max_y - WALL_Y_MAX;
    else if (bb.min_y < WALL_Y_MIN)
        obj_pos[1] += WALL_Y_MIN - bb.min_y;

    if (obj_parent && m_obj.is_armature(obj_parent))
        // translate the parent (armature) of the animated object
        m_trans.set_translation_v(obj_parent, obj_pos);
    else
        m_trans.set_translation_v(obj, obj_pos);
}
Ejemplo n.º 2
0
function loaded_cb(data_id) {

    var objs = m_scenes.get_all_objects("ALL", data_id);
    for (var i = 0; i < objs.length; i++) {
        var obj = objs[i];

        if (m_phy.has_physics(obj)) {
            m_phy.enable_simulation(obj);

            // create sensors to detect collisions
            var sensor_col = m_ctl.create_collision_sensor(obj, "FURNITURE");
            var sensor_sel = m_ctl.create_selection_sensor(obj, true);

            if (obj == _selected_obj)
                m_ctl.set_custom_sensor(sensor_sel, 1);

            m_ctl.create_sensor_manifold(obj, "COLLISION", m_ctl.CT_CONTINUOUS, 
                    [sensor_col, sensor_sel], logic_func, trigger_outline);


            // spawn appended object at a certain position
            var obj_parent = m_obj.get_parent(obj);
            if (obj_parent && m_obj.is_armature(obj_parent))
                // translate the parent (armature) of the animated object
                m_trans.set_translation_v(obj_parent, spawner_pos);
            else
                m_trans.set_translation_v(obj, spawner_pos);
        }

        // show appended object
        if (m_obj.is_mesh(obj))
            m_scenes.show_object(obj);
    }
}
Ejemplo n.º 3
0
function rotate_object(obj, angle) {
    var obj_parent = m_obj.get_parent(obj);
    
    if (obj_parent && m_obj.is_armature(obj_parent)) {
        // rotate the parent (armature) of the animated object
        var obj_quat = m_trans.get_rotation(obj_parent, _vec4_tmp);
        m_quat.rotateZ(obj_quat, angle, obj_quat);
        m_trans.set_rotation_v(obj_parent, obj_quat);
    } else {
        var obj_quat = m_trans.get_rotation(obj, _vec4_tmp);
        m_quat.rotateZ(obj_quat, angle, obj_quat);
        m_trans.set_rotation_v(obj, obj_quat);
    }
    limit_object_position(obj);
}
Ejemplo n.º 4
0
function main_canvas_move(e) {
    if (_drag_mode)
        if (_selected_obj) {
            // disable camera controls while moving the object
            if (_enable_camera_controls) {
                m_app.disable_camera_controls();
                _enable_camera_controls = false;
            }

            // calculate viewport coordinates
            var cam = m_scenes.get_active_camera();

            var x = m_mouse.get_coords_x(e);
            var y = m_mouse.get_coords_y(e);

            if (x >= 0 && y >= 0) {
                x -= _obj_delta_xy[0];
                y -= _obj_delta_xy[1];

                // emit ray from the camera
                var pline = m_cam.calc_ray(cam, x, y, _pline_tmp);
                var camera_ray = m_math.get_pline_directional_vec(pline, _vec3_tmp);

                // calculate ray/floor_plane intersection point
                var cam_trans = m_trans.get_translation(cam, _vec3_tmp2);
                m_math.set_pline_initial_point(_pline_tmp, cam_trans);
                m_math.set_pline_directional_vec(_pline_tmp, camera_ray);
                var point = m_math.line_plane_intersect(FLOOR_PLANE_NORMAL, 0,
                        _pline_tmp, _vec3_tmp3);

                // do not process the parallel case and intersections behind the camera
                if (point && camera_ray[2] < 0) {
                    var obj_parent = m_obj.get_parent(_selected_obj);
                    if (obj_parent && m_obj.is_armature(obj_parent))
                        // translate the parent (armature) of the animated object
                        m_trans.set_translation_v(obj_parent, point);
                    else
                        m_trans.set_translation_v(_selected_obj, point);
                    limit_object_position(_selected_obj);
                }
            }
        }
}
Ejemplo n.º 5
0
function main_canvas_down(e) {
    _drag_mode = true;

    if (e.preventDefault)
        e.preventDefault();

    var x = m_mouse.get_coords_x(e);
    var y = m_mouse.get_coords_y(e);

    var obj = m_scenes.pick_object(x, y);

    // handling outline effect
    if (_selected_obj != obj) {
        if (_selected_obj)
            m_scenes.clear_outline_anim(_selected_obj);
        if (obj)
            m_scenes.apply_outline_anim(obj, 1, 1, 0);

        _selected_obj = obj;
    }

    // calculate delta in viewport coordinates
    if (_selected_obj) {
        var cam = m_scenes.get_active_camera();

        var obj_parent = m_obj.get_parent(_selected_obj);
        if (obj_parent && m_obj.is_armature(obj_parent))
            // get translation from the parent (armature) of the animated object
            m_trans.get_translation(obj_parent, _vec3_tmp);
        else
            m_trans.get_translation(_selected_obj, _vec3_tmp);
        m_cam.project_point(cam, _vec3_tmp, _obj_delta_xy);

        _obj_delta_xy[0] = x - _obj_delta_xy[0];
        _obj_delta_xy[1] = y - _obj_delta_xy[1];
    }
}
Ejemplo n.º 6
0
function register_asteroids() {
    for (var i = 0; i < ASTEROID_COUNT; i++) {
        var name = "asteroid." + int_to_str_length(i, 3);
        var asteroid_obj = m_scs.get_object_by_name(name);
        if (asteroid_obj) {
            var asteroid_children = m_scs.get_object_children(asteroid_obj);

            var asteroid_arm = null;
            var asteroid_emitter_obj = null;
            var asteroid_speaker = null;
            for (var j = 0; j < asteroid_children.length; j++) {
                if (m_obj.is_armature(asteroid_children[j])) {
                    asteroid_arm = asteroid_children[j];
                } if (m_scs.get_object_name(asteroid_children[j]) == "explosion_emitter") {
                    asteroid_emitter_obj = asteroid_children[j];
                } if (m_obj.is_speaker(asteroid_children[j])) {
                    asteroid_speaker = asteroid_children[j];
                }
            }

            var asteroid_copy_obj = m_scs.get_object_by_name(name + "_copy");
            var asteroid_copy_mesh_obj = null;
            var asteroid_copy_children = m_scs.get_object_children(asteroid_copy_obj);
            for (var j = 0; j < asteroid_copy_children.length; j++)
                if (m_obj.is_mesh(asteroid_copy_children[j]))
                    asteroid_copy_mesh_obj = asteroid_copy_children[j];

            var asteroid = init_asteroid(name, asteroid_obj, asteroid_arm,
                    asteroid_copy_obj, asteroid_emitter_obj,
                    asteroid_copy_mesh_obj, asteroid_speaker);
            _asteroid_list.push(asteroid);

            init_asteroid_transform(asteroid);

            var elapsed = m_ctl.create_elapsed_sensor();
            var update_asteroid_cb = function(obj, id, pulse) {
                var asteroid = obj;
                if (asteroid.active) {
                    // set new tranlation
                    var ast_obj = asteroid.ast_obj;
                    var asteroid_pos = m_trans.get_translation(ast_obj, _vec3_tmp);
                    var elapsed = m_ctl.get_sensor_value(obj, id, 0);
                    var diff_pos = m_vec3.scale(asteroid.velosity, elapsed, _vec3_tmp2);
                    m_vec3.add(asteroid_pos, diff_pos, asteroid_pos);
                    m_trans.set_translation_v(ast_obj, asteroid_pos);

                    // set new rotation
                    var angle = m_quat.slerp(QUAT4_IDENT,
                            asteroid.angular_velosity, elapsed, _quat_tmp);

                    var aster_quat = m_trans.get_rotation(ast_obj, _quat_tmp2);
                    var new_aster_quat = m_quat.multiply(aster_quat, angle, _quat_tmp);
                    m_quat.normalize(new_aster_quat, new_aster_quat);
                    m_trans.set_rotation_v(ast_obj, new_aster_quat);

                    var ast_copy_obj = asteroid.ast_copy_obj;
                    if (ast_copy_obj) {
                        m_trans.set_translation_v(ast_copy_obj, asteroid_pos);
                        m_trans.set_rotation_v(ast_copy_obj, new_aster_quat);
                    }

                    if (asteroid_pos[2] > 20)
                        init_asteroid_transform(asteroid);
                }
            }
            m_ctl.create_sensor_manifold(asteroid, "UPDATE_ASTEROID" + name,
                    m_ctl.CT_CONTINUOUS, [elapsed], null, update_asteroid_cb);
        }
    }
}