Collision-detection-related program code.
These functions and classes use the Vector class from dmsgl.py.
| Sphere | functions | Sphere(center=[0,0,0], radius=1) |
| setCenter(center) | ||
| draw() | ||
| drawWireframe() | ||
| variables | center (Vector) | |
| radius (float) |
| AABB | functions | AABB(min=[-1,-1,-1], max=[1,1,1]) |
| draw() | ||
| drawWireframe() | ||
| variables | min (3 element list) | |
| max (3 element list) |
| OBB | functions | OBB(center=[0,0,0], u=[1,0,0], v=[0,1,0], w=[0,0,1]) |
| setCenter(center) | ||
| setAxes(u,v,w) | ||
| draw() | ||
| drawWireframe() | ||
| variables | center (Vector) | |
| u (Vector) | ||
| v (Vector) | ||
| w (Vector) |
| Line | functions | Line(origin=[0,0,0], direction=[0,0,1]) |
| setOrigin(origin) | ||
| setDirection(direction) | ||
| draw(t0=0, t1=1) | ||
| drawWireframe(t0=0, t1=1) | ||
| variables | origin (Vector) | |
| direction (Vector) |
| Segment | functions | Segment(origin=[0,0,0], point2=None, direction=[0,0,1], length=1) |
| setOrigin(origin) | ||
| setDirection(direction) | ||
| draw() | ||
| drawWireframe() | ||
| variables | origin (Vector) | |
| direction (Vector) | ||
| length (float) |
| Plane | functions | Plane(coeffs=[0,0,1,0]) |
| value(point) | ||
| draw(width=1, height=1) | ||
| drawWireframe(width=1, height=1) | ||
| variables | coeffs (4 element list) |
A spherical volume - consists of a center and a radius.
Sphere(center, radius)
Constructor. The center should be a 3-element list or Vector; the radius is
a single floating point value.
Defaults are center=[0,0,0], radius=1
Example:
s = Sphere([5, 0, -1.5], 2.2) s.radius = 3
setCenter(center)
Changes the center position of a sphere. The argument should be a 3-element
list or Vector. This function is provided to ensure that the member
variable center is always a Vector.
Example:
s.setCenter([-5, 0.1, 0])
draw()
Renders the sphere volume, using glutSolidSphere().
Example:
glColor3f(1, 0, 0) s.draw()
drawWireframe()
Renders the sphere volume in wireframe, using glutWireSphere().
Example:
glColor3f(1, 0, 0) s.drawWireframe()
An axis-aligned bounding box volume. Has two member variables, min & max, which are 3-element lists with the minimum X/Y/Z values and the maximum X/Y/Z values.
Example: