20 #include "renderworld.h"
31 #include <QLinkedList>
32 #include <QMutexLocker>
39 # include <GLUT/glut.h>
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;
457 m_viewerStateRestoredFromFile =
false;
463 setContextMenuPolicy( Qt::CustomContextMenu );
472 void RenderWorld::slotRemoveObject(
WObject* w ) {
477 void RenderWorld::slotAddObject( WObject* w ) {
482 void RenderWorld::onWorldResize() {
485 QMutexLocker locker(&
mutex);
487 if (
world() == NULL) {
503 QMutexLocker locker(&
mutex);
508 QMutexLocker locker(&
mutex);
509 showskygroundbox = b;
513 QMutexLocker locker(&
mutex);
518 QMutexLocker locker(&
mutex);
523 QMutexLocker locker(&
mutex);
528 QMutexLocker locker(&
mutex);
533 QMutexLocker locker(&
mutex);
538 QMutexLocker locker(&
mutex);
543 QMutexLocker locker(&
mutex);
548 QMutexLocker locker(&
mutex);
554 QList<QAction*> acts;
556 if ( showskygroundbox ) {
557 act =
new QAction(
"Hide Sky-Ground",
this );
559 act =
new QAction(
"Show Sky-Ground",
this );
561 act->setCheckable(
true );
562 act->setChecked( showskygroundbox );
563 connect( act, SIGNAL( toggled(
bool) ),
567 act =
new QAction(
"Hide Wireframe",
this );
569 act =
new QAction(
"Show Wireframe",
this );
571 act->setCheckable(
true );
572 act->setChecked( wiref );
573 connect( act, SIGNAL( toggled(
bool) ),
578 act =
new QAction(
"Hide Objects",
this );
580 act =
new QAction(
"Show Objects",
this );
582 act->setCheckable(
true );
583 act->setChecked( showobjs );
584 connect( act, SIGNAL( toggled(
bool) ),
589 act =
new QAction(
"Hide Joints",
this );
591 act =
new QAction(
"Show Joints",
this );
593 act->setCheckable(
true );
594 act->setChecked( showjoints );
595 connect( act, SIGNAL( toggled(
bool) ),
600 act =
new QAction(
"Hide AABBs",
this );
602 act =
new QAction(
"Show AABBs",
this );
604 act->setCheckable(
true );
605 act->setChecked( showaabbs );
606 connect( act, SIGNAL( toggled(
bool) ),
610 if ( showcontacts ) {
611 act =
new QAction(
"Hide Contacts",
this );
613 act =
new QAction(
"Show Contacts",
this );
615 act->setCheckable(
true );
616 act->setChecked( showcontacts );
617 connect( act, SIGNAL( toggled(
bool) ),
622 act =
new QAction(
"Hide Forces",
this );
624 act =
new QAction(
"Show Forces",
this );
626 act->setCheckable(
true );
627 act->setChecked( showforces );
628 connect( act, SIGNAL( toggled(
bool) ),
632 if ( showlocalaxes ) {
633 act =
new QAction(
"Hide Local Axes",
this );
635 act =
new QAction(
"Show Local Axes",
this );
637 act->setCheckable(
true );
638 act->setChecked( showlocalaxes );
639 connect( act, SIGNAL( toggled(
bool) ),
644 act =
new QAction(
"Hide Labels",
this );
646 act =
new QAction(
"Show Labels",
this );
648 act->setCheckable(
true );
649 act->setChecked( showlabels );
650 connect( act, SIGNAL( toggled(
bool) ),
654 QMenu::exec( acts, pos );
660 QMutexLocker locker(&
mutex);
662 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] );
void drawArrow(const wVector &from, const wVector &to, float radius=-1, int nbSubdivisions=12, QColor c=Qt::red)
draw arrow of libQGLViewer has a bug
void usableResources(QStringList resources)
void limits(real &lo, real &hi) const
return the limits
friend friend class ResourcesLocker
World * world()
return the World.
void setSceneBoundingBox(const qglviewer::Vec &min, const qglviewer::Vec &max)
Convenient way to call setSceneCenter() and setSceneRadius() from a (world axis aligned) bounding box...
static void drawCone(const wMatrix &mat, float len, float radius, QColor c=Qt::green)
draw a cone (the main axis is z, mat center is on the base)
WObject * object()
return the WObject that this RenderWObject display on OpenGL
virtual void keyPressEvent(QKeyEvent *e)
Key bindings.
static wMatrix identity()
create an identity matrix
static void drawCylinder(wVector axis, wVector centre, float len, float radius, QColor c=Qt::green)
draw a cylinder with aligned with axis given
void showTimeAndStep(bool b)
show/hide the time and step
void size(wVector &minPoint, wVector &maxPoint)
Get the bounding box of the world.
virtual ~RenderWorld()
Destructor.
void showJoints(bool b)
show/hide visualisation of joints
void showForces(bool b)
show/hide visualisation of forces
wVector centre() const
return the centre of rotation/translation
void removeObject(WObject *)
remove an Object
QMutex mutex
The mutex protecting accesses to members of this class.
static wMatrix grammSchmidt(const wVector &dir)
calculate an orthonormal matrix with the Z vector pointing on the dir direction, and the Y and Z are ...
void declareResource(QString name, T *resource, QString lockBuddy="")
virtual void resourceChanged(QString name, ResourceChangeType changeType)
The function called when a resource you use is changed.
wVector yAxis() const
return the Y axis of local DOF frame
void showSkyGround(bool b)
enable/disable SkyBox
void showLabel(bool show)
Sets whether to show the label or not.
bool labelShown() const
Returns whether the label is shown or not.
void contextMenu(const QPoint &)
show the context menu
QColor color() const
return the color of this object
Quaternion orientation() const
Returns the Camera orientation, defined in the world coordinate system.
virtual void init()
Init the renderWorld.
virtual void drawWithNames()
Tell to OpenGL what is selectable (all WObject)
static real distance(const wVectorT< SharedA > &A, const wVectorT< SharedB > &B)
return the distance from A to B
virtual float zFar() const
Returns the far clipping plane distance used by the Camera projection matrix.
void drawLocalAxes(bool d)
Sets whether the object local frame of reference should be drawn or not.
MyCameraConstraint(qglviewer::Vec min, qglviewer::Vec max)
min and max are the bouding-box on which the camera will be constrained
void setStateFileName(const QString &name)
Defines the stateFileName() used by saveStateToFile() and restoreStateFromFile(). ...
real norm() const
return the norm of this vector
virtual float zNear() const
Returns the near clipping plane distance used by the Camera projection matrix.
FARSA_UTIL_TEMPLATE const T max(const T &t1, const U &t2)
static bool addTextureImage(QString filename, QString texturename)
Add a new texture image associating with it the name specified.
virtual bool restoreStateFromFile()
Restores the QGLViewer state from the stateFileName() file using initFromDOMElement().
void applyTexture(QGLContext *gw, QString texts)
Setup only the Texture.
virtual void objectAlreadyDestroyed()
This function is called before the destruction if the WObject we are supposed to draw has already bee...
const QLinkedList< WObject * > objects()
Return the vector of objects present in this world.
void showContacts(bool b)
show/hide visualisation of contacts
ManipulatedCameraFrame * frame() const
Returns the ManipulatedCameraFrame attached to the Camera.
RenderWObject * operator[](const WObject *)
This operator return the RenderWObject associate with WObject passed.
real position() const
return the actual position of bodies For rotational DOF is the angle of rotation For linear DOF is t...
void getPosition(float &x, float &y, float &z) const
x, y and z are set to the position() of the Frame.
wVector xAxis() const
return the X axis of local DOF frame, this is the zero angle position
void wireframe(bool b)
if true view object in wireframe mode
virtual void renderAABB(RenderWorld *gw)
The function rendering the Axis-Aligned Bounding Box (AABB)
void setOrientation(const Quaternion &q)
Sets the Camera orientation(), defined in the world coordinate system.
void addObject(WObject *)
add an Object
void showAABBs(bool b)
show/hide AABBs
virtual ~RenderWObjectContainer()
Destructor.
The Vec class represents 3D positions and 3D vectors.
const wMatrix & matrix() const
return a reference to the transformation matrix
QString stateFileName() const
Returns the state file name.
RenderWorld(QWidget *parent=NULL, QString wResName="world")
Constructor a visualizator of the World passed.
float aspectRatio() const
Returns the Camera aspect ratio defined by screenWidth() / screenHeight().
bool translate() const
return true if it translate along axis
virtual void getOrthoWidthHeight(GLdouble &halfWidth, GLdouble &halfHeight) const
Returns the halfWidth and halfHeight of the Camera orthographic frustum.
void setAlpha(int alpha)
set the value of alpha channel (the transparency)
int selectedName() const
Returns the name (an integer value) of the entity that was last selected by select().
void sanitifize()
change the matrix in order to get a valid one that represent the same rotation/translation ...
bool useColorTextureOfOwner() const
if true, we will use color and texture of our owner (if we have one)
static RenderWObject * createRenderWObjectFor(const WObject *, RenderWObjectContainer *)
Create a suitable RenderWObject to render the WObject passed.
void drawSkyGroundBox(QGLContext *)
Draw a Sky and a Ground (not static because it uses world dimensions)
virtual PhyObject * parent()
Return the parent object; (NULL means an object attached to static world; see Netwon Documentation) ...
A versatile 3D OpenGL viewer based on QGLWidget.
wVectorT< false > scale(real s) const
return a new wVectorT with element scaled by s
static void drawSphere(wVector pos, real radius)
draw a sphere in position indicate with radius specified
qglviewer::Camera * camera() const
Returns the associated qglviewer::Camera, never NULL.
void showLabels(bool b)
show/hide visualisation of labels for all objects
static void drawArrow(const wVector &direction, const wVector &start, float radius, float tipRadius, float tipLength, QColor c=Qt::green)
draw an arrow
A perspective or orthographic camera.
The Quaternion class represents 3D rotations and orientations.
const QVector< RenderWObject * > graphics()
return all RenderWObject presents
const Frame * referenceFrame() const
Returns the reference Frame, in which coordinates system the Frame is defined.
static void drawTorus(real outRad, real innRad, const wMatrix &mat, real angle=2.0 *PI_GRECO, QColor c=Qt::red)
draw a Torus
QString texture() const
Return the texture name.
void setConstraint(Constraint *const constraint)
Sets the constraint() attached to the Frame.
void setCamera(qglviewer::Camera *const camera)
Associates a new qglviewer::Camera to the viewer.
void drawText(int x, int y, const QString &text, const QFont &fnt=QFont())
Draws text at position x, y (expressed in screen coordinates pixels, origin in the upper left corner ...
virtual void saveStateToFile()
Saves in stateFileName() an XML representation of the QGLViewer state, obtained from domElement()...
void setWorld(World *newworld)
Set the World to render.
static void drawArrow(float length=1.0f, float radius=-1.0f, int nbSubdivisions=12)
Draws a 3D arrow along the positive Z axis.
virtual void draw()
Draw the scene.
FARSA_UTIL_TEMPLATE const T min(const T &t1, const U &t2)
The Frame class represents a coordinate system, defined by a position and an orientation.
wVector axis() const
return the axis of rotation/translation
bool localAxesDrawn() const
Returns true if the local frame of refecence of the object should be drawn.
Ownable * owner() const
Returns the owner of this object.
virtual void keyPressEvent(QKeyEvent *)
Overloading of the QWidget method.
virtual void calculateOBB(wVector &dimension, wVector &minPoint, wVector &maxPoint)
Returns the dimension of the Oriented Bounding Box (OBB) in the object local frame.
virtual void constrainTranslation(qglviewer::Vec &t, qglviewer::Frame *const fr)
Filters the translation applied to the frame.
static void drawWireBox(wVector dims, wMatrix matrix)
draw a wireframe Box
RenderWObjectContainer class.
void showLocalAxes(bool b)
show/hide visualisation of local axes for all objects
Vec position() const
Returns the position of the Frame, defined in the world coordinate system.
virtual PhyObject * child()
Return the child object attached to this joint (see Newton Documentation)
An interface class for Frame constraints.
Vec inverseTransformOf(const Vec &src) const
Returns the world transform of the vector whose coordinates in the Frame coordinate system is src (co...
PhyJoint * joint()
return the PhyJoint
void setupColorTexture(QGLContext *, RenderWObject *obj)
Setup the Color and Texture into the OpenGL Context for RenderWObject passed.
virtual void postSelection(const QPoint &point)
Update the association between OpenGL entity selected to corresponding WObject.
bool isInvisible() const
return if it is invisible
virtual void resourceChanged(QString name, ResourceChangeType changeType)
The function called when a resource you use is changed.
const GLdouble * matrix() const
Returns the Quaternion associated 4x4 OpenGL rotation matrix.
void showObjects(bool b)
show/hide visualisation of objects
bool isLimited() const
return true if rotation/translation are limited
Constraint * constraint() const
Returns the current constraint applied to the Frame.