Zobrazit předchozí téma :: Zobrazit následující téma |
Autor |
Zpráva |
Játro.m
Založen: 01. 02. 2010 Příspěvky: 230
|
Zaslal: 29. březen 2010, 06:38:00 Předmět: |
|
|
quas4: mozna to sem hod, nikdy nevis kdy se to muze ostatnim hodit.
if.then: pocitam to z minim a maxim objektu - minima, maxima maji pridany 5.0f na jejich velikosti - to je proc se vam ty koule pripadaj tak velky a neco prida ten vypocet polomeru. |
|
Návrat nahoru |
|
 |
quas4
Založen: 18. 10. 2007 Příspěvky: 199
|
Zaslal: 29. březen 2010, 08:59:38 Předmět: |
|
|
kód: |
static void sphere_of_sphere_and_pt(Sphere& s, const Vec3& p)
{
Vec3 d = p - s.center;
double dist2 = d.dot(d);
if (dist2 > s.radius * s.radius) {
double dist = sqrt(dist2);
double new_radius = (s.radius + dist) * 0.5;
double k = (new_radius - s.radius) / dist;
s.radius = new_radius;
s.center += d * k;
}
}
static void most_separated_points_on_aabb(int& min, int& max, const Array<Vec3>& pt)
{
int minx = 0, maxx = 0, miny = 0, maxy = 0, minz = 0, maxz = 0;
for (int i = 1; i < pt.size(); i++) {
if (pt[i].x < pt[minx].x) minx = i;
if (pt[i].x > pt[maxx].x) maxx = i;
if (pt[i].y < pt[miny].y) miny = i;
if (pt[i].y < pt[maxy].y) maxy = i;
if (pt[i].z < pt[minz].z) minz = i;
if (pt[i].z < pt[maxz].z) maxz = i;
double dist2x = (pt[maxx] - pt[minx]).dot(pt[maxx] - pt[minx]);
double dist2y = (pt[maxy] - pt[miny]).dot(pt[maxy] - pt[miny]);
double dist2z = (pt[maxz] - pt[minz]).dot(pt[maxz] - pt[minz]);
min = minx;
max = maxx;
if (dist2y > dist2x && dist2y > dist2z) {
max = maxy;
min = miny;
}
if (dist2z > dist2x && dist2z > dist2y) {
max = maxz;
min = minz;
}
}
}
static Sphere sphere_from_distant_points(const Array<Vec3>& pt)
{
int min = 0, max = 0;
most_separated_points_on_aabb(min, max, pt);
Vec3 c = (pt[min] + pt[max]) * 0.5;
double r = sqrt((pt[max] - c).dot(pt[max] - c));
return Sphere(c, r);
}
Sphere sphere_construct(const Array<Vec3>& pt) // a tuhle vystavit do headeru
{
Sphere s = sphere_from_distant_points(pt);
for (int i = 0; i < pt.size(); i++)
sphere_of_sphere_and_pt(s, pt[i]);
return s;
}
|
Jde o Ritteruv algoritmus. Jeste lepsi vysledky ma http://www.inf.ethz.ch/personal/gaertner/miniball.html ale uz to neni tak pekne rychle. |
|
Návrat nahoru |
|
 |
|
|
Nemůžete odesílat nové téma do tohoto fóra Nemůžete odpovídat na témata v tomto fóru Nemůžete upravovat své příspěvky v tomto fóru Nemůžete mazat své příspěvky v tomto fóru Nemůžete hlasovat v tomto fóru
|
Powered by phpBB © 2001, 2005 phpBB Group
Vzhled udelal powermac
Styl "vykraden" z phpBB stylu MonkiDream - upraveno by rezna