Equalizer  1.6.1
eqPly/vertexBufferBase.cpp
1 
2 /* Copyright (c) 2008-2009, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * - Neither the name of Eyescale Software GmbH nor the names of its
13  * contributors may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "vertexBufferBase.h"
30 #include "vertexBufferState.h"
31 
32 namespace mesh
33 {
34 void VertexBufferBase::drawBoundingSphere(VertexBufferState& state ) const
35 {
36  GLuint displayList = state.getDisplayList( &_boundingSphere );
37 
38  if( displayList == state.INVALID )
39  {
40  displayList = state.newDisplayList( &_boundingSphere );
41  glNewList( displayList, GL_COMPILE );
42 
43  const float x = _boundingSphere.x();
44  const float y = _boundingSphere.y();
45  const float z = _boundingSphere.z();
46  const float x1 = x - _boundingSphere.w();
47  const float x2 = x + _boundingSphere.w();
48  const float y1 = y - _boundingSphere.w();
49  const float y2 = y + _boundingSphere.w();
50  const float z1 = z - _boundingSphere.w();
51  const float z2 = z + _boundingSphere.w();
52  const float size = _boundingSphere.w();
53 
54 // glDisable( GL_LIGHTING );
55  glBegin( GL_QUADS );
56  glNormal3f( 1.0f, 0.0f, 0.0f );
57  glVertex3f( x1, y - size, z - size );
58  glVertex3f( x1, y + size, z - size );
59  glVertex3f( x1, y + size, z + size );
60  glVertex3f( x1, y - size, z + size );
61  glNormal3f( -1.0f, 0.0f, 0.0f );
62  glVertex3f( x2, y - size, z - size );
63  glVertex3f( x2, y - size, z + size );
64  glVertex3f( x2, y + size, z + size );
65  glVertex3f( x2, y + size, z - size );
66 
67  glNormal3f( 0.0f, -1.0f, 0.0f );
68  glVertex3f( x - size, y2, z - size );
69  glVertex3f( x + size, y2, z - size );
70  glVertex3f( x + size, y2, z + size );
71  glVertex3f( x - size, y2, z + size );
72  glNormal3f( 0.0f, 1.0f, 0.0f );
73  glVertex3f( x - size, y1, z - size );
74  glVertex3f( x - size, y1, z + size );
75  glVertex3f( x + size, y1, z + size );
76  glVertex3f( x + size, y1, z - size );
77 
78  glNormal3f( 0.0f, 0.0f, -1.0f );
79  glVertex3f( x - size, y - size, z2 );
80  glVertex3f( x - size, y + size, z2 );
81  glVertex3f( x + size, y + size, z2 );
82  glVertex3f( x + size, y - size, z2 );
83  glNormal3f( 0.0f, 0.0f, 1.0f );
84  glVertex3f( x - size, y - size, z1 );
85  glVertex3f( x + size, y - size, z1 );
86  glVertex3f( x + size, y + size, z1 );
87  glVertex3f( x - size, y + size, z1 );
88  glEnd();
89 // glEnable( GL_LIGHTING );
90 
91  glEndList();
92  }
93 
94  glCallList( displayList );
95 }
96 }