rotate with mouse?

how do i make a model, rotate with the mouse… ( like in roaming ralph tut when you press left, he rotates to the left, so when my mouse is to the left
the object faces to the left, and if you move it a little to the up, the object faces left-up )

Well, one way to do it would be to use the lookAt function. You pass it either a node or a Point3 and it will change the HPR of you model to look at that node or point.

For following a mouse I’d do this:

import direct.directbase.DirectStart
from direct.task import Task
from pandac.PandaModules import *

MULTIPLIER = 10

class LookAtDemo():
    def __init__(self):

        self.smiley = loader.loadModel("teapot")
        self.smiley.reparentTo(render)
        self.smiley.setPos(0, 20, 0)
        
        base.disableMouse()

        taskMgr.doMethodLater(0.03, self.trackMouse, "trackMouse")

    def trackMouse(self, task):
        if base.mouseWatcherNode.hasMouse():
            x=base.mouseWatcherNode.getMouseX()
            y=base.mouseWatcherNode.getMouseY()
            self.smiley.lookAt(Point3(x, 0, y) * MULTIPLIER)
        
        return task.again
    
lookAtDemo = LookAtDemo()
run()

I’m using a multiplier so that I can change the sensitivity of the movement.

I’m sure there are other way’s but this should at least get u started.

you always stays with the problem that the mouse collides with the borders of the screen!! i figured this out:

class World(DirectObject):
	def __init__(self, main):
		
		#======Mouse Handlers======#
		self.mouseBoxSize = base.win.getYSize()/3 #Mousebox
		self.centerX = base.win.getXSize()/2 #Screen width center
		self.centerY = base.win.getYSize()/2#Screen height center

		self.mouseXMin = self.centerX - self.mouseBoxSize #Lowest X limit
		self.mouseXMax = self.centerX + self.mouseBoxSize #Highest X limit
		self.mouseYMin = self.centerY - self.mouseBoxSize #Lowest Y limit
		self.mouseYMax = self.centerY + self.mouseBoxSize
#Lowest Y limit

		base.win.movePointer(0, self.centerX, self.centerY) #Move the mouse to the center

		self.mouseY = 0 #define the mouse variables
		self.mouseX = 0
		self.mouseXFac = 0
		self.mouseYFac = 0
		#--
		

		#======Tasks======# add the task
		task = taskMgr.add(self.MouseControl, "Task_Mouse")
		self.Gametasks.append(task)
		#--


	#======Task Function======#
	def MouseControl(self,task):
		mouse = base.win.getPointer(0) #Get the real position
		mouseX,mouseY = mouse.getX(),mouse.getY() #Set temponary mouse vars

		# If the mouse passes the borders, replace it back and add or subtract the factor
		if mouseX < self.mouseXMin:
			base.win.movePointer(0, self.centerX, mouseY)
			self.mouseXFac -= 1
		if mouseX > self.mouseXMax:
			base.win.movePointer(0, self.centerX, mouseY)
			self.mouseXFac += 1
		if mouseY < self.mouseYMin:
			base.win.movePointer(0, mouseX, self.centerY)
			self.mouseYFac -= 1
		if mouseY > self.mouseYMax:
			base.win.movePointer(0, mouseX, self.centerY)
			self.mouseYFac += 1

		#Set the calculated mouse positions
		self.mouseX = mouseX - self.centerX + self.mouseBoxSize*self.mouseXFac
		self.mouseY = mouseY - self.centerY + self.mouseBoxSize*self.mouseYFac
		return Task.cont
	#--

every time the mouse position gets smaller or larger than the self.mouseBoxSize

it will be replaced to the center of the screen and the game remembers how much time the mouse passed the limit

self.mouseYFac and self.mouseXFac are the numbers of times the mouse passed the limit

self.mouseY and self.mouseX are the recalculated mousepositions

self.mouseY = 0 and self.mouseX = 0 is in het midden van het scherm!

to use this for a node camera this way:

		self.YourNodePath.setP(self.mouseY*MULTIPLIER)
		self.YourNodePath.setH(-self.mouseX*MULTIPLIER)