Blitz3D+ Command Reference

MeshesIntersect ( mesh_a,mesh_b )

Parameters

mesh_a - handle of the first mesh
mesh_b - handle of the second mesh

Description

Returns true if two meshes are currently intersecting.

This is an exact, triangle-level test using each mesh's current position, rotation and scale - the only polygon-to-polygon check in Blitz3D+. Where the ellipsoid-based Collisions system approximates the moving entity as a blob, MeshesIntersect answers whether the actual geometry overlaps right now - a sword blade meeting a shield, a part clipping through a wall in a building game.

Being exact makes it slow: cost rises with the triangle counts, so keep it for a few important pairs per frame rather than everything against everything. It is also a yes/no answer only - there are no coordinates, normals or response, and fast-moving objects can pass through each other between checks. For gameplay-wide collision handling, the Collisions/UpdateWorld system remains the tool.

See also: Collisions, CountCollisions, EntityBox, EntityRadius, LinePick.

Example

; MeshesIntersect Example
; -----------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

; NOTE: fixed camera - the arrow keys steer the oil drum in this example
camera=CreateCamera()
PositionEntity camera,0,6,-10
RotateEntity camera,25,0,0

light=CreateLight()
RotateEntity light,60,30,0

floor=CreatePlane()
EntityColor floor,70,90,110

; Load two detailed meshes and size each to a friendly 2-unit box
drum=LoadMesh("media/oil-drum/oildrum.3ds")
FitMesh drum,-1,0,-1,2,2,2,True
PositionEntity drum,-4,0,3

crate=LoadMesh("media/wood-crate/wcrate1.3ds")
FitMesh crate,-1,0,-1,2,2,2,True
PositionEntity crate,0,0,3

While Not KeyDown(1)

    ; Arrow keys steer the drum
    If KeyDown(200) Then MoveEntity drum,0,0,0.1
    If KeyDown(208) Then MoveEntity drum,0,0,-0.1
    If KeyDown(203) Then MoveEntity drum,-0.1,0,0
    If KeyDown(205) Then MoveEntity drum,0.1,0,0

    ; The crate slowly spins on the spot
    TurnEntity crate,0,1,0

    ; MeshesIntersect is a true polygon-to-polygon test - the only one in
    ; Blitz3D. The docs warn: "This is a fairly slow routine - use with
    ; discretion..." (fine for two small meshes like these)
    hit=MeshesIntersect(drum,crate)

    ; Tint the crate red while the meshes overlap
    If hit Then EntityColor crate,255,80,80 Else EntityColor crate,255,255,255

    RenderWorld

    Text 0,0,"Arrow keys: drive the drum into the crate   Esc: exit"
    Text 0,20,"MeshesIntersect(drum,crate) = "+hit

    Flip

Wend

End

Index