DWORD tex = ((DWORD)(m_fTime*32))%32;

Started by
6 comments, last by OB1st 21 years, 9 months ago
As basic as this may is, could some one kindly translate it ino English. This code is executed per frame(From the SDK Dolphin ex.) DWORD tex = ((DWORD)(m_fTime*32))%32; m_pCurrentCausticTexture = m_pCausticTextures[tex]; What puzzels me how does the array pointer move to the next data for every frame. My best regards If love is illusion and hate is real, I would rather be crazy
I would love going home to M7, but I can't detect black holes.
Advertisement
>>DWORD tex = ((DWORD)(m_fTime*32))%32;
m_pCurrentCausticTexture = m_pCausticTextures[tex];
What puzzels me how does the array pointer move to the next data for every frame.<<

See the member variable m_fTime above? There''s your culprit =)

-John


- John
Sorry Teknofreek for this question

The % operator defination is (Returns the remainder (modulus) obtained by dividing one numeric expression into another)

What this has to do with advancing tex to next value?
for example x = y*z/z = y. I know I am missing something but I do not know what it is. It is may be the casting after the multiplication by 32 into DWORD.


Could I declare tex as static and insert it in a for loop to assign a texture for every frame, as amatter of fact I may have to do that.

It is only the limited knowledge in some of the C++ operators that limited me from undersatnding this thing.

I will settle for any hint.

Best regards

If love is illusion and hate is real, I would rather be crazy
I would love going home to M7, but I can't detect black holes.
>>What this has to do with advancing tex to next value? for example x = y*z/z = y. I know I am missing something but I do not know what it is. It is may be the casting after the multiplication by 32 into DWORD.<<

Yeah, it certainly looks like the casting is the point of that statement. A DWORD, if I remember correctly, is a long unsigned int.

>>Could I declare tex as static and insert it in a for loop to assign a texture for every frame, as amatter of fact I may have to do that.<<

Umm, probably. As long as it''s using m_fTime, which I assume is getting updated each frame somewhere else, then you should be able to put it wherever you want....as long as it''s after that update.

Good luck!

-John
- John
DWORD tex = ((DWORD)(m_fTime*32))%32;

What''s happening with tex is that it''s actually increasing 32 times every second, not every frame. m_fTime (I''m guessing) is the "current time in seconds", so it''s increasing by 1 every second. If you multiply it by 32, then it''ll increase by 1, 32 times a second. Next, you cast it to DWORD, which just rounds it to the nearest integer. So, you''re taking an integer which inreases by one 32 times every second and you taking it''s value modulo 32, which would be a number that loops from 0 - 32 every second.

codeka.com - Just click it.
Dean

I have a little difficulty with your explanation because why would you would you want to do that. It is like saying x= 1, and in the next line saying x = 2, and so forth. the program will take the last value because m_pCurrentCausticTexture is used once for each render(). And as you know Render() is a per frame thing.

Thanks anyway.

If love is illusion and hate is real, I would rather be crazy
I would love going home to M7, but I can't detect black holes.
Its so you can animate textures at the correct speed when running at different fps. If you just increment the texture to use every draw frame your texture anim will animate twice as fast at 60fps, compared to 30fps.
That''s right. It''s always a good idea to have animations run on a time-basis rather than a frame-basis (if you get my meaning) because then the animation will always run at the same speed, no matter what the frame rate.

codeka.com - Just click it.

This topic is closed to new replies.

Advertisement