Esempio n. 1
0
void WindowGadget::onRender( RenderContext & context, const RectInt & window )
{
	GameDocument * pDoc = (GameDocument *)document();
	if ( pDoc != NULL && pDoc->gadgetTarget() != NULL )
	{
		NounGadget * pTarget = pDoc->gadgetTarget();

		// get the hull of the object
		float scale = 1.0f / pTarget->hull().radius();
		// calculate the view direction from the players ship
		Vector3 view( cos(m_ActiveTime),-1,sin(m_ActiveTime) );
		view.normalize();
		
		Matrix33 cameraFrame( view );
		cameraFrame = cameraFrame * pTarget->frame();
		Vector3 cameraPosition( view * 4.0f );

		// end previous scene
		context.endScene();

		RenderContext::SaveState state( context );
		// set up new render context
		context.setPosition( cameraPosition );
		context.setFrame( cameraFrame );
		context.setWindow( window );
		context.setTime( pDoc->tick() * TICK_DURATION_S );

		DisplayDevice * pDisplay = context.display();
		ASSERT( pDisplay );

		// increase the ambient light so that the object is clearly visible
		pDisplay->setAmbient( WHITE );
		// remove all lights from the render device
		pDisplay->clearLights();

		// disable lights
		NodeLight::sm_bDisable = true;
		NodeSound::sm_bDisable = true;
		NounGadget::sm_bRenderGadgets = true;

		// render the target object
		pTarget->render( context, Matrix33::IDENTITY, Vector3::ZERO );

		// enable lights
		NodeLight::sm_bDisable = false;
		NodeSound::sm_bDisable = false;
		NounGadget::sm_bRenderGadgets = false;

		context.endScene();

		// restore the ambient light
		pDisplay->setAmbient( UNIVERSE_AMBIENT );
	}
}
Esempio n. 2
0
void cam_process(Cam_Info *cinfo){
    V4lCam *cam=(V4lCam*)(cinfo->V4LCam);
    Mat *dsc=(Mat*)(cinfo->Mat);
    Mat mat;
    Mat cameraFrame(cam->imgSize().height,cam->imgSize().width,CV_8UC2,cam->getFrameData()->start);
    if(cameraFrame.empty()){
        printf("Cam read Error\n");
    }

    cvtColor(cameraFrame,*dsc,CV_YUV2BGR_YUYV);

   // imshow("cam",*dsc);
    //cinfo->Mat=new Mat(mat);

}
Esempio n. 3
0
void ViewEngineering::onRender( RenderContext & context, const RectInt & window )
{
	GameDocument * pDoc = (GameDocument *)document();
	if ( pDoc == NULL )
		return;

	UniverseContext * pContext = pDoc->context();
	ASSERT( pContext );
	NounShip * pShip = pDoc->ship();
	ASSERT( pShip );

	// get the time elapsed
	float t = context.elapsed();
	// calculate the distance from the ship based upon it's radius
	float cameraDistance = pShip->radius() * 2.5f;
	// calculate the camera frame and position
	Matrix33 cameraFrame( pShip->frame() );
	cameraFrame.rotate( PI / 4, ViewGame::s_CameraTime * (PI / 4), 0 );
	Vector3	cameraPosition( pShip->worldPosition() - (cameraFrame.k * cameraDistance) );

	if ( ViewGame::s_CameraTime < CAMERA_SNAP_TIME )
	{
		// if ship is moving, keep it from jumping around while the camera is animating
		if ( m_Adjust )
		{
			Vector3 position( pShip->worldPosition() );
			Vector3 adjust( position - m_AdjustPosition );
			m_AdjustPosition = position;

			ViewGame::s_CameraPosition += adjust;
		}
		else
		{
			m_AdjustPosition = pShip->worldPosition();
			m_Adjust = true;
		}

		float d = ViewGame::s_CameraTime / CAMERA_SNAP_TIME;
		// move the camera
		Vector3 deltaPosition( cameraPosition - ViewGame::s_CameraPosition );
		ViewGame::s_CameraPosition += deltaPosition * d;

		// update the camera frame
		ViewGame::s_CameraFrame.i += (cameraFrame.i - ViewGame::s_CameraFrame.i) * d;
		ViewGame::s_CameraFrame.j += (cameraFrame.j - ViewGame::s_CameraFrame.j) * d;
		ViewGame::s_CameraFrame.k += (cameraFrame.k - ViewGame::s_CameraFrame.k) * d;
		ViewGame::s_CameraFrame.orthoNormalizeXY();
	}
	else
	{
		// animation is over, snap directly to the desired frame/position
		ViewGame::s_CameraFrame = cameraFrame;
		ViewGame::s_CameraPosition = cameraPosition;
		m_Adjust = false;
	}

	m_UpdateStatus += t;
	if ( m_UpdateStatus > 1.0f )
	{
		m_UpdateStatus = 0.0f;

		// update the ship status
		String shipStatus;
		shipStatus += String().format("Hull:<X;75;Color;ff00ffff>%d%%</Color>\n", int(pShip->damageRatioInv() * 100) );
		shipStatus += String().format("Energy:<X;75;Color;ff00ffff>%d / %d</Color>\n", pShip->energy(), pShip->maxEnergy() );
		shipStatus += String().format("Velocity:<X;75;Color;ff00ffff>%.1f / %.1f</Color>\n", pShip->velocity(), pShip->maxVelocity() );
		shipStatus += String().format("Signature:<X;75;Color;ff00ffff>%.1f</Color>\n", pShip->signature() );

		shipStatus += "\nSYSTEMS:\n";

		// display armor status
		for(int i=0;i<pShip->childCount();i++)
			if ( WidgetCast<GadgetArmor>( pShip->child(i) ) )
			{
				GadgetArmor * pArmor = (GadgetArmor *)pShip->child(i);
				shipStatus += String().format("%s<X;100>%d%%\n", 
					pArmor->nounContext()->name(), 
					(pArmor->armor() * 100 ) / pArmor->strength() );
			}
		// display shield status
		for(i=0;i<pShip->childCount();i++)
			if ( WidgetCast<GadgetShield>( pShip->child(i) ) )
			{
				GadgetShield * pShield = (GadgetShield *)pShip->child(i);
				shipStatus += String().format("%s<X;100>%d%%\n", 
					pShield->nounContext()->name(), 
					(pShield->charge() * 100 ) / pShield->maxCharge() );
			}

		for(i=0;i<pShip->childCount();i++)
			if ( WidgetCast<NounGadget>( pShip->child(i) ) )
			{
				NounGadget * pGadget = (NounGadget *)pShip->child(i);
				if ( WidgetCast<GadgetArmor>( pGadget ) )
					continue;
				if ( WidgetCast<GadgetShield>( pGadget ) )
					continue;
				
				shipStatus += String().format("%s<X;100>%d%%\n", 
					pGadget->nounContext()->name(), 
					int( pGadget->damageRatioInv() * 100 ) );
			}

		m_pShipStatus->setText( shipStatus );
	}
	
	if ( m_pLayoutRepair->visible() )
	{
		for(int i=0;i<pShip->repairCount();i++)
			GetButton<ButtonGadget>( m_pRepairQueue, i )->setGadget( pShip->repair( i ) );

		// remove excess buttons
		m_pRepairQueue->cullChildren( pShip->repairCount() );
	}

	//----------------------------------------------------------------------------

	// update the active zone
	pContext->setActiveZone( ViewGame::s_CameraPosition );

	// create our render context
	RenderContext engineeringContext( context );
	engineeringContext.setPosition( ViewGame::s_CameraPosition );
	engineeringContext.setFrame(  ViewGame::s_CameraFrame );
	engineeringContext.setTime( pContext->tick() * TICK_DURATION_S );

	//----------------------------------------------------------------------------

	// render the universe
	pContext->render( engineeringContext, 
		~ViewGame::s_CameraFrame, ViewGame::s_CameraFrame * (-ViewGame::s_CameraPosition) );
}