Jump to content

HOW TO ADD A GIZMO


photo

Recommended Posts

Hello 

I have tried to impliment the gizmo following the tutorial on your programming website. And it never works. The code makes the gizmo show but it does not actually move or manipulate the selected objects in the screen.. Please post a working code so i can have a working gizmo that functions similar to the way the editor gizmo works.

I would also like the selected object to be highlighted the way it is on the editor. Please post codes for this and where to out the codes and the appropriate include files to add and where. 

Thank you. 

 

Screenshot_20210908-224424.thumb.png.01c2d656fecc7dca9074ca65d3b21a99.png

Link to comment

Hi @3danimation,

Looks like a small logical mistake took place in this example due to change of callbacks execution order: in the Update function, the current manipulator constantly resets its transformation to the object's one even before any callback is called. If we slightly change the logic, everything works fine:

Spoiler
	/* ... */
	// find object with a right-click
	if (Input::isMouseButtonDown(Input::MOUSE_BUTTON::MOUSE_BUTTON_RIGHT))
	{
		obj = GetNodeUnderCursor();

      	// let's keep the transformation reset here instead of the next section
		if (obj && CurrentObjectManipulator)
			CurrentObjectManipulator->setTransform(obj->getWorldTransform());
		
	}
	// switch widgets on command with Z,X,C keys
	if (obj)
	{
		if (Input::isKeyDown(Input::KEY::KEY_Z))
			SwitchManipulator(ManObjTranslator);
		if (Input::isKeyDown(Input::KEY::KEY_X))
			SwitchManipulator(ManObjRotator);
		if (Input::isKeyDown(Input::KEY::KEY_C))
			SwitchManipulator(ManObjScaler);
	}
	/* ... */

 

To highlight the selected object you can use the Visualizer class:

#include <UnigineVisualizer.h>
  
/* ... */

// enable the visualizer in the init
Visualizer::setEnabled(true);

/* ... */

// draw the object when needed
Visualizer::renderObject(obj, Math::vec4_green);

I've attached the source files with implemented fancy selection animation inspired by UnigineEditor, if you need them. Captured and confirmed to be working on UNIGINE 2.14.1.

Hope this helps. We definitely will fix this example, thank you for pointing the problem out and sorry for the inconvenience caused.

AppSystemLogic.cpp AppSystemLogic.h

  • Like 1
Link to comment

I switched the selection to be done with the left mouse click instead of the right mouse button

How do i now make the right mouse button look around in the scene. 

I followed the tutorial on ur website for how to change the mouse behavior from GRAB, SOFT AND USER. But i dont want the left mouse button to do this.. Only the right mouse button should be used to look around. Please show me how to use the right mouse button like in the unigine editor

Link to comment
On 9/10/2021 at 11:12 PM, 3danimation said:

Please show me how to use the right mouse button like in the unigine editor

You can do it by manually enabling mouse input when the right mouse button clicked. Since now we enable mouse lookaround ourselves, it's better to use the USER mouse handling mode (this can be done both via API and UnigineEditor).

The following code will enable lookaround via the right mouse button provided the world contains a Player that supports mouse input (PlayerSpectator, PlayerPersecutor or PlayerActor). For example, the default world usually includes a prepared PlayerPersecutor.

#include <UnigineInput.h>
/* .. */

	Input::setMouseHandle(Input::MOUSE_HANDLE_USER);

/* .. */

int AppSystemLogic::update()
{
	/* .. */
	if (Input::isMouseButtonDown(Input::MOUSE_BUTTON_RIGHT))
	{
		ControlsApp::setMouseEnabled(true);
	}
	if (Input::isMouseButtonUp(Input::MOUSE_BUTTON_RIGHT))
	{
		ControlsApp::setMouseEnabled(false);
	}
}

However, these default players with predefined behaviour are going to be considered redundant and will be deleted soon from the sdk, so we recommend creating your own player controllers for serious projects.

Thanks!

  • Like 1
Link to comment
×
×
  • Create New...