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


C++ std::cosf方法代码示例

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


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

示例1: GenerateTriangleFan

    inline void GenerateTriangleFan(unsigned int segments)
    {
        vertices.clear();
        normals.clear();
        indicies.clear();
        texCoords.clear();

        float thetaStep = static_cast<float>(PI2 / static_cast<double>(segments));

        int numVerts = segments + 2; // Edge points + center + return to start
        int numTexCoords = (numVerts / 3) * 2;

        vertices.reserve(numVerts);
        normals.reserve(numVerts);
        texCoords.reserve(numVerts);

        // Store start center of the disc
        vertices.push_back(0.0f);
        vertices.push_back(0.0f);
        vertices.push_back(0.0f);

        normals.push_back(0.0f);
        normals.push_back(1.0f);
        normals.push_back(0.0f);

        texCoords.push_back(0.5f);
        texCoords.push_back(0.5f);

        float theta = 0.0f;
        for (unsigned int i = 0; i < segments + 1; i++)
        {
            // Find point on edge
            Vector3 xyz(sinf(theta), 0.0f, cosf(theta));
            
            // Calculate vertex on edge
            vertices.push_back(xyz.x);
            vertices.push_back(0.0f);
            vertices.push_back(xyz.z);

            // Add Normal
            normals.push_back(0.0f);
            normals.push_back(1.0f);
            normals.push_back(0.0f);

            // Work out texture coordinate
            Vector2 uv((xyz.x * 0.5f) + 0.5f, (xyz.z * 0.5f) + 0.5f);
            texCoords.push_back(uv.x);
            texCoords.push_back(uv.y);
            if(i < segments)
            {
                theta += thetaStep;
            }
            else
            {
                theta = 0.0f; // Clamp the final value back to the beginning
            }
        }
    }
开发者ID:Markyparky56,项目名称:minidawn,代码行数:58,代码来源:PrimitiveDisc.hpp

示例2: rotation

quat quat::rotation(float theta, float x, float y, float z)
{
    using std::sinf;
    using std::cosf;
    
    const float haversine = sinf(0.5f * theta);
    const float havercosine = cosf(0.5f * theta);
    
    return quat(
        havercosine,
        haversine * x,
        haversine * y,
        haversine * z
    );
}
开发者ID:BoosYuan,项目名称:kalman-ios,代码行数:15,代码来源:quaternion.cpp

示例3: GenerateTriangles

    inline void GenerateTriangles(unsigned int segments)
    {
        vertices.clear();
        normals.clear();
        indicies.clear();
        texCoords.clear();

        float thetaStep = static_cast<float>(PI2) / static_cast<float>(segments);

        int numVerts = (segments) * 3; // Edge points + center + return to start
        int numTexCoords = (numVerts / 3) * 2;

        vertices.reserve(numVerts);
        normals.reserve(numVerts);
        texCoords.reserve(numVerts);

        float theta1 = 0.0f, theta2 = thetaStep;
        for (unsigned int i = 0; i < segments + 1; i++)
        {
            // Find the two points for this segment
            Vector3 xyz1, xyz2;
            xyz1 = Vector3(sinf(theta1), 0.0f, cosf(theta1));
            xyz2 = Vector3(sinf(theta2), 0.0f, cosf(theta2));

            Vector2 uv1, uv2;
            uv1 = Vector2((xyz1.x * 0.5f) + 0.5f, (xyz1.z * 0.5f) + 0.5f);
            uv2 = Vector2((xyz2.x * 0.5f) + 0.5f, (xyz2.z * 0.5f) + 0.5f);

            // Push the vertices, normals and texture coordinates
            // Center of disc
            vertices.push_back(0.0f);
            vertices.push_back(0.0f);
            vertices.push_back(0.0f);

            vertices.push_back(xyz1.x);
            vertices.push_back(0.0f);
            vertices.push_back(xyz1.z);

            vertices.push_back(xyz2.x);
            vertices.push_back(0.0f);
            vertices.push_back(xyz2.z);

            for (int i = 0; i < 3; i++)
            {
                normals.push_back(0.0f);
                normals.push_back(1.0f);
                normals.push_back(0.0f);
            }

            texCoords.push_back(0.5f);
            texCoords.push_back(0.5f);

            texCoords.push_back(uv1.x);
            texCoords.push_back(uv1.y);
            
            texCoords.push_back(uv2.x);
            texCoords.push_back(uv2.y);

            if (i < segments)
            {
                theta1 += thetaStep;
                theta2 += thetaStep;
            }
            else
            {
                theta1 += thetaStep;
                theta2 = 0.0f; // Clamp back to the beginning
            }
        }
    }
开发者ID:Markyparky56,项目名称:minidawn,代码行数:70,代码来源:PrimitiveDisc.hpp


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