20 #include "renderworld.h"
31 #include <QLinkedList>
32 #include <QMutexLocker>
39 # include <GLUT/glut.h>
44 using namespace qglviewer;
46 #define GLMultMatrix glMultMatrixf
47 #define GLTranslate glTranslatef
50 #include "qglviewer/camera.h"
51 #include "qglviewer/manipulatedCameraFrame.h"
52 #if QT_VERSION >= 0x040000
53 # include <QWheelEvent>
58 void RenderWObject::drawLabel()
60 if (!obj->labelShown() || (obj->label().isEmpty())) {
65 QGLWidget* qglwidget =
dynamic_cast<QGLWidget*
>(container());
66 if (qglwidget == NULL) {
71 glPushAttrib(GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT);
72 glDisable(GL_LIGHTING);
73 glDisable(GL_DEPTH_TEST);
74 const QColor& lcol = obj->labelColor();
75 glColor4f(lcol.redF(), lcol.greenF(), lcol.blueF(), lcol.alphaF());
78 const wVector lpos = obj->labelPosition();
79 qglwidget->renderText(lpos.x, lpos.y, lpos.z, obj->label());
84 QMap<QString, QImage>* RenderWObjectContainer::textmap = NULL;
85 unsigned int RenderWObjectContainer::textmapRefCounter = 0;
86 QMutex RenderWObjectContainer::textmapMutex(QMutex::Recursive);
88 RenderWObjectContainer::RenderWObjectContainer( QString wResName ) :
89 mutex(QMutex::Recursive),
90 worldResourceName(wResName),
93 QMutexLocker locker(&textmapMutex);
107 QMutexLocker locker(&textmapMutex);
109 if (textmapRefCounter == 0) {
116 QMutexLocker locker(&textmapMutex);
120 return (*textmap)[texturename].load(filename);
129 QMutexLocker locker(&
mutex);
132 for(
int i=0; i<graphs.size(); i++ ) {
133 if ( graphs[i]->
object() == obj ) {
142 const QMetaObject* metaObj = obj->metaObject();
144 QString classname = metaObj->className();
145 if (fac->contains(classname)) {
146 return (*fac)[classname]->create( (
WObject*)obj, container );
148 metaObj = metaObj->superClass();
153 return (*fac)[
"farsa::WObject"]->create( (
WObject*)obj, container );
159 QMutexLocker locker(&
mutex);
167 QMutexLocker locker(&
mutex);
169 for(
int i=0; i<graphs.size(); i++ ) {
170 if ( graphs[i]->
object() == wobj ) {
182 QMutexLocker locker(&
mutex);
185 if (name != worldResourceName) {
197 if (changeType == Deleted) {
200 worldv = getResource<World>();
204 if (worldv != NULL) {
211 void RenderWObjectContainer::initializeTextmap()
213 if ( textmap == NULL ) {
214 textmap =
new QMap<QString, QImage>();
215 (*textmap)[
"tile1"].load(
":/tiles/16tile10.jpg" );
216 (*textmap)[
"tile2"].load(
":/tiles/16tile07.jpg" );
217 (*textmap)[
"white"].load(
":/white.jpg" );
218 (*textmap)[
"tile3"].load(
":/tiles/16tile11.jpg" );
219 (*textmap)[
"tile4"].load(
":/tiles/16tile-B.jpg" );
220 (*textmap)[
"tile5"].load(
":/tiles/16tile12.jpg" );
221 (*textmap)[
"tile6"].load(
":/tiles/16tile04.jpg" );
222 (*textmap)[
"tile7"].load(
":/tiles/tile01.jpg" );
223 (*textmap)[
"tile8"].load(
":/tiles/16tile02.jpg" );
224 (*textmap)[
"tile9"].load(
":/tiles/16tile05.jpg" );
225 (*textmap)[
"tile10"].load(
":/tiles/16tile08.jpg" );
226 (*textmap)[
"icub"].load(
":/tiles/16tile11.jpg" );
227 (*textmap)[
"icubFace"].load(
":/covers/face.jpg" );
228 (*textmap)[
"blueye"].load(
":/covers/eyep2_b.jpg" );
229 (*textmap)[
"metal"].load(
":/metal/iron05.jpg" );
230 (*textmap)[
"marXbot_12leds"].load(
":/covers/marxbot_12leds.jpg" );
244 (*textmap)[
"skyb0"].load(
":/skybox/sb2_top.jpg" );
245 (*textmap)[
"skyb1"].load(
":/skybox/sb2_back.jpg" );
246 (*textmap)[
"skyb2"].load(
":/skybox/sb2_front.jpg" );
247 (*textmap)[
"skyb3"].load(
":/ground/cobbles01.jpg" );
248 (*textmap)[
"skyb4"].load(
":/skybox/sb2_right.jpg" );
249 (*textmap)[
"skyb5"].load(
":/skybox/sb2_left.jpg" );
254 QMutexLocker locker(&
mutex);
255 QMutexLocker textmapLocker(&textmapMutex);
257 if ( textmap->contains( texts ) ) {
258 if ( !textGLId.contains( texts ) ) {
259 textGLId[texts] = gw->bindTexture( (*textmap)[texts], GL_TEXTURE_2D, GL_RGB );
261 glBindTexture( GL_TEXTURE_2D, textGLId[texts] );
262 glEnable( GL_TEXTURE_2D );
271 QMutexLocker locker(&
mutex);
274 glShadeModel( GL_SMOOTH );
275 glEnable( GL_BLEND );
276 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
280 if ( owner != NULL ) {
286 QColor colorv = obj->
color();
287 glColor4f( colorv.redF(), colorv.greenF(), colorv.blueF(), colorv.alphaF() );
294 QMutexLocker locker(&
mutex);
296 if (worldv == NULL) {
300 worldv->
size( min, max );
301 wVector m_size =
wVector( fabs(max[0]-min[0]), fabs(max[1]-min[1]), fabs(max[1]-min[1]) );
305 glDisable( GL_LIGHTING );
306 glShadeModel( GL_FLAT );
307 glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
318 glTexCoord2f(0.0, 1.0); glVertex3f( min.x, max.y, max.z);
319 glTexCoord2f(0.0, 0.0); glVertex3f( max.x, max.y, max.z);
320 glTexCoord2f(1.0, 0.0); glVertex3f( max.x, min.y, max.z);
321 glTexCoord2f(1.0, 1.0); glVertex3f( min.x, min.y, max.z);
326 glTexCoord2f(1.0, 0.0); glVertex3f( min.x, max.y, min.z);
327 glTexCoord2f(1.0, 1.0); glVertex3f( min.x, max.y, max.z);
328 glTexCoord2f(0.0, 1.0); glVertex3f( min.x, min.y, max.z);
329 glTexCoord2f(0.0, 0.0); glVertex3f( min.x, min.y, min.z);
334 glTexCoord2f(0.0, 1.0); glVertex3f(max.x, max.y, max.z);
335 glTexCoord2f(0.0, 0.0); glVertex3f(max.x, max.y, min.z);
336 glTexCoord2f(1.0, 0.0); glVertex3f(max.x, min.y, min.z);
337 glTexCoord2f(1.0, 1.0); glVertex3f(max.x, min.y, max.z);
343 float bfs = m_size[1]/0.4;
344 float bft = m_size[0]/0.4;
346 glTexCoord2f(0.0, bft); glVertex3f( max.x, max.y, min.z);
347 glTexCoord2f(0.0, 0.0); glVertex3f( min.x, max.y, min.z);
348 glTexCoord2f(bfs, 0.0); glVertex3f( min.x, min.y, min.z);
349 glTexCoord2f(bfs, bft); glVertex3f( max.x, min.y, min.z);
354 glTexCoord2f(1.0, 1.0); glVertex3f( min.x, min.y, max.z);
355 glTexCoord2f(0.0, 1.0); glVertex3f( max.x, min.y, max.z);
356 glTexCoord2f(0.0, 0.0); glVertex3f( max.x, min.y, min.z);
357 glTexCoord2f(1.0, 0.0); glVertex3f( min.x, min.y, min.z);
362 glTexCoord2f(0.0, 0.0); glVertex3f( min.x, max.y, min.z);
363 glTexCoord2f(1.0, 0.0); glVertex3f( max.x, max.y, min.z);
364 glTexCoord2f(1.0, 1.0); glVertex3f( max.x, max.y, max.z);
365 glTexCoord2f(0.0, 1.0); glVertex3f( min.x, max.y, max.z);
380 void changeOrthoFrustumSize(
int delta) {
388 halfHeight = orthoSize;
408 qDebug() <<
"Using Reference";
414 if ( (pos.x + tw.x > maxP.x && t.x > 0) || (pos.x + tw.x < minP.x && t.x < 0) ||
415 (pos.y + tw.y > maxP.y && t.y > 0) || (pos.y + tw.y < minP.y && t.y < 0) ||
416 (pos.z + tw.z > maxP.z && t.z > 0) || (pos.z + tw.z < minP.z && t.z < 0) ) {
429 class ForceRenderWorldUpdateEvent :
public QEvent
432 ForceRenderWorldUpdateEvent() :
437 virtual ~ForceRenderWorldUpdateEvent()
447 showskygroundbox =
true;
453 showlocalaxes =
false;
455 showtimeandstep =
true;
456 currentSelected = -1;
462 setContextMenuPolicy( Qt::CustomContextMenu );
471 void RenderWorld::slotRemoveObject(
WObject* w ) {
476 void RenderWorld::slotAddObject( WObject* w ) {
481 void RenderWorld::onWorldResize() {
484 QMutexLocker locker(&
mutex);
486 if (
world() == NULL) {
502 QMutexLocker locker(&
mutex);
507 QMutexLocker locker(&
mutex);
508 showskygroundbox = b;
512 QMutexLocker locker(&
mutex);
517 QMutexLocker locker(&
mutex);
522 QMutexLocker locker(&
mutex);
527 QMutexLocker locker(&
mutex);
532 QMutexLocker locker(&
mutex);
537 QMutexLocker locker(&
mutex);
542 QMutexLocker locker(&
mutex);
547 QMutexLocker locker(&
mutex);
553 QList<QAction*> acts;
555 if ( showskygroundbox ) {
556 act =
new QAction(
"Hide Sky-Ground",
this );
558 act =
new QAction(
"Show Sky-Ground",
this );
560 act->setCheckable(
true );
561 act->setChecked( showskygroundbox );
562 connect( act, SIGNAL( toggled(
bool) ),
566 act =
new QAction(
"Hide Wireframe",
this );
568 act =
new QAction(
"Show Wireframe",
this );
570 act->setCheckable(
true );
571 act->setChecked( wiref );
572 connect( act, SIGNAL( toggled(
bool) ),
577 act =
new QAction(
"Hide Objects",
this );
579 act =
new QAction(
"Show Objects",
this );
581 act->setCheckable(
true );
582 act->setChecked( showobjs );
583 connect( act, SIGNAL( toggled(
bool) ),
588 act =
new QAction(
"Hide Joints",
this );
590 act =
new QAction(
"Show Joints",
this );
592 act->setCheckable(
true );
593 act->setChecked( showjoints );
594 connect( act, SIGNAL( toggled(
bool) ),
599 act =
new QAction(
"Hide AABBs",
this );
601 act =
new QAction(
"Show AABBs",
this );
603 act->setCheckable(
true );
604 act->setChecked( showaabbs );
605 connect( act, SIGNAL( toggled(
bool) ),
609 if ( showcontacts ) {
610 act =
new QAction(
"Hide Contacts",
this );
612 act =
new QAction(
"Show Contacts",
this );
614 act->setCheckable(
true );
615 act->setChecked( showcontacts );
616 connect( act, SIGNAL( toggled(
bool) ),
621 act =
new QAction(
"Hide Forces",
this );
623 act =
new QAction(
"Show Forces",
this );
625 act->setCheckable(
true );
626 act->setChecked( showforces );
627 connect( act, SIGNAL( toggled(
bool) ),
631 if ( showlocalaxes ) {
632 act =
new QAction(
"Hide Local Axes",
this );
634 act =
new QAction(
"Show Local Axes",
this );
636 act->setCheckable(
true );
637 act->setChecked( showlocalaxes );
638 connect( act, SIGNAL( toggled(
bool) ),
643 act =
new QAction(
"Hide Labels",
this );
645 act =
new QAction(
"Show Labels",
this );
647 act->setCheckable(
true );
648 act->setChecked( showlabels );
649 connect( act, SIGNAL( toggled(
bool) ),
653 QMenu::exec( acts, pos );
659 QMutexLocker locker(&
mutex);
661 if (
world() == NULL) {
679 QMutexLocker locker(&
mutex);
681 if (
world() == NULL) {
685 if ( showskygroundbox ) {
686 glPushAttrib( GL_ALL_ATTRIB_BITS );
694 float pos[4] = {1.0, 0.5, 1.0, 0.0};
697 glLightfv( GL_LIGHT0, GL_POSITION, pos );
700 if ( showcontacts ) {
701 glPushAttrib( GL_ALL_ATTRIB_BITS );
703 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
704 glDisable( GL_LIGHTING );
706 contactMapIterator itera(
world()->contacts() );
707 while( itera.hasNext() ) {
709 const contactVec& vec = itera.value();
710 for(
int i=0; i<vec.size(); i++ ) {
719 glPushAttrib( GL_ALL_ATTRIB_BITS );
721 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
722 glDisable( GL_LIGHTING );
729 glPushAttrib( GL_ALL_ATTRIB_BITS );
732 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
734 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
736 glEnable( GL_LIGHTING );
738 for(
int i=0; i<
graphics().size(); i++ ) {
741 if ( showforces && ( pr=dynamic_cast<PhyObject*>(r->
object()) ) ) {
742 glPushAttrib( GL_ALL_ATTRIB_BITS );
743 glColor4f( 1.0, 0.0, 0.0, 1.0 );
745 glColor4f( 0.0, 1.0, 0.0, 1.0 );
751 glPushAttrib( GL_ALL_ATTRIB_BITS );
755 if ( showlocalaxes ) {
761 r->render( (QGLContext*)( QGLContext::currentContext() ) );
765 if ( showaabbs && currentSelected == i ) {
766 glPushAttrib( GL_ALL_ATTRIB_BITS );
769 wVector dims, minPoint, maxPoint;
771 glPushAttrib( GL_ALL_ATTRIB_BITS );
779 if (showtimeandstep) {
780 glPushAttrib( GL_ALL_ATTRIB_BITS );
781 glColor4f( 1.0, 0.0, 0.0, 1.0 );
782 drawText( 80, 15, QString(
"time: %1 step: %2")
783 .arg(
world()->elapsedTime())
784 .arg((
int)(
world()->elapsedTime()/
world()->timeStep()))
791 QMutexLocker locker(&
mutex);
793 for(
int i=0; i<
graphics().size(); i++ ) {
795 graphics()[i]->render( (QGLContext*)( QGLContext::currentContext() ) );
801 QMutexLocker locker(&
mutex);
805 if ( i != -1 && i != currentSelected ) {
806 graphics()[qMax(0,currentSelected)]->object()->setColor( Qt::white );
807 graphics()[i]->object()->setColor( Qt::yellow );
813 QMutexLocker locker(&
mutex);
816 #if QT_VERSION < 0x040000
818 const Qt::ButtonState modifiers = (Qt::ButtonState)(e->state() & Qt::KeyButtonMask);
820 const Qt::KeyboardModifiers modifiers = e->modifiers();
826 bool handled =
false;
827 if ((e->key()==Qt::Key_Left) && (modifiers==Qt::NoButton)) {
834 }
else if ((e->key()==Qt::Key_Right) && (modifiers==Qt::NoButton)) {
842 if ((e->key()==Qt::Key_Up) && (modifiers==Qt::NoButton)) {
849 }
else if ((e->key()==Qt::Key_Down) && (modifiers==Qt::NoButton)) {
858 if ((e->key()==Qt::Key_M) && (modifiers==Qt::NoButton)) {
870 QMutexLocker locker(&
mutex);
875 if (
world() == NULL) {
883 this, SLOT( slotRemoveObject(
WObject* ) ), Qt::DirectConnection );
885 this, SLOT( slotAddObject(
WObject* ) ), Qt::DirectConnection );
886 connect(
world(), SIGNAL( resized() ),
887 this, SLOT( onWorldResize() ), Qt::DirectConnection );
906 QCoreApplication::postEvent(
this,
new ForceRenderWorldUpdateEvent());
909 void RenderWorld::drawDOF(
PhyDOF* dof,
bool drawAxes ) {
912 if ( dof->
joint() == NULL )
return;
918 mat.x_ax = dof->
xAxis();
919 mat.y_ax = dof->
yAxis();
920 mat.z_ax = dof->
axis();
921 mat.w_pos = dof->
centre();
930 rw[ child ]->calculateOBB( dims, minP, maxP );
931 real cube = (dims[0]+dims[1]+dims[2])/3.0;
933 rw[ parent ]->calculateOBB( dims, minP, maxP );
934 real cube2 = (dims[0]+dims[1]+dims[2])/3.0;
935 cube =
min( cube2, cube );
937 real len = cube * 0.70;
938 real rad = len * 0.25;
947 mat.w_pos = wVector(0,0,0);
948 mat = mat * wMatrix( wQuaternion( dof->
axis(), lo ), wVector(0,0,0) );
956 mat.x_ax = dof->
xAxis();
957 mat.y_ax = dof->
yAxis();
958 mat.z_ax = dof->
axis();
959 mat.w_pos = wVector(0,0,0);
961 mat = mat * wMatrix( wQuaternion( dof->
axis(), dof->
position()-0.05 ), wVector(0,0,0) );
963 drawTorus( rad, rad*0.55f, mat, 0.1f, Qt::green );
971 void RenderWorld::drawKineChains() {
974 if (
world() == NULL) {
978 foreach( PhyJoint* jn,
world()->joints()) {
980 float dist1 = 0.0f, dist2 = 0.0f;
981 wVector start = jn->centre();
982 wVector end1 = jn->child()->matrix().w_pos;
983 wVector end2 = start;
985 if ( jn->parent() ) {
986 end2 = jn->parent()->matrix().w_pos;
989 real rad = (dist1 + dist2) * 0.04;
993 QVector<PhyDOF*> ds = jn->dofs();
994 for(
int k=0; k<ds.size(); k++ ) {
995 drawDOF( ds[k],
true );
1000 void RenderWorld::customEvent(QEvent* event)
1002 if (event->type() == QEvent::User) {
1009 GLUquadricObj *pObj;
1012 glShadeModel( GL_SMOOTH );
1013 glColor4f( 0.0f, 1.0f, 0.0f, 1.0f );
1017 mat.x_ax = mat.x_ax.
scale( radius );
1018 mat.y_ax = mat.y_ax.
scale( radius );
1019 mat.z_ax = mat.z_ax.
scale( radius );
1021 GLMultMatrix(&mat[0][0]);
1024 pObj = gluNewQuadric();
1026 gluQuadricTexture(pObj,
true);
1027 gluSphere(pObj, 1.0f, 20, 20);
1029 gluDeleteQuadric(pObj);
1034 GLUquadricObj *pObj;
1039 glShadeModel( GL_SMOOTH );
1040 glColor4f( c.redF(), c.greenF(), c.blueF(), c.alphaF() );
1043 glTranslatef( recentre[0], recentre[1], recentre[2] );
1046 Vec ax( axis[0], axis[1], axis[2] );
1048 glMultMatrixd( quad.
matrix() );
1051 pObj = gluNewQuadric();
1052 gluQuadricTexture(pObj,
true);
1053 gluCylinder(pObj, rad, rad, h, 20, 2);
1056 gluQuadricOrientation(pObj, GLU_INSIDE);
1057 gluDisk(pObj, 0.0f, rad, 20, 1);
1059 glTranslatef (0.0f, 0.0f, h);
1060 gluQuadricOrientation(pObj, GLU_OUTSIDE);
1061 gluDisk(pObj, 0.0f, rad, 20, 1);
1063 gluDeleteQuadric(pObj);
1069 const float h = (end - start).norm();
1070 const wVector axis = (end - start).scale(1.0 / h);
1071 const wVector centre = (start + end).scale(0.5);
1110 GLUquadricObj *pObj;
1115 glShadeModel( GL_SMOOTH );
1116 glColor4f( c.redF(), c.greenF(), c.blueF(), c.alphaF() );
1118 GLMultMatrix(&mat[0][0]);
1121 pObj = gluNewQuadric();
1122 gluQuadricTexture(pObj,
true);
1123 gluCylinder(pObj, rad, rad, h, 20, 2);
1126 gluQuadricOrientation(pObj, GLU_INSIDE);
1127 gluDisk(pObj, 0.0f, rad, 20, 1);
1129 glTranslatef (0.0f, 0.0f, h);
1130 gluQuadricOrientation(pObj, GLU_OUTSIDE);
1131 gluDisk(pObj, 0.0f, rad, 20, 1);
1133 gluDeleteQuadric(pObj);
1138 GLUquadricObj *pObj;
1143 glShadeModel( GL_SMOOTH );
1144 glColor4f( c.redF(), c.greenF(), c.blueF(), c.alphaF() );
1146 GLMultMatrix(&mat[0][0]);
1149 pObj = gluNewQuadric();
1150 gluQuadricTexture(pObj,
true);
1151 gluCylinder(pObj, radius, 0, len, 20, 2);
1154 gluQuadricOrientation(pObj, GLU_INSIDE);
1155 gluDisk(pObj, 0.0f, radius, 20, 1);
1157 gluDeleteQuadric(pObj);
1165 const real length = direction.
norm();
1166 const real tailLength = (tipLength > length) ? -1.0 : (length - tipLength);
1174 if (tailLength > 0.0) {
1178 mtr.w_pos += mtr.z_ax.
scale(tailLength);
1182 drawCone(mtr, tipLength, tipRadius, c);
1186 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1190 glShadeModel( GL_SMOOTH );
1191 glColor4f( 1.0f, 1.0f, 0.0f, 1.0f );
1193 float hdx = (dims[0]/2.0);
1194 float hdy = (dims[1]/2.0);
1195 float hdz = (dims[2]/2.0);
1196 GLMultMatrix(&matrix[0][0]);
1203 glNormal3f(0.0, 0.0, 1.0);
1204 glVertex3f(-hdx, -hdy, hdz);
1205 glVertex3f( hdx, -hdy, hdz);
1206 glVertex3f( hdx, hdy, hdz);
1207 glVertex3f(-hdx, hdy, hdz);
1210 glNormal3f(0.0, 0.0, -1.0);
1211 glVertex3f( hdx, -hdy, -hdz);
1212 glVertex3f(-hdx, -hdy, -hdz);
1213 glVertex3f(-hdx, hdy, -hdz);
1214 glVertex3f( hdx, hdy, -hdz);
1217 glNormal3f(0.0, 1.0, 0.0);
1218 glVertex3f(-hdx, hdy, hdz);
1219 glVertex3f( hdx, hdy, hdz);
1220 glVertex3f( hdx, hdy, -hdz);
1221 glVertex3f(-hdx, hdy, -hdz);
1224 glNormal3f(0.0, -1.0, 0.0);
1225 glVertex3f(-hdx, -hdy, -hdz);
1226 glVertex3f( hdx, -hdy, -hdz);
1227 glVertex3f( hdx, -hdy, hdz);
1228 glVertex3f(-hdx, -hdy, hdz);
1231 glNormal3f(-1.0, 0.0, 0.0);
1232 glVertex3f(-hdx, -hdy, -hdz);
1233 glVertex3f(-hdx, -hdy, hdz);
1234 glVertex3f(-hdx, hdy, hdz);
1235 glVertex3f(-hdx, hdy, -hdz);
1238 glNormal3f(1.0, 0.0, 0.0);
1239 glVertex3f(hdx, -hdy, hdz);
1240 glVertex3f(hdx, -hdy, -hdz);
1241 glVertex3f(hdx, hdy, -hdz);
1242 glVertex3f(hdx, hdy, hdz);
1250 GLMultMatrix(&matrix[0][0]);
1256 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1260 glShadeModel( GL_SMOOTH );
1261 glColor4f( 1.0f, 1.0f, 0.0f, 1.0f );
1263 float dx = fabs( max[0]-min[0] );
1264 float dy = fabs( max[1]-min[1] );
1265 float dz = fabs( max[2]-min[2] );
1266 float hdx = (dx/2.0);
1267 float hdy = (dy/2.0);
1268 float hdz = (dz/2.0);
1269 float minX = qMin(min[0], max[0]);
1270 float minY = qMin(min[1], max[1]);
1271 float minZ = qMin(min[2], max[2]);
1272 glTranslatef( minX+hdx, minY+hdy, minZ+hdz );
1279 glNormal3f(0.0, 0.0, 1.0);
1280 glVertex3f(-hdx, -hdy, hdz);
1281 glVertex3f( hdx, -hdy, hdz);
1282 glVertex3f( hdx, hdy, hdz);
1283 glVertex3f(-hdx, hdy, hdz);
1286 glNormal3f(0.0, 0.0, -1.0);
1287 glVertex3f( hdx, -hdy, -hdz);
1288 glVertex3f(-hdx, -hdy, -hdz);
1289 glVertex3f(-hdx, hdy, -hdz);
1290 glVertex3f( hdx, hdy, -hdz);
1293 glNormal3f(0.0, 1.0, 0.0);
1294 glVertex3f(-hdx, hdy, hdz);
1295 glVertex3f( hdx, hdy, hdz);
1296 glVertex3f( hdx, hdy, -hdz);
1297 glVertex3f(-hdx, hdy, -hdz);
1300 glNormal3f(0.0, -1.0, 0.0);
1301 glVertex3f(-hdx, -hdy, -hdz);
1302 glVertex3f( hdx, -hdy, -hdz);
1303 glVertex3f( hdx, -hdy, hdz);
1304 glVertex3f(-hdx, -hdy, hdz);
1307 glNormal3f(-1.0, 0.0, 0.0);
1308 glVertex3f(-hdx, -hdy, -hdz);
1309 glVertex3f(-hdx, -hdy, hdz);
1310 glVertex3f(-hdx, hdy, hdz);
1311 glVertex3f(-hdx, hdy, -hdz);
1314 glNormal3f(1.0, 0.0, 0.0);
1315 glVertex3f(hdx, -hdy, hdz);
1316 glVertex3f(hdx, -hdy, -hdz);
1317 glVertex3f(hdx, hdy, -hdz);
1318 glVertex3f(hdx, hdy, hdz);
1328 glShadeModel( GL_SMOOTH );
1329 glColor4f( c.redF(), c.greenF(), c.blueF(), c.alphaF() );
1331 GLMultMatrix(&matrix[0][0]);
1336 double s, t, x, y, z, twopi;
1337 real tubeRad = (outRad-innRad)/2.0;
1338 real toruRad = outRad - tubeRad;
1339 twopi = 2 * PI_GRECO;
1340 for (i = 0; i < numc; i++) {
1341 glBegin(GL_QUAD_STRIP);
1342 for (j = 0; j <= numt; j++) {
1343 for (k = 1; k >= 0; k--) {
1344 s = (i + k) % numc + 0.5;
1347 x = (toruRad+tubeRad*cos(s*twopi/numc))*cos(t*(angle)/numt);
1348 y = (toruRad+tubeRad*cos(s*twopi/numc))*sin(t*(angle)/numt);
1349 z = tubeRad * sin(s * twopi / numc);
1350 glVertex3f(x, y, z);
1363 glShadeModel( GL_SMOOTH );
1364 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1368 GLMultMatrix( &tm[0][0] );
1373 double s, t, x, y, z, twopi;
1374 real tubeRad = (outRad-innRad)/2.0;
1375 real toruRad = outRad - tubeRad;
1376 twopi = 2 * PI_GRECO;
1377 for (i = 0; i < numc; i++) {
1378 glBegin(GL_QUAD_STRIP);
1379 for (j = 0; j <= numt; j++) {
1380 for (k = 1; k >= 0; k--) {
1381 s = (i + k) % numc + 0.5;
1384 x = (toruRad+tubeRad*cos(s*twopi/numc))*cos(t*(angle)/numt);
1385 y = (toruRad+tubeRad*cos(s*twopi/numc))*sin(t*(angle)/numt);
1386 z = tubeRad * sin(s * twopi / numc);
1387 glVertex3f(x, y, z);
1398 glColor4f( c.redF(), c.greenF(), c.blueF(), c.alphaF() );
1405 GLMultMatrix( &tm[0][0] );