Re: [PyOpenGL-Users] recommendation for setting correctly the new direction of an object
Brought to you by:
mcfletch
From: Mike C. F. <mcf...@vr...> - 2010-08-03 15:25:14
|
On 10-08-02 04:57 PM, Roland Everaert wrote: > Hi, > > I am currently writing a third person view space shooter where the > player can freely fly in the "map". I want to define an arcade flying > model like in most space shooter or spaceship simulation, but I face the > problem of specifying the transformation right. > > For the moment, my scene contains the player space ship pointing toward > the negative z axis, with the camera a little bit behind it. In front of > the ship there are 2 objects. When I apply some thrust to the player > spaceship it goes forward, but if I turn the ship, it is not changing > direction, while the ship and the camera are turning. > > My questions are the following: > > 1. Given the code below, why have I to call the method > self.__chasingView() after rendering the player's ship? > > 2. How to change the direction of the ship? Am I missing some glRotate() > functions somewhere in the code or should I change the code of method > setNewPosition() in such a way that the position of the ship is computed > on all 3 axis? > The problem you are facing is that you want to make the motion of the ship (x,y,z) modify by currentrotation * motionvector. You *could* do that with an ever-increasing set of glRotate/glTranslate calls (you'd need one for every change in direction), but what you really want to do is to track your position in "world" space and change that position by currentrotationmatrix * motionvector. I normally do that with a wrapped Quaternion class in OpenGLContext. See OpenGLContext/move/viewplatform.py for the code that wraps it (particularly the relativePosition() method, on which all of the various forward/sideways/up/down movements are built. http://bazaar.launchpad.net/~mcfletch/openglcontext/trunk/annotate/head:/OpenGLContext/move/viewplatform.py <http://bazaar.launchpad.net/%7Emcfletch/openglcontext/trunk/annotate/head:/OpenGLContext/move/viewplatform.py> > def setNewPosition(self): > self.addToPosition(z=-(self.thrust * self.tick)) > that should be something like self.addToPosition( self.thrust * self.tick * self.orientation ) HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |