当前位置:网站首页>Panda3D keyboard moving scene
Panda3D keyboard moving scene
2022-07-25 05:07:00 【bcbobo21cn】
to glance at panda3d Example Tut-Roaming-Ralph.py;
The character roams through the scene ; Cursor keys control characters ;a、s Key rotation scene ;

pview Take a look at the model of the example , One is the human model , Another is the scene ;
It has a lot of code ; In addition to scene roaming , And collision detection ; collision detection , It is the character who meets the slope , Light up the key and you will climb , Hit the tree , Press the forward cursor key , Characters should not move ; The next round of collision detection ;
Have a look first a and s Key rotation scene ; According to its example, make a general ,
import direct.directbase.DirectStart
from panda3d.core import CollisionTraverser,CollisionNode
from panda3d.core import CollisionHandlerQueue,CollisionRay
from panda3d.core import Filename,AmbientLight,DirectionalLight
from panda3d.core import PandaNode,NodePath,Camera,TextNode
from panda3d.core import Vec3,Vec4,BitMask32
from direct.gui.OnscreenText import OnscreenText
from direct.actor.Actor import Actor
from direct.showbase.DirectObject import DirectObject
import random, sys, os, math
class World(DirectObject):
def __init__(self):
self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0}
base.win.setClearColor(Vec4(0,0,0,1))
self.environ = loader.loadModel("models/world")
self.environ.reparentTo(render)
self.environ.setPos(0,0,0)
self.accept("a", self.setKey, ["cam-left",1])
self.accept("s", self.setKey, ["cam-right",1])
taskMgr.add(self.move,"moveTask")
base.disableMouse()
# Create some lighting
ambientLight = AmbientLight("ambientLight")
ambientLight.setColor(Vec4(.3, .3, .3, 1))
directionalLight = DirectionalLight("directionalLight")
directionalLight.setDirection(Vec3(-5, -5, -5))
directionalLight.setColor(Vec4(1, 1, 1, 1))
directionalLight.setSpecularColor(Vec4(1, 1, 1, 1))
render.setLight(render.attachNewNode(ambientLight))
render.setLight(render.attachNewNode(directionalLight))
def setKey(self, key, value):
self.keyMap[key] = value
def move(self, task):
if (self.keyMap["cam-left"]!=0):
base.camera.setX(base.camera, -20 * globalClock.getDt())
if (self.keyMap["cam-right"]!=0):
base.camera.setX(base.camera, +20 * globalClock.getDt())
return task.cont
w = World()
run()
Scene loaded , hit a or s key , Only one effect , The scene has been moving ; Next time ;
self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0}
python I'm not familiar with the grammar of , This map The array doesn't seem to be declared first , Just assign the value directly ;
边栏推荐
- An article takes you to understand the sentinel mode of redis
- How to get the database creation time?
- "Niuke | daily question" inverse Polish expression
- Bypass XSS filters in Web Applications
- 2022-07-24: what is the output of the following go language code? A:[]int{}; B:[]int(nil); C:panic; D: Compilation error. package main import ( “fmt“ ) f
- Androd releases jitpack open source project (gradle7.2)
- Gbase 8A about no suitable driver
- Introduction to CpG control network
- Document collaboration tool recommendation
- Logu p3398 hamsters find sugar solution
猜你喜欢
随机推荐
Solve the problem that uni app applet obtains routes and route parameters
Idea2021 installation
rhce第一天
Zhongchuang computing power won the recognition of "2022 technology-based small and medium-sized enterprises"
Druid connection pool - strong self-study from 0. Those who don't understand Druid can click in. If you know not to click in, you will think I'm wordy
Document collaboration tool recommendation
epoll的实现原理
This low code reporting tool is needed for data analysis
Event cycle mechanism browser nodejs async await execution sequence promise execution sequence interview questions
four hundred and forty-four thousand one hundred and forty-one
【微信小程序】拍卖商品详情页设计与交互实现(包含倒计时、实时更新出价)
STM32 Development Notes 118: using CMSIS DSP Library in stm32cube IDE
harbor安装
MCU experiment record
How to judge whether it is attacked by DDoS
2022-07-24: what is the output of the following go language code? A:[]int{}; B:[]int(nil); C:panic; D: Compilation error. package main import ( “fmt“ ) f
Gbase JDBC connection database exception
Set up private CA server
[literature notes] pointmlp
2022-7-13 summary


![[literature notes] pointmlp](/img/8f/654dc6e2f4770b7f12aab49098d3d7.png)





