Jump to content
  • Advertisement
Sign in to follow this  
Sync Views

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.

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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by sox
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.


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

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!