You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setup the build environment as described here, then:
$ git clone https://github.com/stetre/moonccd/
$ cd moonccd
moonccd$ make
moonccd$ sudo make install
Example
The example below shows a simple collision detection between two box objects.
Other examples can be found in the examples/ directory.
-- MoonCCD example: hello.lualocalccd=require("moonccd")
-- Support function for box objects:localfunctionsupport(obj, dir)
-- Assume obj is a user defined table containing info about the object,-- in this case a box: obj = { pos, quat, x, y, z } where pos is the-- position, quat is the rotation, and x, y, z are the dimensions.-- Apply the rotation on direction vector:localqinv=ccd.qinvert(obj.quat)
localdir=ccd.vrotate(dir, qinv)
-- Compute the support point in the specified direction:localv= { 0.5*ccd.sign(dir[1])*obj.x,
0.5*ccd.sign(dir[2])*obj.y,
0.5*ccd.sign(dir[3])*obj.z }
-- Transform support point according to the rotation of the object and return itv=ccd.vrotate(v, obj.quat)
v=ccd.vadd(v, obj.pos)
returnvend-- Create two box objects:localbox1= { pos={-5, 0, 0}, quat={1, 0, 0, 0}, x=1, y=2, z=1 }
localbox2= { pos={ 0, 0, 0}, quat={1, 0, 0, 0}, x=2, y=1, z=2 }
-- Create and initialize the ccd parameters:localccdpar=ccd.new({
support1=support, -- support function for first objectsupport2=support, -- support function for second objectmax_iterations=100, -- maximum number of iterations
})
fori=0, 99dolocalintersect=ccd.gjk_intersect(ccdpar, box1, box2)
-- now intersect is true if the two boxes intersect, false otherwise-- print(i, intersect, box1.pos[1], box2.pos[1])ifi<35ori>65thenassert(notintersect)
elseifi~=35andi~=65thenassert(intersect)
end-- move first box along the x axis:box1.pos[1] =box1.pos[1] +0.1end
The script can be executed at the shell prompt with the standard Lua interpreter: