c++ - Rotating around a point different from origin -
I'm trying to code a camera with glTranslate / glRotate to implement look-up / look-down functions To rotate on a point (that is, where is the "camera"), I need all the objects in my rendering space, which is usually different from the original, however, things rotate around the original Is there a way to specify a different point?
Edit: Added code
Thank you for your prompt reply. It seems that I can not work it properly, it does not make any difference, so I have decided to add my code; I highly appreciate if someone can see it and can tell me what changes are needed to translate / rotate / translate back.
#include & lt; Iostream & gt; # Include & lt; Semith & gt; # Include & lt; GLUT / GLUT.h & gt; Const double roaming_step = .13; Double z_offset = .0; Double y_offset = .0; Double x_offset = .0; Const double angle_step = 1.5; Double angle = xz = .0; Double angle = yz = .0; Bull Key Location [256] = {false}; Zero Drawflur () {glColor3f (1.0, 1.0, 1.0); GlBegin (GL_QUADS); GlVertex3f (-3.0, -1.0, 3.0); GlVertex3f (-3.0, -1.0, -3.0); GlVertex3f (3.0, -1.0, -3.0); GlVertex3f (3.0, -1.0, 3.0); GlEnd (); } Zero drawn () {glTranslatef (-3.0, -5, -3.0); GlColor3f (.8, .1, .1); {GlPushMatrix () for (int i = 0; i & lt; 3; i ++); GlTranslatef (.0, -5, i * 3); For (int j = 0; j and lt; 3; j ++) {glPushMatrix (); GlTranslatef (j * 3, .0, .0); Glute Solidfire (.5, 20, 20); GlPopMatrix (); } GlPopMatrix (); }} Pressed zero key (unsigned char key, int x, int y) {keyStates [key] = true; } Zero Key Related (Unsigned four keys, int x, int y) {keyStates [key] = false; } Zero keyboard operation () {if (keyStates ['w']) z_offset + = roaming_step; If (main location ['s']) z_offset - = roaming_step; If (main location ['A']) x_offset + = roaming_step; If (main location ['d']) x_offset - = roaming_step; If (main location ['I']) {angle_xz - = angle_step; If (angle_xz & lt; .0) angle_xz + = 360.0; } If (main location ['o']) {angle_xz + = angle_step; If (angle_xz> = 360.0) angle_xz - = 360.0; } If (main location ['u']) {angle_yz - = angle_step; If (angle_yz & lt; .0) angle_yz + = 360.0; } If (main location ['j']) {angle_yz + = angle_step; If (angle_yz> = 360.0) angle_yz - = 360.0; } If (main location ['q']) exit (0); } // I think it should be done in this function // How to get zero camera () {glLoadIdentity (); // forward / previous glTranslated (.0, .0, z_offset); // left / right glTranslated (x_offset, .0, .0); // axis rotation glrotated (angle_xz, .0, 1.0, .0); // YZ rotation glRotated (angle_yz, 1.0, .0, .0); } Zero performance (zero) {keyboardOperations (); Gluclease (GL_Collo_B_BFFER_BIT | GL_DEPTH_BUFFER_BIT); Camera (); DrawFloor (); DrawBalls (); GlutSwapBuffers (); } Zero resuscitation (int width, intensity height) {glMatrixMode (GL_PROJECTION); GlLoadIdentity (); GlViewport (0, 0, width, height); GLDB aspect = (GLD) width / (GLDB) height; Glu Perspective (60, Aspect, 1, 100); GlMatrixMode (GL_MODELVIEW); } Int main (int argc, char ** argv) {glutInit (and argc, argv); GlutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); GlutInitWindowSize (500, 500); GlutInitWindowPosition (0, 0); GlutCreateWindow ("openGLtest3"); GlClearColor (.0, .0, .0, .0); GlEnable (GL_DEPTH_TEST); GlShadeModel (GL_FLAT); GlutDisplayFunc (display); GlutReshapeFunc (change shape); GlutIdleFunc (display); GlutIgnoreKeyRepeat (true); GlutKeyboardFunc (keypressed); GlutKeyboardUpFunc (keyReleased); GlutMainLoop (); Return 0; }
in Open GL, glRotation
forms of fuction origin Takes references in To rotate around a point (in this case your camera coordination) you should translate the status of your camera into Genesis (accordingly translate all of your items) and then apply the rotation function. And then you back your camera to all your objects)
say that your camera is position (a, b, c), so your code should be something like this:
Foreach object {glPushMatrix (); GlTranslate (a, b, c); GlRotate (...); GlTranslate (-a, b, -c); // render glPopMatrix (); }
Comments
Post a Comment