Results 1 to 3 of 3

Thread: Object not rendering after rotation

  1. #1
    Newbie Newbie
    Join Date
    Apr 2015

    Object not rendering after rotation

    Hello, I have recently started working on a project where I trying to simulate a rocket taking off, the problem I am currently experiencing is regarding the rendering of the object, I translate it on it's "local axis" and it moves fine however when I rotate it, it only displays the 1 degree rotation based on
    Code :
    glRotatef(deg, 1, 0, 0);
    where if the degree value would be 1 it would rotate on the said axis by 1 and only render the first rotation as in if I were to press the left arrow it rotates it by 1 degree, it shows the rotation and any other rotations done afterwards are not rendered however are still applied.
    If I were to press the left key lets say 45 times it and the degree would still be 1 it will render the first rotation of 1 degree then rotate the coord system by another 44 degrees without actually showing the rotation of the object.
    Moving coordinate system and allowing translation on said system.
    Here is the code I am using for the rotation and translation and how I am calling it in the main function.

    Code :
    #include "Rocket.h"
    Rocket::Rocket(float x, float y, float z) 
    	Transform[0] = 1.0f;
    	Transform[5] = 1.0f;
    	Transform[10] = -1.0f;
    	Transform[15] = 1.0f;
    	Transform[12] = x; Transform[13] = y; Transform[14] = z;
    void Rocket::locMove(float x, float y, float z, float distance) 
    	float dx=x*Transform[0] + y*Transform[4] + z*Transform[8];
    	float dy=x*Transform[1] + y*Transform[5] + z*Transform[9];
    	float dz=x*Transform[2] + y*Transform[6] + z*Transform[10];
    	Transform[12] += dx * distance;
    	Transform[13] += dy * distance;
    	Transform[14] += dz * distance;
    void Rocket::locRot(float deg, float x, float y, float z) 
    	glRotatef(deg, x,y,z);
    	glGetFloatv(GL_MODELVIEW_MATRIX, Transform);
    	degG = deg;
    	xG = x;
    	yG = y;
    	zG = z;
    void Rocket::drawRocket()
    		glTranslatef(Transform[12], Transform[13], Transform[14]);
    		glRotatef(degG, xG,yG,zG);			

    Code :
    Rocket rock(rockX, rockY, rockZ);

    The main class is quite large and the only bits of code related is the instancing of a new rocket and calling the draw rocket function, alongside various rock.locRotate and rock.locMove calls within the keypress function.
    My best guess as to how this could be fixed would be an update function for the rocket however I do not know what would be inside said function.
    Any help would be appreciated as this has been an issue of mine for a few weeks now, getting into this stage just a few days ago.
    Thanks again.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    I suggest that you don't use any OpenGL matrix functions other than glLoadMatrix() or possibly glMultMatrix(). If you need to access (or even just store) the matrices in the application, it's easier (and more efficient) to just generate them yourself.

    You can find the actual matrices generated by functions such as glRotate() in the online reference pages. Or you can use GLM instead.

    As for your specific problem, the Transform matrix contains the cumulative result of many translation and rotation operations, but degG,xG,yG,zG contain only the most recent rotation. I'm not sure why you're using glTranslate() and glRotate() in drawRocket() when (so far as I can tell) you could just use glMultMatrix(Transform) instead.

    Unless xG,yG,zG are constant (i.e. you're always rotating about the same axis), the only feasible approach for calculating the cumulative rotation in axis-and-angle form is to calculate it in either matrix or quaternion form then convert that to axis-and-angle (which is pointless if you're just going to use glRotate() to convert it straight back to matrix form).

  3. #3
    Newbie Newbie
    Join Date
    Apr 2015
    That did actually work and yes I was told about storing matrices and calling them if needed with the glm library, had a look at it and it does seem really useful especially if I will deal with quaternions in the future, but for now this simple implementation is all I needed, and plus I am currently using version 1.2 since that is what I was taught so far, have been also learning directx and it seems like the logical step to use the latest version of opengl since it's quite similar and seems like it may not have that big of a learning curve.
    Thank you so much for the help.

Similar Threads

  1. Rotation of object
    By mamata patil in forum OpenGL: Linux
    Replies: 2
    Last Post: 05-27-2018, 04:40 AM
  2. Rotation of an object by rotation matrix
    By MrFoil in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-02-2015, 04:41 PM
  3. Object Position after Rotation
    By danBuonocore in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-27-2014, 04:01 PM
  4. Object Rotation
    By Vincent22 in forum OpenGL: GLSL
    Replies: 4
    Last Post: 11-11-2011, 08:04 AM
  5. object selection and then rotation....
    By kevin in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-22-2000, 07:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean