예제 #1
0
EntityVector GraphicsWorld::VisibleEntities() const
{
    EntityVector ret;

    for (HashSet<EntityWeakPtr>::ConstIterator i = visibleEntities_.Begin(); i != visibleEntities_.End(); ++i)
    {
        if (*i)
            ret.Push(i->Lock());
    }

    return ret;
}
예제 #2
0
EntityVector Placeable::Grandchildren(Entity *entity) const
{
    EntityVector ret;
    if (!entity)
        return ret;
    if (!entity->Component<Placeable>())
        return ret;
    EntityVector children = entity->Component<Placeable>()->Children();

    foreach(const EntityPtr &e, children)
    {
        EntityVector grandchildren = Grandchildren(e.Get());
        ret.Push(grandchildren);
    }
예제 #3
0
EntityVector GraphicsWorld::FrustumQuery(const Urho3D::IntRect &viewrect) const
{
    URHO3D_PROFILE(GraphicsWorld_FrustumQuery);
    
    EntityVector ret;
    Camera* cameraComp = renderer_->MainCameraComponent();
    if (!cameraComp || cameraComp->ParentScene() != scene_)
        return ret;
     Urho3D::Camera* cam = cameraComp->UrhoCamera();
     if (!cam)
        return ret;

    int width = renderer_->WindowWidth();
    int height = renderer_->WindowHeight();
    float w = (float)width;
    float h = (float)height;
    float left = (float)(viewrect.left_) / w, right = (float)(viewrect.right_) / w;
    float top = (float)(viewrect.top_) / h, bottom = (float)(viewrect.bottom_) / h;
    if (left > right) std::swap(left, right);
    if (top > bottom) std::swap(top, bottom);
    // don't do selection if box is too small
    if ((right - left) * (bottom - top) < 0.0001)
        return ret;

    Urho3D::Frustum fr;
    fr.vertices_[0] = cam->ScreenToWorldPoint(Urho3D::Vector3(right, top, cam->GetNearClip()));
    fr.vertices_[1] = cam->ScreenToWorldPoint(Urho3D::Vector3(right, bottom, cam->GetNearClip()));
    fr.vertices_[2] = cam->ScreenToWorldPoint(Urho3D::Vector3(left, bottom, cam->GetNearClip()));
    fr.vertices_[3] = cam->ScreenToWorldPoint(Urho3D::Vector3(left, top, cam->GetNearClip()));
    fr.vertices_[4] = cam->ScreenToWorldPoint(Urho3D::Vector3(right, top, cam->GetFarClip()));
    fr.vertices_[5] = cam->ScreenToWorldPoint(Urho3D::Vector3(right, bottom, cam->GetFarClip()));
    fr.vertices_[6] = cam->ScreenToWorldPoint(Urho3D::Vector3(left, bottom, cam->GetFarClip()));
    fr.vertices_[7] = cam->ScreenToWorldPoint(Urho3D::Vector3(left, top, cam->GetFarClip()));
    fr.UpdatePlanes();

    Urho3D::PODVector<Urho3D::Drawable*> result;
    Urho3D::FrustumOctreeQuery query(result, fr, Urho3D::DRAWABLE_GEOMETRY);
    urhoScene_->GetComponent<Urho3D::Octree>()->GetDrawables(query);

    for (Urho3D::PODVector<Urho3D::Drawable*>::ConstIterator i = result.Begin(); i != result.End(); ++i)
    {
        Entity* entity = static_cast<Entity*>((*i)->GetNode()->GetVar(entityLink).GetPtr());
        if (entity)
            ret.Push(EntityPtr(entity));
    }

    return ret;
}