Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Camera Issues


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 dakeeper1995   Members   -  Reputation: 109

Like
0Likes
Like

Posted 05 October 2012 - 07:25 AM

Hey guys, first post here.

I have a slight problem with my camera right now. When I press the right or left keys (A/D), the screen jumps in that direction(by a lot more then just the key press), movement goes as planned, and when the key is released the screen jumps back to where it would've been. Here's the relevant pieces of code:

The message loop:
while( msg.message != WM_QUIT )
			{
			   if ( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
				{
					 if (msg.message==WM_KEYDOWN) OnKeyDown(msg.wParam);
					 else if (msg.message==WM_KEYUP) OnKeyUp(msg.wParam);
					 else{
						 TranslateMessage( &msg );
						 DispatchMessage( &msg );
					  }
				 }
			  
				 else Render();
			  }

void OnKeyDown(WPARAM key){
	 switch (key){
		  case 0x41:
				 ak=TRUE;
				 break;
		   case 0x53:
				 sk=TRUE;
				 break;
		  case 0x44:
				  dk=TRUE;
				  break;
		  case 0x57:
				  wk=TRUE;
				   break;
		   default:
					break;
	 }
}
void OnKeyUp(WPARAM key){
   switch (key){
	   case 0x41:
			  ak=FALSE;
			  break;
	   case 0x53:
			   sk=FALSE;
			   break;
	   case 0x44:
				dk=FALSE;
				 break;
	   case 0x57:
				wk=FALSE;
			   break;
		default:
				break;
   }

}

if (ak==TRUE) EyePt-=sideVector;
if (sk==TRUE) EyePt-=CurrentView
if (dk==TRUE) EyePt+=sideVector;
if(wk==TRUE) EyePt+=CurrentView;

I'm working on implementing a camera class, but right now I'm very confused as to why my camera jumps whenever the A/D buttons are pressed. SOrry for the messy coding.

Edited by dakeeper1995, 05 October 2012 - 07:34 AM.


Sponsor:

#2 Cornstalks   Crossbones+   -  Reputation: 6991

Like
1Likes
Like

Posted 05 October 2012 - 07:59 AM

I don't see anything obviously wrong from this code. What does your message handler do?

You can try setting break points for when a key is pressed/released and stepping through your program so you can watch values change and see if they are what they should be.
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#3 BCullis   Crossbones+   -  Reputation: 1813

Like
2Likes
Like

Posted 05 October 2012 - 09:59 AM

A few other questions:

Where is sideVector defined/updated (in case it does get modified) and what is it initialized to?

How is EyePoint used in the rendering process?

Does EyePoint get reset anywhere in the render process or outside this message loop at all?
Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

#4 dakeeper1995   Members   -  Reputation: 109

Like
1Likes
Like

Posted 05 October 2012 - 02:26 PM

I figured it out by myself actually. Sorry, I didn't provide more code because I cannibalized a whole bunch of projects together and, seeing as I'm new to programming, I doubt anyone could've understood what most of it was (I have very bad programming conventions)

In case anyone was wondering (or had/have the same problem), I calculated my look at point (D3DXMatrixLookAtLH pAt) before keyboard input changed pEye. My view matrix was passed to DirectX afterwards, so there was a small jump on my screen.

Solved by placing the four "if(...)EyePt..." lines before calculating pAt.

Thanks for the replies.

Edited by dakeeper1995, 05 October 2012 - 02:29 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS