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

  • 相关阅读:
    TSQL入门(msdn)
    在代码中,获取Entity Framework生成的TSQL查询语句
    Code First(一)
    UDPClient的用法
    Building Applications that Can Talk(转)
    Asynchronous Web and Network Calls on the Client in WPF(摘录)
    DropBox能正常使用了
    显示GIF图标报错:“A generic error occurred in GDI+.”
    第 2 篇Scrum 冲刺博客
    第 1 篇 Scrum 冲刺博客
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3957537.html
Copyright © 2011-2022 走看看