WereChipmunk LUA binding for Chipmunk - Testers required!

Share your projects and Chipmunk enhancements.
Post Reply
chris_c
Posts: 6
Joined: Thu Aug 13, 2009 12:02 pm
Contact:

WereChipmunk LUA binding for Chipmunk - Testers required!

Post by chris_c »

I'm writing a wrapper for Chipmunk manually using C (not C++!) for the embedded language Lua.
I'm plodding through the user docs wrapping what I find, and I have these types implemented
for Lua

cpVect
cpBB
cpBody
cpShapeClass
cpCircleShape
cpSegmentShape


I'm a fair way in as you can see from the sample Lua code below (that actually executes!)

I'd like to be able to release it in a complete form *with* running examples, I'm just one person so
I could really do with some people who can code in Lua and know Chipmunk - and can give
the wrapper a good testing and produce simple clear working examples...

Please *do* contact me directly if you are interested in helping me!

Thanks!!!

Code: Select all

print('cpVect struct and routines encapsulation')
a=cpVect.new(1.1,2.2)
print(a:getx(),a:gety())
b=cpVect.new(2,4)
a=a+b
print(a:getx(),a:gety(),'(gc "old" a)')
collectgarbage()
a=0
b=0
print('gc a & b')
collectgarbage()
z=cpVect.new()
x=cpVect.new(-3,-2)
y=z:sub(x)
print('y ',y:getx(),y:gety())
y:normalize()
print('y normalise',y:getx(),y:gety())
z=z-x
print('z-x ',z:getx(),z:gety())
z:neg()
print('z neg ',z:getx(),z:gety())
z:mult(0.9)
print('z mult',z:getx(),z:gety())
z:neg()
print('z neg ',z:getx(),z:gety())
print('z dot y',z:dot(y))
print('z cross y',z:cross(y))
z:perp()
print('z perp',z:getx(),z:gety())

z=cpVect.new(2,4)
print('z',z:getx(),z:gety())
y:project(z)
print('y projected onto z',y:getx(),y:gety())

z:rotate(y)
print('z rotated by y',z:getx(),z:gety())
z:unrotate(y)
print('z unrotated by y',z:getx(),z:gety())
print('z length',z:length())
print('z lengthsq',z:lengthsq())
z:lerp(y,0.2)
print('z lerp y by 0.2',z:getx(),z:gety())
z:clamp(0.99)
print('z clamp 0.99',z:getx(),z:gety())
z=cpVect.new(y)
print('y=',y:getx(),y:gety())
print('z=cpVect.new(y)',z:getx(),z:gety())
z:normalize()
print('z normalise',z:getx(),z:gety())
z:normalize_safe()
print('z normalise_safe',z:getx(),z:gety())
y=cpVect.new(10,10)
print('y',y:getx(),y:gety())

print('distance z to y',z:dist(y))
print('distsq z to y',z:distsq(y))

print('z,y distance closer than 15',z:near(y,15))
print('z,y distance closer than 14',z:near(y,14))
print('z,y distance closer than 13',z:near(y,13))
print('z,y distance closer than 12',z:near(y,12))

z=cpVect.new(3.141)
print('vector of 3.141 radians',z:getx(),z:gety())
print('z toangle',z:toangle())
-- left,bottom,right,top ??
a=cpBB.new(0,0,100,100)
b=cpBB.new(10,10,80,80) -- inside a
c=cpBB.new(0,0,150,150) -- intersects a
d=cpBB.new(200,200,150,150) -- outside a

print("a intersects b",a:intersects(b))
print("a intersects c",a:intersects(c))
print("a intersects d",a:intersects(d))

print("a contains b",a:containsBB(b))
print("a contains c",a:containsBB(c))
print("a contains d",a:containsBB(d))

y=cpVect.new(50,50)
z=cpVect.new(200,200)
print("a contains y",a:containsVect(y))
print("a contains z",a:containsVect(z))
z=cpVect.new(-150,150)
print("z",z:getx(),z:gety())
a:clampVect(z)
print("a clamping z",z:getx(),z:gety())
z=cpVect.new(-150,150)
a:wrapVect(z)
print("a wrapping z",z:getx(),z:gety())
-- TODO setters and getters for cpBB l,b,r,t ????

b=cpBody.new(10,0.1)
b:setMass(20)
b:setMoment(0.5)
b:setAngle(3.141)
b:setPos(cpVect.new(10,20))
b:setForce(cpVect.new(0.6,0.5))
b:setAngVel(0.004)
b:setTorque(0.2)

print("mass",b:getMass())
print("moment",b:getMoment())
print("angle",b:getAngle())
print("angvel",b:getAngVel())
print("torque",b:getTorque())
p=b:getPos()
print("pos",p:getx(),p:gety())
p=b:getVel()
print("vel",p:getx(),p:gety())
p=b:getForce()
print("Force",p:getx(),p:gety())
p=b:getRot()
print("rot",p:getx(),p:gety())


p=b:getLocal2World(cpVect.new(0.12,0.34))
print("local2world",p:getx(),p:gety())
p=b:getWorld2Local(p)
print("World2Local",p:getx(),p:gety())

b:applyImpulse(cpVect.new(1,0),cpVect.new(0.5,0.5))
p=b:getVel()
print("vel",p:getx(),p:gety())
b:resetForces()

b:applyForce(cpVect.new(1,0),cpVect.new(0.5,0.5))
p=b:getForce()
-- TODO implement test case for applyDampedSpring!

-- body,radius,offset
cs=cpCircleShape.new(b,1.5,cpVect.new(0.1,0.2))
print("radius",cs:getRadius())
p=cs:getOffset()
print("offset ",p:getx(),p:gety())

ss=cpSegmentShape.new(b,cpVect.new(-1.4,-1.3),cpVect.new(1.2,1.4),.2)
p=ss:getA()
print("A",p:getx(),p:gety())
p=ss:getB()
print("B",p:getx(),p:gety())
p=ss:getNormal()
print("normal",p:getx(),p:gety())
print("radius",ss:getRadius())

chris_c
Posts: 6
Joined: Thu Aug 13, 2009 12:02 pm
Contact:

Re: WereChipmunk LUA binding for Chipmunk - Testers required!

Post by chris_c »

another session and now you can do this in Lua! can't be far from dropping a box on a static box.....

Code: Select all

verts={ cpVect.new(1.1,2),
   cpVect.new(3,4),
   cpVect.new(5,6),
   cpVect.new(7,8)
}
for i=1,4 do
   print("input",verts[i]:getx(),verts[i]:gety())
end
ps=cpPolyShape.new(b,4,verts,cpVect.new(.1,.2))
print("verts",ps:getNumVerts())
for i=0,3 do
   v=ps:getVert(i)
   print(i,v:getx(),v:gety())
end
gets you....

Code: Select all

verts	4
0	1.2	2.2
1	3.1	4.2
2	5.1	6.2
3	7.1	8.2
chris_c
Posts: 6
Joined: Thu Aug 13, 2009 12:02 pm
Contact:

Re: WereChipmunk LUA binding for Chipmunk - Testers required!

Post by chris_c »

http://www.youtube.com/watch?v=8E28_rp7gK8

here's an example of collision callbacks..... enjoy
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests