static hkpMoppBvTreeShape* createMoppShape()
{
	const int side = 5;

	//
	//	We use a storage mesh in our example, which copies all data.
	//  If you want to share graphics and physics, use the hkpMeshShape instead
	//
	hkpSimpleMeshShape* meshShape = new hkpSimpleMeshShape( 0.05f );

	createMeshShape( side, meshShape );

	hkpMoppCompilerInput mci;
	mci.m_enableChunkSubdivision = true;
	hkpMoppCode* code = hkpMoppUtility::buildCode( meshShape ,mci);

	hkpMoppBvTreeShape* moppShape = new hkpMoppBvTreeShape(meshShape, code);
	code->removeReference();
	meshShape->removeReference();

	return moppShape;
}
Esempio n. 2
0
		void						phyMgr::parseUserText(const wcs& node_name, const SPtr<z3D::SG::SNode>& node, const wcs& user_text)
		{
			Config* cfg = Config::fromWCS(user_text);
			if(cfg->exists(L"collision_shape"))
			{
				wcs shape_name = cfg->getWString(L"collision_shape");
				REAL mass = cfg->getFloat(L"mass");
				int32_t compound = cfg->getInt32(L"compound");

				if(shape_name == L"box")
				{
					if(compound)
					{
						SPtr<phyShape> shape = createCompoundWrappedBoxShape(node->local_bound().extent(), node->local_bound().center());
						SPtr<phyBody> body = createBody(node, shape, Mat4::identity, mass, false);
						addBody(body);

						node->setPhyBody(body);
					}
					else
					{
						SPtr<phyShape> shape = createBoxShape(node->local_bound().extent());
						SPtr<phyBody> body = createBody(node, shape, Mat4::translation(Vec3(node->local_bound().center())), mass, false);
						addBody(body);

						node->setPhyBody(body);
					}
				}
				else if(shape_name == L"sphere")
				{
					Vec3 ext = node->local_bound().extent();
					SPtr<phyShape> shape = createSphereShape((ext[0] + ext[1] + ext[2]) / 3);
					SPtr<phyBody> body = createBody(node, shape, Mat4::translation(Vec3(node->local_bound().center())), mass, false);
					addBody(body);

					node->setPhyBody(body);
				}
				else if(shape_name == L"mesh")
				{
					if(node->type_info()->kind_of(z3D::SG::SMeshNode::type_info_static()))
					{
						SPtr<phyShape> shape = createMeshShape(node.cast<z3D::SG::SMeshNode>()->mesh());
						SPtr<phyBody> body = createBody(node, shape, Mat4::identity, mass, true);
						addBody(body);

						node->setPhyBody(body);
					}
				}
				else if(shape_name == L"convex_hull")
				{
					if(node->type_info()->kind_of(z3D::SG::SMeshNode::type_info_static()))
					{
						Vec3 offset;
						REAL computed_mass;
						Mat3 inertia_tensor;
						SPtr<phyShape> shape = createConvexHullShape(node.cast<z3D::SG::SMeshNode>()->mesh(), offset, computed_mass, inertia_tensor);
						SPtr<phyBody> body = createBody(node, shape, Mat4::translation(offset), mass, mass / computed_mass * Vec3(inertia_tensor[0][0], inertia_tensor[1][1], inertia_tensor[2][2]));

						addBody(body);

						node->setPhyBody(body);
					}
				}
				else if(shape_name == L"convex_decomp")
				{
					if(node->type_info()->kind_of(z3D::SG::SMeshNode::type_info_static()))
					{
						Vec3 offset;
						REAL computed_mass;
						Mat3 inertia_tensor;
						SPtr<phyShape> shape = createDecompConvexHullShape(node.cast<z3D::SG::SMeshNode>()->mesh(), offset, computed_mass, inertia_tensor);
						SPtr<phyBody> body = createBody(node, shape, Mat4::translation(offset), mass, mass / computed_mass * Vec3(inertia_tensor[0][0], inertia_tensor[1][1], inertia_tensor[2][2]));

						addBody(body);

						node->setPhyBody(body);
					}
				}
			}
			delete cfg;
		}
Esempio n. 3
0
hkpMoppBvTreeShape* TowerLand::createMoppShape()
{
	hkpExtendedMeshShape* meshShape = createMeshShape();

	return createMoppShape(meshShape);
}
Esempio n. 4
0
ChunkMoppDemo::ChunkMoppDemo(hkDemoEnvironment* env)
	:	hkDefaultPhysicsDemo(env)
{
	//setGraphicsState(HKG_ENABLED_WIREFRAME, true);	
	//
	// Setup the camera
	//
	{
		hkVector4 from(55.0f, 50.0f, 55.0f);
		hkVector4 to  ( 0.0f,  0.0f,   0.0f);
		hkVector4 up  ( 0.0f,  1.0f,   0.0f);
		setupDefaultCameras(env, from, to, up, 0.1f, 20000.0f);
	}

	//
	// Create the world
	//
	{
		hkpWorldCinfo worldInfo;
		{
			worldInfo.m_gravity.set(0.0f, -9.81f, 0.0f);
			worldInfo.setBroadPhaseWorldSize(10000.0f);
			worldInfo.setupSolverInfo( hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM );
			worldInfo.m_enableDeactivation = false;
		}
		m_world = new hkpWorld(worldInfo);
		m_world->lock();

		// Register ALL agents (though some may not be necessary)
		hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher());

		setupGraphics();
	}

	hkpShapeCollection* meshShape = createMeshShape( VERTS_PER_SIDE, m_delayedCleanup );
	m_shape = createMoppShape( meshShape, true );
	m_shape->getAabb( hkTransform::getIdentity(), 0.1f, m_bounds );

	//
	//  create the ground mopp
	//
	{

		hkpRigidBodyCinfo terrainInfo;
		{
			hkVector4 size(100.0f, 1.0f, 100.0f);

			terrainInfo.m_shape = m_shape;
			terrainInfo.m_motionType = hkpMotion::MOTION_FIXED;
			terrainInfo.m_friction = 0.5f;

			hkpRigidBody* terrainBody = new hkpRigidBody(terrainInfo);
			m_world->addEntity(terrainBody);
			terrainBody->removeReference();	
		}
		terrainInfo.m_shape->removeReference();
	}

	hkVector4 halfExtents;
	hkVector4 centre;
	{
		m_bounds.getHalfExtents( halfExtents );
		m_bounds.getCenter( centre );

		m_minIndex = (halfExtents(0) < halfExtents(1)) ? 
			((halfExtents(0) < halfExtents(2)) ? 0 : 2) :
			((halfExtents(1) < halfExtents(2)) ? 1 : 2) ;
	}

	// Setup the camera
	{
		hkVector4 up; up.setZero4();
		up(m_minIndex) = 1.0f;

		hkVector4 from; from.setAddMul4( m_bounds.m_max, up, 5.0f);
		setupDefaultCameras(env, from, centre, up, 0.1f, 10000.0f);
	}

	//
	// Create objects at random coordinates
	//
	{
		hkVector4 size(0.5f, 0.5f, 0.5f);
		hkpBoxShape* boxShape =  new hkpBoxShape(size);

		hkpRigidBodyCinfo boxInfo;
		{
			boxInfo.m_mass = 1.0f;
			boxInfo.m_shape = boxShape;
			boxInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
		}

		hkPseudoRandomGenerator random(15);

		//
		// create the boxes
		//
		{
			hkVector4 range; range.setSub4( m_bounds.m_max, m_bounds.m_min );
			range.mul4( 1.0f );
			
			const int numObjects = 500;
			for (int i = 0; i < numObjects; i++)
			{
				hkVector4 pos; random.getRandomVector11(pos);
				pos.mul4(0.1f);
				pos.mul4(range);
				pos( m_minIndex ) += m_bounds.m_max( m_minIndex ) + i * (range(m_minIndex)) / numObjects + 4.0f;

				boxInfo.m_position = pos;
				hkpRigidBody* shape;
				shape = new hkpRigidBody(boxInfo);
				
				shape->setMaxLinearVelocity( 30 );
				m_world->addEntity(shape);
				shape->removeReference();
			}
		}

		boxShape->removeReference();
	}

	m_world->unlock();

	m_time = 0.0f;
}