| | |
fps troubles
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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.

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.
•
•
•
•
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
•
•
Join Date: Jan 2009
Posts: 23
Reputation:
Solved Threads: 3
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
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
•
•
Join Date: Jan 2009
Posts: 23
Reputation:
Solved Threads: 3
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.
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.
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
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.
hope that helps!
c++ Syntax (Toggle Plain Text)
#include "DarkGDK.h" void DarkGDK ( void ) { dbSyncOn ( ); dbSyncRate ( 60 ); SetCurrentDirectory ( "media" ); dbSetDisplayMode ( 1280, 768, 32 ); dbSetCameraRange ( 0.1f, 30000.0f ); // here is the viewing frustrum set to 0.1 dbLoadImage ( "texture.jpg", 1 ); dbLoadImage ( "detail.jpg", 2 ); dbSetupTerrain ( ); dbMakeObjectTerrain ( 1 ); dbSetTerrainHeightMap ( 1, "map.bmp" ); dbSetTerrainScale ( 1, 3.0f, 0.6f, 3.0f ); dbSetTerrainLight ( 1, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f ); dbSetTerrainTexture ( 1, 1, 2 ); dbBuildTerrain ( 1 ); dbPositionCamera ( 434, 42, -517 ); dbLoadObject ( "skybox2.x", 2 ); dbSetObjectLight ( 2, 0 ); dbSetObjectTexture ( 2, 3, 2 ); dbScaleObject ( 2, 5000, 5000, 5000 ); dbLoadObject ( "MP5.x", 3 ); // load the gun dbMakeVector3 ( 3 ); // i think this is the identity matrix. dbLoadMusic ( "ambiance.wav", 1 ); register float fCameraAngleX = 0.0f; register float fCameraAngleY = 0.0f; ///////////////////////////////////////////////////// // main loop // ///////////////////////////////////////////////////// while ( LoopGDK ( ) ) { dbControlCameraUsingArrowKeys ( 0, 2.0f, 0.3f ); if ( dbLeftKey ( ) ) dbMoveCameraLeft ( 0, 2.0f ); if ( dbRightKey ( ) ) dbMoveCameraRight ( 0, 2.0f ); register float fHeight = dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) ); dbPositionCamera ( dbCameraPositionX ( ), fHeight + 10.0f, dbCameraPositionZ ( ) ); fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.4f ); fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.4f ); dbXRotateCamera ( fCameraAngleX ); dbYRotateCamera ( fCameraAngleY ); dbPositionObject ( 3, dbCameraPositionX ( ) + 0.2f, dbCameraPositionY ( ) - 0.2f, dbCameraPositionZ ( ) ); // here is the spot that positions the gun. dbXRotateObject ( 3, dbCameraAngleX ( ) ); // here is the spot that rotates the gun dbYRotateObject ( 3, dbCameraAngleY ( ) ); // here to. dbSetObjectCull ( 3, false ); dbLoopMusic ( 1 ); dbSync ( ); } return; }
hope that helps!
![]() |
Similar Threads
- What make Vista bad? (Windows Vista and Windows 7)
Other Threads in the C++ Forum
- Previous Thread: Parallel Sort with STL
- Next Thread: how to convert Binary numbers to decimal numbers and decimal numbers to binary
Views: 1675 | Replies: 22
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return sort stream string strings struct studio system template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






