Camera issues and questions [solvedish]

Hi,

I figured out how to get my camera half working how I want it to.

First here is what it does.

I take the camera and disable the mouse so I can mess with it. I then reparent it to a dummy model and tell the camera to look at that model. I do this so it rotates around that model because I want the camera to rotate around 0,0,0 coordinates of the word where the model is located.

I then set a task for the camera to continue to look at the model and then reactivate the mouse.

However what the camera does is always starts off inside the model.

So heres the problem:

Camera starts inside the model its looking at and I can not set it outside the model since the look at command is called through the task manager every frame and it keeps resetting it inside the model until the mouse is moved to move the camera outside.

Sooo I’ve spent 3 days on this issue and can not figure out a way to get the camera start outside the model instead of inside it.

Code for my camera:


#disable the mouse and reparent it to the dummy with an offset to Y to see the planet
    #then look at the planet with the camera
    base.disableMouse()
    base.camera.reparentTo(dummy)    
    base.camera.lookAt(dummy)


#Call task to make the camera continue to look at the planet
    taskMgr.add(exampleTask, 'MyTaskName', extraArgs=[dummy], appendTask=True)


#Set the task to look at the model every frame
def exampleTask(model, a):
    base.camera.lookAt(model)

    return Task.cont

Thats the first problem so if anyone can let me know of how to go about getting the camera to first display outside the model (so on load the user does not need to scroll out to see the model)

Second problem is:

It just really akward to control the damn camera. I’m looking for if your in a 3d modeling program you can rotate round the 0,0,0 axis and zoom in and out and around.

However the camera does not do this its just plain akward you zoom in but it goes in and to the left etc.

I cant explain it so if you know how to setup a camera to do this that be great!

Thanks for any input/help!

Camera is an ordinary node so you can apply any transform to it(setPos,setHpr,etc).

But it would be better to add separate nodes for this and reattach camera between them to change a view.

Look at examples in documentation, FPS and planet system examples in “Code Snippets” section of this forum.

cameraNP = dummy.attachNewNode("Camera")
cameraNP.setPos(50)
base.camera.reparentTo(cameraNP)   
base.camera.lookAt(dummy) 

there is nodepath.getBounds().getRadius(), so you know where to put the camera.

[[SOLVED] change center position of camera?)

THANKS for the replys i’ll read into all this tomorrow and see what I can find out and or get it to work. Thanks again!

The one above code linked to the other fourm post kinda works but in that example of the linked code form post i cant move the camera down around the center 0,0,0 world coordinates.

Also the mouse is disabled and u cant select menu options.

This has become just too frustrating. I really just need to get this camera issue fixed and I can finally move on with my project instead of trying to figure out something that should be simple.

YES I have read the manual which really did not help much and looked through all those examples.

The solar system example does not help because the camera does not rotate in that either.

Any help would be sooo much appreciated.

Thanks.

the thing is . a camera is just a nodepath, so they behave just like a planet, in fact you could simply simbsitute a planet with the camera.

the steps to do would be:
disable the default camera driver (looks like you did that)
create a dummynode and place it to (0,0,0)-also done
reparent your camera to the dummy -also done
set the new camera position - i havent seen this in your code.
lookAt your dummy.
rotate the dummy.

the order of the steps is critical.

if it still doesnt work feel free to paste the code so we can have a look at it and find the problem.

ok all that makes sense but i’m lost on how to rotate the dummy.

So if i wanted to rotate the dummy say using Mouse Button 3 (hold mouse button 3) and then move the mouse up and or move it left, right, down, diagonal how would I do that? to the model? The camera will follow but not sure how to set the mouse button to move the model while moving the mouse.

but i also need the mouse pointer to be free to click stuff on the screen all the code tutorials i have seen hide the mouse and u can not move the pointer.

kinda got how to do it by this:

    base.accept('wheel_up', lambda : base.cam.setY(base.cam.getY()+1 * globalClock.getDt()))
    base.accept('wheel_down', lambda : base.cam.setY(base.cam.getY()-1 * globalClock.getDt()))
    base.accept('mouse3', lambda : dummy.setH(dummy.getH()-10 * globalClock.getDt()))
    base.accept('mouse1', lambda : dummy.setH(dummy.getH()+10 * globalClock.getDt()))
    base.accept('mouse2', lambda : dummy.setP(dummy.getP()+10 * globalClock.getDt()))

but i think i need to make a task? and somehow find if the camera is moving in the X or P directions? then the task should update it every frame?

but there be only one call th the mouse3 (i had mouse1 and mouse 2 set just to test movements by clicking a lot lol)

using a task would make sense.
to get the cursor position from screen you can use
base.win.getPointer(0).getX() and getY()

using those you can set up click&drag like motion

Im confused on how i would even go about using base.win.getpointer to rotate the model with a task. No clue where to start :[

I’m really confused now because if i just get the say x position of the mouse and then try to set it to the model the models gonna go flying way around the screen and not rotating.

do you have an example please that you could throw up for me too look at and test? I’m just at my last nerve end with this camera I just want it to work after 4 days now so i can just move on to other things on this.

OK OK almost got it to work now my code needs improvment!!

Heres my task:

taskMgr.add(exampleTask, 'MyTaskName', extraArgs=[dummy], appendTask=True)

Here is my zoom in and out with the camera

base.accept('wheel_up', lambda : base.cam.setY(base.cam.getY()+30 * globalClock.getDt()))
    base.accept('wheel_down', lambda : base.cam.setY(base.cam.getY()-30 * globalClock.getDt()))

Here is my task now

def exampleTask(model, a):

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


    return Task.cont

Now what is wrong is that the camera rotates all the time when i move the mouse so now i need to set it up with say the mouse 3 click (as in click and hold) so i want the user to half to click and hold mouse 3 and on mouse button 3 up they the camera will then stop moving.

Not sure how to do that.

you only have to apply the actual position change, not the actual position. either by saving the position value somewhere so you can get it next frame again to calculate the difference. or you may even be able to find an approriate function which does that for you (not sure if that one exists tho)

What i need is now just as in my last post is to have the system be like hey the mouse button 3 has been pushed so do this now and once the mouse button is release stop doing this.

I have no clue how to check if the mouse button was pressed down and or is depressed?

If i can figure that out then i can have it rotate because as in last post i have gotten the camera to rotate but it always rotates because it does not ck for the mouse input…

.accept(‘mouse3’, startTask)
.accept(‘mouse3-up’, stopTask)

ummm can u give me a full example how this code works??

tester = taskMgr.add(exampleTask, 'MyTaskName', extraArgs=[dummy], appendTask=True)
   
    tester.accept('mouse3', startTask)

thats what i tried did not work, please full example this is what i’ve been looking for but i dont know how to use what u just typed… :[

startTask is when taskMgr.add() is called, and stopTask is when taskMgr.remove(‘yourTaskName’) is called.

It’s up to you to arrange them.

startTask is when taskMgr.add() is called, and stopTask is when taskMgr.remove(‘yourTaskName’) is called.

It’s up to you to arrange them.

Whatt??? i’m asking how to find out if the mouse3 button has been pressed?

So like if i just wanted to do an if statment

if mouse3
DO THIS

if mouse3_up
DO THIS

so now how do I check to see if the mouse has been pressed or depressed??? Thats all I need to know to make this code work and to finish it so I can finally move on please let me know.

Thanks

def startTask():
     move your taskMgr.add() here

or

.accept('mouse3', lambda: taskMgr.add(...))

ok this seems to work for the mouse press down but it cant get it to remove the task on mouse3-up

heres my code

Start the task:

base.accept('mouse3', lambda: taskMgr.add(exampleTask, 'MyTaskName', extraArgs=[dummy], appendTask=True))

and heres my task

def exampleTask(model, a):
        
    base.accept('mouse3-up', lambda: taskMgr.remove('exampleTask'))    
    x = base.win.getPointer(0).getX()
    z = base.win.getPointer(0).getY()
    model.setH(x)
    model.setP(z)

    return Task.cont

so i have it checking for the mouse3-up every frame within the task that starts the mouse pressed but when releaseing the mouse it wont stop/remove the task!

sure its something simple but once I get this done then its finished!!!

Thanks so far just this one little problem left