本文整理汇总了C++中Triangle::HaveVertex方法的典型用法代码示例。如果您正苦于以下问题:C++ Triangle::HaveVertex方法的具体用法?C++ Triangle::HaveVertex怎么用?C++ Triangle::HaveVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Triangle
的用法示例。
在下文中一共展示了Triangle::HaveVertex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Set
//.........这里部分代码省略.........
vertex_split->num_old_triangles_ = (int)(_triangle_list.size() - edge_to_collapse.triangle_list_.size());
vertex_split->num_new_triangles_ = (int)edge_to_collapse.triangle_list_.size();
SetDeltaScalars(vertex_split->delta_scalars_,
edge_to_collapse.v1_->scalars_,
edge_to_collapse.v2_->scalars_);
CopyAddScalars(vertex_split->pivot_scalars_,
edge_to_collapse.v2_->scalars_,
vertex_split->delta_scalars_);
CopyScalars(edge_to_collapse.v2_->scalars_,
vertex_split->pivot_scalars_);
TriangleList::iterator tri_iter;
for (tri_iter = edge_to_collapse.triangle_list_.begin();
tri_iter != edge_to_collapse.triangle_list_.end();
++tri_iter) {
Triangle* triangle = *tri_iter;
_triangle_list.remove(triangle);
vertex_split->new_triangles_.push_back(triangle);
}
// Setup the affected triangles. Affected triangles are those that
// are sharing the vertex that will be removed. We need to change the pointer that
// points at the removed vertex to point to the other vertex instead.
for (tri_iter = _triangle_list.begin();
tri_iter != _triangle_list.end();
++tri_iter) {
Triangle* triangle = *tri_iter;
if (triangle->HaveVertex(edge_to_collapse.v1_) == true) {
vertex_split->fix_triangles_.push_back(triangle);
triangle->ReplaceVertex(edge_to_collapse.v1_, vertex_split->vertex_to_split_);
// If two vertices are the same.
if (triangle->v1_ == triangle->v2_ ||
triangle->v1_ == triangle->v3_ ||
triangle->v2_ == triangle->v3_) {
deb_assert(false);
}
}
}
// Place V2 last in the list, and remove V1 completely.
_vertex_list.remove(edge_to_collapse.v1_);
_vertex_list.remove(edge_to_collapse.v2_);
_vertex_list.push_back(edge_to_collapse.v2_);
} // End while(lVertexCount > 1)
// Now we are all done calculating the vertex splits.
// It's time to generate the final data.
// Start with creating the lowest level mesh data.
base_vertex_count_ = (int)_vertex_list.size();
base_triangle_count_ = (int)_triangle_list.size();
num_vertex_splits_ = (int)vertex_split_list.size();
current_vertex_count_ = base_vertex_count_;
current_triangle_count_ = base_triangle_count_;
base_vertex_data_ = new float[base_vertex_count_ * 3];
base_normal_data_ = new float[base_vertex_count_ * 3];
示例2: FindEdgeToCollapse
//.........这里部分代码省略.........
Vertex mid;
// Test V1 and V2.
mid.x() = (triangle->v1_->x() + triangle->v2_->x()) * 0.5f;
mid.y() = (triangle->v1_->y() + triangle->v2_->y()) * 0.5f;
mid.z() = (triangle->v1_->z() + triangle->v2_->z()) * 0.5f;
// Calculate the distance between the new, merged position,
// and the original vertex position.
diff1.Set(mid.x() - triangle->v1_->twin_->x(),
mid.y() - triangle->v1_->twin_->y(),
mid.z() - triangle->v1_->twin_->z());
diff2.Set(mid.x() - triangle->v2_->twin_->x(),
mid.y() - triangle->v2_->twin_->y(),
mid.z() - triangle->v2_->twin_->z());
float error1 = diff1.GetLength() + triangle->v1_->error_;
float error2 = diff2.GetLength() + triangle->v2_->error_;
float error = (error1 + error2 + current_error) / 3.0f;
if (first == true || error < min_error) {
edge.v1_ = triangle->v1_;
edge.v2_ = triangle->v2_;
min_error1 = error1;
min_error2 = error2;
min_error = error;
first = false;
}
// Test V2 and V3.
mid.x() = (triangle->v2_->x() + triangle->v3_->x()) * 0.5f;
mid.y() = (triangle->v2_->y() + triangle->v3_->y()) * 0.5f;
mid.z() = (triangle->v2_->z() + triangle->v3_->z()) * 0.5f;
// Calculate the distance between the new, merged position,
// and the original vertex position.
diff1.Set(mid.x() - triangle->v2_->twin_->x(),
mid.y() - triangle->v2_->twin_->y(),
mid.z() - triangle->v2_->twin_->z());
diff2.Set(mid.x() - triangle->v3_->twin_->x(),
mid.y() - triangle->v3_->twin_->y(),
mid.z() - triangle->v3_->twin_->z());
error1 = diff1.GetLength() + triangle->v1_->error_;
error2 = diff2.GetLength() + triangle->v2_->error_;
error = (error1 + error2 + current_error) / 3.0f;
if (error < min_error) {
edge.v1_ = triangle->v1_;
edge.v2_ = triangle->v2_;
min_error = error;
min_error1 = error1;
min_error2 = error2;
}
// Test V3 and V1.
mid.x() = (triangle->v3_->x() + triangle->v1_->x()) * 0.5f;
mid.y() = (triangle->v3_->y() + triangle->v1_->y()) * 0.5f;
mid.z() = (triangle->v3_->z() + triangle->v1_->z()) * 0.5f;
// Calculate the distance between the new, merged position,
// and the original vertex position.
diff1.Set(mid.x() - triangle->v3_->twin_->x(),
mid.y() - triangle->v3_->twin_->y(),
mid.z() - triangle->v3_->twin_->z());
diff2.Set(mid.x() - triangle->v1_->twin_->x(),
mid.y() - triangle->v1_->twin_->y(),
mid.z() - triangle->v1_->twin_->z());
error1 = diff1.GetLength() + triangle->v1_->error_;
error2 = diff2.GetLength() + triangle->v2_->error_;
error = (error1 + error2 + current_error) / 3.0f;
if (error < min_error) {
edge.v1_ = triangle->v1_;
edge.v2_ = triangle->v2_;
min_error = error;
min_error1 = error1;
min_error2 = error2;
}
if (min_error == 0.0f && edge.v1_ != 0 && edge.v2_ != 0)
break;
}
edge.v1_->error_ = min_error1;
edge.v2_->error_ = min_error2;
// Now add all triangles to _edge that share the two vertices
// _edge->v1_ and _edge->v2_.
for (tri_iter = triangle_list.begin();
tri_iter != triangle_list.end();
++tri_iter) {
Triangle* triangle = *tri_iter;
if (triangle->HaveVertex(edge.v1_) &&
triangle->HaveVertex(edge.v2_)) {
edge.triangle_list_.push_back(triangle);
}
}
}