Need help on mouse rotation coordinates [solvedish]

Ok so finally after getting my camera up and running how I want it too. I have one small tweek I need to make and I’m lost on how to solve it again lol.

First on the right mouse button click the camera rotates around a model with either way the mouse is moving. So if I move the mouse left the model rotates left rotating the attached camera.

However as I left mouse click it rotates the model to the mouses coordinates because its rotating off the mouse coordinates.

Here is my code so u can see what I mean.

``````def exampleTask(model, a):

x = base.win.getPointer(0).getX()
z = base.win.getPointer(0).getY()

model.setH(x)
model.setP(z)

Model is the model that i’m rotating in the above code.

But as you can see i get the x and z of the camera coordiantes so when i keep the mouse button pressed down it will rotate the model in the correct way which works except on the first mouse button press it jerks the camera to whatever pos the mouse clicks at.

SO i’m looking for a way to keep the model/camera from moving like that and staying in place and then rotating from it.

Any suggestions?

Hi, if I understand correctly something like this would do well (you may have to use x/2.0 or (x * 0.10) to get more precision)

``````def exampleTask(model, a):

x = base.win.getPointer(0).getX()
z = base.win.getPointer(0).getY()

model.setH(model, x)
model.setP(model, z)

Changing those lines to have ‘model’ as the first argument, causes panda to say “Ok, take the current H value, and add x to it”, the same for the ‘model.setP’ call, in this way it keeps the current rotation’s, and only adds the x and z values

Hope this helped,

~powerpup118
[/code]

hehe thanks for the help but I just figured it out and was coming back here to say figured it out haha.

After long thinking during the first half of the movie I was watching I struck me

heres what I did:

``````
#Set the task to look at the model every frame

x = base.win.getPointer(0).getX()
z = base.win.getPointer(0).getY()

#Move scene left to right
if x < base.camera_hor:
new_x = model.getH()
new_x = new_x + 5
model.setH(new_x)
base.camera_hor = base.win.getPointer(0).getX()

if x > base.camera_hor:
new_x = model.getH()
new_x = new_x - 5
model.setH(new_x)
base.camera_hor = base.win.getPointer(0).getX()

if x == base.camera_hor:
new_x = model.getH()
new_x = new_x
model.setH(new_x)
base.camera_hor = base.win.getPointer(0).getX()

#Move scene up and down
if z < base.camera_ver:
new_z = model.getP()
new_z = new_z + 2
model.setP(new_z)
base.camera_ver = base.win.getPointer(0).getY()

if z > base.camera_ver:
new_z = model.getP()
new_z = new_z - 2
model.setP(new_z)
base.camera_ver = base.win.getPointer(0).getY()

if z == base.camera_ver:
new_z = model.getP()
new_z = new_z
model.setP(new_z)
base.camera_ver = base.win.getPointer(0).getY()