int KGListCtrl::DrawRect( CDC* dc, CRect rt, COLORREF colorFrame, COLORREF colorBack, int nFlag ) { int nLen = (int)((rt.right - rt.left) * 0.5); CPoint point_top(rt.left + nLen, rt.top + 2); CPoint point_dwn(rt.left + nLen, rt.bottom - 1); CPoint point_lef(rt.left + 2, rt.top + nLen); CPoint point_rig(rt.right - 1, rt.top + nLen); dc->FillRect(&rt, &CBrush(colorBack)); CPen pen(PS_SOLID, 1, colorFrame); dc->SelectObject(&pen); dc->MoveTo(rt.left, rt.top); dc->LineTo(rt.right, rt.top); dc->LineTo(rt.right, rt.bottom); dc->LineTo(rt.left, rt.bottom); dc->LineTo(rt.left, rt.top); if (nFlag) { dc->MoveTo(point_top); dc->LineTo(point_dwn); dc->MoveTo(point_lef); dc->LineTo(point_rig); } else { dc->MoveTo(point_lef); dc->LineTo(point_rig); } return true; }
std::vector< std::vector<c_tikz_obj*> > c_polygon::split(const c_polygon& against) const { std::vector< std::vector<c_tikz_obj*> > ret(3); // Check each point individually char loc_a, loc_b, loc_c; loc_a = utils::is_located(a, against); loc_b = utils::is_located(b, against); loc_c = utils::is_located(c, against); // Check if we're above or below or inside if (loc_a == loc_b && loc_b == loc_c) { ret[loc_a].push_back(clone()); return ret; } // Check if point a is barely touching if (loc_a == 1 && loc_b == loc_c) { ret[loc_b].push_back(clone()); return ret; } // Check if point b is barely touching if (loc_b == 1 && loc_a == loc_c) { ret[loc_c].push_back(clone()); return ret; } // Check if point c is barely touching if (loc_c == 1 && loc_b == loc_a) { ret[loc_a].push_back(clone()); return ret; } // Check if a and b are barely touching if (loc_a == 1 && loc_b == 1) { ret[loc_c].push_back(clone()); return ret; } // Check if a and c are barely touching if (loc_a == 1 && loc_c == 1) { ret[loc_b].push_back(clone()); return ret; } // Check if b and c are barely touching if (loc_b == 1 && loc_c == 1) { ret[loc_a].push_back(clone()); return ret; } // Check if 1 point touching, one above, one below if (loc_a == 1 || loc_b == 1 || loc_c == 1) { c_line line; c_point split1, split2; if (loc_a == 1) { split1 = b; split2 = c; } if (loc_b == 1) { split1 = a; split2 = c; } if (loc_c == 1) { split1 = a; split2 = b; } line.set_points(split1, split2); // Split the line real split_pos = utils::get_split_point(line, against); c_point split_point = split1*split_pos + split2*(1-split_pos); c_polygon * polygon1 = (c_polygon*) this->clone(); c_polygon * polygon2 = (c_polygon*) this->clone(); if (loc_a == 1) { polygon1->a = a; polygon1->b = b; polygon1->c = split_point; polygon2->a = a; polygon2->b = c; polygon2->c = split_point; } if (loc_b == 1) { polygon1->a = b; polygon1->b = c; polygon1->c = split_point; polygon2->a = b; polygon2->b = a; polygon2->c = split_point; } if (loc_c == 1) { polygon1->a = c; polygon1->b = b; polygon1->c = split_point; polygon2->a = c; polygon2->b = a; polygon2->c = split_point; } ret[0].push_back(polygon1); ret[2].push_back(polygon2); return ret; } // Remaining cases: Two points above, one point below c_line line1, line2; bool two_above; if (loc_a == 0 && loc_b == 2 && loc_c == 2) { // Split ba and ca against the polygon line1.set_points(b, a); line2.set_points(c, a); two_above = true; } if (loc_a == 2 && loc_b == 0 && loc_c == 2) { // Split ab and cb against the polygon line1.set_points(a, b); line2.set_points(c, b); two_above = true; } if (loc_a == 2 && loc_b == 2 && loc_c == 0) { // Split ac and bc against the polygon line1.set_points(a, c); line2.set_points(b, c); two_above = true; } if (loc_a == 2 && loc_b == 0 && loc_c == 0) { // Split ba and ca against the polygon line1.set_points(b, a); line2.set_points(c, a); two_above = false; } if (loc_a == 0 && loc_b == 2 && loc_c == 0) { // Split ab and cb against the polygon line1.set_points(a, b); line2.set_points(c, b); two_above = false; } if (loc_a == 0 && loc_b == 0 && loc_c == 2) { // Split ac and bc against the polygon line1.set_points(a, c); line2.set_points(b, c); two_above = false; } std::vector< std::vector<c_tikz_obj*> > line1_split(3); std::vector< std::vector<c_tikz_obj*> > line2_split(3); line1_split = line1.split(against); line2_split = line2.split(against); int loc; if (two_above) { loc = 2; } else { loc = 0; } c_point point_top(((c_line*)line1_split[loc][0])->ex, ((c_line*)line1_split[loc][0])->ey, ((c_line*)line1_split[loc][0])->ez); c_point point_left(((c_line*)line1_split[loc][0])->sx, ((c_line*)line1_split[loc][0])->sy, ((c_line*)line1_split[loc][0])->sz); c_point point_right(((c_line*)line2_split[loc][0])->sx, ((c_line*)line2_split[loc][0])->sy, ((c_line*)line2_split[loc][0])->sz); c_point bottom_left(((c_line*)line1_split[2-loc][0])->sx, ((c_line*)line1_split[2-loc][0])->sy, ((c_line*)line1_split[2-loc][0])->sz); c_point bottom_right(((c_line*)line2_split[2-loc][0])->sx, ((c_line*)line2_split[2-loc][0])->sy, ((c_line*)line2_split[2-loc][0])->sz); c_polygon * polygon1 = (c_polygon*) this->clone(); c_polygon * polygon2 = (c_polygon*) this->clone(); c_polygon * polygon3 = (c_polygon*) this->clone(); polygon1->a = point_top; polygon1->b = point_left; polygon1->c = point_right; polygon2->a = bottom_left; polygon2->b = point_left; polygon2->c = point_right; polygon3->a = bottom_right; polygon3->b = bottom_left; polygon3->c = point_right; ret[2-loc].push_back(polygon1); ret[loc].push_back(polygon2); ret[loc].push_back(polygon3); return ret; }
void Cylinder::buildGeometry() { vertices_.clear(); colors_.clear(); normals_.clear(); indices_.clear(); unsigned short subdiv = 20; float dtheta = 2 * PI / subdiv; glm::vec4 point_top(0.0f, 0.5f * height_, radius_, 1.0f), point_bottom (0.0f, -0.5f * height_, radius_, 1.0f); vector<glm::vec3> cap_top, cap_bottom; // top and bottom cap vertices for (int i = 0; i < subdiv + 1; ++i) { glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), i * dtheta, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 translate = glm::translate(glm::mat4(1.0f), center_); cap_top.push_back(glm::vec3(translate * rotate * point_top)); cap_bottom.push_back(glm::vec3(translate * rotate * point_bottom)); } //Create top cap. for ( int i = 0; i < subdiv - 2; i++) { vertices_.push_back(cap_top[0]); vertices_.push_back(cap_top[i + 1]); vertices_.push_back(cap_top[i + 2]); } //Create bottom cap. for (int i = 0; i < subdiv - 2; i++) { vertices_.push_back(cap_bottom[0]); vertices_.push_back(cap_bottom[i + 1]); vertices_.push_back(cap_bottom[i + 2]); } //Create barrel for (int i = 0; i < subdiv; i++) { //Right-side up triangle vertices_.push_back(cap_top[i]); vertices_.push_back(cap_bottom[i + 1]); vertices_.push_back(cap_bottom[i]); //Upside-down triangle vertices_.push_back(cap_top[i]); vertices_.push_back(cap_top[i + 1]); vertices_.push_back(cap_bottom[i + 1]); } // create normals glm::vec3 top_centerpoint(0.0f , 0.5f * height_ , 0.0f), bottom_centerpoint(0.0f, -0.5f * height_, 0.0f); glm::vec3 normal(0, 1, 0); // Create top cap. for (int i = 0; i < subdiv - 2; i++) { normals_.push_back(normal); normals_.push_back(normal); normals_.push_back(normal); } // Create bottom cap. for (int i = 0; i < subdiv - 2; i++) { normals_.push_back(-normal); normals_.push_back(-normal); normals_.push_back(-normal); } // Create barrel for (int i = 0; i < subdiv; i++) { //Right-side up triangle normals_.push_back(glm::normalize(cap_top[i] - top_centerpoint)); normals_.push_back(glm::normalize(cap_bottom[i + 1] - bottom_centerpoint)); normals_.push_back(glm::normalize(cap_bottom[i] - bottom_centerpoint)); //Upside-down triangle normals_.push_back(glm::normalize(cap_top[i] - top_centerpoint)); normals_.push_back(glm::normalize(cap_top[i + 1] - top_centerpoint)); normals_.push_back(glm::normalize(cap_bottom[i + 1] - bottom_centerpoint)); } // indices for (unsigned int i = 0; i < vertices_.size(); ++i) { indices_.push_back(i); } }