simple 3d map

Hello everybody,
I have a very basic question concerning creating a map for a c# monogame program:
I am wondering, what is the best way to create/add a map in such a program.
Map, I’d like to have:

  • 3d, top view (c.f. the settlers, clash of clans)
  • one camera angle, but if the camera position is moved to one direction the angle to the objects on the map changes

Should I create the map in c# using a 3d grid or in a third party software like blender? And are you aware of a nice tutorial?
Thanks for any help!

Hello lfcom and welcome to the monogame community!

The camera you’re describing is trivial to implement with the built in factory method Matrix.CreateLookAt(cameraPosition, cameraTarget, cameraUpVector).

public class Camera
{
	....

	// The point in 3D space to aim the camera at
	public Vector3 LookAtVector { get; private set; } = new Vector3(0, 0, 0);

	public Matrix View
	{
		get
		{
			return Matrix.CreateLookAt(Position, LookAtVector, UpVector);
		}
	}

	...
}

I think the answer to your second question depends on what you want to build.

If you already have a good grip of the game loop fundamentals (Draw/Update etc) and drawing 2D stuff with SpriteBatch etc I think RB Whitakers XNA/Monogame tutorials are a great starting place for Monogame beginners. In your case perhaps have a look at his 3D tutorials: http://rbwhitaker.wikidot.com/3d-tutorials

Good luck, have fun!

2 Likes

Hi @lfcom Welcome to the Community!

What’s this?

Happy Coding!

with “c.f.” I tried to refer to the mentioned games :sweat_smile:. Probably I should have used “e.g.” except.

1 Like

Oh, therefore I was confused:

Hello,
Thank you for your reply! I’ll take a look at the tutorials you shared.
I have a question about your code example. What exactly is the Vector3 LookAtVector-vector? Is it the coordinate of the map the camera points to? And where is the Vector describing the map?
Thanks again for your help!

Basically, Position is the location of the camera, if you put it in Visual Studio and hover over it or CTRL+Click Matrix.CreateLookAt it should show you more details, but Positon is a Vector3

So, in basic form

Camera has a position using Vector3 [new Vector3(0, 0, 0); in the code above]

And the LookAt part is what the camera looks at, also a Vector3

Does that make sense?

EDIT

Typos

EDIT

Still new to the UpVector…

EDIT

@magneticmuesli edited his post, so please take a second look at it above.

EDIT

Found this nifty animation:


[Source: https://songho.ca/opengl/gl_camera.html]

2 Likes

Yes:)

Hmm. In monogame there is no concept of a “map” built in, you get to write your own class and define it exactly how you want it. So you have to think about what your map is.

Perhaps a map is just a collection of ‘tiles’ with information about their respective positions. And tiles are simple quads with a certain texture.

It all depends on what you are trying to build…

Roughly how confident are you with C# and object oriented programming fundamentals in general?

Cheers

1 Like

Yes, this really helps! Thank you.
What I still don’t get is: Where’s my map?
I was able to create a Camera and a 3d object and move around it. But how do I implement a map?
EDIT:
So say I want a map 10.000px * 10.000px and the camera can only show 500px * 500px. Do I use Vector2D to represent the map?

1 Like

Thank you.
I am completely new to c#, but confident with c/c++ and even more confident to python. So I think I get the object oriented part of c# but all the peculiarities of c# are new to me.

Heres one example of a very basic map class (pseudo code)

class Map
{
    List<Tile> Tiles;

    public void Draw(GameTime gameTime)
    {
        foreach(Tile tile in Tiles)
            tile.Draw();
    }
}

class Tile
{
    Vector3 Position;
    TileType Type;

    public void Draw(GameTime gameTime)
    {
         switch(Type)
         {
              case TileType.Forest:
                    //Some code to draw a forest tile at Position
                    break;
              case TileType.Water:
                    //Some code to draw a water tile at Position
                    break;
         }
    }

    public enum TileType
    {
        Forest,
        Water
    }
}
2 Likes

Be sure to visit here…

2 Likes

Okay, that really helps. Thank you so much :slight_smile:

1 Like