Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Roland Everaert <r.everaert@gm...>  20100826 17:59:49

Hi, The space ship is behaving like a aircraft, so the thrust comes from the rear of the ship and when I turn the ship to the left or the right or go up and down, the ship will go into that new direction. For the delta angles, when an arrow key is pressed to change the orientation of the ship, a constant value is applied to the variable corresponding to the impacted axis, left and right modify the yaxis and up and down modify the xaxis. Applying a rotation transformation is not a problem, the problem is really computing the new position given the current one, the new orientation and the distance (the thrust), hence, if I understand correctly the principle, create a new vector that can be added to the current position. Regards, Roland. Le 08/25/10 21:38, Matthias Baas a écrit : > Hi Roland, > > Roland Everaert wrote: >> searching some guidance on how to use quaternions correctly given the >> following parameters are known to me: >> >>  The thrust to apply to the ship >>  The current position of the ship in the scene >>  The current angle of rotation on all 3 axes >>  The delta to be added to each axis to define the new angle of rotation >> >> Below is the code I have written so far to update the position of the ship: >> >> if self.position[0] == 0.0 and self.position[2] == 0.0 and >> self.position[2] == 0.0: >> v = vec3(0, 0, (self.thrust * self.tick)) >> else: >> v = vec3(self.position) * (self.thrust * self.tick) >> q = quat().fromAngleAxis(math.radians(self.x_delta_angle), (1,0,0)) >> q_tmp = quat().fromAngleAxis(math.radians(self.y_delta_angle), >> (0,1,0)) >> q = q * q_tmp >> q_tmp = quat().fromAngleAxis(math.radians(self.z_delta_angle), >> (0,0,1)) >> q = (q * q_tmp) >> >> self.addToPosition(*q.rotateVec(v)) > Hm, I'm not quite sure I understand how you want to move your ship. You > should add comments to the lines to explain what the idea behind each > section of the code is. What movements is the ship supposed to be able > to do? > You are saying you represent the state of the ship with a position and 3 > rotation angles. About what axes are you rotating the ship? > How do you calculate your delta angles when you want to change the > orientation of the ship? > > I think what the guys in the other list meant when they said you should > use quaternions is to replace your 3 angles by a quaternion to represent > the orientation of the ship. For applying the quaternion as an OpenGL > transformation you can convert it into a matrix and then pass that one > to OpenGL. > >  Matthias  > > >  > Sell apps to millions through the Intel(R) Atom(Tm) Developer Program > Be part of this innovative community and reach millions of netbook users > worldwide. Take advantage of special opportunities to increase revenue and > speed timetomarket. Join now, and jumpstart your future. > http://p.sf.net/sfu/intelatomd2d > _______________________________________________ > cgkituser mailing list > cgkituser@... > https://lists.sourceforge.net/lists/listinfo/cgkituser 
From: Roland Everaert <r.everaert@gm...>  20100824 18:53:45

Hi, I am trying since some times to write a "little" video game, a space shooter, using pygame and pyopengl. Everything is fine until now except that I am not able to update correctly the position of the player ship, and any other object in the scene. So after some recommendation from the pyopengl mailing list, regarding using quaternions to do the job, I tried using the quat class from cgkit, but without any success. So I am searching some guidance on how to use quaternions correctly given the following parameters are known to me:  The thrust to apply to the ship  The current position of the ship in the scene  The current angle of rotation on all 3 axes  The delta to be added to each axis to define the new angle of rotation Below is the code I have written so far to update the position of the ship: if self.position[0] == 0.0 and self.position[2] == 0.0 and self.position[2] == 0.0: v = vec3(0, 0, (self.thrust * self.tick)) else: v = vec3(self.position) * (self.thrust * self.tick) q = quat().fromAngleAxis(math.radians(self.x_delta_angle), (1,0,0)) q_tmp = quat().fromAngleAxis(math.radians(self.y_delta_angle), (0,1,0)) q = q * q_tmp q_tmp = quat().fromAngleAxis(math.radians(self.z_delta_angle), (0,0,1)) q = (q * q_tmp) self.addToPosition(*q.rotateVec(v)) So far, I use only quat and vec3, but I plan to use more from cgkit, like the components which seems great to define physical objects properties or the OBJ loader. I am quite new to CG and video game programming, so any help will be more than appreciated. Thanks, Roland. 
From: Matthias Baas <matthias.baas@gm...>  20100825 19:38:37

Hi Roland, Roland Everaert wrote: > searching some guidance on how to use quaternions correctly given the > following parameters are known to me: > >  The thrust to apply to the ship >  The current position of the ship in the scene >  The current angle of rotation on all 3 axes >  The delta to be added to each axis to define the new angle of rotation > > Below is the code I have written so far to update the position of the ship: > > if self.position[0] == 0.0 and self.position[2] == 0.0 and > self.position[2] == 0.0: > v = vec3(0, 0, (self.thrust * self.tick)) > else: > v = vec3(self.position) * (self.thrust * self.tick) > q = quat().fromAngleAxis(math.radians(self.x_delta_angle), (1,0,0)) > q_tmp = quat().fromAngleAxis(math.radians(self.y_delta_angle), > (0,1,0)) > q = q * q_tmp > q_tmp = quat().fromAngleAxis(math.radians(self.z_delta_angle), > (0,0,1)) > q = (q * q_tmp) > > self.addToPosition(*q.rotateVec(v)) Hm, I'm not quite sure I understand how you want to move your ship. You should add comments to the lines to explain what the idea behind each section of the code is. What movements is the ship supposed to be able to do? You are saying you represent the state of the ship with a position and 3 rotation angles. About what axes are you rotating the ship? How do you calculate your delta angles when you want to change the orientation of the ship? I think what the guys in the other list meant when they said you should use quaternions is to replace your 3 angles by a quaternion to represent the orientation of the ship. For applying the quaternion as an OpenGL transformation you can convert it into a matrix and then pass that one to OpenGL.  Matthias  
From: Roland Everaert <r.everaert@gm...>  20100826 17:59:49

Hi, The space ship is behaving like a aircraft, so the thrust comes from the rear of the ship and when I turn the ship to the left or the right or go up and down, the ship will go into that new direction. For the delta angles, when an arrow key is pressed to change the orientation of the ship, a constant value is applied to the variable corresponding to the impacted axis, left and right modify the yaxis and up and down modify the xaxis. Applying a rotation transformation is not a problem, the problem is really computing the new position given the current one, the new orientation and the distance (the thrust), hence, if I understand correctly the principle, create a new vector that can be added to the current position. Regards, Roland. Le 08/25/10 21:38, Matthias Baas a écrit : > Hi Roland, > > Roland Everaert wrote: >> searching some guidance on how to use quaternions correctly given the >> following parameters are known to me: >> >>  The thrust to apply to the ship >>  The current position of the ship in the scene >>  The current angle of rotation on all 3 axes >>  The delta to be added to each axis to define the new angle of rotation >> >> Below is the code I have written so far to update the position of the ship: >> >> if self.position[0] == 0.0 and self.position[2] == 0.0 and >> self.position[2] == 0.0: >> v = vec3(0, 0, (self.thrust * self.tick)) >> else: >> v = vec3(self.position) * (self.thrust * self.tick) >> q = quat().fromAngleAxis(math.radians(self.x_delta_angle), (1,0,0)) >> q_tmp = quat().fromAngleAxis(math.radians(self.y_delta_angle), >> (0,1,0)) >> q = q * q_tmp >> q_tmp = quat().fromAngleAxis(math.radians(self.z_delta_angle), >> (0,0,1)) >> q = (q * q_tmp) >> >> self.addToPosition(*q.rotateVec(v)) > Hm, I'm not quite sure I understand how you want to move your ship. You > should add comments to the lines to explain what the idea behind each > section of the code is. What movements is the ship supposed to be able > to do? > You are saying you represent the state of the ship with a position and 3 > rotation angles. About what axes are you rotating the ship? > How do you calculate your delta angles when you want to change the > orientation of the ship? > > I think what the guys in the other list meant when they said you should > use quaternions is to replace your 3 angles by a quaternion to represent > the orientation of the ship. For applying the quaternion as an OpenGL > transformation you can convert it into a matrix and then pass that one > to OpenGL. > >  Matthias  > > >  > Sell apps to millions through the Intel(R) Atom(Tm) Developer Program > Be part of this innovative community and reach millions of netbook users > worldwide. Take advantage of special opportunities to increase revenue and > speed timetomarket. Join now, and jumpstart your future. > http://p.sf.net/sfu/intelatomd2d > _______________________________________________ > cgkituser mailing list > cgkituser@... > https://lists.sourceforge.net/lists/listinfo/cgkituser 
From: Matthias Baas <matthias.baas@gm...>  20100831 21:51:55

Hi Roland, > The space ship is behaving like a aircraft, so the thrust comes from the > rear of the ship and when I turn the ship to the left or the right or go > up and down, the ship will go into that new direction. Well, I think a real aircraft couldn't really navigate in space due to the lack of an atmosphere, but as this is just going to be a simple game, I suppose this doesn't really matter... ;) > For the delta angles, when an arrow key is pressed to change the > orientation of the ship, a constant value is applied to the variable > corresponding to the impacted axis, left and right modify the yaxis and > up and down modify the xaxis ok, but you still have to be aware of what the actual rotation axes are. Obviously, it's not just the global axes (which your code seemed to suggest) but the local ones. Once you have established a suitable local coordinate system, applying the thrust shouldn't be a problem as it just acts in the opposite direction of what's considered to be "forward". So the question still is how you represent the state of your space ship. Obviously you need a position and an orientation. The position can be represented as a point in space, but for the orientation it would probably be advantageous to represent it as a single orientation instead of three Euler angles. Maybe you could try and do some experiments with a space ship that has no particular position but only an orientation (just render it at the origin and see if its orientation behaves correctly). Once the orientation of the space ship behaves right, adding the proper position shouldn't be a problem anymore. Cheers,  Matthias  
From: Roland Everaert <r.everaert@gm...>  20100904 14:37:07

Making the ship rotate is not the problem, actually I am usingthe following code to define the rotation: def __chasingView(self, planex, planey, planez, pitch, heading, roll): glRotatef(roll, 0.0, 0.0, 1.0) glRotatef(heading, 0.0, 1.0, 0.0) glRotatef(pitch, 1.0, 0.0, 0.0) glTranslate(planex, planey, planez) An here is the call to the method: playerShipPos = self.__player.getPosition() x, y, z = self.__player.getAngle() self.__chasingView(playerShipPos[0], playerShipPos[1], playerShipPos[2], x, y, z) I think that my biggest problem is my lack in math which prevent me from understanding the logic involved. If you have any book recommandation, it is welcomed. If you think that seeing the full code would help you understanding the logic implemented so far, do not hesitate to ask. Regards, Roland. Le 08/31/10 23:51, Matthias Baas a écrit : > Hi Roland, > >> The space ship is behaving like a aircraft, so the thrust comes from the >> rear of the ship and when I turn the ship to the left or the right or go >> up and down, the ship will go into that new direction. > Well, I think a real aircraft couldn't really navigate in space due to > the lack of an atmosphere, but as this is just going to be a simple > game, I suppose this doesn't really matter... ;) > >> For the delta angles, when an arrow key is pressed to change the >> orientation of the ship, a constant value is applied to the variable >> corresponding to the impacted axis, left and right modify the yaxis and >> up and down modify the xaxis > ok, but you still have to be aware of what the actual rotation axes are. > Obviously, it's not just the global axes (which your code seemed to > suggest) but the local ones. > Once you have established a suitable local coordinate system, applying > the thrust shouldn't be a problem as it just acts in the opposite > direction of what's considered to be "forward". > So the question still is how you represent the state of your space ship. > Obviously you need a position and an orientation. The position can be > represented as a point in space, but for the orientation it would > probably be advantageous to represent it as a single orientation instead > of three Euler angles. Maybe you could try and do some experiments with > a space ship that has no particular position but only an orientation > (just render it at the origin and see if its orientation behaves > correctly). Once the orientation of the space ship behaves right, adding > the proper position shouldn't be a problem anymore. > > Cheers, > >  Matthias  > > >  > This SF.net Dev2Dev email is sponsored by: > > Show off your parallel programming skills. > Enter the Intel(R) Threading Challenge 2010. > http://p.sf.net/sfu/intelthreadsfd > _______________________________________________ > cgkituser mailing list > cgkituser@... > https://lists.sourceforge.net/lists/listinfo/cgkituser 
From: Matthias Baas <matthias.baas@gm...>  20100913 22:18:24

Hi Roland, On 11.09.10 21:59, Roland Everaert wrote: > I have the feeling that the player ship should be the "center of the > universe" and that everything should move around it, but I am not sure > it is the way I should think how to move the camera and I don't really > know how to do it. Well, instead of transforming your ship, you would just apply the inverse transformation to the world (if your ship moves up it's as if the world around it moves down instead). > Now that I can make an object moves using matrix, what would be the > advantage of using quaternions? If everything works as expected now, I would say, you don't have to bother using quaternions for this project. In general, quaternions have an advantage when you want to interpolate orientations because they allow a smooth interpolation whereas just interpolating angles often produces undesirable motions. > I have seen one or two typo in the online documentation of cgkit, to > whom should I report those errors? You can just mail them to me. > When I will get a grasp on how to use the package, I was thinking about > writing some tutorials showing how to integrate cgkit with pygame, to > whom should I submit them and in which format? Again, just send them to me. About the format, have a look into the source archive, they are written in restructured text and converted using the docutils. But actually, I'd like to change that somewhat as I'm having some problems recreating them at the moment. I'm not sure if I'll either switch to Sphinx (like the manual) or just use the wiki.  Matthias  
From: Roland Everaert <r.everaert@gm...>  20100914 20:05:31

Hi, It's me again :( This is were I am blocked, the other objects in my scene are "moving" regarding the position of the camera and not the position of the player ship :'(. Below I break down how I perform the transformations: Transformation for the camera: cameraMat = mat4.translation(vec3(0.0, 3.0, 10.0)) Initial transformation for the player ship: playerFM = FlightModel(mat4.identity()) The class FlightModel as the name implied allows to define all the transformation to apply so that the player ship is "moving" correctly. Initial transformation of the other object of the scene: redShipMat = mat4.translation(vec3(5.0, 0.0, 10.0)) redShipMat = redShipMat * cameraMat In the main loop of pygame: glLoadMatrixf(cameraMat.toList()) # Rendering of the player ship glLoadMatrixf(redShipMat.toList()) # Rendering of the other object #Capturing input from the user # Below is the computation of the transformation to be applied to the other object of the scene redShipMat = playerFM.getMat4(time_passed) * redShipMat Here is the code of the method getMat4(): def getMat4(self, time_elapsed): mat_tmp = mat4.translation(vec3(0.0, 0.0, self.__thrust * time_elapsed)).inverse() mat_tmp = mat_tmp.rotate(math.radians(self.__xAngle * time_elapsed), vec3(1.0, 0.0, 0.0)).inverse() mat_tmp = mat_tmp.rotate(math.radians(self.__yAngle * time_elapsed), vec3(0.0, 1.0, 0.0)).inverse() self.__xAngle = 0.0 self.__yAngle = 0.0 return mat_tmp From my point of view, the camera should be located at (0.0, 3.0, 10.0) and the player ship at the origin, but if I set those coordinates for the camera matrix, the ship is not visible because its the player ship that move and not the camera. What I am missing? Regards, Roland. Le 09/14/10 00:18, Matthias Baas a écrit : > Hi Roland, > > On 11.09.10 21:59, Roland Everaert wrote: >> I have the feeling that the player ship should be the "center of the >> universe" and that everything should move around it, but I am not sure >> it is the way I should think how to move the camera and I don't really >> know how to do it. > Well, instead of transforming your ship, you would just apply the > inverse transformation to the world (if your ship moves up it's as if > the world around it moves down instead). > >> Now that I can make an object moves using matrix, what would be the >> advantage of using quaternions? > If everything works as expected now, I would say, you don't have to > bother using quaternions for this project. > In general, quaternions have an advantage when you want to interpolate > orientations because they allow a smooth interpolation whereas just > interpolating angles often produces undesirable motions. > >> I have seen one or two typo in the online documentation of cgkit, to >> whom should I report those errors? > You can just mail them to me. > >> When I will get a grasp on how to use the package, I was thinking about >> writing some tutorials showing how to integrate cgkit with pygame, to >> whom should I submit them and in which format? > Again, just send them to me. About the format, have a look into the > source archive, they are written in restructured text and converted > using the docutils. But actually, I'd like to change that somewhat as > I'm having some problems recreating them at the moment. I'm not sure if > I'll either switch to Sphinx (like the manual) or just use the wiki. > >  Matthias  > >  > Start uncovering the many advantages of virtual appliances > and start using them to simplify application deployment and > accelerate your shift to cloud computing. > http://p.sf.net/sfu/novellsfdev2dev > _______________________________________________ > cgkituser mailing list > cgkituser@... > https://lists.sourceforge.net/lists/listinfo/cgkituser 
From: Matthias Baas <matthias.baas@gm...>  20100919 17:03:32

On 14.09.10 21:05, Roland Everaert wrote: > cameraMat = mat4.translation(vec3(0.0, 3.0, 10.0)) > [...] > redShipMat = mat4.translation(vec3(5.0, 0.0, 10.0)) > redShipMat = redShipMat * cameraMat > [...] > glLoadMatrixf(cameraMat.toList()) > # Rendering of the player ship > > glLoadMatrixf(redShipMat.toList()) Why are you applying the camera to the transformation of the red ship manually and why are you using glLoadMatrix() instead of glMultMatrix() to set the ship's transformation? Usually, you set the view transformation at the beginning and then you don't have to worry about the camera anymore. Everything else is described in the world coordinate system. I think it would really be beneficial if you could get hold of some OpenGL book or a book about writing 3D games that explains all the basic concepts in more detail than can be done on this list. You may also get more information from a forum/list that is actually dedicated to generic OpenGL rendering. Cheers,  Matthias  
From: Matthias Baas <matthias.baas@gm...>  20100905 13:53:19

Hi Roland, Roland Everaert wrote: > Making the ship rotate is not the problem, actually I am usingthe > following code to define the rotation: > > def __chasingView(self, planex, planey, planez, pitch, heading, roll): > > glRotatef(roll, 0.0, 0.0, 1.0) > glRotatef(heading, 0.0, 1.0, 0.0) > glRotatef(pitch, 1.0, 0.0, 0.0) > glTranslate(planex, planey, planez) If this roll, heading, pitch representation works for your game and all you want to do is finding the "forward" direction in which the ship is supposed to move, then you have to apply the above rotations to the vector (0,0,1) (which is the forward direction as seen in the ship's local coordinate system). You can either use a mat3 or quat for that, you just have to make sure you apply the rotations in the same order as OpenGL does (as an exercise you might try replacing your three calls to glRotate() with one call to glMultMatrix() and construct the rotation matrix yourself). > I think that my biggest problem is my lack in math which prevent me from > understanding the logic involved. If you have any book recommandation, > it is welcomed. I can't recommend a particular book. I suppose you could just pick any book that's about (3D) game development. Maybe you can find some suggestions on http://www.gamedev.net. Cheers,  Matthias  
From: Roland Everaert <r.everaert@gm...>  20100911 20:59:52

At last, I am now able to make the ship move as I want, but I have difficulties to make the "camera" follow the ship. Below is the code I am using to make the ship move (as a reminder, I am using pygame): #Matrix for the player object intMat = mat4.translation(vec3(0.0, 3.0, 10.0)) intMat = intMat.rotate(math.radians(20.0), vec3(1.0, 0.0, 0.0)) thrust = 0.0 #Matrix for the Non Playable object statMat = mat4.translation(vec3(0.0, 3.0, 20.0)) statMat = statMat.rotate(math.radians(20.0), vec3(1.0, 0.0, 0.0)) while True: for event in pygame.event.get(): if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE): exit() pressed = pygame.key.get_pressed() delta_y = 0.0 delta_x = 0.0 glClear (GL_COLOR_BUFFER_BIT); glLoadIdentity (); # /* clear the matrix */ # Position, orient and render player object glLoadMatrixf(intMat.toList()) glColor3f(1.0, 1.0, 1.0) glBegin(GL_TRIANGLES) glVertex3f(1.0, 0.0, 0.0) glVertex3f(0.0, 0.0, 1.0) glVertex3f(1.0, 0.0, 0.0) glEnd() # Position, orient and render Non Playable object glLoadMatrixf(statMat.toList()) glColor3f(1.0, 0.0, 0.0) glBegin(GL_TRIANGLES) glVertex3f(1.0, 0.0, 0.0) glVertex3f(0.0, 0.0, 1.0) glVertex3f(1.0, 0.0, 0.0) glEnd() ... mat_tmp = mat4.translation(vec3(0.0, 0.0, thrust * (clock.tick(50) / 1000.))) mat_tmp = mat_tmp.rotate(math.radians(delta_y), vec3(0.0, 1.0, 0.0)) mat_tmp = mat_tmp.rotate(math.radians(delta_x), vec3(1.0, 0.0, 0.0)) intMat = intMat * mat_tmp # Show the screen pygame.display.flip() I have the feeling that the player ship should be the "center of the universe" and that everything should move around it, but I am not sure it is the way I should think how to move the camera and I don't really know how to do it. Now that I can make an object moves using matrix, what would be the advantage of using quaternions? I have seen one or two typo in the online documentation of cgkit, to whom should I report those errors? When I will get a grasp on how to use the package, I was thinking about writing some tutorials showing how to integrate cgkit with pygame, to whom should I submit them and in which format? Thanks for your help, Roland. Le 09/05/10 15:53, Matthias Baas a écrit : > Hi Roland, > > Roland Everaert wrote: >> Making the ship rotate is not the problem, actually I am usingthe >> following code to define the rotation: >> >> def __chasingView(self, planex, planey, planez, pitch, heading, roll): >> >> glRotatef(roll, 0.0, 0.0, 1.0) >> glRotatef(heading, 0.0, 1.0, 0.0) >> glRotatef(pitch, 1.0, 0.0, 0.0) >> glTranslate(planex, planey, planez) > If this roll, heading, pitch representation works for your game and all > you want to do is finding the "forward" direction in which the ship is > supposed to move, then you have to apply the above rotations to the > vector (0,0,1) (which is the forward direction as seen in the ship's > local coordinate system). > You can either use a mat3 or quat for that, you just have to make sure > you apply the rotations in the same order as OpenGL does (as an exercise > you might try replacing your three calls to glRotate() with one call to > glMultMatrix() and construct the rotation matrix yourself). > >> I think that my biggest problem is my lack in math which prevent me from >> understanding the logic involved. If you have any book recommandation, >> it is welcomed. > I can't recommend a particular book. I suppose you could just pick any > book that's about (3D) game development. Maybe you can find some > suggestions on http://www.gamedev.net. > > Cheers, > >  Matthias  > > >  > This SF.net Dev2Dev email is sponsored by: > > Show off your parallel programming skills. > Enter the Intel(R) Threading Challenge 2010. > http://p.sf.net/sfu/intelthreadsfd > _______________________________________________ > cgkituser mailing list > cgkituser@... > https://lists.sourceforge.net/lists/listinfo/cgkituser 
Sign up for the SourceForge newsletter:
No, thanks