I'm trying to make a 3D WP7 game in XNA by drawing models consisting of lines, using DrawUserIndexedPrimitives This is all working fine, but now I want to give every model its own Rotation. Currently I am using a BasicEffect to draw all the models. I can set its rotation, but then all the objects will have that same rotation. Is there any way to set a different rotation for every object? I've currently come up with a couple of solutions that I could use, but I'm not happy with either of them:
- Create a new BasicEffect for every object, with its own World, then loop over all of the objects to get their basic effect and draw it - I guess all those BasicEffects would create a lot of overhead, and I want to separate the effect from the models.
- Do the calculation of the points myself (ie calclulate the rotation and pass those values on to the DrawUserIndexedPrimitives method) - This is quite an expensive calculation, dragging down the performance a lot.
Is there any suggested route to take here?
I don't know if DrawUserIndexedPrimitives is the best method to use, I just want to be able to draw lines and give them a rotation. If there's a better way to do this, please tell me :)
My current solution:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
foreach (var model in _models)
{
foreach (var pass in model.Effect.CurrentTechnique.Passes)
{
pass.Apply();
model.Effect.World = _model.GetWorld();
var points = model.GetPoints();
GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, points, 0, points.Length, model.Lines, 0, model.Lines.Length / 2);
_models[0].Draw(GraphicsDevice);
}
}
base.Draw(gameTime);
}
model.GetWorld() returns a matrix with the rotation, translation and scale of the object, model.GetPoints() a list with the points and model.Lines is a list with the indices of the connected points