问题描述:

I would like to multiply:

vectorDiff = placementPosition.sub(viewerPosition);

by 10, so that when "model" is moved:

moveModel(vectorDiff, "GPS");

it moves 10 times more than it is currently. How do i do this; im new to javascript any help would be greatly appreciated. The following is the code block the above is located in:

if ( viewerPosition !== null && placementPosition!== null) {

vectorDiff = placementPosition.sub(viewerPosition);

rotationSum = new THREE.Vector3().addVectors(placementRotation, viewerRotation)

//rotationSum.setY(rotationSum.y+180);

moveModel(vectorDiff, "GPS");

//rotateModel(rotationSum, "GPS");

网友答案:

Three.js vectors are mutable; when you call v1.sub(v2), v1 contains the result:

var v1 = new THREE.Vector3(2,3,4);
var v2 = new THREE.Vector3(1,0,3);

v1.sub(v2);
console.log(v1.toArray())
// [1, 3, 1]

Therefore "the result of subtracting one value from another" is just "the first vector". You need a way to multiply that vector by a single number, or scalar.

That method is multiplyScalar:

v1.multiplyScalar(10);
console.log(v1.toArray());
// [4, 12, 4]

JSBin

Three.js docs for Vector3

相关阅读:
Top