8 Replies - 1510 Views - Last Post: 15 June 2012 - 09:17 AM

#1 rex64   User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 175
  • Joined: 31-January 12

Normals

Posted 23 March 2012 - 05:07 PM

I am planning on having my Z axis be for altitude. And everything on the ground will be moving on the XY plane. However all of the models I am loading in seem to be sideways, like they are trying to walk into space. I was thinking about rotating all the models, but I am wondering if there is a better way. I know I can rotate my world, but I would really like to keep this setup since it makes sense to me :) Let me know your thoughts.

I would like to be like a bird looking straight down (Warcraft 3/Starcraft 2 type of view).

Test models location:
x800, y0, z0
x-800, y0, z0

Camera
current position: x0, y0, z20
Target: currentX, currentY, currentZ-1
Vector3.Up

Is This A Good Question/Topic? 0
  • +

Replies To: Normals

#2 Kilorn   User is offline

  • XNArchitect
  • member icon



Reputation: 1361
  • View blog
  • Posts: 3,534
  • Joined: 03-May 10

Re: Normals

Posted 23 March 2012 - 06:28 PM

If you're using an FBX exporter, you'll need to set the models to to Y-up before you export them. Otherwise, you could easily just create a rotation for your world matrix for 90 degrees on the X axis and invert the Z values, or z * -1, of the models so that Z positive points away from you, then you've got a Y-up coordinate system with Z positive in the proper direction.

This post has been edited by Kilorn: 23 March 2012 - 06:28 PM

Was This Post Helpful? 0
  • +
  • -

#3 rex64   User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 175
  • Joined: 31-January 12

Re: Normals

Posted 11 June 2012 - 04:50 PM

It seems like I am looking down on the objects, but when I increase the Y on the objects they move towards the bottom of the screen (when they should move towards the top of the screen?)


This is how I would like the 2d screen to look. Also, when I increase the object Z it would get closer to the camera (and appear larger)
y+
|
|
x- ------ x+
|
|
y-
Was This Post Helpful? 0
  • +
  • -

#4 Kilorn   User is offline

  • XNArchitect
  • member icon



Reputation: 1361
  • View blog
  • Posts: 3,534
  • Joined: 03-May 10

Re: Normals

Posted 11 June 2012 - 05:31 PM

When converting the vertices from world space to screen space, the matrix that you use will transform the object to fit the parameters and dimensions of the screen, including the fact that 0 on the Y axis is the top of the viewable screen.
Was This Post Helpful? 0
  • +
  • -

#5 BBeck   User is offline

  • Here to help.
  • member icon


Reputation: 792
  • View blog
  • Posts: 1,886
  • Joined: 24-April 12

Re: Normals

Posted 12 June 2012 - 05:52 AM

View Postrex64, on 23 March 2012 - 05:07 PM, said:

I am planning on having my Z axis be for altitude. And everything on the ground will be moving on the XY plane. However all of the models I am loading in seem to be sideways, like they are trying to walk into space. I was thinking about rotating all the models, but I am wondering if there is a better way. I know I can rotate my world, but I would really like to keep this setup since it makes sense to me :) Let me know your thoughts.

I would like to be like a bird looking straight down (Warcraft 3/Starcraft 2 type of view).

Test models location:
x800, y0, z0
x-800, y0, z0

Camera
current position: x0, y0, z20
Target: currentX, currentY, currentZ-1
Vector3.Up


I think I see your problem. You said, "I am planning on having my Z axis be for altitude." That's fine if that's what you want, but that means you are going to have to do a lot of conversions. It's probably easier to work with XNA than against it. Y is altitude in XNA by default.

I remember when I first started working with 3D this really threw me. After years and years of working with X,Y graphs in school that represented X,Y as the ground, I just naturally assumed that X,Y would be the ground in 3D games. Not usually the case.

Now that I've been working with it for awhile it seems a lot more natural. X,Y is the monitor or computer screen, where Y is top of screen/bottom of screen and X is Left/Right. Thinking of it that way makes it more natural. And adding Z for depth moves it from 2D to 3D.

So, the X,Y plane isn't the ground but rather Up/Down/Left/Right space (instead of Left/Right/Forward/Backwards space).

To further confuse things, we often want a Vector2 to represent movement along the X,Z plane (yes, I said Z :bigsmile: ). But the Vector2 stores X,Y. So, I see a lot of examples that convert a Vector2 to a Vector3 that make it confusing, because they don't make it clear that the Vector2 is actually holding X,Z coordinates even if Vector2 is commonly thought of as X,Y.

I like using Vector2 in 3D because movement tends to be across the X,Z plane with Y just being an altitude that's largely seperate from position. But I try to write my code to make it clear that the Vector2 is holding X,Z values, and not X,Y values.

If you want a top down look at the 3D world, you should be positioning the camera like this:
Camera
current position: x0, y20, z0
Target: currentX, currentY-1, currentZ
Vector3.Up (Or is it new Vector3(x0, y0, z1)?)

The camera needs to be rotated 180 degrees around the Y axis in order to put positive Z at the top of the screen. I think it will put negative Z at the top of the screen without the rotation (although changing the Up vector may correct the problem without a rotation around Y).

I'm thinking that "should" cause your models to be oriented properly. If not, then you probably have a problem with the export from your modeling program. I've never had a problem with models not loading with correct orientation in XNA, so far. But I've been loading mostly .X models and not .FBX models. Not to mention that some of my models (such as my sky box are hand crafted - rather than going through an exporter).

You might look at my "Movement" tutorial where I discuss the X,Y,Z space in detail complete with illustrations (Ok. There's actually only one illustration, but it may make my point more clear).

http://xna-3d-101.co...s/Movement.html

And you may even want to take a look at the code on the "Holodeck" tutorial I'm working on there to see how I've coded for the 3D space (although I'm not doing a top down perspective). I hope to add the code for my camera class in the next week which tends to have position stored in a Vector2 even though it's a 3D world.

Anyway, I hope that helps and that I haven't completly misunderstood your problem. :bigsmile:

This post has been edited by BBeck: 12 June 2012 - 06:09 AM

Was This Post Helpful? 0
  • +
  • -

#6 rex64   User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 175
  • Joined: 31-January 12

Re: Normals

Posted 14 June 2012 - 06:08 PM

Thanks for your help. I think that helps clear things up a lot.

Let me know if this make sense.

I am creating a Starcraft/Red Alert style view. You would be looking down on a map, so your Z would be how high you are flying above the map.

When your character moves right his X would increase and the models would move left.

When you press Up the models would move down and Y would increase.

I am seeing the top of the models just fine, but the movement was wrong.

I just found the problem (while typing this for the 2nd time). I think my up vector was not being adjusted before when I was testing because I tried several different ones in the past and they did not change things. I think I found the proper spot in my code to make the change.

Do up vectors need to be normalized? What happens id you do not normalize them? Maybe that was my issue in the past as well.
Was This Post Helpful? 0
  • +
  • -

#7 BBeck   User is offline

  • Here to help.
  • member icon


Reputation: 792
  • View blog
  • Posts: 1,886
  • Joined: 24-April 12

Re: Normals

Posted 15 June 2012 - 04:21 AM

View Postrex64, on 14 June 2012 - 06:08 PM, said:

Thanks for your help. I think that helps clear things up a lot.

Let me know if this make sense.

I am creating a Starcraft/Red Alert style view. You would be looking down on a map, so your Z would be how high you are flying above the map.

When your character moves right his X would increase and the models would move left.

When you press Up the models would move down and Y would increase.

I am seeing the top of the models just fine, but the movement was wrong.

I just found the problem (while typing this for the 2nd time). I think my up vector was not being adjusted before when I was testing because I tried several different ones in the past and they did not change things. I think I found the proper spot in my code to make the change.

Do up vectors need to be normalized? What happens id you do not normalize them? Maybe that was my issue in the past as well.



You should normalize the Up vector. I'm not sure how it's being used mathematically; at one time I had to learn about all that rasterization stuff and that was probably in there. But now, I can't remember how that's being used, other than to define "Up" for the "camera".

But in general, a normalized vector is a direction with "no amount" information. That's what an up vector is, so it should always be normalized. If it's not normalized, it will probably throw the calculations off for drawing the screen. I've seen "some" things in XNA (like color) that expect a normalized vector, but seem to normalize it for you if you don't. I'm not sure this is one of those things. Regardless, I would always normalize it.

A normalized vector has a length of one. If it's not normalized it could have any length.

When you multiply a number times a vector it scales the length of the vector while maintaining the vector's direction. So, you multiply times a single number in order to give you a vector that points in the same direction with a new length. Doing this against a normalized vector results in a simple assignment of length. For example:

(Vector Length 1) * 4 = (Vector Length 4)

I'm excluding the direction information there for simplicity but the vector's direction is unaffected by this.

Anyway, that was with a normalized vector. If the vector is not normalized and you try to assign it a length of 4 like this you'll get something like this:

(Vector Length 2.5) * 4 = (Vector Length 10)

So, trying to "assign" it a length of 4 like this resulted in it being assigned a length of 10 due to the fact that the vector was not normalized.

That's what happens when you don't normalize a vector that was supposed to be normalized.
Was This Post Helpful? 0
  • +
  • -

#8 rex64   User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 175
  • Joined: 31-January 12

Re: Normals

Posted 15 June 2012 - 08:06 AM

Thanks for the great help.

Also, on your site I read this at the end of the article, and was wondering if you have an article for this?
"For a lot of things we will load up a matrix with the movement and then “apply it” but that’s another subject."
Was This Post Helpful? 0
  • +
  • -

#9 BBeck   User is offline

  • Here to help.
  • member icon


Reputation: 792
  • View blog
  • Posts: 1,886
  • Joined: 24-April 12

Re: Normals

Posted 15 June 2012 - 09:17 AM

Glad I could help!

I cover matrices at a high level on this page:

http://xna-3d-101.co...s/Matrices.html

The main tutorial, so far, is the Holodeck tutorial. That covers using matrices in a much more specific way. For example - in the tutorial, you load a .X model for a chair and place it in the 3D scene by loading up the Chair's world matrix with the appropriate formulas in the LoadContent method in Part IV.

http://xna-3d-101.co...heHolodeck.html

Also, at the end of Part III, there's an overly simplified camera in the Update method that loads up a matrix that gets applied to the game's View matrix.

I think Part IV is not entirely written, but the complete source code is there along with probably enough to complete it. It's on my "agenda" for this weekend to get Part IV finished, and hopefully get Part V finished (where I think I create the camera/player class that really allows full movement around the room and does more matrix manipulation).

In short, you have a View matrix which is essentially the game's camera. You have the projection matrix which is somewhat similar to a camera's lens system. Those you will generally only have one of for every game. Then there is the World matrix and every object drawn in the game will have it's own personal world matrix that allows you to place the object in the scene where you want it along with moving it and other things. In the holodeck tutorial, I only have a world matrix for the room itself and another one for the chair, but it's enough to start getting the idea.

I've thought about doing tutorials for individual XNA concepts, such as one tutorial that has nothing but matrices, or possibly one for just rotation matrices for example. But I've decided to instead focus on trying to get a series of tutorials that take someone from nothing but a CornFlowerBlue screen to something that feels like an RPG or First Person Shooter. That's a pretty ambitious goal and I have a ton of work left to do to get there. But anyway, I wanted to take that approach to help people see how it all works together. Although, I'm doing the whole thing in "Lessons" in order to declare a "stopping point" and then build the next lesson pretty much from scratch. So, each lesson is self contained/self sufficient but assumes you already know the things taught in the earlier lessons. It kind of allows people to skip forward to a specific lesson, if they already know how to do everything in earlier lessons, but at the same time builds on the information in previous lessons and how everything fits together.

Generally, I prefer something that teaches 1 concept at a time, but I think something that shows how it all fits together is more needed in the XNA community right now. I may go back and do 1 off tutorials in the distant future.

This post has been edited by BBeck: 15 June 2012 - 09:30 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1