CMotionTrail question

I was wondering if there are any examples on how to implement CMotionTrail

I can’t seem to find anything else on it outside of the one page from the docs

1 Like
from direct.showbase.ShowBase import ShowBase
from panda3d.direct import CMotionTrail
from panda3d.core import GeomNode, NodePath, Mat4, Vec3

class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        
        self.scene = self.loader.loadModel("models/environment")
        self.scene.reparentTo(self.render)

        gnode = GeomNode('gnode')

        self.test = CMotionTrail()
        self.test.addVertex(0.5, 0, 0, 0)
        self.test.addVertex(-0.5, 0, 0, 0)

        self.test.enable(True)
        self.test.setGeomNode(gnode)
        self.test.setParameters(sampling_time = 0, time_window = 1 , use_texture = False, calculate_relative_matrix = False, use_nurbs = False, resolution_distance = 10)

        self.test_path = NodePath(gnode)
        self.test_path.reparentTo(render)

        self.taskMgr.add(self.frame, "frame")

    def frame(self, task):
        mat = Mat4()
        mat.setTranslateMat(Vec3(0, task.time*base.clock.dt*100, 0))

        self.test.updateMotionTrail(task.time, mat)

        return task.cont


app = Game()
app.run()

Approximately it can be used like this, but I do not know how to use it correctly. We need to add more vertices, we also need to set the matrix correctly, but I have no experience with this. I don’t understand why the vertex position is set by four components.

1 Like

Thanks! I’ll see if I can get it to work from this.

1 Like