2007年2月14日 星期三

Python-Ogre Tutorial 1-2

上一篇..

座標系

OGRE的座標系系統是:x左右, y上下, z前後
有些其他系統會將y和z顛倒過來

再修改一下_createScene:

def _createScene(self):
sceneManager = self.sceneManager
sceneManager.ambientLight = (1, 1, 1)

ent1 = sceneManager.createEntity("Robot", "robot.mesh")
node1 = sceneManager.rootSceneNode.createChildSceneNode("RobotNode")
node1.attachObject(ent1)

ent2 = sceneManager.createEntity("Robot2", "robot.mesh")
node2 = sceneManager.rootSceneNode.createChildSceneNode("RobotNode2", (50, 0, 0))
node2.attachObject(ent2)


放了兩台機器人:)
注意倒數第二行紅字的部份,第二台機器人有(50, 0, 0)的位移量。



def _createScene(self):
sceneManager = self.sceneManager
sceneManager.ambientLight = (1, 1, 1)

ent1 = sceneManager.createEntity("Robot", "robot.mesh")
node1 = sceneManager.rootSceneNode.createChildSceneNode("RobotNode")
node1.attachObject(ent1)

ent2 = sceneManager.createEntity("Robot2", "robot.mesh")
node2 = node1.createChildSceneNode("RobotNode2", (0, 100, 0))
node2.attachObject(ent2)

再注意倒數第二行,我們這次不把第二台機器人接上SceneManager的root SceneNode,而接上第一台機器人的SceneNode,並且給了(0, 100, 0)的位移量 (正上方一百單位)。



注意:ent2的位置現在完全跟隨著ent1,要是第一台機器人移動,第二台也會跟著動。Wiki中提到可以拿來做grouping (像星海的航空母艦子機 XD)

來看看旋轉類的效果吧:


def _createScene(self):
sceneManager = self.sceneManager
sceneManager.ambientLight = (1, 1, 1)

ent1 = sceneManager.createEntity("Robot", "robot.mesh")
node1 = sceneManager.rootSceneNode.createChildSceneNode("RobotNode")
node1.attachObject(ent1)
node1.yaw(ogre.Degree(-90))

ent2 = sceneManager.createEntity("Robot2", "robot.mesh")
node2 = sceneManager.rootSceneNode.createChildSceneNode("RobotNode2", ogre.Vector3(50, 0, 0))
node2.attachObject(ent2)
node2.pitch(ogre.Degree(-90))

ent3 = sceneManager.createEntity("Robot3", "robot.mesh")
node3 = sceneManager.rootSceneNode.createChildSceneNode("RobotNode3", ogre.Vector3(100, 0, 0))
node3.attachObject(ent3)
node3.roll(ogre.Degree(-90))




注意紅色那三行就對了,不同的轉向函式。

最後,關於縮放(scaling)功能...

Wiki上的語法都不能用:
node.setScale(0.5, 0.2, 1)
node.scaleBy(2, 10, 1)


要用這個:
node.setScale(0.5, 0.2, 1)



這裡有一些PyOgre及Python-Ogre的差異,可是沒寫到scale,害我自己找半天 :(
http://python-ogre.python-hosting.com/wiki/FAQindex:見Converting from PyOgre




Tutorial 1的部份寫了最多,接下來的幾個Tutorial會寫必較少。不是我偷懶喔,而是點到為止就好了。尤其是OGRE Input處理的部份,最後做遊戲時是不太會用到的。

沒有留言: