Ah, thank you so much! But, oddly enough, I have my program set up pretty much how the example does, and it’s still acting strange.
I have two collisions set up, one for regular collisions on walls and one for my end game, which, right now, I’m just testing by making it print “END”. Problem is, “END” will print even when I am not hitting the specified collision solid. It prints when I hit all the walls, and last time I ran it didn’t print anything for the collision I wanted it to. I’m really new to programming, so I think I’ve probably just got something set up wrong. Here is all my code, maybe you can see what I’m doing wrong?
from panda3d.core import loadPrcFileData
# Configure the parallax mapping settings (these are just the defaults)
loadPrcFileData("", "parallax-mapping-samples 3")
loadPrcFileData("", "parallax-mapping-scale 0.1")
from direct.gui.DirectGui import *
from panda3d.core import WindowProperties
from panda3d.core import Filename,Shader
from panda3d.core import AmbientLight,PointLight
from panda3d.core import TextNode
from panda3d.core import Point3,Vec3,Vec4
from pandac.PandaModules import *
from direct.showbase.ShowBase import ShowBase
from direct.task.Task import Task
from direct.actor.Actor import Actor
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
from direct.filter.CommonFilters import *
import sys,os
###
from panda3d.core import TransparencyAttrib
###
# Function to put instructions on the screen.
def addInstructions(pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)
# Function to put title on the screen.
def addTitle(text):
return OnscreenText(text=text, style=1, fg=(1,1,1,1),
pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)
class BumpMapDemo(ShowBase):
def __init__(self):
ShowBase.__init__(self)
base.cTrav = CollisionTraverser()
base.cTrav.setRespectPrevTransform(True)
collisionHandler = CollisionHandlerPusher()
polygonMask = BitMask32.bit(1)
sphereMask = BitMask32.bit(1)
collisionHandler.addInPattern('%fn-into-%in')
collisionHandler.addOutPattern('%fn-out-%in')
self.filters = CommonFilters(base.win, base.cam)
filterok = self.filters.setBloom(blend=(0,0,0,1), desat=-0.5, intensity=5.0, size="small")
if (filterok == False):
addTitle("Toon Shader: Video card not powerful enough to do image postprocessing")
return
self.glowSize=1
# Check video card capabilities.
if (base.win.getGsg().getSupportsBasicShaders() == 0):
addTitle("Bump Mapping: Video driver reports that shaders are not supported.")
return
self.keyMap = {"camera-forward":0}
# Menu Screen
self.myImage=OnscreenImage(image = 'menuscreen.png', pos = (0, 0, 0))
self.myImage.setTransparency(TransparencyAttrib.MAlpha)
self.myImage.reparentTo(render2d)
maps = loader.loadModel('start_button.egg')
self.startbutton = DirectButton(geom = (maps.find('**/startbutton'),
maps.find('**/startbutton_click'),
maps.find('**/startbutton_hover')),command = self.startbuttonevent)
self.startbutton["frameColor"] = (0,0,0,0)
self.startbutton.setScale(0.2,0.2,0.2)
self.startbutton.setPos(0.7,0,0.6)
maps = loader.loadModel('quit_button.egg')
self.quitbutton = DirectButton(geom = (maps.find('**/quitbutton'),
maps.find('**/quitbutton_click'),
maps.find('**/quitbutton_hover')),command = self.quitbuttonevent)
self.quitbutton["frameColor"] = (0,0,0,0)
self.quitbutton.setScale(0.2,0.2,0.2)
self.quitbutton.setPos(0.7,0,0.4)
# Dragon Story Pop-up
#self.myImage=OnscreenImage(image = 'Ryujin Back Story.png', pos = (0, 0, 0))
#self.myImage.setTransparency(TransparencyAttrib.MAlpha)
###imageObject.destroy()
# Post the instructions
self.title = addTitle("shitty labyrinth")
self.inst1 = addInstructions(0.95, "Press ESC to exit")
self.inst2 = addInstructions(0.90, "Move mouse to rotate camera")
self.inst3 = addInstructions(0.85, "Left mouse button: Move forwards")
self.inst4 = addInstructions(0.80, "Right mouse button: Move backwards")
self.sky = loader.loadModel("models/leafplant2_color")
self.sky.reparentTo(render)
self.sky.setHpr(0, 0, 0)
self.sky.setPos(20,-62,0)
self.sky = loader.loadModel("models/sky")
self.sky.reparentTo(render)
self.sky.setHpr(0, 0, 0)
self.sky.setPos(-300,0,70)
self.crystal = loader.loadModel("models/crystals")
self.crystal.reparentTo(render)
self.crystal.setScale(0.5,0.5,0.5)
self.crystal.setHpr(0,-30,30)
self.crystal.setPos(-11,-68,1)
self.mushroom = loader.loadModel("models/mushroom")
self.mushroom.reparentTo(render)
self.mushroom.setScale(0.3,0.3,0.3)
self.mushroom.setPos(80,-62,5)
self.room = loader.loadModel("models/texturemesh")
#texture = loader.loadTexture("models/fieldstone-c.jpg")
#self.room.setTexture(texture)
#texture.setWrapU(Texture.WM_mirror)
#texture.setWrapV(Texture.WM_mirror)
self.room.setHpr(0,0,0)
self.room.setScale(3.0,3.0,3.0)
self.room.reparentTo(render)
roomCollider = self.room.find("**/polygons")
roomCollider.node().setIntoCollideMask(sphereMask)
self.ball = loader.loadModel("models/ball")
ballCollider = self.camera.attachNewNode(CollisionNode('cnode'))
ballCollider.node().addSolid(CollisionSphere(0, 0, 0, 2))
ballCollider.node().setFromCollideMask(sphereMask)
base.cTrav.addCollider(ballCollider, collisionHandler)
collisionHandler.addCollider(ballCollider, self.camera, base.drive.node())
DO = DirectObject()
DO.accept('cnode-into-polygons', self.collideEventIn)
#Collision that ends the game
quad = CollisionPolygon( Point3(0,10,0),Point3(0,10,10),Point3(0,0,10),Point3(0,0,0))
quadPath = self.room.attachNewNode(CollisionNode('qnode'))
quadPath.node().addSolid(quad)
quadPath.node().setIntoCollideMask(polygonMask)
quadPath.node().setFromCollideMask(polygonMask)
base.cTrav.addCollider(quadPath, collisionHandler)
collisionHandler.addCollider(quadPath, self.camera, base.drive.node())
quadPath.setPos(-30, -3, 0)
quadPath.show()
DIR = DirectObject()
DIR.accept('cnode-into-polygons', self.endGameCollision)
mySound = base.loader.loadSfx("cavesound.ogg")
mySound.play()
mySound.setVolume(0.5)
mySound.setLoop(1)
mySound.setLoopCount(0)
#Add a light to the scene.
self.light = render.attachNewNode("lightpivot")
self.light.setPos(-50,-25,75)
#self.light.hprInterval(10,Point3(360,0,0)).loop()
plight = PointLight('plight')
plight.setColor(Vec4(1, 1, 1, 1))
plight.setAttenuation(Vec3(0.7,0.05,0))
plnp = self.light.attachNewNode(plight)
plnp.setPos(45, 0, 0)
self.room.setLight(plnp)
# Add an ambient light
alight = AmbientLight('alight')
alight.setColor(Vec4(0.2, 0.2, 0.2, 1))
alnp = render.attachNewNode(alight)
self.room.setLight(alnp)
# create a sphere to denote the light
sphere = loader.loadModel("models/sphere")
sphere.reparentTo(plnp)
# load and apply the shader. This is using panda's
# built-in shader generation capabilities to create the
# shader for you. However, if desired, you can supply
# the shader manually. Change this line of code to:
# self.room.setShaderInput("light", plnp)
# self.room.setShader(Shader.load("bumpMapper.sha"))
self.room.setShaderAuto()
self.shaderenable = 1
def startbuttonevent(self):
self.myImage.detachNode()
self.startbutton.detachNode()
self.quitbutton.detachNode()
# Make the mouse invisible, turn off normal mouse controls
base.disableMouse()
props = WindowProperties()
props.setCursorHidden(True)
base.win.requestProperties(props)
# Set the current viewing target
self.focus = Vec3(80,-62,10)
self.heading = 180
self.pitch = 0
self.mousex = 0
self.mousey = 0
self.last = 0
self.mousebtn = [0,0,0]
# Start the camera control task:
sound = self.loader.loadSfx("running.ogg")
taskMgr.add(self.controlCamera, "camera-task")
self.accept("escape", sys.exit, [0])
self.accept("mouse1", self.setMouseBtn, [0, 1])
self.accept("mouse1-up", self.setMouseBtn, [0, 0])
self.accept("mouse2", self.setMouseBtn, [1, 1])
self.accept("mouse2-up", self.setMouseBtn, [1, 0])
self.accept("mouse3", self.setMouseBtn, [2, 1])
self.accept("mouse3-up", self.setMouseBtn, [2, 0])
self.accept("enter", self.toggleShader)
self.accept("j", self.rotateLight, [-1])
self.accept("k", self.rotateLight, [1])
def quitbuttonevent(self):
sys.exit(0)
def collideEventIn(self,entry):
colliderINTO = entry.getIntoNodePath().getParent()
colliderFROM = entry.getFromNodePath().getParent()
print "hit!"
def endGameCollision(self,entry):
#Find some way to get the screen to fade out and quit, while displaying "END" or something
colliderINTO = entry.getIntoNodePath().getParent()
colliderFROM = entry.getFromNodePath().getParent()
print "END"
def setKey(self, key, value):
self.keyMap[key] = value
def setMouseBtn(self, btn, value):
self.mousebtn[btn] = value
def rotateLight(self, offset):
self.lightpivot.setH(self.lightpivot.getH()+offset*0)
#def rotateCam(self, offset):
#self.heading = self.heading - offset*10
def toggleGlow(self):
self.glowSize = self.glowSize + 1
if (self.glowSize == 4): self.glowSize = 0
self.filters.setBloom(blend=(0,0,0,1), desat=-0.5, intensity=8.0, size=self.glowSize)
def toggleShader(self):
self.inst5.destroy()
if (self.shaderenable):
self.inst5 = addInstructions(0.75, "Enter: Turn bump maps On")
self.shaderenable = 0
self.room.setShaderOff()
else:
self.inst5 = addInstructions(0.75, "Enter: Turn bump maps Off")
self.shaderenable = 1
self.room.setShaderAuto()
def controlCamera(self, task):
md = base.win.getPointer(0)
x = md.getX()
y = md.getY()
if base.win.movePointer(0, 100, 100):
self.heading = self.heading - (x - 100) * 0.2
self.pitch = self.pitch - (y - 100) * 0.2
if (self.pitch < -45): self.pitch = -45
if (self.pitch > 45): self.pitch = 45
self.camera.setHpr(self.heading,self.pitch,0)
dir = self.camera.getMat().getRow3(1)
elapsed = task.time - self.last
if (self.last == 0): elapsed = 0
if (self.mousebtn[0]):
self.focus = self.focus + dir * elapsed*30
if (self.mousebtn[1]) or (self.mousebtn[2]):
self.focus = self.focus - dir * elapsed*30
self.camera.setFluidPos(self.focus - (dir*5))
if (base.camera.getZ() < 8.0): base.camera.setZ( 8)
if (base.camera.getZ() > 400.0): base.camera.setZ( 400)
if (self.keyMap["camera-forward"]!=0):
self.camera.setFluidPos(self.camera.getPos + 100)
self.focus = self.camera.getPos() + (dir*5)
self.last = task.time
return Task.cont
t = BumpMapDemo()
run()