Public Group

# Few problems

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

## Recommended Posts

1) Bouncing objects off surfaces. I just want some help with the maths side on how to get the new x and y speeds after the bounce... The object is represented by 4 varibles x,y, SpeedX, SpeedY I have not decided on how to represent the surfaces... For horizontal and verticle surfaces I know I can just reverse the speeds but what of other angles?
Vertical:   SpeedX *= -1;
Horizontal: SpeedY *= -1;

2) Is "Var *= -1" the best way to revears the sign? 3)Input Ive been catching the windows input messages to fill an input buffer and then copy that into the main input varibles at the start of each update step. Is this really the best way?
//window proc...

//KEYBOARD
case WM_KEYDOWN:
if(!KeyboardBuffer[wParam][0])KeyboardBuffer[wParam][1] = true;
KeyboardBuffer[wParam][0] = true;
KeyboardBuffer[wParam][3] = true;
break;

case WM_KEYUP:
KeyboardBuffer[wParam][0] = false;
KeyboardBuffer[wParam][2] = true;
break;
//MOUSE
case WM_LBUTTONDOWN: MouseBuffer[0][0] = true;  MouseBuffer[0][1] = true; break;
case WM_LBUTTONUP:   MouseBuffer[0][0] = false; MouseBuffer[0][2] = true; break;
case WM_MBUTTONDOWN: MouseBuffer[1][0] = true;  MouseBuffer[1][1] = true; break;
case WM_MBUTTONUP:   MouseBuffer[1][0] = false; MouseBuffer[1][2] = true; break;
case WM_RBUTTONDOWN: MouseBuffer[2][0] = true;  MouseBuffer[2][1] = true; break;
case WM_RBUTTONUP:   MouseBuffer[2][0] = false; MouseBuffer[2][2] = true; break;


void InputUpdate()
{
int i1, i2;
for (i1 = 0; i1 < 3; i1++)
{
Mouse[i1][0] = MouseBuffer[i1][0];
for (i2 = 1; i2 < 3; i2++)
{
Mouse[i1][i2] = MouseBuffer[i1][i2];
MouseBuffer[i1][i2] = false;
}
}

POINT MousePoint;
if(GetCursorPos(&MousePoint))
{
ScreenToClient(cgm::hwnd, &MousePoint);
MouseX = MousePoint.x;
MouseY = MousePoint.y;
}
for (i1 = 0; i1 < 256; i1++)
{
Keyboard[i1][0] = KeyboardBuffer[i1][0];
Keyboard[i1][3] = KeyboardBuffer[i1][3];
KeyboardBuffer[i1][3] = false;
for (i2 = 1; i2 < 3; i2++)
{
Keyboard[i1][i2] = KeyboardBuffer[i1][i2];
KeyboardBuffer[i1][i2] = false;
}
}
}



##### Share on other sites
1) You'll want to start by finding the angle between your motion and the surface normal (http://en.wikipedia.org/wiki/Surface_normal). Once you have that, a little trig will give you a much better approximation of bouncing.

2) No. The more readable (and therefore better) way is "Var = -Var".

3) Is there any reason your windows input proc isn't just calling InputUpdate() directly? You could pass along the original buffer instead of copying it.

Have fun...

##### Share on other sites
Quote:
 Original post by sox3) Is there any reason your windows input proc isn't just calling InputUpdate() directly? You could pass along the original buffer instead of copying it.

That can cause some nasty issues. It's better to always process the input at the same time each frame.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631415
• Total Posts
2999964
×