Code Optimization

Interesting things in software development and code optimization

Silverligh 3D Icons


Today, I'm going to share my experience with the Silverlight and 3D. One time I saw a Microsoft presentation about a game platform or something, and there were 3D buttons like you see bellow, they did attract my attention so much that I started to make something similar. After a few days video review and thinking I started to implement it myself.

The main thing here is adding image layers and rotate them at once, plus some additional visual effects. So, here is the mouse move handler:

p = e.GetPosition(LayoutRoot);

ry = (mx - p.X) / 2;

rx = -((my - p.Y) / 2);

degree = Math.Atan2(p.Y - my, p.X - mx) * -180 / Math.PI;

degree = 180.0 + degree;

LayoutRoot.Effect.SetValue(DropShadowEffect.DirectionProperty, degree);

BorderControl.Projection.SetValue(PlaneProjection.RotationXProperty, rx);

BorderControl.Projection.SetValue(PlaneProjection.RotationYProperty, ry);

bgTranslate.X = offsetBackgroundX + ry / k;

bgTranslate.Y = offsetBackgroundY + (-rx / k);

foreach (IconImage ii in images)


ii.Image.Projection.SetValue(PlaneProjection.RotationXProperty, rx + (ii.ZIndex / globalZIndexStart));

ii.Image.Projection.SetValue(PlaneProjection.RotationYProperty, ry + (ii.ZIndex / globalZIndexStart));

ii.Image.Effect.SetValue(DropShadowEffect.DirectionProperty, degree);


So, you calculate angle from two points and rotate each image by the angle value.

Source code is bellow, thank you :) (9.3KB)