quadTest
by Konstantin Cryman
JavaScript
var getDirectionForApplyToQuad = function( engPowerArray ) {
var quadrocopter = [ {
position: new THREE.Vector3( 5, 0, 5 ),
impulse: new THREE.Vector3( 0, engPowerArray[0], 0 )
},{
position: new THREE.Vector3( -5, 0, 5 ),
impulse: new THREE.Vector3( 0, engPowerArray[1], 0 )
}, {
position: new THREE.Vector3( -5, 0, -5 ),
impulse: new THREE.Vector3( 0, engPowerArray[2], 0 )
},{
position: new THREE.Vector3( 5, 0, -5 ),
impulse: new THREE.Vector3( 0, engPowerArray[3], 0 )
}
];
var currentVector = new THREE.Vector3( 0, 0, 0 );
var totalPower = 0;
var powerCoefitient = 0.01;
for( var i = 0; i < quadrocopter.length; i++ ){
var eng = {
d: quadrocopter[i].position.clone().distanceTo( new THREE.Vector3( 0, 0, 0 ) ),
n: ( function(){
var norm = quadrocopter[i].position.clone();
norm.normalize();
return norm;
} )(),
i: quadrocopter[i].impulse.clone()
}
var currentEngRotationPower = eng.d * eng.i.y / 4;
totalPower += currentEngRotationPower;
var currentEngRotationDirection = eng.n.clone();
currentEngRotationDirection.multiplyScalar( currentEngRotationPower/10 );
currentVector.addSelf( currentEngRotationDirection );
}
totalPower *= powerCoefitient;
var _impulse = new THREE.Vector3( 0, totalPower, 0 );
_impulse.addSelf( currentVector )
console.log( _impulse );
};
getDirectionForApplyToQuad( [ 0, 0, 0, 5 ] );