[SOLVED] Widget: update sun position


photo

Recommended Posts

Hi,

using the tutorials from the docs I have added a slider to the GuiSample in the VR Template.
The tutorial goes on to adding a sun controlling method, but I cannot get it to work. 

I have added following code to the private section of GuiSample.h:

WidgetSliderPtr slider;
void slider_changed();

This to GuiSample::init in the GuiSample.cpp:

	slider = WidgetSlider::create(gui, 0, 360, 90);
	slider->setButtonHeight(200);
	slider->setPosition(250, 250);
	slider->setButtonWidth(200);
	gui->addChild(slider->getWidget(), Gui::ALIGN_OVERLAP);
	slider->setCallback0(Gui::CHANGED, MakeCallback(this, &GuiSample::slider_changed));

But have problems with the method changing the sun.

 

    void GuiSample::slider_changed()
    {
        ;
    }

 


I tried following the tutorial, but the code crashes on the sun initialization everytime (last line), I get an exception

	// creating a world light and setting up its parameters
	thesun = LightWorld::create(Math::vec4(1.0f, 1.0f, 1.0f, 1.0f));
	thesun->setName("Sun");
	thesun->setDisableAngle(90.0f);
	thesun->setIntensity(1.0f);
	thesun->setScattering(LightWorld::SCATTERING_SUN);
	thesun->setWorldRotation(Math::quat(0.0f, 1.0f, 0.0f, 170.0f));

	// passing node ownership to the editor
	thesun->release();
	editor->addNode(thesun->getNode());

and I think that maybe this code just does not work with the component system.

Could you please help me with the method changing sun position?
And my second question: the slider appears and I can use it, but it is not active along its whole length - meaning, I can drag it only when I point to its right side. But when I drag it and let go, and want to manipulate it once again, lets say drag it back to its minimal position, it is active only on its left side ( so the slider moves, but the space where it can be grabbed seems to be constant; on the screenshots I have marked it with the mouse cursor).
Last but not least: how can I change the size of the gui plane? 

Thanks!
 

sun_control.jpg

sun_control2.jpg

Link to post

Hi Piotr,

As for changing sun's position, you can try something like this (sun node exists in the VR Template's world, so you don't have to create another one):

// GuiSample.cpp
// ...
#include <UnigineLights.h>// <-- header for light sources
#include <UnigineEditor.h>// <-- header for the Editor
                                
// ...
void GuiSample::slider_changed()
{
	// trying to get a node named "sun"
	NodePtr node = Editor::get()->getNodeByName("sun");
	// if such node is found changing its position using the new angle determined by the slider value
	if (node)
		LightWorld::cast(node)->setWorldRotation(Math::quat(Math::vec3(0.0f, 1.0f, 0.0f), 180.0f - slider->getValue()));

}

Try replacing you slider creation code in GuiSample::init() with this (use setWidth() to set the width of your slider):

	slider = WidgetSlider::create(gui, 0, 360, 90);
	slider->setWidth(360);
	slider->setPosition(250, 250);
	gui->addChild(slider->getWidget(), Gui::ALIGN_OVERLAP);
	slider->setCallback0(Gui::CHANGED, MakeCallback(this, &GuiSample::slider_changed));

Hope this helps!

Thank you!

Link to post
  • morbid changed the title to [SOLVED] Widget: update sun position