当前位置:网站首页>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;
}
}
边栏推荐
- Database base (Study & review for self use)
- Chinese pycharm changed to English pycharm
- Chapter 9 of OpenGL super classic (version 7): fragment processing and frame buffering
- Some problems encountered in unity steamvr
- Force buckle 27 Removing Elements
- Writing unityshader with sublimetext
- Configuration and use of controllers and routes in nestjs
- 力扣周赛293题解
- 力扣(LeetCode)180. 连续出现的数字(2022.06.29)
- Passing values between classes using delegates and events
猜你喜欢

Parkour demo

Unity + hololens common basic functions

Autowired注解警告的解决办法

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

MinGW-w64下载文件失败the file has been downloaded incorrectly!

PWN Introduction (2) stack overflow Foundation

一条命令运行rancher

Create transfer generation point

Redis cluster concept

What is multimodal interaction?
随机推荐
Introduction to some representations, neighbors and degrees of Graphs
Unity packaging and publishing webgl error reason exception: failed building webgl player
Chinese pycharm changed to English pycharm
Force buckle 704 Binary search
Chapter 11 advanced data management of OpenGL super classic (version 7)
Unity3d lookat parameter description
Create transfer generation point
amd锐龙CPU A320系列主板如何安装win7
Connect() and disconnect() of socket in C #
003-JS-DOM-Attr-innerText
虚析构和纯虚析构
力扣(LeetCode)180. 连续出现的数字(2022.06.29)
Chapter 7 vertex processing and drawing commands of OpenGL super classic (7th Edition)
Go Land no tests were Run: FMT cannot be used. Printf () & lt; BUG & gt;
Unreal 4 learning notes - Animated Montage
Records of problems encountered in unity + hololens development
Nestjs configures static resources, template engine, and post examples
0 foundation starts self-study unit notes control direction becomes larger
Brew install NVM command not found solution
中文版PyCharm改为英文版PyCharm