KiCad PCB EDA Suite
Loading...
Searching...
No Matches
object_3d.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015-2020 Mario Luzeiro <[email protected]>
5 * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
29#ifndef _OBJECT_3D_H_
30#define _OBJECT_3D_H_
31
32#include "bbox_3d.h"
33#include "../material.h"
34
35class BOARD_ITEM;
36class HITINFOR;
37
39{
43 XYPLANE,
46 MAX
47};
48
49
51{
52public:
53 explicit OBJECT_3D( OBJECT_3D_TYPE aObjType );
54
55 void SetBoardItem( BOARD_ITEM* aBoardItem ) { m_boardItem = aBoardItem; }
56 BOARD_ITEM* GetBoardItem() const { return m_boardItem; }
57
58 void SetMaterial( const MATERIAL* aMaterial )
59 {
60 m_material = aMaterial;
61 m_modelTransparency = aMaterial->GetTransparency(); // Default transparency is from material
62 }
63
64 const MATERIAL* GetMaterial() const { return m_material; }
65 float GetModelTransparency() const { return m_modelTransparency; }
66 void SetModelTransparency( float aModelTransparency )
67 {
68 m_modelTransparency = aModelTransparency;
69 }
70
71 virtual SFVEC3F GetDiffuseColor( const HITINFO& aHitInfo ) const = 0;
72
73 virtual ~OBJECT_3D() {}
74
78 virtual bool Intersects( const BBOX_3D& aBBox ) const = 0;
79
80
84 virtual bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const = 0;
85
90 virtual bool IntersectP( const RAY& aRay, float aMaxDistance ) const = 0;
91
92 const BBOX_3D& GetBBox() const { return m_bbox; }
93
94 const SFVEC3F& GetCentroid() const { return m_centroid; }
95
96protected:
101
103
104 // m_modelTransparency combines the material and model opacity
105 // 0.0 full opaque, 1.0 full transparent.
107};
108
109
113{
114public:
116 {
117 memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT_3D_TYPE::MAX ) );
118 }
119
120 unsigned int GetCountOf( OBJECT_3D_TYPE aObjType ) const
121 {
122 return m_counter[static_cast<int>( aObjType )];
123 }
124
125 void AddOne( OBJECT_3D_TYPE aObjType )
126 {
127 m_counter[static_cast<int>( aObjType )]++;
128 }
129
130 // void PrintStats();
131
133 {
134 if( !s_instance )
136
137 return *s_instance;
138 }
139
140private:
145
146 unsigned int m_counter[static_cast<int>( OBJECT_3D_TYPE::MAX )];
147
149};
150
151
152#endif // _OBJECT_3D_H_
Bounding Box class definition.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
Base material class that can be used to derive other material implementations.
Definition: material.h:240
float GetTransparency() const
Definition: material.h:273
Implements a class for object statistics using Singleton pattern.
Definition: object_3d.h:113
OBJECT_3D_STATS(const OBJECT_3D_STATS &old)
const OBJECT_3D_STATS & operator=(const OBJECT_3D_STATS &old)
static OBJECT_3D_STATS & Instance()
Definition: object_3d.h:132
void ResetStats()
Definition: object_3d.h:115
static OBJECT_3D_STATS * s_instance
Definition: object_3d.h:148
unsigned int GetCountOf(OBJECT_3D_TYPE aObjType) const
Definition: object_3d.h:120
void AddOne(OBJECT_3D_TYPE aObjType)
Definition: object_3d.h:125
unsigned int m_counter[static_cast< int >(OBJECT_3D_TYPE::MAX)]
Definition: object_3d.h:146
void SetMaterial(const MATERIAL *aMaterial)
Definition: object_3d.h:58
virtual bool Intersects(const BBOX_3D &aBBox) const =0
virtual SFVEC3F GetDiffuseColor(const HITINFO &aHitInfo) const =0
BBOX_3D m_bbox
Definition: object_3d.h:97
BOARD_ITEM * GetBoardItem() const
Definition: object_3d.h:56
BOARD_ITEM * m_boardItem
Definition: object_3d.h:102
void SetModelTransparency(float aModelTransparency)
Definition: object_3d.h:66
OBJECT_3D_TYPE m_obj_type
Definition: object_3d.h:99
const SFVEC3F & GetCentroid() const
Definition: object_3d.h:94
virtual bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const =0
virtual ~OBJECT_3D()
Definition: object_3d.h:73
const BBOX_3D & GetBBox() const
Definition: object_3d.h:92
SFVEC3F m_centroid
Definition: object_3d.h:98
void SetBoardItem(BOARD_ITEM *aBoardItem)
Definition: object_3d.h:55
float GetModelTransparency() const
Definition: object_3d.h:65
virtual bool IntersectP(const RAY &aRay, float aMaxDistance) const =0
float m_modelTransparency
Definition: object_3d.h:106
const MATERIAL * GetMaterial() const
Definition: object_3d.h:64
const MATERIAL * m_material
Definition: object_3d.h:100
OBJECT_3D_TYPE
Definition: object_3d.h:39
Manage a bounding box defined by two SFVEC3F min max points.
Definition: bbox_3d.h:43
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:36
Definition: ray.h:63
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44