Professional Web Applications Themes

Billboards - Macromedia Director 3D

Hi Guys I need to make some trees in a 3d project im working on. Since they will be in the distance i want to do them on as billboards (planes with alpha images on). my problem is getting these planes to turn (pointat) towards the camera. I have tried to play with the "pointat" and the "pointatorientation" to make it work, but the planes rotate in more than one direction. I only want them to rotate arround one axis. Does anyone have a solution/suggestion? best regards, Per...

  1. #1

    Default Billboards

    Hi Guys

    I need to make some trees in a 3d project im working on.
    Since they will be in the distance i want to do them on as billboards
    (planes with alpha images on).
    my problem is getting these planes to turn (pointat) towards the camera. I
    have tried to play with the "pointat" and the "pointatorientation" to make
    it work, but the planes rotate in more than one direction. I only want them
    to rotate arround one axis.
    Does anyone have a solution/suggestion?

    best regards,

    Per


    Perdal Guest

  2. #2

    Default Re: Billboards

    My suggestion:

    1- Create a parent script to handle trees rotation. There will be one instance
    per tree. Pass on the model reference as a parameter to the new() handler. Add
    the instance (me) to the actorList to get the stepFrame handler called by
    Director everytime the playhead enters the frame.

    on stepFrame:

    2- Get the vector of your tree and that of the current camera.
    3- Compute the angle between the two vectors with the angleBetween() Lingo
    instruction.
    4- Create a new (target) transform for the camera to reach
    5- Use the interpolateTo() Lingo instruction in order to interpolate to the
    new transform

    So, it would give something like this (from my head):

    property spriteNum
    property pModel
    property pCamera

    on new me, mModel, mSpeed

    pModel = mModel
    pSpeed = mSpeed
    append the actorList, me
    return me

    end

    on stepFrame me

    -- Reference to the current camera
    pCamera = sprite(spriteNum).camera

    -- Get the model and camera vectors
    v1 = pModel.transform.rotation.duplicate()
    v2 = pCamera .transform.rotation.duplicate()

    -- Compute the angle between the two on the Y axis
    angle = v1.angleBetween(v2)

    -- Create the target transform
    targetTransform = pModel.transform.duplicate()
    targetTransform.rotate(0,angle,0)

    -- Interpolate the model transform towards the camera at the given speed
    pModel.interpolateTo(targetTransform, pSpeed)

    end


    I don't think it will work as is, but it gives you the idea...

    Cheers,
    Karl.



    Newt99 Guest

  3. #3

    Default Re: Billboards

    Hi Newt99 and everybody else

    Thanks for the fast response. I have now had time to look at your answer and
    to try to implement it. I can not get it to work.

    I must admit that vector math is not my strong side, but getting the
    "angleBetween" the two rotation tranforms, doesn't that just give you an
    angle between two angles, whereas I want an angle between to positions in a
    plane?? Please tell me if I misunderstood something.

    Best regards,

    Per

    "Newt99" <webforumsusermacromedia.com> wrote in message
    news:captjv$9nk$1forums.macromedia.com...
    > My suggestion:
    >
    > 1- Create a parent script to handle trees rotation. There will be one
    instance
    > per tree. Pass on the model reference as a parameter to the new() handler.
    Add
    > the instance (me) to the actorList to get the stepFrame handler called by
    > Director everytime the playhead enters the frame.
    >
    > on stepFrame:
    >
    > 2- Get the vector of your tree and that of the current camera.
    > 3- Compute the angle between the two vectors with the angleBetween()
    Lingo
    > instruction.
    > 4- Create a new (target) transform for the camera to reach
    > 5- Use the interpolateTo() Lingo instruction in order to interpolate to
    the
    > new transform
    >
    > So, it would give something like this (from my head):
    >
    > property spriteNum
    > property pModel
    > property pCamera
    >
    > on new me, mModel, mSpeed
    >
    > pModel = mModel
    > pSpeed = mSpeed
    > append the actorList, me
    > return me
    >
    > end
    >
    > on stepFrame me
    >
    > -- Reference to the current camera
    > pCamera = sprite(spriteNum).camera
    >
    > -- Get the model and camera vectors
    > v1 = pModel.transform.rotation.duplicate()
    > v2 = pCamera .transform.rotation.duplicate()
    >
    > -- Compute the angle between the two on the Y axis
    > angle = v1.angleBetween(v2)
    >
    > -- Create the target transform
    > targetTransform = pModel.transform.duplicate()
    > targetTransform.rotate(0,angle,0)
    >
    > -- Interpolate the model transform towards the camera at the given
    speed
    > pModel.interpolateTo(targetTransform, pSpeed)
    >
    > end
    >
    >
    > I don't think it will work as is, but it gives you the idea...
    >
    > Cheers,
    > Karl.
    >
    >
    >

    Perdal Guest

  4. #4

    Default Re: Billboards

    I told you it was from my head, not a tested piece of code, so don't be
    surprised it doesn't work straight away. It was indeed a mistake to write
    rotation instead of position:

    -- Get the model and camera vectors
    v1 = pModel.transform.position.duplicate()
    v2 = pCamera .transform.position.duplicate()

    -- Compute the angle between the two
    angle = v1.angleBetween(v2)

    Then, you can either give directly the model the resulting angle:
    pModel.transform.rotation.y = angle

    Or do the interpolation:

    -- Create the target transform

    targetTransform = pModel.transform.duplicate()
    targetTransform.rotate(0,angle,0)

    -- Interpolate the model transform towards the camera at the given speed
    pModel.interpolateTo(targetTransform, pSpeed)

    I will test this piece myself this week end, I don't have the time now.

    Cheers,
    Karl.


    Newt99 Guest

  5. #5

    Default Re: Billboards

    Hi Newt99 (Karl)

    Thank you for the new suggestion.
    I tried with the anglebetween the two positions.. but i couldnt get this to
    work either.
    After knocking my head into the table several times, I have finally gotten a
    solution.
    Here is how I solved it (Pseudo code):

    MyOffset = 180 --myOfset is used because I need to flip the billboard
    pCamPos = camera.worldposition
    pModelPos = object.worldposition
    -- Now I will get the angle between the two points on the plane in radians
    and convert it to degrees (/(PI/180))
    pAngleBetween = atan(pCamPos.x-pModelPos.x,pCamPos.y-pModelPos.y)/(PI/180)
    --get the current rotation of the object
    pModelRotation = object.getWorldTransform().rotation
    --rotate the object to point at camera
    object.rotate(0,0,pAngleBetween+pModelrotation.z-myOffset)

    This is how I solved the problem, if you find a better (cleaner) way, I
    would very much like to hear your take on it.

    Thanks for the help again..

    Best regards,

    Per


    "Newt99" <webforumsusermacromedia.com> wrote in message
    news:caubbo$ro4$1forums.macromedia.com...
    > I told you it was from my head, not a tested piece of code, so don't be
    > surprised it doesn't work straight away. It was indeed a mistake to write
    > rotation instead of position:
    >
    > -- Get the model and camera vectors
    > v1 = pModel.transform.position.duplicate()
    > v2 = pCamera .transform.position.duplicate()
    >
    > -- Compute the angle between the two
    > angle = v1.angleBetween(v2)
    >
    > Then, you can either give directly the model the resulting angle:
    > pModel.transform.rotation.y = angle
    >
    > Or do the interpolation:
    >
    > -- Create the target transform
    >
    > targetTransform = pModel.transform.duplicate()
    > targetTransform.rotate(0,angle,0)
    >
    > -- Interpolate the model transform towards the camera at the given speed
    > pModel.interpolateTo(targetTransform, pSpeed)
    >
    > I will test this piece myself this week end, I don't have the time now.
    >
    > Cheers,
    > Karl.
    >
    >

    Perdal Guest

Similar Threads

  1. Making billboards
    By DANGH_b in forum Macromedia Director 3D
    Replies: 2
    Last Post: February 21st, 01:38 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