Modelling moving parts on models

This is a discussion on Modelling moving parts on models within the Game Programming forums, part of the General Programming Boards category; Finally got farely decent at Blender and have quite a few nice looking ships. I would like to put some ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596

    Modelling moving parts on models

    Finally got farely decent at Blender and have quite a few nice looking ships. I would like to put some moving parts on them but I'm not sure how to do it. I know how to do it in code but I don't know how to go from editor to code.

    I tried using bones but the influence of them is too large and I really do not need vertices to change position in the context of skinning. The parts on my ships are not skinned and do not affect any other portions of the model.

    Since I'm currently using D3DXMesh one of my ideas is to make each moving part a subset of the mesh but I also need transformation information which I simply do not have in the standard x file format.

    Any ideas?

    Here is a pic of the model in the mesh viewer util. Still no textures since I really suck at making them.
    Last edited by VirtualAce; 03-12-2011 at 10:41 AM.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    [Hate] Blender... [/Hate]

    Not sure how to do it when you want to the relationship to carry over to .x files, but the normal way to do this would be by using groups (assuming you are trying to add rockets or something?)

  3. #3

    Join Date
    May 2005
    Posts
    1,041
    Wait I'm a little bit confused about what you are asking. This seems to be a Blender specific question, am I right?

    but the normal way to do this would be by using groups (assuming you are trying to add rockets or something?)
    I agree, for this is how I do this using Milkshape3D, e.g. a propeller, which spins depending on how fast the engine is going, moves separately from the rest of the vehicle. Each group ends up being its own mesh, and each mesh has its own local transformation matrix relative to the absolute transformation of the model.
    Last edited by BobMcGee123; 03-12-2008 at 07:37 AM.
    I'm not immature, I'm refined in the opposite direction.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Ok Bob so in your example you simply make the propeller a group of vertices in the model program? So I guess when you save the mesh the model program also saves the position of the propeller? So would you create a separate mesh called propeller and position it in the model program and then save the entire model? Or do you make the propeller a group of vertices within the entire model mesh?

    I'll try this and see what happens. I'm eagerly awaiting a copy of 3DS Max so when I get it, it will help a lot.

  5. #5

    Join Date
    May 2005
    Posts
    1,041
    So would you create a separate mesh called propeller and position it in the model program and then save the entire model?
    Yes, this is what I do.
    I'm not immature, I'm refined in the opposite direction.

  6. #6

    Join Date
    May 2005
    Posts
    1,041
    Here's a picture demonstrating this. The model is just hacked-together pieces from a jeep model I found online, I added the propeller, nothing fancy it's just to test functionality of the code. In terms of data structures this model is made up of 7 meshes, each of which has its own local transformation matrix. There is another matrix which contains the transformation of the entire model in absolute coordinates.

    I also compute the radius, bounding box and center the mesh. The center is with respect to the center of the model in design coordinates (the center of the entire model is computed, and all vertices are adjusted such that in design coordinates the center is the origin). You must know the center of the mesh to have the propeller properly spin. According to matrix concatenations I have to translate the propeller back to the origin, rotate it about it's z axis based on angular velocity, then translate it back to its original position. When rendering the entire model there is a matrix for the entire model, and each mesh's local matrix is concatenated with that (by the OpenGL matrix stack...this could be the start of a basic scene graph). Here's the Render() hook for a Hovercraft (just hacked together for now), the hook meaning that nothing is actually rendered here, just the appropriate data is added to the renderer and held until the final rendering is done (all together).

    Note that I use 'my own' file format. Milkshape3D (.ms3d) files are optimized for saving file space, whereas my files are optimized for rendering (tightly-packed data structures). My files are subsequently about %30 larger, and called .ntmdl (Nuclear Toaster Model).

    Code:
    void	Hovertank::Render()
    {
    //	DebugPrintFloat("inputs",this->inputs,gpTextManager);
    //	DebugPrintInt("prop index",this->pNTModel->GetMeshByGroupComment("propeller"),gpTextManager);
    	if(gpFrustum->SphereInFrustum(CurrentState.mPosition,mRadius))
    	{
    		Matrix4x4	final_render_mat;
    		
    		final_render_mat	=	CurrentState.mMat_Orientation;
    		final_render_mat.SetTranslation(&CurrentState.mPosition);
    
    		Matrix4x4	rotation,translation_inverse,translation;
    		translation.SetTranslation(&prop->DEBUG_CENTER);
    		translation_inverse.SetTranslation( &(prop->DEBUG_CENTER *-1) );
    		rotation.InitFromAngles(0,0,this->propellor_angle);
    
    		
    		prop->local_mat = translation * rotation * translation_inverse;
    	//	DebugPrint4x4Matrix("prop_local",prop->local_mat,gpTextManager);
    
    		pNTModel->mat = final_render_mat;
    
    		gpGLRenderer->AddNTRenderModelToRenderer(*pNTModel);
    	}
    }
    Attached Images Attached Images  
    Last edited by BobMcGee123; 03-13-2008 at 02:59 PM.
    I'm not immature, I'm refined in the opposite direction.

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Thanks all I'm gonna give it a go and try some stuff to see what happens. I was on the right track but just needed a nudge in the right direction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  2. moving median function
    By supermeew in forum C Programming
    Replies: 0
    Last Post: 05-04-2006, 02:37 PM
  3. Need help with drawing Multiple models?
    By salman86 in forum Game Programming
    Replies: 9
    Last Post: 08-07-2005, 12:59 PM
  4. 3D moving
    By bluehead in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2005, 04:46 AM
  5. removing parts of an image?
    By pode in forum Game Programming
    Replies: 6
    Last Post: 12-18-2002, 05:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21