Windows Vista Forums

Rotating the PerspectiveCamera
  1. #1


    Kevin Hoffman Guest

    Rotating the PerspectiveCamera

    Ok... I've got a scene where my camera is above (Y+) and away from (Z+)
    my 3D object. I can move the camera toward the object by doing this:

    camera.Position += camera.LookDirection;

    I find that quite handy, really intuitive, and brings back fond
    memories of Vector study in Physics class in college

    What I want is to be able to 'turn' the camera to the left or to the
    right. At first glance, I thought I might just increment or decrement
    the X value of the LookDirection... the problem is you get an
    "approaches infinity" type of foreshortening effect there - as you turn
    more and more left, the effect becomes more and more off because you're
    still looking at a point off in the distance at the X axis, not
    actually turning the camera the way it should be.

    What I _think_ I should be doing is applying a 3D Axis rotation where I
    rotate X degrees negative about the Y axis when turning the camera
    left, and X degrees positive about the Y axis in order to spin the
    camera to the right.

    What I can't quite figure out is how to accomplish a transform of the
    Unit Vector indicating my LookDirection. I've tried creating a
    RotateTransform3D based on an AxisAngleRotation3D as follows:

    RotateTransform3D cameraSpinner = new RotateTransform3D(
    new AxisAngleRotation3D(new Vector3D(0,1,0), -10));

    In my newbie little brain, this should create a transformer that will
    rotate something about the Y axis (the 0,1,0 unit vector) to the 'left'
    10 degrees.

    The problem is the RotateTransform3D only operates on a Point3D or an
    array of Point3Ds... so how does one Transform the LookDirection vector
    by rotating the LookDirection of the camera about the Y axis?

    I'm sure this is something totally trivial and I'm missing it because
    I'm a complete newbie, but I would love for someone's input on how to
    accomplish this..



    Thanks,
    Kevin


      My System SpecsSystem Spec

  2. #2


    Kevin Hoffman Guest

    Re: Rotating the PerspectiveCamera

    Valentin,
    That looks like a good plan... The only problem I have is that when
    I use the following line:

    (camera1.Transform as MatrixTransform3D).Matrix *= rt3d.Value;

    I end up with a run-time error telling me that I cannot modify the
    Matrix property because its in a read-only state.


      My System SpecsSystem Spec

  3. #3


    Kevin Hoffman Guest

    Re: Rotating the PerspectiveCamera

    If I had to guess at the behavior here, I would say that the camera is
    actually rotating about the Y axis as it passes through the origin,
    rather than spinning about its own Y axis (e.g. its rotating around the
    origin on Y rather than spinning in place).


      My System SpecsSystem Spec

  4. #4


    Kevin Hoffman Guest

    Re: Rotating the PerspectiveCamera

    GOT IT!
    I do remember saying that it felt as though the rotational
    transformation was taking place relative to a centerpoint of the origin
    rather than the camera itself being the centerpoint...So,I added:

    rt3d.CenterZ = camera1.Position.Z;
    rt3d.CenterY = camera1.Position.Y;
    rt3d.CenterX = camera1.Position.X;

    Before I did the matrix multiplication and it works like a champ.

    I knew it was something simple that I was missing, and setting the
    centerpoint of the axis rotation to be the camera's position instead of
    the origin was definitely a "D'oh!" moment... Thanks for all the
    support getting me this far.


      My System SpecsSystem Spec

  5. #5


    Jason [Mobiform] Guest

    Re: Rotating the PerspectiveCamera

    Maybe this is a recent addition, but RotateTransform3D.Transform does seem
    to accept Vector3D and Vector3D[].

    Jason

    "Kevin Hoffman" <alothien@gmail.com> wrote in message
    news:1141154351.928956.174110@u72g2000cwu.googlegroups.com...
    > Ok... I've got a scene where my camera is above (Y+) and away from (Z+)
    > my 3D object. I can move the camera toward the object by doing this:
    >
    > camera.Position += camera.LookDirection;
    >
    > I find that quite handy, really intuitive, and brings back fond
    > memories of Vector study in Physics class in college
    >
    > What I want is to be able to 'turn' the camera to the left or to the
    > right. At first glance, I thought I might just increment or decrement
    > the X value of the LookDirection... the problem is you get an
    > "approaches infinity" type of foreshortening effect there - as you turn
    > more and more left, the effect becomes more and more off because you're
    > still looking at a point off in the distance at the X axis, not
    > actually turning the camera the way it should be.
    >
    > What I _think_ I should be doing is applying a 3D Axis rotation where I
    > rotate X degrees negative about the Y axis when turning the camera
    > left, and X degrees positive about the Y axis in order to spin the
    > camera to the right.
    >
    > What I can't quite figure out is how to accomplish a transform of the
    > Unit Vector indicating my LookDirection. I've tried creating a
    > RotateTransform3D based on an AxisAngleRotation3D as follows:
    >
    > RotateTransform3D cameraSpinner = new RotateTransform3D(
    > new AxisAngleRotation3D(new Vector3D(0,1,0), -10));
    >
    > In my newbie little brain, this should create a transformer that will
    > rotate something about the Y axis (the 0,1,0 unit vector) to the 'left'
    > 10 degrees.
    >
    > The problem is the RotateTransform3D only operates on a Point3D or an
    > array of Point3Ds... so how does one Transform the LookDirection vector
    > by rotating the LookDirection of the camera about the Y axis?
    >
    > I'm sure this is something totally trivial and I'm missing it because
    > I'm a complete newbie, but I would love for someone's input on how to
    > accomplish this..
    >
    > Thanks,
    > Kevin
    >




      My System SpecsSystem Spec

Rotating the PerspectiveCamera problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rotating a Video david boylan Vista music pictures video 3 02 Jun 2008
screen rotating aoc Vista performance & maintenance 2 09 Feb 2008
Rotating Images Stimpy Vista print fax & scan 1 13 Jul 2007
Rotating Images ixloco Vista music pictures video 5 24 May 2007
Rotating a received fax William Vista print fax & scan 0 27 Mar 2007