FreeGLUT Planet Orbit Speed Help

I’m currently trying to create a Solar System Simulation for a project. I’m using a pretty simple scene graph to make the planets children of the sun and the moons children of the planets so I’m able to make them orbit around their parent. I’m then applying the transformation matrix for each planet and popping it, this is my render code for each planet (as well as the sun and moons):


void SceneObject::Render()
{
	glBindTexture(GL_TEXTURE_2D, texture->GetID());
	

	if (mesh->hasTexCoords && !mesh->hasNormals)
	{
		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);

		glVertexPointer(3, GL_FLOAT, 0, mesh->vertices.data());
		glTexCoordPointer(2, GL_FLOAT, 0, mesh->texCoords.data());
	}

	if (mesh->hasTexCoords && mesh->hasNormals)
	{
		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glEnableClientState(GL_NORMAL_ARRAY);

		glVertexPointer(3, GL_FLOAT, sizeof(Vector3), mesh->vertices.data());
		glTexCoordPointer(2, GL_FLOAT, sizeof(TexCoord), mesh->texCoords.data());
		glNormalPointer(GL_FLOAT, 0, mesh->normals.data());
	}

	//glRotatef(orbitAngle, orbitRotation.X, orbitRotation.Y, orbitRotation.Z);

	//glPushMatrix();

	glTranslatef(position.X, position.Y, position.Z);
	glRotatef(rotationAngle, rotation.X, rotation.Y, rotation.Z);
	glScalef(scale.X, scale.Y, scale.Z);

	glDrawElements(GL_TRIANGLES, mesh->indiceCount, GL_UNSIGNED_SHORT, mesh->indices);

	glPopMatrix();

	if (mesh->hasTexCoords && !mesh->hasNormals)
	{
		glDisableClientState(GL_VERTEX_ARRAY);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	}

	if (mesh->hasTexCoords && mesh->hasNormals)
	{
		glDisableClientState(GL_VERTEX_ARRAY);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisableClientState(GL_NORMAL_ARRAY);
	}
}

This works fine for making the orbits though the speed they orbit at is dependent on the transformation matrix, unlike what I would want which is a orbit speed I can set. You’ll notice in that render code for each “planet” that I do have a line like this:

glRotatef(orbitAngle, orbitRotation.X, orbitRotation.Y, orbitRotation.Z);

This was an attempt basically at trying to be able to change the orbit speed based on a value instead of the transformation matrix itself, though I haven’t got it to work yet. I would simply increase the orbit angle by a orbit speed value set for each “planet”.

I was wondering if someone would possibly be able to help and explain to me how I would be able to make it so I have a set orbit speed that each “planet” uses, so each planet has it’s own orbit speed and I can adjust it accordingly.
Also emphasis on explain as truthfully I’m not at all experienced with using Matrices like this (as you may be able to tell). I have a slight hint of what’s going on but likely not at all enough to make this work by myself :stuck_out_tongue: :confused:

So any help would be appreciated :slight_smile: