Hello. Sorry for the stupid question, but how to do arithmetic operations with vectors as in mono. Perhaps you can somehow expand the list of standard vector methods or something.
let vec1: BABYLON.Vector3 = new BABYLON.Vector3(1, 2, 3);
let vec2: BABYLON.Vector3 = new BABYLON.Vector3(3, 2, 1);
let vec3: BABYLON.Vector3 = new BABYLON.Vector3(2, 3, 1);
let result = vec1 * vec2 * vec3 + 1; //mono
let result = vec1.multiply(vec2).multiply(vec3).add(1 /*?*/); //babylon
Thank you answer. Could you show how such a code would look using the babylon’s vectors?
I think I don’t understand something, because I get something that looks awful.
private BezierTo4Point(t: number, p0: BABYLON.Vector3, p1: BABYLON.Vector3, p2: BABYLON.Vector3, p3: BABYLON.Vector3): BABYLON.Vector3 {
let a = BABYLON.Vector3.Zero;
let d = 1 - t;
// how?
a += p0 * d * d * d;
a += p1 * t * 3 * d * d;
a += p2 * 3 * t * t * d;
return a + p3 * t * t * t;
}
Thanks, I seem to have done.
let result = new BABYLON.Vector3();
let d = 1 - t;
p0.scaleAndAddToRef(d * d * d, result);
p1.scaleAndAddToRef(t * 3 * d * d, result);
p2.scaleAndAddToRef(3 * t * t * d, result);
p3.scaleAndAddToRef(t * t * t, result);
return result;
Not great for production builds though, but you can use it as a standalone tool or make a script post-processor that replaces the eval lines with the expanded code.
I tried to translate it, but did not find the Quaternion.Angle and RotateTowards functions in the babylonjs library. Perhaps they are called somehow differently?
public static AngleTo(a: BABYLON.Quaternion, b: BABYLON.Quaternion): number {
return ??
}
public static RotateTowards(from: BABYLON.Quaternion, to: BABYLON.Quaternion, maxDegreesDelta: number): BABYLON.Quaternion {
let num: number = AngleTo(from, to);
if (num == 0.0) {
return to;
}
let amount: number = Math.min(1.0, maxDegreesDelta / num);
return BABYLON.Quaternion.Slerp(from, to, amount);
}