当前位置:网站首页>Rotation in model space and rotation in world space
Rotation in model space and rotation in world space
2022-07-29 07:57:00 【TingQiaoQiao】
Transform the vertices of the model in the vertex shader , Then follow the teacher's train of thought , The pointer of the following model should follow x Axis rotation ,unity Middle is left-handed coordinates , So its z Axis up ,y Axis right
void Rotation(float mask, inout float3 vertex, float offset, float angle) {
vertex.y -= offset * mask; // Translate the clock with mask
float radx = radians(angle * mask);
float sinx, cosx = 0;
sincos(radx, sinx, cosx);
vertex.yz = float2(vertex.y * cosx - vertex.z * sinx, vertex.y * sinx + vertex.z * cosx);
vertex.y += offset * mask;
}
void ClockRotation(float3 color , inout float3 vertex ) {
Rotation( color.r, vertex, _MoveOffect, _HourAngle);
Rotation( color.g, vertex, _MoveOffect, _MinuteAngle);
Rotation( color.b, vertex, _MoveOffect, _SecondAngle);
}
// Input structure >>> The vertices Shader>>> Output structure
VertexOutput vert(VertexInput v) {
VertexOutput o = (VertexOutput)0;
// Perform vertex transformation on the time needle
ClockRotation(v.color.rgb, v.vertex.xyz);
}
Later, I found that the effect picture is :
It can be clearly seen around z The shaft is turning , instead of x Axis
Later, it was found that it was in Transform It's adjusted inside y Rotating shaft of shaft , The vertex coordinate is the coordinate in model space , At the beginning, by default, the coordinates of model space and time space are consistent , Instead, it revolves around x The shaft rotates . However, the coordinates of the model in world space are discussed later y Axis 90 Degree rotation , So that the coordinates in the model space also follow y Axis progress 90 Degrees of rotation , This leads to the effect that the pointer surrounds z Axis rotation .
In this case, it is best not to transform the model in space , First deal with the vertex in the existing situation, and then convert its world space .
void Rotation( float mask, inout float3 vertex, float offset, float angle ) {
vertex.y -= offset * mask; // Translate the clock with mask
float radz = radians(angle * mask);
float sinz, cosz = 0;
sincos(radz, sinz, cosz);
// At present, the vertex is still the vertex data in object space , There is no vertex data converted to world space , So the coordinate system used is still the object coordinate system , The coordinate system of the component is the coordinate system in world space , At the beginning, by default, the coordinate system in object space is the same as that in world space , But it will be different if we change again
// Here we should pay attention to , You need to initialize all the rotation parameters of the model to 0, Then use the current code to adjust the parameters , Finally, change the overall rotation of the model
vertex.xy = float2(vertex.x * cosz - vertex.y * sinz, vertex.x * sinz + vertex.y * cosz); // The order of rotation parameter adjustment is : The code rotates using the original default coordinate system , Then rotate the model according to the components , Because when the component rotates, the spatial coordinate axis of the object itself will also be rotated accordingly
vertex.y += offset * mask;
}
边栏推荐
- Data warehouse modeling, what is wide table? How to design? Advantages and disadvantages
- 功能自动化测试实施的原则以及方法有哪些?
- JVM garbage collection mechanism (GC)
- 下推分析的限制
- What is the use of chat robots? What type? After reading these, you will understand!
- Pytest set (7) - parameterization
- CentOS deploy PostgreSQL 13
- Database persistence +jdbc database connection
- [skill accumulation] common expressions when writing emails
- [paper reading | cryoelectron microscope] interpretation of the new subtomogram averaging method in relion 4.0
猜你喜欢
The software package is set to - > Yum source
What is the use of chat robots? What type? After reading these, you will understand!
[paper reading | cryoelectron microscope] interpretation of the new subtomogram averaging method in relion 4.0
My entrepreneurial neighbors
207.课程表
Explanation and closing method of server 135, 137, 138, 139, 445 and other ports
Solve the problem that CSDN cannot publish blog due to unknown copyright
[deep learning] data preparation -pytorch custom image segmentation data set loading
MySQL uses date_ FORMAT(date,'%Y-%m')
Do you want to meet all the needs of customers
随机推荐
你学习·我奖励,21天学习挑战赛 | 等你来战
MySQL 45讲 | 08 事务到底是隔离的还是不隔离的?
Detailed explanation of the find command (the most common operation of operation and maintenance at the end of the article)
Day 014 二维数组练习
[WPF] realize language switching through dynamic / static resources
[cryoEM] Introduction to FSC, Fourier shell correlation
Explanation and closing method of server 135, 137, 138, 139, 445 and other ports
The difference between static library and dynamic library of program
Space shooting Lesson 17: game over (end)
330. Complete the array as required
Embroidery of little D
[untitled] format save
10 practical uses of NFT
Write some DP
Solve the problem that the disk is full due to large files
[note] the art of research - (tell a good story and argument)
[cryptography experiment] 0x00 install NTL Library
MySQL 45 | 08 is the transaction isolated or not?
postman接口测试|js脚本之阻塞休眠和非阻塞休眠
String class