convert 24 hour time into rotational value

70 views Asked by At

ok, so a bit of an odd question, I have implemented a real-time system using Date() and Date.getTime(), And I have a plugin installed on my project (mz3d), I know how to use it, however I have run into a problem with the sun,

I need to convert 24 hour time from getTime() into a rotational value for mz3d's sun. however, the sun's topmost position in the sky is at 0 degrees and beneath the floor is 180 degrees.

my code is:

//variables
var d = new Date();
var hr= d.getHours();
var mn= d.getMinutes();
//conversion
var sun;
//mz3d command
mz3d.command('sun pitch',sun,0);

how would I calculate it so 12 to is 0 degrees and 24 or 0 is 180 degrees?

1

There are 1 answers

0
Titanor Soulstone On

Thanks to RobG i found the following code works

var d = new Date();
minSinceMidnight = d.getTime()- d.setHours(
    0, 0, 0, 0
);
minSinceMidnight = Math.round(
    minSinceMidnight / 60000
);
var math1 = minSinceMidnight/1440;
var math2 = math1*360
//console.log(d);
//console.log(minSinceMidnight);
//console.log(math2);
var sun = math2+180
//console.log(
//    "sun pos = ", sun
//);
mz3d.command('sun pitch',sun,0);