控制摄像头

默认摄影机控制系统

默认情况下,Pand3D运行一个任务,允许您使用鼠标移动相机。

导航的关键点是:

鼠标按钮

行动

左按钮:左右平移。

右按钮:前后移动。

中间按钮:围绕应用程序的原点旋转。

右和中按钮:围绕视图轴旋转视点。

Left Button:Pan left and right.

Right Button:Move forwards and backwards.

Middle Button:Rotate around the origin of the application.

Right and Middle Buttons:Roll the point of view around the view axis.
我们要编写一个任务来显式地控制相机的位置。任务只不过是一个每帧都被调用的过程。按以下方式更新代码:

from math import pi, sin, cosfrom direct.showbase.ShowBase import ShowBase
from direct.task import Taskclass MyApp(ShowBase):def __init__(self):ShowBase.__init__(self)# Load the environment model.self.scene = self.loader.loadModel("models/environment")# Reparent the model to render.self.scene.reparentTo(self.render)# Apply scale and position transforms on the model.self.scene.setScale(0.25, 0.25, 0.25)self.scene.setPos(-8, 42, 0)# Add the spinCameraTask procedure to the task manager.self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")# Define a procedure to move the camera.def spinCameraTask(self, task):angleDegrees = task.time * 6.0angleRadians = angleDegrees * (pi / 180.0)self.camera.setPos(20 * sin(angleRadians), -20 * cos(angleRadians), 3)self.camera.setHpr(angleDegrees, 0, 0)return Task.contapp = MyApp()
app.run()

在我们的代码中,过程spinCameraTask()根据经过的时间计算相机的所需位置。照相机每秒旋转6度。前两行计算相机所需的方向;首先以度为单位,然后以弧度为单位。setPos()调用实际上设置相机的位置。(请记住Y是水平的,Z是垂直的,因此通过设置X和Y的动画来改变位置,而Z则固定在地面以上3个单位处。)setHpr()调用实际上设置了方向。
下面代码,照相机向左转动,位置不变化

from math import pi, sin, cosfrom direct.showbase.ShowBase import ShowBase
from direct.task import Taskclass MyApp(ShowBase):def __init__(self):self.i=0ShowBase.__init__(self)# Load the environment model.self.scene = self.loader.loadModel("models/environment")# Reparent the model to render.self.scene.reparentTo(self.render)# Apply scale and position transforms on the model.self.scene.setScale(0.25, 0.25, 0.25)self.scene.setPos(-8, 42, 0)# Add the spinCameraTask procedure to the task manager.self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")# Define a procedure to move the camera.def spinCameraTask(self, task):self.i+=0.1j=int(self.i)self.camera.setPos(0,0,3)self.camera.setHpr(j, 0, 0)return Task.contapp = MyApp()
app.run()

下面代码先向左移,再向右移,摄相机来回移动

from math import pi, sin, cosfrom direct.showbase.ShowBase import ShowBase
from direct.task import Taskclass MyApp(ShowBase):def __init__(self):self.i=0self.step=0.5ShowBase.__init__(self)# Load the environment model.self.scene = self.loader.loadModel("models/environment")# Reparent the model to render.self.scene.reparentTo(self.render)# Apply scale and position transforms on the model.self.scene.setScale(0.25, 0.25, 0.25)self.scene.setPos(-8, 42, 0)# Add the spinCameraTask procedure to the task manager.self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")# Define a procedure to move the camera.def spinCameraTask(self, task):#angleDegrees = task.time * 6.0#angleRadians = angleDegrees * (pi / 180.0)#self.camera.setPos(20 * sin(angleRadians), -20 * cos(angleRadians), 3)if self.i>50 or self.i<-50:self.step=-self.stepself.i+=self.stepj=int(self.i)self.camera.setPos(0,0,3)self.camera.setHpr(j, 0, 0)return Task.contapp = MyApp()
app.run()

self.camera.setHpr(x, y, z)
x:左(正数),右(负数)
y:上(正数),下(负数)
z:顺时针向右转(正数),逆时针向左转(负数)

python3的3D实战 -基于panda3d(3)相关推荐

  1. python3的3D实战 -基于panda3d(4)

    Actor类是用于动画模型的.请注意,我们仅在静态模型和Actor是动画时才使用loadModel().Actor类的两个构造函数参数是包含模型的文件名称和包含包含动画的文件名称的Python字典. ...

  2. python3的3D实战-基于panda3d(2)

    Panda3D包含一个称为场景图Scene Graph的数据结构.场景图Scene Graph 是包含所有需要渲染的对象的树.树的根是一个名为render的对象.在首次插入到场景图Scene Grap ...

  3. python3的3D实战-基于panda3d(1)

    Panda 3D 是一个3D游戏引擎:一个 3D 渲染和游戏开发库 开发维护者:迪士尼VR工作室和卡耐基梅隆娱乐技术中心 授权协议:BSD 类继承自ShowBase.这个类加载大多数其他Panda3D ...

  4. python3的3D开发-基于blender(1)

    Blender Python API特性: 编辑用户界面可以编辑的任何数据(场景,网格,粒子等). 修改用户首选项.键图和主题. 使用自己的设置运行工具. 创建用户界面元素,如菜单,标题和面板. 创建 ...

  5. python3的3D开发-基于blender(2)

    访问集合 输出当前对象集合中的对象名字. >>> for obj in bpy.data.objects: ... print(obj.name) ... Camera Cube L ...

  6. Python3《机器学习实战》学习笔记(八):支持向量机原理篇之手撕线性SVM

    原 Python3<机器学习实战>学习笔记(八):支持向量机原理篇之手撕线性SVM 置顶 2017年09月23日 17:50:18 阅读数:12644 转载请注明作者和出处: https: ...

  7. Python3《机器学习实战》学习笔记(三):决策树实战篇

    转载请注明作者和出处: http://blog.csdn.net/c406495762  运行平台: Windows  Python版本: Python3.x  IDE: Sublime text3 ...

  8. 自动化运维-----项目实战: 基于Ansible的云平台自动化运维系统

    文章目录 项目实战: 基于Ansible的云平台自动化运维系统 一.项目介绍 1.项目介绍 2.项目背景 二.项目环境搭建 1.项目目录的配置 2.远程服务器虚拟环境的配置 3.MySQL数据库配置 ...

  9. 机器学习实战:基于Scikit-Learn.Keras和TensorFlow(原书第2版) 奥雷利安·杰龙——环境搭建anaconda

    这个学期开了一门课,机器学习 然后实验部分用的是这本教材:机器学习实战:基于Scikit-Learn.Keras和TensorFlow 奥雷利安·杰龙,第几版的就不知道了. 用最新的机器学习库,一定会 ...

最新文章

  1. 曾被无视多年,却成就19世纪最伟大的一场革命,影响了整个世界!
  2. 禅修笔记——硅谷最受欢迎的情商课
  3. 新概念0804:潘石屹学习python
  4. C# 系统应用之窗体最小化至任务栏及常用操作
  5. React开发(145):目录规范:
  6. python2 爬虫value_53. Python 爬虫(2)
  7. MQL5 信号的优势
  8. MDIO总线介绍 |CSDN创作打卡
  9. 微信小程序官方示例文档免费下载文档
  10. java poi pdf实例_java通过poi导出excel和pdf
  11. 沟通中的情绪管理(演讲稿)
  12. ps3自建服务器,PS3新手图文教程之网络设置
  13. html修改progress背景色,html5 progress标签如何更改进度条颜色?progress进度条详解...
  14. 全网最易懂的Flink背压问题,看不懂你打我~
  15. Kotlin-Android世界的一股清流-Package
  16. 图情论文笔记 | 智慧图书馆下的阅读推广服务策略
  17. 为什么建议大家使用 Linux 开发?有那么爽吗?
  18. Flutter 2(1),还在等机会
  19. 自然语言处理的数学原理(一)
  20. Linux调试器工作原理——基础篇

热门文章

  1. 题解 P4779 【【模板】单源最短路径(标准版)】
  2. 网络流24题之餐巾计划问题
  3. Python - 字符串
  4. 如何让FPGA中的SPI与其他模块互动起来
  5. 素数 乘法表 闰年
  6. Appium+RobotFrameWork测试环境搭建
  7. 1.初次运行git前的配置
  8. mongodb基本语句
  9. Js获取地址栏参数值
  10. CC2538相关资料