当前位置:网站首页>panda3d 键盘移动场景
panda3d 键盘移动场景
2022-07-25 05:04:00 【bcbobo21cn】
看一下panda3d示例Tut-Roaming-Ralph.py;
角色在场景中漫游;光标键控制人物;a、s键旋转场景;

pview看一下示例的模型,一个是人的模型,还有一个是场景;
它的代码比较多;除了场景漫游,还有碰撞检测;碰撞检测,就是人物碰到坡,打光标键自己会爬,碰到树,打前进光标键,人物应动不了;下回再整碰撞检测;
先看一下a和s键旋转场景;根据它的示例大体做一下,
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()
场景加载了,打a或s键,只有一下效果,场景一直在移动;下回再整;
self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0}
python的语法还不太熟悉,这个map数组看上去没有先声明,直接赋值就可以了;
边栏推荐
- Docker builds MySQL master-slave replication
- 2022-7-15 summary
- Completed project series Tutorials - smart campus management system
- [wechat applet] label (86/100)
- 小说抓取实战
- Your technical leader doesn't understand this? Without it, there is no complete thinking process of design
- 【基于stm32f103的SHT30温湿度显示】
- Bypass XSS filters in Web Applications
- How to transfer NFT metadata from IPFs to smart contracts
- Json.tojsonstring cannot pass Boolean
猜你喜欢
[email protected]研发效能度量指标"/>学习记录[email protected]研发效能度量指标

QT download installation tutorial

How to publish your own NPM package

Unity LOD

When we talk about immutable infrastructure, what are we talking about

PyG搭建GCN实现链接预测

Summary of UPR optimization suggestions of unity

Web: compiling big refactoring from 10 to 1

rhcsa暑假第二天

HMS core discovery Episode 16 live broadcast preview | play AI's new "sound" state with tiger pier
随机推荐
Pikachu vulnerability platform exercise
When image component in wechat applet is used as background picture
How can test / development programmers with 5 years of experience break through the technical bottleneck? Common problems in big factories
Tiny-emitter.js: a small event subscription and Publishing Library
Li Kou 731. My schedule II
深入掌握Service
Teach you how to locate unreasonable SQL? And optimize it
Most of the time, it's probability
[untitled]
It we media shows off its wealth in a high profile, and is targeted by hacker organizations. It is bound to be imprisoned
Your technical leader doesn't understand this? Without it, there is no complete thinking process of design
服务器防护的七个建议
2022-7-15 summary
Valley p2420 let's XOR solution
Construction of Seata multilingual system
The third question of force deduction -- the longest substring without repeated characters
PyG搭建GCN实现链接预测
rhce第一天
GDT,LDT,GDTR,LDTR
Xiaohongshu joins hands with HMS core to enjoy HD vision and grow grass for a better life