A feature sadly rarely used, that can sometimes fasten coding are user-defined type conversion operators that are invoked with a cast. In the following example we define a struct Sentence that has an explicit conversion operator from string to Sentence.
In the Main method we are creating an instance of Sentence by casting a string to it.
The output of the program looks like this:
There is little difference in syntax for using an implicit conversion. It is done by declaring the conversion this way:
And using it without the cast:
Implicit conversion can improve code readability, however if you are using implicit conversion, you MUST MAKE SURE that the conversion will NEVER loose information or cause exceptions. The reason for this is the compiler, it will use the conversion and if that can cause a problem you will wreck havoc in your code.
Monday, April 11, 2011
Explicit and implicit conversion (C#)
Sunday, April 10, 2011
HLSL (DirectX/XNA) effect for stereo side by side anaglyph
The following code takes the input texture and paints over it the stereo effect.
The technique used (actually the colro transformation matrix) is called Dubois by it's original author.
You will need to set the texture and the width/height from your DX / XNA code:
You will have to render to texture and then show only the half of the image that you need (if the first image in the source is left show the left side, else the right). If the source is half SBS (means shrinked to half) then you need to stretch it back (double the width).
The technique used (actually the colro transformation matrix) is called Dubois by it's original author.
You will need to set the texture and the width/height from your DX / XNA code:
You will have to render to texture and then show only the half of the image that you need (if the first image in the source is left show the left side, else the right). If the source is half SBS (means shrinked to half) then you need to stretch it back (double the width).
To follow in the next few posts
In the next few posts I will post some HLSL source code I happened to code for a purpose of being able to view stereoscopic side by side video using anaglyph glasses (cyan/magenta in my case).
Stereoscopy is a technique used to produce 3D images or video from 2D source material.
The source consists of two images/video streams captured at the same time with an offset of a few centimeters from the objectives. Very similar to how our eyes do it.
I may post other HLSL pixel shader examples if I found them to have some general value to 3D folks.
In the meantime I will post a link to a prealpha version of a video player I'm working on. You can download and try to open some stereo material. If you dare then you will need to open the anaglyph shader that suits you glasses, which of course you need to see something.
Here is a link to the source material:
Stereo samples
The player currently supports only SideBySide material (not the TopDown).
Here is the link to the alpha version of the player:
3DPEE / Tridipy - player and HLSL compiler
You will need the latest DirectX and .NET Framework 3.5.
Do not expect absence of bugs :)
Stereoscopy is a technique used to produce 3D images or video from 2D source material.
The source consists of two images/video streams captured at the same time with an offset of a few centimeters from the objectives. Very similar to how our eyes do it.
I may post other HLSL pixel shader examples if I found them to have some general value to 3D folks.
In the meantime I will post a link to a prealpha version of a video player I'm working on. You can download and try to open some stereo material. If you dare then you will need to open the anaglyph shader that suits you glasses, which of course you need to see something.
Here is a link to the source material:
Stereo samples
The player currently supports only SideBySide material (not the TopDown).
Here is the link to the alpha version of the player:
3DPEE / Tridipy - player and HLSL compiler
You will need the latest DirectX and .NET Framework 3.5.
Do not expect absence of bugs :)
C++ reference operator standard behaviour exemption
If you are reading this, you probably already know that:
means take the address of value and put it in valueAdress.
So the & operator gives back the address of something?!
Well, that is wrong. I't not always like that. There is one case when this is untrue.
In this case we are using a pointer to member and it does not make much sense to get the address of something that does not have an instance. In this case the & operator gives back an offset to the member in the class we are pointing to.
The offset (in the last line) called the member pointer is dereferenced to a member and then assigned normally.
means take the address of value and put it in valueAdress.
So the & operator gives back the address of something?!
Well, that is wrong. I't not always like that. There is one case when this is untrue.
In this case we are using a pointer to member and it does not make much sense to get the address of something that does not have an instance. In this case the & operator gives back an offset to the member in the class we are pointing to.
The offset (in the last line) called the member pointer is dereferenced to a member and then assigned normally.
Quick fire&forget method to delay execution of some code in WPF in C# 4.0
This code will trigger aproximately after 5 seconds and will execute on the UI thread through the dispatcher:
This example uses the Task class introduced with .Net 4.
If you need a more precise way to do it the you should look at the Stopwatch class.
This example uses the Task class introduced with .Net 4.
If you need a more precise way to do it the you should look at the Stopwatch class.
JS / JQuery: Sync two lists / containers with drag and drop
Given the following HTML when you want to sync the drag and drop reordering of the UL to the child divs of div_container:
This code will do it:
You can attach the same metodology to div_container to make it fll duplex :)
This code will do it:
You can attach the same metodology to div_container to make it fll duplex :)
Subscribe to:
Posts (Atom)