arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

GLItems.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     6-20-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 /// GLItems.cpp
00019 
00020 #include "GLItems.h"
00021 #include <iostream>
00022 #include "../GL/glUtil.h"
00023 #include <mathGutz.h>
00024 
00025 using namespace std;
00026 using namespace gutz;
00027 
00028 ////////////////////////////////////////////////////////////////////////////
00029 /// GLItem :: Draw()
00030 ////////////////////////////////////////////////////////////////////////////
00031 void GLItem::drawGL()
00032 {
00033    if(_compile && _update)
00034    {
00035       if(!glIsList(_listName))
00036          _listName = glGenLists(1);
00037 
00038       glNewList(_listName, GL_COMPILE);
00039       {
00040          drawGLDef();
00041       }
00042       glEndList();
00043       _update = false;
00044    }
00045 
00046    if(_compile)
00047    {
00048       glCallList(_listName);
00049       /// for debugging...
00050       ///drawDef();
00051    }
00052    else
00053    {
00054       drawGLDef();
00055    }
00056 
00057    glErr(cerr, "GLItem::draw()");
00058 }
00059 
00060 void    GLItem::initNames(unsigned int name1, unsigned int name2)
00061 {
00062    pushName(name1);
00063    pushName(name2);
00064 }
00065 
00066 void    GLItem::pushName(unsigned int name)
00067 {
00068    glPushName(name);
00069    ++_numNames;
00070 }
00071 
00072 void    GLItem::popNames()
00073 {
00074    for(int i=0; i<_numNames; ++i)
00075       glPopName();
00076    _numNames = 0;
00077 }
00078 
00079 ////////////////////////////////////////////////////////////////////////////
00080 ////////////////////////////////////////////////////////////////////////////
00081 ////////////////////////////////////////////////////////////////////////////
00082 /// GLUItem
00083 ////////////////////////////////////////////////////////////////////////////
00084 ////////////////////////////////////////////////////////////////////////////
00085 ////////////////////////////////////////////////////////////////////////////
00086 
00087 ////////////////////////////////////////////////////////////////////////////
00088 /// GLUItem :: construct
00089 ////////////////////////////////////////////////////////////////////////////
00090 GLUItem::GLUItem(int slice, int stack)
00091 :_qobj(gluNewQuadric()), _slice(slice), _stack(stack)
00092 {
00093 
00094 }
00095 
00096 GLUItem::GLUItem(const GLUItem &gi)
00097 :_qobj(gluNewQuadric()), _slice(gi._slice), _stack(gi._stack)
00098 {
00099 
00100 }
00101 
00102 ////////////////////////////////////////////////////////////////////////////
00103 /// assign
00104 ////////////////////////////////////////////////////////////////////////////
00105 GLUItem &GLUItem::operator=(const GLUItem &gi)
00106 {
00107    GLItem::operator=(gi);
00108    _slice = gi._slice;
00109    _stack = gi._stack;
00110    setUp();
00111    return *this;
00112 }
00113 
00114 ////////////////////////////////////////////////////////////////////////////
00115 /// GLUItem :: destruct
00116 ////////////////////////////////////////////////////////////////////////////
00117 GLUItem::~GLUItem()
00118 {
00119    if(_qobj) gluDeleteQuadric(_qobj);
00120 }
00121 
00122 ////////////////////////////////////////////////////////////////////////////
00123 /// GLUItem :: draw sphere
00124 ////////////////////////////////////////////////////////////////////////////
00125 void  GLUItem::drawSphere(const gutz::vec3f &pos, float rad)
00126 {
00127    glPushMatrix();
00128    {
00129       glTranslatef(pos.x, pos.y, pos.z);
00130       gluSphere(_qobj, rad, _slice, _stack);
00131    }
00132    glPopMatrix();
00133 }
00134 
00135 ////////////////////////////////////////////////////////////////////////////
00136 /// GLUItem :: draw bar
00137 ////////////////////////////////////////////////////////////////////////////
00138 void  GLUItem::drawBar(const gutz::vec3f &start, const gutz::vec3f &end, float rad)
00139 {
00140    vec3f dir = end - start;
00141    float len = dir.normalize();
00142    mat4f xf(axis2axisPN(dir,vec3f_z),start);
00143 
00144    glPushMatrix();
00145    {
00146       glMultMatrixf(xf.m);
00147       gluCylinder(_qobj,rad,rad,len, _slice, _stack);
00148    }
00149    glPopMatrix();
00150 }
00151 

Send questions, comments, and bug reports to:
jmk