PDA

View Full Version : plz help me(opengl/fps game)



djoker
04-12-2006, 08:21 PM
HI ppl...

my 2 attached guns draw above the terrain ...with this happens? :cry:
the guns is attached 2 camera ,fps style


http://img159.imageshack.us/img159/4992/probrv6.th.jpg (http://img159.imageshack.us/my.php?image=probrv6.jpg)

http://img159.imageshack.us/img159/1061/prob2pp2.th.jpg (http://img159.imageshack.us/my.php?image=prob2pp2.jpg)





function Convert_2D_To_3D(x,y:integer):TD3DVector;
var
modelM : TMatrix4d;
projectM: TMatrix4d;
bx,ex,ey,ez,
by,
bz: GLdouble;
viewport: TVector4i;
NEAR_Z:gldouble;
RayBegin:TD3DVector;
begin
NEAR_Z:=1.0;
glGetDoublev(GL_PROJECTION_MATRIX, @projectM );
glGetDoublev(GL_MODELVIEW_MATRIX, @modelM);
glGetIntegerv(GL_VIEWPORT, @viewport );
gluUnProject(X, viewport[3]-y ,0.0,modelm, projectm, viewport,@bx,@by,@bz);
raybegin:=Make3DVector(bx,by,bz);
NEAR_Z:=0.965;// dist 2 camera
gluUnProject(X, viewport[3]-y ,NEAR_Z,modelm, projectm, viewport,@ex,@ey,@ez);
result:=Make3DVector(ex,ey,ez);
end;

--------------------------------------------------------
//update camera
DivCamera_Update(0);
DivCamera_MouseLook(0);

// get the ray from screen space to 3D Space
gun1:=Convert_2D_To_3D(800 div 2+280,600 div 2+ 250);
gun2:=Convert_2D_To_3D(800 div 2-280,600 div 2+ 250);

//draw terrain and water
DivTerrain_Render;
DivWaterPlane_Draw(0);




// draw gun 1
DivEntities_Render(0,timegettime/1000);
DivEntities_Yaw(0, 180-DivCamera_GetRX);
DivEntities_Pitch(0,+(DivCamera_GetRY-90));
DivEntities_Position(0,gun2.x,gun2.y,gun2.z);

// draw gun 2
DivEntities_Render(0,timegettime/1000);
DivEntities_Yaw(0, 180-DivCamera_GetRX);
DivEntities_Pitch(0,+(DivCamera_GetRY-90));
DivEntities_Position(0,gun1.x,gun1.y,gun1.z);

WILL
04-12-2006, 08:39 PM
Well I can't help you with your immediate problem, but I can certainly help you get help.

:arrow: First thing, either use the 'Help!' forum for stuff you are absolutely stuck on. But don't just post stuff there that you can do with a little more effort. Experienced individual hate that and will not want to help you that much or simply ignore you altogether.

:arrow: Also you might want to post to the forum category you are actually talking about. (Graphics, Omega, MIDletPascal, etc) At first glance I had no idea what your problem was related to, so my ability to think that I could help you was swiftly taken away.

:arrow: Lastly... "Help me" sounds like begging. It might as well be "please oh please dear god and all that is righteous save me" for all I'm concerned. I'll maybe then only look because it made me laugh. :) Give the subject line something descriptive. My biggest pet-peeve (irritant) is having to rename someone else's thread Subject line because they didn't give it even half a thought before posting. I think your subject line should be made as 'OpenGL sort order problem'. Or maybe 'guns being covered by terrain' or why not 'guns covered' at least.


I hope this help you at least in your seeking of knowledge if nothing else. Please let me know what your intentions are and I'll move this thread to a move appropriate category.

Cheers and good luck! ;)

djoker
04-12-2006, 09:12 PM
ok ... sory and i fix the prob :oops:
i understand what you say .. i help lots of friends but this is
get my nerves out im stuck on this prob about 3 days ...


ps:sory about my inglish

WILL
04-12-2006, 09:22 PM
It's ok. The English is not a problem. Just what I mentioned above. ;)

Since you seem really stuck on this problem I'll place it in the Help forum. Just remember these things for next time you post.

Oh and I was posting as you changed the subject title so didn't notice that. I'd not have made mention of that had I noticed. :)

djoker
04-12-2006, 09:49 PM
tks dude but i solve the prob... i have 2 ways 2 do this


1 way is set the gun very cose 2 the camera and
the 2 way is trasform with Identity camera matrix

when we are not relax do this kind of c****

tks wil 1 more time ;)

K4Z
04-12-2006, 10:11 PM
Drawing the gun really close to the camera may not completely fix the problem. You may want to actually draw the gun in front of everything else, by changing the DepthRange.

Mabye something like this:


glDepthRange(0, 0.1); //Always draw on top of world
DrawGunModel;
glDepthRange(0.1, 1);

DrawScene;

JSoftware
04-12-2006, 11:13 PM
or just disable depth test if if you draw the guns last

DrawWorld;
glDisable(gl_depth_test);
DrawGun;
glEnable(gl_depth_test);

Kaz, I don't see how your solution makes sense. Wouldn't you sacrifice a heckload of depth precision doing that and clip the scene further away from the camera?

K4Z
04-12-2006, 11:23 PM
I use glDepthRange more so just for control, and allowing you to draw out of order :P.

I just typed in the code that I wrote there, not sure the exact values, but in using glDepthRange, I havn't noticed any loss or clipping.

But I guess just disabling the Depth Test would be a lot easier for a simple task :wink:

Huehnerschaender
04-12-2006, 11:59 PM
In DirectX you would just disable the z-buffer when drawing the gun... I think this gl_depth_test might be the same...

NecroDOME
05-12-2006, 12:18 AM
2 options to solve...

1. Scale down your guns and place them closer to cam
2. Clear z-buffer...

Huehnerschaender
05-12-2006, 07:24 AM
a second thought about this brings me to the conclusion that the best solution is scaling down the weapon to the size it really has in realworld. then attach it very close to the camera as if camera were your eyes and the weapons were in your hands. you will get problems with the weapons otherwise, because they are much too big (like a house). how would you place the shooting fire if the guns are moving? how would you apply a lightsource to the weapons model etc. all this will not work correct if the gun is big like in your screen.

Crusare
11-12-2006, 09:32 AM
I would recommend you - as I recommend to anyone having problems with basic OpenGL features, to use GLScene (www.glscene.org). Easy to use, no problems there, and you may use the given examples. :D