Archived

This topic is now archived and is closed to further replies.

FPS Weapon Rendering

This topic is 5334 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

I want to render the players current weapon to screen (fps style) and am having a few problems. I have my cameras position vector and look vector and am trying to render the weapon model in the correct place in the scene using these. However i think that maybe i should be looking at changing the projection and perhaps tackle the problem that way. Has anyone done this and if so how. Any thoughts would be most welcome.

Share this post


Link to post
Share on other sites
well obviously i don''t want the identity matrix when i render cause the weapon will move around the world with the camera. I have been experimenting with rendering the weapon using the camera''s vectors as the starting point with limited success (rotations start playing havoc). I''m pretty sure that the best solution will involve altering the projection when i render it but i''m not exactly sure how.

Share this post


Link to post
Share on other sites
if the weapon is modeled so that it is at (0,0,0) and pointing down the negative z axis, then as long as u have the identity matrix loaded, just translate to, say, (0,0,-5), depending on how big the model is and where exactly u want it on the screen.

Share this post


Link to post
Share on other sites
OK i have solved my problem and it works fine but this has really been bugging me. It shouldn''t work. If i load the identity matrix and render then the object should be rendereed at the origin not at the cameras current position, why does it work?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Because you are under the impression that you are really moving through a "world" when it is really the world moving around you. The "camera" never moves, it is always at the origin.

Share this post


Link to post
Share on other sites
I thought that gluLookAt setup the model view matrix so that the scene will be rendered from the cameras perspective but the origin is not at the camera point. I am sure this is right.

Share this post


Link to post
Share on other sites
In openGL, there is no REAL camera. yes, u do see things thorough a viewpoint, but when u ''move'' this viewpoint/''camera'' u''re really moving EVERYTHING the opposite direction than intended. So when u''re turning right, the objects are really turning left relative to your viewpoint.

wat gluLookAt does is it simplifies the specification of this so called camera. Try this: instead of using gluLookAt, u do the glRotate* and glTranslate* urself to simulate the ''camera'' movements. Heck, its not impossible, but it aint something u would want to keep doing coz personally, i rather like it clean. So gluLookAt does all the actual dirty work for you.

also, objects are positionally rendered disregarding actual framebuffer information. meaning, when u translate an object to (10, 0, -10) and render it, u get a translated object. But right after that, if u load an identity matrix, the translation is negated so all following objects are rendered relative to the origin = viewpoint position. So unless u translate the objects again, any subsequent rendering may actually ''overlap'' other objects already rendered in the framebuffer. Remember, if its position u wanna talk about, its all in the transformation.

Share this post


Link to post
Share on other sites
Yes but the origin does not lie at the camera position. You can ''place'' the camera at (0, 1000, 0) using gluLookAt and render something at 0,0,0. The rendered object will not be rendered at the camera''s position rather it will be rendered 1000 units down the Y axis. Whereas if i places the camera at 0,1000,0 then glLoadIdentity() then render the object at 0,0,0 it will be rendered at the camera''s current position.

Share this post


Link to post
Share on other sites
hrm.. tough one this. when u use gluLookAt to ''position'' the camera at (0, 1000, 0), u''re really telling OpenGL to render everything else at (0, -1000, 0) onwards. its true the ''virtual'' origin is at (0, 0, 0) and the camera is in the ''virtual'' systems position of (0, 1000, 0). the whole reason a LoadIdentity places stuff at the camera is because the ACTUAL origin is still at the camera irrespective of ur transformation. the whole camera-model is just a way for us to perceive view transformation in a more humanly sense, but when it involves resetting the matrices and all, knowing this fact comes in handy.

Share this post


Link to post
Share on other sites
quote:
Original post by LordShade
Render as you normally would but be sure to shut off the Z-buffer else your weapon will stick into walls and other geometry.


Turning the z-buffer off is not a good idea, because the z ordening of your 3d weapon object will get in trouble. The right thing to do is to clear the z-buffer after rendering the scen and thén rendering the object wíth z-buffer on.

Share this post


Link to post
Share on other sites
as craze said (he''s right u know) there is no camera.
the camera is an abstract concept for 3d.
to see what i mean:
lets say ur head is the origin.
look at a point on a wall.
move ur head to the left.
what do u see? the point is more to the right now. but the origin cant move so that means that the point moved.
thats what opengl does.

the weapon will always point forwards even if u are facing the point on the wall or if u are facing opposite from it because using an identity matrix, it will not be rotated or translated like the point, get what i mean?

if u want to move the weapon around a little to make the effect of running with it just rotate it around the x axys increasing the angle every frame.

Share this post


Link to post
Share on other sites
to make it even easier: it absolutely doesnt matter what is moving in which direction, because loading the identity will reset the matrix and will make it completely unimportant what glulookat did to the matrix earlier. if you insist on your camera, then identity will reset the camera also.

Share this post


Link to post
Share on other sites