当前位置:网站首页>[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

边栏推荐
猜你喜欢

1.6 - CPU组成

Gazebo model modification

Analysis of startup process of gazebo multi computer simulation

史上最全一句话木马

First experience of Galaxy Kirin
![[mask RCNN] target detection and recognition based on mask RCNN](/img/80/f3db990b4f242609679d872b0dfe00.png)
[mask RCNN] target detection and recognition based on mask RCNN

Pay attention to this live broadcast and learn about the path to achieve the dual carbon goal of the energy industry

ROS service communication programming

Why does ETL often become ELT or even let?

随机网络,无标度网络,小世界网络以及NS小世界的性能对比matlab仿真
随机推荐
银河麒麟初体验
C语言:练习题三
tomorrow! "Mobile cloud Cup" competition air publicity will start!
ftplib+ tqdm 上传下载进度条
Solr search
明天!“移动云杯”大赛空宣会开播!
汇编语言学习一(有栈协程铺垫,32位寄存器和相关指令学习,未完待续06/29)
Fastapi learning Day1
RT thread Kernel Implementation (I): threads and scheduling
SOC_SD_CLK
RT thread Kernel Implementation (II): critical area, object container
ROS multi machine
Fastapi learning Day2
First experience of Galaxy Kirin
【docsify基本使用】
华泰炒股安全吗?我想网上开户。
Initial love with mqtt
Problems and solutions of creating topic messages in ROS
Combat simulation system data
1.9 - Cache