# Editor and gizmo

## Recommended Posts

Hi, I need some advices of how to go about implementing an editor-like progie in that someone could pick an object with the mouse, translate, rotate and scale along the axis. Every object has an axis aligned bounding box and the 3 axis are displayed also.
Picking an object with the mouse works fine, but I'm not really sure how to implement translation, rotation and scaling the selected object. I have 2 implemetations that work more or less fine, but maybe there is an easy,straight-forward and standart way for gizmo-like functionality.

For the translation, I currently use something like this :
I construct a ray from the current mouse position, construct a plane from the
selected object center and a main axis normal (1,0,0), (0,1,0) or (0,0,1) depending of the view and intersect the ray and the plane.
From the intersection point, if I want to translate by the Z-axis, I get the z component of the intersection point and set it as the z component of the selected object traslation.
That works for single selection , but not for multiple selections.
Rotations and scaling are more simple, as I just use the mouse Y or X position on the screen to calculate the amount of scaling roation.

The results aren't very nice and I feel maybe I'm missing something that is used in most of the editor that have gizmos implemented.
I would appreciate any guidings on the subject.
Thank you.

##### Share on other sites
Oops, instead of "edit", I hit "quote". Sorry...

##### Share on other sites
Well when it comes to multiple selections, you have to be picking 1 of them to act as the "main" selection I guess. Personally, I actually work out my translations slightly different. I take the direction of the translation I'll be doing (eg, along Z), and project that into view space (using only view rotation, no translation). I can then dot it with the dela mouse position and work out how far to move along the axis. Maybe if you did it that way around it would work with multiple selections a bit easier? It's slightly more difficult to make it move the perfect distance in world space for how far you move the mouse though.

##### Share on other sites

The problem with my approach as I see it is mainly that instead of adding/subtraction from the current position x/y/z components(depends of the chosen axis of translation) I actually set it. For multiple selections that make all of the selected object to line up along the ray (they all occlude each other that way :) ) of the mouse in world space during translation and that's wrong.
I will try to use a single object for translation and move others relative to it or something. I have a feeling that there are several of ways to implement gizmos for multiple selections.
If I come up with something simple and straight-forward I'll post it here.

##### Share on other sites
Oh I see what you mean now. But as you said, it should be easy to get a delta translation and apply that to the other objects. Most editors with multi selections just move everything by the same amount so I think this should be fine.

##### Share on other sites
Decouple selection and transformation. You know what objects are selected, then transform them all. The calculated parameters of the transformation are independent from the actual objects.

You operate with the gizmo: the position of the gizmo determines the transformation. This position is rather arbitrary: it may be average of the centres of the selected objects, it may be one of the centres of the objects, it can be the centre of the object, that's closest to the mouse ray, etc. It's simple with translation. Calculate the axis and the offset value, then ADD this to the current positions of the objects. Well, I would store all centre's coordinates and the mouse coordinates at the beginning of the dragging ("origin"). Something like
obj_pos = obj_origin + CaclulateOffsetFromMouse(mouse_origin,mouse_current);
This way, you can undo the transformation: just set obj_pos = obj_origin.

With scale and rotation, it's a matter of the desired behaviour. All objects are transformed independently "around" their own centre, or around a shared centre? The position of this shared centre is arbitrary too.

All of these questions are behavioural questions, we can't really help with that. What behaviour do YOU want?
We can help with the mathematics, logic, software structure etc, if we know what YOU want.

Anyway, work with the gizmo for determining the parameters of the transformation, that's the basic idea.

I hope that's clear.

##### Share on other sites
Yeah, it's perfectly clear now. I was uncertain which way to use and why. I was using the approach with ray/plane intersection for translation and it worked very well and positioning was accurate, except for multi-selections. Now I see how I should go about it. That's why I posted the question.
Thank you people.