20 #include "renderworld.h"
21 #include "physphere.h"
23 #include "phycylinder.h"
28 #include "phycompoundobject.h"
30 #include "graphicalwobject.h"
31 #include "private/renderwobjecthierarchy.h"
44 # include <GLUT/glut.h>
49 using namespace qglviewer;
51 #define GLMultMatrix glMultMatrixf
66 virtual void render( QGLContext* ) {
70 calculateAABB( minpoint, maxpoint, obj->matrix() );
75 minPoint = tm.w_pos - rds;
76 maxPoint = tm.w_pos + rds;
80 dimension[0] = rad*2.0;
81 dimension[1] = rad*2.0;
82 dimension[2] = rad*2.0;
97 virtual void render( QGLContext* gw ) {
100 if ( wmesh->attachedTo() ) {
101 m = m * wmesh->attachedTo()->matrix();
103 GLMultMatrix(&m[0][0]);
104 int m_numMeshes = wmesh->meshesCount();
112 for (
int i = 0; i < m_numMeshes; i++ ) {
113 int materialIndex = m_pMeshes[i].m_materialIndex;
114 if ( materialIndex >= 0 ) {
115 glMaterialfv( GL_FRONT, GL_AMBIENT, m_pMaterials[materialIndex].m_ambient );
116 glMaterialfv( GL_FRONT, GL_DIFFUSE, m_pMaterials[materialIndex].m_diffuse );
117 glMaterialfv( GL_FRONT, GL_SPECULAR, m_pMaterials[materialIndex].m_specular );
118 glMaterialfv( GL_FRONT, GL_EMISSION, m_pMaterials[materialIndex].m_emissive );
119 glMaterialf( GL_FRONT, GL_SHININESS, m_pMaterials[materialIndex].m_shininess );
123 glBegin( GL_TRIANGLES );
124 for (
int j = 0; j < m_pMeshes[i].m_numTriangles; j++ ) {
125 int triangleIndex = m_pMeshes[i].m_pTriangleIndices[j];
127 for (
int k = 0; k < 3; k++ ) {
128 int index = pTri->m_vertexIndices[k];
129 glNormal3fv( pTri->m_vertexNormals[k] );
130 glTexCoord2f( pTri->m_s[k], pTri->m_t[k] );
131 glVertex3fv( m_pVertices[index].m_location );
157 virtual void render( QGLContext* gw ) {
160 const wMatrix& m = box->matrix();
161 GLMultMatrix(&m[0][0]);
167 float hdx = (dx/2.0);
168 float hdy = (dy/2.0);
169 float hdz = (dz/2.0);
171 glNormal3f(0.0, 0.0, 1.0);
172 glTexCoord2f(0.0, 0.0); glVertex3f(-hdx, -hdy, hdz);
173 glTexCoord2f(1.0, 0.0); glVertex3f( hdx, -hdy, hdz);
174 glTexCoord2f(1.0, 1.0); glVertex3f( hdx, hdy, hdz);
175 glTexCoord2f(0.0, 1.0); glVertex3f(-hdx, hdy, hdz);
178 glNormal3f(0.0, 0.0, -1.0);
179 glTexCoord2f(0.0, 0.0); glVertex3f( hdx, -hdy, -hdz);
180 glTexCoord2f(1.0, 0.0); glVertex3f(-hdx, -hdy, -hdz);
181 glTexCoord2f(1.0, 1.0); glVertex3f(-hdx, hdy, -hdz);
182 glTexCoord2f(0.0, 1.0); glVertex3f( hdx, hdy, -hdz);
185 glNormal3f(0.0, 1.0, 0.0);
186 glTexCoord2f(0.0, 0.0); glVertex3f(-hdx, hdy, hdz);
187 glTexCoord2f(1.0, 0.0); glVertex3f( hdx, hdy, hdz);
188 glTexCoord2f(1.0, 1.0); glVertex3f( hdx, hdy, -hdz);
189 glTexCoord2f(0.0, 1.0); glVertex3f(-hdx, hdy, -hdz);
192 glNormal3f(0.0, -1.0, 0.0);
193 glTexCoord2f(0.0, 0.0); glVertex3f(-hdx, -hdy, -hdz);
194 glTexCoord2f(1.0, 0.0); glVertex3f( hdx, -hdy, -hdz);
195 glTexCoord2f(1.0, 1.0); glVertex3f( hdx, -hdy, hdz);
196 glTexCoord2f(0.0, 1.0); glVertex3f(-hdx, -hdy, hdz);
199 glNormal3f(-1.0, 0.0, 0.0);
200 glTexCoord2f(0.0, 0.0); glVertex3f(-hdx, -hdy, -hdz);
201 glTexCoord2f(1.0, 0.0); glVertex3f(-hdx, -hdy, hdz);
202 glTexCoord2f(1.0, 1.0); glVertex3f(-hdx, hdy, hdz);
203 glTexCoord2f(0.0, 1.0); glVertex3f(-hdx, hdy, -hdz);
206 glNormal3f(1.0, 0.0, 0.0);
207 glTexCoord2f(0.0, 0.0); glVertex3f(hdx, -hdy, hdz);
208 glTexCoord2f(1.0, 0.0); glVertex3f(hdx, -hdy, -hdz);
209 glTexCoord2f(1.0, 1.0); glVertex3f(hdx, hdy, -hdz);
210 glTexCoord2f(0.0, 1.0); glVertex3f(hdx, hdy, hdz);
217 calculateAABB( minpoint, maxpoint, obj->matrix() );
221 real tdx = fabs(tm.x_ax[0]*dx) + fabs(tm.y_ax[0]*dy) + fabs(tm.z_ax[0]*dz);
222 real tdy = fabs(tm.x_ax[1]*dx) + fabs(tm.y_ax[1]*dy) + fabs(tm.z_ax[1]*dz);
223 real tdz = fabs(tm.x_ax[2]*dx) + fabs(tm.y_ax[2]*dy) + fabs(tm.z_ax[2]*dz);
225 wVector hds( tdx/2.0, tdy/2.0, tdz/2.0 );
226 minPoint = tm.w_pos - hds;
227 maxPoint = tm.w_pos + hds;
234 wVector hds( dx/2.0, dy/2.0, dz/2.0 );
251 virtual void render( QGLContext* gw ) {
256 mat.x_ax = mat.x_ax.
scale( rad );
257 mat.y_ax = mat.y_ax.
scale( rad );
258 mat.z_ax = mat.z_ax.
scale( rad );
259 GLMultMatrix(&mat[0][0]);
262 pObj = gluNewQuadric();
264 gluQuadricTexture(pObj,
true);
265 gluSphere(pObj, 1.0f, 20, 20);
266 gluDeleteQuadric(pObj);
271 calculateAABB( minpoint, maxpoint, obj->matrix() );
276 minPoint = tm.w_pos - rds;
277 maxPoint = tm.w_pos + rds;
281 dimension[0] = rad*2.0;
282 dimension[1] = rad*2.0;
283 dimension[2] = rad*2.0;
377 m_height(m_cylinder->height()),
378 m_radius(m_cylinder->radius()),
379 m_cylinderVertexes(),
382 m_cylinderTextureCoords(),
383 m_upperBaseVertexes(),
384 m_upperBaseNormals(),
386 m_upperBaseTextureCoords(),
387 m_upperBaseSegmentsLength(),
388 m_lowerBaseVertexes(),
389 m_lowerBaseNormals(),
391 m_lowerBaseTextureCoords(),
392 m_lowerBaseSegmentsLength()
410 virtual void render(QGLContext* gw)
413 if (m_cylinder->graphicalRepresentationNeedsUpdate()) {
414 updateRepresentation();
418 container()->setupColorTexture(gw,
this);
419 GLMultMatrix(&(m_cylinder->matrix()[0][0]));
423 glEnableClientState(GL_NORMAL_ARRAY);
424 glEnableClientState(GL_COLOR_ARRAY);
425 glEnableClientState(GL_VERTEX_ARRAY);
426 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
428 glNormalPointer(GL_FLOAT, 0, m_cylinderNormals.data());
429 glColorPointer(3, GL_FLOAT, 0, m_cylinderColors.data());
430 glVertexPointer(3, GL_FLOAT, 0, m_cylinderVertexes.data());
431 glTexCoordPointer(2, GL_FLOAT, 0, m_cylinderTextureCoords.data());
433 glDrawArrays(GL_TRIANGLE_STRIP, 0, m_cylinderVertexes.size() / 3);
436 glNormalPointer(GL_FLOAT, 0, m_upperBaseNormals.data());
437 glColorPointer(3, GL_FLOAT, 0, m_upperBaseColors.data());
438 glVertexPointer(3, GL_FLOAT, 0, m_upperBaseVertexes.data());
439 glTexCoordPointer(2, GL_FLOAT, 0, m_upperBaseTextureCoords.data());
441 unsigned int startIndex = 0;
442 foreach (
unsigned int curLength, m_upperBaseSegmentsLength) {
443 glDrawArrays(GL_TRIANGLE_FAN, startIndex, curLength);
444 startIndex += curLength;
448 glNormalPointer(GL_FLOAT, 0, m_lowerBaseNormals.data());
449 glColorPointer(3, GL_FLOAT, 0, m_lowerBaseColors.data());
450 glVertexPointer(3, GL_FLOAT, 0, m_lowerBaseVertexes.data());
451 glTexCoordPointer(2, GL_FLOAT, 0, m_lowerBaseTextureCoords.data());
454 foreach (
unsigned int curLength, m_lowerBaseSegmentsLength) {
455 glDrawArrays(GL_TRIANGLE_FAN, startIndex, curLength);
456 startIndex += curLength;
459 glDisableClientState(GL_VERTEX_ARRAY);
460 glDisableClientState(GL_COLOR_ARRAY);
461 glDisableClientState(GL_NORMAL_ARRAY);
462 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
475 if (m_cylinder->graphicalRepresentationNeedsUpdate()) {
476 updateRepresentation();
480 calculateAABB(minpoint, maxpoint, obj->matrix());
494 if (m_cylinder->graphicalRepresentationNeedsUpdate()) {
495 updateRepresentation();
498 const real h2 = m_height / 2.0;
499 const real tdx = fabs(tm.x_ax[0] * h2) + fabs(tm.y_ax[0] * m_radius) + fabs(tm.z_ax[0] * m_radius);
500 const real tdy = fabs(tm.x_ax[1] * h2) + fabs(tm.y_ax[1] * m_radius) + fabs(tm.z_ax[1] * m_radius);
501 const real tdz = fabs(tm.x_ax[2] * h2) + fabs(tm.y_ax[2] * m_radius) + fabs(tm.z_ax[2] * m_radius);
502 const wVector hds(tdx, tdy, tdz);
503 minPoint = tm.w_pos - hds;
504 maxPoint = tm.w_pos + hds;
517 if (m_cylinder->graphicalRepresentationNeedsUpdate()) {
518 updateRepresentation();
521 dimension[0] = m_height;
522 dimension[1] = m_radius * 2.0;
523 dimension[2] = m_radius * 2.0;
524 const wVector rds(m_height / 2.0, m_radius, m_radius);
535 void updateRepresentation()
538 const int numDivs = 20;
539 const float anglePerDiv = (2 * M_PI) /
float(numDivs);
540 const float lowerBaseX = -m_height / 2.0;
541 const float upperBaseX = +m_height / 2.0;
544 m_cylinderVertexes.clear();
545 m_cylinderNormals.clear();
546 m_cylinderColors.clear();
547 m_cylinderTextureCoords.clear();
548 m_upperBaseVertexes.clear();
549 m_upperBaseNormals.clear();
550 m_upperBaseColors.clear();
551 m_upperBaseTextureCoords.clear();
552 m_upperBaseSegmentsLength.clear();
553 m_lowerBaseVertexes.clear();
554 m_lowerBaseNormals.clear();
555 m_lowerBaseColors.clear();
556 m_lowerBaseTextureCoords.clear();
557 m_lowerBaseSegmentsLength.clear();
561 QList<PhyCylinder::SegmentColor> cylinderColors;
562 if (m_cylinder->color().isValid()) {
566 cylinderColors = m_cylinder->segmentsColor();
570 float curOffset = 0.0;
571 unsigned int curSegment = 0;
575 while (curOffset < (2.0 * M_PI + anglePerDiv / 2.0)) {
576 const float curAngle = cylinderColors[0].startingAngle + curOffset;
578 if (((curSegment + 1) != cylinderColors.size()) && (cylinderColors[curSegment + 1].startingAngle < curAngle)) {
580 const float normY = sin(cylinderColors[curSegment + 1].startingAngle);
581 const float normZ = cos(cylinderColors[curSegment + 1].startingAngle);
582 const float y = m_radius * normY;
583 const float z = m_radius * normZ;
586 m_cylinderVertexes.append(lowerBaseX);
587 m_cylinderVertexes.append(y);
588 m_cylinderVertexes.append(z);
589 m_cylinderNormals.append(0.0);
590 m_cylinderNormals.append(normY);
591 m_cylinderNormals.append(normZ);
592 m_cylinderColors.append(cylinderColors[curSegment].color.redF());
593 m_cylinderColors.append(cylinderColors[curSegment].color.greenF());
594 m_cylinderColors.append(cylinderColors[curSegment].color.blueF());
595 m_cylinderTextureCoords.append(0.0);
596 m_cylinderTextureCoords.append(cylinderColors[curSegment + 1].startingAngle / (2.0 * M_PI));
597 m_cylinderVertexes.append(upperBaseX);
598 m_cylinderVertexes.append(y);
599 m_cylinderVertexes.append(z);
600 m_cylinderNormals.append(0.0);
601 m_cylinderNormals.append(normY);
602 m_cylinderNormals.append(normZ);
603 m_cylinderColors.append(cylinderColors[curSegment].color.redF());
604 m_cylinderColors.append(cylinderColors[curSegment].color.greenF());
605 m_cylinderColors.append(cylinderColors[curSegment].color.blueF());
606 m_cylinderTextureCoords.append(1.0);
607 m_cylinderTextureCoords.append(cylinderColors[curSegment + 1].startingAngle / (2.0 * M_PI));
613 m_cylinderVertexes.append(lowerBaseX);
614 m_cylinderVertexes.append(y);
615 m_cylinderVertexes.append(z);
616 m_cylinderNormals.append(0.0);
617 m_cylinderNormals.append(normY);
618 m_cylinderNormals.append(normZ);
619 m_cylinderColors.append(cylinderColors[curSegment].color.redF());
620 m_cylinderColors.append(cylinderColors[curSegment].color.greenF());
621 m_cylinderColors.append(cylinderColors[curSegment].color.blueF());
622 m_cylinderTextureCoords.append(0.0);
623 m_cylinderTextureCoords.append(cylinderColors[curSegment].startingAngle / (2.0 * M_PI));
624 m_cylinderVertexes.append(upperBaseX);
625 m_cylinderVertexes.append(y);
626 m_cylinderVertexes.append(z);
627 m_cylinderNormals.append(0.0);
628 m_cylinderNormals.append(normY);
629 m_cylinderNormals.append(normZ);
630 m_cylinderColors.append(cylinderColors[curSegment].color.redF());
631 m_cylinderColors.append(cylinderColors[curSegment].color.greenF());
632 m_cylinderColors.append(cylinderColors[curSegment].color.blueF());
633 m_cylinderTextureCoords.append(1.0);
634 m_cylinderTextureCoords.append(cylinderColors[curSegment].startingAngle / (2.0 * M_PI));
638 const float normY = sin(curAngle);
639 const float normZ = cos(curAngle);
640 const float y = m_radius * normY;
641 const float z = m_radius * normZ;
642 m_cylinderVertexes.append(lowerBaseX);
643 m_cylinderVertexes.append(y);
644 m_cylinderVertexes.append(z);
645 m_cylinderNormals.append(0.0);
646 m_cylinderNormals.append(normY);
647 m_cylinderNormals.append(normZ);
648 m_cylinderColors.append(cylinderColors[curSegment].color.redF());
649 m_cylinderColors.append(cylinderColors[curSegment].color.greenF());
650 m_cylinderColors.append(cylinderColors[curSegment].color.blueF());
651 m_cylinderTextureCoords.append(0.0);
652 m_cylinderTextureCoords.append(curOffset / (2.0 * M_PI));
653 m_cylinderVertexes.append(upperBaseX);
654 m_cylinderVertexes.append(y);
655 m_cylinderVertexes.append(z);
656 m_cylinderNormals.append(0.0);
657 m_cylinderNormals.append(normY);
658 m_cylinderNormals.append(normZ);
659 m_cylinderColors.append(cylinderColors[curSegment].color.redF());
660 m_cylinderColors.append(cylinderColors[curSegment].color.greenF());
661 m_cylinderColors.append(cylinderColors[curSegment].color.blueF());
662 m_cylinderTextureCoords.append(1.0);
663 m_cylinderTextureCoords.append(curOffset / (2.0 * M_PI));
665 curOffset += anglePerDiv;
670 QList<PhyCylinder::SegmentColor> upperBaseColor;
671 if (m_cylinder->color().isValid()) {
674 }
else if (m_cylinder->upperBaseColor().isValid()) {
678 upperBaseColor = m_cylinder->segmentsColor();
684 unsigned int numVertexesCurSegment = 0;
689 m_upperBaseVertexes.append(upperBaseX);
690 m_upperBaseVertexes.append(0.0);
691 m_upperBaseVertexes.append(0.0);
692 m_upperBaseNormals.append(1.0);
693 m_upperBaseNormals.append(0.0);
694 m_upperBaseNormals.append(0.0);
695 m_upperBaseColors.append(upperBaseColor[curSegment].color.redF());
696 m_upperBaseColors.append(upperBaseColor[curSegment].color.greenF());
697 m_upperBaseColors.append(upperBaseColor[curSegment].color.blueF());
698 m_upperBaseTextureCoords.append(0.5);
699 m_upperBaseTextureCoords.append(0.5);
700 ++numVertexesCurSegment;
701 while (curOffset < (2.0 * M_PI + anglePerDiv / 2.0)) {
702 const float curAngle = upperBaseColor[0].startingAngle + curOffset;
704 if (((curSegment + 1) != upperBaseColor.size()) && (upperBaseColor[curSegment + 1].startingAngle < curAngle)) {
706 const float normY = sin(upperBaseColor[curSegment + 1].startingAngle);
707 const float normZ = cos(upperBaseColor[curSegment + 1].startingAngle);
708 const float y = m_radius * normY;
709 const float z = m_radius * normZ;
712 m_upperBaseVertexes.append(upperBaseX);
713 m_upperBaseVertexes.append(y);
714 m_upperBaseVertexes.append(z);
715 m_upperBaseNormals.append(1.0);
716 m_upperBaseNormals.append(0.0);
717 m_upperBaseNormals.append(0.0);
718 m_upperBaseColors.append(upperBaseColor[curSegment].color.redF());
719 m_upperBaseColors.append(upperBaseColor[curSegment].color.greenF());
720 m_upperBaseColors.append(upperBaseColor[curSegment].color.blueF());
721 m_upperBaseTextureCoords.append((normY + 1.0) / 2.0);
722 m_upperBaseTextureCoords.append((normZ + 1.0) / 2.0);
723 ++numVertexesCurSegment;
724 m_upperBaseSegmentsLength.append(numVertexesCurSegment);
730 m_upperBaseVertexes.append(upperBaseX);
731 m_upperBaseVertexes.append(0.0);
732 m_upperBaseVertexes.append(0.0);
733 m_upperBaseNormals.append(1.0);
734 m_upperBaseNormals.append(0.0);
735 m_upperBaseNormals.append(0.0);
736 m_upperBaseColors.append(upperBaseColor[curSegment].color.redF());
737 m_upperBaseColors.append(upperBaseColor[curSegment].color.greenF());
738 m_upperBaseColors.append(upperBaseColor[curSegment].color.blueF());
739 m_upperBaseTextureCoords.append(0.5);
740 m_upperBaseTextureCoords.append(0.5);
741 m_upperBaseVertexes.append(upperBaseX);
742 m_upperBaseVertexes.append(y);
743 m_upperBaseVertexes.append(z);
744 m_upperBaseNormals.append(1.0);
745 m_upperBaseNormals.append(0.0);
746 m_upperBaseNormals.append(0.0);
747 m_upperBaseColors.append(upperBaseColor[curSegment].color.redF());
748 m_upperBaseColors.append(upperBaseColor[curSegment].color.greenF());
749 m_upperBaseColors.append(upperBaseColor[curSegment].color.blueF());
750 m_upperBaseTextureCoords.append((normY + 1.0) / 2.0);
751 m_upperBaseTextureCoords.append((normZ + 1.0) / 2.0);
752 numVertexesCurSegment = 2;
756 const float normY = sin(curAngle);
757 const float normZ = cos(curAngle);
758 const float y = m_radius * normY;
759 const float z = m_radius * normZ;
760 m_upperBaseVertexes.append(upperBaseX);
761 m_upperBaseVertexes.append(y);
762 m_upperBaseVertexes.append(z);
763 m_upperBaseNormals.append(1.0);
764 m_upperBaseNormals.append(0.0);
765 m_upperBaseNormals.append(0.0);
766 m_upperBaseColors.append(upperBaseColor[curSegment].color.redF());
767 m_upperBaseColors.append(upperBaseColor[curSegment].color.greenF());
768 m_upperBaseColors.append(upperBaseColor[curSegment].color.blueF());
769 m_upperBaseTextureCoords.append((normY + 1.0) / 2.0);
770 m_upperBaseTextureCoords.append((normZ + 1.0) / 2.0);
771 ++numVertexesCurSegment;
773 curOffset += anglePerDiv;
776 m_upperBaseSegmentsLength.append(numVertexesCurSegment);
780 QList<PhyCylinder::SegmentColor> lowerBaseColor;
781 if (m_cylinder->color().isValid()) {
784 }
else if (m_cylinder->lowerBaseColor().isValid()) {
788 lowerBaseColor = m_cylinder->segmentsColor();
794 numVertexesCurSegment = 0;
799 m_lowerBaseVertexes.append(lowerBaseX);
800 m_lowerBaseVertexes.append(0.0);
801 m_lowerBaseVertexes.append(0.0);
802 m_lowerBaseNormals.append(-1.0);
803 m_lowerBaseNormals.append(0.0);
804 m_lowerBaseNormals.append(0.0);
805 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.redF());
806 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.greenF());
807 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.blueF());
808 m_lowerBaseTextureCoords.append(0.5);
809 m_lowerBaseTextureCoords.append(0.5);
810 ++numVertexesCurSegment;
811 while (curOffset < (2.0 * M_PI + anglePerDiv / 2.0)) {
812 const float curAngle = lowerBaseColor[0].startingAngle + curOffset;
814 if (((curSegment + 1) != lowerBaseColor.size()) && (lowerBaseColor[curSegment + 1].startingAngle < curAngle)) {
816 const float normY = sin(lowerBaseColor[curSegment + 1].startingAngle);
817 const float normZ = cos(lowerBaseColor[curSegment + 1].startingAngle);
818 const float y = m_radius * normY;
819 const float z = m_radius * normZ;
822 m_lowerBaseVertexes.append(lowerBaseX);
823 m_lowerBaseVertexes.append(y);
824 m_lowerBaseVertexes.append(z);
825 m_lowerBaseNormals.append(-1.0);
826 m_lowerBaseNormals.append(0.0);
827 m_lowerBaseNormals.append(0.0);
828 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.redF());
829 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.greenF());
830 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.blueF());
831 m_lowerBaseTextureCoords.append((normY + 1.0) / 2.0);
832 m_lowerBaseTextureCoords.append((normZ + 1.0) / 2.0);
833 ++numVertexesCurSegment;
834 m_lowerBaseSegmentsLength.append(numVertexesCurSegment);
840 m_lowerBaseVertexes.append(lowerBaseX);
841 m_lowerBaseVertexes.append(0.0);
842 m_lowerBaseVertexes.append(0.0);
843 m_lowerBaseNormals.append(-1.0);
844 m_lowerBaseNormals.append(0.0);
845 m_lowerBaseNormals.append(0.0);
846 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.redF());
847 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.greenF());
848 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.blueF());
849 m_lowerBaseTextureCoords.append(0.5);
850 m_lowerBaseTextureCoords.append(0.5);
851 m_lowerBaseVertexes.append(lowerBaseX);
852 m_lowerBaseVertexes.append(y);
853 m_lowerBaseVertexes.append(z);
854 m_lowerBaseNormals.append(-1.0);
855 m_lowerBaseNormals.append(0.0);
856 m_lowerBaseNormals.append(0.0);
857 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.redF());
858 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.greenF());
859 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.blueF());
860 m_lowerBaseTextureCoords.append((normY + 1.0) / 2.0);
861 m_lowerBaseTextureCoords.append((normZ + 1.0) / 2.0);
862 numVertexesCurSegment = 2;
866 const float normY = sin(curAngle);
867 const float normZ = cos(curAngle);
868 const float y = m_radius * normY;
869 const float z = m_radius * normZ;
870 m_lowerBaseVertexes.append(lowerBaseX);
871 m_lowerBaseVertexes.append(y);
872 m_lowerBaseVertexes.append(z);
873 m_lowerBaseNormals.append(-1.0);
874 m_lowerBaseNormals.append(0.0);
875 m_lowerBaseNormals.append(0.0);
876 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.redF());
877 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.greenF());
878 m_lowerBaseColors.append(lowerBaseColor[curSegment].color.blueF());
879 m_lowerBaseTextureCoords.append((normY + 1.0) / 2.0);
880 m_lowerBaseTextureCoords.append((normZ + 1.0) / 2.0);
881 ++numVertexesCurSegment;
883 curOffset += anglePerDiv;
886 m_lowerBaseSegmentsLength.append(numVertexesCurSegment);
1011 rad = cone->radius();
1012 hei = cone->height();
1015 virtual void render( QGLContext* gw ) {
1017 GLUquadricObj *pObj;
1022 wMatrix matrix = wMatrix::yaw( PI_GRECO * 0.5 );
1024 matrix = matrix * cone->matrix();
1025 GLMultMatrix(&matrix[0][0]);
1028 pObj = gluNewQuadric();
1029 gluQuadricTexture(pObj,
true);
1030 gluCylinder(pObj, rad, 0, hei, 20, 2);
1033 gluQuadricOrientation(pObj, GLU_INSIDE);
1034 gluDisk(pObj, 0.0f, rad, 20, 1);
1036 gluDeleteQuadric(pObj);
1041 calculateAABB( minpoint, maxpoint, obj->matrix() );
1046 real tdx = fabs(tm.x_ax[0]*h2) + fabs(tm.y_ax[0]*rad) + fabs(tm.z_ax[0]*rad);
1047 real tdy = fabs(tm.x_ax[1]*h2) + fabs(tm.y_ax[1]*rad) + fabs(tm.z_ax[1]*rad);
1048 real tdz = fabs(tm.x_ax[2]*h2) + fabs(tm.y_ax[2]*rad) + fabs(tm.z_ax[2]*rad);
1050 minPoint = tm.w_pos - hds;
1051 maxPoint = tm.w_pos + hds;
1056 dimension[1] = rad*2.0;
1057 dimension[2] = rad*2.0;
1158 #ifdef FARSA_USE_YARP_AND_ICUB
1160 RenderICub::RenderICub( WObject* wobj, RenderWObjectContainer* container ) :
1161 RenderWObject( wobj, container )
1163 icub = (PhyiCub*)wobj;
1164 icub->forceKinematicChainsUpdate(
true);
1165 initRobjv(container);
1168 RenderICub::~RenderICub()
1171 icub->forceKinematicChainsUpdate(
false);
1175 void RenderICub::render( QGLContext* gw )
1180 void RenderICub::renderAABB( RenderWorld* gw )
1182 wVector minpoint, maxpoint;
1183 calculateAABB( minpoint, maxpoint, obj->matrix() );
1184 gw->drawWireBox( minpoint, maxpoint );
1187 void RenderICub::calculateAABB( wVector& minPoint, wVector& maxPoint,
const wMatrix tm )
1190 QList<RenderWObject*> robjs = robjv.values();
1191 robjs[0]->calculateAABB( minPoint, maxPoint, robjs[0]->
object()->matrix() );
1193 for(
int i=1; i<robjs.size(); i++ ) {
1194 robjs[i]->calculateAABB( minP, maxP, robjs[i]->
object()->matrix() );
1195 mergeAABB( minPoint, maxPoint, minP, maxP );
1199 void RenderICub::calculateOBB( wVector& dimension, wVector& minPoint, wVector& maxPoint )
1210 dimension[0] = fabs( maxPoint[0] - minPoint[0] );
1211 dimension[1] = fabs( maxPoint[1] - minPoint[1] );
1212 dimension[2] = fabs( maxPoint[2] - minPoint[2] );
1215 void RenderICub::objectAlreadyDestroyed()
1220 void RenderICub::initRobjv( RenderWObjectContainer* container )
1223 foreach( RenderWObject* wobj, container->graphics() ) {
1224 if ( wobj->object()->owner() == icub ) {
1225 robjv[wobj->object()] = wobj;
1228 foreach( WObject* obj, icub->leftLeg() ) {
1229 obj->setUseColorTextureOfOwner(
true);
1231 foreach( WObject* obj, icub->rightLeg() ) {
1232 obj->setUseColorTextureOfOwner(
true);
1234 foreach( WObject* obj, icub->torso() ) {
1235 obj->setUseColorTextureOfOwner(
true);
1237 foreach( WObject* obj, icub->leftArm() ) {
1238 obj->setUseColorTextureOfOwner(
true);
1240 foreach( WObject* obj, icub->rightArm() ) {
1241 obj->setUseColorTextureOfOwner(
true);
1244 foreach( WObject* obj, icub->headNeck() ) {
1246 if ( ( i == 4 ) || ( i == 5 ) ) {
1247 obj->setUseColorTextureOfOwner(
false);
1249 obj->setUseColorTextureOfOwner(
true);
1253 foreach( WObject* obj, icub->covers() ) {
1254 obj->setUseColorTextureOfOwner(
false);
1258 void RenderICub::mergeAABB( wVector& minPointA, wVector& maxPointA,
const wVector& minPointB,
const wVector& maxPointB )
1260 minPointA[0] =
min( minPointA[0], minPointB[0] );
1261 minPointA[1] =
min( minPointA[1], minPointB[1] );
1262 minPointA[2] =
min( minPointA[2], minPointB[2] );
1263 maxPointA[0] =
max( maxPointA[0], maxPointB[0] );
1264 maxPointA[1] =
max( maxPointA[1], maxPointB[1] );
1265 maxPointA[2] =
max( maxPointA[2], maxPointB[2] );
1274 initRobjv( container );
1281 virtual void render( QGLContext* gw ) {
1285 GLMultMatrix(&matrix[0][0]);
1297 robjv[0]->calculateAABB( minPoint, maxPoint, robjv[0]->
object()->matrix()*tm );
1299 for(
int i=1; i<robjv.size(); i++ ) {
1300 robjv[i]->calculateAABB( minP, maxP, robjv[i]->
object()->matrix()*tm );
1301 mergeAABB( minPoint, maxPoint, minP, maxP );
1308 if ( robjv.size() == 0 ) {
1309 qWarning(
"== this point should never reached: renderwobjecthierarchy.cpp:435" );
1312 robjv[0]->calculateAABB( minPoint, maxPoint, robjv[0]->
object()->matrix() );
1313 for(
int i=1; i<robjv.size(); i++ ) {
1314 robjv[i]->calculateAABB( minP, maxP, robjv[i]->
object()->matrix() );
1315 mergeAABB( minPoint, maxPoint, minP, maxP );
1317 dimension[0] = fabs( maxPoint[0] - minPoint[0] );
1318 dimension[1] = fabs( maxPoint[1] - minPoint[1] );
1319 dimension[2] = fabs( maxPoint[2] - minPoint[2] );
1323 QVector<RenderWObject*> robjv;
1330 void mergeAABB( wVector& minPointA, wVector& maxPointA,
const wVector& minPointB,
const wVector& maxPointB ) {
1331 minPointA[0] =
min( minPointA[0], minPointB[0] );
1332 minPointA[1] =
min( minPointA[1], minPointB[1] );
1333 minPointA[2] =
min( minPointA[2], minPointB[2] );
1334 maxPointA[0] =
max( maxPointA[0], maxPointB[0] );
1335 maxPointA[1] =
max( maxPointA[1], maxPointB[1] );
1336 maxPointA[2] =
max( maxPointA[2], maxPointB[2] );
1340 #ifdef FARSA_USE_YARP_AND_ICUB
1351 virtual void render( QGLContext* gw ) {
1356 GLMultMatrix(&m[0][0]);
1361 float hdx = (dx/2.0);
1362 float hdy = (dy/2.0);
1363 float hdz = (dz/2.0);
1365 glNormal3f(0.0, 0.0, 1.0);
1366 glTexCoord2f(0.0, 0.0); glVertex3f(-hdx, -hdy, hdz);
1367 glTexCoord2f(1.0, 0.0); glVertex3f( hdx, -hdy, hdz);
1368 glTexCoord2f(1.0, 1.0); glVertex3f( hdx, hdy, hdz);
1369 glTexCoord2f(0.0, 1.0); glVertex3f(-hdx, hdy, hdz);
1371 glNormal3f(0.0, 0.0, -1.0);
1372 glTexCoord2f(0.0, 0.0); glVertex3f( hdx, -hdy, -hdz);
1373 glTexCoord2f(1.0, 0.0); glVertex3f(-hdx, -hdy, -hdz);
1374 glTexCoord2f(1.0, 1.0); glVertex3f(-hdx, hdy, -hdz);
1375 glTexCoord2f(0.0, 1.0); glVertex3f( hdx, hdy, -hdz);
1377 glNormal3f(0.0, 1.0, 0.0);
1378 glTexCoord2f(0.0, 0.0); glVertex3f(-hdx, hdy, hdz);
1379 glTexCoord2f(1.0, 0.0); glVertex3f( hdx, hdy, hdz);
1380 glTexCoord2f(1.0, 1.0); glVertex3f( hdx, hdy, -hdz);
1381 glTexCoord2f(0.0, 1.0); glVertex3f(-hdx, hdy, -hdz);
1383 glNormal3f(0.0, -1.0, 0.0);
1384 glTexCoord2f(0.0, 0.0); glVertex3f(-hdx, -hdy, -hdz);
1385 glTexCoord2f(1.0, 0.0); glVertex3f( hdx, -hdy, -hdz);
1386 glTexCoord2f(1.0, 1.0); glVertex3f( hdx, -hdy, hdz);
1387 glTexCoord2f(0.0, 1.0); glVertex3f(-hdx, -hdy, hdz);
1389 glNormal3f(-1.0, 0.0, 0.0);
1390 glTexCoord2f(0.0, 0.0); glVertex3f(-hdx, -hdy, -hdz);
1391 glTexCoord2f(1.0, 0.0); glVertex3f(-hdx, -hdy, hdz);
1392 glTexCoord2f(1.0, 1.0); glVertex3f(-hdx, hdy, hdz);
1393 glTexCoord2f(0.0, 1.0); glVertex3f(-hdx, hdy, -hdz);
1395 glNormal3f(1.0, 0.0, 0.0);
1396 glTexCoord2f(0.0, 0.0); glVertex3f(hdx, -hdy, hdz);
1397 glTexCoord2f(1.0, 0.0); glVertex3f(hdx, -hdy, -hdz);
1398 glTexCoord2f(1.0, 1.0); glVertex3f(hdx, hdy, -hdz);
1399 glTexCoord2f(0.0, 1.0); glVertex3f(hdx, hdy, hdz);
1414 real tdx = fabs(tm.x_ax[0]*dx) + fabs(tm.y_ax[0]*dy) + fabs(tm.z_ax[0]*dz);
1415 real tdy = fabs(tm.x_ax[1]*dx) + fabs(tm.y_ax[1]*dy) + fabs(tm.z_ax[1]*dz);
1416 real tdz = fabs(tm.x_ax[2]*dx) + fabs(tm.y_ax[2]*dy) + fabs(tm.z_ax[2]*dz);
1417 wVector hds( tdx/2.0, tdy/2.0, tdz/2.0 );
1418 minPoint = tm.w_pos - hds;
1419 maxPoint = tm.w_pos + hds;
1425 wVector hds( dx/2.0, dy/2.0, dz/2.0 );
1434 #endif // FARSA_USE_YARP_AND_ICUB
1443 m_graphicalWObject(dynamic_cast<GraphicalWObject*>(obj))
1451 virtual void render(QGLContext *gw)
1475 bool RenderWObjectContainer::facInited =
false;
1476 QMap<QString, WAbstractCreator*>* RenderWObjectContainer::fac;
1477 void RenderWObjectContainer::initFactory() {
1478 if ( facInited )
return;
1480 fac =
new QMap<QString, WAbstractCreator*>();
1482 (*fac)[
"farsa::WMesh"] =
new WCreator<RenderWMesh>();
1483 (*fac)[
"farsa::PhyBox"] =
new WCreator<RenderPhyBox>();
1484 (*fac)[
"farsa::PhySphere"] =
new WCreator<RenderPhySphere>();
1485 (*fac)[
"farsa::PhyCylinder"] =
new WCreator<RenderPhyCylinder>();
1486 (*fac)[
"farsa::PhyCone"] =
new WCreator<RenderPhyCone>();
1488 (*fac)[
"farsa::PhyCompoundObject"] =
new WCreator<RenderCompoundObject>();
1489 #ifdef FARSA_USE_YARP_AND_ICUB
1490 (*fac)[
"farsa::WCamera"] =
new WCreator<RenderWCamera>();
1491 (*fac)[PhyiCub::staticMetaObject.className()] =
new WCreator<RenderICub>();
1493 (*fac)[
"farsa::GraphicalWObject"] =
new WCreator<GraphicalWObjectRenderer>();
1496 (*fac)[
"farsa::WObject"] =
new WCreator<RenderGenericObject>();
1497 (*fac)[
"farsa::WorldController"] =
new WCreator<RenderGenericObject>();