i m new to Panda3D and am interested in knowing how to pan the camera vertically by using a mouse (look up and down). I am able to pan horizontally but useDrive() does not allow vertical movement. I need to move the camera both horizontally and vertically like one controls a gun in a game. Please show a code snippet if possible so that i can follow.
Welcome to Panda.
I think this post should be put in a different place in the forum. This place is for semi-completed work.
but to answer your question, the nature demo on the forum has a basic yet powerful mouse nagivator.
def setMouseButton( self, button, value ): self.mouse[ button ] = value def _setupBase( self ): props = base.win.getProperties( ) props.setCursorHidden( True ) self.centerx = props.getXSize( )/2 self.centery = props.getYSize( )/2 base.disableMouse( ) base.setBackgroundColor( 0, 0, 0 ) base.win.requestProperties( props ) base.win.movePointer( 0, self.centerx, self.centery ) def _setupInput( self ): self.accept( 'escape', self.exit ) self.accept( 'mouse1', self.setMouseButton, [ 0, 1 ] ) self.accept( 'mouse1-up', self.setMouseButton, [ 0, 0 ] ) self.accept( 'mouse2', self.setMouseButton, [ 1, 1 ] ) self.accept( 'mouse2-up', self.setMouseButton, [ 1, 0 ] ) self.accept( 'mouse3', self.setMouseButton, [ 2, 1 ] ) self.accept( 'mouse3-up', self.setMouseButton, [ 2, 0 ] ) def updateCamera( self, task ): md = base.win.getPointer( 0 ) x = md.getX( ) y = md.getY( ) if base.win.movePointer( 0, self.centerx, self.centery ): self.heading += ( x - self.centerx ) * -0.2 self.pitch += ( y - self.centery ) * -0.2 self.pitch = clampScalar( self.pitch, -80.0, 80.0 ) if self.mouse[ 0 ]: speed = 500 * ( task.time - self.last ) elif self.mouse[ 1 ] or self.mouse[ 2 ]: speed = -500 * ( task.time - self.last ) else: speed = 0 base.camera.setHpr( self.heading, self.pitch, 0 ) base.camera.setPos( base.camera, Vec3( 0, 1, 0 ) * speed ) self.last = task.time return Task.cont
Again, try to put post like this in the appropriate place.
Thank you, Mavasher. I apologize.Since this was my first post i did not realize that i posted my question at the wrong place. I guess it should have been general discussion.
Anyways, just 1 more question since u have so generously replied to my query. the panning works gr8. but what we want to lock the movement explicitly for horizontal and vertical mouse movements. i.e. with the currrent code, using the middle mouse button we can pan up & down and right and left, which is want i desire. but the environmet tilts and turns which i do not require. I want to keep the camera straight in horizontal and vertical movements.
I’ll be careful to post in the right place hereon.
Once again I thank u for all your help.
It belongs in Scripting Issues, not General Discussion.
Camera control code is not hard to write. Dive into camera control (manual!) and do it yourself.
Camera controls are not difficult to write using useDrive() and useTrackball() but the do not support vertical movement. I have gone thru the camera control manual also. I am however not being able to figure out a solution for fixed verital movement.
I guess I’m confused. I don’t understand what the problem is. What do you mean by
You mean you want to change heading but not pitch? Just code it that way. Set pitch to a constant like “0”.
In Panda there are three axises: X, Y, Z.
X is to the right. Y is forward. Z is up. Heading is rotation about the Z-axis so its the direction you are pointed in the XY plane. Pitch is rotation about the X-axis so it’s the direction you are pointed up/down.
Thanks for your response. I guess i am not able to explain myself properly for sure. I have not been able to achieve what i want to since the past 1 day. Let me try and make it simple.
How can we, on a left mouse button press, tilt the camera to look up on dragging the mouse pointer up and similarly look down for down/left and right depending on which way the mouse is dragged. I thought it would be simple but since useDrive() supports on left right but no up down movement , i m stuck.
You have been very kind in backing up your concepts with code and explainations. I sincerely thank u for this.
I don’t mean using the pre-installed functions, but by writing the camera controls yourself. You know, from scratch.
pro-rsoft, what’s wrong with u. Dont u get it. I am new to programming and am trying to get a hold of it. I will not mind u calling me lazy bcos u dont even know who i am nor the fact that i am, after 2 days of work, able to move the camera but by keyboard. I still need to do that by mouse and am unable to do so. I may be a slow learner but am a confidentlearner. Anyways! THANKS for all your help and advise.
I’m really sorry, I misunderstood you entirely. Could you please describe your problem some more? Because I’m afraid I don’t really get your point.
About how to go about solving this:
I’m not sure how the proper programming way is. I’m not a programmer. I just do this as a hobby.
But here’s what I would do. I would check for if the mouse button is clicked or not. The code I gave you has that setMouseButton function. You can use that variable to check if the mouse is clicked. Use the other stuff to grab the position of the mouse. And write an “if statment” if the mouse button is clicked do your drag functions ‘x,y,z’ else do the other kind of functions. Have one set of functions for when the mouse is clicked and another set of functions for when the mouse isn’t.
and Pro-rsoft. This is what i want to achieve.
I want to achieve exactly what the useDrive() function achieves while panning horizontally. Only thing is i want to pann the camera vertically also when i move the cursor up or down. when we move the cursor up / down using useDrive(), it zooms in and zooms out. I want the vertical panning movement instaed of zoom in/zoomout.
to further explain my problem,
on left mouse click if i drag my mouse up, the camera should look up towards the sky and if i drag my mouse cursor down, it should look towards the ground. The effect would be similar to that of a gun in a computer battle game like dalta force. if we point the gun up, we aim towards the sky and if we point the gun down, we can aim towards the ground.
I hope i am now able to express my problem in a clearer fashion.
i am still not able to solve this and any help at all would be appreciated.
I want to think you did not mean that negatively, but its clear mohak took it that way, as most people would. We need to be careful how we phrase things because this isn’t real life where you can see someones face and how they are speaking …in part that is what 's are for.
We make friends in life with good things to say, rather than any other methodology.
I would try the point and click script here:
I have a feeling that point & click is not what Mohak is looking for. But his explanation is still a bit, well, inconsistent. Still I think I know what he means.
I might be wrong, but AFAIK drive mode is NOT sensitive to mouse movement, but to mouse position. So talking about dragging is misleading. What drive mode does is the following: if the mouse button is pressed it checks each frame for the position of the mouse relative to the screen center. Then it rotates the camera left/right (heading!) according to the horizontal distance from the center, and it moves the camera forward/backward according to the vertical distance from the center.
Again I might be wrong, but the semantics of “panning” is to move the camera sideways while keeping it’s orientation fixed. E.g. sliding to the left. (And if I am wrong I have an excuse: this is not my native language Trackball mode does panning, both horizontal and vertical, if holding the left mouse button down and the DRAGGING the mouse.
The following code should be what he means, rotation of the camera according to the distance of the mouse pointer from the screen center, both horizontal and vertical. Please be aware that orientation has a third degree of freedom: roll.
import direct.directbase.DirectStart from direct.showbase.DirectObject import DirectObject from pandac.PandaModules import MouseButton import sys class Test( DirectObject ): def __init__( self ): base.disableMouse( ) props = base.win.getProperties( ) self.centerx = props.getXSize( )/2 self.centery = props.getYSize( )/2 self.accept( 'escape', self.exit ) self.accept( 'c', self.center ) self.prevtime = 0.0 taskMgr.add( self.update, 'updateWorld' ) # box #np = loader.loadModel( 'models/box' ) #np.reparentTo( render ) #np.setPos( 0, 20, 0 ) def exit( self ): sys.exit( ) def center( self ): base.camera.setHpr( 0, 0, 0 ) def update( self, task ): dt = task.time - self.prevtime if base.mouseWatcherNode.isButtonDown( MouseButton.one( ) ): md = base.win.getPointer( 0 ) x = md.getX( ) - self.centerx y = md.getY( ) - self.centery base.camera.setHpr( base.camera, x * dt * 0.1, y * dt * 0.1, 0 ) self.prevtime = task.time return task.cont demo = Test( ) run( )
Yes Ennox, u got it right. Exactly what I was looking for. Thanks a lot. couldn’t really put my problemsin the right terms! I really appreciate the effort put in by all of u. Mavsher, nl, pro-rsoft… This is the very first forum i have joined in my life and hope to start contributing soon. u guys are a talented lot but more importantly those who want to share their knowledge. Its good to have met u guys. and pro-rsoft, i know u did not mean to be harsh or anything. No hard feelings friend!!!
Once again, thanks a lot guys.
I should not have used point and click as reference, but that is how I think of it , in part because it allows you to point mouse to top , bottom, left and right and camera pans or pivots or tilts accordingly…but also if you ‘click’ on terrain the avatar goes there
therefore I thought it would serve you well though if you dont want to click part that would be excess though you could comment it or remove altogether…anyway its a solid starting point …all said scripts.
Sorry for being late and moving the topic now. Here is the better place.