KiCad PCB EDA Suite
render_3d_opengl.cpp File Reference
#include <gal/opengl/kiglew.h>
#include "render_3d_opengl.h"
#include "opengl_utils.h"
#include "common_ogl/ogl_utils.h"
#include <footprint.h>
#include <3d_math.h>
#include <math/util.h>
#include <wx/log.h>
#include <base_units.h>

Go to the source code of this file.

Macros

#define UNITS3D_TO_UNITSPCB   (IU_PER_MM)
 Scale conversion from 3d model units to pcb units. More...
 

Functions

void init_lights (void)
 

Macro Definition Documentation

◆ UNITS3D_TO_UNITSPCB

#define UNITS3D_TO_UNITSPCB   (IU_PER_MM)

Scale conversion from 3d model units to pcb units.

Definition at line 40 of file render_3d_opengl.cpp.

Function Documentation

◆ init_lights()

void init_lights ( void  )

Definition at line 451 of file render_3d_opengl.cpp.

452 {
453  // Setup light
454  // https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
455  const GLfloat ambient[] = { 0.084f, 0.084f, 0.084f, 1.0f };
456  const GLfloat diffuse0[] = { 0.3f, 0.3f, 0.3f, 1.0f };
457  const GLfloat specular0[] = { 0.5f, 0.5f, 0.5f, 1.0f };
458 
459  glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
460  glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse0 );
461  glLightfv( GL_LIGHT0, GL_SPECULAR, specular0 );
462 
463  const GLfloat diffuse12[] = { 0.7f, 0.7f, 0.7f, 1.0f };
464  const GLfloat specular12[] = { 0.7f, 0.7f, 0.7f, 1.0f };
465 
466  // defines a directional light that points along the negative z-axis
467  GLfloat position[4] = { 0.0f, 0.0f, 1.0f, 0.0f };
468 
469  // This makes a vector slight not perpendicular with XZ plane
470  const SFVEC3F vectorLight = SphericalToCartesian( glm::pi<float>() * 0.03f,
471  glm::pi<float>() * 0.25f );
472 
473  position[0] = vectorLight.x;
474  position[1] = vectorLight.y;
475  position[2] = vectorLight.z;
476 
477  glLightfv( GL_LIGHT1, GL_AMBIENT, ambient );
478  glLightfv( GL_LIGHT1, GL_DIFFUSE, diffuse12 );
479  glLightfv( GL_LIGHT1, GL_SPECULAR, specular12 );
480  glLightfv( GL_LIGHT1, GL_POSITION, position );
481 
482  // defines a directional light that points along the positive z-axis
483  position[2] = -position[2];
484 
485  glLightfv( GL_LIGHT2, GL_AMBIENT, ambient );
486  glLightfv( GL_LIGHT2, GL_DIFFUSE, diffuse12 );
487  glLightfv( GL_LIGHT2, GL_SPECULAR, specular12 );
488  glLightfv( GL_LIGHT2, GL_POSITION, position );
489 
490  const GLfloat lmodel_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
491 
492  glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
493 
494  glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
495 }
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F SphericalToCartesian(float aInclination, float aAzimuth)
https://en.wikipedia.org/wiki/Spherical_coordinate_system
Definition: 3d_math.h:43

References SphericalToCartesian().

Referenced by RENDER_3D_OPENGL::initializeOpenGL().