zoukankan      html  css  js  c++  java
  • CG中的类型

    Matrix

      通常像下面这样定义Matrix:

    int1x1    iMatrix;   // integer matrix with 1 row,  1 column
    int4x1    iMatrix;   // integer matrix with 4 rows, 1 column
    int1x4    iMatrix;   // integer matrix with 1 row, 4 columns
    double3x3 dMatrix;   // double matrix with 3 rows, 3 columns
    
    float2x2 fMatrix = { 0.0f, 0.1, // row 1
                         2.1f, 2.2f // row 2
                       };   
    View Code

      也可以像下面这样定义Matrix:

    matrix <Type, Number> VariableName
    matrix <float, 2, 2> fMatrix = { 0.0f, 0.1, // row 1
                                     2.1f, 2.2f // row 2
                                   };
    View Code

      Member access for matrix types

    _m00, _m01,_m02, _m03 
    
    _m10, _m11,_m12, _m13 
    
    _m20, _m21,_m22, _m23 
    
    _m30, _m31,_m32, _m33 
    
    or
    
    _11, _12,_13, _14 
    
    _21, _22,_23, _24 
    
    _31, _32,_33, _34 
    
    _41, _42,_43, _4
    View Code

    参考:http://msdn.microsoft.com/en-us/library/windows/desktop/bb509623(v=vs.85).aspx

    Vector

      通常像下面这样定义Vector:

    bool    bVector;   // scalar containing 1 Boolean
    int1    iVector = 1;
    float3  fVector = { 0.2f, 0.3f, 0.4f };
    View Code

      也可像下面这样定义:

    vector <Type, Number> VariableName
    
    vector <int,    1> iVector = 1;
    vector <double, 4> dVector = { 0.2, 0.3, 0.4, 0.5 };
    View Code

    Scalar

    • bool - true or false.
    • int - 32-bit signed integer.
    • uint - 32-bit unsigned integer.
    • dword - 32-bit unsigned integer.
    • half - 16-bit floating point value. This data type is provided only for language compatibility. Direct3D 10 shader targets map all half data types to float data types. A half data type cannot be used on a uniform global variable (use the /Gec flag if this functionality is desired).
    • float - 32-bit floating point value.
    • double - 64-bit floating point value. You cannot use double precision values as inputs and outputs for a stream. To pass double precision values between shaders, declare each double as a pair of uint data types. Then, use the asdouble function to pack each double into the pair of uints and the asuint function to unpack the pair of uints back into the double.

    Per-Component Math Operations

      可以单独取出Vector中的分量进行计算:

    float4 pos = float4(0,0,2,1);
    float2 f_2D;
    f_2D = pos.xy;   // read two components 
    f_2D = pos.xz;   // read components in any order       
    f_2D = pos.zx;
    
    f_2D = pos.xx;   // components can be read more than once
    f_2D = pos.yy;
    View Code

      读取matrix的某一行:

    float2 temp;
    float2x2 fMatrix;
    temp = fMatrix[0] // read the first row
    View Code

    参考:http://msdn.microsoft.com/en-us/library/windows/desktop/bb509634(v=vs.85).aspx

  • 相关阅读:
    eval()和JSON.parse()的区别
    Android的Monkey和MonkeyRunner
    JavaScript event对象clientX,offsetX,screenX异同
    @-webkit-keyframes 动画 css3
    W3C标准定义的DOM由哪三部分组成
    Javascript 中的神器——Promise
    为什么你的javascript学了这么久,水平还是烂成了渣?
    js深入理解构造函数和原型对象
    js常用面试题整理
    面试宝典:25个最经典的JavaScript面试题及答案
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3957537.html
Copyright © 2011-2022 走看看