Archive for the ‘Posts’ Category

Creating shadows in WPF & Silverlight games

Friday, June 18th, 2010

In this short post I will show example of creating shadows for isometric games, like one shown on the picture below:

 wpfshadow_game.png

For this purpose you need an image with transparent background. Then a copy of the image should be:

1) Flipped - Scale transform (y = -1)

<ScaleTransform ScaleY=”-1″ />

2)  Skewed - To simulate position of light

<SkewTransform AngleX=”20″ />

3) Blurred

<BlurEffect></BlurEffect>

4) Opacity Mask applied to make shadow more realistic

<LinearGradientBrush StartPoint=”0.5,1″ EndPoint=”0.5,0″ >

    <LinearGradientBrush.GradientStops><GradientStop Offset=”0″ Color=”Black”/>

           <GradientStop Offset=”1″ Color=”Transparent”/>

    </LinearGradientBrush.GradientStops>

</LinearGradientBrush>

5) Source image transformed to Black and White:

<FormatConvertedBitmap  Source=”..”  

DestinationFormat=”BlackWhite” />

As a result you will get something like this:

 wpfshadow.png

Links:

Download Source

Code Project Article on the same topic

Synchronuos start of many instances of the same process

Friday, February 27th, 2009

Suppose you need to start 5 instances of the same process simultaneously. There are no problems until those process does not use resources exclusively. For example they are trying to write to the same log file at the same time:

config1.GIF

In this case you will need to synchronize them in a some way. You may want to make those processes to run some sections of code in a mutually exclusive mode:

config2.GIF

 This may be naturally achieved by introducing a mutex synchronization. The sample below shows this approach on practice: mutex.zip

To see the results start several instances of this application at the same time, and the release mutex lock by pressing any key on the application’s console. You will see how other processes will react on this event:

synchronizedstart.JPG

Оставьте место для чуда!

Wednesday, February 4th, 2009

Недавно я наткнулся на книгу Стивена Хокинга, “Краткая история времени”. В ней автор пытается дать своё толкование истории и происхождения Вселенной, всячески подчеркивая свой неоспоримый авторитет в этой области.

Но есть одно “но”: это принцип неопределённости, который часто упоминается в книге. А говорит, он о том, что как бы нам не хотелось, мы не можем измерить одну величину, не повлияв при этом на другую. Для науки это означает, что какие бы точные методы измерения не использовались, какие бы совершенные теории не изобрел бы человеческий гений - всегда найдется место для “неопределенности”, всегда найдётся место для “чуда”.

Так вот, в этот кризисный для нас и для всего мира время, вероятно, не стоит гнаться за несбыточными надеждами, может просто стоит оставить место для чуда?

Please, leave a place for a miracle!

I recently came across a book by Stephen Hawking, “A Brief History of Time”. The author tries to give his interpretation of the history and origin of the universe there, often stressing his indisputable authority in this field. But its ok, he is really great scientist.

But there is one “but”: it is the principle of uncertainty, which is often mentioned in the book. And it says that no matter how hard we’d want we will be unable to measure one value, while not predictably affecting the other. For a natural science, this means that whatever exact measurement methods are not used, whatever the theory is not invented by a genius of a man - there will always be a place for the “uncertainty”, there will always be a place for “miracle.”

So, in this crisis time for all of us in the world we’d probably should not pursue delusive hopes, but may be simply leave a place for a miracle?

Matrix Calculator

Tuesday, January 27th, 2009

One of my tools started to became more and more popular. This is Matrix Calculator. It appears on the first page of a google search in Ukrainian segment:

Matrix Calculator on Google

It was written about 5 years ago when I was a university student. There is a great tool for dealing with matrices - called MathLab. It is very powerful, but also a very large and probably expensive tool. One of the great feature of MathLab is its syntax: very simple and straightforward. And it is very good suitable for console input.

So, what I’ve tried to do is to simply use MathLab syntax and implement most recently used matrix functions in my calculator. It works under Windows XP in Console mode. Here is a sample of using Matrix Calculator:

Sample Calculations

It supports following functions:

  • iden(dim) - identity matrix of dim x dim 
  • det(identifier) - determinant of matrix
  • slae(identifier) - solves linear equations
  • transpose(identifier) - transpose
  • inv(identifier) - invariant matrix
  • rank(identifier) - rank of the matrix
  • gauss(identifier) - diagonalization of matrix using Gauss method

Matrix Calculator may be download by the following link:  Download Matrix Calc (Zip)

Today I am 25

Tuesday, January 20th, 2009

Today is my 25-th birthday!

25.JPG