[WPF Disciples] PlaneProjection ... am I just being obtuse?

120 views
Skip to first unread message

Colin Eberhardt

unread,
May 10, 2010, 4:01:05 PM5/10/10
to WPF Disciples
Hi All,

I get the feeling I am just being a bit dumb here ...

The following XAML renders two rectangles of different width. Each are
rotated by 60 degrees about the Y axis, with an X offset such that
they are rotated around their left hand edge:

<UserControl ...
Width="683"
Height="197">
<Grid x:Name="LayoutRoot">
<Rectangle Width="700" Height="50" Fill="Black"
Margin="96,91,87,56">
<Rectangle.Projection>
<PlaneProjection CenterOfRotationX="0" RotationY="60"/
>
</Rectangle.Projection>
</Rectangle>

<Rectangle Width="200" Height="50" Fill="Black"
Margin="96,13,387,134">
<Rectangle.Projection>
<PlaneProjection CenterOfRotationX="0" RotationY="60"/
>
</Rectangle.Projection>
</Rectangle>
</Grid>
</UserControl>

How come the longer rectangle looks like it is rotated through a
greater angle? As I increase the width the problem becomes worse, i.e.
wider objects seem to rotate 'more rapidly'.

As I said, I have the feeling I am doing something utterly stupid
here.

Please point out my silly mistake, have a laugh, and I can stop
pulling my hair out ;-)

Many thanks,
Colin E.

Charles Petzold

unread,
May 10, 2010, 9:25:30 PM5/10/10
to wpf-di...@googlegroups.com
The problem here -- put it into 3D lingo -- is that you're looking at the
two rectangles with two different cameras.

For any element, the PlaneProjection is calculated as if you're looking
straight at the center of the element. Probably the best way to see this is
to remove the CenterOfRotationX settings (which means Y rotation is at the
center of the element) and then animate the RotationY properties in unison.
You'll see that the two elements are rotating around independent axes
(relative to the viewer), and yet they both disappear at 90 and 180 degrees.
That's impossible in the real world.

When you set the CenterOfRotationX to 0, you still looking at the wide
rectangle from a perspective of 350 pixels from the left of that rectangle,
but you're looking at the narrower rectangle from a perspective of 100
pixels from the left of that rectangle. Those two centers are not
horizontally aligned, so you're not looking at the two rectangles from the
same vantage point. That's why they seem to be rotated in different angles.

A problem like this is what's alluded to by the common saying "A little 3D
is a dangerous thing."

Charles





--------------------------------------------------
From: "Colin Eberhardt" <colin.e...@gmail.com>
Sent: Monday, May 10, 2010 4:01 PM
To: "WPF Disciples" <wpf-di...@googlegroups.com>
Subject: [WPF Disciples] PlaneProjection ... am I just being obtuse?

Charles Petzold

unread,
May 10, 2010, 10:06:52 PM5/10/10
to wpf-di...@googlegroups.com
Try setting the RotationY of the larger rectangle to 70.7 and the RotationY
of the smaller rectangle to 84.3. In both cases, you'll be looking at the
edge of the rectangle. I calculated these two angles by knowing that
PlaneProjection assumes a camera location of 1000 pixels on the Z axis and a
X position in the midpoint of the element, so the smaller rectangle extends
from X = -100 to +100, and the larger one extends from X = -350 to +350.
The calculations are:

smaller rectangle: atan(1000/100) = 84.3

larger rectangle: atan(1000/350) = 70.7




--------------------------------------------------
From: "Colin Eberhardt" <colin.e...@gmail.com>
Sent: Monday, May 10, 2010 4:01 PM
To: "WPF Disciples" <wpf-di...@googlegroups.com>
Subject: [WPF Disciples] PlaneProjection ... am I just being obtuse?

Sacha Barber

unread,
May 11, 2010, 1:55:51 AM5/11/10
to wpf-di...@googlegroups.com
Charles you know too much. Its all groovy though
--
Sacha Barber
sacha....@gmail.com

Peter O'Hanlon

unread,
May 11, 2010, 3:49:52 AM5/11/10
to wpf-di...@googlegroups.com
Yeah. What he said ;->
--
Peter O'Hanlon

Sacha Barber

unread,
May 11, 2010, 4:23:21 AM5/11/10
to wpf-di...@googlegroups.com
I also concur, I think?
--
Sacha Barber
sacha....@gmail.com

Peter O'Hanlon

unread,
May 11, 2010, 5:00:50 AM5/11/10
to wpf-di...@googlegroups.com
He said it with conviction, so even if he's wrong it sounds good;-> Only kidding Charles, this makes a lot of sense - and if I'd been thinking with my 3D modelling head on I'd have seen it.
--
Peter O'Hanlon

Colin Eberhardt

unread,
May 11, 2010, 5:44:33 AM5/11/10
to WPF Disciples
I'll second that.

Thanks Charles ... it has all 'clicked' for me now. I had not
considered the camera location.

On May 11, 6:55 am, Sacha Barber <sacha.bar...@gmail.com> wrote:
> Charles you know too much. Its all groovy though
>
> On Tue, May 11, 2010 at 3:06 AM, Charles Petzold <c...@charlespetzold.com>wrote:
>
>
>
> > Try setting the RotationY of the larger rectangle to 70.7 and the RotationY
> > of the smaller rectangle to 84.3.  In both cases, you'll be looking at the
> > edge of the rectangle.   I calculated these two angles by knowing that
> > PlaneProjection assumes a camera location of 1000 pixels on the Z axis and a
> > X position in the midpoint of the element, so the smaller rectangle extends
> > from X = -100 to +100, and the larger one extends from X = -350 to +350. The
> > calculations are:
>
> >   smaller rectangle:   atan(1000/100) = 84.3
>
> >   larger rectangle:  atan(1000/350) = 70.7
>
> > --------------------------------------------------
> > From: "Colin  Eberhardt" <colin.eberha...@gmail.com>
> sacha.bar...@gmail.com

Sacha Barber

unread,
May 11, 2010, 6:20:39 AM5/11/10
to wpf-di...@googlegroups.com
Yes 3D is hard, I always loose things and I am like aha my camera is pointing away from the plane, not towards it, its hard, like Charles said a little 3d is dangerous. Lukcily me team mate is ace with 3D, he has even written a 3D with excellent cube as a highly aerodynamic space ship, truly excellent.

--
Sacha Barber
sacha....@gmail.com
Reply all
Reply to author
Forward
0 new messages