• 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
neogeocg

Making two vectors parallel

8 posts in this topic

Hello,
i am stuck at some basic xna math.I have two 3D vectors .The first vector is pointing in some direction and the second one is pointing in another direction.Now i want to make the second vector point in the same direction as the first one,hence making both vectors parallel.Please suggest a built in method in xna or a way i can accomplish this?.Thank you
0

Share this post


Link to post
Share on other sites
What do you mean by that? 2 vectors are parallel when they are proportionals, like (x, y, z) and (2x, 2y, 2z). just multiply the first by the factor of the length of both. Edited by Such1
1

Share this post


Link to post
Share on other sites
The question makes sense only if you're thinking vectors as being some kind of "entities" of their own identity. Therefore the (mathematically correct) answers given above can seem a bit silly.

If you want to rotate vector v1 so that it faces to the same direction of v2, you should do as Such1 said, and construct a new vector that points to the direction of v2, but has the length of v1, i.e. the vector you are looking for is
[code]
vector newVector = v2 * (v1.length / v2.length);
[/code]

Remember to take account the special case when v2.length == 0, if that can happen in your context.
0

Share this post


Link to post
Share on other sites
First of all ,Thank you for your replies.

I think I have made a mistake in describing my problem.Actually I am implementing a chase camera.I have two classes,the camera class and the object class(the 3D object the camera is chasing). Initially the camera is behind the object as some predefined offset.Now as I rotate the object its forward vector rotates along y-axis.In the camera class I have a camera position and a camera offset.The camera position is determined as "[b]camera position=object position+camera offset[/b]".Now in order to keep the camera always behind the object I want to rotate the offset so that its parallel to object forward and then to get the new position of the camera I use the above equation(with the new transformed offset).What I need is a way or built in function that rotates the offset to object's forward every time I rotate my object.Thank you

My vector math has become a little rusty over the years of "no practice".So plz bear with me:).Thank You for your help Edited by neogeocg
0

Share this post


Link to post
Share on other sites
I think it's just as others have described. The camera offset vector is the object's forward vector, normalized, negated (assuming the camera is "behind" the object) and then scaled by the desired distance between the object and the camera.
0

Share this post


Link to post
Share on other sites
[quote name='neogeocg' timestamp='1351602555' post='4995390'] "[b]camera position=object position+camera offset[/b]"
[/quote]

so, it'd look like: camera.position = object.position + object.forwardVector*(camera.offset.length/object.forwardVector.length);
1

Share this post


Link to post
Share on other sites
Thank you all for replying

"[b]slicer4ever[/b]" what you wrote worked but (even though the camera was behind the object) I had to explicitly add an offset value to the Y component of camera position to keep the camera up because it was at the same level as the object.I will really appreciate if you explain this "[b]camera.position = object.position + object.forwardVector*(camera.offset.length/object.forwardVector.length)[/b]" to me.Thank you
0

Share this post


Link to post
Share on other sites
Your object has a set of transformations, part of which indicates what direction it is facing. The code that slicer4ever present takes this facing direction (a vector is basically a direction) and calculates a new spot on the line that the direction describes, and places the camera there. The reason you had to translate your camera vertically is because the object's forward vector points forward only, so going backward along it will result in a camera location sitting on the same elevation as the object. To go above the object's head does require the vertical translation.

To break down that equation, you have the object's position. You have its forward-facing direction vector. Any point on the line defined by the vector can be calculated as an offset from the object's point. The generalized form for this is:

[code]
point = p1 + t*vector
[/code]

where t determines the distance from the point p1; in slicer4ever's post, t=camera.offset.length. This form assumes that the vector is unit length. If the vector is not unit-length, then you can divide t by the length of the vector (which is really actually the same as dividing vector by its length, which is the operation typically used to normalize a vector to unit length). Failing to normalize to unit length can result in the camera being either closer or further away than you expect it to be based on its offset.

Once you have the camera at the right distance behind the player, then you can translate the camera vertically to put it above.
2

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