Beispiel #1
0
	ISimpleMesh* CMeshManager::createSphereMesh(
		const std::string& name,
		f32 radius,
		u32 sliceCount,
		u32 stackCount,
		E_MEMORY_USAGE usage)
	{
		if (sliceCount == 0)
		{
			GF_PRINT_CONSOLE_INFO("The sliceCount of a sphere mesh can't be 0.\n");
			return nullptr;
		}

		if (stackCount == 0)
		{
			GF_PRINT_CONSOLE_INFO("The stackCount of a sphere mesh can't be 0.\n");
			return nullptr;
		}

		SGeometryData geoData;
		mGeometryCreator->createSphereData(radius, sliceCount, stackCount, geoData);

		u32 vertexFormat = EVF_POSITION | EVF_NORMAL | EVF_TANGENT | EVF_TEXCOORD0;

		ISimpleMesh* mesh = createSimpleMesh(name, vertexFormat,
			&geoData.Vertices[0], &geoData.Indices[0],
			geoData.Vertices.size(), mGeometryCreator->getVertexStride(), geoData.Indices.size(),
			geoData.Aabb, false, usage);

		return mesh;
	}
Beispiel #2
0
	ISimpleMesh* CMeshManager::createPlaneMesh(
		const std::string& name,
		f32 width,
		f32 depth,
		u32 xsegments,
		u32 ysegments,
		f32 uTiles,
		f32 vTiles,
		E_MEMORY_USAGE usage)
	{

		if (xsegments == 0 || ysegments == 0)
		{
			GF_PRINT_CONSOLE_INFO("The segments of a plane mesh can't be 0.\n");
			return nullptr;
		}

		SGeometryData geoData;
		mGeometryCreator->createPlaneData(width, depth, xsegments, ysegments, uTiles, vTiles, geoData);

		u32 vertexFormat = EVF_POSITION | EVF_NORMAL | EVF_TANGENT | EVF_TEXCOORD0;

		ISimpleMesh* mesh = createSimpleMesh(name, vertexFormat,
			&geoData.Vertices[0], &geoData.Indices[0],
			geoData.Vertices.size(), mGeometryCreator->getVertexStride(), geoData.Indices.size(),
			geoData.Aabb, false, usage);

		return mesh;
	}
Beispiel #3
0
	ISimpleMesh* CMeshManager::createQuad(const std::string& name, E_MEMORY_USAGE usage)
	{
		XMFLOAT3 vertices[6];
		math::SAxisAlignedBox aabb;
		mGeometryCreator->createQuadData(vertices, aabb);

		ISimpleMesh* mesh = createSimpleMesh(name, EVF_POSITION,
			vertices, nullptr, 6, sizeof(XMFLOAT3), 0, aabb, false, usage);
		return mesh;
	}
Beispiel #4
0
	ISimpleMesh* CMeshManager::createCubeMesh(
		const std::string& name,
		f32 width,
		f32 height,
		f32 depth,
		E_MEMORY_USAGE usage)
	{
		SGeometryData geoData;
		mGeometryCreator->createCubeData(width, height, depth, geoData);

		u32 vertexFormat = EVF_POSITION | EVF_NORMAL | EVF_TANGENT | EVF_TEXCOORD0;

		ISimpleMesh* mesh = createSimpleMesh(name, vertexFormat,
			&geoData.Vertices[0], &geoData.Indices[0],
			geoData.Vertices.size(), mGeometryCreator->getVertexStride(), geoData.Indices.size(),
			geoData.Aabb, false, usage);
		return mesh;
	}
Beispiel #5
0
	ISimpleMesh* CMeshManager::createCylinderMesh(
		const std::string& name,
		f32 bottomRadius,
		f32 topRadius,
		f32 height,
		u32 sliceCount,
		u32 stackCount,
		E_MEMORY_USAGE usage)
	{
		SGeometryData geoData;
		mGeometryCreator->createCylinderData(bottomRadius, topRadius, height,
			sliceCount, stackCount, geoData);

		u32 vertexFormat = EVF_POSITION | EVF_NORMAL | EVF_TANGENT | EVF_TEXCOORD0;
		ISimpleMesh* mesh = createSimpleMesh(name, vertexFormat,
			&geoData.Vertices[0], &geoData.Indices[0],
			geoData.Vertices.size(), mGeometryCreator->getVertexStride(), geoData.Indices.size(),
			geoData.Aabb, false, usage);

		return mesh;
	}
Beispiel #6
0
    void WorldTest::testRigidAndDeformableProxies() {
        // create and add both, rigid and deformable proxies to the world and
        // make sure collision detection knows about all of them
        //
        // they are all colliding with each other, so we get n^2 pairs.
        // simply checking the broadphase results is sufficient, since we only
        // want to know if the World object knows about all proxies, not whether
        // the collision detection algorithms work correctly (that's the job of
        // other tests)

        std::list<Proxy*> proxies;
        World world(Vector3(1024.0, 1024.0, 1024.0));

        // simple rigid proxies
        proxies.push_back(world.createProxy(new Box(100.0, 100.0, 100.0)));
        proxies.push_back(world.createProxy(new Sphere(100.0)));
#if USE_CYLINDER_WEDGE_CONE
        proxies.push_back(world.createProxy(new Cone(100.0, 100.0)));
        proxies.push_back(world.createProxy(new Wedge(100.0, 100.0, 100.0)));
        proxies.push_back(world.createProxy(new Cylinder(100.0, 100.0)));
#endif

        // simple rigid && fixed proxies
        proxies.push_back(world.createProxy(new Box(100.0, 100.0, 100.0), PROXYTYPE_FIXED));
        proxies.push_back(world.createProxy(new Sphere(100.0), PROXYTYPE_FIXED));
#if USE_CYLINDER_WEDGE_CONE
        proxies.push_back(world.createProxy(new Cone(100.0, 100.0), PROXYTYPE_FIXED));
        proxies.push_back(world.createProxy(new Wedge(100.0, 100.0, 100.0), PROXYTYPE_FIXED));
        proxies.push_back(world.createProxy(new Cylinder(100.0, 100.0), PROXYTYPE_FIXED));
#endif

        // simple rigid && self collidable proxies
        // this is actually nonsense, as there is a single shape in the proxy
        // only, i.e. no self collision possible.
        // however for a test whether this proxy type still is collided with
        // other objects properly this is sufficient.
        proxies.push_back(world.createProxy(new Box(100.0, 100.0, 100.0), (ProxyTypes) (PROXYTYPE_RIGID | PROXYTYPE_SELFCOLLIDABLE)));
        proxies.push_back(world.createProxy(new Sphere(100.0), (ProxyTypes) (PROXYTYPE_RIGID | PROXYTYPE_SELFCOLLIDABLE)));
#if USE_CYLINDER_WEDGE_CONE
        proxies.push_back(world.createProxy(new Cone(100.0, 100.0), (ProxyTypes) (PROXYTYPE_RIGID | PROXYTYPE_SELFCOLLIDABLE)));
        proxies.push_back(world.createProxy(new Wedge(100.0, 100.0, 100.0), (ProxyTypes) (PROXYTYPE_RIGID | PROXYTYPE_SELFCOLLIDABLE)));
        proxies.push_back(world.createProxy(new Cylinder(100.0, 100.0), (ProxyTypes) (PROXYTYPE_RIGID | PROXYTYPE_SELFCOLLIDABLE)));
#endif

        // meshes, rigid and deformable.
        proxies.push_back(world.createProxy(createSimpleMesh(), PROXYTYPE_RIGID));
        proxies.push_back(world.createProxy(createSimpleMesh(), (ProxyTypes) (PROXYTYPE_RIGID | PROXYTYPE_SELFCOLLIDABLE)));
        proxies.push_back(world.createProxy(createSimpleMesh(), PROXYTYPE_FIXED));

        proxies.push_back(world.createProxy(createSimpleMesh(), PROXYTYPE_DEFORMABLE));
        proxies.push_back(world.createProxy(createSimpleMesh(), (ProxyTypes) (PROXYTYPE_DEFORMABLE | PROXYTYPE_SELFCOLLIDABLE)));

        for (std::list<Proxy*>::iterator it = proxies.begin(); it != proxies.end(); ++it) {
            world.addProxy(*it);
        }

        world.prepareSimulation();

        WorldCollisions collisions = world.calculateAllCollisions(World::COLLISIONFLAG_SKIP_MIDDLE_PHASE);
        const BroadPhaseCollisions* broad = collisions.getBroadPhaseCollisions();
        for (std::list<Proxy*>::iterator it1 = proxies.begin(); it1 != proxies.end(); ++it1) {
            std::list<Proxy*>::iterator it2 = it1;
            ++it2;
            for (; it2 != proxies.end(); ++it2) {
                if (((*it1)->getProxyType() & PROXYTYPE_FIXED) &&
                    ((*it2)->getProxyType() & PROXYTYPE_FIXED)) {
                    // 2 fixed proxies dont collide with each other
                    // (at least they dont have to - World is allowed to return
                    // them anyway)
                    continue;
                }
                CollisionPair pair;
                CPPUNIT_ASSERT((*it1)->getBvHierarchyNode() != 0);
                CPPUNIT_ASSERT((*it1)->getBvHierarchyNode()->getBoundingVolume() != 0);
                CPPUNIT_ASSERT((*it2)->getBvHierarchyNode() != 0);
                CPPUNIT_ASSERT((*it2)->getBvHierarchyNode()->getBoundingVolume() != 0);
                pair.bvol1 = (*it1)->getBvHierarchyNode()->getBoundingVolume();
                pair.bvol2 = (*it2)->getBvHierarchyNode()->getBoundingVolume();

                CPPUNIT_ASSERT(std::count(broad->getResults().begin(), broad->getResults().end(), pair));
            }
        }
    }