fps troubles

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 382
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

fps troubles

 
0
  #1
Jan 26th, 2009
before i ask this question i want you to keep in mind that i am asking it in general, and i also want a general answer

i am making a 3d first person shooter and i want to know how i would go about getting a gun infront of the camera, making it look like the player is holding the gun, like in other fps games, i dont want any code or recomendations to any engines or anything like that, just the theory of how to do it, i can figure out the rest.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,662
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: fps troubles

 
0
  #2
Jan 26th, 2009
>>i am making a 3d first person
what is that? I've heard of a 1st person shooter, but 3d???
Last edited by Ancient Dragon; Jan 26th, 2009 at 9:00 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 23
Reputation: _adam_ is an unknown quantity at this point 
Solved Threads: 3
_adam_ _adam_ is offline Offline
Newbie Poster

Re: fps troubles

 
0
  #3
Jan 26th, 2009
Ancient Dragon: I think he's talking about a 3d game of the first person shooter game type.

tomtetlaw: If you have the gun rendering already, simply align the model with the direction of the camera, slightly offset the position of it and you should be away.

Best of luck!

Adam
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 382
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: fps troubles

 
0
  #4
Jan 26th, 2009
Originally Posted by _adam_ View Post
Ancient Dragon: I think he's talking about a 3d game of the first person shooter game type.

tomtetlaw: If you have the gun rendering already, simply align the model with the direction of the camera, slightly offset the position of it and you should be away.

Best of luck!

Adam
i try that, but i can never get the gun to look right, the camera goes through the gun, the gun rotates to the other side of the camera, but what i am really asking is it just a matter of positioning/rotating it right?
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 23
Reputation: _adam_ is an unknown quantity at this point 
Solved Threads: 3
_adam_ _adam_ is offline Offline
Newbie Poster

Re: fps troubles

 
0
  #5
Jan 26th, 2009
First up, have you tried reducing the near plane distance to say 0.1 instead of 1.0, this should reduce clipping?

The alignment problem you're having needn't be one. Here's what you need to do for drawing the weapon:

1. Load the Identity matrix (back to basic transforms here).
2. Translate the weapon slightly into the scene (In opengl you'd translate in the direction of the negative-z axis, in directx the positive)

When you can see the gun in front of you...

3. Translate the weapon down ever so slightly (I'm guessing you're using y-up so -y, but only a small amount)

Finally...

4. Translate the weapon in the x-axis by a small amount depending on which hand you'd like the gun to be in.

Hope this helps.
Adam
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 382
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: fps troubles

 
0
  #6
Jan 27th, 2009
what is near plane distance? and what is identity martix?
Last edited by tomtetlaw; Jan 27th, 2009 at 12:10 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 23
Reputation: _adam_ is an unknown quantity at this point 
Solved Threads: 3
_adam_ _adam_ is offline Offline
Newbie Poster

Re: fps troubles

 
1
  #7
Jan 28th, 2009
Ok, first of all you need to understand what the view frustum is. The view frustum is a volume of 3D space that will contain vertex data that will later be rendered to the screen.

Simply put, the near plane is the closest point that models can be 'seen', the far plane is the furthest point that models can be 'seen' by the camera.

This page should give you a basic idea what this is (check out the image!).

Next, as you're unsure of what a identity matrix actually is, I'm guessing you don't know about matrices.

The best example I can give without going into specifics is that the identity matrix it the transformation that is applied to the vertices that will apply no translation or rotation (i.e. no change).

If you intend to get into 3D graphics programming you're going to need to learn vector and matrix mathematics.

A book I recommend for this is: "3D math primer for graphics and game development" by Fletcher Dunn and Ian Parberry..

I'd also have a look for some 'beginning' books in whatever graphical API you're using.

Also, I'd check out a lot of the free tutorials you'd be able to find through your favourite search engine.

As one last thing, check out the beginnners forums at gamedev.net for games and graphical specific help.

As far as getting the hang of 3D graphics, it can be a lot of fun, but there will be a lot of work to go with it.

Best of luck,
Adam.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 30
Reputation: Richy321 is an unknown quantity at this point 
Solved Threads: 0
Richy321 Richy321 is offline Offline
Light Poster

Re: fps troubles

 
0
  #8
Jan 28th, 2009
Also on a side note, alot of fps's hide the actual player model and then have seperate higher detailed models for the arm/gun specially for the first person view. This will obviously solve most clipping problems as well.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: fps troubles

 
0
  #9
Jan 28th, 2009
Originally Posted by Richy321 View Post
Also on a side note, alot of fps's hide the actual player model and then have seperate higher detailed models for the arm/gun specially for the first person view. This will obviously solve most clipping problems as well.
This will not be a solution to clipping issues, the near viewing plane reduction is the fix to the clipping issue. rendering different objects does nothing to what the camera can see
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 382
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: fps troubles

 
0
  #10
Jan 29th, 2009
i did everything you said and it is almost fixed but i still have the problem with the gun rotating rong. heres my code so you can see althouhg i doubt it will help since its in DarkGDK but i will comment it.
  1. #include "DarkGDK.h"
  2.  
  3. void DarkGDK ( void )
  4. {
  5. dbSyncOn ( );
  6. dbSyncRate ( 60 );
  7.  
  8. SetCurrentDirectory ( "media" );
  9.  
  10. dbSetDisplayMode ( 1280, 768, 32 );
  11.  
  12. dbSetCameraRange ( 0.1f, 30000.0f ); // here is the viewing frustrum set to 0.1
  13.  
  14. dbLoadImage ( "texture.jpg", 1 );
  15. dbLoadImage ( "detail.jpg", 2 );
  16. dbSetupTerrain ( );
  17. dbMakeObjectTerrain ( 1 );
  18. dbSetTerrainHeightMap ( 1, "map.bmp" );
  19. dbSetTerrainScale ( 1, 3.0f, 0.6f, 3.0f );
  20. dbSetTerrainLight ( 1, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f );
  21. dbSetTerrainTexture ( 1, 1, 2 );
  22. dbBuildTerrain ( 1 );
  23.  
  24. dbPositionCamera ( 434, 42, -517 );
  25. dbLoadObject ( "skybox2.x", 2 );
  26. dbSetObjectLight ( 2, 0 );
  27. dbSetObjectTexture ( 2, 3, 2 );
  28. dbScaleObject ( 2, 5000, 5000, 5000 );
  29.  
  30. dbLoadObject ( "MP5.x", 3 ); // load the gun
  31. dbMakeVector3 ( 3 ); // i think this is the identity matrix.
  32.  
  33. dbLoadMusic ( "ambiance.wav", 1 );
  34.  
  35. register float fCameraAngleX = 0.0f;
  36. register float fCameraAngleY = 0.0f;
  37.  
  38. /////////////////////////////////////////////////////
  39. // main loop //
  40. /////////////////////////////////////////////////////
  41.  
  42. while ( LoopGDK ( ) )
  43. {
  44. dbControlCameraUsingArrowKeys ( 0, 2.0f, 0.3f );
  45. if ( dbLeftKey ( ) )
  46. dbMoveCameraLeft ( 0, 2.0f );
  47. if ( dbRightKey ( ) )
  48. dbMoveCameraRight ( 0, 2.0f );
  49.  
  50. register float fHeight = dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) );
  51. dbPositionCamera ( dbCameraPositionX ( ), fHeight + 10.0f, dbCameraPositionZ ( ) );
  52.  
  53. fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.4f );
  54. fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.4f );
  55.  
  56. dbXRotateCamera ( fCameraAngleX );
  57. dbYRotateCamera ( fCameraAngleY );
  58. dbPositionObject ( 3, dbCameraPositionX ( ) + 0.2f, dbCameraPositionY ( ) - 0.2f, dbCameraPositionZ ( ) ); // here is the spot that positions the gun.
  59. dbXRotateObject ( 3, dbCameraAngleX ( ) ); // here is the spot that rotates the gun
  60. dbYRotateObject ( 3, dbCameraAngleY ( ) ); // here to.
  61.  
  62. dbSetObjectCull ( 3, false );
  63.  
  64. dbLoopMusic ( 1 );
  65.  
  66. dbSync ( );
  67. }
  68.  
  69. return;
  70. }

hope that helps!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 1675 | Replies: 22
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC