示例#1
0
文件: camera.c 项目: ttammear/tt3d
// TODO: alot of slow stuff in it
b32 cameraIsPointInFrustum(Camera *cam, Vec3 worldPos)
{
    Plane frustumPlanes[6];
    getFrustumPlanes(&cam->perspectiveMatrix, frustumPlanes);
    for(int i = 0; i < 6; i++)
    {
        Vec4 thing = vec4(frustumPlanes[i].a,frustumPlanes[i].b,frustumPlanes[i].c,0.0f);
        Mat4 mat = cameraCalculateInverseViewMatrix(cam);
        Vec4 res;
        mat4Vec4Mul(&res, &mat, &thing);
        frustumPlanes[i] = planeFromVec4(&res);
    }

    Vec3 n[6];
    r32 d[6];

    for(int planeId = 0; planeId < 6; planeId++)
    {
        Vec3 idk = vec3(frustumPlanes[planeId].a,frustumPlanes[planeId].b,frustumPlanes[planeId].c);
        n[planeId] = vec3Normalized(&idk);
        d[planeId] = frustumPlanes[planeId].d;
    }

        // TODO: check for all 6 planes?
    Vec3 pos;
    vec3Sub(&pos, &worldPos, &cam->position);
    r32 res = vec3Dot(&pos, &n[0]) + d[0] + 141.0f;
    r32 res2 = vec3Dot(&pos, &n[1]) + d[1] + 141.0f;
    if(res <= 0.f || res2 <= 0.f)
        return false;
    return true;
}
示例#2
0
void SceneManager::update(double t, double dt)
{
    this->t = t;
    this->dt = dt;

    if (root != NULL) {
        root->updateLocalToWorld(NULL);
        mat4d cameraToScreen = getCameraToScreen();
        worldToScreen = cameraToScreen * getCameraNode()->getWorldToLocal();
        root->updateLocalToCamera(getCameraNode()->getWorldToLocal(), cameraToScreen);
        getFrustumPlanes(worldToScreen, worldFrustumPlanes);
        computeVisibility(root, PARTIALLY_VISIBLE);
    }
}
示例#3
0
int SE_Camera::cullBV(const SE_BoundingVolume& bv) const
{
    SE_Plane cullPlanes[6];
    SE_Plane_Side planeSide = SE_NEGATIVE;
    getFrustumPlanes(cullPlanes);
    for(int i = 0 ; i < 6 ; i++)
    {
        SE_Plane_Side p = bv.whichSide(cullPlanes[i]);
        if(p == SE_POSITIVE)
            return SE_FULL_CULL;
        if(p != SE_NEGATIVE)
            planeSide = p;
    }
    if(planeSide == SE_NEGATIVE)
        return SE_NOT_CULL;
    else
        return SE_PART_CULL;
}