void TowerRenderable::Init() { back = new RectRenderable(size, size); back->setup_vertexes(); back->set_shader(this->shader); Color3f back_color(0.1f, 0.2f, 0.3f); back->SetColor(back_color); front = new RectRenderable(size, size); front->set_shader(this->shader); Color3f front_color(0.0f, 0.3f, 0.9f); front->SetColor(front_color); }
void ramActorsScene::drawNodes(const ramNodeArray &NA) { ofPushStyle(); ofNoFill(); ofSetRectMode(OF_RECTMODE_CENTER); glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(GL_CULL_FACE); ofColor front_color(ofGetStyle().color, 200); ofColor back_color(ofGetStyle().color, 150); for (int i = 0; i < NA.getNumNode(); i++) { ofSetColor(front_color); const ramNode &node = NA.getNode(i); const ramNode *parent = node.getParent(); if (parent == NULL) continue; ramBox(node, 2); parent->beginTransform(); ofVec3f axis(0, 0, 1); ofVec3f c = node.getPosition().normalized().crossed(axis); ofRotate(90, c.x, c.y, c.z); ofVec3f p0 = node.getGlobalPosition(); ofVec3f p1 = parent->getGlobalPosition(); float dist = p0.distance(p1); float offset = 0.2; glNormal3f(0, 0, 0); ofLine(ofVec3f(0), ofVec3f(0, 0, -dist)); if (i < 4) glScalef(1., 1.8, 1); else if (i == 4) glScalef(1, 1, 3); else glScalef(1., 0.8, 1); glBegin(GL_TRIANGLE_STRIP); for (int n = 0; n < 6; n++) { float d = ofMap(n, 0, 5, 0, 1); float dd = ofMap(d, 0, 1, offset, 1 - offset); float xx = sin(d * PI) * 2 + 4; float zz = dd * -dist; float w = 5; glNormal3f(1, 0.5, 0); glVertex3f(xx, w, zz); glNormal3f(1, -0.5, 0); glVertex3f(xx, -w, zz); } glEnd(); ofSetColor(back_color); glBegin(GL_TRIANGLE_STRIP); for (int n = 0; n < 6; n++) { float d = ofMap(n, 0, 5, 0, 1); float dd = ofMap(d, 0, 1, offset, 1 - offset); float xx = -sin(d * PI) * 1 - 6; float zz = dd * -dist; float w = 3; glNormal3f(-1, 0.5, 0); glVertex3f(xx, -w, zz); glNormal3f(-1, -0.5, 0); glVertex3f(xx, w, zz); } glEnd(); parent->endTransform(); } glPopAttrib(); ofPopStyle(); }
// Pie Charts. // //++++++++++++++++++++++ void glwidget::push_piechart( qreal cx, qreal cy ){ // Create the back of the piechart. // { QVector3D back_color(1,1,1); qreal r=0.4; int num=20; qreal step = 360.0/num; qreal s,c; for(int ii=0; ii<num; ii++){ // Rotate around the center by a radius. // qreal t=step*ii; t *= (3.14159265359 / 180.0); s = sin(t); c = cos(t); qreal x=c*(cx+r)-s*(cy+r); qreal y=s*(cx+r)+c*(cy+r); // Create the vertex/index. // //_info._vertices.push_back( Vertex( x,y,0,1, back_color.x(),back_color.y(),back_color.z(),1) ); //_info._indices.push_back( _info._index_count++ ); } } // Create the slices. // int slices=3; { // Create the back of the piechart. // QVector3D slice_colors[] = { QVector3D(1,0,0), QVector3D(0,1,0), QVector3D(0,0,1) }; qreal r=0.05; int num=20; qreal step = 360.0/num; qreal s,c; int slice_step=num/slices; int slice_count=0; int slice=0; for(int ii=0; ii<num; ii++){ // if( slice_count >= slice_step ){ slice_count=0; slice++; if( slice >= slices ) slice=0; } slice_count++; // Rotate around the center by a radius. // qreal t=step*ii; t *= (3.14159265359 / 180.0); s = sin(t); c = cos(t); qreal x_here=cx + (c*r-s*r); qreal y_here=cy + (s*r+c*r); // Rotate around the center by a radius. // t=step*(ii+1); t *= (3.14159265359 / 180.0); s = sin(t); c = cos(t); qreal x_next=cx + (c*r-s*r); qreal y_next=cy + (s*r+c*r); // Create the triangle. // _info._vertices.push_back( Vertex( cx,cy,0,1, slice_colors[slice].x(),slice_colors[slice].y(),slice_colors[slice].z(),1) ); _info._vertices.push_back( Vertex( x_here,y_here,0,1, slice_colors[slice].x(),slice_colors[slice].y(),slice_colors[slice].z(),1) ); _info._vertices.push_back( Vertex( x_next,y_next,0,1, slice_colors[slice].x(),slice_colors[slice].y(),slice_colors[slice].z(),1) ); _info._indices.push_back( _info._index_count++ ); _info._indices.push_back( _info._index_count++ ); _info._indices.push_back( _info._index_count++ ); } } // Glue. // _info._vertices.push_back( Vertex( 0,0,0,1, 0,0,0,1) ); _info._vertices.push_back( Vertex( 0,0,0,1, 0,0,0,1) ); _info._vertices.push_back( Vertex( 0,0,0,1, 0,0,0,1) ); _info._indices.push_back( _info._index_count++ ); _info._indices.push_back( _info._index_count++ ); _info._indices.push_back( _info._index_count++ ); // Find the number of vertices in a single pie chart. // if( _info._verts_in_single_chart == 0 ){ _info._verts_in_single_chart=_info._vertices.count(); qDebug() << QString("Vertices in single chart [count:%1]") .arg(_info._verts_in_single_chart); } }