|
|
|
|
|
|
|
FAQ
Search
Memberlist
Profile
Log in to check your private messages
Register
Log in
|
| View previous topic :: View next topic |
| Author |
Message |
Chia_Pet
Joined: 31 Oct 2009 Posts: 14
|
Posted: Tue Nov 03, 2009 1:02 pm Post subject: Variable issue [Solved] |
|
|
Ok so i have a code that i got from the site to control my camera the way i wanted it to move. It has Pan limits built into it though and i need it to change for each map. so is there a way without changing too much code that i can call a variable from another file?
just to show you (File 1):
| Code: |
import direct.directbase.DirectStart
from CameraHandlerClass import CameraHandler
class World(DirectObject):
def __init__(self):
#Task to add camera controls for the camera
camHandler = CameraHandler()
run()
|
Of course i cut out all my code execpt my current call. This calls CameraHandlerClass.py and in that code there is this (File 2):
| Code: |
from direct.showbase import DirectObject
from pandac.PandaModules import Vec3,Vec2
import math
class CameraHandler(DirectObject.DirectObject):
def __init__(self):
base.camera.setPos(0,0,50)
base.camera.lookAt(0,0,0)
# Gives the camera an initial position and rotation.
self.mx,self.my=0,0
# Sets up variables for storing the mouse coordinates
self.orbiting=False
# A boolean variable for specifying whether the camera is in orbiting mode. Orbiting mode refers to when the camera is being moved
# because the user is holding down the right mouse button.
self.target=Vec3()
# sets up a vector variable for the camera's target. The target will be the coordinates that the camera is currently focusing on.
self.camDist = 40
# A variable that will determine how far the camera is from it's target focus
self.panRateDivisor = 20
# This variable is used as a divisor when calculating how far to move the camera when panning. Higher numbers will yield slower panning
# and lower numbers will yield faster panning. This must not be set to 0.
self.panZoneSize = .10
# This variable controls how close the mouse cursor needs to be to the edge of the screen to start panning the camera. It must be less than 1,
# and I recommend keeping it less than .2
self.panLimitsX = Vec2(-20, 20)
self.panLimitsY = Vec2(-20, 20)
# These two vairables will serve as limits for how far the camera can pan, so you don't scroll away from the map.
|
What i want to do is call panLimitsX and Y as well as base.camera.setPos and base.camera.lookAt from the first code is this possible to do this? and if so how do i change the code to do this? I have tried to figure it out and either im just over compicating this or something needs to be added so i can do this
Last edited by Chia_Pet on Tue Nov 03, 2009 7:00 pm; edited 1 time in total |
|
| Back to top |
|
 |
Chia_Pet
Joined: 31 Oct 2009 Posts: 14
|
Posted: Tue Nov 03, 2009 6:58 pm Post subject: |
|
|
ok it was figured out to pass the information i needed.
I used a return function as shown in the code below:
| Code: |
def plCamera(plX, plY):
return CameraHandler(plX=Vec2(0, 20), plY=Vec2(0, 20))
|
This allowed me to pass plX and plY to CameraHandler (seperate .py file) class there was a little more that had to be done like in my camera handler call i did:
| Code: |
camHandler = CameraHandler(Vec2(0, 20), Vec2(0, 20))
|
and i had to add plX and plY to CameraHanlders class like so:
| Code: |
def __init__(self, plX, plY):
|
then lastly I had to setup the transfer into the __init__ def by using this:
| Code: |
self.panLimitsX = plX
self.panLimitsY = plY
|
Once i did those it was all done, and the information passed from my main file to my camera file so i dont have to directly edit the camera file again! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|
|
|
 |
|
 |
|
|
|
|