示例#1
0
BoundingBox MeshRenderer::getBoundingBox() {
    std::vector<Vector3f> coordinates;
    for(uint i = 0; i < getNrOfInputData(); i++) {
        BoundingBox transformedBoundingBox = mMeshToRender[i]->getTransformedBoundingBox();
        MatrixXf corners = transformedBoundingBox.getCorners();
        for(uint j = 0; j < 8; j++) {
            coordinates.push_back((Vector3f)corners.row(j));
        }
    }
    return BoundingBox(coordinates);
}
示例#2
0
bool Frustum::boundsInFrustum (BoundingBox& bounds) {
    const std::vector<Vector3>& corners = bounds.getCorners();
    int len = corners.size();

    for (int i = 0, len2 = 6; i < len2; i++) {
        int out = 0;

        for (int j = 0; j < len; j++)
          if (planes[i]->testPoint(corners[j]) == Plane::PlaneSide_Back) out++;

        if (out == 8) return false;
    }

    return true;
}
示例#3
0
文件: app.cpp 项目: ileben/GameEngine
BoundingBox appProjectActor (Actor3D *actor, Camera *camera,
                             Float viewX, Float viewY, Float viewW, Float viewH)
{
  //Get the transformation matrix
  Matrix4x4 world = actor->getGlobalMatrix();
  Matrix4x4 modelview = camera->getGlobalMatrix().affineNormalize().affineInverse();
  Matrix4x4 projection = camera->getProjection( viewW, viewH );
  Matrix4x4 m = projection * modelview * world;

  //Get corners of the bounding box
  BoundingBox bboxActor = actor->getBoundingBox();
  Vector3 bboxCorners[8];
  bboxActor.getCorners( bboxCorners );

  //Project each corner into viewport
  BoundingBox bboxOut;
  for (Uint c=0; c<8; ++c)
  {
    //Projection and perspective division
    Vector4 p = m.transformPoint( bboxCorners[ c ].xyz(1.0f) );
    p /= p.w;

    //Apply view
    Vector3 v;
    v.x = (Float)viewX + (0.5f * p.x + 0.5f) * (Float)viewW;
    v.y = (Float)viewY + (0.5f * p.y + 0.5f) * (Float)viewH;
    v.z = 1.0f - (0.5f * p.z + 0.5f);

    //Find projected bounds
    if (c==0) bboxOut.min = bboxOut.max = v;
    else {

      if (v.x < bboxOut.min.x) bboxOut.min.x = v.x;
      if (v.y < bboxOut.min.y) bboxOut.min.y = v.y;
      if (v.z < bboxOut.min.z) bboxOut.min.z = v.z;

      if (v.x > bboxOut.max.x) bboxOut.max.x = v.x;
      if (v.y > bboxOut.max.y) bboxOut.max.y = v.y;
      if (v.z > bboxOut.max.z) bboxOut.max.z = v.z;
    }
  }

  return bboxOut;
}
示例#4
0
int lua_BoundingBox_getCorners(lua_State* state)
{
    // Get the number of parameters.
    int paramCount = lua_gettop(state);

    // Attempt to match the parameters to a valid binding.
    switch (paramCount)
    {
        case 2:
        {
            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
                (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
            {
                // Get parameter 1 off the stack.
                bool param1Valid;
                gameplay::ScriptUtil::LuaArray<Vector3> param1 = gameplay::ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", false, &param1Valid);
                if (!param1Valid)
                {
                    lua_pushstring(state, "Failed to convert parameter 1 to type 'Vector3'.");
                    lua_error(state);
                }

                BoundingBox* instance = getInstance(state);
                instance->getCorners(param1);
                
                return 0;
            }

            lua_pushstring(state, "lua_BoundingBox_getCorners - Failed to match the given parameters to a valid function signature.");
            lua_error(state);
            break;
        }
        default:
        {
            lua_pushstring(state, "Invalid number of parameters (expected 2).");
            lua_error(state);
            break;
        }
    }
    return 0;
}