Professional Web Applications Themes

Slope and Rotation from face - Macromedia Director 3D

Hi. I'm trying to get the slope and rotation from a face that the user clicks on. I created the attached code which was fine untill I realised that it gives the wrong results if the selected face has a combination of slope and rotation. Please help. This has been bugging me for ages! Trevor property p_Origin on mouseDown me mdl = sprite(me.spriteNum).camera.modelsUnderLoc(the mouseLoc - p_Origin, #detailed) rot = getRotationFromNormal(mdl[1][#isectNormal]) slp = getSlopeFromNormal(mdl[1][#isectNormal]) end on getRotationFromNormal vNormal tAngle = vNormal.angleBetween(vector(0,1,0)) if vNormal.x < 0 then tAngle = 360 - tAngle end if return tAngle end on getSlopeFromNormal vNormal tAngle = ...

  1. #1

    Default Slope and Rotation from face

    Hi.
    I'm trying to get the slope and rotation from a face that the user clicks on.
    I created the attached code which was fine untill I realised that it gives the
    wrong results if the selected face has a combination of slope and rotation.

    Please help. This has been bugging me for ages!

    Trevor



    property p_Origin

    on mouseDown me
    mdl = sprite(me.spriteNum).camera.modelsUnderLoc(the mouseLoc - p_Origin,
    #detailed)
    rot = getRotationFromNormal(mdl[1][#isectNormal])
    slp = getSlopeFromNormal(mdl[1][#isectNormal])
    end

    on getRotationFromNormal vNormal
    tAngle = vNormal.angleBetween(vector(0,1,0))

    if vNormal.x < 0 then
    tAngle = 360 - tAngle
    end if

    return tAngle
    end

    on getSlopeFromNormal vNormal
    tAngle = vNormal.angleBetween(vector(0,0,1))

    return tAngle
    end

    The Guest

  2. #2

    Default Re: Slope and Rotation from face

    This is what I always use:

    tiltAngle = vector(0,0,1).anglebetween(faceNormal)
    tiltVector = faceNormal.perpendicularto(vector(0,0,1))

    and then to align an object to that normal:

    myObject.transform.rotation = vector(0,0,0)
    myObject.transform.rotate(myObject.transform.posit ion,tiltVector,-tiltAngle)

    hope this helps,

    - Ben


    duckets Guest

  3. #3

    Default Re: Slope and Rotation from face

    Hi Ben,
    Thanks for your reply.
    Your use of perpendicularto() function has possibly helped with a separate
    problem I 'm trying to solve.

    However, I don't think it actually helps me for this problem.
    I'm not trying to align an object to a face. I'm trying to get the individual
    rotation and slope components from a vector. These values are then used for
    ysis.
    Here's an example:
    If I pick a face and its normal is
    vector( 0.0000, -1.0000, 0.0000 )
    I can get its rotation
    put faceNormal.angleBetween(vector(0,1,0))
    -- 180.0000

    If I change the slope of the face so that its normal is
    vector( 0.0000, -0.9461, 0.3240 )
    when I get the rotation of the face normal, I get
    put faceNormal.angleBetween(vector(0,1,0))
    -- 161.0954
    but I should still be getting 180.000 as the rotation is still the same.

    Hope I'm confusing things with this explanation...

    Regards,
    Trevor



    The Guest

  4. #4

    Default Re: Slope and Rotation from face

    No, you shouldn't be getting 180. Your face normal is initially pointing
    directly along the negative Y axis. Then you get the angle between that and
    0,1,0 (directly along the positive Y axis). The angle between the two is 180.

    Then you've tilted the face slightly, so the normal is slightly off the
    negative Y axis, and then you're measuring the angle between(0,1,0) and your
    new face normal, which is no longer 180 degrees in the opposite direction. It's
    slightly less.

    The code I supplied gets the 'tilt vector' (i.e. the 'slope') and 'tile
    angle', from a face normal compared with a given axis (in my code, z+).

    If this isn't what you want, you'll have to describe more clearly what you
    want - perhaps describe what you want to do with the values once you have them?

    - Ben



    duckets Guest

  5. #5

    Default Re: Slope and Rotation from face

    To demonstrate my problem, I've created an image :
    http://www.the-mindseye.co.uk/download/rot_from_norm.jpg
    one face of a box is selected and displayed in red.
    It has a rotation of 180 and a slope 90.
    If I adjust its slope by 10 degrees, I end up with a slope of 80 but also a
    rotation of 170 but you can clearly see it still has the same rotation.

    I'm using these values to pass to an external ysis program which then
    works out the solar and fabric gain of a building.

    Cheers,
    Trevor


    The Guest

  6. #6

    Default Re: Slope and Rotation from face

    Imagine a line protruding from that red face, perpendicular to that face. In
    the top image, the face is vertical, so the line protruding from that face
    (which, incidentally, is the 'normal' of that face). would be pointing in
    exactly the opposite direction to your Y axis. Your Y axis is identified by the
    green axis line. (RGB = XYZ, for the axis markers). Hence, 180 degrees retured
    by the angleBetween function.

    In the lower image, the face is tilted a little, which means the line
    protruding from the face would be angled upwards a little. Now, if you measure
    the angle between that line and the green Y axis line, it is less than 180
    degrees, because you have rotated it around a little.

    I've done a bit of drawing on your image, to illustrate what's happening:

    http://www.robotduck.com/misc/angleBetween.jpg

    - Ben


    duckets Guest

Similar Threads

  1. Rotation between two transform.rotation vectors.
    By SuperTank in forum Macromedia Director 3D
    Replies: 3
    Last Post: September 27th, 05:07 PM
  2. How to make object not slide along the slope in Havok?
    By alex in forum Macromedia Director 3D
    Replies: 1
    Last Post: October 17th, 03:00 PM
  3. Rotation?
    By quick star in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 3
    Last Post: June 25th, 08:36 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