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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
24
25#ifndef _OBJECT_3D_H_
26#define _OBJECT_3D_H_
27
28#include "bbox_3d.h"
29#include "../material.h"
30
31class BOARD_ITEM;
32class HITINFOR;
33
44
45
47{
48public:
49 explicit OBJECT_3D( OBJECT_3D_TYPE aObjType );
50
51 void SetBoardItem( BOARD_ITEM* aBoardItem ) { m_boardItem = aBoardItem; }
52 BOARD_ITEM* GetBoardItem() const { return m_boardItem; }
53
54 void SetMaterial( const MATERIAL* aMaterial )
55 {
56 m_material = aMaterial;
57 m_modelTransparency = aMaterial->GetTransparency(); // Default transparency is from material
58 }
59
60 const MATERIAL* GetMaterial() const { return m_material; }
61 float GetModelTransparency() const { return m_modelTransparency; }
62 void SetModelTransparency( float aModelTransparency )
63 {
64 m_modelTransparency = aModelTransparency;
65 }
66
67 virtual SFVEC3F GetDiffuseColor( const HITINFO& aHitInfo ) const = 0;
68
69 virtual ~OBJECT_3D() {}
70
74 virtual bool Intersects( const BBOX_3D& aBBox ) const = 0;
75
76
80 virtual bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const = 0;
81
86 virtual bool IntersectP( const RAY& aRay, float aMaxDistance ) const = 0;
87
88 const BBOX_3D& GetBBox() const { return m_bbox; }
89
90 const SFVEC3F& GetCentroid() const { return m_centroid; }
91
92protected:
97
99
100 // m_modelTransparency combines the material and model opacity
101 // 0.0 full opaque, 1.0 full transparent.
103};
104
105
109{
110public:
112 {
113 memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT_3D_TYPE::MAX ) );
114 }
115
116 unsigned int GetCountOf( OBJECT_3D_TYPE aObjType ) const
117 {
118 return m_counter[static_cast<int>( aObjType )];
119 }
120
121 void AddOne( OBJECT_3D_TYPE aObjType )
122 {
123 m_counter[static_cast<int>( aObjType )]++;
124 }
125
126 // void PrintStats();
127
129 {
130 if( !s_instance )
132
133 return *s_instance;
134 }
135
136private:
141
142 unsigned int m_counter[static_cast<int>( OBJECT_3D_TYPE::MAX )];
143
145};
146
147
148#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:81
A vertical cylinder.
Definition cylinder_3d.h:34
Base material class that can be used to derive other material implementations.
Definition material.h:236
float GetTransparency() const
Definition material.h:269
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:128
void ResetStats()
Definition object_3d.h:111
static OBJECT_3D_STATS * s_instance
Definition object_3d.h:144
unsigned int GetCountOf(OBJECT_3D_TYPE aObjType) const
Definition object_3d.h:116
void AddOne(OBJECT_3D_TYPE aObjType)
Definition object_3d.h:121
unsigned int m_counter[static_cast< int >(OBJECT_3D_TYPE::MAX)]
Definition object_3d.h:142
void SetMaterial(const MATERIAL *aMaterial)
Definition object_3d.h:54
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:93
BOARD_ITEM * GetBoardItem() const
Definition object_3d.h:52
BOARD_ITEM * m_boardItem
Definition object_3d.h:98
void SetModelTransparency(float aModelTransparency)
Definition object_3d.h:62
OBJECT_3D_TYPE m_obj_type
Definition object_3d.h:95
const SFVEC3F & GetCentroid() const
Definition object_3d.h:90
virtual bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const =0
virtual ~OBJECT_3D()
Definition object_3d.h:69
const BBOX_3D & GetBBox() const
Definition object_3d.h:88
SFVEC3F m_centroid
Definition object_3d.h:94
void SetBoardItem(BOARD_ITEM *aBoardItem)
Definition object_3d.h:51
float GetModelTransparency() const
Definition object_3d.h:61
OBJECT_3D(OBJECT_3D_TYPE aObjType)
Definition object_3d.cpp:36
virtual bool IntersectP(const RAY &aRay, float aMaxDistance) const =0
float m_modelTransparency
Definition object_3d.h:102
const MATERIAL * GetMaterial() const
Definition object_3d.h:60
const MATERIAL * m_material
Definition object_3d.h:96
A triangle object.
Definition triangle_3d.h:39
@ MAX
OBJECT_3D_TYPE
Definition object_3d.h:35
Manage a bounding box defined by two SFVEC3F min max points.
Definition bbox_3d.h:39
Stores the hit information of a ray with a point on the surface of a object.
Definition hitinfo.h:32
Definition ray.h:59
glm::vec3 SFVEC3F
Definition xv3d_types.h:40