Esempio n. 1
0
int main(void)
{
	myEngine::Timing::Clock *clock = myEngine::Timing::Clock::createAndStart();
	int temp = LoadScene(LOAD_FILE);
	Point3 cameraRight = (camera.dir ^ camera.up).GetNormalized();
	double aspectRatio = static_cast<double>(camera.imgWidth) / static_cast<double>(camera.imgHeight);
	float camera_l = 1 / (tan((camera.fov / 2) * (M_PI/ 180)));
	
	Point3 Sx = cameraRight;
	Point3 Sy = (-1.0f) * camera.up;
	
	Point3 pixel;
	Point3 k = camera.pos + camera_l* camera.dir;// -cameraRight + camera.up;

	HitInfo hitInfo;
	

	//Color24 hitPixelColor = { 255,255,255 };
	Color noHitPixelColor = { 0,0,0 };
	Color24* temp_image = renderImage.GetPixels();

	float* temp_zBuffer = renderImage.GetZBuffer();

	
	for (int i = 0;i < camera.imgHeight; i++)
	{
		//printf("%d\n",i);
		for (int j = 0; j < camera.imgWidth; j++)
		{
			hitInfo.Init();
			float flipped_i = camera.imgHeight - i - 1;
			pixel = k + (((2.0f*aspectRatio * (j + 0.5f)) / camera.imgWidth) - aspectRatio)*Sx + ((((flipped_i + 0.5) * 2) / camera.imgHeight) - 1)* Sy;
			pixelRay.p = camera.pos;
			pixelRay.dir = (pixel - camera.pos).GetNormalized();
			
			if (TraceRay(&rootNode, pixelRay, hitInfo))
			{
#ifdef  RELEASE_DEBUG
				temp_image[i*camera.imgWidth + j] = normalColor(hitInfo);
#else
				temp_image[i*camera.imgWidth + j] = hitInfo.node->GetMaterial()->Shade(pixelRay, hitInfo, lights, 7);
#endif
				temp_zBuffer[i*camera.imgWidth + j] = hitInfo.z;
			}
			else
			{

				temp_image[i*camera.imgWidth + j] = noHitPixelColor;
				temp_zBuffer[i*camera.imgWidth + j] = hitInfo.z;
			}
		}
	}

	renderImage.SaveImage("RayCasted.ppm");
	renderImage.ComputeZBufferImage();
	renderImage.SaveZImage("RayCastWithZ.ppm");
	
	clock->updateDeltaTime();
	double time = clock->getdeltaTime();
	printf("Time to render ray casting  %f", clock->getdeltaTime());
	printf("Time to render zBuffer Image  %f", clock->getdeltaTime());

	ShowViewport();
	
}
Esempio n. 2
0
//---------------------------------------------------------------------------
// DummyWndProc
//
// This is the window proc for the "dummy" run-time window, which remains
// iconic at all times.
//
// RETURNS:     Per windows convention
//---------------------------------------------------------------------------
LONG  APIENTRY DummyWndProc (HWND hwnd, WORD msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
        {
        case WM_CREATE:
            {
            HMENU   hSysMenu;

            hSysMenu = GetSystemMenu (hwnd, 0);
            AppendMenu (hSysMenu, MF_SEPARATOR, 0, NULL);
            AppendMenu (hSysMenu, MF_STRING, IDM_WINDOWSHOW, "Show &Viewport");
            EnableMenuItem (hSysMenu, SC_RESTORE, MF_GRAYED);
            EnableMenuItem (hSysMenu, SC_MAXIMIZE, MF_GRAYED);
            break;
            }

        case WM_INITMENU:
            {
            HMENU   hSysMenu;

            hSysMenu = GetSystemMenu (hwnd, 0);
            EnableMenuItem (hSysMenu, IDM_WINDOWSHOW,
                        IsWindowVisible (hwndViewPort)?MF_GRAYED:MF_ENABLED);

            break;
            }

        case WM_QUERYOPEN:
            return (FALSE);

        case WM_CLOSE:
        case WM_DESTROY:
            wParam = IDM_RUNBREAK;
            // fall through code below...

        case WM_COMMAND:
            if (wParam == IDM_RUNBREAK)
                {
                // This msg can be sent to us by testevnt when journalling
                // is interrupted by ctrl-esc
                //-----------------------------------------------------------
                BreakFlag = 1;
                SLEEPING = 0;
                }
            break;

        case WM_SYSCOMMAND:
            switch (wParam)
                {
                case IDM_WINDOWSHOW:
                    ShowViewport (hwndViewPort);
                    break;

                case IDM_RUNBREAK:
                case SC_CLOSE:
                    BreakFlag = 1;
                    SLEEPING = 0;
                    return (FALSE);

                case SC_RESTORE:
                case SC_MAXIMIZE:
                    return FALSE;
                }
            break;
        }
    return (DefWindowProc (hwnd, msg, wParam, lParam));
}
Esempio n. 3
0
void showDefault()
{
	ShowViewport();
}