Thursday, April 12, 2012

Only seeing 1 object out of an array of 3 in XNA

Can anyone see where I am going wrong here.



I have a CameraObject class (its not a camera, simply the Model of a box to represent a "camera") that has a Model and a Position. It also has the usual LoadContent(), Draw() and Update() methods.
However, when I draw the array of Models, I only see 1 model on the screen (well, there might be 3 but they might all be in the same location)?



The Draw() method for the CameraModel class looks like this:



public void Draw(Matrix view, Matrix projection) 
{
transforms = new Matrix[CameraModel.Bones.Count];
CameraModel.CopyAbsoluteBoneTransformsTo(transforms);

// Draw the model
foreach(ModelMesh myMesh in CameraModel.Meshes)
{
foreach (BasicEffect myEffect in myMesh.Effects)
{
myEffect.World = transforms[myMesh.ParentBone.Index];
myEffect.View = view;
myEffect.Projection = projection;

myEffect.EnableDefaultLighting();
myEffect.SpecularColor = new Vector3(0.25f);
myEffect.SpecularPower = 16;
}
myMesh.Draw();
}
}


Then in my Game1 class I create an array of CameraObject objects:



CameraObject[] cameraObject = new CameraObject[3]; 


Which I Initialize() - so each new object should be at +10 from the previous object



for (int i = 0; i < cameraObject.Length; i++) 
{
cameraObject[i] = new CameraObject();
cameraObject[i].Position = new Vector3(i * 10, i * 10, i * 10);
}


And finally Draw()



Matrix view = camera.viewMatrix; 
Matrix projection = camera.projectionMatrix;

for (int i = 0; i < cameraObject.Length; i++)
{
cameraObject[i].Draw(view, projection);
}


Where view and projection are from my Camera() class which looks like so:



viewMatrix = Matrix.Identity; 
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), 16 / 9, .5f, 500f);


But I only see 1 object drawn to the screen? I have stepped through the code and all seems well but I cant figure out why I cant see 3 objects?



Can anyone spot where I am going wrong?





No comments:

Post a Comment