Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Rotating the PerspectiveCamera

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 02-28-2006   #1 (permalink)
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
Old 02-28-2006   #2 (permalink)
viliescu
Guest


 

RE: Rotating the PerspectiveCamera

The best way to move/rotate the camera is to use its Transform property.

cameraTransform = new RotateTransform3D( new AxisAngleRotation3D(new
Vector3D(0,1,0), -10));
(camera.Transform as MatrixTransform3D).Matrix *= cameraTransform.Value;
--
Valentin Iliescu [MVP C#]


"Kevin Hoffman" wrote:

> 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
Old 02-28-2006   #3 (permalink)
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
Old 02-28-2006   #4 (permalink)
Kevin Hoffman
Guest


 

Re: Rotating the PerspectiveCamera

I went back into the XAML and made sure that my camera had a transform
in it of type MatrixTransform3D and that allowed the transformation
code to work.

The problem I'm having now is that when I rotate using that , it
definitely doesn't look like what I would expect...

Here are my key handlers for the left and right arrow keys:

if (e.Key == System.Windows.Input.Key.Left)
{
// turn the camera to the left
RotateTransform3D rt3d = new RotateTransform3D(
new AxisAngleRotation3D( new Vector3D(0,1,0), 1));

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

txtBlock2.Text = "Camera Look Direction Changed: " +
camera1.LookDirection.ToString();
}
if (e.Key == System.Windows.Input.Key.Right)
{
RotateTransform3D rt3d = new RotateTransform3D(
new AxisAngleRotation3D(new Vector3D(0, 1, 0), -1));
(camera1.Transform as MatrixTransform3D).Matrix *= rt3d.Value;
txtBlock2.Text = "Camera Look Direction Changed: " +
camera1.LookDirection.ToString();
}

What I'm looking is to turn the camera left or right depending on
hitting the left or right key... But when I transform using the matrix,
the camera also seems to tilt slightly. Is that because the camera is
pointing downward 1 unit on the Y axis when being transformed? I'm at a
loss here...

My System SpecsSystem Spec
Old 02-28-2006   #5 (permalink)
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
Old 02-28-2006   #6 (permalink)
Erno
Guest


 

Re: Rotating the PerspectiveCamera

When the camera is tilted you should rotate it around the up-vector or
around the 0,1,0 vector.
Take your pick... just think carefully about what you want to happen.

Cheers

Erno
----
WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx




"Kevin Hoffman" <alothien@gmail.com> wrote in message
news:1141159814.670185.166230@j33g2000cwa.googlegroups.com...
>I went back into the XAML and made sure that my camera had a transform
> in it of type MatrixTransform3D and that allowed the transformation
> code to work.
>
> The problem I'm having now is that when I rotate using that , it
> definitely doesn't look like what I would expect...
>
> Here are my key handlers for the left and right arrow keys:
>
> if (e.Key == System.Windows.Input.Key.Left)
> {
> // turn the camera to the left
> RotateTransform3D rt3d = new RotateTransform3D(
> new AxisAngleRotation3D( new Vector3D(0,1,0), 1));
>
> (camera1.Transform as MatrixTransform3D).Matrix *= rt3d.Value;
>
> txtBlock2.Text = "Camera Look Direction Changed: " +
> camera1.LookDirection.ToString();
> }
> if (e.Key == System.Windows.Input.Key.Right)
> {
> RotateTransform3D rt3d = new RotateTransform3D(
> new AxisAngleRotation3D(new Vector3D(0, 1, 0), -1));
> (camera1.Transform as MatrixTransform3D).Matrix *= rt3d.Value;
> txtBlock2.Text = "Camera Look Direction Changed: " +
> camera1.LookDirection.ToString();
> }
>
> What I'm looking is to turn the camera left or right depending on
> hitting the left or right key... But when I transform using the matrix,
> the camera also seems to tilt slightly. Is that because the camera is
> pointing downward 1 unit on the Y axis when being transformed? I'm at a
> loss here...
>



My System SpecsSystem Spec
Old 02-28-2006   #7 (permalink)
Kevin Hoffman
Guest


 

Re: Rotating the PerspectiveCamera

What I want to happen is the camera to 'turn' in the direction I want
it to turn. The Up vector is (0,1,0), the Y axis vector. What's
happening when I try to rotate about that is the position is changing
as well ... because the camera isn't sitting on the Y axis origin.

I thought that rotating the camera about (0,1,0) for X degrees would
spin it in place... If there is a different rotation I need to perform
to spin the camera's LookDirection without modifying its position, I'd
love to know....

My System SpecsSystem Spec
Old 02-28-2006   #8 (permalink)
viliescu
Guest


 

Re: Rotating the PerspectiveCamera

Sorry, I didn't pay attention to the vector. The rotation vector should be
the camera UpDirection:

RotateTransform3D rt3d = new RotateTransform3D(
new AxisAngleRotation3D( camera1.UpDirection, 1));
--
Valentin Iliescu [MVP C#]


"Kevin Hoffman" wrote:

> I went back into the XAML and made sure that my camera had a transform
> in it of type MatrixTransform3D and that allowed the transformation
> code to work.
>
> The problem I'm having now is that when I rotate using that , it
> definitely doesn't look like what I would expect...
>
> Here are my key handlers for the left and right arrow keys:
>
> if (e.Key == System.Windows.Input.Key.Left)
> {
> // turn the camera to the left
> RotateTransform3D rt3d = new RotateTransform3D(
> new AxisAngleRotation3D( new Vector3D(0,1,0), 1));
>
> (camera1.Transform as MatrixTransform3D).Matrix *= rt3d.Value;
>
> txtBlock2.Text = "Camera Look Direction Changed: " +
> camera1.LookDirection.ToString();
> }
> if (e.Key == System.Windows.Input.Key.Right)
> {
> RotateTransform3D rt3d = new RotateTransform3D(
> new AxisAngleRotation3D(new Vector3D(0, 1, 0), -1));
> (camera1.Transform as MatrixTransform3D).Matrix *= rt3d.Value;
> txtBlock2.Text = "Camera Look Direction Changed: " +
> camera1.LookDirection.ToString();
> }
>
> What I'm looking is to turn the camera left or right depending on
> hitting the left or right key... But when I transform using the matrix,
> the camera also seems to tilt slightly. Is that because the camera is
> pointing downward 1 unit on the Y axis when being transformed? I'm at a
> loss here...
>
>

My System SpecsSystem Spec
Old 02-28-2006   #9 (permalink)
Kevin Hoffman
Guest


 

Re: Rotating the PerspectiveCamera

camera1.UpDirection is in fact 0,1,0 - the same vector that I've been
using.. and the results still don't appear as though the camera is
rotating about itself... it still looks like its rotating about the
origin with regard to the Y axis...so its tilting instead of spinning.

When I do this while looking at a plane instead of looking at the
complex structure I was looking at, rotating using the above code seems
to make the plane rotate about the Y, not the camera...

If the camera is looking at a plane that is 50 units away, and the
camera "turns to the right" the plane should appear to move out of the
field of view to the left and eventually disappear.. until the camera
returns again to the same rotation. This is what I _want_ to happen.

What is happening is that using the code above, it appears as though
the plane is rotating about the Y axis, not the camera.

My System SpecsSystem Spec
Old 02-28-2006   #10 (permalink)
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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
screen rotating aoc Vista performance & maintenance 2 02-09-2008 09:10 PM
Rotating Images Stimpy Vista print fax & scan 1 07-13-2007 01:14 AM
Rotating Images ixloco Vista music pictures video 5 05-24-2007 02:27 PM
Rotating a received fax William Vista print fax & scan 0 03-27-2007 07:21 PM
Rotating menu swheeler Vista General 3 02-14-2007 01:03 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

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