Professional Web Applications Themes

3D movement and collision queries - Macromedia Director 3D

I have a 3D box that I want to move a camera around the inside of, using mousedown on sprites. I want the camera to pan left/right, pan up/down, and move in/out (to te a zoom). I have a bit of script where I set up the 3D environment, and below is the code that I have attached to the 3D member, which is triggered by a left button clicks on each sprite. I've mixed the lingo together from different bits of scripts. The camera pans left/right/up/down, but it doesn't 'dolly' in/out. Can someone show me where I'm going wrong? ...

  1. #1

    Default 3D movement and collision queries

    I have a 3D box that I want to move a camera around the inside of, using
    mousedown on sprites. I want the camera to pan left/right, pan up/down, and
    move in/out (to te a zoom).

    I have a bit of script where I set up the 3D environment, and below is the
    code that I have attached to the 3D member, which is triggered by a left button
    clicks on each sprite. I've mixed the lingo together from different bits of
    scripts. The camera pans left/right/up/down, but it doesn't 'dolly' in/out. Can
    someone show me where I'm going wrong?

    property pGroupName
    property pPanAmount
    property pDollyAmount
    property pAlerted
    property pCamera
    property pCameraOriginTransform
    property pCenter
    property pInitialized
    property pMember
    property pMemberStateOK
    property pQueuedTriggeredEvents
    property pRect
    property pSprite
    property p3dMember
    property pCameraSphere


    on beginSprite(me)

    p3dMember = sprite(me.spriteNum).member
    pSprite = sprite(me.spriteNum)
    pMember = pSprite.member
    pMemberStateOK = me.isMemberStateOK()
    pCamera = pSprite.camera

    if pMemberStateOK then
    pInitialized = me.initialize()
    else
    pInitialized = FALSE
    end if

    p3dMember = sprite(me.spriteNum).member
    pCamera = pSprite.camera

    pAlerted = FALSE

    camSphereRes = p3dMember.newModelResource("camSphereRes",#sphere)
    camSphereRes.radius = 20
    pCameraSphere = p3dMember.newModel("cameraSphere",camSphereRes)
    pCamera.addChild(pCameraSphere,#preserveParent)
    p3dMember.registerForEvent(#timeMS,#controlCamera, me,2000,50,0)

    end beginSprite


    on endSprite(me)

    if pInitialized then
    pCamera.transform = pCameraOriginTransform
    end if

    end endSprite


    on enterFrame(me)

    if pMemberStateOK then

    if pInitialized then

    if pQueuedTriggeredEvents.count > 0 then

    repeat with j = 1 to pQueuedTriggeredEvents.count
    tEvent = pQueuedTriggeredEvents[j]

    case tEvent of
    #panCameraUp:
    me.panCamera(pPanAmount, 0, 0)
    #panCameraDown:
    me.panCamera(-pPanAmount, 0, 0)
    #panCameraLeft:
    me.panCamera(0,pPanAmount, 0)
    #panCameraRight:
    me.panCamera(0,-pPanAmount, 0)
    #dollyCameraIn:
    me.dollyCamera(0,0,-pDollyAmount)
    #dollyCameraOut:
    me.dollyCamera(0,0,pDollyAmount)
    end case

    end repeat

    pQueuedTriggeredEvents = []

    end if

    else
    pInitialized = me.initialize()
    end if

    else
    pMemberStateOK = me.isMemberStateOK()
    end if

    end enterFrame


    on registerEvent(me, aEvent, aTriggerSpriteNum, aTargetBehaviorInstance)

    if pInitialized then
    if me = aTargetBehaviorInstance then

    tHandler = [#panCameraUp: "Pan Camera Up",\
    #panCameraDown: "Pan Camera Down",\
    #panCameraLeft: "Pan Camera Left",\
    #panCameraRight: "Pan Camera Right",\
    #dollyCameraIn: "Move Camera In",\
    #dollyCameraOut: "Move Camera Out"].getOne(aEvent)

    if symbolP(tHandler) then
    pQueuedTriggeredEvents.add(tHandler)
    end if

    end if
    end if

    end registerEvent



    on withGroupNameOf(me, aName, aList)

    if aName = pGroupName then
    if voidP(aList.getAProp(me.spriteNum)) then
    tNewList = [:]
    tNewList.addProp(me.getScriptName(),me)
    aList.addProp(me.spriteNum, tNewList)

    else
    tBehaviorName = me.getScriptName()
    tSpriteBehaviorList = aList.getProp(me.spriteNum)

    if voidP(tSpriteBehaviorList.getAProp(tBehaviorName)) then
    tSpriteBehaviorList.addProp(me.getScriptName(),me)

    else
    nothing
    end if

    end if
    end if

    end withGroupNameOf

    on controlCamera me

    collisionList = p3dMember.modelsUnderRay(pCamera.worldPosition,\
    -pCamera.transform.xAxis,#detailed)

    if (collisionList.count) then
    me.checkForCollision(collisionList[1])
    end if

    collisionList = p3dMember.modelsUnderRay(pCamera.worldPosition,\
    pCamera.transform.xAxis,#detailed)

    if (collisionList.count) then
    me.checkForCollision(collisionList[1])
    end if

    collisionList = p3dMember.modelsUnderRay(pCamera.worldPosition,\
    -pCamera.transform.zAxis,#detailed)

    if (collisionList.count) then
    me.checkForCollision(collisionList[1])
    end if

    collisionList = p3dMember.modelsUnderRay(pCamera.worldPosition,\
    pCamera.transform.zAxis,#detailed)

    if (collisionList.count) then
    me.checkForCollision(collisionList[1])
    end if

    end


    on checkForCollision me, thisData

    dist = thisData.distance

    if (dist < pCameraSphere.resource.radius) then

    diff = pCameraSphere.resource.radius - dist
    tVector = thisData.isectNormal * diff
    pCamera.translate(tVector,#world)

    end if

    end


    on initialize(me)

    pCamera = pSprite.camera
    pCameraOriginTransform = duplicate(pCamera.transform)
    pRect = pSprite.rect
    pCenter = point(pRect.left + (pRect.width / 2.0), pRect.top + (pRect.height
    / 2.0))
    pQueuedTriggeredEvents = []
    return(TRUE)

    end initialize


    on isMemberStateOK(me)

    tOKstate = FALSE

    case pMember.type of
    #shockwave3d:
    if pMember.state >= 2 then
    tOKstate = TRUE
    end if

    #text:
    if pMember.displayMode = #mode3D then
    if pMember.state >= 2 then
    tOKstate = TRUE
    end if
    else
    if NOT(pAlerted) then
    me.textTypeAlert()
    pAlerted = TRUE
    end if
    end if
    end case

    return(tOKstate)

    end isMemberStateOK


    on panCamera(me, aX, aY, aZ)

    pCamera.rotate(aX, aY, aZ)

    end panCamera


    on dollyCamera(me, aDollyAmount)

    pCamera.translate(0,0, aDollyAmount)

    end dollyCamera


    on textTypeAlert(me)

    tString1 = "The behavior indicated below requires that its text member's
    display be set to 3D Mode. " & \
    "This sprite's member is not set that way. " & \
    "Please correct this." & RETURN & RETURN
    tString2= "Sprite" & ":" && string(me.spriteNum) & RETURN & RETURN
    tString3 = "Behavior" & ":" && QUOTE & me.getScriptName() & QUOTE
    alert(me.typeset(tString1 & tString2 & tString3))

    end textTypeAlert


    on isOKtoAttach(aScript, aSpriteType, aSpriteNum)

    case aSpriteType of
    #Graphic:
    case sprite(aSpriteNum).member.type of
    #shockwave3d:
    return(TRUE)

    #text:
    if sprite(aSpriteNum).member.displayMode = #mode3D then
    return(TRUE)
    end if
    end case

    #script:
    return(FALSE)
    end case

    end isOKtoAttach


    on getPropertyDescriptionList(aScript)

    if the currentSpriteNum > 0 then

    tGPDList = [:]
    if aScript.is3D(sprite(the currentSpriteNum).member) then

    tGPDList[#pPanAmount] = \
    [#comment:"Degrees to pan per frame",\
    #format: #integer,\
    #default: 2]

    tGPDList[#pDollyAmount] = \
    [#comment:"Amount to dolly per frame",\
    #format:#float,\
    #default: 5.0]

    tGPDList[#pGroupName] = \
    [#comment:"Which group does this behavior belong to?",\
    #format: #string,\
    #default: "Unassigned!" ]

    end if

    return(tGPDList)

    end if

    end getPropertyDescriptionList


    on getScriptName(me)

    tScriptName = string(me.script)
    tName = EMPTY
    repeat with tWord = 2 to tScriptName.word.count
    tName = tName && tScriptName.word[tWord]
    end repeat
    tName = tName.char[3..(tName.char.count) - 2]
    return(tName)

    end getScriptName


    on is3D(me, aMember)

    tIs3D = FALSE

    case aMember.type of
    #shockwave3d:
    tIs3D = TRUE
    #text:
    if aMember.displayMode = #mode3D then
    tIs3D = TRUE
    end if
    end case

    return(tIs3D)

    end is3D


    on typeSet(aScript, aString)

    tCharLimit = 50
    tTempChunk = aString.char[1..tCharLimit]
    tNewString = EMPTY

    repeat while tTempChunk <> EMPTY
    tTempChunk = aString.char[1..tCharLimit]
    tCount = tTempChunk.char.count

    if tTempChunk.char[tCharLimit] = " " then
    tStopWord = tTempChunk.word.count

    else if aString.char[tCharLimit + 1] = " " then
    tStopWord = tTempChunk.word.count

    else if tTempChunk.char.count < tCharLimit then
    tStopWord = tTempChunk.word.count

    else
    tStopWord = tTempChunk.word.count - 1
    end if

    tTempChunk = aString.word[1..tStopWord]

    tNewString = tNewString & RETURN & tTempChunk
    delete aString.word[1..tStopWord]

    end repeat
    return(tNewString)

    end typeSet



    --------------------------------------------------------------------------------
    --beginInterfaceBlock
    --publicHandler = [#panCameraUp: "Pan Camera Up"]
    --publicHandler = [#panCameraDown: "Pan Camera Down"]
    --publicHandler = [#panCameraLeft: "Pan Camera Left"]
    --publicHandler = [#panCameraRight: "Pan Camera Right"]
    --publicHandler = [#dollyCameraIn: "Move Camera In"]
    --publicHandler = [#dollyCameraOut: "Move Camera Out"]
    --respondsTo = [#mouse, #key]
    --respondToOnlyThisSprite = [FALSE]
    --endInterfaceBlock


    Nickname Guest

  2. #2

    Default Re: 3D movement and collision queries

    I would bet that nobody is going to look through that amount of code for you to
    find your bug, however I do have an alternative camera script with
    pan/zoom/dolly/crane controls, which you can take a look at here:


    http://robotduck.com/content/articles/director/3d/camera/standardCamera/index.ht
    m

    hope this helps!

    - Ben




    duckets Guest

  3. #3

    Default Re: 3D movement and collision queries

    I would bet that nobody is going to look through that amount of code for you to
    find your bug, however I do have an alternative camera script with
    pan/zoom/dolly/crane controls, which you can take a look at here:


    http://robotduck.com/content/articles/director/3d/camera/standardCamera/index.ht
    m

    hope this helps!

    - Ben




    duckets Guest

  4. #4

    Default Re: 3D movement and collision queries

    I think you may be right, and that's the slightly shorter version!!!!

    Thanks for the script, it works really smoothly. I'm trying to digest it at
    the moment, my animation needs to be in a 'from the inside looking out' rather
    than 'outside looing in', plus I have exponent buttons rather than sliders. And
    I have the small problem of collision detection that I hope I've fixed.

    Thanks very much though, hopefully this might shed some light on where I'm
    going wrong. I'll email back if (or when!) I get any questions on it (if that's
    ok with you!?!).

    Nickname Guest

Similar Threads

  1. Restrict Camera movement and collision
    By Nickname in forum Macromedia Director 3D
    Replies: 5
    Last Post: December 19th, 11:58 AM
  2. Queries Of Queries Single Quote Problem
    By TimH2O in forum Macromedia ColdFusion
    Replies: 0
    Last Post: April 1st, 07:46 PM
  3. relative movement
    By rAT.mAN in forum Macromedia Director 3D
    Replies: 1
    Last Post: October 12th, 12:59 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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139