Jump to content


Photo

3D model staying on screen


  • Please log in to reply
7 replies to this topic

#1 Ashley Phoenix

Ashley Phoenix

    GMC Member

  • GMC Member
  • 319 posts
  • Version:Unknown

Posted 10 March 2012 - 08:59 PM

Well, I've looked around the forums of how to keep a gun in a fixed position on a screen and I've found loads of results but none of them are commented or say how to do it.

This is the code I'm using:
d3d_transform_set_identity();
d3d_transform_add_scaling(scale,scale,scale);
d3d_transform_add_rotation_x(x_rot-zdirection);
d3d_transform_add_rotation_y(y_rot);
d3d_transform_add_rotation_z(z_rot+direction);
d3d_transform_add_translation(x,y,z)
draw_set_color(c_white);
d3d_model_draw(gun_upper,+.66,+1.6,+2,upper)
//d3d_model_draw(2,x,y,0,background_get_texture(tex_red))
d3d_transform_set_identity();

Picture 1: Posted Image

Picture 2: Posted Image

If you need any more information just ask.

Oh and also, if you point out any code that could be improved, just let me know, thanks ;)

  • 0

#2 eafg2

eafg2

    GMC Member

  • GMC Member
  • 166 posts

Posted 10 March 2012 - 10:35 PM

I think the orgin in the model destroys everything for you,
the model rotates around the orgin and the orgin should be alined with the camera root.
  • 0

#3 Ashley Phoenix

Ashley Phoenix

    GMC Member

  • GMC Member
  • 319 posts
  • Version:Unknown

Posted 10 March 2012 - 10:38 PM

I think the orgin in the model destroys everything for you,
the model rotates around the orgin and the orgin should be alined with the camera root.


Well I've seen it done with other .obj models.

Any idea on how I could fix it.
  • 0

#4 eafg2

eafg2

    GMC Member

  • GMC Member
  • 166 posts

Posted 10 March 2012 - 11:10 PM

With a 3d program like Blender.
  • 0

#5 THE_GAME_EDITOR

THE_GAME_EDITOR

    GMC Member

  • GMC Member
  • 809 posts
  • Version:GM8.1

Posted 11 March 2012 - 01:48 PM

You could use gmmodelfix.
Very simple fix by clicking the three x,y and z buttons.
The buttons are called center on mass.

Edited by THE_GAME_EDITOR, 11 March 2012 - 01:48 PM.

  • 0

#6 Gamer3D

Gamer3D

    Human* me = this;

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

Posted 11 March 2012 - 04:06 PM

It's likely that you have code like this somewhere before you draw your model:

d3d_transform_add_scaling()
d3d_transform_add_rotation()
d3d_transform_add_translation()

To change the local origin of your gun without changing the model itself, use d3d_transform_set_translation() before the rest of the transformations.
  • 0

#7 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 11 March 2012 - 09:36 PM

It's likely that you have code like this somewhere before you draw your model:

d3d_transform_add_scaling()
d3d_transform_add_rotation()
d3d_transform_add_translation()

To change the local origin of your gun without changing the model itself, use d3d_transform_set_translation() before the rest of the transformations.


he got scaling.... So I would
d3d_transform_add_translation(0,0,5)
after the scaling and before the rotation.

where 5 would be 5 feet off the ground if 1 unit is a foot.

the gun will follow the rotations and final translation from that position

you have to draw the model with x,y,z set to 0,0,0 though.

The scaling would not be needed if the model had been pre scaled to the game with a 3rd party tool

the d3d_transform_add_translation(0,0,5) would not be needed if you used a 3rd party tool to set the origins to include this first transform. center the model then move it 5 units off the ground.
  • 0

#8 TheSnidr

TheSnidr

    That guy

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

Posted 11 March 2012 - 09:57 PM

You could also use a separate, fixed projection for the gun. Some rough pseudo-code:
set_projection(0,0,0, 1,0,0, 0,0,1) //A projection looking down the x-axis
draw_gun() //Draw the gun at its coordinate in the camera's local coordinate system

set_normal_projection()
draw_everything_else()
Game's looking good, and that's a nice weapon model

EDIT:
This is the method I used here (at about 01:50)

Edited by TheSnidr, 11 March 2012 - 10:02 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users