当前位置:网站首页>[my advanced OpenGL learning journey] about the access methods of vector and matrix classification of OpenGL shaders: xyzw/rgba/stpq and array subscripts
[my advanced OpenGL learning journey] about the access methods of vector and matrix classification of OpenGL shaders: xyzw/rgba/stpq and array subscripts
2022-06-30 06:53:00 【Byte scrolling】
One 、 The expression of the individual components of a vector
The individual components of a vector can be accessed in two ways :
- Use “
.”Operator. - Use
The array subscript.
Two 、 Naming scheme
2.1 Three combined access methods
According to the number of components that make up the vector , Each component can be accessed through the following three combinations
{x,y,z,w}
It usually represents a spatial coordinate(x,y,z,w), You can use... Separately.x、.y、.z and .wTo get their first1、2、3、4Weight .{r,g,b,a}
Usually represents a color(r,g,b,a), You can use... Separately.r、.g、.b and .aTo get their first1、2、3、4Weight .{s,t,p,q}
Usually represents a texture coordinate(s,t,p,q), You can use... Separately.s、.t、.p and .qTo get their first1、2、3、4Weight .
2.2 Meaning of combination mode
The reason for the three different naming schemes is that vectors can be used interchangeably to represent mathematical vector 、 Color and texture coordinates .
x/r/sThe component always refers to the... Of the vector1Weight .y/g/tThe component always refers to the... Of the vector2Weight .z/b/pThe component always refers to the... Of the vector3Weight .w/a/qThe component always refers to the... Of the vector4Weight .
Different naming conventions are just not convenient .
2.3 Precautions for combination mode
however , You cannot mix naming conventions when accessing vectors ( In other words , No .xgr Such reference methods , Because only one naming convention can be used at a time )
3、 ... and 、 Use “.” Operator
Use "." Operator , You can rearrange the components of the vector in the operation .
Here is an example .
vec3 myVec3 = vec3(0.0,1.0,2.0); // myVec3 = {0.0,1.0,2.0}
vec3 temp;
temp = myVec3.xyz; // temp = {0.0,1.0,2.0}
temp = myVec3.xxx; // temp = {0.0,0.0,0.0}
temp = myVec3.zyx; // temp = {2.0,1.0,0.0}

Four 、 Use array subscripts "[]" Operator access
Besides using "." Operator , Use array subscripts "[]" Operator access .
In array subscript , Elements [0] Corresponding to x, Elements [1] Corresponding to y, wait .
A matrix is considered to consist of some vectors . for example ,mat2 It can be seen as two vec2,mat3 Can be seen as 3 individual vec3, wait .
For matrices , Individual columns can use the array subscript operator "[]" choice , Each vector can then be accessed through the vector access behavior .
Here are some examples of access matrices :
mat4 myMat4 = mat4(1.0); // Initialize diagonal to 1.0 (identity)
vex4 col0 = myMat4[0]; // Get col0 vector out of the matrix
float m1_1 = myMat4[1][1]; // Get element at [1][1] in matrix
float m2_2 = myMat4[2].z; // Get element at [2][2] in matrix

边栏推荐
猜你喜欢

随机网络,无标度网络,小世界网络以及NS小世界的性能对比matlab仿真

RT thread Kernel Implementation (II): critical area, object container

HuaWei满级大牛首次分享出这份598页网络协议全彩手册

Introduction to neural networks

1.4 - fixed and floating point numbers

1.6 - CPU组成
![[my creation anniversary] one year anniversary essay](/img/98/f9305894747687465f86354fe08500.png)
[my creation anniversary] one year anniversary essay

1.8 - multi level storage

Record one time of Tencent Test Development Engineer's automation interface test practice experience

File transfer protocol, FTP file sharing server
随机推荐
【Hot100】11. 盛最多水的容器
Ffmplay is not generated during the compilation and installation of ffmpeg source code
tomorrow! "Mobile cloud Cup" competition air publicity will start!
Write a C program to judge whether the system is large end byte order or small end byte order
Pay attention to this live broadcast and learn about the path to achieve the dual carbon goal of the energy industry
Ls1028 manual
1.4 - fixed and floating point numbers
CPU到底是怎么识别代码的?
NFS mount
C language: exercise 3
Basic questions (I)
RT thread Kernel Implementation (II): critical area, object container
相关数据库问题提问。
How to set the hot deployment of idea web project
ETL为什么经常变成ELT甚至LET?
The solution of memcpy memory overlap
How does the CPU recognize the code?
Google Earth Engine(GEE)——墨累全球潮汐湿地变化 v1 (1999-2019) 数据集
[JSON tutorial] Chapter 1 learning notes
Hao looking for a job