forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_into_poly.py
More file actions
48 lines (35 loc) · 1.69 KB
/
test_into_poly.py
File metadata and controls
48 lines (35 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from collisions import *
def test_box_into_poly():
box = CollisionBox((0, 0, 0), 2, 3, 4)
poly = CollisionPolygon(Point3(0, 0, 0), Point3(0, 0, 1), Point3(0, 1, 1), Point3(0, 1, 0))
entry = make_collision(box, poly)[0]
assert entry is not None
assert entry.get_from() == box
assert entry.get_into() == poly
# Colliding just on the edge
entry, np_from, np_into = make_collision(CollisionBox((0, 3, 0), 1, 2, 1), poly)
assert entry.get_surface_point(np_from) == Point3(0, 3, 0)
assert entry.get_surface_normal(np_into) == Vec3(-1, 0, 0) # Testing surface normal
# No collision
entry = make_collision(CollisionBox((10, 10, 10), 8, 9, 10), poly)[0]
assert entry is None
def test_sphere_into_poly():
sphere = CollisionSphere(0, 0, 0, 1)
poly = CollisionPolygon(Point3(0, 0, 0), Point3(0, 0, 1), Point3(0, 1, 1), Point3(0, 1, 0))
entry = make_collision(sphere, poly)[0]
assert entry is not None
assert entry.get_from() == sphere
assert entry.get_into() == poly
# Colliding just on the edge
entry, np_from, np_into = make_collision(CollisionSphere(0, 0, 3, 2), poly)
assert entry.get_surface_point(np_from) == Point3(0, 0, 3)
assert entry.get_surface_normal(np_into) == Vec3(-1, 0, 0) # Testing surface normal
# No collision
entry = make_collision(CollisionSphere(100, 100, 100, 100), poly)[0]
assert entry is None
def test_plane_into_poly():
# CollisionPlane is not a 'from' object
plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
poly = CollisionPolygon(Point3(0, 0, 0), Point3(0, 0, 1), Point3(0, 1, 1), Point3(0, 1, 0))
entry = make_collision(plane, poly)[0]
assert entry is None