added OrientedCylinder to primitive creating functions
This commit is contained in:
parent
604bc3903f
commit
1c20f47552
|
|
@ -847,8 +847,28 @@ void OrientedDisk(MeshType &m, int slices, Point3f center, Point3f norm, float r
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MeshType>
|
template <class MeshType>
|
||||||
void Cylinder(int slices, int stacks, MeshType & m){
|
void OrientedCylinder(MeshType & m, const Point3f origin, const Point3f end, float radius, int slices=32, int stacks=4 )
|
||||||
|
{
|
||||||
|
Cylinder(slices,stacks,m);
|
||||||
|
tri::UpdatePosition<MeshType>::Translate(m,Point3f(0,1,0));
|
||||||
|
tri::UpdatePosition<MeshType>::Scale(m,Point3f(1,0.5f,1));
|
||||||
|
|
||||||
|
Matrix44f scale;
|
||||||
|
float height = Distance(origin,end);
|
||||||
|
tri::UpdatePosition<MeshType>::Scale(m,Point3f(radius,height,radius));
|
||||||
|
Point3f norm = end-origin;
|
||||||
|
float angleRad = Angle(Point3f(0,1,0),norm);
|
||||||
|
Point3f axis = Point3f(0,1,0)^norm;
|
||||||
|
Matrix44f rotM;
|
||||||
|
rotM.SetRotateRad(angleRad,axis);
|
||||||
|
tri::UpdatePosition<MeshType>::Matrix(m,rotM);
|
||||||
|
tri::UpdatePosition<MeshType>::Translate(m,origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class MeshType>
|
||||||
|
void Cylinder(int slices, int stacks, MeshType & m)
|
||||||
|
{
|
||||||
|
m.Clear();
|
||||||
typename MeshType::VertexIterator vi = vcg::tri::Allocator<MeshType>::AddVertices(m,slices*(stacks+1));
|
typename MeshType::VertexIterator vi = vcg::tri::Allocator<MeshType>::AddVertices(m,slices*(stacks+1));
|
||||||
for ( int i = 0; i < stacks+1; ++i)
|
for ( int i = 0; i < stacks+1; ++i)
|
||||||
for ( int j = 0; j < slices; ++j)
|
for ( int j = 0; j < slices; ++j)
|
||||||
|
|
@ -901,8 +921,6 @@ void Cylinder(int slices, int stacks, MeshType & m){
|
||||||
(*fi).SetF(2);
|
(*fi).SetF(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MeshType>
|
template <class MeshType>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue