Changing entity shape type on the fly?
Posted: Thu Dec 16, 2010 3:57 pm
I've got a method that can take any entity and change its shape on the fly:
The problem is that this method causes the shape to occasionally draw at (0, 0, 0) for a single frame before being drawn in its original place.
How else can I change the shape of an entity without encountering this problem?
Code: Select all
protected void CreateBasicObject(Shape shape, Vector3 scale, Vector3 rotation, Vector3 position, float mass)
{
if (entity != null)
{
space.Remove(entity);
}
switch (shape)
{
case Shape.Box:
{
entity = mass == float.MaxValue ? new Box(position, scaleFactor, scaleFactor, scaleFactor) : new Box(position, scaleFactor, scaleFactor, scaleFactor, mass);
entity.InternalOrientationMatrix = Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);
break;
}
case Shape.Capsule:
{
entity = mass == float.MaxValue ? new Capsule(position, scaleFactor, scaleFactor * 0.5f) : new Capsule(position, scaleFactor, scaleFactor * 0.5f, mass);
entity.InternalOrientationMatrix = Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);
break;
}
case Shape.Cone:
{
entity = mass == float.MaxValue ? new Cone(position, scaleFactor, scaleFactor * 0.5f) : new Cone(position, scaleFactor, scaleFactor * 0.5f, mass);
entity.InternalOrientationMatrix = Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);
break;
}
case Shape.Cylinder:
{
entity = mass == float.MaxValue ? new Cylinder(position, scaleFactor, scaleFactor * 0.5f) : new Cylinder(position, scaleFactor, scaleFactor * 0.5f, mass);
entity.InternalOrientationMatrix = Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);
break;
}
case Shape.Sphere:
{
entity = mass == float.MaxValue ? new Sphere(position, scaleFactor * 0.5f) : new Sphere(position, scaleFactor * 0.5f, mass);
entity.InternalOrientationMatrix = Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);
break;
}
default:
{
entity = mass == float.MaxValue ? new Box(position, scaleFactor, scaleFactor, scaleFactor) : new Box(position, scaleFactor, scaleFactor, scaleFactor, mass);
entity.InternalOrientationMatrix = Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);
break;
}
}
space.Add(entity);
}
How else can I change the shape of an entity without encountering this problem?