5 Replies Latest reply on Jul 14, 2006 9:35 AM by Roofy

    Getting worldPosition of group of models

    Wriker
      Hi,

      I have troubles getting the position of a group of models. The group consists of a bunch of box models created with Lingo. Director documentation says I can use worldPosition with a group, but all it returns is vector(0,0,0). If I target a single model directly, it does return the correct vector.

      Is it not possible to get the worldPosition of a group of models, or am I missing something?
        • 1. Re: Getting worldPosition of group of models
          _lw Level 1
          the group is not automatically the average worldposition of all models you put in. you have to calculate the position of the group by hand before you put the models in.

          regards!
          • 2. Re: Getting worldPosition of group of models
            Wriker Level 1
            I was afraid of that, I guess I'm still thinking too much "in sprites".

            I think I'll best just get the worldPosition of one of the models in the group and do some math from there.
            • 3. Re: Getting worldPosition of group of models
              a¿ex
              you can group sprites ?
              :-)

              in fact the it is the naming, that may confuse.
              a group is a node, just like a model, a camera and a light. a node has a transform and a parent and an array of children.
              there are some other common properties of nodes like for example all of them have a property userdata.
              a group is just the minimum node type with no further "features". a model can have a modelresource as a feature and several properties, which determine how the modelresource gets rendered.
              that's it more or less.
              you could completely ignore groups and use models with void modelresources instead of groups. they act and behave exactly the same.
              but in no case it would make sense, if the transform of the group changed, depending on the transforms of its children.
              what you would want means, you move a child in the group and the position of the group in the world would magically change?
              You wouldn't have much fun with that, for sure.
              • 4. Re: Getting worldPosition of group of models
                Wriker Level 1
                What I was trying do to, by the way, is rotate the group of models around an axis that is on the outside of the group -- i.e. like opening a door. To open a door that opens to the left, I need an axis that is on the leftmost position of the door. If it opens to the right, the axis is on the right side.

                When working with sprites, you can easily get the leftpos or the rightpos of a sprite, but that's not so easy in 3-D. ;-)
                • 5. Re: Getting worldPosition of group of models
                  Roofy Level 1
                  quote:

                  Originally posted by: Wriker
                  What I was trying do to, by the way, is rotate the group of models around an axis that is on the outside of the group -- i.e. like opening a door. To open a door that opens to the left, I need an axis that is on the leftmost position of the door. If it opens to the right, the axis is on the right side.

                  When working with sprites, you can easily get the leftpos or the rightpos of a sprite, but that's not so easy in 3-D. ;-)


                  Acutally there is a simple way of doing this in 3d. There are 2 things you can do.

                  1. if you know where this outside of the group axis is located, then do this...

                  yourGroup.rotate(yourOutsideAxisPosition, whichAxisYouWantToRotateAbout, yourAngle)

                  2. if you do not know the outside position, then do this...
                  2a. before you do anything, and if you do not have 3DPI, I would recommend downloading it at http://www.3dpi-director.com/. In there you will find the link to download and also a link for the tutorials. Otherwise continue to the next step.

                  2b. create a new box in 3DPI, and then play with its position so that the new box is located to the position of where you want this some known outside position to be and note down the position where you have placed you new box. Note... this does not accually create the new box for you. You will need to put the below script that I give you to acually create the box.

                  2c. in your behaviour script that controls the rotation, place this following line of code at the very top of the behaviour script before any of the handlers that get called...

                  property pModel

                  2d. before accessing the rotation in your behaviour script, setup the following script inside your on beginSprite handler

                  --create a new modelresource and make the visabillty not to be viewable by setting the last argument to #none
                  mr = member("your3DMember").newModelResource("NameOfModelResource", #box, #none)
                  mdl = member("your3DMember").newModel("NameOfNewModel", mr)
                  mdl.trasnsform.position = the position that you have noted from 3DPI
                  pModel = mdl

                  2e. By doing the above script, you have created an invisable box that can be used as an axis like a door hinge. You would use its position in replace of the position of what is your outside of the group position like so...

                  yourGroup.rotate(pModel.transform.position, yourAxisYouWantToRotateAbout, yourAngle)

                  also note that the "yourAxisYouWantToRotateAbout" is a vector that says you either want the object to rotate along the x axis which would be set to vector(1, 0, 0), or along the yAxis which is set to vector(0, 1, 0), or along the z axis which is set to vector(0, 0, 1), or a combintation like so... example vector(1, 1, 0) will rotate an object along both the x and y axises.

                  HTH,
                  roofy