Archived

This topic is now archived and is closed to further replies.

OB1st

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

Recommended Posts

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

Share this post


Link to post
Share on other sites
>>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


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
>>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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites