Where Did The Time Go? and why are frame rates so frustrating?
Now back to the project - Where You Linger is an interactive diorama where the user can accelerate time in the model by rotating a rotary encoder. In the diorama is a top down view of someone's desktop, and a Pepper's Ghost effect is overlayed onto the physical environment for more dynamic interaction. The content that is reflected include an animated humanoid that, as you may have guessed, work at the desk on which the objects react depending on the person's activity. One of these objects is a digital clock face, which changes time at different rates which is responsive to what the user does with the rotary encoder. Since this interactive video is built in Unity, the clock face is scripted in C#. Building a clock... just the start
The "currentTime" string variable is constructed with "HH (hour integer variable) + ":" + MM (minute integer variable". However, this created an issue where 1 through 9 were not showing up as 2 digits with leading zeros (01, 02, 03...). I did go through some mental gymnastics of "What if the MM integer variable is converted to a string before it is fed into the 'currentTime' variable, that way if the MM integer is less than 10, I can construct the number with leading zero. But then every time the number needs to change, it has to be converted back to an integer in order to be updated... Then there is the HH variable that needs to be updated when MM reaches 59." And at this point I decided I would turn to the google to see how other people are ensuring that integers are displayed in a fixed number of digits and came across the syntax: $"{HH:D2}:{MM:D2}"
There as a whole process to figure out how to how to reference data from a different script since serial readings can only be called once, and the humanoid animation already called dibs on that. Then realizing that the variable that was brought in had to be converted from a float value into an integer, but thats might be for a different non ICM blog post... but to simplify: Actually updating and accelerating time!From here its just to figure out how to update MM in relation to the "iValue", which is the stepper motor's position presented in the form of an integer. Then update HH with MM. Does your head hurt yet? Cause I think I had a melt down at this point. But good news, we figured it out! To keep it simple, lets assume that every step the motor takes is a minute on the digital clock face. For the MM values, I used the stepper motor position only display the remainder when it is divided by 60 (since there are 60 minutes in an hour "MM = iValue % 60;" I really struggled with the HH value. Not how to get it mathematically, but rather how to update it without being affected by frame rate. What I mean by that is, my initial attempt was to update HH every time MM reached 00, and if it was 12, than to reset to 01 at the next update. So then I tried a method that checked if MM updated from from the last time Update() before making any changes to HH. This will ensure that even if MM == 00 for a few frames, HH will not update until the next 00. But for some reason, "previousMM" would never reach 59, therefore never updating the HH value. Comments are closed.
|
Blog posts and other documentation from NYU ITP classes
Categories
All
|