Commits

German Larrain  committed bee0c92

collision.base: added ConstantHeightfieldTrimesh, including `calc_vertices`.

  • Participants
  • Parent commits 9073f41

Comments (0)

Files changed (1)

File ars/model/collision/base.py

 
 		return faces
 
+
+class ConstantHeightfieldTrimesh(HeightfieldTrimesh):
+
+	"""A trimesh that is a heightfield at constant level.
+
+	.. note::
+	   More than anything, this geom is for demonstration purposes,
+	   because it could be easily replaced with a :class:`Plane`.
+
+	"""
+
+	def __init__(self, space, size_x, size_z, height):
+		"""Constructor.
+
+		:param space:
+		:type space: :class:`Space`
+		:param size_x: number of cells along the X axis
+		:type size_x: positive int
+		:param size_z: number of cells along the Z axis
+		:type size_z: positive int
+		:param height:
+		:type height: float
+
+		"""
+		vertices = self.calc_vertices(size_x, size_z, height)
+		super(ConstantHeightfieldTrimesh, self).__init__(
+			space, size_x, size_z, vertices)
+
+	@staticmethod
+	def calc_vertices(size_x, size_z, height=0.0):
+		"""Return the vertices of a horizontal grid of ``size_x`` by ``size_z``
+		cells at a certain ``height``.
+
+		:param size_x: number of cells along the X axis
+		:type size_x: positive int
+		:param size_z: number of cells along the Z axis
+		:type size_z: positive int
+		:param height:
+		:type height: float
+
+		>>> ConstantHeightfieldTrimesh.calc_vertices(2, 4)
+		[(0, 0.0, 0), (0, 0.0, 1), (0, 0.0, 2), ..., (1, 0.0, 3)]
+
+		"""
+		verts = []
+		for x in range(size_x):
+			for z in range(size_z):
+				verts.append((x, height, z))
+		return verts
+
 #==============================================================================
 # Basic Shapes
 #==============================================================================