当前位置:网站首页>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;
}边栏推荐
- Solve the problem that CSDN cannot publish blog due to unknown copyright
- My entrepreneurial neighbors
- The new colleague wrote a few pieces of code, broke the system, and was blasted by the boss!
- What are the common error types and solutions of black box testing?
- NLP introduction + practice: Chapter 5: using the API in pytorch to realize linear regression
- Compare three clock circuit schemes of single chip microcomputer
- QT connects two qslite databases and reports an error qsqlquery:: exec: database not open
- 功能自动化测试实施的原则以及方法有哪些?
- Basic introduction to pod
- [memo] summary of the reasons why SSH failed? Remember to come next time.
猜你喜欢
![[WPF] realize language switching through dynamic / static resources](/img/23/1e089ce4a07128323824b25897a8c4.png)
[WPF] realize language switching through dynamic / static resources

技术分享| 快对讲综合调度系统

Jianmu continuous integration platform v2.5.2 release

@JsonSerialize注解的使用

Matrix decomposition and gradient descent

Day 014 2D array exercise

Sort out the two NFT pricing paradigms and four solutions on the market

How to draw an excellent architecture diagram
What are the common error types and solutions of black box testing?

Solving linear programming problems based on MATLAB
随机推荐
黑盒测试常见错误类型说明及解决方法有哪些?
An optimal buffer management scheme with dynamic thresholds paper summary
Day 014 二维数组练习
[paper reading] tomoalign: a novel approach to correcting sample motion and 3D CTF in cryoet
[lecture notes] how to do in-depth learning in poor data?
The database uses PSQL and JDBC to connect remotely and disconnect automatically from time to time
Processes and threads
Useful websites
Strongly connected component
Some thoughts on growing into an architect
[memo] summary of the reasons why SSH failed? Remember to come next time.
在js中,0表示false,非0表示true
监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)
《nlp入门+实战:第五章:使用pytorch中的API实现线性回归》
String类
Matlab simulation of LDPC minimum sum decoding based on high-order six ring free
Cross domain problems when downloading webapi interface files
Basic introduction to pod
Measured waveform of boot capacitor short circuit and open circuit of buck circuit
[untitled] format save