PhysicsQueryContactTriangle ( query,manifold,point )
Parameters
|
query - owned query handle manifold - one-based manifold index point - one-based point index within the manifold |
Description
|
Returns the mesh or terrain triangle index of a contact, or -1. Returns the copied native zero-based mesh/terrain triangle index, or -1 for primitive-only pairs. It applies to whichever side is a mesh/terrain. No compound-child ID or material ID is supplied by this manifold field. Query results are copied and survive stepping, other queries and deletion until this query runs successfully again or is freed. Generation-checked identity getters return zero for deleted objects; copied tags and numerical fields survive. Failed runs retain the complete previous payload. Freeing the owning world frees its queries. Invalid/stale/wrong-kind handles, invalid indices or unavailable payload fields raise runtime errors. Requires Extended mode. See also: QueryPhysicsBodyContacts, QueryPhysicsShapeContacts, QueryPhysicsSensor, CountPhysicsQueryManifolds, PhysicsBodyEvents. |
Example
; PhysicsQueryContactTriangle Example ; ----------------------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() Const PHYSICS_STATIC=0 Const PHYSICS_DYNAMIC=2 camera=CreateCamera() PositionEntity camera,0,3,-7 RotateEntity camera,20,0,0 light=CreateLight() RotateEntity light,45,-30,0 AmbientLight 60,60,60 ; An independent Box3D world with standard gravity world=CreatePhysicsWorld() ; Blue static floor ground=CreateCube() ScaleEntity ground,6,0.5,6 PositionEntity ground,0,-0.5,0 EntityColor ground,80,160,255 ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC) ground_shape=PhysicsBodyBox(ground_body,12,1,12) ; A static mesh ramp made of 8 strips, each strip two triangles ramp=CreateMesh() surface=CreateSurface(ramp) For strip=0 To 7 x#=strip-4 AddVertex surface,x,1.6-strip*0.2,-1.5 AddVertex surface,x,1.6-strip*0.2,1.5 AddVertex surface,x+1,1.4-strip*0.2,-1.5 AddVertex surface,x+1,1.4-strip*0.2,1.5 AddTriangle surface,strip*4,strip*4+1,strip*4+3 AddTriangle surface,strip*4,strip*4+3,strip*4+2 Next UpdateNormals ramp EntityFX ramp,2 ramp_body=CreatePhysicsBody(world,ramp,PHYSICS_STATIC) ramp_shape=PhysicsBodyMesh(ramp_body,ramp) ; Slot 2 of the ramp's material table is ice, with no friction PhysicsShapeMaterials ramp_shape,2 PhysicsShapeMaterialFriction ramp_shape,2,0 query=CreatePhysicsQuery(world) ; Crates resting on the grippy ramp Dim crate_bodies(3) For i=0 To 3 crate=CreateCube() ScaleEntity crate,0.3,0.3,0.3 EntityColor crate,255,120,70 crate_bodies(i)=CreatePhysicsBody(world,crate,PHYSICS_DYNAMIC) crate_shape=PhysicsBodyBox(crate_bodies(i),0.6,0.6,0.6) ResetPhysicsBody crate_bodies(i),-3.5+i*2,2-i*0.4,0,0,0,-0.2 Next PaintStrips(ramp,painted) While Not KeyDown(1) ; Space paints the next strip as ice, so the crates slide If KeyHit(57) And painted<8 PhysicsMeshTriangleMaterial ramp_shape,painted*2,2,2 painted=painted+1 PaintStrips(ramp,painted) EndIf StepPhysics world,1.0/60.0,4 ; Copy the first crate's contact with the ramp, and find which side is the ramp manifolds=QueryPhysicsBodyContacts(query,crate_bodies(0)) side=1 If manifolds>0 If PhysicsQueryContactBody(query,1,2)=ramp_body Then side=2 EndIf ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Arrow keys: move camera Space: paint ice Esc: exit" If manifolds>0 Then Text 0,20,"PhysicsQueryContactTriangle(query,1,1) = "+PhysicsQueryContactTriangle(query,1,1) Text 0,20,"(the first crate sits on strip 0, triangles 0 and 1)" Flip Wend FreePhysicsWorld world End Function PaintStrips(ramp,painted) ; Ice strips are pale blue, grippy strips are green surface=GetSurface(ramp,1) For v=0 To CountVertices(surface)-1 If v/4<painted VertexColor surface,v,200,230,255 Else VertexColor surface,v,120,200,140 EndIf Next End Function
Index