当前位置:网站首页>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;
}
}
边栏推荐
- Deep learning ----- different methods to realize inception-10
- Initial environment configuration of the list of OpenGL super classic (version 7) vs2019
- Unity a* road finding force planning
- 力扣704. 二分查找
- Unity2019.3.8f1 development environment configuration of hololens2
- 力扣349. 两个数组的交集
- Very nervous. What should I do on the first day of software testing?
- Pytorchcnn image recognition and classification model training framework
- Chapter 8 primitive processing of OpenGL super classic (version 7)
- Unity multiple UI page turning left and right
猜你喜欢
随机推荐
JPA composite primary key usage
产生 BUG 测试人员需要自己去分析原因吗?
Unity3d Google Earth
On mask culling of unity
Unity lens making
Nestjs中控制器和路由的配置使用
Unity notes_ SQL Function
z-index属性在什么情况下会失效?
C # equipment synthesis
Unity profiler performance analysis
Create transfer generation point
One command to run rancher
GoLand No Tests Were Run : 不能使用 fmt.Printf() &lt;BUG&gt;
Sourcetree usage
C # Foundation
Four methods of unity ugui button binding events
0 foundation starts self-study unit notes control direction becomes larger
2021-03-16
Records of some problems encountered during unity development (continuously updated)
Li Kou 2049: count the number of nodes with the highest score









