-1

In OpenGL I created a simple cube that I rotate. I am rotating the cube, not the camera!

Then I added a light source. The light also rotates with the cube. How can I avoid this?

Can somebody tell me when to activate which matrix mode and when to push and pop the current matrix. I have tried many, many combinations and sequences, but the damn light always (!) follows the rotation.

I am not expecting a general answer that just says that has something to do with the matrix stack. A concrete short example of a rotating object with a non-rotating light would be great!

Nick Müller
  • 61
  • 1
  • 7
  • Possible duplicate of [How do I fixate a light source in OpenGL while rotating an object?](http://stackoverflow.com/questions/1757958/how-do-i-fixate-a-light-source-in-opengl-while-rotating-an-object) – 463035818_is_not_an_ai Jan 19 '16 at 14:12
  • 2
    *I am not expecting a general answer that just says that has something to do with the matrix stack. A concrete short example of a rotating object with a non-rotating light would be great!* so basically you want a working example instead of explanations ? then just go find it, there's plenty on the internet. On the other hand, if you want help, you can start by posting some code, or tell us what *I am rotating the cube* means in term of code so we could understand what you are actually doing – Guiroux Jan 19 '16 at 14:21
  • @tobi303 The one answer in the thread you mentioned seems to rotate the camera (what I don't want to do!) and the other answer does not seem to work. – Nick Müller Jan 19 '16 at 14:30
  • if you have only a cube, a camera and the light source, then it does not matter whether you rotate the cube or camera (as long as you want to keep the light source fixed). – 463035818_is_not_an_ai Jan 19 '16 at 14:52
  • 1
    @NickMüller: Welcome to Stack Overflow. We are not a code-writing service. We may be able to find the bug(s) in your code, but we can only do that if you provide code. Simply saying, "my code isn't working, could you write it for me?" isn't going to fly here. – Nicol Bolas Jan 19 '16 at 14:55
  • @tobi303 Later there will be more (independent) objects, so the camera rotation is no option! I just wanted to focus the problem and abstract from the additional things. You can think that by yourself... – Nick Müller Jan 19 '16 at 15:00
  • @Nicol Bolas I asked a concrete question and did not bother you with one line of my code. I do not ask you searching a bug in my code. I have a problem case I do not know how to solve after several tries. Do you know the issue with the rotating lights in OpenGL? – Nick Müller Jan 19 '16 at 15:06
  • 1
    @NickMüller: There is no "*issue with the rotating lights in OpenGL*". People have been rotating objects and lights independently with OpenGL for *decades*. If you aren't able to do it, then the issue is clearly *you* writing your code *wrong*. And we can't help you without knowing what your code is, since there are *numerous* ways that your code could be wrong. – Nicol Bolas Jan 19 '16 at 15:08
  • @Nicol Bolas You are right, there must be an error (or actually the lighting is just missing since I do not know how to implement it properly.) – Nick Müller Jan 19 '16 at 15:17
  • even if the answers in the [possible duplicate](http://stackoverflow.com/questions/1757958/how-do-i-fixate-a-light-source-in-opengl-while-rotating-an-object) isnt what you want, the question is the same... – 463035818_is_not_an_ai Jan 19 '16 at 16:29
  • @tobi303 I agree that it is absoletely the same question. But was it well ansewered in the other thread? In my mind not. Moving the camera was also not the solution for the other question. By the way I found unanswered versions of this question in more threads than these two and also in other forums. This is also a reason I don't think that a code snippet is needed because you seem to have understood the problem. Who does know the solution? – Nick Müller Jan 19 '16 at 21:14

1 Answers1

1

A probable reason why the light follows a rotating object is that there was defined no (suitable) normal vector for the object. Although the light and the movements of the objects are programmed correctly the wrong or no normal vectors can make the whole scene look like the light follows a rotating object.

Defining normal vectors for the objects, that determine how the light is reflected, can solve the problem.

Nick Müller
  • 61
  • 1
  • 7