访问搅拌机对象的旋转

发布于 2024-10-26 23:52:09 字数 429 浏览 1 评论 0原文

我刚刚开始使用 Blender 和 Python,我一直在尝试使用带有 Python 2.5.1 的 Blender 游戏引擎来访问立方体的旋转属性

我将这个 python 脚本附加到场景中的立方体上:

cont = GameLogic.getCurrentController()
own = cont.owner

print own.RotX, own.RotY, own.RotZ

我得到的一切是这个错误吗:
来自控制器“cont#CONTR#1”的 Python 脚本错误: 回溯(最近一次调用最后一次): 文件“starter”,第 4 行,位于 AttributeError:“KX_GameObject”对象没有属性“RotX”

有人能告诉我如何访问旋转属性吗?感觉我要疯了!

谢谢,
将要

I'm just starting out with Blender and Python and I've been trying to access the rotation properties of a cube using the blender game engine with Python 2.5.1

I have this python script attached to a cube in my scene:

cont = GameLogic.getCurrentController()
own = cont.owner

print own.RotX, own.RotY, own.RotZ

All I get is this error:
Python script error from controller "cont#CONTR#1":
Traceback (most recent call last):
File "starter", line 4, in
AttributeError: 'KX_GameObject' object has no attribute 'RotX'

Can anybody tell me how I can access the rotation properties? feel like I'm going crazy!

Thanks,
Will

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一场春暖 2024-11-02 23:52:09

您可以使用 localOrientation 属性,这似乎是在游戏引擎中访问旋转的唯一方法,而无需使用不允许打印当前旋转的运动执行器。

localOrientation 由列表列表或 3x3 矩阵组成。矩阵的每一行都是相应轴将指向的点。
对于默认多维数据集:

import GameLogic
cont = GameLogic.getCurrentController()
own = cont.owner

print(own.localOrientation)

将产生
Matrix((1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)) 因为对象的x轴指向点(1, 0, 0),y轴指向( 0, 1, 0),z 到 (0, 0, 1)

希望这有帮助!

编辑:
只是玩弄这个,我想说,如果事情表现得很奇怪,请记住这是本地导向。如果事情不正常,请检查对象的本地位置!我只是感到非常困惑,因为我没有意识到我的对象的本地位置为 (0,0,0),尽管它看起来像是在 (9,-10,0)

You can use the property localOrientation, which seems to be the only way to access rotation in the game engine without using the motion actuator which doesn't allow the printing of the current rotation.

localOrientation consists of a list of lists, or a 3x3 matrix. each row of the matrix is a point that the corresponding axis will point to.
For a default cube:

import GameLogic
cont = GameLogic.getCurrentController()
own = cont.owner

print(own.localOrientation)

will yield
Matrix((1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)) because the x axis of the object points to the point (1, 0, 0), and y points to (0, 1, 0), the z to (0, 0, 1)

hope this helps!

EDIT:
just played around with this, and I would like to say that if things are acting weird remember that this is LOCAL orientation. Check the local location of the object if things aren't working right! I just got severely confused because I didn't realize my object had a local position of (0,0,0) even though it looked like it was at (9,-10,0)

你不是我要的菜∠ 2024-11-02 23:52:09

据我记得,您可以通过 getDRot() 函数访问旋转属性,其中 getDRot()[0] = rotX,getDRot()[1] = rotY,getDRot()[2] = rotZ。但我不确定是否可以在所有者对象上调用它。从我很久以前写的一些片段来看,我在执行器上调用了这个函数。所以你的球必须有一个 Actuator,然后你就可以

import GameLogic
cont = GameLogic.getCurrentController()
moveAct = cont.getActuator("move") # or the name you gave it
rotX = moveAct.getDRot()[0]
#etc

As far as I remember you can access the rotation properties by the getDRot() function, where getDRot()[0] = rotX, getDRot()[1] = rotY, getDRot()[2] = rotZ. But I am not sure if you can call it on the owner object. From some snippets that I have written a long time ago I call this function on an Actuator. So your ball must have an Actuator, and then you can

import GameLogic
cont = GameLogic.getCurrentController()
moveAct = cont.getActuator("move") # or the name you gave it
rotX = moveAct.getDRot()[0]
#etc
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文