-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathOctahedron.h
101 lines (87 loc) · 3.37 KB
/
Octahedron.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/***********************************************************************
Octahedron - Class for aluminum oxide structural units (used to build
heterogeneous silicate crystals).
Copyright (c) 2003-2011 Oliver Kreylos
The Nanotech Construction Kit is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Nanotech Construction Kit is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with the Nanotech Construction Kit; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***********************************************************************/
#ifndef OCTAHEDRON_INCLUDED
#define OCTAHEDRON_INCLUDED
#include "StructuralUnit.h"
namespace NCK {
class OctahedronRenderer:public UnitRenderer
{
/* Methods: */
virtual void initContext(GLContextData& contextData) const;
};
class Octahedron:public StructuralUnit
{
friend class OctahedronRenderer;
/* Elements: */
protected:
static Scalar radius,radius2; // Radius and squared radius of octahedron's circumspheres
static Scalar mass; // Mass of an octahedron
static Vector vertexOffsets[6]; // Octahedron vertices in local coordinates
static Point renderVertices[6]; // Octahedron vertices for rendering
static Vector renderNormals[8]; // Octahedron face normals in local coordinates
static OctahedronRenderer* unitRenderer; // Renderer for octahedron units
/* Protected methods: */
static void calculateShape(void); // Re-calculates octahedron shape after size change
/* Constructors and destructors: */
public:
static void initClass(const Misc::ConfigurationFileSection& configFileSection); // Initializes class settings based on the given configuration file section
Octahedron(const Point& sPosition,const Rotation& sOrientation)
:StructuralUnit(sPosition,sOrientation,6)
{
};
Octahedron(Misc::File& file)
:StructuralUnit(6,file)
{
};
static void deinitClass(void); // Destroys class data
/* Methods: */
static Scalar getClassRadius(void) // Returns radius of all octahedra
{
return radius;
};
static int getClassNumVertices(void) // Returns number of vertices of octahedron class
{
return 6;
};
static Vector getClassVertexOffset(int vertexIndex) // Returns offset from octahedron center to one octahedron vertex
{
return vertexOffsets[vertexIndex];
};
static void setRadius(Scalar newRadius); // Sets octahedrons' radius
static void setMass(Scalar newMass); // Sets octahedrons' mass
virtual Scalar getRadius(void) const
{
return radius;
};
virtual Scalar getMass(void) const
{
return mass;
};
virtual Vector getVertexOffset(int index) const
{
return orientation.transform(vertexOffsets[index]);
};
virtual Point getVertex(int index) const
{
return position+orientation.transform(vertexOffsets[index]);
};
virtual void applyVertexForce(int index,const Vector& force,Scalar timeStep);
virtual void applyCentralForce(const Vector& force,Scalar timeStep);
virtual void glRenderAction(GLContextData& contextData) const;
};
}
#endif