Beispiel #1
0
void		CEngine::s_plat_render_world()
{
	NxPs2::RenderPrologue();	 	// should this be in test_render_start_frame? (Garrett: Answer is no, it won't work)
	NxPs2::RenderInitImmediateMode();


//#define NUM_TRIS 1851
////	float	xyz[(NUM_TRIS+2)*3];
//	float	sn[NUM_TRIS*4];
//	uint16	list[NUM_TRIS*3];
//	float	vec[3] = { 1.0f, 1.5f, 2.0f };
//
//	for ( int lp = 0; lp < NUM_TRIS; lp++ )
//	{
//		sn[(lp*4)+0] = 6.0f;
//		sn[(lp*4)+1] = 7.0f;
//		sn[(lp*4)+2] = 8.0f;
//
////		xyz[(lp*3)+0] = ((float)(lp/2));
////		xyz[(lp*3)+1] = ((float)(lp&1));
////		xyz[(lp*3)+2] = 0.0f;
//
//		list[(lp*3)+0] = ( lp + 0 ) * 12;
//		list[(lp*3)+1] = ( lp + 1 ) * 12;
//		list[(lp*3)+2] = ( lp + 2 ) * 12;
//	}
//
//	Tmr::CPUCycles cycles = Tmr::GetTimeInCPUCycles();
//	shadow_test( sn, list, NUM_TRIS, vec );
//	cycles = Tmr::GetTimeInCPUCycles() - cycles;
//	printf( "CPU Cycles for shadow test: %d\n", cycles );

	#if 0
	// (Mike) see if there are any viewports to render, and return if there aren't
	// (Mike) ...perhaps make this trivial by having a CViewportManager::sGetNumActiveCameras() ?
	bool no_viewports = true;
	for (int view_idx = 0; view_idx < CViewportManager::sGetNumActiveViewports(); view_idx++)
	{
		if (CViewportManager::sGetActiveViewport(view_idx)->GetCamera())
		{
			no_viewports = false;
			break;
		}
	}
	if (no_viewports)
	{
		return;
	}
	// (Mike) now we know there's something to render...
	#endif


/*
	#if 1
	// normal 4:3 TV	
	float view_angle = 72.0f;   			// The angle prepended by the width of the screen
	float screen_aspect = 4.0f/3.0f;		// physical ration of width to height on the screen	(4:3 or 16:9)
	#else 
	// anamorphic widescreen
	float view_angle = 80.0f;   			// The angle prepended by the width of the screen
	float screen_aspect = 16.0f/9.0f;	// physical ratio of width to height on the screen	(4:3 or 16:9)
	#endif
*/
//	CViewportManager::sSetScreenMode(vSPLIT_V);
	
	

	bool got_vu0 = NxPs2::OccludeUseVU0();
	Dbg_Assert(got_vu0);
	
	// Note: this method of setting up the camera must change
	// so that the p_nx module does not reference things higher up the hierarchy
	for (int view_idx = 0; view_idx < CViewportManager::sGetNumActiveViewports(); view_idx++)
	{
		Gfx::Camera *cur_camera;
		CViewport *p_cur_viewport = CViewportManager::sGetActiveViewport(view_idx);
		
		Dbg_MsgAssert(p_cur_viewport,("Unable to get viewport %d",view_idx));
		cur_camera = p_cur_viewport->GetCamera();
		
		if (cur_camera)
		{
			
			// Build the occluders first now that we know where the camera is for this frame.
			NxPs2::BuildOccluders( &( cur_camera->GetPos()));

			// Make camera matrix
			Mth::Matrix cam_matrix(cur_camera->GetMatrix());
			cam_matrix[W] = cur_camera->GetPos();

			// Garrett: For some reason, only these clipping values work
			NxPs2::RenderViewport(view_idx, cam_matrix, p_cur_viewport->GetRect(), cur_camera->GetAdjustedHFOV(), p_cur_viewport->GetAspectRatio(),
								  /*-cur_camera->GetNearClipPlane(), -cur_camera->GetFarClipPlane()*/ -1.0f, -100000.0f, s_render_mode > 1);
#	ifdef __USE_PROFILER__
			Sys::CPUProfiler->PushContext( 0, 0, 255 );	 	// Blue (Under Yellow) = Immediate mode rnedering
#	endif // __USE_PROFILER__

			// Draw the immediate mode stuff
			NxPs2::RenderSwitchImmediateMode();
			NxPs2::CImmediateMode::sViewportInit();

// Mick: Moved this here from test_render_end_frame
			NxPs2::Reallocate2DVRAM();

			if (NxPs2::FlipCopyEnabled()) // TT 13470, 13471, 11061 Particle systems displayed when screen is blank
			{
			
				Nx::render_particles();
				mp_particle_manager->RenderParticles();
	
				// Render Weather effects.
				mp_weather->Process( Tmr::FrameLength() );
				mp_weather->Render();
	
				//Nx::CTextured3dPoly::sRenderAll();
				TextureSplatRender();
				ShatterRender();			// Make sure this is always the last immediate draw since it switches DMA lists
			}
						
			NxPs2::RenderSwitchImmediateMode();

#	ifdef __USE_PROFILER__
			Sys::CPUProfiler->PopContext(  );	 
#	endif // __USE_PROFILER__

			if (s_render_mode)
			{
#ifdef __NOPT_ASSERT__
				for (int i = 0; i < MAX_LOADED_SCENES; i++)
				{
					if (sp_loaded_scenes[i])
					{
						sp_loaded_scenes[i]->DebugRenderCollision(s_debug_ignore_1, s_debug_ignore_0);
					}
				}
#endif

				const Lst::Head<Obj::CObject>& composite_obj_list = Nx::CEngine::sGetMovableObjects();
				Lst::Node<Obj::CObject>* p_composite_node = composite_obj_list.GetNext();
				while( p_composite_node )
				{
					Obj::CCompositeObject* p_composite_object = static_cast<Obj::CCompositeObject*>(p_composite_node->GetData());
					Dbg_MsgAssert(p_composite_object, ("Node in CObject list wasn't a CCompositeObject"));

					Obj::CCollisionComponent* p_collision_component = GetCollisionComponentFromObject( p_composite_object );
					if ( p_collision_component )
					{
						CCollObj* p_coll_obj = p_collision_component->GetCollision();
						if (p_coll_obj)
						{
							p_coll_obj->DebugRender( s_debug_ignore_1, s_debug_ignore_0 );
						}
					}

					p_composite_node = p_composite_node->GetNext();
				}
			}	
		}
		else
		{
			//printf ("RENDERING FRAME WITH NO CAMERA (Nothing rendered)\n");
		}
		
		// Screen flash rendering.
		Nx::ScreenFlashRender( view_idx, 0 );
	}

	//NxPs2::RenderEpilogueStart();
	
	if (got_vu0)
	{
		NxPs2::OccludeDisableVU0();
	}
}
Beispiel #2
0
Camera::Camera(CAMERAMODE mode, int fps):_mode(mode), _fps(fps){
    /// By default we only care from 30cm to 1.5m
    _zNear = 300 /*mm*/;
    _zFar = 1500 /*mm*/;

    switch(_mode){
        case VGA:
            _width = 640;
            _height = 480;
            _focal_length_x = 525.5;
            _focal_length_y = 525.5;
            break;
        case QVGA:
            _width = 320;
            _height = 240;
            _focal_length_x = 287.26;
            _focal_length_y = 287.26;
            //_zFar = 800;
            _zFar = 1000;
            break;
        case Tompson:
            _width = 640;
            _height = 480;
#ifdef FIX_CALIB_PARS
            // _focal_length_x = 557.5;
            //_focal_length_y = 557.5;
#else
            _focal_length_x = 588.036865;
            _focal_length_y = 587.075073;
#endif
            break;
        case Tang: ///< same camera as Chen?
        case Chen:
            _width = 320;
            _height = 240;
            _focal_length_x = 241.42;
            _focal_length_y = 241.42;
            _zNear = 150;
            _zFar = 600;
        case Intel:
           _width = 320;
           _height = 240;
           _focal_length_x = 224.502;
           _focal_length_y = 230.494;
           _zFar = 500;
           _zNear = 100;
            break;
        break;
        default:
            printf("!!!FATAL: Invalid Camera");
            exit(0);
    }

    ///--- Assemble projection matrix
    auto kinectproj = [=]() {
        Matrix33f cam_matrix = Matrix33f::Zero();
        cam_matrix (0, 0) = _focal_length_x; /// FocalLength X
        cam_matrix (1, 1) = _focal_length_y; /// FocalLength Y
        cam_matrix (0, 2) = _width / 2;      /// CameraCenter X
        cam_matrix (1, 2) = _height / 2;     /// CameraCenter Y
        cam_matrix (2, 2) = 1.0;
        return cam_matrix;
    };
    proj = kinectproj();
    iproj = proj.inverse();
    // cout << "Camera::proj" << endl << proj  << endl;
    // cout << "Camera::iproj" << endl << iproj << endl;
}