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


C++ Vector4D::GetPoint3D方法代码示例

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


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

示例1: CalculateShadowCasterVolume

void sreFrustum::CalculateShadowCasterVolume(const Vector4D& lightpos, int nu_frustum_planes) {
    nu_frustum_planes = maxf(nu_frustum_planes, SRE_NU_FRUSTUM_PLANES);
    // Note: for beam lights, this might be inaccurate.
    if (lightpos.w == 1.0f && Intersects(lightpos.GetPoint3D(), frustum_world)) {
        // If the point light position is inside the view frustum, we only need to consider the
        // set of visible objects.
        shadow_caster_volume.nu_planes = nu_frustum_planes;
        for (int i = 0; i < nu_frustum_planes; i++)
            shadow_caster_volume.plane[i] = frustum_world.plane[i];
        goto end;
    }
    // Calculate the convex hull enclosing the view frustum and the light source.
    shadow_caster_volume.nu_planes = 0;
    // Calculate the dot products between the frustum planes and the light source.
    float dot[6] DST_ALIGNED(16);
    // The SIMD-accelerated version check for 16-bytes aligned arrays, which is hard to
    // guarantee in this case; otherwise, no SIMD will be used.
#if 1
    dstCalculateDotProductsNx1(nu_frustum_planes, &frustum_world.plane[0],
        lightpos, &dot[0]);
#else
    for (int i = 0; i < nu_frustum_planes; i++)
        dot[i] = Dot(frustum_world.plane[i], lightpos);
#endif
    // For each frustum plane, add it if it is part of the convex hull.
    for (int i = 0; i < nu_frustum_planes; i++)
        if (dot[i] > 0) {
             shadow_caster_volume.plane[shadow_caster_volume.nu_planes] = frustum_world.plane[i];
             shadow_caster_volume.nu_planes++;
        }
//    printf("Shadow caster volume planes: from frustum: %d\n", shadow_caster_volume.nu_planes);
    if (shadow_caster_volume.nu_planes == 0 && lightpos.w == 1.0f) {
        // Special case: the point light source is behind the camera and there is no far plane.
        // As a result, there is no plane from the frustum with a positive dot product. In
        // this case, construct a volume consisting of the lightsource and four planes parallel 
        // to the frustum side planes but starting at the lightsource.
        for (int i = 0; i < 4; i++) {
            // Copy the normal.
            shadow_caster_volume.plane[i] = frustum_world.plane[i];
            // Calculate the distance such that the lightsource is in the plane.
            shadow_caster_volume.plane[i].w = - Dot(frustum_world.plane[i].GetVector3D(),
                lightpos.GetPoint3D());
        }
        shadow_caster_volume.nu_planes = 4;
        goto end;
    }
    // For each pair of adjacent frustum planes, if one has a positive dot product and the other
    // does not, calculate a new plane defined by the edge between those two frustum planes and
    // the position of the light source, making sure the plane's normal direction faces inward.
    // For directional lights, the plane runs parallel to the direction of the light.
    nu_shadow_caster_edges = 0;
    int n;
    if (nu_frustum_planes == 5)
        n = 8;
    else
        n = 12;
    for (int i = 0; i < n; i++)
        if ((dot[adjacent_plane[i].plane0] > 0 && dot[adjacent_plane[i].plane1] <= 0) ||
        (dot[adjacent_plane[i].plane0] <= 0 && dot[adjacent_plane[i].plane1] > 0)) {
//            printf("Setting plane from adjacent planes %d and %d using frustum vertices %d and %d\n",
//                adjacent_plane[i].plane0, adjacent_plane[i].plane1, adjacent_plane[i].vertex0,
//                adjacent_plane[i].vertex1);
            if (lightpos.w == 1.0f)
                shadow_caster_volume.plane[shadow_caster_volume.nu_planes] = dstPlaneFromPoints(
                    frustum_world.hull.vertex[adjacent_plane[i].vertex0],
                    frustum_world.hull.vertex[adjacent_plane[i].vertex1],
                    lightpos.GetPoint3D()
                    );
            else {
                shadow_caster_volume.plane[shadow_caster_volume.nu_planes] = dstPlaneFromPoints(
                    frustum_world.hull.vertex[adjacent_plane[i].vertex0],
                    frustum_world.hull.vertex[adjacent_plane[i].vertex1],
                    frustum_world.hull.vertex[adjacent_plane[i].vertex0] + lightpos.GetVector3D()
                    );
                shadow_caster_edge[nu_shadow_caster_edges][0] = adjacent_plane[i].vertex0;
                shadow_caster_edge[nu_shadow_caster_edges][1] = adjacent_plane[i].vertex1;
                nu_shadow_caster_edges++;
            }
            // Make sure the normal is pointed inward, check by taking the dot product with the frustum
            // "centroid".
            shadow_caster_volume.plane[shadow_caster_volume.nu_planes].OrientPlaneTowardsPoint(
                frustum_world.sphere.center);
            shadow_caster_volume.nu_planes++;
        }
end: ;
#if 0
    printf("Light (%lf, %lf, %lf, %lf), %d planes in shadow caster volume.\n",
        lightpos.x, lightpos.y, lightpos.z, lightpos.w, shadow_caster_volume.nu_planes);
    for (int i = 0; i < shadow_caster_volume.nu_planes; i++)
        printf("Plane %d: (%lf, %lf, %lf, %lf) ", i,
            shadow_caster_volume.plane[i].x, shadow_caster_volume.plane[i].y,
            shadow_caster_volume.plane[i].y, shadow_caster_volume.plane[i].w);
    printf("\n");
#endif
}
开发者ID:hglm,项目名称:sre,代码行数:95,代码来源:frustum.cpp


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