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

2D reflection

6 posts in this topic

Believe me.... I've googled this. But I don't have a math background. I'm trying to understand how Vector2.Reflect works (in XNA to be specific). What is a normal, in plain (plane lol) english and how do you apply it? If an object is approaching a tile, let's say. Its CollisionBox will be overlapping the tile next frame. How do I calculate the bounce?
0

Share this post


Link to post
Share on other sites
A normal is either:

A) a vector with length 1 ( V * (1.0/V.Length) = normal )
B) a vector that forms an angle of 90 degree with the surface
0

Share this post


Link to post
Share on other sites
Wikipedia has got something to say about reflections -- including a nice picture:



From the name Vector2 I assume you're asking about reflection in two dimensions. Your "mirror" in this case is the surface you're reflecting from.
0

Share this post


Link to post
Share on other sites
A normal is a vector that is perpendicular to another vector or surface. A normalized vector is a vector with length 1. The terms are a little confusing, but they are very different. Most normal vectors are normalized, just because it makes calculations easier.

This Wolfram article helps explain reflection vectors. This Wolfram article explains normal vectors. This Wikipedia page explains a normal vector (a.k.a. surface normal) in relatively clear English terms.

Basically if you have a vector v, which represents the object's velocity, and a normalized normal vector n, which is perpendicular to the surface with which the object collides, then the new velocity v' is given by the equation:

v' = 2 * (v . n) * n - v;

Where '*' is the scalar multiplication operator, '.' is the dot product of two vectors, and '-' is the subtraction operator for two vectors. v is reflected off of the surface, and gives a reflection vector v' which is used as the new velocity of the object.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by MikeTacular
A normal is a vector that is perpendicular to another vector or surface. A normalized vector is a vector with length 1. The terms are a little confusing, but they are very different. Most normal vectors are normalized, just because it makes calculations easier.

This Wolfram article helps explain reflection vectors. This Wolfram article explains normal vectors. This Wikipedia page explains a normal vector (a.k.a. surface normal) in relatively clear English terms.

Basically if you have a vector v, which represents the object's velocity, and a normalized normal vector n, which is perpendicular to the surface with which the object collides, then the new velocity v' is given by the equation:

v' = 2 * (v . n) * n - v;

Where '*' is the scalar multiplication operator, '.' is the dot product of two vectors, and '-' is the subtraction operator for two vectors. v is reflected off of the surface, and gives a reflection vector v' which is used as the new velocity of the object.


how do you find n? let's say the wall is at an angle of 87 degrees (in vector form).
0

Share this post


Link to post
Share on other sites
There are two ways to find a normal:

1) If you have the angle the normal makes with the horizontal (like the picture below), the normal vector N can be found using a little trig.

N.x = -sin(87); // be sure to convert to radians though!
N.y = cos(87);

Using this method, N will already be normalized (have a length of 1) because of the properties of sin and cos.




2) If you don't have the angle, but instead two points that define a line segment, you can use another method. If a line segment is defined by points A and B, then the direction of the line segment is the line going from point A to point B, or in other words, the direction of the line segment can be found by doing B - A. Let's define vector v = B - A. The vector which is perpendicular to v will also be perpendicular to line segment AB. In 2D, it is very easy to find a vector perpendicular to another vector. The formula is:

// P stands for Perpendicular Vector, and is perpendicular to vector V
P.x = -v.y;
P.y = v.x;

// Since N is perpendicular to AB, and so is P, we can say that N = P, or in other words:
N.x = -v.y;
N.y = v.x;

Now we just need to resize vector N so it has a length of 1. To do this, we divide each component of vector N by N's total length. This is called normalizing the vector.

float length = std::sqrt(N.x * N.x + N.y * N.y);
N.x /= length;
N.y /= length;

And done! Now you have a normal vector N perpendicular to line segment AB.



If you notice, the equation for the coordinates of a circle are:

x = cos(theta);
y = sin(theta);

This is the equation I used in method 1). Notice that in method 2), I say that a perpendicular vector can be found by swapping the components of a vector and multiplying x by -1. See something similar in both methods?

Remember this is for 2D, but the same principles can easily be extended to 3D.
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