• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Sir David

Moving a scene/entity in a 3D world.

4 posts in this topic

I'm working on a space game where the player controls a spaceship, and I'm having some difficulty getting the math right.

What I'd like is a spaceship starting at the origin of the world with up in the positive Y, and forward into the screen, and the ability to move the ship forward, backward, left/right (strafe), turn to the right and left (rotation on the Y axis), and nose up and down (rotation on the X axis).

All this is working, at least to start. However, I'm having difficulty, suppose I start my game, and turn the ship to the left by 45 degrees so I'm still on the Z plane have neither angle up nor down, and simply am pointing off between negative Z (away from the screen), and negative X. Suppose the ship is given some forward acceleration, and then stopped say 50 units away from the origin.
Note: Up to this point, I have this working, the following is where it gets tricky.
Now suppose the ship is put nose down 45 degrees, and another 45 degrees to the left, so I'm facing directly in the negative X with my nose now pointing in the half-way between negative Y and negative X. Now, suppose I give the ship some velocity in the forward direction... Where should it end up?

So put another way, given a ship at an arbitrary 3D point, (x, y, z), a heading/direction, a velocity and a time(delta), how do I find the point where the ship should end up? Also, how should the heading/direction be stored?

Along the same lines, currently, when a user presses keys for rotating the ship on one of the axes, I increment a value, and rotate the ship on the corresponding axis. This works, and looks right, but I'm having trouble keeping track of where "heading/direction" is. How should this be recorded? Should I have three vectors for each axis or something?

I would greatly appreciate some detailed explanation or discussion of this. I've browsed and found some useful vector/matrix math stuff that's been helpful, but not quite enough to get me where I'm going. Any insight you could provide is welcome. Thanks in advance.
0

Share this post


Link to post
Share on other sites
You can use a unit vector to store your facing direction.
If you want to turn, rotate the vector.
If you want to move, the velocity is speed*direction.

Another option is to use a quaternion, but I think starting with a vector is easier (more straightforward, anyway).
0

Share this post


Link to post
Share on other sites
[quote name='Sir David' timestamp='1343707921' post='4964704']
Also, how should the heading/direction be stored?
[/quote]
Via a normalized 3D vector.

[quote name='Sir David' timestamp='1343707921' post='4964704']
So put another way, given a ship at an arbitrary 3D point, (x, y, z), a heading/direction, a velocity and a time(delta), how do I find the point where the ship should end up?
[/quote]
Take the previous 3D vector, multiply it by the speed (not velocity) and by time, then add it to the ship’s current 3D vector that represents its position. The position of the ship has now moved in the correct direction by the correct amount.


L. Spiro
0

Share this post


Link to post
Share on other sites
[quote name='L. Spiro' timestamp='1343738080' post='4964833']
Take the previous 3D vector, multiply it by the speed (not velocity) and by time, then add it to the ship’s current 3D vector that represents its position. The position of the ship has now moved in the correct direction by the correct amount.
[/quote]
This makes sense, I think. You're saying that I have one vector at my world origin which gives the ships x, y, z, and after adding the speed*direction*time to the position vector, it's the ship's new position.


[quote name='wolfscaptain' timestamp='1343732720' post='4964803']
You can use a unit vector to store your facing direction.
If you want to turn, rotate the vector.
[/quote]
This I'm not so clear on. Is this unit vector centered about the world origin? I suppose it would be, right? If so, my difficulty now is in adjusting the direction of that unit vector. If the ship's "up" is in the positive Y direction, and the ship is facing the negative X, then when the user turns there ship to the left, I just rotate the facing direction about the Y axis, but I have trouble envisioning how it works when the "up" vector has X and Z components.

I think if I had an explanation and solution for the following problem, that might help.
The ship has a direction described by the vector D=(0.36, 0.59, 0.72)
The ship's "up" direction is described by U=(.62, .75, -.21)
When a user "turns" for time 't', (rotating only about the "up" axis, like turning on a flat road in a car), the ship rotates 'pi/10' radians in the direction turned.
If this ship turns for one time unit, what is its new direction vector?


Even describing the above problem though, I foresee more issues. It seems like the direction vector MUST be centered at the ship's origin because if the direction is centered about the world origin, when the ship turns, and there's a rotation about U by pi/10 at the origin, it won't "feel" like pi/10 for the ship. From the ship's point of view it will turn very quickly at some 't's and very slowly at others based on its position from the world origin.
So there must be some sort of translation between the ship's "reference frame" and the world's.
I'm brand new to all this, so as much as you can dumb down any insight, the better.

To give the above problem a little more practicality with reference to my previous paragraph monologue, consider the following:
The ship's position in the world's reference frame is P=(50, 35, 35).
The ship moves 30 units in direction D before it turns, what is its new position P'?
Now the ship turns for one unit of time and rotates about U by pi/10.
The ship moves another 30 units in it's new direction D'.
Where is the ship's position P'' now?

A detailed solution to this would be GREATLY appreciated. Thank you.
0

Share this post


Link to post
Share on other sites
You are heavily overengineering this. There is nothing tricky about it.

[quote name='Sir David' timestamp='1344099682' post='4966134']
This I'm not so clear on. Is this unit vector centered about the world origin?
[/quote]
It is a direction; it has no center point. This is like asking , “What is the center point of left?”.


[quote name='Sir David' timestamp='1344099682' post='4966134']
When a user "turns" for time 't', (rotating only about the "up" axis, like turning on a flat road in a car), the ship rotates 'pi/10' radians in the direction turned.
If this ship turns for one time unit, what is its new direction vector?
[/quote]
D + Rotated amount. To combine rotations, look into quaternions or matrix rotation around axes.


[quote name='Sir David' timestamp='1344099682' post='4966134']
The ship's position in the world's reference frame is P=(50, 35, 35).
The ship moves 30 units in direction D before it turns, what is its new position P'?
[/quote]
P + D * 30.

[quote name='Sir David' timestamp='1344099682' post='4966134']
Now the ship turns for one unit of time and rotates about U by pi/10.
The ship moves another 30 units in it's new direction D'.
Where is the ship's position P'' now?
[/quote]
D += PI/10 (Matrix Rotation Around U).
P" = P' + D * 30.


There is nothing tricky, fancy, or non-trivial happening here.
Just add and multiply things.


L. Spiro
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0