how can i code this and put it in yours? i tried droping behavior "dragModel" from director's library to make it move toward and away from camera, but i still need to lock the value of z. many thanks mike [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => just_mik3 [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 3 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> how to strict the movement? - Macromedia Director 3D

how to strict the movement? - Macromedia Director 3D

i got this behavior from a tutorial on web. i drag and drop it to my 3d member, and it works great. i can move the model i clicked anywhere on the sprite. however, i need to strict the movement to x and y axis. can anyone please tell me how to do this? this is the code: property spriteNum property myTopLeft -- loc of top left corner of sprite(spriteNum) property myCamera -- sprite(spriteNum).camera property myModel -- the model the user clicked on property myDelta -- offset between the clickLoc and the apparent -- loc of the cone model on ...

  1. #1

    Default how to strict the movement?

    i got this behavior from a tutorial on web.
    i drag and drop it to my 3d member, and it works great.
    i can move the model i clicked anywhere on the sprite.
    however, i need to strict the movement to x and y axis.
    can anyone please tell me how to do this?

    this is the code:

    property spriteNum
    property myTopLeft -- loc of top left corner of sprite(spriteNum)
    property myCamera -- sprite(spriteNum).camera
    property myModel -- the model the user clicked on
    property myDelta -- offset between the clickLoc and the apparent
    -- loc of the cone model


    on beginSprite(me)
    tSprite = sprite(spriteNum)
    tMember = tSprite.member

    myTopLeft = point(tSprite.left, tSprite.top)
    myCamera = tMember.camera(spriteNum)

    -- Ensure that the colorBuffer.clearValue is maintained
    tClearValue = myCamera.colorBuffer.clearValue
    tSprite.camera = myCamera
    myCamera.colorBuffer.clearValue = tClearValue
    end beginSprite



    on mouseDown(me)
    tSpriteLoc = the mouseLoc - myTopLeft -- loc relative to sprite
    tModel = myCamera.modelUnderLoc(tSpriteLoc)

    if ilk(tModel, #model) then
    myModel = tModel
    tLoc = myCamera.worldSpaceToSpriteSpace(tModel.worldPosit ion)
    myDelta = tSpriteLoc - tLoc
    end if
    end mouseDown



    on exitFrame(me)
    if ilk(myDelta, #point) then
    if the mouseDown then
    me.mMoveCone()
    else
    myDelta = VOID
    myModel = VOID
    end if
    end if
    end exitFrame



    on mMoveCone(me)
    -- Find where the mouse is relative to the sprite
    tSpriteLoc = the mouseLoc - myTopLeft
    tSpriteLoc = tSpriteLoc - myDelta -- correct for the centre of model

    -- Find myModel and myCamera in the 3D world
    tModelLoc = myModel.worldPosition
    tCameraLoc = myCamera.worldPosition

    -- Find a (distant) point beneath the mouse, in the world
    tDistantLoc = myCamera.spriteSpaceToWorldSpace(tSpriteLoc)

    -- Create an imaginary line between the user's eye and this point
    tRay = tDistantLoc - tCameraLoc
    -- We need to work with a vector whose length is 1 unit
    tRay.normalize()

    -- Determine which axis the camera is looking along
    tCameraAxis = myCamera.getWorldTransform().zAxis

    -- Do a little mathematics, based on the fact that the dotProduct of
    -- two perpendicular vectors is zero.
    tVector = tModelLoc - tCameraLoc
    tDistance = (tVector * tCameraAxis) / (tRay * tCameraAxis)
    tLoc = tCameraLoc + (tRay * tDistance)

    -- Move the model
    myModel.worldPosition = tLoc
    end mMoveCone

    -----------
    regards,
    mike

    just_mik3 Guest

  2. #2

    Default Re: how to strict the movement?

    I recognise that code!

    Are you asking:

    a) How do I make the model move only along the plane where z = <the current
    value of z>?
    OR
    b) How do I prevent the model from moving more than a certain distance
    horizontally and vertically?

    Answer (a) could mean that the model moves towards and away from the camera if
    the camera is not looking directly down the z-axis.

    openspark Guest

  3. #3

    Default Re: how to strict the movement?

    I don't think i understand this camera concept yet.
    "camera is looking directly down the z-axis" is like this?

    <camera>
    V(direction of camera)

    | z-axis A(movement direction{towards camera})
    | [model]
    | V(movement direction{away from camera})
    |_________ x-axis
    /
    /
    /
    y-axis
    if i set the camera position like that above, and i move it towards and away
    from the camera, then the model will move up and down of the surface(floor).
    Just like the ASCII drawing(or something like that).

    if i lock the value of z with "z = <the current value of z>"
    will it still move like that in the drawing?
    "z = <the current value of z>"--->how can i code this and put it in yours?
    i tried droping behavior "dragModel" from director's library to make it move
    toward and away from camera, but i still need to lock the value of z.

    many thanks
    mike


    just_mik3 Guest

  4. #4

    Default Re: how to strict the movement?

    sorry, the ASCII drawing is ed up.
    i hope u understand what i meant.
    just_mik3 Guest

  5. #5

    Default Re: how to strict the movement?

    Perhaps you could post a mini storyboard sketch somewhere on the web, to explain graphically what you are looking for.
    openspark Guest

  6. #6

    Default Re: how to strict the movement?

    Hi,
    to constrain the movement in just the x and y axis, let the code do it's work
    and touch up the model movement code a little

    Instead of:
    -- Move the model
    myModel.worldPosition = tLoc

    do something like this:
    -- Move the model
    myModel.worldPosition.x = tLoc.x
    myModel.worldPosition.y = tLoc.y


    I don't know if this really works, I'm just giving you something to think about

    take care
    -kyriakos

    kterz Guest

  7. #7

    Default Re: how to strict the movement?

    thank you kterz.
    I tried the code and it worked, but i'm having 2 new problems.
    Every first time i try to move an object, my director goes to "not responding"
    state for about 15 seconds or less. Same thing happen when i stop the movie.
    It's kind a hard to describe my second problem in words. So taking openspark's
    advice, i'm going to post a mini storyboard. I haven't done it yet but i'll do
    it tomorrow and let you know.

    regards,
    mike.

    just_mik3 Guest

  8. #8

    Default Re: how to strict the movement?

    hi mike,
    are you using any other code on exitframe besides the one that you have posted?
    Try to use the [on idle] handler instead of the [on exitframe] to see if this
    solves your problem.
    What version of Director are you using?
    What vga card do you have?


    kterz Guest

  9. #9

    Default Re: how to strict the movement?

    Hi,i'm sorry i haven't finished my storyboard yet. Hopefully, it can be done in
    few days.
    Using the code you gave me, how can i use it to move a group?Is that
    possible?Or if i make the parent-child thing of a set of models, how can i move
    tho whole hierarchy if i click and drag one of its child?
    About my previous problem, i tried to use [on idle] but nothing changed.
    i don't use any other exitframe
    i'm using Director MX 2004
    my VGA card is ATI Radeon 9600

    regards,
    mike

    just_mik3 Guest

  10. #10

    Default Re: how to strict the movement?

    hi again,
    hierarchy is maintained throughout the mesh exporting process. I use 3dsmax,
    and when i export a parent model and it's children, when i move my parent model
    in director the other objects just follow.
    Here are the steps:
    1) Create a parent object (e.g. a box)
    2) Create some child objects and link them to the parent.
    3) Export the mesh into a w3d file (be sure to check the "Scenegraph
    Hierarchy" option when exporting)
    4) Import the w3d file and run your movie

    If you try and move the parent object, normally the children will follow

    You can also try to group your mesh (with group or Edit Mesh) so director will
    import it as a single object.

    hope that was helpful
    -k

    kterz Guest

  11. #11

    Default Re: how to strict the movement?

    Hi kterz,
    Thank you for replying. Is there anyway to move the whole hierarchy when i
    click on a child?Or how can i find out which parent does a child model belong
    to?So that when i click and drag a child, i can move the parent of it.
    I can't group the models and export it, because i still need to change the
    texture of particular models in the group.
    When i tried to change the texture of a grouped model, only the first object
    that i created will be chaged.
    For example, i made 2 boxes, by default it would be named
    box01
    box02
    next, i grouped these boxes and named it [boxes].
    when i assigned a texture to the shader of that group in the director, only
    the box01 will be changed. i was expecting that it would change both box01 and
    box02.
    i hope i don't bother you with this kind of questions. i'm new to lingo and i
    rarely see a director's book that cover programming 3d with lingo in my country
    especially that doesn't exceed my funding limitation.

    regards,
    mike

    just_mik3 Guest

  12. #12

    Default Re: how to strict the movement?

    Mike,
    If you need the parent object to move when the children are moved, you can use
    lists in Director to control the behaviour of any object.
    An example of this is that you can set a list for every model, to include the
    models that you want to move when moving it. Check out the "userData" 3d
    property in the director help system. It's an internal list that can be kept
    for every model in your scene that you can use to do what you want.

    here is an example of adding a property to a model's userdata:

    member(?scene?).model(?ParentBox01?).userData.addP rop(#modelsUnderInfluence,["Ch
    ild01","Child02","Child03"]])
    you must do this to any model that you want to influence other models

    if you do a:
    put member(?scene?).model(?ParentBox01?).userData
    you will get the custom property that you have created.

    So using the getaprop function you can access the properties at any time:
    modelsToMove = getaProp(gW.model("ParentBox01").userData,
    #modelsUnderInfluence)
    put modelsToMove

    now, when you move a model using your custom model movement script, you can
    write extra code to also move the other models with a repeat loop.
    e.g:
    repeat with i = 1 to modelsToMove.count
    --move each model here using:
    member("Scene").model(modelsToMove).transform.posi tion = blahblahblah
    end repeat

    hope that was helpful, even though i can't think straight at the moment due to
    the lack of coffee :)
    if you need any clarification, please do not hesitate to ask
    cheers
    -kyriakos

    kterz Guest

Similar Threads

  1. Problem with XHTML Strict
    By e_scott in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: June 19th, 10:13 PM
  2. Use strict with plperl
    By Mike G. in forum PostgreSQL / PGSQL
    Replies: 1
    Last Post: January 17th, 04:10 PM
  3. Use Strict Error
    By Bill Jastram in forum PERL Beginners
    Replies: 2
    Last Post: January 23rd, 03:26 PM
  4. use strict and filehandles
    By B McKee in forum PERL Beginners
    Replies: 2
    Last Post: January 21st, 05:04 PM
  5. Using strict references
    By Todd Bair in forum PERL Miscellaneous
    Replies: 7
    Last Post: August 21st, 09:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •