예제 #1
0
//
// Draw The Scene
//
void DrawGLScene(GLvoid)				// Here's Where We Do All The Drawing
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
    glClearColor(0.0f, 0.0f, 0.3f, 0.0f);				// Black Background


    // begin scene ---
    BEGIN_BOT;

    RenderWalls();
    RenderPlane();

    SetLights();
    driver_objects[STARS_OBJECT]->render();

    Draw_Wall_List();

    DrawExplosions();

    DrawFireAnts();

    END_BOT;

    // Draw the multiple sets of Heads up displays
    Super_DrawText();

    Draw_Title();

    DrawHUD();

} // end of the function
예제 #2
0
void CVehicle::StoreEmptyVehicle(EMPTYVEHICLESYNCPACKET * syncPacket)
{
	// Check stuff
	if(syncPacket->bLights != GetLights())
		SetLights(syncPacket->bLights);

	if(syncPacket->bSirenState != GetSirenState())
		SetSirenState(syncPacket->bSirenState);

	if(syncPacket->bTaxiLights != GetTaxiLights())
		TurnTaxiLights(syncPacket->bTaxiLights);

	if(syncPacket->fDirtLevel != GetDirtLevel())
		SetDirtLevel(syncPacket->fDirtLevel);

	if(syncPacket->fPetrolHealth != GetPetrolTankHealth())
		SetPetrolTankHealth(syncPacket->fPetrolHealth);

	if(syncPacket->uiHealth != GetHealth())
		SetHealth(syncPacket->uiHealth);

	// Only when the vehicle stands still -> update stuff
	/*if(syncPacket->vecMoveSpeed.Length() == 0)
	{
		CVector3 vecPos; GetPosition(vecPos);
		if((vecPos-syncPacket->vecPosition).Length() > 5.0f || (vecPos-syncPacket->vecPosition).Length() < -5.0f)
			SetPosition(syncPacket->vecPosition);

		CVector3 vecRot; GetRotation(vecRot);
		if((vecRot-syncPacket->vecRotation).Length() > 5.0f || (vecRot-syncPacket->vecRotation).Length() < -5.0f)
			SetRotation(syncPacket->vecRotation);

		CVector3 vecTurnSpeed; GetTurnSpeed(vecTurnSpeed);
		if((vecTurnSpeed-syncPacket->vecTurnSpeed).Length() > 5.0f || (vecTurnSpeed-syncPacket->vecTurnSpeed).Length() < -5.0f)
			SetTurnSpeed(syncPacket->vecTurnSpeed);

		CVector3 vecMoveSpeed; GetMoveSpeed(vecMoveSpeed);
		if((vecMoveSpeed-syncPacket->vecMoveSpeed).Length() > 5.0f || (vecMoveSpeed-syncPacket->vecMoveSpeed).Length() < -5.0f)
			SetMoveSpeed(syncPacket->vecMoveSpeed);
	}*/

	/*for(unsigned int ui = 0; ui <= 3; ui++)
	{
		if(syncPacket->bWindow[ui] != m_bWindow[ui])
			SetWindowState(ui, syncPacket->bWindow[ui]);
	}

	for(unsigned int ui = 0; ui <= 5; ui++)
	{
		if(syncPacket->bTyre[ui] != m_bTyre[ui])
			SetTyreState(ui, syncPacket->bTyre[ui]);
	}*/
}
예제 #3
0
파일: SinyMain.cpp 프로젝트: SinYocto/Siny
/**
 * AppSetup()
 */
int AppSetup()
{
	SetGUIStyle();
	SetCamera();
	SetShaders();
	SetMaterials();
	SetTerrain();
	SetMeshes();
	SetLights();
	SetSky();
	scene.backgroundColor = 0xff1e90ff;

	return 1;
}
예제 #4
0
int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
	glLoadIdentity();									// Reset The View
	/******new motion variables****/
	xpos *= 0.8f;
	zpos *= 0.8f;
	xtrans2 += xpos/10;
	ztrans2 += zpos/10;
	// tu wczesniej byly deklaracje - czy to duza zmiana?
	xtrans = -xtrans2;
	ztrans = -ztrans2;
	zprot*=0.9;
	_heading += zprot;
	heading = mouse_xpos_cursor + _heading;
	yrot = heading;
	//ytrans = ytrans-walkbias-0.35f;
	GLfloat sceneroty = 360.0f - yrot;	
		
	glRotatef(lookupdown,1.0f,0,0);
	glRotated(mouse_ypos_cursor,1.0f,0,0);
	glRotatef(sceneroty,0,1.0f,0);		
	
	glTranslatef(xtrans,ytrans,ztrans);		
	
	SetLights();

	/****end of new variables****/
	DrawGLMap( current );

	glBegin(GL_TRIANGLES);
		glNormal3f( 0, 1, 0 );
		glVertex3f(x_light,y_light,z_light);
		glVertex3f(x_light,y_light,z_light-0.05f);
		glVertex3f( x_light, y_light-0.05f, z_light-0.05f);
	glEnd();
	
				// dzwieki ruchu gracza - w jakim miejscu?
				MovingCamera();
	//gluCylinder(quadratic,0.2f,0.2f,3.0f,32,32);	// Draw Our Cylinder

	return TRUE;										// Everything Went OK
}
예제 #5
0
파일: Traffic.c 프로젝트: EnergyMicro/RTX
/*----------------------------------------------------------------------------
  Thread 2 'blinking': runs if current time is outside start & end time 
 *---------------------------------------------------------------------------*/
void blinking (void const *argument) {        /* blink YELLOW light          */
  SetLights (RED, 0);                         /* all lights off              */
  SetLights (YELLOW, 0);
  SetLights (GREEN, 0);
  SetLights (STOP, 0);
  SetLights (WALK, 0);
  while (1) {                                 /* endless loop                */
    SetLights (YELLOW, 1);                    /* YELLOW light on             */
    osDelay(300);                             /* wait for timeout: 300ms     */
    SetLights (YELLOW, 0);                    /* YELLOW light off            */
    osDelay(300);                             /* wait for timeout: 300ms     */
    if (signalon ()) {                        /* if blinking time over       */
      tid_lights = osThreadCreate(osThread(lights), NULL);
                                              /* start lights                */
      return;                                 /* and STOP blinking           */
    }
  }
}
예제 #6
0
//
// Draw The Scene
//
void DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
	
	glClearColor(0.0f, 0.0f, 0.3f, 0.0f);				// Black Background


	//BEGIN_CAMERA			// setup viewing camera			
	BEGIN_BOT;

		//RenderGrid();	
		RenderWalls();
		RenderPlane();


#if ENABLE_LIGHTS
		SetLights();
#endif
		driver_objects[STARS_OBJECT]->render();

		Draw_Wall_List();

		DrawExplosions();	// draw fire explosions

		DrawFireAnts();		// the mother of all enemies

	//END_CAMERA				// end viewing camera
	END_BOT;


	// Draw the heads up display --
	Super_DrawText();

	Draw_Title();

	DrawHUD();


} // end of the function 
예제 #7
0
/* Initialize broad parameters for OpenGL */
void EDA_3D_CANVAS::InitGL()
{
    wxSize size = GetClientSize();

    if( !m_init )
    {
        m_init = true;
        g_Parm_3D_Visu.m_Zoom = 1.0;
        m_ZBottom = 1.0;
        m_ZTop = 10.0;

        glDisable( GL_CULL_FACE );      // show back faces

        glEnable( GL_DEPTH_TEST );      // Enable z-buferring

        glEnable( GL_LINE_SMOOTH );
        glEnable( GL_COLOR_MATERIAL );
        glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );

        /* speedups */
        glEnable( GL_DITHER );
        glShadeModel( GL_SMOOTH );
        glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE );
        glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
        glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );    // can be GL_FASTEST

        /* blend */
        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    }

    // set viewing projection

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

#define MAX_VIEW_ANGLE 160.0 / 45.0
    if( g_Parm_3D_Visu.m_Zoom > MAX_VIEW_ANGLE )
        g_Parm_3D_Visu.m_Zoom = MAX_VIEW_ANGLE;

     if( Parent()->ModeIsOrtho() )
     {
         // OrthoReductionFactor is chosen so as to provide roughly the same size as
         // Perspective View
         const double orthoReductionFactor = 400 / g_Parm_3D_Visu.m_Zoom;

         // Initialize Projection Matrix for Ortographic View
         glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor,
                  -size.y / orthoReductionFactor, size.y / orthoReductionFactor, 1, 10 );
     }
     else
     {
         // Ratio width / height of the window display
         double ratio_HV = (double) size.x / size.y;

         // Initialize Projection Matrix for Perspective View
         gluPerspective( 45.0 * g_Parm_3D_Visu.m_Zoom, ratio_HV, 1, 10 );
     }


    // position viewer
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    glTranslatef( 0.0F, 0.0F, -( m_ZBottom + m_ZTop) / 2 );

    // clear color and depth buffers
    glClearColor( g_Parm_3D_Visu.m_BgColor.m_Red,
                  g_Parm_3D_Visu.m_BgColor.m_Green,
                  g_Parm_3D_Visu.m_BgColor.m_Blue, 1 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // Setup light sources:
    SetLights();

    CheckGLError();
}
예제 #8
0
// Creates the scene geometry
bool SceneSetup()
{
	srand(time(NULL)); // used as part of tank evade, but only needs to be called once.

	//////////////////////////////////////////
	// Create scenery templates and entities

	// Create scenery templates - loads the meshes
	// Template type, template name, mesh name
	EntityManager.CreateTemplate( "Scenery", "Skybox", "Skybox.x" );
	EntityManager.CreateTemplate( "Scenery", "Floor", "Floor.x" );
	EntityManager.CreateTemplate( "Scenery", "Building", "Building.x" );
	EntityManager.CreateTemplate( "Scenery", "Tree", "Tree.x" );

	// Creates scenery entities
	// Type (template name), entity name, position, rotation, scale
	EntityManager.CreateEntity( "Skybox", "Skybox", CVector3(0.0f, -10000.0f, 0.0f), CVector3::kZero, CVector3( 10, 10, 10) );
	EntityManager.CreateEntity( "Floor", "Floor" );
	EntityManager.CreateEntity( "Building", "Building", CVector3(0.0f, 0.0f, 40.0f) );
	for (int tree = 0; tree < 100; ++tree)
	{
		EntityManager.CreateEntity( "Tree", "Tree", 
		                            CVector3(Random( -200.0f, 30.0f ), 0.0f, Random(40.0f, 150.0f) ), 
									CVector3(0.0f, Random(0.0f, 2.0f * kfPi), 0.0f ) );
	}


	
	
	/////////////////////////////////
	// Create tank templates

	
	// Template type, template name, mesh name, top speed, acceleration, tank turn speed, turret
	// turn speed, max HP and shell damage. These latter settings are for advanced requirements only
	EntityManager.CreateTankTemplate( "Tank", "Rogue Scout", "HoverTank02.x", 
	                                  24.0f, 2.2f, 2.0f, kfPi/3, 100, 20);
	EntityManager.CreateTankTemplate( "Tank", "Oberon MkII", "HoverTank07.x",
	                                  18.0f, 1.6f, 1.3f, kfPi/4, 120, 35);

	// Template for tank shell
	EntityManager.CreateTemplate( "Projectile", "Shell Type 1", "Bullet.x" );


	////////////////////////////////
	// Create tank entities

	//Create Patrol Routes
	CVector3 PushVector;
	PushVector.x = 0.0f;
	PushVector.y = 0.0f;
	PushVector.z = 0.0f;

	vector<CVector3> TankAPatrolRoute;
	PushVector.z = -80.0f;
	TankAPatrolRoute.push_back(PushVector);
	PushVector.z = 30.0f;
	TankAPatrolRoute.push_back(PushVector);
	PushVector.z = 0.0f;

	vector<CVector3> TankBPatrolRoute;
	PushVector.x = -50.0f;
	TankBPatrolRoute.push_back(PushVector);
	PushVector.x = 50.0f;
	TankBPatrolRoute.push_back(PushVector);
	PushVector.x = 0.0f;

	// Type (template name), team number, tank name, position, rotation
	TankA = EntityManager.CreateTank( "Rogue Scout", 0, TankAPatrolRoute, "A-1", CVector3(-30.0f, 0.5f, -20.0f),
	                                  CVector3(0.0f, ToRadians(0.0f), 0.0f) );
	TankVector.push_back(TankA);
	TankB = EntityManager.CreateTank( "Oberon MkII", 1, TankBPatrolRoute, "B-1", CVector3(30.0f, 0.5f, 20.0f),
	                                  CVector3(0.0f, ToRadians(180.0f), 0.0f) );
	TankVector.push_back(TankB);

	EntityManager.CreateTemplate("AmmoBox","AmmoBox","Cube.x");
	

	/////////////////////////////
	// Camera / light setup

	// Set camera position and clip planes
	MainCamera = new CCamera( CVector3( 0.0f, 30.0f, -100.0f ),
	                          CVector3(ToRadians(15.0f), 0, 0) );
	MainCamera->SetNearFarClip( 1.0f, 20000.0f ); 


	// Ambient light level
	AmbientLight = SColourRGBA( 0.6f, 0.6f, 0.6f, 1.0f );

	// Sunlight
	Lights[0] = new CLight( CVector3( -5000.0f, 4000.0f, -10000.0f),
	                        SColourRGBA(1.0f, 0.9f, 0.6f), 40000.0f );
	Lights[1] = new CLight( CVector3( 6.0f, 7.5f, 40.0f),
	                        SColourRGBA(1.0f, 0.0f, 0.0f), 1.0f );


	// Set light information for render methods
	SetAmbientLight( AmbientLight );
	SetLights( &Lights[0] );

	return true;
}
예제 #9
0
// Render everything in the scene
void CScene::RenderScene()
{
	// Clear the back buffer - before drawing the geometry clear the entire window to a fixed colour
	float ClearColor[4] = { 0.2f, 0.2f, 0.3f, 1.0f }; // Good idea to match background to ambient colour
	mpd3dDeviceContext->ClearRenderTargetView( RenderTargetView, ClearColor );
	mpd3dDeviceContext->ClearDepthStencilView( DepthStencilView, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL , 1.0f, 0 ); // Clear the depth buffer too


	// Pass the camera's matrices to the vertex shader
	ViewMatrixVar->SetMatrix( (float*)&Camera.GetViewMatrix() );
	ProjMatrixVar->SetMatrix( (float*)&Camera.GetProjectionMatrix() );

	//pass the camera position
	//V3 temp = XMF3ToFloat3( Camera->GetPosition() );
	//DirectX::XMFLOAT3 temp = Camera.GetPosition();
	dxCameraPos->SetRawValue( &Camera.GetPosition(), 0, 12);

	//pass the lighting colours
	//temp = XMF3ToFloat3( AmbientColour );
	dxAmbientColour->SetRawValue( &AmbientColour, 0, 12  );

	SetLights( DirectX::XMFLOAT3(0.0f, 0.0f, 0.0f), mpLights, miNumLights);

	//---------------------------
	// Render each model
	
	DrawAllObjects(false);

	mp_openSquares.RenderBatch(WorldMatrixVar, ModelColourVar);
	mp_walls.RenderBatch( WorldMatrixVar, ModelColourVar );
	mp_pathModel.RenderBatch(WorldMatrixVar, ModelColourVar);
	mp_splineModel.RenderBatch(WorldMatrixVar, ModelColourVar);
	mp_heavyTurretModel.RenderBatch(WorldMatrixVar, ModelColourVar);
	mp_mediumTurretModel.RenderBatch(WorldMatrixVar, ModelColourVar);
	mp_lightTurretModel.RenderBatch(WorldMatrixVar, ModelColourVar);

	mpSpriteBatch->Begin();
	//mpSpriteFont->DrawString( mpSpriteBatch, L"Hello, world!", DirectX::XMFLOAT2( 500.0f, 500.0f ) );

	FontRect.bottom = 0;
	FontRect.right = 0;

	if( mb_showBaseIM )
	{
		DisplayText( "Base Influence Map", 0);
		DisplayMapText(BASE_OFFSET);
	}

	if( mb_showBase2IM )
	{
		DisplayText( "Base 2 Influence Map", 0);
		DisplayMapText(BASE2_OFFSET);
	}

	if( mb_showCost )
	{
		DisplayText( "Square Cost", 0);
		DisplayMapText(COST_OFFSET);
	}

	if( mb_showHTIM )
	{
		DisplayText( "Heavy Turret Influence Map", 0 );
		DisplayMapText(HEAVY_OFFSET);
	}

	if( mb_showLTIM )
	{
		DisplayText( "Light Turret Influence Map", 0);
		DisplayMapText(LIGHT_OFFSET);
	}

	if( mb_showMTIM )
	{
		DisplayText( "Medium Turret Influence Map", 0);
		DisplayMapText(MEDIUM_OFFSET);
	}

	if( mb_showPathIM )
	{
		DisplayText( "Path Influence Map", 0 );
		DisplayMapText( PATH_OFFSET);
	}

	if( mb_showWallIM )
	{
		DisplayText( "Wall Influence Map", 0);
		DisplayMapText(WALL_OFFSET);
	}
	mpSpriteBatch->End();
	TwDraw();

	//---------------------------
	// Display the Scene

	// After we've finished drawing to the off-screen back buffer, we "present" it to the front buffer (the screen)
	SwapChain->Present( 0, 0 );
}
예제 #10
0
파일: Traffic.c 프로젝트: EnergyMicro/RTX
/*----------------------------------------------------------------------------
  Thread 3 'lights': executes if current time is between start & end time
 *---------------------------------------------------------------------------*/
void lights (void const *argument) {          /* traffic light operation     */
  SetLights (RED, 1);                         /* RED & STOP lights on        */
  SetLights (STOP, 1);
  SetLights (YELLOW, 0);
  SetLights (GREEN, 0);
  SetLights (WALK, 0);
  while (1) {                                 /* endless loop                */
    osDelay(500);                             /* wait for timeout: 500ms     */
    if (!signalon ()) {                       /* if traffic signal time over */
      tid_blinking = osThreadCreate(osThread(blinking), NULL);
                                              /* start blinking              */
      return;                                 /* STOP lights                 */
    }
    SetLights (YELLOW, 1);
    osDelay(500);                             /* wait for timeout: 500ms     */
    SetLights (RED, 0);                       /* GREEN light for cars        */
    SetLights (YELLOW, 0);
    SetLights (GREEN, 1);
    osSignalClear(tid_lights, 0x0010);
    osDelay(500);                             /* wait for timeout: 500ms     */
    osSignalWait(0x0010, 7500);               /* wait for event with timeout */
    SetLights (YELLOW, 1);                    /* timeout value: 7.5s         */
    SetLights (GREEN, 0);
    osDelay(500);                             /* wait for timeout: 500ms     */
    SetLights (RED, 1);                       /* RED light for cars          */
    SetLights (YELLOW, 0);
    osDelay(500);                             /* wait for timeout: 500ms     */
    SetLights (STOP, 0);                      /* GREEN light for WALKers     */    
    SetLights (WALK, 1);
    osDelay(2500);                            /* wait for timeout: 2.5s      */
    SetLights (STOP, 1);                      /* RED light for WALKers       */        
    SetLights (WALK, 0);
  }
}
예제 #11
0
NzLightManager::NzLightManager(const NzLight** lights, unsigned int lightCount)
{
	SetLights(lights, lightCount);
}
예제 #12
0
void EDA_3D_CANVAS::Redraw()
{
    // SwapBuffer requires the window to be shown before calling
    if( !IsShownOnScreen() )
        return;

    wxString err_messages;
    WX_STRING_REPORTER errorReporter( &err_messages );
    STATUS_TEXT_REPORTER activityReporter( Parent(), 0 );

    // Display build time at the end of build
    unsigned strtime = GetRunningMicroSecs();

    GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );

    // Set the OpenGL viewport according to the client size of this canvas.
    // This is done here rather than in a wxSizeEvent handler because our
    // OpenGL rendering context (and thus viewport setting) is used with
    // multiple canvases: If we updated the viewport in the wxSizeEvent
    // handler, changing the size of one canvas causes a viewport setting that
    // is wrong when next another canvas is repainted.
    wxSize size = GetClientSize();

    InitGL();

    if( isRealisticMode() && isEnabled( FL_RENDER_SHADOWS ) )
    {
        generateFakeShadowsTextures( &errorReporter, &activityReporter );
    }

    // *MUST* be called *after* GL_CONTEXT_MANAGER::LockCtx():
    glViewport( 0, 0, size.x, size.y );

    // clear color and depth buffers
    glClearColor( 0.95, 0.95, 1.0, 1.0 );
    glClearStencil( 0 );
    glClearDepth( 1.0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

    glShadeModel( GL_SMOOTH );

    // Draw background
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    glDisable( GL_LIGHTING );
    glDisable( GL_COLOR_MATERIAL );
    glDisable( GL_DEPTH_TEST );
    glDisable( GL_TEXTURE_2D );

    // Draw the background ( rectangle with color gradient)
    glBegin( GL_QUADS );
    SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 );
    glVertex2f( -1.0, 1.0 );    // Top left corner

    SetGLColor( GetPrm3DVisu().m_BgColor, 1.0 );
    glVertex2f( -1.0,-1.0 );    // bottom left corner
    glVertex2f( 1.0,-1.0 );     // bottom right corner

    SetGLColor( GetPrm3DVisu().m_BgColor_Top, 1.0 );
    glVertex2f( 1.0, 1.0 );     // top right corner

    glEnd();
    glEnable( GL_DEPTH_TEST );


    // set viewing projection
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

#define MAX_VIEW_ANGLE 160.0 / 45.0

    if( GetPrm3DVisu().m_Zoom > MAX_VIEW_ANGLE )
        GetPrm3DVisu().m_Zoom = MAX_VIEW_ANGLE;

     if( Parent()->ModeIsOrtho() )
     {
         // OrthoReductionFactor is chosen to provide roughly the same size as
         // Perspective View
         const double orthoReductionFactor = 400 / GetPrm3DVisu().m_Zoom;

         // Initialize Projection Matrix for Ortographic View
         glOrtho( -size.x / orthoReductionFactor, size.x / orthoReductionFactor,
                  -size.y / orthoReductionFactor, size.y / orthoReductionFactor, 1, 100 );
     }
     else
     {
         // Ratio width / height of the window display
         double ratio_HV = (double) size.x / size.y;

         // Initialize Projection Matrix for Perspective View
         gluPerspective( 45.0f * GetPrm3DVisu().m_Zoom, ratio_HV, 1, 100 );
     }

    // position viewer
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    glTranslatef( 0.0f, 0.0f, -(m_ZBottom + m_ZTop) / 2.0f );

    // Setup light sources:
    SetLights();

    CheckGLError( __FILE__, __LINE__ );

    glMatrixMode( GL_MODELVIEW );    // position viewer

    // transformations
    GLfloat mat[4][4];

    // Translate motion first, so rotations don't mess up the orientation...
    glTranslatef( m_draw3dOffset.x, m_draw3dOffset.y, 0.0F );

    build_rotmatrix( mat, GetPrm3DVisu().m_Quat );
    glMultMatrixf( &mat[0][0] );

    glRotatef( GetPrm3DVisu().m_Rot[0], 1.0, 0.0, 0.0 );
    glRotatef( GetPrm3DVisu().m_Rot[1], 0.0, 1.0, 0.0 );
    glRotatef( GetPrm3DVisu().m_Rot[2], 0.0, 0.0, 1.0 );


    if( ! m_glLists[GL_ID_BOARD] || ! m_glLists[GL_ID_TECH_LAYERS] )
        CreateDrawGL_List( &errorReporter, &activityReporter );

    if( isEnabled( FL_AXIS ) && m_glLists[GL_ID_AXIS] )
        glCallList( m_glLists[GL_ID_AXIS] );

    // move the board in order to draw it with its center at 0,0 3D coordinates
    glTranslatef( -GetPrm3DVisu().m_BoardPos.x * GetPrm3DVisu().m_BiuTo3Dunits,
                  -GetPrm3DVisu().m_BoardPos.y * GetPrm3DVisu().m_BiuTo3Dunits,
                  0.0f );

    if( isEnabled( FL_MODULE ) )
    {
        if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] )
            CreateDrawGL_List( &errorReporter, &activityReporter );
    }

    glEnable( GL_LIGHTING );

    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    if( isRealisticMode() && isEnabled( FL_RENDER_TEXTURES ) )
        glEnable( GL_TEXTURE_2D );
    else
        glDisable( GL_TEXTURE_2D );

    // Set material for the board
    glEnable( GL_COLOR_MATERIAL );
    SetOpenGlDefaultMaterial();

    //glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, FALSE );

    // Board Body

    GLint shininess_value = 32;
    glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value );

    if( isEnabled( FL_SHOW_BOARD_BODY ) )
    {
        if( m_glLists[GL_ID_BODY] )
        {
            glCallList( m_glLists[GL_ID_BODY] );
        }
    }


    // Board

    // specify material parameters for the lighting model.
    shininess_value = 52;
    glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value );

    glm::vec4 specular( GetPrm3DVisu().m_CopperColor.m_Red   * 0.20f,
                        GetPrm3DVisu().m_CopperColor.m_Green * 0.20f,
                        GetPrm3DVisu().m_CopperColor.m_Blue  * 0.20f, 1.0f );
    glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specular.x );

    if( m_glLists[GL_ID_BOARD] )
    {
        glCallList( m_glLists[GL_ID_BOARD] );
    }


    // Tech layers

    shininess_value = 32;
    glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shininess_value );

    glm::vec4 specularTech( 0.0f, 0.0f, 0.0f, 1.0f );
    glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, &specularTech.x );

    if( m_glLists[GL_ID_TECH_LAYERS] )
    {
        glCallList( m_glLists[GL_ID_TECH_LAYERS] );
    }

    if( isEnabled( FL_COMMENTS ) || isEnabled( FL_ECO )  )
    {
        if( ! m_glLists[GL_ID_AUX_LAYERS] )
            CreateDrawGL_List( &errorReporter, &activityReporter );

        glCallList( m_glLists[GL_ID_AUX_LAYERS] );
    }

    //glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, TRUE );

    // Draw Component Shadow

    if( isEnabled( FL_MODULE )  && isRealisticMode() &&
        isEnabled( FL_RENDER_SHADOWS ) )
    {
        glEnable( GL_CULL_FACE );
        glDisable( GL_DEPTH_TEST );

        glEnable( GL_COLOR_MATERIAL ) ;
        SetOpenGlDefaultMaterial();
        glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );

        glEnable( GL_TEXTURE_2D );

        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

        if( m_glLists[GL_ID_SHADOW_FRONT] )
        {
            glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_front );
            glCallList( m_glLists[GL_ID_SHADOW_FRONT] );
        }

        if( m_glLists[GL_ID_SHADOW_BACK] )
        {
            glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_back );
            glCallList( m_glLists[GL_ID_SHADOW_BACK] );
        }
        glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );

        glEnable( GL_DEPTH_TEST );
        glDisable( GL_TEXTURE_2D );
        glDisable( GL_CULL_FACE );
    }

    glEnable( GL_COLOR_MATERIAL );
    SetOpenGlDefaultMaterial();

    glDisable( GL_BLEND );


    // Draw Solid Shapes

    if( isEnabled( FL_MODULE ) )
    {
        if( ! m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] )
            CreateDrawGL_List( &errorReporter, &activityReporter );

        glCallList( m_glLists[GL_ID_3DSHAPES_SOLID_FRONT] );
    }

    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );


    // Grid uses transparency: draw it after all objects

    if( isEnabled( FL_GRID ) )
    {
        if( ! m_glLists[GL_ID_GRID] )
            CreateDrawGL_List( &errorReporter, &activityReporter );

        glCallList( m_glLists[GL_ID_GRID] );
    }


    // Draw Board Shadow

    if( isRealisticMode() && isEnabled( FL_RENDER_SHADOWS ) )
    {
        if( m_glLists[GL_ID_SHADOW_BOARD] )
        {
            glEnable( GL_BLEND );
            glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
            glColor4f( 1.0, 1.0, 1.0, 0.75f );
            glEnable( GL_CULL_FACE );
            glDisable( GL_COLOR_MATERIAL );
            glEnable( GL_TEXTURE_2D );
            glBindTexture( GL_TEXTURE_2D, m_text_fake_shadow_board );
            glCallList( m_glLists[GL_ID_SHADOW_BOARD] );
            glDisable( GL_CULL_FACE );
            glDisable( GL_TEXTURE_2D );
        }
    }

    // This list must be drawn last, because it contains the
    // transparent gl objects, which should be drawn after all
    // non transparent objects
    if(  isEnabled( FL_MODULE ) && m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] )
    {
        glEnable( GL_COLOR_MATERIAL );
        SetOpenGlDefaultMaterial();
        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        glCallList( m_glLists[GL_ID_3DSHAPES_TRANSP_FRONT] );
    }

    // Debug bounding boxes
    /*
    glDisable( GL_BLEND );
    glDisable( GL_COLOR_MATERIAL );
    glDisable( GL_LIGHTING );
    glColor4f( 1.0f, 0.0f, 1.0f, 1.0f );
    m_fastAABBox_Shadow.GLdebug();

    glColor4f( 0.0f, 1.0f, 1.0f, 1.0f );
    m_boardAABBox.GLdebug();
    */

    SwapBuffers();
    GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );

    // Show calculation time if some activity was reported
    if( activityReporter.HasMessage() )
    {
        // Calculation time in seconds
        double calculation_time = (double)( GetRunningMicroSecs() - strtime) / 1e6;

        activityReporter.Report( wxString::Format( _( "Build time %.3f s" ),
                                 calculation_time ) );
    }
    else
        activityReporter.Report( wxEmptyString );

    if( !err_messages.IsEmpty() )
        wxLogMessage( err_messages );

}
예제 #13
0
LightManager::LightManager()
{
	InitPositions();
	SetLights();
}
예제 #14
0
void
GlfSimpleLightingContext::SetStateFromOpenGL()
{
    // import classic GL light's parameters into shaded lights
    SetUseLighting(glIsEnabled(GL_LIGHTING));

    GfMatrix4d worldToViewMatrix;
    glGetDoublev(GL_MODELVIEW_MATRIX, worldToViewMatrix.GetArray());
    GfMatrix4d viewToWorldMatrix = worldToViewMatrix.GetInverse();

    GLint nLights = 0;
    glGetIntegerv(GL_MAX_LIGHTS, &nLights);

    GlfSimpleLightVector lights;
    lights.reserve(nLights);

    GlfSimpleLight light;
    for(int i = 0; i < nLights; ++i)
    {
        int lightName = GL_LIGHT0 + i;
        if (glIsEnabled(lightName)) {
            GLfloat position[4], color[4];

            glGetLightfv(lightName, GL_POSITION, position);
            light.SetPosition(GfVec4f(position)*viewToWorldMatrix);
            
            glGetLightfv(lightName, GL_AMBIENT, color);
            light.SetAmbient(GfVec4f(color));
            
            glGetLightfv(lightName, GL_DIFFUSE, color);
            light.SetDiffuse(GfVec4f(color));
            
            glGetLightfv(lightName, GL_SPECULAR, color);
            light.SetSpecular(GfVec4f(color));

            lights.push_back(light);
        }
    }

    SetLights(lights);

    GlfSimpleMaterial material;

    GLfloat color[4], shininess;
    glGetMaterialfv(GL_FRONT, GL_AMBIENT, color);
    material.SetAmbient(GfVec4f(color));
    glGetMaterialfv(GL_FRONT, GL_DIFFUSE, color);
    material.SetDiffuse(GfVec4f(color));
    glGetMaterialfv(GL_FRONT, GL_SPECULAR, color);
    material.SetSpecular(GfVec4f(color));
    glGetMaterialfv(GL_FRONT, GL_EMISSION, color);
    material.SetEmission(GfVec4f(color));
    glGetMaterialfv(GL_FRONT, GL_SHININESS, &shininess);
    // clamp to 0.0001, since pow(0,0) is undefined in GLSL.
    shininess = std::max(0.0001f, shininess);
    material.SetShininess(shininess);

    SetMaterial(material);

    GfVec4f sceneAmbient;
    glGetFloatv(GL_LIGHT_MODEL_AMBIENT, &sceneAmbient[0]);
    SetSceneAmbient(sceneAmbient);
}