39 |
|
|
40 |
#include <vob/glerr.hxx> |
#include <vob/glerr.hxx> |
41 |
|
|
|
#include <vob/geom/Fillets.hxx> |
|
42 |
#include <vob/geom/Fillets2.hxx> |
#include <vob/geom/Fillets2.hxx> |
43 |
|
|
44 |
|
#include <vob/poly/Dicer.hxx> |
45 |
|
|
46 |
#ifndef VOB_DEFINED |
#ifndef VOB_DEFINED |
47 |
#define VOB_DEFINED(t) |
#define VOB_DEFINED(t) |
48 |
#endif |
#endif |
750 |
int N; |
int N; |
751 |
float r; |
float r; |
752 |
|
|
753 |
|
int append(ZVec v, bool b = false) { |
754 |
|
int ind = size(); |
755 |
|
if (b) |
756 |
|
push_back(Vert(v, b)); |
757 |
|
else |
758 |
|
push_back(f.blend(conns, N, r, v)); |
759 |
|
|
760 |
|
return ind; |
761 |
|
} |
762 |
|
|
763 |
int operator() (int i, int j, float fract = .5) { |
int operator() (int i, int j, float fract = .5) { |
764 |
int ind = size(); |
int ind = size(); |
765 |
push_back(f.blend(conns, N, r, |
push_back(f.blend(conns, N, r, |
792 |
}; |
}; |
793 |
|
|
794 |
|
|
795 |
|
void addSpan(std::vector<int> &poly, Verts &verts, int i0, int i1, ZVec d0, ZVec d1) const { |
796 |
|
int i, k0 = i0, k1 = i0; |
797 |
|
float d0min = 1E20; |
798 |
|
float d1min = 1E20; |
799 |
|
for (i = i0; i < i1; i++) { |
800 |
|
float dist0 = (verts[i] - d0).length(); |
801 |
|
float dist1 = (verts[i] - d1).length(); |
802 |
|
if (dist0 < d0min) d0min = dist0, k0 = i; |
803 |
|
if (dist1 < d1min) d1min = dist1, k1 = i; |
804 |
|
} |
805 |
|
|
806 |
|
i = k0; |
807 |
|
do { |
808 |
|
poly.push_back(i); |
809 |
|
if (++i == i1) i = i0; |
810 |
|
} while (i != k1); |
811 |
|
|
812 |
|
} |
813 |
|
|
814 |
void render(const Transform **t, int n) const { |
void render(const Transform **t, int n) const { |
815 |
const Transform &thick_t = *t[0]; |
const Transform &thick_t = *t[0]; |
884 |
} |
} |
885 |
|
|
886 |
|
|
887 |
|
// Add the vertices of the diced midsections of the connectors |
888 |
|
Verts verts(*this, conns, N, r); |
889 |
|
for (i = 0; i < N; i++) { |
890 |
|
float t = 0.5 * conns[i]->c.t; |
891 |
|
float d = conns[i]->c.d; |
892 |
|
|
893 |
|
ZVec e0 = conns[i]->dir; |
894 |
|
ZVec e1 = e0.crossp(ZVec(0,0,1)); |
895 |
|
ZVec e2 = e0.crossp(e1); |
896 |
|
|
897 |
|
ZVec p0 = d * e0; |
898 |
|
|
899 |
|
for (j = 0; j < ndice; j++) { |
900 |
|
float a = j * M_PI * 2 / ndice; |
901 |
|
verts.append(p0 + t * (e1 * cos(a) + e2 * sin(a)), true); |
902 |
|
} |
903 |
|
} |
904 |
|
|
905 |
|
// Add the dummy connector vertices |
906 |
|
int dummy_i0 = verts.size(); |
907 |
|
for (i = N; i < (int)dirs.size(); i++) { |
908 |
|
verts.append(dirs[i]); |
909 |
|
} |
910 |
|
|
911 |
|
// Triangulate the surface |
912 |
|
::Vob::Dicer::Triangles<Verts> triangler(verts); |
913 |
|
for (i = 0; i < (int)tri.size(); i++) { |
914 |
|
std::vector<int> poly; |
915 |
|
for (j = 0; j < 3; j++) { |
916 |
|
int k = tri[i][j]; |
917 |
|
if (k >= N) { |
918 |
|
poly.push_back(dummy_i0 + k - N); |
919 |
|
} else { |
920 |
|
int k0 = tri[i][(j+1)%3]; |
921 |
|
int k1 = tri[i][(j+2)%3]; |
922 |
|
if ((dirs[k0] - dirs[k]).crossp(dirs[k1] - dirs[k]).dot(dirs[k]) < 0) |
923 |
|
k0 ^= k1 ^= k0 ^= k1; // Swap |
924 |
|
|
925 |
|
addSpan(poly, verts, ndice * k, ndice * (k + 1), dirs[k0], dirs[k1]); |
926 |
|
} |
927 |
|
} |
928 |
|
|
929 |
|
// Triangulate as a star polygon |
930 |
|
ZVec sum(0,0,0); |
931 |
|
for (j = 0; j < (int)poly.size(); j++) |
932 |
|
sum += verts[poly[j]]; |
933 |
|
|
934 |
|
int nvert = verts.append(sum); |
935 |
|
for (j = 0; j < (int)poly.size(); j++) |
936 |
|
triangler.add(nvert, poly[j], poly[(j+1) % poly.size()]); |
937 |
|
} |
938 |
|
|
939 |
|
|
940 |
|
|
941 |
ZVec pt[ndice + 1][ndice*2]; |
ZVec pt[ndice + 1][ndice*2]; |
942 |
ZVec norm[ndice + 1][ndice*2]; |
ZVec norm[ndice + 1][ndice*2]; |
943 |
|
|