当前位置:网站首页>Rotation, translation and scaling of unity VR objects
Rotation, translation and scaling of unity VR objects
2022-06-30 05:08:00 【zjh_ three hundred and sixty-eight】
Operation instructions : Because it involves the operation after triggering the object , Therefore, the rotation and scaling need to be switched by the trigger key . Translate the left handle by holding down the pick key , Right handle rotation , Click the trigger key on the right handle to switch to zoom , At this time, the rotation function will not be available , The left and right handles can be translated , The double handle operation is zoom . Then click the trigger button on the right handle , The right handle can restore the rotation function .
One 、 Pan zoom
1、 Create a new spherical trigger as the operation object , The model that needs to be manipulated can be used as the sub object of this service , Self adjusting trigger range .
2、 Pan use the function of grabbing the model . The small arrow in the following figure , Is the default left handle trigger translation .
3、VRTK_AxisScaleGrabAction by VRTK Scale object scripts
Two 、 rotate
update The rotation control function is used to control the rotation of the model object by obtaining the position of the handle .
The last three are all handle controller key events , The last one is the trigger button used to switch the rotation and zoom functions .
Vector3 previousPosition;
Vector3 offset;
bool isRotate = true;
private bool isOpertion = false;
void Update()
{
// Grab key Operation or not
if (!isOpertion)
{
previousPosition = controllerRight.position;
}else
{
// The rotation of the model is controlled by the position of the handle
offset = controllerRight.position - previousPosition;
previousPosition = controllerRight.position;
float xdis = Mathf.Abs(offset.x);
float ydis = Mathf.Abs(offset.y);
if (xdis > ydis)
{
if (offset.x > 0)
{
sphereMoveObj.transform.Rotate(Vector3.down, offset.magnitude * 80f, Space.World);
}
if (offset.x < 0)
{
sphereMoveObj.transform.Rotate(Vector3.up, offset.magnitude * 80f, Space.World);
}
}
else
{
if (offset.y > 0)
{
sphereMoveObj.transform.Rotate(Vector3.right , offset.magnitude * 80f, Space.World);
}
if (offset.y < 0)
{
sphereMoveObj.transform.Rotate(Vector3.left, offset.magnitude * 80f, Space.World);
}
}
}
}
// The right handle releases the grab button
private void VrtkIG_Right_GrabButtonReleased(object sender, ControllerInteractionEventArgs e)
{
isOpertion = false;
}
// The right handle emits when grabbing a valid object
private void VrtkIG_Right_ControllerGrabInteractableObject(object sender, ObjectInteractEventArgs e)
{
if (isRotate)
{
isOpertion = true;
}
}
// When the trigger is squeezed a little, it emits
private void VrtkCE_Right_TriggerTouchStart(object sender, ControllerInteractionEventArgs e)
{
// Toggle rotation and translation
if (sphereMoveObj.transform.GetComponent<VRTK_InteractableObject>().allowedGrabControllers == VRTK_InteractableObject.AllowedController.Both)
{
sphereMoveObj.transform.GetComponent<VRTK_InteractableObject>().allowedGrabControllers = VRTK_InteractableObject.AllowedController.LeftOnly;
isRotate = true;
}
else
{
sphereMoveObj.transform.GetComponent<VRTK_InteractableObject>().allowedGrabControllers = VRTK_InteractableObject.AllowedController.Both;
isRotate = false;
}
}
边栏推荐
猜你喜欢
Yolov5 torch installation
力扣59. 螺旋矩阵 II
Pit of smoothstep node in shadergraph
Unity realizes rotation and Revolution
【 VCS + Verdi joint simulation】 ~ Taking Counter as an Example
Unreal 4 unavigationsystemv1 compilation error
The file has been downloaded incorrectly!
【VCS+Verdi聯合仿真】~ 以計數器為例
Parkour demo
Unity project hosting platform plasticscm (learn to use 1)
随机推荐
Unity application class and data file path
How to install win7 on AMD Ruilong CPU A320 series motherboard
Unrealeengine4 - about uobject's giant pit that is automatically GC garbage collected
虚析构和纯虚析构
力扣2049:统计最高分的节点数目
Some books you should not miss when you are new to the workplace
LxC and LXD container summary
Very nervous. What should I do on the first day of software testing?
z-index属性在什么情况下会失效?
Unity lens making
[recruitment] UE4 Development Engineer
One command to run rancher
Detailed explanation of the process of "flyingbird" small game (camera adjustment and following part)
Yolov5 torch installation
Unreal 4 learning notes - Animated Montage
一条命令运行rancher
Nestjs中控制器和路由的配置使用
Unity script life cycle and execution sequence
2021-07-29 compilation of Cura in ubantu18.04
Force buckle 209 Minimum length subarray