base/obb
회전된 바운딩 박스. (원본 base/obb.js)
- 원본과 같이 2D 다. 꼭짓점 4 개(원본 이름은 edges)를 차례로 이은 볼록 사각형이다.
- contains 는 원본과 같은 반직선 교차 판정이다. 왼쪽, 위 변 위의 점은 안이고 오른쪽, 아래 변 위의 점은 밖이다.
- overlaps 는 원본과 같은 분리축 정리(SAT)다. 두 사각형의 변 법선마다 양쪽 꼭짓점(get_edges)을 투영하고, 맞닿기만 해도 겹친 것으로 친다. (< 비교)
- 원본 setEdges 는 null, 배열 아님, 길이 다름을 예외로 막는다. 러스트 판은 [Vector2; 4] 타입이 그 일을 한다.
Oriented bounding box. (the original base/obb.js)
- 2D as in the original. A convex quadrilateral joining 4 corners (named edges in the original) in order.
- contains is the same ray crossing test as the original. Points on the left and top edges are inside, points on the right and bottom edges are outside.
- overlaps is the same separating axis theorem (SAT) as the original. Projects both sets of corners (get_edges) onto each edge normal of the two rectangles, and counts merely touching as overlapping. (< comparison)
- The original setEdges blocks null, non-arrays and wrong lengths with exceptions. In the Rust version, the [Vector2; 4] type does that job.
OBBstruct traits Clone, Copy, Debug, Default, PartialEq
회전된 바운딩 박스. (2D, 꼭짓점 4 개를 차례로 이은 볼록 사각형)
Oriented bounding box. (2D, a convex quadrilateral joining 4 corners in order)
use vanilla::{Vector2, OBB};
let mut square = OBB::new();
square.set_edges([Vector2::create(0.0, 0.0), Vector2::create(10.0, 0.0), Vector2::create(10.0, 10.0), Vector2::create(0.0, 10.0)]);
let mut diamond = OBB::new();
diamond.set_edges([Vector2::create(5.0, -2.0), Vector2::create(12.0, 5.0), Vector2::create(5.0, 12.0), Vector2::create(-2.0, 5.0)]);
assert!(square.contains(Vector2::create(5.0, 5.0)));
assert!(!square.contains(Vector2::create(11.0, 5.0)));
assert!(square.overlaps(&diamond));생성. (꼭짓점은 모두 (0, 0))
Constructor. (all corners (0, 0))
반환ReturnsOBB 꼭짓점 4 개가 모두 (0, 0) 인 OBB.An OBB with all 4 corners at (0, 0).
짝Counterpart: vanilla.js OBB.constructor
점이 안에 있는지. (반직선 교차 판정)
Whether a point is inside. (ray crossing test)
- view_positionVector2
- 판정할 점. (꼭짓점과 같은 좌표계)Point to test. (in the same coordinate system as the corners)
반환Returnsbool 안에 있으면 true. (축 정렬 사각형이면 왼쪽, 위 변 위의 점은 안, 오른쪽, 아래 변 위의 점은 밖)true if inside. (for an axis-aligned rectangle, points on the left and top edges are inside, points on the right and bottom edges are outside)
짝Counterpart: vanilla.js OBB.contains
use vanilla::{Vector2, OBB};
let mut square = OBB::new();
square.set_edges([Vector2::create(0.0, 0.0), Vector2::create(10.0, 0.0), Vector2::create(10.0, 10.0), Vector2::create(0.0, 10.0)]);
assert!(square.contains(Vector2::create(0.0, 5.0)));
assert!(!square.contains(Vector2::create(10.0, 5.0)));
assert!(!square.contains(Vector2::create(5.0, 10.0)));다른 OBB 와 겹치는지. (분리축 정리, 두 사각형의 모든 변 법선에 투영해 본다)
Whether it overlaps another OBB. (separating axis theorem, projects onto every edge normal of both rectangles)
- other&OBB
- 겹침을 볼 OBB.OBB to check overlap with.
반환Returnsbool 겹치거나 맞닿으면 true. 두 사각형의 변 법선 가운데 하나라도 분리축이면 false.true if overlapping or touching. false if any edge normal of the two rectangles is a separating axis.
짝Counterpart: vanilla.js OBB.overlaps
use vanilla::{Vector2, OBB};
let mut left = OBB::new();
left.set_edges([Vector2::create(0.0, 0.0), Vector2::create(10.0, 0.0), Vector2::create(10.0, 10.0), Vector2::create(0.0, 10.0)]);
let mut right = OBB::new();
right.set_edges([Vector2::create(10.0, 0.0), Vector2::create(20.0, 0.0), Vector2::create(20.0, 10.0), Vector2::create(10.0, 10.0)]);
let mut far = OBB::new();
far.set_edges([Vector2::create(30.0, 0.0), Vector2::create(40.0, 0.0), Vector2::create(40.0, 10.0), Vector2::create(30.0, 10.0)]);
assert!(left.overlaps(&right));
assert!(!left.overlaps(&far));꼭짓점 목록 설정.
Sets the corner list.
- edges[Vector2; 4]
- 꼭짓점 4 개. (차례로 이으면 볼록 사각형이 되는 순서)4 corners. (in an order that forms a convex quadrilateral when joined in sequence)
짝Counterpart: vanilla.js OBB.setEdges
꼭짓점 목록 반환.
Returns the corner list.
반환Returns&[Vector2; 4] 꼭짓점 4 개의 읽기 참조.Read reference to the 4 corners.
짝Counterpart: vanilla.js OBB.getEdges