Beispiel #1
0
// PointLight Method Definitions
Spectrum PointLight::Sample_Li(const Interaction &ref, const Point2f &u,
                               Vector3f *wi, Float *pdf,
                               VisibilityTester *vis) const {
    ProfilePhase _(Prof::LightSample);
    *wi = Normalize(pLight - ref.p);
    *pdf = 1.f;
    *vis =
        VisibilityTester(ref, Interaction(pLight, ref.time, mediumInterface));
    return I / DistanceSquared(pLight, ref.p);
}
Beispiel #2
0
void MHInteractible::InteractSetInteractionStatus(bool newStatus, MHEngine *engine)
{
    if (newStatus)   // Turning interaction on.
    {
        if (engine->GetInteraction() == 0) // No current interactible
        {
            Interaction(engine);    // virtual function
        }
    }
    else   // Turning interaction off.
    {
        if (m_fInteractionStatus)
        {
            m_fInteractionStatus = false;
            engine->SetInteraction(0);
            InteractionCompleted(engine); // Interaction is interrupted.
            engine->EventTriggered(m_parent, EventInteractionCompleted);
        }
    }
}
Beispiel #3
0
Spectrum InfiniteAreaLight::Sample_L(const Interaction &ref,
                                     const Point2f &lightSample, Vector3f *wi,
                                     Float *pdf, VisibilityTester *vis) const {
    // Find $(u,v)$ sample coordinates in infinite light texture
    Float mapPdf;
    Point2f uv = distribution->SampleContinuous(lightSample, &mapPdf);
    if (mapPdf == 0.f) return Spectrum(0.f);

    // Convert infinite light sample point to direction
    Float theta = uv[1] * Pi, phi = uv[0] * 2.f * Pi;
    Float costheta = std::cos(theta), sintheta = std::sin(theta);
    Float sinphi = std::sin(phi), cosphi = std::cos(phi);
    *wi =
        LightToWorld(Vector3f(sintheta * cosphi, sintheta * sinphi, costheta));

    // Compute PDF for sampled infinite light direction
    *pdf = mapPdf / (2.f * Pi * Pi * sintheta);
    if (sintheta == 0.f) *pdf = 0.f;

    // Return radiance value for infinite light direction
    *vis = VisibilityTester(
        ref, Interaction(ref.p + *wi * (2 * worldRadius), ref.time, medium));
    return Spectrum(Lmap->Lookup(uv), SpectrumType::Illuminant);
}
Beispiel #4
0
Interaction Curve::Sample(const Point2f &u) const {
    Severe("Curve::Sample not implemented.");
    return Interaction();
}
void SystemeMotivationnel::add(Experience e, Resultat r, int m)
{
    m_systeme[qMakePair(e,r)] = Interaction(Experience(e), Resultat(r),m);
}
//---------------------------------------------------------------------------
void __fastcall TFormSoaSimMain::TimerInteractionTimer(TObject *Sender)
{
    //Detect new couples
    const int personWidth  = ImagePersonRed->Picture->Graphic->Width;
    bool doRetry = true;

    while(doRetry == true)
    {
        doRetry = false;

        for (std::list<boost::shared_ptr<Person > >::iterator personA = mPersons.begin();
                personA!=mPersons.end();
                ++personA)
        {
            std::list<boost::shared_ptr<Person > >::iterator personB = personA;
            for ( ++personB;
                    personB!=mPersons.end();
                    ++personB)
            {
                if (GetDistance( (*personA)->x - (*personB)->x, (*personA)->y - (*personB)->y )
                        < static_cast<double>(personWidth) )
                {
                    //An interaction!
                    mInteractions.push_back(Interaction( *personA, *personB ));
                    //Remove this couple from the list
                    mPersons.erase(personA);
                    mPersons.erase(personB);
                    //The lists are messed up, so try again
                    doRetry = true;
                }
                if (doRetry == true) break;
            }
            if (doRetry == true) break;
        }
    }

    //Remove couples that ended their interaction
    {
        for (std::list<Interaction>::iterator i = mInteractions.begin();
                i!=mInteractions.end();
                ++i)
        {
            if ((*i).mInteraction == Interaction::aAndBleave)
            {
                (*i).mA->direction -= M_PI;
                (*i).mB->direction += M_PI;
                //Swap them for fun...
                mPersons.push_back( (*i).mB );
                mPersons.push_back( (*i).mA );
                std::list<Interaction>::iterator newI = i;
                --newI;
                mInteractions.erase(i);
                i = newI;
            }
        }
    }

    //Do their interactions
    {
        for (std::list<Interaction>::iterator i = mInteractions.begin();
                i!=mInteractions.end();
                ++i)
        {
            assert((*i).mInteraction != Interaction::aAndBleave);
            (*i).DoInteraction();
        }
    }
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int cnt;
    static HDC hdc,hdcMem;
    static PAINTSTRUCT ps;
    static RECT rect;
    static HBRUSH hBrush;
    static HBITMAP hbmMem;

    static HANDLE hOld;

    static int timerSpeed = 1,nrObj = 0;
    static RECT area = {0, 0, 800, 600};

    switch (message)
    {
        case WM_CREATE:
        {
          hdc = GetDC(hwnd);
          GetClientRect(hwnd,&rect);

          SetTimer(hwnd, ID_TIMER, timerSpeed, NULL);
        break;
        }

        case WM_SIZE:
        {
            hdc = GetDC(hwnd);
            GetClientRect(hwnd, &rect);
        break;
        }

        case WM_LBUTTONDOWN:
        {
            POINT coord;
            coord.x = LOWORD(lParam);
            coord.y = HIWORD(lParam);
            cnt=0;
            if (nrObj>0)
            {
                for(int i = 0; i<nrObj; i++)
                {
                    if(abs(coord.x-objs[i]->center.x)<52)
                    {
                        cnt+=1;
                    }
                }
                if(cnt==0)
                {
                    objs[nrObj] = new Circle(coord,2 + coord.x%5);
                    objs[nrObj] -> Color(RGB(coord.x%200, coord.x%150+coord.y%100, coord.y%200));

                    nrObj++;
                }
            }
            else
            {
                objs[nrObj] = new Circle(coord,2 + coord.x%5);
                objs[nrObj] -> Color(RGB(coord.x%200, coord.x%150+coord.y%100, coord.y%200));

                nrObj++;
            }
        break;
        }

         case WM_KEYDOWN:
         {
            switch(wParam)
            {
                case VK_DOWN:
                {
                    timerSpeed+=10;
                break;
                }

                case VK_UP:
                {
                    timerSpeed-=10;

                        if (timerSpeed < 0)
                        {
                            timerSpeed = 1;
                        }
                 break;
                }

                default: return DefWindowProc (hwnd, message, wParam, lParam);
            break;
            }

            KillTimer(hwnd,ID_TIMER);
            SetTimer(hwnd,ID_TIMER,timerSpeed,NULL);
        break;
        }

        case WM_MOUSEWHEEL:
        {
            if((short)HIWORD(wParam)<0)
            {
                timerSpeed+=10;
            }
            else
            {
                timerSpeed-=10;
                if (timerSpeed<0)
                {
                    timerSpeed=1;
                }
            }
            KillTimer(hwnd,ID_TIMER);
            SetTimer(hwnd,ID_TIMER,timerSpeed,NULL);
        break;
        }

        case WM_PAINT:
        {
            hdc = BeginPaint(hwnd,&ps);
            GetClientRect(hwnd,&rect);

            hdcMem = CreateCompatibleDC(hdc);
            hbmMem = CreateCompatibleBitmap(hdc, rect.right, rect.bottom);
            hOld = SelectObject(hdcMem, hbmMem);

            for(int i = 0; i<nrObj-1; i++)
            {
                for(int j = i+1; j < nrObj; j++)
                {
                    Interaction(*objs[i],*objs[j]);
                }
            }

            FillRect(hdcMem, &rect,(HBRUSH)GetStockObject(WHITE_BRUSH));

            for(int i = 0; i < nrObj; i++)
            {
                objs[i] -> Move(hdcMem, rect, hBrush);
            }

            BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY);

            SelectObject(hdcMem,hOld);
            DeleteObject(hbmMem);
            DeleteDC(hdcMem);

            EndPaint(hwnd,&ps);

        break;
        }

        case WM_ERASEBKGND:
            return 1;
        break;

        case WM_TIMER:
        {
            InvalidateRect(hwnd,NULL,FALSE);
        break;
        }

        case WM_DESTROY:
        {
            KillTimer(hwnd,ID_TIMER);

            PostQuitMessage (0);
        break;
        }

        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}