Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Light object rotating using slider

Light object rotating using slider

samunawa
Enthusiast Enthusiast
518 Views
1 Reply
Message 1 of 2

Light object rotating using slider

samunawa
Enthusiast
Enthusiast

Hi guys. I have a bit an issue with a project I'm currently working on. Basically I'm trying to create a very very basic slider which is hooked up to my light object and this will essentially replicate hours of the time. But my issue is, is that I cant get it to work or even I cant find the right type of slider. Heres what I have now:

798592d770e54f328bde8dfa46597e5d

 

 

 

 

 

 

And heres my code for it:

    frameLayout -collapsable true -label "Time Options";
        gridLayout -cellWidthHeight 300 50 -numberOfColumns 2;
            attrFieldSliderGrp -label "Time 24H" 
            -min 0 -max 24 
            -sliderMinValue 0 -sliderMaxValue 24
            -at sun_light.rotateX;

What I need this to do is to show in my window an integer of 1-24 (the 24 hour system we use) but on the actual attribute (light object(lets just call it sun_light for now)) it needs to be rotating at a certain angle. I thought maybe using the expression editor would be a good way to get around this but I don't know how I would calculate the rotation values and how I would hook them up with each other. 

 

So for example if the slider is at a value of 5 which in 24 hour time would be 05:00, the sun_light object would be rotated at a certain angle to replicate that.

 

I made a thread a while back regarding a similar issue to this but I wanted to try using something less similar and using as little code as possible in order to achieve a simple script (if there is even such a thing as a simple script haha), thanks.

 

 

0 Likes
519 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Hi,

 

first I think a float will be better than an integer, because you maybe want a really smooth transition.You could simply generate a float slider and add a changed callback. Other sliders also have change callbacks so just check which is must appropriate for you.

 

// New global procedure to receive the changed callback
global proc TimeChanged()
{
   //Currently just print the value of the slider
   print `floatSliderGrp -q -value gTimeSlider`;

   // Add the computation for the angle of the light
}



// Inside your window creation method or ...
floatSliderGrp -label "Time" -minValue 0 -maxValue 24 -changeCommand "TimeChanged()" gTimeSlider;

Now you have to compute the angle of the light inside the TimeChanged method. For this you have to make some research, for example 

http://www.geoastro.de/elevaz/basics/index.htm

http://answers.google.com/answers/threadview/id/782886.html

Of course this getting more complex, because you need more than just the time, the position on the earth is also important, but you could simply hardcorde a position on the earth to workaround that. Maybe you can even find some c++ code and you could transfer it to mel script.