This forum has been a treasure. Though this is my first post, I have been following this passively. Pleasure to jump aboard.
So I created a Geom primitive ( lets assume the procedural-cube example cube) and now want to rotate the model based on mouse movements. Functionality exactly like pview would be the result I am looking for. However from searching the documents, I found that by default you can rotate the camera and can’t rotate the model. Is there any way to do it ? Any class to attach to the model which replicates pview like functionality? help would be appreciated.
Sure. Here’s a code example that attaches a Trackball to a spotlight, so you can move around the spotlight and see what effect it has.
import direct.directbase.DirectStart
from pandac.PandaModules import *
spot = Spotlight('spot')
spot.setColor(VBase4(1, 1, 0, 1))
lens = PerspectiveLens()
spot.setLens(lens)
snp = render.attachNewNode(spot)
loader.loadModel('camera.egg').reparentTo(snp)
tp = loader.loadModel('teapot.egg')
tp.reparentTo(render)
tp.setLight(snp)
# Pull the camera back and disable the normal camera trackball controls.
base.disableMouse()
base.camera.setPos(0, -20, 0)
# Set up a special trackball to move around snp.
snpTrackball = Trackball('snpTrackball')
snpTrackball.setRelTo(base.cam)
snpTrackball.setInvert(0)
tnp = base.mouseWatcher.attachNewNode(snpTrackball)
t2n = Transform2SG('snpTrackball2snp')
t2n.setNode(spot)
tnp.attachNewNode(t2n)