2014-08-09 18:01:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-09-20 11:51:23 +00:00
|
|
|
TABS.setup = {
|
2014-07-10 17:23:16 +00:00
|
|
|
yaw_fix: 0.0
|
|
|
|
};
|
2014-08-12 14:05:22 +00:00
|
|
|
|
2014-09-20 11:51:23 +00:00
|
|
|
TABS.setup.initialize = function (callback) {
|
2014-07-10 17:23:16 +00:00
|
|
|
var self = this;
|
2014-07-10 16:51:02 +00:00
|
|
|
GUI.active_tab_ref = this;
|
2014-09-20 11:51:23 +00:00
|
|
|
GUI.active_tab = 'setup';
|
2014-09-17 08:31:36 +00:00
|
|
|
googleAnalytics.sendAppView('Setup');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-07 01:01:59 +00:00
|
|
|
function load_ident() {
|
2014-09-16 17:27:30 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_IDENT, false, false, load_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_config() {
|
|
|
|
if (bit_check(CONFIG.capability, 30)) {
|
|
|
|
MSP.send_message(MSP_codes.MSP_CONFIG, false, false, load_misc_data);
|
|
|
|
} else {
|
|
|
|
load_misc_data();
|
|
|
|
}
|
2014-05-07 01:01:59 +00:00
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
function load_misc_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_MISC, false, false, load_html);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function load_html() {
|
2014-09-20 11:51:23 +00:00
|
|
|
$('#content').load("./tabs/setup.html", process_html);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-08-14 14:48:16 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_ACC_TRIM, false, false, load_ident);
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
function process_html() {
|
2014-05-06 14:48:46 +00:00
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
2014-09-16 17:27:30 +00:00
|
|
|
// if CAP_BASEFLIGHT_CONFIG (30)
|
|
|
|
if (bit_check(CONFIG.capability, 30)) {
|
|
|
|
// current stuff, this will become default when the compatibility period ends
|
|
|
|
$('.CAP_BASEFLIGHT_CONFIG').show();
|
|
|
|
|
|
|
|
// initialize 3D
|
|
|
|
self.initialize3D(false);
|
|
|
|
|
|
|
|
// set heading in interactive block
|
|
|
|
$('span.heading').text(chrome.i18n.getMessage('initialSetupheading', [0]));
|
|
|
|
} else {
|
|
|
|
// old stuff
|
|
|
|
$('.COMPATIBILITY').show();
|
|
|
|
|
|
|
|
// initialize 3D
|
|
|
|
self.initialize3D(true);
|
|
|
|
|
|
|
|
// Fill in misc stuff
|
|
|
|
$('input[name="mincellvoltage"]').val(MISC.vbatmincellvoltage);
|
|
|
|
$('input[name="maxcellvoltage"]').val(MISC.vbatmaxcellvoltage);
|
|
|
|
$('input[name="voltagescale"]').val(MISC.vbatscale);
|
|
|
|
|
|
|
|
$('input[name="minthrottle"]').val(MISC.minthrottle);
|
|
|
|
$('input[name="maxthrottle"]').val(MISC.maxthrottle);
|
|
|
|
$('input[name="failsafe_throttle"]').val(MISC.failsafe_throttle);
|
|
|
|
$('input[name="mincommand"]').val(MISC.mincommand);
|
|
|
|
|
|
|
|
$('input[name="mag_declination"]').val(MISC.mag_declination / 10);
|
|
|
|
|
|
|
|
// Fill in the accel trimms from CONFIG object
|
|
|
|
$('input[name="pitch"]').val(CONFIG.accelerometerTrims[0]);
|
|
|
|
$('input[name="roll"]').val(CONFIG.accelerometerTrims[1]);
|
|
|
|
|
|
|
|
// Display multiType and motor diagram (if such exist)
|
|
|
|
var str;
|
|
|
|
switch (CONFIG.multiType) {
|
|
|
|
case 1: // TRI
|
|
|
|
str = 'TRI';
|
|
|
|
$('.modelMixDiagram').attr('src', './images/motor_order/tri.svg').addClass('modelMixTri');
|
|
|
|
break;
|
|
|
|
case 2: // QUAD +
|
|
|
|
str = 'Quad +';
|
2014-09-19 14:04:08 +00:00
|
|
|
$('.modelMixDiagram').attr('src', './images/motor_order/quad_p.svg').addClass('modelMixQuadP');
|
2014-09-16 17:27:30 +00:00
|
|
|
break;
|
|
|
|
case 3: // QUAD X
|
|
|
|
str = 'Quad X';
|
2014-09-19 14:04:08 +00:00
|
|
|
$('.modelMixDiagram').attr('src', './images/motor_order/quad_x.svg').addClass('modelMixQuadX');
|
2014-09-16 17:27:30 +00:00
|
|
|
break;
|
|
|
|
case 4: // BI
|
|
|
|
str = 'BI';
|
|
|
|
break;
|
|
|
|
case 5: // GIMBAL
|
|
|
|
str = 'Gimbal';
|
|
|
|
break;
|
|
|
|
case 6: // Y6
|
|
|
|
str = 'Y6';
|
|
|
|
$('.modelMixDiagram').attr('src', './images/motor_order/y6.svg').addClass('modelMixY6');
|
|
|
|
break;
|
|
|
|
case 7: // HEX 6
|
|
|
|
str = 'HEX 6';
|
2014-09-19 14:04:08 +00:00
|
|
|
$('.modelMixDiagram').attr('src', './images/motor_order/hex_p.svg').addClass('modelMixHex6P');
|
2014-09-16 17:27:30 +00:00
|
|
|
break;
|
|
|
|
case 8: // FLYING_WING
|
|
|
|
str = 'Flying Wing';
|
|
|
|
break;
|
|
|
|
case 9: // Y4
|
|
|
|
str = 'Y4';
|
|
|
|
$('.modelMixDiagram').attr('src', './images/motor_order/y4.svg').addClass('modelMixY4');
|
|
|
|
break;
|
|
|
|
case 10: // HEX6 X
|
|
|
|
str = 'HEX6 X';
|
2014-09-19 14:04:08 +00:00
|
|
|
$('.modelMixDiagram').attr('src', './images/motor_order/hex_x.svg').addClass('modelMixHex6X');
|
2014-09-16 17:27:30 +00:00
|
|
|
break;
|
|
|
|
case 11: // OCTO X8
|
|
|
|
case 12:
|
|
|
|
case 13:
|
|
|
|
str = 'OCTO X8';
|
2014-09-19 14:04:08 +00:00
|
|
|
$('.modelMixDiagram').attr('src', './images/motor_order/octo_flat_x.svg').addClass('modelMixOctoX');
|
2014-09-16 17:27:30 +00:00
|
|
|
break;
|
|
|
|
case 14: // AIRPLANE
|
|
|
|
str = 'Airplane';
|
|
|
|
$('.modelMixDiagram').attr('src', './images/motor_order/airplane.svg').addClass('modelMixAirplane');
|
|
|
|
break;
|
|
|
|
case 15: // Heli 120
|
|
|
|
str = 'Heli 120';
|
|
|
|
break;
|
|
|
|
case 16: // Heli 90
|
|
|
|
str = 'Heli 90';
|
|
|
|
break;
|
|
|
|
case 17: // Vtail
|
|
|
|
str = 'Vtail';
|
2014-09-19 14:04:08 +00:00
|
|
|
$('.modelMixDiagram').attr('src', './images/motor_order/vtail_quad.svg').addClass('modelMixVtail');
|
2014-09-16 17:27:30 +00:00
|
|
|
break;
|
|
|
|
case 18: // HEX6 H
|
|
|
|
str = 'HEX6 H';
|
|
|
|
$('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom');
|
|
|
|
break;
|
|
|
|
case 19: // PPM to SERVO
|
|
|
|
str = 'PPM to SERVO';
|
|
|
|
$('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom');
|
|
|
|
break;
|
|
|
|
case 20: // Dualcopter
|
|
|
|
str = 'Dualcopter';
|
|
|
|
$('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom');
|
|
|
|
break;
|
|
|
|
case 21: // Singlecopter
|
|
|
|
str = 'Singlecopter';
|
|
|
|
$('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom');
|
|
|
|
break;
|
|
|
|
case 22: // Custom
|
|
|
|
str = 'Custom';
|
|
|
|
$('.modelMixDiagram').attr("src", './images/motor_order/custom.svg').addClass('modelMixCustom');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('span.model').text(chrome.i18n.getMessage('initialSetupModel', [str]));
|
|
|
|
|
|
|
|
// Heading
|
|
|
|
$('span.heading').text(chrome.i18n.getMessage('initialSetupheading', [0]));
|
|
|
|
|
|
|
|
$('a.update').click(function () {
|
|
|
|
CONFIG.accelerometerTrims[0] = parseInt($('input[name="pitch"]').val());
|
|
|
|
CONFIG.accelerometerTrims[1] = parseInt($('input[name="roll"]').val());
|
|
|
|
|
|
|
|
MISC.vbatmincellvoltage = parseFloat($('input[name="mincellvoltage"]').val()) * 10;
|
|
|
|
MISC.vbatmaxcellvoltage = parseFloat($('input[name="maxcellvoltage"]').val()) * 10;
|
|
|
|
MISC.vbatscale = parseInt($('input[name="voltagescale"]').val());
|
|
|
|
|
|
|
|
MISC.minthrottle = parseInt($('input[name="minthrottle"]').val());
|
|
|
|
MISC.maxthrottle = parseInt($('input[name="maxthrottle"]').val());
|
|
|
|
MISC.failsafe_throttle = parseInt($('input[name="failsafe_throttle"]').val());
|
|
|
|
MISC.mincommand = parseInt($('input[name="mincommand"]').val());
|
|
|
|
|
|
|
|
MISC.mag_declination = parseFloat($('input[name="mag_declination"]').val()) * 10;
|
|
|
|
|
|
|
|
function save_to_eeprom() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () {
|
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupEepromSaved'));
|
|
|
|
});
|
|
|
|
}
|
2014-09-17 08:51:54 +00:00
|
|
|
|
|
|
|
// Send over the new trims
|
|
|
|
MSP.send_message(MSP_codes.MSP_SET_ACC_TRIM, MSP.crunch(MSP_codes.MSP_SET_ACC_TRIM));
|
|
|
|
|
|
|
|
// Send over new misc
|
|
|
|
MSP.send_message(MSP_codes.MSP_SET_MISC, MSP.crunch(MSP_codes.MSP_SET_MISC), false, save_to_eeprom);
|
2014-09-16 17:27:30 +00:00
|
|
|
});
|
|
|
|
}
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-09-17 08:51:54 +00:00
|
|
|
// check if we have magnetometer
|
|
|
|
if (!bit_check(CONFIG.activeSensors, 2)) {
|
|
|
|
$('a.calibrateMag').addClass('disabled');
|
|
|
|
}
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// UI Hooks
|
2014-08-12 14:05:22 +00:00
|
|
|
$('a.calibrateAccel').click(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
var self = $(this);
|
|
|
|
|
|
|
|
if (!self.hasClass('calibrating')) {
|
|
|
|
self.addClass('calibrating');
|
|
|
|
|
|
|
|
// During this period MCU won't be able to process any serial commands because its locked in a for/while loop
|
|
|
|
// until this operation finishes, sending more commands through data_poll() will result in serial buffer overflow
|
2014-09-20 11:51:23 +00:00
|
|
|
GUI.interval_pause('setup_data_pull');
|
2014-08-12 14:05:22 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_ACC_CALIBRATION, false, false, function () {
|
2014-05-06 16:07:32 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupAccelCalibStarted'));
|
2014-02-14 21:17:51 +00:00
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:05:22 +00:00
|
|
|
GUI.timeout_add('button_reset', function () {
|
2014-09-20 11:51:23 +00:00
|
|
|
GUI.interval_resume('setup_data_pull');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-06 16:07:32 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupAccelCalibEnded'));
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
self.removeClass('calibrating');
|
|
|
|
}, 2000);
|
|
|
|
}
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:05:22 +00:00
|
|
|
$('a.calibrateMag').click(function () {
|
2014-03-22 23:28:41 +00:00
|
|
|
var self = $(this);
|
2014-01-13 16:43:22 +00:00
|
|
|
|
2014-09-17 08:51:54 +00:00
|
|
|
if (!self.hasClass('calibrating') && !self.hasClass('disabled')) {
|
2014-03-22 23:28:41 +00:00
|
|
|
self.addClass('calibrating');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-08-12 14:05:22 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_MAG_CALIBRATION, false, false, function () {
|
2014-05-06 16:07:32 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupMagCalibStarted'));
|
2014-02-14 21:17:51 +00:00
|
|
|
});
|
2013-06-17 21:36:19 +00:00
|
|
|
|
2014-08-12 14:05:22 +00:00
|
|
|
GUI.timeout_add('button_reset', function () {
|
2014-05-06 16:07:32 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupMagCalibEnded'));
|
2014-03-22 23:28:41 +00:00
|
|
|
self.removeClass('calibrating');
|
|
|
|
}, 30000);
|
|
|
|
}
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
$('a.resetSettings').click(function() {
|
2014-08-12 14:05:22 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_RESET_CONF, false, false, function () {
|
2014-05-06 16:07:32 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('initialSetupSettingsRestored'));
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
GUI.tab_switch_cleanup(function() {
|
2014-09-20 11:51:23 +00:00
|
|
|
TABS.setup.initialize();
|
2014-03-08 05:25:15 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-07-10 17:23:16 +00:00
|
|
|
// display current yaw fix value (important during tab re-initialization)
|
|
|
|
$('div#interactive_block > a.reset').text(chrome.i18n.getMessage('initialSetupButtonResetZaxisValue', [self.yaw_fix]));
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// reset yaw button hook
|
2014-08-12 14:05:22 +00:00
|
|
|
$('div#interactive_block > a.reset').click(function () {
|
2014-07-10 17:23:16 +00:00
|
|
|
self.yaw_fix = SENSOR_DATA.kinematics[2] * - 1.0;
|
|
|
|
$(this).text(chrome.i18n.getMessage('initialSetupButtonResetZaxisValue', [self.yaw_fix]));
|
2014-07-06 09:24:18 +00:00
|
|
|
|
2014-07-10 17:23:16 +00:00
|
|
|
console.log('YAW reset to 0 deg, fix: ' + self.yaw_fix + ' deg');
|
2013-12-15 01:28:12 +00:00
|
|
|
});
|
2014-03-22 23:28:41 +00:00
|
|
|
|
|
|
|
$('#content .backup').click(configuration_backup);
|
|
|
|
|
|
|
|
$('#content .restore').click(configuration_restore);
|
|
|
|
|
|
|
|
// data pulling functions used inside interval timer
|
2014-09-18 10:54:59 +00:00
|
|
|
// this stuff will be reworked when compatibility period ends, to make the pulling more efficient
|
2014-03-22 23:28:41 +00:00
|
|
|
function get_analog_data() {
|
2014-09-18 10:54:59 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_ANALOG, false, false, get_gps_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_gps_data() {
|
|
|
|
MSP.send_message(MSP_codes.MSP_RAW_GPS, false, false, get_attitude_data);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_attitude_data() {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_ATTITUDE, false, false, update_ui);
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 10:54:59 +00:00
|
|
|
// in future update selectors will be moved outside to specific variables to increase performance
|
2014-03-22 23:28:41 +00:00
|
|
|
function update_ui() {
|
2014-09-18 10:54:59 +00:00
|
|
|
// Update heading
|
|
|
|
$('span.heading').text(chrome.i18n.getMessage('initialSetupheading', [SENSOR_DATA.kinematics[2]]));
|
|
|
|
|
2014-03-22 23:28:41 +00:00
|
|
|
// Update voltage indicator
|
2014-05-06 16:07:32 +00:00
|
|
|
$('.bat-voltage').text(chrome.i18n.getMessage('initialSetupBatteryValue', [ANALOG.voltage]));
|
2014-05-29 18:16:32 +00:00
|
|
|
$('.bat-mah-drawn').text(chrome.i18n.getMessage('initialSetupBatteryMahValue', [ANALOG.mAhdrawn]));
|
2014-05-29 23:41:27 +00:00
|
|
|
$('.bat-mah-drawing').text(chrome.i18n.getMessage('initialSetupBatteryAValue', [ANALOG.amperage.toFixed(2)]));
|
2014-05-06 16:07:32 +00:00
|
|
|
$('.rssi').text(chrome.i18n.getMessage('initialSetupRSSIValue', [((ANALOG.rssi / 1023) * 100).toFixed(0)]));
|
2014-03-22 23:28:41 +00:00
|
|
|
|
2014-09-18 10:54:59 +00:00
|
|
|
// Update gps
|
|
|
|
$('.gpsFix').html((GPS_DATA.fix) ? chrome.i18n.getMessage('gpsFixTrue') : chrome.i18n.getMessage('gpsFixFalse'));
|
|
|
|
$('.gpsSats').text(GPS_DATA.numSat);
|
|
|
|
$('.gpsLat').text((GPS_DATA.lat / 10000000).toFixed(4) + ' deg');
|
|
|
|
$('.gpsLon').text((GPS_DATA.lon / 10000000).toFixed(4) + ' deg');
|
2014-09-13 23:27:50 +00:00
|
|
|
|
|
|
|
// Update 3D
|
|
|
|
self.render3D();
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2014-09-20 11:51:23 +00:00
|
|
|
GUI.interval_add('setup_data_pull', get_analog_data, 50, true);
|
2014-03-30 09:51:16 +00:00
|
|
|
|
|
|
|
// status data pulled via separate timer with static speed
|
2014-09-16 17:27:30 +00:00
|
|
|
GUI.interval_add('status_pull', function status_pull () {
|
2014-06-01 12:10:18 +00:00
|
|
|
MSP.send_message(MSP_codes.MSP_STATUS);
|
2014-03-30 09:51:16 +00:00
|
|
|
}, 250, true);
|
2014-07-10 16:14:26 +00:00
|
|
|
|
|
|
|
if (callback) callback();
|
2014-03-22 23:28:41 +00:00
|
|
|
}
|
2014-07-10 16:14:26 +00:00
|
|
|
};
|
|
|
|
|
2014-09-20 11:51:23 +00:00
|
|
|
TABS.setup.initialize3D = function (compatibility) {
|
2014-09-24 11:45:38 +00:00
|
|
|
var self = this,
|
2014-09-30 18:25:48 +00:00
|
|
|
loader, canvas, wrapper, renderer, camera, scene, light, light2, modelWrapper, model, model_file,
|
|
|
|
fallback = false;
|
2014-09-16 17:27:30 +00:00
|
|
|
|
|
|
|
if (compatibility) {
|
2014-09-24 11:45:38 +00:00
|
|
|
canvas = $('.COMPATIBILITY #canvas');
|
|
|
|
wrapper = $('.COMPATIBILITY #canvas_wrapper');
|
2014-09-16 17:27:30 +00:00
|
|
|
} else {
|
2014-09-24 11:45:38 +00:00
|
|
|
canvas = $('.CAP_BASEFLIGHT_CONFIG #canvas');
|
|
|
|
wrapper = $('.CAP_BASEFLIGHT_CONFIG #canvas_wrapper');
|
2014-09-16 17:27:30 +00:00
|
|
|
}
|
2014-09-13 23:27:50 +00:00
|
|
|
|
2014-09-24 11:45:38 +00:00
|
|
|
if (window.WebGLRenderingContext && (canvas.get(0).getContext('webgl') || canvas.get(0).getContext('experimental-webgl'))) {
|
2014-09-14 18:38:39 +00:00
|
|
|
renderer = new THREE.WebGLRenderer({canvas: canvas.get(0), alpha: true, antialias: true});
|
|
|
|
} else {
|
|
|
|
renderer = new THREE.CanvasRenderer({canvas: canvas.get(0), alpha: true});
|
2014-09-30 18:25:48 +00:00
|
|
|
fallback = true;
|
2014-09-14 18:38:39 +00:00
|
|
|
}
|
2014-09-24 11:45:38 +00:00
|
|
|
|
2014-09-29 18:25:20 +00:00
|
|
|
// modelWrapper just adds an extra axis of rotation to avoid gimbal lock withe euler angles
|
|
|
|
modelWrapper = new THREE.Object3D()
|
|
|
|
|
|
|
|
// load the model including materials
|
2014-09-30 18:25:48 +00:00
|
|
|
if (!fallback) {
|
|
|
|
// array of supported models will go here in the future
|
|
|
|
model_file = 'quad_x';
|
|
|
|
} else {
|
|
|
|
model_file = 'fallback';
|
|
|
|
}
|
|
|
|
|
2014-09-29 18:25:20 +00:00
|
|
|
loader = new THREE.JSONLoader();
|
2014-09-30 18:25:48 +00:00
|
|
|
loader.load('./resources/models/' + model_file + '.js', function (geometry, materials) {
|
|
|
|
if (fallback) { // enable overdraw in case we use canvas renderer
|
|
|
|
for (var i = 0; i < materials.length; i++) {
|
|
|
|
materials[i].overdraw = true;
|
|
|
|
}
|
2014-09-30 15:07:44 +00:00
|
|
|
}
|
|
|
|
|
2014-09-29 18:25:20 +00:00
|
|
|
model = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));
|
|
|
|
model.scale.set(10, 10, 10);
|
|
|
|
|
|
|
|
modelWrapper.add(model);
|
|
|
|
scene.add(modelWrapper);
|
|
|
|
});
|
|
|
|
|
2014-09-24 11:45:38 +00:00
|
|
|
// stacionary camera
|
|
|
|
camera = new THREE.PerspectiveCamera(50, wrapper.width() / wrapper.height(), 1, 10000);
|
|
|
|
|
|
|
|
// setup scene
|
2014-09-29 18:25:20 +00:00
|
|
|
scene = new THREE.Scene();
|
2014-09-13 23:27:50 +00:00
|
|
|
|
|
|
|
// some light
|
2014-09-29 18:25:20 +00:00
|
|
|
light = new THREE.AmbientLight(0x404040);
|
|
|
|
light2 = new THREE.DirectionalLight(new THREE.Color(1, 1, 1), 1.5);
|
|
|
|
light2.position.set(0, 1, 0);
|
2014-09-13 23:27:50 +00:00
|
|
|
|
|
|
|
// initialize render size for current canvas size
|
|
|
|
renderer.setSize(wrapper.width(), wrapper.height());
|
|
|
|
|
|
|
|
// move camera away from the model
|
2014-09-29 18:25:20 +00:00
|
|
|
camera.position.z = 125;
|
2014-09-13 23:27:50 +00:00
|
|
|
|
|
|
|
// add camera, model, light to the foreground scene
|
2014-09-29 18:25:20 +00:00
|
|
|
scene.add(light);
|
|
|
|
scene.add(light2);
|
2014-09-13 23:27:50 +00:00
|
|
|
scene.add(camera);
|
|
|
|
scene.add(modelWrapper);
|
|
|
|
|
|
|
|
this.render3D = function () {
|
|
|
|
// compute the changes
|
|
|
|
model.rotation.x = (SENSOR_DATA.kinematics[1] * -1.0) * 0.017453292519943295;
|
|
|
|
modelWrapper.rotation.y = ((SENSOR_DATA.kinematics[2] * -1.0) - self.yaw_fix) * 0.017453292519943295;
|
|
|
|
model.rotation.z = (SENSOR_DATA.kinematics[0] * -1.0) * 0.017453292519943295;
|
|
|
|
|
|
|
|
// draw
|
|
|
|
renderer.render(scene, camera);
|
|
|
|
};
|
|
|
|
|
|
|
|
// handle canvas resize
|
|
|
|
$(window).resize(function () {
|
|
|
|
renderer.setSize(wrapper.width(), wrapper.height());
|
|
|
|
camera.aspect = wrapper.width() / wrapper.height();
|
|
|
|
camera.updateProjectionMatrix();
|
|
|
|
|
|
|
|
self.render3D();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-09-20 11:51:23 +00:00
|
|
|
TABS.setup.cleanup = function (callback) {
|
2014-09-13 23:27:50 +00:00
|
|
|
$(window).unbind('resize');
|
|
|
|
|
2014-07-10 16:14:26 +00:00
|
|
|
if (callback) callback();
|
|
|
|
};
|