Black screen when trying to draw model

I’m trying to make a world object that can use a camera and draw multiple models at once, each with their own position (and rotation, etc. in the future). Except it comes up with a black screen and I don’t know why.

I’ve tried changing the way the matrices are created, adjusted the positions, and nothing.

World:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Xna.Framework;

using Simple3DWorld.Objects;

namespace Simple3DWorld
{
	public class World
	{
		public Camera Camera;
		public ModelObject[] Objects;

		public World()
		{
			Camera = new Camera(new Vector3(0, 0, 1), Vector3.Zero);
			Objects = new ModelObject[100];
			AddObject(new Landscape(new Vector3(0, 0, -1)));
		}

		public void AddObject(ModelObject obj)
		{
			bool added = false;

			for (int i = 0; i < Objects.Length && !added; i++)
			{
				if (Objects[i] == null)
				{
					Objects[i] = obj;
					added = true;
				}
			}
		}

		public void Update(GameTime gt)
		{
			for (int i = 0; i < Objects.Length; i++)
			{
				if (Objects[i] != null)
				{
					Objects[i].Update(gt);
				}
			}
		}

		public void Draw()
		{
			for (int i = 0; i < Objects.Length; i++)
			{
				if (Objects[i] != null)
				{
					Objects[i].Draw(Camera);
				}
			}
		}
	}
}

Camera:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Simple3DWorld
{
	public class Camera
	{
		public Vector3 Position;
		public Vector3 LookingAt;
		public float FieldOfView;
		public float AspectRatio;
		
		public Camera(Vector3 pos, Vector3 lookAt)
		{
			Position = pos;
			LookingAt = lookAt;
			FieldOfView = MathHelper.PiOver4;
			AspectRatio = STDW.Width / STDW.Height;
		}
	}
}

ModelObject:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Simple3DWorld
{
	public class ModelObject
	{
		public Model Model;
		public Vector3 Position;
		
		public ModelObject(Model model, Vector3 pos)
		{
			Model = model;
			Position = pos;
		}
		
		public virtual void Update(GameTime gt)
		{
			
		}
		
		public virtual void Draw(Camera camera)
		{
			foreach (ModelMesh mesh in Model.Meshes)
			{
				foreach (BasicEffect effect in mesh.Effects)
				{
					effect.EnableDefaultLighting();
					effect.PreferPerPixelLighting = true;
					effect.World = Matrix.CreateTranslation(Position);
					effect.View = Matrix.CreateLookAt(camera.Position, camera.LookingAt, Vector3.UnitZ);
					effect.Projection = Matrix.CreatePerspectiveFieldOfView(camera.FieldOfView, camera.AspectRatio, 1f, 100f);
				}

				mesh.Draw();
			}
		}
	}
}

And yes, I have made sure that all methods are being called correctly. What should be showing on screen is my landscape model.

Can’t say for sure because I didn’t test the code, but maybe the Apply function call is missing to ‘activate’ the shader.

Could you please put effect.CurrentTechnique.Passes[0].Apply() before the mesh.Draw() to test if that’s the problem?

I don’t think that was the issue as I never had to add that line of code when I was testing 3D drawing before. Tried anyway, and unfortunately nothing different happened.

Since you have a fixed camera, maybe your model is blocking the screen, model with distort normals drawn as black when light is enabled, try to put some scaling on your model to fit on screen.

I’ve used the same model before, and it did not need scaling. But I tried scaling anyway to 0.1f, and no change.

no idea then, sorry : (

For some stupid, frustrating reason, MonoGame will not render your models if your camera’s X and Y (not the up vector) are both 0. If anyone could somehow explain this, I would be infinitely grateful.

If your camera position is x,y is 0 and your camera UpVector is UnitZ, ( 0,0,1 ), maybe that’s where
the problem lies try to change it to Vector.Up

effect.View = Matrix.CreateLookAt(camera.Position, camera.LookingAt, Vector3.Up );

As I understand, because Vector3.Up is 0,1,0, that would simply just make it so the Y coordinate is used for going up or down.