Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (5 posts)

Transform model face

Last post 5/22/2009 6:37 PM by Byron Nelson. 4 replies.
  • 5/22/2009 2:45 PM

    Transform model face

    Quick question,

    I need to transform a cube along a path in such a way that one side of the cube remains stationary while the other side continues to grow/stretch.

    Unfortunately, I've looked through all of the static Matrix methods and I'm coming up blank. Since I don't know how to describe what I'm trying to do mathematically google hasn't been much help either.

    Anything to push me in the right direction would be greatly appreciated.

    [EDIT] I just had an idea that maybe I could draw the faces manually by points... Still interested if anyone has any other ideas. [/EDIT]

  • 5/22/2009 4:54 PM In reply to

    Re: Transform model face

    I think what you want is MatrixCreateScale, but before you do that use a transform to move the origin to the edge that you want stationary.

    I don't mean to fanboy on my new favorite thing too much...  But you would be much happier with your results if you did the whole animation in Mod Tool, and then just set the animation index to get exactly what you wanted.
  • 5/22/2009 5:51 PM In reply to

    Re: Transform model face

    Moving it while scaling might just work. It might be tricky to figure out the move point in conjunction with the scaling, but it's an idea I hadn't thought of. Thanks.

    As for Mod Tool, I have a graphics guy and he's pretty much set on using Blender. Actually, I'm only learning XNA because he recently finished his degree in graphics design with an emphasis in games and he needed a codemonkey to help him build some stuff for his portfolio. I only agreed to help if I could choose the language/platform and picked XNA because I have a torrid love affair with C#.

    Thanks again,
  • 5/22/2009 6:31 PM In reply to

    Re: Transform model face

    I think you can do that with a cube model as well. Haven't tried it the following sounds like it should work.
    First you translate the cube until the face that you do not want to move during scaling is aligned with the world origin and coplanar with the two axis that will not be involved in the scaling, then you apply your scaling.

    That first translation basically transforms the vertices that make up the face you don't want the scaling on to have a zero component in the scaling axis. Then during scaling, anything times zero equals zero... no effect on those vertices.

    So if your cube is 3 by 3 by 3 and centered on the world origin & want to scale it only in the positive x direction.

    Matrix cubeWorld = Matrix.Identity;
    Matrix cubePreScale = Matrix.Identity;
    cubePreScale *= Matrix.CreateTranslation(new Vector3(1.5f,0,0));
    float myScale = 1f;

    //in the update method
    myScale += 0.1f;
    cubeworld = cubePreScale * Matrix.CreateScale(myScale, 1, 1);

    [edit] looks like GregA had the same idea.
  • 5/22/2009 6:37 PM In reply to

    Re: Transform model face

    I think you want to "extrued" the cube face along a path?

    I've done something like this in my game with a distorted cylinder that I used as a "warp" tube.  Its simple, or complicated, depending on how you look at it I guess.

    Make a cube with N slices.  (4 corners, but more than four vertices) that is 1 x 1 x 1 unit.

    Create an array of Vector3s, with as many elements as you have slices in your cube.  Each point represents a point along the path that you want to extrued your cube.

    Pass the array to a vertex shader.  There, for each vertex, lookup where it should be placed in the path based on the vertex's Z value.

    So for each vertex being processed, take the vertex while it is in its original state (before the world_view_projection multiplication). Translate the Z so that you have no negative Z values.  Multiply the vertex's Z by the size of the array and that is the index of the array of path positions for that vertex.   Add the Vector3 in that array to the vertex.

    Now, if you want the faces to follow the curve, that is, stay perpendicular to the path as they mover around it, you'll need to look at each position and the one behind it in the array, get the change in direction, create a rotation matrix,  and rotate the vertex accordingly.

    Once you do all that with the raw vertex, then process it as you normally would (i.e., do your world & world view projection transforms).

Page 1 of 1 (5 posts) Previous Discussion Next Discussion