Rotating models using the mouse

Hi Folks

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()
snp = render.attachNewNode(spot)

tp = loader.loadModel('teapot.egg')

# Pull the camera back and disable the normal camera trackball controls.
base.disableMouse(), -20, 0)

# Set up a special trackball to move around snp.
snpTrackball = Trackball('snpTrackball')

tnp = base.mouseWatcher.attachNewNode(snpTrackball)
t2n = Transform2SG('snpTrackball2snp')


Thanks David :slight_smile: Trackball is the way to go.

You’ve been very helpful in this forum and I am learning a lot.