I am a student and is a beginner scripter learning to use panda3d, i have faced a few problems and requires some assistance about scripts on certain situations.
This is the main script
import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.gui.DirectGui import *
from direct.task import Task
from direct.actor import Actor
import math, random, sys, os, math
from direct.showbase.DirectObject import DirectObject
from direct.interval.IntervalGlobal import *
from direct.gui.OnscreenImage import OnscreenImage
import Camera#class camera
import Environment
#figure the directory
MYDIR = os.path.abspath(sys.path[0])
MYDIR = Filename.fromOsSpecific(MYDIR).getFullpath()
class World(DirectObject):
def init(self):
self.accept("enter",self.startGame)
#start screen
self.imageObject = OnscreenImage ( image = "StartScreen.jpeg",
pos = (0,0,0),
scale = (800/600.0,1,1)
def UpdateWorld(task):
#update all objects in World-----------------Camera
Camera.cam.UpdateCamera()
return Task.cont
taskMgr.add(UpdateWorld, "UpdateWorldTask")
def startGame(self):
self.imageObject.destroy()
#dlight = DirectionalLight(‘dlight’)
#dlnp = render.attachNewNode(dlight.upcastToPandaNode())
#render.setLight(dlnp)
alight = AmbientLight(‘alight’)
alight.setColor(VBase4(0.4, 0.4, 0.4, 1))
alnp = render.attachNewNode(alight.upcastToPandaNode())
render.setLight(alnp)
dlight = DirectionalLight(‘dlight’)
dlight.setColor(VBase4(0.4, 0.4, 0.4, 1))
dlnp = render.attachNewNode(dlight.upcastToPandaNode())
dlnp.setHpr(0, -60, 0)
render.setLight(dlnp)
#fog
myFog = Fog(“Fog”)
myFog.setColor(0.2,0.5,0.7)
myFog.setExpDensity(0.01)
render.setFog(myFog)
w=World()
run()
the class camera script
#Camera Class
import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.gui.DirectGui import *
from direct.task import Task
from direct.showbase.DirectObject import DirectObject
from direct.actor import Actor
from direct.interval.IntervalGlobal import *
import math,sys,os,random
class Camera(DirectObject):
def init(self):
self.userControlled= 1
self.prevMouseX= 0
self.deltaX=0
self.xpos=0
self.ypos=0
self.zpos=0
self.zrot=0
self.xrot=0
self.accept('w-repeat', self.goForward)
self.accept('s-repeat', self.goBackward)
self.accept('w', self.goForward)
self.accept('s', self.goBackward)
self.accept('a-repeat', self.rotateLeft)
self.accept('d-repeat',self.rotateRight)
self.accept('a', self.rotateLeft)
self.accept('d', self.rotateRight)
self.accept('arrow_up-repeat', self.tiltDown)
self.accept('arrow_down-repeat', self.tiltUp)
self.accept('arrow_up', self.tiltDown)
self.accept('arrow_down', self.tiltUp)
#self.accept('u-repeat', self.goUp)
#self.accept('d-repeat', self.goDown)
#self.accept('u', self.goUp)
#self.accept('d', self.goDown)
#end of init
def UpdateCamera(self):
#ise mouse horizontal movement
#if base.mouseWatcherNode.hasMouse():
# x= base.mouseWatcherNode.getMouseX()
# self.deltaX= x-self.prevMouseX
# self.prevMouseX=x
# if self.deltaX>0:
# self.rotateRight()
# else:
# if self.deltaX<0:
# self.rotateLeft()
base.camera.setPos(self.xpos, self.ypos, self.zpos)
base.camera.setHpr(self.zrot, self.xrot,0)
def goForward(self):
if self.userControlled==1:
angleradians= self.zrot*(math.pi/180)
deltaX=0.5*math.sin(angleradians)
deltaY= -0.5*math.cos(angleradians)
self.xpos-=deltaX
self.ypos-=deltaY
def goBackward(self):
if self.userControlled==1:
angleradians= self.zrot*(math.pi/180)
deltaX=0.5*math.sin(angleradians)
deltaY= -0.5*math.cos(angleradians)
self.xpos+=deltaX
self.ypos+=deltaY
def rotateLeft(self):
self.zrot+=2
def rotateRight(self):
self.zrot-=2
def tiltUp(self):
self.xrot+=2
def tiltDown(self):
self.xrot-=2
def goUp(self):
self.zpos+=0.5
def goDown(self):
self.zpos-=0.5
cam = Camera()
The problems
- Textures files are not loading from the same directory(It is using the same directory during the export to egg file)
- Camera is not working as if it is not loaded
- Start screen is not loading (the script comes out error on the “def UpdateWorld” too)
Things that require more scripts
- A collision between camera and an object that enable a talk scene when camera is facing the object and when play hit the mouse left click
- A starting cinematic followed by a loading screen then to the start screen.(the cinematic can be skipped by pressing any button)
- An event to open another python file when the camera reach a location in the scene.(instancing into another scene)
- If possible i would like an API documentation of panda3d
Thanks.