Using projection to build a 3D carousel in Silverlight 3

<script type="text/javascript">&lt;!-- google_ad_client = &quot;pub-8333256540030241&quot;; /* 468x15, created 11/13/09 */ google_ad_slot = &quot;6101684395&quot;; google_ad_width = 468; google_ad_height = 15; //--&gt; </script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script><script src="http://pagead2.googlesyndication.com/pagead/expansion_embed.js"></script><script src="http://googleads.g.doubleclick.net/pagead/test_domain.js"></script><script>google_protectAndRun(&quot;ads_core.google_render_ad&quot;, google_handleError, google_render_ad);</script>  
  
<script type="text/javascript">&lt;!-- google_ad_client = &quot;pub-8333256540030241&quot;; /* 300x250, created 11/15/09 */ google_ad_slot = &quot;2868923228&quot;; google_ad_width = 300; google_ad_height = 250; //--&gt; </script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script><script>google_protectAndRun(&quot;ads_core.google_render_ad&quot;, google_handleError, google_render_ad);</script>

In the below example I used the new projection properties in Silverlight 3 to build a 3D image carousel. Moving the mouse left to right controls the speed and direction of the carousel. Moving the mouse up and down changes the opacity of the carousel, allowing you to see what is going on behind the carousel.

Please upgrade your browser

The ‘how to’ bit

To start with I have placed 6 images inside Blend and used the projection properties to offset them against each other to form a 3 dimensional hexagon. I do this by changing 2 projection properties:

CenterOfRotationZ=”-173″

RotationY=”60″

I use the ‘CenterOfRotationZ’ value to move the center point away from each image plane. This value needs to be the same on each of the 6 images I use in order to get them to match up at the edges. I then use the ‘RotationY’ value to change the angle of each image, as I have 6 images each image is rotated by a factor of 60 degrees (6 x 60 = 360 degrees).

I then place an x:Name on each images projection tag as seen in the below example:

<PlaneProjection x:Name=”Image1Projection” CenterOfRotationZ=”-173″ RotationZ=”0″/>

This will allow me to easily change the angle of each image dynamically in the C#.

In the C# I set up a listener to monitor the mouse movement and store the values in ‘pt’:

void LayoutRoot_MouseMove(object sender, MouseEventArgs e)

{

pt = e.GetPosition(LayoutRoot);

}

Next I set up a CompositionTarget.Rendering function so that I can update my 3 dimensional carousel constantly. I use the mouse X co-ordinates to change the speed and direction of the carousel and the mouse Y value to change the opacity:

void CompositionTarget_Rendering(object sender, EventArgs e)

{

Image1Projection.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;

Image2Projection.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;

Image3Projection.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;

Image4Projection.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;

Image5Projection.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;

Image6Projection.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;

image1.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;

image2.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;

image3.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;

image4.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;

image5.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;

image6.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;

}

Grab the code

As always you can grab the code source here .

 

written by Gavin Wignall \\ tags: 3D , C# , Carousel , Direction , Effects , Expression Blend , Fun , Mouse position , Rotation , Silverlight 3 , tutorial , XAML

<!-- /entry --> <!-- Pings -->

3 Pings to “Using projection to build a 3D carousel in Silverlight 3”

  1. Shadow effect using 3D projection in Silverlight 3 » Says:

    [...] Using projection to build a 3D carousel in Silverlight 3 [...]

  2. Creating a 3D cube with images in Silverlight 3 » Says:

    [...] Resource Using projection to build a 3D carousel in Silverlight 3 Shadow effect using 3D projection in Silverlight [...]

  3. progg.ru Says:

    Using projection to build a 3D carousel in Silverlight 3 »…

    Thank you for submitting this cool story – Trackback from progg.ru…


<!-- You can start editing here. -->

5 Responses to “Using projection to build a 3D carousel in Silverlight 3”

  1. 1. Mike Says:

    Hey, great post, really well written. You should post more about this.

  2. 2. GUSTAVO Says:

    how i do to select one image ?

  3. 3. Gavin Wignall Says:

    I have not written in the functionality to select the items in the carousel, but it is not that difficult. Each image is able to be treated as a button like any other normal image.

  4. 4. Katarina Says:

    Hello! Love your demo!

    I used UserControls instead of images, they appear correctly in Blend but when I run the application they won`t rotate.
    It works fine with an image control or grid control.

    How do I get to rotate my UserControls also?
    What am I missing?
    Please help out!

    Thanks in advance!

    Katarina

    Here is a short code of my example…

    MAIN PAGE XAML

    MAIN PAGE CODE BEHIND

    public MainPage()
    {
    // Required to initialize variables
    InitializeComponent();
    ucProj1 = new PlaneProjection();
    ucProj2 = new PlaneProjection();
    ucProj3 = new PlaneProjection();
    ucProj4 = new PlaneProjection();
    }

    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
    ucProj1.RotationY = 60;
    ucProj2.RotationY = 120;
    ucProj3.RotationY = 180;
    ucProj4.RotationY = 240;
    LayoutRoot.MouseMove += new MouseEventHandler(LayoutRoot_MouseMove);
    CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
    }

    void CompositionTarget_Rendering(object sender, EventArgs e)
    {
    ucProj0.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;
    ucProj1.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;
    ucProj2.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;
    ucProj3.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;
    ucProj4.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;
    ucProj5.RotationY += ((pt.X – (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;
    }
    private Point pt;
    void LayoutRoot_MouseMove(object sender, MouseEventArgs e)
    {
    pt = e.GetPosition(LayoutRoot);
    }

    USER CONTROL with a grid

    <UserControl

    …..
    …….

  5. 5. jairoxxx Says:

    the function to get “-173″ is:

    double getApothem(double height, double sides)
    {
    var x0 = 360.0 / (2 * sides);
    var k = Math.Sin(Math.PI * x0 / 180.0);
    var r = (double)(height / 2) / k;
    return – Math.Sqrt((r * r) – Math.Pow((double)height / 2, (double)2));
    }

Leave a Reply

Name (required)

Mail (will not be published) (required)

Website

<!-- /post -->
<!-- /content -->
<!-- /left-col -->
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
3D表面重建中,适应性条纹投影用于避免图像饱和。饱和是指当投影的光线过亮时,图像中的某些区域会出现过曝或过暗的现象。为了解决这个问题,适应性条纹投影技术被引入。 适应性条纹投影技术根据场景的亮度情况调整投影光线的亮度,并在图像中生成相应的条纹纹理。这些条纹纹理具有不同的亮度和颜色,可以在图像中创建一个光照变化的效应。通过这种方式,适应性条纹投影技术可以在不同亮度的区域中保持图像的细节和清晰度,避免了图像饱和现象的发生。 在3D表面重建中,适应性条纹投影技术非常有用。当使用投影仪投影条纹图案到三维表面上进行重建时,不同区域的亮度可能有所不同。一些区域可能非常亮,而另一些区域可能非常暗。如果不处理好这些亮度差异,就会出现图像饱和现象,导致重建结果不准确。 适应性条纹投影技术通过实时调整投影光线的亮度,使得不同区域的亮度更加均衡。这样,被投影区域的光照变化就可以更好地还原,从而获得更准确的三维表面重建结果。同时,适应性条纹投影技术还可以根据场景的亮度变化自动调整投影光线的亮度,提高了系统的稳定性和适应性。 总之,适应性条纹投影技术是一种用于避免图像饱和的重要技术。在3D表面重建中,它通过实时调整投影光线的亮度,保持图像区域亮度的均衡,从而获得更准确的重建结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值