mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-17 20:23:47 -04:00
better support for small collision polygons
This commit is contained in:
parent
916fea794f
commit
2210ebe3df
@ -97,7 +97,7 @@ verify_points(const LPoint3f *begin, const LPoint3f *end) {
|
|||||||
// Make sure no points are repeated.
|
// Make sure no points are repeated.
|
||||||
const LPoint3f *pj;
|
const LPoint3f *pj;
|
||||||
for (pj = begin; pj != pi && all_ok; ++pj) {
|
for (pj = begin; pj != pi && all_ok; ++pj) {
|
||||||
if ((*pj).almost_equal(*pi)) {
|
if ((*pj) == (*pi)) {
|
||||||
all_ok = false;
|
all_ok = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1198,7 +1198,7 @@ setup_points(const LPoint3f *begin, const LPoint3f *end) {
|
|||||||
normal[2] += p0[0] * p1[1] - p0[1] * p1[0];
|
normal[2] += p0[0] * p1[1] - p0[1] * p1[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_NEARLY_ZERO(normal.length_squared())) {
|
if (normal.length_squared() == 0.0f) {
|
||||||
// The polygon has no area.
|
// The polygon has no area.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1302,7 +1302,7 @@ compare_collider_to_geom(CollisionEntry &entry, const Geom *geom,
|
|||||||
nassertv(ci != _colliders.end());
|
nassertv(ci != _colliders.end());
|
||||||
|
|
||||||
if (geom->get_primitive_type() == Geom::PT_polygons) {
|
if (geom->get_primitive_type() == Geom::PT_polygons) {
|
||||||
const GeomVertexData *data =geom->get_vertex_data();
|
const GeomVertexData *data = geom->get_vertex_data();
|
||||||
GeomVertexReader vertex(data, InternalName::get_vertex());
|
GeomVertexReader vertex(data, InternalName::get_vertex());
|
||||||
|
|
||||||
int num_primitives = geom->get_num_primitives();
|
int num_primitives = geom->get_num_primitives();
|
||||||
@ -1311,33 +1311,66 @@ compare_collider_to_geom(CollisionEntry &entry, const Geom *geom,
|
|||||||
CPT(GeomPrimitive) tris = primitive->decompose();
|
CPT(GeomPrimitive) tris = primitive->decompose();
|
||||||
nassertv(tris->is_of_type(GeomTriangles::get_class_type()));
|
nassertv(tris->is_of_type(GeomTriangles::get_class_type()));
|
||||||
|
|
||||||
GeomVertexReader index(tris->get_vertices(), 0);
|
if (tris->is_indexed()) {
|
||||||
while (!index.is_at_end()) {
|
// Indexed case.
|
||||||
Vertexf v[3];
|
GeomVertexReader index(tris->get_vertices(), 0);
|
||||||
|
while (!index.is_at_end()) {
|
||||||
vertex.set_row(index.get_data1i());
|
Vertexf v[3];
|
||||||
v[0] = vertex.get_data3f();
|
|
||||||
vertex.set_row(index.get_data1i());
|
vertex.set_row(index.get_data1i());
|
||||||
v[1] = vertex.get_data3f();
|
v[0] = vertex.get_data3f();
|
||||||
vertex.set_row(index.get_data1i());
|
vertex.set_row(index.get_data1i());
|
||||||
v[2] = vertex.get_data3f();
|
v[1] = vertex.get_data3f();
|
||||||
|
vertex.set_row(index.get_data1i());
|
||||||
// Generate a temporary CollisionGeom on the fly for each
|
v[2] = vertex.get_data3f();
|
||||||
// triangle in the Geom.
|
|
||||||
if (CollisionPolygon::verify_points(v[0], v[1], v[2])) {
|
// Generate a temporary CollisionGeom on the fly for each
|
||||||
bool within_solid_bounds = true;
|
// triangle in the Geom.
|
||||||
if (from_node_gbv != (GeometricBoundingVolume *)NULL) {
|
if (CollisionPolygon::verify_points(v[0], v[1], v[2])) {
|
||||||
PT(BoundingSphere) sphere = new BoundingSphere;
|
bool within_solid_bounds = true;
|
||||||
sphere->around(v, v + 3);
|
if (from_node_gbv != (GeometricBoundingVolume *)NULL) {
|
||||||
within_solid_bounds = (sphere->contains(from_node_gbv) != 0);
|
PT(BoundingSphere) sphere = new BoundingSphere;
|
||||||
#ifdef DO_PSTATS
|
sphere->around(v, v + 3);
|
||||||
CollisionGeom::_volume_pcollector.add_level(1);
|
within_solid_bounds = (sphere->contains(from_node_gbv) != 0);
|
||||||
#endif // DO_PSTATS
|
#ifdef DO_PSTATS
|
||||||
|
CollisionGeom::_volume_pcollector.add_level(1);
|
||||||
|
#endif // DO_PSTATS
|
||||||
|
}
|
||||||
|
if (within_solid_bounds) {
|
||||||
|
PT(CollisionGeom) cgeom = new CollisionGeom(v[0], v[1], v[2]);
|
||||||
|
entry._into = cgeom;
|
||||||
|
entry.test_intersection((*ci).second, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (within_solid_bounds) {
|
}
|
||||||
PT(CollisionGeom) cgeom = new CollisionGeom(v[0], v[1], v[2]);
|
} else {
|
||||||
entry._into = cgeom;
|
// Non-indexed case.
|
||||||
entry.test_intersection((*ci).second, this);
|
vertex.set_row(primitive->get_first_vertex());
|
||||||
|
int num_vertices = primitive->get_num_vertices();
|
||||||
|
for (int i = 0; i < num_vertices; i += 3) {
|
||||||
|
Vertexf v[3];
|
||||||
|
|
||||||
|
v[0] = vertex.get_data3f();
|
||||||
|
v[1] = vertex.get_data3f();
|
||||||
|
v[2] = vertex.get_data3f();
|
||||||
|
|
||||||
|
// Generate a temporary CollisionGeom on the fly for each
|
||||||
|
// triangle in the Geom.
|
||||||
|
if (CollisionPolygon::verify_points(v[0], v[1], v[2])) {
|
||||||
|
bool within_solid_bounds = true;
|
||||||
|
if (from_node_gbv != (GeometricBoundingVolume *)NULL) {
|
||||||
|
PT(BoundingSphere) sphere = new BoundingSphere;
|
||||||
|
sphere->around(v, v + 3);
|
||||||
|
within_solid_bounds = (sphere->contains(from_node_gbv) != 0);
|
||||||
|
#ifdef DO_PSTATS
|
||||||
|
CollisionGeom::_volume_pcollector.add_level(1);
|
||||||
|
#endif // DO_PSTATS
|
||||||
|
}
|
||||||
|
if (within_solid_bounds) {
|
||||||
|
PT(CollisionGeom) cgeom = new CollisionGeom(v[0], v[1], v[2]);
|
||||||
|
entry._into = cgeom;
|
||||||
|
entry.test_intersection((*ci).second, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user