3D Viewer: remove all instances of "C" prefix from object names.

This commit is contained in:
Wayne Stambaugh 2021-01-02 16:05:29 -05:00
parent a06387fafd
commit 8416c1fc37
99 changed files with 2731 additions and 3599 deletions

View File

@ -80,7 +80,7 @@ static bool isSHA1Same( const unsigned char* shaA, const unsigned char* shaB ) n
static bool checkTag( const char* aTag, void* aPluginMgrPtr ) static bool checkTag( const char* aTag, void* aPluginMgrPtr )
{ {
if( NULL == aTag || NULL == aPluginMgrPtr ) if( nullptr == aTag || nullptr == aPluginMgrPtr )
return false; return false;
S3D_PLUGIN_MANAGER *pp = (S3D_PLUGIN_MANAGER*) aPluginMgrPtr; S3D_PLUGIN_MANAGER *pp = (S3D_PLUGIN_MANAGER*) aPluginMgrPtr;
@ -149,8 +149,8 @@ private:
S3D_CACHE_ENTRY::S3D_CACHE_ENTRY() S3D_CACHE_ENTRY::S3D_CACHE_ENTRY()
{ {
sceneData = NULL; sceneData = nullptr;
renderData = NULL; renderData = nullptr;
memset( sha1sum, 0, 20 ); memset( sha1sum, 0, 20 );
} }
@ -159,14 +159,14 @@ S3D_CACHE_ENTRY::~S3D_CACHE_ENTRY()
{ {
delete sceneData; delete sceneData;
if( NULL != renderData ) if( nullptr != renderData )
S3D::Destroy3DModel( &renderData ); S3D::Destroy3DModel( &renderData );
} }
void S3D_CACHE_ENTRY::SetSHA1( const unsigned char* aSHA1Sum ) void S3D_CACHE_ENTRY::SetSHA1( const unsigned char* aSHA1Sum )
{ {
if( NULL == aSHA1Sum ) if( nullptr == aSHA1Sum )
{ {
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * [BUG] NULL passed for aSHA1Sum", wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * [BUG] NULL passed for aSHA1Sum",
__FILE__, __FUNCTION__, __LINE__ ); __FILE__, __FUNCTION__, __LINE__ );
@ -217,7 +217,7 @@ S3D_CACHE::~S3D_CACHE()
SCENEGRAPH* S3D_CACHE::load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCachePtr ) SCENEGRAPH* S3D_CACHE::load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCachePtr )
{ {
if( aCachePtr ) if( aCachePtr )
*aCachePtr = NULL; *aCachePtr = nullptr;
wxString full3Dpath = m_FNResolver->ResolvePath( aModelFile ); wxString full3Dpath = m_FNResolver->ResolvePath( aModelFile );
@ -226,7 +226,7 @@ SCENEGRAPH* S3D_CACHE::load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCach
// the model cannot be found; we cannot proceed // the model cannot be found; we cannot proceed
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * [3D model] could not find model '%s'\n", wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * [3D model] could not find model '%s'\n",
__FILE__, __FUNCTION__, __LINE__, aModelFile ); __FILE__, __FUNCTION__, __LINE__, aModelFile );
return NULL; return nullptr;
} }
// check cache if file is already loaded // check cache if file is already loaded
@ -259,13 +259,13 @@ SCENEGRAPH* S3D_CACHE::load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCach
if( reload ) if( reload )
{ {
if( NULL != mi->second->sceneData ) if( nullptr != mi->second->sceneData )
{ {
S3D::DestroyNode( mi->second->sceneData ); S3D::DestroyNode( mi->second->sceneData );
mi->second->sceneData = NULL; mi->second->sceneData = nullptr;
} }
if( NULL != mi->second->renderData ) if( nullptr != mi->second->renderData )
S3D::Destroy3DModel( &mi->second->renderData ); S3D::Destroy3DModel( &mi->second->renderData );
mi->second->sceneData = m_Plugins->Load3DModel( full3Dpath, mi->second->sceneData = m_Plugins->Load3DModel( full3Dpath,
@ -273,7 +273,7 @@ SCENEGRAPH* S3D_CACHE::load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCach
} }
} }
if( NULL != aCachePtr ) if( nullptr != aCachePtr )
*aCachePtr = mi->second; *aCachePtr = mi->second;
return mi->second->sceneData; return mi->second->sceneData;
@ -293,7 +293,7 @@ SCENEGRAPH* S3D_CACHE::Load( const wxString& aModelFile )
SCENEGRAPH* S3D_CACHE::checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr ) SCENEGRAPH* S3D_CACHE::checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr )
{ {
if( aCachePtr ) if( aCachePtr )
*aCachePtr = NULL; *aCachePtr = nullptr;
unsigned char sha1sum[20]; unsigned char sha1sum[20];
@ -322,7 +322,7 @@ SCENEGRAPH* S3D_CACHE::checkCache( const wxString& aFileName, S3D_CACHE_ENTRY**
*aCachePtr = ep; *aCachePtr = ep;
} }
return NULL; return nullptr;
} }
S3D_CACHE_ENTRY* ep = new S3D_CACHE_ENTRY; S3D_CACHE_ENTRY* ep = new S3D_CACHE_ENTRY;
@ -338,7 +338,7 @@ SCENEGRAPH* S3D_CACHE::checkCache( const wxString& aFileName, S3D_CACHE_ENTRY**
m_CacheList.pop_back(); m_CacheList.pop_back();
delete ep; delete ep;
return NULL; return nullptr;
} }
if( aCachePtr ) if( aCachePtr )
@ -354,7 +354,7 @@ SCENEGRAPH* S3D_CACHE::checkCache( const wxString& aFileName, S3D_CACHE_ENTRY**
ep->sceneData = m_Plugins->Load3DModel( aFileName, ep->pluginInfo ); ep->sceneData = m_Plugins->Load3DModel( aFileName, ep->pluginInfo );
if( NULL != ep->sceneData ) if( nullptr != ep->sceneData )
saveCacheData( ep ); saveCacheData( ep );
return ep->sceneData; return ep->sceneData;
@ -371,7 +371,7 @@ bool S3D_CACHE::getSHA1( const wxString& aFileName, unsigned char* aSHA1Sum )
return false; return false;
} }
if( NULL == aSHA1Sum ) if( nullptr == aSHA1Sum )
{ {
wxLogTrace( MASK_3D_CACHE, "%s\n * [BUG] NULL pointer passed for aMD5Sum", wxLogTrace( MASK_3D_CACHE, "%s\n * [BUG] NULL pointer passed for aMD5Sum",
__FILE__, __FUNCTION__, __LINE__ ); __FILE__, __FUNCTION__, __LINE__ );
@ -385,7 +385,7 @@ bool S3D_CACHE::getSHA1( const wxString& aFileName, unsigned char* aSHA1Sum )
FILE* fp = fopen( aFileName.ToUTF8(), "rb" ); FILE* fp = fopen( aFileName.ToUTF8(), "rb" );
#endif #endif
if( NULL == fp ) if( nullptr == fp )
return false; return false;
boost::uuids::detail::sha1 dblock; boost::uuids::detail::sha1 dblock;
@ -446,12 +446,12 @@ bool S3D_CACHE::loadCacheData( S3D_CACHE_ENTRY* aCacheItem )
return false; return false;
} }
if( NULL != aCacheItem->sceneData ) if( nullptr != aCacheItem->sceneData )
S3D::DestroyNode( (SGNODE*) aCacheItem->sceneData ); S3D::DestroyNode( (SGNODE*) aCacheItem->sceneData );
aCacheItem->sceneData = (SCENEGRAPH*)S3D::ReadCache( fname.ToUTF8(), m_Plugins, checkTag ); aCacheItem->sceneData = (SCENEGRAPH*)S3D::ReadCache( fname.ToUTF8(), m_Plugins, checkTag );
if( NULL == aCacheItem->sceneData ) if( nullptr == aCacheItem->sceneData )
return false; return false;
return true; return true;
@ -460,7 +460,7 @@ bool S3D_CACHE::loadCacheData( S3D_CACHE_ENTRY* aCacheItem )
bool S3D_CACHE::saveCacheData( S3D_CACHE_ENTRY* aCacheItem ) bool S3D_CACHE::saveCacheData( S3D_CACHE_ENTRY* aCacheItem )
{ {
if( NULL == aCacheItem ) if( nullptr == aCacheItem )
{ {
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * NULL passed for aCacheItem", wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * NULL passed for aCacheItem",
__FILE__, __FUNCTION__, __LINE__ ); __FILE__, __FUNCTION__, __LINE__ );
@ -468,7 +468,7 @@ bool S3D_CACHE::saveCacheData( S3D_CACHE_ENTRY* aCacheItem )
return false; return false;
} }
if( NULL == aCacheItem->sceneData ) if( nullptr == aCacheItem->sceneData )
{ {
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * aCacheItem has no valid scene data", wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * aCacheItem has no valid scene data",
__FILE__, __FUNCTION__, __LINE__ ); __FILE__, __FUNCTION__, __LINE__ );
@ -665,11 +665,11 @@ void S3D_CACHE::ClosePlugins()
S3DMODEL* S3D_CACHE::GetModel( const wxString& aModelFileName ) S3DMODEL* S3D_CACHE::GetModel( const wxString& aModelFileName )
{ {
S3D_CACHE_ENTRY* cp = NULL; S3D_CACHE_ENTRY* cp = nullptr;
SCENEGRAPH* sp = load( aModelFileName, &cp ); SCENEGRAPH* sp = load( aModelFileName, &cp );
if( !sp ) if( !sp )
return NULL; return nullptr;
if( !cp ) if( !cp )
{ {
@ -677,7 +677,7 @@ S3DMODEL* S3D_CACHE::GetModel( const wxString& aModelFileName )
"%s:%s:%d\n * [BUG] model loaded with no associated S3D_CACHE_ENTRY", "%s:%s:%d\n * [BUG] model loaded with no associated S3D_CACHE_ENTRY",
__FILE__, __FUNCTION__, __LINE__ ); __FILE__, __FUNCTION__, __LINE__ );
return NULL; return nullptr;
} }
if( cp->renderData ) if( cp->renderData )

View File

@ -146,7 +146,7 @@ private:
* @param aCachePtr is an optional return address for cache entry pointer. * @param aCachePtr is an optional return address for cache entry pointer.
* @return SCENEGRAPH object associated with file name or NULL on error. * @return SCENEGRAPH object associated with file name or NULL on error.
*/ */
SCENEGRAPH* checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr = NULL ); SCENEGRAPH* checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr = nullptr );
/** /**
* Calculate the SHA1 hash of the given file. * Calculate the SHA1 hash of the given file.
@ -164,7 +164,7 @@ private:
bool saveCacheData( S3D_CACHE_ENTRY* aCacheItem ); bool saveCacheData( S3D_CACHE_ENTRY* aCacheItem );
// the real load function (can supply a cache entry pointer to member functions) // the real load function (can supply a cache entry pointer to member functions)
SCENEGRAPH* load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCachePtr = NULL ); SCENEGRAPH* load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCachePtr = nullptr );
/// cache entries /// cache entries
std::list< S3D_CACHE_ENTRY* > m_CacheList; std::list< S3D_CACHE_ENTRY* > m_CacheList;

View File

@ -57,7 +57,7 @@ DLG_SELECT_3DMODEL::DLG_SELECT_3DMODEL( wxWindow* aParent, S3D_CACHE* aCacheMana
m_modelViewer = NULL; m_modelViewer = NULL;
m_modelViewer = new C3D_MODEL_VIEWER( m_pane3Dviewer, m_modelViewer = new C3D_MODEL_VIEWER( m_pane3Dviewer,
COGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ), OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ),
m_cache ); m_cache );
m_modelViewer->SetMinSize( wxSize( 400, -1 ) ); m_modelViewer->SetMinSize( wxSize( 400, -1 ) );
m_Sizer3Dviewer->Add( m_modelViewer, 1, wxEXPAND|wxRIGHT, 5 ); m_Sizer3Dviewer->Add( m_modelViewer, 1, wxEXPAND|wxRIGHT, 5 );

View File

@ -91,7 +91,7 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, FOOTPRI
// Create the 3D canvas // Create the 3D canvas
m_previewPane = new EDA_3D_CANVAS( this, m_previewPane = new EDA_3D_CANVAS( this,
COGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ), OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ),
m_dummyBoard, m_boardAdapter, m_currentCamera, m_dummyBoard, m_boardAdapter, m_currentCamera,
aFrame->Prj().Get3DCacheManager() ); aFrame->Prj().Get3DCacheManager() );

View File

@ -88,7 +88,7 @@ public:
wxWindow* GetToolCanvas() const override { return m_previewPane; } wxWindow* GetToolCanvas() const override { return m_previewPane; }
BOARD_ADAPTER& GetAdapter() override { return m_boardAdapter; } BOARD_ADAPTER& GetAdapter() override { return m_boardAdapter; }
CCAMERA& GetCurrentCamera() override { return m_currentCamera; } CAMERA& GetCurrentCamera() override { return m_currentCamera; }
/** /**
* Set the currently selected index in the model list so that the scale/rotation/offset * Set the currently selected index in the model list so that the scale/rotation/offset
@ -111,7 +111,7 @@ private:
/** /**
* It will receive the events from editing the fields. * It will receive the events from editing the fields.
*/ */
void updateOrientation( wxCommandEvent &event ) override; void updateOrientation( wxCommandEvent& event ) override;
void onMouseWheelScale( wxMouseEvent& event ) override; void onMouseWheelScale( wxMouseEvent& event ) override;
void onMouseWheelRot( wxMouseEvent& event ) override; void onMouseWheelRot( wxMouseEvent& event ) override;
@ -198,8 +198,8 @@ private:
EDA_3D_CANVAS* m_previewPane; EDA_3D_CANVAS* m_previewPane;
WX_INFOBAR* m_infobar; WX_INFOBAR* m_infobar;
BOARD_ADAPTER m_boardAdapter; BOARD_ADAPTER m_boardAdapter;
CCAMERA& m_currentCamera; CAMERA& m_currentCamera;
CTRACK_BALL m_trackBallCamera; TRACK_BALL m_trackBallCamera;
BOARD* m_dummyBoard; BOARD* m_dummyBoard;
FOOTPRINT* m_dummyFootprint; FOOTPRINT* m_dummyFootprint;

View File

@ -439,7 +439,7 @@ void BOARD_ADAPTER::InitSettings( REPORTER* aStatusReporter, REPORTER* aWarningR
boardMin.z = m_layerZcoordTop[B_Adhes]; boardMin.z = m_layerZcoordTop[B_Adhes];
boardMax.z = m_layerZcoordTop[F_Adhes]; boardMax.z = m_layerZcoordTop[F_Adhes];
m_boardBoundingBox = CBBOX( boardMin, boardMax ); m_boardBoundingBox = BBOX_3D( boardMin, boardMax );
#ifdef PRINT_STATISTICS_3D_VIEWER #ifdef PRINT_STATISTICS_3D_VIEWER
unsigned stats_startCreateBoardPolyTime = GetRunningMicroSecs(); unsigned stats_startCreateBoardPolyTime = GetRunningMicroSecs();

View File

@ -50,7 +50,7 @@
class COLOR_SETTINGS; class COLOR_SETTINGS;
/// A type that stores a container of 2d objects for each layer id /// A type that stores a container of 2d objects for each layer id
typedef std::map< PCB_LAYER_ID, CBVHCONTAINER2D *> MAP_CONTAINER_2D; typedef std::map< PCB_LAYER_ID, BVH_CONTAINER_2D *> MAP_CONTAINER_2D_BASE;
/// A type that stores polysets for each layer id /// A type that stores polysets for each layer id
typedef std::map< PCB_LAYER_ID, SHAPE_POLY_SET *> MAP_POLY; typedef std::map< PCB_LAYER_ID, SHAPE_POLY_SET *> MAP_POLY;
@ -76,7 +76,7 @@ public:
* *
* @param aCachePointer: the pointer to the 3D cache manager. * @param aCachePointer: the pointer to the 3D cache manager.
*/ */
void Set3DCacheManager( S3D_CACHE *aCachePointer ) noexcept void Set3DCacheManager( S3D_CACHE* aCachePointer ) noexcept
{ {
m_3d_model_manager = aCachePointer; m_3d_model_manager = aCachePointer;
} }
@ -122,7 +122,7 @@ public:
* *
* @param aBoard board to process. * @param aBoard board to process.
*/ */
void SetBoard( BOARD *aBoard ) noexcept void SetBoard( BOARD* aBoard ) noexcept
{ {
m_board = aBoard; m_board = aBoard;
} }
@ -132,7 +132,7 @@ public:
* *
* @return BOARD pointer * @return BOARD pointer
*/ */
const BOARD *GetBoard() const noexcept const BOARD* GetBoard() const noexcept
{ {
return m_board; return m_board;
} }
@ -165,7 +165,7 @@ public:
* *
* @return the board bbox in 3D units. * @return the board bbox in 3D units.
*/ */
const CBBOX &GetBBox3DU() const noexcept const BBOX_3D& GetBBox3DU() const noexcept
{ {
return m_boardBoundingBox; return m_boardBoundingBox;
} }
@ -232,7 +232,7 @@ public:
* *
* @return board center vector position in 3D units. * @return board center vector position in 3D units.
*/ */
const SFVEC3F &GetBoardCenter3DU() const noexcept const SFVEC3F& GetBoardCenter3DU() const noexcept
{ {
return m_boardCenter; return m_boardCenter;
} }
@ -317,7 +317,7 @@ public:
* *
* @return the shape polygon * @return the shape polygon
*/ */
const SHAPE_POLY_SET &GetBoardPoly() const noexcept const SHAPE_POLY_SET& GetBoardPoly() const noexcept
{ {
return m_board_poly; return m_board_poly;
} }
@ -371,17 +371,17 @@ public:
* *
* @return the map containers of this board * @return the map containers of this board
*/ */
const MAP_CONTAINER_2D &GetMapLayers() const noexcept const MAP_CONTAINER_2D_BASE& GetMapLayers() const noexcept
{ {
return m_layers_container2D; return m_layers_container2D;
} }
const CBVHCONTAINER2D* GetPlatedPads_Front() const noexcept const BVH_CONTAINER_2D* GetPlatedPads_Front() const noexcept
{ {
return m_platedpads_container2D_F_Cu; return m_platedpads_container2D_F_Cu;
} }
const CBVHCONTAINER2D* GetPlatedPads_Back() const noexcept const BVH_CONTAINER_2D* GetPlatedPads_Back() const noexcept
{ {
return m_platedpads_container2D_B_Cu; return m_platedpads_container2D_B_Cu;
} }
@ -391,7 +391,7 @@ public:
* *
* @return the map containers of holes from this board. * @return the map containers of holes from this board.
*/ */
const MAP_CONTAINER_2D &GetMapLayersHoles() const noexcept const MAP_CONTAINER_2D_BASE& GetMapLayersHoles() const noexcept
{ {
return m_layers_holes2D; return m_layers_holes2D;
} }
@ -401,7 +401,7 @@ public:
* *
* @return a container with holes. * @return a container with holes.
*/ */
const CBVHCONTAINER2D &GetThroughHole_Outer() const noexcept const BVH_CONTAINER_2D& GetThroughHole_Outer() const noexcept
{ {
return m_through_holes_outer; return m_through_holes_outer;
} }
@ -411,22 +411,22 @@ public:
* *
* @return a container with holes. * @return a container with holes.
*/ */
const CBVHCONTAINER2D& GetThroughHole_Outer_Ring() const noexcept const BVH_CONTAINER_2D& GetThroughHole_Outer_Ring() const noexcept
{ {
return m_through_holes_outer_ring; return m_through_holes_outer_ring;
} }
const SHAPE_POLY_SET &GetThroughHole_Outer_poly() const noexcept const SHAPE_POLY_SET& GetThroughHole_Outer_poly() const noexcept
{ {
return m_through_outer_holes_poly; return m_through_outer_holes_poly;
} }
const SHAPE_POLY_SET &GetThroughHole_Outer_Ring_poly() const noexcept const SHAPE_POLY_SET& GetThroughHole_Outer_Ring_poly() const noexcept
{ {
return m_through_outer_ring_holes_poly; return m_through_outer_ring_holes_poly;
} }
const SHAPE_POLY_SET &GetThroughHole_Outer_poly_NPTH() const noexcept const SHAPE_POLY_SET& GetThroughHole_Outer_poly_NPTH() const noexcept
{ {
return m_through_outer_holes_poly_NPTH; return m_through_outer_holes_poly_NPTH;
} }
@ -434,12 +434,12 @@ public:
/** /**
* @return a container with via THT holes only. * @return a container with via THT holes only.
*/ */
const CBVHCONTAINER2D &GetThroughHole_Vias_Outer() const noexcept const BVH_CONTAINER_2D& GetThroughHole_Vias_Outer() const noexcept
{ {
return m_through_holes_vias_outer; return m_through_holes_vias_outer;
} }
const SHAPE_POLY_SET &GetThroughHole_Vias_Outer_poly() const noexcept const SHAPE_POLY_SET& GetThroughHole_Vias_Outer_poly() const noexcept
{ {
return m_through_outer_holes_vias_poly; return m_through_outer_holes_vias_poly;
} }
@ -449,7 +449,7 @@ public:
* *
* @return a container with holes. * @return a container with holes.
*/ */
const CBVHCONTAINER2D &GetThroughHole_Inner() const noexcept const BVH_CONTAINER_2D& GetThroughHole_Inner() const noexcept
{ {
return m_through_holes_inner; return m_through_holes_inner;
} }
@ -521,7 +521,7 @@ public:
* *
* @return the map with polygon's layers. * @return the map with polygon's layers.
*/ */
const MAP_POLY &GetPolyMap() const noexcept const MAP_POLY& GetPolyMap() const noexcept
{ {
return m_layers_poly; return m_layers_poly;
} }
@ -536,12 +536,12 @@ public:
return m_B_Cu_PlatedPads_poly; return m_B_Cu_PlatedPads_poly;
} }
const MAP_POLY &GetPolyMapHoles_Inner() const noexcept const MAP_POLY& GetPolyMapHoles_Inner() const noexcept
{ {
return m_layers_inner_holes_poly; return m_layers_inner_holes_poly;
} }
const MAP_POLY &GetPolyMapHoles_Outer() const noexcept const MAP_POLY& GetPolyMapHoles_Outer() const noexcept
{ {
return m_layers_outer_holes_poly; return m_layers_outer_holes_poly;
} }
@ -557,52 +557,49 @@ public:
void destroyLayers(); void destroyLayers();
// Helper functions to create the board // Helper functions to create the board
void createNewTrack( const TRACK* aTrack, CGENERICCONTAINER2D *aDstContainer, void createNewTrack( const TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer,
int aClearanceValue ); int aClearanceValue );
void createNewPadWithClearance( const PAD *aPad, CGENERICCONTAINER2D *aDstContainer, void createNewPadWithClearance( const PAD *aPad, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayer, wxSize aClearanceValue ) const; PCB_LAYER_ID aLayer, wxSize aClearanceValue ) const;
COBJECT2D *createNewPadDrill( const PAD* aPad, int aInflateValue ); OBJECT_2D *createNewPadDrill( const PAD* aPad, int aInflateValue );
void AddPadsWithClearanceToContainer( const FOOTPRINT *aFootprint, void AddPadsWithClearanceToContainer( const FOOTPRINT* aFootprint,
CGENERICCONTAINER2D *aDstContainer, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId, int aInflateValue, PCB_LAYER_ID aLayerId, int aInflateValue,
bool aSkipNPTHPadsWihNoCopper, bool aSkipPlatedPads, bool aSkipNPTHPadsWihNoCopper, bool aSkipPlatedPads,
bool aSkipNonPlatedPads ); bool aSkipNonPlatedPads );
void AddFPShapesWithClearanceToContainer( const FOOTPRINT *aFootprint, void AddFPShapesWithClearanceToContainer( const FOOTPRINT* aFootprint,
CGENERICCONTAINER2D *aDstContainer, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId, int aInflateValue ); PCB_LAYER_ID aLayerId, int aInflateValue );
void AddShapeWithClearanceToContainer( const PCB_TEXT *aText, void AddShapeWithClearanceToContainer( const PCB_TEXT* aText, CONTAINER_2D_BASE* aDstContainer,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId, int aClearanceValue ); PCB_LAYER_ID aLayerId, int aClearanceValue );
void AddShapeWithClearanceToContainer( const PCB_SHAPE *aShape, void AddShapeWithClearanceToContainer( const PCB_SHAPE* aShape, CONTAINER_2D_BASE* aDstContainer,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId, int aClearanceValue ); PCB_LAYER_ID aLayerId, int aClearanceValue );
void AddShapeWithClearanceToContainer( const DIMENSION_BASE *aDimension, void AddShapeWithClearanceToContainer( const DIMENSION_BASE* aDimension,
CGENERICCONTAINER2D *aDstContainer, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId, int aClearanceValue ); PCB_LAYER_ID aLayerId, int aClearanceValue );
void AddSolidAreasShapesToContainer( const ZONE *aZoneContainer, void AddSolidAreasShapesToContainer( const ZONE* aZoneContainer, CONTAINER_2D_BASE* aDstContainer,
CGENERICCONTAINER2D *aDstContainer,
PCB_LAYER_ID aLayerId ); PCB_LAYER_ID aLayerId );
void TransformArcToSegments( const wxPoint &aCentre, const wxPoint &aStart, double aArcAngle, void TransformArcToSegments( const wxPoint& aCentre, const wxPoint& aStart, double aArcAngle,
int aCircleToSegmentsCount, int aWidth, int aCircleToSegmentsCount, int aWidth,
CGENERICCONTAINER2D *aDstContainer, const BOARD_ITEM &aBoardItem ); CONTAINER_2D_BASE* aDstContainer, const BOARD_ITEM& aBoardItem );
void buildPadShapeThickOutlineAsSegments( const PAD *aPad, CGENERICCONTAINER2D *aDstContainer, void buildPadShapeThickOutlineAsSegments( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer,
int aWidth ); int aWidth );
// Helper functions to create poly contours // Helper functions to create poly contours
void buildPadShapeThickOutlineAsPolygon( const PAD *aPad, SHAPE_POLY_SET &aCornerBuffer, void buildPadShapeThickOutlineAsPolygon( const PAD* aPad, SHAPE_POLY_SET& aCornerBuffer,
int aWidth) const; int aWidth) const;
void transformFPShapesToPolygon( const FOOTPRINT *aFootprint, PCB_LAYER_ID aLayer, void transformFPShapesToPolygon( const FOOTPRINT* aFootprint, PCB_LAYER_ID aLayer,
SHAPE_POLY_SET& aCornerBuffer ) const; SHAPE_POLY_SET& aCornerBuffer ) const;
public: public:
@ -668,7 +665,7 @@ private:
// Pcb board bounding boxes // Pcb board bounding boxes
/// 3d bounding box of the pcb board in 3d units /// 3d bounding box of the pcb board in 3d units
CBBOX m_boardBoundingBox; BBOX_3D m_boardBoundingBox;
/// It contains polygon contours for each layer /// It contains polygon contours for each layer
MAP_POLY m_layers_poly; MAP_POLY m_layers_poly;
@ -701,33 +698,33 @@ private:
// 2D element containers // 2D element containers
/// It contains the 2d elements of each layer /// It contains the 2d elements of each layer
MAP_CONTAINER_2D m_layers_container2D; MAP_CONTAINER_2D_BASE m_layers_container2D;
CBVHCONTAINER2D* m_platedpads_container2D_F_Cu; BVH_CONTAINER_2D* m_platedpads_container2D_F_Cu;
CBVHCONTAINER2D* m_platedpads_container2D_B_Cu; BVH_CONTAINER_2D* m_platedpads_container2D_B_Cu;
/// It contains the holes per each layer /// It contains the holes per each layer
MAP_CONTAINER_2D m_layers_holes2D; MAP_CONTAINER_2D_BASE m_layers_holes2D;
/// It contains the list of throughHoles of the board, /// It contains the list of throughHoles of the board,
/// the radius of the hole is inflated with the copper thickness /// the radius of the hole is inflated with the copper thickness
CBVHCONTAINER2D m_through_holes_outer; BVH_CONTAINER_2D m_through_holes_outer;
/// It contains the list of throughHoles of the board, /// It contains the list of throughHoles of the board,
/// the radius of the hole is inflated with the annular ring size /// the radius of the hole is inflated with the annular ring size
CBVHCONTAINER2D m_through_holes_outer_ring; BVH_CONTAINER_2D m_through_holes_outer_ring;
/// It contains the list of throughHoles of the board, /// It contains the list of throughHoles of the board,
/// the radius is the inner hole /// the radius is the inner hole
CBVHCONTAINER2D m_through_holes_inner; BVH_CONTAINER_2D m_through_holes_inner;
/// It contains the list of throughHoles vias of the board, /// It contains the list of throughHoles vias of the board,
/// the radius of the hole is inflated with the copper thickness /// the radius of the hole is inflated with the copper thickness
CBVHCONTAINER2D m_through_holes_vias_outer; BVH_CONTAINER_2D m_through_holes_vias_outer;
/// It contains the list of throughHoles vias of the board, /// It contains the list of throughHoles vias of the board,
/// the radius of the hole /// the radius of the hole
CBVHCONTAINER2D m_through_holes_vias_inner; BVH_CONTAINER_2D m_through_holes_vias_inner;
// Layers information // Layers information
@ -787,7 +784,7 @@ private:
* "KI_TRACE_EDA_CINFO3D_VISU". See the wxWidgets documentation on wxLogTrace for * "KI_TRACE_EDA_CINFO3D_VISU". See the wxWidgets documentation on wxLogTrace for
* more information. * more information.
*/ */
static const wxChar *m_logTrace; static const wxChar* m_logTrace;
}; };
@ -796,7 +793,7 @@ class EDA_3D_BOARD_HOLDER
{ {
public: public:
virtual BOARD_ADAPTER& GetAdapter() = 0; virtual BOARD_ADAPTER& GetAdapter() = 0;
virtual CCAMERA& GetCurrentCamera() = 0; virtual CAMERA& GetCurrentCamera() = 0;
virtual ~EDA_3D_BOARD_HOLDER() {}; virtual ~EDA_3D_BOARD_HOLDER() {};
}; };

View File

@ -59,7 +59,7 @@
// But addTextSegmToContainer is a call-back function, // But addTextSegmToContainer is a call-back function,
// so we cannot send them as arguments. // so we cannot send them as arguments.
static int s_textWidth; static int s_textWidth;
static CGENERICCONTAINER2D* s_dstcontainer = nullptr; static CONTAINER_2D_BASE* s_dstcontainer = nullptr;
static float s_biuTo3Dunits; static float s_biuTo3Dunits;
static const BOARD_ITEM* s_boardItem = nullptr; static const BOARD_ITEM* s_boardItem = nullptr;
@ -71,10 +71,10 @@ void addTextSegmToContainer( int x0, int y0, int xf, int yf, void* aData )
const SFVEC2F end3DU ( xf * s_biuTo3Dunits, -yf * s_biuTo3Dunits ); const SFVEC2F end3DU ( xf * s_biuTo3Dunits, -yf * s_biuTo3Dunits );
if( Is_segment_a_circle( start3DU, end3DU ) ) if( Is_segment_a_circle( start3DU, end3DU ) )
s_dstcontainer->Add( new CFILLEDCIRCLE2D( start3DU, ( s_textWidth / 2 ) * s_biuTo3Dunits, s_dstcontainer->Add( new FILLED_CIRCLE_2D( start3DU, ( s_textWidth / 2 ) * s_biuTo3Dunits,
*s_boardItem) ); *s_boardItem) );
else else
s_dstcontainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, s_textWidth * s_biuTo3Dunits, s_dstcontainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, s_textWidth * s_biuTo3Dunits,
*s_boardItem ) ); *s_boardItem ) );
} }
@ -83,7 +83,7 @@ void addTextSegmToContainer( int x0, int y0, int xf, int yf, void* aData )
// void PCB_TEXT::TransformTextShapeWithClearanceToPolygon // void PCB_TEXT::TransformTextShapeWithClearanceToPolygon
// board_items_to_polygon_shape_transform.cpp // board_items_to_polygon_shape_transform.cpp
void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_TEXT* aText, void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_TEXT* aText,
CGENERICCONTAINER2D* aDstContainer, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId, int aClearanceValue ) PCB_LAYER_ID aLayerId, int aClearanceValue )
{ {
wxSize size = aText->GetTextSize(); wxSize size = aText->GetTextSize();
@ -128,7 +128,7 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_TEXT* aText,
void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const DIMENSION_BASE* aDimension, void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const DIMENSION_BASE* aDimension,
CGENERICCONTAINER2D* aDstContainer, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId, int aClearanceValue ) PCB_LAYER_ID aLayerId, int aClearanceValue )
{ {
AddShapeWithClearanceToContainer( &aDimension->Text(), aDstContainer, aLayerId, AddShapeWithClearanceToContainer( &aDimension->Text(), aDstContainer, aLayerId,
@ -148,7 +148,7 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const DIMENSION_BASE* aDim
const SFVEC2F end3DU( seg.B.x * m_biuTo3Dunits, -seg.B.y * m_biuTo3Dunits ); const SFVEC2F end3DU( seg.B.x * m_biuTo3Dunits, -seg.B.y * m_biuTo3Dunits );
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, linewidth * m_biuTo3Dunits, aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, linewidth * m_biuTo3Dunits,
*aDimension ) ); *aDimension ) );
break; break;
} }
@ -161,7 +161,7 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const DIMENSION_BASE* aDim
SFVEC2F center( shape->Centre().x * m_biuTo3Dunits, SFVEC2F center( shape->Centre().x * m_biuTo3Dunits,
shape->Centre().y * m_biuTo3Dunits ); shape->Centre().y * m_biuTo3Dunits );
aDstContainer->Add( new CRING2D( center, ( radius - deltar ) * m_biuTo3Dunits, aDstContainer->Add( new RING_2D( center, ( radius - deltar ) * m_biuTo3Dunits,
( radius + deltar ) * m_biuTo3Dunits, *aDimension ) ); ( radius + deltar ) * m_biuTo3Dunits, *aDimension ) );
break; break;
@ -180,7 +180,7 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const DIMENSION_BASE* aDim
// void FOOTPRINT::TransformFPShapesWithClearanceToPolygonSet // void FOOTPRINT::TransformFPShapesWithClearanceToPolygonSet
// board_items_to_polygon_shape_transform.cpp#L204 // board_items_to_polygon_shape_transform.cpp#L204
void BOARD_ADAPTER::AddFPShapesWithClearanceToContainer( const FOOTPRINT* aFootprint, void BOARD_ADAPTER::AddFPShapesWithClearanceToContainer( const FOOTPRINT* aFootprint,
CGENERICCONTAINER2D* aDstContainer, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId, PCB_LAYER_ID aLayerId,
int aInflateValue ) int aInflateValue )
{ {
@ -246,7 +246,7 @@ void BOARD_ADAPTER::AddFPShapesWithClearanceToContainer( const FOOTPRINT* aFootp
} }
void BOARD_ADAPTER::createNewTrack( const TRACK* aTrack, CGENERICCONTAINER2D* aDstContainer, void BOARD_ADAPTER::createNewTrack( const TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer,
int aClearanceValue ) int aClearanceValue )
{ {
SFVEC2F start3DU( aTrack->GetStart().x * m_biuTo3Dunits, SFVEC2F start3DU( aTrack->GetStart().x * m_biuTo3Dunits,
@ -257,7 +257,7 @@ void BOARD_ADAPTER::createNewTrack( const TRACK* aTrack, CGENERICCONTAINER2D* aD
case PCB_VIA_T: case PCB_VIA_T:
{ {
const float radius = ( ( aTrack->GetWidth() / 2 ) + aClearanceValue ) * m_biuTo3Dunits; const float radius = ( ( aTrack->GetWidth() / 2 ) + aClearanceValue ) * m_biuTo3Dunits;
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, radius, *aTrack ) ); aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, radius, *aTrack ) );
break; break;
} }
@ -307,13 +307,13 @@ void BOARD_ADAPTER::createNewTrack( const TRACK* aTrack, CGENERICCONTAINER2D* aD
{ {
const float radius = ((aTrack->GetWidth() / 2) + aClearanceValue) * m_biuTo3Dunits; const float radius = ((aTrack->GetWidth() / 2) + aClearanceValue) * m_biuTo3Dunits;
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, radius, *aTrack ) ); aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, radius, *aTrack ) );
} }
else else
{ {
const float width = (aTrack->GetWidth() + 2 * aClearanceValue ) * m_biuTo3Dunits; const float width = (aTrack->GetWidth() + 2 * aClearanceValue ) * m_biuTo3Dunits;
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, width, *aTrack ) ); aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, width, *aTrack ) );
} }
break; break;
@ -325,7 +325,7 @@ void BOARD_ADAPTER::createNewTrack( const TRACK* aTrack, CGENERICCONTAINER2D* aD
} }
void BOARD_ADAPTER::createNewPadWithClearance( const PAD* aPad, CGENERICCONTAINER2D* aDstContainer, void BOARD_ADAPTER::createNewPadWithClearance( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayer, wxSize aClearanceValue ) const PCB_LAYER_ID aLayer, wxSize aClearanceValue ) const
{ {
SHAPE_POLY_SET poly; SHAPE_POLY_SET poly;
@ -365,13 +365,13 @@ void BOARD_ADAPTER::createNewPadWithClearance( const PAD* aPad, CGENERICCONTAINE
// Cannot add segments that have the same start and end point // Cannot add segments that have the same start and end point
if( Is_segment_a_circle( start3DU, end3DU ) ) if( Is_segment_a_circle( start3DU, end3DU ) )
{ {
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU,
( width / 2) * m_biuTo3Dunits, ( width / 2) * m_biuTo3Dunits,
*aPad ) ); *aPad ) );
} }
else else
{ {
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU,
width * m_biuTo3Dunits, width * m_biuTo3Dunits,
*aPad ) ); *aPad ) );
} }
@ -385,7 +385,8 @@ void BOARD_ADAPTER::createNewPadWithClearance( const PAD* aPad, CGENERICCONTAINE
const SFVEC2F center( circle->GetCenter().x * m_biuTo3Dunits, const SFVEC2F center( circle->GetCenter().x * m_biuTo3Dunits,
-circle->GetCenter().y * m_biuTo3Dunits ); -circle->GetCenter().y * m_biuTo3Dunits );
aDstContainer->Add( new CFILLEDCIRCLE2D( center, radius * m_biuTo3Dunits, *aPad ) ); aDstContainer->Add( new FILLED_CIRCLE_2D( center, radius * m_biuTo3Dunits,
*aPad ) );
} }
break; break;
@ -428,7 +429,7 @@ void BOARD_ADAPTER::createNewPadWithClearance( const PAD* aPad, CGENERICCONTAINE
} }
COBJECT2D* BOARD_ADAPTER::createNewPadDrill( const PAD* aPad, int aInflateValue ) OBJECT_2D* BOARD_ADAPTER::createNewPadDrill( const PAD* aPad, int aInflateValue )
{ {
wxSize drillSize = aPad->GetDrillSize(); wxSize drillSize = aPad->GetDrillSize();
@ -445,7 +446,7 @@ COBJECT2D* BOARD_ADAPTER::createNewPadDrill( const PAD* aPad, int aInflateValue
const SFVEC2F center( aPad->GetPosition().x * m_biuTo3Dunits, const SFVEC2F center( aPad->GetPosition().x * m_biuTo3Dunits,
-aPad->GetPosition().y * m_biuTo3Dunits ); -aPad->GetPosition().y * m_biuTo3Dunits );
return new CFILLEDCIRCLE2D( center, radius * m_biuTo3Dunits, *aPad ); return new FILLED_CIRCLE_2D( center, radius * m_biuTo3Dunits, *aPad );
} }
else // Oblong hole else // Oblong hole
@ -459,7 +460,7 @@ COBJECT2D* BOARD_ADAPTER::createNewPadDrill( const PAD* aPad, int aInflateValue
SFVEC2F end3DU ( seg->GetSeg().B.x * m_biuTo3Dunits, SFVEC2F end3DU ( seg->GetSeg().B.x * m_biuTo3Dunits,
-seg->GetSeg().B.y * m_biuTo3Dunits ); -seg->GetSeg().B.y * m_biuTo3Dunits );
return new CROUNDSEGMENT2D( start3DU, end3DU, width * m_biuTo3Dunits, *aPad ); return new ROUND_SEGMENT_2D( start3DU, end3DU, width * m_biuTo3Dunits, *aPad );
} }
return nullptr; return nullptr;
@ -467,7 +468,7 @@ COBJECT2D* BOARD_ADAPTER::createNewPadDrill( const PAD* aPad, int aInflateValue
void BOARD_ADAPTER::AddPadsWithClearanceToContainer( const FOOTPRINT* aFootprint, void BOARD_ADAPTER::AddPadsWithClearanceToContainer( const FOOTPRINT* aFootprint,
CGENERICCONTAINER2D* aDstContainer, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId, PCB_LAYER_ID aLayerId,
int aInflateValue, int aInflateValue,
bool aSkipNPTHPadsWihNoCopper, bool aSkipNPTHPadsWihNoCopper,
@ -544,7 +545,7 @@ void BOARD_ADAPTER::AddPadsWithClearanceToContainer( const FOOTPRINT* aFootprint
// common/convert_basic_shapes_to_polygon.cpp // common/convert_basic_shapes_to_polygon.cpp
void BOARD_ADAPTER::TransformArcToSegments( const wxPoint& aCentre, const wxPoint& aStart, void BOARD_ADAPTER::TransformArcToSegments( const wxPoint& aCentre, const wxPoint& aStart,
double aArcAngle, int aCircleToSegmentsCount, double aArcAngle, int aCircleToSegmentsCount,
int aWidth, CGENERICCONTAINER2D* aDstContainer, int aWidth, CONTAINER_2D_BASE* aDstContainer,
const BOARD_ITEM& aBoardItem ) const BOARD_ITEM& aBoardItem )
{ {
wxPoint arc_start, arc_end; wxPoint arc_start, arc_end;
@ -577,12 +578,12 @@ void BOARD_ADAPTER::TransformArcToSegments( const wxPoint& aCentre, const wxPoin
if( Is_segment_a_circle( start3DU, end3DU ) ) if( Is_segment_a_circle( start3DU, end3DU ) )
{ {
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, ( aWidth / 2 ) * m_biuTo3Dunits, aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, ( aWidth / 2 ) * m_biuTo3Dunits,
aBoardItem ) ); aBoardItem ) );
} }
else else
{ {
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, aWidth * m_biuTo3Dunits, aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, aWidth * m_biuTo3Dunits,
aBoardItem ) ); aBoardItem ) );
} }
@ -596,12 +597,12 @@ void BOARD_ADAPTER::TransformArcToSegments( const wxPoint& aCentre, const wxPoin
if( Is_segment_a_circle( start3DU, end3DU ) ) if( Is_segment_a_circle( start3DU, end3DU ) )
{ {
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, ( aWidth / 2 ) * m_biuTo3Dunits, aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, ( aWidth / 2 ) * m_biuTo3Dunits,
aBoardItem ) ); aBoardItem ) );
} }
else else
{ {
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, aWidth * m_biuTo3Dunits, aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, aWidth * m_biuTo3Dunits,
aBoardItem ) ); aBoardItem ) );
} }
} }
@ -612,7 +613,7 @@ void BOARD_ADAPTER::TransformArcToSegments( const wxPoint& aCentre, const wxPoin
// TransformShapeWithClearanceToPolygon // TransformShapeWithClearanceToPolygon
// board_items_to_polygon_shape_transform.cpp#L431 // board_items_to_polygon_shape_transform.cpp#L431
void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_SHAPE* aShape, void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_SHAPE* aShape,
CGENERICCONTAINER2D* aDstContainer, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId, PCB_LAYER_ID aLayerId,
int aClearanceValue ) int aClearanceValue )
{ {
@ -634,9 +635,9 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_SHAPE* aShape,
inner_radius = 0; inner_radius = 0;
if( aShape->IsFilled() ) if( aShape->IsFilled() )
aDstContainer->Add( new CFILLEDCIRCLE2D( center3DU, outer_radius, *aShape ) ); aDstContainer->Add( new FILLED_CIRCLE_2D( center3DU, outer_radius, *aShape ) );
else else
aDstContainer->Add( new CRING2D( center3DU, inner_radius, outer_radius, *aShape ) ); aDstContainer->Add( new RING_2D( center3DU, inner_radius, outer_radius, *aShape ) );
} }
break; break;
@ -662,13 +663,13 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_SHAPE* aShape,
const SFVEC2F botRight3DU( pts[2].x * m_biuTo3Dunits, -pts[2].y * m_biuTo3Dunits ); const SFVEC2F botRight3DU( pts[2].x * m_biuTo3Dunits, -pts[2].y * m_biuTo3Dunits );
const SFVEC2F botLeft3DU( pts[3].x * m_biuTo3Dunits, -pts[3].y * m_biuTo3Dunits ); const SFVEC2F botLeft3DU( pts[3].x * m_biuTo3Dunits, -pts[3].y * m_biuTo3Dunits );
aDstContainer->Add( new CROUNDSEGMENT2D( topLeft3DU, topRight3DU, aDstContainer->Add( new ROUND_SEGMENT_2D( topLeft3DU, topRight3DU,
linewidth * m_biuTo3Dunits, *aShape ) ); linewidth * m_biuTo3Dunits, *aShape ) );
aDstContainer->Add( new CROUNDSEGMENT2D( topRight3DU, botRight3DU, aDstContainer->Add( new ROUND_SEGMENT_2D( topRight3DU, botRight3DU,
linewidth * m_biuTo3Dunits, *aShape ) ); linewidth * m_biuTo3Dunits, *aShape ) );
aDstContainer->Add( new CROUNDSEGMENT2D( botRight3DU, botLeft3DU, aDstContainer->Add( new ROUND_SEGMENT_2D( botRight3DU, botLeft3DU,
linewidth * m_biuTo3Dunits, *aShape ) ); linewidth * m_biuTo3Dunits, *aShape ) );
aDstContainer->Add( new CROUNDSEGMENT2D( botLeft3DU, topLeft3DU, aDstContainer->Add( new ROUND_SEGMENT_2D( botLeft3DU, topLeft3DU,
linewidth * m_biuTo3Dunits, *aShape ) ); linewidth * m_biuTo3Dunits, *aShape ) );
} }
break; break;
@ -692,12 +693,12 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_SHAPE* aShape,
if( Is_segment_a_circle( start3DU, end3DU ) ) if( Is_segment_a_circle( start3DU, end3DU ) )
{ {
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, ( linewidth / 2 ) * m_biuTo3Dunits, aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, ( linewidth / 2 ) * m_biuTo3Dunits,
*aShape ) ); *aShape ) );
} }
else else
{ {
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, linewidth * m_biuTo3Dunits, aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, linewidth * m_biuTo3Dunits,
*aShape ) ); *aShape ) );
} }
} }
@ -733,7 +734,7 @@ void BOARD_ADAPTER::AddShapeWithClearanceToContainer( const PCB_SHAPE* aShape,
// TransformSolidAreasShapesToPolygonSet // TransformSolidAreasShapesToPolygonSet
// board_items_to_polygon_shape_transform.cpp // board_items_to_polygon_shape_transform.cpp
void BOARD_ADAPTER::AddSolidAreasShapesToContainer( const ZONE* aZoneContainer, void BOARD_ADAPTER::AddSolidAreasShapesToContainer( const ZONE* aZoneContainer,
CGENERICCONTAINER2D* aDstContainer, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId ) PCB_LAYER_ID aLayerId )
{ {
// Copy the polys list because we have to simplify it // Copy the polys list because we have to simplify it
@ -768,11 +769,11 @@ void BOARD_ADAPTER::AddSolidAreasShapesToContainer( const ZONE* aZoneContainer,
float radius = line_thickness/2; float radius = line_thickness/2;
if( radius > 0.0 ) // degenerated circles crash 3D viewer if( radius > 0.0 ) // degenerated circles crash 3D viewer
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, radius, *aZoneContainer ) ); aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, radius, *aZoneContainer ) );
} }
else else
{ {
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, line_thickness, aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, line_thickness,
*aZoneContainer ) ); *aZoneContainer ) );
} }
} }
@ -795,12 +796,12 @@ void BOARD_ADAPTER::AddSolidAreasShapesToContainer( const ZONE* aZoneContainer,
float radius = line_thickness/2; float radius = line_thickness/2;
if( radius > 0.0 ) // degenerated circles crash 3D viewer if( radius > 0.0 ) // degenerated circles crash 3D viewer
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, radius, aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, radius,
*aZoneContainer ) ); *aZoneContainer ) );
} }
else else
{ {
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, line_thickness, aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, line_thickness,
*aZoneContainer ) ); *aZoneContainer ) );
} }
} }
@ -810,7 +811,7 @@ void BOARD_ADAPTER::AddSolidAreasShapesToContainer( const ZONE* aZoneContainer,
void BOARD_ADAPTER::buildPadShapeThickOutlineAsSegments( const PAD* aPad, void BOARD_ADAPTER::buildPadShapeThickOutlineAsSegments( const PAD* aPad,
CGENERICCONTAINER2D* aDstContainer, CONTAINER_2D_BASE* aDstContainer,
int aWidth ) int aWidth )
{ {
if( aPad->GetShape() == PAD_SHAPE_CIRCLE ) // Draw a ring if( aPad->GetShape() == PAD_SHAPE_CIRCLE ) // Draw a ring
@ -822,7 +823,7 @@ void BOARD_ADAPTER::buildPadShapeThickOutlineAsSegments( const PAD* aPad,
const float inner_radius = ( radius - aWidth / 2 ) * m_biuTo3Dunits; const float inner_radius = ( radius - aWidth / 2 ) * m_biuTo3Dunits;
const float outer_radius = ( radius + aWidth / 2 ) * m_biuTo3Dunits; const float outer_radius = ( radius + aWidth / 2 ) * m_biuTo3Dunits;
aDstContainer->Add( new CRING2D( center3DU, inner_radius, outer_radius, *aPad ) ); aDstContainer->Add( new RING_2D( center3DU, inner_radius, outer_radius, *aPad ) );
return; return;
} }
@ -841,12 +842,12 @@ void BOARD_ADAPTER::buildPadShapeThickOutlineAsSegments( const PAD* aPad,
if( Is_segment_a_circle( start3DU, end3DU ) ) if( Is_segment_a_circle( start3DU, end3DU ) )
{ {
aDstContainer->Add( new CFILLEDCIRCLE2D( start3DU, ( aWidth / 2 ) * m_biuTo3Dunits, aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, ( aWidth / 2 ) * m_biuTo3Dunits,
*aPad ) ); *aPad ) );
} }
else else
{ {
aDstContainer->Add( new CROUNDSEGMENT2D( start3DU, end3DU, aWidth * m_biuTo3Dunits, aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, aWidth * m_biuTo3Dunits,
*aPad ) ); *aPad ) );
} }
} }

View File

@ -197,7 +197,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
layer_id.push_back( curr_layer_id ); layer_id.push_back( curr_layer_id );
CBVHCONTAINER2D *layerContainer = new CBVHCONTAINER2D; BVH_CONTAINER_2D *layerContainer = new BVH_CONTAINER_2D;
m_layers_container2D[curr_layer_id] = layerContainer; m_layers_container2D[curr_layer_id] = layerContainer;
if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS )
@ -213,8 +213,8 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
m_F_Cu_PlatedPads_poly = new SHAPE_POLY_SET; m_F_Cu_PlatedPads_poly = new SHAPE_POLY_SET;
m_B_Cu_PlatedPads_poly = new SHAPE_POLY_SET; m_B_Cu_PlatedPads_poly = new SHAPE_POLY_SET;
m_platedpads_container2D_F_Cu = new CBVHCONTAINER2D; m_platedpads_container2D_F_Cu = new BVH_CONTAINER_2D;
m_platedpads_container2D_B_Cu = new CBVHCONTAINER2D; m_platedpads_container2D_B_Cu = new BVH_CONTAINER_2D;
} }
@ -226,7 +226,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
{ {
wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() ); wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
CBVHCONTAINER2D *layerContainer = m_layers_container2D[curr_layer_id]; BVH_CONTAINER_2D *layerContainer = m_layers_container2D[curr_layer_id];
// Add track segments shapes and via annulus shapes // Add track segments shapes and via annulus shapes
unsigned int nTracks = trackList.size(); unsigned int nTracks = trackList.size();
@ -280,13 +280,13 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
{ {
// Add hole objects // Add hole objects
CBVHCONTAINER2D *layerHoleContainer = NULL; BVH_CONTAINER_2D *layerHoleContainer = nullptr;
// Check if the layer is already created // Check if the layer is already created
if( m_layers_holes2D.find( curr_layer_id ) == m_layers_holes2D.end() ) if( m_layers_holes2D.find( curr_layer_id ) == m_layers_holes2D.end() )
{ {
// not found, create a new container // not found, create a new container
layerHoleContainer = new CBVHCONTAINER2D; layerHoleContainer = new BVH_CONTAINER_2D;
m_layers_holes2D[curr_layer_id] = layerHoleContainer; m_layers_holes2D[curr_layer_id] = layerHoleContainer;
} }
else else
@ -296,34 +296,30 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
} }
// Add a hole for this layer // Add a hole for this layer
layerHoleContainer->Add( new CFILLEDCIRCLE2D( via_center, layerHoleContainer->Add( new FILLED_CIRCLE_2D( via_center,
hole_inner_radius + thickness, hole_inner_radius + thickness,
*track ) ); *track ) );
} }
else if( curr_layer_id == layer_id[0] ) // it only adds once the THT holes else if( curr_layer_id == layer_id[0] ) // it only adds once the THT holes
{ {
// Add through hole object // Add through hole object
m_through_holes_outer.Add( new CFILLEDCIRCLE2D( via_center, m_through_holes_outer.Add( new FILLED_CIRCLE_2D( via_center,
hole_inner_radius + thickness, hole_inner_radius + thickness,
*track ) ); *track ) );
m_through_holes_vias_outer.Add( m_through_holes_vias_outer.Add(
new CFILLEDCIRCLE2D( via_center, hole_inner_radius + thickness, new FILLED_CIRCLE_2D( via_center, hole_inner_radius + thickness,
*track ) ); *track ) );
if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) && if( GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) &&
GetFlag( FL_USE_REALISTIC_MODE ) ) GetFlag( FL_USE_REALISTIC_MODE ) )
{ {
m_through_holes_outer_ring.Add( new CFILLEDCIRCLE2D( via_center, m_through_holes_outer_ring.Add( new FILLED_CIRCLE_2D( via_center,
ring_radius, ring_radius,
*track ) ); *track ) );
} }
m_through_holes_inner.Add( new CFILLEDCIRCLE2D( via_center, hole_inner_radius, m_through_holes_inner.Add( new FILLED_CIRCLE_2D( via_center, hole_inner_radius,
*track ) ); *track ) );
//m_through_holes_vias_inner.Add( new CFILLEDCIRCLE2D( via_center,
// hole_inner_radius,
// *track ) );
} }
} }
} }
@ -353,8 +349,8 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
// Add VIA hole contours // Add VIA hole contours
// Add outer holes of VIAs // Add outer holes of VIAs
SHAPE_POLY_SET *layerOuterHolesPoly = NULL; SHAPE_POLY_SET *layerOuterHolesPoly = nullptr;
SHAPE_POLY_SET *layerInnerHolesPoly = NULL; SHAPE_POLY_SET *layerInnerHolesPoly = nullptr;
// Check if the layer is already created // Check if the layer is already created
if( m_layers_outer_holes_poly.find( curr_layer_id ) == if( m_layers_outer_holes_poly.find( curr_layer_id ) ==
@ -527,7 +523,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
{ {
wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() ); wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
CBVHCONTAINER2D *layerContainer = m_layers_container2D[curr_layer_id]; BVH_CONTAINER_2D *layerContainer = m_layers_container2D[curr_layer_id];
// ADD PADS // ADD PADS
for( FOOTPRINT* footprint : m_board->Footprints() ) for( FOOTPRINT* footprint : m_board->Footprints() )
@ -607,7 +603,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
{ {
wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() ); wxASSERT( m_layers_container2D.find( curr_layer_id ) != m_layers_container2D.end() );
CBVHCONTAINER2D *layerContainer = m_layers_container2D[curr_layer_id]; BVH_CONTAINER_2D *layerContainer = m_layers_container2D[curr_layer_id];
// Add graphic items on copper layers (texts and other graphics) // Add graphic items on copper layers (texts and other graphics)
for( BOARD_ITEM* item : m_board->Drawings() ) for( BOARD_ITEM* item : m_board->Drawings() )
@ -897,7 +893,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
if( !Is3DLayerEnabled( curr_layer_id ) ) if( !Is3DLayerEnabled( curr_layer_id ) )
continue; continue;
CBVHCONTAINER2D *layerContainer = new CBVHCONTAINER2D; BVH_CONTAINER_2D *layerContainer = new BVH_CONTAINER_2D;
m_layers_container2D[curr_layer_id] = layerContainer; m_layers_container2D[curr_layer_id] = layerContainer;
SHAPE_POLY_SET *layerPoly = new SHAPE_POLY_SET; SHAPE_POLY_SET *layerPoly = new SHAPE_POLY_SET;

View File

@ -52,7 +52,7 @@
* *
* @ingroup trace_env_vars * @ingroup trace_env_vars
*/ */
const wxChar * EDA_3D_CANVAS::m_logTrace = wxT( "KI_TRACE_EDA_3D_CANVAS" ); const wxChar* EDA_3D_CANVAS::m_logTrace = wxT( "KI_TRACE_EDA_3D_CANVAS" );
const float EDA_3D_CANVAS::m_delta_move_step_factor = 0.7f; const float EDA_3D_CANVAS::m_delta_move_step_factor = 0.7f;
@ -87,7 +87,7 @@ END_EVENT_TABLE()
EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD* aBoard, EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD* aBoard,
BOARD_ADAPTER& aBoardAdapter, CCAMERA& aCamera, BOARD_ADAPTER& aBoardAdapter, CAMERA& aCamera,
S3D_CACHE* a3DCachePointer ) S3D_CACHE* a3DCachePointer )
: HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, wxDefaultSize, : HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE ), wxFULL_REPAINT_ON_RESIZE ),
@ -116,26 +116,20 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD*
wxLogTrace( m_logTrace, "EDA_3D_CANVAS::EDA_3D_CANVAS" ); wxLogTrace( m_logTrace, "EDA_3D_CANVAS::EDA_3D_CANVAS" );
m_editing_timeout_timer.SetOwner( this ); m_editing_timeout_timer.SetOwner( this );
Connect( m_editing_timeout_timer.GetId(), Connect( m_editing_timeout_timer.GetId(), wxEVT_TIMER,
wxEVT_TIMER, wxTimerEventHandler( EDA_3D_CANVAS::OnTimerTimeout_Editing ), nullptr, this );
wxTimerEventHandler( EDA_3D_CANVAS::OnTimerTimeout_Editing ),
NULL,
this );
m_redraw_trigger_timer.SetOwner( this ); m_redraw_trigger_timer.SetOwner( this );
Connect( m_redraw_trigger_timer.GetId(), Connect( m_redraw_trigger_timer.GetId(), wxEVT_TIMER,
wxEVT_TIMER, wxTimerEventHandler( EDA_3D_CANVAS::OnTimerTimeout_Redraw ), nullptr, this );
wxTimerEventHandler( EDA_3D_CANVAS::OnTimerTimeout_Redraw ),
NULL,
this );
m_is_currently_painting.clear(); m_is_currently_painting.clear();
m_3d_render_raytracing = new C3D_RENDER_RAYTRACING( m_boardAdapter, m_camera ); m_3d_render_raytracing = new RENDER_3D_RAYTRACE( m_boardAdapter, m_camera );
m_3d_render_ogl_legacy = new C3D_RENDER_OGL_LEGACY( m_boardAdapter, m_camera ); m_3d_render_ogl_legacy = new RENDER_3D_LEGACY( m_boardAdapter, m_camera );
wxASSERT( m_3d_render_raytracing != NULL ); wxASSERT( m_3d_render_raytracing != nullptr );
wxASSERT( m_3d_render_ogl_legacy != NULL ); wxASSERT( m_3d_render_ogl_legacy != nullptr );
auto busy_indicator_factory = []() { return std::make_unique<WX_BUSY_INDICATOR>(); }; auto busy_indicator_factory = []() { return std::make_unique<WX_BUSY_INDICATOR>(); };
@ -144,12 +138,12 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD*
RenderEngineChanged(); RenderEngineChanged();
wxASSERT( aBoard != NULL ); wxASSERT( aBoard != nullptr );
m_boardAdapter.SetBoard( aBoard ); m_boardAdapter.SetBoard( aBoard );
m_boardAdapter.SetColorSettings( Pgm().GetSettingsManager().GetColorSettings() ); m_boardAdapter.SetColorSettings( Pgm().GetSettingsManager().GetColorSettings() );
wxASSERT( a3DCachePointer != NULL ); wxASSERT( a3DCachePointer != nullptr );
m_boardAdapter.Set3DCacheManager( a3DCachePointer ); m_boardAdapter.Set3DCacheManager( a3DCachePointer );
const wxEventType events[] = const wxEventType events[] =
@ -169,7 +163,7 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD*
}; };
for( wxEventType eventType : events ) for( wxEventType eventType : events )
Connect( eventType, wxEventHandler( EDA_3D_CANVAS::OnEvent ), NULL, m_eventDispatcher ); Connect( eventType, wxEventHandler( EDA_3D_CANVAS::OnEvent ), nullptr, m_eventDispatcher );
} }
@ -178,7 +172,7 @@ EDA_3D_CANVAS::~EDA_3D_CANVAS()
wxLogTrace( m_logTrace, "EDA_3D_CANVAS::~EDA_3D_CANVAS" ); wxLogTrace( m_logTrace, "EDA_3D_CANVAS::~EDA_3D_CANVAS" );
delete m_accelerator3DShapes; delete m_accelerator3DShapes;
m_accelerator3DShapes = NULL; m_accelerator3DShapes = nullptr;
releaseOpenGL(); releaseOpenGL();
} }
@ -191,22 +185,22 @@ void EDA_3D_CANVAS::releaseOpenGL()
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this ); GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
delete m_3d_render_raytracing; delete m_3d_render_raytracing;
m_3d_render_raytracing = NULL; m_3d_render_raytracing = nullptr;
delete m_3d_render_ogl_legacy; delete m_3d_render_ogl_legacy;
m_3d_render_ogl_legacy = NULL; m_3d_render_ogl_legacy = nullptr;
// This is just a copy of a pointer, can safely be set to NULL // This is just a copy of a pointer, can safely be set to NULL.
m_3d_render = NULL; m_3d_render = nullptr;
GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC ); GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );
GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC ); GL_CONTEXT_MANAGER::Get().DestroyCtx( m_glRC );
m_glRC = NULL; m_glRC = nullptr;
} }
} }
void EDA_3D_CANVAS::OnCloseWindow( wxCloseEvent &event ) void EDA_3D_CANVAS::OnCloseWindow( wxCloseEvent& event )
{ {
releaseOpenGL(); releaseOpenGL();
@ -214,7 +208,7 @@ void EDA_3D_CANVAS::OnCloseWindow( wxCloseEvent &event )
} }
void EDA_3D_CANVAS::OnResize( wxSizeEvent &event ) void EDA_3D_CANVAS::OnResize( wxSizeEvent& event )
{ {
this->Request_refresh(); this->Request_refresh();
} }
@ -295,18 +289,18 @@ bool EDA_3D_CANVAS::initializeOpenGL()
} }
void EDA_3D_CANVAS::GetScreenshot( wxImage &aDstImage ) void EDA_3D_CANVAS::GetScreenshot( wxImage& aDstImage )
{ {
OGL_GetScreenshot( aDstImage ); OGL_GetScreenshot( aDstImage );
} }
void EDA_3D_CANVAS::ReloadRequest( BOARD *aBoard , S3D_CACHE *aCachePointer ) void EDA_3D_CANVAS::ReloadRequest( BOARD* aBoard , S3D_CACHE* aCachePointer )
{ {
if( aCachePointer != NULL ) if( aCachePointer != nullptr )
m_boardAdapter.Set3DCacheManager( aCachePointer ); m_boardAdapter.Set3DCacheManager( aCachePointer );
if( aBoard != NULL ) if( aBoard != nullptr )
m_boardAdapter.SetBoard( aBoard ); m_boardAdapter.SetBoard( aBoard );
m_boardAdapter.SetColorSettings( Pgm().GetSettingsManager().GetColorSettings() ); m_boardAdapter.SetColorSettings( Pgm().GetSettingsManager().GetColorSettings() );
@ -392,7 +386,7 @@ void EDA_3D_CANVAS::DoRePaint()
// This function may only be called when the window is shown on screen" // This function may only be called when the window is shown on screen"
// Explicitly create a new rendering context instance for this canvas. // Explicitly create a new rendering context instance for this canvas.
if( m_glRC == NULL ) if( m_glRC == nullptr )
m_glRC = GL_CONTEXT_MANAGER::Get().CreateCtx( this ); m_glRC = GL_CONTEXT_MANAGER::Get().CreateCtx( this );
GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this ); GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );
@ -554,7 +548,7 @@ void EDA_3D_CANVAS::DoRePaint()
if( !err_messages.IsEmpty() ) if( !err_messages.IsEmpty() )
wxLogMessage( err_messages ); wxLogMessage( err_messages );
if( (!m_camera_is_moving) && requested_redraw ) if( ( !m_camera_is_moving ) && requested_redraw )
{ {
m_mouse_was_moved = false; m_mouse_was_moved = false;
Request_refresh( false ); Request_refresh( false );
@ -572,14 +566,14 @@ void EDA_3D_CANVAS::SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher )
{ {
m_parent->Connect( wxEVT_TOOL, m_parent->Connect( wxEVT_TOOL,
wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher ); nullptr, m_eventDispatcher );
} }
else else
{ {
// While loop is used to be sure that all event handlers are removed. // While loop is used to be sure that all event handlers are removed.
while( m_parent->Disconnect( wxEVT_TOOL, while( m_parent->Disconnect( wxEVT_TOOL,
wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ), wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher ) ); nullptr, m_eventDispatcher ) );
} }
} }
@ -595,14 +589,14 @@ void EDA_3D_CANVAS::OnEvent( wxEvent& aEvent )
} }
void EDA_3D_CANVAS::OnEraseBackground( wxEraseEvent &event ) void EDA_3D_CANVAS::OnEraseBackground( wxEraseEvent& event )
{ {
wxLogTrace( m_logTrace, "EDA_3D_CANVAS::OnEraseBackground" ); wxLogTrace( m_logTrace, "EDA_3D_CANVAS::OnEraseBackground" );
// Do nothing, to avoid flashing. // Do nothing, to avoid flashing.
} }
void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent &event ) void EDA_3D_CANVAS::OnMouseWheel( wxMouseEvent& event )
{ {
bool mouseActivity = false; bool mouseActivity = false;
@ -690,7 +684,7 @@ void EDA_3D_CANVAS::OnMagnify( wxMouseEvent& event )
#endif #endif
void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent &event ) void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent& event )
{ {
//wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::OnMouseMove" ) ); //wxLogTrace( m_logTrace, wxT( "EDA_3D_CANVAS::OnMouseMove" ) );
@ -811,7 +805,7 @@ void EDA_3D_CANVAS::OnMouseMove( wxMouseEvent &event )
} }
void EDA_3D_CANVAS::OnLeftDown( wxMouseEvent &event ) void EDA_3D_CANVAS::OnLeftDown( wxMouseEvent& event )
{ {
SetFocus(); SetFocus();
stop_editingTimeOut_Timer(); stop_editingTimeOut_Timer();
@ -827,7 +821,7 @@ void EDA_3D_CANVAS::OnLeftDown( wxMouseEvent &event )
} }
void EDA_3D_CANVAS::OnLeftUp( wxMouseEvent &event ) void EDA_3D_CANVAS::OnLeftUp( wxMouseEvent& event )
{ {
if( m_camera_is_moving ) if( m_camera_is_moving )
return; return;
@ -840,14 +834,14 @@ void EDA_3D_CANVAS::OnLeftUp( wxMouseEvent &event )
} }
void EDA_3D_CANVAS::OnMiddleDown( wxMouseEvent &event ) void EDA_3D_CANVAS::OnMiddleDown( wxMouseEvent& event )
{ {
SetFocus(); SetFocus();
stop_editingTimeOut_Timer(); stop_editingTimeOut_Timer();
} }
void EDA_3D_CANVAS::OnMiddleUp( wxMouseEvent &event ) void EDA_3D_CANVAS::OnMiddleUp( wxMouseEvent& event )
{ {
if( m_camera_is_moving ) if( m_camera_is_moving )
return; return;
@ -864,7 +858,7 @@ void EDA_3D_CANVAS::OnMiddleUp( wxMouseEvent &event )
} }
void EDA_3D_CANVAS::OnTimerTimeout_Editing( wxTimerEvent &event ) void EDA_3D_CANVAS::OnTimerTimeout_Editing( wxTimerEvent& event )
{ {
(void)event; (void)event;
@ -888,7 +882,7 @@ void EDA_3D_CANVAS::restart_editingTimeOut_Timer()
} }
void EDA_3D_CANVAS::OnTimerTimeout_Redraw( wxTimerEvent &event ) void EDA_3D_CANVAS::OnTimerTimeout_Redraw( wxTimerEvent& event )
{ {
Request_refresh( true ); Request_refresh( true );
} }
@ -1136,7 +1130,7 @@ void EDA_3D_CANVAS::RenderEngineChanged()
{ {
case RENDER_ENGINE::OPENGL_LEGACY: m_3d_render = m_3d_render_ogl_legacy; break; case RENDER_ENGINE::OPENGL_LEGACY: m_3d_render = m_3d_render_ogl_legacy; break;
case RENDER_ENGINE::RAYTRACING: m_3d_render = m_3d_render_raytracing; break; case RENDER_ENGINE::RAYTRACING: m_3d_render = m_3d_render_raytracing; break;
default: m_3d_render = NULL; break; default: m_3d_render = nullptr; break;
} }
if( m_3d_render ) if( m_3d_render )

View File

@ -38,8 +38,8 @@
class WX_INFOBAR; class WX_INFOBAR;
class wxStatusBar; class wxStatusBar;
class BOARD; class BOARD;
class C3D_RENDER_RAYTRACING; class RENDER_3D_RAYTRACE;
class C3D_RENDER_OGL_LEGACY; class RENDER_3D_LEGACY;
/** /**
@ -57,7 +57,7 @@ public:
* @param aSettings the settings options to be used by this canvas. * @param aSettings the settings options to be used by this canvas.
*/ */
EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD* aBoard, EDA_3D_CANVAS( wxWindow* aParent, const int* aAttribList, BOARD* aBoard,
BOARD_ADAPTER& aSettings, CCAMERA& aCamera, S3D_CACHE* a3DCachePointer ); BOARD_ADAPTER& aSettings, CAMERA& aCamera, S3D_CACHE* a3DCachePointer );
~EDA_3D_CANVAS(); ~EDA_3D_CANVAS();
@ -81,7 +81,7 @@ public:
m_parentInfoBar = aInfoBar; m_parentInfoBar = aInfoBar;
} }
void ReloadRequest( BOARD *aBoard = NULL, S3D_CACHE *aCachePointer = NULL ); void ReloadRequest( BOARD* aBoard = nullptr, S3D_CACHE* aCachePointer = nullptr );
/** /**
* Query if there is a pending reload request. * Query if there is a pending reload request.
@ -102,10 +102,11 @@ public:
void RenderRaytracingRequest(); void RenderRaytracingRequest();
/** /**
* Request a screenshot and output it to the aDstImage * Request a screenshot and output it to the \a aDstImage
*
* @param aDstImage - Screenshot destination image * @param aDstImage - Screenshot destination image
*/ */
void GetScreenshot( wxImage &aDstImage ); void GetScreenshot( wxImage& aDstImage );
/** /**
* Helper function to call view commands. * Helper function to call view commands.
@ -183,24 +184,24 @@ private:
*/ */
void DoRePaint(); void DoRePaint();
void OnEraseBackground( wxEraseEvent &event ); void OnEraseBackground( wxEraseEvent& event );
void OnRefreshRequest( wxEvent& aEvent ); void OnRefreshRequest( wxEvent& aEvent );
void OnMouseWheel( wxMouseEvent &event ); void OnMouseWheel( wxMouseEvent& event );
#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
void OnMagnify( wxMouseEvent& event ); void OnMagnify( wxMouseEvent& event );
#endif #endif
void OnMouseMove( wxMouseEvent &event ); void OnMouseMove( wxMouseEvent& event );
void OnLeftDown( wxMouseEvent &event ); void OnLeftDown( wxMouseEvent& event );
void OnLeftUp( wxMouseEvent &event ); void OnLeftUp( wxMouseEvent& event );
void OnMiddleUp( wxMouseEvent &event ); void OnMiddleUp( wxMouseEvent& event );
void OnMiddleDown( wxMouseEvent &event ); void OnMiddleDown( wxMouseEvent& event );
void OnTimerTimeout_Editing( wxTimerEvent& event ); void OnTimerTimeout_Editing( wxTimerEvent& event );
void OnCloseWindow( wxCloseEvent &event ); void OnCloseWindow( wxCloseEvent& event );
void OnResize( wxSizeEvent &event ); void OnResize( wxSizeEvent& event );
void OnTimerTimeout_Redraw( wxTimerEvent& event ); void OnTimerTimeout_Redraw( wxTimerEvent& event );
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
@ -272,10 +273,10 @@ private:
int m_moving_speed_multiplier; // Camera animation speed multiplier option int m_moving_speed_multiplier; // Camera animation speed multiplier option
BOARD_ADAPTER& m_boardAdapter; // Pre-computed 3D info and settings BOARD_ADAPTER& m_boardAdapter; // Pre-computed 3D info and settings
CCAMERA& m_camera; CAMERA& m_camera;
C3D_RENDER_BASE* m_3d_render; RENDER_3D_BASE* m_3d_render;
C3D_RENDER_RAYTRACING* m_3d_render_raytracing; RENDER_3D_RAYTRACE* m_3d_render_raytracing;
C3D_RENDER_OGL_LEGACY* m_3d_render_ogl_legacy; RENDER_3D_LEGACY* m_3d_render_ogl_legacy;
static const float m_delta_move_step_factor; // Step factor to used with cursor on static const float m_delta_move_step_factor; // Step factor to used with cursor on
// relation to the current zoom // relation to the current zoom
@ -283,8 +284,8 @@ private:
bool m_opengl_supports_raytracing; bool m_opengl_supports_raytracing;
bool m_render_raytracing_was_requested; bool m_render_raytracing_was_requested;
CCONTAINER m_3DShapes_container; // Holds 3D shapes from footprints CONTAINER_3D m_3DShapes_container; // Holds 3D shapes from footprints
CGENERICACCELERATOR *m_accelerator3DShapes; // used for mouse over searching ACCELERATOR_3D* m_accelerator3DShapes; // used for mouse over searching
BOARD_ITEM* m_currentIntersectedBoardItem; BOARD_ITEM* m_currentIntersectedBoardItem;
@ -294,7 +295,7 @@ private:
* "KI_TRACE_EDA_3D_CANVAS". See the wxWidgets documentation on wxLogTrace for * "KI_TRACE_EDA_3D_CANVAS". See the wxWidgets documentation on wxLogTrace for
* more information. * more information.
*/ */
static const wxChar *m_logTrace; static const wxChar* m_logTrace;
}; };

View File

@ -117,7 +117,7 @@ C3D_MODEL_VIEWER::~C3D_MODEL_VIEWER()
} }
void C3D_MODEL_VIEWER::Set3DModel( const S3DMODEL &a3DModel ) void C3D_MODEL_VIEWER::Set3DModel( const S3DMODEL& a3DModel )
{ {
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::Set3DModel with a S3DMODEL" ) ); wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::Set3DModel with a S3DMODEL" ) );
@ -144,7 +144,7 @@ void C3D_MODEL_VIEWER::Set3DModel( const S3DMODEL &a3DModel )
} }
void C3D_MODEL_VIEWER::Set3DModel(const wxString &aModelPathName) void C3D_MODEL_VIEWER::Set3DModel(const wxString& aModelPathName)
{ {
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::Set3DModel with a wxString" ) ); wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::Set3DModel with a wxString" ) );
@ -182,7 +182,6 @@ void C3D_MODEL_VIEWER::ogl_initialize()
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
glEnable( GL_DEPTH_TEST ); glEnable( GL_DEPTH_TEST );
//glDepthFunc( GL_LEQUAL );
glEnable( GL_CULL_FACE ); glEnable( GL_CULL_FACE );
glShadeModel( GL_SMOOTH ); glShadeModel( GL_SMOOTH );
glEnable( GL_LINE_SMOOTH ); glEnable( GL_LINE_SMOOTH );
@ -219,7 +218,7 @@ void C3D_MODEL_VIEWER::ogl_set_arrow_material()
} }
void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event ) void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent& event )
{ {
event.Skip( false ); event.Skip( false );
@ -257,7 +256,7 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnPaint m_reload_is_needed" ) ); wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnPaint m_reload_is_needed" ) );
m_reload_is_needed = false; m_reload_is_needed = false;
m_ogl_3dmodel = new C_OGL_3DMODEL( *m_3d_model, MATERIAL_MODE::NORMAL ); m_ogl_3dmodel = new MODEL_3D( *m_3d_model, MATERIAL_MODE::NORMAL );
// It convert a model as it was a board, so get the max size dimension of the board // It convert a model as it was a board, so get the max size dimension of the board
// and compute the conversion scale // and compute the conversion scale
@ -330,15 +329,15 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
ogl_set_arrow_material(); ogl_set_arrow_material();
glColor3f( 0.9f, 0.0f, 0.0f ); glColor3f( 0.9f, 0.0f, 0.0f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( RANGE_SCALE_3D / 2.65f, 0.0f, 0.0f ), DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( RANGE_SCALE_3D / 2.65f, 0.0f, 0.0f ),
0.275f ); 0.275f );
glColor3f( 0.0f, 0.9f, 0.0f ); glColor3f( 0.0f, 0.9f, 0.0f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, RANGE_SCALE_3D / 2.65f, 0.0f ), DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, RANGE_SCALE_3D / 2.65f, 0.0f ),
0.275f ); 0.275f );
glColor3f( 0.0f, 0.0f, 0.9f ); glColor3f( 0.0f, 0.0f, 0.9f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 2.65f ), DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 2.65f ),
0.275f ); 0.275f );
// "Swaps the double-buffer of this window, making the back-buffer the // "Swaps the double-buffer of this window, making the back-buffer the
@ -350,14 +349,14 @@ void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
} }
void C3D_MODEL_VIEWER::OnEraseBackground( wxEraseEvent &event ) void C3D_MODEL_VIEWER::OnEraseBackground( wxEraseEvent& event )
{ {
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnEraseBackground" ) ); wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnEraseBackground" ) );
// Do nothing, to avoid flashing. // Do nothing, to avoid flashing.
} }
void C3D_MODEL_VIEWER::OnMouseWheel( wxMouseEvent &event ) void C3D_MODEL_VIEWER::OnMouseWheel( wxMouseEvent& event )
{ {
wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnMouseWheel" ) ); wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnMouseWheel" ) );
@ -390,19 +389,11 @@ void C3D_MODEL_VIEWER::OnMouseWheel( wxMouseEvent &event )
#ifdef USE_OSX_MAGNIFY_EVENT #ifdef USE_OSX_MAGNIFY_EVENT
void C3D_MODEL_VIEWER::OnMagnify( wxMouseEvent& event ) void C3D_MODEL_VIEWER::OnMagnify( wxMouseEvent& event )
{ {
/*
double magnification = ( event.GetMagnification() + 1.0f );
GetPrm3DVisu().m_Zoom /= magnification;
if( GetPrm3DVisu().m_Zoom <= 0.01 )
GetPrm3DVisu().m_Zoom = 0.01;
DisplayStatus();
Refresh( false );
*/
} }
#endif #endif
void C3D_MODEL_VIEWER::OnMouseMove( wxMouseEvent &event ) void C3D_MODEL_VIEWER::OnMouseMove( wxMouseEvent& event )
{ {
m_trackBallCamera.SetCurWindowSize( GetClientSize() ); m_trackBallCamera.SetCurWindowSize( GetClientSize() );
@ -410,8 +401,6 @@ void C3D_MODEL_VIEWER::OnMouseMove( wxMouseEvent &event )
{ {
if( event.LeftIsDown() ) // Drag if( event.LeftIsDown() ) // Drag
m_trackBallCamera.Drag( event.GetPosition() ); m_trackBallCamera.Drag( event.GetPosition() );
//else if( event.MiddleIsDown() ) // Pan
// m_trackBallCamera.Pan( event.GetPosition() );
// orientation has changed, redraw mesh // orientation has changed, redraw mesh
Refresh( false ); Refresh( false );
@ -421,37 +410,31 @@ void C3D_MODEL_VIEWER::OnMouseMove( wxMouseEvent &event )
} }
void C3D_MODEL_VIEWER::OnLeftDown( wxMouseEvent &event ) void C3D_MODEL_VIEWER::OnLeftDown( wxMouseEvent& event )
{ {
//m_is_moving_mouse = true; event.Skip();
event.Skip(); }
}
void C3D_MODEL_VIEWER::OnLeftUp( wxMouseEvent& event )
void C3D_MODEL_VIEWER::OnLeftUp( wxMouseEvent &event ) {
{ event.Skip();
//m_is_moving_mouse = false; }
//Refresh( false );
event.Skip();
} void C3D_MODEL_VIEWER::OnMiddleDown( wxMouseEvent& event )
{
event.Skip();
void C3D_MODEL_VIEWER::OnMiddleDown( wxMouseEvent &event ) }
{
//m_is_moving_mouse = true;
event.Skip(); void C3D_MODEL_VIEWER::OnMiddleUp( wxMouseEvent& event )
} {
event.Skip();
}
void C3D_MODEL_VIEWER::OnMiddleUp( wxMouseEvent &event )
{
//m_is_moving_mouse = false; void C3D_MODEL_VIEWER::OnRightClick( wxMouseEvent& event )
//Refresh( false );
event.Skip();
}
void C3D_MODEL_VIEWER::OnRightClick( wxMouseEvent &event )
{ {
event.Skip(); event.Skip();
} }

View File

@ -37,7 +37,7 @@
#include <gal/hidpi_gl_canvas.h> #include <gal/hidpi_gl_canvas.h>
class S3D_CACHE; class S3D_CACHE;
class C_OGL_3DMODEL; class MODEL_3D;
/** /**
* Implement a canvas based on a wxGLCanvas. * Implement a canvas based on a wxGLCanvas.
@ -49,7 +49,7 @@ public:
* Create a new 3D Canvas with a attribute list. * Create a new 3D Canvas with a attribute list.
* *
* @param aParent the parent creator of this canvas. * @param aParent the parent creator of this canvas.
* @param aAttribList a list of openGL options created by #COGL_ATT_LIST::GetAttributesList. * @param aAttribList a list of openGL options created by #OGL_ATT_LIST::GetAttributesList.
*/ */
C3D_MODEL_VIEWER( wxWindow* aParent, const int* aAttribList = 0, C3D_MODEL_VIEWER( wxWindow* aParent, const int* aAttribList = 0,
S3D_CACHE* aCacheManager = nullptr ); S3D_CACHE* aCacheManager = nullptr );
@ -107,13 +107,13 @@ private:
wxGLContext* m_glRC; wxGLContext* m_glRC;
/// Camera used in this canvas /// Camera used in this canvas
CTRACK_BALL m_trackBallCamera; TRACK_BALL m_trackBallCamera;
/// Original 3d model data /// Original 3d model data
const S3DMODEL* m_3d_model; const S3DMODEL* m_3d_model;
/// Class holder for 3d model to display on openGL /// Class holder for 3d model to display on openGL
C_OGL_3DMODEL* m_ogl_3dmodel; MODEL_3D* m_ogl_3dmodel;
/// Flag that we have a new model and it need to be reloaded when the paint is called /// Flag that we have a new model and it need to be reloaded when the paint is called
bool m_reload_is_needed; bool m_reload_is_needed;

View File

@ -32,11 +32,11 @@
#include <profile.h> // To use GetRunningMicroSecs or another profiling utility #include <profile.h> // To use GetRunningMicroSecs or another profiling utility
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CFILLEDCIRCLE2D * aFilledCircle, void RENDER_3D_LEGACY::add_object_to_triangle_layer( const FILLED_CIRCLE_2D* aFilledCircle,
CLAYER_TRIANGLES *aDstLayer, TRIANGLE_DISPLAY_LIST* aDstLayer,
float aZtop, float aZbot ) float aZtop, float aZbot )
{ {
const SFVEC2F &center = aFilledCircle->GetCenter(); const SFVEC2F& center = aFilledCircle->GetCenter();
const float radius = aFilledCircle->GetRadius() * const float radius = aFilledCircle->GetRadius() *
2.0f; // Double because the render triangle 2.0f; // Double because the render triangle
@ -63,25 +63,24 @@ void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CFILLEDCIRCLE2D
} }
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CPOLYGON4PTS2D * aPoly, void RENDER_3D_LEGACY::add_object_to_triangle_layer( const POLYGON_4PT_2D* aPoly,
CLAYER_TRIANGLES *aDstLayer, TRIANGLE_DISPLAY_LIST* aDstLayer,
float aZtop, float aZbot ) float aZtop, float aZbot )
{ {
const SFVEC2F &v0 = aPoly->GetV0(); const SFVEC2F& v0 = aPoly->GetV0();
const SFVEC2F &v1 = aPoly->GetV1(); const SFVEC2F& v1 = aPoly->GetV1();
const SFVEC2F &v2 = aPoly->GetV2(); const SFVEC2F& v2 = aPoly->GetV2();
const SFVEC2F &v3 = aPoly->GetV3(); const SFVEC2F& v3 = aPoly->GetV3();
add_triangle_top_bot( aDstLayer, v0, v2, v1, aZtop, aZbot ); add_triangle_top_bot( aDstLayer, v0, v2, v1, aZtop, aZbot );
add_triangle_top_bot( aDstLayer, v2, v0, v3, aZtop, aZbot ); add_triangle_top_bot( aDstLayer, v2, v0, v3, aZtop, aZbot );
} }
void C3D_RENDER_OGL_LEGACY::generate_ring_contour( const SFVEC2F &aCenter, void RENDER_3D_LEGACY::generate_ring_contour( const SFVEC2F& aCenter, float aInnerRadius,
float aInnerRadius, float aOuterRadius, float aOuterRadius, unsigned int aNr_sides_per_circle,
unsigned int aNr_sides_per_circle, std::vector< SFVEC2F >& aInnerContourResult,
std::vector< SFVEC2F > &aInnerContourResult, std::vector< SFVEC2F >& aOuterContourResult,
std::vector< SFVEC2F > &aOuterContourResult,
bool aInvertOrder ) bool aInvertOrder )
{ {
aInnerContourResult.clear(); aInnerContourResult.clear();
@ -112,32 +111,27 @@ void C3D_RENDER_OGL_LEGACY::generate_ring_contour( const SFVEC2F &aCenter,
} }
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CRING2D * aRing, void RENDER_3D_LEGACY::add_object_to_triangle_layer( const RING_2D* aRing,
CLAYER_TRIANGLES *aDstLayer, TRIANGLE_DISPLAY_LIST* aDstLayer,
float aZtop, float aZbot ) float aZtop, float aZbot )
{ {
const SFVEC2F &center = aRing->GetCenter(); const SFVEC2F& center = aRing->GetCenter();
const float inner = aRing->GetInnerRadius(); const float inner = aRing->GetInnerRadius();
const float outer = aRing->GetOuterRadius(); const float outer = aRing->GetOuterRadius();
std::vector< SFVEC2F > innerContour; std::vector< SFVEC2F > innerContour;
std::vector< SFVEC2F > outerContour; std::vector< SFVEC2F > outerContour;
generate_ring_contour( center, generate_ring_contour( center, inner, outer, m_boardAdapter.GetNrSegmentsCircle( outer * 2.0f ),
inner, innerContour, outerContour, false );
outer,
m_boardAdapter.GetNrSegmentsCircle( outer * 2.0f ),
innerContour,
outerContour,
false );
// This will add the top and bot quads that will form the approximated ring // This will add the top and bot quads that will form the approximated ring
for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i ) for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
{ {
const SFVEC2F &vi0 = innerContour[i + 0]; const SFVEC2F& vi0 = innerContour[i + 0];
const SFVEC2F &vi1 = innerContour[i + 1]; const SFVEC2F& vi1 = innerContour[i + 1];
const SFVEC2F &vo0 = outerContour[i + 0]; const SFVEC2F& vo0 = outerContour[i + 0];
const SFVEC2F &vo1 = outerContour[i + 1]; const SFVEC2F& vo1 = outerContour[i + 1];
aDstLayer->m_layer_top_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZtop ), aDstLayer->m_layer_top_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZtop ),
SFVEC3F( vi0.x, vi0.y, aZtop ), SFVEC3F( vi0.x, vi0.y, aZtop ),
@ -152,20 +146,20 @@ void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CRING2D * aRing,
} }
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CTRIANGLE2D * aTri, void RENDER_3D_LEGACY::add_object_to_triangle_layer( const TRIANGLE_2D* aTri,
CLAYER_TRIANGLES *aDstLayer, TRIANGLE_DISPLAY_LIST* aDstLayer,
float aZtop, float aZbot ) float aZtop, float aZbot )
{ {
const SFVEC2F &v1 = aTri->GetP1(); const SFVEC2F& v1 = aTri->GetP1();
const SFVEC2F &v2 = aTri->GetP2(); const SFVEC2F& v2 = aTri->GetP2();
const SFVEC2F &v3 = aTri->GetP3(); const SFVEC2F& v3 = aTri->GetP3();
add_triangle_top_bot( aDstLayer, v1, v2, v3, aZtop, aZbot ); add_triangle_top_bot( aDstLayer, v1, v2, v3, aZtop, aZbot );
} }
void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CROUNDSEGMENT2D * aSeg, void RENDER_3D_LEGACY::add_object_to_triangle_layer( const ROUND_SEGMENT_2D* aSeg,
CLAYER_TRIANGLES *aDstLayer, TRIANGLE_DISPLAY_LIST* aDstLayer,
float aZtop, float aZbot ) float aZtop, float aZbot )
{ {
const SFVEC2F& leftStart = aSeg->GetLeftStar(); const SFVEC2F& leftStart = aSeg->GetLeftStar();
@ -249,44 +243,41 @@ void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CROUNDSEGMENT2D
} }
CLAYERS_OGL_DISP_LISTS *C3D_RENDER_OGL_LEGACY::generate_holes_display_list( OPENGL_RENDER_LIST* RENDER_3D_LEGACY::generate_holes_display_list(
const LIST_OBJECT2D &aListHolesObject2d, const LIST_OBJECT2D& aListHolesObject2d, const SHAPE_POLY_SET& aPoly,
const SHAPE_POLY_SET &aPoly, float aZtop, float aZbot, bool aInvertFaces, const BVH_CONTAINER_2D* aThroughHoles )
float aZtop,
float aZbot,
bool aInvertFaces,
const CBVHCONTAINER2D *aThroughHoles )
{ {
CLAYERS_OGL_DISP_LISTS *ret = NULL; OPENGL_RENDER_LIST* ret = nullptr;
if( aListHolesObject2d.size() > 0 ) if( aListHolesObject2d.size() > 0 )
{ {
CLAYER_TRIANGLES *layerTriangles = new CLAYER_TRIANGLES( aListHolesObject2d.size() * 2 ); TRIANGLE_DISPLAY_LIST* layerTriangles =
new TRIANGLE_DISPLAY_LIST( aListHolesObject2d.size() * 2 );
// Convert the list of objects(filled circles) to triangle layer structure // Convert the list of objects(filled circles) to triangle layer structure
for( LIST_OBJECT2D::const_iterator itemOnLayer = aListHolesObject2d.begin(); for( LIST_OBJECT2D::const_iterator itemOnLayer = aListHolesObject2d.begin();
itemOnLayer != aListHolesObject2d.end(); itemOnLayer != aListHolesObject2d.end();
++itemOnLayer ) ++itemOnLayer )
{ {
const COBJECT2D* object2d_A = static_cast<const COBJECT2D*>( *itemOnLayer ); const OBJECT_2D* object2d_A = static_cast<const OBJECT_2D*>( *itemOnLayer );
wxASSERT( ( object2d_A->GetObjectType() == OBJECT2D_TYPE::FILLED_CIRCLE ) wxASSERT( ( object2d_A->GetObjectType() == OBJECT_2D_TYPE::FILLED_CIRCLE )
|| ( object2d_A->GetObjectType() == OBJECT2D_TYPE::ROUNDSEG ) ); || ( object2d_A->GetObjectType() == OBJECT_2D_TYPE::ROUNDSEG ) );
switch( object2d_A->GetObjectType() ) switch( object2d_A->GetObjectType() )
{ {
case OBJECT2D_TYPE::FILLED_CIRCLE: case OBJECT_2D_TYPE::FILLED_CIRCLE:
add_object_to_triangle_layer( static_cast<const CFILLEDCIRCLE2D*>( object2d_A ), add_object_to_triangle_layer( static_cast<const FILLED_CIRCLE_2D*>( object2d_A ),
layerTriangles, aZtop, aZbot ); layerTriangles, aZtop, aZbot );
break; break;
case OBJECT2D_TYPE::ROUNDSEG: case OBJECT_2D_TYPE::ROUNDSEG:
add_object_to_triangle_layer( static_cast<const CROUNDSEGMENT2D*>( object2d_A ), add_object_to_triangle_layer( static_cast<const ROUND_SEGMENT_2D*>( object2d_A ),
layerTriangles, aZtop, aZbot ); layerTriangles, aZtop, aZbot );
break; break;
default: default:
wxFAIL_MSG( "C3D_RENDER_OGL_LEGACY::generate_holes_display_list: " wxFAIL_MSG( "RENDER_3D_LEGACY::generate_holes_display_list: "
"Object type is not implemented" ); "Object type is not implemented" );
break; break;
} }
@ -301,7 +292,7 @@ CLAYERS_OGL_DISP_LISTS *C3D_RENDER_OGL_LEGACY::generate_holes_display_list(
aInvertFaces, aThroughHoles ); aInvertFaces, aThroughHoles );
} }
ret = new CLAYERS_OGL_DISP_LISTS( *layerTriangles, m_ogl_circle_texture, aZbot, aZtop ); ret = new OPENGL_RENDER_LIST( *layerTriangles, m_ogl_circle_texture, aZbot, aZtop );
delete layerTriangles; delete layerTriangles;
} }
@ -310,16 +301,16 @@ CLAYERS_OGL_DISP_LISTS *C3D_RENDER_OGL_LEGACY::generate_holes_display_list(
} }
CLAYERS_OGL_DISP_LISTS* OPENGL_RENDER_LIST*
C3D_RENDER_OGL_LEGACY::generateLayerListFromContainer( const CBVHCONTAINER2D *aContainer, RENDER_3D_LEGACY::generateLayerListFromContainer( const BVH_CONTAINER_2D* aContainer,
const SHAPE_POLY_SET *aPolyList, const SHAPE_POLY_SET* aPolyList,
PCB_LAYER_ID aLayerId, PCB_LAYER_ID aLayerId,
const CBVHCONTAINER2D *aThroughHoles ) const BVH_CONTAINER_2D* aThroughHoles )
{ {
if( aContainer == nullptr ) if( aContainer == nullptr )
return nullptr; return nullptr;
const LIST_OBJECT2D &listObject2d = aContainer->GetList(); const LIST_OBJECT2D& listObject2d = aContainer->GetList();
if( listObject2d.size() == 0 ) if( listObject2d.size() == 0 )
return nullptr; return nullptr;
@ -332,7 +323,7 @@ C3D_RENDER_OGL_LEGACY::generateLayerListFromContainer( const CBVHCONTAINER2D *aC
// Calculate an estimation for the nr of triangles based on the nr of objects // Calculate an estimation for the nr of triangles based on the nr of objects
unsigned int nrTrianglesEstimation = listObject2d.size() * 8; unsigned int nrTrianglesEstimation = listObject2d.size() * 8;
CLAYER_TRIANGLES *layerTriangles = new CLAYER_TRIANGLES( nrTrianglesEstimation ); TRIANGLE_DISPLAY_LIST* layerTriangles = new TRIANGLE_DISPLAY_LIST( nrTrianglesEstimation );
// store in a list so it will be latter deleted // store in a list so it will be latter deleted
m_triangles.push_back( layerTriangles ); m_triangles.push_back( layerTriangles );
@ -342,37 +333,37 @@ C3D_RENDER_OGL_LEGACY::generateLayerListFromContainer( const CBVHCONTAINER2D *aC
itemOnLayer != listObject2d.end(); itemOnLayer != listObject2d.end();
++itemOnLayer ) ++itemOnLayer )
{ {
const COBJECT2D *object2d_A = static_cast<const COBJECT2D *>(*itemOnLayer); const OBJECT_2D* object2d_A = static_cast<const OBJECT_2D*>( *itemOnLayer );
switch( object2d_A->GetObjectType() ) switch( object2d_A->GetObjectType() )
{ {
case OBJECT2D_TYPE::FILLED_CIRCLE: case OBJECT_2D_TYPE::FILLED_CIRCLE:
add_object_to_triangle_layer( (const CFILLEDCIRCLE2D *)object2d_A, add_object_to_triangle_layer( (const FILLED_CIRCLE_2D *)object2d_A,
layerTriangles, layer_z_top, layer_z_bot ); layerTriangles, layer_z_top, layer_z_bot );
break; break;
case OBJECT2D_TYPE::POLYGON4PT: case OBJECT_2D_TYPE::POLYGON4PT:
add_object_to_triangle_layer( (const CPOLYGON4PTS2D *)object2d_A, add_object_to_triangle_layer( (const POLYGON_4PT_2D*)object2d_A,
layerTriangles, layer_z_top, layer_z_bot ); layerTriangles, layer_z_top, layer_z_bot );
break; break;
case OBJECT2D_TYPE::RING: case OBJECT_2D_TYPE::RING:
add_object_to_triangle_layer( (const CRING2D *)object2d_A, add_object_to_triangle_layer( (const RING_2D*)object2d_A,
layerTriangles, layer_z_top, layer_z_bot ); layerTriangles, layer_z_top, layer_z_bot );
break; break;
case OBJECT2D_TYPE::TRIANGLE: case OBJECT_2D_TYPE::TRIANGLE:
add_object_to_triangle_layer( (const CTRIANGLE2D *)object2d_A, add_object_to_triangle_layer( (const TRIANGLE_2D*)object2d_A,
layerTriangles, layer_z_top, layer_z_bot ); layerTriangles, layer_z_top, layer_z_bot );
break; break;
case OBJECT2D_TYPE::ROUNDSEG: case OBJECT_2D_TYPE::ROUNDSEG:
add_object_to_triangle_layer( (const CROUNDSEGMENT2D *) object2d_A, add_object_to_triangle_layer( (const ROUND_SEGMENT_2D*) object2d_A,
layerTriangles, layer_z_top, layer_z_bot ); layerTriangles, layer_z_top, layer_z_bot );
break; break;
default: default:
wxFAIL_MSG("C3D_RENDER_OGL_LEGACY: Object type is not implemented"); wxFAIL_MSG( "RENDER_3D_LEGACY: Object type is not implemented" );
break; break;
} }
} }
@ -384,23 +375,23 @@ C3D_RENDER_OGL_LEGACY::generateLayerListFromContainer( const CBVHCONTAINER2D *aC
} }
// Create display list // Create display list
return new CLAYERS_OGL_DISP_LISTS( *layerTriangles, m_ogl_circle_texture, layer_z_bot, return new OPENGL_RENDER_LIST( *layerTriangles, m_ogl_circle_texture, layer_z_bot,
layer_z_top ); layer_z_top );
} }
CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::createBoard( const SHAPE_POLY_SET& aBoardPoly, OPENGL_RENDER_LIST* RENDER_3D_LEGACY::createBoard( const SHAPE_POLY_SET& aBoardPoly,
const CBVHCONTAINER2D *aThroughHoles ) const BVH_CONTAINER_2D* aThroughHoles )
{ {
CLAYERS_OGL_DISP_LISTS* dispLists = nullptr; OPENGL_RENDER_LIST* dispLists = nullptr;
CCONTAINER2D boardContainer; CONTAINER_2D boardContainer;
SHAPE_POLY_SET brd_outlines = aBoardPoly; SHAPE_POLY_SET brd_outlines = aBoardPoly;
Convert_shape_line_polygon_to_triangles( brd_outlines, boardContainer, Convert_shape_line_polygon_to_triangles( brd_outlines, boardContainer,
m_boardAdapter.BiuTo3Dunits(), m_boardAdapter.BiuTo3Dunits(),
(const BOARD_ITEM &)*m_boardAdapter.GetBoard() ); (const BOARD_ITEM &)*m_boardAdapter.GetBoard() );
const LIST_OBJECT2D &listBoardObject2d = boardContainer.GetList(); const LIST_OBJECT2D& listBoardObject2d = boardContainer.GetList();
if( listBoardObject2d.size() > 0 ) if( listBoardObject2d.size() > 0 )
{ {
@ -410,22 +401,23 @@ CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::createBoard( const SHAPE_POLY_SET
const float layer_z_top = 1.0f; const float layer_z_top = 1.0f;
const float layer_z_bot = 0.0f; const float layer_z_bot = 0.0f;
CLAYER_TRIANGLES *layerTriangles = new CLAYER_TRIANGLES( listBoardObject2d.size() ); TRIANGLE_DISPLAY_LIST* layerTriangles =
new TRIANGLE_DISPLAY_LIST( listBoardObject2d.size() );
// Convert the list of objects(triangles) to triangle layer structure // Convert the list of objects(triangles) to triangle layer structure
for( LIST_OBJECT2D::const_iterator itemOnLayer = listBoardObject2d.begin(); for( LIST_OBJECT2D::const_iterator itemOnLayer = listBoardObject2d.begin();
itemOnLayer != listBoardObject2d.end(); itemOnLayer != listBoardObject2d.end();
++itemOnLayer ) ++itemOnLayer )
{ {
const COBJECT2D* object2d_A = static_cast<const COBJECT2D*>( *itemOnLayer ); const OBJECT_2D* object2d_A = static_cast<const OBJECT_2D*>( *itemOnLayer );
wxASSERT( object2d_A->GetObjectType() == OBJECT2D_TYPE::TRIANGLE ); wxASSERT( object2d_A->GetObjectType() == OBJECT_2D_TYPE::TRIANGLE );
const CTRIANGLE2D *tri = (const CTRIANGLE2D *)object2d_A; const TRIANGLE_2D* tri = (const TRIANGLE_2D *)object2d_A;
const SFVEC2F &v1 = tri->GetP1(); const SFVEC2F& v1 = tri->GetP1();
const SFVEC2F &v2 = tri->GetP2(); const SFVEC2F& v2 = tri->GetP2();
const SFVEC2F &v3 = tri->GetP3(); const SFVEC2F& v3 = tri->GetP3();
add_triangle_top_bot( layerTriangles, v1, v2, v3, layer_z_top, layer_z_bot ); add_triangle_top_bot( layerTriangles, v1, v2, v3, layer_z_top, layer_z_bot );
} }
@ -436,7 +428,7 @@ CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::createBoard( const SHAPE_POLY_SET
m_boardAdapter.BiuTo3Dunits(), false, m_boardAdapter.BiuTo3Dunits(), false,
aThroughHoles ); aThroughHoles );
dispLists = new CLAYERS_OGL_DISP_LISTS( *layerTriangles, m_ogl_circle_texture, dispLists = new OPENGL_RENDER_LIST( *layerTriangles, m_ogl_circle_texture,
layer_z_top, layer_z_top ); layer_z_top, layer_z_top );
} }
@ -447,13 +439,13 @@ CLAYERS_OGL_DISP_LISTS* C3D_RENDER_OGL_LEGACY::createBoard( const SHAPE_POLY_SET
} }
void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter ) void RENDER_3D_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter )
{ {
m_reloadRequested = false; m_reloadRequested = false;
ogl_free_all_display_lists(); ogl_free_all_display_lists();
COBJECT2D_STATS::Instance().ResetStats(); OBJECT_2D_STATS::Instance().ResetStats();
unsigned stats_startReloadTime = GetRunningMicroSecs(); unsigned stats_startReloadTime = GetRunningMicroSecs();
@ -536,12 +528,12 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
// m_boardAdapter.GetThroughHole_Vias_Inner_poly(), // m_boardAdapter.GetThroughHole_Vias_Inner_poly(),
// 1.0f, 0.0f, // 1.0f, 0.0f,
// false ); // false );
const MAP_POLY & innerMapHoles = m_boardAdapter.GetPolyMapHoles_Inner(); const MAP_POLY& innerMapHoles = m_boardAdapter.GetPolyMapHoles_Inner();
const MAP_POLY & outerMapHoles = m_boardAdapter.GetPolyMapHoles_Outer(); const MAP_POLY& outerMapHoles = m_boardAdapter.GetPolyMapHoles_Outer();
wxASSERT( innerMapHoles.size() == outerMapHoles.size() ); wxASSERT( innerMapHoles.size() == outerMapHoles.size() );
const MAP_CONTAINER_2D &map_holes = m_boardAdapter.GetMapLayersHoles(); const MAP_CONTAINER_2D_BASE& map_holes = m_boardAdapter.GetMapLayersHoles();
if( outerMapHoles.size() > 0 ) if( outerMapHoles.size() > 0 )
{ {
@ -552,7 +544,7 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
{ {
PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first); PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>(ii->first);
const SHAPE_POLY_SET* poly = static_cast<const SHAPE_POLY_SET*>( ii->second ); const SHAPE_POLY_SET* poly = static_cast<const SHAPE_POLY_SET*>( ii->second );
const CBVHCONTAINER2D* container = map_holes.at( layer_id ); const BVH_CONTAINER_2D* container = map_holes.at( layer_id );
get_layer_z_pos( layer_id, layer_z_top, layer_z_bot ); get_layer_z_pos( layer_id, layer_z_top, layer_z_bot );
@ -565,7 +557,7 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
{ {
PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>( ii->first ); PCB_LAYER_ID layer_id = static_cast<PCB_LAYER_ID>( ii->first );
const SHAPE_POLY_SET* poly = static_cast<const SHAPE_POLY_SET*>( ii->second ); const SHAPE_POLY_SET* poly = static_cast<const SHAPE_POLY_SET*>( ii->second );
const CBVHCONTAINER2D* container = map_holes.at( layer_id ); const BVH_CONTAINER_2D* container = map_holes.at( layer_id );
get_layer_z_pos( layer_id, layer_z_top, layer_z_bot ); get_layer_z_pos( layer_id, layer_z_top, layer_z_bot );
@ -582,9 +574,9 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
if( aStatusReporter ) if( aStatusReporter )
aStatusReporter->Report( _( "Load OpenGL: layers" ) ); aStatusReporter->Report( _( "Load OpenGL: layers" ) );
const MAP_POLY &map_poly = m_boardAdapter.GetPolyMap(); const MAP_POLY& map_poly = m_boardAdapter.GetPolyMap();
for( MAP_CONTAINER_2D::const_iterator ii = m_boardAdapter.GetMapLayers().begin(); for( MAP_CONTAINER_2D_BASE::const_iterator ii = m_boardAdapter.GetMapLayers().begin();
ii != m_boardAdapter.GetMapLayers().end(); ii != m_boardAdapter.GetMapLayers().end();
++ii ) ++ii )
{ {
@ -593,10 +585,10 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
if( !m_boardAdapter.Is3DLayerEnabled( layer_id ) ) if( !m_boardAdapter.Is3DLayerEnabled( layer_id ) )
continue; continue;
const CBVHCONTAINER2D* container2d = static_cast<const CBVHCONTAINER2D*>( ii->second ); const BVH_CONTAINER_2D* container2d = static_cast<const BVH_CONTAINER_2D*>( ii->second );
SHAPE_POLY_SET polyListSubtracted; SHAPE_POLY_SET polyListSubtracted;
SHAPE_POLY_SET *aPolyList = nullptr; SHAPE_POLY_SET* aPolyList = nullptr;
// Load the vertical (Z axis) component of shapes // Load the vertical (Z axis) component of shapes
@ -638,7 +630,7 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
aPolyList = &polyListSubtracted; aPolyList = &polyListSubtracted;
} }
CLAYERS_OGL_DISP_LISTS* oglList = generateLayerListFromContainer( OPENGL_RENDER_LIST* oglList = generateLayerListFromContainer(
container2d, aPolyList, container2d, aPolyList,
layer_id, layer_id,
&m_boardAdapter.GetThroughHole_Inner() ); &m_boardAdapter.GetThroughHole_Inner() );
@ -698,12 +690,9 @@ void C3D_RENDER_OGL_LEGACY::reload( REPORTER* aStatusReporter, REPORTER* aWarnin
} }
void C3D_RENDER_OGL_LEGACY::add_triangle_top_bot( CLAYER_TRIANGLES *aDst, void RENDER_3D_LEGACY::add_triangle_top_bot( TRIANGLE_DISPLAY_LIST* aDst, const SFVEC2F& v0,
const SFVEC2F &v0, const SFVEC2F& v1, const SFVEC2F& v2,
const SFVEC2F &v1, float top, float bot )
const SFVEC2F &v2,
float top,
float bot )
{ {
aDst->m_layer_bot_triangles->AddTriangle( SFVEC3F( v0.x, v0.y, bot ), aDst->m_layer_bot_triangles->AddTriangle( SFVEC3F( v0.x, v0.y, bot ),
SFVEC3F( v1.x, v1.y, bot ), SFVEC3F( v1.x, v1.y, bot ),
@ -715,9 +704,8 @@ void C3D_RENDER_OGL_LEGACY::add_triangle_top_bot( CLAYER_TRIANGLES *aDst,
} }
void C3D_RENDER_OGL_LEGACY::get_layer_z_pos ( PCB_LAYER_ID aLayerID, void RENDER_3D_LEGACY::get_layer_z_pos ( PCB_LAYER_ID aLayerID, float& aOutZtop,
float &aOutZtop, float& aOutZbot ) const
float &aOutZbot ) const
{ {
aOutZbot = m_boardAdapter.GetLayerBottomZpos3DU( aLayerID ); aOutZbot = m_boardAdapter.GetLayerBottomZpos3DU( aLayerID );
aOutZtop = m_boardAdapter.GetLayerTopZpos3DU( aLayerID ); aOutZtop = m_boardAdapter.GetLayerTopZpos3DU( aLayerID );
@ -731,13 +719,10 @@ void C3D_RENDER_OGL_LEGACY::get_layer_z_pos ( PCB_LAYER_ID aLayerID,
} }
void C3D_RENDER_OGL_LEGACY::generate_cylinder( const SFVEC2F &aCenter, void RENDER_3D_LEGACY::generate_cylinder( const SFVEC2F& aCenter, float aInnerRadius,
float aInnerRadius, float aOuterRadius, float aZtop, float aZbot,
float aOuterRadius,
float aZtop,
float aZbot,
unsigned int aNr_sides_per_circle, unsigned int aNr_sides_per_circle,
CLAYER_TRIANGLES *aDstLayer ) TRIANGLE_DISPLAY_LIST* aDstLayer )
{ {
std::vector< SFVEC2F > innerContour; std::vector< SFVEC2F > innerContour;
std::vector< SFVEC2F > outerContour; std::vector< SFVEC2F > outerContour;
@ -747,10 +732,10 @@ void C3D_RENDER_OGL_LEGACY::generate_cylinder( const SFVEC2F &aCenter,
for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i ) for( unsigned int i = 0; i < ( innerContour.size() - 1 ); ++i )
{ {
const SFVEC2F &vi0 = innerContour[i + 0]; const SFVEC2F& vi0 = innerContour[i + 0];
const SFVEC2F &vi1 = innerContour[i + 1]; const SFVEC2F& vi1 = innerContour[i + 1];
const SFVEC2F &vo0 = outerContour[i + 0]; const SFVEC2F& vo0 = outerContour[i + 0];
const SFVEC2F &vo1 = outerContour[i + 1]; const SFVEC2F& vo1 = outerContour[i + 1];
aDstLayer->m_layer_top_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZtop ), aDstLayer->m_layer_top_triangles->AddQuad( SFVEC3F( vi1.x, vi1.y, aZtop ),
SFVEC3F( vi0.x, vi0.y, aZtop ), SFVEC3F( vi0.x, vi0.y, aZtop ),
@ -768,7 +753,7 @@ void C3D_RENDER_OGL_LEGACY::generate_cylinder( const SFVEC2F &aCenter,
} }
void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads() void RENDER_3D_LEGACY::generate_3D_Vias_and_Pads()
{ {
if( m_boardAdapter.GetStats_Nr_Vias() ) if( m_boardAdapter.GetStats_Nr_Vias() )
{ {
@ -777,8 +762,8 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
m_boardAdapter.GetStats_Med_Via_Hole_Diameter3DU() ) * 8 * m_boardAdapter.GetStats_Med_Via_Hole_Diameter3DU() ) * 8 *
m_boardAdapter.GetStats_Nr_Vias(); m_boardAdapter.GetStats_Nr_Vias();
CLAYER_TRIANGLES *layerTriangleVIA = TRIANGLE_DISPLAY_LIST* layerTriangleVIA =
new CLAYER_TRIANGLES( reserve_nr_triangles_estimation ); new TRIANGLE_DISPLAY_LIST( reserve_nr_triangles_estimation );
// Insert plated vertical holes inside the board // Insert plated vertical holes inside the board
@ -787,7 +772,7 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
{ {
if( track->Type() == PCB_VIA_T ) if( track->Type() == PCB_VIA_T )
{ {
const VIA *via = static_cast<const VIA*>(track); const VIA* via = static_cast<const VIA*>(track);
const float holediameter = via->GetDrillValue() * m_boardAdapter.BiuTo3Dunits(); const float holediameter = via->GetDrillValue() * m_boardAdapter.BiuTo3Dunits();
const float thickness = m_boardAdapter.GetCopperThickness3DU(); const float thickness = m_boardAdapter.GetCopperThickness3DU();
@ -812,7 +797,7 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
} }
} }
m_vias = new CLAYERS_OGL_DISP_LISTS( *layerTriangleVIA, 0, 0.0f, 0.0f ); m_vias = new OPENGL_RENDER_LIST( *layerTriangleVIA, 0, 0.0f, 0.0f );
delete layerTriangleVIA; delete layerTriangleVIA;
} }
@ -856,13 +841,13 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ) if( m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) )
tht_outer_holes_poly.BooleanSubtract( m_anti_board_poly, SHAPE_POLY_SET::PM_FAST ); tht_outer_holes_poly.BooleanSubtract( m_anti_board_poly, SHAPE_POLY_SET::PM_FAST );
CCONTAINER2D holesContainer; CONTAINER_2D holesContainer;
Convert_shape_line_polygon_to_triangles( tht_outer_holes_poly, holesContainer, Convert_shape_line_polygon_to_triangles( tht_outer_holes_poly, holesContainer,
m_boardAdapter.BiuTo3Dunits(), m_boardAdapter.BiuTo3Dunits(),
(const BOARD_ITEM &)*m_boardAdapter.GetBoard() ); (const BOARD_ITEM &)*m_boardAdapter.GetBoard() );
const LIST_OBJECT2D &listHolesObject2d = holesContainer.GetList(); const LIST_OBJECT2D& listHolesObject2d = holesContainer.GetList();
if( listHolesObject2d.size() > 0 ) if( listHolesObject2d.size() > 0 )
{ {
@ -871,22 +856,23 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
get_layer_z_pos( F_Cu, layer_z_top, dummy ); get_layer_z_pos( F_Cu, layer_z_top, dummy );
get_layer_z_pos( B_Cu, dummy, layer_z_bot ); get_layer_z_pos( B_Cu, dummy, layer_z_bot );
CLAYER_TRIANGLES *layerTriangles = new CLAYER_TRIANGLES( listHolesObject2d.size() ); TRIANGLE_DISPLAY_LIST* layerTriangles =
new TRIANGLE_DISPLAY_LIST( listHolesObject2d.size() );
// Convert the list of objects(triangles) to triangle layer structure // Convert the list of objects(triangles) to triangle layer structure
for( LIST_OBJECT2D::const_iterator itemOnLayer = listHolesObject2d.begin(); for( LIST_OBJECT2D::const_iterator itemOnLayer = listHolesObject2d.begin();
itemOnLayer != listHolesObject2d.end(); itemOnLayer != listHolesObject2d.end();
++itemOnLayer ) ++itemOnLayer )
{ {
const COBJECT2D *object2d_A = static_cast<const COBJECT2D *>(*itemOnLayer); const OBJECT_2D* object2d_A = static_cast<const OBJECT_2D*>( *itemOnLayer );
wxASSERT( object2d_A->GetObjectType() == OBJECT2D_TYPE::TRIANGLE ); wxASSERT( object2d_A->GetObjectType() == OBJECT_2D_TYPE::TRIANGLE );
const CTRIANGLE2D *tri = (const CTRIANGLE2D *)object2d_A; const TRIANGLE_2D* tri = (const TRIANGLE_2D *)object2d_A;
const SFVEC2F &v1 = tri->GetP1(); const SFVEC2F& v1 = tri->GetP1();
const SFVEC2F &v2 = tri->GetP2(); const SFVEC2F& v2 = tri->GetP2();
const SFVEC2F &v3 = tri->GetP3(); const SFVEC2F& v3 = tri->GetP3();
add_triangle_top_bot( layerTriangles, v1, v2, v3, layer_z_top, layer_z_bot ); add_triangle_top_bot( layerTriangles, v1, v2, v3, layer_z_top, layer_z_bot );
} }
@ -899,7 +885,7 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
layer_z_bot, layer_z_top, layer_z_bot, layer_z_top,
m_boardAdapter.BiuTo3Dunits(), false ); m_boardAdapter.BiuTo3Dunits(), false );
m_pad_holes = new CLAYERS_OGL_DISP_LISTS( *layerTriangles, m_pad_holes = new OPENGL_RENDER_LIST( *layerTriangles,
m_ogl_circle_texture, // not need m_ogl_circle_texture, // not need
layer_z_top, layer_z_top ); layer_z_top, layer_z_top );
} }
@ -910,7 +896,7 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads()
} }
void C3D_RENDER_OGL_LEGACY::load_3D_models( REPORTER* aStatusReporter ) void RENDER_3D_LEGACY::load_3D_models( REPORTER* aStatusReporter )
{ {
if( !m_boardAdapter.GetFlag( FL_FP_ATTRIBUTES_NORMAL ) if( !m_boardAdapter.GetFlag( FL_FP_ATTRIBUTES_NORMAL )
&& !m_boardAdapter.GetFlag( FL_FP_ATTRIBUTES_NORMAL_INSERT ) && !m_boardAdapter.GetFlag( FL_FP_ATTRIBUTES_NORMAL_INSERT )
@ -948,7 +934,7 @@ void C3D_RENDER_OGL_LEGACY::load_3D_models( REPORTER* aStatusReporter )
if( modelPtr ) if( modelPtr )
{ {
MATERIAL_MODE materialMode = m_boardAdapter.MaterialModeGet(); MATERIAL_MODE materialMode = m_boardAdapter.MaterialModeGet();
C_OGL_3DMODEL* ogl_model = new C_OGL_3DMODEL( *modelPtr, materialMode ); MODEL_3D* ogl_model = new MODEL_3D( *modelPtr, materialMode );
if( ogl_model ) if( ogl_model )
m_3dmodel_map[ model.m_Filename ] = ogl_model; m_3dmodel_map[ model.m_Filename ] = ogl_model;

View File

@ -38,28 +38,27 @@
*/ */
#define UNITS3D_TO_UNITSPCB (IU_PER_MM) #define UNITS3D_TO_UNITSPCB (IU_PER_MM)
C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY( BOARD_ADAPTER& aAdapter, CCAMERA& aCamera ) : RENDER_3D_LEGACY::RENDER_3D_LEGACY( BOARD_ADAPTER& aAdapter, CAMERA& aCamera ) :
C3D_RENDER_BASE( aAdapter, aCamera ) RENDER_3D_BASE( aAdapter, aCamera )
{ {
wxLogTrace( m_logTrace, wxT( "C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY" ) ); wxLogTrace( m_logTrace, wxT( "RENDER_3D_LEGACY::RENDER_3D_LEGACY" ) );
m_layers.clear(); m_layers.clear();
m_layers_holes_outer.clear(); m_layers_holes_outer.clear();
m_layers_holes_inner.clear(); m_layers_holes_inner.clear();
m_triangles.clear(); m_triangles.clear();
m_board = NULL; m_board = nullptr;
m_anti_board = NULL; m_anti_board = nullptr;
m_platedPads_F_Cu = nullptr; m_platedPads_F_Cu = nullptr;
m_platedPads_B_Cu = nullptr; m_platedPads_B_Cu = nullptr;
m_through_holes_outer = NULL; m_through_holes_outer = nullptr;
m_through_holes_outer_ring = NULL; m_through_holes_outer_ring = nullptr;
m_through_holes_vias_outer = NULL; m_through_holes_vias_outer = nullptr;
//m_through_holes_vias_inner = NULL; m_vias = nullptr;
m_vias = NULL; m_pad_holes = nullptr;
m_pad_holes = NULL; m_vias_and_pad_holes_outer_contourn_and_caps = nullptr;
m_vias_and_pad_holes_outer_contourn_and_caps = NULL;
m_ogl_circle_texture = 0; m_ogl_circle_texture = 0;
m_grid = 0; m_grid = 0;
@ -71,9 +70,9 @@ C3D_RENDER_OGL_LEGACY::C3D_RENDER_OGL_LEGACY( BOARD_ADAPTER& aAdapter, CCAMERA&
} }
C3D_RENDER_OGL_LEGACY::~C3D_RENDER_OGL_LEGACY() RENDER_3D_LEGACY::~RENDER_3D_LEGACY()
{ {
wxLogTrace( m_logTrace, wxT( "C3D_RENDER_OGL_LEGACY::~C3D_RENDER_OGL_LEGACY" ) ); wxLogTrace( m_logTrace, wxT( "RENDER_3D_LEGACY::~RENDER_3D_LEGACY" ) );
ogl_free_all_display_lists(); ogl_free_all_display_lists();
@ -81,13 +80,13 @@ C3D_RENDER_OGL_LEGACY::~C3D_RENDER_OGL_LEGACY()
} }
int C3D_RENDER_OGL_LEGACY::GetWaitForEditingTimeOut() int RENDER_3D_LEGACY::GetWaitForEditingTimeOut()
{ {
return 50; // ms return 50; // ms
} }
void C3D_RENDER_OGL_LEGACY::SetCurWindowSize( const wxSize &aSize ) void RENDER_3D_LEGACY::SetCurWindowSize( const wxSize& aSize )
{ {
if( m_windowSize != aSize ) if( m_windowSize != aSize )
{ {
@ -99,7 +98,7 @@ void C3D_RENDER_OGL_LEGACY::SetCurWindowSize( const wxSize &aSize )
} }
void C3D_RENDER_OGL_LEGACY::setLight_Front( bool enabled ) void RENDER_3D_LEGACY::setLight_Front( bool enabled )
{ {
if( enabled ) if( enabled )
glEnable( GL_LIGHT0 ); glEnable( GL_LIGHT0 );
@ -108,7 +107,7 @@ void C3D_RENDER_OGL_LEGACY::setLight_Front( bool enabled )
} }
void C3D_RENDER_OGL_LEGACY::setLight_Top( bool enabled ) void RENDER_3D_LEGACY::setLight_Top( bool enabled )
{ {
if( enabled ) if( enabled )
glEnable( GL_LIGHT1 ); glEnable( GL_LIGHT1 );
@ -117,7 +116,7 @@ void C3D_RENDER_OGL_LEGACY::setLight_Top( bool enabled )
} }
void C3D_RENDER_OGL_LEGACY::setLight_Bottom( bool enabled ) void RENDER_3D_LEGACY::setLight_Bottom( bool enabled )
{ {
if( enabled ) if( enabled )
glEnable( GL_LIGHT2 ); glEnable( GL_LIGHT2 );
@ -126,7 +125,7 @@ void C3D_RENDER_OGL_LEGACY::setLight_Bottom( bool enabled )
} }
void C3D_RENDER_OGL_LEGACY::render_3D_arrows() void RENDER_3D_LEGACY::render_3D_arrows()
{ {
const float arrow_size = RANGE_SCALE_3D * 0.30f; const float arrow_size = RANGE_SCALE_3D * 0.30f;
@ -154,25 +153,19 @@ void C3D_RENDER_OGL_LEGACY::render_3D_arrows()
ogl_set_arrow_material(); ogl_set_arrow_material();
glColor3f( 0.9f, 0.0f, 0.0f ); glColor3f( 0.9f, 0.0f, 0.0f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( arrow_size, 0.0f, 0.0f ), 0.275f );
SFVEC3F( arrow_size, 0.0f, 0.0f ),
0.275f );
glColor3f( 0.0f, 0.9f, 0.0f ); glColor3f( 0.0f, 0.9f, 0.0f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, arrow_size, 0.0f ), 0.275f );
SFVEC3F( 0.0f, arrow_size, 0.0f ),
0.275f );
glColor3f( 0.0f, 0.0f, 0.9f ); glColor3f( 0.0f, 0.0f, 0.9f );
OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), DrawRoundArrow( SFVEC3F( 0.0f, 0.0f, 0.0f ), SFVEC3F( 0.0f, 0.0f, arrow_size ), 0.275f );
SFVEC3F( 0.0f, 0.0f, arrow_size ),
0.275f );
glEnable( GL_CULL_FACE ); glEnable( GL_CULL_FACE );
} }
void C3D_RENDER_OGL_LEGACY::setupMaterials() void RENDER_3D_LEGACY::setupMaterials()
{ {
m_materials = {}; m_materials = {};
@ -230,9 +223,12 @@ void C3D_RENDER_OGL_LEGACY::setupMaterials()
m_boardAdapter.m_SilkScreenColorTop.b ); m_boardAdapter.m_SilkScreenColorTop.b );
m_materials.m_SilkSTop.m_Specular = SFVEC3F( m_materials.m_SilkSTop.m_Specular = SFVEC3F(
m_boardAdapter.m_SilkScreenColorTop.r * m_boardAdapter.m_SilkScreenColorTop.r + 0.10f, m_boardAdapter.m_SilkScreenColorTop.r * m_boardAdapter.m_SilkScreenColorTop.r +
m_boardAdapter.m_SilkScreenColorTop.g * m_boardAdapter.m_SilkScreenColorTop.g + 0.10f, 0.10f,
m_boardAdapter.m_SilkScreenColorTop.b * m_boardAdapter.m_SilkScreenColorTop.b + 0.10f ); m_boardAdapter.m_SilkScreenColorTop.g * m_boardAdapter.m_SilkScreenColorTop.g +
0.10f,
m_boardAdapter.m_SilkScreenColorTop.b * m_boardAdapter.m_SilkScreenColorTop.b +
0.10f );
m_materials.m_SilkSTop.m_Shininess = 0.078125f * 128.0f; m_materials.m_SilkSTop.m_Shininess = 0.078125f * 128.0f;
m_materials.m_SilkSTop.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f ); m_materials.m_SilkSTop.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
@ -243,9 +239,12 @@ void C3D_RENDER_OGL_LEGACY::setupMaterials()
m_boardAdapter.m_SilkScreenColorBot.b ); m_boardAdapter.m_SilkScreenColorBot.b );
m_materials.m_SilkSBot.m_Specular = SFVEC3F( m_materials.m_SilkSBot.m_Specular = SFVEC3F(
m_boardAdapter.m_SilkScreenColorBot.r * m_boardAdapter.m_SilkScreenColorBot.r + 0.10f, m_boardAdapter.m_SilkScreenColorBot.r * m_boardAdapter.m_SilkScreenColorBot.r +
m_boardAdapter.m_SilkScreenColorBot.g * m_boardAdapter.m_SilkScreenColorBot.g + 0.10f, 0.10f,
m_boardAdapter.m_SilkScreenColorBot.b * m_boardAdapter.m_SilkScreenColorBot.b + 0.10f ); m_boardAdapter.m_SilkScreenColorBot.g * m_boardAdapter.m_SilkScreenColorBot.g +
0.10f,
m_boardAdapter.m_SilkScreenColorBot.b * m_boardAdapter.m_SilkScreenColorBot.b +
0.10f );
m_materials.m_SilkSBot.m_Shininess = 0.078125f * 128.0f; m_materials.m_SilkSBot.m_Shininess = 0.078125f * 128.0f;
m_materials.m_SilkSBot.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f ); m_materials.m_SilkSBot.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
@ -254,12 +253,10 @@ void C3D_RENDER_OGL_LEGACY::setupMaterials()
m_materials.m_SolderMask.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f ); m_materials.m_SolderMask.m_Emissive = SFVEC3F( 0.0f, 0.0f, 0.0f );
// Epoxy material // Epoxy material
m_materials.m_EpoxyBoard.m_Ambient = SFVEC3F( 117.0f / 255.0f, m_materials.m_EpoxyBoard.m_Ambient = SFVEC3F( 117.0f / 255.0f, 97.0f / 255.0f,
97.0f / 255.0f,
47.0f / 255.0f ); 47.0f / 255.0f );
m_materials.m_EpoxyBoard.m_Specular = SFVEC3F( 18.0f / 255.0f, m_materials.m_EpoxyBoard.m_Specular = SFVEC3F( 18.0f / 255.0f, 3.0f / 255.0f,
3.0f / 255.0f,
20.0f / 255.0f ); 20.0f / 255.0f );
m_materials.m_EpoxyBoard.m_Shininess = 0.1f * 128.0f; m_materials.m_EpoxyBoard.m_Shininess = 0.1f * 128.0f;
@ -317,7 +314,7 @@ void C3D_RENDER_OGL_LEGACY::setupMaterials()
} }
void C3D_RENDER_OGL_LEGACY::set_layer_material( PCB_LAYER_ID aLayerID ) void RENDER_3D_LEGACY::set_layer_material( PCB_LAYER_ID aLayerID )
{ {
switch( aLayerID ) switch( aLayerID )
{ {
@ -394,7 +391,7 @@ void C3D_RENDER_OGL_LEGACY::set_layer_material( PCB_LAYER_ID aLayerID )
} }
SFVEC4F C3D_RENDER_OGL_LEGACY::get_layer_color( PCB_LAYER_ID aLayerID ) SFVEC4F RENDER_3D_LEGACY::get_layer_color( PCB_LAYER_ID aLayerID )
{ {
SFVEC4F layerColor = m_boardAdapter.GetLayerColor( aLayerID ); SFVEC4F layerColor = m_boardAdapter.GetLayerColor( aLayerID );
@ -451,7 +448,7 @@ SFVEC4F C3D_RENDER_OGL_LEGACY::get_layer_color( PCB_LAYER_ID aLayerID )
} }
void init_lights(void) void init_lights( void )
{ {
// Setup light // Setup light
// https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml // https://www.opengl.org/sdk/docs/man2/xhtml/glLight.xml
@ -498,13 +495,13 @@ void init_lights(void)
} }
void C3D_RENDER_OGL_LEGACY::setCopperMaterial() void RENDER_3D_LEGACY::setCopperMaterial()
{ {
OGL_SetMaterial( m_materials.m_NonPlatedCopper, 1.0f ); OGL_SetMaterial( m_materials.m_NonPlatedCopper, 1.0f );
} }
void C3D_RENDER_OGL_LEGACY::setPlatedCopperAndDepthOffset( PCB_LAYER_ID aLayer_id ) void RENDER_3D_LEGACY::setPlatedCopperAndDepthOffset( PCB_LAYER_ID aLayer_id )
{ {
glEnable( GL_POLYGON_OFFSET_FILL ); glEnable( GL_POLYGON_OFFSET_FILL );
glPolygonOffset(-0.1f, -2.0f ); glPolygonOffset(-0.1f, -2.0f );
@ -512,13 +509,13 @@ void C3D_RENDER_OGL_LEGACY::setPlatedCopperAndDepthOffset( PCB_LAYER_ID aLayer_i
} }
void C3D_RENDER_OGL_LEGACY::unsetDepthOffset() void RENDER_3D_LEGACY::unsetDepthOffset()
{ {
glDisable( GL_POLYGON_OFFSET_FILL ); glDisable( GL_POLYGON_OFFSET_FILL );
} }
void C3D_RENDER_OGL_LEGACY::render_board_body( bool aSkipRenderHoles ) void RENDER_3D_LEGACY::render_board_body( bool aSkipRenderHoles )
{ {
m_materials.m_EpoxyBoard.m_Diffuse = m_boardAdapter.m_BoardBodyColor; m_materials.m_EpoxyBoard.m_Diffuse = m_boardAdapter.m_BoardBodyColor;
@ -527,7 +524,7 @@ void C3D_RENDER_OGL_LEGACY::render_board_body( bool aSkipRenderHoles )
OGL_SetMaterial( m_materials.m_EpoxyBoard, 1.0f ); OGL_SetMaterial( m_materials.m_EpoxyBoard, 1.0f );
CLAYERS_OGL_DISP_LISTS* ogl_disp_list = nullptr; OPENGL_RENDER_LIST* ogl_disp_list = nullptr;
if( aSkipRenderHoles ) if( aSkipRenderHoles )
ogl_disp_list = m_board; ogl_disp_list = m_board;
@ -546,7 +543,7 @@ void C3D_RENDER_OGL_LEGACY::render_board_body( bool aSkipRenderHoles )
} }
bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter, bool RENDER_3D_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
REPORTER* aWarningReporter ) REPORTER* aWarningReporter )
{ {
// Initialize OpenGL // Initialize OpenGL
@ -623,7 +620,7 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
glEnable( GL_LIGHTING ); glEnable( GL_LIGHTING );
{ {
const SFVEC3F &cameraPos = m_camera.GetPos(); const SFVEC3F& cameraPos = m_camera.GetPos();
// Place the light at a minimum Z so the diffuse factor will not drop // Place the light at a minimum Z so the diffuse factor will not drop
// and the board will still look with good light. // and the board will still look with good light.
@ -638,10 +635,8 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
zpos = glm::min( cameraPos.z,-0.5f ) - cameraPos.z * cameraPos.z; zpos = glm::min( cameraPos.z,-0.5f ) - cameraPos.z * cameraPos.z;
} }
const GLfloat headlight_pos[] = { cameraPos.x, // This is a point light.
cameraPos.y, const GLfloat headlight_pos[] = { cameraPos.x, cameraPos.y, zpos, 1.0f };
zpos,
1.0f }; // This is a point light
glLightfv( GL_LIGHT0, GL_POSITION, headlight_pos ); glLightfv( GL_LIGHT0, GL_POSITION, headlight_pos );
} }
@ -690,11 +685,9 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
glPushMatrix(); glPushMatrix();
/// @todo Determine what to do with this commented out code. OPENGL_RENDER_LIST* pLayerDispList = static_cast<OPENGL_RENDER_LIST*>( ii->second );
//glScalef( 1.0f, 1.0f, 3.0f );
CLAYERS_OGL_DISP_LISTS *pLayerDispList = static_cast<CLAYERS_OGL_DISP_LISTS*>(ii->second);
if( (layer_id >= F_Cu) && (layer_id <= B_Cu) ) if( ( layer_id >= F_Cu ) && ( layer_id <= B_Cu ) )
{ {
if( !m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) || if( !m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) ||
!( m_boardAdapter.GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) && !( m_boardAdapter.GetFlag( FL_RENDER_PLATED_PADS_AS_PLATED ) &&
@ -743,12 +736,12 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
if( m_layers_holes_outer.find( layer_id ) != m_layers_holes_outer.end() ) if( m_layers_holes_outer.find( layer_id ) != m_layers_holes_outer.end() )
{ {
const CLAYERS_OGL_DISP_LISTS* viasHolesLayer = const OPENGL_RENDER_LIST* viasHolesLayer =
m_layers_holes_outer.at( layer_id ); m_layers_holes_outer.at( layer_id );
wxASSERT( viasHolesLayer != NULL ); wxASSERT( viasHolesLayer != nullptr );
if( viasHolesLayer != NULL ) if( viasHolesLayer != nullptr )
{ {
pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments, pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
m_through_holes_outer, m_through_holes_outer,
@ -817,7 +810,7 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
{ {
set_layer_material( layer_id ); set_layer_material( layer_id );
CLAYERS_OGL_DISP_LISTS* throughHolesOuter = OPENGL_RENDER_LIST* throughHolesOuter =
m_boardAdapter.GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS ) m_boardAdapter.GetFlag( FL_CLIP_SILK_ON_VIA_ANNULUS )
&& m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE ) && m_boardAdapter.GetFlag( FL_USE_REALISTIC_MODE )
&& ( layer_id == B_SilkS || layer_id == F_SilkS ) && ( layer_id == B_SilkS || layer_id == F_SilkS )
@ -831,7 +824,7 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
pLayerDispList->GetZTop() - pLayerDispList->GetZBot() ); pLayerDispList->GetZTop() - pLayerDispList->GetZBot() );
} }
CLAYERS_OGL_DISP_LISTS* anti_board = m_anti_board; OPENGL_RENDER_LIST* anti_board = m_anti_board;
if( ( layer_id == B_Paste ) || ( layer_id == F_Paste ) ) if( ( layer_id == B_Paste ) || ( layer_id == F_Paste ) )
anti_board = nullptr; anti_board = nullptr;
@ -851,7 +844,7 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
{ {
const PCB_LAYER_ID layerMask_id = (layer_id == B_SilkS) ? B_Mask : F_Mask; const PCB_LAYER_ID layerMask_id = (layer_id == B_SilkS) ? B_Mask : F_Mask;
const CLAYERS_OGL_DISP_LISTS *pLayerDispListMask = m_layers.at( layerMask_id ); const OPENGL_RENDER_LIST* pLayerDispListMask = m_layers.at( layerMask_id );
pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments, pLayerDispList->DrawAllCameraCulledSubtractLayer( drawMiddleSegments,
pLayerDispListMask, pLayerDispListMask,
@ -983,7 +976,7 @@ bool C3D_RENDER_OGL_LEGACY::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
} }
bool C3D_RENDER_OGL_LEGACY::initializeOpenGL() bool RENDER_3D_LEGACY::initializeOpenGL()
{ {
glEnable( GL_LINE_SMOOTH ); glEnable( GL_LINE_SMOOTH );
glShadeModel( GL_SMOOTH ); glShadeModel( GL_SMOOTH );
@ -992,7 +985,7 @@ bool C3D_RENDER_OGL_LEGACY::initializeOpenGL()
glPixelStorei( GL_UNPACK_ALIGNMENT, 4 ); glPixelStorei( GL_UNPACK_ALIGNMENT, 4 );
// Initialize the open GL texture to draw the filled semi-circle of the segments // Initialize the open GL texture to draw the filled semi-circle of the segments
CIMAGE *circleImage = new CIMAGE( SIZE_OF_CIRCLE_TEXTURE, SIZE_OF_CIRCLE_TEXTURE ); IMAGE* circleImage = new IMAGE( SIZE_OF_CIRCLE_TEXTURE, SIZE_OF_CIRCLE_TEXTURE );
if( !circleImage ) if( !circleImage )
return false; return false;
@ -1002,12 +995,7 @@ bool C3D_RENDER_OGL_LEGACY::initializeOpenGL()
( SIZE_OF_CIRCLE_TEXTURE / 2 ) - 4, ( SIZE_OF_CIRCLE_TEXTURE / 2 ) - 4,
0xFF ); 0xFF );
/// @todo Determine what to do with this commented out code. IMAGE* circleImage_Copy = new IMAGE( *circleImage );
//circleImage->CircleFilled( (SIZE_OF_CIRCLE_TEXTURE / 4)*1.5f - 1,
// (SIZE_OF_CIRCLE_TEXTURE / 4)*1.5f - 1,
// (SIZE_OF_CIRCLE_TEXTURE / 4)*1.5f - 2, 0xFF );
CIMAGE *circleImage_Copy = new CIMAGE( *circleImage );
circleImage->EfxFilter( circleImage_Copy, IMAGE_FILTER::BLUR_3X3 ); circleImage->EfxFilter( circleImage_Copy, IMAGE_FILTER::BLUR_3X3 );
@ -1031,7 +1019,7 @@ bool C3D_RENDER_OGL_LEGACY::initializeOpenGL()
} }
void C3D_RENDER_OGL_LEGACY::ogl_set_arrow_material() void RENDER_3D_LEGACY::ogl_set_arrow_material()
{ {
glEnable( GL_COLOR_MATERIAL ); glEnable( GL_COLOR_MATERIAL );
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
@ -1050,7 +1038,7 @@ void C3D_RENDER_OGL_LEGACY::ogl_set_arrow_material()
} }
void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists() void RENDER_3D_LEGACY::ogl_free_all_display_lists()
{ {
if( glIsList( m_grid ) ) if( glIsList( m_grid ) )
glDeleteLists( m_grid, 1 ); glDeleteLists( m_grid, 1 );
@ -1059,7 +1047,7 @@ void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists()
for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii ) for( MAP_OGL_DISP_LISTS::const_iterator ii = m_layers.begin(); ii != m_layers.end(); ++ii )
{ {
CLAYERS_OGL_DISP_LISTS *pLayerDispList = static_cast<CLAYERS_OGL_DISP_LISTS*>( ii->second ); OPENGL_RENDER_LIST* pLayerDispList = static_cast<OPENGL_RENDER_LIST*>( ii->second );
delete pLayerDispList; delete pLayerDispList;
} }
@ -1075,7 +1063,7 @@ void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists()
ii != m_layers_holes_outer.end(); ii != m_layers_holes_outer.end();
++ii ) ++ii )
{ {
CLAYERS_OGL_DISP_LISTS* pLayerDispList = static_cast<CLAYERS_OGL_DISP_LISTS*>( ii->second ); OPENGL_RENDER_LIST* pLayerDispList = static_cast<OPENGL_RENDER_LIST*>( ii->second );
delete pLayerDispList; delete pLayerDispList;
} }
@ -1085,7 +1073,7 @@ void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists()
ii != m_layers_holes_inner.end(); ii != m_layers_holes_inner.end();
++ii ) ++ii )
{ {
CLAYERS_OGL_DISP_LISTS* pLayerDispList = static_cast<CLAYERS_OGL_DISP_LISTS*>( ii->second ); OPENGL_RENDER_LIST* pLayerDispList = static_cast<OPENGL_RENDER_LIST*>( ii->second );
delete pLayerDispList; delete pLayerDispList;
} }
@ -1100,7 +1088,7 @@ void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists()
for( MAP_3DMODEL::const_iterator ii = m_3dmodel_map.begin(); ii != m_3dmodel_map.end(); ++ii ) for( MAP_3DMODEL::const_iterator ii = m_3dmodel_map.begin(); ii != m_3dmodel_map.end(); ++ii )
{ {
C_OGL_3DMODEL *pointer = static_cast<C_OGL_3DMODEL*>(ii->second); MODEL_3D* pointer = static_cast<MODEL_3D*>(ii->second);
delete pointer; delete pointer;
} }
@ -1135,9 +1123,8 @@ void C3D_RENDER_OGL_LEGACY::ogl_free_all_display_lists()
} }
void C3D_RENDER_OGL_LEGACY::render_solder_mask_layer( PCB_LAYER_ID aLayerID, float aZPosition, void RENDER_3D_LEGACY::render_solder_mask_layer( PCB_LAYER_ID aLayerID, float aZPosition,
bool aDrawMiddleSegments, bool aDrawMiddleSegments, bool aSkipRenderHoles )
bool aSkipRenderHoles )
{ {
wxASSERT( (aLayerID == B_Mask) || (aLayerID == F_Mask) ); wxASSERT( (aLayerID == B_Mask) || (aLayerID == F_Mask) );
@ -1147,7 +1134,7 @@ void C3D_RENDER_OGL_LEGACY::render_solder_mask_layer( PCB_LAYER_ID aLayerID, flo
{ {
if( m_layers.find( aLayerID ) != m_layers.end() ) if( m_layers.find( aLayerID ) != m_layers.end() )
{ {
CLAYERS_OGL_DISP_LISTS *pLayerDispListMask = m_layers.at( aLayerID ); OPENGL_RENDER_LIST* pLayerDispListMask = m_layers.at( aLayerID );
if( m_through_holes_vias_outer ) if( m_through_holes_vias_outer )
m_through_holes_vias_outer->ApplyScalePosition( aZPosition, nonCopperThickness ); m_through_holes_vias_outer->ApplyScalePosition( aZPosition, nonCopperThickness );
@ -1195,12 +1182,11 @@ void C3D_RENDER_OGL_LEGACY::render_solder_mask_layer( PCB_LAYER_ID aLayerID, flo
} }
void C3D_RENDER_OGL_LEGACY::render_3D_models_selected( bool aRenderTopOrBot, void RENDER_3D_LEGACY::render_3D_models_selected( bool aRenderTopOrBot, bool aRenderTransparentOnly,
bool aRenderTransparentOnly,
bool aRenderSelectedOnly ) bool aRenderSelectedOnly )
{ {
C_OGL_3DMODEL::BeginDrawMulti( !aRenderSelectedOnly ); MODEL_3D::BeginDrawMulti( !aRenderSelectedOnly );
// Go for all footprints // Go for all footprints
for( FOOTPRINT* fp : m_boardAdapter.GetBoard()->Footprints() ) for( FOOTPRINT* fp : m_boardAdapter.GetBoard()->Footprints() )
@ -1242,11 +1228,11 @@ void C3D_RENDER_OGL_LEGACY::render_3D_models_selected( bool aRenderTopOrBot,
} }
} }
C_OGL_3DMODEL::EndDrawMulti(); MODEL_3D::EndDrawMulti();
} }
void C3D_RENDER_OGL_LEGACY::render_3D_models( bool aRenderTopOrBot, bool aRenderTransparentOnly ) void RENDER_3D_LEGACY::render_3D_models( bool aRenderTopOrBot, bool aRenderTransparentOnly )
{ {
if( m_boardAdapter.GetFlag( FL_USE_SELECTION ) ) if( m_boardAdapter.GetFlag( FL_USE_SELECTION ) )
render_3D_models_selected( aRenderTopOrBot, aRenderTransparentOnly, true ); render_3D_models_selected( aRenderTopOrBot, aRenderTransparentOnly, true );
@ -1255,9 +1241,8 @@ void C3D_RENDER_OGL_LEGACY::render_3D_models( bool aRenderTopOrBot, bool aRender
} }
void C3D_RENDER_OGL_LEGACY::render_3D_footprint( const FOOTPRINT* aFootprint, void RENDER_3D_LEGACY::render_3D_footprint( const FOOTPRINT* aFootprint,
bool aRenderTransparentOnly, bool aRenderTransparentOnly, bool aIsSelected )
bool aIsSelected )
{ {
if( !aFootprint->Models().empty() ) if( !aFootprint->Models().empty() )
{ {
@ -1282,8 +1267,7 @@ void C3D_RENDER_OGL_LEGACY::render_3D_footprint( const FOOTPRINT* aFootprint,
double modelunit_to_3d_units_factor = m_boardAdapter.BiuTo3Dunits() * UNITS3D_TO_UNITSPCB; double modelunit_to_3d_units_factor = m_boardAdapter.BiuTo3Dunits() * UNITS3D_TO_UNITSPCB;
glScaled( modelunit_to_3d_units_factor, glScaled( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor,
modelunit_to_3d_units_factor,
modelunit_to_3d_units_factor ); modelunit_to_3d_units_factor );
// Get the list of model files for this model // Get the list of model files for this model
@ -1298,7 +1282,7 @@ void C3D_RENDER_OGL_LEGACY::render_3D_footprint( const FOOTPRINT* aFootprint,
if( cache_i == m_3dmodel_map.end() ) if( cache_i == m_3dmodel_map.end() )
continue; continue;
if( const C_OGL_3DMODEL *modelPtr = cache_i->second ) if( const MODEL_3D* modelPtr = cache_i->second )
{ {
bool opaque = sM.m_Opacity >= 1.0; bool opaque = sM.m_Opacity >= 1.0;
@ -1359,7 +1343,7 @@ void C3D_RENDER_OGL_LEGACY::render_3D_footprint( const FOOTPRINT* aFootprint,
} }
void C3D_RENDER_OGL_LEGACY::generate_new_3DGrid( GRID3D_TYPE aGridType ) void RENDER_3D_LEGACY::generate_new_3DGrid( GRID3D_TYPE aGridType )
{ {
if( glIsList( m_grid ) ) if( glIsList( m_grid ) )
glDeleteLists( m_grid, 1 ); glDeleteLists( m_grid, 1 );
@ -1421,10 +1405,10 @@ void C3D_RENDER_OGL_LEGACY::generate_new_3DGrid( GRID3D_TYPE aGridType )
const int ysize = std::max( brd_size.y, Millimeter2iu( 100 ) ) * 1.2; const int ysize = std::max( brd_size.y, Millimeter2iu( 100 ) ) * 1.2;
// Grid limits, in 3D units // Grid limits, in 3D units
double xmin = (brd_center_pos.x - xsize / 2) * scale; double xmin = ( brd_center_pos.x - xsize / 2 ) * scale;
double xmax = (brd_center_pos.x + xsize / 2) * scale; double xmax = ( brd_center_pos.x + xsize / 2 ) * scale;
double ymin = (brd_center_pos.y - ysize / 2) * scale; double ymin = ( brd_center_pos.y - ysize / 2 ) * scale;
double ymax = (brd_center_pos.y + ysize / 2) * scale; double ymax = ( brd_center_pos.y + ysize / 2 ) * scale;
double zmin = Millimeter2iu( -50 ) * scale; double zmin = Millimeter2iu( -50 ) * scale;
double zmax = Millimeter2iu( 100 ) * scale; double zmax = Millimeter2iu( 100 ) * scale;
@ -1434,9 +1418,7 @@ void C3D_RENDER_OGL_LEGACY::generate_new_3DGrid( GRID3D_TYPE aGridType )
if( (ii % 5) ) if( (ii % 5) )
glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency ); glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
else else
glColor4f( gridColor_marker.r, glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b,
gridColor_marker.g,
gridColor_marker.b,
transparency ); transparency );
const int delta = KiROUND( ii * griSizeMM * IU_PER_MM ); const int delta = KiROUND( ii * griSizeMM * IU_PER_MM );
@ -1460,15 +1442,15 @@ void C3D_RENDER_OGL_LEGACY::generate_new_3DGrid( GRID3D_TYPE aGridType )
if( delta <= ysize / 2 ) // Draw grid lines parallel to Y axis if( delta <= ysize / 2 ) // Draw grid lines parallel to Y axis
{ {
glBegin( GL_LINES ); glBegin( GL_LINES );
glVertex3f( xmin, -(brd_center_pos.y + delta) * scale, zpos ); glVertex3f( xmin, -( brd_center_pos.y + delta ) * scale, zpos );
glVertex3f( xmax, -(brd_center_pos.y + delta) * scale, zpos ); glVertex3f( xmax, -( brd_center_pos.y + delta ) * scale, zpos );
glEnd(); glEnd();
if( ii != 0 ) if( ii != 0 )
{ {
glBegin( GL_LINES ); glBegin( GL_LINES );
glVertex3f( xmin, -(brd_center_pos.y - delta) * scale, zpos ); glVertex3f( xmin, -( brd_center_pos.y - delta ) * scale, zpos );
glVertex3f( xmax, -(brd_center_pos.y - delta) * scale, zpos ); glVertex3f( xmax, -( brd_center_pos.y - delta ) * scale, zpos );
glEnd(); glEnd();
} }
} }
@ -1488,15 +1470,13 @@ void C3D_RENDER_OGL_LEGACY::generate_new_3DGrid( GRID3D_TYPE aGridType )
if( (ii % 5) ) if( (ii % 5) )
glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency ); glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
else else
glColor4f( gridColor_marker.r, glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b,
gridColor_marker.g,
gridColor_marker.b,
transparency ); transparency );
const double delta = ii * griSizeMM * IU_PER_MM; const double delta = ii * griSizeMM * IU_PER_MM;
glBegin( GL_LINES ); glBegin( GL_LINES );
xmax = (brd_center_pos.x + delta) * scale; xmax = ( brd_center_pos.x + delta ) * scale;
glVertex3f( xmax, posy, zmin ); glVertex3f( xmax, posy, zmin );
glVertex3f( xmax, posy, zmax ); glVertex3f( xmax, posy, zmax );
@ -1505,7 +1485,7 @@ void C3D_RENDER_OGL_LEGACY::generate_new_3DGrid( GRID3D_TYPE aGridType )
if( ii != 0 ) if( ii != 0 )
{ {
glBegin( GL_LINES ); glBegin( GL_LINES );
xmin = (brd_center_pos.x - delta) * scale; xmin = ( brd_center_pos.x - delta ) * scale;
glVertex3f( xmin, posy, zmin ); glVertex3f( xmin, posy, zmin );
glVertex3f( xmin, posy, zmax ); glVertex3f( xmin, posy, zmax );
glEnd(); glEnd();
@ -1521,9 +1501,7 @@ void C3D_RENDER_OGL_LEGACY::generate_new_3DGrid( GRID3D_TYPE aGridType )
if( (ii % 5) ) if( (ii % 5) )
glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency ); glColor4f( gridColor.r, gridColor.g, gridColor.b, transparency );
else else
glColor4f( gridColor_marker.r, glColor4f( gridColor_marker.r, gridColor_marker.g, gridColor_marker.b,
gridColor_marker.g,
gridColor_marker.b,
transparency ); transparency );
const double delta = ii * griSizeMM * IU_PER_MM * scale; const double delta = ii * griSizeMM * IU_PER_MM * scale;

View File

@ -27,8 +27,8 @@
* @brief * @brief
*/ */
#ifndef C3D_RENDER_OGL_LEGACY_H_ #ifndef RENDER_3D_LEGACY_H_
#define C3D_RENDER_OGL_LEGACY_H_ #define RENDER_3D_LEGACY_H_
#include "../c3d_render_base.h" #include "../c3d_render_base.h"
#include "clayer_triangles.h" #include "clayer_triangles.h"
@ -47,23 +47,23 @@
#include <map> #include <map>
typedef std::map< PCB_LAYER_ID, CLAYERS_OGL_DISP_LISTS* > MAP_OGL_DISP_LISTS; typedef std::map< PCB_LAYER_ID, OPENGL_RENDER_LIST* > MAP_OGL_DISP_LISTS;
typedef std::list<CLAYER_TRIANGLES * > LIST_TRIANGLES; typedef std::list<TRIANGLE_DISPLAY_LIST* > LIST_TRIANGLES;
typedef std::map< wxString, C_OGL_3DMODEL * > MAP_3DMODEL; typedef std::map< wxString, MODEL_3D* > MAP_3DMODEL;
#define SIZE_OF_CIRCLE_TEXTURE 1024 #define SIZE_OF_CIRCLE_TEXTURE 1024
/** /**
* Object to render the board using openGL legacy mode. * Object to render the board using openGL legacy mode.
*/ */
class C3D_RENDER_OGL_LEGACY : public C3D_RENDER_BASE class RENDER_3D_LEGACY : public RENDER_3D_BASE
{ {
public: public:
explicit C3D_RENDER_OGL_LEGACY( BOARD_ADAPTER& aAdapter, CCAMERA& aCamera ); explicit RENDER_3D_LEGACY( BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
~C3D_RENDER_OGL_LEGACY(); ~RENDER_3D_LEGACY();
void SetCurWindowSize( const wxSize &aSize ) override; void SetCurWindowSize( const wxSize& aSize ) override;
bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override; bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override;
int GetWaitForEditingTimeOut() override; int GetWaitForEditingTimeOut() override;
@ -74,85 +74,61 @@ public:
} }
private: private:
CLAYERS_OGL_DISP_LISTS *generate_holes_display_list( const LIST_OBJECT2D &aListHolesObject2d, OPENGL_RENDER_LIST* generate_holes_display_list( const LIST_OBJECT2D& aListHolesObject2d,
const SHAPE_POLY_SET &aPoly, const SHAPE_POLY_SET& aPoly,
float aZtop, float aZtop,
float aZbot, float aZbot,
bool aInvertFaces, bool aInvertFaces,
const CBVHCONTAINER2D *aThroughHoles = nullptr ); const BVH_CONTAINER_2D* aThroughHoles = nullptr );
CLAYERS_OGL_DISP_LISTS* generateLayerListFromContainer( const CBVHCONTAINER2D *aContainer, OPENGL_RENDER_LIST* generateLayerListFromContainer( const BVH_CONTAINER_2D* aContainer,
const SHAPE_POLY_SET *aPolyList, const SHAPE_POLY_SET* aPolyList,
PCB_LAYER_ID aLayerId, PCB_LAYER_ID aLayerId,
const CBVHCONTAINER2D *aThroughHoles = nullptr ); const BVH_CONTAINER_2D* aThroughHoles = nullptr );
void add_triangle_top_bot( CLAYER_TRIANGLES *aDst, void add_triangle_top_bot( TRIANGLE_DISPLAY_LIST* aDst, const SFVEC2F& v0, const SFVEC2F& v1,
const SFVEC2F &v0, const SFVEC2F& v2, float top, float bot );
const SFVEC2F &v1,
const SFVEC2F &v2,
float top,
float bot );
void add_object_to_triangle_layer( const CRING2D *aRing, void add_object_to_triangle_layer( const RING_2D* aRing, TRIANGLE_DISPLAY_LIST* aDstLayer,
CLAYER_TRIANGLES *aDstLayer, float aZtop, float aZbot );
float aZtop,
float aZbot );
void add_object_to_triangle_layer( const CPOLYGON4PTS2D *aPoly, void add_object_to_triangle_layer( const POLYGON_4PT_2D* aPoly,
CLAYER_TRIANGLES *aDstLayer, TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot );
float aZtop,
float aZbot );
void add_object_to_triangle_layer( const CFILLEDCIRCLE2D *aFilledCircle, void add_object_to_triangle_layer( const FILLED_CIRCLE_2D* aFilledCircle,
CLAYER_TRIANGLES *aDstLayer, TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot );
float aZtop,
float aZbot );
void add_object_to_triangle_layer( const CTRIANGLE2D *aTri, void add_object_to_triangle_layer( const TRIANGLE_2D* aTri, TRIANGLE_DISPLAY_LIST* aDstLayer,
CLAYER_TRIANGLES *aDstLayer, float aZtop, float aZbot );
float aZtop,
float aZbot );
void add_object_to_triangle_layer( const CROUNDSEGMENT2D *aSeg, void add_object_to_triangle_layer( const ROUND_SEGMENT_2D* aSeg,
CLAYER_TRIANGLES *aDstLayer, TRIANGLE_DISPLAY_LIST* aDstLayer, float aZtop, float aZbot );
float aZtop,
float aZbot );
void render_solder_mask_layer( PCB_LAYER_ID aLayerID, void render_solder_mask_layer( PCB_LAYER_ID aLayerID, float aZPosition,
float aZPosition, bool aDrawMiddleSegments, bool aSkipRenderHoles );
bool aDrawMiddleSegments,
bool aSkipRenderHoles );
void render_board_body( bool aSkipRenderHoles ); void render_board_body( bool aSkipRenderHoles );
void get_layer_z_pos( PCB_LAYER_ID aLayerID, void get_layer_z_pos( PCB_LAYER_ID aLayerID, float& aOutZtop, float& aOutZbot ) const;
float &aOutZtop,
float &aOutZbot ) const;
void generate_ring_contour( const SFVEC2F &aCenter, void generate_ring_contour( const SFVEC2F& aCenter, float aInnerRadius,
float aInnerRadius, float aOuterRadius, unsigned int aNr_sides_per_circle,
float aOuterRadius, std::vector< SFVEC2F >& aInnerContourResult,
unsigned int aNr_sides_per_circle, std::vector< SFVEC2F >& aOuterContourResult,
std::vector< SFVEC2F > &aInnerContourResult,
std::vector< SFVEC2F > &aOuterContourResult,
bool aInvertOrder ); bool aInvertOrder );
void generate_cylinder( const SFVEC2F &aCenter, void generate_cylinder( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
float aInnerRadius, float aZtop, float aZbot, unsigned int aNr_sides_per_circle,
float aOuterRadius, TRIANGLE_DISPLAY_LIST* aDstLayer );
float aZtop,
float aZbot,
unsigned int aNr_sides_per_circle,
CLAYER_TRIANGLES *aDstLayer );
void generate_3D_Vias_and_Pads(); void generate_3D_Vias_and_Pads();
/** /**
* Load footprint models from the cache and load it to openGL lists in the form of * Load footprint models from the cache and load it to openGL lists in the form of
* #C_OGL_3DMODEL objects. * #MODEL_3D objects.
* *
* This map of models will work as a local cache for this render. (cache based on * This map of models will work as a local cache for this render. (cache based on
* C_OGL_3DMODEL with associated openGL lists in GPU memory) * MODEL_3D with associated openGL lists in GPU memory)
*/ */
void load_3D_models( REPORTER* aStatusReporter ); void load_3D_models( REPORTER* aStatusReporter );
@ -193,8 +169,8 @@ private:
SFVEC4F get_layer_color( PCB_LAYER_ID aLayerID ); SFVEC4F get_layer_color( PCB_LAYER_ID aLayerID );
bool initializeOpenGL(); bool initializeOpenGL();
CLAYERS_OGL_DISP_LISTS* createBoard( const SHAPE_POLY_SET& aBoardPoly, OPENGL_RENDER_LIST* createBoard( const SHAPE_POLY_SET& aBoardPoly,
const CBVHCONTAINER2D *aThroughHoles = nullptr ); const BVH_CONTAINER_2D* aThroughHoles = nullptr );
void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter ); void reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter );
void ogl_set_arrow_material(); void ogl_set_arrow_material();
@ -215,17 +191,17 @@ private:
} m_materials; } m_materials;
MAP_OGL_DISP_LISTS m_layers; MAP_OGL_DISP_LISTS m_layers;
CLAYERS_OGL_DISP_LISTS* m_platedPads_F_Cu; OPENGL_RENDER_LIST* m_platedPads_F_Cu;
CLAYERS_OGL_DISP_LISTS* m_platedPads_B_Cu; OPENGL_RENDER_LIST* m_platedPads_B_Cu;
MAP_OGL_DISP_LISTS m_layers_holes_outer; MAP_OGL_DISP_LISTS m_layers_holes_outer;
MAP_OGL_DISP_LISTS m_layers_holes_inner; MAP_OGL_DISP_LISTS m_layers_holes_inner;
CLAYERS_OGL_DISP_LISTS* m_board; OPENGL_RENDER_LIST* m_board;
CLAYERS_OGL_DISP_LISTS* m_board_with_holes; OPENGL_RENDER_LIST* m_board_with_holes;
CLAYERS_OGL_DISP_LISTS* m_anti_board; OPENGL_RENDER_LIST* m_anti_board;
CLAYERS_OGL_DISP_LISTS* m_through_holes_outer; OPENGL_RENDER_LIST* m_through_holes_outer;
CLAYERS_OGL_DISP_LISTS* m_through_holes_vias_outer; OPENGL_RENDER_LIST* m_through_holes_vias_outer;
CLAYERS_OGL_DISP_LISTS* m_through_holes_outer_ring; OPENGL_RENDER_LIST* m_through_holes_outer_ring;
CLAYERS_OGL_DISP_LISTS* m_vias_and_pad_holes_outer_contourn_and_caps; OPENGL_RENDER_LIST* m_vias_and_pad_holes_outer_contourn_and_caps;
LIST_TRIANGLES m_triangles; ///< store pointers so can be deleted latter LIST_TRIANGLES m_triangles; ///< store pointers so can be deleted latter
GLuint m_ogl_circle_texture; GLuint m_ogl_circle_texture;
@ -233,8 +209,8 @@ private:
GLuint m_grid; ///< oGL list that stores current grid GLuint m_grid; ///< oGL list that stores current grid
GRID3D_TYPE m_last_grid_type; ///< Stores the last grid computed GRID3D_TYPE m_last_grid_type; ///< Stores the last grid computed
CLAYERS_OGL_DISP_LISTS* m_vias; OPENGL_RENDER_LIST* m_vias;
CLAYERS_OGL_DISP_LISTS* m_pad_holes; OPENGL_RENDER_LIST* m_pad_holes;
MAP_3DMODEL m_3dmodel_map; MAP_3DMODEL m_3dmodel_map;
@ -243,4 +219,4 @@ private:
SHAPE_POLY_SET m_anti_board_poly; ///< negative polygon representation of the board outline SHAPE_POLY_SET m_anti_board_poly; ///< negative polygon representation of the board outline
}; };
#endif // C3D_RENDER_OGL_LEGACY_H_ #endif // RENDER_3D_LEGACY_H_

View File

@ -39,14 +39,15 @@
/* /*
* Flag to enable connectivity profiling * Flag to enable connectivity profiling.
*
* @ingroup trace_env_vars * @ingroup trace_env_vars
*/ */
const wxChar * C_OGL_3DMODEL::m_logTrace = wxT( "KI_TRACE_EDA_OGL_3DMODEL" ); const wxChar* MODEL_3D::m_logTrace = wxT( "KI_TRACE_EDA_OGL_3DMODEL" );
void C_OGL_3DMODEL::MakeBbox( const CBBOX &aBox, unsigned int aIdxOffset, VERTEX *aVtxOut, void MODEL_3D::MakeBbox( const BBOX_3D& aBox, unsigned int aIdxOffset, VERTEX* aVtxOut,
GLuint *aIdxOut, const glm::vec4 &aColor ) GLuint* aIdxOut, const glm::vec4& aColor )
{ {
aVtxOut[0].m_pos = { aBox.Min().x, aBox.Min().y, aBox.Min().z }; aVtxOut[0].m_pos = { aBox.Min().x, aBox.Min().y, aBox.Min().z };
aVtxOut[1].m_pos = { aBox.Max().x, aBox.Min().y, aBox.Min().z }; aVtxOut[1].m_pos = { aBox.Max().x, aBox.Min().y, aBox.Min().z };
@ -84,9 +85,9 @@ void C_OGL_3DMODEL::MakeBbox( const CBBOX &aBox, unsigned int aIdxOffset, VERTEX
} }
C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel, MATERIAL_MODE aMaterialMode ) MODEL_3D::MODEL_3D( const S3DMODEL& a3DModel, MATERIAL_MODE aMaterialMode )
{ {
wxLogTrace( m_logTrace, wxT( "C_OGL_3DMODEL::C_OGL_3DMODEL %u meshes %u materials" ), wxLogTrace( m_logTrace, wxT( "MODEL_3D::MODEL_3D %u meshes %u materials" ),
static_cast<unsigned int>( a3DModel.m_MeshesSize ), static_cast<unsigned int>( a3DModel.m_MeshesSize ),
static_cast<unsigned int>( a3DModel.m_MaterialsSize ) ); static_cast<unsigned int>( a3DModel.m_MaterialsSize ) );
@ -104,8 +105,7 @@ C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel, MATERIAL_MODE aMaterialM
|| a3DModel.m_MaterialsSize == 0 || a3DModel.m_MeshesSize == 0 ) || a3DModel.m_MaterialsSize == 0 || a3DModel.m_MeshesSize == 0 )
return; return;
// create empty bbox for each mesh. it will be updated when the vertices // create empty bbox for each mesh. it will be updated when the vertices are copied.
// are copied.
m_meshes_bbox.resize( a3DModel.m_MeshesSize ); m_meshes_bbox.resize( a3DModel.m_MeshesSize );
// copy materials for later use during rendering. // copy materials for later use during rendering.
@ -185,8 +185,7 @@ C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel, MATERIAL_MODE aMaterialM
vtx_out.m_cad_color = vtx_out.m_cad_color =
glm::clamp( glm::vec4( MaterialDiffuseToColorCAD( mesh.m_Color[vtx_i] ), glm::clamp( glm::vec4( MaterialDiffuseToColorCAD( mesh.m_Color[vtx_i] ),
1 ) * 255.0f, 1 ) * 255.0f, 0.0f, 255.0f );
0.0f, 255.0f );
} }
else else
{ {
@ -343,9 +342,7 @@ C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel, MATERIAL_MODE aMaterialM
*idx_out++ = static_cast<GLuint>( idx + prev_vtx_count ); *idx_out++ = static_cast<GLuint>( idx + prev_vtx_count );
} }
glBufferSubData( GL_ARRAY_BUFFER, glBufferSubData( GL_ARRAY_BUFFER, vtx_offset, mg.m_vertices.size() * sizeof( VERTEX ),
vtx_offset,
mg.m_vertices.size() * sizeof( VERTEX ),
mg.m_vertices.data() ); mg.m_vertices.data() );
mat.m_render_idx_buffer_offset = idx_offset; mat.m_render_idx_buffer_offset = idx_offset;
@ -358,8 +355,8 @@ C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel, MATERIAL_MODE aMaterialM
glGenBuffers( 1, &m_index_buffer ); glGenBuffers( 1, &m_index_buffer );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_index_buffer ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_index_buffer );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, idx_size * total_index_count, glBufferData( GL_ELEMENT_ARRAY_BUFFER, idx_size * total_index_count, tmp_idx.get(),
tmp_idx.get(), GL_STATIC_DRAW ); GL_STATIC_DRAW );
glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
@ -372,7 +369,7 @@ C_OGL_3DMODEL::C_OGL_3DMODEL( const S3DMODEL &a3DModel, MATERIAL_MODE aMaterialM
} }
void C_OGL_3DMODEL::BeginDrawMulti( bool aUseColorInformation ) void MODEL_3D::BeginDrawMulti( bool aUseColorInformation )
{ {
glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_NORMAL_ARRAY ); glEnableClientState( GL_NORMAL_ARRAY );
@ -388,7 +385,7 @@ void C_OGL_3DMODEL::BeginDrawMulti( bool aUseColorInformation )
} }
void C_OGL_3DMODEL::EndDrawMulti() void MODEL_3D::EndDrawMulti()
{ {
glDisable( GL_COLOR_MATERIAL ); glDisable( GL_COLOR_MATERIAL );
glDisableClientState( GL_VERTEX_ARRAY ); glDisableClientState( GL_VERTEX_ARRAY );
@ -401,7 +398,7 @@ void C_OGL_3DMODEL::EndDrawMulti()
} }
void C_OGL_3DMODEL::Draw( bool aTransparent, float aOpacity, bool aUseSelectedMaterial, void MODEL_3D::Draw( bool aTransparent, float aOpacity, bool aUseSelectedMaterial,
SFVEC3F aSelectionColor ) const SFVEC3F aSelectionColor ) const
{ {
if( aOpacity <= FLT_EPSILON ) if( aOpacity <= FLT_EPSILON )
@ -462,7 +459,7 @@ void C_OGL_3DMODEL::Draw( bool aTransparent, float aOpacity, bool aUseSelectedMa
} }
C_OGL_3DMODEL::~C_OGL_3DMODEL() MODEL_3D::~MODEL_3D()
{ {
if( glDeleteBuffers ) if( glDeleteBuffers )
{ {
@ -474,7 +471,7 @@ C_OGL_3DMODEL::~C_OGL_3DMODEL()
} }
void C_OGL_3DMODEL::Draw_bbox() const void MODEL_3D::Draw_bbox() const
{ {
if( !glBindBuffer ) if( !glBindBuffer )
throw std::runtime_error( "The OpenGL context no longer exists: unable to draw bbox" ); throw std::runtime_error( "The OpenGL context no longer exists: unable to draw bbox" );
@ -493,7 +490,7 @@ void C_OGL_3DMODEL::Draw_bbox() const
} }
void C_OGL_3DMODEL::Draw_bboxes() const void MODEL_3D::Draw_bboxes() const
{ {
if( !glBindBuffer ) if( !glBindBuffer )
throw std::runtime_error( "The OpenGL context no longer exists: unable to draw bboxes" ); throw std::runtime_error( "The OpenGL context no longer exists: unable to draw bboxes" );

View File

@ -28,8 +28,8 @@
* @brief implement a legacy 3dmodel render * @brief implement a legacy 3dmodel render
*/ */
#ifndef _C_OGL_3DMODEL_H_ #ifndef _MODEL_3D_H_
#define _C_OGL_3DMODEL_H_ #define _MODEL_3D_H_
#include <vector> #include <vector>
#include <plugins/3dapi/c3dmodel.h> #include <plugins/3dapi/c3dmodel.h>
@ -37,25 +37,25 @@
#include "../3d_render_raytracing/shapes3D/cbbox.h" #include "../3d_render_raytracing/shapes3D/cbbox.h"
#include "../../3d_enums.h" #include "../../3d_enums.h"
class C_OGL_3DMODEL class MODEL_3D
{ {
public: public:
/** /**
* Load a 3d model. * Load a 3D model.
* *
* @note This must be called inside a gl context. * @note This must be called inside a gl context.
*
* @param a3DModel a 3d model data to load. * @param a3DModel a 3d model data to load.
* @param aMaterialMode a mode to render the materials of the model. * @param aMaterialMode a mode to render the materials of the model.
*/ */
C_OGL_3DMODEL( const S3DMODEL &a3DModel, MATERIAL_MODE aMaterialMode ); MODEL_3D( const S3DMODEL& a3DModel, MATERIAL_MODE aMaterialMode );
~C_OGL_3DMODEL(); ~MODEL_3D();
/** /**
* Render the model into the current context. * Render the model into the current context.
*/ */
void Draw_opaque( bool aUseSelectedMaterial, void Draw_opaque( bool aUseSelectedMaterial, SFVEC3F aSelectionColor = SFVEC3F( 0.0f ) ) const
SFVEC3F aSelectionColor = SFVEC3F( 0.0f ) ) const
{ {
Draw( false, 1.0f, aUseSelectedMaterial, aSelectionColor ); Draw( false, 1.0f, aUseSelectedMaterial, aSelectionColor );
} }
@ -93,7 +93,7 @@ public:
* Get the main bounding box. * Get the main bounding box.
* @return the main model bounding box. * @return the main model bounding box.
*/ */
const CBBOX &GetBBox() const { return m_model_bbox; } const BBOX_3D& GetBBox() const { return m_model_bbox; }
/** /**
* Set some basic render states before drawing multiple models. * Set some basic render states before drawing multiple models.
@ -106,15 +106,15 @@ public:
static void EndDrawMulti(); static void EndDrawMulti();
private: private:
static const wxChar *m_logTrace; static const wxChar* m_logTrace;
// the material mode that was used to generate the rendering data. // the material mode that was used to generate the rendering data.
// FIXME: this can be selected at run-time and does not require re-creation // FIXME: this can be selected at run-time and does not require re-creation
// of the whole model objects. // of the whole model objects.
MATERIAL_MODE m_material_mode; MATERIAL_MODE m_material_mode;
CBBOX m_model_bbox; ///< global bounding box for this model BBOX_3D m_model_bbox; ///< global bounding box for this model
std::vector<CBBOX> m_meshes_bbox; ///< individual bbox for each mesh std::vector<BBOX_3D> m_meshes_bbox; ///< individual bbox for each mesh
// unified vertex format for mesh rendering. // unified vertex format for mesh rendering.
struct VERTEX struct VERTEX
@ -139,7 +139,7 @@ private:
unsigned int m_render_idx_buffer_offset = 0; unsigned int m_render_idx_buffer_offset = 0;
unsigned int m_render_idx_count = 0; unsigned int m_render_idx_count = 0;
MATERIAL( const SMATERIAL &aOther ) : SMATERIAL( aOther ) { } MATERIAL( const SMATERIAL& aOther ) : SMATERIAL( aOther ) { }
bool IsTransparent() const { return m_Transparency > FLT_EPSILON; } bool IsTransparent() const { return m_Transparency > FLT_EPSILON; }
}; };
@ -160,12 +160,11 @@ private:
GLuint m_bbox_index_buffer = 0; GLuint m_bbox_index_buffer = 0;
GLenum m_bbox_index_buffer_type = GL_INVALID_ENUM; GLenum m_bbox_index_buffer_type = GL_INVALID_ENUM;
static void MakeBbox( const CBBOX &aBox, unsigned int aIdxOffset, static void MakeBbox( const BBOX_3D& aBox, unsigned int aIdxOffset, VERTEX* aVtxOut,
VERTEX *aVtxOut, GLuint *aIdxOut, GLuint* aIdxOut, const glm::vec4& aColor );
const glm::vec4 &aColor );
void Draw( bool aTransparent, float aOpacity, bool aUseSelectedMaterial, void Draw( bool aTransparent, float aOpacity, bool aUseSelectedMaterial,
SFVEC3F aSelectionColor ) const; SFVEC3F aSelectionColor ) const;
}; };
#endif // _C_OGL_3DMODEL_H_ #endif // _MODEL_3D_H_

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,7 +24,6 @@
/** /**
* @file clayer_triangles.cpp * @file clayer_triangles.cpp
* @brief
*/ */
@ -35,8 +34,7 @@
#include <atomic> #include <atomic>
CLAYER_TRIANGLE_CONTAINER::CLAYER_TRIANGLE_CONTAINER( unsigned int aNrReservedTriangles, TRIANGLE_LIST::TRIANGLE_LIST( unsigned int aNrReservedTriangles, bool aReserveNormals )
bool aReserveNormals )
{ {
wxASSERT( aNrReservedTriangles > 0 ); wxASSERT( aNrReservedTriangles > 0 );
@ -50,8 +48,7 @@ CLAYER_TRIANGLE_CONTAINER::CLAYER_TRIANGLE_CONTAINER( unsigned int aNrReservedTr
} }
void CLAYER_TRIANGLE_CONTAINER::Reserve_More( unsigned int aNrReservedTriangles, void TRIANGLE_LIST::Reserve_More( unsigned int aNrReservedTriangles, bool aReserveNormals )
bool aReserveNormals )
{ {
m_vertexs.reserve( m_vertexs.size() + aNrReservedTriangles * 3 ); m_vertexs.reserve( m_vertexs.size() + aNrReservedTriangles * 3 );
@ -60,10 +57,8 @@ void CLAYER_TRIANGLE_CONTAINER::Reserve_More( unsigned int aNrReservedTriangles,
} }
void CLAYER_TRIANGLE_CONTAINER::AddQuad( const SFVEC3F &aV1, void TRIANGLE_LIST::AddQuad( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3,
const SFVEC3F &aV2, const SFVEC3F& aV4 )
const SFVEC3F &aV3,
const SFVEC3F &aV4 )
{ {
m_vertexs.push_back( aV1 ); m_vertexs.push_back( aV1 );
m_vertexs.push_back( aV2 ); m_vertexs.push_back( aV2 );
@ -75,9 +70,7 @@ void CLAYER_TRIANGLE_CONTAINER::AddQuad( const SFVEC3F &aV1,
} }
void CLAYER_TRIANGLE_CONTAINER::AddTriangle( const SFVEC3F &aV1, void TRIANGLE_LIST::AddTriangle( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3 )
const SFVEC3F &aV2,
const SFVEC3F &aV3 )
{ {
m_vertexs.push_back( aV1 ); m_vertexs.push_back( aV1 );
m_vertexs.push_back( aV2 ); m_vertexs.push_back( aV2 );
@ -85,19 +78,15 @@ void CLAYER_TRIANGLE_CONTAINER::AddTriangle( const SFVEC3F &aV1,
} }
void CLAYER_TRIANGLE_CONTAINER::AddNormal( const SFVEC3F &aN1, void TRIANGLE_LIST::AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3 )
const SFVEC3F &aN2,
const SFVEC3F &aN3 )
{ {
m_normals.push_back( aN1 ); m_normals.push_back( aN1 );
m_normals.push_back( aN2 ); m_normals.push_back( aN2 );
m_normals.push_back( aN3 ); m_normals.push_back( aN3 );
} }
void CLAYER_TRIANGLE_CONTAINER::AddNormal( const SFVEC3F &aN1, void TRIANGLE_LIST::AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3,
const SFVEC3F &aN2, const SFVEC3F& aN4 )
const SFVEC3F &aN3,
const SFVEC3F &aN4 )
{ {
m_normals.push_back( aN1 ); m_normals.push_back( aN1 );
m_normals.push_back( aN2 ); m_normals.push_back( aN2 );
@ -109,24 +98,19 @@ void CLAYER_TRIANGLE_CONTAINER::AddNormal( const SFVEC3F &aN1,
} }
CLAYER_TRIANGLES::CLAYER_TRIANGLES( unsigned int aNrReservedTriangles ) TRIANGLE_DISPLAY_LIST::TRIANGLE_DISPLAY_LIST( unsigned int aNrReservedTriangles )
{ {
wxASSERT( aNrReservedTriangles > 0 ); wxASSERT( aNrReservedTriangles > 0 );
m_layer_top_segment_ends = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles, m_layer_top_segment_ends = new TRIANGLE_LIST( aNrReservedTriangles, false );
false ); m_layer_top_triangles = new TRIANGLE_LIST( aNrReservedTriangles, false );
m_layer_top_triangles = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles, m_layer_middle_contourns_quads = new TRIANGLE_LIST( aNrReservedTriangles, true );
false ); m_layer_bot_triangles = new TRIANGLE_LIST( aNrReservedTriangles, false );
m_layer_middle_contourns_quads = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles, m_layer_bot_segment_ends = new TRIANGLE_LIST( aNrReservedTriangles, false );
true );
m_layer_bot_triangles = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
false );
m_layer_bot_segment_ends = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
false );
} }
CLAYER_TRIANGLES::~CLAYER_TRIANGLES() TRIANGLE_DISPLAY_LIST::~TRIANGLE_DISPLAY_LIST()
{ {
delete m_layer_top_segment_ends; delete m_layer_top_segment_ends;
m_layer_top_segment_ends = 0; m_layer_top_segment_ends = 0;
@ -145,11 +129,9 @@ CLAYER_TRIANGLES::~CLAYER_TRIANGLES()
} }
void CLAYER_TRIANGLES::AddToMiddleContourns( const std::vector< SFVEC2F > &aContournPoints, void TRIANGLE_DISPLAY_LIST::AddToMiddleContourns( const std::vector< SFVEC2F >& aContournPoints,
float zBot, float zBot, float zTop, bool aInvertFaceDirection,
float zTop, const BVH_CONTAINER_2D* aThroughHoles )
bool aInvertFaceDirection,
const CBVHCONTAINER2D *aThroughHoles )
{ {
if( aContournPoints.size() >= 4 ) if( aContournPoints.size() >= 4 )
{ {
@ -163,8 +145,8 @@ void CLAYER_TRIANGLES::AddToMiddleContourns( const std::vector< SFVEC2F > &aCont
{ {
for( unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i ) for( unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
{ {
const SFVEC2F &v0 = aContournPoints[i + 0]; const SFVEC2F& v0 = aContournPoints[i + 0];
const SFVEC2F &v1 = aContournPoints[i + 1]; const SFVEC2F& v1 = aContournPoints[i + 1];
const SFVEC2F n = glm::normalize( v1 - v0 ); const SFVEC2F n = glm::normalize( v1 - v0 );
contournNormals[i] = SFVEC2F( n.y,-n.x ); contournNormals[i] = SFVEC2F( n.y,-n.x );
@ -174,8 +156,8 @@ void CLAYER_TRIANGLES::AddToMiddleContourns( const std::vector< SFVEC2F > &aCont
{ {
for( unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i ) for( unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
{ {
const SFVEC2F &v0 = aContournPoints[i + 0]; const SFVEC2F& v0 = aContournPoints[i + 0];
const SFVEC2F &v1 = aContournPoints[i + 1]; const SFVEC2F& v1 = aContournPoints[i + 1];
const SFVEC2F n = glm::normalize( v1 - v0 ); const SFVEC2F n = glm::normalize( v1 - v0 );
contournNormals[i] = SFVEC2F( -n.y, n.x ); contournNormals[i] = SFVEC2F( -n.y, n.x );
@ -218,11 +200,13 @@ void CLAYER_TRIANGLES::AddToMiddleContourns( const std::vector< SFVEC2F > &aCont
const SFVEC3F n3d0 = SFVEC3F( n0.x, n0.y, 0.0f ); const SFVEC3F n3d0 = SFVEC3F( n0.x, n0.y, 0.0f );
const SFVEC3F n3d1 = SFVEC3F( n1.x, n1.y, 0.0f ); const SFVEC3F n3d1 = SFVEC3F( n1.x, n1.y, 0.0f );
const SFVEC2F &v0 = aContournPoints[i + 0]; const SFVEC2F& v0 = aContournPoints[i + 0];
const SFVEC2F &v1 = aContournPoints[i + 1]; const SFVEC2F& v1 = aContournPoints[i + 1];
if( aThroughHoles && aThroughHoles->IntersectAny( RAYSEG2D( v0, v1 ) ) ) if( aThroughHoles && aThroughHoles->IntersectAny( RAYSEG2D( v0, v1 ) ) )
{
continue; continue;
}
else else
{ {
std::lock_guard<std::mutex> lock( m_middle_layer_lock ); std::lock_guard<std::mutex> lock( m_middle_layer_lock );
@ -238,31 +222,27 @@ void CLAYER_TRIANGLES::AddToMiddleContourns( const std::vector< SFVEC2F > &aCont
} }
void CLAYER_TRIANGLES::AddToMiddleContourns( const SHAPE_LINE_CHAIN &outlinePath, void TRIANGLE_DISPLAY_LIST::AddToMiddleContourns( const SHAPE_LINE_CHAIN& outlinePath, float zBot,
float zBot, float zTop, double aBiuTo3Du,
float zTop,
double aBiuTo3Du,
bool aInvertFaceDirection, bool aInvertFaceDirection,
const CBVHCONTAINER2D *aThroughHoles ) const BVH_CONTAINER_2D* aThroughHoles )
{ {
std::vector< SFVEC2F >contournPoints; std::vector< SFVEC2F >contournPoints;
contournPoints.clear(); contournPoints.clear();
contournPoints.reserve( outlinePath.PointCount() + 2 ); contournPoints.reserve( outlinePath.PointCount() + 2 );
const VECTOR2I &firstV = outlinePath.CPoint( 0 ); const VECTOR2I& firstV = outlinePath.CPoint( 0 );
SFVEC2F lastV = SFVEC2F( firstV.x * aBiuTo3Du, SFVEC2F lastV = SFVEC2F( firstV.x * aBiuTo3Du, -firstV.y * aBiuTo3Du );
-firstV.y * aBiuTo3Du );
contournPoints.push_back( lastV ); contournPoints.push_back( lastV );
for( unsigned int i = 1; i < (unsigned int)outlinePath.PointCount(); ++i ) for( unsigned int i = 1; i < (unsigned int)outlinePath.PointCount(); ++i )
{ {
const VECTOR2I & v = outlinePath.CPoint( i ); const VECTOR2I& v = outlinePath.CPoint( i );
const SFVEC2F vf = SFVEC2F( v.x * aBiuTo3Du, const SFVEC2F vf = SFVEC2F( v.x * aBiuTo3Du, -v.y * aBiuTo3Du );
-v.y * aBiuTo3Du );
if( vf != lastV ) // Do not add repeated points if( vf != lastV ) // Do not add repeated points
{ {
@ -279,12 +259,10 @@ void CLAYER_TRIANGLES::AddToMiddleContourns( const SHAPE_LINE_CHAIN &outlinePath
} }
void CLAYER_TRIANGLES::AddToMiddleContourns( const SHAPE_POLY_SET &aPolySet, void TRIANGLE_DISPLAY_LIST::AddToMiddleContourns( const SHAPE_POLY_SET& aPolySet, float zBot,
float zBot, float zTop, double aBiuTo3Du,
float zTop,
double aBiuTo3Du,
bool aInvertFaceDirection, bool aInvertFaceDirection,
const CBVHCONTAINER2D *aThroughHoles ) const BVH_CONTAINER_2D* aThroughHoles )
{ {
if( aPolySet.OutlineCount() == 0 ) if( aPolySet.OutlineCount() == 0 )
return; return;
@ -300,37 +278,37 @@ void CLAYER_TRIANGLES::AddToMiddleContourns( const SHAPE_POLY_SET &aPolySet,
for( int h = 0; h < aPolySet.HoleCount( i ); ++h ) for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
{ {
const SHAPE_LINE_CHAIN &hole = aPolySet.CHole( i, h ); const SHAPE_LINE_CHAIN& hole = aPolySet.CHole( i, h );
nrContournPointsToReserve += hole.PointCount(); nrContournPointsToReserve += hole.PointCount();
} }
} }
// Request to reserve more space // Request to reserve more space
m_layer_middle_contourns_quads->Reserve_More( nrContournPointsToReserve * 2, m_layer_middle_contourns_quads->Reserve_More( nrContournPointsToReserve * 2, true );
true );
for( int i = 0; i < aPolySet.OutlineCount(); i++ ) for( int i = 0; i < aPolySet.OutlineCount(); i++ )
{ {
// Add outline // Add outline
const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i ); const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
AddToMiddleContourns( pathOutline, zBot, zTop, aBiuTo3Du, aInvertFaceDirection, aThroughHoles ); AddToMiddleContourns( pathOutline, zBot, zTop, aBiuTo3Du, aInvertFaceDirection,
aThroughHoles );
// Add holes for this outline // Add holes for this outline
for( int h = 0; h < aPolySet.HoleCount( i ); ++h ) for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
{ {
const SHAPE_LINE_CHAIN &hole = aPolySet.CHole( i, h ); const SHAPE_LINE_CHAIN& hole = aPolySet.CHole( i, h );
AddToMiddleContourns( hole, zBot, zTop, aBiuTo3Du, aInvertFaceDirection, aThroughHoles ); AddToMiddleContourns( hole, zBot, zTop, aBiuTo3Du, aInvertFaceDirection,
aThroughHoles );
} }
} }
} }
CLAYERS_OGL_DISP_LISTS::CLAYERS_OGL_DISP_LISTS( const CLAYER_TRIANGLES &aLayerTriangles, OPENGL_RENDER_LIST::OPENGL_RENDER_LIST( const TRIANGLE_DISPLAY_LIST& aLayerTriangles,
GLuint aTextureIndexForSegEnds, GLuint aTextureIndexForSegEnds,
float aZBot, float aZBot, float aZTop )
float aZTop )
{ {
m_zBot = aZBot; m_zBot = aZBot;
m_zTop = aZTop; m_zTop = aZTop;
@ -349,13 +327,11 @@ CLAYERS_OGL_DISP_LISTS::CLAYERS_OGL_DISP_LISTS( const CLAYER_TRIANGLES &aLayerTr
{ {
m_layer_top_segment_ends = m_layer_top_segment_ends =
generate_top_or_bot_seg_ends( aLayerTriangles.m_layer_top_segment_ends, generate_top_or_bot_seg_ends( aLayerTriangles.m_layer_top_segment_ends,
true, true, aTextureIndexForSegEnds );
aTextureIndexForSegEnds );
m_layer_bot_segment_ends = m_layer_bot_segment_ends =
generate_top_or_bot_seg_ends( aLayerTriangles.m_layer_bot_segment_ends, generate_top_or_bot_seg_ends( aLayerTriangles.m_layer_bot_segment_ends,
false, false, aTextureIndexForSegEnds );
aTextureIndexForSegEnds );
} }
} }
@ -379,7 +355,7 @@ CLAYERS_OGL_DISP_LISTS::CLAYERS_OGL_DISP_LISTS( const CLAYER_TRIANGLES &aLayerTr
} }
CLAYERS_OGL_DISP_LISTS::~CLAYERS_OGL_DISP_LISTS() OPENGL_RENDER_LIST::~OPENGL_RENDER_LIST()
{ {
if( glIsList( m_layer_top_segment_ends ) ) if( glIsList( m_layer_top_segment_ends ) )
glDeleteLists( m_layer_top_segment_ends, 1 ); glDeleteLists( m_layer_top_segment_ends, 1 );
@ -404,7 +380,7 @@ CLAYERS_OGL_DISP_LISTS::~CLAYERS_OGL_DISP_LISTS()
} }
void CLAYERS_OGL_DISP_LISTS::DrawTopAndMiddle() const void OPENGL_RENDER_LIST::DrawTopAndMiddle() const
{ {
beginTransformation(); beginTransformation();
@ -421,7 +397,7 @@ void CLAYERS_OGL_DISP_LISTS::DrawTopAndMiddle() const
} }
void CLAYERS_OGL_DISP_LISTS::DrawBotAndMiddle() const void OPENGL_RENDER_LIST::DrawBotAndMiddle() const
{ {
beginTransformation(); beginTransformation();
@ -438,7 +414,7 @@ void CLAYERS_OGL_DISP_LISTS::DrawBotAndMiddle() const
} }
void CLAYERS_OGL_DISP_LISTS::DrawTop() const void OPENGL_RENDER_LIST::DrawTop() const
{ {
beginTransformation(); beginTransformation();
@ -452,7 +428,7 @@ void CLAYERS_OGL_DISP_LISTS::DrawTop() const
} }
void CLAYERS_OGL_DISP_LISTS::DrawBot() const void OPENGL_RENDER_LIST::DrawBot() const
{ {
beginTransformation(); beginTransformation();
@ -466,7 +442,7 @@ void CLAYERS_OGL_DISP_LISTS::DrawBot() const
} }
void CLAYERS_OGL_DISP_LISTS::DrawMiddle() const void OPENGL_RENDER_LIST::DrawMiddle() const
{ {
beginTransformation(); beginTransformation();
@ -477,7 +453,7 @@ void CLAYERS_OGL_DISP_LISTS::DrawMiddle() const
} }
void CLAYERS_OGL_DISP_LISTS::DrawAll( bool aDrawMiddle ) const void OPENGL_RENDER_LIST::DrawAll( bool aDrawMiddle ) const
{ {
beginTransformation(); beginTransformation();
@ -501,10 +477,11 @@ void CLAYERS_OGL_DISP_LISTS::DrawAll( bool aDrawMiddle ) const
} }
void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulled(float zCameraPos, bool aDrawMiddle ) const void OPENGL_RENDER_LIST::DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle ) const
{ {
zCameraPos = m_haveTransformation?( (zCameraPos - m_zPositionTransformation ) / zCameraPos = m_haveTransformation
m_zScaleTransformation ):zCameraPos; ? ( ( zCameraPos - m_zPositionTransformation ) / m_zScaleTransformation )
: zCameraPos;
if( aDrawMiddle ) if( aDrawMiddle )
DrawMiddle(); DrawMiddle();
@ -521,17 +498,17 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulled(float zCameraPos, bool aDrawMid
} }
else else
{ {
// If camera is in the middle dont draw it // If camera is in the middle dont draw it.
} }
} }
} }
void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer( bool aDrawMiddle, void OPENGL_RENDER_LIST::DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractA, const OPENGL_RENDER_LIST* aLayerToSubtractA,
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractB, const OPENGL_RENDER_LIST* aLayerToSubtractB,
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractC, const OPENGL_RENDER_LIST* aLayerToSubtractC,
const CLAYERS_OGL_DISP_LISTS *aLayerToSubtractD ) const const OPENGL_RENDER_LIST* aLayerToSubtractD ) const
{ {
glClearStencil( 0x00 ); glClearStencil( 0x00 );
glClear( GL_STENCIL_BUFFER_BIT ); glClear( GL_STENCIL_BUFFER_BIT );
@ -558,11 +535,8 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
if( aLayerToSubtractD ) if( aLayerToSubtractD )
aLayerToSubtractD->DrawBot(); aLayerToSubtractD->DrawBot();
//if( !m_draw_it_transparent )
{
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
}
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
glStencilFunc( GL_EQUAL, 0, 1 ); glStencilFunc( GL_EQUAL, 0, 1 );
@ -588,12 +562,8 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
if( aLayerToSubtractD ) if( aLayerToSubtractD )
aLayerToSubtractD->DrawTop(); aLayerToSubtractD->DrawTop();
//if( !m_draw_it_transparent )
{
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
}
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
glStencilFunc( GL_NOTEQUAL, 2, 0x03 ); glStencilFunc( GL_NOTEQUAL, 2, 0x03 );
glStencilOp( GL_KEEP, GL_KEEP, GL_INCR ); glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
@ -613,32 +583,16 @@ void CLAYERS_OGL_DISP_LISTS::DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
{ {
if( aLayerToSubtractA ) if( aLayerToSubtractA )
aLayerToSubtractA->DrawMiddle(); aLayerToSubtractA->DrawMiddle();
// It will not render the middle contours of the layer.
// It is used with vias and holes (copper vias and to subtract solder
// mask holes). But since in the vias, it will draw a cylinder
// and in soldermask it doesn't need to draw the contour.
// so it is not used the middle part of B
// if( aLayerToSubtractB )
// aLayerToSubtractB->DrawMiddle();
} }
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE ); glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
glCullFace( GL_BACK ); glCullFace( GL_BACK );
glDisable( GL_STENCIL_TEST ); glDisable( GL_STENCIL_TEST );
/*
if( m_draw_it_transparent )
{
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
}*/
} }
void CLAYERS_OGL_DISP_LISTS::ApplyScalePosition( float aZposition, void OPENGL_RENDER_LIST::ApplyScalePosition( float aZposition, float aZscale )
float aZscale )
{ {
wxASSERT( aZscale > FLT_EPSILON ); wxASSERT( aZscale > FLT_EPSILON );
@ -648,37 +602,33 @@ void CLAYERS_OGL_DISP_LISTS::ApplyScalePosition( float aZposition,
} }
void CLAYERS_OGL_DISP_LISTS::SetItIsTransparent( bool aSetTransparent ) void OPENGL_RENDER_LIST::SetItIsTransparent( bool aSetTransparent )
{ {
m_draw_it_transparent = aSetTransparent; m_draw_it_transparent = aSetTransparent;
} }
GLuint CLAYERS_OGL_DISP_LISTS::generate_top_or_bot_seg_ends( GLuint OPENGL_RENDER_LIST::generate_top_or_bot_seg_ends(
const CLAYER_TRIANGLE_CONTAINER *aTriangleContainer, const TRIANGLE_LIST* aTriangleContainer, bool aIsNormalUp, GLuint aTextureId ) const
bool aIsNormalUp,
GLuint aTextureId ) const
{ {
wxASSERT( aTriangleContainer != NULL ); wxASSERT( aTriangleContainer != nullptr );
wxASSERT( (aTriangleContainer->GetVertexSize() % 3) == 0 ); wxASSERT( (aTriangleContainer->GetVertexSize() % 3) == 0 );
// Top and Bot dont have normals array stored in container // Top and Bot dont have normals array stored in container
wxASSERT( aTriangleContainer->GetNormalsSize() == 0 ); wxASSERT( aTriangleContainer->GetNormalsSize() == 0 );
if( (aTriangleContainer->GetVertexSize() > 0) && if( ( aTriangleContainer->GetVertexSize() > 0 )
((aTriangleContainer->GetVertexSize() % 3) == 0) ) && ( ( aTriangleContainer->GetVertexSize() % 3 ) == 0 ) )
{ {
GLuint listIdx = glGenLists( 1 ); GLuint listIdx = glGenLists( 1 );
if( glIsList( listIdx ) ) if( glIsList( listIdx ) )
{ {
// Prepare an array of UV text coordinates // Prepare an array of UV text coordinates
SFVEC2F *uvArray = new SFVEC2F[aTriangleContainer->GetVertexSize()]; SFVEC2F* uvArray = new SFVEC2F[aTriangleContainer->GetVertexSize()];
for( unsigned int i = 0; for( unsigned int i = 0; i < aTriangleContainer->GetVertexSize(); i += 3 )
i < aTriangleContainer->GetVertexSize();
i += 3 )
{ {
uvArray[i + 0] = SFVEC2F( 1.0f, 0.0f ); uvArray[i + 0] = SFVEC2F( 1.0f, 0.0f );
uvArray[i + 1] = SFVEC2F( 0.0f, 1.0f ); uvArray[i + 1] = SFVEC2F( 0.0f, 1.0f );
@ -726,19 +676,18 @@ GLuint CLAYERS_OGL_DISP_LISTS::generate_top_or_bot_seg_ends(
} }
GLuint CLAYERS_OGL_DISP_LISTS::generate_top_or_bot_triangles( GLuint OPENGL_RENDER_LIST::generate_top_or_bot_triangles(
const CLAYER_TRIANGLE_CONTAINER *aTriangleContainer, const TRIANGLE_LIST* aTriangleContainer, bool aIsNormalUp ) const
bool aIsNormalUp ) const
{ {
wxASSERT( aTriangleContainer != NULL ); wxASSERT( aTriangleContainer != nullptr );
wxASSERT( (aTriangleContainer->GetVertexSize() % 3) == 0 ); wxASSERT( ( aTriangleContainer->GetVertexSize() % 3 ) == 0 );
// Top and Bot dont have normals array stored in container // Top and Bot dont have normals array stored in container
wxASSERT( aTriangleContainer->GetNormalsSize() == 0 ); wxASSERT( aTriangleContainer->GetNormalsSize() == 0 );
if( (aTriangleContainer->GetVertexSize() > 0) && if( ( aTriangleContainer->GetVertexSize() > 0 )
( (aTriangleContainer->GetVertexSize() % 3) == 0) ) && ( ( aTriangleContainer->GetVertexSize() % 3 ) == 0 ) )
{ {
const GLuint listIdx = glGenLists( 1 ); const GLuint listIdx = glGenLists( 1 );
@ -771,25 +720,24 @@ GLuint CLAYERS_OGL_DISP_LISTS::generate_top_or_bot_triangles(
} }
GLuint CLAYERS_OGL_DISP_LISTS::generate_middle_triangles( GLuint OPENGL_RENDER_LIST::generate_middle_triangles(
const CLAYER_TRIANGLE_CONTAINER *aTriangleContainer ) const const TRIANGLE_LIST* aTriangleContainer ) const
{ {
wxASSERT( aTriangleContainer != NULL ); wxASSERT( aTriangleContainer != nullptr );
// We expect that it is a multiple of 3 vertex // We expect that it is a multiple of 3 vertex
wxASSERT( (aTriangleContainer->GetVertexSize() % 3) == 0 ); wxASSERT( ( aTriangleContainer->GetVertexSize() % 3 ) == 0 );
// We expect that it is a multiple of 6 vertex (because we expect to add quads) // We expect that it is a multiple of 6 vertex (because we expect to add quads)
wxASSERT( (aTriangleContainer->GetVertexSize() % 6) == 0 ); wxASSERT( (aTriangleContainer->GetVertexSize() % 6 ) == 0 );
// We expect that there are normals with same size as vertex // We expect that there are normals with same size as vertex
wxASSERT( aTriangleContainer->GetNormalsSize() == aTriangleContainer->GetVertexSize() ); wxASSERT( aTriangleContainer->GetNormalsSize() == aTriangleContainer->GetVertexSize() );
if( ( aTriangleContainer->GetVertexSize() > 0 )
if( ( aTriangleContainer->GetVertexSize() > 0 ) && && ( ( aTriangleContainer->GetVertexSize() % 3 ) == 0 )
( (aTriangleContainer->GetVertexSize() % 3) == 0 ) && && ( ( aTriangleContainer->GetVertexSize() % 6 ) == 0 )
( (aTriangleContainer->GetVertexSize() % 6) == 0 ) && && ( aTriangleContainer->GetNormalsSize() == aTriangleContainer->GetVertexSize() ) )
( aTriangleContainer->GetNormalsSize() == aTriangleContainer->GetVertexSize() ) )
{ {
const GLuint listIdx = glGenLists( 1 ); const GLuint listIdx = glGenLists( 1 );
@ -822,7 +770,7 @@ GLuint CLAYERS_OGL_DISP_LISTS::generate_middle_triangles(
} }
void CLAYERS_OGL_DISP_LISTS::endTransformation() const void OPENGL_RENDER_LIST::endTransformation() const
{ {
if( m_haveTransformation ) if( m_haveTransformation )
{ {
@ -831,14 +779,14 @@ void CLAYERS_OGL_DISP_LISTS::endTransformation() const
} }
void CLAYERS_OGL_DISP_LISTS::setBlendfunction() const void OPENGL_RENDER_LIST::setBlendfunction() const
{ {
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
} }
void CLAYERS_OGL_DISP_LISTS::beginTransformation() const void OPENGL_RENDER_LIST::beginTransformation() const
{ {
if( m_haveTransformation ) if( m_haveTransformation )
{ {

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,11 +24,10 @@
/** /**
* @file clayer_triangles.h * @file clayer_triangles.h
* @brief
*/ */
#ifndef CLAYER_TRIANGLES_H_ #ifndef TRIANGLE_DISPLAY_LIST_H_
#define CLAYER_TRIANGLES_H_ #define TRIANGLE_DISPLAY_LIST_H_
#include "../../common_ogl/openGL_includes.h" #include "../../common_ogl/openGL_includes.h"
#include <plugins/3dapi/xv3d_types.h> #include <plugins/3dapi/xv3d_types.h>
@ -43,89 +42,49 @@ typedef std::vector< SFVEC3F > SFVEC3F_VECTOR;
/** /**
* @brief The CLAYER_TRIANGLE_CONTAINER class stores an manage vector of triangles * Container to manage a vector of triangles.
*/ */
class CLAYER_TRIANGLE_CONTAINER class TRIANGLE_LIST
{ {
public: public:
/** /**
* @brief CLAYER_TRIANGLE_CONTAINER * @param aNrReservedTriangles is number of triangles expected to be used.
* @param aNrReservedTriangles: number of triangles expected to be used * @param aReserveNormals if you use normals, set it to bool to reserve space.
* @param aReserveNormals: if you will use normals, set it to bool to pre
* reserve space
*/ */
CLAYER_TRIANGLE_CONTAINER( unsigned int aNrReservedTriangles, bool aReserveNormals ); TRIANGLE_LIST( unsigned int aNrReservedTriangles, bool aReserveNormals );
/** /**
* @brief Reserve_More - reserve more triangles * Reserve more triangles.
*
*/ */
void Reserve_More( unsigned int aNrReservedTriangles, bool aReserveNormals ); void Reserve_More( unsigned int aNrReservedTriangles, bool aReserveNormals );
/** void AddTriangle( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3 );
* @brief AddTriangle
* @param aV1 void AddQuad( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3, const SFVEC3F& aV4 );
* @param aV2
* @param aV3 void AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3 );
*/
void AddTriangle( const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3 ); void AddNormal( const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3,
const SFVEC3F& aN4 );
/** /**
* @brief AddQuad * Get the array of vertexes.
* @param aV1 *
* @param aV2 * @return a pointer to the start of array vertex.
* @param aV3
* @param aV4
*/ */
void AddQuad( const SFVEC3F &aV1, const float* GetVertexPointer() const { return (const float *)&m_vertexs[0].x; }
const SFVEC3F &aV2,
const SFVEC3F &aV3,
const SFVEC3F &aV4 );
/** /**
* @brief AddNormal * Get the array of normals.
* @param aN1 *
* @param aN2 * @return a pointer to start of array of normals.
* @param aN3
*/ */
void AddNormal( const SFVEC3F &aN1, const SFVEC3F &aN2, const SFVEC3F &aN3 ); const float* GetNormalsPointer() const { return (const float*) &m_normals[0].x; }
/** unsigned int GetVertexSize() const { return (unsigned int) m_vertexs.size(); }
* @brief AddNormal
* @param aN1
* @param aN2
* @param aN3
*/
void AddNormal( const SFVEC3F &aN1,
const SFVEC3F &aN2,
const SFVEC3F &aN3,
const SFVEC3F &aN4 );
/** unsigned int GetNormalsSize() const { return (unsigned int) m_normals.size(); }
* @brief GetVertexPointer - Get the array of vertexes
* @return The pointer to the start of array vertex
*/
const float *GetVertexPointer() const { return (const float *)&m_vertexs[0].x; }
/**
* @brief GetNormalsPointer - Get the array of normals
* @return The pointer to start of array of normals
*/
const float *GetNormalsPointer() const { return (const float *)&m_normals[0].x; }
/**
* @brief GetVertexSize
* @return
*/
unsigned int GetVertexSize() const { return (unsigned int)m_vertexs.size(); }
/**
* @brief GetNormalsSize
* @return
*/
unsigned int GetNormalsSize() const { return (unsigned int)m_normals.size(); }
private: private:
SFVEC3F_VECTOR m_vertexs; ///< vertex array SFVEC3F_VECTOR m_vertexs; ///< vertex array
@ -134,134 +93,118 @@ private:
/** /**
* @brief The CLAYER_TRIANGLES class stores arrays of triangles to be used to * Store arrays of triangles to be used to create display lists.
* create display lists
*/ */
class CLAYER_TRIANGLES class TRIANGLE_DISPLAY_LIST
{ {
public: public:
/** /**
* @brief CLAYER_TRIANGLES - initialize arrays with reserved triangles * Initialize arrays with reserved triangles.
* @param aNrReservedTriangles: number of pre alloc triangles to reserve *
* @param aNrReservedTriangles is the number of triangles to reserve.
*/ */
explicit CLAYER_TRIANGLES( unsigned int aNrReservedTriangles ); explicit TRIANGLE_DISPLAY_LIST( unsigned int aNrReservedTriangles );
~TRIANGLE_DISPLAY_LIST();
/** /**
* @brief ~CLAYER_TRIANGLES - Free containers * Check if the vertex arrays of the layers are as expected.
*/ *
~CLAYER_TRIANGLES(); * @return true if layers are correctly setup.
/**
* @brief IsLayersSizeValid - check if the vertex arrays of the layers are
* as expected
* @return TRUE if layers are correctly setup
*/ */
bool IsLayersSizeValid(); bool IsLayersSizeValid();
void AddToMiddleContourns( const SHAPE_LINE_CHAIN &outlinePath, void AddToMiddleContourns( const SHAPE_LINE_CHAIN& outlinePath, float zBot, float zTop,
float zBot, double aBiuTo3Du, bool aInvertFaceDirection,
float zTop, const BVH_CONTAINER_2D* aThroughHoles = nullptr );
double aBiuTo3Du,
bool aInvertFaceDirection,
const CBVHCONTAINER2D *aThroughHoles = nullptr );
void AddToMiddleContourns( const SHAPE_POLY_SET &aPolySet, void AddToMiddleContourns( const SHAPE_POLY_SET& aPolySet, float zBot, float zTop,
float zBot, double aBiuTo3Du, bool aInvertFaceDirection,
float zTop, const BVH_CONTAINER_2D* aThroughHoles = nullptr );
double aBiuTo3Du,
bool aInvertFaceDirection,
const CBVHCONTAINER2D *aThroughHoles = nullptr );
void AddToMiddleContourns( const std::vector< SFVEC2F > &aContournPoints, void AddToMiddleContourns( const std::vector< SFVEC2F >& aContournPoints, float zBot,
float zBot, float zTop, bool aInvertFaceDirection,
float zTop, const BVH_CONTAINER_2D* aThroughHoles = nullptr );
bool aInvertFaceDirection,
const CBVHCONTAINER2D *aThroughHoles = nullptr );
std::mutex m_middle_layer_lock; std::mutex m_middle_layer_lock;
CLAYER_TRIANGLE_CONTAINER *m_layer_top_segment_ends; TRIANGLE_LIST* m_layer_top_segment_ends;
CLAYER_TRIANGLE_CONTAINER *m_layer_top_triangles; TRIANGLE_LIST* m_layer_top_triangles;
CLAYER_TRIANGLE_CONTAINER *m_layer_middle_contourns_quads; TRIANGLE_LIST* m_layer_middle_contourns_quads;
CLAYER_TRIANGLE_CONTAINER *m_layer_bot_triangles; TRIANGLE_LIST* m_layer_bot_triangles;
CLAYER_TRIANGLE_CONTAINER *m_layer_bot_segment_ends; TRIANGLE_LIST* m_layer_bot_segment_ends;
}; };
/** /**
* @brief The CLAYERS_OGL_DISP_LISTS class stores the openGL display lists to * Store the OpenGL display lists to related with a layer.
* related with a layer
*/ */
class CLAYERS_OGL_DISP_LISTS class OPENGL_RENDER_LIST
{ {
public: public:
/** /**
* @brief CLAYERS_OGL_DISP_LISTS - Creates the display lists for a layer * Create the display lists for a layer.
* @param aLayerTriangles: contains the layers array of vertex to render to *
* display lists * @param aLayerTriangles contains the layers array of vertex to render to display lists.
* @param aTextureIndexForSegEnds: texture index to be used by segment ends. * @param aTextureIndexForSegEnds is the texture index to be used by segment ends.
* It is a black and white squared texture * It is a black and white squared texture
* with a center circle diameter of the size * with a center circle diameter of the size
* of the texture. * of the texture.
*/ */
CLAYERS_OGL_DISP_LISTS( const CLAYER_TRIANGLES &aLayerTriangles, OPENGL_RENDER_LIST( const TRIANGLE_DISPLAY_LIST& aLayerTriangles,
GLuint aTextureIndexForSegEnds, GLuint aTextureIndexForSegEnds, float aZBot, float aZTop );
float aZBot,
float aZTop );
/** /**
* @brief ~CLAYERS_OGL_DISP_LISTS - Destroy this class while free the display * Destroy this class while free the display lists from GPU memory.
* lists from GPU mem
*/ */
~CLAYERS_OGL_DISP_LISTS(); ~OPENGL_RENDER_LIST();
/** /**
* @brief DrawTopAndMiddle - This function calls the display lists for the * Call the display lists for the top elements and middle contours.
* top elements and middle contourns
*/ */
void DrawTopAndMiddle() const; void DrawTopAndMiddle() const;
/** /**
* @brief DrawBotAndMiddle - This function calls the display lists for the * Call the display lists for the bottom elements and middle contours.
* botton elements and middle contourns
*/ */
void DrawBotAndMiddle() const; void DrawBotAndMiddle() const;
/** /**
* @brief DrawTop - This function calls the display lists for the top elements * Call the display lists for the top elements.
*/ */
void DrawTop() const; void DrawTop() const;
/** /**
* @brief DrawBot - This function calls the display lists for the botton elements * Call the display lists for the bottom elements.
*/ */
void DrawBot() const; void DrawBot() const;
/** /**
* @brief DrawMiddle - This function calls the display lists for the middle * Call the display lists for the middle elements.
* elements
*/ */
void DrawMiddle() const; void DrawMiddle() const;
/** /**
* @brief DrawAll - This function calls all the display lists * Call to draw all the display lists.
*/ */
void DrawAll( bool aDrawMiddle = true ) const; void DrawAll( bool aDrawMiddle = true ) const;
/** /**
* @brief DrawAllCameraCulled - Draw all layers if they are visible by the camera. * Draw all layers if they are visible by the camera if camera position is above the layer.
* i.e.: if camera position is above the layer. This only works because the *
* board is centered and the planes are always perpendicular to the Z axis. * This only works because the board is centered and the planes are always perpendicular to
* @param zCameraPos: camera z position * the Z axis.
*
* @param zCameraPos is the camera z axis position.
*/ */
void DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle = true ) const; void DrawAllCameraCulled( float zCameraPos, bool aDrawMiddle = true ) const;
void DrawAllCameraCulledSubtractLayer( bool aDrawMiddle, void DrawAllCameraCulledSubtractLayer( bool aDrawMiddle,
const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractA = nullptr, const OPENGL_RENDER_LIST* aLayerToSubtractA = nullptr,
const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractB = nullptr, const OPENGL_RENDER_LIST* aLayerToSubtractB = nullptr,
const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractC = nullptr, const OPENGL_RENDER_LIST* aLayerToSubtractC = nullptr,
const CLAYERS_OGL_DISP_LISTS* aLayerToSubtractD = nullptr ) const; const OPENGL_RENDER_LIST* aLayerToSubtractD = nullptr ) const;
void ApplyScalePosition( float aZposition, float aZscale ); void ApplyScalePosition( float aZposition, float aZscale );
@ -273,14 +216,13 @@ public:
float GetZTop() const { return m_zTop; } float GetZTop() const { return m_zTop; }
private: private:
GLuint generate_top_or_bot_seg_ends( const CLAYER_TRIANGLE_CONTAINER * aTriangleContainer, GLuint generate_top_or_bot_seg_ends( const TRIANGLE_LIST* aTriangleContainer,
bool aIsNormalUp, bool aIsNormalUp, GLuint aTextureId ) const;
GLuint aTextureId ) const;
GLuint generate_top_or_bot_triangles( const CLAYER_TRIANGLE_CONTAINER * aTriangleContainer, GLuint generate_top_or_bot_triangles( const TRIANGLE_LIST* aTriangleContainer,
bool aIsNormalUp ) const; bool aIsNormalUp ) const;
GLuint generate_middle_triangles( const CLAYER_TRIANGLE_CONTAINER * aTriangleContainer ) const; GLuint generate_middle_triangles( const TRIANGLE_LIST* aTriangleContainer ) const;
void beginTransformation() const; void beginTransformation() const;
void endTransformation() const; void endTransformation() const;
@ -303,4 +245,4 @@ private:
bool m_draw_it_transparent; bool m_draw_it_transparent;
}; };
#endif // CLAYER_TRIANGLES_H_ #endif // TRIANGLE_DISPLAY_LIST_H_

View File

@ -35,11 +35,11 @@
#define RADPERDEG 0.0174533 #define RADPERDEG 0.0174533
void OGL_draw_arrow( SFVEC3F aPosition, SFVEC3F aTargetPos, float aSize ) void DrawRoundArrow( SFVEC3F aPosition, SFVEC3F aTargetPos, float aSize )
{ {
wxASSERT( aSize > 0.0f ); wxASSERT( aSize > 0.0f );
SFVEC3F vec = (aTargetPos - aPosition); SFVEC3F vec = aTargetPos - aPosition;
float length = glm::length( vec ); float length = glm::length( vec );
GLUquadricObj *quadObj; GLUquadricObj *quadObj;
@ -52,11 +52,10 @@ void OGL_draw_arrow( SFVEC3F aPosition, SFVEC3F aTargetPos, float aSize )
{ {
glRotatef( atan2( vec.y, vec.x ) / RADPERDEG, 0.0f, 0.0f, 1.0f ); glRotatef( atan2( vec.y, vec.x ) / RADPERDEG, 0.0f, 0.0f, 1.0f );
glRotatef( atan2( sqrt( vec.x * vec.x + vec.y * vec.y ), vec.z ) / RADPERDEG, glRotatef( atan2( sqrt( vec.x * vec.x + vec.y * vec.y ), vec.z ) / RADPERDEG,
0.0f, 0.0f, 1.0f, 0.0f );
1.0f,
0.0f );
} else if( vec.z < 0.0f ) }
else if( vec.z < 0.0f )
{ {
glRotatef( 180.0f, 1.0f, 0.0f, 0.0f ); glRotatef( 180.0f, 1.0f, 0.0f, 0.0f );
} }
@ -95,14 +94,6 @@ void OGL_draw_arrow( SFVEC3F aPosition, SFVEC3F aTargetPos, float aSize )
gluQuadricNormals( quadObj, GLU_SMOOTH ); gluQuadricNormals( quadObj, GLU_SMOOTH );
gluCylinder( quadObj, aSize, aSize, length - 4.0 * aSize, 12, 1 ); gluCylinder( quadObj, aSize, aSize, length - 4.0 * aSize, 12, 1 );
gluDeleteQuadric( quadObj ); gluDeleteQuadric( quadObj );
/*
quadObj = gluNewQuadric();
gluQuadricDrawStyle( quadObj, GLU_FILL );
gluQuadricNormals( quadObj, GLU_SMOOTH );
gluSphere( quadObj, aSize, 24, 24 );
gluDeleteQuadric( quadObj );
*/
quadObj = gluNewQuadric(); quadObj = gluNewQuadric();
gluQuadricDrawStyle( quadObj, GLU_FILL ); gluQuadricDrawStyle( quadObj, GLU_FILL );
@ -114,7 +105,7 @@ void OGL_draw_arrow( SFVEC3F aPosition, SFVEC3F aTargetPos, float aSize )
} }
void OGL_draw_bbox( const CBBOX &aBBox ) void DrawBoundingBox( const BBOX_3D& aBBox )
{ {
wxASSERT( aBBox.IsInitialized() ); wxASSERT( aBBox.IsInitialized() );
@ -154,7 +145,7 @@ void OGL_draw_bbox( const CBBOX &aBBox )
} }
void OGL_draw_half_open_cylinder( unsigned int aNrSidesPerCircle ) void DrawHalfOpenCylinder( unsigned int aNrSidesPerCircle )
{ {
if( aNrSidesPerCircle > 1 ) if( aNrSidesPerCircle > 1 )
{ {
@ -213,8 +204,7 @@ void OGL_draw_half_open_cylinder( unsigned int aNrSidesPerCircle )
} }
void OGL_Draw_segment( const CROUNDSEGMENT2D &aSegment, void DrawSegment( const ROUND_SEGMENT_2D& aSegment, unsigned int aNrSidesPerCircle )
unsigned int aNrSidesPerCircle )
{ {
glPushMatrix(); glPushMatrix();
@ -228,16 +218,13 @@ void OGL_Draw_segment( const CROUNDSEGMENT2D &aSegment,
if( ( end_minus_start.x != 0.0f ) || ( end_minus_start.y != 0.0f ) ) if( ( end_minus_start.x != 0.0f ) || ( end_minus_start.y != 0.0f ) )
{ {
glRotatef( atan2( end_minus_start.y, end_minus_start.x ) / RADPERDEG, glRotatef( atan2( end_minus_start.y, end_minus_start.x ) / RADPERDEG, 0.0f, 0.0f, 1.0f );
0.0f,
0.0f,
1.0f );
} }
glPushMatrix(); glPushMatrix();
glTranslatef( length, 0.0, 0.0f ); glTranslatef( length, 0.0, 0.0f );
glScalef( width, width, 1.0f ); glScalef( width, width, 1.0f );
OGL_draw_half_open_cylinder( aNrSidesPerCircle ); DrawHalfOpenCylinder( aNrSidesPerCircle );
glPopMatrix(); glPopMatrix();
glBegin( GL_QUADS ); glBegin( GL_QUADS );
@ -274,7 +261,7 @@ void OGL_Draw_segment( const CROUNDSEGMENT2D &aSegment,
glScalef( width, width, 1.0f ); glScalef( width, width, 1.0f );
glRotatef( 180, 0.0, 0.0, 1.0 ); glRotatef( 180, 0.0, 0.0, 1.0 );
OGL_draw_half_open_cylinder( aNrSidesPerCircle ); DrawHalfOpenCylinder( aNrSidesPerCircle );
glPopMatrix (); glPopMatrix ();
} }

View File

@ -34,37 +34,40 @@
#include "../3d_render_raytracing/shapes2D/croundsegment2d.h" #include "../3d_render_raytracing/shapes2D/croundsegment2d.h"
/** /**
* @brief OGL_draw_arrow - draw a round arrow * Draw a round arrow.
* @param aPosition: start position of the arrow *
* @param aTargetPos: end position of the arror * @param aPosition is the start position of the arrow.
* @param aSize: diameter size * @param aTargetPos is the end position of the arrow.
* @param aSize is the diameter of the arrow.
*/ */
void OGL_draw_arrow( SFVEC3F aPosition, SFVEC3F aTargetPos, float aSize ); void DrawRoundArrow( SFVEC3F aPosition, SFVEC3F aTargetPos, float aSize );
/** /**
* @brief OGL_draw_bbox - draw the bounding box lines * Draw the bounding box lines.
* @param aBBox is the box to draw *
* @param aBBox is the box to draw.
*/ */
void OGL_draw_bbox( const CBBOX &aBBox ); void DrawBoundingBox( const BBOX_3D& aBBox );
/** /**
* @brief OGL_draw_half_open_cylinder - draws an open half cylinder * Draw a half open cylinder with diameter 1.0f and height 1.0f.
* with diameter 1.0f and Height 1.0f *
* the bottom center is at (0,0,0) and top center is at (0,0,1) * The bottom center is at (0,0,0) and top center is at (0,0,1).
*
* @param aNrSidesPerCircle is the number of segments to approximate a circle. * @param aNrSidesPerCircle is the number of segments to approximate a circle.
*/ */
void OGL_draw_half_open_cylinder( unsigned int aNrSidesPerCircle ); void DrawHalfOpenCylinder( unsigned int aNrSidesPerCircle );
/** /**
* @brief OGL_Draw_segment draws a thick segment with rounded ends * Draw a thick line segment with rounded ends.
*
* @param aSegment is the thick segment to draw * @param aSegment is the thick segment to draw
* @param aNrSidesPerCircle is the number of segments to approximate a circle. * @param aNrSidesPerCircle is the number of segments to approximate the circle used to draw
* used to draw the rounded ends of the segment * the rounded ends of the segment.
*/ */
void OGL_Draw_segment( const CROUNDSEGMENT2D &aSegment, void DrawSegment( const ROUND_SEGMENT_2D& aSegment, unsigned int aNrSidesPerCircle );
unsigned int aNrSidesPerCircle );
#endif // OGL_LEGACY_UTILS_H_ #endif // OGL_LEGACY_UTILS_H_

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,17 +24,17 @@
/** /**
* @file caccelerator.cpp * @file caccelerator.cpp
* @brief
*/ */
#include "caccelerator.h" #include "caccelerator.h"
CGENERICACCELERATOR::CGENERICACCELERATOR( ) ACCELERATOR_3D::ACCELERATOR_3D( )
{ {
m_bbox.Reset(); m_bbox.Reset();
} }
CGENERICACCELERATOR::~CGENERICACCELERATOR()
ACCELERATOR_3D::~ACCELERATOR_3D()
{ {
} }

View File

@ -34,25 +34,24 @@
#include "../raypacket.h" #include "../raypacket.h"
class CGENERICACCELERATOR class ACCELERATOR_3D
{ {
public: public:
CGENERICACCELERATOR( ); ACCELERATOR_3D( );
virtual ~CGENERICACCELERATOR(); virtual ~ACCELERATOR_3D();
virtual bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const = 0; virtual bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const = 0;
virtual bool Intersect( const RAY &aRay, virtual bool Intersect( const RAY& aRay, HITINFO& aHitInfo,
HITINFO &aHitInfo,
unsigned int aAccNodeInfo ) const = 0; unsigned int aAccNodeInfo ) const = 0;
virtual bool Intersect( const RAYPACKET &aRayPacket, virtual bool Intersect( const RAYPACKET& aRayPacket,
HITINFO_PACKET *aHitInfoPacket ) const = 0; HITINFO_PACKET* aHitInfoPacket ) const = 0;
virtual bool IntersectP( const RAY &aRay, float aMaxDistance ) const = 0; virtual bool IntersectP( const RAY& aRay, float aMaxDistance ) const = 0;
protected: protected:
CBBOX m_bbox; BBOX_3D m_bbox;
}; };
#endif // _CACCELERATOR_H_ #endif // _CACCELERATOR_H_

View File

@ -45,10 +45,8 @@ struct StackNode
}; };
static inline unsigned int getFirstHit( const RAYPACKET &aRayPacket, static inline unsigned int getFirstHit( const RAYPACKET& aRayPacket, const BBOX_3D& aBBox,
const CBBOX &aBBox, unsigned int ia, HITINFO_PACKET* aHitInfoPacket )
unsigned int ia,
HITINFO_PACKET *aHitInfoPacket )
{ {
float hitT; float hitT;
@ -72,10 +70,8 @@ static inline unsigned int getFirstHit( const RAYPACKET &aRayPacket,
#ifdef BVH_RANGED_TRAVERSAL #ifdef BVH_RANGED_TRAVERSAL
static inline unsigned int getLastHit( const RAYPACKET &aRayPacket, static inline unsigned int getLastHit( const RAYPACKET& aRayPacket, const BBOX_3D& aBBox,
const CBBOX &aBBox, unsigned int ia, HITINFO_PACKET* aHitInfoPacket )
unsigned int ia,
HITINFO_PACKET *aHitInfoPacket )
{ {
for( unsigned int ie = (RAYPACKET_RAYS_PER_PACKET - 1); ie > ia; --ie ) for( unsigned int ie = (RAYPACKET_RAYS_PER_PACKET - 1); ie > ia; --ie )
{ {
@ -94,12 +90,12 @@ static inline unsigned int getLastHit( const RAYPACKET &aRayPacket,
// http://cseweb.ucsd.edu/~ravir/whitted.pdf // http://cseweb.ucsd.edu/~ravir/whitted.pdf
// Ranged Traversal // Ranged Traversal
bool CBVH_PBRT::Intersect( const RAYPACKET &aRayPacket, HITINFO_PACKET *aHitInfoPacket ) const bool BVH_PBRT::Intersect( const RAYPACKET& aRayPacket, HITINFO_PACKET* aHitInfoPacket ) const
{ {
if( m_nodes == NULL ) if( m_nodes == nullptr )
return false; return false;
if( (&m_nodes[0]) == NULL ) if( &m_nodes[0] == nullptr )
return false; return false;
bool anyHitted = false; bool anyHitted = false;
@ -118,7 +114,7 @@ bool CBVH_PBRT::Intersect( const RAYPACKET &aRayPacket, HITINFO_PACKET *aHitInfo
{ {
if( curCell->nPrimitives == 0 ) if( curCell->nPrimitives == 0 )
{ {
StackNode &node = todo[todoOffset++]; StackNode& node = todo[todoOffset++];
node.cell = curCell->secondChildOffset; node.cell = curCell->secondChildOffset;
node.ia = ia; node.ia = ia;
nodeNum = nodeNum + 1; nodeNum = nodeNum + 1;
@ -126,14 +122,12 @@ bool CBVH_PBRT::Intersect( const RAYPACKET &aRayPacket, HITINFO_PACKET *aHitInfo
} }
else else
{ {
const unsigned int ie = getLastHit( aRayPacket, const unsigned int ie = getLastHit( aRayPacket, curCell->bounds, ia,
curCell->bounds,
ia,
aHitInfoPacket ); aHitInfoPacket );
for( int j = 0; j < curCell->nPrimitives; ++j ) for( int j = 0; j < curCell->nPrimitives; ++j )
{ {
const COBJECT *obj = m_primitives[curCell->primitivesOffset + j]; const OBJECT_3D* obj = m_primitives[curCell->primitivesOffset + j];
if( aRayPacket.m_Frustum.Intersect( obj->GetBBox() ) ) if( aRayPacket.m_Frustum.Intersect( obj->GetBBox() ) )
{ {
@ -157,7 +151,7 @@ bool CBVH_PBRT::Intersect( const RAYPACKET &aRayPacket, HITINFO_PACKET *aHitInfo
if( todoOffset == 0 ) if( todoOffset == 0 )
break; break;
const StackNode &node = todo[--todoOffset]; const StackNode& node = todo[--todoOffset];
nodeNum = node.cell; nodeNum = node.cell;
ia = node.ia; ia = node.ia;
@ -174,11 +168,9 @@ bool CBVH_PBRT::Intersect( const RAYPACKET &aRayPacket, HITINFO_PACKET *aHitInfo
#ifdef BVH_PARTITION_TRAVERSAL #ifdef BVH_PARTITION_TRAVERSAL
static inline unsigned int getLastHit( const RAYPACKET &aRayPacket, static inline unsigned int getLastHit( const RAYPACKET& aRayPacket, const BBOX_3D& aBBox,
const CBBOX &aBBox, unsigned int ia, const unsigned int* aRayIndex,
unsigned int ia, HITINFO_PACKET* aHitInfoPacket )
const unsigned int *aRayIndex,
HITINFO_PACKET *aHitInfoPacket )
{ {
for( unsigned int ie = (RAYPACKET_RAYS_PER_PACKET - 1); ie > ia; --ie ) for( unsigned int ie = (RAYPACKET_RAYS_PER_PACKET - 1); ie > ia; --ie )
{ {
@ -193,11 +185,9 @@ static inline unsigned int getLastHit( const RAYPACKET &aRayPacket,
} }
static inline unsigned int partRays( const RAYPACKET &aRayPacket, static inline unsigned int partRays( const RAYPACKET& aRayPacket, const BBOX_3D& aBBox,
const CBBOX &aBBox, unsigned int ia, unsigned int* aRayIndex,
unsigned int ia, HITINFO_PACKET* aHitInfoPacket )
unsigned int *aRayIndex,
HITINFO_PACKET *aHitInfoPacket )
{ {
if( !aRayPacket.m_Frustum.Intersect( aBBox ) ) if( !aRayPacket.m_Frustum.Intersect( aBBox ) )
@ -208,6 +198,7 @@ static inline unsigned int partRays( const RAYPACKET &aRayPacket,
for( unsigned int i = 0; i < ia; ++i ) for( unsigned int i = 0; i < ia; ++i )
{ {
float hitT; float hitT;
if( aBBox.Intersect( aRayPacket.m_ray[ aRayIndex[i] ], &hitT ) if( aBBox.Intersect( aRayPacket.m_ray[ aRayIndex[i] ], &hitT )
&& ( hitT < aHitInfoPacket[ aRayIndex[i] ].m_HitInfo.m_tHit ) ) && ( hitT < aHitInfoPacket[ aRayIndex[i] ].m_HitInfo.m_tHit ) )
std::swap( aRayIndex[ie++], aRayIndex[i] ); std::swap( aRayIndex[ie++], aRayIndex[i] );
@ -217,7 +208,7 @@ static inline unsigned int partRays( const RAYPACKET &aRayPacket,
} }
bool CBVH_PBRT::Intersect( const RAYPACKET &aRayPacket, HITINFO_PACKET *aHitInfoPacket ) const bool BVH_PBRT::Intersect( const RAYPACKET& aRayPacket, HITINFO_PACKET* aHitInfoPacket ) const
{ {
bool anyHitted = false; bool anyHitted = false;
int todoOffset = 0, nodeNum = 0; int todoOffset = 0, nodeNum = 0;
@ -239,7 +230,7 @@ bool CBVH_PBRT::Intersect( const RAYPACKET &aRayPacket, HITINFO_PACKET *aHitInfo
{ {
if( curCell->nPrimitives == 0 ) if( curCell->nPrimitives == 0 )
{ {
StackNode &node = todo[todoOffset++]; StackNode& node = todo[todoOffset++];
node.cell = curCell->secondChildOffset; node.cell = curCell->secondChildOffset;
node.ia = ia; node.ia = ia;
nodeNum = nodeNum + 1; nodeNum = nodeNum + 1;
@ -247,15 +238,12 @@ bool CBVH_PBRT::Intersect( const RAYPACKET &aRayPacket, HITINFO_PACKET *aHitInfo
} }
else else
{ {
unsigned int ie = getLastHit( aRayPacket, unsigned int ie = geetLastHit( aRayPacket, curCell->bounds, ia, I,
curCell->bounds,
ia,
I,
aHitInfoPacket ); aHitInfoPacket );
for( int j = 0; j < curCell->nPrimitives; ++j ) for( int j = 0; j < curCell->nPrimitives; ++j )
{ {
const COBJECT *obj = m_primitives[curCell->primitivesOffset + j]; const OBJECT_3D* obj = m_primitives[curCell->primitivesOffset + j];
if( aRayPacket.m_Frustum.Intersect( obj->GetBBox() ) ) if( aRayPacket.m_Frustum.Intersect( obj->GetBBox() ) )
{ {
@ -281,7 +269,7 @@ bool CBVH_PBRT::Intersect( const RAYPACKET &aRayPacket, HITINFO_PACKET *aHitInfo
if( todoOffset == 0 ) if( todoOffset == 0 )
break; break;
const StackNode &node = todo[--todoOffset]; const StackNode& node = todo[--todoOffset];
nodeNum = node.cell; nodeNum = node.cell;
ia = node.ia; ia = node.ia;

View File

@ -92,13 +92,13 @@ struct BVHPrimitiveInfo
centroid = SFVEC3F( 0.0f ); centroid = SFVEC3F( 0.0f );
} }
BVHPrimitiveInfo( int aPrimitiveNumber, const CBBOX &aBounds ) : BVHPrimitiveInfo( int aPrimitiveNumber, const BBOX_3D& aBounds ) :
primitiveNumber( aPrimitiveNumber ), primitiveNumber( aPrimitiveNumber ),
bounds( aBounds ), bounds( aBounds ),
centroid( .5f * aBounds.Min() + .5f * aBounds.Max() ) {} centroid( .5f * aBounds.Min() + .5f * aBounds.Max() ) {}
int primitiveNumber; int primitiveNumber;
CBBOX bounds; BBOX_3D bounds;
SFVEC3F centroid; SFVEC3F centroid;
}; };
@ -106,15 +106,15 @@ struct BVHPrimitiveInfo
struct BVHBuildNode struct BVHBuildNode
{ {
// BVHBuildNode Public Methods // BVHBuildNode Public Methods
void InitLeaf( int first, int n, const CBBOX &b) void InitLeaf( int first, int n, const BBOX_3D& b)
{ {
firstPrimOffset = first; firstPrimOffset = first;
nPrimitives = n; nPrimitives = n;
bounds = b; bounds = b;
children[0] = children[1] = NULL; children[0] = children[1] = nullptr;
} }
void InitInterior( int axis, BVHBuildNode *c0, BVHBuildNode *c1 ) void InitInterior( int axis, BVHBuildNode* c0, BVHBuildNode* c1 )
{ {
children[0] = c0; children[0] = c0;
children[1] = c1; children[1] = c1;
@ -124,8 +124,8 @@ struct BVHBuildNode
nPrimitives = 0; nPrimitives = 0;
} }
CBBOX bounds; BBOX_3D bounds;
BVHBuildNode *children[2]; BVHBuildNode* children[2];
int splitAxis, firstPrimOffset, nPrimitives; int splitAxis, firstPrimOffset, nPrimitives;
}; };
@ -165,17 +165,17 @@ inline uint32_t LeftShift3( uint32_t x )
} }
inline uint32_t EncodeMorton3( const SFVEC3F &v ) inline uint32_t EncodeMorton3( const SFVEC3F& v )
{ {
wxASSERT( v.x >= 0 && v.x <= (1 << 10) ); wxASSERT( v.x >= 0 && v.x <= ( 1 << 10 ) );
wxASSERT( v.y >= 0 && v.y <= (1 << 10) ); wxASSERT( v.y >= 0 && v.y <= ( 1 << 10 ) );
wxASSERT( v.z >= 0 && v.z <= (1 << 10) ); wxASSERT( v.z >= 0 && v.z <= ( 1 << 10 ) );
return (LeftShift3(v.z) << 2) | (LeftShift3(v.y) << 1) | LeftShift3(v.x); return ( LeftShift3( v.z ) << 2 ) | ( LeftShift3( v.y ) << 1 ) | LeftShift3( v.x );
} }
static void RadixSort( std::vector<MortonPrimitive> *v ) static void RadixSort( std::vector<MortonPrimitive>* v )
{ {
std::vector<MortonPrimitive> tempVector( v->size() ); std::vector<MortonPrimitive> tempVector( v->size() );
@ -192,8 +192,8 @@ static void RadixSort( std::vector<MortonPrimitive> *v )
const int lowBit = pass * bitsPerPass; const int lowBit = pass * bitsPerPass;
// Set in and out vector pointers for radix sort pass // Set in and out vector pointers for radix sort pass
std::vector<MortonPrimitive> &in = (pass & 1) ? tempVector : *v; std::vector<MortonPrimitive>& in = ( pass & 1 ) ? tempVector : *v;
std::vector<MortonPrimitive> &out = (pass & 1) ? *v : tempVector; std::vector<MortonPrimitive>& out = ( pass & 1 ) ? *v : tempVector;
// Count number of zero bits in array for current radix sort bit // Count number of zero bits in array for current radix sort bit
const int nBuckets = 1 << bitsPerPass; const int nBuckets = 1 << bitsPerPass;
@ -203,9 +203,9 @@ static void RadixSort( std::vector<MortonPrimitive> *v )
for( uint32_t i = 0; i < in.size(); ++i ) for( uint32_t i = 0; i < in.size(); ++i )
{ {
const MortonPrimitive &mp = in[i]; const MortonPrimitive &mp = in[i];
int bucket = (mp.mortonCode >> lowBit) & bitMask; int bucket = ( mp.mortonCode >> lowBit ) & bitMask;
wxASSERT( (bucket >= 0) && (bucket < nBuckets) ); wxASSERT( ( bucket >= 0 ) && ( bucket < nBuckets ) );
++bucketCount[bucket]; ++bucketCount[bucket];
} }
@ -220,7 +220,7 @@ static void RadixSort( std::vector<MortonPrimitive> *v )
// Store sorted values in output array // Store sorted values in output array
for( uint32_t i = 0; i < in.size(); ++i ) for( uint32_t i = 0; i < in.size(); ++i )
{ {
const MortonPrimitive &mp = in[i]; const MortonPrimitive& mp = in[i];
int bucket = (mp.mortonCode >> lowBit) & bitMask; int bucket = (mp.mortonCode >> lowBit) & bitMask;
out[startIndex[bucket]++] = mp; out[startIndex[bucket]++] = mp;
} }
@ -232,15 +232,14 @@ static void RadixSort( std::vector<MortonPrimitive> *v )
} }
CBVH_PBRT::CBVH_PBRT( const CGENERICCONTAINER &aObjectContainer, BVH_PBRT::BVH_PBRT( const CONTAINER_3D_BASE& aObjectContainer, int aMaxPrimsInNode,
int aMaxPrimsInNode,
SPLITMETHOD aSplitMethod ) : SPLITMETHOD aSplitMethod ) :
m_maxPrimsInNode( std::min( 255, aMaxPrimsInNode ) ), m_maxPrimsInNode( std::min( 255, aMaxPrimsInNode ) ),
m_splitMethod( aSplitMethod ) m_splitMethod( aSplitMethod )
{ {
if( aObjectContainer.GetList().empty() ) if( aObjectContainer.GetList().empty() )
{ {
m_nodes = NULL; m_nodes = nullptr;
return; return;
} }
@ -276,18 +275,16 @@ CBVH_PBRT::CBVH_PBRT( const CGENERICCONTAINER &aObjectContainer,
BVHBuildNode *root; BVHBuildNode *root;
if( m_splitMethod == SPLITMETHOD::HLBVH ) if( m_splitMethod == SPLITMETHOD::HLBVH )
root = HLBVHBuild( primitiveInfo, &totalNodes, orderedPrims); root = HLBVHBuild( primitiveInfo, &totalNodes, orderedPrims );
else else
root = recursiveBuild( primitiveInfo, 0, m_primitives.size(), root = recursiveBuild( primitiveInfo, 0, m_primitives.size(), &totalNodes, orderedPrims );
&totalNodes, orderedPrims);
wxASSERT( m_primitives.size() == orderedPrims.size() ); wxASSERT( m_primitives.size() == orderedPrims.size() );
m_primitives.swap( orderedPrims ); m_primitives.swap( orderedPrims );
// Compute representation of depth-first traversal of BVH tree // Compute representation of depth-first traversal of BVH tree
m_nodes = static_cast<LinearBVHNode *>( malloc( sizeof( LinearBVHNode ) * m_nodes = static_cast<LinearBVHNode*>( malloc( sizeof( LinearBVHNode ) * totalNodes ) );
totalNodes ) );
m_addresses_pointer_to_mm_free.push_back( m_nodes ); m_addresses_pointer_to_mm_free.push_back( m_nodes );
for( int i = 0; i < totalNodes; ++i ) for( int i = 0; i < totalNodes; ++i )
@ -306,7 +303,7 @@ CBVH_PBRT::CBVH_PBRT( const CGENERICCONTAINER &aObjectContainer,
} }
CBVH_PBRT::~CBVH_PBRT() BVH_PBRT::~BVH_PBRT()
{ {
if( !m_addresses_pointer_to_mm_free.empty() ) if( !m_addresses_pointer_to_mm_free.empty() )
{ {
@ -315,7 +312,7 @@ CBVH_PBRT::~CBVH_PBRT()
++ii ) ++ii )
{ {
free( *ii ); free( *ii );
*ii = NULL; *ii = nullptr;
} }
} }
@ -325,11 +322,11 @@ CBVH_PBRT::~CBVH_PBRT()
struct ComparePoints struct ComparePoints
{ {
explicit ComparePoints(int d) { dim = d; } explicit ComparePoints( int d ) { dim = d; }
int dim; int dim;
bool operator()( const BVHPrimitiveInfo &a, const BVHPrimitiveInfo &b ) const bool operator()( const BVHPrimitiveInfo& a, const BVHPrimitiveInfo& b ) const
{ {
return a.centroid[dim] < b.centroid[dim]; return a.centroid[dim] < b.centroid[dim];
} }
@ -343,7 +340,7 @@ struct CompareToMid
int dim; int dim;
float mid; float mid;
bool operator()( const BVHPrimitiveInfo &a ) const bool operator()( const BVHPrimitiveInfo& a ) const
{ {
return a.centroid[dim] < mid; return a.centroid[dim] < mid;
} }
@ -352,22 +349,23 @@ struct CompareToMid
struct CompareToBucket struct CompareToBucket
{ {
CompareToBucket( int split, int num, int d, const CBBOX &b ) CompareToBucket( int split, int num, int d, const BBOX_3D& b )
: centroidBounds(b) : centroidBounds( b )
{ {
splitBucket = split; splitBucket = split;
nBuckets = num; dim = d; nBuckets = num;
dim = d;
} }
bool operator()(const BVHPrimitiveInfo &p) const; bool operator()( const BVHPrimitiveInfo& p ) const;
int splitBucket, nBuckets, dim; int splitBucket, nBuckets, dim;
const CBBOX &centroidBounds; const BBOX_3D& centroidBounds;
}; };
bool CompareToBucket::operator()( const BVHPrimitiveInfo &p ) const bool CompareToBucket::operator()( const BVHPrimitiveInfo& p ) const
{ {
const float centroid = p.centroid[dim]; const float centroid = p.centroid[dim];
@ -379,7 +377,7 @@ bool CompareToBucket::operator()( const BVHPrimitiveInfo &p ) const
if( b == nBuckets ) if( b == nBuckets )
b = nBuckets - 1; b = nBuckets - 1;
wxASSERT( (b >= 0) && (b < nBuckets) ); wxASSERT( ( b >= 0 ) && ( b < nBuckets ) );
return b <= splitBucket; return b <= splitBucket;
} }
@ -387,21 +385,21 @@ bool CompareToBucket::operator()( const BVHPrimitiveInfo &p ) const
struct HLBVH_SAH_Evaluator struct HLBVH_SAH_Evaluator
{ {
HLBVH_SAH_Evaluator( int split, int num, int d, const CBBOX &b ) HLBVH_SAH_Evaluator( int split, int num, int d, const BBOX_3D& b )
: centroidBounds(b) : centroidBounds(b)
{ {
minCostSplitBucket = split; minCostSplitBucket = split;
nBuckets = num; dim = d; nBuckets = num; dim = d;
} }
bool operator()(const BVHBuildNode *node) const; bool operator()( const BVHBuildNode* node ) const;
int minCostSplitBucket, nBuckets, dim; int minCostSplitBucket, nBuckets, dim;
const CBBOX &centroidBounds; const BBOX_3D& centroidBounds;
}; };
bool HLBVH_SAH_Evaluator::operator()( const BVHBuildNode *node ) const bool HLBVH_SAH_Evaluator::operator()( const BVHBuildNode* node ) const
{ {
const float centroid = node->bounds.GetCenter( dim ); const float centroid = node->bounds.GetCenter( dim );
@ -422,17 +420,15 @@ bool HLBVH_SAH_Evaluator::operator()( const BVHBuildNode *node ) const
struct BucketInfo struct BucketInfo
{ {
int count; int count;
CBBOX bounds; BBOX_3D bounds;
}; };
BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primitiveInfo, BVHBuildNode *BVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo>& primitiveInfo,
int start, int start, int end, int* totalNodes,
int end, CONST_VECTOR_OBJECT& orderedPrims )
int *totalNodes,
CONST_VECTOR_OBJECT &orderedPrims )
{ {
wxASSERT( totalNodes != NULL ); wxASSERT( totalNodes != nullptr );
wxASSERT( start >= 0 ); wxASSERT( start >= 0 );
wxASSERT( end >= 0 ); wxASSERT( end >= 0 );
wxASSERT( start != end ); wxASSERT( start != end );
@ -450,11 +446,11 @@ BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primiti
node->firstPrimOffset = 0; node->firstPrimOffset = 0;
node->nPrimitives = 0; node->nPrimitives = 0;
node->splitAxis = 0; node->splitAxis = 0;
node->children[0] = NULL; node->children[0] = nullptr;
node->children[1] = NULL; node->children[1] = nullptr;
// Compute bounds of all primitives in BVH node // Compute bounds of all primitives in BVH node
CBBOX bounds; BBOX_3D bounds;
bounds.Reset(); bounds.Reset();
for( int i = start; i < end; ++i ) for( int i = start; i < end; ++i )
@ -479,7 +475,7 @@ BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primiti
else else
{ {
// Compute bound of primitive centroids, choose split dimension _dim_ // Compute bound of primitive centroids, choose split dimension _dim_
CBBOX centroidBounds; BBOX_3D centroidBounds;
centroidBounds.Reset(); centroidBounds.Reset();
for( int i = start; i < end; ++i ) for( int i = start; i < end; ++i )
@ -502,9 +498,9 @@ BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primiti
wxASSERT( ( primitiveNr >= 0 ) && ( primitiveNr < (int) m_primitives.size() ) ); wxASSERT( ( primitiveNr >= 0 ) && ( primitiveNr < (int) m_primitives.size() ) );
const COBJECT *obj = static_cast<const COBJECT *>( m_primitives[ primitiveNr ] ); const OBJECT_3D* obj = static_cast<const OBJECT_3D*>( m_primitives[ primitiveNr ] );
wxASSERT( obj != NULL ); wxASSERT( obj != nullptr );
orderedPrims.push_back( obj ); orderedPrims.push_back( obj );
} }
@ -541,10 +537,8 @@ BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primiti
// Partition primitives into equally-sized subsets // Partition primitives into equally-sized subsets
mid = (start + end) / 2; mid = (start + end) / 2;
std::nth_element( &primitiveInfo[start], std::nth_element( &primitiveInfo[start], &primitiveInfo[mid],
&primitiveInfo[mid], &primitiveInfo[end - 1] + 1, ComparePoints( dim ) );
&primitiveInfo[end - 1] + 1,
ComparePoints( dim ) );
break; break;
} }
@ -558,10 +552,8 @@ BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primiti
// Partition primitives into equally-sized subsets // Partition primitives into equally-sized subsets
mid = (start + end) / 2; mid = (start + end) / 2;
std::nth_element( &primitiveInfo[start], std::nth_element( &primitiveInfo[start], &primitiveInfo[mid],
&primitiveInfo[mid], &primitiveInfo[end - 1] + 1, ComparePoints( dim ) );
&primitiveInfo[end - 1] + 1,
ComparePoints( dim ) );
} }
else else
{ {
@ -596,7 +588,7 @@ BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primiti
for( int i = 0; i < ( nBuckets - 1 ); ++i ) for( int i = 0; i < ( nBuckets - 1 ); ++i )
{ {
CBBOX b0, b1; BBOX_3D b0, b1;
b0.Reset(); b0.Reset();
b1.Reset(); b1.Reset();
@ -622,10 +614,8 @@ BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primiti
} }
} }
cost[i] = 1.0f + cost[i] = 1.0f + ( count0 * b0.SurfaceArea() +
( count0 * b0.SurfaceArea() + count1 * b1.SurfaceArea() ) / bounds.SurfaceArea();
count1 * b1.SurfaceArea() ) /
bounds.SurfaceArea();
} }
// Find bucket to split at that minimizes SAH metric // Find bucket to split at that minimizes SAH metric
@ -645,12 +635,9 @@ BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primiti
if( ( nPrimitives > m_maxPrimsInNode ) || ( minCost < (float) nPrimitives ) ) if( ( nPrimitives > m_maxPrimsInNode ) || ( minCost < (float) nPrimitives ) )
{ {
BVHPrimitiveInfo *pmid = BVHPrimitiveInfo *pmid =
std::partition( &primitiveInfo[start], std::partition( &primitiveInfo[start], &primitiveInfo[end - 1] + 1,
&primitiveInfo[end - 1] + 1, CompareToBucket( minCostSplitBucket, nBuckets,
CompareToBucket( minCostSplitBucket, dim, centroidBounds ) );
nBuckets,
dim,
centroidBounds ) );
mid = pmid - &primitiveInfo[0]; mid = pmid - &primitiveInfo[0];
wxASSERT( ( mid >= start ) && ( mid <= end ) ); wxASSERT( ( mid >= start ) && ( mid <= end ) );
@ -678,16 +665,9 @@ BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primiti
} }
} }
node->InitInterior( dim, node->InitInterior( dim, recursiveBuild( primitiveInfo, start, mid, totalNodes,
recursiveBuild( primitiveInfo,
start,
mid,
totalNodes,
orderedPrims ), orderedPrims ),
recursiveBuild( primitiveInfo, recursiveBuild( primitiveInfo, mid, end, totalNodes,
mid,
end,
totalNodes,
orderedPrims) ); orderedPrims) );
} }
} }
@ -696,12 +676,11 @@ BVHBuildNode *CBVH_PBRT::recursiveBuild ( std::vector<BVHPrimitiveInfo> &primiti
} }
BVHBuildNode *CBVH_PBRT::HLBVHBuild( const std::vector<BVHPrimitiveInfo> &primitiveInfo, BVHBuildNode *BVH_PBRT::HLBVHBuild( const std::vector<BVHPrimitiveInfo>& primitiveInfo,
int *totalNodes, int* totalNodes, CONST_VECTOR_OBJECT& orderedPrims )
CONST_VECTOR_OBJECT &orderedPrims )
{ {
// Compute bounding box of all primitive centroids // Compute bounding box of all primitive centroids
CBBOX bounds; BBOX_3D bounds;
bounds.Reset(); bounds.Reset();
for( unsigned int i = 0; i < primitiveInfo.size(); ++i ) for( unsigned int i = 0; i < primitiveInfo.size(); ++i )
@ -726,8 +705,7 @@ BVHBuildNode *CBVH_PBRT::HLBVHBuild( const std::vector<BVHPrimitiveInfo> &primit
wxASSERT( ( centroidOffset.y >= 0.0f ) && ( centroidOffset.y <= 1.0f ) ); wxASSERT( ( centroidOffset.y >= 0.0f ) && ( centroidOffset.y <= 1.0f ) );
wxASSERT( ( centroidOffset.z >= 0.0f ) && ( centroidOffset.z <= 1.0f ) ); wxASSERT( ( centroidOffset.z >= 0.0f ) && ( centroidOffset.z <= 1.0f ) );
mortonPrims[i].mortonCode = EncodeMorton3( centroidOffset * mortonPrims[i].mortonCode = EncodeMorton3( centroidOffset * SFVEC3F( (float)mortonScale ) );
SFVEC3F( (float)mortonScale ) );
} }
// Radix sort primitive Morton indices // Radix sort primitive Morton indices
@ -762,8 +740,8 @@ BVHBuildNode *CBVH_PBRT::HLBVHBuild( const std::vector<BVHPrimitiveInfo> &primit
nodes[i].firstPrimOffset = 0; nodes[i].firstPrimOffset = 0;
nodes[i].nPrimitives = 0; nodes[i].nPrimitives = 0;
nodes[i].splitAxis = 0; nodes[i].splitAxis = 0;
nodes[i].children[0] = NULL; nodes[i].children[0] = nullptr;
nodes[i].children[1] = NULL; nodes[i].children[1] = nullptr;
} }
LBVHTreelet tmpTreelet; LBVHTreelet tmpTreelet;
@ -794,14 +772,9 @@ BVHBuildNode *CBVH_PBRT::HLBVHBuild( const std::vector<BVHPrimitiveInfo> &primit
wxASSERT( tr.startIndex < (int)mortonPrims.size() ); wxASSERT( tr.startIndex < (int)mortonPrims.size() );
tr.buildNodes = emitLBVH( tr.buildNodes, tr.buildNodes = emitLBVH( tr.buildNodes, primitiveInfo, &mortonPrims[tr.startIndex],
primitiveInfo, tr.numPrimitives, &nodesCreated, orderedPrims,
&mortonPrims[tr.startIndex], &orderedPrimsOffset, firstBit );
tr.numPrimitives,
&nodesCreated,
orderedPrims,
&orderedPrimsOffset,
firstBit );
atomicTotal += nodesCreated; atomicTotal += nodesCreated;
} }
@ -816,24 +789,21 @@ BVHBuildNode *CBVH_PBRT::HLBVHBuild( const std::vector<BVHPrimitiveInfo> &primit
finishedTreelets.push_back( treeletsToBuild[index].buildNodes ); finishedTreelets.push_back( treeletsToBuild[index].buildNodes );
// Create and return SAH BVH from LBVH treelets // Create and return SAH BVH from LBVH treelets
return buildUpperSAH( finishedTreelets, return buildUpperSAH( finishedTreelets, 0, finishedTreelets.size(), totalNodes );
0,
finishedTreelets.size(),
totalNodes );
} }
BVHBuildNode *CBVH_PBRT::emitLBVH( BVHBuildNode *&buildNodes, BVHBuildNode *BVH_PBRT::emitLBVH( BVHBuildNode* &buildNodes,
const std::vector<BVHPrimitiveInfo> &primitiveInfo, const std::vector<BVHPrimitiveInfo>& primitiveInfo,
MortonPrimitive *mortonPrims, int nPrimitives, int *totalNodes, MortonPrimitive* mortonPrims, int nPrimitives, int* totalNodes,
CONST_VECTOR_OBJECT &orderedPrims, CONST_VECTOR_OBJECT& orderedPrims, int *orderedPrimsOffset,
int *orderedPrimsOffset, int bit ) int bit )
{ {
wxASSERT( nPrimitives > 0 ); wxASSERT( nPrimitives > 0 );
wxASSERT( totalNodes != NULL ); wxASSERT( totalNodes != nullptr );
wxASSERT( orderedPrimsOffset != NULL ); wxASSERT( orderedPrimsOffset != nullptr );
wxASSERT( nPrimitives > 0 ); wxASSERT( nPrimitives > 0 );
wxASSERT( mortonPrims != NULL ); wxASSERT( mortonPrims != nullptr );
if( ( bit == -1 ) || ( nPrimitives < m_maxPrimsInNode ) ) if( ( bit == -1 ) || ( nPrimitives < m_maxPrimsInNode ) )
{ {
@ -841,7 +811,7 @@ BVHBuildNode *CBVH_PBRT::emitLBVH( BVHBuildNode *&buildNodes,
(*totalNodes)++; (*totalNodes)++;
BVHBuildNode *node = buildNodes++; BVHBuildNode *node = buildNodes++;
CBBOX bounds; BBOX_3D bounds;
bounds.Reset(); bounds.Reset();
int firstPrimOffset = *orderedPrimsOffset; int firstPrimOffset = *orderedPrimsOffset;
@ -922,10 +892,10 @@ BVHBuildNode *CBVH_PBRT::emitLBVH( BVHBuildNode *&buildNodes,
} }
BVHBuildNode *CBVH_PBRT::buildUpperSAH( std::vector<BVHBuildNode *> &treeletRoots, BVHBuildNode *BVH_PBRT::buildUpperSAH( std::vector<BVHBuildNode*>& treeletRoots, int start,
int start, int end, int *totalNodes ) int end, int* totalNodes )
{ {
wxASSERT( totalNodes != NULL ); wxASSERT( totalNodes != nullptr );
wxASSERT( start < end ); wxASSERT( start < end );
wxASSERT( end <= (int)treeletRoots.size() ); wxASSERT( end <= (int)treeletRoots.size() );
@ -936,7 +906,7 @@ BVHBuildNode *CBVH_PBRT::buildUpperSAH( std::vector<BVHBuildNode *> &treeletRoot
(*totalNodes)++; (*totalNodes)++;
BVHBuildNode *node = static_cast<BVHBuildNode *>( malloc( sizeof( BVHBuildNode ) ) ); BVHBuildNode* node = static_cast<BVHBuildNode*>( malloc( sizeof( BVHBuildNode ) ) );
m_addresses_pointer_to_mm_free.push_back( node ); m_addresses_pointer_to_mm_free.push_back( node );
@ -944,27 +914,25 @@ BVHBuildNode *CBVH_PBRT::buildUpperSAH( std::vector<BVHBuildNode *> &treeletRoot
node->firstPrimOffset = 0; node->firstPrimOffset = 0;
node->nPrimitives = 0; node->nPrimitives = 0;
node->splitAxis = 0; node->splitAxis = 0;
node->children[0] = NULL; node->children[0] = nullptr;
node->children[1] = NULL; node->children[1] = nullptr;
// Compute bounds of all nodes under this HLBVH node // Compute bounds of all nodes under this HLBVH node
CBBOX bounds; BBOX_3D bounds;
bounds.Reset(); bounds.Reset();
for( int i = start; i < end; ++i ) for( int i = start; i < end; ++i )
bounds.Union( treeletRoots[i]->bounds ); bounds.Union( treeletRoots[i]->bounds );
// Compute bound of HLBVH node centroids, choose split dimension _dim_ // Compute bound of HLBVH node centroids, choose split dimension _dim_
CBBOX centroidBounds; BBOX_3D centroidBounds;
centroidBounds.Reset(); centroidBounds.Reset();
for( int i = start; i < end; ++i ) for( int i = start; i < end; ++i )
{ {
SFVEC3F centroid = SFVEC3F centroid = ( treeletRoots[i]->bounds.Min() + treeletRoots[i]->bounds.Max() ) * 0.5f;
(treeletRoots[i]->bounds.Min() + treeletRoots[i]->bounds.Max()) *
0.5f;
centroidBounds.Union(centroid); centroidBounds.Union( centroid );
} }
const int dim = centroidBounds.MaxDimension(); const int dim = centroidBounds.MaxDimension();
@ -988,10 +956,9 @@ BVHBuildNode *CBVH_PBRT::buildUpperSAH( std::vector<BVHBuildNode *> &treeletRoot
for( int i = start; i < end; ++i ) for( int i = start; i < end; ++i )
{ {
const float centroid = ( treeletRoots[i]->bounds.Min()[dim] + const float centroid = ( treeletRoots[i]->bounds.Min()[dim] +
treeletRoots[i]->bounds.Max()[dim] ) * treeletRoots[i]->bounds.Max()[dim] ) * 0.5f;
0.5f; int b = nBuckets * ( ( centroid - centroidBounds.Min()[dim] )
int b = nBuckets * ( (centroid - centroidBounds.Min()[dim] ) / / ( centroidBounds.Max()[dim] - centroidBounds.Min()[dim] ) );
(centroidBounds.Max()[dim] - centroidBounds.Min()[dim] ) );
if( b == nBuckets ) if( b == nBuckets )
b = nBuckets - 1; b = nBuckets - 1;
@ -1007,7 +974,7 @@ BVHBuildNode *CBVH_PBRT::buildUpperSAH( std::vector<BVHBuildNode *> &treeletRoot
for( int i = 0; i < nBuckets - 1; ++i ) for( int i = 0; i < nBuckets - 1; ++i )
{ {
CBBOX b0, b1; BBOX_3D b0, b1;
b0.Reset(); b0.Reset();
b1.Reset(); b1.Reset();
@ -1031,8 +998,7 @@ BVHBuildNode *CBVH_PBRT::buildUpperSAH( std::vector<BVHBuildNode *> &treeletRoot
} }
} }
cost[i] = .125f + cost[i] = .125f + ( count0 * b0.SurfaceArea() + count1 * b1.SurfaceArea() ) /
( count0 * b0.SurfaceArea() + count1 * b1.SurfaceArea() ) /
bounds.SurfaceArea(); bounds.SurfaceArea();
} }
@ -1050,16 +1016,13 @@ BVHBuildNode *CBVH_PBRT::buildUpperSAH( std::vector<BVHBuildNode *> &treeletRoot
} }
// Split nodes and create interior HLBVH SAH node // Split nodes and create interior HLBVH SAH node
BVHBuildNode **pmid = std::partition( &treeletRoots[start], BVHBuildNode **pmid = std::partition( &treeletRoots[start], &treeletRoots[end - 1] + 1,
&treeletRoots[end - 1] + 1, HLBVH_SAH_Evaluator( minCostSplitBucket, nBuckets,
HLBVH_SAH_Evaluator( minCostSplitBucket, dim, centroidBounds ) );
nBuckets,
dim,
centroidBounds ) );
const int mid = pmid - &treeletRoots[0]; const int mid = pmid - &treeletRoots[0];
wxASSERT( (mid > start) && (mid < end) ); wxASSERT( ( mid > start ) && ( mid < end ) );
node->InitInterior( dim, node->InitInterior( dim,
buildUpperSAH( treeletRoots, start, mid, totalNodes ), buildUpperSAH( treeletRoots, start, mid, totalNodes ),
@ -1069,7 +1032,7 @@ BVHBuildNode *CBVH_PBRT::buildUpperSAH( std::vector<BVHBuildNode *> &treeletRoot
} }
int CBVH_PBRT::flattenBVHTree( BVHBuildNode *node, uint32_t *offset ) int BVH_PBRT::flattenBVHTree( BVHBuildNode* node, uint32_t* offset )
{ {
LinearBVHNode *linearNode = &m_nodes[*offset]; LinearBVHNode *linearNode = &m_nodes[*offset];
@ -1079,7 +1042,7 @@ int CBVH_PBRT::flattenBVHTree( BVHBuildNode *node, uint32_t *offset )
if( node->nPrimitives > 0 ) if( node->nPrimitives > 0 )
{ {
wxASSERT( (!node->children[0]) && (!node->children[1]) ); wxASSERT( ( !node->children[0] ) && ( !node->children[1] ) );
wxASSERT( node->nPrimitives < 65536 ); wxASSERT( node->nPrimitives < 65536 );
linearNode->primitivesOffset = node->firstPrimOffset; linearNode->primitivesOffset = node->firstPrimOffset;
@ -1101,7 +1064,7 @@ int CBVH_PBRT::flattenBVHTree( BVHBuildNode *node, uint32_t *offset )
#define MAX_TODOS 64 #define MAX_TODOS 64
bool CBVH_PBRT::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const bool BVH_PBRT::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
{ {
if( !m_nodes ) if( !m_nodes )
return false; return false;
@ -1123,7 +1086,7 @@ bool CBVH_PBRT::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
const bool hitted = node->bounds.Intersect( aRay, &hitBox ); const bool hitted = node->bounds.Intersect( aRay, &hitBox );
if( hitted && (hitBox < aHitInfo.m_tHit) ) if( hitted && ( hitBox < aHitInfo.m_tHit ) )
{ {
if( node->nPrimitives > 0 ) if( node->nPrimitives > 0 )
{ {
@ -1166,7 +1129,7 @@ bool CBVH_PBRT::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
/// @todo This may be optimized /// @todo This may be optimized
bool CBVH_PBRT::Intersect( const RAY& aRay, HITINFO& aHitInfo, unsigned int aAccNodeInfo ) const bool BVH_PBRT::Intersect( const RAY& aRay, HITINFO& aHitInfo, unsigned int aAccNodeInfo ) const
{ {
if( !m_nodes ) if( !m_nodes )
return false; return false;
@ -1230,7 +1193,7 @@ bool CBVH_PBRT::Intersect( const RAY& aRay, HITINFO& aHitInfo, unsigned int aAcc
} }
bool CBVH_PBRT::IntersectP( const RAY &aRay, float aMaxDistance ) const bool BVH_PBRT::IntersectP( const RAY& aRay, float aMaxDistance ) const
{ {
if( !m_nodes ) if( !m_nodes )
return false; return false;
@ -1241,7 +1204,7 @@ bool CBVH_PBRT::IntersectP( const RAY &aRay, float aMaxDistance ) const
while( true ) while( true )
{ {
const LinearBVHNode *node = &m_nodes[nodeNum]; const LinearBVHNode* node = &m_nodes[nodeNum];
wxASSERT( todoOffset < MAX_TODOS ); wxASSERT( todoOffset < MAX_TODOS );
@ -1257,7 +1220,7 @@ bool CBVH_PBRT::IntersectP( const RAY &aRay, float aMaxDistance ) const
// Intersect ray with primitives in leaf BVH node // Intersect ray with primitives in leaf BVH node
for( int i = 0; i < node->nPrimitives; ++i ) for( int i = 0; i < node->nPrimitives; ++i )
{ {
const COBJECT *obj = m_primitives[node->primitivesOffset + i]; const OBJECT_3D* obj = m_primitives[node->primitivesOffset + i];
if( obj->GetMaterial()->GetCastShadows() if( obj->GetMaterial()->GetCastShadows()
&& obj->IntersectP( aRay, aMaxDistance ) ) && obj->IntersectP( aRay, aMaxDistance ) )

View File

@ -67,8 +67,8 @@
*/ */
#ifndef _CBVH_PBRT_H_ #ifndef _BVH_PBRT_H_
#define _CBVH_PBRT_H_ #define _BVH_PBRT_H_
#include "caccelerator.h" #include "caccelerator.h"
#include <cstdint> #include <cstdint>
@ -82,7 +82,7 @@ struct MortonPrimitive;
struct LinearBVHNode struct LinearBVHNode
{ {
// 24 bytes // 24 bytes
CBBOX bounds; BBOX_3D bounds;
// 4 bytes // 4 bytes
union union
@ -107,59 +107,47 @@ enum class SPLITMETHOD
}; };
class CBVH_PBRT : public CGENERICACCELERATOR class BVH_PBRT : public ACCELERATOR_3D
{ {
public: public:
CBVH_PBRT( const CGENERICCONTAINER& aObjectContainer, int aMaxPrimsInNode = 4, BVH_PBRT( const CONTAINER_3D_BASE& aObjectContainer, int aMaxPrimsInNode = 4,
SPLITMETHOD aSplitMethod = SPLITMETHOD::SAH ); SPLITMETHOD aSplitMethod = SPLITMETHOD::SAH );
~CBVH_PBRT(); ~BVH_PBRT();
// Imported from CGENERICACCELERATOR bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const override;
bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const override; bool Intersect( const RAY& aRay, HITINFO& aHitInfo, unsigned int aAccNodeInfo ) const override;
bool Intersect( const RAY &aRay, HITINFO &aHitInfo, unsigned int aAccNodeInfo ) const override; bool Intersect( const RAYPACKET& aRayPacket, HITINFO_PACKET* aHitInfoPacket ) const override;
bool Intersect( const RAYPACKET &aRayPacket, HITINFO_PACKET *aHitInfoPacket ) const override; bool IntersectP( const RAY& aRay, float aMaxDistance ) const override;
bool IntersectP( const RAY &aRay, float aMaxDistance ) const override;
private: private:
BVHBuildNode* recursiveBuild( std::vector<BVHPrimitiveInfo>& primitiveInfo, int start,
int end, int* totalNodes, CONST_VECTOR_OBJECT& orderedPrims );
BVHBuildNode *recursiveBuild( std::vector<BVHPrimitiveInfo> &primitiveInfo, BVHBuildNode* HLBVHBuild( const std::vector<BVHPrimitiveInfo>& primitiveInfo,
int start, int* totalNodes, CONST_VECTOR_OBJECT& orderedPrims );
int end,
int *totalNodes,
CONST_VECTOR_OBJECT &orderedPrims );
BVHBuildNode *HLBVHBuild( const std::vector<BVHPrimitiveInfo> &primitiveInfo,
int *totalNodes,
CONST_VECTOR_OBJECT &orderedPrims );
//!TODO: after implement memory arena, put const back to this functions //!TODO: after implement memory arena, put const back to this functions
BVHBuildNode *emitLBVH( BVHBuildNode *&buildNodes, BVHBuildNode* emitLBVH( BVHBuildNode* &buildNodes,
const std::vector<BVHPrimitiveInfo> &primitiveInfo, const std::vector<BVHPrimitiveInfo>& primitiveInfo,
MortonPrimitive *mortonPrims, MortonPrimitive* mortonPrims, int nPrimitives, int* totalNodes,
int nPrimitives, CONST_VECTOR_OBJECT& orderedPrims, int* orderedPrimsOffset, int bit );
int *totalNodes,
CONST_VECTOR_OBJECT &orderedPrims,
int *orderedPrimsOffset,
int bit );
BVHBuildNode *buildUpperSAH( std::vector<BVHBuildNode *> &treeletRoots, BVHBuildNode* buildUpperSAH( std::vector<BVHBuildNode*>& treeletRoots, int start, int end,
int start, int* totalNodes );
int end,
int *totalNodes );
int flattenBVHTree( BVHBuildNode *node, uint32_t *offset ); int flattenBVHTree( BVHBuildNode* node, uint32_t* offset );
// BVH Private Data // BVH Private Data
const int m_maxPrimsInNode; const int m_maxPrimsInNode;
SPLITMETHOD m_splitMethod; SPLITMETHOD m_splitMethod;
CONST_VECTOR_OBJECT m_primitives; CONST_VECTOR_OBJECT m_primitives;
LinearBVHNode *m_nodes; LinearBVHNode* m_nodes;
std::list<void *> m_addresses_pointer_to_mm_free; std::list<void*> m_addresses_pointer_to_mm_free;
// Partition traversal // Partition traversal
unsigned int m_I[RAYPACKET_RAYS_PER_PACKET]; unsigned int m_I[RAYPACKET_RAYS_PER_PACKET];
}; };
#endif // _CBVH_PBRT_H_ #endif // _BVH_PBRT_H_

View File

@ -30,21 +30,21 @@
#include "ccontainer.h" #include "ccontainer.h"
#include <cstdio> #include <cstdio>
CGENERICCONTAINER::CGENERICCONTAINER() CONTAINER_3D_BASE::CONTAINER_3D_BASE()
{ {
m_objects.clear(); m_objects.clear();
m_bbox.Reset(); m_bbox.Reset();
} }
void CGENERICCONTAINER::Clear() void CONTAINER_3D_BASE::Clear()
{ {
if( !m_objects.empty() ) if( !m_objects.empty() )
{ {
for( LIST_OBJECT::iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii ) for( LIST_OBJECT::iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii )
{ {
delete *ii; delete *ii;
*ii = NULL; *ii = nullptr;
} }
m_objects.clear(); m_objects.clear();
@ -54,13 +54,13 @@ void CGENERICCONTAINER::Clear()
} }
CGENERICCONTAINER::~CGENERICCONTAINER() CONTAINER_3D_BASE::~CONTAINER_3D_BASE()
{ {
Clear(); Clear();
} }
void CGENERICCONTAINER::ConvertTo( CONST_VECTOR_OBJECT &aOutVector ) const void CONTAINER_3D_BASE::ConvertTo( CONST_VECTOR_OBJECT &aOutVector ) const
{ {
aOutVector.resize( m_objects.size() ); aOutVector.resize( m_objects.size() );
@ -70,15 +70,15 @@ void CGENERICCONTAINER::ConvertTo( CONST_VECTOR_OBJECT &aOutVector ) const
for( LIST_OBJECT::const_iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii ) for( LIST_OBJECT::const_iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii )
{ {
wxASSERT( (*ii) != NULL ); wxASSERT( (*ii) != nullptr );
aOutVector[i++] = static_cast<const COBJECT *>(*ii); aOutVector[i++] = static_cast<const OBJECT_3D *>(*ii);
} }
} }
} }
bool CCONTAINER::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const bool CONTAINER_3D::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
{ {
if( !m_bbox.Intersect( aRay ) ) if( !m_bbox.Intersect( aRay ) )
@ -88,7 +88,7 @@ bool CCONTAINER::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
for( LIST_OBJECT::const_iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii ) for( LIST_OBJECT::const_iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii )
{ {
const COBJECT *object = static_cast<const COBJECT *>( *ii ); const OBJECT_3D *object = static_cast<const OBJECT_3D *>( *ii );
if( object->Intersect( aRay, aHitInfo) ) if( object->Intersect( aRay, aHitInfo) )
hitted = true; hitted = true;
@ -98,17 +98,11 @@ bool CCONTAINER::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
} }
bool CCONTAINER::IntersectP( const RAY &aRay, float aMaxDistance ) const bool CONTAINER_3D::IntersectP( const RAY &aRay, float aMaxDistance ) const
{ {
/// @todo Determine what to do with this commented out code.
/*
if( !m_bbox.Inside( aRay.m_Origin ) )
if( !m_bbox.Intersect( aRay ) )
return false;
*/
for( LIST_OBJECT::const_iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii ) for( LIST_OBJECT::const_iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii )
{ {
const COBJECT *object = static_cast<const COBJECT *>(*ii); const OBJECT_3D *object = static_cast<const OBJECT_3D*>( *ii );
if( object->IntersectP( aRay, aMaxDistance ) ) if( object->IntersectP( aRay, aMaxDistance ) )
return true; return true;

View File

@ -27,26 +27,26 @@
* @brief * @brief
*/ */
#ifndef _CCONTAINER_H_ #ifndef _CONTAINER_3D_H_
#define _CCONTAINER_H_ #define _CONTAINER_3D_H_
#include "../shapes3D/cobject.h" #include "../shapes3D/cobject.h"
#include <list> #include <list>
#include <vector> #include <vector>
typedef std::list<COBJECT *> LIST_OBJECT; typedef std::list<OBJECT_3D*> LIST_OBJECT;
typedef std::vector<COBJECT *> VECTOR_OBJECT; typedef std::vector<OBJECT_3D*> VECTOR_OBJECT;
typedef std::vector<const COBJECT *> CONST_VECTOR_OBJECT; typedef std::vector<const OBJECT_3D*> CONST_VECTOR_OBJECT;
class CGENERICCONTAINER class CONTAINER_3D_BASE
{ {
public: public:
CGENERICCONTAINER(); CONTAINER_3D_BASE();
virtual ~CGENERICCONTAINER(); virtual ~CONTAINER_3D_BASE();
void Add( COBJECT *aObject ) void Add( OBJECT_3D *aObject )
{ {
if( aObject ) if( aObject )
{ {
@ -57,26 +57,26 @@ public:
void Clear(); void Clear();
const LIST_OBJECT &GetList() const { return m_objects; } const LIST_OBJECT& GetList() const { return m_objects; }
void ConvertTo( CONST_VECTOR_OBJECT &aOutVector ) const; void ConvertTo( CONST_VECTOR_OBJECT& aOutVector ) const;
const CBBOX &GetBBox() const { return m_bbox; } const BBOX_3D& GetBBox() const { return m_bbox; }
virtual bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const = 0; virtual bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const = 0;
virtual bool IntersectP( const RAY &aRay, float aMaxDistance ) const = 0; virtual bool IntersectP( const RAY& aRay, float aMaxDistance ) const = 0;
protected: protected:
CBBOX m_bbox; BBOX_3D m_bbox;
LIST_OBJECT m_objects; LIST_OBJECT m_objects;
}; };
class CCONTAINER : public CGENERICCONTAINER class CONTAINER_3D : public CONTAINER_3D_BASE
{ {
public: public:
bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const override; bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const override;
bool IntersectP( const RAY &aRay, float aMaxDistance ) const override; bool IntersectP( const RAY& aRay, float aMaxDistance ) const override;
}; };
#endif // _CCONTAINER_H_ #endif // _CONTAINER_3D_H_

View File

@ -35,20 +35,18 @@
#include <wx/debug.h> #include <wx/debug.h>
CGENERICCONTAINER2D::CGENERICCONTAINER2D( OBJECT2D_TYPE aObjType ) CONTAINER_2D_BASE::CONTAINER_2D_BASE( OBJECT_2D_TYPE aObjType )
{ {
m_bbox.Reset(); m_bbox.Reset();
} }
void CGENERICCONTAINER2D::Clear() void CONTAINER_2D_BASE::Clear()
{ {
std::lock_guard<std::mutex> lock( m_lock ); std::lock_guard<std::mutex> lock( m_lock );
m_bbox.Reset(); m_bbox.Reset();
for( LIST_OBJECT2D::iterator ii = m_objects.begin(); for( LIST_OBJECT2D::iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii )
ii != m_objects.end();
++ii )
{ {
delete *ii; delete *ii;
} }
@ -57,196 +55,51 @@ void CGENERICCONTAINER2D::Clear()
} }
CGENERICCONTAINER2D::~CGENERICCONTAINER2D() CONTAINER_2D_BASE::~CONTAINER_2D_BASE()
{ {
Clear(); Clear();
} }
CCONTAINER2D::CCONTAINER2D() : CGENERICCONTAINER2D( OBJECT2D_TYPE::CONTAINER ) CONTAINER_2D::CONTAINER_2D() : CONTAINER_2D_BASE( OBJECT_2D_TYPE::CONTAINER )
{ {
} }
/// @todo Determine what to do with this commented out code. void CONTAINER_2D::GetListObjectsIntersects( const BBOX_2D& aBBox,
/* CONST_LIST_OBJECT2D& aOutList ) const
bool CCONTAINER2D::Intersects( const CBBOX2D &aBBox ) const
{
return false;
}
bool CCONTAINER2D::Overlaps( const CBBOX2D &aBBox ) const
{
// NOT IMPLEMENTED
return false;
}
bool CCONTAINER2D::Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const
{
if( !m_bbox.Intersect( aSegRay ) )
return false;
bool hitted = false;
for( LIST_OBJECT2D::const_iterator ii = m_objects.begin();
ii != m_objects.end();
ii++ )
{
const COBJECT2D *object = static_cast<const COBJECT2D *>(*ii);
float t;
SFVEC2F hitNormal;
if( object->Intersect( aSegRay, &t, &hitNormal ) )
if( (hitted == false) || (t < *aOutT ) )
{
hitted = true;
*aOutT = t;
*aNormalOut = hitNormal;
}
}
return hitted;
}
INTERSECTION_RESULT CCONTAINER2D::IsBBoxInside( const CBBOX2D &aBBox ) const
{
return INTERSECTION_RESULT::MISSES;
}
bool CCONTAINER2D::IsPointInside( const SFVEC2F &aPoint ) const
{
if( !m_bbox.Inside( aPoint ) )
return false;
for( LIST_OBJECT2D::const_iterator ii = m_objects.begin();
ii != m_objects.end();
ii++ )
{
const COBJECT2D *object = static_cast<const COBJECT2D *>(*ii);
if( object->IsPointInside( aPoint ) )
return true;
}
return false;
}
*/
void CCONTAINER2D::GetListObjectsIntersects( const CBBOX2D & aBBox,
CONST_LIST_OBJECT2D &aOutList ) const
{ {
/// @todo Determine what to do with this code. /// @todo Determine what to do with this code.
} }
bool CCONTAINER2D::IntersectAny( const RAYSEG2D &aSegRay ) const bool CONTAINER_2D::IntersectAny( const RAYSEG2D& aSegRay ) const
{ {
/// @todo Determine what what needs done because someone wrote TODO here. /// @todo Determine what what needs done because someone wrote TODO here.
return false; return false;
} }
CBVHCONTAINER2D::CBVHCONTAINER2D() : CGENERICCONTAINER2D( OBJECT2D_TYPE::BVHCONTAINER ) BVH_CONTAINER_2D::BVH_CONTAINER_2D() : CONTAINER_2D_BASE( OBJECT_2D_TYPE::BVHCONTAINER )
{ {
m_isInitialized = false; m_isInitialized = false;
m_bbox.Reset(); m_bbox.Reset();
m_elements_to_delete.clear(); m_elements_to_delete.clear();
m_Tree = NULL; m_Tree = nullptr;
} }
/// @todo Determine what to do with this commented out code. void BVH_CONTAINER_2D::Clear()
/*
bool CBVHCONTAINER2D::Intersects( const CBBOX2D &aBBox ) const
{ {
// !TODO: implement the BVH CONTAINER_2D_BASE::Clear();
return m_bbox.Intersects( aBBox );
}
bool CBVHCONTAINER2D::Overlaps( const CBBOX2D &aBBox ) const
{
// NOT IMPLEMENTED
return false;
}
bool CBVHCONTAINER2D::Intersect( const RAYSEG2D &aSegRay,
float *aOutT, SFVEC2F *aNormalOut ) const
{
// !TODO: implement the BVH
if( !m_bbox.Intersect( aSegRay ) )
return false;
bool hitted = false;
for( LIST_OBJECT2D::const_iterator ii = m_objects.begin();
ii != m_objects.end();
ii++ )
{
const COBJECT2D *object = static_cast<const COBJECT2D *>(*ii);
float t;
SFVEC2F hitNormal;
if( object->Intersect( aSegRay, &t, &hitNormal ) )
if( (hitted == false) || (t < *aOutT ) )
{
hitted = true;
*aOutT = t;
*aNormalOut = hitNormal;
}
}
return hitted;
}
INTERSECTION_RESULT CBVHCONTAINER2D::IsBBoxInside( const CBBOX2D &aBBox ) const
{
return INTR_MISSES;
}
bool CBVHCONTAINER2D::IsPointInside( const SFVEC2F &aPoint ) const
{
// !TODO: implement the BVH
if( !m_bbox.Inside( aPoint ) )
return false;
for( LIST_OBJECT2D::const_iterator ii = m_objects.begin();
ii != m_objects.end();
ii++ )
{
const COBJECT2D *object = static_cast<const COBJECT2D *>(*ii);
if( object->IsPointInside( aPoint ) )
return true;
}
return false;
}
*/
void CBVHCONTAINER2D::Clear()
{
CGENERICCONTAINER2D::Clear();
destroy(); destroy();
} }
void CBVHCONTAINER2D::destroy() void BVH_CONTAINER_2D::destroy()
{ {
for( std::list<BVH_CONTAINER_NODE_2D *>::iterator ii = m_elements_to_delete.begin(); for( std::list<BVH_CONTAINER_NODE_2D*>::iterator ii = m_elements_to_delete.begin();
ii != m_elements_to_delete.end(); ii != m_elements_to_delete.end();
++ii ) ++ii )
{ {
@ -259,7 +112,7 @@ void CBVHCONTAINER2D::destroy()
} }
CBVHCONTAINER2D::~CBVHCONTAINER2D() BVH_CONTAINER_2D::~BVH_CONTAINER_2D()
{ {
destroy(); destroy();
} }
@ -268,7 +121,7 @@ CBVHCONTAINER2D::~CBVHCONTAINER2D()
#define BVH_CONTAINER2D_MAX_OBJ_PER_LEAF 4 #define BVH_CONTAINER2D_MAX_OBJ_PER_LEAF 4
void CBVHCONTAINER2D::BuildBVH() void BVH_CONTAINER_2D::BuildBVH()
{ {
if( m_isInitialized ) if( m_isInitialized )
destroy(); destroy();
@ -287,7 +140,7 @@ void CBVHCONTAINER2D::BuildBVH()
for( LIST_OBJECT2D::const_iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii ) for( LIST_OBJECT2D::const_iterator ii = m_objects.begin(); ii != m_objects.end(); ++ii )
{ {
m_Tree->m_LeafList.push_back( static_cast<const COBJECT2D *>( *ii ) ); m_Tree->m_LeafList.push_back( static_cast<const OBJECT_2D*>( *ii ) );
} }
recursiveBuild_MIDDLE_SPLIT( m_Tree ); recursiveBuild_MIDDLE_SPLIT( m_Tree );
@ -301,35 +154,35 @@ void CBVHCONTAINER2D::BuildBVH()
// "Split in the middle of the longest Axis" // "Split in the middle of the longest Axis"
// "Creates a binary tree with Top-Down approach. // "Creates a binary tree with Top-Down approach.
// Fastest BVH building, but least [speed] accuracy." // Fastest BVH building, but least [speed] accuracy."
static bool sortByCentroid_X( const COBJECT2D *a, const COBJECT2D *b ) static bool sortByCentroid_X( const OBJECT_2D* a, const OBJECT_2D* b )
{ {
return a->GetCentroid()[0] < b->GetCentroid()[0]; return a->GetCentroid()[0] < b->GetCentroid()[0];
} }
static bool sortByCentroid_Y( const COBJECT2D *a, const COBJECT2D *b ) static bool sortByCentroid_Y( const OBJECT_2D* a, const OBJECT_2D* b )
{ {
return a->GetCentroid()[0] < b->GetCentroid()[0]; return a->GetCentroid()[0] < b->GetCentroid()[0];
} }
static bool sortByCentroid_Z( const COBJECT2D *a, const COBJECT2D *b ) static bool sortByCentroid_Z( const OBJECT_2D* a, const OBJECT_2D* b )
{ {
return a->GetCentroid()[0] < b->GetCentroid()[0]; return a->GetCentroid()[0] < b->GetCentroid()[0];
} }
void CBVHCONTAINER2D::recursiveBuild_MIDDLE_SPLIT( BVH_CONTAINER_NODE_2D *aNodeParent ) void BVH_CONTAINER_2D::recursiveBuild_MIDDLE_SPLIT( BVH_CONTAINER_NODE_2D* aNodeParent )
{ {
wxASSERT( aNodeParent != NULL ); wxASSERT( aNodeParent != nullptr );
wxASSERT( aNodeParent->m_BBox.IsInitialized() == true ); wxASSERT( aNodeParent->m_BBox.IsInitialized() == true );
wxASSERT( aNodeParent->m_LeafList.size() > 0 ); wxASSERT( aNodeParent->m_LeafList.size() > 0 );
if( aNodeParent->m_LeafList.size() > BVH_CONTAINER2D_MAX_OBJ_PER_LEAF ) if( aNodeParent->m_LeafList.size() > BVH_CONTAINER2D_MAX_OBJ_PER_LEAF )
{ {
// Create Leaf Nodes // Create Leaf Nodes
BVH_CONTAINER_NODE_2D *leftNode = new BVH_CONTAINER_NODE_2D; BVH_CONTAINER_NODE_2D* leftNode = new BVH_CONTAINER_NODE_2D;
BVH_CONTAINER_NODE_2D *rightNode = new BVH_CONTAINER_NODE_2D; BVH_CONTAINER_NODE_2D* rightNode = new BVH_CONTAINER_NODE_2D;
m_elements_to_delete.push_back( leftNode ); m_elements_to_delete.push_back( leftNode );
m_elements_to_delete.push_back( rightNode ); m_elements_to_delete.push_back( rightNode );
@ -355,7 +208,7 @@ void CBVHCONTAINER2D::recursiveBuild_MIDDLE_SPLIT( BVH_CONTAINER_NODE_2D *aNodeP
ii != aNodeParent->m_LeafList.end(); ii != aNodeParent->m_LeafList.end();
++ii ) ++ii )
{ {
const COBJECT2D *object = static_cast<const COBJECT2D *>(*ii); const OBJECT_2D* object = static_cast<const OBJECT_2D*>( *ii );
if( i < (aNodeParent->m_LeafList.size() / 2 ) ) if( i < (aNodeParent->m_LeafList.size() / 2 ) )
{ {
@ -388,16 +241,16 @@ void CBVHCONTAINER2D::recursiveBuild_MIDDLE_SPLIT( BVH_CONTAINER_NODE_2D *aNodeP
else else
{ {
// It is a Leaf // It is a Leaf
aNodeParent->m_Children[0] = NULL; aNodeParent->m_Children[0] = nullptr;
aNodeParent->m_Children[1] = NULL; aNodeParent->m_Children[1] = nullptr;
} }
wxASSERT( aNodeParent != NULL ); wxASSERT( aNodeParent != nullptr );
wxASSERT( aNodeParent->m_BBox.IsInitialized() == true ); wxASSERT( aNodeParent->m_BBox.IsInitialized() == true );
} }
bool CBVHCONTAINER2D::IntersectAny( const RAYSEG2D &aSegRay ) const bool BVH_CONTAINER_2D::IntersectAny( const RAYSEG2D& aSegRay ) const
{ {
wxASSERT( m_isInitialized == true ); wxASSERT( m_isInitialized == true );
@ -408,22 +261,21 @@ bool CBVHCONTAINER2D::IntersectAny( const RAYSEG2D &aSegRay ) const
} }
bool CBVHCONTAINER2D::recursiveIntersectAny( const BVH_CONTAINER_NODE_2D *aNode, bool BVH_CONTAINER_2D::recursiveIntersectAny( const BVH_CONTAINER_NODE_2D* aNode,
const RAYSEG2D &aSegRay ) const const RAYSEG2D& aSegRay ) const
{ {
wxASSERT( aNode != NULL ); wxASSERT( aNode != nullptr );
if( aNode->m_BBox.Inside( aSegRay.m_Start ) || if( aNode->m_BBox.Inside( aSegRay.m_Start ) || aNode->m_BBox.Inside( aSegRay.m_End ) ||
aNode->m_BBox.Inside( aSegRay.m_End ) ||
aNode->m_BBox.Intersect( aSegRay ) ) aNode->m_BBox.Intersect( aSegRay ) )
{ {
if( !aNode->m_LeafList.empty() ) if( !aNode->m_LeafList.empty() )
{ {
wxASSERT( aNode->m_Children[0] == NULL ); wxASSERT( aNode->m_Children[0] == nullptr );
wxASSERT( aNode->m_Children[1] == NULL ); wxASSERT( aNode->m_Children[1] == nullptr );
// Leaf // Leaf
for( const COBJECT2D *obj : aNode->m_LeafList ) for( const OBJECT_2D* obj : aNode->m_LeafList )
{ {
if( obj->IsPointInside( aSegRay.m_Start ) || if( obj->IsPointInside( aSegRay.m_Start ) ||
obj->IsPointInside( aSegRay.m_End ) || obj->IsPointInside( aSegRay.m_End ) ||
@ -433,8 +285,8 @@ bool CBVHCONTAINER2D::recursiveIntersectAny( const BVH_CONTAINER_NODE_2D *aNode,
} }
else else
{ {
wxASSERT( aNode->m_Children[0] != NULL ); wxASSERT( aNode->m_Children[0] != nullptr );
wxASSERT( aNode->m_Children[1] != NULL ); wxASSERT( aNode->m_Children[1] != nullptr );
// Node // Node
if( recursiveIntersectAny( aNode->m_Children[0], aSegRay ) ) if( recursiveIntersectAny( aNode->m_Children[0], aSegRay ) )
@ -448,8 +300,8 @@ bool CBVHCONTAINER2D::recursiveIntersectAny( const BVH_CONTAINER_NODE_2D *aNode,
} }
void CBVHCONTAINER2D::GetListObjectsIntersects( const CBBOX2D &aBBox, void BVH_CONTAINER_2D::GetListObjectsIntersects( const BBOX_2D& aBBox,
CONST_LIST_OBJECT2D &aOutList ) const CONST_LIST_OBJECT2D& aOutList ) const
{ {
wxASSERT( aBBox.IsInitialized() == true ); wxASSERT( aBBox.IsInitialized() == true );
wxASSERT( m_isInitialized == true ); wxASSERT( m_isInitialized == true );
@ -461,26 +313,26 @@ void CBVHCONTAINER2D::GetListObjectsIntersects( const CBBOX2D &aBBox,
} }
void CBVHCONTAINER2D::recursiveGetListObjectsIntersects( const BVH_CONTAINER_NODE_2D *aNode, void BVH_CONTAINER_2D::recursiveGetListObjectsIntersects( const BVH_CONTAINER_NODE_2D* aNode,
const CBBOX2D & aBBox, const BBOX_2D& aBBox,
CONST_LIST_OBJECT2D &aOutList ) const CONST_LIST_OBJECT2D& aOutList ) const
{ {
wxASSERT( aNode != NULL ); wxASSERT( aNode != nullptr );
wxASSERT( aBBox.IsInitialized() == true ); wxASSERT( aBBox.IsInitialized() == true );
if( aNode->m_BBox.Intersects( aBBox ) ) if( aNode->m_BBox.Intersects( aBBox ) )
{ {
if( !aNode->m_LeafList.empty() ) if( !aNode->m_LeafList.empty() )
{ {
wxASSERT( aNode->m_Children[0] == NULL ); wxASSERT( aNode->m_Children[0] == nullptr );
wxASSERT( aNode->m_Children[1] == NULL ); wxASSERT( aNode->m_Children[1] == nullptr );
// Leaf // Leaf
for( CONST_LIST_OBJECT2D::const_iterator ii = aNode->m_LeafList.begin(); for( CONST_LIST_OBJECT2D::const_iterator ii = aNode->m_LeafList.begin();
ii != aNode->m_LeafList.end(); ii != aNode->m_LeafList.end();
++ii ) ++ii )
{ {
const COBJECT2D *obj = static_cast<const COBJECT2D *>(*ii); const OBJECT_2D* obj = static_cast<const OBJECT_2D*>( *ii );
if( obj->Intersects( aBBox ) ) if( obj->Intersects( aBBox ) )
aOutList.push_back( obj ); aOutList.push_back( obj );
@ -488,8 +340,8 @@ void CBVHCONTAINER2D::recursiveGetListObjectsIntersects( const BVH_CONTAINER_NOD
} }
else else
{ {
wxASSERT( aNode->m_Children[0] != NULL ); wxASSERT( aNode->m_Children[0] != nullptr );
wxASSERT( aNode->m_Children[1] != NULL ); wxASSERT( aNode->m_Children[1] != nullptr );
// Node // Node
recursiveGetListObjectsIntersects( aNode->m_Children[0], aBBox, aOutList ); recursiveGetListObjectsIntersects( aNode->m_Children[0], aBBox, aOutList );

View File

@ -27,25 +27,25 @@
* @brief * @brief
*/ */
#ifndef _CCONTAINER2D_H_ #ifndef _CONTAINER_2D_H_
#define _CCONTAINER2D_H_ #define _CONTAINER_2D_H_
#include "../shapes2D/cobject2d.h" #include "../shapes2D/cobject2d.h"
#include <list> #include <list>
#include <mutex> #include <mutex>
typedef std::list<COBJECT2D *> LIST_OBJECT2D; typedef std::list<OBJECT_2D*> LIST_OBJECT2D;
typedef std::list<const COBJECT2D *> CONST_LIST_OBJECT2D; typedef std::list<const OBJECT_2D*> CONST_LIST_OBJECT2D;
class CGENERICCONTAINER2D class CONTAINER_2D_BASE
{ {
public: public:
explicit CGENERICCONTAINER2D( OBJECT2D_TYPE aObjType ); explicit CONTAINER_2D_BASE( OBJECT_2D_TYPE aObjType );
virtual ~CGENERICCONTAINER2D(); virtual ~CONTAINER_2D_BASE();
void Add( COBJECT2D *aObject ) void Add( OBJECT_2D* aObject )
{ {
if( aObject ) if( aObject )
{ {
@ -55,14 +55,14 @@ public:
} }
} }
const CBBOX2D &GetBBox() const const BBOX_2D& GetBBox() const
{ {
return m_bbox; return m_bbox;
} }
virtual void Clear(); virtual void Clear();
const LIST_OBJECT2D &GetList() const { return m_objects; } const LIST_OBJECT2D& GetList() const { return m_objects; }
/** /**
* Get a list of objects that intersects a bounding box. * Get a list of objects that intersects a bounding box.
@ -70,8 +70,8 @@ public:
* @param aBBox The bounding box to test. * @param aBBox The bounding box to test.
* @param aOutList The list of objects that intersects the bounding box. * @param aOutList The list of objects that intersects the bounding box.
*/ */
virtual void GetListObjectsIntersects( const CBBOX2D & aBBox, virtual void GetListObjectsIntersects( const BBOX_2D& aBBox,
CONST_LIST_OBJECT2D &aOutList ) const = 0; CONST_LIST_OBJECT2D& aOutList ) const = 0;
/** /**
* Intersect and check if a segment ray hits a object or is inside it. * Intersect and check if a segment ray hits a object or is inside it.
@ -79,10 +79,10 @@ public:
* @param aSegRay The segment to intersect with objects. * @param aSegRay The segment to intersect with objects.
* @return true if it hits any of the objects or is inside any object. * @return true if it hits any of the objects or is inside any object.
*/ */
virtual bool IntersectAny( const RAYSEG2D &aSegRay ) const = 0; virtual bool IntersectAny( const RAYSEG2D& aSegRay ) const = 0;
protected: protected:
CBBOX2D m_bbox; BBOX_2D m_bbox;
LIST_OBJECT2D m_objects; LIST_OBJECT2D m_objects;
private: private:
@ -90,58 +90,56 @@ private:
}; };
class CCONTAINER2D : public CGENERICCONTAINER2D class CONTAINER_2D : public CONTAINER_2D_BASE
{ {
public: public:
CCONTAINER2D(); CONTAINER_2D();
// Imported from CGENERICCONTAINER2D void GetListObjectsIntersects( const BBOX_2D& aBBox,
void GetListObjectsIntersects( const CBBOX2D & aBBox, CONST_LIST_OBJECT2D& aOutList ) const override;
CONST_LIST_OBJECT2D &aOutList ) const override;
bool IntersectAny( const RAYSEG2D &aSegRay ) const override; bool IntersectAny( const RAYSEG2D& aSegRay ) const override;
}; };
struct BVH_CONTAINER_NODE_2D struct BVH_CONTAINER_NODE_2D
{ {
CBBOX2D m_BBox; BBOX_2D m_BBox;
BVH_CONTAINER_NODE_2D *m_Children[2]; BVH_CONTAINER_NODE_2D* m_Children[2];
/// Store the list of objects if that node is a Leaf /// Store the list of objects if that node is a Leaf
CONST_LIST_OBJECT2D m_LeafList; CONST_LIST_OBJECT2D m_LeafList;
}; };
class CBVHCONTAINER2D : public CGENERICCONTAINER2D class BVH_CONTAINER_2D : public CONTAINER_2D_BASE
{ {
public: public:
CBVHCONTAINER2D(); BVH_CONTAINER_2D();
~CBVHCONTAINER2D(); ~BVH_CONTAINER_2D();
void BuildBVH(); void BuildBVH();
void Clear() override; void Clear() override;
// Imported from CGENERICCONTAINER2D void GetListObjectsIntersects( const BBOX_2D& aBBox,
void GetListObjectsIntersects( const CBBOX2D & aBBox, CONST_LIST_OBJECT2D& aOutList ) const override;
CONST_LIST_OBJECT2D &aOutList ) const override;
bool IntersectAny( const RAYSEG2D &aSegRay ) const override; bool IntersectAny( const RAYSEG2D& aSegRay ) const override;
private: private:
void destroy(); void destroy();
void recursiveBuild_MIDDLE_SPLIT( BVH_CONTAINER_NODE_2D *aNodeParent ); void recursiveBuild_MIDDLE_SPLIT( BVH_CONTAINER_NODE_2D* aNodeParent );
void recursiveGetListObjectsIntersects( const BVH_CONTAINER_NODE_2D *aNode, void recursiveGetListObjectsIntersects( const BVH_CONTAINER_NODE_2D* aNode,
const CBBOX2D & aBBox, const BBOX_2D& aBBox,
CONST_LIST_OBJECT2D &aOutList ) const; CONST_LIST_OBJECT2D& aOutList ) const;
bool recursiveIntersectAny( const BVH_CONTAINER_NODE_2D *aNode, bool recursiveIntersectAny( const BVH_CONTAINER_NODE_2D* aNode,
const RAYSEG2D &aSegRay ) const; const RAYSEG2D& aSegRay ) const;
bool m_isInitialized; bool m_isInitialized;
std::list<BVH_CONTAINER_NODE_2D *> m_elements_to_delete; std::list<BVH_CONTAINER_NODE_2D*> m_elements_to_delete;
BVH_CONTAINER_NODE_2D* m_Tree; BVH_CONTAINER_NODE_2D* m_Tree;
}; };
#endif // _CCONTAINER2D_H_ #endif // _CONTAINER_2D_H_

View File

@ -47,25 +47,25 @@
// convertLinearToSRGB // convertLinearToSRGB
//#include <glm/gtc/color_space.hpp> //#include <glm/gtc/color_space.hpp>
C3D_RENDER_RAYTRACING::C3D_RENDER_RAYTRACING( BOARD_ADAPTER& aAdapter, CCAMERA& aCamera ) : RENDER_3D_RAYTRACE::RENDER_3D_RAYTRACE( BOARD_ADAPTER& aAdapter, CAMERA& aCamera ) :
C3D_RENDER_BASE( aAdapter, aCamera ), RENDER_3D_BASE( aAdapter, aCamera ),
m_postshader_ssao( aCamera ) m_postshader_ssao( aCamera )
{ {
wxLogTrace( m_logTrace, wxT( "C3D_RENDER_RAYTRACING::C3D_RENDER_RAYTRACING" ) ); wxLogTrace( m_logTrace, wxT( "RENDER_3D_RAYTRACE::RENDER_3D_RAYTRACE" ) );
m_opengl_support_vertex_buffer_object = false; m_opengl_support_vertex_buffer_object = false;
m_pboId = GL_NONE; m_pboId = GL_NONE;
m_pboDataSize = 0; m_pboDataSize = 0;
m_accelerator = NULL; m_accelerator = nullptr;
m_stats_converted_dummy_to_plane = 0; m_stats_converted_dummy_to_plane = 0;
m_stats_converted_roundsegment2d_to_roundsegment = 0; m_stats_converted_roundsegment2d_to_roundsegment = 0;
m_oldWindowsSize.x = 0; m_oldWindowsSize.x = 0;
m_oldWindowsSize.y = 0; m_oldWindowsSize.y = 0;
m_outlineBoard2dObjects = NULL; m_outlineBoard2dObjects = nullptr;
m_antioutlineBoard2dObjects = NULL; m_antioutlineBoard2dObjects = nullptr;
m_firstHitinfo = NULL; m_firstHitinfo = nullptr;
m_shaderBuffer = NULL; m_shaderBuffer = nullptr;
m_camera_light = NULL; m_camera_light = nullptr;
m_xoffset = 0; m_xoffset = 0;
m_yoffset = 0; m_yoffset = 0;
@ -77,33 +77,33 @@ C3D_RENDER_RAYTRACING::C3D_RENDER_RAYTRACING( BOARD_ADAPTER& aAdapter, CCAMERA&
} }
C3D_RENDER_RAYTRACING::~C3D_RENDER_RAYTRACING() RENDER_3D_RAYTRACE::~RENDER_3D_RAYTRACE()
{ {
wxLogTrace( m_logTrace, wxT( "C3D_RENDER_RAYTRACING::~C3D_RENDER_RAYTRACING" ) ); wxLogTrace( m_logTrace, wxT( "RENDER_3D_RAYTRACE::~RENDER_3D_RAYTRACE" ) );
delete m_accelerator; delete m_accelerator;
m_accelerator = NULL; m_accelerator = nullptr;
delete m_outlineBoard2dObjects; delete m_outlineBoard2dObjects;
m_outlineBoard2dObjects = NULL; m_outlineBoard2dObjects = nullptr;
delete m_antioutlineBoard2dObjects; delete m_antioutlineBoard2dObjects;
m_antioutlineBoard2dObjects = NULL; m_antioutlineBoard2dObjects = nullptr;
delete[] m_shaderBuffer; delete[] m_shaderBuffer;
m_shaderBuffer = NULL; m_shaderBuffer = nullptr;
opengl_delete_pbo(); opengl_delete_pbo();
} }
int C3D_RENDER_RAYTRACING::GetWaitForEditingTimeOut() int RENDER_3D_RAYTRACE::GetWaitForEditingTimeOut()
{ {
return 1000; // ms return 1000; // ms
} }
void C3D_RENDER_RAYTRACING::opengl_delete_pbo() void RENDER_3D_RAYTRACE::opengl_delete_pbo()
{ {
// Delete PBO if it was created // Delete PBO if it was created
if( m_opengl_support_vertex_buffer_object ) if( m_opengl_support_vertex_buffer_object )
@ -116,7 +116,7 @@ void C3D_RENDER_RAYTRACING::opengl_delete_pbo()
} }
void C3D_RENDER_RAYTRACING::SetCurWindowSize( const wxSize& aSize ) void RENDER_3D_RAYTRACE::SetCurWindowSize( const wxSize& aSize )
{ {
if( m_windowSize != aSize ) if( m_windowSize != aSize )
{ {
@ -128,7 +128,7 @@ void C3D_RENDER_RAYTRACING::SetCurWindowSize( const wxSize& aSize )
} }
void C3D_RENDER_RAYTRACING::restart_render_state() void RENDER_3D_RAYTRACE::restart_render_state()
{ {
m_stats_start_rendering_time = GetRunningMicroSecs(); m_stats_start_rendering_time = GetRunningMicroSecs();
@ -144,13 +144,13 @@ void C3D_RENDER_RAYTRACING::restart_render_state()
} }
static inline void SetPixel( GLubyte *p, const CCOLORRGB &v ) static inline void SetPixel( GLubyte* p, const COLOR_RGB& v )
{ {
p[0] = v.c[0]; p[1] = v.c[1]; p[2] = v.c[2]; p[3] = 255; p[0] = v.c[0]; p[1] = v.c[1]; p[2] = v.c[2]; p[3] = 255;
} }
bool C3D_RENDER_RAYTRACING::Redraw( bool aIsMoving, REPORTER* aStatusReporter, bool RENDER_3D_RAYTRACE::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
REPORTER* aWarningReporter ) REPORTER* aWarningReporter )
{ {
bool requestRedraw = false; bool requestRedraw = false;
@ -232,7 +232,7 @@ bool C3D_RENDER_RAYTRACING::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, m_pboId ); glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, m_pboId );
// Get the PBO pixel pointer to write the data // Get the PBO pixel pointer to write the data
GLubyte *ptrPBO = (GLubyte *)glMapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, GLubyte* ptrPBO = (GLubyte *)glMapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB,
GL_WRITE_ONLY_ARB ); GL_WRITE_ONLY_ARB );
if( ptrPBO ) if( ptrPBO )
@ -253,7 +253,7 @@ bool C3D_RENDER_RAYTRACING::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
if( m_rt_render_state != RT_RENDER_STATE_FINISH ) if( m_rt_render_state != RT_RENDER_STATE_FINISH )
{ {
// Get the PBO pixel pointer to write the data // Get the PBO pixel pointer to write the data
GLubyte *ptrPBO = (GLubyte *)glMapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, GLubyte* ptrPBO = (GLubyte *)glMapBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB,
GL_WRITE_ONLY_ARB ); GL_WRITE_ONLY_ARB );
if( ptrPBO ) if( ptrPBO )
@ -292,7 +292,7 @@ bool C3D_RENDER_RAYTRACING::Redraw( bool aIsMoving, REPORTER* aStatusReporter,
} }
void C3D_RENDER_RAYTRACING::render( GLubyte* ptrPBO, REPORTER* aStatusReporter ) void RENDER_3D_RAYTRACE::render( GLubyte* ptrPBO, REPORTER* aStatusReporter )
{ {
if( ( m_rt_render_state == RT_RENDER_STATE_FINISH ) if( ( m_rt_render_state == RT_RENDER_STATE_FINISH )
|| ( m_rt_render_state >= RT_RENDER_STATE_MAX ) ) || ( m_rt_render_state >= RT_RENDER_STATE_MAX ) )
@ -308,7 +308,7 @@ void C3D_RENDER_RAYTRACING::render( GLubyte* ptrPBO, REPORTER* aStatusReporter )
// This way it will draw the full buffer but only shows the updated ( // This way it will draw the full buffer but only shows the updated (
// already calculated) squares // already calculated) squares
unsigned int nPixels = m_realBufferSize.x * m_realBufferSize.y; unsigned int nPixels = m_realBufferSize.x * m_realBufferSize.y;
GLubyte *tmp_ptrPBO = ptrPBO + 3; // PBO is RGBA GLubyte* tmp_ptrPBO = ptrPBO + 3; // PBO is RGBA
for( unsigned int i = 0; i < nPixels; ++i ) for( unsigned int i = 0; i < nPixels; ++i )
{ {
@ -353,7 +353,7 @@ void C3D_RENDER_RAYTRACING::render( GLubyte* ptrPBO, REPORTER* aStatusReporter )
} }
void C3D_RENDER_RAYTRACING::rt_render_tracing( GLubyte* ptrPBO, REPORTER* aStatusReporter ) void RENDER_3D_RAYTRACE::rt_render_tracing( GLubyte* ptrPBO, REPORTER* aStatusReporter )
{ {
m_isPreview = false; m_isPreview = false;
@ -443,17 +443,17 @@ SFVEC3F ConvertSRGBToLinear( const SFVEC3F& aSRGBcolor )
{ {
const float gammaCorrection = SRGB_GAMA; const float gammaCorrection = SRGB_GAMA;
return glm::mix( glm::pow( (aSRGBcolor + SFVEC3F(0.055f)) * return glm::mix( glm::pow( ( aSRGBcolor + SFVEC3F( 0.055f ) )
SFVEC3F(0.94786729857819905213270142180095f), * SFVEC3F( 0.94786729857819905213270142180095f ),
SFVEC3F(gammaCorrection) ), SFVEC3F( gammaCorrection ) ),
aSRGBcolor * SFVEC3F(0.07739938080495356037151702786378f), aSRGBcolor * SFVEC3F( 0.07739938080495356037151702786378f ),
glm::lessThanEqual( aSRGBcolor, SFVEC3F(0.04045f) ) ); glm::lessThanEqual( aSRGBcolor, SFVEC3F( 0.04045f ) ) );
} }
#endif #endif
void C3D_RENDER_RAYTRACING::rt_final_color( GLubyte* ptrPBO, const SFVEC3F& rgbColor, void RENDER_3D_RAYTRACE::rt_final_color( GLubyte* ptrPBO, const SFVEC3F& rgbColor,
bool applyColorSpaceConversion ) bool applyColorSpaceConversion )
{ {
SFVEC3F color = rgbColor; SFVEC3F color = rgbColor;
@ -467,9 +467,9 @@ void C3D_RENDER_RAYTRACING::rt_final_color( GLubyte* ptrPBO, const SFVEC3F& rgbC
color = convertLinearToSRGB( rgbColor ); color = convertLinearToSRGB( rgbColor );
#endif #endif
ptrPBO[0] = (unsigned int)glm::clamp( (int)(color.r * 255), 0, 255 ); ptrPBO[0] = (unsigned int) glm::clamp( (int) ( color.r * 255 ), 0, 255 );
ptrPBO[1] = (unsigned int)glm::clamp( (int)(color.g * 255), 0, 255 ); ptrPBO[1] = (unsigned int) glm::clamp( (int) ( color.g * 255 ), 0, 255 );
ptrPBO[2] = (unsigned int)glm::clamp( (int)(color.b * 255), 0, 255 ); ptrPBO[2] = (unsigned int) glm::clamp( (int) ( color.b * 255 ), 0, 255 );
ptrPBO[3] = 255; ptrPBO[3] = 255;
} }
@ -488,7 +488,7 @@ static void HITINFO_PACKET_init( HITINFO_PACKET* aHitPacket )
} }
void C3D_RENDER_RAYTRACING::rt_shades_packet( const SFVEC3F* bgColorY, const RAY* aRayPkt, void RENDER_3D_RAYTRACE::rt_shades_packet( const SFVEC3F* bgColorY, const RAY* aRayPkt,
HITINFO_PACKET* aHitPacket, bool is_testShadow, HITINFO_PACKET* aHitPacket, bool is_testShadow,
SFVEC3F* aOutHitColor ) SFVEC3F* aOutHitColor )
{ {
@ -510,11 +510,10 @@ void C3D_RENDER_RAYTRACING::rt_shades_packet( const SFVEC3F* bgColorY, const RAY
} }
void C3D_RENDER_RAYTRACING::rt_trace_AA_packet( const SFVEC3F* aBgColorY, void RENDER_3D_RAYTRACE::rt_trace_AA_packet( const SFVEC3F* aBgColorY,
const HITINFO_PACKET* aHitPck_X0Y0, const HITINFO_PACKET* aHitPck_X0Y0,
const HITINFO_PACKET* aHitPck_AA_X1Y1, const HITINFO_PACKET* aHitPck_AA_X1Y1,
const RAY* aRayPck, const RAY* aRayPck, SFVEC3F* aOutHitColor )
SFVEC3F* aOutHitColor )
{ {
const bool is_testShadow = m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_SHADOWS ); const bool is_testShadow = m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_SHADOWS );
@ -522,7 +521,7 @@ void C3D_RENDER_RAYTRACING::rt_trace_AA_packet( const SFVEC3F* aBgColorY,
{ {
for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i ) for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
{ {
const RAY &rayAA = aRayPck[i]; const RAY& rayAA = aRayPck[i];
HITINFO hitAA; HITINFO hitAA;
hitAA.m_tHit = std::numeric_limits<float>::infinity(); hitAA.m_tHit = std::numeric_limits<float>::infinity();
@ -632,14 +631,14 @@ void C3D_RENDER_RAYTRACING::rt_trace_AA_packet( const SFVEC3F* aBgColorY,
#define DISP_FACTOR 0.075f #define DISP_FACTOR 0.075f
void C3D_RENDER_RAYTRACING::rt_render_trace_block( GLubyte* ptrPBO, signed int iBlock ) void RENDER_3D_RAYTRACE::rt_render_trace_block( GLubyte* ptrPBO, signed int iBlock )
{ {
// Initialize ray packets // Initialize ray packets
const SFVEC2UI &blockPos = m_blockPositions[iBlock]; const SFVEC2UI& blockPos = m_blockPositions[iBlock];
const SFVEC2I blockPosI = SFVEC2I( blockPos.x + m_xoffset, blockPos.y + m_yoffset ); const SFVEC2I blockPosI = SFVEC2I( blockPos.x + m_xoffset, blockPos.y + m_yoffset );
RAYPACKET blockPacket( m_camera, (SFVEC2F)blockPosI + SFVEC2F(DISP_FACTOR, DISP_FACTOR), RAYPACKET blockPacket( m_camera, (SFVEC2F) blockPosI + SFVEC2F( DISP_FACTOR, DISP_FACTOR ),
SFVEC2F(DISP_FACTOR, DISP_FACTOR) /* Displacement random factor */ ); SFVEC2F( DISP_FACTOR, DISP_FACTOR ) /* Displacement random factor */ );
HITINFO_PACKET hitPacket_X0Y0[RAYPACKET_RAYS_PER_PACKET]; HITINFO_PACKET hitPacket_X0Y0[RAYPACKET_RAYS_PER_PACKET];
@ -651,7 +650,7 @@ void C3D_RENDER_RAYTRACING::rt_render_trace_block( GLubyte* ptrPBO, signed int i
for( unsigned int y = 0; y < RAYPACKET_DIM; ++y ) for( unsigned int y = 0; y < RAYPACKET_DIM; ++y )
{ {
const float posYfactor = (float)(blockPosI.y + y) / (float)m_windowSize.y; const float posYfactor = (float) ( blockPosI.y + y ) / (float) m_windowSize.y;
bgColor[y] = m_BgColorTop_LinearRGB * SFVEC3F(posYfactor) + bgColor[y] = m_BgColorTop_LinearRGB * SFVEC3F(posYfactor) +
m_BgColorBot_LinearRGB * ( SFVEC3F(1.0f) - SFVEC3F(posYfactor) ); m_BgColorBot_LinearRGB * ( SFVEC3F(1.0f) - SFVEC3F(posYfactor) );
@ -665,7 +664,7 @@ void C3D_RENDER_RAYTRACING::rt_render_trace_block( GLubyte* ptrPBO, signed int i
{ {
for( unsigned int y = 0; y < RAYPACKET_DIM; ++y ) for( unsigned int y = 0; y < RAYPACKET_DIM; ++y )
{ {
const SFVEC3F &outColor = bgColor[y]; const SFVEC3F& outColor = bgColor[y];
const unsigned int yBlockPos = blockPos.y + y; const unsigned int yBlockPos = blockPos.y + y;
@ -686,13 +685,13 @@ void C3D_RENDER_RAYTRACING::rt_render_trace_block( GLubyte* ptrPBO, signed int i
for( unsigned int y = 0; y < RAYPACKET_DIM; ++y ) for( unsigned int y = 0; y < RAYPACKET_DIM; ++y )
{ {
const SFVEC3F &outColor = bgColor[y]; const SFVEC3F& outColor = bgColor[y];
const unsigned int yConst = blockPos.x + ( (y + blockPos.y) * m_realBufferSize.x ); const unsigned int yConst = blockPos.x + ( ( y + blockPos.y ) * m_realBufferSize.x );
for( unsigned int x = 0; x < RAYPACKET_DIM; ++x ) for( unsigned int x = 0; x < RAYPACKET_DIM; ++x )
{ {
GLubyte *ptr = &ptrPBO[ (yConst + x) * 4 ]; GLubyte* ptr = &ptrPBO[( yConst + x ) * 4];
rt_final_color( ptr, outColor, isFinalColor ); rt_final_color( ptr, outColor, isFinalColor );
} }
@ -725,7 +724,7 @@ void C3D_RENDER_RAYTRACING::rt_render_trace_block( GLubyte* ptrPBO, signed int i
// Missed all the package // Missed all the package
for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y ) for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
{ {
const SFVEC3F &outColor = bgColor[y]; const SFVEC3F& outColor = bgColor[y];
for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i ) for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
{ {
@ -804,7 +803,7 @@ void C3D_RENDER_RAYTRACING::rt_render_trace_block( GLubyte* ptrPBO, signed int i
for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i ) for( unsigned int x = 0; x < RAYPACKET_DIM; ++x, ++i )
{ {
const SFVEC3F &hColor = hitColor_X0Y0[i]; const SFVEC3F& hColor = hitColor_X0Y0[i];
if( hitPacket_X0Y0[i].m_hitresult == true ) if( hitPacket_X0Y0[i].m_hitresult == true )
m_postshader_ssao.SetPixelData( bPos.x, bPos.y, m_postshader_ssao.SetPixelData( bPos.x, bPos.y,
@ -848,8 +847,7 @@ void C3D_RENDER_RAYTRACING::rt_render_trace_block( GLubyte* ptrPBO, signed int i
} }
void C3D_RENDER_RAYTRACING::rt_render_post_process_shade( GLubyte* ptrPBO, void RENDER_3D_RAYTRACE::rt_render_post_process_shade( GLubyte* ptrPBO, REPORTER* aStatusReporter )
REPORTER* aStatusReporter )
{ {
(void)ptrPBO; // unused (void)ptrPBO; // unused
@ -874,7 +872,7 @@ void C3D_RENDER_RAYTRACING::rt_render_post_process_shade( GLubyte* ptrPBO,
y < m_realBufferSize.y; y < m_realBufferSize.y;
y = nextBlock.fetch_add( 1 ) ) y = nextBlock.fetch_add( 1 ) )
{ {
SFVEC3F *ptr = &m_shaderBuffer[ y * m_realBufferSize.x ]; SFVEC3F* ptr = &m_shaderBuffer[ y * m_realBufferSize.x ];
for( signed int x = 0; x < (int)m_realBufferSize.x; ++x ) for( signed int x = 0; x < (int)m_realBufferSize.x; ++x )
{ {
@ -905,7 +903,7 @@ void C3D_RENDER_RAYTRACING::rt_render_post_process_shade( GLubyte* ptrPBO,
} }
void C3D_RENDER_RAYTRACING::rt_render_post_process_blur_finish( GLubyte* ptrPBO, void RENDER_3D_RAYTRACE::rt_render_post_process_blur_finish( GLubyte* ptrPBO,
REPORTER* aStatusReporter ) REPORTER* aStatusReporter )
{ {
(void) aStatusReporter; //unused (void) aStatusReporter; //unused
@ -925,7 +923,7 @@ void C3D_RENDER_RAYTRACING::rt_render_post_process_blur_finish( GLubyte* ptrPBO,
for( size_t y = nextBlock.fetch_add( 1 ); y < m_realBufferSize.y; for( size_t y = nextBlock.fetch_add( 1 ); y < m_realBufferSize.y;
y = nextBlock.fetch_add( 1 ) ) y = nextBlock.fetch_add( 1 ) )
{ {
GLubyte *ptr = &ptrPBO[ y * m_realBufferSize.x * 4 ]; GLubyte* ptr = &ptrPBO[ y * m_realBufferSize.x * 4 ];
for( signed int x = 0; x < (int)m_realBufferSize.x; ++x ) for( signed int x = 0; x < (int)m_realBufferSize.x; ++x )
{ {
@ -965,7 +963,7 @@ void C3D_RENDER_RAYTRACING::rt_render_post_process_blur_finish( GLubyte* ptrPBO,
} }
void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO ) void RENDER_3D_RAYTRACE::render_preview( GLubyte* ptrPBO )
{ {
m_isPreview = true; m_isPreview = true;
@ -983,7 +981,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
for( size_t iBlock = nextBlock.fetch_add( 1 ); iBlock < m_blockPositionsFast.size(); for( size_t iBlock = nextBlock.fetch_add( 1 ); iBlock < m_blockPositionsFast.size();
iBlock = nextBlock.fetch_add( 1 ) ) iBlock = nextBlock.fetch_add( 1 ) )
{ {
const SFVEC2UI &windowPosUI = m_blockPositionsFast[ iBlock ]; const SFVEC2UI& windowPosUI = m_blockPositionsFast[ iBlock ];
const SFVEC2I windowsPos = SFVEC2I( windowPosUI.x + m_xoffset, const SFVEC2I windowsPos = SFVEC2I( windowPosUI.x + m_xoffset,
windowPosUI.y + m_yoffset ); windowPosUI.y + m_yoffset );
@ -1015,7 +1013,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
* ( SFVEC3F( 1.0f ) - SFVEC3F( posYfactor ) ); * ( SFVEC3F( 1.0f ) - SFVEC3F( posYfactor ) );
} }
CCOLORRGB hitColorShading[RAYPACKET_RAYS_PER_PACKET]; COLOR_RGB hitColorShading[RAYPACKET_RAYS_PER_PACKET];
for( unsigned int i = 0; i < RAYPACKET_RAYS_PER_PACKET; ++i ) for( unsigned int i = 0; i < RAYPACKET_RAYS_PER_PACKET; ++i )
{ {
@ -1027,21 +1025,21 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
hitPacket[i].m_HitInfo, false, hitPacket[i].m_HitInfo, false,
0, false ); 0, false );
hitColorShading[i] = CCOLORRGB( hitColor ); hitColorShading[i] = COLOR_RGB( hitColor );
} }
else else
hitColorShading[i] = bhColorY; hitColorShading[i] = bhColorY;
} }
CCOLORRGB cLRB_old[(RAYPACKET_DIM - 1)]; COLOR_RGB cLRB_old[(RAYPACKET_DIM - 1)];
for( unsigned int y = 0; y < (RAYPACKET_DIM - 1); ++y ) for( unsigned int y = 0; y < (RAYPACKET_DIM - 1); ++y )
{ {
const SFVEC3F bgColorY = bgColor[y]; const SFVEC3F bgColorY = bgColor[y];
const CCOLORRGB bgColorYRGB = CCOLORRGB( bgColorY ); const COLOR_RGB bgColorYRGB = COLOR_RGB( bgColorY );
// This stores cRTB from the last block to be reused next time in a cLTB pixel // This stores cRTB from the last block to be reused next time in a cLTB pixel
CCOLORRGB cRTB_old; COLOR_RGB cRTB_old;
//RAY cRTB_ray; //RAY cRTB_ray;
//HITINFO cRTB_hitInfo; //HITINFO cRTB_hitInfo;
@ -1064,19 +1062,19 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
const unsigned int iRB = ( ( x + 1 ) + RAYPACKET_DIM * ( y + 1 ) ); const unsigned int iRB = ( ( x + 1 ) + RAYPACKET_DIM * ( y + 1 ) );
// !TODO: skip when there are no hits // !TODO: skip when there are no hits
const CCOLORRGB &cLT = hitColorShading[ iLT ]; const COLOR_RGB& cLT = hitColorShading[ iLT ];
const CCOLORRGB &cRT = hitColorShading[ iRT ]; const COLOR_RGB& cRT = hitColorShading[ iRT ];
const CCOLORRGB &cLB = hitColorShading[ iLB ]; const COLOR_RGB& cLB = hitColorShading[ iLB ];
const CCOLORRGB &cRB = hitColorShading[ iRB ]; const COLOR_RGB& cRB = hitColorShading[ iRB ];
// Trace and shade cC // Trace and shade cC
CCOLORRGB cC = bgColorYRGB; COLOR_RGB cC = bgColorYRGB;
const SFVEC3F &oriLT = blockPacket.m_ray[ iLT ].m_Origin; const SFVEC3F& oriLT = blockPacket.m_ray[ iLT ].m_Origin;
const SFVEC3F &oriRB = blockPacket.m_ray[ iRB ].m_Origin; const SFVEC3F& oriRB = blockPacket.m_ray[ iRB ].m_Origin;
const SFVEC3F &dirLT = blockPacket.m_ray[ iLT ].m_Dir; const SFVEC3F& dirLT = blockPacket.m_ray[ iLT ].m_Dir;
const SFVEC3F &dirRB = blockPacket.m_ray[ iRB ].m_Dir; const SFVEC3F& dirRB = blockPacket.m_ray[ iRB ].m_Dir;
SFVEC3F oriC; SFVEC3F oriC;
SFVEC3F dirC; SFVEC3F dirC;
@ -1122,7 +1120,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
if( hittedC ) if( hittedC )
{ {
cC = CCOLORRGB( shadeHit( bgColorY, centerRay, centerHitInfo, cC = COLOR_RGB( shadeHit( bgColorY, centerRay, centerHitInfo,
false, 0, false ) ); false, 0, false ) );
} }
else else
@ -1131,16 +1129,16 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
hittedC = m_accelerator->Intersect( centerRay, centerHitInfo ); hittedC = m_accelerator->Intersect( centerRay, centerHitInfo );
if( hittedC ) if( hittedC )
cC = CCOLORRGB( shadeHit( bgColorY, centerRay, centerHitInfo, cC = COLOR_RGB( shadeHit( bgColorY, centerRay, centerHitInfo,
false, 0, false ) ); false, 0, false ) );
} }
} }
// Trace and shade cLRT // Trace and shade cLRT
CCOLORRGB cLRT = bgColorYRGB; COLOR_RGB cLRT = bgColorYRGB;
const SFVEC3F &oriRT = blockPacket.m_ray[ iRT ].m_Origin; const SFVEC3F& oriRT = blockPacket.m_ray[ iRT ].m_Origin;
const SFVEC3F &dirRT = blockPacket.m_ray[ iRT ].m_Dir; const SFVEC3F& dirRT = blockPacket.m_ray[ iRT ].m_Dir;
if( y == 0 ) if( y == 0 )
{ {
@ -1163,7 +1161,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
glm::normalize( ( hitPacket[ iLT ].m_HitInfo.m_HitNormal + glm::normalize( ( hitPacket[ iLT ].m_HitInfo.m_HitNormal +
hitPacket[ iRT ].m_HitInfo.m_HitNormal ) * 0.5f ); hitPacket[ iRT ].m_HitInfo.m_HitNormal ) * 0.5f );
cLRT = CCOLORRGB( shadeHit( bgColorY, rayLRT, hitInfoLRT, false, cLRT = COLOR_RGB( shadeHit( bgColorY, rayLRT, hitInfoLRT, false,
0, false ) ); 0, false ) );
cLRT = BlendColor( cLRT, BlendColor( cLT, cRT ) ); cLRT = BlendColor( cLRT, BlendColor( cLT, cRT ) );
} }
@ -1188,14 +1186,14 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
nodeRT ); nodeRT );
if( hittedLRT ) if( hittedLRT )
cLRT = CCOLORRGB( shadeHit( bgColorY, rayLRT, hitInfoLRT, cLRT = COLOR_RGB( shadeHit( bgColorY, rayLRT, hitInfoLRT,
false, 0, false ) ); false, 0, false ) );
else else
{ {
hitInfoLRT.m_tHit = std::numeric_limits<float>::infinity(); hitInfoLRT.m_tHit = std::numeric_limits<float>::infinity();
if( m_accelerator->Intersect( rayLRT,hitInfoLRT ) ) if( m_accelerator->Intersect( rayLRT,hitInfoLRT ) )
cLRT = CCOLORRGB( shadeHit( bgColorY, rayLRT, cLRT = COLOR_RGB( shadeHit( bgColorY, rayLRT,
hitInfoLRT, false, hitInfoLRT, false,
0, false ) ); 0, false ) );
} }
@ -1208,12 +1206,12 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
} }
// Trace and shade cLTB // Trace and shade cLTB
CCOLORRGB cLTB = bgColorYRGB; COLOR_RGB cLTB = bgColorYRGB;
if( x == 0 ) if( x == 0 )
{ {
const SFVEC3F &oriLB = blockPacket.m_ray[ iLB ].m_Origin; const SFVEC3F &oriLB = blockPacket.m_ray[ iLB ].m_Origin;
const SFVEC3F &dirLB = blockPacket.m_ray[ iLB ].m_Dir; const SFVEC3F& dirLB = blockPacket.m_ray[ iLB ].m_Dir;
// Trace the center ray // Trace the center ray
RAY rayLTB; RAY rayLTB;
@ -1233,7 +1231,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
hitInfoLTB.m_HitNormal = hitInfoLTB.m_HitNormal =
glm::normalize( ( hitPacket[ iLT ].m_HitInfo.m_HitNormal + glm::normalize( ( hitPacket[ iLT ].m_HitInfo.m_HitNormal +
hitPacket[ iLB ].m_HitInfo.m_HitNormal ) * 0.5f ); hitPacket[ iLB ].m_HitInfo.m_HitNormal ) * 0.5f );
cLTB = CCOLORRGB( shadeHit( bgColorY, rayLTB, hitInfoLTB, false, cLTB = COLOR_RGB( shadeHit( bgColorY, rayLTB, hitInfoLTB, false,
0, false ) ); 0, false ) );
cLTB = BlendColor( cLTB, BlendColor( cLT, cLB) ); cLTB = BlendColor( cLTB, BlendColor( cLT, cLB) );
} }
@ -1258,14 +1256,14 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
nodeLB ); nodeLB );
if( hittedLTB ) if( hittedLTB )
cLTB = CCOLORRGB( shadeHit( bgColorY, rayLTB, hitInfoLTB, cLTB = COLOR_RGB( shadeHit( bgColorY, rayLTB, hitInfoLTB,
false, 0, false ) ); false, 0, false ) );
else else
{ {
hitInfoLTB.m_tHit = std::numeric_limits<float>::infinity(); hitInfoLTB.m_tHit = std::numeric_limits<float>::infinity();
if( m_accelerator->Intersect( rayLTB, hitInfoLTB ) ) if( m_accelerator->Intersect( rayLTB, hitInfoLTB ) )
cLTB = CCOLORRGB( shadeHit( bgColorY, rayLTB, cLTB = COLOR_RGB( shadeHit( bgColorY, rayLTB,
hitInfoLTB, false, hitInfoLTB, false,
0, false ) ); 0, false ) );
} }
@ -1278,7 +1276,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
} }
// Trace and shade cRTB // Trace and shade cRTB
CCOLORRGB cRTB = bgColorYRGB; COLOR_RGB cRTB = bgColorYRGB;
// Trace the center ray // Trace the center ray
RAY rayRTB; RAY rayRTB;
@ -1301,7 +1299,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
glm::normalize( ( hitPacket[ iRT ].m_HitInfo.m_HitNormal + glm::normalize( ( hitPacket[ iRT ].m_HitInfo.m_HitNormal +
hitPacket[ iRB ].m_HitInfo.m_HitNormal ) * 0.5f ); hitPacket[ iRB ].m_HitInfo.m_HitNormal ) * 0.5f );
cRTB = CCOLORRGB( shadeHit( bgColorY, rayRTB, hitInfoRTB, false, 0, cRTB = COLOR_RGB( shadeHit( bgColorY, rayRTB, hitInfoRTB, false, 0,
false ) ); false ) );
cRTB = BlendColor( cRTB, BlendColor( cRT, cRB ) ); cRTB = BlendColor( cRTB, BlendColor( cRT, cRB ) );
} }
@ -1327,7 +1325,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
if( hittedRTB ) if( hittedRTB )
{ {
cRTB = CCOLORRGB( shadeHit( bgColorY, rayRTB, hitInfoRTB, cRTB = COLOR_RGB( shadeHit( bgColorY, rayRTB, hitInfoRTB,
false, 0, false) ); false, 0, false) );
} }
else else
@ -1335,7 +1333,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
hitInfoRTB.m_tHit = std::numeric_limits<float>::infinity(); hitInfoRTB.m_tHit = std::numeric_limits<float>::infinity();
if( m_accelerator->Intersect( rayRTB, hitInfoRTB ) ) if( m_accelerator->Intersect( rayRTB, hitInfoRTB ) )
cRTB = CCOLORRGB( shadeHit( bgColorY, rayRTB, hitInfoRTB, cRTB = COLOR_RGB( shadeHit( bgColorY, rayRTB, hitInfoRTB,
false, 0, false ) ); false, 0, false ) );
} }
} }
@ -1344,10 +1342,10 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
cRTB_old = cRTB; cRTB_old = cRTB;
// Trace and shade cLRB // Trace and shade cLRB
CCOLORRGB cLRB = bgColorYRGB; COLOR_RGB cLRB = bgColorYRGB;
const SFVEC3F &oriLB = blockPacket.m_ray[ iLB ].m_Origin; const SFVEC3F& oriLB = blockPacket.m_ray[ iLB ].m_Origin;
const SFVEC3F &dirLB = blockPacket.m_ray[ iLB ].m_Dir; const SFVEC3F& dirLB = blockPacket.m_ray[ iLB ].m_Dir;
// Trace the center ray // Trace the center ray
RAY rayLRB; RAY rayLRB;
@ -1370,7 +1368,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
glm::normalize( ( hitPacket[ iLB ].m_HitInfo.m_HitNormal + glm::normalize( ( hitPacket[ iLB ].m_HitInfo.m_HitNormal +
hitPacket[ iRB ].m_HitInfo.m_HitNormal ) * 0.5f ); hitPacket[ iRB ].m_HitInfo.m_HitNormal ) * 0.5f );
cLRB = CCOLORRGB( shadeHit( bgColorY, rayLRB, hitInfoLRB, false, 0, cLRB = COLOR_RGB( shadeHit( bgColorY, rayLRB, hitInfoLRB, false, 0,
false ) ); false ) );
cLRB = BlendColor( cLRB, BlendColor( cLB, cRB ) ); cLRB = BlendColor( cLRB, BlendColor( cLB, cRB ) );
} }
@ -1396,7 +1394,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
if( hittedLRB ) if( hittedLRB )
{ {
cLRB = CCOLORRGB( shadeHit( bgColorY, rayLRB, hitInfoLRB, cLRB = COLOR_RGB( shadeHit( bgColorY, rayLRB, hitInfoLRB,
false, 0, false ) ); false, 0, false ) );
} }
else else
@ -1404,7 +1402,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
hitInfoLRB.m_tHit = std::numeric_limits<float>::infinity(); hitInfoLRB.m_tHit = std::numeric_limits<float>::infinity();
if( m_accelerator->Intersect( rayLRB, hitInfoLRB ) ) if( m_accelerator->Intersect( rayLRB, hitInfoLRB ) )
cLRB = CCOLORRGB( shadeHit( bgColorY, rayLRB, hitInfoLRB, cLRB = COLOR_RGB( shadeHit( bgColorY, rayLRB, hitInfoLRB,
false, 0, false ) ); false, 0, false ) );
} }
} }
@ -1413,7 +1411,7 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
cLRB_old[x] = cLRB; cLRB_old[x] = cLRB;
// Trace and shade cLTC // Trace and shade cLTC
CCOLORRGB cLTC = BlendColor( cLT , cC ); COLOR_RGB cLTC = BlendColor( cLT , cC );
if( hitPacket[ iLT ].m_hitresult || hittedC ) if( hitPacket[ iLT ].m_hitresult || hittedC )
{ {
@ -1435,12 +1433,12 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
hitInfoLTC ); hitInfoLTC );
if( hitted ) if( hitted )
cLTC = CCOLORRGB( shadeHit( bgColorY, rayLTC, hitInfoLTC, false, cLTC = COLOR_RGB( shadeHit( bgColorY, rayLTC, hitInfoLTC, false,
0, false ) ); 0, false ) );
} }
// Trace and shade cRTC // Trace and shade cRTC
CCOLORRGB cRTC = BlendColor( cRT , cC ); COLOR_RGB cRTC = BlendColor( cRT , cC );
if( hitPacket[ iRT ].m_hitresult || hittedC ) if( hitPacket[ iRT ].m_hitresult || hittedC )
{ {
@ -1461,12 +1459,12 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
hitInfoRTC ); hitInfoRTC );
if( hitted ) if( hitted )
cRTC = CCOLORRGB( shadeHit( bgColorY, rayRTC, hitInfoRTC, false, cRTC = COLOR_RGB( shadeHit( bgColorY, rayRTC, hitInfoRTC, false,
0, false ) ); 0, false ) );
} }
// Trace and shade cLBC // Trace and shade cLBC
CCOLORRGB cLBC = BlendColor( cLB , cC ); COLOR_RGB cLBC = BlendColor( cLB , cC );
if( hitPacket[ iLB ].m_hitresult || hittedC ) if( hitPacket[ iLB ].m_hitresult || hittedC )
{ {
@ -1487,12 +1485,12 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
hitInfoLBC ); hitInfoLBC );
if( hitted ) if( hitted )
cLBC = CCOLORRGB( shadeHit( bgColorY, rayLBC, hitInfoLBC, false, cLBC = COLOR_RGB( shadeHit( bgColorY, rayLBC, hitInfoLBC, false,
0, false ) ); 0, false ) );
} }
// Trace and shade cRBC // Trace and shade cRBC
CCOLORRGB cRBC = BlendColor( cRB , cC ); COLOR_RGB cRBC = BlendColor( cRB , cC );
if( hitPacket[ iRB ].m_hitresult || hittedC ) if( hitPacket[ iRB ].m_hitresult || hittedC )
{ {
@ -1513,12 +1511,12 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
hitInfoRBC ); hitInfoRBC );
if( hitted ) if( hitted )
cRBC = CCOLORRGB( shadeHit( bgColorY, rayRBC, hitInfoRBC, false, cRBC = COLOR_RGB( shadeHit( bgColorY, rayRBC, hitInfoRBC, false,
0, false ) ); 0, false ) );
} }
// Set pixel colors // Set pixel colors
GLubyte *ptr = &ptrPBO[ (4 * x + m_blockPositionsFast[iBlock].x + GLubyte* ptr = &ptrPBO[ (4 * x + m_blockPositionsFast[iBlock].x +
m_realBufferSize.x * m_realBufferSize.x *
(m_blockPositionsFast[iBlock].y + 4 * y)) * 4 ]; (m_blockPositionsFast[iBlock].y + 4 * y)) * 4 ];
SetPixel( ptr + 0, cLT ); SetPixel( ptr + 0, cLT );
@ -1560,12 +1558,12 @@ void C3D_RENDER_RAYTRACING::render_preview( GLubyte* ptrPBO )
#define USE_EXPERIMENTAL_SOFT_SHADOWS 1 #define USE_EXPERIMENTAL_SOFT_SHADOWS 1
SFVEC3F C3D_RENDER_RAYTRACING::shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, SFVEC3F RENDER_3D_RAYTRACE::shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, HITINFO& aHitInfo,
HITINFO& aHitInfo, bool aIsInsideObject, bool aIsInsideObject, unsigned int aRecursiveLevel,
unsigned int aRecursiveLevel, bool is_testShadow ) const bool is_testShadow ) const
{ {
const CMATERIAL *objMaterial = aHitInfo.pHitObject->GetMaterial(); const MATERIAL* objMaterial = aHitInfo.pHitObject->GetMaterial();
wxASSERT( objMaterial != NULL ); wxASSERT( objMaterial != nullptr );
SFVEC3F outColor = objMaterial->GetEmissiveColor() + objMaterial->GetAmbientColor(); SFVEC3F outColor = objMaterial->GetEmissiveColor() + objMaterial->GetAmbientColor();
@ -1578,7 +1576,7 @@ SFVEC3F C3D_RENDER_RAYTRACING::shadeHit( const SFVEC3F& aBgColor, const RAY& aRa
const SFVEC3F diffuseColorObj = aHitInfo.pHitObject->GetDiffuseColor( aHitInfo ); const SFVEC3F diffuseColorObj = aHitInfo.pHitObject->GetDiffuseColor( aHitInfo );
const LIST_LIGHT &lightList = m_lights.GetList(); const LIST_LIGHT& lightList = m_lights.GetList();
#if USE_EXPERIMENTAL_SOFT_SHADOWS #if USE_EXPERIMENTAL_SOFT_SHADOWS
const bool is_aa_enabled = m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING ) && const bool is_aa_enabled = m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING ) &&
@ -1591,7 +1589,7 @@ SFVEC3F C3D_RENDER_RAYTRACING::shadeHit( const SFVEC3F& aBgColor, const RAY& aRa
for( LIST_LIGHT::const_iterator ii = lightList.begin(); ii != lightList.end(); ++ii ) for( LIST_LIGHT::const_iterator ii = lightList.begin(); ii != lightList.end(); ++ii )
{ {
const CLIGHT *light = (CLIGHT *)*ii; const LIGHT* light = (LIGHT *)*ii;
SFVEC3F vectorToLight; SFVEC3F vectorToLight;
SFVEC3F colorOfLight; SFVEC3F colorOfLight;
@ -1821,13 +1819,12 @@ SFVEC3F C3D_RENDER_RAYTRACING::shadeHit( const SFVEC3F& aBgColor, const RAY& aRa
} }
} }
outColor = outColor * (1.0f - objTransparency) + outColor = outColor * ( 1.0f - objTransparency ) + objTransparency * sum_color
objTransparency * sum_color / / SFVEC3F( (float) refractions_number_of_samples );
SFVEC3F( (float)refractions_number_of_samples);
} }
else else
{ {
outColor = outColor * (1.0f - objTransparency) + objTransparency * aBgColor; outColor = outColor * ( 1.0f - objTransparency ) + objTransparency * aBgColor;
} }
} }
} }
@ -1839,13 +1836,13 @@ SFVEC3F C3D_RENDER_RAYTRACING::shadeHit( const SFVEC3F& aBgColor, const RAY& aRa
} }
void C3D_RENDER_RAYTRACING::initializeNewWindowSize() void RENDER_3D_RAYTRACE::initializeNewWindowSize()
{ {
opengl_init_pbo(); opengl_init_pbo();
} }
void C3D_RENDER_RAYTRACING::opengl_init_pbo() void RENDER_3D_RAYTRACE::opengl_init_pbo()
{ {
if( GLEW_ARB_pixel_buffer_object ) if( GLEW_ARB_pixel_buffer_object )
{ {
@ -1869,12 +1866,12 @@ void C3D_RENDER_RAYTRACING::opengl_init_pbo()
glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, 0 ); glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, 0 );
wxLogTrace( m_logTrace, wxLogTrace( m_logTrace,
wxT( "C3D_RENDER_RAYTRACING:: GLEW_ARB_pixel_buffer_object is supported" ) ); wxT( "RENDER_3D_RAYTRACE:: GLEW_ARB_pixel_buffer_object is supported" ) );
} }
} }
bool C3D_RENDER_RAYTRACING::initializeOpenGL() bool RENDER_3D_RAYTRACE::initializeOpenGL()
{ {
m_is_opengl_initialized = true; m_is_opengl_initialized = true;
@ -1890,7 +1887,7 @@ static float distance( const SFVEC2UI& a, const SFVEC2UI& b )
} }
void C3D_RENDER_RAYTRACING::initialize_block_positions() void RENDER_3D_RAYTRACE::initialize_block_positions()
{ {
m_realBufferSize = SFVEC2UI( 0 ); m_realBufferSize = SFVEC2UI( 0 );
@ -1964,7 +1961,7 @@ void C3D_RENDER_RAYTRACING::initialize_block_positions()
} }
BOARD_ITEM* C3D_RENDER_RAYTRACING::IntersectBoardItem( const RAY& aRay ) BOARD_ITEM* RENDER_3D_RAYTRACE::IntersectBoardItem( const RAY& aRay )
{ {
HITINFO hitInfo; HITINFO hitInfo;
hitInfo.m_tHit = std::numeric_limits<float>::infinity(); hitInfo.m_tHit = std::numeric_limits<float>::infinity();

View File

@ -24,11 +24,10 @@
/** /**
* @file c3d_render_raytracing.h * @file c3d_render_raytracing.h
* @brief
*/ */
#ifndef C3D_RENDER_RAYTRACING_H #ifndef RENDER_3D_RAYTRACE_H
#define C3D_RENDER_RAYTRACING_H #define RENDER_3D_RAYTRACE_H
#include "../../common_ogl/openGL_includes.h" #include "../../common_ogl/openGL_includes.h"
#include "accelerators/ccontainer.h" #include "accelerators/ccontainer.h"
@ -42,10 +41,10 @@
#include <map> #include <map>
/// Vector of materials /// Vector of materials
typedef std::vector< CBLINN_PHONG_MATERIAL > MODEL_MATERIALS; typedef std::vector< BLINN_PHONG_MATERIAL > MODEL_MATERIALS;
/// Maps a S3DMODEL pointer with a created CBLINN_PHONG_MATERIAL vector /// Maps a S3DMODEL pointer with a created BLINN_PHONG_MATERIAL vector
typedef std::map< const S3DMODEL * , MODEL_MATERIALS > MAP_MODEL_MATERIALS; typedef std::map< const S3DMODEL* , MODEL_MATERIALS > MAP_MODEL_MATERIALS;
typedef enum typedef enum
{ {
@ -57,15 +56,15 @@ typedef enum
} RT_RENDER_STATE; } RT_RENDER_STATE;
class C3D_RENDER_RAYTRACING : public C3D_RENDER_BASE class RENDER_3D_RAYTRACE : public RENDER_3D_BASE
{ {
public: public:
explicit C3D_RENDER_RAYTRACING( BOARD_ADAPTER& aAdapter, CCAMERA& aCamera ); explicit RENDER_3D_RAYTRACE( BOARD_ADAPTER& aAdapter, CAMERA& aCamera );
~C3D_RENDER_RAYTRACING(); ~RENDER_3D_RAYTRACE();
// Imported from C3D_RENDER_BASE // Imported from RENDER_3D_BASE
void SetCurWindowSize( const wxSize &aSize ) override; void SetCurWindowSize( const wxSize& aSize ) override;
bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override; bool Redraw( bool aIsMoving, REPORTER* aStatusReporter, REPORTER* aWarningReporter ) override;
int GetWaitForEditingTimeOut() override; int GetWaitForEditingTimeOut() override;
@ -73,97 +72,82 @@ public:
void Reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter, void Reload( REPORTER* aStatusReporter, REPORTER* aWarningReporter,
bool aOnlyLoadCopperAndShapes ); bool aOnlyLoadCopperAndShapes );
BOARD_ITEM *IntersectBoardItem( const RAY &aRay ); BOARD_ITEM *IntersectBoardItem( const RAY& aRay );
private: private:
bool initializeOpenGL(); bool initializeOpenGL();
void initializeNewWindowSize(); void initializeNewWindowSize();
void opengl_init_pbo(); void opengl_init_pbo();
void opengl_delete_pbo(); void opengl_delete_pbo();
void createItemsFromContainer( const CBVHCONTAINER2D *aContainer2d, void createItemsFromContainer( const BVH_CONTAINER_2D* aContainer2d, PCB_LAYER_ID aLayer_id,
PCB_LAYER_ID aLayer_id, const MATERIAL* aMaterialLayer, const SFVEC3F& aLayerColor,
const CMATERIAL *aMaterialLayer,
const SFVEC3F &aLayerColor,
float aLayerZOffset ); float aLayerZOffset );
void restart_render_state(); void restart_render_state();
void rt_render_tracing( GLubyte* ptrPBO, REPORTER* aStatusReporter ); void rt_render_tracing( GLubyte* ptrPBO, REPORTER* aStatusReporter );
void rt_render_post_process_shade( GLubyte* ptrPBO, REPORTER* aStatusReporter ); void rt_render_post_process_shade( GLubyte* ptrPBO, REPORTER* aStatusReporter );
void rt_render_post_process_blur_finish( GLubyte* ptrPBO, REPORTER* aStatusReporter ); void rt_render_post_process_blur_finish( GLubyte* ptrPBO, REPORTER* aStatusReporter );
void rt_render_trace_block( GLubyte *ptrPBO , signed int iBlock ); void rt_render_trace_block( GLubyte* ptrPBO , signed int iBlock );
void rt_final_color( GLubyte *ptrPBO, const SFVEC3F &rgbColor, bool applyColorSpaceConversion ); void rt_final_color( GLubyte* ptrPBO, const SFVEC3F& rgbColor, bool applyColorSpaceConversion );
void rt_shades_packet( const SFVEC3F *bgColorY, void rt_shades_packet( const SFVEC3F* bgColorY, const RAY* aRayPkt, HITINFO_PACKET* aHitPacket,
const RAY *aRayPkt, bool is_testShadow, SFVEC3F* aOutHitColor );
HITINFO_PACKET *aHitPacket,
bool is_testShadow,
SFVEC3F *aOutHitColor );
void rt_trace_AA_packet( const SFVEC3F *aBgColorY, void rt_trace_AA_packet( const SFVEC3F* aBgColorY, const HITINFO_PACKET* aHitPck_X0Y0,
const HITINFO_PACKET *aHitPck_X0Y0, const HITINFO_PACKET* aHitPck_AA_X1Y1, const RAY* aRayPck,
const HITINFO_PACKET *aHitPck_AA_X1Y1, SFVEC3F* aOutHitColor );
const RAY *aRayPck,
SFVEC3F *aOutHitColor );
// Materials // Materials
void setupMaterials(); void setupMaterials();
SFVEC3F shadeHit( const SFVEC3F &aBgColor, SFVEC3F shadeHit( const SFVEC3F& aBgColor, const RAY& aRay, HITINFO& aHitInfo,
const RAY &aRay, bool aIsInsideObject, unsigned int aRecursiveLevel,
HITINFO &aHitInfo,
bool aIsInsideObject,
unsigned int aRecursiveLevel,
bool is_testShadow ) const; bool is_testShadow ) const;
/** /**
* Create one or more 3D objects form a 2D object and Z positions. * Create one or more 3D objects form a 2D object and Z positions.
* *
* It tries to optimize some types of objects that will be faster to trace than the * It tries to optimize some types of objects that will be faster to trace than the
* CLAYERITEM object. * LAYER_ITEM object.
*/ */
void create_3d_object_from( CCONTAINER &aDstContainer, void create_3d_object_from( CONTAINER_3D& aDstContainer, const OBJECT_2D* aObject2D,
const COBJECT2D *aObject2D, float aZMin, float aZMax, const MATERIAL* aMaterial,
float aZMin, float aZMax, const SFVEC3F& aObjColor );
const CMATERIAL *aMaterial,
const SFVEC3F &aObjColor );
void add_3D_vias_and_pads_to_container(); void add_3D_vias_and_pads_to_container();
void insert3DViaHole( const VIA* aVia ); void insert3DViaHole( const VIA* aVia );
void insert3DPadHole( const PAD* aPad ); void insert3DPadHole( const PAD* aPad );
void load_3D_models( CCONTAINER &aDstContainer, bool aSkipMaterialInformation ); void load_3D_models( CONTAINER_3D& aDstContainer, bool aSkipMaterialInformation );
void add_3D_models( CCONTAINER &aDstContainer, void add_3D_models( CONTAINER_3D& aDstContainer, const S3DMODEL* a3DModel,
const S3DMODEL *a3DModel, const glm::mat4& aModelMatrix, float aFPOpacity,
const glm::mat4 &aModelMatrix, bool aSkipMaterialInformation, BOARD_ITEM* aBoardItem );
float aFPOpacity,
bool aSkipMaterialInformation,
BOARD_ITEM *aBoardItem );
MODEL_MATERIALS *get_3D_model_material( const S3DMODEL *a3DModel ); MODEL_MATERIALS* get_3D_model_material( const S3DMODEL* a3DModel );
void initialize_block_positions(); void initialize_block_positions();
void render( GLubyte* ptrPBO, REPORTER* aStatusReporter ); void render( GLubyte* ptrPBO, REPORTER* aStatusReporter );
void render_preview( GLubyte *ptrPBO ); void render_preview( GLubyte* ptrPBO );
struct struct
{ {
CBLINN_PHONG_MATERIAL m_Paste; BLINN_PHONG_MATERIAL m_Paste;
CBLINN_PHONG_MATERIAL m_SilkS; BLINN_PHONG_MATERIAL m_SilkS;
CBLINN_PHONG_MATERIAL m_SolderMask; BLINN_PHONG_MATERIAL m_SolderMask;
CBLINN_PHONG_MATERIAL m_EpoxyBoard; BLINN_PHONG_MATERIAL m_EpoxyBoard;
CBLINN_PHONG_MATERIAL m_Copper; BLINN_PHONG_MATERIAL m_Copper;
CBLINN_PHONG_MATERIAL m_NonPlatedCopper; BLINN_PHONG_MATERIAL m_NonPlatedCopper;
CBLINN_PHONG_MATERIAL m_Floor; BLINN_PHONG_MATERIAL m_Floor;
} m_materials; } m_materials;
CBOARDNORMAL m_board_normal_perturbator; BOARD_NORMAL m_board_normal_perturbator;
CCOPPERNORMAL m_copper_normal_perturbator; COPPER_NORMAL m_copper_normal_perturbator;
CPLATEDCOPPERNORMAL m_platedcopper_normal_perturbator; PLATED_COPPER_NORMAL m_platedcopper_normal_perturbator;
CSOLDERMASKNORMAL m_solder_mask_normal_perturbator; SOLDER_MASK_NORMAL m_solder_mask_normal_perturbator;
CPLASTICNORMAL m_plastic_normal_perturbator; PLASTIC_NORMAL m_plastic_normal_perturbator;
CPLASTICSHINENORMAL m_plastic_shine_normal_perturbator; PLASTIC_SHINE_NORMAL m_plastic_shine_normal_perturbator;
CMETALBRUSHEDNORMAL m_brushed_metal_normal_perturbator; BRUSHED_METAL_NORMAL m_brushed_metal_normal_perturbator;
CSILKSCREENNORMAL m_silkscreen_normal_perturbator; SILK_SCREEN_NORMAL m_silkscreen_normal_perturbator;
bool m_isPreview; bool m_isPreview;
@ -176,27 +160,27 @@ private:
/// Save the number of blocks progress of the render /// Save the number of blocks progress of the render
size_t m_nrBlocksRenderProgress; size_t m_nrBlocksRenderProgress;
CPOSTSHADER_SSAO m_postshader_ssao; POST_SHADER_SSAO m_postshader_ssao;
CLIGHTCONTAINER m_lights; LIGHT_SOURCES m_lights;
CDIRECTIONALLIGHT *m_camera_light; DIRECTIONAL_LIGHT* m_camera_light;
bool m_opengl_support_vertex_buffer_object; bool m_opengl_support_vertex_buffer_object;
GLuint m_pboId; GLuint m_pboId;
GLuint m_pboDataSize; GLuint m_pboDataSize;
CCONTAINER m_object_container; CONTAINER_3D m_object_container;
/// This will store the list of created objects special for RT, /// This will store the list of created objects special for RT,
/// that will be clear in the end /// that will be clear in the end
CCONTAINER2D m_containerWithObjectsToDelete; CONTAINER_2D m_containerWithObjectsToDelete;
CCONTAINER2D *m_outlineBoard2dObjects; CONTAINER_2D* m_outlineBoard2dObjects;
CBVHCONTAINER2D *m_antioutlineBoard2dObjects; BVH_CONTAINER_2D* m_antioutlineBoard2dObjects;
CGENERICACCELERATOR *m_accelerator; ACCELERATOR_3D* m_accelerator;
SFVEC3F m_BgColorTop_LinearRGB; SFVEC3F m_BgColorTop_LinearRGB;
SFVEC3F m_BgColorBot_LinearRGB; SFVEC3F m_BgColorBot_LinearRGB;
@ -218,9 +202,9 @@ private:
SFVEC2UI m_realBufferSize; SFVEC2UI m_realBufferSize;
SFVEC2UI m_fastPreviewModeSize; SFVEC2UI m_fastPreviewModeSize;
HITINFO_PACKET *m_firstHitinfo; HITINFO_PACKET* m_firstHitinfo;
SFVEC3F *m_shaderBuffer; SFVEC3F* m_shaderBuffer;
// Display Offset // Display Offset
unsigned int m_xoffset; unsigned int m_xoffset;
@ -237,9 +221,9 @@ private:
#define USE_SRGB_SPACE #define USE_SRGB_SPACE
#ifdef USE_SRGB_SPACE #ifdef USE_SRGB_SPACE
extern SFVEC3F ConvertSRGBToLinear( const SFVEC3F &aSRGBcolor ); extern SFVEC3F ConvertSRGBToLinear( const SFVEC3F& aSRGBcolor );
#else #else
#define ConvertSRGBToLinear(v) (v) #define ConvertSRGBToLinear( v ) ( v )
#endif #endif
#endif // C3D_RENDER_RAYTRACING_H #endif // RENDER_3D_RAYTRACE_H

View File

@ -39,10 +39,8 @@
#endif #endif
void CFRUSTUM::GenerateFrustum( const RAY &topLeft, void FRUSTUM::GenerateFrustum( const RAY& topLeft, const RAY& topRight, const RAY& bottomLeft,
const RAY &topRight, const RAY& bottomRight )
const RAY &bottomLeft,
const RAY &bottomRight )
{ {
m_point[0] = topLeft.m_Origin; m_point[0] = topLeft.m_Origin;
m_point[1] = topRight.m_Origin; m_point[1] = topRight.m_Origin;
@ -62,7 +60,7 @@ void CFRUSTUM::GenerateFrustum( const RAY &topLeft,
// by Nathan Slobody and Adam Wright // by Nathan Slobody and Adam Wright
// The frustum test is not exllude all the boxes, // The frustum test is not exllude all the boxes,
// when a box is behind and if it is intersecting the planes it will not be discardly but should. // when a box is behind and if it is intersecting the planes it will not be discardly but should.
bool CFRUSTUM::Intersect( const CBBOX &aBBox ) const bool FRUSTUM::Intersect( const BBOX_3D& aBBox ) const
{ {
const SFVEC3F box[8] = { aBBox.Min(), const SFVEC3F box[8] = { aBBox.Min(),
aBBox.Max(), aBBox.Max(),
@ -79,8 +77,8 @@ bool CFRUSTUM::Intersect( const CBBOX &aBBox ) const
for( unsigned int i = 0; i < 4; ++i ) for( unsigned int i = 0; i < 4; ++i )
{ {
const SFVEC3F &pointPlane = m_point[i]; const SFVEC3F& pointPlane = m_point[i];
const SFVEC3F &normalPlane = m_normals[i]; const SFVEC3F& normalPlane = m_normals[i];
for( unsigned int j = 0; j < 8; ++j ) for( unsigned int j = 0; j < 8; ++j )
{ {

View File

@ -27,8 +27,8 @@
* @brief implements a frustum that is used to test ray pack tests * @brief implements a frustum that is used to test ray pack tests
*/ */
#ifndef _CFRUSTUM_H_ #ifndef _FRUSTUM_H_
#define _CFRUSTUM_H_ #define _FRUSTUM_H_
#include "shapes3D/cbbox.h" #include "shapes3D/cbbox.h"
#include "ray.h" #include "ray.h"
@ -38,28 +38,19 @@
#if 0 #if 0
#error not implemented #error not implemented
#else #else
struct CFRUSTUM struct FRUSTUM
{ {
public: public:
/** void GenerateFrustum( const RAY& topLeft, const RAY& topRight, const RAY& bottomLeft,
* @brief GenerateFrustum const RAY& bottomRight );
* @param topLeft
* @param topRight
* @param bottomLeft
* @param bottomRight
*/
void GenerateFrustum( const RAY &topLeft,
const RAY &topRight,
const RAY &bottomLeft,
const RAY &bottomRight );
/** /**
* @brief Intersect - Intersects a bbox with this frustum * Intersect \a aBBox with this frustum.
* @param aBBox: a bbox to test *
* @return true if the bbox intersects this frustum * @param aBBox is a bounding box to test.
* @return true if the bounding box intersects this frustum.
*/ */
bool Intersect( const CBBOX &aBBox ) const; bool Intersect( const BBOX_3D& aBBox ) const;
private: private:
SFVEC3F m_normals[4]; SFVEC3F m_normals[4];
@ -68,4 +59,4 @@ private:
#endif #endif
#endif // _CFRUSTUM_H_ #endif // _FRUSTUM_H_

View File

@ -27,8 +27,8 @@
* @brief declare and implement light types classes * @brief declare and implement light types classes
*/ */
#ifndef _CLIGHT_H_ #ifndef _LIGHT_H_
#define _CLIGHT_H_ #define _LIGHT_H_
#include "ray.h" #include "ray.h"
#include "hitinfo.h" #include "hitinfo.h"
@ -37,12 +37,12 @@
/** /**
* A base light class to derive to implement other light classes. * A base light class to derive to implement other light classes.
*/ */
class CLIGHT class LIGHT
{ {
public: public:
CLIGHT() { m_castShadow = true; } LIGHT() { m_castShadow = true; }
virtual ~CLIGHT() {} virtual ~LIGHT() {}
/** /**
* Get parameters from this light. * Get parameters from this light.
@ -53,10 +53,8 @@ public:
* @param aOutLightColor the color of this light * @param aOutLightColor the color of this light
* @param aOutDistance the distance from the point to the light * @param aOutDistance the distance from the point to the light
*/ */
virtual void GetLightParameters( const SFVEC3F &aHitPoint, virtual void GetLightParameters( const SFVEC3F& aHitPoint, SFVEC3F& aOutVectorToLight,
SFVEC3F &aOutVectorToLight, SFVEC3F& aOutLightColor, float& aOutDistance ) const = 0;
SFVEC3F &aOutLightColor,
float &aOutDistance ) const = 0;
void SetCastShadows( bool aCastShadow ) { m_castShadow = aCastShadow; } void SetCastShadows( bool aCastShadow ) { m_castShadow = aCastShadow; }
bool GetCastShadows() const { return m_castShadow; } bool GetCastShadows() const { return m_castShadow; }
@ -67,12 +65,12 @@ protected:
/** /**
* Point light based on http://ogldev.atspace.co.uk/www/tutorial20/tutorial20.html. * Point light source based on http://ogldev.atspace.co.uk/www/tutorial20/tutorial20.html.
*/ */
class CPOINTLIGHT : public CLIGHT class POINT_LIGHT : public LIGHT
{ {
public: public:
CPOINTLIGHT( const SFVEC3F &aPos, const SFVEC3F &aColor ) POINT_LIGHT( const SFVEC3F& aPos, const SFVEC3F& aColor )
{ {
m_position = aPos; m_position = aPos;
m_color = aColor; m_color = aColor;
@ -82,11 +80,9 @@ public:
m_castShadow = true; m_castShadow = true;
} }
// Imported functions from CLIGHT // Imported functions from LIGHT
void GetLightParameters( const SFVEC3F &aHitPoint, void GetLightParameters( const SFVEC3F& aHitPoint, SFVEC3F& aOutVectorToLight,
SFVEC3F &aOutVectorToLight, SFVEC3F& aOutLightColor, float& aOutDistance ) const override
SFVEC3F &aOutLightColor,
float &aOutDistance ) const override
{ {
const SFVEC3F vectorLight = m_position - aHitPoint; const SFVEC3F vectorLight = m_position - aHitPoint;
@ -114,12 +110,12 @@ private:
/** /**
* A light based only on a direction vector. * A light source based only on a directional vector.
*/ */
class CDIRECTIONALLIGHT : public CLIGHT class DIRECTIONAL_LIGHT : public LIGHT
{ {
public: public:
CDIRECTIONALLIGHT( const SFVEC3F &aDir, const SFVEC3F &aColor ) DIRECTIONAL_LIGHT( const SFVEC3F& aDir, const SFVEC3F& aColor )
{ {
// Invert light direction and make sure it is normalized // Invert light direction and make sure it is normalized
m_inv_direction = glm::normalize( -aDir ); m_inv_direction = glm::normalize( -aDir );
@ -128,16 +124,15 @@ public:
} }
/** /**
* @brief SetDirection Set directional light orientation * Set directional light orientation.
* @param aDir: vector from the light *
* @param aDir is the vector defining the direction of the light source.
*/ */
void SetDirection( const SFVEC3F &aDir ) { m_inv_direction = -aDir; } void SetDirection( const SFVEC3F& aDir ) { m_inv_direction = -aDir; }
// Imported functions from CLIGHT // Imported functions from LIGHT
void GetLightParameters( const SFVEC3F &aHitPoint, void GetLightParameters( const SFVEC3F& aHitPoint, SFVEC3F& aOutVectorToLight,
SFVEC3F &aOutVectorToLight, SFVEC3F& aOutLightColor, float& aOutDistance ) const override
SFVEC3F &aOutLightColor,
float &aOutDistance ) const override
{ {
(void)aHitPoint; // unused (void)aHitPoint; // unused
@ -152,34 +147,32 @@ private:
}; };
typedef std::list< CLIGHT * > LIST_LIGHT; typedef std::list<LIGHT*> LIST_LIGHT;
/** /**
* A light container. It will add lights and remove it in the end. * A container for light sources.
* *
* @todo Do we really need this object? Wouldn't it be cleaner to just use std::list directly? * @todo Do we really need this object? Wouldn't it be cleaner to just use std::list directly?
*/ */
class CLIGHTCONTAINER class LIGHT_SOURCES
{ {
public: public:
CLIGHTCONTAINER() {} LIGHT_SOURCES() {}
~CLIGHTCONTAINER() { Clear(); } ~LIGHT_SOURCES() { Clear(); }
/** /**
* @brief Clear - Remove all lights from the container * Remove all lights from the container.
*/ */
void Clear() void Clear()
{ {
if( !m_lights.empty() ) if( !m_lights.empty() )
{ {
for( LIST_LIGHT::iterator ii = m_lights.begin(); for( LIST_LIGHT::iterator ii = m_lights.begin(); ii != m_lights.end(); ++ii )
ii != m_lights.end();
++ii )
{ {
delete *ii; delete *ii;
*ii = NULL; *ii = nullptr;
} }
m_lights.clear(); m_lights.clear();
@ -187,23 +180,23 @@ public:
} }
/** /**
* @brief Add - Add a light to the container * Add a light source to the container.
* @param aLight
*/ */
void Add( CLIGHT *aLight ) void Add( LIGHT* aLight )
{ {
if( aLight ) if( aLight )
m_lights.push_back( aLight ); m_lights.push_back( aLight );
} }
/** /**
* @brief GetList - get light list of this container * Get light list of this container.
*
* @return a list of lights * @return a list of lights
*/ */
const LIST_LIGHT &GetList() const { return m_lights; } const LIST_LIGHT& GetList() const { return m_lights; }
private: private:
LIST_LIGHT m_lights; ///< list of lights LIST_LIGHT m_lights; ///< list of lights
}; };
#endif // _CLIGHT_H_ #endif // _LIGHT_H_

View File

@ -31,10 +31,10 @@
#include <3d_math.h> #include <3d_math.h>
#include <wx/debug.h> #include <wx/debug.h>
int CMATERIAL::m_default_nrsamples_refractions = 4; int MATERIAL::m_default_nrsamples_refractions = 4;
int CMATERIAL::m_default_nrsamples_reflections = 3; int MATERIAL::m_default_nrsamples_reflections = 3;
int CMATERIAL::m_default_refractions_recursive_levels = 2; int MATERIAL::m_default_refractions_recursive_levels = 2;
int CMATERIAL::m_default_reflections_recursive_levels = 3; int MATERIAL::m_default_reflections_recursive_levels = 3;
// This may be a good value if based on nr of lights // This may be a good value if based on nr of lights
// that contribute to the illumination of that point // that contribute to the illumination of that point
@ -42,7 +42,7 @@ int CMATERIAL::m_default_reflections_recursive_levels = 3;
#define SPECULAR_FACTOR 1.0f #define SPECULAR_FACTOR 1.0f
CMATERIAL::CMATERIAL() MATERIAL::MATERIAL()
{ {
m_ambientColor = SFVEC3F( 0.2f, 0.2f, 0.2f ); m_ambientColor = SFVEC3F( 0.2f, 0.2f, 0.2f );
m_emissiveColor = SFVEC3F( 0.0f, 0.0f, 0.0f ); m_emissiveColor = SFVEC3F( 0.0f, 0.0f, 0.0f );
@ -57,16 +57,12 @@ CMATERIAL::CMATERIAL()
m_refractions_recursive_levels = m_default_refractions_recursive_levels; m_refractions_recursive_levels = m_default_refractions_recursive_levels;
m_reflections_recursive_levels = m_default_reflections_recursive_levels; m_reflections_recursive_levels = m_default_reflections_recursive_levels;
m_normal_perturbator = NULL; m_normal_perturbator = nullptr;
} }
CMATERIAL::CMATERIAL( const SFVEC3F &aAmbient, MATERIAL::MATERIAL( const SFVEC3F& aAmbient, const SFVEC3F& aEmissive, const SFVEC3F& aSpecular,
const SFVEC3F &aEmissive, float aShinness, float aTransparency, float aReflection )
const SFVEC3F &aSpecular,
float aShinness,
float aTransparency,
float aReflection )
{ {
wxASSERT( aReflection >= 0.0f ); wxASSERT( aReflection >= 0.0f );
wxASSERT( aReflection <= 1.0f ); wxASSERT( aReflection <= 1.0f );
@ -91,13 +87,11 @@ CMATERIAL::CMATERIAL( const SFVEC3F &aAmbient,
m_refractions_recursive_levels = m_default_refractions_recursive_levels; m_refractions_recursive_levels = m_default_refractions_recursive_levels;
m_reflections_recursive_levels = m_default_reflections_recursive_levels; m_reflections_recursive_levels = m_default_reflections_recursive_levels;
m_normal_perturbator = NULL; m_normal_perturbator = nullptr;
} }
void CMATERIAL::PerturbeNormal( SFVEC3F &aNormal, void MATERIAL::PerturbeNormal( SFVEC3F& aNormal, const RAY& aRay, const HITINFO& aHitInfo ) const
const RAY &aRay,
const HITINFO &aHitInfo ) const
{ {
if( m_normal_perturbator ) if( m_normal_perturbator )
{ {
@ -108,22 +102,15 @@ void CMATERIAL::PerturbeNormal( SFVEC3F &aNormal,
// https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model // https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model
SFVEC3F CBLINN_PHONG_MATERIAL::Shade( const RAY &aRay, SFVEC3F BLINN_PHONG_MATERIAL::Shade( const RAY& aRay, const HITINFO& aHitInfo, float NdotL,
const HITINFO &aHitInfo, const SFVEC3F& aDiffuseObjColor, const SFVEC3F& aDirToLight,
float NdotL, const SFVEC3F& aLightColor,
const SFVEC3F &aDiffuseObjColor,
const SFVEC3F &aDirToLight,
const SFVEC3F &aLightColor,
float aShadowAttenuationFactor ) const float aShadowAttenuationFactor ) const
{ {
wxASSERT( NdotL >= FLT_EPSILON ); wxASSERT( NdotL >= FLT_EPSILON );
// This is a hack to get some kind of fake ambient illumination // This is a hack to get some kind of fake ambient illumination
// There is no logic behind this, just pure artistic experimentation // There is no logic behind this, just pure artistic experimentation
//const float ambientFactor = glm::max( ( (1.0f - NdotL) /** (1.0f - NdotL)*/ ) *
// ( AMBIENT_FACTOR + AMBIENT_FACTOR ),
// AMBIENT_FACTOR );
if( aShadowAttenuationFactor > FLT_EPSILON ) if( aShadowAttenuationFactor > FLT_EPSILON )
{ {
// Calculate the diffuse light factoring in light color, // Calculate the diffuse light factoring in light color,
@ -135,22 +122,18 @@ SFVEC3F CBLINN_PHONG_MATERIAL::Shade( const RAY &aRay,
//Intensity of the specular light //Intensity of the specular light
const float NdotH = glm::dot( H, aHitInfo.m_HitNormal ); const float NdotH = glm::dot( H, aHitInfo.m_HitNormal );
const float intensitySpecular = glm::pow( glm::max( NdotH, 0.0f ), const float intensitySpecular = glm::pow( glm::max( NdotH, 0.0f ), m_shinness );
m_shinness );
return m_ambientColor + return m_ambientColor +
aShadowAttenuationFactor * ( diffuse * aDiffuseObjColor + aShadowAttenuationFactor * ( diffuse * aDiffuseObjColor + SPECULAR_FACTOR *
SPECULAR_FACTOR * aLightColor * intensitySpecular * m_specularColor );
aLightColor *
intensitySpecular *
m_specularColor );
} }
return m_ambientColor; return m_ambientColor;
} }
CPROCEDURALGENERATOR::CPROCEDURALGENERATOR() PROCEDURAL_GENERATOR::PROCEDURAL_GENERATOR()
{ {
} }
@ -158,13 +141,13 @@ CPROCEDURALGENERATOR::CPROCEDURALGENERATOR()
static PerlinNoise s_perlinNoise = PerlinNoise( 0 ); static PerlinNoise s_perlinNoise = PerlinNoise( 0 );
CBOARDNORMAL::CBOARDNORMAL( float aScale ) : CPROCEDURALGENERATOR() BOARD_NORMAL::BOARD_NORMAL( float aScale ) : PROCEDURAL_GENERATOR()
{ {
m_scale = (2.0f * glm::pi<float>()) / aScale; m_scale = ( 2.0f * glm::pi<float>() ) / aScale;
} }
SFVEC3F CBOARDNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const SFVEC3F BOARD_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
{ {
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale; const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
@ -183,14 +166,14 @@ SFVEC3F CBOARDNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const
} }
CCOPPERNORMAL::CCOPPERNORMAL( float aScale, const CPROCEDURALGENERATOR *aBoardNormalGenerator ) COPPER_NORMAL::COPPER_NORMAL( float aScale, const PROCEDURAL_GENERATOR* aBoardNormalGenerator )
{ {
m_board_normal_generator = aBoardNormalGenerator; m_board_normal_generator = aBoardNormalGenerator;
m_scale = 1.0f / aScale; m_scale = 1.0f / aScale;
} }
SFVEC3F CCOPPERNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const SFVEC3F COPPER_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
{ {
if( m_board_normal_generator ) if( m_board_normal_generator )
{ {
@ -200,9 +183,7 @@ SFVEC3F CCOPPERNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) cons
const float noise = const float noise =
( s_perlinNoise.noise( hitPos.x + boardNormal.y + aRay.m_Origin.x * 0.2f, ( s_perlinNoise.noise( hitPos.x + boardNormal.y + aRay.m_Origin.x * 0.2f,
hitPos.y + boardNormal.x ) hitPos.y + boardNormal.x ) - 0.5f ) * 2.0f;
- 0.5f )
* 2.0f;
float scratchPattern = float scratchPattern =
( s_perlinNoise.noise( noise + hitPos.x / 100.0f, hitPos.y * 100.0f ) - 0.5f ); ( s_perlinNoise.noise( noise + hitPos.x / 100.0f, hitPos.y * 100.0f ) - 0.5f );
@ -219,13 +200,13 @@ SFVEC3F CCOPPERNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) cons
} }
CSOLDERMASKNORMAL::CSOLDERMASKNORMAL( const CPROCEDURALGENERATOR *aCopperNormalGenerator ) SOLDER_MASK_NORMAL::SOLDER_MASK_NORMAL( const PROCEDURAL_GENERATOR* aCopperNormalGenerator )
{ {
m_copper_normal_generator = aCopperNormalGenerator; m_copper_normal_generator = aCopperNormalGenerator;
} }
SFVEC3F CSOLDERMASKNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const SFVEC3F SOLDER_MASK_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
{ {
if( m_copper_normal_generator ) if( m_copper_normal_generator )
{ {
@ -235,12 +216,12 @@ SFVEC3F CSOLDERMASKNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo )
} }
else else
{ {
return SFVEC3F(0.0f); return SFVEC3F( 0.0f );
} }
} }
SFVEC3F CPLATEDCOPPERNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const SFVEC3F PLATED_COPPER_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
{ {
SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale; SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
@ -251,26 +232,23 @@ SFVEC3F CPLATEDCOPPERNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo
} }
CPLASTICNORMAL::CPLASTICNORMAL( float aScale ) PLASTIC_NORMAL::PLASTIC_NORMAL( float aScale )
{ {
m_scale = 1.0f / aScale; m_scale = 1.0f / aScale;
} }
SFVEC3F CPLASTICNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const SFVEC3F PLASTIC_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
{ {
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale; const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
const float noise1 = s_perlinNoise.noise( hitPos.x * 1.0f, const float noise1 = s_perlinNoise.noise( hitPos.x * 1.0f, hitPos.y * 1.1f,
hitPos.y * 1.1f,
hitPos.z * 1.2f ) - 0.5f; hitPos.z * 1.2f ) - 0.5f;
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.3f, const float noise2 = s_perlinNoise.noise( hitPos.x * 1.3f, hitPos.y * 1.0f,
hitPos.y * 1.0f,
hitPos.z * 1.5f ) - 0.5f; hitPos.z * 1.5f ) - 0.5f;
const float noise3 = s_perlinNoise.noise( hitPos.x * 1.0f, const float noise3 = s_perlinNoise.noise( hitPos.x * 1.0f, hitPos.y * 1.0f,
hitPos.y * 1.0f,
hitPos.z * 1.8f ) - 0.5f; hitPos.z * 1.8f ) - 0.5f;
const float distanceReduction = 1.0f / ( aHitInfo.m_tHit + 0.5f ); const float distanceReduction = 1.0f / ( aHitInfo.m_tHit + 0.5f );
@ -279,26 +257,23 @@ SFVEC3F CPLASTICNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) con
} }
CPLASTICSHINENORMAL::CPLASTICSHINENORMAL( float aScale ) PLASTIC_SHINE_NORMAL::PLASTIC_SHINE_NORMAL( float aScale )
{ {
m_scale = 1.0f / aScale; m_scale = 1.0f / aScale;
} }
SFVEC3F CPLASTICSHINENORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const SFVEC3F PLASTIC_SHINE_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
{ {
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale; const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
const float noise1 = s_perlinNoise.noise( hitPos.x * 0.01f, const float noise1 = s_perlinNoise.noise( hitPos.x * 0.01f, hitPos.y * 0.01f,
hitPos.y * 0.01f,
hitPos.z * 0.01f ) - 0.5f; hitPos.z * 0.01f ) - 0.5f;
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.0f, const float noise2 = s_perlinNoise.noise( hitPos.x * 1.0f, hitPos.y * 1.0f,
hitPos.y * 1.0f,
hitPos.z * 1.6f ) - 0.5f; hitPos.z * 1.6f ) - 0.5f;
float noise3 = s_perlinNoise.noise( hitPos.x * 1.5f, float noise3 = s_perlinNoise.noise( hitPos.x * 1.5f, hitPos.y * 1.5f,
hitPos.y * 1.5f,
hitPos.z * 1.0f ) - 0.5f; hitPos.z * 1.0f ) - 0.5f;
noise3 = noise3 * noise3 * noise3; noise3 = noise3 * noise3 * noise3;
@ -306,51 +281,42 @@ SFVEC3F CPLASTICSHINENORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo
} }
CMETALBRUSHEDNORMAL::CMETALBRUSHEDNORMAL( float aScale ) BRUSHED_METAL_NORMAL::BRUSHED_METAL_NORMAL( float aScale )
{ {
m_scale = 1.0f / aScale; m_scale = 1.0f / aScale;
} }
SFVEC3F CMETALBRUSHEDNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const SFVEC3F BRUSHED_METAL_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
{ {
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale; const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
const float noise1 = s_perlinNoise.noise( hitPos.x * 1.0f, const float noise1 = s_perlinNoise.noise( hitPos.x * 1.0f, hitPos.y * 1.1f,
hitPos.y * 1.1f,
hitPos.z * 1.2f ) - 0.5f; hitPos.z * 1.2f ) - 0.5f;
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.3f, const float noise2 = s_perlinNoise.noise( hitPos.x * 1.3f, hitPos.y * 1.4f,
hitPos.y * 1.4f,
hitPos.z * 1.5f ) - 0.5f; hitPos.z * 1.5f ) - 0.5f;
const float noise3 = s_perlinNoise.noise( hitPos.x * 0.1f, const float noise3 = s_perlinNoise.noise( hitPos.x * 0.1f, hitPos.y * 0.1f,
hitPos.y * 0.1f,
hitPos.z * 1.0f ) - 0.5f; hitPos.z * 1.0f ) - 0.5f;
return SFVEC3F( noise1 * 0.15f + noise3 * 0.35f, return SFVEC3F( noise1 * 0.15f + noise3 * 0.35f, noise2 * 0.25f, noise1 * noise2 * noise3 );
noise2 * 0.25f,
noise1 * noise2 * noise3 );
} }
CSILKSCREENNORMAL::CSILKSCREENNORMAL( float aScale ) SILK_SCREEN_NORMAL::SILK_SCREEN_NORMAL( float aScale )
{ {
m_scale = 1.0f / aScale; m_scale = 1.0f / aScale;
} }
SFVEC3F CSILKSCREENNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const SFVEC3F SILK_SCREEN_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
{ {
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale; const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
const float noise1 = s_perlinNoise.noise( hitPos.x * 2.7f, const float noise1 = s_perlinNoise.noise( hitPos.x * 2.7f, hitPos.y * 2.6f, hitPos.z );
hitPos.y * 2.6f,
hitPos.z );
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.1f, const float noise2 = s_perlinNoise.noise( hitPos.x * 1.1f, hitPos.y * 1.2f, hitPos.z );
hitPos.y * 1.2f,
hitPos.z );
SFVEC3F t = SFVEC3F t =
glm::abs( ( 1.8f / ( SFVEC3F( noise1, noise2, hitPos.z ) + 0.4f ) ) - 1.5f ) - 0.25f; glm::abs( ( 1.8f / ( SFVEC3F( noise1, noise2, hitPos.z ) + 0.4f ) ) - 1.5f ) - 0.25f;

View File

@ -27,45 +27,47 @@
* @brief * @brief
*/ */
#ifndef _CMATERIAL_H_ #ifndef _MATERIAL_H_
#define _CMATERIAL_H_ #define _MATERIAL_H_
#include "ray.h" #include "ray.h"
#include "hitinfo.h" #include "hitinfo.h"
#include "PerlinNoise.h" #include "PerlinNoise.h"
/// A base class that can be used to derive a procedural generator implementation /**
class CPROCEDURALGENERATOR * A base class that can be used to derive procedurally generated materials.
*/
class PROCEDURAL_GENERATOR
{ {
public: public:
CPROCEDURALGENERATOR(); PROCEDURAL_GENERATOR();
virtual ~CPROCEDURALGENERATOR() virtual ~PROCEDURAL_GENERATOR()
{ {
} }
/** /**
* Generates a 3D vector based on the ray and* hit information depending on the implementation. * Generate a 3D vector based on the ray and hit information depending on the implementation.
* *
* @param aRay the camera ray that hits the object * @param aRay the camera ray that hits the object
* @param aHitInfo the hit information * @param aHitInfo the hit information
* @return the result of the procedural * @return the result of the procedural
*/ */
virtual SFVEC3F Generate( const RAY &aRay, const HITINFO &aHitInfo ) const = 0; virtual SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const = 0;
}; };
class CBOARDNORMAL : public CPROCEDURALGENERATOR class BOARD_NORMAL : public PROCEDURAL_GENERATOR
{ {
public: public:
CBOARDNORMAL() : CPROCEDURALGENERATOR() { m_scale = 1.0f; } BOARD_NORMAL() : PROCEDURAL_GENERATOR() { m_scale = 1.0f; }
CBOARDNORMAL( float aScale ); BOARD_NORMAL( float aScale );
virtual ~CBOARDNORMAL() virtual ~BOARD_NORMAL()
{ {
} }
SFVEC3F Generate( const RAY &aRay, const HITINFO &aHitInfo ) const override; SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
private: private:
float m_scale; float m_scale;
@ -75,47 +77,48 @@ private:
/** /**
* Procedural generation of the copper normals. * Procedural generation of the copper normals.
*/ */
class CCOPPERNORMAL : public CPROCEDURALGENERATOR class COPPER_NORMAL : public PROCEDURAL_GENERATOR
{ {
public: public:
CCOPPERNORMAL() : CPROCEDURALGENERATOR() COPPER_NORMAL() : PROCEDURAL_GENERATOR()
{ {
m_board_normal_generator = NULL; m_board_normal_generator = nullptr;
m_scale = 1.0f; m_scale = 1.0f;
} }
CCOPPERNORMAL( float aScale, const CPROCEDURALGENERATOR *aBoardNormalGenerator ); COPPER_NORMAL( float aScale, const PROCEDURAL_GENERATOR* aBoardNormalGenerator );
virtual ~CCOPPERNORMAL() virtual ~COPPER_NORMAL()
{ {
} }
SFVEC3F Generate( const RAY &aRay, const HITINFO &aHitInfo ) const override; SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
private: private:
const CPROCEDURALGENERATOR *m_board_normal_generator; const PROCEDURAL_GENERATOR* m_board_normal_generator;
float m_scale; float m_scale;
}; };
class CPLATEDCOPPERNORMAL : public CPROCEDURALGENERATOR class PLATED_COPPER_NORMAL : public PROCEDURAL_GENERATOR
{ {
public: public:
CPLATEDCOPPERNORMAL() : CPROCEDURALGENERATOR() PLATED_COPPER_NORMAL() : PROCEDURAL_GENERATOR()
{ {
m_scale = 1.0f; m_scale = 1.0f;
} }
CPLATEDCOPPERNORMAL( float aScale ) PLATED_COPPER_NORMAL( float aScale )
{ {
m_scale = 1.0f / aScale; m_scale = 1.0f / aScale;
} }
virtual ~CPLATEDCOPPERNORMAL() virtual ~PLATED_COPPER_NORMAL()
{ {
} }
SFVEC3F Generate( const RAY &aRay, const HITINFO &aHitInfo ) const override; SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
private: private:
float m_scale; float m_scale;
}; };
@ -124,41 +127,41 @@ private:
/** /**
* Procedural generation of the solder mask. * Procedural generation of the solder mask.
*/ */
class CSOLDERMASKNORMAL : public CPROCEDURALGENERATOR class SOLDER_MASK_NORMAL : public PROCEDURAL_GENERATOR
{ {
public: public:
CSOLDERMASKNORMAL() : CPROCEDURALGENERATOR() { m_copper_normal_generator = NULL; } SOLDER_MASK_NORMAL() : PROCEDURAL_GENERATOR() { m_copper_normal_generator = nullptr; }
CSOLDERMASKNORMAL( const CPROCEDURALGENERATOR *aCopperNormalGenerator ); SOLDER_MASK_NORMAL( const PROCEDURAL_GENERATOR* aCopperNormalGenerator );
virtual ~CSOLDERMASKNORMAL() virtual ~SOLDER_MASK_NORMAL()
{ {
} }
SFVEC3F Generate( const RAY &aRay, const HITINFO &aHitInfo ) const override; SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
private: private:
const CPROCEDURALGENERATOR *m_copper_normal_generator; const PROCEDURAL_GENERATOR* m_copper_normal_generator;
}; };
/** /**
* Procedural generation of the plastic normals. * Procedural generation of the plastic normals.
*/ */
class CPLASTICNORMAL : public CPROCEDURALGENERATOR class PLASTIC_NORMAL : public PROCEDURAL_GENERATOR
{ {
public: public:
CPLASTICNORMAL() : CPROCEDURALGENERATOR() PLASTIC_NORMAL() : PROCEDURAL_GENERATOR()
{ {
m_scale = 1.0f; m_scale = 1.0f;
} }
CPLASTICNORMAL( float aScale ); PLASTIC_NORMAL( float aScale );
virtual ~CPLASTICNORMAL() virtual ~PLASTIC_NORMAL()
{ {
} }
SFVEC3F Generate( const RAY &aRay, const HITINFO &aHitInfo ) const override; SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
private: private:
float m_scale; float m_scale;
@ -168,66 +171,67 @@ private:
/** /**
* Procedural generation of the shiny plastic normals. * Procedural generation of the shiny plastic normals.
*/ */
class CPLASTICSHINENORMAL : public CPROCEDURALGENERATOR class PLASTIC_SHINE_NORMAL : public PROCEDURAL_GENERATOR
{ {
public: public:
CPLASTICSHINENORMAL() : CPROCEDURALGENERATOR() PLASTIC_SHINE_NORMAL() : PROCEDURAL_GENERATOR()
{ {
m_scale = 1.0f; m_scale = 1.0f;
} }
CPLASTICSHINENORMAL( float aScale ); PLASTIC_SHINE_NORMAL( float aScale );
virtual ~CPLASTICSHINENORMAL() virtual ~PLASTIC_SHINE_NORMAL()
{ {
} }
// Imported from CPROCEDURALGENERATOR // Imported from PROCEDURAL_GENERATOR
SFVEC3F Generate( const RAY &aRay, SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
const HITINFO &aHitInfo ) const override;
private: private:
float m_scale; float m_scale;
}; };
/** /**
* Procedural generation of the shiny brushed metal. * Procedural generation of the shiny brushed metal.
*/ */
class CMETALBRUSHEDNORMAL : public CPROCEDURALGENERATOR class BRUSHED_METAL_NORMAL : public PROCEDURAL_GENERATOR
{ {
public: public:
CMETALBRUSHEDNORMAL() : CPROCEDURALGENERATOR() BRUSHED_METAL_NORMAL() : PROCEDURAL_GENERATOR()
{ {
m_scale = 1.0f; m_scale = 1.0f;
} }
CMETALBRUSHEDNORMAL( float aScale ); BRUSHED_METAL_NORMAL( float aScale );
virtual ~CMETALBRUSHEDNORMAL() virtual ~BRUSHED_METAL_NORMAL()
{ {
} }
SFVEC3F Generate( const RAY &aRay, const HITINFO &aHitInfo ) const override; SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
private: private:
float m_scale; float m_scale;
}; };
class CSILKSCREENNORMAL : public CPROCEDURALGENERATOR class SILK_SCREEN_NORMAL : public PROCEDURAL_GENERATOR
{ {
public: public:
CSILKSCREENNORMAL() : CPROCEDURALGENERATOR() SILK_SCREEN_NORMAL() : PROCEDURAL_GENERATOR()
{ {
m_scale = 1.0f; m_scale = 1.0f;
} }
CSILKSCREENNORMAL( float aScale ); SILK_SCREEN_NORMAL( float aScale );
virtual ~CSILKSCREENNORMAL() virtual ~SILK_SCREEN_NORMAL()
{ {
} }
SFVEC3F Generate( const RAY &aRay, const HITINFO &aHitInfo ) const override; SFVEC3F Generate( const RAY& aRay, const HITINFO& aHitInfo ) const override;
private: private:
float m_scale; float m_scale;
@ -237,7 +241,7 @@ private:
/** /**
* Base material class that can be used to derive other material implementations. * Base material class that can be used to derive other material implementations.
*/ */
class CMATERIAL class MATERIAL
{ {
public: public:
static void SetDefaultNrRefractionsSamples( unsigned int aNrRefractions ) static void SetDefaultNrRefractionsSamples( unsigned int aNrRefractions )
@ -260,19 +264,15 @@ public:
m_default_reflections_recursive_levels = aReflectionLevel; m_default_reflections_recursive_levels = aReflectionLevel;
} }
CMATERIAL(); MATERIAL();
CMATERIAL( const SFVEC3F &aAmbient, MATERIAL( const SFVEC3F& aAmbient, const SFVEC3F& aEmissive, const SFVEC3F& aSpecular,
const SFVEC3F &aEmissive, float aShinness, float aTransparency, float aReflection );
const SFVEC3F &aSpecular,
float aShinness,
float aTransparency,
float aReflection );
virtual ~CMATERIAL() {} virtual ~MATERIAL() {}
const SFVEC3F &GetAmbientColor() const { return m_ambientColor; } const SFVEC3F& GetAmbientColor() const { return m_ambientColor; }
const SFVEC3F &GetEmissiveColor() const { return m_emissiveColor; } const SFVEC3F& GetEmissiveColor() const { return m_emissiveColor; }
const SFVEC3F &GetSpecularColor() const { return m_specularColor; } const SFVEC3F& GetSpecularColor() const { return m_specularColor; }
float GetShinness() const { return m_shinness; } float GetShinness() const { return m_shinness; }
float GetTransparency() const { return m_transparency; } float GetTransparency() const { return m_transparency; }
@ -325,22 +325,19 @@ public:
* @param aShadowAttenuationFactor 0.0f total in shadow, 1.0f completely not in shadow * @param aShadowAttenuationFactor 0.0f total in shadow, 1.0f completely not in shadow
* @return the resultant color * @return the resultant color
*/ */
virtual SFVEC3F Shade( const RAY &aRay, virtual SFVEC3F Shade( const RAY& aRay, const HITINFO& aHitInfo, float NdotL,
const HITINFO &aHitInfo, const SFVEC3F& aDiffuseObjColor, const SFVEC3F& aDirToLight,
float NdotL, const SFVEC3F& aLightColor,
const SFVEC3F &aDiffuseObjColor,
const SFVEC3F &aDirToLight,
const SFVEC3F &aLightColor,
float aShadowAttenuationFactor ) const = 0; float aShadowAttenuationFactor ) const = 0;
void SetNormalPerturbator( const CPROCEDURALGENERATOR *aPerturbator ) void SetNormalPerturbator( const PROCEDURAL_GENERATOR* aPerturbator )
{ {
m_normal_perturbator = aPerturbator; m_normal_perturbator = aPerturbator;
} }
const CPROCEDURALGENERATOR *GetNormalPerturbator() const { return m_normal_perturbator; } const PROCEDURAL_GENERATOR* GetNormalPerturbator() const { return m_normal_perturbator; }
void PerturbeNormal( SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo ) const; void PerturbeNormal( SFVEC3F& aNormal, const RAY& aRay, const HITINFO& aHitInfo ) const;
protected: protected:
SFVEC3F m_ambientColor; SFVEC3F m_ambientColor;
@ -371,7 +368,7 @@ protected:
///< Number of levels it allows for reflection recursiveness. ///< Number of levels it allows for reflection recursiveness.
unsigned int m_reflections_recursive_levels; unsigned int m_reflections_recursive_levels;
const CPROCEDURALGENERATOR *m_normal_perturbator; const PROCEDURAL_GENERATOR* m_normal_perturbator;
private: private:
static int m_default_nrsamples_refractions; static int m_default_nrsamples_refractions;
@ -383,31 +380,20 @@ private:
/// Blinn Phong based material /// Blinn Phong based material
/// https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model /// https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model
class CBLINN_PHONG_MATERIAL : public CMATERIAL class BLINN_PHONG_MATERIAL : public MATERIAL
{ {
public: public:
CBLINN_PHONG_MATERIAL() : CMATERIAL() {} BLINN_PHONG_MATERIAL() : MATERIAL() {}
CBLINN_PHONG_MATERIAL( const SFVEC3F &aAmbient, BLINN_PHONG_MATERIAL( const SFVEC3F& aAmbient, const SFVEC3F& aEmissive,
const SFVEC3F &aEmissive, const SFVEC3F& aSpecular, float aShinness, float aTransparency,
const SFVEC3F &aSpecular, float aReflection ) :
float aShinness, MATERIAL( aAmbient, aEmissive, aSpecular, aShinness, aTransparency, aReflection ) {}
float aTransparency,
float aReflection ) : CMATERIAL( aAmbient,
aEmissive,
aSpecular,
aShinness,
aTransparency,
aReflection ) {}
// Imported from CMATERIAL // Imported from MATERIAL
SFVEC3F Shade( const RAY &aRay, SFVEC3F Shade( const RAY& aRay, const HITINFO& aHitInfo, float NdotL,
const HITINFO &aHitInfo, const SFVEC3F& aDiffuseObjColor, const SFVEC3F& aDirToLight,
float NdotL, const SFVEC3F& aLightColor, float aShadowAttenuationFactor ) const override;
const SFVEC3F &aDiffuseObjColor,
const SFVEC3F &aDirToLight,
const SFVEC3F &aLightColor,
float aShadowAttenuationFactor ) const override;
}; };
#endif // _CMATERIAL_H_ #endif // _MATERIAL_H_

View File

@ -34,7 +34,7 @@
//#define RAYTRACING_RAY_STATISTICS //#define RAYTRACING_RAY_STATISTICS
class COBJECT; class OBJECT_3D;
/// Stores the hit information of a ray with a point on the surface of a object /// Stores the hit information of a ray with a point on the surface of a object
struct HITINFO struct HITINFO
@ -42,7 +42,7 @@ struct HITINFO
SFVEC3F m_HitNormal; ///< (12) normal at the hit point SFVEC3F m_HitNormal; ///< (12) normal at the hit point
float m_tHit; ///< ( 4) distance float m_tHit; ///< ( 4) distance
const COBJECT *pHitObject; ///< ( 4) Object that was hitted const OBJECT_3D* pHitObject; ///< ( 4) Object that was hitted
SFVEC2F m_UV; ///< ( 8) 2-D texture coordinates SFVEC2F m_UV; ///< ( 8) 2-D texture coordinates
unsigned int m_acc_node_info; ///< ( 4) The acc stores here the node that it hits unsigned int m_acc_node_info; ///< ( 4) The acc stores here the node that it hits

View File

@ -32,7 +32,7 @@
#include <wx/debug.h> #include <wx/debug.h>
static void RAYPACKET_GenerateFrustum( CFRUSTUM *m_Frustum, RAY *m_ray ) static void RAYPACKET_GenerateFrustum( FRUSTUM* m_Frustum, RAY* m_ray )
{ {
m_Frustum->GenerateFrustum( m_Frustum->GenerateFrustum(
m_ray[ 0 * RAYPACKET_DIM + 0 ], m_ray[ 0 * RAYPACKET_DIM + 0 ],
@ -42,7 +42,7 @@ static void RAYPACKET_GenerateFrustum( CFRUSTUM *m_Frustum, RAY *m_ray )
} }
RAYPACKET::RAYPACKET( const CCAMERA &aCamera, const SFVEC2I &aWindowsPosition ) RAYPACKET::RAYPACKET( const CAMERA& aCamera, const SFVEC2I& aWindowsPosition )
{ {
unsigned int i = 0; unsigned int i = 0;
@ -53,8 +53,7 @@ RAYPACKET::RAYPACKET( const CCAMERA &aCamera, const SFVEC2I &aWindowsPosition )
SFVEC3F rayOrigin; SFVEC3F rayOrigin;
SFVEC3F rayDir; SFVEC3F rayDir;
aCamera.MakeRay( SFVEC2I( aWindowsPosition.x + x, aCamera.MakeRay( SFVEC2I( aWindowsPosition.x + x, aWindowsPosition.y + y ),
aWindowsPosition.y + y ),
rayOrigin, rayDir ); rayOrigin, rayDir );
m_ray[i].Init( rayOrigin, rayDir ); m_ray[i].Init( rayOrigin, rayDir );
@ -69,8 +68,7 @@ RAYPACKET::RAYPACKET( const CCAMERA &aCamera, const SFVEC2I &aWindowsPosition )
} }
RAYPACKET::RAYPACKET( const CCAMERA &aCamera, RAYPACKET::RAYPACKET( const CAMERA& aCamera, const SFVEC2F& aWindowsPosition )
const SFVEC2F &aWindowsPosition )
{ {
RAYPACKET_InitRays( aCamera, aWindowsPosition, m_ray ); RAYPACKET_InitRays( aCamera, aWindowsPosition, m_ray );
@ -78,9 +76,8 @@ RAYPACKET::RAYPACKET( const CCAMERA &aCamera,
} }
RAYPACKET::RAYPACKET( const CCAMERA &aCamera, RAYPACKET::RAYPACKET( const CAMERA& aCamera, const SFVEC2F& aWindowsPosition,
const SFVEC2F &aWindowsPosition, const SFVEC2F& a2DWindowsPosDisplacementFactor )
const SFVEC2F &a2DWindowsPosDisplacementFactor )
{ {
RAYPACKET_InitRays_with2DDisplacement( aCamera, RAYPACKET_InitRays_with2DDisplacement( aCamera,
aWindowsPosition, aWindowsPosition,
@ -91,9 +88,8 @@ RAYPACKET::RAYPACKET( const CCAMERA &aCamera,
} }
RAYPACKET::RAYPACKET( const CCAMERA &aCamera, RAYPACKET::RAYPACKET( const CAMERA& aCamera, const SFVEC2I& aWindowsPosition,
const SFVEC2I &aWindowsPosition, const SFVEC3F& aDirectionDisplacementFactor )
const SFVEC3F &aDirectionDisplacementFactor )
{ {
unsigned int i = 0; unsigned int i = 0;
@ -123,8 +119,7 @@ RAYPACKET::RAYPACKET( const CCAMERA &aCamera,
} }
RAYPACKET::RAYPACKET( const CCAMERA &aCamera, RAYPACKET::RAYPACKET( const CAMERA& aCamera, const SFVEC2I& aWindowsPosition,
const SFVEC2I &aWindowsPosition,
unsigned int aPixelMultiple ) unsigned int aPixelMultiple )
{ {
unsigned int i = 0; unsigned int i = 0;
@ -152,9 +147,7 @@ RAYPACKET::RAYPACKET( const CCAMERA &aCamera,
} }
void RAYPACKET_InitRays( const CCAMERA &aCamera, void RAYPACKET_InitRays( const CAMERA& aCamera, const SFVEC2F& aWindowsPosition, RAY* aRayPck )
const SFVEC2F &aWindowsPosition,
RAY *aRayPck )
{ {
for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y ) for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
{ {
@ -173,10 +166,9 @@ void RAYPACKET_InitRays( const CCAMERA &aCamera,
} }
void RAYPACKET_InitRays_with2DDisplacement( const CCAMERA &aCamera, void RAYPACKET_InitRays_with2DDisplacement( const CAMERA& aCamera, const SFVEC2F& aWindowsPosition,
const SFVEC2F &aWindowsPosition, const SFVEC2F& a2DWindowsPosDisplacementFactor,
const SFVEC2F &a2DWindowsPosDisplacementFactor, RAY* aRayPck )
RAY *aRayPck )
{ {
for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y ) for( unsigned int y = 0, i = 0; y < RAYPACKET_DIM; ++y )
{ {

View File

@ -35,34 +35,33 @@
#include "../ccamera.h" #include "../ccamera.h"
#define RAYPACKET_DIM (1 << 3) #define RAYPACKET_DIM (1 << 3)
#define RAYPACKET_MASK (unsigned int)( (RAYPACKET_DIM - 1)) #define RAYPACKET_MASK (unsigned int) ( ( RAYPACKET_DIM - 1 ) )
#define RAYPACKET_INVMASK (unsigned int)(~(RAYPACKET_DIM - 1)) #define RAYPACKET_INVMASK (unsigned int) ( ~( RAYPACKET_DIM - 1 ) )
#define RAYPACKET_RAYS_PER_PACKET (RAYPACKET_DIM * RAYPACKET_DIM) #define RAYPACKET_RAYS_PER_PACKET ( RAYPACKET_DIM * RAYPACKET_DIM )
struct RAYPACKET struct RAYPACKET
{ {
RAYPACKET( const CCAMERA& aCamera, const SFVEC2I& aWindowsPosition ); RAYPACKET( const CAMERA& aCamera, const SFVEC2I& aWindowsPosition );
RAYPACKET( const CCAMERA& aCamera, const SFVEC2I& aWindowsPosition, RAYPACKET( const CAMERA& aCamera, const SFVEC2I& aWindowsPosition,
const SFVEC3F& aDirectionDisplacementFactor ); const SFVEC3F& aDirectionDisplacementFactor );
RAYPACKET( const CCAMERA& aCamera, const SFVEC2I& aWindowsPosition, RAYPACKET( const CAMERA& aCamera, const SFVEC2I& aWindowsPosition,
unsigned int aPixelMultiple ); unsigned int aPixelMultiple );
RAYPACKET( const CCAMERA& aCamera, const SFVEC2F& aWindowsPosition ); RAYPACKET( const CAMERA& aCamera, const SFVEC2F& aWindowsPosition );
RAYPACKET( const CCAMERA& aCamera, const SFVEC2F& aWindowsPosition, RAYPACKET( const CAMERA& aCamera, const SFVEC2F& aWindowsPosition,
const SFVEC2F& a2DWindowsPosDisplacementFactor ); const SFVEC2F& a2DWindowsPosDisplacementFactor );
CFRUSTUM m_Frustum; FRUSTUM m_Frustum;
RAY m_ray[RAYPACKET_RAYS_PER_PACKET]; RAY m_ray[RAYPACKET_RAYS_PER_PACKET];
}; };
void RAYPACKET_InitRays( const CCAMERA& aCamera, const SFVEC2F& aWindowsPosition, RAY* aRayPck ); void RAYPACKET_InitRays( const CAMERA& aCamera, const SFVEC2F& aWindowsPosition, RAY* aRayPck );
void RAYPACKET_InitRays_with2DDisplacement( const CCAMERA& aCamera, void RAYPACKET_InitRays_with2DDisplacement( const CAMERA& aCamera, const SFVEC2F& aWindowsPosition,
const SFVEC2F& aWindowsPosition,
const SFVEC2F& a2DWindowsPosDisplacementFactor, const SFVEC2F& a2DWindowsPosDisplacementFactor,
RAY* aRayPck ); RAY* aRayPck );

View File

@ -33,31 +33,31 @@
#include <wx/debug.h> #include <wx/debug.h>
CBBOX2D::CBBOX2D() BBOX_2D::BBOX_2D()
{ {
Reset(); Reset();
} }
CBBOX2D::CBBOX2D( const SFVEC2F &aPbInit ) BBOX_2D::BBOX_2D( const SFVEC2F& aPbInit )
{ {
m_min = aPbInit; m_min = aPbInit;
m_max = aPbInit; m_max = aPbInit;
} }
CBBOX2D::CBBOX2D( const SFVEC2F &aPbMin, const SFVEC2F &aPbMax ) BBOX_2D::BBOX_2D( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax )
{ {
Set( aPbMin, aPbMax ); Set( aPbMin, aPbMax );
} }
CBBOX2D::~CBBOX2D() BBOX_2D::~BBOX_2D()
{ {
} }
void CBBOX2D::Set( const SFVEC2F &aPbMin, const SFVEC2F &aPbMax ) void BBOX_2D::Set( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax )
{ {
m_min.x = fminf( aPbMin.x, aPbMax.x ); m_min.x = fminf( aPbMin.x, aPbMax.x );
m_min.y = fminf( aPbMin.y, aPbMax.y ); m_min.y = fminf( aPbMin.y, aPbMax.y );
@ -67,7 +67,7 @@ void CBBOX2D::Set( const SFVEC2F &aPbMin, const SFVEC2F &aPbMax )
} }
void CBBOX2D::Set( const CBBOX2D &aBBox ) void BBOX_2D::Set( const BBOX_2D& aBBox )
{ {
wxASSERT( aBBox.IsInitialized() ); wxASSERT( aBBox.IsInitialized() );
@ -75,23 +75,21 @@ void CBBOX2D::Set( const CBBOX2D &aBBox )
} }
bool CBBOX2D::IsInitialized() const bool BBOX_2D::IsInitialized() const
{ {
return !( ( FLT_MAX == m_min.x) || return !( ( FLT_MAX == m_min.x) || ( FLT_MAX == m_min.y) ||
( FLT_MAX == m_min.y) || (-FLT_MAX == m_max.x) || (-FLT_MAX == m_max.y) );
(-FLT_MAX == m_max.x) ||
(-FLT_MAX == m_max.y) );
} }
void CBBOX2D::Reset() void BBOX_2D::Reset()
{ {
m_min = SFVEC2F( FLT_MAX, FLT_MAX ); m_min = SFVEC2F( FLT_MAX, FLT_MAX );
m_max = SFVEC2F(-FLT_MAX,-FLT_MAX ); m_max = SFVEC2F( -FLT_MAX,-FLT_MAX );
} }
void CBBOX2D::Union( const SFVEC2F &aPoint ) void BBOX_2D::Union( const SFVEC2F& aPoint )
{ {
// get the minimum value between the added point and the existent bounding box // get the minimum value between the added point and the existent bounding box
m_min.x = fminf( m_min.x, aPoint.x ); m_min.x = fminf( m_min.x, aPoint.x );
@ -103,7 +101,7 @@ void CBBOX2D::Union( const SFVEC2F &aPoint )
} }
void CBBOX2D::Union( const CBBOX2D &aBBox ) void BBOX_2D::Union( const BBOX_2D& aBBox )
{ {
// get the minimum value between the added bounding box and // get the minimum value between the added bounding box and
// the existent bounding box // the existent bounding box
@ -117,19 +115,19 @@ void CBBOX2D::Union( const CBBOX2D &aBBox )
} }
SFVEC2F CBBOX2D::GetCenter() const SFVEC2F BBOX_2D::GetCenter() const
{ {
return (m_max + m_min) * 0.5f; return (m_max + m_min) * 0.5f;
} }
SFVEC2F CBBOX2D::GetExtent() const SFVEC2F BBOX_2D::GetExtent() const
{ {
return m_max - m_min; return m_max - m_min;
} }
unsigned int CBBOX2D::MaxDimension() const unsigned int BBOX_2D::MaxDimension() const
{ {
unsigned int result = 0; unsigned int result = 0;
const SFVEC2F extent = GetExtent(); const SFVEC2F extent = GetExtent();
@ -140,7 +138,7 @@ unsigned int CBBOX2D::MaxDimension() const
} }
float CBBOX2D::Perimeter() const float BBOX_2D::Perimeter() const
{ {
const SFVEC2F extent = GetExtent(); const SFVEC2F extent = GetExtent();
@ -148,7 +146,7 @@ float CBBOX2D::Perimeter() const
} }
void CBBOX2D::Scale( float aScale ) void BBOX_2D::Scale( float aScale )
{ {
wxASSERT( IsInitialized() ); wxASSERT( IsInitialized() );
@ -160,7 +158,7 @@ void CBBOX2D::Scale( float aScale )
} }
void CBBOX2D::ScaleNextUp() void BBOX_2D::ScaleNextUp()
{ {
m_min.x = NextFloatDown( m_min.x ); m_min.x = NextFloatDown( m_min.x );
m_min.y = NextFloatDown( m_min.y ); m_min.y = NextFloatDown( m_min.y );
@ -170,7 +168,7 @@ void CBBOX2D::ScaleNextUp()
} }
void CBBOX2D::ScaleNextDown() void BBOX_2D::ScaleNextDown()
{ {
m_min.x = NextFloatUp( m_min.x ); m_min.x = NextFloatUp( m_min.x );
m_min.y = NextFloatUp( m_min.y ); m_min.y = NextFloatUp( m_min.y );
@ -182,7 +180,7 @@ void CBBOX2D::ScaleNextDown()
// http://goanna.cs.rmit.edu.au/~gl/teaching/rtr&3dgp/notes/intersection.pdf // http://goanna.cs.rmit.edu.au/~gl/teaching/rtr&3dgp/notes/intersection.pdf
// http://www.mrtc.mdh.se/projects/3Dgraphics/paperF.pdf // http://www.mrtc.mdh.se/projects/3Dgraphics/paperF.pdf
bool CBBOX2D::Intersects( const SFVEC2F &aCenter, float aRadiusSquared ) const bool BBOX_2D::Intersects( const SFVEC2F& aCenter, float aRadiusSquared ) const
{ {
float fDistSq = 0.0f; float fDistSq = 0.0f;
@ -209,7 +207,7 @@ bool CBBOX2D::Intersects( const SFVEC2F &aCenter, float aRadiusSquared ) const
} }
bool CBBOX2D::Intersects( const CBBOX2D &aBBox ) const bool BBOX_2D::Intersects( const BBOX_2D& aBBox ) const
{ {
wxASSERT( IsInitialized() ); wxASSERT( IsInitialized() );
wxASSERT( aBBox.IsInitialized() ); wxASSERT( aBBox.IsInitialized() );
@ -221,7 +219,7 @@ bool CBBOX2D::Intersects( const CBBOX2D &aBBox ) const
} }
bool CBBOX2D::Inside( const SFVEC2F &aPoint ) const bool BBOX_2D::Inside( const SFVEC2F& aPoint ) const
{ {
wxASSERT( IsInitialized() ); wxASSERT( IsInitialized() );
@ -230,7 +228,7 @@ bool CBBOX2D::Inside( const SFVEC2F &aPoint ) const
} }
float CBBOX2D::Area() const float BBOX_2D::Area() const
{ {
SFVEC2F extent = GetExtent(); SFVEC2F extent = GetExtent();
return extent.x * extent.y; return extent.x * extent.y;
@ -238,7 +236,7 @@ float CBBOX2D::Area() const
// http://tavianator.com/fast-branchless-raybounding-box-intersections/ // http://tavianator.com/fast-branchless-raybounding-box-intersections/
bool CBBOX2D::Intersect( const RAY2D &aRay, float *t ) const bool BBOX_2D::Intersect( const RAY2D& aRay, float* t ) const
{ {
wxASSERT( t ); wxASSERT( t );
@ -263,7 +261,7 @@ bool CBBOX2D::Intersect( const RAY2D &aRay, float *t ) const
} }
bool CBBOX2D::Intersect( const RAYSEG2D &aRaySeg ) const bool BBOX_2D::Intersect( const RAYSEG2D& aRaySeg ) const
{ {
const float tx1 = (m_min.x - aRaySeg.m_Start.x) * aRaySeg.m_InvDir.x; const float tx1 = (m_min.x - aRaySeg.m_Start.x) * aRaySeg.m_InvDir.x;
const float tx2 = (m_max.x - aRaySeg.m_Start.x) * aRaySeg.m_InvDir.x; const float tx2 = (m_max.x - aRaySeg.m_Start.x) * aRaySeg.m_InvDir.x;
@ -288,19 +286,19 @@ bool CBBOX2D::Intersect( const RAYSEG2D &aRaySeg ) const
} }
bool CBBOX2D::Intersect( const RAY2D &aRay, float *aOutHitT0, float *aOutHitT1 ) const bool BBOX_2D::Intersect( const RAY2D& aRay, float* aOutHitT0, float* aOutHitT1 ) const
{ {
wxASSERT( aOutHitT0 ); wxASSERT( aOutHitT0 );
wxASSERT( aOutHitT1 ); wxASSERT( aOutHitT1 );
const float tx1 = (m_min.x - aRay.m_Origin.x) * aRay.m_InvDir.x; const float tx1 = ( m_min.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
const float tx2 = (m_max.x - aRay.m_Origin.x) * aRay.m_InvDir.x; const float tx2 = ( m_max.x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
float tmin = glm::min( tx1, tx2 ); float tmin = glm::min( tx1, tx2 );
float tmax = glm::max( tx1, tx2 ); float tmax = glm::max( tx1, tx2 );
const float ty1 = (m_min.y - aRay.m_Origin.y) * aRay.m_InvDir.y; const float ty1 = ( m_min.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
const float ty2 = (m_max.y - aRay.m_Origin.y) * aRay.m_InvDir.y; const float ty2 = ( m_max.y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
tmin = glm::max( tmin, glm::min( ty1, ty2 ) ); tmin = glm::max( tmin, glm::min( ty1, ty2 ) );
tmax = glm::min( tmax, glm::max( ty1, ty2 ) ); tmax = glm::min( tmax, glm::max( ty1, ty2 ) );

View File

@ -27,8 +27,8 @@
* @brief 2D Bounding Box class definition * @brief 2D Bounding Box class definition
*/ */
#ifndef _CBBOX2D_H_ #ifndef _BBOX_2D_H_
#define _CBBOX2D_H_ #define _BBOX_2D_H_
#include "../ray.h" #include "../ray.h"
@ -36,22 +36,21 @@
/** /**
* Manage a bounding box defined by two SFVEC2F min max points. * Manage a bounding box defined by two SFVEC2F min max points.
*/ */
struct CBBOX2D struct BBOX_2D
{ {
public: public:
/** /**
* Create with default values a bounding box (not initialized). * Create with default values a bounding box (not initialized).
*/ */
CBBOX2D(); BBOX_2D();
/** /**
* Initialize a bounding box with a given point. * Initialize a bounding box with a given point.
* *
* @param aPbInit a point for the bounding box initialization. * @param aPbInit a point for the bounding box initialization.
*/ */
explicit CBBOX2D( const SFVEC2F &aPbInit ); explicit BBOX_2D( const SFVEC2F& aPbInit );
/** /**
* Initialize a bounding box with a minimum and a maximum point. * Initialize a bounding box with a minimum and a maximum point.
@ -59,9 +58,9 @@ public:
* @param aPbMin the minimum point to initialize the bounding box. * @param aPbMin the minimum point to initialize the bounding box.
* @param aPbMax the maximum point to initialize the bounding box. * @param aPbMax the maximum point to initialize the bounding box.
*/ */
CBBOX2D( const SFVEC2F &aPbMin, const SFVEC2F &aPbMax ); BBOX_2D( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax );
~CBBOX2D(); ~BBOX_2D();
/** /**
@ -70,28 +69,28 @@ public:
* @param aPbMin the minimum point to initialize the bounding box. * @param aPbMin the minimum point to initialize the bounding box.
* @param aPbMax the maximum point to initialize the bounding box. * @param aPbMax the maximum point to initialize the bounding box.
*/ */
void Set( const SFVEC2F &aPbMin, const SFVEC2F &aPbMax ); void Set( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax );
/** /**
* Set bounding box based on another bounding box. * Set bounding box based on another bounding box.
* *
* @param CBBOX2D a bounding box to initialize this one. * @param BBOX_2D a bounding box to initialize this one.
*/ */
void Set( const CBBOX2D &aBBox ); void Set( const BBOX_2D& aBBox );
/** /**
* Recalculate the bounding box adding a point. * Recalculate the bounding box adding a point.
* *
* @param aPoint the point to be bounded * @param aPoint the point to be bounded
*/ */
void Union( const SFVEC2F &aPoint ); void Union( const SFVEC2F& aPoint );
/** /**
* Recalculate the bounding box adding other bounding box. * Recalculate the bounding box adding other bounding box.
* *
* @param aBBox the bounding box to be bounded. * @param aBBox the bounding box to be bounded.
*/ */
void Union( const CBBOX2D &aBBox ); void Union( const BBOX_2D& aBBox );
/** /**
* Scale a bounding box by its center. * Scale a bounding box by its center.
@ -115,21 +114,21 @@ public:
* *
* @param aBBox the bounding box to check if it intersects. * @param aBBox the bounding box to check if it intersects.
*/ */
bool Intersects( const CBBOX2D &aBBox ) const; bool Intersects( const BBOX_2D& aBBox ) const;
/** /**
* Test if a circle intersects this box. * Test if a circle intersects this box.
* *
* @param aBBox the bounding box to check if it intersects. * @param aBBox the bounding box to check if it intersects.
*/ */
bool Intersects( const SFVEC2F &aCenter, float aRadiusSquared ) const; bool Intersects( const SFVEC2F& aCenter, float aRadiusSquared ) const;
/** /**
* Check is a point is inside this bounding box. * Check is a point is inside this bounding box.
* *
* @param aPoint point to test. * @param aPoint point to test.
*/ */
bool Inside( const SFVEC2F &aPoint ) const; bool Inside( const SFVEC2F& aPoint ) const;
/** /**
* Calculate the area of a bounding box. * Calculate the area of a bounding box.
@ -151,8 +150,6 @@ public:
void Reset(); void Reset();
/** /**
* Return the center point of the bounding box.
*
* @return the position of the center of this bounding box. * @return the position of the center of this bounding box.
*/ */
SFVEC2F GetCenter() const; SFVEC2F GetCenter() const;
@ -163,17 +160,14 @@ public:
SFVEC2F GetExtent() const; SFVEC2F GetExtent() const;
/** /**
* Return the minimum vertex point.
*
* @return the minimum vertex position. * @return the minimum vertex position.
*/ */
const SFVEC2F &Min() const { return m_min; } const SFVEC2F& Min() const { return m_min; }
/** /**
* Return the maximum vertex point.
* @return the maximum vertex position. * @return the maximum vertex position.
*/ */
const SFVEC2F &Max() const { return m_max; } const SFVEC2F& Max() const { return m_max; }
/** /**
@ -182,20 +176,20 @@ public:
unsigned int MaxDimension() const; unsigned int MaxDimension() const;
/** /**
* @return the surface area of the box * @return the surface area of the box.
*/ */
float Perimeter() const; float Perimeter() const;
/** /**
* @param aRay ray to intersect the box * @param aRay is a ray to intersect the box.
* @param t distance point of the ray of the intersection (if true) * @param t is the distance point of the ray of the intersection (if true).
* @return true if the ray hits the box * @return true if the ray hits the box.
*/ */
bool Intersect( const RAY2D &aRay, float *t ) const; bool Intersect( const RAY2D& aRay, float* t ) const;
bool Intersect( const RAY2D &aRay, float *aOutHitT0, float *aOutHitT1 ) const; bool Intersect( const RAY2D& aRay, float* aOutHitT0, float* aOutHitT1 ) const;
bool Intersect( const RAYSEG2D &aRaySeg ) const; bool Intersect( const RAYSEG2D& aRaySeg ) const;
private: private:
SFVEC2F m_min; ///< point of the lower position of the bounding box SFVEC2F m_min; ///< point of the lower position of the bounding box

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -31,9 +31,9 @@
#include <wx/debug.h> #include <wx/debug.h>
CFILLEDCIRCLE2D::CFILLEDCIRCLE2D( FILLED_CIRCLE_2D::FILLED_CIRCLE_2D( const SFVEC2F& aCenter, float aRadius,
const SFVEC2F& aCenter, float aRadius, const BOARD_ITEM& aBoardItem ) const BOARD_ITEM& aBoardItem ) :
: COBJECT2D( OBJECT2D_TYPE::FILLED_CIRCLE, aBoardItem ) OBJECT_2D( OBJECT_2D_TYPE::FILLED_CIRCLE, aBoardItem )
{ {
wxASSERT( aRadius > 0.0f ); // If that happens, it should be handled before create this circle wxASSERT( aRadius > 0.0f ); // If that happens, it should be handled before create this circle
@ -51,22 +51,20 @@ CFILLEDCIRCLE2D::CFILLEDCIRCLE2D(
} }
bool CFILLEDCIRCLE2D::Overlaps( const CBBOX2D &aBBox ) const bool FILLED_CIRCLE_2D::Overlaps( const BBOX_2D& aBBox ) const
{ {
// NOT IMPLEMENTED // NOT IMPLEMENTED
return false; return false;
} }
bool CFILLEDCIRCLE2D::Intersects( const CBBOX2D &aBBox ) const bool FILLED_CIRCLE_2D::Intersects( const BBOX_2D& aBBox ) const
{ {
return aBBox.Intersects( m_center, m_radius_squared ); return aBBox.Intersects( m_center, m_radius_squared );
} }
bool CFILLEDCIRCLE2D::Intersect( const RAYSEG2D &aSegRay, bool FILLED_CIRCLE_2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const
float *aOutT,
SFVEC2F *aNormalOut ) const
{ {
// This code used directly from Steve Marschner's CS667 framework // This code used directly from Steve Marschner's CS667 framework
// http://cs665pd.googlecode.com/svn/trunk/photon/sphere.cpp // http://cs665pd.googlecode.com/svn/trunk/photon/sphere.cpp
@ -80,7 +78,7 @@ bool CFILLEDCIRCLE2D::Intersect( const RAYSEG2D &aSegRay,
// solving the quadratic equation for t at the pts of intersection // solving the quadratic equation for t at the pts of intersection
// dd*t^2 + (2*qd)*t + (qq-r^2) = 0 // dd*t^2 + (2*qd)*t + (qq-r^2) = 0
const float discriminantsqr = (qd * qd - (qq - m_radius_squared)); const float discriminantsqr = ( qd * qd - ( qq - m_radius_squared ) );
// If the discriminant is less than zero, there is no intersection // If the discriminant is less than zero, there is no intersection
if( discriminantsqr < FLT_EPSILON ) if( discriminantsqr < FLT_EPSILON )
@ -89,23 +87,25 @@ bool CFILLEDCIRCLE2D::Intersect( const RAYSEG2D &aSegRay,
// Otherwise check and make sure that the intersections occur on the ray (t // Otherwise check and make sure that the intersections occur on the ray (t
// > 0) and return the closer one // > 0) and return the closer one
const float discriminant = sqrt(discriminantsqr); const float discriminant = sqrt( discriminantsqr );
const float t1 = (-qd - discriminant); const float t1 = ( -qd - discriminant );
const float t2 = (-qd + discriminant); const float t2 = ( -qd + discriminant );
float t; float t;
if( (t1 > 0.0f) && (t1 < aSegRay.m_Length) ) if( ( t1 > 0.0f ) && ( t1 < aSegRay.m_Length ) )
{
t = t1; t = t1;
}
else else
{ {
if( (t2 > 0.0f) && (t2 < aSegRay.m_Length) ) if( ( t2 > 0.0f ) && ( t2 < aSegRay.m_Length ) )
t = t2; t = t2;
else else
return false; // Neither intersection was in the ray's half line. return false; // Neither intersection was in the ray's half line.
} }
wxASSERT( (t > 0.0f) && (t <= aSegRay.m_Length) ); wxASSERT( ( t > 0.0f ) && ( t <= aSegRay.m_Length ) );
// Convert the intersection to a normalized 0.0 .. 1.0 // Convert the intersection to a normalized 0.0 .. 1.0
if( aOutT ) if( aOutT )
@ -120,7 +120,7 @@ bool CFILLEDCIRCLE2D::Intersect( const RAYSEG2D &aSegRay,
} }
INTERSECTION_RESULT CFILLEDCIRCLE2D::IsBBoxInside( const CBBOX2D &aBBox ) const INTERSECTION_RESULT FILLED_CIRCLE_2D::IsBBoxInside( const BBOX_2D& aBBox ) const
{ {
if( !m_bbox.Intersects( aBBox ) ) if( !m_bbox.Intersects( aBBox ) )
return INTERSECTION_RESULT::MISSES; return INTERSECTION_RESULT::MISSES;
@ -147,28 +147,22 @@ INTERSECTION_RESULT CFILLEDCIRCLE2D::IsBBoxInside( const CBBOX2D &aBBox ) const
isInside[3] = s[3] <= m_radius_squared; isInside[3] = s[3] <= m_radius_squared;
// Check if all points are inside the circle // Check if all points are inside the circle
if( isInside[0] && if( isInside[0] && isInside[1] && isInside[2] && isInside[3] )
isInside[1] &&
isInside[2] &&
isInside[3] )
return INTERSECTION_RESULT::FULL_INSIDE; return INTERSECTION_RESULT::FULL_INSIDE;
// Check if any point is inside the circle // Check if any point is inside the circle
if( isInside[0] || if( isInside[0] || isInside[1] || isInside[2] || isInside[3] )
isInside[1] ||
isInside[2] ||
isInside[3] )
return INTERSECTION_RESULT::INTERSECTS; return INTERSECTION_RESULT::INTERSECTS;
return INTERSECTION_RESULT::MISSES; return INTERSECTION_RESULT::MISSES;
} }
bool CFILLEDCIRCLE2D::IsPointInside( const SFVEC2F &aPoint ) const bool FILLED_CIRCLE_2D::IsPointInside( const SFVEC2F& aPoint ) const
{ {
const SFVEC2F v = m_center - aPoint; const SFVEC2F v = m_center - aPoint;
if( (v.x * v.x + v.y * v.y) <= m_radius_squared ) if( ( v.x * v.x + v.y * v.y ) <= m_radius_squared )
return true; return true;
return false; return false;

View File

@ -27,26 +27,26 @@
* @brief * @brief
*/ */
#ifndef _CFILLEDCIRCLE2D_H_ #ifndef _FILLED_CIRCLE_2D_H_
#define _CFILLEDCIRCLE2D_H_ #define _FILLED_CIRCLE_2D_H_
#include "cobject2d.h" #include "cobject2d.h"
class CFILLEDCIRCLE2D : public COBJECT2D class FILLED_CIRCLE_2D : public OBJECT_2D
{ {
public: public:
CFILLEDCIRCLE2D( const SFVEC2F &aCenter, float aRadius, const BOARD_ITEM &aBoardItem ); FILLED_CIRCLE_2D( const SFVEC2F& aCenter, float aRadius, const BOARD_ITEM& aBoardItem );
float GetRadius() const { return m_radius; } float GetRadius() const { return m_radius; }
const SFVEC2F &GetCenter() const { return m_center; } const SFVEC2F& GetCenter() const { return m_center; }
float GetRadiusSquared() const { return m_radius_squared; } float GetRadiusSquared() const { return m_radius_squared; }
// Imported from COBJECT2D // Imported from OBJECT_2D
bool Overlaps( const CBBOX2D &aBBox ) const override; bool Overlaps( const BBOX_2D& aBBox ) const override;
bool Intersects( const CBBOX2D &aBBox ) const override; bool Intersects( const BBOX_2D& aBBox ) const override;
bool Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const override; bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const override; INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
bool IsPointInside( const SFVEC2F &aPoint ) const override; bool IsPointInside( const SFVEC2F& aPoint ) const override;
private: private:
SFVEC2F m_center; SFVEC2F m_center;
@ -55,4 +55,4 @@ private:
}; };
#endif // _CFILLEDCIRCLE2D_H_ #endif // _FILLED_CIRCLE_2D_H_

View File

@ -32,11 +32,9 @@
#include <wx/debug.h> #include <wx/debug.h>
CITEMLAYERCSG2D::CITEMLAYERCSG2D( const COBJECT2D* aObjectA, LAYER_ITEM_2D::LAYER_ITEM_2D( const OBJECT_2D* aObjectA, std::vector<const OBJECT_2D*>* aObjectB,
std::vector<const COBJECT2D*>* aObjectB, const OBJECT_2D* aObjectC, const BOARD_ITEM& aBoardItem ) :
const COBJECT2D* aObjectC, OBJECT_2D( OBJECT_2D_TYPE::CSG, aBoardItem ),
const BOARD_ITEM& aBoardItem ) :
COBJECT2D( OBJECT2D_TYPE::CSG, aBoardItem ),
m_objectA( aObjectA ), m_objectA( aObjectA ),
m_objectB( aObjectB ), m_objectB( aObjectB ),
m_objectC( aObjectC ) m_objectC( aObjectC )
@ -52,17 +50,17 @@ CITEMLAYERCSG2D::CITEMLAYERCSG2D( const COBJECT2D* aObjectA,
} }
CITEMLAYERCSG2D::~CITEMLAYERCSG2D() LAYER_ITEM_2D::~LAYER_ITEM_2D()
{ {
if( ( (void*) m_objectB != CSGITEM_EMPTY ) && ( (void*) m_objectB != CSGITEM_FULL ) ) if( ( (void*) m_objectB != CSGITEM_EMPTY ) && ( (void*) m_objectB != CSGITEM_FULL ) )
{ {
delete m_objectB; delete m_objectB;
m_objectB = NULL; m_objectB = nullptr;
} }
} }
bool CITEMLAYERCSG2D::Intersects( const CBBOX2D& aBBox ) const bool LAYER_ITEM_2D::Intersects( const BBOX_2D& aBBox ) const
{ {
return m_bbox.Intersects( aBBox ); return m_bbox.Intersects( aBBox );
// !TODO: improve this implementation // !TODO: improve this implementation
@ -70,7 +68,7 @@ bool CITEMLAYERCSG2D::Intersects( const CBBOX2D& aBBox ) const
} }
bool CITEMLAYERCSG2D::Overlaps( const CBBOX2D& aBBox ) const bool LAYER_ITEM_2D::Overlaps( const BBOX_2D& aBBox ) const
{ {
// NOT IMPLEMENTED // NOT IMPLEMENTED
return false; return false;
@ -79,9 +77,9 @@ bool CITEMLAYERCSG2D::Overlaps( const CBBOX2D& aBBox ) const
// Based on ideas and implementation by Nick Chapman // Based on ideas and implementation by Nick Chapman
// http://homepages.paradise.net.nz/nickamy/raytracer/raytracer.htm // http://homepages.paradise.net.nz/nickamy/raytracer/raytracer.htm
bool CITEMLAYERCSG2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const bool LAYER_ITEM_2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const
{ {
if( m_objectA->GetObjectType() == OBJECT2D_TYPE::DUMMYBLOCK ) if( m_objectA->GetObjectType() == OBJECT_2D_TYPE::DUMMYBLOCK )
return false; return false;
SFVEC2F currentRayPos = aSegRay.m_Start; SFVEC2F currentRayPos = aSegRay.m_Start;
@ -112,13 +110,13 @@ bool CITEMLAYERCSG2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F*
//check against all subbed objects //check against all subbed objects
for( unsigned int i = 0; i < m_objectB->size(); ++i ) for( unsigned int i = 0; i < m_objectB->size(); ++i )
{ {
if( ( (const COBJECT2D*) ( *m_objectB )[i] )->IsPointInside( currentRayPos ) ) if( ( (const OBJECT_2D*) ( *m_objectB )[i] )->IsPointInside( currentRayPos ) )
{ {
// ray point is inside a subtracted region, so move it to the end of the // ray point is inside a subtracted region, so move it to the end of the
// subtracted region // subtracted region
float hitDist; float hitDist;
SFVEC2F tmpNormal; SFVEC2F tmpNormal;
if( !( (const COBJECT2D*) ( *m_objectB )[i] ) if( !( (const OBJECT_2D*) ( *m_objectB )[i] )
->Intersect( currentRay, &hitDist, &tmpNormal ) ) ->Intersect( currentRay, &hitDist, &tmpNormal ) )
return false; // ray hit main object but did not leave subtracted volume return false; // ray hit main object but did not leave subtracted volume
@ -155,7 +153,7 @@ bool CITEMLAYERCSG2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F*
} }
INTERSECTION_RESULT CITEMLAYERCSG2D::IsBBoxInside( const CBBOX2D& aBBox ) const INTERSECTION_RESULT LAYER_ITEM_2D::IsBBoxInside( const BBOX_2D& aBBox ) const
{ {
// !TODO: // !TODO:
@ -164,7 +162,7 @@ INTERSECTION_RESULT CITEMLAYERCSG2D::IsBBoxInside( const CBBOX2D& aBBox ) const
} }
bool CITEMLAYERCSG2D::IsPointInside( const SFVEC2F& aPoint ) const bool LAYER_ITEM_2D::IsPointInside( const SFVEC2F& aPoint ) const
{ {
// Perform the operation (A - B) /\ C // Perform the operation (A - B) /\ C
if( m_objectA->IsPointInside( aPoint ) ) if( m_objectA->IsPointInside( aPoint ) )

View File

@ -1,3 +1,4 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
@ -27,18 +28,18 @@
* @brief * @brief
*/ */
#ifndef _CITEMLAYERCSG2D_H_ #ifndef _LAYER_ITEM_2D_H_
#define _CITEMLAYERCSG2D_H_ #define _LAYER_ITEM_2D_H_
#include "cobject2d.h" #include "cobject2d.h"
#include <vector> #include <vector>
#define CSGITEM_EMPTY 0 #define CSGITEM_EMPTY 0
#define CSGITEM_FULL (COBJECT2D *)((size_t)(-1)) #define CSGITEM_FULL (OBJECT_2D*) ( ( size_t )( -1 ) )
/** /**
* Make constructive solid geometry for items objects on layers. * Make solid geometry for objects on layers.
* *
* The operation is in the form (A - B) /\ C * The operation is in the form (A - B) /\ C
* For almost all of the layers it translate something like: * For almost all of the layers it translate something like:
@ -75,27 +76,25 @@
* Layers.Paste = P - 0 /\ BODY * Layers.Paste = P - 0 /\ BODY
* Layers.Silk = S - 0 /\ BODY * Layers.Silk = S - 0 /\ BODY
*/ */
class CITEMLAYERCSG2D : public COBJECT2D class LAYER_ITEM_2D : public OBJECT_2D
{ {
public: public:
CITEMLAYERCSG2D( const COBJECT2D *aObjectA, LAYER_ITEM_2D( const OBJECT_2D* aObjectA, std::vector<const OBJECT_2D*>* aObjectB,
std::vector<const COBJECT2D *> *aObjectB, const OBJECT_2D* aObjectC, const BOARD_ITEM& aBoardItem );
const COBJECT2D *aObjectC,
const BOARD_ITEM &aBoardItem );
~CITEMLAYERCSG2D(); ~LAYER_ITEM_2D();
// Imported from COBJECT2D // Imported from OBJECT_2D
bool Overlaps( const CBBOX2D &aBBox ) const override; bool Overlaps( const BBOX_2D& aBBox ) const override;
bool Intersects( const CBBOX2D &aBBox ) const override; bool Intersects( const BBOX_2D& aBBox ) const override;
bool Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const override; bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const override; INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
bool IsPointInside( const SFVEC2F &aPoint ) const override; bool IsPointInside( const SFVEC2F& aPoint ) const override;
private: private:
const COBJECT2D *m_objectA; const OBJECT_2D* m_objectA;
std::vector<const COBJECT2D *> *m_objectB; std::vector<const OBJECT_2D*>* m_objectB;
const COBJECT2D *m_objectC; const OBJECT_2D* m_objectC;
}; };
#endif // _CITEMLAYERCSG2D_H_ #endif // _LAYER_ITEM_2D_H_

View File

@ -31,38 +31,38 @@
#include <cstdio> #include <cstdio>
COBJECT2D_STATS *COBJECT2D_STATS::s_instance = 0; OBJECT_2D_STATS *OBJECT_2D_STATS::s_instance = 0;
COBJECT2D::COBJECT2D( OBJECT2D_TYPE aObjType, const BOARD_ITEM &aBoardItem ) OBJECT_2D::OBJECT_2D( OBJECT_2D_TYPE aObjType, const BOARD_ITEM &aBoardItem )
: m_boardItem(aBoardItem) : m_boardItem(aBoardItem)
{ {
m_obj_type = aObjType; m_obj_type = aObjType;
COBJECT2D_STATS::Instance().AddOne( aObjType ); OBJECT_2D_STATS::Instance().AddOne( aObjType );
} }
/* /*
* Lookup table for OBJECT2D_TYPE printed names * Lookup table for OBJECT_2D_TYPE printed names
*/ */
// clang-format off // clang-format off
const std::map<OBJECT2D_TYPE, const char*> objectTypeNames const std::map<OBJECT_2D_TYPE, const char*> objectTypeNames
{ {
{ OBJECT2D_TYPE::FILLED_CIRCLE, "OBJECT2D_TYPE::FILLED_CIRCLE" }, { OBJECT_2D_TYPE::FILLED_CIRCLE, "OBJECT_2D_TYPE::FILLED_CIRCLE" },
{ OBJECT2D_TYPE::CSG, "OBJECT2D_TYPE::CSG" }, { OBJECT_2D_TYPE::CSG, "OBJECT_2D_TYPE::CSG" },
{ OBJECT2D_TYPE::POLYGON, "OBJECT2D_TYPE::POLYGON" }, { OBJECT_2D_TYPE::POLYGON, "OBJECT_2D_TYPE::POLYGON" },
{ OBJECT2D_TYPE::DUMMYBLOCK, "OBJECT2D_TYPE::DUMMYBLOCK" }, { OBJECT_2D_TYPE::DUMMYBLOCK, "OBJECT_2D_TYPE::DUMMYBLOCK" },
{ OBJECT2D_TYPE::POLYGON4PT, "OBJECT2D_TYPE::POLYGON4PT" }, { OBJECT_2D_TYPE::POLYGON4PT, "OBJECT_2D_TYPE::POLYGON4PT" },
{ OBJECT2D_TYPE::RING, "OBJECT2D_TYPE::RING" }, { OBJECT_2D_TYPE::RING, "OBJECT_2D_TYPE::RING" },
{ OBJECT2D_TYPE::ROUNDSEG, "OBJECT2D_TYPE::ROUNDSEG" }, { OBJECT_2D_TYPE::ROUNDSEG, "OBJECT_2D_TYPE::ROUNDSEG" },
{ OBJECT2D_TYPE::TRIANGLE, "OBJECT2D_TYPE::TRIANGLE" }, { OBJECT_2D_TYPE::TRIANGLE, "OBJECT_2D_TYPE::TRIANGLE" },
{ OBJECT2D_TYPE::CONTAINER, "OBJECT2D_TYPE::CONTAINER" }, { OBJECT_2D_TYPE::CONTAINER, "OBJECT_2D_TYPE::CONTAINER" },
{ OBJECT2D_TYPE::BVHCONTAINER, "OBJECT2D_TYPE::BVHCONTAINER" }, { OBJECT_2D_TYPE::BVHCONTAINER, "OBJECT_2D_TYPE::BVHCONTAINER" },
}; };
// clang-format on // clang-format on
void COBJECT2D_STATS::PrintStats() void OBJECT_2D_STATS::PrintStats()
{ {
for( auto& objectType : objectTypeNames ) for( auto& objectType : objectTypeNames )
{ {

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,11 +24,10 @@
/** /**
* @file cobject2d.h * @file cobject2d.h
* @brief
*/ */
#ifndef _COBJECT2D_H_ #ifndef _OBJECT_2D_H_
#define _COBJECT2D_H_ #define _OBJECT_2D_H_
#include "cbbox2d.h" #include "cbbox2d.h"
#include <cstring> #include <cstring>
@ -43,7 +42,7 @@ enum class INTERSECTION_RESULT
}; };
enum class OBJECT2D_TYPE enum class OBJECT_2D_TYPE
{ {
FILLED_CIRCLE, FILLED_CIRCLE,
CSG, CSG,
@ -59,13 +58,13 @@ enum class OBJECT2D_TYPE
}; };
class COBJECT2D class OBJECT_2D
{ {
public: public:
COBJECT2D( OBJECT2D_TYPE aObjType, const BOARD_ITEM &aBoardItem ); OBJECT_2D( OBJECT_2D_TYPE aObjType, const BOARD_ITEM& aBoardItem );
virtual ~COBJECT2D() {} virtual ~OBJECT_2D() {}
const BOARD_ITEM &GetBoardItem() const { return m_boardItem; } const BOARD_ITEM& GetBoardItem() const { return m_boardItem; }
/** /**
* Test if the box overlaps the object. * Test if the box overlaps the object.
@ -78,86 +77,83 @@ public:
* of the bounding box (so the overlap cannot be a point or a line) and one * of the bounding box (so the overlap cannot be a point or a line) and one
* of the boxes cannot full contain the other box. * of the boxes cannot full contain the other box.
* *
* @param aBBox - The bounding box to test * @param aBBox is the bounding box to test.
* @return true if the BBox intersects the object or is inside it * @return true if the BBox intersects the object or is inside it.
*/ */
virtual bool Overlaps( const CBBOX2D &aBBox ) const = 0; virtual bool Overlaps( const BBOX_2D& aBBox ) const = 0;
/** /**
* a.Intersects(b) !a.Disjoint(b) !(a b = ) * a.Intersects(b) !a.Disjoint(b) !(a b = )
*/ */
virtual bool Intersects( const CBBOX2D &aBBox ) const = 0; virtual bool Intersects( const BBOX_2D& aBBox ) const = 0;
/** /**
* @param aOutT a value between 0.0 and 1.0 in relation to the time of the * @param aOutT a value between 0.0 and 1.0 in relation to the time of the hit of the segment.
* hit of the segment
*/ */
virtual bool Intersect( const RAYSEG2D &aSegRay, virtual bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const = 0;
float *aOutT,
SFVEC2F *aNormalOut ) const = 0;
/** /**
* Test this object if it's completely outside, intersects, or is completely inside \a aBBox. * Test this object if it's completely outside, intersects, or is completely inside \a aBBox.
* *
* @return INTERSECTION_RESULT * @return INTERSECTION_RESULT
*/ */
virtual INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const = 0; virtual INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const = 0;
virtual bool IsPointInside( const SFVEC2F &aPoint ) const = 0; virtual bool IsPointInside( const SFVEC2F& aPoint ) const = 0;
const CBBOX2D &GetBBox() const { return m_bbox; } const BBOX_2D& GetBBox() const { return m_bbox; }
const SFVEC2F &GetCentroid() const { return m_centroid; } const SFVEC2F& GetCentroid() const { return m_centroid; }
OBJECT2D_TYPE GetObjectType() const { return m_obj_type; } OBJECT_2D_TYPE GetObjectType() const { return m_obj_type; }
protected: protected:
CBBOX2D m_bbox; BBOX_2D m_bbox;
SFVEC2F m_centroid; SFVEC2F m_centroid;
OBJECT2D_TYPE m_obj_type; OBJECT_2D_TYPE m_obj_type;
const BOARD_ITEM &m_boardItem; const BOARD_ITEM& m_boardItem;
}; };
class COBJECT2D_STATS class OBJECT_2D_STATS
{ {
public: public:
void ResetStats() void ResetStats()
{ {
memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT2D_TYPE::MAX ) ); memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT_2D_TYPE::MAX ) );
} }
unsigned int GetCountOf( OBJECT2D_TYPE aObjType ) const unsigned int GetCountOf( OBJECT_2D_TYPE aObjType ) const
{ {
return m_counter[static_cast<int>( aObjType )]; return m_counter[static_cast<int>( aObjType )];
} }
void AddOne( OBJECT2D_TYPE aObjType ) void AddOne( OBJECT_2D_TYPE aObjType )
{ {
m_counter[static_cast<int>( aObjType )]++; m_counter[static_cast<int>( aObjType )]++;
} }
void PrintStats(); void PrintStats();
static COBJECT2D_STATS &Instance() static OBJECT_2D_STATS& Instance()
{ {
if( !s_instance ) if( !s_instance )
s_instance = new COBJECT2D_STATS; s_instance = new OBJECT_2D_STATS;
return *s_instance; return *s_instance;
} }
private: private:
COBJECT2D_STATS(){ ResetStats(); } OBJECT_2D_STATS(){ ResetStats(); }
COBJECT2D_STATS( const COBJECT2D_STATS &old ); OBJECT_2D_STATS( const OBJECT_2D_STATS& old );
const COBJECT2D_STATS &operator=( const COBJECT2D_STATS &old ); const OBJECT_2D_STATS& operator=( const OBJECT_2D_STATS& old );
~COBJECT2D_STATS(){} ~OBJECT_2D_STATS(){}
unsigned int m_counter[static_cast<int>( OBJECT2D_TYPE::MAX )]; unsigned int m_counter[static_cast<int>( OBJECT_2D_TYPE::MAX )];
static COBJECT2D_STATS *s_instance; static OBJECT_2D_STATS* s_instance;
}; };
#endif // _COBJECT2D_H_ #endif // _OBJECT_2D_H_

View File

@ -65,9 +65,9 @@ static bool polygon_IsPointInside( const SEGMENTS& aSegments, const SFVEC2F& aPo
} }
CPOLYGONBLOCK2D::CPOLYGONBLOCK2D( const SEGMENTS_WIDTH_NORMALS& aOpenSegmentList, POLYGON_2D::POLYGON_2D( const SEGMENTS_WIDTH_NORMALS& aOpenSegmentList,
const OUTERS_AND_HOLES& aOuter_and_holes, const BOARD_ITEM& aBoardItem ) const OUTERS_AND_HOLES& aOuter_and_holes, const BOARD_ITEM& aBoardItem )
: COBJECT2D( OBJECT2D_TYPE::POLYGON, aBoardItem ) : OBJECT_2D( OBJECT_2D_TYPE::POLYGON, aBoardItem )
{ {
m_open_segments.resize( aOpenSegmentList.size() ); m_open_segments.resize( aOpenSegmentList.size() );
@ -104,7 +104,7 @@ CPOLYGONBLOCK2D::CPOLYGONBLOCK2D( const SEGMENTS_WIDTH_NORMALS& aOpenSegmentList
} }
bool CPOLYGONBLOCK2D::Intersects( const CBBOX2D& aBBox ) const bool POLYGON_2D::Intersects( const BBOX_2D& aBBox ) const
{ {
return m_bbox.Intersects( aBBox ); return m_bbox.Intersects( aBBox );
@ -114,14 +114,14 @@ bool CPOLYGONBLOCK2D::Intersects( const CBBOX2D& aBBox ) const
} }
bool CPOLYGONBLOCK2D::Overlaps( const CBBOX2D& aBBox ) const bool POLYGON_2D::Overlaps( const BBOX_2D& aBBox ) const
{ {
// NOT IMPLEMENTED // NOT IMPLEMENTED
return false; return false;
} }
bool CPOLYGONBLOCK2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const bool POLYGON_2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const
{ {
int hitIndex = -1; int hitIndex = -1;
float hitU = 0.0f; float hitU = 0.0f;
@ -180,14 +180,14 @@ bool CPOLYGONBLOCK2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F*
} }
INTERSECTION_RESULT CPOLYGONBLOCK2D::IsBBoxInside( const CBBOX2D& aBBox ) const INTERSECTION_RESULT POLYGON_2D::IsBBoxInside( const BBOX_2D& aBBox ) const
{ {
return INTERSECTION_RESULT::MISSES; return INTERSECTION_RESULT::MISSES;
} }
bool CPOLYGONBLOCK2D::IsPointInside( const SFVEC2F& aPoint ) const bool POLYGON_2D::IsPointInside( const SFVEC2F& aPoint ) const
{ {
// NOTE: we could add here a test for the bounding box, but because in the // NOTE: we could add here a test for the bounding box, but because in the
// 3d object it already checked for a 3d bbox. // 3d object it already checked for a 3d bbox.
@ -211,9 +211,9 @@ bool CPOLYGONBLOCK2D::IsPointInside( const SFVEC2F& aPoint ) const
} }
CDUMMYBLOCK2D::CDUMMYBLOCK2D( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax, DUMMY_BLOCK_2D::DUMMY_BLOCK_2D( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax,
const BOARD_ITEM& aBoardItem ) const BOARD_ITEM& aBoardItem )
: COBJECT2D( OBJECT2D_TYPE::DUMMYBLOCK, aBoardItem ) : OBJECT_2D( OBJECT_2D_TYPE::DUMMYBLOCK, aBoardItem )
{ {
m_bbox.Set( aPbMin, aPbMax ); m_bbox.Set( aPbMin, aPbMax );
m_bbox.ScaleNextUp(); m_bbox.ScaleNextUp();
@ -221,8 +221,8 @@ CDUMMYBLOCK2D::CDUMMYBLOCK2D( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax,
} }
CDUMMYBLOCK2D::CDUMMYBLOCK2D( const CBBOX2D& aBBox, const BOARD_ITEM& aBoardItem ) DUMMY_BLOCK_2D::DUMMY_BLOCK_2D( const BBOX_2D& aBBox, const BOARD_ITEM& aBoardItem )
: COBJECT2D( OBJECT2D_TYPE::DUMMYBLOCK, aBoardItem ) : OBJECT_2D( OBJECT_2D_TYPE::DUMMYBLOCK, aBoardItem )
{ {
m_bbox.Set( aBBox ); m_bbox.Set( aBBox );
m_bbox.ScaleNextUp(); m_bbox.ScaleNextUp();
@ -230,20 +230,20 @@ CDUMMYBLOCK2D::CDUMMYBLOCK2D( const CBBOX2D& aBBox, const BOARD_ITEM& aBoardItem
} }
bool CDUMMYBLOCK2D::Intersects( const CBBOX2D& aBBox ) const bool DUMMY_BLOCK_2D::Intersects( const BBOX_2D& aBBox ) const
{ {
return m_bbox.Intersects( aBBox ); return m_bbox.Intersects( aBBox );
} }
bool CDUMMYBLOCK2D::Overlaps( const CBBOX2D& aBBox ) const bool DUMMY_BLOCK_2D::Overlaps( const BBOX_2D& aBBox ) const
{ {
// Not implemented // Not implemented
return false; return false;
} }
bool CDUMMYBLOCK2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const bool DUMMY_BLOCK_2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const
{ {
// The dummy block will be never intersected because it have no edges, // The dummy block will be never intersected because it have no edges,
// only it have a plan surface of the size of the bounding box // only it have a plan surface of the size of the bounding box
@ -251,14 +251,14 @@ bool CDUMMYBLOCK2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* a
} }
INTERSECTION_RESULT CDUMMYBLOCK2D::IsBBoxInside( const CBBOX2D& aBBox ) const INTERSECTION_RESULT DUMMY_BLOCK_2D::IsBBoxInside( const BBOX_2D& aBBox ) const
{ {
//!TODO: //!TODO:
return INTERSECTION_RESULT::MISSES; return INTERSECTION_RESULT::MISSES;
} }
bool CDUMMYBLOCK2D::IsPointInside( const SFVEC2F& aPoint ) const bool DUMMY_BLOCK_2D::IsPointInside( const SFVEC2F& aPoint ) const
{ {
// The dummy is filled in all his bounding box, so if it hit the bbox // The dummy is filled in all his bounding box, so if it hit the bbox
// it will hit this dummy // it will hit this dummy
@ -306,7 +306,7 @@ static bool intersect( const SEGMENT_WITH_NORMALS& aSeg, const SFVEC2F& aStart,
} }
static void extractPathsFrom( const SEGMENTS_WIDTH_NORMALS& aSegList, const CBBOX2D& aBBox, static void extractPathsFrom( const SEGMENTS_WIDTH_NORMALS& aSegList, const BBOX_2D& aBBox,
SEGMENTS_WIDTH_NORMALS& aOutSegThatIntersect ) SEGMENTS_WIDTH_NORMALS& aOutSegThatIntersect )
{ {
wxASSERT( aSegList.size() >= 3 ); wxASSERT( aSegList.size() >= 3 );
@ -334,7 +334,7 @@ static void extractPathsFrom( const SEGMENTS_WIDTH_NORMALS& aSegList, const CBBO
// Check if a segment intersects the bounding box // Check if a segment intersects the bounding box
// Make a bounding box based on the segments start and end // Make a bounding box based on the segments start and end
CBBOX2D segmentBBox( aSegList[i].m_Start, aSegList[j].m_Start ); BBOX_2D segmentBBox( aSegList[i].m_Start, aSegList[j].m_Start );
if( aBBox.Intersects( segmentBBox ) ) if( aBBox.Intersects( segmentBBox ) )
{ {
@ -380,7 +380,7 @@ static void polygon_Convert( const SHAPE_LINE_CHAIN& aPath, SEGMENTS& aOutSegmen
void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks( const SHAPE_POLY_SET& aMainPath, void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks( const SHAPE_POLY_SET& aMainPath,
CGENERICCONTAINER2D& aDstContainer, float aBiuTo3DunitsScale, float aDivFactor, CONTAINER_2D_BASE& aDstContainer, float aBiuTo3DunitsScale, float aDivFactor,
const BOARD_ITEM& aBoardItem, int aPolyIndex ) const BOARD_ITEM& aBoardItem, int aPolyIndex )
{ {
// Get the path // Get the path
@ -391,7 +391,7 @@ void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks( const SHAPE_POLY_S
BOX2I pathBounds = path.BBox(); BOX2I pathBounds = path.BBox();
// Convert the points to segments class // Convert the points to segments class
CBBOX2D bbox; BBOX_2D bbox;
bbox.Reset(); bbox.Reset();
// Contains the main list of segments and each segment normal interpolated // Contains the main list of segments and each segment normal interpolated
@ -553,13 +553,12 @@ void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks( const SHAPE_POLY_S
for( unsigned int iy = 0; iy < grid_divisions.y; iy++ ) for( unsigned int iy = 0; iy < grid_divisions.y; iy++ )
{ {
int leftToRight = pathBounds.GetLeft(); int leftToRight = pathBounds.GetLeft();
float blockX = bbox.Min().x; float blockX = bbox.Min().x;
for( unsigned int ix = 0; ix < grid_divisions.x; ix++ ) for( unsigned int ix = 0; ix < grid_divisions.x; ix++ )
{ {
CBBOX2D blockBox( SFVEC2F( blockX, blockY - blockAdvance.y ), BBOX_2D blockBox( SFVEC2F( blockX, blockY - blockAdvance.y ),
SFVEC2F( blockX + blockAdvance.x, blockY ) ); SFVEC2F( blockX + blockAdvance.x, blockY ) );
// Make the box large to it will catch (intersect) the edges // Make the box large to it will catch (intersect) the edges
@ -587,7 +586,7 @@ void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks( const SHAPE_POLY_S
// polygon, so it means that if any point is inside it, // polygon, so it means that if any point is inside it,
// then all other are inside the polygon. // then all other are inside the polygon.
// This is a full bbox inside, so add a dummy box // This is a full bbox inside, so add a dummy box
aDstContainer.Add( new CDUMMYBLOCK2D( blockBox, aBoardItem ) ); aDstContainer.Add( new DUMMY_BLOCK_2D( blockBox, aBoardItem ) );
stats_n_dummy_blocks++; stats_n_dummy_blocks++;
} }
else else
@ -619,8 +618,8 @@ void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks( const SHAPE_POLY_S
// We need here a strictly simple polygon with outlines and holes // We need here a strictly simple polygon with outlines and holes
SHAPE_POLY_SET solution; SHAPE_POLY_SET solution;
solution.BooleanIntersection( solution.BooleanIntersection( aMainPath, subBlockPoly,
aMainPath, subBlockPoly, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
OUTERS_AND_HOLES outersAndHoles; OUTERS_AND_HOLES outersAndHoles;
@ -650,7 +649,7 @@ void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks( const SHAPE_POLY_S
if( !outersAndHoles.m_Outers.empty() ) if( !outersAndHoles.m_Outers.empty() )
{ {
aDstContainer.Add( new CPOLYGONBLOCK2D( extractedSegments, outersAndHoles, aDstContainer.Add( new POLYGON_2D( extractedSegments, outersAndHoles,
aBoardItem ) ); aBoardItem ) );
stats_n_poly_blocks++; stats_n_poly_blocks++;
} }
@ -693,8 +692,7 @@ static void polygon_Convert( const ClipperLib::Path& aPath, SEGMENTS& aOutSegmen
void Polygon2d_TestModule() void Polygon2d_TestModule()
{ {
// "This structure contains a sequence of IntPoint vertices defining a // "This structure contains a sequence of IntPoint vertices defining a single contour"
// single contour"
ClipperLib::Path aPath; ClipperLib::Path aPath;
SEGMENTS aSegments; SEGMENTS aSegments;

View File

@ -91,19 +91,19 @@ typedef struct
* There is information for the contours (used to test the ray2d intersection) and a close * There is information for the contours (used to test the ray2d intersection) and a close
* definition of the block polygon to test if a point is inside. * definition of the block polygon to test if a point is inside.
*/ */
class CPOLYGONBLOCK2D : public COBJECT2D class POLYGON_2D : public OBJECT_2D
{ {
public: public:
CPOLYGONBLOCK2D( const SEGMENTS_WIDTH_NORMALS &aOpenSegmentList, POLYGON_2D( const SEGMENTS_WIDTH_NORMALS& aOpenSegmentList,
const OUTERS_AND_HOLES &aOuter_and_holes, const OUTERS_AND_HOLES& aOuter_and_holes,
const BOARD_ITEM &aBoardItem ); const BOARD_ITEM& aBoardItem );
// Imported from COBJECT2D // Imported from OBJECT_2D
bool Overlaps( const CBBOX2D &aBBox ) const override; bool Overlaps( const BBOX_2D& aBBox ) const override;
bool Intersects( const CBBOX2D &aBBox ) const override; bool Intersects( const BBOX_2D& aBBox ) const override;
bool Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const override; bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const override; INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
bool IsPointInside( const SFVEC2F &aPoint ) const override; bool IsPointInside( const SFVEC2F& aPoint ) const override;
private: private:
/** /**
@ -124,29 +124,27 @@ private:
* *
* If the point is inside the bounding box it will return always true. However, the * If the point is inside the bounding box it will return always true. However, the
* intersection with a ray will return always false. This is used as a sub block * intersection with a ray will return always false. This is used as a sub block
* extracted from polygon (pcb polygon areas) and represents an area that is full filled. * extracted from polygon (pcb polygon areas) and represents an area that is fully filled.
*/ */
class CDUMMYBLOCK2D : public COBJECT2D class DUMMY_BLOCK_2D : public OBJECT_2D
{ {
public: public:
CDUMMYBLOCK2D( const SFVEC2F &aPbMin, DUMMY_BLOCK_2D( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax, const BOARD_ITEM& aBoardItem );
const SFVEC2F &aPbMax,
const BOARD_ITEM &aBoardItem );
CDUMMYBLOCK2D( const CBBOX2D &aBBox, const BOARD_ITEM &aBoardItem ); DUMMY_BLOCK_2D( const BBOX_2D& aBBox, const BOARD_ITEM& aBoardItem );
// Imported from COBJECT2D // Imported from OBJECT_2D
bool Overlaps( const CBBOX2D &aBBox ) const override; bool Overlaps( const BBOX_2D& aBBox ) const override;
bool Intersects( const CBBOX2D &aBBox ) const override; bool Intersects( const BBOX_2D& aBBox ) const override;
bool Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const override; bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const override; INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
bool IsPointInside( const SFVEC2F &aPoint ) const override; bool IsPointInside( const SFVEC2F& aPoint ) const override;
}; };
/** /**
* Use a polygon in the format of the ClipperLib::Path and process it and create multiple 2d * Use a polygon in the format of the ClipperLib::Path and process it and create multiple 2d
* objects (CPOLYGONBLOCK2D and CDUMMYBLOCK2D) that can be used to represent this polygon area. * objects (POLYGON_2D and DUMMY_BLOCK_2D) that can be used to represent this polygon area.
* *
* @param aMainPath the polygon are that was converted from the pcb board * @param aMainPath the polygon are that was converted from the pcb board
* @param aDstContainer the destination container to put the created sub blocks * @param aDstContainer the destination container to put the created sub blocks
@ -155,11 +153,11 @@ public:
* 0.0f will use the internal polygon segm statistics * 0.0f will use the internal polygon segm statistics
*/ */
void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks( void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(
const SHAPE_POLY_SET &aMainPath, const SHAPE_POLY_SET& aMainPath,
CGENERICCONTAINER2D &aDstContainer, CONTAINER_2D_BASE& aDstContainer,
float aBiuTo3DunitsScale, float aBiuTo3DunitsScale,
float aDivFactor, float aDivFactor,
const BOARD_ITEM &aBoardItem, const BOARD_ITEM& aBoardItem,
int aPolyIndex ); int aPolyIndex );
void Polygon2d_TestModule(); void Polygon2d_TestModule();

View File

@ -31,24 +31,14 @@
#include <wx/debug.h> #include <wx/debug.h>
CPOLYGON4PTS2D::CPOLYGON4PTS2D( const SFVEC2F& v1, const SFVEC2F& v2, const SFVEC2F& v3, POLYGON_4PT_2D::POLYGON_4PT_2D( const SFVEC2F& v1, const SFVEC2F& v2, const SFVEC2F& v3,
const SFVEC2F& v4, const BOARD_ITEM& aBoardItem ) : const SFVEC2F& v4, const BOARD_ITEM& aBoardItem ) :
COBJECT2D( OBJECT2D_TYPE::POLYGON4PT, aBoardItem ) OBJECT_2D( OBJECT_2D_TYPE::POLYGON4PT, aBoardItem )
{ /* {
if( (v1.x > v2.x) || (v1.y < v2.y) )
{
m_segments[0] = v4;
m_segments[1] = v3;
m_segments[2] = v2;
m_segments[3] = v1;
}
else
{*/
m_segments[0] = v1; m_segments[0] = v1;
m_segments[1] = v4; m_segments[1] = v4;
m_segments[2] = v3; m_segments[2] = v3;
m_segments[3] = v2; m_segments[3] = v2;
// }
unsigned int i; unsigned int i;
unsigned int j = 4 - 1; unsigned int j = 4 - 1;
@ -76,63 +66,20 @@ CPOLYGON4PTS2D::CPOLYGON4PTS2D( const SFVEC2F& v1, const SFVEC2F& v2, const SFVE
} }
bool CPOLYGON4PTS2D::Intersects( const CBBOX2D& aBBox ) const bool POLYGON_4PT_2D::Intersects( const BBOX_2D& aBBox ) const
{ {
return m_bbox.Intersects( aBBox ); return m_bbox.Intersects( aBBox );
// This source code is not working OK.
/*
if( !m_bbox.Intersects( aBBox ) )
return false;
// Check if the bounding box complety have inside the small bounding box
if( (aBBox.Max().x > m_bbox.Max().x) &&
(aBBox.Max().y > m_bbox.Max().x) &&
(aBBox.Min().x < m_bbox.Min().x) &&
(aBBox.Min().y < m_bbox.Min().y)
)
return true;
SFVEC2F v[4];
v[0] = aBBox.Min();
v[1] = SFVEC2F( aBBox.Min().x, aBBox.Max().y );
v[2] = aBBox.Max();
v[3] = SFVEC2F( aBBox.Max().x, aBBox.Min().y );
for( unsigned int i = 0; i < 4; i++ )
{
if( IntersectSegment( m_segments[i], m_precalc_slope[i], v[0], v[1] - v[0] ) )
return true;
if( IntersectSegment( m_segments[i], m_precalc_slope[i], v[1], v[2] - v[1] ) )
return true;
if( IntersectSegment( m_segments[i], m_precalc_slope[i], v[2], v[3] - v[2] ) )
return true;
if( IntersectSegment( m_segments[i], m_precalc_slope[i], v[3], v[0] - v[3] ) )
return true;
}
if( IsPointInside( v[0] ) )
return true;
if( IsPointInside( v[1] ) )
return true;
if( IsPointInside( v[2] ) )
return true;
if( IsPointInside( v[3] ) )
return true;
return false;*/
} }
bool CPOLYGON4PTS2D::Overlaps( const CBBOX2D& aBBox ) const bool POLYGON_4PT_2D::Overlaps( const BBOX_2D& aBBox ) const
{ {
// NOT IMPLEMENTED // NOT IMPLEMENTED
return true; return true;
} }
bool CPOLYGON4PTS2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const bool POLYGON_4PT_2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const
{ {
bool hited = false; bool hited = false;
unsigned int hitIndex; unsigned int hitIndex;
@ -170,7 +117,7 @@ bool CPOLYGON4PTS2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F*
} }
INTERSECTION_RESULT CPOLYGON4PTS2D::IsBBoxInside( const CBBOX2D& aBBox ) const INTERSECTION_RESULT POLYGON_4PT_2D::IsBBoxInside( const BBOX_2D& aBBox ) const
{ {
// !TODO: // !TODO:
@ -178,7 +125,7 @@ INTERSECTION_RESULT CPOLYGON4PTS2D::IsBBoxInside( const CBBOX2D& aBBox ) const
} }
bool CPOLYGON4PTS2D::IsPointInside( const SFVEC2F& aPoint ) const bool POLYGON_4PT_2D::IsPointInside( const SFVEC2F& aPoint ) const
{ {
unsigned int i; unsigned int i;
unsigned int j = 4 - 1; unsigned int j = 4 - 1;

View File

@ -27,8 +27,8 @@
* @brief A simplified 4 point polygon * @brief A simplified 4 point polygon
*/ */
#ifndef _CPOLYGON4PTS2D_H_ #ifndef _POLYGON_4PT_2D_H_
#define _CPOLYGON4PTS2D_H_ #define _POLYGON_4PT_2D_H_
#include "cobject2d.h" #include "cobject2d.h"
@ -38,31 +38,27 @@
* Used for footprint pads. (rectangles, trapezoids, with rotation.etc). This is a * Used for footprint pads. (rectangles, trapezoids, with rotation.etc). This is a
* simplified version of the #CPOLYGON2D class. * simplified version of the #CPOLYGON2D class.
*/ */
class CPOLYGON4PTS2D : public COBJECT2D class POLYGON_4PT_2D : public OBJECT_2D
{ {
public: public:
CPOLYGON4PTS2D( const SFVEC2F &v1, POLYGON_4PT_2D( const SFVEC2F& v1, const SFVEC2F& v2, const SFVEC2F& v3, const SFVEC2F& v4,
const SFVEC2F &v2, const BOARD_ITEM& aBoardItem );
const SFVEC2F &v3,
const SFVEC2F &v4,
const BOARD_ITEM &aBoardItem );
const SFVEC2F &GetV0() const { return m_segments[0]; } const SFVEC2F& GetV0() const { return m_segments[0]; }
const SFVEC2F &GetV1() const { return m_segments[1]; } const SFVEC2F& GetV1() const { return m_segments[1]; }
const SFVEC2F &GetV2() const { return m_segments[2]; } const SFVEC2F& GetV2() const { return m_segments[2]; }
const SFVEC2F &GetV3() const { return m_segments[3]; } const SFVEC2F& GetV3() const { return m_segments[3]; }
const SFVEC2F &GetN0() const { return m_seg_normal[0]; } const SFVEC2F& GetN0() const { return m_seg_normal[0]; }
const SFVEC2F &GetN1() const { return m_seg_normal[1]; } const SFVEC2F& GetN1() const { return m_seg_normal[1]; }
const SFVEC2F &GetN2() const { return m_seg_normal[2]; } const SFVEC2F& GetN2() const { return m_seg_normal[2]; }
const SFVEC2F &GetN3() const { return m_seg_normal[3]; } const SFVEC2F& GetN3() const { return m_seg_normal[3]; }
// Imported from COBJECT2D bool Overlaps( const BBOX_2D& aBBox ) const override;
bool Overlaps( const CBBOX2D &aBBox ) const override; bool Intersects( const BBOX_2D& aBBox ) const override;
bool Intersects( const CBBOX2D &aBBox ) const override; bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
bool Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const override; INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const override; bool IsPointInside( const SFVEC2F& aPoint ) const override;
bool IsPointInside( const SFVEC2F &aPoint ) const override;
private: private:
SFVEC2F m_segments[4]; SFVEC2F m_segments[4];
@ -71,4 +67,4 @@ private:
}; };
#endif // _CPOLYGON4PTS2D_H_ #endif // _POLYGON_4PT_2D_H_

View File

@ -32,9 +32,9 @@
#include <wx/debug.h> #include <wx/debug.h>
CRING2D::CRING2D( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius, RING_2D::RING_2D( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
const BOARD_ITEM& aBoardItem ) : const BOARD_ITEM& aBoardItem ) :
COBJECT2D( OBJECT2D_TYPE::RING, aBoardItem ) OBJECT_2D( OBJECT_2D_TYPE::RING, aBoardItem )
{ {
wxASSERT( aInnerRadius < aOuterRadius ); wxASSERT( aInnerRadius < aOuterRadius );
@ -55,30 +55,28 @@ CRING2D::CRING2D( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius
} }
bool CRING2D::Overlaps( const CBBOX2D &aBBox ) const bool RING_2D::Overlaps( const BBOX_2D& aBBox ) const
{ {
// NOT IMPLEMENTED // NOT IMPLEMENTED, why?
return false; return false;
} }
bool CRING2D::Intersects( const CBBOX2D &aBBox ) const bool RING_2D::Intersects( const BBOX_2D& aBBox ) const
{ {
// !TODO: check the inside for a great improvement // !TODO: check the inside for a great improvement
return aBBox.Intersects( m_center, m_outer_radius_squared ); return aBBox.Intersects( m_center, m_outer_radius_squared );
} }
bool CRING2D::Intersect( const RAYSEG2D &aSegRay, bool RING_2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const
float *aOutT,
SFVEC2F *aNormalOut ) const
{ {
// This code used directly from Steve Marschner's CS667 framework // This code used directly from Steve Marschner's CS667 framework
// http://cs665pd.googlecode.com/svn/trunk/photon/sphere.cpp // http://cs665pd.googlecode.com/svn/trunk/photon/sphere.cpp
// Compute some factors used in computation // Compute some factors used in computation
const float qx = (aSegRay.m_Start.x - m_center.x); const float qx = ( aSegRay.m_Start.x - m_center.x );
const float qy = (aSegRay.m_Start.y - m_center.y); const float qy = ( aSegRay.m_Start.y - m_center.y );
const float qd = qx * aSegRay.m_Dir.x + qy * aSegRay.m_Dir.y; const float qd = qx * aSegRay.m_Dir.x + qy * aSegRay.m_Dir.y;
const float qq = qx * qx + qy * qy; const float qq = qx * qx + qy * qy;
@ -95,9 +93,9 @@ bool CRING2D::Intersect( const RAYSEG2D &aSegRay,
// Otherwise check and make sure that the intersections occur on the ray (t // Otherwise check and make sure that the intersections occur on the ray (t
// > 0) and return the closer one // > 0) and return the closer one
const float discriminant = sqrt( discriminantsqr_outer ); const float discriminant = sqrt( discriminantsqr_outer );
float t = (-qd - discriminant); float t = ( -qd - discriminant );
if( (t > FLT_EPSILON) && (t < aSegRay.m_Length) ) if( ( t > FLT_EPSILON ) && ( t < aSegRay.m_Length ) )
{ {
if( aNormalOut ) if( aNormalOut )
{ {
@ -113,9 +111,9 @@ bool CRING2D::Intersect( const RAYSEG2D &aSegRay,
{ {
const float discriminant_inner = sqrt( discriminantsqr_inter ); const float discriminant_inner = sqrt( discriminantsqr_inter );
const float t2_inner = (-qd + discriminant_inner); const float t2_inner = ( -qd + discriminant_inner );
if( (t2_inner > FLT_EPSILON) && (t2_inner < aSegRay.m_Length) ) if( ( t2_inner > FLT_EPSILON ) && ( t2_inner < aSegRay.m_Length ) )
{ {
t = t2_inner; t = t2_inner;
@ -123,7 +121,7 @@ bool CRING2D::Intersect( const RAYSEG2D &aSegRay,
{ {
const SFVEC2F hitPoint = aSegRay.at( t2_inner ); const SFVEC2F hitPoint = aSegRay.at( t2_inner );
*aNormalOut = (m_center - hitPoint) / m_inner_radius; *aNormalOut = ( m_center - hitPoint ) / m_inner_radius;
} }
} }
else else
@ -147,58 +145,19 @@ bool CRING2D::Intersect( const RAYSEG2D &aSegRay,
} }
INTERSECTION_RESULT CRING2D::IsBBoxInside( const CBBOX2D &aBBox ) const INTERSECTION_RESULT RING_2D::IsBBoxInside( const BBOX_2D& aBBox ) const
{ {
/*
if( !m_bbox.Overlaps( aBBox ) )
return INTERSECTION_RESULT::MISSES;
SFVEC2F v[4];
v[0] = aBBox.Min() - m_center;
v[1] = aBBox.Max() - m_center;
v[2] = SFVEC2F( aBBox.Min().x, aBBox.Max().y ) - m_center;
v[3] = SFVEC2F( aBBox.Max().x, aBBox.Min().y ) - m_center;
float s[4];
s[0] = v[0].x * v[0].x + v[0].y * v[0].y;
s[1] = v[1].x * v[1].x + v[1].y * v[1].y;
s[2] = v[2].x * v[2].x + v[2].y * v[2].y;
s[3] = v[3].x * v[3].x + v[3].y * v[3].y;
bool isInside[4];
isInside[0] = s[0] <= m_radius_squared;
isInside[1] = s[1] <= m_radius_squared;
isInside[2] = s[2] <= m_radius_squared;
isInside[3] = s[3] <= m_radius_squared;
// Check if all points are inside the circle
if( isInside[0] &&
isInside[1] &&
isInside[2] &&
isInside[3] )
return INTERSECTION_RESULT::FULL_INSIDE;
// Check if any point is inside the circle
if( isInside[0] ||
isInside[1] ||
isInside[2] ||
isInside[3] )
return INTERSECTION_RESULT::INTERSECTS;
*/
return INTERSECTION_RESULT::MISSES; return INTERSECTION_RESULT::MISSES;
} }
bool CRING2D::IsPointInside( const SFVEC2F &aPoint ) const bool RING_2D::IsPointInside( const SFVEC2F& aPoint ) const
{ {
const SFVEC2F v = m_center - aPoint; const SFVEC2F v = m_center - aPoint;
const float dot = glm::dot( v, v ); const float dot = glm::dot( v, v );
if( (dot <= m_outer_radius_squared) && (dot >= m_inner_radius_squared) ) if( ( dot <= m_outer_radius_squared ) && ( dot >= m_inner_radius_squared ) )
return true; return true;
return false; return false;

View File

@ -27,25 +27,25 @@
* @brief * @brief
*/ */
#ifndef _CRING2D_H_ #ifndef _RING_2D_H_
#define _CRING2D_H_ #define _RING_2D_H_
#include "cobject2d.h" #include "cobject2d.h"
class CRING2D : public COBJECT2D class RING_2D : public OBJECT_2D
{ {
public: public:
CRING2D( const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, RING_2D( const SFVEC2F& aCenter, float aInnerRadius, float aOuterRadius,
const BOARD_ITEM &aBoardItem ); const BOARD_ITEM& aBoardItem );
// Imported from COBJECT2D // Imported from OBJECT_2D
bool Overlaps( const CBBOX2D &aBBox ) const override; bool Overlaps( const BBOX_2D& aBBox ) const override;
bool Intersects( const CBBOX2D &aBBox ) const override; bool Intersects( const BBOX_2D& aBBox ) const override;
bool Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const override; bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const override; INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
bool IsPointInside( const SFVEC2F &aPoint ) const override; bool IsPointInside( const SFVEC2F& aPoint ) const override;
const SFVEC2F &GetCenter() const { return m_center; } const SFVEC2F& GetCenter() const { return m_center; }
float GetInnerRadius() const { return m_inner_radius; } float GetInnerRadius() const { return m_inner_radius; }
float GetOuterRadius() const { return m_outer_radius; } float GetOuterRadius() const { return m_outer_radius; }
@ -61,4 +61,4 @@ private:
}; };
#endif // _CRING2D_H_ #endif // _RING_2D_H_

View File

@ -31,9 +31,9 @@
#include <wx/debug.h> #include <wx/debug.h>
CROUNDSEGMENT2D::CROUNDSEGMENT2D( const SFVEC2F& aStart, const SFVEC2F& aEnd, float aWidth, ROUND_SEGMENT_2D::ROUND_SEGMENT_2D( const SFVEC2F& aStart, const SFVEC2F& aEnd, float aWidth,
const BOARD_ITEM& aBoardItem ) : const BOARD_ITEM& aBoardItem ) :
COBJECT2D( OBJECT2D_TYPE::ROUNDSEG, aBoardItem ), OBJECT_2D( OBJECT_2D_TYPE::ROUNDSEG, aBoardItem ),
m_segment( aStart, aEnd ) m_segment( aStart, aEnd )
{ {
wxASSERT( aStart != aEnd ); wxASSERT( aStart != aEnd );
@ -49,8 +49,7 @@ CROUNDSEGMENT2D::CROUNDSEGMENT2D( const SFVEC2F& aStart, const SFVEC2F& aEnd, fl
m_leftEndMinusStart = m_leftEnd - m_leftStart; m_leftEndMinusStart = m_leftEnd - m_leftStart;
m_leftDir = glm::normalize( m_leftEndMinusStart ); m_leftDir = glm::normalize( m_leftEndMinusStart );
SFVEC2F rightRadiusOffset( -leftRadiusOffset.x, SFVEC2F rightRadiusOffset( -leftRadiusOffset.x, -leftRadiusOffset.y );
-leftRadiusOffset.y );
m_rightStart = aEnd + rightRadiusOffset; m_rightStart = aEnd + rightRadiusOffset;
m_rightEnd = aStart + rightRadiusOffset; m_rightEnd = aStart + rightRadiusOffset;
m_rightEndMinusStart = m_rightEnd - m_rightStart; m_rightEndMinusStart = m_rightEnd - m_rightStart;
@ -67,7 +66,7 @@ CROUNDSEGMENT2D::CROUNDSEGMENT2D( const SFVEC2F& aStart, const SFVEC2F& aEnd, fl
} }
bool CROUNDSEGMENT2D::Intersects( const CBBOX2D &aBBox ) const bool ROUND_SEGMENT_2D::Intersects( const BBOX_2D& aBBox ) const
{ {
if( !m_bbox.Intersects( aBBox ) ) if( !m_bbox.Intersects( aBBox ) )
return false; return false;
@ -96,7 +95,6 @@ bool CROUNDSEGMENT2D::Intersects( const CBBOX2D &aBBox ) const
if( IntersectSegment( m_leftStart, m_leftEndMinusStart, v[3], v[0] - v[3] ) ) if( IntersectSegment( m_leftStart, m_leftEndMinusStart, v[3], v[0] - v[3] ) )
return true; return true;
if( IntersectSegment( m_rightStart, m_rightEndMinusStart, v[0], v[1] - v[0] ) ) if( IntersectSegment( m_rightStart, m_rightEndMinusStart, v[0], v[1] - v[0] ) )
return true; return true;
@ -120,16 +118,14 @@ bool CROUNDSEGMENT2D::Intersects( const CBBOX2D &aBBox ) const
} }
bool CROUNDSEGMENT2D::Overlaps( const CBBOX2D &aBBox ) const bool ROUND_SEGMENT_2D::Overlaps( const BBOX_2D& aBBox ) const
{ {
// NOT IMPLEMENTED // NOT IMPLEMENTED
return false; return false;
} }
bool CROUNDSEGMENT2D::Intersect( const RAYSEG2D &aSegRay, bool ROUND_SEGMENT_2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const
float *aOutT,
SFVEC2F *aNormalOut ) const
{ {
const bool start_is_inside = IsPointInside( aSegRay.m_Start ); const bool start_is_inside = IsPointInside( aSegRay.m_Start );
const bool end_is_inside = IsPointInside( aSegRay.m_End ); const bool end_is_inside = IsPointInside( aSegRay.m_End );
@ -147,8 +143,7 @@ bool CROUNDSEGMENT2D::Intersect( const RAYSEG2D &aSegRay,
SFVEC2F farHitNormal; SFVEC2F farHitNormal;
float leftSegT; float leftSegT;
const bool leftSegmentHit = aSegRay.IntersectSegment( m_leftStart, const bool leftSegmentHit = aSegRay.IntersectSegment( m_leftStart, m_leftEndMinusStart,
m_leftEndMinusStart,
&leftSegT ); &leftSegT );
if( leftSegmentHit ) if( leftSegmentHit )
@ -162,8 +157,7 @@ bool CROUNDSEGMENT2D::Intersect( const RAYSEG2D &aSegRay,
} }
float rightSegT; float rightSegT;
const bool rightSegmentHit = aSegRay.IntersectSegment( m_rightStart, const bool rightSegmentHit = aSegRay.IntersectSegment( m_rightStart, m_rightEndMinusStart,
m_rightEndMinusStart,
&rightSegT ); &rightSegT );
if( rightSegmentHit ) if( rightSegmentHit )
@ -203,7 +197,7 @@ bool CROUNDSEGMENT2D::Intersect( const RAYSEG2D &aSegRay,
{ {
if( !start_is_inside ) if( !start_is_inside )
{ {
if( (hitted == false) || (circleStart_T0 < closerHitT) ) if( ( hitted == false ) || ( circleStart_T0 < closerHitT ) )
{ {
closerHitT = circleStart_T0; closerHitT = circleStart_T0;
closerHitNormal = circleStart_N0; closerHitNormal = circleStart_N0;
@ -211,7 +205,7 @@ bool CROUNDSEGMENT2D::Intersect( const RAYSEG2D &aSegRay,
} }
else else
{ {
if( (hitted == false) || (circleStart_T1 > farHitT) ) if( ( hitted == false ) || ( circleStart_T1 > farHitT ) )
{ {
farHitT = circleStart_T1; farHitT = circleStart_T1;
farHitNormal = circleStart_N1; farHitNormal = circleStart_N1;
@ -221,7 +215,7 @@ bool CROUNDSEGMENT2D::Intersect( const RAYSEG2D &aSegRay,
else else
{ {
// This can only happen if the ray starts inside // This can only happen if the ray starts inside
if( (hitted == false) || (circleStart_T1 > farHitT) ) if( ( hitted == false ) || ( circleStart_T1 > farHitT ) )
{ {
farHitT = circleStart_T1; farHitT = circleStart_T1;
farHitNormal = circleStart_N1; farHitNormal = circleStart_N1;
@ -245,7 +239,7 @@ bool CROUNDSEGMENT2D::Intersect( const RAYSEG2D &aSegRay,
{ {
if( !start_is_inside ) if( !start_is_inside )
{ {
if( (hitted == false) || (circleEnd_T0 < closerHitT) ) if( ( hitted == false ) || ( circleEnd_T0 < closerHitT ) )
{ {
closerHitT = circleEnd_T0; closerHitT = circleEnd_T0;
closerHitNormal = circleEnd_N0; closerHitNormal = circleEnd_N0;
@ -253,7 +247,7 @@ bool CROUNDSEGMENT2D::Intersect( const RAYSEG2D &aSegRay,
} }
else else
{ {
if( (hitted == false) || (circleEnd_T1 > farHitT) ) if( ( hitted == false ) || ( circleEnd_T1 > farHitT ) )
{ {
farHitT = circleEnd_T1; farHitT = circleEnd_T1;
farHitNormal = circleEnd_N1; farHitNormal = circleEnd_N1;
@ -263,7 +257,7 @@ bool CROUNDSEGMENT2D::Intersect( const RAYSEG2D &aSegRay,
else else
{ {
// This can only happen if the ray starts inside // This can only happen if the ray starts inside
if( (hitted == false) || (circleEnd_T1 > farHitT) ) if( ( hitted == false ) || ( circleEnd_T1 > farHitT ) )
{ {
farHitT = circleEnd_T1; farHitT = circleEnd_T1;
farHitNormal = circleEnd_N1; farHitNormal = circleEnd_N1;
@ -300,7 +294,7 @@ bool CROUNDSEGMENT2D::Intersect( const RAYSEG2D &aSegRay,
} }
INTERSECTION_RESULT CROUNDSEGMENT2D::IsBBoxInside( const CBBOX2D &aBBox ) const INTERSECTION_RESULT ROUND_SEGMENT_2D::IsBBoxInside( const BBOX_2D &aBBox ) const
{ {
if( !m_bbox.Intersects( aBBox ) ) if( !m_bbox.Intersects( aBBox ) )
return INTERSECTION_RESULT::MISSES; return INTERSECTION_RESULT::MISSES;
@ -331,7 +325,7 @@ INTERSECTION_RESULT CROUNDSEGMENT2D::IsBBoxInside( const CBBOX2D &aBBox ) const
} }
bool CROUNDSEGMENT2D::IsPointInside( const SFVEC2F &aPoint ) const bool ROUND_SEGMENT_2D::IsPointInside( const SFVEC2F& aPoint ) const
{ {
float dSquared = m_segment.DistanceToPointSquared( aPoint ); float dSquared = m_segment.DistanceToPointSquared( aPoint );

View File

@ -24,50 +24,47 @@
/** /**
* @file croundsegment2d.h * @file croundsegment2d.h
* @brief
*/ */
#ifndef _CROUNDSEGMENT2D_H_ #ifndef _ROUND_SEGMENT_2D_H_
#define _CROUNDSEGMENT2D_H_ #define _ROUND_SEGMENT_2D_H_
#include "cobject2d.h" #include "cobject2d.h"
class CROUNDSEGMENT2D : public COBJECT2D class ROUND_SEGMENT_2D : public OBJECT_2D
{ {
friend class CROUNDSEG;
public: public:
CROUNDSEGMENT2D( const SFVEC2F &aStart, const SFVEC2F &aEnd, float aWidth, ROUND_SEGMENT_2D( const SFVEC2F& aStart, const SFVEC2F& aEnd, float aWidth,
const BOARD_ITEM &aBoardItem ); const BOARD_ITEM& aBoardItem );
float GetRadius() const { return m_radius; } float GetRadius() const { return m_radius; }
float GetRadiusSquared() const { return m_radius_squared; } float GetRadiusSquared() const { return m_radius_squared; }
float GetWidth() const { return m_width; } float GetWidth() const { return m_width; }
float GetLength() const { return m_segment.m_Length; } float GetLength() const { return m_segment.m_Length; }
const SFVEC2F &GetStart() const { return m_segment.m_Start; } const SFVEC2F& GetStart() const { return m_segment.m_Start; }
const SFVEC2F &GetEnd() const { return m_segment.m_End; } const SFVEC2F& GetEnd() const { return m_segment.m_End; }
const SFVEC2F &GetEnd_minus_Start() const { return m_segment.m_End_minus_start; } const SFVEC2F& GetEnd_minus_Start() const { return m_segment.m_End_minus_start; }
const SFVEC2F &GetLeftStar() const { return m_leftStart; } const SFVEC2F& GetLeftStar() const { return m_leftStart; }
const SFVEC2F &GetLeftEnd() const { return m_leftEnd; } const SFVEC2F& GetLeftEnd() const { return m_leftEnd; }
const SFVEC2F &GetLeftEnd_minus_Start() const { return m_leftEndMinusStart; } const SFVEC2F& GetLeftEnd_minus_Start() const { return m_leftEndMinusStart; }
const SFVEC2F &GetLeftDir() const { return m_leftDir; } const SFVEC2F& GetLeftDir() const { return m_leftDir; }
const SFVEC2F &GetRightStar() const { return m_rightStart; } const SFVEC2F& GetRightStar() const { return m_rightStart; }
const SFVEC2F &GetRightEnd() const { return m_rightEnd; } const SFVEC2F& GetRightEnd() const { return m_rightEnd; }
const SFVEC2F &GetRightEnd_minus_Start() const { return m_rightEndMinusStart; } const SFVEC2F& GetRightEnd_minus_Start() const { return m_rightEndMinusStart; }
const SFVEC2F &GetRightDir() const { return m_rightDir; } const SFVEC2F& GetRightDir() const { return m_rightDir; }
// Imported from COBJECT2D bool Overlaps( const BBOX_2D& aBBox ) const override;
bool Overlaps( const CBBOX2D &aBBox ) const override; bool Intersects( const BBOX_2D& aBBox ) const override;
bool Intersects( const CBBOX2D &aBBox ) const override; bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
bool Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const override; INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const override; bool IsPointInside( const SFVEC2F& aPoint ) const override;
bool IsPointInside( const SFVEC2F &aPoint ) const override;
private: private:
friend class ROUND_SEGMENT;
RAYSEG2D m_segment; RAYSEG2D m_segment;
SFVEC2F m_leftStart; SFVEC2F m_leftStart;
@ -85,7 +82,7 @@ private:
float m_width; float m_width;
}; };
static const float s_min_dot = (FLT_EPSILON * 4.0f * FLT_EPSILON * 4.0f) ; static const float s_min_dot = ( FLT_EPSILON * 4.0f * FLT_EPSILON * 4.0f );
/** /**
* Check if segment start and end is very close to each other. * Check if segment start and end is very close to each other.
@ -94,7 +91,7 @@ static const float s_min_dot = (FLT_EPSILON * 4.0f * FLT_EPSILON * 4.0f) ;
* *
* @return true is it is better to convert the segment to circle * @return true is it is better to convert the segment to circle
*/ */
inline bool Is_segment_a_circle( const SFVEC2F &aStart, const SFVEC2F &aEnd ) inline bool Is_segment_a_circle( const SFVEC2F& aStart, const SFVEC2F& aEnd )
{ {
const SFVEC2F vec = aEnd - aStart; const SFVEC2F vec = aEnd - aStart;
@ -104,4 +101,4 @@ inline bool Is_segment_a_circle( const SFVEC2F &aStart, const SFVEC2F &aEnd )
( glm::dot( vec, vec ) <= s_min_dot ); ( glm::dot( vec, vec ) <= s_min_dot );
} }
#endif // _CROUNDSEGMENT2D_H_ #endif // _ROUND_SEGMENT_2D_H_

View File

@ -39,9 +39,9 @@
#include "../../../3d_fastmath.h" #include "../../../3d_fastmath.h"
CTRIANGLE2D::CTRIANGLE2D( const SFVEC2F& aV1, const SFVEC2F& aV2, const SFVEC2F& aV3, TRIANGLE_2D::TRIANGLE_2D( const SFVEC2F& aV1, const SFVEC2F& aV2, const SFVEC2F& aV3,
const BOARD_ITEM& aBoardItem ) : const BOARD_ITEM& aBoardItem ) :
COBJECT2D( OBJECT2D_TYPE::TRIANGLE, aBoardItem ) OBJECT_2D( OBJECT_2D_TYPE::TRIANGLE, aBoardItem )
{ {
p1 = aV1; p1 = aV1;
p2 = aV2; p2 = aV2;
@ -66,7 +66,7 @@ CTRIANGLE2D::CTRIANGLE2D( const SFVEC2F& aV1, const SFVEC2F& aV2, const SFVEC2F&
} }
bool CTRIANGLE2D::Intersects( const CBBOX2D &aBBox ) const bool TRIANGLE_2D::Intersects( const BBOX_2D& aBBox ) const
{ {
if( !m_bbox.Intersects( aBBox ) ) if( !m_bbox.Intersects( aBBox ) )
return false; return false;
@ -76,22 +76,20 @@ bool CTRIANGLE2D::Intersects( const CBBOX2D &aBBox ) const
} }
bool CTRIANGLE2D::Overlaps( const CBBOX2D &aBBox ) const bool TRIANGLE_2D::Overlaps( const BBOX_2D& aBBox ) const
{ {
// NOT IMPLEMENTED // NOT IMPLEMENTED
return false; return false;
} }
bool CTRIANGLE2D::Intersect( const RAYSEG2D &aSegRay, bool TRIANGLE_2D::Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const
float *aOutT,
SFVEC2F *aNormalOut ) const
{ {
return false; return false;
} }
INTERSECTION_RESULT CTRIANGLE2D::IsBBoxInside( const CBBOX2D &aBBox ) const INTERSECTION_RESULT TRIANGLE_2D::IsBBoxInside( const BBOX_2D& aBBox ) const
{ {
if( !m_bbox.Intersects( aBBox ) ) if( !m_bbox.Intersects( aBBox ) )
return INTERSECTION_RESULT::MISSES; return INTERSECTION_RESULT::MISSES;
@ -101,7 +99,7 @@ INTERSECTION_RESULT CTRIANGLE2D::IsBBoxInside( const CBBOX2D &aBBox ) const
} }
bool CTRIANGLE2D::IsPointInside( const SFVEC2F &aPoint ) const bool TRIANGLE_2D::IsPointInside( const SFVEC2F& aPoint ) const
{ {
// http://totologic.blogspot.co.uk/2014/01/accurate-point-in-triangle-test.html // http://totologic.blogspot.co.uk/2014/01/accurate-point-in-triangle-test.html
@ -126,10 +124,10 @@ bool CTRIANGLE2D::IsPointInside( const SFVEC2F &aPoint ) const
} }
void Convert_shape_line_polygon_to_triangles( SHAPE_POLY_SET &aPolyList, void Convert_shape_line_polygon_to_triangles( SHAPE_POLY_SET& aPolyList,
CGENERICCONTAINER2D &aDstContainer, CONTAINER_2D_BASE& aDstContainer,
float aBiuTo3DunitsScale , float aBiuTo3DunitsScale ,
const BOARD_ITEM &aBoardItem ) const BOARD_ITEM& aBoardItem )
{ {
VECTOR2I a; VECTOR2I a;
VECTOR2I b; VECTOR2I b;
@ -146,12 +144,9 @@ void Convert_shape_line_polygon_to_triangles( SHAPE_POLY_SET &aPolyList,
{ {
triPoly->GetTriangle( i, a, b, c ); triPoly->GetTriangle( i, a, b, c );
aDstContainer.Add( new CTRIANGLE2D( SFVEC2F( a.x * conver_d, aDstContainer.Add( new TRIANGLE_2D( SFVEC2F( a.x * conver_d, -a.y * conver_d ),
-a.y * conver_d ), SFVEC2F( b.x * conver_d, -b.y * conver_d ),
SFVEC2F( b.x * conver_d, SFVEC2F( c.x * conver_d, -c.y * conver_d ),
-b.y * conver_d ),
SFVEC2F( c.x * conver_d,
-c.y * conver_d ),
aBoardItem ) ); aBoardItem ) );
} }
} }

View File

@ -24,11 +24,10 @@
/** /**
* @file ctriangle2d.h * @file ctriangle2d.h
* @brief
*/ */
#ifndef _CTRIANGLE2D_H_ #ifndef _TRIANGLE_2D_H_
#define _CTRIANGLE2D_H_ #define _TRIANGLE_2D_H_
#include "cobject2d.h" #include "cobject2d.h"
#include "../accelerators/ccontainer2d.h" #include "../accelerators/ccontainer2d.h"
@ -36,24 +35,22 @@
#include <geometry/shape_poly_set.h> #include <geometry/shape_poly_set.h>
#include <clipper.hpp> #include <clipper.hpp>
class CTRIANGLE2D : public COBJECT2D class TRIANGLE_2D : public OBJECT_2D
{ {
public: public:
CTRIANGLE2D ( const SFVEC2F &aV1, TRIANGLE_2D( const SFVEC2F& aV1, const SFVEC2F& aV2, const SFVEC2F& aV3,
const SFVEC2F &aV2, const BOARD_ITEM& aBoardItem );
const SFVEC2F &aV3,
const BOARD_ITEM &aBoardItem );
const SFVEC2F &GetP1() const { return p1; } const SFVEC2F& GetP1() const { return p1; }
const SFVEC2F &GetP2() const { return p2; } const SFVEC2F& GetP2() const { return p2; }
const SFVEC2F &GetP3() const { return p3; } const SFVEC2F& GetP3() const { return p3; }
// Imported from COBJECT2D // Imported from OBJECT_2D
bool Overlaps( const CBBOX2D &aBBox ) const override; bool Overlaps( const BBOX_2D& aBBox ) const override;
bool Intersects( const CBBOX2D &aBBox ) const override; bool Intersects( const BBOX_2D& aBBox ) const override;
bool Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const override; bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const override; INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
bool IsPointInside( const SFVEC2F &aPoint ) const override; bool IsPointInside( const SFVEC2F& aPoint ) const override;
private: private:
SFVEC2F p1; SFVEC2F p1;
@ -68,8 +65,8 @@ private:
}; };
void Convert_shape_line_polygon_to_triangles( SHAPE_POLY_SET &aPolyList, void Convert_shape_line_polygon_to_triangles( SHAPE_POLY_SET& aPolyList,
CGENERICCONTAINER2D &aDstContainer, CONTAINER_2D_BASE& aDstContainer,
float aBiuTo3DunitsScale, float aBiuTo3DunitsScale,
const BOARD_ITEM &aBoardItem ); const BOARD_ITEM& aBoardItem );
#endif // _CTRIANGLE2D_H_ #endif // _TRIANGLE_2D_H_

View File

@ -34,38 +34,38 @@
#include <wx/debug.h> // For the wxASSERT #include <wx/debug.h> // For the wxASSERT
CBBOX::CBBOX() BBOX_3D::BBOX_3D()
{ {
Reset(); Reset();
} }
CBBOX::CBBOX( const SFVEC3F &aPbInit ) BBOX_3D::BBOX_3D( const SFVEC3F& aPbInit )
{ {
m_min = aPbInit; m_min = aPbInit;
m_max = aPbInit; m_max = aPbInit;
} }
CBBOX::CBBOX( const SFVEC3F &aPbMin, const SFVEC3F &aPbMax ) BBOX_3D::BBOX_3D( const SFVEC3F& aPbMin, const SFVEC3F& aPbMax )
{ {
Set( aPbMin, aPbMax ); Set( aPbMin, aPbMax );
} }
CBBOX::~CBBOX() BBOX_3D::~BBOX_3D()
{ {
} }
void CBBOX::Set( const SFVEC3F &aPoint ) void BBOX_3D::Set( const SFVEC3F& aPoint )
{ {
m_min = aPoint; m_min = aPoint;
m_max = aPoint; m_max = aPoint;
} }
void CBBOX::Set( const SFVEC3F &aPbMin, const SFVEC3F &aPbMax ) void BBOX_3D::Set( const SFVEC3F& aPbMin, const SFVEC3F& aPbMax )
{ {
m_min.x = fminf( aPbMin.x, aPbMax.x ); m_min.x = fminf( aPbMin.x, aPbMax.x );
m_min.y = fminf( aPbMin.y, aPbMax.y ); m_min.y = fminf( aPbMin.y, aPbMax.y );
@ -77,7 +77,7 @@ void CBBOX::Set( const SFVEC3F &aPbMin, const SFVEC3F &aPbMax )
} }
void CBBOX::Set( const CBBOX &aBBox ) void BBOX_3D::Set( const BBOX_3D& aBBox )
{ {
wxASSERT( aBBox.IsInitialized() ); wxASSERT( aBBox.IsInitialized() );
@ -85,25 +85,21 @@ void CBBOX::Set( const CBBOX &aBBox )
} }
bool CBBOX::IsInitialized() const bool BBOX_3D::IsInitialized() const
{ {
return !( ( FLT_MAX == m_min.x) || return !( ( FLT_MAX == m_min.x) || ( FLT_MAX == m_min.y) || ( FLT_MAX == m_min.z) ||
( FLT_MAX == m_min.y) || (-FLT_MAX == m_max.x) || (-FLT_MAX == m_max.y) || (-FLT_MAX == m_max.z) );
( FLT_MAX == m_min.z) ||
(-FLT_MAX == m_max.x) ||
(-FLT_MAX == m_max.y) ||
(-FLT_MAX == m_max.z) );
} }
void CBBOX::Reset() void BBOX_3D::Reset()
{ {
m_min = SFVEC3F( FLT_MAX, FLT_MAX, FLT_MAX ); m_min = SFVEC3F( FLT_MAX, FLT_MAX, FLT_MAX );
m_max = SFVEC3F(-FLT_MAX,-FLT_MAX,-FLT_MAX ); m_max = SFVEC3F(-FLT_MAX,-FLT_MAX,-FLT_MAX );
} }
void CBBOX::Union( const SFVEC3F &aPoint ) void BBOX_3D::Union( const SFVEC3F& aPoint )
{ {
// get the minimum value between the added point and the existent bounding box // get the minimum value between the added point and the existent bounding box
m_min.x = fminf( m_min.x, aPoint.x ); m_min.x = fminf( m_min.x, aPoint.x );
@ -117,7 +113,7 @@ void CBBOX::Union( const SFVEC3F &aPoint )
} }
void CBBOX::Union( const CBBOX &aBBox ) void BBOX_3D::Union( const BBOX_3D& aBBox )
{ {
wxASSERT( aBBox.IsInitialized() ); wxASSERT( aBBox.IsInitialized() );
@ -133,26 +129,26 @@ void CBBOX::Union( const CBBOX &aBBox )
} }
SFVEC3F CBBOX::GetCenter() const SFVEC3F BBOX_3D::GetCenter() const
{ {
return (m_max + m_min) * 0.5f; return ( m_max + m_min ) * 0.5f;
} }
float CBBOX::GetCenter( unsigned int aAxis ) const float BBOX_3D::GetCenter( unsigned int aAxis ) const
{ {
wxASSERT( aAxis < 3 ); wxASSERT( aAxis < 3 );
return (m_max[aAxis] + m_min[aAxis]) * 0.5f; return (m_max[aAxis] + m_min[aAxis]) * 0.5f;
} }
const SFVEC3F CBBOX::GetExtent() const const SFVEC3F BBOX_3D::GetExtent() const
{ {
return m_max - m_min; return m_max - m_min;
} }
unsigned int CBBOX::MaxDimension() const unsigned int BBOX_3D::MaxDimension() const
{ {
unsigned int result = 0; unsigned int result = 0;
@ -160,6 +156,7 @@ unsigned int CBBOX::MaxDimension() const
if( extent.y > extent.x ) if( extent.y > extent.x )
result = 1; result = 1;
if( extent.z > extent.y ) if( extent.z > extent.y )
result = 2; result = 2;
@ -167,7 +164,7 @@ unsigned int CBBOX::MaxDimension() const
} }
float CBBOX::GetMaxDimension() const float BBOX_3D::GetMaxDimension() const
{ {
unsigned int max_dimensions_idx = 0; unsigned int max_dimensions_idx = 0;
@ -175,6 +172,7 @@ float CBBOX::GetMaxDimension() const
if( extent.y > extent.x ) if( extent.y > extent.x )
max_dimensions_idx = 1; max_dimensions_idx = 1;
if( extent.z > extent.y ) if( extent.z > extent.y )
max_dimensions_idx = 2; max_dimensions_idx = 2;
@ -182,29 +180,27 @@ float CBBOX::GetMaxDimension() const
} }
float CBBOX::SurfaceArea() const float BBOX_3D::SurfaceArea() const
{ {
SFVEC3F extent = GetExtent(); SFVEC3F extent = GetExtent();
return 2.0f * ( extent.x * extent.z + return 2.0f * ( extent.x * extent.z + extent.x * extent.y + extent.y * extent.z );
extent.x * extent.y +
extent.y * extent.z );
} }
void CBBOX::Scale( float aScale ) void BBOX_3D::Scale( float aScale )
{ {
wxASSERT( IsInitialized() ); wxASSERT( IsInitialized() );
SFVEC3F scaleV = SFVEC3F( aScale, aScale, aScale ); SFVEC3F scaleV = SFVEC3F( aScale, aScale, aScale );
SFVEC3F centerV = GetCenter(); SFVEC3F centerV = GetCenter();
m_min = (m_min - centerV) * scaleV + centerV; m_min = ( m_min - centerV ) * scaleV + centerV;
m_max = (m_max - centerV) * scaleV + centerV; m_max = ( m_max - centerV ) * scaleV + centerV;
} }
void CBBOX::ScaleNextUp() void BBOX_3D::ScaleNextUp()
{ {
m_min.x = NextFloatDown( m_min.x ); m_min.x = NextFloatDown( m_min.x );
m_min.y = NextFloatDown( m_min.y ); m_min.y = NextFloatDown( m_min.y );
@ -216,7 +212,7 @@ void CBBOX::ScaleNextUp()
} }
void CBBOX::ScaleNextDown() void BBOX_3D::ScaleNextDown()
{ {
m_min.x = NextFloatUp( m_min.x ); m_min.x = NextFloatUp( m_min.x );
m_min.y = NextFloatUp( m_min.y ); m_min.y = NextFloatUp( m_min.y );
@ -228,7 +224,7 @@ void CBBOX::ScaleNextDown()
} }
bool CBBOX::Intersects( const CBBOX &aBBox ) const bool BBOX_3D::Intersects( const BBOX_3D& aBBox ) const
{ {
wxASSERT( IsInitialized() ); wxASSERT( IsInitialized() );
wxASSERT( aBBox.IsInitialized() ); wxASSERT( aBBox.IsInitialized() );
@ -241,7 +237,7 @@ bool CBBOX::Intersects( const CBBOX &aBBox ) const
} }
bool CBBOX::Inside( const SFVEC3F &aPoint ) const bool BBOX_3D::Inside( const SFVEC3F& aPoint ) const
{ {
wxASSERT( IsInitialized() ); wxASSERT( IsInitialized() );
@ -251,7 +247,7 @@ bool CBBOX::Inside( const SFVEC3F &aPoint ) const
} }
float CBBOX::Volume() const float BBOX_3D::Volume() const
{ {
wxASSERT( IsInitialized() ); wxASSERT( IsInitialized() );
@ -261,7 +257,7 @@ float CBBOX::Volume() const
} }
SFVEC3F CBBOX::Offset( const SFVEC3F &p ) const SFVEC3F BBOX_3D::Offset( const SFVEC3F& p ) const
{ {
return (p - m_min) / (m_max - m_min); return (p - m_min) / (m_max - m_min);
} }
@ -270,9 +266,8 @@ SFVEC3F CBBOX::Offset( const SFVEC3F &p ) const
// Intersection code based on the book: // Intersection code based on the book:
// "Physical Based Ray Tracing" (by Matt Pharr and Greg Humphrey) // "Physical Based Ray Tracing" (by Matt Pharr and Greg Humphrey)
// https://github.com/mmp/pbrt-v2/blob/master/src/core/geometry.cpp#L68 // https://github.com/mmp/pbrt-v2/blob/master/src/core/geometry.cpp#L68
// /////////////////////////////////////////////////////////////////////////
#if 0 #if 0
bool CBBOX::Intersect( const RAY &aRay, float *aOutHitt0, float *aOutHitt1 ) const bool BBOX_3D::Intersect( const RAY& aRay, float* aOutHitt0, float* aOutHitt1 ) const
{ {
float t0 = 0.0f; float t0 = 0.0f;
float t1 = FLT_MAX; float t1 = FLT_MAX;
@ -280,8 +275,8 @@ bool CBBOX::Intersect( const RAY &aRay, float *aOutHitt0, float *aOutHitt1 ) con
for( unsigned int i = 0; i < 3; ++i ) for( unsigned int i = 0; i < 3; ++i )
{ {
// Update interval for _i_th bounding box slab // Update interval for _i_th bounding box slab
float tNear = (m_min[i] - aRay.m_Origin[i]) * aRay.m_InvDir[i]; float tNear = ( m_min[i] - aRay.m_Origin[i] ) * aRay.m_InvDir[i];
float tFar = (m_max[i] - aRay.m_Origin[i]) * aRay.m_InvDir[i]; float tFar = ( m_max[i] - aRay.m_Origin[i] ) * aRay.m_InvDir[i];
// Update parametric interval from slab intersection // Update parametric interval from slab intersection
if( tNear > tFar ) if( tNear > tFar )
@ -301,6 +296,7 @@ bool CBBOX::Intersect( const RAY &aRay, float *aOutHitt0, float *aOutHitt1 ) con
if( aOutHitt0 ) if( aOutHitt0 )
*aOutHitt0 = t0; *aOutHitt0 = t0;
if( aOutHitt1 ) if( aOutHitt1 )
*aOutHitt1 = t1; *aOutHitt1 = t1;
@ -308,9 +304,7 @@ bool CBBOX::Intersect( const RAY &aRay, float *aOutHitt0, float *aOutHitt1 ) con
} }
#else #else
// https://github.com/mmp/pbrt-v2/blob/master/src/accelerators/bvh.cpp#L126 // https://github.com/mmp/pbrt-v2/blob/master/src/accelerators/bvh.cpp#L126
bool CBBOX::Intersect( const RAY &aRay, bool BBOX_3D::Intersect( const RAY& aRay, float* aOutHitt0, float* aOutHitt1 ) const
float *aOutHitt0,
float *aOutHitt1 ) const
{ {
wxASSERT( aOutHitt0 ); wxASSERT( aOutHitt0 );
wxASSERT( aOutHitt1 ); wxASSERT( aOutHitt1 );
@ -323,17 +317,17 @@ bool CBBOX::Intersect( const RAY &aRay,
const float tymin = (bounds[ aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y) * aRay.m_InvDir.y; const float tymin = (bounds[ aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y) * aRay.m_InvDir.y;
const float tymax = (bounds[1 - aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y) * aRay.m_InvDir.y; const float tymax = (bounds[1 - aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y) * aRay.m_InvDir.y;
if( (tmin > tymax) || (tymin > tmax) ) if( ( tmin > tymax ) || ( tymin > tmax ) )
return false; return false;
tmin = (tymin > tmin)? tymin : tmin; tmin = ( tymin > tmin ) ? tymin : tmin;
tmax = (tymax < tmax)? tymax : tmax; tmax = ( tymax < tmax ) ? tymax : tmax;
// Check for ray intersection against z slab // Check for ray intersection against z slab
const float tzmin = (bounds[ aRay.m_dirIsNeg[2]].z - aRay.m_Origin.z) * aRay.m_InvDir.z; const float tzmin = (bounds[ aRay.m_dirIsNeg[2]].z - aRay.m_Origin.z) * aRay.m_InvDir.z;
const float tzmax = (bounds[1 - aRay.m_dirIsNeg[2]].z - aRay.m_Origin.z) * aRay.m_InvDir.z; const float tzmax = (bounds[1 - aRay.m_dirIsNeg[2]].z - aRay.m_Origin.z) * aRay.m_InvDir.z;
if( (tmin > tzmax) || (tzmin > tmax) ) if( ( tmin > tzmax ) || ( tzmin > tmax ) )
return false; return false;
tmin = (tzmin > tmin)? tzmin : tmin; tmin = (tzmin > tmin)? tzmin : tmin;
@ -349,15 +343,13 @@ bool CBBOX::Intersect( const RAY &aRay,
#endif #endif
void CBBOX::ApplyTransformation( glm::mat4 aTransformMatrix ) void BBOX_3D::ApplyTransformation( glm::mat4 aTransformMatrix )
{ {
wxASSERT( IsInitialized() ); wxASSERT( IsInitialized() );
const SFVEC3F v1 = SFVEC3F( aTransformMatrix * const SFVEC3F v1 = SFVEC3F( aTransformMatrix * glm::vec4( m_min.x, m_min.y, m_min.z, 1.0f ) );
glm::vec4( m_min.x, m_min.y, m_min.z, 1.0f ) );
const SFVEC3F v2 = SFVEC3F( aTransformMatrix * const SFVEC3F v2 = SFVEC3F( aTransformMatrix * glm::vec4( m_max.x, m_max.y, m_max.z, 1.0f ) );
glm::vec4( m_max.x, m_max.y, m_max.z, 1.0f ) );
Reset(); Reset();
Union( v1 ); Union( v1 );
@ -365,36 +357,28 @@ void CBBOX::ApplyTransformation( glm::mat4 aTransformMatrix )
} }
void CBBOX::ApplyTransformationAA( glm::mat4 aTransformMatrix ) void BBOX_3D::ApplyTransformationAA( glm::mat4 aTransformMatrix )
{ {
wxASSERT( IsInitialized() ); wxASSERT( IsInitialized() );
// apply the transformation matrix for each of vertices of the bounding box // apply the transformation matrix for each of vertices of the bounding box
// and make a union with all vertices // and make a union with all vertices
CBBOX tmpBBox = CBBOX( BBOX_3D tmpBBox = BBOX_3D(
SFVEC3F( aTransformMatrix * SFVEC3F( aTransformMatrix * glm::vec4( m_min.x, m_min.y, m_min.z, 1.0f ) ) );
glm::vec4( m_min.x, m_min.y, m_min.z, 1.0f ) ) ); tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_max.x, m_min.y, m_min.z, 1.0f ) ) );
tmpBBox.Union( SFVEC3F( aTransformMatrix * tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_min.x, m_max.y, m_min.z, 1.0f ) ) );
glm::vec4( m_max.x, m_min.y, m_min.z, 1.0f ) ) ); tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_min.x, m_min.y, m_max.z, 1.0f ) ) );
tmpBBox.Union( SFVEC3F( aTransformMatrix * tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_min.x, m_max.y, m_max.z, 1.0f ) ) );
glm::vec4( m_min.x, m_max.y, m_min.z, 1.0f ) ) ); tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_max.x, m_max.y, m_min.z, 1.0f ) ) );
tmpBBox.Union( SFVEC3F( aTransformMatrix * tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_max.x, m_min.y, m_max.z, 1.0f ) ) );
glm::vec4( m_min.x, m_min.y, m_max.z, 1.0f ) ) ); tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_max.x, m_max.y, m_max.z, 1.0f ) ) );
tmpBBox.Union( SFVEC3F( aTransformMatrix *
glm::vec4( m_min.x, m_max.y, m_max.z, 1.0f ) ) );
tmpBBox.Union( SFVEC3F( aTransformMatrix *
glm::vec4( m_max.x, m_max.y, m_min.z, 1.0f ) ) );
tmpBBox.Union( SFVEC3F( aTransformMatrix *
glm::vec4( m_max.x, m_min.y, m_max.z, 1.0f ) ) );
tmpBBox.Union( SFVEC3F( aTransformMatrix *
glm::vec4( m_max.x, m_max.y, m_max.z, 1.0f ) ) );
m_min = tmpBBox.m_min; m_min = tmpBBox.m_min;
m_max = tmpBBox.m_max; m_max = tmpBBox.m_max;
} }
void CBBOX::debug() const void BBOX_3D::debug() const
{ {
wxLogDebug( "min(%f, %f, %f) - max(%f, %f, %f)\n", m_min.x, m_min.y, m_min.z, wxLogDebug( "min(%f, %f, %f) - max(%f, %f, %f)\n", m_min.x, m_min.y, m_min.z,
m_max.x, m_max.y, m_max.z ); m_max.x, m_max.y, m_max.z );

View File

@ -27,28 +27,28 @@
* @brief Bounding Box class definition * @brief Bounding Box class definition
*/ */
#ifndef _CBBOX_H_ #ifndef _BBOX_3D_H_
#define _CBBOX_H_ #define _BBOX_3D_H_
#include "../ray.h" #include "../ray.h"
/** /**
* Manage a bounding box defined by two SFVEC3F min max points. * Manage a bounding box defined by two SFVEC3F min max points.
*/ */
struct CBBOX struct BBOX_3D
{ {
public: public:
/** /**
* Create with default values a bounding box (not initialized) * Create with default values a bounding box (not initialized)
*/ */
CBBOX(); BBOX_3D();
/** /**
* Initialize a bounding box with a given point. * Initialize a bounding box with a given point.
* *
* @param aPbInit a point for the bounding box initialization. * @param aPbInit a point for the bounding box initialization.
*/ */
explicit CBBOX( const SFVEC3F &aPbInit ); explicit BBOX_3D( const SFVEC3F& aPbInit );
/** /**
* Initialize a bounding box with a minimum and a maximum point. * Initialize a bounding box with a minimum and a maximum point.
@ -56,9 +56,9 @@ public:
* @param aPbMin the minimum point to initialize the bounding box. * @param aPbMin the minimum point to initialize the bounding box.
* @param aPbMax the maximum point to initialize the bounding box. * @param aPbMax the maximum point to initialize the bounding box.
*/ */
CBBOX( const SFVEC3F &aPbMin, const SFVEC3F &aPbMax ); BBOX_3D( const SFVEC3F& aPbMin, const SFVEC3F& aPbMax );
~CBBOX(); ~BBOX_3D();
/** /**
@ -67,9 +67,9 @@ public:
* @param aPbMin the minimum point to initialize the bounding box. * @param aPbMin the minimum point to initialize the bounding box.
* @param aPbMax the maximum point to initialize the bounding box. * @param aPbMax the maximum point to initialize the bounding box.
*/ */
void Set( const SFVEC3F &aPbMin, const SFVEC3F &aPbMax ); void Set( const SFVEC3F& aPbMin, const SFVEC3F& aPbMax );
void Set( const CBBOX &aBBox ); void Set( const BBOX_3D& aBBox );
/** /**
* @brief Set * @brief Set
@ -83,14 +83,14 @@ public:
* *
* @param aPoint the point to be bounded. * @param aPoint the point to be bounded.
*/ */
void Union( const SFVEC3F &aPoint ); void Union( const SFVEC3F& aPoint );
/** /**
* Recalculate the bounding box adding other bounding box. * Recalculate the bounding box adding other bounding box.
* *
* @param aBBox the bounding box to be bounded. * @param aBBox the bounding box to be bounded.
*/ */
void Union( const CBBOX &aBBox ); void Union( const BBOX_3D& aBBox );
/** /**
* Scales a bounding box by its center. * Scales a bounding box by its center.
@ -114,14 +114,14 @@ public:
* *
* @param aBBox the bounding box to check if it intersects. * @param aBBox the bounding box to check if it intersects.
*/ */
bool Intersects( const CBBOX &aBBox ) const; bool Intersects( const BBOX_3D& aBBox ) const;
/** /**
* Check if a point is inside this bounding box. * Check if a point is inside this bounding box.
* *
* @param aPoint point to test. * @param aPoint point to test.
*/ */
bool Inside( const SFVEC3F &aPoint ) const; bool Inside( const SFVEC3F& aPoint ) const;
/** /**
* Apply a transformation matrix to the box points. * Apply a transformation matrix to the box points.
@ -146,7 +146,7 @@ public:
float Volume() const; float Volume() const;
/** /**
* Output this CBBOX to the stdout. * Output this BBOX_3D to the stdout.
*/ */
void debug() const; void debug() const;
@ -179,7 +179,7 @@ public:
/** /**
* @return SFVEC3F - return the offset relative to max-min. * @return SFVEC3F - return the offset relative to max-min.
*/ */
SFVEC3F Offset( const SFVEC3F &p ) const; SFVEC3F Offset( const SFVEC3F& p ) const;
/** /**
* @return SFVEC3F - max-min. * @return SFVEC3F - max-min.
@ -191,14 +191,14 @@ public:
* *
* @return SFVEC3F - the minimum vertex position. * @return SFVEC3F - the minimum vertex position.
*/ */
const SFVEC3F &Min() const { return m_min; } const SFVEC3F& Min() const { return m_min; }
/** /**
* Return the maximum vertex pointer. * Return the maximum vertex pointer.
* *
* @return SFVEC3F - the maximum vertex position. * @return SFVEC3F - the maximum vertex position.
*/ */
const SFVEC3F &Max() const { return m_max; } const SFVEC3F& Max() const { return m_max; }
/** /**
@ -221,9 +221,9 @@ public:
* @param t The distance point of the ray of the intersection (if true). * @param t The distance point of the ray of the intersection (if true).
* @return true if the ray hits the box. * @return true if the ray hits the box.
*/ */
bool Intersect( const RAY &aRay, float *t ) const; bool Intersect( const RAY& aRay, float* t ) const;
bool Intersect( const RAY &aRay ) const; bool Intersect( const RAY& aRay ) const;
/** /**
* Fetch the enter and exit position when a ray starts inside the bounding box. * Fetch the enter and exit position when a ray starts inside the bounding box.
@ -233,7 +233,7 @@ public:
* @param aOutHitt1 The distance point of the ray of the exit (if true). * @param aOutHitt1 The distance point of the ray of the exit (if true).
* @return true if the ray hits the box * @return true if the ray hits the box
*/ */
bool Intersect( const RAY &aRay, float *aOutHitt0, float *aOutHitt1 ) const; bool Intersect( const RAY& aRay, float* aOutHitt0, float* aOutHitt1 ) const;
private: private:
SFVEC3F m_min; ///< (12) point of the lower position of the bounding box SFVEC3F m_min; ///< (12) point of the lower position of the bounding box

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -42,7 +42,7 @@
// This source code is public domain, but please mention us if you use it." // This source code is public domain, but please mention us if you use it."
bool CBBOX::Intersect( const RAY& aRay, float* t ) const bool BBOX_3D::Intersect( const RAY& aRay, float* t ) const
{ {
switch( aRay.m_Classification ) switch( aRay.m_Classification )
{ {
@ -557,7 +557,7 @@ bool CBBOX::Intersect( const RAY& aRay, float* t ) const
} }
bool CBBOX::Intersect( const RAY& aRay ) const bool BBOX_3D::Intersect( const RAY& aRay ) const
{ {
switch( aRay.m_Classification ) switch( aRay.m_Classification )
{ {

View File

@ -31,30 +31,24 @@
#include "ccylinder.h" #include "ccylinder.h"
CVCYLINDER::CVCYLINDER( SFVEC2F aCenterPoint, float aZmin, float aZmax, float aRadius ) CYLINDER::CYLINDER( SFVEC2F aCenterPoint, float aZmin, float aZmax, float aRadius )
: COBJECT( OBJECT3D_TYPE::CYLINDER ) : OBJECT_3D( OBJECT_3D_TYPE::CYLINDER )
{ {
m_center = aCenterPoint; m_center = aCenterPoint;
m_radius_squared = aRadius * aRadius; m_radius_squared = aRadius * aRadius;
m_inv_radius = 1.0f / aRadius; m_inv_radius = 1.0f / aRadius;
m_bbox.Set( SFVEC3F( aCenterPoint.x - aRadius, m_bbox.Set( SFVEC3F( aCenterPoint.x - aRadius, aCenterPoint.y - aRadius, aZmin ),
aCenterPoint.y - aRadius, SFVEC3F( aCenterPoint.x + aRadius, aCenterPoint.y + aRadius, aZmax ) );
aZmin ),
SFVEC3F( aCenterPoint.x + aRadius,
aCenterPoint.y + aRadius,
aZmax ) );
m_bbox.ScaleNextUp(); m_bbox.ScaleNextUp();
m_centroid = m_bbox.GetCenter(); m_centroid = m_bbox.GetCenter();
} }
bool CVCYLINDER::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const bool CYLINDER::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
{ {
// Based on: // Based on: http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
// http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
// Ray-sphere intersection: geometric // Ray-sphere intersection: geometric
// /////////////////////////////////////////////////////////////////////////
const double OCx_Start = aRay.m_Origin.x - m_center.x; const double OCx_Start = aRay.m_Origin.x - m_center.x;
const double OCy_Start = aRay.m_Origin.y - m_center.y; const double OCy_Start = aRay.m_Origin.y - m_center.y;
@ -66,7 +60,7 @@ bool CVCYLINDER::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
(double)aRay.m_Dir.y * (double)OCy_Start; (double)aRay.m_Dir.y * (double)OCy_Start;
const double c = p_dot_p - m_radius_squared; const double c = p_dot_p - m_radius_squared;
const float delta = (float)(b * b - a * c); const float delta = (float) ( b * b - a * c );
bool hitResult = false; bool hitResult = false;
@ -78,8 +72,7 @@ bool CVCYLINDER::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
const float t = (-b - sdelta) * inv_a; const float t = (-b - sdelta) * inv_a;
const float z = aRay.m_Origin.z + t * aRay.m_Dir.z; const float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
if( (z >= m_bbox.Min().z) && if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
(z <= m_bbox.Max().z) )
{ {
if( t < aHitInfo.m_tHit ) if( t < aHitInfo.m_tHit )
{ {
@ -93,8 +86,7 @@ bool CVCYLINDER::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
const float t1 = (-b + sdelta) * inv_a; const float t1 = (-b + sdelta) * inv_a;
const float z1 = aRay.m_Origin.z + t1 * aRay.m_Dir.z; const float z1 = aRay.m_Origin.z + t1 * aRay.m_Dir.z;
if( (z1 > m_bbox.Min().z ) && if( ( z1 > m_bbox.Min().z ) && ( z1 < m_bbox.Max().z ) )
(z1 < m_bbox.Max().z ) )
{ {
if( t1 < aHitInfo.m_tHit ) if( t1 < aHitInfo.m_tHit )
{ {
@ -109,8 +101,7 @@ bool CVCYLINDER::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
{ {
aHitInfo.m_HitPoint = aRay.at( aHitInfo.m_tHit ); aHitInfo.m_HitPoint = aRay.at( aHitInfo.m_tHit );
const SFVEC2F hitPoint2D = SFVEC2F( aHitInfo.m_HitPoint.x, const SFVEC2F hitPoint2D = SFVEC2F( aHitInfo.m_HitPoint.x, aHitInfo.m_HitPoint.y );
aHitInfo.m_HitPoint.y );
aHitInfo.m_HitNormal = SFVEC3F( -(hitPoint2D.x - m_center.x) * m_inv_radius, aHitInfo.m_HitNormal = SFVEC3F( -(hitPoint2D.x - m_center.x) * m_inv_radius,
-(hitPoint2D.y - m_center.y) * m_inv_radius, -(hitPoint2D.y - m_center.y) * m_inv_radius,
@ -125,12 +116,10 @@ bool CVCYLINDER::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
} }
bool CVCYLINDER::IntersectP(const RAY &aRay , float aMaxDistance ) const bool CYLINDER::IntersectP(const RAY& aRay , float aMaxDistance ) const
{ {
// Based on: // Based on: http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
// http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
// Ray-sphere intersection: geometric // Ray-sphere intersection: geometric
// /////////////////////////////////////////////////////////////////////////
const double OCx_Start = aRay.m_Origin.x - m_center.x; const double OCx_Start = aRay.m_Origin.x - m_center.x;
const double OCy_Start = aRay.m_Origin.y - m_center.y; const double OCy_Start = aRay.m_Origin.y - m_center.y;
@ -142,7 +131,7 @@ bool CVCYLINDER::IntersectP(const RAY &aRay , float aMaxDistance ) const
(double)aRay.m_Dir.y * (double)OCy_Start; (double)aRay.m_Dir.y * (double)OCy_Start;
const double c = p_dot_p - m_radius_squared; const double c = p_dot_p - m_radius_squared;
const float delta = (float)(b * b - a * c); const float delta = (float) ( b * b - a * c );
if( delta > FLT_EPSILON ) if( delta > FLT_EPSILON )
{ {
@ -152,8 +141,7 @@ bool CVCYLINDER::IntersectP(const RAY &aRay , float aMaxDistance ) const
const float t = (-b - sdelta) * inv_a; const float t = (-b - sdelta) * inv_a;
const float z = aRay.m_Origin.z + t * aRay.m_Dir.z; const float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
if( (z >= m_bbox.Min().z) && if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
(z <= m_bbox.Max().z) )
{ {
if( t < aMaxDistance ) if( t < aMaxDistance )
return true; return true;
@ -162,8 +150,7 @@ bool CVCYLINDER::IntersectP(const RAY &aRay , float aMaxDistance ) const
const float t1 = (-b + sdelta) * inv_a; const float t1 = (-b + sdelta) * inv_a;
const float z1 = aRay.m_Origin.z + t1 * aRay.m_Dir.z; const float z1 = aRay.m_Origin.z + t1 * aRay.m_Dir.z;
if( (z1 > m_bbox.Min().z ) && if( ( z1 > m_bbox.Min().z ) && ( z1 < m_bbox.Max().z ) )
(z1 < m_bbox.Max().z ) )
{ {
if( t1 < aMaxDistance ) if( t1 < aMaxDistance )
return true; return true;
@ -174,14 +161,14 @@ bool CVCYLINDER::IntersectP(const RAY &aRay , float aMaxDistance ) const
} }
bool CVCYLINDER::Intersects( const CBBOX &aBBox ) const bool CYLINDER::Intersects( const BBOX_3D& aBBox ) const
{ {
// !TODO: improove // !TODO: improove
return m_bbox.Intersects( aBBox ); return m_bbox.Intersects( aBBox );
} }
SFVEC3F CVCYLINDER::GetDiffuseColor( const HITINFO &aHitInfo ) const SFVEC3F CYLINDER::GetDiffuseColor( const HITINFO& aHitInfo ) const
{ {
(void)aHitInfo; // unused (void)aHitInfo; // unused

View File

@ -35,9 +35,8 @@
/** /**
* A vertical cylinder * A vertical cylinder
*/ */
class CVCYLINDER : public COBJECT class CYLINDER : public OBJECT_3D
{ {
public: public:
/** /**
* @param aCenterPoint = position of the vertical cylinder axis in the XY plane * @param aCenterPoint = position of the vertical cylinder axis in the XY plane
@ -45,15 +44,14 @@ public:
* @param aZmax = top position (Z axis) * @param aZmax = top position (Z axis)
* @param aRadius = radius of the cylinder * @param aRadius = radius of the cylinder
*/ */
CVCYLINDER( SFVEC2F aCenterPoint, float aZmin, float aZmax, float aRadius ); CYLINDER( SFVEC2F aCenterPoint, float aZmin, float aZmax, float aRadius );
void SetColor( SFVEC3F aObjColor ) { m_diffusecolor = aObjColor; } void SetColor( SFVEC3F aObjColor ) { m_diffusecolor = aObjColor; }
// Imported from COBJECT bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const override;
bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const override; bool IntersectP(const RAY& aRay, float aMaxDistance ) const override;
bool IntersectP(const RAY &aRay , float aMaxDistance ) const override; bool Intersects( const BBOX_3D& aBBox ) const override;
bool Intersects( const CBBOX &aBBox ) const override; SFVEC3F GetDiffuseColor( const HITINFO& aHitInfo ) const override;
SFVEC3F GetDiffuseColor( const HITINFO &aHitInfo ) const override;
private: private:
SFVEC2F m_center; SFVEC2F m_center;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt> * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -30,7 +30,7 @@
#include "cdummyblock.h" #include "cdummyblock.h"
CDUMMYBLOCK::CDUMMYBLOCK( const CBBOX& aBBox ) : COBJECT( OBJECT3D_TYPE::DUMMYBLOCK ) DUMMY_BLOCK::DUMMY_BLOCK( const BBOX_3D& aBBox ) : OBJECT_3D( OBJECT_3D_TYPE::DUMMYBLOCK )
{ {
m_centroid = aBBox.GetCenter(); m_centroid = aBBox.GetCenter();
m_bbox.Reset(); m_bbox.Reset();
@ -38,7 +38,7 @@ CDUMMYBLOCK::CDUMMYBLOCK( const CBBOX& aBBox ) : COBJECT( OBJECT3D_TYPE::DUMMYBL
} }
bool CDUMMYBLOCK::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const bool DUMMY_BLOCK::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
{ {
float t; float t;
@ -66,7 +66,7 @@ bool CDUMMYBLOCK::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
} }
bool CDUMMYBLOCK::IntersectP(const RAY &aRay , float aMaxDistance ) const bool DUMMY_BLOCK::IntersectP(const RAY& aRay, float aMaxDistance ) const
{ {
float t; float t;
@ -80,13 +80,13 @@ bool CDUMMYBLOCK::IntersectP(const RAY &aRay , float aMaxDistance ) const
} }
bool CDUMMYBLOCK::Intersects( const CBBOX &aBBox ) const bool DUMMY_BLOCK::Intersects( const BBOX_3D& aBBox ) const
{ {
return m_bbox.Intersects( aBBox ); return m_bbox.Intersects( aBBox );
} }
SFVEC3F CDUMMYBLOCK::GetDiffuseColor( const HITINFO &aHitInfo ) const SFVEC3F DUMMY_BLOCK::GetDiffuseColor( const HITINFO& aHitInfo ) const
{ {
(void)aHitInfo; // unused (void)aHitInfo; // unused

View File

@ -24,11 +24,10 @@
/** /**
* @file cdummyblock.h * @file cdummyblock.h
* @brief
*/ */
#ifndef _CDUMMYBLOCK_H_ #ifndef _DUMMY_BLOCK_H_
#define _CDUMMYBLOCK_H_ #define _DUMMY_BLOCK_H_
#include "cobject.h" #include "cobject.h"
@ -36,22 +35,21 @@
* A dummy block is used to fill the polygons. It will only will be intercepted * A dummy block is used to fill the polygons. It will only will be intercepted
* from top or from bottom. * from top or from bottom.
*/ */
class CDUMMYBLOCK : public COBJECT class DUMMY_BLOCK : public OBJECT_3D
{ {
public: public:
explicit CDUMMYBLOCK( const CBBOX &aBBox ); explicit DUMMY_BLOCK( const BBOX_3D& aBBox );
void SetColor( SFVEC3F aObjColor ) { m_diffusecolor = aObjColor; } void SetColor( SFVEC3F aObjColor ) { m_diffusecolor = aObjColor; }
// Imported from COBJECT bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const override;
bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const override; bool IntersectP(const RAY& aRay , float aMaxDistance ) const override;
bool IntersectP(const RAY &aRay , float aMaxDistance ) const override; bool Intersects( const BBOX_3D& aBBox ) const override;
bool Intersects( const CBBOX &aBBox ) const override; SFVEC3F GetDiffuseColor( const HITINFO& aHitInfo ) const override;
SFVEC3F GetDiffuseColor( const HITINFO &aHitInfo ) const override;
private: private:
SFVEC3F m_diffusecolor; SFVEC3F m_diffusecolor;
}; };
#endif // _CDUMMYBLOCK_H_ #endif // _DUMMY_BLOCK_H_

View File

@ -32,12 +32,13 @@
#include <wx/debug.h> #include <wx/debug.h>
CLAYERITEM::CLAYERITEM( const COBJECT2D* aObject2D, float aZMin, float aZMax ) LAYER_ITEM::LAYER_ITEM( const OBJECT_2D* aObject2D, float aZMin, float aZMax ) :
: COBJECT( OBJECT3D_TYPE::LAYERITEM ), m_object2d( aObject2D ) OBJECT_3D( OBJECT_3D_TYPE::LAYERITEM ),
m_object2d( aObject2D )
{ {
wxASSERT( aObject2D ); wxASSERT( aObject2D );
CBBOX2D bbox2d = m_object2d->GetBBox(); BBOX_2D bbox2d = m_object2d->GetBBox();
bbox2d.ScaleNextUp(); bbox2d.ScaleNextUp();
bbox2d.ScaleNextUp(); bbox2d.ScaleNextUp();
@ -47,13 +48,12 @@ CLAYERITEM::CLAYERITEM( const COBJECT2D* aObject2D, float aZMin, float aZMax )
m_bbox.ScaleNextUp(); m_bbox.ScaleNextUp();
m_bbox.Scale( 1.0001f ); m_bbox.Scale( 1.0001f );
m_centroid = SFVEC3F( aObject2D->GetCentroid().x, m_centroid = SFVEC3F( aObject2D->GetCentroid().x, aObject2D->GetCentroid().y,
aObject2D->GetCentroid().y, ( aZMax + aZMin ) * 0.5f );
(aZMax + aZMin) * 0.5f );
} }
bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const bool LAYER_ITEM::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
{ {
float tBBoxStart; float tBBoxStart;
float tBBoxEnd; float tBBoxEnd;
@ -76,7 +76,7 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
bool hit_top = false; bool hit_top = false;
bool hit_bot = false; bool hit_bot = false;
if( (float)fabs(aRay.m_Dir.z) > FLT_EPSILON ) if( (float) fabs( aRay.m_Dir.z ) > FLT_EPSILON )
{ {
tBot = (m_bbox.Min().z - aRay.m_Origin.z) * aRay.m_InvDir.z; tBot = (m_bbox.Min().z - aRay.m_Origin.z) * aRay.m_InvDir.z;
tTop = (m_bbox.Max().z - aRay.m_Origin.z) * aRay.m_InvDir.z; tTop = (m_bbox.Max().z - aRay.m_Origin.z) * aRay.m_InvDir.z;
@ -220,8 +220,7 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
// The hitT is a hit value for the segment length 'start' - 'end', // The hitT is a hit value for the segment length 'start' - 'end',
// so it ranges from 0.0 - 1.0. We now convert it to a 3D hit position // so it ranges from 0.0 - 1.0. We now convert it to a 3D hit position
// and calculate the real hitT of the ray. // and calculate the real hitT of the ray.
SFVEC3F hitPoint = boxHitPointStart + SFVEC3F hitPoint = boxHitPointStart + ( boxHitPointEnd - boxHitPointStart ) * tOut;
(boxHitPointEnd - boxHitPointStart) * tOut;
const float t = glm::length( hitPoint - aRay.m_Origin ); const float t = glm::length( hitPoint - aRay.m_Origin );
@ -230,8 +229,7 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
aHitInfo.m_tHit = t; aHitInfo.m_tHit = t;
aHitInfo.m_HitPoint = hitPoint; aHitInfo.m_HitPoint = hitPoint;
if( (outNormal.x == 0.0f) && if( ( outNormal.x == 0.0f ) && ( outNormal.y == 0.0f ) )
(outNormal.y == 0.0f) )
{ {
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f ); aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
} }
@ -264,7 +262,7 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
const SFVEC2F boxHitPointEnd2D( boxHitPointEnd.x, boxHitPointEnd.y ); const SFVEC2F boxHitPointEnd2D( boxHitPointEnd.x, boxHitPointEnd.y );
if(!(m_object2d->IsPointInside( boxHitPointStart2D ) && if( !( m_object2d->IsPointInside( boxHitPointStart2D ) &&
m_object2d->IsPointInside( boxHitPointEnd2D ) ) ) m_object2d->IsPointInside( boxHitPointEnd2D ) ) )
return false; return false;
@ -272,7 +270,7 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
SFVEC2F outNormal; SFVEC2F outNormal;
RAYSEG2D raySeg( boxHitPointStart2D, boxHitPointEnd2D ); RAYSEG2D raySeg( boxHitPointStart2D, boxHitPointEnd2D );
if( (m_object2d->IsPointInside( boxHitPointStart2D ) && if( ( m_object2d->IsPointInside( boxHitPointStart2D ) &&
m_object2d->IsPointInside( boxHitPointEnd2D ) ) ) m_object2d->IsPointInside( boxHitPointEnd2D ) ) )
{ {
if( tBBoxEnd < aHitInfo.m_tHit ) if( tBBoxEnd < aHitInfo.m_tHit )
@ -299,7 +297,7 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
// so it ranges from 0.0 - 1.0. We now convert it to a 3D hit position // so it ranges from 0.0 - 1.0. We now convert it to a 3D hit position
// and calculate the real hitT of the ray. // and calculate the real hitT of the ray.
const SFVEC3F hitPoint = boxHitPointStart + const SFVEC3F hitPoint = boxHitPointStart +
(boxHitPointEnd - boxHitPointStart) * tOut; ( boxHitPointEnd - boxHitPointStart ) * tOut;
const float t = glm::length( hitPoint - aRay.m_Origin ); const float t = glm::length( hitPoint - aRay.m_Origin );
@ -318,11 +316,12 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
} }
#endif #endif
} }
return false; return false;
} }
bool CLAYERITEM::IntersectP( const RAY &aRay , float aMaxDistance ) const bool LAYER_ITEM::IntersectP( const RAY& aRay, float aMaxDistance ) const
{ {
float tBBoxStart; float tBBoxStart;
float tBBoxEnd; float tBBoxEnd;
@ -330,9 +329,7 @@ bool CLAYERITEM::IntersectP( const RAY &aRay , float aMaxDistance ) const
if( !m_bbox.Intersect( aRay, &tBBoxStart, &tBBoxEnd ) ) if( !m_bbox.Intersect( aRay, &tBBoxStart, &tBBoxEnd ) )
return false; return false;
if( ( tBBoxStart > aMaxDistance ) || if( ( tBBoxStart > aMaxDistance ) || ( fabs( tBBoxStart - tBBoxEnd ) < FLT_EPSILON ) )
//( tBBoxEnd < FLT_EPSILON )
( fabs(tBBoxStart - tBBoxEnd) < FLT_EPSILON ) )
return false; return false;
float tTop = FLT_MAX; float tTop = FLT_MAX;
@ -340,10 +337,10 @@ bool CLAYERITEM::IntersectP( const RAY &aRay , float aMaxDistance ) const
bool hit_top = false; bool hit_top = false;
bool hit_bot = false; bool hit_bot = false;
if( (float)fabs(aRay.m_Dir.z) > FLT_EPSILON ) if( (float)fabs( aRay.m_Dir.z ) > FLT_EPSILON )
{ {
tBot = (m_bbox.Min().z - aRay.m_Origin.z) * aRay.m_InvDir.z; tBot = ( m_bbox.Min().z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
tTop = (m_bbox.Max().z - aRay.m_Origin.z) * aRay.m_InvDir.z; tTop = ( m_bbox.Max().z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
const float tBBoxStartAdjusted = NextFloatUp( tBBoxStart ); const float tBBoxStartAdjusted = NextFloatUp( tBBoxStart );
@ -455,10 +452,10 @@ bool CLAYERITEM::IntersectP( const RAY &aRay , float aMaxDistance ) const
// so it ranges from 0.0 - 1.0. We now convert it to a 3D hit position // so it ranges from 0.0 - 1.0. We now convert it to a 3D hit position
// and calculate the real hitT of the ray. // and calculate the real hitT of the ray.
const SFVEC3F hitPoint = boxHitPointStart + const SFVEC3F hitPoint = boxHitPointStart +
(boxHitPointEnd - boxHitPointStart) * tOut; ( boxHitPointEnd - boxHitPointStart ) * tOut;
const float t = glm::length( hitPoint - aRay.m_Origin ); const float t = glm::length( hitPoint - aRay.m_Origin );
if( (t < aMaxDistance) && ( t > FLT_EPSILON ) ) if( ( t < aMaxDistance ) && ( t > FLT_EPSILON ) )
return true; return true;
} }
} }
@ -467,19 +464,19 @@ bool CLAYERITEM::IntersectP( const RAY &aRay , float aMaxDistance ) const
} }
bool CLAYERITEM::Intersects( const CBBOX &aBBox ) const bool LAYER_ITEM::Intersects( const BBOX_3D& aBBox ) const
{ {
if( !m_bbox.Intersects( aBBox ) ) if( !m_bbox.Intersects( aBBox ) )
return false; return false;
const CBBOX2D bbox2D( SFVEC2F( aBBox.Min().x, aBBox.Min().y), const BBOX_2D bbox2D( SFVEC2F( aBBox.Min().x, aBBox.Min().y ),
SFVEC2F( aBBox.Max().x, aBBox.Max().y) ); SFVEC2F( aBBox.Max().x, aBBox.Max().y ) );
return m_object2d->Intersects( bbox2D ); return m_object2d->Intersects( bbox2D );
} }
SFVEC3F CLAYERITEM::GetDiffuseColor( const HITINFO &aHitInfo ) const SFVEC3F LAYER_ITEM::GetDiffuseColor( const HITINFO& aHitInfo ) const
{ {
(void)aHitInfo; // unused (void)aHitInfo; // unused

View File

@ -27,31 +27,31 @@
* @brief * @brief
*/ */
#ifndef _CLAYERITEM_H_ #ifndef _LAYER_ITEM_H_
#define _CLAYERITEM_H_ #define _LAYER_ITEM_H_
#include "cobject.h" #include "cobject.h"
#include "../shapes2D/cobject2d.h" #include "../shapes2D/cobject2d.h"
class CLAYERITEM : public COBJECT class LAYER_ITEM : public OBJECT_3D
{ {
public: public:
CLAYERITEM( const COBJECT2D *aObject2D, float aZMin, float aZMax ); LAYER_ITEM( const OBJECT_2D* aObject2D, float aZMin, float aZMax );
void SetColor( SFVEC3F aObjColor ) { m_diffusecolor = aObjColor; } void SetColor( SFVEC3F aObjColor ) { m_diffusecolor = aObjColor; }
// Imported from COBJECT // Imported from OBJECT_3D
bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const override; bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const override;
bool IntersectP(const RAY &aRay , float aMaxDistance ) const override; bool IntersectP(const RAY& aRay , float aMaxDistance ) const override;
bool Intersects( const CBBOX &aBBox ) const override; bool Intersects( const BBOX_3D& aBBox ) const override;
SFVEC3F GetDiffuseColor( const HITINFO &aHitInfo ) const override; SFVEC3F GetDiffuseColor( const HITINFO& aHitInfo ) const override;
protected: protected:
const COBJECT2D *m_object2d; const OBJECT_2D* m_object2d;
private: private:
SFVEC3F m_diffusecolor; SFVEC3F m_diffusecolor;
}; };
#endif // _CLAYERITEM_H_ #endif // _LAYER_ITEM_H_

View File

@ -32,15 +32,15 @@
#include <map> #include <map>
COBJECT3D_STATS *COBJECT3D_STATS::s_instance = 0; OBJECT_3D_STATS* OBJECT_3D_STATS::s_instance = 0;
static const CBLINN_PHONG_MATERIAL s_defaultMaterial = CBLINN_PHONG_MATERIAL(); static const BLINN_PHONG_MATERIAL s_defaultMaterial = BLINN_PHONG_MATERIAL();
COBJECT::COBJECT( OBJECT3D_TYPE aObjType ) OBJECT_3D::OBJECT_3D( OBJECT_3D_TYPE aObjType )
{ {
m_obj_type = aObjType; m_obj_type = aObjType;
COBJECT3D_STATS::Instance().AddOne( aObjType ); OBJECT_3D_STATS::Instance().AddOne( aObjType );
m_material = &s_defaultMaterial; m_material = &s_defaultMaterial;
m_modelTransparency = 0.0f; m_modelTransparency = 0.0f;
m_boardItem = nullptr; m_boardItem = nullptr;
@ -48,24 +48,24 @@ COBJECT::COBJECT( OBJECT3D_TYPE aObjType )
/* /*
* Lookup table for OBJECT2D_TYPE printed names * Lookup table for OBJECT_2D_TYPE printed names
*/ */
// clang-format off // clang-format off
const std::map<OBJECT3D_TYPE, const char*> objectTypeNames const std::map<OBJECT_3D_TYPE, const char*> objectTypeNames
{ {
{ OBJECT3D_TYPE::CYLINDER, "OBJECT3D_TYPE::CYLINDER" }, { OBJECT_3D_TYPE::CYLINDER, "OBJECT_3D_TYPE::CYLINDER" },
{ OBJECT3D_TYPE::DUMMYBLOCK, "OBJECT2D_TYPE::DUMMYBLOCK" }, { OBJECT_3D_TYPE::DUMMYBLOCK, "OBJECT_3D_TYPE::DUMMY_BLOCK" },
{ OBJECT3D_TYPE::LAYERITEM, "OBJECT2D_TYPE::LAYERITEM" }, { OBJECT_3D_TYPE::LAYERITEM, "OBJECT_3D_TYPE::LAYER_ITEM" },
{ OBJECT3D_TYPE::XYPLANE, "OBJECT2D_TYPE::XYPLANE" }, { OBJECT_3D_TYPE::XYPLANE, "OBJECT_3D_TYPE::XY_PLANE" },
{ OBJECT3D_TYPE::ROUNDSEG, "OBJECT2D_TYPE::ROUNDSEG" }, { OBJECT_3D_TYPE::ROUNDSEG, "OBJECT_3D_TYPE::ROUND_SEG" },
{ OBJECT3D_TYPE::TRIANGLE, "OBJECT2D_TYPE::TRIANGLE" } { OBJECT_3D_TYPE::TRIANGLE, "OBJECT_3D_TYPE::TRIANGLE" }
}; };
// clang-format on // clang-format on
void COBJECT3D_STATS::PrintStats() void OBJECT_3D_STATS::PrintStats()
{ {
wxLogDebug( "OBJ3D Statistics:\n" ); wxLogDebug( "OBJECT_3D_STATS:\n" );
for( auto& objectType : objectTypeNames ) for( auto& objectType : objectTypeNames )
{ {

View File

@ -24,11 +24,10 @@
/** /**
* @file cobject.h * @file cobject.h
* @brief
*/ */
#ifndef _COBJECT_H_ #ifndef _OBJECT_3D_H_
#define _COBJECT_H_ #define _OBJECT_3D_H_
#include "cbbox.h" #include "cbbox.h"
#include "../hitinfo.h" #include "../hitinfo.h"
@ -36,7 +35,7 @@
#include <board_item.h> #include <board_item.h>
enum class OBJECT3D_TYPE enum class OBJECT_3D_TYPE
{ {
CYLINDER, CYLINDER,
DUMMYBLOCK, DUMMYBLOCK,
@ -48,61 +47,59 @@ enum class OBJECT3D_TYPE
}; };
class COBJECT class OBJECT_3D
{ {
public: public:
explicit COBJECT( OBJECT3D_TYPE aObjType ); explicit OBJECT_3D( OBJECT_3D_TYPE aObjType );
const void SetBoardItem( BOARD_ITEM *aBoardItem ) { m_boardItem = aBoardItem; } const void SetBoardItem( BOARD_ITEM* aBoardItem ) { m_boardItem = aBoardItem; }
BOARD_ITEM *GetBoardItem() const { return m_boardItem; } BOARD_ITEM* GetBoardItem() const { return m_boardItem; }
void SetMaterial( const CMATERIAL *aMaterial ) void SetMaterial( const MATERIAL* aMaterial )
{ {
m_material = aMaterial; m_material = aMaterial;
m_modelTransparency = aMaterial->GetTransparency(); // Default transparency is from material m_modelTransparency = aMaterial->GetTransparency(); // Default transparency is from material
} }
const CMATERIAL *GetMaterial() const { return m_material; } const MATERIAL *GetMaterial() const { return m_material; }
float GetModelTransparency() const { return m_modelTransparency; } float GetModelTransparency() const { return m_modelTransparency; }
void SetModelTransparency( float aModelTransparency ) void SetModelTransparency( float aModelTransparency )
{ {
m_modelTransparency = aModelTransparency; m_modelTransparency = aModelTransparency;
} }
virtual SFVEC3F GetDiffuseColor( const HITINFO &aHitInfo ) const = 0; virtual SFVEC3F GetDiffuseColor( const HITINFO& aHitInfo ) const = 0;
virtual ~COBJECT() {} virtual ~OBJECT_3D() {}
/** /**
* Intersects - a.Intersects(b) !a.Disjoint(b) !(a b = ). * @return true if this object intersects \a aBBox.
*
* It intersects if the result intersection is not null
*/ */
virtual bool Intersects( const CBBOX &aBBox ) const = 0; virtual bool Intersects( const BBOX_3D& aBBox ) const = 0;
/** /**
* @return true if the aRay intersects the object * @return true if the \a aRay intersects the object.
*/ */
virtual bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const = 0; virtual bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const = 0;
/** /**
* @param aMaxDistance - max distance of the test * @param aMaxDistance is the maximum distance of the test.
* @return true if the aRay intersects the object * @return true if \a aRay intersects the object.
*/ */
virtual bool IntersectP( const RAY &aRay, float aMaxDistance ) const = 0; virtual bool IntersectP( const RAY& aRay, float aMaxDistance ) const = 0;
const CBBOX &GetBBox() const { return m_bbox; } const BBOX_3D& GetBBox() const { return m_bbox; }
const SFVEC3F &GetCentroid() const { return m_centroid; } const SFVEC3F& GetCentroid() const { return m_centroid; }
protected: protected:
CBBOX m_bbox; BBOX_3D m_bbox;
SFVEC3F m_centroid; SFVEC3F m_centroid;
OBJECT3D_TYPE m_obj_type; OBJECT_3D_TYPE m_obj_type;
const CMATERIAL *m_material; const MATERIAL* m_material;
BOARD_ITEM *m_boardItem; BOARD_ITEM* m_boardItem;
// m_modelTransparency combines the material and model opacity // m_modelTransparency combines the material and model opacity
// 0.0 full opaque, 1.0 full transparent. // 0.0 full opaque, 1.0 full transparent.
@ -112,44 +109,44 @@ protected:
/// Implements a class for object statistics /// Implements a class for object statistics
/// using Singleton pattern /// using Singleton pattern
class COBJECT3D_STATS class OBJECT_3D_STATS
{ {
public: public:
void ResetStats() void ResetStats()
{ {
memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT3D_TYPE::MAX ) ); memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT_3D_TYPE::MAX ) );
} }
unsigned int GetCountOf( OBJECT3D_TYPE aObjType ) const unsigned int GetCountOf( OBJECT_3D_TYPE aObjType ) const
{ {
return m_counter[static_cast<int>( aObjType )]; return m_counter[static_cast<int>( aObjType )];
} }
void AddOne( OBJECT3D_TYPE aObjType ) void AddOne( OBJECT_3D_TYPE aObjType )
{ {
m_counter[static_cast<int>( aObjType )]++; m_counter[static_cast<int>( aObjType )]++;
} }
void PrintStats(); void PrintStats();
static COBJECT3D_STATS &Instance() static OBJECT_3D_STATS& Instance()
{ {
if( !s_instance ) if( !s_instance )
s_instance = new COBJECT3D_STATS; s_instance = new OBJECT_3D_STATS;
return *s_instance; return *s_instance;
} }
private: private:
COBJECT3D_STATS(){ ResetStats(); } OBJECT_3D_STATS(){ ResetStats(); }
COBJECT3D_STATS( const COBJECT3D_STATS &old ); OBJECT_3D_STATS( const OBJECT_3D_STATS& old );
const COBJECT3D_STATS &operator=( const COBJECT3D_STATS &old ); const OBJECT_3D_STATS& operator=( const OBJECT_3D_STATS& old );
~COBJECT3D_STATS() {} ~OBJECT_3D_STATS() {}
unsigned int m_counter[static_cast<int>( OBJECT3D_TYPE::MAX )]; unsigned int m_counter[static_cast<int>( OBJECT_3D_TYPE::MAX )];
static COBJECT3D_STATS *s_instance; static OBJECT_3D_STATS* s_instance;
}; };
#endif // _COBJECT_H_ #endif // _OBJECT_3D_H_

View File

@ -24,13 +24,12 @@
/** /**
* @file cplane.cpp * @file cplane.cpp
* @brief
*/ */
#include "cplane.h" #include "cplane.h"
CXYPLANE::CXYPLANE( const CBBOX& aBBox ) : COBJECT( OBJECT3D_TYPE::XYPLANE ) XY_PLANE::XY_PLANE( const BBOX_3D& aBBox ) : OBJECT_3D( OBJECT_3D_TYPE::XYPLANE )
{ {
m_centerPoint = aBBox.GetCenter(); m_centerPoint = aBBox.GetCenter();
m_centroid = m_centerPoint; m_centroid = m_centerPoint;
@ -39,35 +38,32 @@ CXYPLANE::CXYPLANE( const CBBOX& aBBox ) : COBJECT( OBJECT3D_TYPE::XYPLANE )
m_bbox.Set( aBBox ); m_bbox.Set( aBBox );
m_xsize = aBBox.GetExtent().x; m_xsize = aBBox.GetExtent().x;
m_ysize = aBBox.GetExtent().y; m_ysize = aBBox.GetExtent().y;
m_xsize_inv2 = 1.0f / (2.0f * m_xsize); m_xsize_inv2 = 1.0f / ( 2.0f * m_xsize );
m_ysize_inv2 = 1.0f / (2.0f * m_ysize); m_ysize_inv2 = 1.0f / ( 2.0f * m_ysize );
} }
CXYPLANE::CXYPLANE( SFVEC3F aCenterPoint, float aXSize, float aYSize ) XY_PLANE::XY_PLANE( SFVEC3F aCenterPoint, float aXSize, float aYSize )
: COBJECT( OBJECT3D_TYPE::XYPLANE ) : OBJECT_3D( OBJECT_3D_TYPE::XYPLANE )
{ {
m_centerPoint = aCenterPoint; m_centerPoint = aCenterPoint;
m_xsize = aXSize; m_xsize = aXSize;
m_ysize = aYSize; m_ysize = aYSize;
m_xsize_inv2 = 1.0f / (2.0f * aXSize); m_xsize_inv2 = 1.0f / ( 2.0f * aXSize );
m_ysize_inv2 = 1.0f / (2.0f * aYSize); m_ysize_inv2 = 1.0f / ( 2.0f * aYSize );
m_bbox.Set( SFVEC3F( aCenterPoint.x - aXSize / 2.0f, m_bbox.Set( SFVEC3F( aCenterPoint.x - aXSize / 2.0f, aCenterPoint.y - aYSize / 2.0f,
aCenterPoint.y - aYSize / 2.0f,
aCenterPoint.z ), aCenterPoint.z ),
SFVEC3F( aCenterPoint.x + aXSize / 2.0f, SFVEC3F( aCenterPoint.x + aXSize / 2.0f, aCenterPoint.y + aYSize / 2.0f,
aCenterPoint.y + aYSize / 2.0f,
aCenterPoint.z ) ); aCenterPoint.z ) );
m_centroid = aCenterPoint; m_centroid = aCenterPoint;
} }
bool CXYPLANE::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const bool XY_PLANE::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
{ {
const float t = (m_centerPoint.z - aRay.m_Origin.z) * aRay.m_InvDir.z; const float t = (m_centerPoint.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
if( ( t < FLT_EPSILON ) || if( ( t < FLT_EPSILON ) || ( t >= aHitInfo.m_tHit ) )
( t >= aHitInfo.m_tHit ) )
return false; return false;
const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x; const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x;
@ -77,7 +73,7 @@ bool CXYPLANE::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y; const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y;
if( (vSV < -m_ysize) || (vSV > m_ysize) ) if( ( vSV < -m_ysize ) || ( vSV > m_ysize ) )
return false; return false;
aHitInfo.m_tHit = t; aHitInfo.m_tHit = t;
@ -95,12 +91,11 @@ bool CXYPLANE::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
} }
bool CXYPLANE::IntersectP(const RAY &aRay , float aMaxDistance ) const bool XY_PLANE::IntersectP(const RAY& aRay, float aMaxDistance ) const
{ {
const float t = (m_centerPoint.z - aRay.m_Origin.z) * aRay.m_InvDir.z; const float t = ( m_centerPoint.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( ( t < FLT_EPSILON ) || if( ( t < FLT_EPSILON ) || ( t >= aMaxDistance ) )
( t >= aMaxDistance ) )
return false; return false;
const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x; const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x;
@ -110,20 +105,20 @@ bool CXYPLANE::IntersectP(const RAY &aRay , float aMaxDistance ) const
const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y; const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y;
if( (vSV < -m_ysize) || (vSV > m_ysize) ) if( ( vSV < -m_ysize ) || ( vSV > m_ysize ) )
return false; return false;
return true; return true;
} }
bool CXYPLANE::Intersects( const CBBOX &aBBox ) const bool XY_PLANE::Intersects( const BBOX_3D& aBBox ) const
{ {
return m_bbox.Intersects( aBBox ); return m_bbox.Intersects( aBBox );
} }
SFVEC3F CXYPLANE::GetDiffuseColor( const HITINFO &aHitInfo ) const SFVEC3F XY_PLANE::GetDiffuseColor( const HITINFO& aHitInfo ) const
{ {
(void)aHitInfo; // unused (void)aHitInfo; // unused

View File

@ -35,25 +35,24 @@
/** /**
* A plane that is parallel to XY plane * A plane that is parallel to XY plane
*/ */
class CXYPLANE : public COBJECT class XY_PLANE : public OBJECT_3D
{ {
public: public:
explicit CXYPLANE( const CBBOX &aBBox ); explicit XY_PLANE( const BBOX_3D& aBBox );
/** /**
* @param aCenterPoint = position of the center of the plane * @param aCenterPoint = position of the center of the plane
* @param aXSize = size by X axis * @param aXSize = size by X axis
* @param aYSize = size by Y axis * @param aYSize = size by Y axis
*/ */
CXYPLANE( SFVEC3F aCenterPoint, float aXSize, float aYSize ); XY_PLANE( SFVEC3F aCenterPoint, float aXSize, float aYSize );
void SetColor( SFVEC3F aObjColor ) { m_diffusecolor = aObjColor; } void SetColor( SFVEC3F aObjColor ) { m_diffusecolor = aObjColor; }
// Imported from COBJECT bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const override;
bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const override; bool IntersectP(const RAY& aRay, float aMaxDistance ) const override;
bool IntersectP(const RAY &aRay , float aMaxDistance ) const override; bool Intersects( const BBOX_3D& aBBox ) const override;
bool Intersects( const CBBOX &aBBox ) const override; SFVEC3F GetDiffuseColor( const HITINFO& aHitInfo ) const override;
SFVEC3F GetDiffuseColor( const HITINFO &aHitInfo ) const override;
private: private:
SFVEC3F m_centerPoint; SFVEC3F m_centerPoint;

View File

@ -24,14 +24,14 @@
/** /**
* @file croundseg.cpp * @file croundseg.cpp
* @brief
*/ */
#include "croundseg.h" #include "croundseg.h"
CROUNDSEG::CROUNDSEG( const CROUNDSEGMENT2D& aSeg2D, float aZmin, float aZmax ) ROUND_SEGMENT::ROUND_SEGMENT( const ROUND_SEGMENT_2D& aSeg2D, float aZmin, float aZmax ) :
: COBJECT( OBJECT3D_TYPE::ROUNDSEG ), m_segment( aSeg2D.m_segment ) OBJECT_3D( OBJECT_3D_TYPE::ROUNDSEG ),
m_segment( aSeg2D.m_segment )
{ {
m_radius = aSeg2D.GetRadius(); m_radius = aSeg2D.GetRadius();
m_radius_squared = m_radius * m_radius; m_radius_squared = m_radius * m_radius;
@ -42,8 +42,8 @@ CROUNDSEG::CROUNDSEG( const CROUNDSEGMENT2D& aSeg2D, float aZmin, float aZmax )
m_bbox.Reset(); m_bbox.Reset();
m_bbox.Set( SFVEC3F( m_segment.m_Start.x, m_segment.m_Start.y, aZmin), m_bbox.Set( SFVEC3F( m_segment.m_Start.x, m_segment.m_Start.y, aZmin ),
SFVEC3F( m_segment.m_End.x, m_segment.m_End.y, aZmax) ); SFVEC3F( m_segment.m_End.x, m_segment.m_End.y, aZmax ) );
m_bbox.Set( m_bbox.Min() - SFVEC3F( m_radius, m_radius, 0.0f ), m_bbox.Set( m_bbox.Min() - SFVEC3F( m_radius, m_radius, 0.0f ),
m_bbox.Max() + SFVEC3F( m_radius, m_radius, 0.0f ) ); m_bbox.Max() + SFVEC3F( m_radius, m_radius, 0.0f ) );
@ -54,18 +54,16 @@ CROUNDSEG::CROUNDSEG( const CROUNDSEGMENT2D& aSeg2D, float aZmin, float aZmax )
m_center_left = m_centroid + m_plane_dir_left * m_radius; m_center_left = m_centroid + m_plane_dir_left * m_radius;
m_center_right = m_centroid + m_plane_dir_right * m_radius; m_center_right = m_centroid + m_plane_dir_right * m_radius;
m_seglen_over_two_squared = (m_segment.m_Length / 2.0f) * m_seglen_over_two_squared = ( m_segment.m_Length / 2.0f ) * ( m_segment.m_Length / 2.0f );
(m_segment.m_Length / 2.0f);
} }
bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const bool ROUND_SEGMENT::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
{ {
// Top / Bottom plane // Top / Bottom plane
// /////////////////////////////////////////////////////////////////////////
float zPlanePos = aRay.m_dirIsNeg[2]? m_bbox.Max().z : m_bbox.Min().z; float zPlanePos = aRay.m_dirIsNeg[2]? m_bbox.Max().z : m_bbox.Min().z;
float tPlane = ( zPlanePos - aRay.m_Origin.z) * aRay.m_InvDir.z; float tPlane = ( zPlanePos - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( ( tPlane >= aHitInfo.m_tHit ) || ( tPlane < FLT_EPSILON ) ) if( ( tPlane >= aHitInfo.m_tHit ) || ( tPlane < FLT_EPSILON ) )
return false; // Early exit return false; // Early exit
@ -80,12 +78,9 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
if( tPlane < aHitInfo.m_tHit ) if( tPlane < aHitInfo.m_tHit )
{ {
aHitInfo.m_tHit = tPlane; aHitInfo.m_tHit = tPlane;
aHitInfo.m_HitPoint = SFVEC3F( planeHitPoint2d.x, aHitInfo.m_HitPoint = SFVEC3F( planeHitPoint2d.x, planeHitPoint2d.y,
planeHitPoint2d.y,
aRay.m_Origin.z + aRay.m_Dir.z * tPlane ); aRay.m_Origin.z + aRay.m_Dir.z * tPlane );
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, aRay.m_dirIsNeg[2] ? 1.0f : -1.0f );
0.0f,
aRay.m_dirIsNeg[2]? 1.0f: -1.0f );
aHitInfo.pHitObject = this; aHitInfo.pHitObject = this;
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo ); m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
@ -97,7 +92,6 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
} }
// Test LEFT / RIGHT plane // Test LEFT / RIGHT plane
// /////////////////////////////////////////////////////////////////////////
float normal_dot_ray = glm::dot( m_plane_dir_right, aRay.m_Dir ); float normal_dot_ray = glm::dot( m_plane_dir_right, aRay.m_Dir );
if( normal_dot_ray < 0.0f ) // If the dot is neg, the it hits the plane if( normal_dot_ray < 0.0f ) // If the dot is neg, the it hits the plane
@ -113,16 +107,14 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
const SFVEC3F v = hitP - m_center_right; const SFVEC3F v = hitP - m_center_right;
const float len = glm::dot( v, v ); const float len = glm::dot( v, v );
if( (len <= m_seglen_over_two_squared) && if( ( len <= m_seglen_over_two_squared ) && ( hitP.z >= m_bbox.Min().z )
(hitP.z >= m_bbox.Min().z) && && ( hitP.z <= m_bbox.Max().z ) )
(hitP.z <= m_bbox.Max().z) )
{ {
if( t < aHitInfo.m_tHit ) if( t < aHitInfo.m_tHit )
{ {
aHitInfo.m_tHit = t; aHitInfo.m_tHit = t;
aHitInfo.m_HitPoint = hitP; aHitInfo.m_HitPoint = hitP;
aHitInfo.m_HitNormal = SFVEC3F( m_plane_dir_right.x, aHitInfo.m_HitNormal = SFVEC3F( m_plane_dir_right.x, m_plane_dir_right.y,
m_plane_dir_right.y,
0.0f ); 0.0f );
aHitInfo.pHitObject = this; aHitInfo.pHitObject = this;
@ -152,16 +144,14 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
const SFVEC3F v = hitP - m_center_left; const SFVEC3F v = hitP - m_center_left;
const float len = glm::dot( v, v ); const float len = glm::dot( v, v );
if( (len <= m_seglen_over_two_squared) && if( ( len <= m_seglen_over_two_squared ) && ( hitP.z >= m_bbox.Min().z )
(hitP.z >= m_bbox.Min().z) && && ( hitP.z <= m_bbox.Max().z ) )
(hitP.z <= m_bbox.Max().z) )
{ {
if( t < aHitInfo.m_tHit ) if( t < aHitInfo.m_tHit )
{ {
aHitInfo.m_tHit = t; aHitInfo.m_tHit = t;
aHitInfo.m_HitPoint = hitP; aHitInfo.m_HitPoint = hitP;
aHitInfo.m_HitNormal = SFVEC3F( m_plane_dir_left.x, aHitInfo.m_HitNormal = SFVEC3F( m_plane_dir_left.x, m_plane_dir_left.y,
m_plane_dir_left.y,
0.0f ); 0.0f );
aHitInfo.pHitObject = this; aHitInfo.pHitObject = this;
@ -176,12 +166,8 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
} }
} }
// Based on: // Based on: http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
// http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
// Ray-sphere intersection: geometric // Ray-sphere intersection: geometric
// /////////////////////////////////////////////////////////////////////////
const double OCx_Start = aRay.m_Origin.x - m_segment.m_Start.x; const double OCx_Start = aRay.m_Origin.x - m_segment.m_Start.x;
const double OCy_Start = aRay.m_Origin.y - m_segment.m_Start.y; const double OCy_Start = aRay.m_Origin.y - m_segment.m_Start.y;
@ -195,24 +181,22 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
const double c_Start = p_dot_p_Start - m_radius_squared; const double c_Start = p_dot_p_Start - m_radius_squared;
const float delta_Start = (float)(b_Start * b_Start - a * c_Start); const float delta_Start = (float) ( b_Start * b_Start - a * c_Start );
if( delta_Start > FLT_EPSILON ) if( delta_Start > FLT_EPSILON )
{ {
const float sdelta = sqrtf( delta_Start ); const float sdelta = sqrtf( delta_Start );
const float t = (-b_Start - sdelta) / a; const float t = ( -b_Start - sdelta ) / a;
const float z = aRay.m_Origin.z + t * aRay.m_Dir.z; const float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
if( (z >= m_bbox.Min().z) && if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
(z <= m_bbox.Max().z) )
{ {
if( t < aHitInfo.m_tHit ) if( t < aHitInfo.m_tHit )
{ {
aHitInfo.m_tHit = t; aHitInfo.m_tHit = t;
aHitInfo.m_HitPoint = aRay.at( t ); aHitInfo.m_HitPoint = aRay.at( t );
const SFVEC2F hitPoint2D = SFVEC2F( aHitInfo.m_HitPoint.x, const SFVEC2F hitPoint2D = SFVEC2F( aHitInfo.m_HitPoint.x, aHitInfo.m_HitPoint.y );
aHitInfo.m_HitPoint.y );
aHitInfo.m_HitNormal = SFVEC3F( aHitInfo.m_HitNormal = SFVEC3F(
(hitPoint2D.x - m_segment.m_Start.x) * m_inv_radius, (hitPoint2D.x - m_segment.m_Start.x) * m_inv_radius,
@ -248,8 +232,7 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
const float t = (-b_End - sdelta) / a; const float t = (-b_End - sdelta) / a;
const float z = aRay.m_Origin.z + t * aRay.m_Dir.z; const float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
if( (z >= m_bbox.Min().z) && if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
(z <= m_bbox.Max().z) )
{ {
if( t < aHitInfo.m_tHit ) if( t < aHitInfo.m_tHit )
{ {
@ -278,13 +261,12 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
} }
bool CROUNDSEG::IntersectP( const RAY &aRay, float aMaxDistance ) const bool ROUND_SEGMENT::IntersectP( const RAY& aRay, float aMaxDistance ) const
{ {
// Top / Bottom plane // Top / Bottom plane
// /////////////////////////////////////////////////////////////////////////
const float zPlanePos = aRay.m_dirIsNeg[2]? m_bbox.Max().z : m_bbox.Min().z; const float zPlanePos = aRay.m_dirIsNeg[2]? m_bbox.Max().z : m_bbox.Min().z;
const float tPlane = ( zPlanePos - aRay.m_Origin.z) * aRay.m_InvDir.z; const float tPlane = ( zPlanePos - aRay.m_Origin.z ) * aRay.m_InvDir.z;
if( ( tPlane >= aMaxDistance) || ( tPlane < FLT_EPSILON ) ) if( ( tPlane >= aMaxDistance) || ( tPlane < FLT_EPSILON ) )
return false; // Early exit return false; // Early exit
@ -307,13 +289,11 @@ bool CROUNDSEG::IntersectP( const RAY &aRay, float aMaxDistance ) const
return false; return false;
#if 0 #if 0
// Test LEFT / RIGHT plane // Test LEFT / RIGHT plane
// /////////////////////////////////////////////////////////////////////////
float normal_dot_ray = glm::dot( m_plane_dir_right, aRay.m_Dir ); float normal_dot_ray = glm::dot( m_plane_dir_right, aRay.m_Dir );
if( normal_dot_ray < 0.0f ) // If the dot is neg, the it hits the plane if( normal_dot_ray < 0.0f ) // If the dot is neg, the it hits the plane
{ {
float n_dot_ray_origin = glm::dot( m_plane_dir_right, float n_dot_ray_origin = glm::dot( m_plane_dir_right, m_center_right - aRay.m_Origin );
m_center_right - aRay.m_Origin );
float t = n_dot_ray_origin / normal_dot_ray; float t = n_dot_ray_origin / normal_dot_ray;
if( t > 0.0f ) if( t > 0.0f )
@ -323,8 +303,8 @@ bool CROUNDSEG::IntersectP( const RAY &aRay, float aMaxDistance ) const
SFVEC3F v = hitP - m_center_right; SFVEC3F v = hitP - m_center_right;
float len = glm::dot( v, v ); float len = glm::dot( v, v );
if( (len <= m_seglen_over_two_squared) && if( ( len <= m_seglen_over_two_squared ) &&
(hitP.z >= m_bbox.Min().z) && (hitP.z <= m_bbox.Max().z) ) ( hitP.z >= m_bbox.Min().z ) && ( hitP.z <= m_bbox.Max().z ) )
{ {
if( t < aMaxDistance ) if( t < aMaxDistance )
return true; return true;
@ -350,8 +330,8 @@ bool CROUNDSEG::IntersectP( const RAY &aRay, float aMaxDistance ) const
SFVEC3F v = hitP - m_center_left; SFVEC3F v = hitP - m_center_left;
float len = glm::dot( v, v ); float len = glm::dot( v, v );
if( (len <= m_seglen_over_two_squared) && if( ( len <= m_seglen_over_two_squared ) &&
(hitP.z >= m_bbox.Min().z) && (hitP.z <= m_bbox.Max().z) ) ( hitP.z >= m_bbox.Min().z ) && ( hitP.z <= m_bbox.Max().z ) )
{ {
if( t < aMaxDistance ) if( t < aMaxDistance )
return true; return true;
@ -362,11 +342,8 @@ bool CROUNDSEG::IntersectP( const RAY &aRay, float aMaxDistance ) const
} }
} }
// Based on: // Based on: http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
// http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
// Ray-sphere intersection: geometric // Ray-sphere intersection: geometric
// /////////////////////////////////////////////////////////////////////////
double OCx_Start = aRay.m_Origin.x - m_segment.m_Start.x; double OCx_Start = aRay.m_Origin.x - m_segment.m_Start.x;
double OCy_Start = aRay.m_Origin.y - m_segment.m_Start.y; double OCy_Start = aRay.m_Origin.y - m_segment.m_Start.y;
@ -389,8 +366,7 @@ bool CROUNDSEG::IntersectP( const RAY &aRay, float aMaxDistance ) const
float t = (-b_Start - sdelta) / a; float t = (-b_Start - sdelta) / a;
float z = aRay.m_Origin.z + t * aRay.m_Dir.z; float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
if( (z >= m_bbox.Min().z) && if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
(z <= m_bbox.Max().z) )
{ {
if( t < aMaxDistance ) if( t < aMaxDistance )
return true; return true;
@ -415,11 +391,10 @@ bool CROUNDSEG::IntersectP( const RAY &aRay, float aMaxDistance ) const
if( delta_End > FLT_EPSILON ) if( delta_End > FLT_EPSILON )
{ {
float sdelta = sqrtf( delta_End ); float sdelta = sqrtf( delta_End );
float t = (-b_End - sdelta) / a; float t = ( -b_End - sdelta ) / a;
float z = aRay.m_Origin.z + t * aRay.m_Dir.z; float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
if( (z >= m_bbox.Min().z) && if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
(z <= m_bbox.Max().z) )
{ {
if( t < aMaxDistance ) if( t < aMaxDistance )
return true; return true;
@ -433,14 +408,14 @@ bool CROUNDSEG::IntersectP( const RAY &aRay, float aMaxDistance ) const
} }
bool CROUNDSEG::Intersects( const CBBOX &aBBox ) const bool ROUND_SEGMENT::Intersects( const BBOX_3D& aBBox ) const
{ {
//!TODO: improve //!TODO: improve
return m_bbox.Intersects( aBBox ); return m_bbox.Intersects( aBBox );
} }
SFVEC3F CROUNDSEG::GetDiffuseColor( const HITINFO &aHitInfo ) const SFVEC3F ROUND_SEGMENT::GetDiffuseColor( const HITINFO& aHitInfo ) const
{ {
(void)aHitInfo; // unused (void)aHitInfo; // unused

View File

@ -24,27 +24,26 @@
/** /**
* @file croundseg.h * @file croundseg.h
* @brief
*/ */
#ifndef _CROUNDSEG_H_ #ifndef _ROUND_SEGMENT_H_
#define _CROUNDSEG_H_ #define _ROUND_SEGMENT_H_
#include "cobject.h" #include "cobject.h"
#include "../shapes2D/croundsegment2d.h" #include "../shapes2D/croundsegment2d.h"
class CROUNDSEG : public COBJECT class ROUND_SEGMENT : public OBJECT_3D
{ {
public: public:
CROUNDSEG( const CROUNDSEGMENT2D &aSeg2D, float aZmin, float aZmax ); ROUND_SEGMENT( const ROUND_SEGMENT_2D& aSeg2D, float aZmin, float aZmax );
void SetColor( SFVEC3F aObjColor ) { m_diffusecolor = aObjColor; } void SetColor( SFVEC3F aObjColor ) { m_diffusecolor = aObjColor; }
// Imported from COBJECT // Imported from OBJECT_3D
bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const override; bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const override;
bool IntersectP( const RAY &aRay, float aMaxDistance ) const override; bool IntersectP( const RAY& aRay, float aMaxDistance ) const override;
bool Intersects( const CBBOX &aBBox ) const override; bool Intersects( const BBOX_3D& aBBox ) const override;
SFVEC3F GetDiffuseColor( const HITINFO &aHitInfo ) const override; SFVEC3F GetDiffuseColor( const HITINFO& aHitInfo ) const override;
private: private:
RAYSEG2D m_segment; RAYSEG2D m_segment;
@ -65,22 +64,19 @@ private:
#if 0 #if 0
/** /**
* This is a object similar to a round segment but with a ring * This is a object similar to a round segment but with a ring indside of it.
*
* It is used for Oblong holes * It is used for Oblong holes
*/ */
class COBLONGRING : public COBJECT class OBLONG_RING : public OBJECT_3D
{ {
public: public:
CROUNDSEG( const SFVEC2F &aStart, ROUND_SEGMENT( const SFVEC2F& aStart, const SFVEC2F& aEnd, float aInnerRadius,
const SFVEC2F &aEnd, float aOuterRadius, float aZmin, float aZmax );
float aInnerRadius,
float aOuterRadius,
float aZmin,
float aZmax );
// Imported from COBJECT // Imported from OBJECT_3D
bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const; bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const;
bool Intersects( const CBBOX &aBBox ) const; bool Intersects( const BBOX_3D& aBBox ) const;
private: private:
RAYSEG2D m_segment; RAYSEG2D m_segment;
@ -101,4 +97,4 @@ private:
}; };
#endif #endif
#endif // _CROUNDSEG_H_ #endif // _ROUND_SEGMENT_H_

View File

@ -34,11 +34,11 @@
#include "ctriangle.h" #include "ctriangle.h"
void CTRIANGLE::pre_calc_const() void TRIANGLE::pre_calc_const()
{ {
const SFVEC3F &A = m_vertex[0]; const SFVEC3F& A = m_vertex[0];
const SFVEC3F &B = m_vertex[1]; const SFVEC3F& B = m_vertex[1];
const SFVEC3F &C = m_vertex[2]; const SFVEC3F& C = m_vertex[2];
const SFVEC3F c = B - A; const SFVEC3F c = B - A;
const SFVEC3F b = C - A; const SFVEC3F b = C - A;
@ -66,9 +66,8 @@ void CTRIANGLE::pre_calc_const()
m_k = 2; m_k = 2;
} }
int u = (m_k + 1) % 3; int u = ( m_k + 1 ) % 3;
int v = (m_k + 2) % 3; int v = ( m_k + 2 ) % 3;
// precomp // precomp
float krec = 1.0f / m_n[m_k]; float krec = 1.0f / m_n[m_k];
@ -77,14 +76,12 @@ void CTRIANGLE::pre_calc_const()
m_nv = m_n[v] * krec; m_nv = m_n[v] * krec;
m_nd = glm::dot( m_n, A ) * krec; m_nd = glm::dot( m_n, A ) * krec;
// first line equation // first line equation
float reci = 1.0f / (b[u] * c[v] - b[v] * c[u]); float reci = 1.0f / (b[u] * c[v] - b[v] * c[u]);
m_bnu = b[u] * reci; m_bnu = b[u] * reci;
m_bnv = -b[v] * reci; m_bnv = -b[v] * reci;
// second line equation // second line equation
m_cnu = c[v] * reci; m_cnu = c[v] * reci;
m_cnv = -c[u] * reci; m_cnv = -c[u] * reci;
@ -98,8 +95,8 @@ void CTRIANGLE::pre_calc_const()
} }
CTRIANGLE::CTRIANGLE( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3 ) TRIANGLE::TRIANGLE( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3 )
: COBJECT( OBJECT3D_TYPE::TRIANGLE ) : OBJECT_3D( OBJECT_3D_TYPE::TRIANGLE )
{ {
m_vertex[0] = aV1; m_vertex[0] = aV1;
m_vertex[1] = aV2; m_vertex[1] = aV2;
@ -113,9 +110,9 @@ CTRIANGLE::CTRIANGLE( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3
} }
CTRIANGLE::CTRIANGLE( TRIANGLE::TRIANGLE( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3,
const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3, const SFVEC3F& aFaceNormal ) const SFVEC3F& aFaceNormal )
: COBJECT( OBJECT3D_TYPE::TRIANGLE ) : OBJECT_3D( OBJECT_3D_TYPE::TRIANGLE )
{ {
m_vertex[0] = aV1; m_vertex[0] = aV1;
m_vertex[1] = aV2; m_vertex[1] = aV2;
@ -133,9 +130,9 @@ CTRIANGLE::CTRIANGLE(
} }
CTRIANGLE::CTRIANGLE( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3, TRIANGLE::TRIANGLE( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3,
const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3 ) const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3 )
: COBJECT( OBJECT3D_TYPE::TRIANGLE ) : OBJECT_3D( OBJECT_3D_TYPE::TRIANGLE )
{ {
m_vertex[0] = aV1; m_vertex[0] = aV1;
m_vertex[1] = aV2; m_vertex[1] = aV2;
@ -153,33 +150,33 @@ CTRIANGLE::CTRIANGLE( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3
} }
void CTRIANGLE::SetColor( const SFVEC3F &aColor ) void TRIANGLE::SetColor( const SFVEC3F& aColor )
{ {
m_vertexColorRGBA[0] = ((unsigned int)(aColor.r * 255) << 24) | m_vertexColorRGBA[0] = ( (unsigned int) ( aColor.r * 255 ) << 24 )
((unsigned int)(aColor.g * 255) << 16) | | ( (unsigned int) ( aColor.g * 255 ) << 16 )
((unsigned int)(aColor.b * 255) << 8) | 0xFF; | ( (unsigned int) ( aColor.b * 255 ) << 8 ) | 0xFF;
m_vertexColorRGBA[1] = m_vertexColorRGBA[0]; m_vertexColorRGBA[1] = m_vertexColorRGBA[0];
m_vertexColorRGBA[2] = m_vertexColorRGBA[0]; m_vertexColorRGBA[2] = m_vertexColorRGBA[0];
} }
void CTRIANGLE::SetColor( const SFVEC3F &aVC0, void TRIANGLE::SetColor( const SFVEC3F& aVC0,
const SFVEC3F &aVC1, const SFVEC3F& aVC1,
const SFVEC3F &aVC2 ) const SFVEC3F& aVC2 )
{ {
m_vertexColorRGBA[0] = ((unsigned int)(aVC0.r * 255) << 24) | m_vertexColorRGBA[0] = ( (unsigned int) ( aVC0.r * 255 ) << 24 )
((unsigned int)(aVC0.g * 255) << 16) | | ( (unsigned int) ( aVC0.g * 255 ) << 16 )
((unsigned int)(aVC0.b * 255) << 8) | 0xFF; | ( (unsigned int) ( aVC0.b * 255 ) << 8 ) | 0xFF;
m_vertexColorRGBA[1] = ((unsigned int)(aVC1.r * 255) << 24) | m_vertexColorRGBA[1] = ( (unsigned int) ( aVC1.r * 255 ) << 24 )
((unsigned int)(aVC1.g * 255) << 16) | | ( (unsigned int) ( aVC1.g * 255 ) << 16 )
((unsigned int)(aVC1.b * 255) << 8) | 0xFF; | ( (unsigned int) ( aVC1.b * 255 ) << 8 ) | 0xFF;
m_vertexColorRGBA[2] = ((unsigned int)(aVC2.r * 255) << 24) | m_vertexColorRGBA[2] = ( (unsigned int) ( aVC2.r * 255 ) << 24 )
((unsigned int)(aVC2.g * 255) << 16) | | ( (unsigned int) ( aVC2.g * 255 ) << 16 )
((unsigned int)(aVC2.b * 255) << 8) | 0xFF; | ( (unsigned int) ( aVC2.b * 255 ) << 8 ) | 0xFF;
} }
void CTRIANGLE::SetColor( unsigned int aFaceColorRGBA ) void TRIANGLE::SetColor( unsigned int aFaceColorRGBA )
{ {
m_vertexColorRGBA[0] = aFaceColorRGBA; m_vertexColorRGBA[0] = aFaceColorRGBA;
m_vertexColorRGBA[1] = aFaceColorRGBA; m_vertexColorRGBA[1] = aFaceColorRGBA;
@ -187,8 +184,7 @@ void CTRIANGLE::SetColor( unsigned int aFaceColorRGBA )
} }
void CTRIANGLE::SetColor( unsigned int aVertex1ColorRGBA, void TRIANGLE::SetColor( unsigned int aVertex1ColorRGBA, unsigned int aVertex2ColorRGBA,
unsigned int aVertex2ColorRGBA,
unsigned int aVertex3ColorRGBA ) unsigned int aVertex3ColorRGBA )
{ {
m_vertexColorRGBA[0] = aVertex1ColorRGBA; m_vertexColorRGBA[0] = aVertex1ColorRGBA;
@ -197,9 +193,7 @@ void CTRIANGLE::SetColor( unsigned int aVertex1ColorRGBA,
} }
void CTRIANGLE::SetUV( const SFVEC2F &aUV1, void TRIANGLE::SetUV( const SFVEC2F& aUV1, const SFVEC2F& aUV2, const SFVEC2F& aUV3 )
const SFVEC2F &aUV2,
const SFVEC2F &aUV3 )
{ {
m_uv[0] = aUV1; m_uv[0] = aUV1;
m_uv[1] = aUV2; m_uv[1] = aUV2;
@ -209,20 +203,21 @@ void CTRIANGLE::SetUV( const SFVEC2F &aUV1,
static const unsigned int s_modulo[] = { 0, 1, 2, 0, 1 }; static const unsigned int s_modulo[] = { 0, 1, 2, 0, 1 };
bool CTRIANGLE::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
bool TRIANGLE::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
{ {
//!TODO: precalc this, improove it //!TODO: precalc this, improove it
#define ku s_modulo[m_k + 1] #define ku s_modulo[m_k + 1]
#define kv s_modulo[m_k + 2] #define kv s_modulo[m_k + 2]
const SFVEC3F &O = aRay.m_Origin; const SFVEC3F& O = aRay.m_Origin;
const SFVEC3F &D = aRay.m_Dir; const SFVEC3F& D = aRay.m_Dir;
const SFVEC3F &A = m_vertex[0]; const SFVEC3F& A = m_vertex[0];
const float lnd = 1.0f / (D[m_k] + m_nu * D[ku] + m_nv * D[kv]); const float lnd = 1.0f / (D[m_k] + m_nu * D[ku] + m_nv * D[kv]);
const float t = (m_nd - O[m_k] - m_nu * O[ku] - m_nv * O[kv]) * lnd; const float t = (m_nd - O[m_k] - m_nu * O[ku] - m_nv * O[kv]) * lnd;
if( !( (aHitInfo.m_tHit > t) && (t > 0.0f) ) ) if( !( ( aHitInfo.m_tHit > t ) && ( t > 0.0f ) ) )
return false; return false;
const float hu = O[ku] + t * D[ku] - A[ku]; const float hu = O[ku] + t * D[ku] - A[ku];
@ -250,8 +245,7 @@ bool CTRIANGLE::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
aHitInfo.m_HitPoint = aRay.at( t ); aHitInfo.m_HitPoint = aRay.at( t );
// interpolate vertex normals with UVW using Gouraud's shading // interpolate vertex normals with UVW using Gouraud's shading
aHitInfo.m_HitNormal = glm::normalize( (1.0f - u - v) * m_normal[0] + aHitInfo.m_HitNormal = glm::normalize( (1.0f - u - v) * m_normal[0] + u * m_normal[1] +
u * m_normal[1] +
v * m_normal[2] ); v * m_normal[2] );
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo ); m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
@ -264,8 +258,7 @@ bool CTRIANGLE::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
} }
bool CTRIANGLE::IntersectP( const RAY &aRay, bool TRIANGLE::IntersectP( const RAY& aRay, float aMaxDistance ) const
float aMaxDistance ) const
{ {
//!TODO: precalc this //!TODO: precalc this
#define ku s_modulo[m_k + 1] #define ku s_modulo[m_k + 1]
@ -278,7 +271,7 @@ bool CTRIANGLE::IntersectP( const RAY &aRay,
const float lnd = 1.0f / (D[m_k] + m_nu * D[ku] + m_nv * D[kv]); const float lnd = 1.0f / (D[m_k] + m_nu * D[ku] + m_nv * D[kv]);
const float t = (m_nd - O[m_k] - m_nu * O[ku] - m_nv * O[kv]) * lnd; const float t = (m_nd - O[m_k] - m_nu * O[ku] - m_nv * O[kv]) * lnd;
if( !( (aMaxDistance > t) && (t > 0.0f) ) ) if( !( ( aMaxDistance > t ) && ( t > 0.0f ) ) )
return false; return false;
const float hu = O[ku] + t * D[ku] - A[ku]; const float hu = O[ku] + t * D[ku] - A[ku];
@ -308,28 +301,28 @@ bool CTRIANGLE::IntersectP( const RAY &aRay,
} }
bool CTRIANGLE::Intersects( const CBBOX &aBBox ) const bool TRIANGLE::Intersects( const BBOX_3D& aBBox ) const
{ {
//!TODO: improove //!TODO: improove
return m_bbox.Intersects( aBBox ); return m_bbox.Intersects( aBBox );
} }
SFVEC3F CTRIANGLE::GetDiffuseColor( const HITINFO &aHitInfo ) const SFVEC3F TRIANGLE::GetDiffuseColor( const HITINFO& aHitInfo ) const
{ {
const unsigned int rgbC1 = m_vertexColorRGBA[0]; const unsigned int rgbC1 = m_vertexColorRGBA[0];
const unsigned int rgbC2 = m_vertexColorRGBA[1]; const unsigned int rgbC2 = m_vertexColorRGBA[1];
const unsigned int rgbC3 = m_vertexColorRGBA[2]; const unsigned int rgbC3 = m_vertexColorRGBA[2];
const SFVEC3F c1 = SFVEC3F( (float)((rgbC1 >> 24) & 0xFF) / 255.0f, const SFVEC3F c1 = SFVEC3F( (float) ( ( rgbC1 >> 24 ) & 0xFF ) / 255.0f,
(float)((rgbC1 >> 16) & 0xFF) / 255.0f, (float) ( ( rgbC1 >> 16 ) & 0xFF ) / 255.0f,
(float)((rgbC1 >> 8) & 0xFF) / 255.0f ); (float) ( ( rgbC1 >> 8 ) & 0xFF ) / 255.0f );
const SFVEC3F c2 = SFVEC3F( (float)((rgbC2 >> 24) & 0xFF) / 255.0f, const SFVEC3F c2 = SFVEC3F( (float) ( ( rgbC2 >> 24 ) & 0xFF ) / 255.0f,
(float)((rgbC2 >> 16) & 0xFF) / 255.0f, (float) ( ( rgbC2 >> 16 ) & 0xFF ) / 255.0f,
(float)((rgbC2 >> 8) & 0xFF) / 255.0f ); (float) ( ( rgbC2 >> 8 ) & 0xFF ) / 255.0f );
const SFVEC3F c3 = SFVEC3F( (float)((rgbC3 >> 24) & 0xFF) / 255.0f, const SFVEC3F c3 = SFVEC3F( (float) ( ( rgbC3 >> 24 ) & 0xFF ) / 255.0f,
(float)((rgbC3 >> 16) & 0xFF) / 255.0f, (float) ( ( rgbC3 >> 16 ) & 0xFF ) / 255.0f,
(float)((rgbC3 >> 8) & 0xFF) / 255.0f ); (float) ( ( rgbC3 >> 8 ) & 0xFF ) / 255.0f );
const float u = aHitInfo.m_UV.x; const float u = aHitInfo.m_UV.x;
const float v = aHitInfo.m_UV.y; const float v = aHitInfo.m_UV.y;

View File

@ -25,48 +25,46 @@
/** /**
* @file ctriangle.h * @file ctriangle.h
* @brief Implements a triangle ray intersection based on article * @brief Implement a triangle ray intersection based on article
* http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_7_Kd-Trees_and_More_Speed.shtml * http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_7_Kd-Trees_and_More_Speed.shtml
* by Jacco Bikker, that implement optimizations based on Ingo Wald's thesis. * by Jacco Bikker, that implement optimizations based on Ingo Wald's thesis.
*/ */
#ifndef _CTRIANGLE_H_ #ifndef _TRIANGLE_H_
#define _CTRIANGLE_H_ #define _TRIANGLE_H_
#include "cobject.h" #include "cobject.h"
/** /**
* A triangle object * A triangle object.
*/ */
class CTRIANGLE : public COBJECT class TRIANGLE : public OBJECT_3D
{ {
public: public:
CTRIANGLE( const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3 ); TRIANGLE( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3 );
CTRIANGLE( const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, TRIANGLE( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3,
const SFVEC3F &aFaceNormal ); const SFVEC3F& aFaceNormal );
CTRIANGLE( const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, TRIANGLE( const SFVEC3F& aV1, const SFVEC3F& aV2, const SFVEC3F& aV3,
const SFVEC3F &aN1, const SFVEC3F &aN2, const SFVEC3F &aN3 ); const SFVEC3F& aN1, const SFVEC3F& aN2, const SFVEC3F& aN3 );
void SetColor( const SFVEC3F &aColor ); void SetColor( const SFVEC3F& aColor );
void SetColor( const SFVEC3F &aVC0, const SFVEC3F &aVC1, const SFVEC3F &aVC2 ); void SetColor( const SFVEC3F& aVC0, const SFVEC3F& aVC1, const SFVEC3F& aVC2 );
void SetColor( unsigned int aFaceColorRGBA ); void SetColor( unsigned int aFaceColorRGBA );
void SetColor( unsigned int aVertex1ColorRGBA, void SetColor( unsigned int aVertex1ColorRGBA, unsigned int aVertex2ColorRGBA,
unsigned int aVertex2ColorRGBA,
unsigned int aVertex3ColorRGBA ); unsigned int aVertex3ColorRGBA );
void SetUV( const SFVEC2F &aUV1, const SFVEC2F &aUV2, const SFVEC2F &aUV3 ); void SetUV( const SFVEC2F& aUV1, const SFVEC2F& aUV2, const SFVEC2F& aUV3 );
// Imported from COBJECT bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const override;
bool Intersect( const RAY &aRay, HITINFO &aHitInfo ) const override; bool IntersectP(const RAY& aRay, float aMaxDistance ) const override;
bool IntersectP(const RAY &aRay , float aMaxDistance ) const override; bool Intersects( const BBOX_3D& aBBox ) const override;
bool Intersects( const CBBOX &aBBox ) const override; SFVEC3F GetDiffuseColor( const HITINFO& aHitInfo ) const override;
SFVEC3F GetDiffuseColor( const HITINFO &aHitInfo ) const override;
private: private:
void pre_calc_const(); void pre_calc_const();
@ -83,4 +81,4 @@ private:
// 152 bytes (max 160 == 5 * 32) // 152 bytes (max 160 == 5 * 32)
}; };
#endif // _CTRIANGLE_H_ #endif // _TRIANGLE_H_

View File

@ -40,32 +40,32 @@
* *
* @ingroup trace_env_vars * @ingroup trace_env_vars
*/ */
const wxChar* C3D_RENDER_BASE::m_logTrace = wxT( "KI_TRACE_3D_RENDER" ); const wxChar* RENDER_3D_BASE::m_logTrace = wxT( "KI_TRACE_3D_RENDER" );
C3D_RENDER_BASE::C3D_RENDER_BASE( BOARD_ADAPTER& aBoardAdapter, CCAMERA& aCamera ) : RENDER_3D_BASE::RENDER_3D_BASE( BOARD_ADAPTER& aBoardAdapter, CAMERA& aCamera ) :
m_boardAdapter( aBoardAdapter ), m_boardAdapter( aBoardAdapter ),
m_camera( aCamera ) m_camera( aCamera )
{ {
wxLogTrace( m_logTrace, wxT( "C3D_RENDER_BASE::C3D_RENDER_BASE" ) ); wxLogTrace( m_logTrace, wxT( "RENDER_3D_BASE::RENDER_3D_BASE" ) );
m_is_opengl_initialized = false; m_is_opengl_initialized = false;
m_windowSize = wxSize( -1, -1 ); m_windowSize = wxSize( -1, -1 );
m_reloadRequested = true; m_reloadRequested = true;
} }
C3D_RENDER_BASE::~C3D_RENDER_BASE() RENDER_3D_BASE::~RENDER_3D_BASE()
{ {
} }
void C3D_RENDER_BASE::SetBusyIndicatorFactory( BUSY_INDICATOR::FACTORY aNewFactory ) void RENDER_3D_BASE::SetBusyIndicatorFactory( BUSY_INDICATOR::FACTORY aNewFactory )
{ {
m_busyIndicatorFactory = aNewFactory; m_busyIndicatorFactory = aNewFactory;
} }
std::unique_ptr<BUSY_INDICATOR> C3D_RENDER_BASE::CreateBusyIndicator() const std::unique_ptr<BUSY_INDICATOR> RENDER_3D_BASE::CreateBusyIndicator() const
{ {
std::unique_ptr<BUSY_INDICATOR> busy; std::unique_ptr<BUSY_INDICATOR> busy;

View File

@ -27,8 +27,8 @@
* @brief * @brief
*/ */
#ifndef C3D_RENDER_BASE_H #ifndef RENDER_3D_BASE_H
#define C3D_RENDER_BASE_H #define RENDER_3D_BASE_H
#include <pcb_base_frame.h> #include <pcb_base_frame.h>
@ -40,12 +40,12 @@
/** /**
* This is a base class to hold data and functions for render targets. * This is a base class to hold data and functions for render targets.
*/ */
class C3D_RENDER_BASE class RENDER_3D_BASE
{ {
public: public:
explicit C3D_RENDER_BASE( BOARD_ADAPTER& aBoardAdapter, CCAMERA& aCamera ); explicit RENDER_3D_BASE( BOARD_ADAPTER& aBoardAdapter, CAMERA& aCamera );
virtual ~C3D_RENDER_BASE() = 0; virtual ~RENDER_3D_BASE() = 0;
/** /**
* Before each render, the canvas will tell the render what is the size of its windows, * Before each render, the canvas will tell the render what is the size of its windows,
@ -53,7 +53,7 @@ public:
* *
* @param aSize the current size of the render window * @param aSize the current size of the render window
*/ */
virtual void SetCurWindowSize( const wxSize &aSize ) = 0; virtual void SetCurWindowSize( const wxSize& aSize ) = 0;
/** /**
* Redraw the view. * Redraw the view.
@ -62,8 +62,8 @@ public:
* @param aStatusReporter a pointer to the status progress reporter. * @param aStatusReporter a pointer to the status progress reporter.
* @return true if the render would like to redraw again. * @return true if the render would like to redraw again.
*/ */
virtual bool Redraw( bool aIsMoving, REPORTER* aStatusReporter = NULL, virtual bool Redraw( bool aIsMoving, REPORTER* aStatusReporter = nullptr,
REPORTER* aWarningReporter = NULL ) = 0; REPORTER* aWarningReporter = nullptr ) = 0;
/** /**
* @todo This must be reviewed to add flags to improve specific render. * @todo This must be reviewed to add flags to improve specific render.
@ -102,7 +102,7 @@ protected:
///< Settings reference in use for this render. ///< Settings reference in use for this render.
BOARD_ADAPTER& m_boardAdapter; BOARD_ADAPTER& m_boardAdapter;
CCAMERA& m_camera; CAMERA& m_camera;
///< Flag if the opengl specific for this render was already initialized. ///< Flag if the opengl specific for this render was already initialized.
bool m_is_opengl_initialized; bool m_is_opengl_initialized;
@ -119,11 +119,11 @@ protected:
* "KI_TRACE_3D_RENDER". See the wxWidgets documentation on wxLogTrace for * "KI_TRACE_3D_RENDER". See the wxWidgets documentation on wxLogTrace for
* more information. * more information.
*/ */
static const wxChar *m_logTrace; static const wxChar* m_logTrace;
private: private:
///< Factory that returns a suitable busy indicator for the context. ///< Factory that returns a suitable busy indicator for the context.
BUSY_INDICATOR::FACTORY m_busyIndicatorFactory; BUSY_INDICATOR::FACTORY m_busyIndicatorFactory;
}; };
#endif // C3D_RENDER_BASE_H #endif // RENDER_3D_BASE_H

View File

@ -45,16 +45,16 @@ inline void normalise2PI( float& aAngle )
/** /**
* @ingroup trace_env_vars * @ingroup trace_env_vars
*/ */
const wxChar *CCAMERA::m_logTrace = wxT( "KI_TRACE_CCAMERA" ); const wxChar *CAMERA::m_logTrace = wxT( "KI_TRACE_CAMERA" );
#define MIN_ZOOM 0.10f #define MIN_ZOOM 0.10f
#define MAX_ZOOM 1.25f #define MAX_ZOOM 1.25f
CCAMERA::CCAMERA( float aRangeScale ) CAMERA::CAMERA( float aRangeScale )
{ {
wxLogTrace( m_logTrace, wxT( "CCAMERA::CCAMERA" ) ); wxLogTrace( m_logTrace, wxT( "CAMERA::CAMERA" ) );
m_range_scale = aRangeScale; m_range_scale = aRangeScale;
m_camera_pos_init = SFVEC3F( 0.0f, 0.0f, -(aRangeScale * 2.0f ) ); m_camera_pos_init = SFVEC3F( 0.0f, 0.0f, -(aRangeScale * 2.0f ) );
@ -67,7 +67,7 @@ CCAMERA::CCAMERA( float aRangeScale )
} }
void CCAMERA::Reset() void CAMERA::Reset()
{ {
m_parametersChanged = true; m_parametersChanged = true;
m_projectionMatrix = glm::mat4( 1.0f ); m_projectionMatrix = glm::mat4( 1.0f );
@ -99,7 +99,7 @@ void CCAMERA::Reset()
} }
void CCAMERA::Reset_T1() void CAMERA::Reset_T1()
{ {
m_camera_pos_t1 = m_camera_pos_init; m_camera_pos_t1 = m_camera_pos_init;
m_zoom_t1 = 1.0f; m_zoom_t1 = 1.0f;
@ -120,7 +120,7 @@ void CCAMERA::Reset_T1()
} }
void CCAMERA::updateViewMatrix() void CAMERA::updateViewMatrix()
{ {
m_viewMatrix = glm::translate( glm::mat4( 1.0f ), m_camera_pos ) * m_viewMatrix = glm::translate( glm::mat4( 1.0f ), m_camera_pos ) *
m_rotationMatrix * m_rotationMatrixAux * m_rotationMatrix * m_rotationMatrixAux *
@ -128,20 +128,17 @@ void CCAMERA::updateViewMatrix()
} }
void CCAMERA::updateRotationMatrix() void CAMERA::updateRotationMatrix()
{ {
m_rotationMatrixAux = glm::rotate( glm::mat4( 1.0f ), m_rotationMatrixAux = glm::rotate( glm::mat4( 1.0f ), m_rotate_aux.x,
m_rotate_aux.x,
SFVEC3F( 1.0f, 0.0f, 0.0f ) ); SFVEC3F( 1.0f, 0.0f, 0.0f ) );
normalise2PI( m_rotate_aux.x ); normalise2PI( m_rotate_aux.x );
m_rotationMatrixAux = glm::rotate( m_rotationMatrixAux, m_rotationMatrixAux = glm::rotate( m_rotationMatrixAux, m_rotate_aux.y,
m_rotate_aux.y,
SFVEC3F( 0.0f, 1.0f, 0.0f ) ); SFVEC3F( 0.0f, 1.0f, 0.0f ) );
normalise2PI( m_rotate_aux.y ); normalise2PI( m_rotate_aux.y );
m_rotationMatrixAux = glm::rotate( m_rotationMatrixAux, m_rotationMatrixAux = glm::rotate( m_rotationMatrixAux, m_rotate_aux.z,
m_rotate_aux.z,
SFVEC3F( 0.0f, 0.0f, 1.0f ) ); SFVEC3F( 0.0f, 0.0f, 1.0f ) );
normalise2PI( m_rotate_aux.z ); normalise2PI( m_rotate_aux.z );
@ -152,13 +149,13 @@ void CCAMERA::updateRotationMatrix()
} }
const glm::mat4 CCAMERA::GetRotationMatrix() const const glm::mat4 CAMERA::GetRotationMatrix() const
{ {
return m_rotationMatrix * m_rotationMatrixAux; return m_rotationMatrix * m_rotationMatrixAux;
} }
void CCAMERA::rebuildProjection() void CAMERA::rebuildProjection()
{ {
if( ( m_windowSize.x == 0 ) || ( m_windowSize.y == 0 ) ) if( ( m_windowSize.x == 0 ) || ( m_windowSize.y == 0 ) )
return; return;
@ -178,10 +175,8 @@ void CCAMERA::rebuildProjection()
// Ratio width / height of the window display // Ratio width / height of the window display
m_frustum.angle = 45.0f * m_zoom; m_frustum.angle = 45.0f * m_zoom;
m_projectionMatrix = glm::perspective( glm::radians( m_frustum.angle ), m_projectionMatrix = glm::perspective( glm::radians( m_frustum.angle ), m_frustum.ratio,
m_frustum.ratio, m_frustum.nearD, m_frustum.farD );
m_frustum.nearD,
m_frustum.farD );
m_projectionMatrixInv = glm::inverse( m_projectionMatrix ); m_projectionMatrixInv = glm::inverse( m_projectionMatrix );
@ -253,7 +248,7 @@ void CCAMERA::rebuildProjection()
} }
void CCAMERA::updateFrustum() void CAMERA::updateFrustum()
{ {
// Update matrix and vectors // Update matrix and vectors
m_viewMatrixInverse = glm::inverse( m_viewMatrix ); m_viewMatrixInverse = glm::inverse( m_viewMatrix );
@ -311,8 +306,8 @@ void CCAMERA::updateFrustum()
} }
void CCAMERA::MakeRay( const SFVEC2I &aWindowPos, SFVEC3F &aOutOrigin, void CAMERA::MakeRay( const SFVEC2I& aWindowPos, SFVEC3F& aOutOrigin,
SFVEC3F &aOutDirection ) const SFVEC3F& aOutDirection ) const
{ {
wxASSERT( aWindowPos.x < m_windowSize.x ); wxASSERT( aWindowPos.x < m_windowSize.x );
wxASSERT( aWindowPos.y < m_windowSize.y ); wxASSERT( aWindowPos.y < m_windowSize.y );
@ -335,8 +330,8 @@ void CCAMERA::MakeRay( const SFVEC2I &aWindowPos, SFVEC3F &aOutOrigin,
} }
void CCAMERA::MakeRay( const SFVEC2F &aWindowPos, SFVEC3F &aOutOrigin, void CAMERA::MakeRay( const SFVEC2F& aWindowPos, SFVEC3F& aOutOrigin,
SFVEC3F &aOutDirection ) const SFVEC3F& aOutDirection ) const
{ {
wxASSERT( aWindowPos.x < (float)m_windowSize.x ); wxASSERT( aWindowPos.x < (float)m_windowSize.x );
wxASSERT( aWindowPos.y < (float)m_windowSize.y ); wxASSERT( aWindowPos.y < (float)m_windowSize.y );
@ -367,7 +362,7 @@ void CCAMERA::MakeRay( const SFVEC2F &aWindowPos, SFVEC3F &aOutOrigin,
} }
void CCAMERA::MakeRayAtCurrrentMousePosition( SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection ) const void CAMERA::MakeRayAtCurrrentMousePosition( SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const
{ {
const SFVEC2I windowPos = SFVEC2I( m_lastPosition.x, m_windowSize.y - m_lastPosition.y ); const SFVEC2I windowPos = SFVEC2I( m_lastPosition.x, m_windowSize.y - m_lastPosition.y );
@ -379,19 +374,19 @@ void CCAMERA::MakeRayAtCurrrentMousePosition( SFVEC3F &aOutOrigin, SFVEC3F &aOut
} }
const glm::mat4 &CCAMERA::GetProjectionMatrix() const const glm::mat4& CAMERA::GetProjectionMatrix() const
{ {
return m_projectionMatrix; return m_projectionMatrix;
} }
const glm::mat4 &CCAMERA::GetProjectionMatrixInv() const const glm::mat4& CAMERA::GetProjectionMatrixInv() const
{ {
return m_projectionMatrixInv; return m_projectionMatrixInv;
} }
void CCAMERA::ResetXYpos() void CAMERA::ResetXYpos()
{ {
m_parametersChanged = true; m_parametersChanged = true;
m_camera_pos.x = 0.0f; m_camera_pos.x = 0.0f;
@ -402,32 +397,32 @@ void CCAMERA::ResetXYpos()
} }
void CCAMERA::ResetXYpos_T1() void CAMERA::ResetXYpos_T1()
{ {
m_camera_pos_t1.x = 0.0f; m_camera_pos_t1.x = 0.0f;
m_camera_pos_t1.y = 0.0f; m_camera_pos_t1.y = 0.0f;
} }
const glm::mat4 &CCAMERA::GetViewMatrix() const const glm::mat4& CAMERA::GetViewMatrix() const
{ {
return m_viewMatrix; return m_viewMatrix;
} }
const glm::mat4 &CCAMERA::GetViewMatrix_Inv() const const glm::mat4& CAMERA::GetViewMatrix_Inv() const
{ {
return m_viewMatrixInverse; return m_viewMatrixInverse;
} }
void CCAMERA::SetCurMousePosition( const wxPoint &aNewMousePosition ) void CAMERA::SetCurMousePosition( const wxPoint& aNewMousePosition )
{ {
m_lastPosition = aNewMousePosition; m_lastPosition = aNewMousePosition;
} }
void CCAMERA::ToggleProjection() void CAMERA::ToggleProjection()
{ {
if( m_projectionType == PROJECTION_TYPE::ORTHO ) if( m_projectionType == PROJECTION_TYPE::ORTHO )
m_projectionType = PROJECTION_TYPE::PERSPECTIVE; m_projectionType = PROJECTION_TYPE::PERSPECTIVE;
@ -438,7 +433,7 @@ void CCAMERA::ToggleProjection()
} }
bool CCAMERA::SetCurWindowSize( const wxSize &aSize ) bool CAMERA::SetCurWindowSize( const wxSize& aSize )
{ {
const SFVEC2I newSize = SFVEC2I( aSize.x, aSize.y ); const SFVEC2I newSize = SFVEC2I( aSize.x, aSize.y );
@ -454,7 +449,7 @@ bool CCAMERA::SetCurWindowSize( const wxSize &aSize )
} }
void CCAMERA::ZoomReset() void CAMERA::ZoomReset()
{ {
m_zoom = 1.0f; m_zoom = 1.0f;
@ -464,7 +459,7 @@ void CCAMERA::ZoomReset()
rebuildProjection(); rebuildProjection();
} }
bool CCAMERA::Zoom( float aFactor ) bool CAMERA::Zoom( float aFactor )
{ {
if( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 ) if( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 )
|| aFactor == 1 ) || aFactor == 1 )
@ -487,7 +482,7 @@ bool CCAMERA::Zoom( float aFactor )
} }
bool CCAMERA::Zoom_T1( float aFactor ) bool CAMERA::Zoom_T1( float aFactor )
{ {
if( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 ) if( ( m_zoom == MIN_ZOOM && aFactor > 1 ) || ( m_zoom == MAX_ZOOM && aFactor < 1 )
|| aFactor == 1 ) || aFactor == 1 )
@ -507,52 +502,52 @@ bool CCAMERA::Zoom_T1( float aFactor )
} }
float CCAMERA::ZoomGet() const float CAMERA::ZoomGet() const
{ {
return m_zoom; return m_zoom;
} }
void CCAMERA::RotateX( float aAngleInRadians ) void CAMERA::RotateX( float aAngleInRadians )
{ {
m_rotate_aux.x += aAngleInRadians; m_rotate_aux.x += aAngleInRadians;
updateRotationMatrix(); updateRotationMatrix();
} }
void CCAMERA::RotateY( float aAngleInRadians ) void CAMERA::RotateY( float aAngleInRadians )
{ {
m_rotate_aux.y += aAngleInRadians; m_rotate_aux.y += aAngleInRadians;
updateRotationMatrix(); updateRotationMatrix();
} }
void CCAMERA::RotateZ( float aAngleInRadians ) void CAMERA::RotateZ( float aAngleInRadians )
{ {
m_rotate_aux.z += aAngleInRadians; m_rotate_aux.z += aAngleInRadians;
updateRotationMatrix(); updateRotationMatrix();
} }
void CCAMERA::RotateX_T1( float aAngleInRadians ) void CAMERA::RotateX_T1( float aAngleInRadians )
{ {
m_rotate_aux_t1.x += aAngleInRadians; m_rotate_aux_t1.x += aAngleInRadians;
} }
void CCAMERA::RotateY_T1( float aAngleInRadians ) void CAMERA::RotateY_T1( float aAngleInRadians )
{ {
m_rotate_aux_t1.y += aAngleInRadians; m_rotate_aux_t1.y += aAngleInRadians;
} }
void CCAMERA::RotateZ_T1( float aAngleInRadians ) void CAMERA::RotateZ_T1( float aAngleInRadians )
{ {
m_rotate_aux_t1.z += aAngleInRadians; m_rotate_aux_t1.z += aAngleInRadians;
} }
void CCAMERA::SetT0_and_T1_current_T() void CAMERA::SetT0_and_T1_current_T()
{ {
m_camera_pos_t0 = m_camera_pos; m_camera_pos_t0 = m_camera_pos;
m_lookat_pos_t0 = m_lookat_pos; m_lookat_pos_t0 = m_lookat_pos;
@ -566,7 +561,7 @@ void CCAMERA::SetT0_and_T1_current_T()
} }
void CCAMERA::Interpolate( float t ) void CAMERA::Interpolate( float t )
{ {
wxASSERT( t >= 0.0f ); wxASSERT( t >= 0.0f );
@ -584,7 +579,7 @@ void CCAMERA::Interpolate( float t )
} }
bool CCAMERA::ParametersChanged() bool CAMERA::ParametersChanged()
{ {
const bool parametersChanged = m_parametersChanged; const bool parametersChanged = m_parametersChanged;

View File

@ -27,8 +27,8 @@
* @brief Define an abstract camera * @brief Define an abstract camera
*/ */
#ifndef CCAMERA_H #ifndef CAMERA_H
#define CCAMERA_H #define CAMERA_H
#include "../3d_rendering/3d_render_raytracing/ray.h" #include "../3d_rendering/3d_render_raytracing/ray.h"
#include <wx/gdicmn.h> // for wxSize #include <wx/gdicmn.h> // for wxSize
@ -44,7 +44,7 @@ enum class PROJECTION_TYPE
* Frustum is a implementation based on a tutorial by * Frustum is a implementation based on a tutorial by
* http://www.lighthouse3d.com/tutorials/view-frustum-culling/ * http://www.lighthouse3d.com/tutorials/view-frustum-culling/
*/ */
struct FRUSTUM struct CAMERA_FRUSTUM
{ {
SFVEC3F nc; SFVEC3F nc;
SFVEC3F fc; SFVEC3F fc;
@ -74,7 +74,7 @@ enum class CAMERA_INTERPOLATION
* *
* It must be derived by other classes to implement a real camera object. * It must be derived by other classes to implement a real camera object.
*/ */
class CCAMERA class CAMERA
{ {
public: public:
/** /**
@ -84,13 +84,12 @@ public:
* -aRangeScale/2 to +aRangeScale/2. It will initialize the * -aRangeScale/2 to +aRangeScale/2. It will initialize the
* Z position with aRangeScale. * Z position with aRangeScale.
*/ */
explicit CCAMERA( float aRangeScale ); explicit CAMERA( float aRangeScale );
virtual ~CCAMERA() virtual ~CAMERA()
{ {
} }
/** /**
* Get the rotation matrix to be applied in a transformation camera. * Get the rotation matrix to be applied in a transformation camera.
* *
@ -98,21 +97,21 @@ public:
*/ */
const glm::mat4 GetRotationMatrix() const; const glm::mat4 GetRotationMatrix() const;
const glm::mat4 &GetViewMatrix() const; const glm::mat4& GetViewMatrix() const;
const glm::mat4 &GetViewMatrix_Inv() const; const glm::mat4& GetViewMatrix_Inv() const;
const glm::mat4 &GetProjectionMatrix() const; const glm::mat4& GetProjectionMatrix() const;
const glm::mat4 &GetProjectionMatrixInv() const; const glm::mat4& GetProjectionMatrixInv() const;
const SFVEC3F &GetRight() const { return m_right; } const SFVEC3F& GetRight() const { return m_right; }
const SFVEC3F &GetUp() const { return m_up; } const SFVEC3F& GetUp() const { return m_up; }
const SFVEC3F &GetDir() const { return m_dir; } const SFVEC3F& GetDir() const { return m_dir; }
const SFVEC3F &GetPos() const { return m_pos; } const SFVEC3F& GetPos() const { return m_pos; }
const SFVEC2F &GetFocalLen() const { return m_focalLen; } const SFVEC2F& GetFocalLen() const { return m_focalLen; }
float GetNear() const { return m_frustum.nearD; } float GetNear() const { return m_frustum.nearD; }
float GetFar() const { return m_frustum.farD; } float GetFar() const { return m_frustum.farD; }
void SetBoardLookAtPos( const SFVEC3F &aBoardPos ) void SetBoardLookAtPos( const SFVEC3F& aBoardPos )
{ {
if( m_board_lookat_pos_init != aBoardPos ) if( m_board_lookat_pos_init != aBoardPos )
{ {
@ -121,27 +120,27 @@ public:
} }
} }
virtual void SetLookAtPos( const SFVEC3F &aLookAtPos ) = 0; virtual void SetLookAtPos( const SFVEC3F& aLookAtPos ) = 0;
void SetLookAtPos_T1( const SFVEC3F &aLookAtPos ) void SetLookAtPos_T1( const SFVEC3F& aLookAtPos )
{ {
m_lookat_pos_t1 = aLookAtPos; m_lookat_pos_t1 = aLookAtPos;
} }
const SFVEC3F &GetLookAtPos_T1() const { return m_lookat_pos_t1; } const SFVEC3F& GetLookAtPos_T1() const { return m_lookat_pos_t1; }
const SFVEC3F &GetCameraPos() const { return m_camera_pos; } const SFVEC3F& GetCameraPos() const { return m_camera_pos; }
/** /**
* Calculate a new mouse drag position * Calculate a new mouse drag position
*/ */
virtual void Drag( const wxPoint &aNewMousePosition ) = 0; virtual void Drag( const wxPoint& aNewMousePosition ) = 0;
virtual void Pan( const wxPoint &aNewMousePosition ) = 0; virtual void Pan( const wxPoint& aNewMousePosition ) = 0;
virtual void Pan( const SFVEC3F &aDeltaOffsetInc ) = 0; virtual void Pan( const SFVEC3F& aDeltaOffsetInc ) = 0;
virtual void Pan_T1( const SFVEC3F &aDeltaOffsetInc ) = 0; virtual void Pan_T1( const SFVEC3F& aDeltaOffsetInc ) = 0;
/** /**
* Reset the camera to initial state * Reset the camera to initial state
@ -155,7 +154,7 @@ public:
/** /**
* Update the current mouse position without make any new calculations on camera. * Update the current mouse position without make any new calculations on camera.
*/ */
void SetCurMousePosition( const wxPoint &aPosition ); void SetCurMousePosition( const wxPoint& aPosition );
void ToggleProjection(); void ToggleProjection();
PROJECTION_TYPE GetProjection() { return m_projectionType; } PROJECTION_TYPE GetProjection() { return m_projectionType; }
@ -165,7 +164,7 @@ public:
* *
* @return true if the windows size changed since last time. * @return true if the windows size changed since last time.
*/ */
bool SetCurWindowSize( const wxSize &aSize ); bool SetCurWindowSize( const wxSize& aSize );
void ZoomReset(); void ZoomReset();
@ -217,7 +216,7 @@ public:
* @param aOutOrigin out origin position of the ray. * @param aOutOrigin out origin position of the ray.
* @param aOutDirection out direction * @param aOutDirection out direction
*/ */
void MakeRay( const SFVEC2I &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection ) const; void MakeRay( const SFVEC2I& aWindowPos, SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
/** /**
* Make a ray based on a windows screen position, it will interpolate based on the * Make a ray based on a windows screen position, it will interpolate based on the
@ -227,7 +226,7 @@ public:
* @param aOutOrigin out origin position of the ray. * @param aOutOrigin out origin position of the ray.
* @param aOutDirection out direction. * @param aOutDirection out direction.
*/ */
void MakeRay( const SFVEC2F &aWindowPos, SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection ) const; void MakeRay( const SFVEC2F& aWindowPos, SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
/** /**
* Make a ray based on the latest mouse position. * Make a ray based on the latest mouse position.
@ -235,7 +234,7 @@ public:
* @param aOutOrigin out origin position of the ray. * @param aOutOrigin out origin position of the ray.
* @param aOutDirection out direction. * @param aOutDirection out direction.
*/ */
void MakeRayAtCurrrentMousePosition( SFVEC3F &aOutOrigin, SFVEC3F &aOutDirection ) const; void MakeRayAtCurrrentMousePosition( SFVEC3F& aOutOrigin, SFVEC3F& aOutDirection ) const;
protected: protected:
void rebuildProjection(); void rebuildProjection();
@ -276,7 +275,7 @@ protected:
glm::mat4 m_projectionMatrixInv; glm::mat4 m_projectionMatrixInv;
PROJECTION_TYPE m_projectionType; PROJECTION_TYPE m_projectionType;
FRUSTUM m_frustum; CAMERA_FRUSTUM m_frustum;
SFVEC3F m_right; SFVEC3F m_right;
SFVEC3F m_up; SFVEC3F m_up;
@ -323,10 +322,10 @@ protected:
* Trace mask used to enable or disable the trace output of this class. * Trace mask used to enable or disable the trace output of this class.
* *
* The debug output can be turned on by setting the WXTRACE environment variable to * The debug output can be turned on by setting the WXTRACE environment variable to
* "KI_TRACE_CCAMERA". See the wxWidgets documentation on wxLogTrace for * "KI_TRACE_CAMERA". See the wxWidgets documentation on wxLogTrace for
* more information. * more information.
*/ */
static const wxChar *m_logTrace; static const wxChar* m_logTrace;
}; };
#endif // CCAMERA_H #endif // CAMERA_H

View File

@ -31,7 +31,7 @@
#include "ccolorrgb.h" #include "ccolorrgb.h"
CCOLORRGB::CCOLORRGB( const SFVEC3F &aColor ) COLOR_RGB::COLOR_RGB( const SFVEC3F& aColor )
{ {
r = (unsigned int) glm::clamp( (int) ( aColor.r * 255 ), 0, 255 ); r = (unsigned int) glm::clamp( (int) ( aColor.r * 255 ), 0, 255 );
g = (unsigned int) glm::clamp( (int) ( aColor.g * 255 ), 0, 255 ); g = (unsigned int) glm::clamp( (int) ( aColor.g * 255 ), 0, 255 );
@ -39,32 +39,32 @@ CCOLORRGB::CCOLORRGB( const SFVEC3F &aColor )
} }
CCOLORRGB BlendColor( const CCOLORRGB &aC1, const CCOLORRGB &aC2 ) COLOR_RGB BlendColor( const COLOR_RGB& aC1, const COLOR_RGB& aC2 )
{ {
const unsigned int r = aC1.r + aC2.r; const unsigned int r = aC1.r + aC2.r;
const unsigned int g = aC1.g + aC2.g; const unsigned int g = aC1.g + aC2.g;
const unsigned int b = aC1.b + aC2.b; const unsigned int b = aC1.b + aC2.b;
return CCOLORRGB( ( r >> 1 ), ( g >> 1 ), ( b >> 1 ) ); return COLOR_RGB( ( r >> 1 ), ( g >> 1 ), ( b >> 1 ) );
} }
CCOLORRGB BlendColor( const CCOLORRGB &aC1, const CCOLORRGB &aC2, const CCOLORRGB &aC3 ) COLOR_RGB BlendColor( const COLOR_RGB& aC1, const COLOR_RGB& aC2, const COLOR_RGB& aC3 )
{ {
const unsigned int r = aC1.r + aC2.r + aC3.r; const unsigned int r = aC1.r + aC2.r + aC3.r;
const unsigned int g = aC1.g + aC2.g + aC3.g; const unsigned int g = aC1.g + aC2.g + aC3.g;
const unsigned int b = aC1.b + aC2.b + aC3.b; const unsigned int b = aC1.b + aC2.b + aC3.b;
return CCOLORRGB( ( r / 3 ), ( g / 3 ), ( b / 3 ) ); return COLOR_RGB( ( r / 3 ), ( g / 3 ), ( b / 3 ) );
} }
CCOLORRGB BlendColor( const CCOLORRGB &aC1, const CCOLORRGB &aC2, const CCOLORRGB &aC3, COLOR_RGB BlendColor( const COLOR_RGB& aC1, const COLOR_RGB& aC2, const COLOR_RGB& aC3,
const CCOLORRGB &aC4 ) const COLOR_RGB& aC4 )
{ {
const unsigned int r = aC1.r + aC2.r + aC3.r + aC4.r; const unsigned int r = aC1.r + aC2.r + aC3.r + aC4.r;
const unsigned int g = aC1.g + aC2.g + aC3.g + aC4.g; const unsigned int g = aC1.g + aC2.g + aC3.g + aC4.g;
const unsigned int b = aC1.b + aC2.b + aC3.b + aC4.b; const unsigned int b = aC1.b + aC2.b + aC3.b + aC4.b;
return CCOLORRGB( ( r >> 2 ), ( g >> 2 ), ( b >> 2 ) ); return COLOR_RGB( ( r >> 2 ), ( g >> 2 ), ( b >> 2 ) );
} }

View File

@ -27,12 +27,12 @@
* @brief * @brief
*/ */
#ifndef CCOLORRGB_H #ifndef COLOR_RGB_H
#define CCOLORRGB_H #define COLOR_RGB_H
#include <plugins/3dapi/xv3d_types.h> #include <plugins/3dapi/xv3d_types.h>
union CCOLORRGB union COLOR_RGB
{ {
unsigned char c[3]; unsigned char c[3];
@ -43,9 +43,9 @@ union CCOLORRGB
unsigned char b; unsigned char b;
}; };
CCOLORRGB( const SFVEC3F &aColor ); COLOR_RGB( const SFVEC3F& aColor );
CCOLORRGB() { r = 0; g = 0; b = 0; } COLOR_RGB() { r = 0; g = 0; b = 0; }
CCOLORRGB( unsigned char aR, unsigned char aG, unsigned char aB ) COLOR_RGB( unsigned char aR, unsigned char aG, unsigned char aB )
{ {
r = aR; r = aR;
g = aG; g = aG;
@ -54,9 +54,9 @@ union CCOLORRGB
}; };
CCOLORRGB BlendColor( const CCOLORRGB &aC1, const CCOLORRGB &aC2 ); COLOR_RGB BlendColor( const COLOR_RGB& aC1, const COLOR_RGB& aC2 );
CCOLORRGB BlendColor( const CCOLORRGB &aC1, const CCOLORRGB &aC2, const CCOLORRGB &aC3 ); COLOR_RGB BlendColor( const COLOR_RGB& aC1, const COLOR_RGB& aC2, const COLOR_RGB& aC3 );
CCOLORRGB BlendColor( const CCOLORRGB &aC1, const CCOLORRGB &aC2, const CCOLORRGB &aC3, COLOR_RGB BlendColor( const COLOR_RGB& aC1, const COLOR_RGB& aC2, const COLOR_RGB& aC3,
const CCOLORRGB &aC4 ); const COLOR_RGB& aC4 );
#endif // CCOLORRGB_H #endif // COLOR_RGB_H

View File

@ -42,7 +42,7 @@
#endif #endif
CIMAGE::CIMAGE( unsigned int aXsize, unsigned int aYsize ) IMAGE::IMAGE( unsigned int aXsize, unsigned int aYsize )
{ {
m_wxh = aXsize * aYsize; m_wxh = aXsize * aYsize;
m_pixels = new unsigned char[m_wxh]; m_pixels = new unsigned char[m_wxh];
@ -53,7 +53,7 @@ CIMAGE::CIMAGE( unsigned int aXsize, unsigned int aYsize )
} }
CIMAGE::CIMAGE( const CIMAGE &aSrcImage ) IMAGE::IMAGE( const IMAGE& aSrcImage )
{ {
m_wxh = aSrcImage.GetWidth() * aSrcImage.GetHeight(); m_wxh = aSrcImage.GetWidth() * aSrcImage.GetHeight();
m_pixels = new unsigned char[m_wxh]; m_pixels = new unsigned char[m_wxh];
@ -64,19 +64,19 @@ CIMAGE::CIMAGE( const CIMAGE &aSrcImage )
} }
CIMAGE::~CIMAGE() IMAGE::~IMAGE()
{ {
delete[] m_pixels; delete[] m_pixels;
} }
unsigned char* CIMAGE::GetBuffer() const unsigned char* IMAGE::GetBuffer() const
{ {
return m_pixels; return m_pixels;
} }
bool CIMAGE::wrapCoords( int *aXo, int *aYo ) const bool IMAGE::wrapCoords( int* aXo, int* aYo ) const
{ {
int x = *aXo; int x = *aXo;
int y = *aYo; int y = *aYo;
@ -111,7 +111,7 @@ bool CIMAGE::wrapCoords( int *aXo, int *aYo ) const
} }
void CIMAGE::plot8CircleLines( int aCx, int aCy, int aX, int aY, unsigned char aValue ) void IMAGE::plot8CircleLines( int aCx, int aCy, int aX, int aY, unsigned char aValue )
{ {
Hline( aCx - aX, aCx + aX, aCy + aY, aValue ); Hline( aCx - aX, aCx + aX, aCy + aY, aValue );
Hline( aCx - aX, aCx + aX, aCy - aY, aValue ); Hline( aCx - aX, aCx + aX, aCy - aY, aValue );
@ -120,14 +120,14 @@ void CIMAGE::plot8CircleLines( int aCx, int aCy, int aX, int aY, unsigned char a
} }
void CIMAGE::Setpixel( int aX, int aY, unsigned char aValue ) void IMAGE::Setpixel( int aX, int aY, unsigned char aValue )
{ {
if( wrapCoords( &aX, &aY ) ) if( wrapCoords( &aX, &aY ) )
m_pixels[aX + aY * m_width] = aValue; m_pixels[aX + aY * m_width] = aValue;
} }
unsigned char CIMAGE::Getpixel( int aX, int aY ) const unsigned char IMAGE::Getpixel( int aX, int aY ) const
{ {
if( wrapCoords( &aX, &aY ) ) if( wrapCoords( &aX, &aY ) )
return m_pixels[aX + aY * m_width]; return m_pixels[aX + aY * m_width];
@ -136,7 +136,7 @@ unsigned char CIMAGE::Getpixel( int aX, int aY ) const
} }
void CIMAGE::Hline( int aXStart, int aXEnd, int aY, unsigned char aValue ) void IMAGE::Hline( int aXStart, int aXEnd, int aY, unsigned char aValue )
{ {
if( ( aY < 0 ) || ( aY >= (int) m_height ) || ( ( aXStart < 0 ) && ( aXEnd < 0 ) ) if( ( aY < 0 ) || ( aY >= (int) m_height ) || ( ( aXStart < 0 ) && ( aXEnd < 0 ) )
|| ( ( aXStart >= (int) m_width ) && ( aXEnd >= (int) m_width ) ) ) || ( ( aXStart >= (int) m_width ) && ( aXEnd >= (int) m_width ) ) )
@ -170,7 +170,7 @@ void CIMAGE::Hline( int aXStart, int aXEnd, int aY, unsigned char aValue )
// Based on paper // Based on paper
// http://web.engr.oregonstate.edu/~sllu/bcircle.pdf // http://web.engr.oregonstate.edu/~sllu/bcircle.pdf
void CIMAGE::CircleFilled( int aCx, int aCy, int aRadius, unsigned char aValue ) void IMAGE::CircleFilled( int aCx, int aCy, int aRadius, unsigned char aValue )
{ {
int x = aRadius; int x = aRadius;
int y = 0; int y = 0;
@ -195,25 +195,25 @@ void CIMAGE::CircleFilled( int aCx, int aCy, int aRadius, unsigned char aValue )
} }
void CIMAGE::Invert() void IMAGE::Invert()
{ {
for( unsigned int it = 0; it < m_wxh; it++ ) for( unsigned int it = 0; it < m_wxh; it++ )
m_pixels[it] = 255 - m_pixels[it]; m_pixels[it] = 255 - m_pixels[it];
} }
void CIMAGE::CopyFull( const CIMAGE* aImgA, const CIMAGE* aImgB, IMAGE_OP aOperation ) void IMAGE::CopyFull( const IMAGE* aImgA, const IMAGE* aImgB, IMAGE_OP aOperation )
{ {
int aV, bV; int aV, bV;
if( aOperation == IMAGE_OP::RAW ) if( aOperation == IMAGE_OP::RAW )
{ {
if( aImgA == NULL ) if( aImgA == nullptr )
return; return;
} }
else else
{ {
if( ( aImgA == NULL ) || ( aImgB == NULL ) ) if( ( aImgA == nullptr ) || ( aImgB == nullptr ) )
return; return;
} }
@ -471,7 +471,7 @@ static const S_FILTER FILTERS[] = {
/// do it without use the getpixel function. /// do it without use the getpixel function.
/// Optimization can be done to m_pixels[ix + iy * m_width] /// Optimization can be done to m_pixels[ix + iy * m_width]
/// but keep in mind the parallel process of the algorithm /// but keep in mind the parallel process of the algorithm
void CIMAGE::EfxFilter( CIMAGE* aInImg, IMAGE_FILTER aFilterType ) void IMAGE::EfxFilter( IMAGE* aInImg, IMAGE_FILTER aFilterType )
{ {
S_FILTER filter = FILTERS[static_cast<int>( aFilterType )]; S_FILTER filter = FILTERS[static_cast<int>( aFilterType )];
@ -487,9 +487,7 @@ void CIMAGE::EfxFilter( CIMAGE* aInImg, IMAGE_FILTER aFilterType )
{ {
std::thread t = std::thread( [&]() std::thread t = std::thread( [&]()
{ {
for( size_t iy = nextRow.fetch_add( 1 ); for( size_t iy = nextRow.fetch_add( 1 ); iy < m_height; iy = nextRow.fetch_add( 1 ) )
iy < m_height;
iy = nextRow.fetch_add( 1 ) )
{ {
for( size_t ix = 0; ix < m_width; ix++ ) for( size_t ix = 0; ix < m_width; ix++ )
{ {
@ -500,8 +498,7 @@ void CIMAGE::EfxFilter( CIMAGE* aInImg, IMAGE_FILTER aFilterType )
for( size_t sx = 0; sx < 5; sx++ ) for( size_t sx = 0; sx < 5; sx++ )
{ {
int factor = filter.kernel[sx][sy]; int factor = filter.kernel[sx][sy];
unsigned char pixelv = aInImg->Getpixel( ix + sx - 2, unsigned char pixelv = aInImg->Getpixel( ix + sx - 2, iy + sy - 2 );
iy + sy - 2 );
v += pixelv * factor; v += pixelv * factor;
} }
@ -527,7 +524,7 @@ void CIMAGE::EfxFilter( CIMAGE* aInImg, IMAGE_FILTER aFilterType )
} }
void CIMAGE::SetPixelsFromNormalizedFloat( const float * aNormalizedFloatArray ) void IMAGE::SetPixelsFromNormalizedFloat( const float* aNormalizedFloatArray )
{ {
for( unsigned int i = 0; i < m_wxh; i++ ) for( unsigned int i = 0; i < m_wxh; i++ )
{ {
@ -539,7 +536,7 @@ void CIMAGE::SetPixelsFromNormalizedFloat( const float * aNormalizedFloatArray )
} }
void CIMAGE::SaveAsPNG( const wxString& aFileName ) const void IMAGE::SaveAsPNG( const wxString& aFileName ) const
{ {
DBG_SaveBuffer( aFileName, m_pixels, m_width, m_height ); DBG_SaveBuffer( aFileName, m_pixels, m_width, m_height );
} }

View File

@ -27,8 +27,8 @@
* @brief one 8bit-channel image definition * @brief one 8bit-channel image definition
*/ */
#ifndef CIMAGE_H #ifndef IMAGE_H
#define CIMAGE_H #define IMAGE_H
#include <wx/string.h> #include <wx/string.h>
@ -86,27 +86,27 @@ typedef struct
/** /**
* Manage an 8-bit channel image. * Manage an 8-bit channel image.
*/ */
class CIMAGE class IMAGE
{ {
public: public:
/** /**
* Construct a CIMAGE based on image size. * Construct a IMAGE based on image size.
* *
* @param aXsize x size * @param aXsize x size
* @param aYsize y size * @param aYsize y size
*/ */
CIMAGE( unsigned int aXsize, unsigned int aYsize ); IMAGE( unsigned int aXsize, unsigned int aYsize );
/** /**
* Construct a CIMAGE based from an existing image. * Construct a IMAGE based from an existing image.
* *
* It will make a copy the \a aSrcImage. * It will make a copy the \a aSrcImage.
* *
* @param aSrcImage * @param aSrcImage
*/ */
CIMAGE( const CIMAGE &aSrcImage ); IMAGE( const IMAGE& aSrcImage );
~CIMAGE(); ~IMAGE();
/** /**
* Set a value in a pixel position, position is clamped in accordance with the * Set a value in a pixel position, position is clamped in accordance with the
@ -160,7 +160,7 @@ public:
* @param aImgB an image input. * @param aImgB an image input.
* @param aOperation operation to perform * @param aOperation operation to perform
*/ */
void CopyFull( const CIMAGE* aImgA, const CIMAGE* aImgB, IMAGE_OP aOperation ); void CopyFull( const IMAGE* aImgA, const IMAGE* aImgB, IMAGE_OP aOperation );
/** /**
* Invert the values of this image <- (255 - this) * Invert the values of this image <- (255 - this)
@ -173,7 +173,7 @@ public:
* @param aInImg input image * @param aInImg input image
* @param aFilterType filter type to apply * @param aFilterType filter type to apply
*/ */
void EfxFilter( CIMAGE* aInImg, IMAGE_FILTER aFilterType ); void EfxFilter( IMAGE* aInImg, IMAGE_FILTER aFilterType );
/** /**
* Save image buffer to a PNG file into the working folder. * Save image buffer to a PNG file into the working folder.
@ -211,7 +211,7 @@ private:
* @param aXo Y coordinate to be converted (output). * @param aXo Y coordinate to be converted (output).
* @return bool - true if the coordinates are inside the image, false otherwise. * @return bool - true if the coordinates are inside the image, false otherwise.
*/ */
bool wrapCoords( int *aXo, int *aYo ) const; bool wrapCoords( int* aXo, int* aYo ) const;
void plot8CircleLines( int aCx, int aCy, int aX, int aY, unsigned char aValue ); void plot8CircleLines( int aCx, int aCy, int aX, int aY, unsigned char aValue );
@ -222,4 +222,4 @@ private:
IMAGE_WRAP m_wraping; ///< current wrapping type IMAGE_WRAP m_wraping; ///< current wrapping type
}; };
#endif // CIMAGE_H #endif // IMAGE_H

View File

@ -33,26 +33,27 @@
#include <wx/debug.h> #include <wx/debug.h>
CPOSTSHADER::CPOSTSHADER( const CCAMERA &aCamera ) : m_camera(aCamera) POST_SHADER::POST_SHADER( const CAMERA& aCamera ) :
m_camera( aCamera )
{ {
m_size = SFVEC2UI( 0, 0 ); m_size = SFVEC2UI( 0, 0 );
m_normals = NULL; m_normals = nullptr;
m_color = NULL; m_color = nullptr;
m_depth = NULL; m_depth = nullptr;
m_wc_hitposition = NULL; m_wc_hitposition = nullptr;
m_shadow_att_factor = NULL; m_shadow_att_factor = nullptr;
m_tmin = FLT_MAX; m_tmin = FLT_MAX;
m_tmax = FLT_MIN; m_tmax = FLT_MIN;
} }
CPOSTSHADER::~CPOSTSHADER() POST_SHADER::~POST_SHADER()
{ {
destroy_buffers(); destroy_buffers();
} }
void CPOSTSHADER::UpdateSize( unsigned int xSize, unsigned int ySize ) void POST_SHADER::UpdateSize( unsigned int xSize, unsigned int ySize )
{ {
destroy_buffers(); destroy_buffers();
@ -69,14 +70,14 @@ void CPOSTSHADER::UpdateSize( unsigned int xSize, unsigned int ySize )
} }
void CPOSTSHADER::UpdateSize( const SFVEC2UI &aSize ) void POST_SHADER::UpdateSize( const SFVEC2UI& aSize )
{ {
UpdateSize( aSize.x, aSize.y ); UpdateSize( aSize.x, aSize.y );
} }
void CPOSTSHADER::SetPixelData( unsigned int x, unsigned int y, const SFVEC3F &aNormal, void POST_SHADER::SetPixelData( unsigned int x, unsigned int y, const SFVEC3F& aNormal,
const SFVEC3F &aColor, const SFVEC3F &aHitPosition, const SFVEC3F& aColor, const SFVEC3F& aHitPosition,
float aDepth, float aShadowAttFactor ) float aDepth, float aShadowAttFactor )
{ {
wxASSERT( x < m_size.x ); wxASSERT( x < m_size.x );
@ -103,7 +104,7 @@ void CPOSTSHADER::SetPixelData( unsigned int x, unsigned int y, const SFVEC3F &a
} }
void CPOSTSHADER::destroy_buffers() void POST_SHADER::destroy_buffers()
{ {
delete[] m_normals; delete[] m_normals;
m_normals = nullptr; m_normals = nullptr;
@ -118,55 +119,55 @@ void CPOSTSHADER::destroy_buffers()
} }
const SFVEC3F &CPOSTSHADER::GetNormalAt( const SFVEC2F &aPos ) const const SFVEC3F& POST_SHADER::GetNormalAt( const SFVEC2F& aPos ) const
{ {
return m_normals[GetIndex( aPos )]; return m_normals[GetIndex( aPos )];
} }
const SFVEC3F &CPOSTSHADER::GetColorAt( const SFVEC2F &aPos ) const const SFVEC3F& POST_SHADER::GetColorAt( const SFVEC2F& aPos ) const
{ {
return m_color[GetIndex( aPos )]; return m_color[GetIndex( aPos )];
} }
float CPOSTSHADER::GetDepthAt( const SFVEC2F &aPos ) const float POST_SHADER::GetDepthAt( const SFVEC2F& aPos ) const
{ {
return m_depth[GetIndex( aPos )]; return m_depth[GetIndex( aPos )];
} }
const SFVEC3F &CPOSTSHADER::GetPositionAt( const SFVEC2F &aPos ) const const SFVEC3F& POST_SHADER::GetPositionAt( const SFVEC2F& aPos ) const
{ {
return m_wc_hitposition[GetIndex( aPos )]; return m_wc_hitposition[GetIndex( aPos )];
} }
const SFVEC3F &CPOSTSHADER::GetNormalAt( const SFVEC2I &aPos ) const const SFVEC3F& POST_SHADER::GetNormalAt( const SFVEC2I& aPos ) const
{ {
return m_normals[GetIndex( aPos )]; return m_normals[GetIndex( aPos )];
} }
const SFVEC3F &CPOSTSHADER::GetColorAt( const SFVEC2I &aPos ) const const SFVEC3F& POST_SHADER::GetColorAt( const SFVEC2I& aPos ) const
{ {
return m_color[GetIndex( aPos )]; return m_color[GetIndex( aPos )];
} }
const SFVEC3F &CPOSTSHADER::GetColorAtNotProtected( const SFVEC2I &aPos ) const const SFVEC3F& POST_SHADER::GetColorAtNotProtected( const SFVEC2I& aPos ) const
{ {
return m_color[ aPos.x + m_size.x * aPos.y ]; return m_color[ aPos.x + m_size.x * aPos.y ];
} }
float CPOSTSHADER::GetDepthAt( const SFVEC2I &aPos ) const float POST_SHADER::GetDepthAt( const SFVEC2I& aPos ) const
{ {
return m_depth[GetIndex( aPos )]; return m_depth[GetIndex( aPos )];
} }
float CPOSTSHADER::GetDepthNormalizedAt( const SFVEC2I &aPos ) const float POST_SHADER::GetDepthNormalizedAt( const SFVEC2I& aPos ) const
{ {
const float depth = m_depth[GetIndex( aPos )]; const float depth = m_depth[GetIndex( aPos )];
@ -177,19 +178,19 @@ float CPOSTSHADER::GetDepthNormalizedAt( const SFVEC2I &aPos ) const
} }
const SFVEC3F &CPOSTSHADER::GetPositionAt( const SFVEC2I &aPos ) const const SFVEC3F& POST_SHADER::GetPositionAt( const SFVEC2I& aPos ) const
{ {
return m_wc_hitposition[GetIndex( aPos )]; return m_wc_hitposition[GetIndex( aPos )];
} }
const float &CPOSTSHADER::GetShadowFactorAt( const SFVEC2I &aPos ) const const float& POST_SHADER::GetShadowFactorAt( const SFVEC2I& aPos ) const
{ {
return m_shadow_att_factor[GetIndex( aPos )]; return m_shadow_att_factor[GetIndex( aPos )];
} }
void CPOSTSHADER::DebugBuffersOutputAsImages() const void POST_SHADER::DebugBuffersOutputAsImages() const
{ {
DBG_SaveBuffer( "m_shadow_att_factor", m_shadow_att_factor, m_size.x, m_size.y ); DBG_SaveBuffer( "m_shadow_att_factor", m_shadow_att_factor, m_size.x, m_size.y );
DBG_SaveBuffer( "m_color", m_color, m_size.x, m_size.y ); DBG_SaveBuffer( "m_color", m_color, m_size.x, m_size.y );

View File

@ -27,18 +27,18 @@
* @brief a base class to create post shaders * @brief a base class to create post shaders
*/ */
#ifndef CPOSTSHADER_H #ifndef POST_SHADER_H
#define CPOSTSHADER_H #define POST_SHADER_H
#include "ccamera.h" #include "ccamera.h"
class CPOSTSHADER class POST_SHADER
{ {
public: public:
explicit CPOSTSHADER( const CCAMERA &aCamera ); explicit POST_SHADER( const CAMERA& aCamera );
virtual ~CPOSTSHADER(); virtual ~POST_SHADER();
virtual SFVEC3F Shade( const SFVEC2I &aShaderPos ) const = 0; virtual SFVEC3F Shade( const SFVEC2I& aShaderPos ) const = 0;
/** /**
* Apply the final color process using a previous stage color. * Apply the final color process using a previous stage color.
@ -46,20 +46,20 @@ public:
* @param aShadeColor The result of the shader. * @param aShadeColor The result of the shader.
* @return the result of the shade process * @return the result of the shade process
*/ */
virtual SFVEC3F ApplyShadeColor( const SFVEC2I &aShaderPos, const SFVEC3F &aInputColor, virtual SFVEC3F ApplyShadeColor( const SFVEC2I& aShaderPos, const SFVEC3F& aInputColor,
const SFVEC3F &aShadeColor ) const = 0; const SFVEC3F& aShadeColor ) const = 0;
void UpdateSize( const SFVEC2UI &aSize ); void UpdateSize( const SFVEC2UI& aSize );
void UpdateSize( unsigned int xSize, unsigned int ySize ); void UpdateSize( unsigned int xSize, unsigned int ySize );
void InitFrame() { m_tmin = FLT_MAX; m_tmax = 0.0f; } void InitFrame() { m_tmin = FLT_MAX; m_tmax = 0.0f; }
void SetPixelData( unsigned int x, unsigned int y, const SFVEC3F &aNormal, void SetPixelData( unsigned int x, unsigned int y, const SFVEC3F& aNormal,
const SFVEC3F &aColor, const SFVEC3F &aHitPosition, const SFVEC3F& aColor, const SFVEC3F& aHitPosition,
float aDepth, float aShadowAttFactor ); float aDepth, float aShadowAttFactor );
const SFVEC3F &GetColorAtNotProtected( const SFVEC2I &aPos ) const; const SFVEC3F& GetColorAtNotProtected( const SFVEC2I& aPos ) const;
void DebugBuffersOutputAsImages() const; void DebugBuffersOutputAsImages() const;
@ -87,35 +87,35 @@ public:
} }
protected: protected:
const SFVEC3F &GetNormalAt( const SFVEC2F &aPos ) const; const SFVEC3F& GetNormalAt( const SFVEC2F& aPos ) const;
const SFVEC3F &GetColorAt( const SFVEC2F &aPos ) const; const SFVEC3F& GetColorAt( const SFVEC2F& aPos ) const;
const SFVEC3F &GetPositionAt( const SFVEC2F &aPos ) const; const SFVEC3F& GetPositionAt( const SFVEC2F& aPos ) const;
float GetDepthAt( const SFVEC2F &aPos ) const; float GetDepthAt( const SFVEC2F& aPos ) const;
const SFVEC3F &GetNormalAt( const SFVEC2I &aPos ) const; const SFVEC3F& GetNormalAt( const SFVEC2I& aPos ) const;
const SFVEC3F &GetColorAt( const SFVEC2I &aPos ) const; const SFVEC3F& GetColorAt( const SFVEC2I& aPos ) const;
const SFVEC3F &GetPositionAt( const SFVEC2I &aPos ) const; const SFVEC3F& GetPositionAt( const SFVEC2I& aPos ) const;
const float &GetShadowFactorAt( const SFVEC2I &aPos ) const; const float& GetShadowFactorAt( const SFVEC2I& aPos ) const;
float GetDepthAt( const SFVEC2I &aPos ) const; float GetDepthAt( const SFVEC2I& aPos ) const;
float GetDepthNormalizedAt( const SFVEC2I &aPos ) const; float GetDepthNormalizedAt( const SFVEC2I& aPos ) const;
float GetMaxDepth() const { return m_tmax; } float GetMaxDepth() const { return m_tmax; }
private: private:
void destroy_buffers(); void destroy_buffers();
protected: protected:
const CCAMERA &m_camera; const CAMERA& m_camera;
SFVEC2UI m_size; SFVEC2UI m_size;
SFVEC3F *m_normals; SFVEC3F* m_normals;
SFVEC3F *m_color; SFVEC3F* m_color;
SFVEC3F *m_wc_hitposition; SFVEC3F* m_wc_hitposition;
float *m_depth; float* m_depth;
float *m_shadow_att_factor; float* m_shadow_att_factor;
float m_tmin; float m_tmin;
float m_tmax; float m_tmax;
}; };
#endif // CPOSTSHADER_H #endif // POST_SHADER_H

View File

@ -31,8 +31,8 @@
#include "../3d_fastmath.h" #include "../3d_fastmath.h"
CPOSTSHADER_SSAO::CPOSTSHADER_SSAO( const CCAMERA &aCamera ) : POST_SHADER_SSAO::POST_SHADER_SSAO( const CAMERA& aCamera ) :
CPOSTSHADER( aCamera ), POST_SHADER( aCamera ),
m_shadedBuffer( nullptr ), m_shadedBuffer( nullptr ),
m_isUsingShadows( false ) m_isUsingShadows( false )
{ {
@ -44,8 +44,8 @@ CPOSTSHADER_SSAO::CPOSTSHADER_SSAO( const CCAMERA &aCamera ) :
//http://www.gamedev.net/topic/556187-the-best-ssao-ive-seen/ //http://www.gamedev.net/topic/556187-the-best-ssao-ive-seen/
//http://www.gamedev.net/topic/556187-the-best-ssao-ive-seen/?view=findpost&p=4632208 //http://www.gamedev.net/topic/556187-the-best-ssao-ive-seen/?view=findpost&p=4632208
float CPOSTSHADER_SSAO::aoFF( const SFVEC2I &aShaderPos, const SFVEC3F &ddiff, float POST_SHADER_SSAO::aoFF( const SFVEC2I& aShaderPos, const SFVEC3F& ddiff,
const SFVEC3F &cnorm, const float aShadowAtSamplePos, const SFVEC3F& cnorm, const float aShadowAtSamplePos,
const float aShadowAtCenterPos, int c1, int c2 ) const const float aShadowAtCenterPos, int c1, int c2 ) const
{ {
const float shadowGain = 0.60f; const float shadowGain = 0.60f;
@ -110,8 +110,8 @@ float CPOSTSHADER_SSAO::aoFF( const SFVEC2I &aShaderPos, const SFVEC3F &ddiff,
} }
float CPOSTSHADER_SSAO::giFF( const SFVEC2I &aShaderPos, const SFVEC3F &ddiff, float POST_SHADER_SSAO::giFF( const SFVEC2I& aShaderPos, const SFVEC3F& ddiff,
const SFVEC3F &cnorm, const float aShadow, int c1, int c2 ) const const SFVEC3F& cnorm, const float aShadow, int c1, int c2 ) const
{ {
if( ( ddiff.x > FLT_EPSILON ) || ( ddiff.y > FLT_EPSILON ) || ( ddiff.z > FLT_EPSILON ) ) if( ( ddiff.x > FLT_EPSILON ) || ( ddiff.y > FLT_EPSILON ) || ( ddiff.z > FLT_EPSILON ) )
{ {
@ -130,7 +130,7 @@ float CPOSTSHADER_SSAO::giFF( const SFVEC2I &aShaderPos, const SFVEC3F &ddiff,
} }
SFVEC3F CPOSTSHADER_SSAO::Shade( const SFVEC2I &aShaderPos ) const SFVEC3F POST_SHADER_SSAO::Shade( const SFVEC2I& aShaderPos ) const
{ {
float cdepth = GetDepthAt( aShaderPos ); float cdepth = GetDepthAt( aShaderPos );
@ -146,7 +146,7 @@ SFVEC3F CPOSTSHADER_SSAO::Shade( const SFVEC2I &aShaderPos ) const
// initialize variables: // initialize variables:
float ao = 0.0f; float ao = 0.0f;
SFVEC3F gi = SFVEC3F(0.0f); SFVEC3F gi = SFVEC3F( 0.0f );
#define ROUNDS 3 #define ROUNDS 3
for( unsigned int i = 0; i < ROUNDS; ++i ) for( unsigned int i = 0; i < ROUNDS; ++i )
@ -227,8 +227,8 @@ SFVEC3F CPOSTSHADER_SSAO::Shade( const SFVEC2I &aShaderPos ) const
} }
SFVEC3F CPOSTSHADER_SSAO::ApplyShadeColor( const SFVEC2I &aShaderPos, const SFVEC3F &aInputColor, SFVEC3F POST_SHADER_SSAO::ApplyShadeColor( const SFVEC2I& aShaderPos, const SFVEC3F& aInputColor,
const SFVEC3F &aShadeColor ) const const SFVEC3F& aShadeColor ) const
{ {
SFVEC3F outColor; SFVEC3F outColor;
@ -244,7 +244,7 @@ SFVEC3F CPOSTSHADER_SSAO::ApplyShadeColor( const SFVEC2I &aShaderPos, const SFVE
} }
SFVEC3F CPOSTSHADER_SSAO::giColorCurve( const SFVEC3F &aColor ) const SFVEC3F POST_SHADER_SSAO::giColorCurve( const SFVEC3F& aColor ) const
{ {
const SFVEC3F vec1 = SFVEC3F( 1.0f ); const SFVEC3F vec1 = SFVEC3F( 1.0f );
@ -256,7 +256,7 @@ SFVEC3F CPOSTSHADER_SSAO::giColorCurve( const SFVEC3F &aColor ) const
} }
SFVEC3F CPOSTSHADER_SSAO::Blur( const SFVEC2I& aShaderPos ) const SFVEC3F POST_SHADER_SSAO::Blur( const SFVEC2I& aShaderPos ) const
{ {
const float dCenter = GetDepthAt( aShaderPos ); const float dCenter = GetDepthAt( aShaderPos );

View File

@ -27,21 +27,21 @@
* @brief Implements a post shader screen space ambient occlusion on software * @brief Implements a post shader screen space ambient occlusion on software
*/ */
#ifndef CPOSTSHADER_SSAO_H #ifndef POST_SHADER_SSAO_H
#define CPOSTSHADER_SSAO_H #define POST_SHADER_SSAO_H
#include "cpostshader.h" #include "cpostshader.h"
class CPOSTSHADER_SSAO : public CPOSTSHADER class POST_SHADER_SSAO : public POST_SHADER
{ {
public: public:
explicit CPOSTSHADER_SSAO( const CCAMERA &aCamera ); explicit POST_SHADER_SSAO( const CAMERA& aCamera );
SFVEC3F Shade(const SFVEC2I &aShaderPos ) const override; SFVEC3F Shade(const SFVEC2I& aShaderPos ) const override;
SFVEC3F ApplyShadeColor( const SFVEC2I &aShaderPos, const SFVEC3F &aInputColor, SFVEC3F ApplyShadeColor( const SFVEC2I& aShaderPos, const SFVEC3F& aInputColor,
const SFVEC3F &aShadeColor ) const override; const SFVEC3F& aShadeColor ) const override;
SFVEC3F Blur( const SFVEC2I& aShaderPos ) const; SFVEC3F Blur( const SFVEC2I& aShaderPos ) const;
@ -76,7 +76,7 @@ private:
* @param aColor input color. * @param aColor input color.
* @return transformed color. * @return transformed color.
*/ */
SFVEC3F giColorCurve( const SFVEC3F &aColor ) const; SFVEC3F giColorCurve( const SFVEC3F& aColor ) const;
SFVEC3F* m_shadedBuffer; SFVEC3F* m_shadedBuffer;
@ -84,4 +84,4 @@ private:
}; };
#endif // CPOSTSHADER_SSAO_H #endif // POST_SHADER_SSAO_H

View File

@ -34,9 +34,9 @@
#include <wx/log.h> #include <wx/log.h>
CTRACK_BALL::CTRACK_BALL( float aRangeScale ) : CCAMERA( aRangeScale ) TRACK_BALL::TRACK_BALL( float aRangeScale ) : CAMERA( aRangeScale )
{ {
wxLogTrace( m_logTrace, wxT( "CTRACK_BALL::CTRACK_BALL" ) ); wxLogTrace( m_logTrace, wxT( "TRACK_BALL::TRACK_BALL" ) );
memset( m_quat, 0, sizeof( m_quat ) ); memset( m_quat, 0, sizeof( m_quat ) );
memset( m_quat_t0, 0, sizeof( m_quat_t0 ) ); memset( m_quat_t0, 0, sizeof( m_quat_t0 ) );
@ -48,7 +48,7 @@ CTRACK_BALL::CTRACK_BALL( float aRangeScale ) : CCAMERA( aRangeScale )
} }
void CTRACK_BALL::Drag( const wxPoint& aNewMousePosition ) void TRACK_BALL::Drag( const wxPoint& aNewMousePosition )
{ {
m_parametersChanged = true; m_parametersChanged = true;
@ -77,7 +77,7 @@ void CTRACK_BALL::Drag( const wxPoint& aNewMousePosition )
} }
void CTRACK_BALL::SetLookAtPos( const SFVEC3F& aLookAtPos ) void TRACK_BALL::SetLookAtPos( const SFVEC3F& aLookAtPos )
{ {
if( m_lookat_pos != aLookAtPos ) if( m_lookat_pos != aLookAtPos )
{ {
@ -91,14 +91,14 @@ void CTRACK_BALL::SetLookAtPos( const SFVEC3F& aLookAtPos )
} }
void CTRACK_BALL::Pan( const wxPoint& aNewMousePosition ) void TRACK_BALL::Pan( const wxPoint& aNewMousePosition )
{ {
m_parametersChanged = true; m_parametersChanged = true;
if( m_projectionType == PROJECTION_TYPE::ORTHO ) if( m_projectionType == PROJECTION_TYPE::ORTHO )
{ {
// With the orthographic projection, there is just a zoom factor // With the orthographic projection, there is just a zoom factor
const float panFactor = m_zoom / 37.5f; // Magic number from CCAMERA::rebuildProjection const float panFactor = m_zoom / 37.5f; // Magic number from CAMERA::rebuildProjection
m_camera_pos.x -= panFactor * ( m_lastPosition.x - aNewMousePosition.x ); m_camera_pos.x -= panFactor * ( m_lastPosition.x - aNewMousePosition.x );
m_camera_pos.y -= panFactor * ( aNewMousePosition.y - m_lastPosition.y ); m_camera_pos.y -= panFactor * ( aNewMousePosition.y - m_lastPosition.y );
} }
@ -116,7 +116,7 @@ void CTRACK_BALL::Pan( const wxPoint& aNewMousePosition )
} }
void CTRACK_BALL::Pan( const SFVEC3F& aDeltaOffsetInc ) void TRACK_BALL::Pan( const SFVEC3F& aDeltaOffsetInc )
{ {
m_parametersChanged = true; m_parametersChanged = true;
@ -127,40 +127,40 @@ void CTRACK_BALL::Pan( const SFVEC3F& aDeltaOffsetInc )
} }
void CTRACK_BALL::Pan_T1( const SFVEC3F& aDeltaOffsetInc ) void TRACK_BALL::Pan_T1( const SFVEC3F& aDeltaOffsetInc )
{ {
m_camera_pos_t1 = m_camera_pos + aDeltaOffsetInc; m_camera_pos_t1 = m_camera_pos + aDeltaOffsetInc;
} }
void CTRACK_BALL::Reset() void TRACK_BALL::Reset()
{ {
CCAMERA::Reset(); CAMERA::Reset();
memset( m_quat, 0, sizeof( m_quat ) ); memset( m_quat, 0, sizeof( m_quat ) );
trackball( m_quat, 0.0, 0.0, 0.0, 0.0 ); trackball( m_quat, 0.0, 0.0, 0.0, 0.0 );
} }
void CTRACK_BALL::Reset_T1() void TRACK_BALL::Reset_T1()
{ {
CCAMERA::Reset_T1(); CAMERA::Reset_T1();
memset( m_quat_t1, 0, sizeof( m_quat_t1 ) ); memset( m_quat_t1, 0, sizeof( m_quat_t1 ) );
trackball( m_quat_t1, 0.0, 0.0, 0.0, 0.0 ); trackball( m_quat_t1, 0.0, 0.0, 0.0, 0.0 );
} }
void CTRACK_BALL::SetT0_and_T1_current_T() void TRACK_BALL::SetT0_and_T1_current_T()
{ {
CCAMERA::SetT0_and_T1_current_T(); CAMERA::SetT0_and_T1_current_T();
memcpy( m_quat_t0, m_quat, sizeof( m_quat ) ); memcpy( m_quat_t0, m_quat, sizeof( m_quat ) );
memcpy( m_quat_t1, m_quat, sizeof( m_quat ) ); memcpy( m_quat_t1, m_quat, sizeof( m_quat ) );
} }
void CTRACK_BALL::Interpolate( float t ) void TRACK_BALL::Interpolate( float t )
{ {
wxASSERT( t >= 0.0f ); wxASSERT( t >= 0.0f );
@ -195,5 +195,5 @@ void CTRACK_BALL::Interpolate( float t )
m_rotationMatrix = glm::make_mat4( &rotationMatrix[0][0] ); m_rotationMatrix = glm::make_mat4( &rotationMatrix[0][0] );
CCAMERA::Interpolate( t ); CAMERA::Interpolate( t );
} }

View File

@ -27,18 +27,18 @@
* @brief Declaration for a track ball camera * @brief Declaration for a track ball camera
*/ */
#ifndef CTRACK_BALL_H #ifndef TRACK_BALL_H
#define CTRACK_BALL_H #define TRACK_BALL_H
#include "ccamera.h" #include "ccamera.h"
class CTRACK_BALL : public CCAMERA class TRACK_BALL : public CAMERA
{ {
public: public:
explicit CTRACK_BALL( float aRangeScale ); explicit TRACK_BALL( float aRangeScale );
virtual ~CTRACK_BALL() virtual ~TRACK_BALL()
{ {
} }
@ -69,4 +69,4 @@ private:
double m_quat_t1[4]; double m_quat_t1[4];
}; };
#endif // CTRACK_BALL_H #endif // TRACK_BALL_H

View File

@ -47,24 +47,11 @@ void Run_3d_viewer_test_cases()
s_Run_Test_Cases = true; s_Run_Test_Cases = true;
// Test CBBOX2D // Test BBOX_2D
CBBOX2D bbox2d_A; BBOX_2D bbox2d_A;
CBBOX2D bbox2d_B; BBOX_2D bbox2d_B;
// Test a not initialized box conditions // Test a not initialized box conditions
/*
wxASSERT( bbox2d_A.IsInitialized() == false );
wxASSERT( bbox2d_A.Area() == 0.0f );
wxASSERT( bbox2d_A.GetCenter() == SFVEC2F( 0.0f, 0.0f ) );
wxASSERT( bbox2d_A.GetExtent() == SFVEC2F( 0.0f, 0.0f ) );
wxASSERT( bbox2d_A.Inside( SFVEC2F( 0.0f, 0.0f ) ) == false );
wxASSERT( bbox2d_A.Max() == SFVEC2F( 0.0f, 0.0f ) );
wxASSERT( bbox2d_A.Min() == SFVEC2F( 0.0f, 0.0f ) );
wxASSERT( bbox2d_A.Intersects( bbox2d_B ) == false );
wxASSERT( bbox2d_A.Intersects( bbox2d_A ) == false );
wxASSERT( bbox2d_A.MaxDimension() == 0 );
wxASSERT( bbox2d_A.Perimeter() == 0.0f );
*/
bbox2d_A.Set( SFVEC2F( 1.0f, -1.0f ), SFVEC2F( -1.0f, 1.0f ) ); bbox2d_A.Set( SFVEC2F( 1.0f, -1.0f ), SFVEC2F( -1.0f, 1.0f ) );
wxASSERT( bbox2d_A.IsInitialized() == true ); wxASSERT( bbox2d_A.IsInitialized() == true );
@ -74,7 +61,6 @@ void Run_3d_viewer_test_cases()
wxASSERT( bbox2d_A.Inside( SFVEC2F( 0.0f, 0.0f ) ) == true ); wxASSERT( bbox2d_A.Inside( SFVEC2F( 0.0f, 0.0f ) ) == true );
wxASSERT( bbox2d_A.Max() == SFVEC2F( 1.0f, 1.0f ) ); wxASSERT( bbox2d_A.Max() == SFVEC2F( 1.0f, 1.0f ) );
wxASSERT( bbox2d_A.Min() == SFVEC2F(-1.0f,-1.0f ) ); wxASSERT( bbox2d_A.Min() == SFVEC2F(-1.0f,-1.0f ) );
//wxASSERT( bbox2d_A.Intersects( bbox2d_B ) == false );
wxASSERT( bbox2d_A.Intersects( bbox2d_A ) == true ); wxASSERT( bbox2d_A.Intersects( bbox2d_A ) == true );
wxASSERT( bbox2d_A.MaxDimension() == 0 ); wxASSERT( bbox2d_A.MaxDimension() == 0 );
wxASSERT( bbox2d_A.Perimeter() == 8.0f ); wxASSERT( bbox2d_A.Perimeter() == 8.0f );
@ -88,7 +74,6 @@ void Run_3d_viewer_test_cases()
wxASSERT( bbox2d_A.Inside( SFVEC2F( 0.0f, 0.0f ) ) == true ); wxASSERT( bbox2d_A.Inside( SFVEC2F( 0.0f, 0.0f ) ) == true );
wxASSERT( bbox2d_A.Max() == SFVEC2F( 2.0f, 2.0f ) ); wxASSERT( bbox2d_A.Max() == SFVEC2F( 2.0f, 2.0f ) );
wxASSERT( bbox2d_A.Min() == SFVEC2F(-2.0f,-2.0f ) ); wxASSERT( bbox2d_A.Min() == SFVEC2F(-2.0f,-2.0f ) );
//wxASSERT( bbox2d_A.Intersects( bbox2d_B ) == false );
wxASSERT( bbox2d_A.Intersects( bbox2d_A ) == true ); wxASSERT( bbox2d_A.Intersects( bbox2d_A ) == true );
wxASSERT( bbox2d_A.MaxDimension() == 0 ); wxASSERT( bbox2d_A.MaxDimension() == 0 );
wxASSERT( bbox2d_A.Perimeter() == 16.0f ); wxASSERT( bbox2d_A.Perimeter() == 16.0f );
@ -133,8 +118,8 @@ void Run_3d_viewer_test_cases()
bbox2d_B.Set( SFVEC2F(-0.5f, -0.5f ), SFVEC2F( 0.5f, 0.5f ) ); bbox2d_B.Set( SFVEC2F(-0.5f, -0.5f ), SFVEC2F( 0.5f, 0.5f ) );
wxASSERT( bbox2d_A.Intersects( bbox2d_B ) == true ); wxASSERT( bbox2d_A.Intersects( bbox2d_B ) == true );
// Test CFILLEDCIRCLE2D // Test FILLED_CIRCLE_2D
CFILLEDCIRCLE2D filledCircle2d( SFVEC2F( 2.0f, 2.0f ), 1.0f ); FILLED_CIRCLE_2D filledCircle2d( SFVEC2F( 2.0f, 2.0f ), 1.0f );
wxASSERT( filledCircle2d.IsPointInside( SFVEC2F( 2.0f, 2.0f ) ) == true ); wxASSERT( filledCircle2d.IsPointInside( SFVEC2F( 2.0f, 2.0f ) ) == true );
@ -176,8 +161,8 @@ void Run_3d_viewer_test_cases()
wxASSERT( filledCircle2d.Intersects( bbox2d_B ) == true ); wxASSERT( filledCircle2d.Intersects( bbox2d_B ) == true );
// Test CROUNDSEGMENT2D // Test ROUND_SEGMENT_2D
CROUNDSEGMENT2D roundSegment2d( SFVEC2F( -1.0f, 0.0f ), SFVEC2F( 1.0f, 0.0f ), 2.0f ); ROUND_SEGMENT_2D roundSegment2d( SFVEC2F( -1.0f, 0.0f ), SFVEC2F( 1.0f, 0.0f ), 2.0f );
wxASSERT( roundSegment2d.IsPointInside( SFVEC2F( 0.0f, 0.0f ) ) == true ); wxASSERT( roundSegment2d.IsPointInside( SFVEC2F( 0.0f, 0.0f ) ) == true );
wxASSERT( roundSegment2d.IsPointInside( SFVEC2F( 1.0f, 0.0f ) ) == true ); wxASSERT( roundSegment2d.IsPointInside( SFVEC2F( 1.0f, 0.0f ) ) == true );
@ -235,53 +220,11 @@ void Run_3d_viewer_test_cases()
#if 0 #if 0
// Test Frustum // Test Frustum
{ {
CFRUSTUM frustum; FRUSTUM frustum;
SFVEC3F ori = SFVEC3F( 0.0, 0.0, 0.0 ); SFVEC3F ori = SFVEC3F( 0.0, 0.0, 0.0 );
float z = 10.0; float z = 10.0;
/*
const RAY topLeft( ori, glm::normalize( SFVEC3F(+1.0,-1.0, z) - ori ) );
const RAY topRight( ori, glm::normalize( SFVEC3F(-1.0,-1.0, z) - ori ) );
const RAY bottomLeft( ori, glm::normalize( SFVEC3F(+1.0,+1.0, z) - ori ) );
const RAY bottomRight( ori, glm::normalize( SFVEC3F(-1.0,+1.0, z) - ori ) );
*/
/*
const RAY topLeft( ori, glm::normalize( SFVEC3F(+1.0,+1.0, z) - ori ) );
const RAY topRight( ori, glm::normalize( SFVEC3F(-1.0,+1.0, z) - ori ) );
const RAY bottomLeft( ori, glm::normalize( SFVEC3F(+1.0,-1.0, z) - ori ) );
const RAY bottomRight( ori, glm::normalize( SFVEC3F(-1.0,-1.0, z) - ori ) );
*/
/*
const RAY topLeft( ori, glm::normalize( SFVEC3F(-1.0,-1.0, z) - ori ) );
const RAY topRight( ori, glm::normalize( SFVEC3F(+1.0,-1.0, z) - ori ) );
const RAY bottomLeft( ori, glm::normalize( SFVEC3F(-1.0,+1.0, z) - ori ) );
const RAY bottomRight( ori, glm::normalize( SFVEC3F(+1.0,+1.0, z) - ori ) );
*/
/*
const RAY topLeft( ori, glm::normalize( SFVEC3F(-1.0,+1.0, z) - ori ) );
const RAY topRight( ori, glm::normalize( SFVEC3F(+1.0,+1.0, z) - ori ) );
const RAY bottomLeft( ori, glm::normalize( SFVEC3F(-1.0,-1.0, z) - ori ) );
const RAY bottomRight( ori, glm::normalize( SFVEC3F(+1.0,-1.0, z) - ori ) );
*/
/*
const RAY topLeft( ori, glm::normalize( ori - SFVEC3F(+1.0,-1.0, z) ) );
const RAY topRight( ori, glm::normalize( ori - SFVEC3F(-1.0,-1.0, z) ) );
const RAY bottomLeft( ori, glm::normalize( ori - SFVEC3F(+1.0,+1.0, z) ) );
const RAY bottomRight( ori, glm::normalize( ori - SFVEC3F(-1.0,+1.0, z) ) );
*/
/*
const RAY topLeft( ori, glm::normalize( ori - SFVEC3F(-1.0,-1.0, z) ) );
const RAY topRight( ori, glm::normalize( ori - SFVEC3F(+1.0,-1.0, z) ) );
const RAY bottomLeft( ori, glm::normalize( ori - SFVEC3F(-1.0,+1.0, z) ) );
const RAY bottomRight( ori, glm::normalize( ori - SFVEC3F(+1.0,+1.0, z) ) );
*/
/*
const RAY topLeft( ori, glm::normalize( ori - SFVEC3F(-1.0,+1.0, z) ) );
const RAY topRight( ori, glm::normalize( ori - SFVEC3F(+1.0,+1.0, z) ) );
const RAY bottomLeft( ori, glm::normalize( ori - SFVEC3F(-1.0,-1.0, z) ) );
const RAY bottomRight( ori, glm::normalize( ori - SFVEC3F(+1.0,-1.0, z) ) );
*/
const RAY topLeft( ori, glm::normalize( ori - SFVEC3F(+1.0,+1.0, z) ) ); const RAY topLeft( ori, glm::normalize( ori - SFVEC3F(+1.0,+1.0, z) ) );
const RAY topRight( ori, glm::normalize( ori - SFVEC3F(-1.0,+1.0, z) ) ); const RAY topRight( ori, glm::normalize( ori - SFVEC3F(-1.0,+1.0, z) ) );
@ -290,7 +233,7 @@ void Run_3d_viewer_test_cases()
frustum.GenerateFrustum( topLeft, topRight, bottomLeft, bottomRight ); frustum.GenerateFrustum( topLeft, topRight, bottomLeft, bottomRight );
CBBOX bbox3d; BBOX_3D bbox3d;
bbox3d.Set( SFVEC3F( -1.0f, -1.0f, z ), SFVEC3F( +1.0f, +1.0f, z + 1.0f ) ); bbox3d.Set( SFVEC3F( -1.0f, -1.0f, z ), SFVEC3F( +1.0f, +1.0f, z + 1.0f ) );
wxASSERT( frustum.Intersect( bbox3d ) == true ); wxASSERT( frustum.Intersect( bbox3d ) == true );
@ -323,7 +266,7 @@ void Run_3d_viewer_test_cases()
wxASSERT( frustum.Intersect( bbox3d ) == false ); wxASSERT( frustum.Intersect( bbox3d ) == false );
} }
{ {
CFRUSTUM frustum; FRUSTUM frustum;
float z = 10.0; float z = 10.0;
@ -336,7 +279,7 @@ void Run_3d_viewer_test_cases()
frustum.GenerateFrustum( topLeft, topRight, bottomLeft, bottomRight ); frustum.GenerateFrustum( topLeft, topRight, bottomLeft, bottomRight );
CBBOX bbox3d; BBOX_3D bbox3d;
bbox3d.Set( SFVEC3F( -1.0f, -1.0f, -z), SFVEC3F( +1.0f, +1.0f, -z + 1.0f ) ); bbox3d.Set( SFVEC3F( -1.0f, -1.0f, -z), SFVEC3F( +1.0f, +1.0f, -z + 1.0f ) );
wxASSERT( frustum.Intersect( bbox3d ) == true ); wxASSERT( frustum.Intersect( bbox3d ) == true );

View File

@ -107,7 +107,7 @@ EDA_3D_VIEWER::EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent, const wxSt
SetStatusWidths( arrayDim( status_dims ), status_dims ); SetStatusWidths( arrayDim( status_dims ), status_dims );
m_canvas = new EDA_3D_CANVAS( this, m_canvas = new EDA_3D_CANVAS( this,
COGL_ATT_LIST::GetAttributesList( m_boardAdapter.AntiAliasingGet() ), OGL_ATT_LIST::GetAttributesList( m_boardAdapter.AntiAliasingGet() ),
aParent->GetBoard(), m_boardAdapter, m_currentCamera, aParent->GetBoard(), m_boardAdapter, m_currentCamera,
Prj().Get3DCacheManager() ); Prj().Get3DCacheManager() );
@ -314,7 +314,7 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event )
wxLogTrace( m_logTrace, "EDA_3D_VIEWER::Process_Special_Functions id %d isChecked %d", wxLogTrace( m_logTrace, "EDA_3D_VIEWER::Process_Special_Functions id %d isChecked %d",
id, isChecked ); id, isChecked );
if( m_canvas == NULL ) if( m_canvas == nullptr )
return; return;
switch( id ) switch( id )

View File

@ -103,7 +103,7 @@ public:
void Redraw(); void Redraw();
BOARD_ADAPTER& GetAdapter() override { return m_boardAdapter; } BOARD_ADAPTER& GetAdapter() override { return m_boardAdapter; }
CCAMERA& GetCurrentCamera() override { return m_currentCamera; } CAMERA& GetCurrentCamera() override { return m_currentCamera; }
EDA_3D_CANVAS* GetCanvas() { return m_canvas; } EDA_3D_CANVAS* GetCanvas() { return m_canvas; }
@ -218,8 +218,8 @@ private:
ACTION_TOOLBAR* m_mainToolBar; ACTION_TOOLBAR* m_mainToolBar;
EDA_3D_CANVAS* m_canvas; EDA_3D_CANVAS* m_canvas;
BOARD_ADAPTER m_boardAdapter; BOARD_ADAPTER m_boardAdapter;
CCAMERA& m_currentCamera; CAMERA& m_currentCamera;
CTRACK_BALL m_trackBallCamera; TRACK_BALL m_trackBallCamera;
bool m_disable_ray_tracing; bool m_disable_ray_tracing;

View File

@ -105,7 +105,7 @@ private:
private: private:
EDA_3D_CANVAS* m_canvas; EDA_3D_CANVAS* m_canvas;
BOARD_ADAPTER* m_boardAdapter; BOARD_ADAPTER* m_boardAdapter;
CCAMERA* m_camera; CAMERA* m_camera;
double m_rotationIncrement; ///< Rotation increment for the rotate actions (degrees) double m_rotationIncrement; ///< Rotation increment for the rotate actions (degrees)
}; };

View File

@ -32,18 +32,8 @@
#include <wx/debug.h> #include <wx/debug.h>
#include <core/arraydim.h> #include <core/arraydim.h>
/**
* Attributes list to be passed to a wxGLCanvas creation. const int OGL_ATT_LIST::m_openGL_attributes_list[] = {
*
* This array should be 2*n+1
* Sadly wxwidgets / glx < 13 allowed
* a thing named "boolean attributes" that don't take a value.
* (See src/unix/glx11.cpp -> wxGLCanvasX11::ConvertWXAttrsToGL() ).
* To avoid problems due to this, just specify those attributes twice.
* Only WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_STEREO are such boolean
* attributes.
*/
const int COGL_ATT_LIST::m_openGL_attributes_list[] = {
// Boolean attributes (using itself at padding): // Boolean attributes (using itself at padding):
@ -76,16 +66,15 @@ const int COGL_ATT_LIST::m_openGL_attributes_list[] = {
#define ATT_WX_GL_SAMPLE_BUFFERS_OFFSET 10 #define ATT_WX_GL_SAMPLE_BUFFERS_OFFSET 10
#define ATT_WX_GL_SAMPLE_BUFFERS_DATA 11 #define ATT_WX_GL_SAMPLE_BUFFERS_DATA 11
int COGL_ATT_LIST::m_openGL_attributes_list_to_use[ int OGL_ATT_LIST::m_openGL_attributes_list_to_use[
arrayDim( COGL_ATT_LIST::m_openGL_attributes_list ) ] = { 0 }; arrayDim( OGL_ATT_LIST::m_openGL_attributes_list ) ] = { 0 };
const int *COGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE aAntiAliasingMode ) const int* OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE aAntiAliasingMode )
{ {
wxASSERT( aAntiAliasingMode <= ANTIALIASING_MODE::AA_8X ); wxASSERT( aAntiAliasingMode <= ANTIALIASING_MODE::AA_8X );
memcpy( m_openGL_attributes_list_to_use, memcpy( m_openGL_attributes_list_to_use, m_openGL_attributes_list,
m_openGL_attributes_list,
sizeof( m_openGL_attributes_list_to_use ) ); sizeof( m_openGL_attributes_list_to_use ) );
if( aAntiAliasingMode > ANTIALIASING_MODE::AA_NONE ) if( aAntiAliasingMode > ANTIALIASING_MODE::AA_NONE )

View File

@ -27,8 +27,8 @@
* @brief Declaration of the cogl_att_list class * @brief Declaration of the cogl_att_list class
*/ */
#ifndef _COGL_ATT_LIST_H #ifndef _OGL_ATT_LIST_H
#define _COGL_ATT_LIST_H #define _OGL_ATT_LIST_H
/// Anti-aliasing options /// Anti-aliasing options
enum class ANTIALIASING_MODE enum class ANTIALIASING_MODE
@ -40,20 +40,20 @@ enum class ANTIALIASING_MODE
}; };
/** /**
* Class COGL_ATT_LIST * Helper class to create an attribute list.
* Helper class to create an attribute list
*/ */
class COGL_ATT_LIST class OGL_ATT_LIST
{ {
public: public:
/** /**
* Get a list of attributes to pass to wxGLCanvas * Get a list of attributes to pass to wxGLCanvas.
*
* @param aAntiAliasingMode = 0 - disabled; try to initialize (if is supported) the * @param aAntiAliasingMode = 0 - disabled; try to initialize (if is supported) the
* list with anti aliasing capabilities * list with anti aliasing capabilities
* @return a list of options to be passed in the creation of a EDA_3D_CANVAS class * @return a list of options to be passed in the creation of a EDA_3D_CANVAS class
*/ */
static const int *GetAttributesList( ANTIALIASING_MODE aAntiAliasingMode ); static const int* GetAttributesList( ANTIALIASING_MODE aAntiAliasingMode );
private: private:
/** /**
@ -70,9 +70,9 @@ private:
static const int m_openGL_attributes_list[]; static const int m_openGL_attributes_list[];
/** /**
* Attributes list that was (eventualy) changed and are passed to creation * Attributes list that was (eventually) changed and are passed to creation.
*/ */
static int m_openGL_attributes_list_to_use[]; static int m_openGL_attributes_list_to_use[];
}; };
#endif // _COGL_ATT_LIST_H #endif // _OGL_ATT_LIST_H

View File

@ -76,7 +76,7 @@ void OGL_GetScreenshot( wxImage& aDstImage )
} }
GLuint OGL_LoadTexture( const CIMAGE& aImage ) GLuint OGL_LoadTexture( const IMAGE& aImage )
{ {
unsigned char* rgbaBuffer = (unsigned char*) malloc( aImage.GetWidth() * unsigned char* rgbaBuffer = (unsigned char*) malloc( aImage.GetWidth() *
aImage.GetHeight() * 4 ); aImage.GetHeight() * 4 );

View File

@ -60,7 +60,7 @@ void OGL_SetDiffuseOnlyMaterial( const SFVEC3F& aMaterialDiffuse, float aOpacity
* @param aImage a image to generate the texture from. * @param aImage a image to generate the texture from.
* @return the OpenGL texture index created. * @return the OpenGL texture index created.
*/ */
GLuint OGL_LoadTexture( const CIMAGE& aImage ); GLuint OGL_LoadTexture( const IMAGE& aImage );
/** /**
* Get the pixel data of current OpenGL image. * Get the pixel data of current OpenGL image.