Forum

Interactively placing objects in arbitrary location in 3D space

02 May 2018 21:02
In the Furnishing a Room tutorial the author explains how to place objects in 3D space constrained to the floor plane. In this forum thread (3D Object move according to mouse movement x and y coordinate..) the possibility of extending the placement of objects without constraining to the floor plane is examined. Nonetheless, following the forum thread resulted in erratic behavior when trying to place objects in 3D space.

The code includes the following line:
var FLOOR_PLANE_NORMAL = [0, 0, 1];

0, 0, 1 is the floor (Z plane).
0, 1, 0 is the wall (Y plane).
1, 0, 0 is the wall (X plane)

Setting all three values to 1 approximates the behavior I'm looking for. Nonetheless, it still behaves erratically because when selecting the object to move/drag, the location of the object is "reset" to a predefined position (if I remember correctly, I think the center of the scene) making the placement of the object very cumbersome.

So, would it be possible for somebody to explain how to extend the "Furnishing a Room" code to be able to consistently and accurately place objects anywhere in 3D space (specifically, without the floor plane constraint)? An example of the new behavior would be the ability to place, for example, another object on top of the table previously placed in the scene (see the red arrow in the attached "scene-editor.png" image).

Any help with regards to this issue will be greatly appreciated

Brett
11 May 2018 21:20
I am using a work-around to solve this issue. Instead of trying to translate the position of the mouse cursor to all 3 axis, I am using the keyboard to change the location of the selected object:
Z and z keys: adding a positive and negative offset to the current Z-value, respectively
X and x keys: adding a positive and negative offset to the current X-value, respectively
Y and y keys: adding a positive and negative offset to the current Y-value, respectively

It's not the greatest solution but it does do exactly what I need. If anyone has a better suggestion I would love to hear it :)

Brett
11 May 2018 21:57
I would suggest using the SHIFT key to denote movement in the Z axis. That is, when SHIFT is not held down, mouse movements translate to "normal" movement, i.e. moving the object freely around in the room (X/Y axes) as in the furnishing example. But when SHIFT is held down, the object becomes locked in X/Y axes and mouse movement now translates to vertical up/down (Z axis) movement.

I think it's more natural than your solution because the user can still use the mouse for everything. SHIFT for vertical control was often used in isometric / 3D builder games.

Another possibility would be using the mouse wheel for up/down (however, the mouse wheel may already serve other functions, such as camera zooming).
12 May 2018 18:13
Hi Blend4Life,

I like your suggested solution. I'll give it a try and let you know how it goes :)

Brett
 
Please register or log in to leave a reply.