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