当前位置:网站首页>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;
}
}
边栏推荐
- Redis cluster concept
- Network communication problem locating steps
- Four methods of unity ugui button binding events
- Unity automatic pathfinding
- 很紧张,第一天做软件测试,需要做什么?
- Pytorchcnn image recognition and classification model training framework
- 力扣209. 长度最小的子数组
- 产生 BUG 测试人员需要自己去分析原因吗?
- Exploration of unity webgl
- Unity notes_ SQL Function
猜你喜欢

Unity3d packaging and publishing APK process

力扣704. 二分查找

Unity automatic pathfinding

虚析构和纯虚析构

Preorder traversal of Li Kou 589:n fork tree

Unreal 4 unavigationsystemv1 compilation error

Basic operations of Oracle data
![[vcs+verdi joint simulation] ~ take the counter as an example](/img/fb/214a4e65c53503ecbc38a5e43523cf.png)
[vcs+verdi joint simulation] ~ take the counter as an example

MySQL query gadget (I) replace a property value of the object in the JSON array in the JSON format string field

Unity + hololens publishing settings
随机推荐
How to install win7 on AMD Ruilong CPU A320 series motherboard
Pytorchcnn image recognition and classification model training framework
[learning notes] AssetBundle, xlua, hot update (use steps)
Chapter 9 of OpenGL super classic (version 7): fragment processing and frame buffering
Parkour demo
Unreal 4 learning notes - data storage using blueprints
力扣27. 移除元素
Chapter 10 of OpenGL super classic (7th Edition) calculation shader
Solution to the 292 week match of Li Kou
【VCS+Verdi聯合仿真】~ 以計數器為例
Brew install NVM command not found solution
svg和canvas的区别
力扣349. 两个数组的交集
Go Land no tests were Run: FMT cannot be used. Printf () & lt; BUG & gt;
Connect() and disconnect() of socket in C #
Unity3d Google Earth
MinGW-w64下载文件失败the file has been downloaded incorrectly!
Unity project hosting platform plasticscm (learn to use 1)
PWN Introduction (2) stack overflow Foundation
Force buckle 977 Square of ordered array