base/vector3
3차원 벡터. (원본 base/vector3.js)
- 원본은 x, y, z 를 감춘 필드와 프로퍼티로 두지만, 러스트 판은 Vector2 처럼 공개 필드를 둔 Copy 값이다. 원본 clone 은 복사로, equals 는 PartialEq 로 갈음한다.
- 원본 add / subtract / multiply / divide 는 수와 Vector3 를 다 받는다. 러스트 판은 Vector3 를 받는 것과 수를 받는 ...Scalar 로 나눴다. (Vector2 의 multiply_scalar 와 같은 꼴)
- 수는 원본 자바스크립트 수처럼 f64 다.
- lerp 는 원본 math.lerp 식(from * (1 - t) + to * t)을 그대로 쓴다. 러스트 math::lerp(from + (to - from) * t)와 끝자리가 다를 수 있어서 따로 계산한다.
3D vector. (the original base/vector3.js)
- The original keeps x, y, z as hidden fields with properties, but the Rust version is a Copy value with public fields like Vector2. The original clone is replaced by copying, and equals by PartialEq.
- The original add / subtract / multiply / divide accept both numbers and Vector3. The Rust version splits them into ones taking Vector3 and ...Scalar ones taking numbers. (the same shape as Vector2's multiply_scalar)
- Numbers are f64 like the original JavaScript numbers.
- lerp uses the original math.lerp formula (from * (1 - t) + to * t) as is. It may differ in the last digits from the Rust math::lerp (from + (to - from) * t), so it is computed separately.
Vector3struct traits Clone, Copy, Debug, Default, PartialEq, Add, Sub, Mul<f64>, AddAssign, SubAssign
3차원 벡터. (x, y, z 를 공개 필드로 둔 Copy 값, 계산 함수는 자신을 바꾸지 않고 새 벡터를 돌려준다)
3D vector. (a Copy value with x, y, z as public fields; computing functions return a new vector without changing self)
use vanilla::Vector3;
let position = Vector3::create(1.0, 2.0, 2.0);
assert_eq!(position.length(), 3.0);
let moved = position.add(Vector3::up());
assert_eq!(moved, Vector3::create(1.0, 3.0, 2.0));
let axis_x = Vector3::create(1.0, 0.0, 0.0);
let axis_z = Vector3::create(0.0, 0.0, 1.0);
assert_eq!(axis_x.cross(Vector3::up()), axis_z);
let mut velocity = Vector3::zero();
velocity += Vector3::one() * 2.0;
assert_eq!(velocity, Vector3::create(2.0, 2.0, 2.0));생성.
Constructor.
- xf64
- x 성분.x component.
- yf64
- y 성분.y component.
- zf64
- z 성분.z component.
반환ReturnsVector3 (x, y, z) 벡터.The vector (x, y, z).
짝Counterpart: vanilla.js Vector3.create
영벡터. (0, 0, 0)
Zero vector. (0, 0, 0)
반환ReturnsVector3 세 성분이 0 인 벡터.A vector with all three components 0.
짝Counterpart: vanilla.js Vector3.zero
일벡터. (1, 1, 1)
One vector. (1, 1, 1)
반환ReturnsVector3 세 성분이 1 인 벡터.A vector with all three components 1.
짝Counterpart: vanilla.js Vector3.one
위쪽 단위벡터. (0, 1, 0)
Up unit vector. (0, 1, 0)
반환ReturnsVector3 (0, 1, 0) 벡터.A (0, 1, 0) vector.
짝Counterpart: vanilla.js Vector3.up
선형 보간. (원본 math.lerp 식: from * (1 - t) + to * t)
Linear interpolation. (the original math.lerp formula: from * (1 - t) + to * t)
- fromVector3
- 시작 벡터.Start vector.
- toVector3
- 끝 벡터.End vector.
- normalized_timef64
- 보간 비율. (0 이면 from, 1 이면 to, 0 ~ 1 밖도 자르지 않고 늘여 잇는다)Interpolation ratio. (0 is from, 1 is to; values outside 0 ~ 1 are not clamped and extrapolate)
반환ReturnsVector3 보간한 새 벡터.A new interpolated vector.
짝Counterpart: vanilla.js Vector3.lerp
use vanilla::Vector3;
let from = Vector3::create(0.0, 10.0, -4.0);
let to = Vector3::create(8.0, 0.0, 4.0);
assert_eq!(Vector3::lerp(from, to, 0.25), Vector3::create(2.0, 7.5, -2.0));
assert_eq!(Vector3::lerp(from, to, 1.0), to);대입.
Assignment.
- xf64
- 넣을 x 성분.x component to set.
- yf64
- 넣을 y 성분.y component to set.
- zf64
- 넣을 z 성분.z component to set.
짝Counterpart: vanilla.js Vector3.set
가로축 반환.
Returns the horizontal axis.
반환Returnsf64 x 성분.x component.
짝Counterpart: vanilla.js Vector3.getX
세로축 반환.
Returns the vertical axis.
반환Returnsf64 y 성분.y component.
짝Counterpart: vanilla.js Vector3.getY
길이.
Length.
반환Returnsf64 벡터의 길이. (0 이상)Length of the vector. (0 or more)
짝Counterpart: vanilla.js Vector3.length
길이 제곱.
Squared length.
반환Returnsf64 x * x + y * y + z * z. (제곱근을 셈하지 않는다)x * x + y * y + z * z. (no square root is computed)
짝Counterpart: vanilla.js Vector3.lengthSquared
정규화. (길이가 0 이하이면 그대로 복사해 돌려준다)
Normalization. (returns a copy as is if the length is 0 or less)
반환ReturnsVector3 길이가 1 인 새 벡터. 길이가 0 이하이면 자신과 같은 값.A new vector of length 1. The same value as self if the length is 0 or less.
짝Counterpart: vanilla.js Vector3.normalize
use vanilla::Vector3;
let direction = Vector3::create(0.0, 3.0, 4.0).normalize();
assert_eq!(direction, Vector3::create(0.0, 0.6, 0.8));
assert_eq!(Vector3::zero().normalize(), Vector3::zero());더하기.
Add.
- otherVector3
- 더할 벡터.Vector to add.
반환ReturnsVector3 성분별로 더한 새 벡터. (자신은 바뀌지 않는다)A new vector added per component. (self is not changed)
짝Counterpart: vanilla.js Vector3.add
세 성분에 같은 수를 더하기. (원본 add(number))
Adds the same number to all three components. (the original add(number))
- scalarf64
- 세 성분에 더할 수.Number to add to all three components.
반환ReturnsVector3 더한 새 벡터.The new added vector.
짝Counterpart: vanilla.js Vector3.addScalar
빼기.
Subtract.
- otherVector3
- 뺄 벡터.Vector to subtract.
반환ReturnsVector3 성분별로 뺀 새 벡터. (self - other)A new vector subtracted per component. (self - other)
짝Counterpart: vanilla.js Vector3.subtract
세 성분에서 같은 수를 빼기. (원본 subtract(number))
Subtracts the same number from all three components. (the original subtract(number))
- scalarf64
- 세 성분에서 뺄 수.Number to subtract from all three components.
반환ReturnsVector3 뺀 새 벡터.The new subtracted vector.
짝Counterpart: vanilla.js Vector3.subtractScalar
성분별 곱하기.
Per-component multiplication.
- otherVector3
- 성분별로 곱할 벡터.Vector to multiply per component.
반환ReturnsVector3 성분별로 곱한 새 벡터.A new vector multiplied per component.
짝Counterpart: vanilla.js Vector3.multiply
스칼라 곱하기. (원본 multiply(number))
Scalar multiplication. (the original multiply(number))
- scalarf64
- 세 성분에 곱할 수.Number to multiply all three components by.
반환ReturnsVector3 곱한 새 벡터.The new multiplied vector.
짝Counterpart: vanilla.js Vector3.multiplyScalar
성분별 나누기.
Per-component division.
- otherVector3
- 성분별로 나눌 벡터. (0 인 성분은 무한대나 NaN 이 된다)Vector to divide by per component. (components that are 0 give infinity or NaN)
반환ReturnsVector3 성분별로 나눈 새 벡터.A new vector divided per component.
짝Counterpart: vanilla.js Vector3.divide
스칼라 나누기. (원본 divide(number))
Scalar division. (the original divide(number))
- scalarf64
- 세 성분을 나눌 수. (0 이면 무한대나 NaN 이 된다)Number to divide all three components by. (0 gives infinity or NaN)
반환ReturnsVector3 나눈 새 벡터.The new divided vector.
짝Counterpart: vanilla.js Vector3.divideScalar
내적.
Dot product.
- otherVector3
- 내적할 벡터.Vector for the dot product.
반환Returnsf64 내적 값. (x * other.x + y * other.y + z * other.z)Dot product. (x * other.x + y * other.y + z * other.z)
짝Counterpart: vanilla.js Vector3.dot
외적. (오른손 좌표계: x 축 외적 y 축 = z 축)
Cross product. (right-handed coordinate system: x axis cross y axis = z axis)
- otherVector3
- 오른쪽에 둘 벡터. (self 외적 other)Vector placed on the right. (self cross other)
반환ReturnsVector3 두 벡터에 수직인 새 벡터. (길이는 두 길이의 곱 x 사이 각의 사인)A new vector perpendicular to both vectors. (length is the product of the two lengths x the sine of the angle between them)
짝Counterpart: vanilla.js Vector3.cross
use vanilla::Vector3;
let axis_x = Vector3::create(1.0, 0.0, 0.0);
let axis_y = Vector3::up();
let axis_z = Vector3::create(0.0, 0.0, 1.0);
assert_eq!(axis_x.cross(axis_y), axis_z);
assert_eq!(axis_y.cross(axis_x), Vector3::create(0.0, 0.0, -1.0));두 점 사이 거리.
Distance between two points.
- otherVector3
- 거리를 잴 점.Point to measure the distance to.
반환Returnsf64 두 점 사이 거리. (0 이상)Distance between the two points. (0 or more)
짝Counterpart: vanilla.js Vector3.distance