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
87 virtual bool IntersectP( const RAY& aRay, float aMaxDistance ) const = 0;
88
89 const BBOX_3D& GetBBox() const { return m_bbox; }
90
91 const SFVEC3F& GetCentroid() const { return m_centroid; }
92
93protected:
98
100
101 // m_modelTransparency combines the material and model opacity
102 // 0.0 full opaque, 1.0 full transparent.
104};
105
106
110{
111public:
113 {
114 memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT_3D_TYPE::MAX ) );
115 }
116
117 unsigned int GetCountOf( OBJECT_3D_TYPE aObjType ) const
118 {
119 return m_counter[static_cast<int>( aObjType )];
120 }
121
122 void AddOne( OBJECT_3D_TYPE aObjType )
123 {
124 m_counter[static_cast<int>( aObjType )]++;
125 }
126
127 // void PrintStats();
128
130 {
131 if( !s_instance )
133
134 return *s_instance;
135 }
136
137private:
142
143 unsigned int m_counter[static_cast<int>( OBJECT_3D_TYPE::MAX )];
144
146};
147
148
149#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:84
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:129
void ResetStats()
Definition object_3d.h:112
static OBJECT_3D_STATS * s_instance
Definition object_3d.h:145
unsigned int GetCountOf(OBJECT_3D_TYPE aObjType) const
Definition object_3d.h:117
void AddOne(OBJECT_3D_TYPE aObjType)
Definition object_3d.h:122
unsigned int m_counter[static_cast< int >(OBJECT_3D_TYPE::MAX)]
Definition object_3d.h:143
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:94
BOARD_ITEM * GetBoardItem() const
Definition object_3d.h:52
BOARD_ITEM * m_boardItem
Definition object_3d.h:99
void SetModelTransparency(float aModelTransparency)
Definition object_3d.h:62
OBJECT_3D_TYPE m_obj_type
Definition object_3d.h:96
const SFVEC3F & GetCentroid() const
Definition object_3d.h:91
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:89
SFVEC3F m_centroid
Definition object_3d.h:95
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:103
const MATERIAL * GetMaterial() const
Definition object_3d.h:60
const MATERIAL * m_material
Definition object_3d.h:97
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