Jump to content


Photo

3d depth problem


  • Please log in to reply
12 replies to this topic

#1 whiteshadow

whiteshadow

    GMC Member

  • New Member
  • 29 posts
  • Version:GM8

Posted 20 October 2011 - 10:04 AM

hi

ive been using gm 3d for over a year now and i have a problem that i cant seem to fix and i have tried a lot of things and even looked through most of the 3d forums and tried it all out but nothing works. the problem is when the 3d model of a gun goes through the wall or other model and i know it is a common problem but nothing works for me.

i think it may be due to my draw codes:

my code for my player draw event is
{
{
if ads > 5
{
d3d_set_projection_ext(x,y,z+player_height,x+cos(direction*pi/180),y-sin(direction*pi/180),z-sin(pitch*pi/180)+player_height+v_jump,0,0,1,45-ads_zoom-plus_zoom,1.33,1,1100)
}
else
{
d3d_set_projection_ext(x,y,z+player_height,x+cos(direction*pi/180),y-sin(direction*pi/180),z-sin(pitch*pi/180)+player_height,0,0,1,45,1.33,1,1100)
}
}
}

and for my gun(separate object)
{

d3d_transform_set_identity();

d3d_transform_add_rotation_y((-obj_player.pitch_2+obj_player.stop_z_move)-(recoil*0.75))
d3d_transform_add_rotation_z(obj_player.direction);
d3d_transform_add_rotation_x(obj_player.x_rotation)

d3d_transform_add_scaling(0.5,0.5,0.5)
d3d_set_depth(-999)

d3d_transform_add_translation(obj_player.x,obj_player.y,obj_player.z+obj_player.player_height-obj_player.gun_height+obj_player.prone_height);

d3d_model_draw(global.model_gun_g3,9+recoil-obj_player.aim_move,(obj_player.x_move+obj_player.stop_x_move),-obj_player.aim_rise,background_get_texture(texture_gun_g3));
d3d_model_draw(global.model_gun_g3_slide,9+recoil+slide_move-obj_player.aim_move,(obj_player.x_move+obj_player.stop_x_move),-obj_player.aim_rise,background_get_texture(texture_gun_g3));
d3d_model_draw(global.model_gun_g3_magazine,9+recoil-obj_player.aim_move,(obj_player.x_move+obj_player.stop_x_move),-obj_player.aim_rise,background_get_texture(texture_gun_g3));

{

(other models are drawn here but to many to put on this )

}
}

if anyone knows a proper fix for this please share.

i know some people are probably going to say to use the search but before you do, i have many times.

thanks in advance

Edited by whiteshadow, 20 October 2011 - 10:59 AM.

  • 0

#2 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 20 October 2011 - 10:49 AM

You could render the gun to a surface then draw the gun before you draw your UI
  • 0

#3 whiteshadow

whiteshadow

    GMC Member

  • New Member
  • 29 posts
  • Version:GM8

Posted 24 October 2011 - 07:49 AM

You could render the gun to a surface then draw the gun before you draw your UI

If you mean drawing the gun as a 2d sprite then i cant do that as i already have my models working great.
If thats not what you meant then could you pleas tell me what you mean.

Thanks.
  • 0

#4 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 24 October 2011 - 01:55 PM

I ment that you render your gun as a 3d model on a 2d surface (if you have GM 8.1 or know how to use surface fix)

//creat event
gun_surface = surface_create(view_width, view_height)


//some where in the draw/step event
surface_set_target(gun_surface)
draw_clear_alpha(0, 0)
d3d_model_draw(gun_model, .... )
surface_target_reset()

//then right before you draw your UI
surface_draw(gun_surface, ... )
  • 0

#5 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14391 posts
  • Version:GM:Studio

Posted 24 October 2011 - 06:36 PM

The set_identity belongs at the END of your transformation and draw commands. not at the beginning.

Before drawing the gun, turn hidden OFF then draw then turn hidden back ON. And make sure it's the last thing to draw in the 3d world. That way the gun wont enter a wall.
  • 0

#6 whiteshadow

whiteshadow

    GMC Member

  • New Member
  • 29 posts
  • Version:GM8

Posted 25 October 2011 - 08:23 AM

ment that you render your gun as a 3d model on a 2d surface (if you have GM 8.1 or know how to use surface fix)

//creat event
gun_surface = surface_create(view_width, view_height)


//some where in the draw/step event
surface_set_target(gun_surface)
draw_clear_alpha(0, 0)
d3d_model_draw(gun_model, .... )
surface_target_reset()

//then right before you draw your UI
surface_draw(gun_surface, ... )


Ok thanks for the reply but i dont think im doing it right. There is nothing drawing when i tried this. Could you tell me in what object i need to put the 'draw_surface' in.

Before drawing the gun, turn hidden OFF then draw then turn hidden back ON. And make sure it's the last thing to draw in the 3d world. That way the gun wont enter a wall.

i have tried this before and it works but the model draws in a complete mess and isnt good in my game.
  • 0

#7 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14391 posts
  • Version:GM:Studio

Posted 25 October 2011 - 08:26 AM

Before drawing the gun, turn hidden OFF then draw then turn hidden back ON. And make sure it's the last thing to draw in the 3d world. That way the gun wont enter a wall.

i have tried this before and it works but the model draws in a complete mess and isnt good in my game.


Culling ON could fix that
  • 0

#8 whiteshadow

whiteshadow

    GMC Member

  • New Member
  • 29 posts
  • Version:GM8

Posted 25 October 2011 - 09:43 AM



Before drawing the gun, turn hidden OFF then draw then turn hidden back ON. And make sure it's the last thing to draw in the 3d world. That way the gun wont enter a wall.

i have tried this before and it works but the model draws in a complete mess and isnt good in my game.


Culling ON could fix that


i already have culling on but thanks anyway.
  • 0

#9 whiteshadow

whiteshadow

    GMC Member

  • New Member
  • 29 posts
  • Version:GM8

Posted 31 October 2011 - 09:42 AM

Ok so i retried this fix but i still cant seem to get it to work properly. If anyone has done this and got it to work properly then please help or if there is another way then please post a reply.

thanks.
  • 0

#10 Nehacoo

Nehacoo

    GMC Member

  • New Member
  • 180 posts
  • Version:GM8.1

Posted 31 October 2011 - 12:20 PM

If anyone has done this and got it to work properly

I guess I would fall within that category :P

What exactly is the issue? That the model shows up in the wrong place as you wrote in that topic? If so, what exactly do you mean by that - that it moves with the camera but is not in the right place on the screen, or that it's moving entirely separately from the camera and is all over the scene?
In the former case just adjust where the model is drawn: the x,y and z arguments of the d3d_model_draw() function. Otherwise make sure you draw the projection and the model in the same place, not the model at the player's coordinates and the projection at (0,0,0) or vice versa, for instance.
  • 0

#11 whiteshadow

whiteshadow

    GMC Member

  • New Member
  • 29 posts
  • Version:GM8

Posted 01 November 2011 - 08:14 AM

If anyone has done this and got it to work properly

I guess I would fall within that category :P

What exactly is the issue? That the model shows up in the wrong place as you wrote in that topic? If so, what exactly do you mean by that - that it moves with the camera but is not in the right place on the screen, or that it's moving entirely separately from the camera and is all over the scene?
In the former case just adjust where the model is drawn: the x,y and z arguments of the d3d_model_draw() function. Otherwise make sure you draw the projection and the model in the same place, not the model at the player's coordinates and the projection at (0,0,0) or vice versa, for instance.


ok thanks i never tried it that way and it works but with 1 slight problem. The model draws behind everything and i mean everything (except 1 random object for some reason). i dont realy know why but a little more help would be appreciated.

Thanks again. Whiteshadow
  • 0

#12 Nehacoo

Nehacoo

    GMC Member

  • New Member
  • 180 posts
  • Version:GM8.1

Posted 01 November 2011 - 01:16 PM

Make sure the object that draws the gun projection and model has the lowest depth in the scene (aside from ortho projections). Then play around with the znear and zfar arguments of the gun's projection, in particular make sure to set the znear as high as you can get it before it clips the model.

Edited by Nehacoo, 01 November 2011 - 03:48 PM.

  • 0

#13 PivotGamer84

PivotGamer84

    GMC Member

  • New Member
  • 170 posts

Posted 07 November 2011 - 02:24 AM

Set the depth of the object that is rendering the object to a ridiculously low value.

D3D works with layers, so to speak.

It renders objects in order of depth, meaning that an object with a high depth will appear to be behind an object with a lower depth. It's similar to the regular 2D depth used for isometric games.

If you set your camera object (or which ever object renders the gun) to a depth of, say -10000, it will render last meaning it will render over objects that render with a higher depth.

If your camera object doesn't render your gun, and some other object does, be sure to set the camera's depth to be lower than the rendering object's depth, otherwise it will mess up and likely cause projection problems.

Intermediate-tip:
Render your FPS in this order:
- Other objects
- Player items/equips/weapons
- Camera projection
- GUI/HUD

Also be sure to set the perspective mode to true if you alter the depths, otherwise your game may change the projection or make it act weird.

Edited by PivotGamer84, 07 November 2011 - 02:46 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users