Get the latest Education e-news
 

Go Back   Game Career Guide Forums > Programming
Forum Home Register Members List Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 04-06-2009, 07:29 PM   #1
brainydexter
Member

Activity Longevity
0/20 16/20
Today Posts
0/11 sssssss77
Location: N. America
Default 3D coordinate system & relative movement

I am trying to learn 3D game programming now (in XNA). Though, its really a math question..

(XNA follows the right hand coordinate system: From MSDN:
" The XNA Framework uses a right-handed coordinate system, with the positive z-axis pointing toward the observer when the positive x-axis is pointing to the right, and the positive y-axis is pointing up. "

Ok, now in this tutorial at msdn, its about basic movement and displaying stuff. Before that, here are some positions:

Camera:
AvatarHeadOffset = new Vector3(0, 7, -15);
TargetOffset = new Vector3(0, 5, 0);

Objects located at:
Cube.Position = new Vector3(10, 0, 10);
Pyramid.Position = new Vector3(20, 0, 10);

My Position = Origin

As per these, in my opinion, the cube should be displayed on the right and the pyramid afterwards at x = 10 and x = 20.
But, when I run the tutorial, it displays: the cube first on the left followed by pyramid (feels as if, cube is at x = -10 and pyramid at x = -20).

I dont understand why this is happening ? Given the coordinate system and where I currently am, should they not be seen on the right ?

The next question follows this one:
Its about movement along the x axis again. on right arrow, if i decrease my current position, i strafe right.

Can somebody please explain me as to what am I doing wrong here ?

The tutorial can be found over here.

Also, I have attached a copy of the code. Its XNA 3.0 (& it uses WASD for strafing, Q/E for rotation).

Thanks
Attached Files
File Type: zip FuelCell - Part 4.zip (50.6 KB, 4 views)
__________________
Twitter ~ Blog
brainydexter is offline   Reply With Quote
Old 04-06-2009, 08:43 PM   #2
sbodie
Junior Member

Activity Longevity
0/20 15/20
Today Posts
0/11 sssssss13
Location: Nashville, TN
Default

I think you have the coordinate system a bit backward from my look at it. From the starting point of view of your "fuelcarrier" the x axis has a positive direction to the left and negative to the right, the y axis is positive up and negative down, and the z-axis is positive in the way your camera is looking (so out away from you) and negative from behind you. I hope that helps somewhat, I'm not sure if that's the answer but playing around with a few of your vector3's that's what it's looking like.
sbodie is offline   Reply With Quote
Old 04-06-2009, 09:08 PM   #3
brainydexter
Member

Activity Longevity
0/20 16/20
Today Posts
0/11 sssssss77
Location: N. America
Default

Exactly!

But the definition of coordinate system from msdn says, that +X should be on the right. Thus, the models should appear on right and not on left

I dint write this code, its from a tutorial at msdn. Personally, I think I am getting messed up between the frame of reference from where the right hand coordinate is considered..but, coordinate system is one place, where I want to be absolutely sure before I actually get into some serious XNA 3d programming..otherwise, it will be a pain all along the way, and I would never be confident about what code I write..

But yeah, thanks for your suggestion. If I find an answer, I will definitely post it and log it in my FAQ
__________________
Twitter ~ Blog
brainydexter is offline   Reply With Quote
Old 04-06-2009, 11:57 PM   #4
Claxon
Senior Member

Activity Longevity
0/20 18/20
Today Posts
0/11 ssssss345
Location: London
Default

Quote:
Originally Posted by brainydexter View Post
Camera:
AvatarHeadOffset = new Vector3(0, 7, -15);
TargetOffset = new Vector3(0, 5, 0);

Objects located at:
Cube.Position = new Vector3(10, 0, 10);
Pyramid.Position = new Vector3(20, 0, 10);
I've not really looked at this in depth, but it seems a very simple problem. Your head offset is the -15 along the Z axis from the camera position. and the Target offset (which the camera is looking at) is 0 on the Z axis. If you remember that you are looking into the negative direction along the Z axis, that means that your camera is essentially looking backwards. Thus reversing the way things look.
Claxon is offline   Reply With Quote
Old 04-07-2009, 01:27 AM   #5
Adrir
Administrator
 
Adrir's Avatar

Activity Longevity
1/20 20/20
Today Posts
0/11 sssss1464
Location: London, UK
Default

The right hand rule for coordinates:

__________________
Michael 'Adrir' Scott :: Games, Virtual Worlds, Education
Networking | Current Project | Research | Teaching
Adrir is offline   Reply With Quote
Old 04-07-2009, 04:21 AM   #6
sbodie
Junior Member

Activity Longevity
0/20 15/20
Today Posts
0/11 sssssss13
Location: Nashville, TN
Default

Quote:
Originally Posted by Claxon View Post
I've not really looked at this in depth, but it seems a very simple problem. Your head offset is the -15 along the Z axis from the camera position. and the Target offset (which the camera is looking at) is 0 on the Z axis. If you remember that you are looking into the negative direction along the Z axis, that means that your camera is essentially looking backwards. Thus reversing the way things look.
He is exactly right this is the issue, your camera position and target makes the view seem like the coordinate system is backwards.
sbodie is offline   Reply With Quote
Old 04-07-2009, 05:28 AM   #7
Gshonk
Moderator

Activity Longevity
0/20 20/20
Today Posts
0/11 ssssss831
Location: Philadelphia, PA
Default

Quote:
Originally Posted by Adrir View Post
The right hand rule for coordinates:

Win! This is the best way to remember the rule.
__________________
Grant Shonkwiler()
"I would love to fix the world if someone would just give me the source code"
Website Industry blog LinkedIn
Gshonk is offline   Reply With Quote
Old 04-07-2009, 06:11 AM   #8
Adrir
Administrator
 
Adrir's Avatar

Activity Longevity
1/20 20/20
Today Posts
0/11 sssss1464
Location: London, UK
Default

Quote:
Originally Posted by sbodie View Post
He is exactly right this is the issue, your camera position and target makes the view seem like the coordinate system is backwards.
Yeah, that sounds about right.
__________________
Michael 'Adrir' Scott :: Games, Virtual Worlds, Education
Networking | Current Project | Research | Teaching
Adrir is offline   Reply With Quote
Old 04-07-2009, 08:07 PM   #9
brainydexter
Member

Activity Longevity
0/20 16/20
Today Posts
0/11 sssssss77
Location: N. America
Default

Ah, I finally understand how this works. Also, I put my understanding to test in my code and it works, yaaay !!

Thanks a lot, for clarifying this. I drew a grid on paper and marked everything, then I was able to see how things got inverted.

Also, I made these following changes:

Camera:
AvatarHeadOffset = new Vector3(0, 7, 15);
TargetOffset = new Vector3(0, 5, 0);

voila, and it behaves the way i want it to.

Also, for strafing, I say something like this>

If W: velocity.z = -1;
else if S: velocity.z = 1;

if A: velocity.x = -1;
else if D: velocity.x = 1;

(I do this, keeping in mind the right hand coordinate system) and it works fine. I wonder why did the tutorial at msdn; place the camera at z = -15 ? Is this an industry convention or what? Also, they had the velocity increments inverted (as to what I have written here). Personally, I found that to complicate things. Anyways, I would like to know, if that is some sort of industry convention or is there something like that that I need to keep in mind when I code for 3D.

As of now, I can roam around in this 3d world, strafe and rotate..woohoo

Thanks guys!

(I will post my code here and on my blog FAQ..just in case, if some1 lands into the same trouble and needs to see it..)
__________________
Twitter ~ Blog
brainydexter is offline   Reply With Quote
Old 04-08-2009, 01:36 AM   #10
Claxon
Senior Member

Activity Longevity
0/20 18/20
Today Posts
0/11 ssssss345
Location: London
Default

Quote:
Originally Posted by brainydexter View Post
I wonder why did the tutorial at msdn; place the camera at z = -15 ? Is this an industry convention or what? Also, they had the velocity increments inverted (as to what I have written here). Personally, I found that to complicate things. Anyways, I would like to know, if that is some sort of industry convention or is there something like that that I need to keep in mind when I code for 3D.
My guess is that it was converted from a DirectX tutorial or written by a DX programmer, because Direct3D uses a left-handed coordinate system, where the positive Z axis extends forward from the camera.
Claxon is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 10:48 PM.






UBM Tech