Skip to main content
gamedev.net
🔒 Locked

Desperate for Code: Angles.

Started by ExoEight May 26, 2002 at 3:24 AM 3 replies 200+ views
Original Post
ExoEight
ExoEight
I need the code for either one of these languages: Visual Basc 6 or Visual C++. If it''s possible, I could use it for both languages. This code I am desperate to obtain. This is what I need the code to do. Lets say you shoot a lazer beam into a mirror, the beam then reflects off of the mirror at a certain angle. How to I calculat this angle and make the lazer bounce off correctly at the angle? A better way to think of it would be a bullet hitting a wall and bouncing off. Does anyone know how to do this. All I need is the basic code, and 2d. Like a Pixle bouncing around inside of a Box or something like that. I really am desperate for this code, any help at all would be greatly appreciated, thanks in advance. -ExoEight
invective
invective
Does the level of desperation indicate a home work problem? Open up your physics book. For a perfect mirror the angle of incidence is equal to the angle of reflection reflected about the normal. ie just negate the incident vector and rotate it 180 degrees about the normal at the point of impact.
ExoEight
ExoEight
Honestly, this is no assignment you are doing for me, im just sick and tierd of not being able to solve this problem myself. I swear to you, and I will wait any period of time for the answer to prove it, just as long as i get is sometime. I really am curious at how to do this personally, despite my many attempts and failures i still tried, and kept failing, so now i come here. And as usual everyone thinks they are doing my homework which doesn't even exist..... *sigh*. How long do I have to wait to convince you that this isn't a due assignment?

Ive done enough reading, and I dont know physics, thats why i need the code. And i dont want any physics invovled, just geometry, i want a pixle steadily moving for ever, unless any key is pressed, bouncing around at one steady speed, no physics should be required for that.

[edited by - ExoEight on May 26, 2002 4:37:48 AM]
Alimonster
Alimonster
Well, you''ve already been given an answer above but I''ll clarify it: if you''re modelling a basic ''bouncing around in rectangle'', such as off the sides of the screen, then just negate your direction when the object hits the edge. For example:


  yourObject.x += yourObject.xSpeed;
yourObject.y += yourObject.ySpeed;

if (yourObject.x <= 0)
{
yourObject.x = 0;
yourObject.xSpeed = -yourObject.xSpeed;
}
if (yourObject.x >= SCREEN_WIDTH - 1)
{
yourObject.x = SCREEN_WIDTH - 1;
yourObject.xSpeed = -yourObject.xSpeed;
}
if (yourObject.y <= 0)
{
yourObject.y = 0;
yourObject.ySpeed = -yourObject.ySpeed;
}
if (yourObject.y >= SCREEN_HEIGHT - 1)
{
yourObject.y = SCREEN_HEIGHT - 1;
yourObject.ySpeed = -yourObject.ySpeed;
}
ExoEight
ExoEight
Thanks for the help on the matter, ill get to work on putting this code to good use. I must say, the forums here get some pretty damn fast responses.

Kick ass.

"Society through out history has seeked out scapegoats to blame for its problems, WELL HERE I AM!"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.