Ok,I got an actor moving along a nurbs curve using the method you suggested. It looks something like this:
class RopeInterval(LerpFunctionInterval):
def __init__(self,rope,model,duration=0.0):
curve = rope.node().getCurve()
curve.normalizeKnots()
result=curve.evaluate()
def updateModelPos(val,curve=result,model=model):
point = Vec3()
tang = Vec3()
curve.evalPoint(val,point)
curve.evalTangent(val,tang)
angle = atan2(tang.getY(),tang.getX())
model.setHpr(degrees(angle)+90,0,0)
model.setPos(point)
LerpFunctionInterval.__init__(self,updateModelPos,duration = duration,fromData = result.getStartT(), toData = result.getEndT())
I quickly noticed that the actor’s motion is not uniform along the curve. That is, it’s fast in someplaces and slow in others (mainly around bends).
I think this has something to do w/how the NURBS equations work. So then I tried to decompose the curve into linear segments so I can control the rate of travel of the actor (and make it uniform). I came up w/this.
class RopeMotionSequence2(Sequence):
def getPoints(self, len):
"""Returns a list of len points, evenly distributed in
parametric space on the rope, in the coordinate space of the
Rope itself."""
curve = self.rope.node().getCurve()
curve.normalizeKnots()
result = curve.evaluate(render)
numPts = len
ropePts = []
print "CURVE START T: "+str(result.getStartT())
print "CURVE END T: "+str(result.getEndT())
for i in range(numPts):
pt = Point3()
#print "evaluating t: "+str(i / float(numPts - 1))
result.evalPoint(i / float(numPts - 1), pt)
ropePts.append(pt)
return ropePts
def __init__(self,rope,model,duration=0.0):
grandularity = 100
self.rope = rope
points= self.getPoints(grandularity)
dur = float(duration)/float(grandularity)
seq = []
for ptId in range(len(points)-1):
#print "Creating interval: "+str(points[ptId])+" "+str(points[ptId+1])
seq.append(LerpPosInterval(model,duration=dur,startPos=points[ptId],pos=points[ptId+1]))
print 'created: ' +str(len(seq))+' lerp intervals '
return Sequence.__init__(self,*seq)
No dice here either. It seems to be a little better, but still basically the same issue. I think what I need is to somehow capture the arc length of the curve between two points and use that to make uniform lerp intrevals.
Anyways, I’m sure someone has done this before so any hints or suggestions would be useful.
Thanks,
Aaron