00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "vpcylinder.h"
00023 #ifdef VP_OGL
00024 #include <GL/glu.h>
00025 #endif
00026
00027
00028 #include <iostream>
00029 using namespace std;
00030
00031
00032 VPCylinder::VPCylinder() : VPGraphicObj() {
00033 height = radius = 1.0;
00034 side = top = bottom = true;
00035 }
00036
00037 VPCylinder::VPCylinder( float fHi, float fRad ) : VPGraphicObj() {
00038 height = fHi;
00039 radius = fRad;
00040 }
00041
00042 VPCylinder::VPCylinder( float fHi, float fRad, bool bS, bool bT, bool bB )
00043 : VPGraphicObj() {
00044 height = fHi;
00045 radius = fRad;
00046 side = bS;
00047 top = bT;
00048 bottom = bB;
00049 }
00050
00051 void VPCylinder::ComputeBoundingBox() {
00052 bBox.SetBoundingBox(-radius, -radius, 0, radius, radius, top);
00053 }
00054
00055 void VPCylinder::SetHeight( float h ){
00056 height = h;
00057 }
00058
00059 void VPCylinder::SetRadius( float r ){
00060 radius = r;
00061 }
00062
00063 void VPCylinder::ShowSide( bool yesno ){
00064 side = yesno;
00065 }
00066
00067 void VPCylinder::ShowTop( bool yesno ){
00068 top = yesno;
00069 }
00070
00071 void VPCylinder::ShowBottom( bool yesno ){
00072 bottom = yesno;
00073 }
00074
00075 float VPCylinder::GetHeight( void ){
00076 return height;
00077 }
00078
00079 float VPCylinder::GetRadius( void ){
00080 return radius;
00081 }
00082
00083 bool VPCylinder::ShowSide( void ){
00084 return side;
00085 }
00086
00087 bool VPCylinder::ShowTop( void ){
00088 return top;
00089 }
00090
00091 bool VPCylinder::ShowBottom( void ){
00092 return bottom;
00093 }
00094
00095 bool VPCylinder::DrawInstanceOGL() const {
00096 #ifdef VP_OGL
00097 GLUquadricObj* qObj = gluNewQuadric();
00098
00099 bool result = material.DrawOGL();
00100
00101 if (side) {
00102 gluQuadricDrawStyle(qObj, GLU_FILL);
00103 gluQuadricNormals(qObj, GLU_SMOOTH);
00104 gluCylinder(qObj, radius, radius, height, 15, 1);
00105 }
00106
00107 if (bottom) {
00108 gluQuadricOrientation(qObj,GLU_INSIDE);
00109 gluDisk(qObj, 0.0, radius, 15, 1);
00110 }
00111
00112 if (top) {
00113 glPushMatrix();
00114 gluQuadricOrientation(qObj,GLU_OUTSIDE);
00115 glTranslatef(0.0f, 0.0f, height);
00116 gluDisk(qObj, 0.0, radius, 15, 1);
00117 glPopMatrix();
00118 }
00119 gluDeleteQuadric(qObj);
00120 return result;
00121 #else
00122 return false;
00123 #endif
00124 }