V-ART
cone.cpp
Go to the documentation of this file.
1 
5 #ifdef WIN32
6 #include <windows.h>
7 #endif
8 #ifdef VART_OGL
9 #include <GL/glu.h>
10 #endif
11 #include "vart/cone.h"
12 
13 #include <iostream>
14 using namespace std;
15 
16 
18 {
19 }
20 
21 
23 {
24  this->operator =(cone);
25 }
26 
28 {
29  this->GraphicObj::operator=(cone);
30  height = cone.height;
31  btRadius = cone.btRadius;
32  sidesVisible = cone.sidesVisible;
33  topVisible = cone.topVisible;
34  bottomVisible = cone.bottomVisible;
35  material = cone.material;
36  return *this;
37 }
38 
39 
40 
41 VART::Cone::Cone(float fHi, float fRad) : VART::GraphicObj()
42 {
43  height = fHi;
44  topRadius = 0.0;
45  btRadius = fRad;
46  sidesVisible = topVisible = bottomVisible = true;
47  bBox.SetBoundingBox(-fRad, -fRad, 0, fRad, fRad, fHi);
48  recBBox = bBox;
49 }
50 
51 
53 {
54  return new VART::Cone(*this);
55 }
56 
57 
58 VART::Cone::Cone( float fHi, float fRad, bool bS, bool bB ) : VART::GraphicObj()
59 {
60  height = fHi;
61  topRadius = 0.0;
62  btRadius = fRad;
63  sidesVisible = bS;
64  bottomVisible = bB;
65  bBox.SetBoundingBox(-fRad, -fRad, 0, fRad, fRad, fHi);
66  recBBox = bBox;
67 }
68 
70 {
71  float maxRadius = btRadius;
72  bBox.SetBoundingBox(-maxRadius, -maxRadius, 0, maxRadius, maxRadius, height);
73 }
74 
75 void VART::Cone::SetHeight(float h)
76 {
77  float maxRadius = btRadius;
78  height = h;
79  bBox.SetBoundingBox(-maxRadius, -maxRadius, 0, maxRadius, maxRadius, h);
80  ComputeRecursiveBoundingBox();
81 }
82 
83 void VART::Cone::SetRadius(float r)
84 {
85  btRadius = r;
86  bBox.SetBoundingBox(-r, -r, 0, r, r, height);
87  ComputeRecursiveBoundingBox();
88 }
89 
91 {
92  bottomVisible = static_cast<bool>(parts & BOTTOM);
93  sidesVisible = static_cast<bool>(parts & SIDES);
94 }
95 
97 {
98  if (parts & BOTTOM) bottomVisible = !bottomVisible;
99  if (parts & SIDES) sidesVisible = !sidesVisible;
100 }
101 
103 {
104  PartsID result = NONE;
105  if (bottomVisible) result = result & BOTTOM;
106  if (sidesVisible) result = result & SIDES;
107  return result;
108 }
109 
110 void VART::Cone::ShowSide(bool yesno)
111 {
112  sidesVisible = yesno;
113  cerr << "Warning: VART::Cone::ShowSide is deprecated." << endl;
114 }
115 
116 
117 void VART::Cone::ShowBottom(bool yesno)
118 {
119  bottomVisible = yesno;
120  cerr << "Warning: VART::Cone::ShowBottom is deprecated." << endl;
121 }
122 
124 {
125  return height;
126 }
127 
129 {
130  return btRadius;
131 }
132 
134 {
135  cerr << "Warning: VART::Cone::ShowSide is deprecated." << endl;
136  return sidesVisible;
137 }
138 
140 {
141  cerr << "Warning: VART::Cone::ShowBottom is deprecated." << endl;
142  return bottomVisible;
143 }
144 
145 bool VART::Cone::DrawInstanceOGL() const
146 {
147 #ifdef VART_OGL
148  GLUquadricObj* qObj = gluNewQuadric();
149  bool result = true;
150 
151  if (show)
152  {
153  switch (howToShow)
154  {
155  case LINES:
156  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
157  break;
158  case POINTS:
159  glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
160  break;
161  default:
162  glPolygonMode(GL_FRONT, GL_FILL);
163  break;
164  }
165  if ( material.GetTexture().HasData() ) {
166  gluQuadricTexture(qObj,GL_TRUE);
167  }
168  result = material.DrawOGL();
169  // Render sides
170  if (sidesVisible) {
171  gluQuadricDrawStyle(qObj, GLU_FILL);
172  gluQuadricNormals(qObj, GLU_SMOOTH);
173  gluCylinder(qObj, btRadius, 0.0 , height, 15, 1);
174  }
175  // Render bottom
176  if (bottomVisible) {
177  gluQuadricOrientation(qObj,GLU_INSIDE);
178  gluDisk(qObj, 0.0, btRadius, 15, 1);
179  }
180  gluDeleteQuadric(qObj);
181  }
182  if (bBox.visible) // Is the bounding box visible?
183  bBox.DrawInstanceOGL();
184  if (recBBox.visible)
185  recBBox.DrawInstanceOGL();
186  return result;
187 #else
188  return false;
189 #endif
190 }
191 
192 
A cone.
Definition: cone.h:18
Base class for objects that compose a scene graph.
Definition: scenenode.h:25
PartsID GetPartsVisibility()
Returns internal visibility state as PartsID.
Definition: cone.cpp:102
virtual VART::SceneNode * Copy()
Returns a copy of an cone. Every derived class must reimplements this method, to avoid errors with VA...
Definition: cone.cpp:52
PartsID
Bitmask for cone parts.
Definition: cone.h:24
void SetBoundingBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)
BoundingBox recBBox
Definition: graphicobj.h:85
float GetHeight()
Definition: cone.cpp:123
void SetRadius(float r)
Sets the value of bottom radius.
Definition: cone.cpp:83
void SetHeight(float h)
Definition: cone.cpp:75
An scene node that is associated with a shape.
Definition: graphicobj.h:18
virtual void ComputeBoundingBox()
Computes the bounding box.
Definition: cone.cpp:69
SceneNode & operator=(const SceneNode &node)
Definition: scenenode.cpp:47
bool ShowSide()
Definition: cone.cpp:133
bool ShowBottom()
Definition: cone.cpp:139
float GetRadius()
Returns the bottom radius.
Definition: cone.cpp:128
void SetPartsVisibility(PartsID parts)
Sets which parts are visible.
Definition: cone.cpp:90
BoundingBox bBox
Definition: graphicobj.h:84
Cone()
Creates an uninitialized cone.
Definition: cone.cpp:17
VART::Cone & operator=(const VART::Cone &cone)
Definition: cone.cpp:27
void TogglePartsVisibilty(PartsID parts)
Toogle visibility of marked parts.
Definition: cone.cpp:96
Header file for V-ART class "Cone".