Jump to content

rotate Canvas


photo

Recommended Posts

Hello all,
I have a question about the WidgetCanvas Class I have drawn a triangle, which should rotate in a circle. However, when rotating it, it is only visible in a certain area. Maybe someone could tell me how to make it visible everywhere.
With kind regards
Leon

 

init()
{
	obj_Gui = checked_ptr_cast<ObjectGui>(World::getNodeById(568410087));
	obj_Gui->setBackground(1);
	auto gui1 = obj_Gui->getGui();
	
	canvas = WidgetCanvas::create(gui1);
	
  	int SouthTriangle = canvas->addPolygon(8);
	for (int i = 0; i <= 3; i++)
	{
		float s = sin(360 / 3 * UNIGINE_DEG2RAD * i) * 20 + 0;
		float c = cos(360 / 3 * UNIGINE_DEG2RAD * i) * 20 +100;
		canvas->addPolygonPoint(SouthTriangle, vec3(s, c, 0.0f));
	}
	canvas->setPolygonColor(SouthTriangle, vec4(0.0f, 0.0f, 1.0f, 1.0f));
  	gui1->addChild(canvas, Gui::ALIGN_OVERLAP | Gui::ALIGN_CENTER);
}

update()
{
	i = i + 0.5;
	canvas->setPolygonTransform(SouthTriangle, (mat4(rotateZ(i))));
}

 

2021-12-06 14-52-29.mkv

 

Link to comment

Hello,

The position of the widget is determined by the upper left corner, i.e. for the canvas, it is located in the center of the GUI. With the current transformation change, the polygon extends outside the canvas. For correct display, the polygon must be rotated and moved to the center of the widget. You can try to change the code like in the example below:

int canvas_width = 400;
int canvas_height = 400;

init()
{
	//...
	// create canvas
	//...

	canvas->setWidth(canvas_width);
	canvas->setHeight(canvas_height);
	canvas->setPosition((obj_Gui->getScreenWidth() - canvas_width) / 2, (obj_Gui->getScreenHeight() - canvas_height) / 2);
  	gui1->addChild(canvas, Gui::ALIGN_OVERLAP);
}

update()
{
	i = i + 0.5;
	canvas->setPolygonTransform(SouthTriangle, translate(vec3(canvas_width / 2, canvas_height / 2, 0.0f)) * rotateZ(i));
}

 

canvas_0.PNG

canvas_1.PNG

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