BaseIF* makeVane(const Real& thick, const RealVect& normal, const Real& innerRadius, const Real& outerRadius, const Real& offset, const Real& height) { RealVect zero(D_DECL(0.0,0.0,0.0)); RealVect xAxis(D_DECL(1.0,0.0,0.0)); bool inside = true; Vector<BaseIF*> vaneParts; // Each side of the vane (infinite) RealVect normal1(normal); RealVect point1(D_DECL(offset+height/2.0,-thick/2.0,0.0)); PlaneIF plane1(normal1,point1,inside); vaneParts.push_back(&plane1); RealVect normal2(-normal); RealVect point2(D_DECL(offset+height/2.0,thick/2.0,0.0)); PlaneIF plane2(normal2,point2,inside); vaneParts.push_back(&plane2); // Make sure we only get something to the right of the origin RealVect normal3(D_DECL(0.0,0.0,1.0)); RealVect point3(D_DECL(0.0,0.0,0.0)); PlaneIF plane3(normal3,point3,inside); vaneParts.push_back(&plane3); // Cut off the top and bottom RealVect normal4(D_DECL(1.0,0.0,0.0)); RealVect point4(D_DECL(offset,0.0,0.0)); PlaneIF plane4(normal4,point4,inside); vaneParts.push_back(&plane4); RealVect normal5(D_DECL(-1.0,0.0,0.0)); RealVect point5(D_DECL(offset+height,0.0,0.0)); PlaneIF plane5(normal5,point5,inside); vaneParts.push_back(&plane5); // The outside of the inner cylinder TiltedCylinderIF inner(innerRadius,xAxis,zero,!inside); vaneParts.push_back(&inner); // The inside of the outer cylinder TiltedCylinderIF outer(outerRadius,xAxis,zero,inside); vaneParts.push_back(&outer); IntersectionIF* vane = new IntersectionIF(vaneParts); return vane; }
void lookat(vec3 eye, vec3 center, vec3 up, float* camera) { vec3 z = normal3(sub3(eye, center)); vec3 x = normal3(cross3(up,z)); vec3 y = normal3(cross3(z,x)); float Minv[4][4]; float Tr[4][4]; mat_identity(&Minv[0][0]); mat_identity(&Tr[0][0]); Minv[0][0] = x.x; Minv[1][0] = y.x; Minv[2][0] = z.x; Tr[0][3] = -center.x; Minv[0][1] = x.y; Minv[1][1] = y.y; Minv[2][1] = z.y; Tr[1][3] = -center.y; Minv[0][2] = x.z; Minv[1][2] = y.z; Minv[2][2] = z.z; Tr[2][3] = -center.z; matmul(&Minv[0][0], &Tr[0][0], camera); }
BaseIF* makeVane(const Real& thick, const RealVect& normal, const Real& innerRadius, const Real& outerRadius, const Real& offset, const Real& height, const Real& angle) { RealVect zeroVect(D_DECL(0.0,0.0,0.0)); RealVect xAxis(D_DECL(1.0,0.0,0.0)); bool inside = true; Vector<BaseIF*> vaneParts; Real sinTheta = sin(angle); #if CH_SPACEDIM == 3 Real cosTheta = cos(angle); // Each side of the vane (infinite) // rotate the normal around x-axis RealVect normal1(D_DECL(normal[0],cosTheta*normal[1]-sinTheta*normal[2],sinTheta*normal[1]+cosTheta*normal[2])); // rotate point on top of vane around x-axis RealVect point(D_DECL(offset+height/2.0,-thick/2.0,0.0)); RealVect point1(D_DECL(point[0],cosTheta*point[1]-sinTheta*point[2],sinTheta*point[1]+cosTheta*point[2])); PlaneIF plane1(normal1,point1,inside); vaneParts.push_back(&plane1); RealVect normal2(-normal1); // rotate point on bottom (-point[2] of vane around x-axis RealVect point2(D_DECL(point[0],-cosTheta*point[1]-sinTheta*point[2],-sinTheta*point[1]+cosTheta*point[2])); PlaneIF plane2(normal2,point2,inside); vaneParts.push_back(&plane2); #endif // Make sure we only get something to the right of the origin RealVect normal3(D_DECL(0.0,-sinTheta,cosTheta)); RealVect point3(D_DECL(0.0,0.0,0.0)); PlaneIF plane3(normal3,point3,inside); vaneParts.push_back(&plane3); // Cut off the top and bottom RealVect normal4(D_DECL(1.0,0.0,0.0)); RealVect point4(D_DECL(offset,0.0,0.0)); PlaneIF plane4(normal4,point4,inside); vaneParts.push_back(&plane4); RealVect normal5(D_DECL(-1.0,0.0,0.0)); RealVect point5(D_DECL(offset+height,0.0,0.0)); PlaneIF plane5(normal5,point5,inside); vaneParts.push_back(&plane5); // The outside of the inner cylinder TiltedCylinderIF inner(innerRadius,xAxis,zeroVect,!inside); vaneParts.push_back(&inner); // The inside of the outer cylinder TiltedCylinderIF outer(outerRadius,xAxis,zeroVect,inside); vaneParts.push_back(&outer); IntersectionIF* vane = new IntersectionIF(vaneParts); return vane; }
void ShapeParabolicRectangle::generatePrimitives(SoAction *action) { SoPrimitiveVertex pv; SoState *state = action->getState(); SbBool useTexFunc = ( SoTextureCoordinateElement::getType(state) == SoTextureCoordinateElement::FUNCTION ); const SoTextureCoordinateElement* tce = 0; if ( useTexFunc ) tce = SoTextureCoordinateElement::getInstance(state); SbVec3f point; const int rows = 12; // Number of points per row const int columns = 12; // Number of points per column const int totalPoints = (rows)*(columns); // Total points in the grid float vertex[totalPoints][6]; int h = 0; double ui = 0; double vj = 0; for (int i = 0; i < rows; ++i ) { ui =( 1.0 /(double)(rows-1) ) * i; for ( int j = 0 ; j < columns ; ++j ) { vj = ( 1.0 /(double)(columns-1) ) * j; Point3D point = GetPoint3D(ui, vj); NormalVector normal; if( activeSide.getValue() == 0 ) normal = -GetNormal(ui, vj); else normal = GetNormal(ui, vj); vertex[h][0] = point.x; vertex[h][1] = point.y; vertex[h][2] = point.z; vertex[h][3] = normal.x; vertex[h][4] = normal.y; vertex[h][5] = normal.z; pv.setPoint( vertex[h][0], vertex[h][1], vertex[h][2] ); h++; //Increase h to the next point. } } float u = 1; float v = 1; beginShape(action, QUADS ); for( int irow = 0; irow < (rows-1); ++irow ) { for( int icolumn = 0; icolumn < (columns-1); ++icolumn ) { int index0 = irow*columns + icolumn; SbVec3f point0( vertex[index0][0], vertex[index0][1], vertex[index0][2] ); SbVec3f normal0(vertex[index0][3], vertex[index0][4], vertex[index0][5] ); SbVec4f texCoord0 = useTexFunc ? tce->get(point0, normal0): SbVec4f( u,v, 0.0, 1.0 ); pv.setPoint(point0); pv.setNormal(normal0); pv.setTextureCoords(texCoord0); shapeVertex(&pv); int index1 = index0 + 1; SbVec3f point1( vertex[index1][0], vertex[index1][1], vertex[index1][2] ); SbVec3f normal1(vertex[index1][3], vertex[index1][4], vertex[index1][5] ); SbVec4f texCoord1 = useTexFunc ? tce->get(point1, normal1): SbVec4f( u,v, 0.0, 1.0 ); pv.setPoint(point1); pv.setNormal(normal1); pv.setTextureCoords(texCoord1); shapeVertex(&pv); int index3 = index0 + columns; int index2 = index3 + 1; SbVec3f point2( vertex[index2][0], vertex[index2][1], vertex[index2][2] ); SbVec3f normal2(vertex[index2][3], vertex[index2][4], vertex[index2][5] ); SbVec4f texCoord2 = useTexFunc ? tce->get(point2, normal2): SbVec4f( u,v, 0.0, 1.0 ); pv.setPoint(point2); pv.setNormal(normal2); pv.setTextureCoords(texCoord2); shapeVertex(&pv); SbVec3f point3( vertex[index3][0], vertex[index3][1], vertex[index3][2] ); SbVec3f normal3(vertex[index3][3], vertex[index3][4], vertex[index3][5] ); SbVec4f texCoord3 = useTexFunc ? tce->get(point3, normal3): SbVec4f( u,v, 0.0, 1.0 ); pv.setPoint(point3); pv.setNormal(normal3); pv.setTextureCoords(texCoord3); shapeVertex(&pv); } } endShape(); }
void QmaxButton::createArrowBackground(QPainter &painter) { // printf("Arrow BackGround2\n"); QRect scaledRect; scaledRect = matrix.mapRect(QRect(0, 0, this->logicalSize.width(), this->logicalSize.height())); QImage image(scaledRect.width(), scaledRect.height(), QImage::Format_ARGB32_Premultiplied); image.fill(QColor(0, 0, 0, 0).rgba()); //QPainter painter(image); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); painter.drawImage(0, 0, image); if(Colors::useEightBitPalette) { painter.setPen(QColor(120,120,120)); if(this->m_nPressed) painter.setBrush(QColor(60,60,60)); else if(this->m_nHighlight) painter.setBrush(QColor(100,100,100)); else painter.setBrush(QColor(80,80,80)); } else { QLinearGradient outlinebrush(0,0,0,scaledRect.height()); QLinearGradient brush(0,0,0,scaledRect.height()); brush.setSpread(QLinearGradient::PadSpread); QColor highlight(255,255,255,128); QColor shadow(0,0,0,70); QColor sunken(220,220,220,30); QColor normal1(88,88,89,255); QColor normal2(88,88,89,255); QColor normal3(0,0,200,10); QColor normal4(255,255,250,255); if(m_nType==3 || m_nType == 4) { normal1 = QColor(100,180,189,55); normal2 = QColor(100,180,189,255); } if(m_nPressed) { outlinebrush.setColorAt(0.0f,shadow); outlinebrush.setColorAt(1.0f,highlight); brush.setColorAt(1.0f,sunken); painter.setPen(Qt::NoPen); } else { outlinebrush.setColorAt(0.75f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal2); if(m_nHighlight) brush.setColorAt(1.0f,normal1); painter.setPen(QPen(outlinebrush,1)); } if(this->isEnabled()==false ) { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal3); painter.setPen(QPen(outlinebrush,2)); } if(m_nStatus ) { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal2); painter.setPen(QPen(outlinebrush,1)); } painter.setBrush(brush); } // painter.drawRect(0, 0, scaledRect.width(), scaledRect.height()); float xOff = scaledRect.width() / 2; float yOff = scaledRect.height() / 2; float sizex = 5.0f * matrix.m11(); float sizey = 3.5f * matrix.m22(); if (m_nType == 3) sizey *= -1; QPainterPath path; path.moveTo(xOff, yOff + (5 * sizey)); path.lineTo(xOff - (4 * sizex), yOff - (3 * sizey)); path.lineTo(xOff + (4 * sizex), yOff - (3 * sizey)); path.lineTo(xOff, yOff + (5 * sizey)); painter.drawPath(path); }
void QmaxButton::createButton(QPainter &painter) { QRect scaledRect; scaledRect = matrix.mapRect(QRect(0,0,this->logicalSize.width(),this->logicalSize.height())); QImage bg(this->m_strImage); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); QLinearGradient brush1(0,0,0,scaledRect.height()); painter.drawImage(-2, -2, bg); if(Colors::useEightBitPalette) { painter.setPen(QColor(120,120,120)); if(this->m_nPressed) painter.setBrush(QColor(60,60,60)); else if(this->m_nHighlight) painter.setBrush(QColor(100,100,100)); else painter.setBrush(QColor(80,80,80)); } else { QLinearGradient outlinebrush(0,0,0,scaledRect.height()); QLinearGradient brush(0,0,0,scaledRect.height()); brush.setSpread(QLinearGradient::PadSpread); QColor highlight(255,255,255,128); QColor shadow(0,0,0,70); QColor sunken(220,220,220,30); QColor normal1(255,255,245,60); QColor normal2(255,255,235,10); QColor normal3(200,200,200,10); QColor normal4(255,255,250,255); if(m_nType && m_nType != 5 ) { normal1 = QColor(200,170,160,50); normal2 = QColor(50,10,0,50); } if(m_nPressed) { outlinebrush.setColorAt(0.0f,shadow); outlinebrush.setColorAt(1.0f,highlight); brush.setColorAt(1.0f,sunken); painter.setPen(Qt::NoPen); } else { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal1); if(m_nHighlight) brush.setColorAt(1.0f,normal2); painter.setPen(QPen(outlinebrush,1)); } if(this->isEnabled()==false ) { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal3); painter.setPen(QPen(outlinebrush,1)); } if(m_nStatus ) { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal4); painter.setPen(QPen(outlinebrush,1)); } painter.setBrush(brush); } if(m_nType == 1) painter.drawRect(0,0,scaledRect.width(),scaledRect.height()); else if(m_nType == 0) painter.drawRoundedRect(0,0,scaledRect.width(),scaledRect.height(),40.0,40.0,Qt::RelativeSize); else if(m_nType == 5) painter.drawEllipse(0,0,scaledRect.width(),scaledRect.height()); QFont font( "DejaVu Sans" ); font.setPointSize( 12 ); painter.setFont( font ); brush1.setColorAt(1.0f,QColor(255,255,255,255)); if(this->isEnabled()==false) { brush1.setColorAt(1.0f,QColor(200,200,200,100)); } painter.setPen(QPen(brush1,1)); painter.setBrush(brush1); QFontMetrics fMetrics = painter.fontMetrics(); QSize sz = fMetrics.size( Qt::TextWordWrap, m_strText ); QRectF txtRect( scaledRect.center(), sz ); int xPoint = (scaledRect.width()/2)- ((m_strText.count()/2)*10); int yPoint = scaledRect.height()/2; painter.drawText(xPoint,yPoint,m_strText); }