Professional Web Applications Themes

constraining the rotate axes of the camera - Macromedia Director 3D

Hi there all, I am tring to make a 3d world that allows the user to rotate with their mouse. Now following the instructions from the post that I asked awhile back ago, you have to setup a global mouseLoc that is in the event handle "on mouseDown", and then calculate its offsets in the event handler "on exitFrame" just like so... property pMouse on mouseDown pmouse = the mouseLoc end mouseDown on exitFrame if the mouseDown then dMouse = (pMouseLoc - the mouseLoc) / 100.0 -- / 100 sets the speed of rotation dx = dMouse.locH * 20 -- ...

  1. #1

    Default constraining the rotate axes of the camera

    Hi there all,
    I am tring to make a 3d world that allows the user to rotate with their mouse.
    Now following the instructions from the post that I asked awhile back ago, you
    have to setup a global mouseLoc that is in the event handle "on mouseDown", and
    then calculate its offsets in the event handler "on exitFrame" just like so...

    property pMouse

    on mouseDown
    pmouse = the mouseLoc
    end mouseDown

    on exitFrame
    if the mouseDown then
    dMouse = (pMouseLoc - the mouseLoc) / 100.0 -- / 100 sets the speed of rotation
    dx = dMouse.locH * 20 -- we multiple by 20 for the senistivty of the mouse
    dy = dMouse.locV * 20 -- the smaller the sensitivity is the less amount the
    camera will rotate
    pMouseLoc = the mouseLoc

    -- in the command below, we switch dx and dy around because I want the camera
    to rotate off the y axis when the user moves the mouse left and right, and I
    want the camera to rotate off the x axis when the user moves the mouse up and
    down. --

    pCamera.rotate(dy, dx, 0, #world)
    end if
    end exitFrame
    -- end of script

    Now that does work, but lets say when the user doesn't move the mouse in a
    straight line and let's go of the mouse button and then rotates again, then the
    camera starts to rotate around all 3 axes, but I want the z to always be 0. I
    did a study in 3DPI by just rotating the camera around the y axis, and I
    noticed that when you rotate the y axis beyond -90 or +90, the x axis gets
    flipped from 0 to 180, and z axis gets flipped from 0 to -180. In addition,
    when the y axis is beyond -90, then y starts to increase back to 0, and when
    the y axis is beyond +90, then the y axis starts to decrease back to 0. So in
    other words, it appears that when rotating, the y axis only has a -90 to +90
    limit constraints. So my question is, how can I get this to do the same thing
    in lingo without lossing the mouse movements of the x axis?:confused;

    Roofy Guest

  2. #2

    Default Re: constraining the rotate axes of the camera

    If that's your coordinate system, just replace:

    pCamera.rotate(dy, dx, 0, #world)

    with

    pCamera.transform.rotation.x = pCamera.transform.rotation.x + dx
    pCamera.transform.rotation.y = pCamera.transform.rotation.y + dy


    that's all.



    necromanthus Guest

  3. #3

    Default Re: constraining the rotate axes of the camera

    Thanks for tring to chip in necromanthus, but doing that doesn't rotate around
    the world axis. Instead it keeps on rotating on its own axis. In addition, I
    tried implementing your method with

    pCamera.transform.preRotate(vector(0, 0, 0), vector(1, 0, 0), dy)
    pCamera.transform.preRotate(vector(0, 0, 0), vector(0, 1, 0), dx)

    but this does 2 wrong things. 1. it still doesn't rotate off the world axis,
    and 2. it does the same funky z thing as like in the rotate command.

    My latest attempts was I have went to jmckell's website and found something
    simular to what I am looking for, but the problem with his method is 2 things.
    1. is that his script is designed by making his own 3d engine. Meaning that it
    is not shockwave's 3d engine. 2. The whole entire engine rely's on parent
    scripting which I never wrote before in my life and I couldn't even begin to
    understand this theory at all. Though tring to see what he has done, some how
    he is taking 2 invisible nodes called CamX and CamY. He then rotates them
    seperately so that CamY can create the x axis and z axis flips when the y axis
    goes beyond -90. Meaning for example lets say the last rotation of CamY is
    vector(0, -90, 0), and then lets say the next rotation is going to make the y
    axis to equal -91, all 3 axes can flip properly to vector(180, -89, 180)
    because the x movements of the mouse are recorded on the CamX rotation vector.
    So if CamX = vector(10, 0, 0) and CamY = vector(0, -90, 0) and when the mouse
    movement increases 1 for x and 1 for y then CamX is now vector(11, 0, 0) and
    CamY now vector(180, -89, 180).

    So I tried implementing this and then added the CamX with CamY together to get
    a combined vector as one like so
    newVector = CamX +CamY. I then placed this newVector into
    pCamera.transform.rotation = newVector. Doing that, the rotation part worked
    but of course it still doesn't rotate around the world's axis which is the most
    important thing because this is how other 3d applications rotate its
    perspective view. Is their any other way that I can get this to rotate around
    the world axis?

    Roofy Guest

  4. #4

    Default Re: constraining the rotate axes of the camera

    I can't figure what are you doing wrong there.
    Anyway, download & study this example (source file included):
    [url]http://necromanthus.com/Games/ShockWave/tutorials/PanCamera.html[/url]
    cheers
    necromanthus Guest

  5. #5

    Default Re: constraining the rotate axes of the camera

    Hi their,

    I did some tweeking on your file to show you what I mean. Here is the link to
    watch the movie
    [url]http://home.comcast.net/~rneilen216/example/panCamera/tweekedPanCamera.zip[/url]

    Basically all I did was, I moved the camera back a little so that the camera
    is not dead center. In addition, I added some code that adds a cube on the fly
    that is placed in the center of the world. The purpose of me doing this is to
    show you that I want the camera to rotate around the world axis which I made
    the cube for you as a reference of where the world axis is located at. If this
    was working the way I want it to work, the camera should rotate around the cube
    but by playing this movie, you can see that the camera is not doing that.
    Instead what it is doing is rotating around the camera's axis.

    If you still can't grasp what I mean then the best way to explain this is if
    you could try this example down below in your 3d application whether it be
    Maya, Lightwave, Max, or what ever it is you use to design your 3D artwork.

    First thing first, open up your 3d app. Then create a cube the size of "x=1,
    y=1, z=1", in the center of the world. Then set the pespective view a few
    distances away from the cube and then rotate your pespective view. While doing
    so, watch how the camera is rotating around the cube. Doing this, you'll notice
    that the camera's view never leaves the cube. It always will point to the cube.
    This is because the camera is rotating around the world axis or should say
    vector(0, 0, 0). To prove that the camera is always rotating around the world
    axis or vector(0, 0, 0), you can move the cube to vector(10, 0, 10). Then
    rotate the camera again and watch how the camera is still going around the cube
    but at one point when the cube directly faces the camera, the cube will be
    closer to the camera, and when the cube is in the opposite directoion of the
    camera, the cube looks like it is futher away. This is how I want my camera to
    work and not around its own axis.

    Roofy Guest

  6. #6

    Default Re: constraining the rotate axes of the camera

    You're always unsatisfied isn't it ? (LOL)
    Few hints :
    1) "Pan Camera" has nothig to do with "rotating around an object"
    2) There is no need to tweek anything in that source file.
    3) Your initial script (I don't know the real author) has nothing to do with
    "rotating around the world"
    4) pCamera.rotate(dy, dx, 0, #world) doesn't mean "rotating around the world".
    #world applies the increments relative to the world coordinate system, but
    nothing more.
    5) I don't have enough spare time to open up my 3d app
    6) Now how to to make the camera "rotating around an object" :
    use the "Pan Camera" source file and replace the frame2 script with this one:

    global w
    global pCamera,dmy
    property pMouse

    on beginSprite me
    pCamera = w.camera(1)
    pMouse = the mouseLoc
    tRes = w.newModelResource("dummyRs", #box)
    tRes.width = 10
    tRes.height = 10
    tRes.length = 10
    w.newModel("dummy", w.modelResource("dummyRs"))
    dmy = w.model("dummy")
    dmy.transform.position = vector(50,-50,0)
    -- dmy.visibility = #none
    pCamera.rotate(0,-45,0)
    end

    on mouseDown
    pMouse = the mouseLoc
    end

    on exitFrame(me)
    if the mouseDown then
    dMouse = (pMouse - the mouseLoc) / 100.0
    dx = dMouse.locV * 20
    dz = dMouse.locH * 20
    pCamera.rotate(vector(0,dx,dz),dmy)
    pCamera.pointAt(dmy,vector(0,0,1))
    pMouse = the mouseLoc
    end if
    go to frame 2
    end


    Clear enough now, isn't it ?
    cheers


    necromanthus Guest

  7. #7

    Default Re: constraining the rotate axes of the camera

    Originally posted by: necromanthus
    You're always unsatisfied isn't it ? (LOL)

    Yep, :D And the reason why I want this to be perfect is because if I was to
    just leave this alone and put this out for people to download, then they would
    say why does the camera rotate funky and they would not be able to use the
    program.

    I never mentioned this this before,. though the purpose for the project was I
    was tring to create a finializer animation program. I wanted to create this
    because I have found that most 3d apps always have some sort of animation quark
    that doesn't export correctly to shockwave. My thoughts where to create a
    projector that lets the user to animate their project and then the projector
    would create the lingo into a text file. Then all the user would have to do is
    past the text into a new behaiviour script. sort of like 3DPI. However what
    would be different is that the user would not have to know which bone the user
    wants to rotate or move ect. becuase they would be able to just point and click
    on the bone he/she chooses just like you would In a 3D application. So my goal
    was to make the perspective view react like any ordinary 3d app would do so
    that the user wouldn't have to learn a new program. If you ever noticed with
    any 3D program, their are only very tiny differences in how the program works.
    However, most of them are pick a tool and then click and drag. For example, In
    Maya, to move an object, you click on the move tool and click and drag. To move
    an object in Plasma, you click on the move tool and click and drag. So why
    should my camera movements be different since all other prgrams work the same
    way?

    Anywho, enough blabbing away and gettting to my point, the camera now does
    rotate around the object but not smooth at all. In addition, I am giving up for
    now or at least untill I take a course in c++, and advanced algerbra. Also I
    really appreciate your help in taking the time to help me but for now I don't
    want to sound to pushy so I am leaving this be for now. Thanks for the help.

    Roofy Guest

Similar Threads

  1. Chart Axes positioning
    By gmaheshmca in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: April 30th, 04:34 AM
  2. Make camera zoom and rotate around object
    By foq in forum Macromedia Director 3D
    Replies: 7
    Last Post: October 27th, 04:25 PM
  3. rotation slider using #self axes
    By John_Everist in forum Macromedia Director 3D
    Replies: 4
    Last Post: October 22nd, 07:45 AM
  4. rotate camera along an axis
    By kasi@i-waves in forum Macromedia Director 3D
    Replies: 1
    Last Post: August 5th, 06:27 AM
  5. Camera Rotate - Help!
    By Ryo_Hazuki in forum Macromedia Director 3D
    Replies: 1
    Last Post: March 16th, 10:27 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