Код из samples
from panda3d.core import loadPrcFileData
loadPrcFileData("", "parallax-mapping-samples 3")
loadPrcFileData("", "parallax-mapping-scale 0.1")
import direct.directbase.DirectStart
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 direct.task.Task import Task
#from direct.actor.Actor import Actor
from direct.showbase.DirectObject import DirectObject
from direct.filter.CommonFilters import *
import sys,os
class BumpMapDemo(DirectObject):
def __init__(self):
self.room = loader.loadModel("models/abstractroom")
self.room.reparentTo(render)
self.keyMap = {"left":0, "right":0, "forward":0, "back":0}
base.disableMouse()
props = WindowProperties()
props.setCursorHidden(True)
base.win.requestProperties(props)
self.focus = Vec3(55,-55,20)
self.heading = 180
self.pitch = 0
self.mousex = 0
self.mousey = 0
self.last = 0
self.mousebtn = [0,0,0]
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("mouse3", self.setMouseBtn, [2, 1])
self.accept("mouse3-up", self.setMouseBtn, [2, 0])'''
self.accept("arrow_left", self.setKey, ["left",1])
self.accept("arrow_right", self.setKey, ["right",1])
self.accept("arrow_up", self.setKey, ["forward",1])
self.accept("arrow_down", self.setKey, ["back",1])
self.accept("arrow_left-up", self.setKey, ["left",0])
self.accept("arrow_right-up", self.setKey, ["right",0])
self.accept("arrow_up-up", self.setKey, ["forward",0])
self.accept("arrow_down-up", self.setKey, ["back",0])
def setMouseBtn(self, btn, value):
self.mousebtn[btn] = value
def setKey(self, key, value):
self.keyMap[key] = value
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 < -90): self.pitch = -90
if (self.pitch > 90): self.pitch = 90
base.camera.setHpr(self.heading,self.pitch,0)
dir = base.camera.getMat().getRow3(1)
dir1 = base.camera.getMat().getRow3(0)
elapsed = task.time - self.last
if (self.last == 0): elapsed = 0
if (self.keyMap["forward"]!=0):
self.focus = self.focus + dir * elapsed*30
if (self.keyMap["back"]!=0):
self.focus = self.focus - dir * elapsed*30
if (self.keyMap["left"]!=0):
self.focus = self.focus - dir1 * elapsed*30
if (self.keyMap["right"]!=0):
self.focus = self.focus + dir1 * elapsed*30
#print(dir)
'''if (self.last == 0): elapsed = 0
if (self.mousebtn[0]):
self.focus = self.focus + dir * elapsed*30
if (self.mousebtn[2]):
self.focus = self.focus - dir * elapsed*30'''
#base.camera.setPos(self.focus - (dir*5))
base.camera.setPos((self.focus - (dir*5))[0],(self.focus - (dir*5))[1],0)
if (base.camera.getX() < -59.0): base.camera.setX(-59)
if (base.camera.getX() > 59.0): base.camera.setX( 59)
if (base.camera.getY() < -59.0): base.camera.setY(-59)
if (base.camera.getY() > 59.0): base.camera.setY( 59)
if (base.camera.getZ() < 5.0): base.camera.setZ( 5)
if (base.camera.getZ() > 45.0): base.camera.setZ( 45)
self.focus = base.camera.getPos() + (dir*5)
self.last = task.time
return Task.cont
t = BumpMapDemo()
run()