Here's a simple example using the 'convenience' triangle class. This is an entity.
Triangle t = new Triangle(new Vector3(15, 10, 0), new Vector3(16, 10, 0), new Vector3(15, 10, 1));
If you then immediately check the position of the entity, you see {X:15.33333 Y:10 Z:0.3333333}.
The vertices, having been recentered, are:
{X:-0.333334 Y:0 Z:-0.3333333}
{X:0.666666 Y:0 Z:-0.3333333}
{X:-0.333334 Y:0 Z:0.6666666}
Those vertices are the
local vertices. In the next beta, this will become more obvious with both LocalVertex and Vertex properties. The current Vertex properties (and the future LocalVertex properties) are simply a wrapper over the TriangleShape's properties.
Transforming those local positions into world space using the entity's position (and orientation, if it were rotated):
{X:15 Y:10 Z:0}
{X:16 Y:10 Z:0}
{X:15 Y:10 Z:1}
Which are the original world space vertex locations.
Here's how you could make an entity without using the prefab, while still having the same behavior:
Code: Select all
Vector3 center;
TriangleShape tShape = new TriangleShape(new Vector3(15, 10, 0), new Vector3(16, 10, 0), new Vector3(15, 10, 1), out center);
var t = new Entity<ConvexCollisionInformation<TriangleShape>>(new ConvexCollisionInformation<TriangleShape>(tShape));
t.Position = center;
That's basically what the Triangle convenience class does internally. You could also use the MorphableEntity if you wanted.
There are a lot of ways of computing a triangle center and not all of them accurate depending on the triangle type.
Fortunately, you never have to worry about how to compute it; just use what the engine provides, when necessary. However, in case you're curious: for the purposes of the engine, the center is simply the average of each world-space vertex. The actual technical requirement for convex shapes is that they intersect/contain their local origin, and do so in a consistent manner. The average of the vertices produces an acceptable result.