Jump to content
  • Advertisement
Sign in to follow this  
dwfait

Mirror an angle?

This topic is 3643 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey. Say I have an object coming in at say 45 degrees to a surface above it, it will bounce off at a mirrored angle. I guess my question is, what would the formula be to work this out? And would I need a different one for a vertical surface? A different one for a different direction? I'm making a simple breakout game and obviously would like to make the ball bounce.

Share this post


Link to post
Share on other sites
Advertisement
In the case of breakout the ball is interacting with only vertical and horizontal surfaces. This is a good thing because we can employ a simple trick to calculate the reflected vector.

Lets say the ball's direction vector is <x,y>.

That vector reflected off of a horizontal surface is is <-x, y>
That vector reflected off of a vertical surface is is <x, -y>

Share this post


Link to post
Share on other sites
Are you just using horizontal and vertical surfaces? If so, just negate the horizontal velocity when hitting a vertical surface, and negate the vertical velocity when hitting a horizontal surface.

Share this post


Link to post
Share on other sites
At the moment I'm just using an angle and calculating the x and y real time, is there a way to just use the angle?


Also, what would be the formula for a slanted / diagonal surface?

Share this post


Link to post
Share on other sites
Quote:
Original post by dwfait
At the moment I'm just using an angle and calculating the x and y real time, is there a way to just use the angle?


Also, what would be the formula for a slanted / diagonal surface?


It wont be possible until you familiarize yourself with the concept of a direction vector.

Share this post


Link to post
Share on other sites
Well I am familiar with vectors. Not sure why I picked to work with angles really. I've converted the code to have a double vectorX and a double vectorY, to be multiplied by a double moveSpeed variable. So all I would do is -vectorY for horizontal and -vectorX for vertical?


How would I go about diagonal / slanted surfaces? Would I need the angle of the surface?

Share this post


Link to post
Share on other sites
Quote:
Original post by dwfait
Well I am familiar with vectors. Not sure why I picked to work with angles really. I've converted the code to have a double vectorX and a double vectorY, to be multiplied by a double moveSpeed variable.


I'm not sure what you're referring to as the "angle" here. Those sound like vectors to me.

Quote:
Original post by dwfait So all I would do is -vectorY for horizontal and -vectorX for vertical?


Yes, for simple reflections off of horizontal and vertical planes.

Quote:
Original post by dwfait
How would I go about diagonal / slanted surfaces? Would I need the angle of the surface?


You would need the normal vector of the surface. This will work in 2 or 3 dimensions:

I_R = I - 2*(N dot I) cross N

I is your incident vector, I_R is your resulting reflected vector and N is the normal to the surface the incident vector is reflecting off of.

Share this post


Link to post
Share on other sites
Quote:
Original post by fpsgamer
Quote:
Original post by dwfait
Well I am familiar with vectors. Not sure why I picked to work with angles really. I've converted the code to have a double vectorX and a double vectorY, to be multiplied by a double moveSpeed variable. So all I would do is -vectorY for horizontal and -vectorX for vertical?


How would I go about diagonal / slanted surfaces? Would I need the angle of the surface?


You would need the normal vector of the surface. This will work in 2 or 3 dimensions:

I_R = I - 2*(N dot I) cross N

I is your incident vector, I_R is your resulting reflected vector and N is the normal to the surface the incident vector is reflecting off of.




Would I be right in thinking that the Normal is the vector of the line that is perpendicular to the surface?

Share this post


Link to post
Share on other sites
Quote:
Original post by dwfait
Would I be right in thinking that the Normal is the vector of the line that is perpendicular to the surface?


Yup. IIRC is must also be unit length.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!