当前位置: 首页>>代码示例>>C++>>正文


C++ Mat3::getTransformedVector方法代码示例

本文整理汇总了C++中Mat3::getTransformedVector方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat3::getTransformedVector方法的具体用法?C++ Mat3::getTransformedVector怎么用?C++ Mat3::getTransformedVector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mat3的用法示例。


在下文中一共展示了Mat3::getTransformedVector方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: bakeTexture

void OcclusionBaker::bakeTexture(cocos2d::RenderTexture* tex,
                                  const cocos2d::Vec2& worldPos,
                                  const cocos2d::Vec2& scaleFactor,
                                  const std::vector<realtrick::Polygon>& polygons,
                                  const cocos2d::Size& boundarySize,
                                  const FieldOfView& fov)
{
    _eyePos = worldPos;
    
    // 경계면 정점을 만든다.
    realtrick::Polygon clipBoundary;
    
    //
    // (v2)               (v3)
    //   . --------------- .
    //   |     worldPos    |
    //   |        .        |
    //   |                 |
    //   . --------------- .
    // (v1)               (v4)
    //
    const int PAD = 0;
    Vec2 v1 = Vec2(worldPos.x - boundarySize.width / 2 + PAD, worldPos.y - boundarySize.height / 2 + PAD); // left bottom
    Vec2 v2 = Vec2(worldPos.x - boundarySize.width / 2 + PAD, worldPos.y + boundarySize.height / 2 - PAD); // left top
    Vec2 v3 = Vec2(worldPos.x + boundarySize.width / 2 - PAD, worldPos.y + boundarySize.height / 2 - PAD); // right top
    Vec2 v4 = Vec2(worldPos.x + boundarySize.width / 2 - PAD, worldPos.y - boundarySize.height / 2 + PAD); // right bottom
    
    PROFILE_BEGIN("a");
    if ( fov.isEnable )
    {
        // fov 를 적용한다면 시야각과 플레이어 주변 원 데이터를 이용해 클리핑 경계면을 만든다. ( CCW )
        //                                     *fov : field of view (시야각)
        //             (n + m)
        //   (1) . ---.---.---.-- . (n+4)
        //        \              /
        //         \            /
        //          \          /
        //           \        /
        //            \ fov  /
        //             \    /
        //           (2)'  '(n+3)
        //             . w  .
        //              '..'
        //          ( n 개의 정점 )
        //
        //
        
        // "1", "n + 4" vertex
        vector<Segment> boundaryWalls;
        boundaryWalls.push_back(Segment(v1, v2));
        boundaryWalls.push_back(Segment(v2, v3));
        boundaryWalls.push_back(Segment(v3, v4));
        boundaryWalls.push_back(Segment(v4, v1));
        
        Mat3 rotationMatrix;
        rotationMatrix.rotate(MATH_DEG_TO_RAD(fov.entryDegree/2));
        Vec2 leftDir = rotationMatrix.getTransformedVector(fov.heading);
        Segment leftRay = Segment(worldPos, worldPos + leftDir * SEGMENT_LENGTH);
        
        rotationMatrix.identity();
        rotationMatrix.rotate(MATH_DEG_TO_RAD(-fov.entryDegree/2));
        Vec2 rightDir = rotationMatrix.getTransformedVector(fov.heading);
        Segment rightRay = Segment(worldPos, worldPos + rightDir * SEGMENT_LENGTH);
        
        Vec2 leftIntersectPoint = _getClosestIntersectPointToWall(boundaryWalls, leftRay);
        Vec2 rightIntersectPoint = _getClosestIntersectPointToWall(boundaryWalls, rightRay);
        
        
        // "n + m" vertex
        std::vector<Vec2> belongPoints;
        if ( leftDir.cross(v1 - worldPos) < 0 && rightDir.cross(v1 - worldPos) > 0 ) belongPoints.push_back(v1);
        if ( leftDir.cross(v2 - worldPos) < 0 && rightDir.cross(v2 - worldPos) > 0 ) belongPoints.push_back(v2);
        if ( leftDir.cross(v3 - worldPos) < 0 && rightDir.cross(v3 - worldPos) > 0 ) belongPoints.push_back(v3);
        if ( leftDir.cross(v4 - worldPos) < 0 && rightDir.cross(v4 - worldPos) > 0 ) belongPoints.push_back(v4);
        
        std::sort(std::begin(belongPoints), std::end(belongPoints), [&](const Vec2& v1, const Vec2& v2){
            
            Vec2 tempV1 = (v1 - _eyePos).getNormalized();
            Vec2 tempV2 = (v2 - _eyePos).getNormalized();
            
            float angle1 = physics::getAngleFromAxis(tempV1, fov.heading);
            float angle2 = physics::getAngleFromAxis(tempV2, fov.heading);
            
            return angle1 > angle2;
            
        });
        
        
        // "2", "n + 3" vertex
        Vec2 leftCirclePoint = worldPos + leftDir * fov.aroundCircleRadius;
        Vec2 rightCirclePoint = worldPos + rightDir * fov.aroundCircleRadius;
        
        
        // "n" vertices
        std::vector<Vec2> circleVertices;
        int remainCircleDegree = 360 - fov.entryDegree;
        int sliceCount = std::max(fov.aroundCircleSlice, 10); // 최소 10개의 정점을 이용해 정점 n을 만든다.
        int degreePerLoop = remainCircleDegree / sliceCount;
        for(int i = 1 ; i < sliceCount ; ++ i)
        {
//.........这里部分代码省略.........
开发者ID:Realtrick-Games,项目名称:DeadForest,代码行数:101,代码来源:OcclusionBaker.cpp


注:本文中的Mat3::getTransformedVector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。