Re: [cgkit-user] specifiying the new location of an opengl "object" using quaternion
Brought to you by:
mbaas
From: Roland E. <r.e...@gm...> - 2010-09-11 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 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/intel-thread-sfd > _______________________________________________ > cgkit-user mailing list > cgk...@li... > https://lists.sourceforge.net/lists/listinfo/cgkit-user |