Raytraced audio operates against a low-poly copy of the world, similar to physics engines.
To add a primitive to the simulation, invoke the `AddPrimitive` function:
```cs
// Create a rectangular prism
var prism = new PrismPrimitive()
{
// Set its material
material = MaterialType.Metal,
// Scale it
size = new Vector3F(15),
// Rotate and position it
transform = Matrix4F.CreateRotationX(MathF.PI / 4) *
Matrix4F.CreateTranslation(32, 32, 32)
};
context.AddPrimitive(prism);
```
Every primitive has a `material` property, which must be set. An exception will be thrown if a primitive is created with `MaterialType.Air`.
Below is the full list of primitives.
Flat primitives:
- [[TrianglePrimitive|Triangle]]
- [[PlanePrimitive|Plane]]
- [[DiskPrimitive|Disk]]
Prism primitives:
- [[PrismPrimitive|Prism]]
- [[TriangularPrismPrimitive|Triangular prism]]
Circular primitives:
- [[SpherePrimitive|Sphere]]
- [[HalfSpherePrimitive|Half sphere]]
- [[CylinderPrimitive|Cylinder]]
- [[CapsulePrimitive|Capsule]]
Cone primitives:
- [[ConePrimitive|Cone]]
- [[TriangularConePrimitive|Triangular cone]]
- [[RectangularConePrimitive|Rectangular cone]]
Complex primitives:
- [[MeshPrimitive|Mesh]]
## Updating Primitives
The position/rotation/material/etc of primitives can be updated at any time, even while the background raytracing threads are running. However the updates will only apply the next time raytracing occurs, i.e. when `context.Update(...)` is invoked.
When a primitive is updated, it will automatically be flagged as 'dirty'. The manager keeps track of all dirty primitives, and the next time raytracing occurs it will re-compute the bounding volume hierarchy (BVH) that is used to speed up raytracing intersections.
This occurs on background threads so there will be no performance impact on the main thread, but raytracing will be slightly delayed by this preparation work. You can check how long preparation and BVH update takes via the `context.PreparationTime` field.