Basically I’m writing a C++ program to draw objects in a world and I’m having some difficulty with lighting when I’m rotating/translating an object that consists of multiple objects (For example a tree object consists of a cylinder object for the trunk and pyramid objects for the leaves).
I have a working light source right now but I run into some issues when rotating a subcomponent of an object (like the pyramid object inside its parent, the tree).
All lighting/shading works when I apply a rotation to the tree object, but lighting gets wonky and random if I attempt to rotate the pyramid object inside the tree. I’m really hoping someone may have some tips or hints as to what I could be running into?
Edit: There are a lot of files with this project and it would be difficult to throw enough up here to give the entire picture. Essentially my steps are:
- Set up a world with a functioning opengl light source.
- Create a shape object which has a transformation matrix associated with it.
- Using the shape and its matrix and calculate its normals to use for shading.
- Now create a new shape object which consists of the other shape objects, and throw it in the world for the lighting to take effect.
- Now the problem happens here. If I rotate the parent object, lighting is fine, but if I rotate the child object, lighting becomes random.
I found the problem in my code. I was updating the normals too frequently so opengl lighting had bad normals to work with.
Thanks for the help everyone!