博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Self-define float4 vector
阅读量:2442 次
发布时间:2019-05-10

本文共 1436 字,大约阅读时间需要 4 分钟。

The float4 structure encapsulates 4 float values and can be used to represent a 4-element vector or a row of a 4-column matrix:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct
float4
{
 
float4() {};
 
float4(
float
s) : x(s), y(s), z(s), w(s) {}
 
float4(
float
x,
float
y,
float
z,
float
w) : x(x), y(y), z(z), w(w) {}
 
float
x, y, z, w;
 
 
inline
float4 operator*(
float
s)
const
{
return
float4(x*s, y*s, z*s, w*s); }
 
inline
float4 operator+(
const
float4& a)
const
{
return
float4(x+a.x, y+a.y, z+a.z, w+a.w); }
};
 
// dot product of two float4 vectors
inline
float
dot(
const
float4& a,
const
float4& b) {
 
return
a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
}

Similar to the float4 datatype, we define another common type: float3. It can be used, for example, for representing 3D vectors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct
float3
{
 
float3() {};
 
float3(
float
s) : x(s), y(s), z(s) {}
 
float3(
float
x,
float
y,
float
z) : x(x), y(y), z(z) {}
 
float
x, y, z;
 
 
inline
float3 operator*(
float
s)
const
{
return
float3(x*s, y*s, z*s); }
 
inline
float3 operator+(
const
float3& a)
const
{
return
float3(x+a.x, y+a.y, z+a.z); }
};
 
// dot product of two float3 vectors
inline
float
dot(
const
float3& a,
const
float3& b) {
 
return
a.x * b.x + a.y * b.y + a.z * b.z;
}

The float2 datatype contains 2 float elements:

1
2
3
4
5
6
7
struct
float3
{
 
float2() {};
 
float2(
float
s) : x(s), y(s) {}
 
float2(
float
x,
float
y) : x(x), y(y) {}
 
float
x, y;
};

转载地址:http://oviqb.baihongyu.com/

你可能感兴趣的文章
利用Apache+PHP3+MySQL建立数据库驱动的动态网站(转)
查看>>
C#中实现DataGrid双向排序(转)
查看>>
利用C语言小程序来解决大问题(转)
查看>>
简单方法在C#中取得汉字的拼音的首字母(转)
查看>>
编程秘籍:使C语言高效的四大绝招(转)
查看>>
计算机加锁 把U盘变成打开电脑的钥匙(转)
查看>>
Fedora Core 4 基础教程 (上传完毕)(转)
查看>>
删除MSSQL危险存储过程的代码(转)
查看>>
红旗软件:树立国际的Linux品牌(转)
查看>>
Linux学习要点(转)
查看>>
影响mysqld安全的几个选项(转)
查看>>
最新版本Linux Flash 9 Beta开放发布(转)
查看>>
mysql事务处理(转)
查看>>
Fedora 显示设备配置工具介绍(转)
查看>>
FREEBSD 升级及优化全攻略(转)
查看>>
系统移民须知:Linux操作系统安装要点(转)
查看>>
在redhat系统中使用LVM(转)
查看>>
Gentoo 2005.1 完整的USE参数清单中文详解(转)
查看>>
如何在嵌入式Linux产品中做立体、覆盖产品生命期的调试 (5)
查看>>
手机最新触控技术
查看>>