svxtc

I have code that creates a model at a designated mouse click. I want to change is so that when I click and hold the mouse, the model follows the mouse. Then, when I release the mouse, I would like the model to stay in that position. But then I want to be able to do that again for another model. I think that the draw code that I have will be a problem, because I am drawing the models from an arraylist. My question is: Is it possible to create multiple draw methods, one for the model while it is following the mouse and the other for the models that stay put Here is my draw code:

protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

Matrix[] transforms = new Matrix[currentModel.Bones.Count];
currentModel.CopyAbsoluteBoneTransformsTo(transforms);
for (int i = 0; i < modelPosition.Count; i++)
{
foreach (ModelMesh mesh in currentModel.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();

effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
aspectRatio, 1.0f, 10000.0f);

effect.World = transforms[mesh.ParentBone.Index] *
Matrix.CreateRotationY(modelRotation) *
Matrix.CreateTranslation((Vector3)modelPositionIdea);

}
mesh.Draw();
}
}


base.Draw(gameTime);
}

Any help is greatly appreciated.



Re: XNA Game Studio Express Creating Models

Kyle_W

If you are just trying to create multiple instances of the same model, and assuming there is nothing unique about each instance other than its position, then you could simply keep a list of Vector3 positions or possibly Matrices (not sure which would be more efficient) and each time a new instance is created (dropped), add its position or matrix to the list. In the Draw() method you would then have a loop that draws the same model multiple times (once for each item in the list). You would then have an extra draw call in the Draw() method to draw one more instance of the model, but only if the mouse button is down. In the Update() method, you would need to track the previous and current mouse state. If the current mouse state is down, then the model instance that is being dragged by the mouse needs to have its position updated. If the previous mouse state was down and the current mouse state is up, then a new instance has been dropped and needs to have its position or matrix added to the list.



Re: XNA Game Studio Express Creating Models

svxtc

I could probably just have an if statement within the draw method, couldn't I



Re: XNA Game Studio Express Creating Models

Kyle_W

An if statement to do what If you want helpful responses in the forums you need to state your questions clearly. Certainly variations of what I said in the previous paragraph are possible. As long as you understood the basic logic of what I was saying, you can customize it as you see fit.