Some simple 3D model building help

kupo15

Member
I've wanted to dabble into 3D a little bit and understand the basics of working in it for the most part. I'm having a bit of trouble grasping some concepts with models though. Are you able to rotate primatives during the model creation process or are the d3d_rotation functions only able to be used when drawing? For example this isn't rotating the cylinder to form a crossbar

Code:
// Create
net_model = d3d_model_create();

d3d_model_cylinder(net_model,-80,-2.5,75,-75,2.5,0,1,1,true,20); // left post
d3d_transform_set_rotation_z(90)
d3d_model_cylinder(net_model,-20,-2.5,160,-15,2.5,0,1,1,true,20); // cross bar
d3d_transform_set_rotation_z(0)
d3d_model_cylinder(net_model,75,-2.5,75,80,2.5,0,1,1,true,20); // right post

// draw
d3d_model_draw(net_model,x,y,z,-1);
Secondly with this, I purposely offset the crossbar's z axis instead of centering it as you can see by the 0's in the Z slot. I assume this is how it will allow me to rotate it at the end or should I be setting up my models always centered and shift the origin for rotation another way?

 
Last edited:
E

elementbound

Guest
The d3d_transform_* functions only apply to drawing.
 
Z

zircher

Guest
Check out the Draw 3D in the help file. So, in your draw event for the object that is your 3d model, you'll have something like this...

Code:
  d3d_start();
  d3d_set_perspective(true);
  d3d_set_hidden(true);
  d3d_set_culling(true);

  draw_set_color(c_white);
  d3d_set_lighting(true);
  d3d_light_enable(0,true);

  d3d_transform_set_identity();
  d3d_transform_add_rotation_z(-cnt);
  d3d_transform_add_translation(x,y,z);
  d3d_model_draw(selectRing,0,0,0, -1);
  d3d_transform_set_identity();     
  d3d_end(); // if this is the only thing you're doing in 3d, otherwise comment this out.
Also, you'll want something like this since you're wanting to create three models during the create event.
net_left = d3d_model_create();
net_right = d3d_model_create();
net_cross = d3d_model_create();

d3d_model_cylinder(net_left,-80,-2.5,75,-75,2.5,0,1,1,true,20); // left post
d3d_model_cylinder(net_cross,-20,-2.5,160,-15,2.5,0,1,1,true,20); // cross bar
d3d_model_cylinder(net_right,75,-2.5,75,80,2.5,0,1,1,true,20); // right post

And then you'll do your set identity(s), rotations, and translations, in the draw event. Hope that helps.
 
actually, you can use d3d_transforms to rotate a vertex, which you can then use to construct your model

put this code somewhere and see the result

d3d_transform_set_rotation_z(45);
vect = d3d_transform_vertex(1,0,0);
show_message(vect);

result:
{{0.71, -0.71, 0.00 }, }
 
Last edited:

kupo15

Member
The d3d_transform_* functions only apply to drawing.
I was afraid of that
Check out the Draw 3D in the help file. So, in your draw event for the object that is your 3d model, you'll have something like this...

Code:
  d3d_start();
  d3d_set_perspective(true);
  d3d_set_hidden(true);
  d3d_set_culling(true);

  draw_set_color(c_white);
  d3d_set_lighting(true);
  d3d_light_enable(0,true);

  d3d_transform_set_identity();
  d3d_transform_add_rotation_z(-cnt);
  d3d_transform_add_translation(x,y,z);
  d3d_model_draw(selectRing,0,0,0, -1);
  d3d_transform_set_identity();    
  d3d_end(); // if this is the only thing you're doing in 3d, otherwise comment this out.
Also, you'll want something like this since you're wanting to create three models during the create event.
net_left = d3d_model_create();
net_right = d3d_model_create();
net_cross = d3d_model_create();

d3d_model_cylinder(net_left,-80,-2.5,75,-75,2.5,0,1,1,true,20); // left post
d3d_model_cylinder(net_cross,-20,-2.5,160,-15,2.5,0,1,1,true,20); // cross bar
d3d_model_cylinder(net_right,75,-2.5,75,80,2.5,0,1,1,true,20); // right post

And then you'll do your set identity(s), rotations, and translations, in the draw event. Hope that helps.
Thanks, yea that is what I found also but isn't all that work with creating separate models really only needed if you are going to have it move and animate? This net isn't going to move so my plan was to make drawing super simply by constructing it in the create and simply drawing a single model
actually, you can use d3d_transforms to rotate a vertex, which you can then use to construct your model

put this code somewhere and see the result

d3d_transform_set_rotation_z(45);
vect = d3d_transform_vertex(1,0,0);
show_message(vect);

result:
Interesting, I'll look into this. In the meantime don't you think the best method to do this is to create the whole bar section as one piece using 3D primitives? How would I begin to try and draw a 3d cylinder using primitives though if that is a better method?
 
Z

zircher

Guest
Yeah, even if you don't do the rotation or scaling, you need to do the transform to position it in the scene. So, something like that has to be in the draw event for the object that has the 3D model as part of it.
 

kupo15

Member
Yeah, even if you don't do the rotation or scaling, you need to do the transform to position it in the scene. So, something like that has to be in the draw event for the object that has the 3D model as part of it.
I'm curious, what really is the point of using the translation functions at all? Why can't I just manipulate the movement using the draw event? For example:

Code:
// CREATE
// model-specific:
body_model = goalie_body;
body_texture = -1;
body_color = c_white;
// offset:
body_pos_x = 0;
body_pos_y = 0;
body_pos_z = 60;
// rotation:
body_rot_x = 0;
body_rot_y = 0;
body_rot_z = 0;
// parent bone:
body_parent = -1;

// DRAW
// draw the body
d3d_transform_stack_push();
d3d_transform_add_translation(body_pos_x,body_pos_y,body_pos_z);
d3d_transform_add_rotation_x(body_rot_x);
d3d_transform_add_rotation_y(body_rot_y);
d3d_transform_add_rotation_z(body_rot_z);

d3d_model_draw(body_model,x,y,z,body_texture);
d3d_transform_stack_pop();
The transform_functions aren't doing anything. The body isn't appearing 60 up using this but if I do
d3d_model_draw(body_model,x,y,z+60,body_texture);

it does. I'm really not sure why the transform_ functions aren't translating the model. What's stopping me from just not using them? I'm trying to follow @YellowAfterlife 's bone tutorial to build the goalie model with questionable success
 
Z

zircher

Guest
Did you add the d3d_transform_set_identity(); commands before and after the draw block? I normally don't use the stack, but that's just the way I learned it.
 

kupo15

Member
Nothing at all.
Are you confirming my suspicion that all of those d3d_transformations are useless and pointless functions that cause more trouble then they are worth and I literally can just stick with using draw functions instead? I will be so happy if that is the case...

I can see how any translation codes might be useless but am not sure how you would rotate things without the rotation transformation codes

Did you add the d3d_transform_set_identity(); commands before and after the draw block? I normally don't use the stack, but that's just the way I learned it.
Nope, but then again that code doesn't appear anywhere in Yellow's tutorial and yet it still manages to work somehow.
http://yal.cc/gamemaker-basic-3d-bone-animations/

Edit: I realized why it wasn't translating, I was stupid and wasn't finished with another code which overwrote the values to z so it works. I am still curious if the translation function is really necessary at all though or if I could just handle it in the draw_model line. I should be able to right?
 
Last edited:

kupo15

Member
Ha! I wouldn't say that. I was just saying there is nothing stopping you from using an alternate method, if you have one.

I use the d3d_transform_* functions all the time.
This is really frustating...I can't get anything to work. When I try adding a z rotation to rotate it around its origin it rotates around somewhere else and moves away...doesn't matter if I use the _identity function either. Is there any good tutorials you know of that can look at to try and figure this out? Its pretty sad that even a simple z rotation is a struggle
 

kupo15

Member
interesting..well I tried putting the translation at the end and it still didn't work. Would you mind giving it a quick look to see what I'm doing wrong? I barely started the project so there shouldn't be much to comb through. I have that strange keyboard code in the draw_goalie script merely to just try to test to get the rotation working. Ideally I would like it to be tied in with the dir var which controls the direction the goalie is facing. And movement works via a controller

https://www.dropbox.com/s/bbwwmmlax1lquvx/Goalie Prototype.gmz?dl=0
 

kupo15

Member
yea that's exactly what I gather as well, it is rotating but translating also. Glad it isn't just me...does it work correctly if you use what you are used to instead of the model? At this point I'm just trying to get a basic shape to move and rotate correctly
 
what happens when you do this?

Code:
d3d_transform_stack_push();
d3d_transform_add_rotation_x(body_rot_x);
d3d_transform_add_rotation_y(body_rot_y);
d3d_transform_add_rotation_z(body_rot_z);
d3d_transform_add_translation(x,y,body_pos_z);
d3d_model_draw(body_model,0,0,0,body_texture);
d3d_transform_stack_pop();
the coordinates you supply into the draw function will be transformed by the current matrix.
(so if we've moved the origin to the position where the goalie is supposed to be located, we want to draw him at position 0,0,0.
 

kupo15

Member
what happens when you do this?

Code:
d3d_transform_stack_push();
d3d_transform_add_rotation_x(body_rot_x);
d3d_transform_add_rotation_y(body_rot_y);
d3d_transform_add_rotation_z(body_rot_z);
d3d_transform_add_translation(x,y,body_pos_z);
d3d_model_draw(body_model,0,0,0,body_texture);
d3d_transform_stack_pop();
the coordinates you supply into the draw function will be transformed by the current matrix.
(so if we've moved the origin to the position where the goalie is supposed to be located, we want to draw him at position 0,0,0.
Wow dude that actually works! I think I immediately understood what was wrong when I saw your post because my code was still half based on that tutorial which had the object centered around 0,0,0. Mine is not centered there so it was rotating it around 0,0,0 I think

Thank you so much!!! :D

Quick follow up, since this is the body when he bends over he obviously won't be rotating around his center but the bottom of the model since that is his waist...what needs to be changed to reflect this?

d3d_model_draw(body_model,0,0,60,body_texture); ?? I tried it and it works so that has to be it haha
 
Last edited:

kupo15

Member
Quick question: When is the best time to use models? Is it mainly best to use for complicated static objects and not movable humanoids for example? Would it be best to simple use normal draw functions with d3d_set_identity?

I'm wondering if I'm making things harder for myself by using models
 
Top