help the noob to make his objects move

GoGonan

01-09-2006 15:36:20

ok, firstyl im a noob, and i wanna know how to move my objects. i've tried to move them but the program crashes when i press a key(mostly it just doesn't work).

could someone please provide a simple example of moving objects (of corse i can use a physics engine to move them but i'm still the same noob as when i started writing this)?

can't it be done just by

if self.inputDevice.isKeyDown(ogre.KC_KEY):
node.translate(vector3 * (0, 0, 0))

bharling

02-09-2006 10:41:20

Have a look at the SampleFramework.py, the process for moving scenenodes is the same as for moving the camera. There is a variable called self.translateVector which holds all the keyboard input obtained from the '_processUnbufferedKeyInput' function. Then the program calls the 'moveRelative' method of the camera's sceneNode during the 'moveCamera' function. Since all this is doing is performing 'moveRelative' on a sceneNode, it will be the same for sceneNodes with models attached instead of the camera.
I think this is the important bit of the code:



def _processUnbufferedKeyInput(self, frameEvent):
if self.inputDevice.isKeyDown(ogre.KC_A):
self.translateVector.x = -self.moveScale

if self.inputDevice.isKeyDown(ogre.KC_D):
self.translateVector.x = self.moveScale

...

def _moveCamera(self):
self.camera.yaw(self.rotationX)
self.camera.pitch(self.rotationY)
self.camera.moveRelative(self.translateVector)


Note that this is all contained within a FrameListener class, which has to be registered with ogre's list of framelisteners.

Hope that helps a bit. Basically, just go through the tutorials on the site and all will become clear. :wink:

GoGonan

02-09-2006 13:22:43

ok, i tried, i created a translateVector, but the fish i have does not move. what s the reason?

class FrameListener(ogre.CombinedListener):
def __init__(self, renderWindow, camera):
ogre.CombinedListener.__init__(self)
self.translateVector = ogre.Vector3(0.0,0.0,0.0)

self._setupInput

def FrameStarted(self, frameEvent):
self.inputDevice.capture
if self.timeUntilNextToggle >= 0:
self.timeUntilNextToggle -= frameEvent.timeSinceLastFrame
if inputDevice.isKeyDown(ogre.KC_K):
translateVector.z += paikka.move
return True

def FrameEnded(self, frameEvent):
self._updateStatistics()
return True

def _movePaikka(paikka):
paikka.yaw(paikka.rotationX)
paikka.pitch(paikka.rotationY)
paikka.moveRelative(paikka.translateVector)


this is confusing... thereƤs no tutorial for moving nodes. only for moving the camera.

no help. it doesnot move.

TOO HARD!

second attempt:


class FrameListener(sf.FrameListener):
def __init__(self, renderWindow, camera, sceneManager):
ogre.CombinedListener.__init__(self)
node.move = 250

def frameStarted(paikka, frameEvent):
inputDevice = self.inputDevice
inputDevice.capture()

transVector = ogre.Vector3(0.0,0.0,0.0)

if inputDevice.isKeyDown(KC_K):
transVector.x -= node.move


third attempt, no moving fish. this time im giving the whole code.

from pyogre import ogre
import SampleFramework as sf


class Application(sf.Application):
def _createScene(self):
sceneManager = self.sceneManager
camera = self.camera

ent = sceneManager.createEntity('fish','fish.mesh')
node = sceneManager.rootSceneNode.createChildSceneNode().attachObject(ent)

pass


class FrameListener(sf.FrameListener):
def __init__(self, renderWindow, camera, sceneManager):
ogre.CombinedListener.__init__(self)

self.transVector = ogre.Vector3(0.0,0.0,0.0)

self.node.orientation = 10
self.node.move = 250

def frameStarted(self, frameEvent):
inputDevice = self.inputDevice
inputDevice.capture()

if inputDevice.isKeyDown(KC_K):
transVector.x -= self.node.moveScale

self.node.translate(self.node.orientation * self.transVector * evt.timeSinceLastFrame)


if __name__ == '__main__':
try:
application = Application()
application.go()
except ogre.OgreException, e:
print e


there is no wrestling with pyhton, but it seems that i have tow rite 1000 lines to get something moving in 1 direction?

dermont

02-09-2006 16:11:43

You should really go through the beginner tutorials and demos. The following was on pyOgre1.2.x but should work on 1.0.6


from pyogre import ogre
import SampleFramework as sf


class Application(sf.Application):
def _createScene(self):
sceneManager = self.sceneManager
ent = sceneManager.createEntity('fish','fish.mesh')
self.node = sceneManager.rootSceneNode.createChildSceneNode("fish")
self.node.attachObject(ent)

def _createFrameListener(self):
self.frameListener = FrameListener(self.renderWindow, self.camera,self.sceneManager)
self.root.addFrameListener(self.frameListener)


class FrameListener(sf.FrameListener):
def __init__(self, renderWindow, camera, sceneManager):
sf.FrameListener.__init__(self, renderWindow, camera)
self.node = sceneManager.getSceneNode("fish")

def frameStarted(self, frameEvent):
moveFactor = 80.0 * frameEvent.timeSinceLastFrame
inputDevice = self.inputDevice
inputDevice.capture()

if inputDevice.isKeyDown(ogre.KC_UP):
self.node.translate(0.0, moveFactor, 0.0)
if inputDevice.isKeyDown(ogre.KC_DOWN):
self.node.translate(0.0, -moveFactor, 0.0)
if inputDevice.isKeyDown(ogre.KC_RIGHT):
self.node.translate(moveFactor, 0.0,0.0)
if inputDevice.isKeyDown(ogre.KC_LEFT):
self.node.translate(-moveFactor, 0.0,0.0)
if inputDevice.isKeyDown(ogre.KC_Z):
self.node.translate(0.0, 0.0, moveFactor)
if inputDevice.isKeyDown(ogre.KC_X):
self.node.translate(0.0, 0.0, -moveFactor)

if inputDevice.isKeyDown(ogre.KC_ESCAPE):
return False
return True

#self.node.translate(self.node.orientation * self.transVector * frameEvent.timeSinceLastFrame)



if __name__ == '__main__':
try:
application = Application()
application.go()
except ogre.OgreException, e:
print e

GoGonan

02-09-2006 17:37:16

well i went through them and tried to follow them but no... it didnt help.

btw is there pyogre 12x?

oh and thanks dermont

viblo2

04-09-2006 12:37:45

well i went through them and tried to follow them but no... it didnt help.

btw is there pyogre 12x?

oh and thanks dermont


Yes, "Development Snapshot" on http://www.ogre3d.org/wiki/index.php/PyOgre