# Code Snippets #27 – Set3D array extension method

Published 7/13/2015 by createdbyx in Code Snippets | Example | News | Programming
Tags: , ,

Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only

```/// <summary>
/// Sets the value in a single dimensional array that represents a three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose value is to be set.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <param name="x">The x index (0 to width - 1).</param>
/// <param name="y">The y index (0 to height - 1).</param>
/// <param name="z">The z index (0 to depth - 1).</param>
/// <param name="value">The value to set.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1.
/// </exception>
/// <remarks>
/// <p>This method provides an alternative to working with three dimensional arrays "var value = new int[3,3,3];" by operating
/// on a single dimensional array using a math formula to determine the index into the array.</p>
/// <p>Think of a multi-layered image. Each image layer consists of a grid of cells defined by width * height.</p>
/// <p>We can use the formula "layer * (width * height)" to get the starting index of the layer in the array.
/// To get the index in the image we can use the formula "(y * width) + x".
/// Combining these two formulas we can access any grid cell of any layer in the array like so "(layer * (width * height)) + ((y * width) + x)".</p>
/// <p>This method does not perform range checking and will throw index out of range exceptions if invalid arguments are specified.</p>
/// </remarks>
public static void Set3D<T>(this T[] array, int width, int height, int x, int y, int z, T value)
{
if (width < 1)
{
throw new ArgumentOutOfRangeException("width");
}

if (height < 1)
{
throw new ArgumentOutOfRangeException("height");
}

array[(z * (width * height)) + ((y * width) + x)] = value;
}```

# Unity 101 Tip #85 – Disallow Multiple Components Attribute

Published 7/10/2015 by createdbyx in Unity | Programming
Tags: ,

If you are writing custom scripts there may be situations where you don’t want the same component added more then once to a game object. For such situations Unity provides the DisallowMultipleComponent attribute that you can specify in your scripts code.

# Code Snippets #26 – Generic Image Array Smoothen

Published 5/11/2015 by createdbyx in Code Snippets | Example | News
Tags: , ,

Takes in an array of floats representing pixels ordered left to right top to bottom. Width & height arguments specify the image dimensions.

```        /// <summary>
/// Smoothens out the image.
/// </summary>
/// <param name="image">The source image.</param>
/// <exception cref="ArgumentNullException"><paramref name="getPixel"/> or <paramref name="setPixel"/> is <see langword="null" />.</exception>
public static void Smoothen(this float[] image, int width, int height, Func<int, int, float> getPixel, Action<int, int, float> setPixel, float smoothinValue = 9f)
{
if (getPixel == null)
{
throw new ArgumentNullException("getPixel");
}

if (setPixel == null)
{
throw new ArgumentNullException("setPixel");
}

for (var x = 1; x < width - 1; ++x)
{
for (var y = 1; y < height - 1; ++y)
{
var total = 0f;
for (var u = -1; u <= 1; u++)
{
for (var v = -1; v <= 1; v++)
{
total += getPixel(x + u, y + v);
}
}

setPixel(x, y, total / smoothinValue);
}
}
}```

# Unity 101 Tip #84 – Don’t just show errors alert them

Published 5/4/2015 by createdbyx in Unity
Tags: ,

It’s not something people think about these days. Back in the 90’s when MS-DOS was king, alerting the user to a problem involved both a visual alert as well as a auditory alert in the form of a “beep”. It’s actually something I miss from those days. Luckily the unity editor has an API to alert the user and wouldn't you know it, it’s called “Beep”!

# Unity 101 Tip #83 – Detect when unity compiles scripts *Redux*

Published 4/27/2015 by createdbyx in Unity
Tags: ,

If you are developing unity editor extensions often it is necessary to know weather or not unity is compiling the projects scripts. To determine if unity is currently compiling you can simply check the EditorApplication.isCompiling flag in your code before deciding what to do. See older related tip and code example here.

# Unity 101 Tip #82 – Enhancing the Project and Hierarchy windows

Published 4/24/2015 by createdbyx in Unity
Tags: ,

Unity provides hooks into the Project and Hierarchy windows OnGui event. This allows you to add additional flair to these windows. To learn how to enhance these windows see the fallowing documentation pages

If you want an example project to work off of and learn from there is an open source project called “UnityEditorEnhancements” that you can download as a zip file or you can fork the Mercurial repository.

# SteelSeries 7H Final Review

Published 4/13/2015 by createdbyx in News | Reviews
Tags: ,

I don't like to write reviews immediately after receiving an item, I'd much rather wait a good long time before posting. I purchased these headphones back in Oct 25, 2010 and am only posting this now because the headphones are still for sale on ncix and else where.

Ultimately they worked great for about 2 years of infrequent use, but considering that they are a mid range (price wise) headset and I paid \$130 after tax & shipping, I expected them to last a lot longer.

After the first few months the glue partly separated on one side of the top padding. (See link to picture below)

Then the cord had a line break at the point at which the cable merges with the micro usb style end (the end that plugs into the left ear muff). I fully admit this was most likely my fault with the cord break. 2-3 times I had my headphones on and while sitting in my desk chair I bent over to pick something off the ground and yanked on the cord. Not enough to pull them off my head but enough for me to curse at my own stupidity. :P  Even though they did not break after being yanked they did eventually stop working and I needed to bend and twist the cable to get the sound working.

I finally contacted SteelSeries support and was able to purchase a replacement cable for just \$5 through PayPal. I bought 2 cables just in case it broke again and I would not have to go through the replacement process another time.

Over the last year the right ear muff would periodically stop working. I would only have to twist the headphones on my head slightly to get them to work. I suspected at the time that it was a connection issue at the point where the top head piece clips into the right ear muff piece. There are 4 springy pins in the ear muffs that make the connection with the top piece. I thought there was just a lack of solid connection but the problem got a bit worse even after a bit of polishing/cleaning.

They finally died this last week when the right ear muff stopped working completely. I broke down and decided to take the right ear muff piece apart. I inspected the cable where the ear muff passes through the hinge that allows the muff to rotate 90 degrees and there did not seem to be any issues with frayed/pinched wiring etc. Before putting them back together I did adjust the wire routing slightly to give it more slack but it did not fix the issue.

Next I took apart the top piece. There were 3 screws holding either the connection points at both ends of the top piece and there did not appear to be any issues there. Then I peeled back the padding and tried taking off the plastic panel via 4 screws but there is 2 plastic weld points that prevented me from removing the panel. I suspect that the problems are hidden behind the panel but I can't get access to it without destroying the panel in the process.

Here is a picture showing the breaks in the plastic, glue separation, and stress points. 7H Problems Screenshot

The glue separation is due to a combination of the heat from my head and the flex in the top part of the head band and never came apart more then what you see in the picture.

I rated this two stars because a 5 star headset is perfect, every part works until it has been used for a few years, and can take a beating. Based on my experience these are not able to take much of a beating in day to day use. I only ever used them periodically at night when other people were sleeping otherwise I prefer to use my 5.1 surround sound speakers. I used them a few times when traveling and kept them in a laptop backpack but always took care to ensure there safety.

All in all when they did work they worked great, but ultimately I won't be buying another SteelSeries headset product. I have nothing against SteelSeries but I am the type of person that expects more out of the products I buy. I'm sure others have had great experiences with there 7H's but I feel my experience was lacking. Buying headphones off the internet is always a crap shoot as you can only rely on on line reviews, and each person has different hearing and tastes.

I have since purchased a Logitech G430 as a replacement based on the reviews, specs, and the fact it has a 3 year warranty.

# Work Delegation

Published 4/8/2015 by createdbyx in News
Tags:

I came across a YouTube video related to delegating your work and thought I would try and break it down more as it video did not quite make sense to me at first.

Me
==========
5 day work week
8hrs day
\$25hr wage
\$200 a day
\$1000 week income

Assistant
==========
1 day work week
8hrs day
\$30hr wage
\$240 day
\$240 week income

(me) \$1000 a week – (assistant) \$240 a week = (me) \$760 at end of week

I earned \$760 adjusted weekly income and I worked 5 days a week

I work 5 days a week and spend \$240 a week for someone to work one day means I technically put in a 6 day work week but personally earned \$760 if I used an assistant to work that extra day. Normally I would have had to work a 6 day a week job but hiring the assistant means I can work a regular 5 day a week job.

In reality if I personally worked for 5 days a week without an assistant I would earn \$1000 a week. At 4 days a week at \$25hr I make \$800 week Monday to Thursday. I hire an assistant at \$30hr to work on Friday and they get my \$200 a day wage for taking my place and working on Friday. Then on Friday I give them an extra \$40 for working on Friday so they earn there \$30hr/\$240 a day wage.

So at the end of the week I make \$800 - \$40 = \$760 income for a 5 day work week even though I only actually worked 4 days. You earn \$760 take home at the end of the week after having paid \$40 to not work on Friday. The benefit to me is that for \$40 a week expense I can work 4 days a week and have someone else do my job on Friday.

For the assistant they are getting paid more money then I do at \$30hr plus I am paying them an additional \$40 for that day of work. So the assistant doing my job for one day actually gets paid \$5hr more than I would have earned.

Just because I paid someone to work one extra day for me what benefit does that get me? I still work 4 days a week and I have to spend money to hire an assistant to work 1 extra day but in reality where does that get me?

Essentially what I am getting from hiring an assistant is 24hrs of free time and it only costs me \$40. And having 24hrs of free time allows me to get other things done. This is of course totally dependent on how valuable the work my assistant does and weather or not they are properly trained and capable of performing the assigned tasks. From the assistants perspective they are making \$5hr more then I do but are under more pressure to perform in order to keep the job in order to justify the \$30hr wage.

# Unity 101 Tip #81 – Camera Fog

Published 4/6/2015 by createdbyx in Example | Programming | Unity
Tags: ,

The fallowing script allows you to control fog settings on a per camera basis, allowing you to use say green fog for one camera but red fog for another camera.

Unity 5 package demo is available here CameraFog.unitypackage (46.66 kb)

CameraFog.cs script

```// --------------------------------------------------------------------------------------------------------------------
//   contact@codefarts.com
//   http://www.codefarts.com
// --------------------------------------------------------------------------------------------------------------------

// Per-camera fog
// This is a simple class that, when added to a GameObject with a camera, allows you to control the fog settings for that camera separately from the global ones.
// I'd love to hear from you if you do anything cool with this or have any suggestions :)
// Original author: http://wiki.unity3d.com/index.php/User:Tenebrous
// Author website as of 2015: www.tenebrous.co.uk
// Source: http://wiki.unity3d.com/index.php/CameraFog

namespace Codefarts.GeneralTools.Scripts.Camera
{
using UnityEngine;

/// <summary>
/// Modifies a camera to allows you to control the fog settings for that camera separately from the global scene fog or other cameras.
/// </summary>
[RequireComponent(typeof(Camera))]
[ExecuteInEditMode]
public class CameraFog : MonoBehaviour
{
/// <summary>
/// The enabled state weather or not fog will be visible.
/// </summary>
public bool Enabled;

/// <summary>
/// The start distance from the camera where the fog will be drawn.
/// </summary>
public float StartDistance;

/// <summary>
/// The end distance from the camera where the fog will be drawn.
/// </summary>
public float EndDistance;

/// <summary>
/// The fog mode that controls how the fog is rendered.
/// </summary>
public FogMode Mode;

/// <summary>
/// The density of the fog that is rendered.
/// </summary>
public float Density;

/// <summary>
/// The fog color.
/// </summary>
public Color Color;

/// <summary>
/// Stores the pre-render state of the start distance.
/// </summary>
private float _startDistance;

/// <summary>
/// Stores the pre-render state of the end  distance.
/// </summary>
private float _endDistance;

/// <summary>
/// Stores the pre-render state of the fog mode.
/// </summary>
private FogMode _mode;

/// <summary>
/// Stores the pre-render state of the density.
/// </summary>
private float _density;

/// <summary>
/// Stores the pre-render state of the fog color.
/// </summary>
private Color _color;

/// <summary>
/// Stores the pre-render state wheather or not the fog is enabled.
/// </summary>
private bool _enabled;

/// <summary>
/// Event that is fired before any camera starts rendering.
/// </summary>
private void OnPreRender()
{
this._startDistance = RenderSettings.fogStartDistance;
this._endDistance = RenderSettings.fogEndDistance;
this._mode = RenderSettings.fogMode;
this._density = RenderSettings.fogDensity;
this._color = RenderSettings.fogColor;
this._enabled = RenderSettings.fog;

RenderSettings.fog = this.Enabled;
RenderSettings.fogStartDistance = this.StartDistance;
RenderSettings.fogEndDistance = this.EndDistance;
RenderSettings.fogMode = this.Mode;
RenderSettings.fogDensity = this.Density;
RenderSettings.fogColor = this.Color;
}

/// <summary>
/// Event that is fired after any camera finishes rendering.
/// </summary>
private void OnPostRender()
{
RenderSettings.fog = this._enabled;
RenderSettings.fogStartDistance = this._startDistance;
RenderSettings.fogEndDistance = this._endDistance;
RenderSettings.fogMode = this._mode;
RenderSettings.fogDensity = this._density;
RenderSettings.fogColor = this._color;
}
}
}```

# Why the big 3 VR makers could poison the well, … again.

Published 4/4/2015 by createdbyx in News

When the Oculus Rift became a successful Kickstarter it helped launch a world wide interest again in the promise of VR. Even I began to realize that VR could actually become a thing given the advances in technology. But in the subsequent years I can’t help but see all the familiar patterns and signs that led to the downfall of VR way back in the 1990’s.

I hate to be a pessimist but it’s hard not to be as events of recent years have unfolded. I’ve been wanting to write about VR for a while now and finally decided to write down a few of my thoughts on the subject.

#### But first lets sing the praises of VR shal we

When I caught wind of the Oculus rift it had taken me by surprise. Having been through the disappointment of VR back in the 90’s I was so close to buying a Forte VFX-1 headset but never did. Being a tech geek and budding programmer at the time I know what I’d be getting and I just couldn't justify the cost at the time. The plan was to wait for a newer better cheaper version to come out but nothing ever did.

Funny thing happened between the 1990’s and when Oculus make VR popular again. I completely forgot about VR and I rarely if ever thought about it. It was a distant bitter memory of what could have been. I have resisted the urge to get a smart phone because of bitter resentment towards the way the cell carriers operate, but along came OnePlus and they won me over with a off contract phone that was high end yet still relatively affordable. The OnePlus One was the first cell phone I’ve ever owned and it’s pretty nice. Not having a smart phone meant that I was out of the loop as to what had been going on in the smart phone space. Oculus made me realize that yes indeed smartphones have exploded and along with them the cost of small high resolution screens, and accurate tracking sensors had come down in price significantly. VR could be a real thing again!

Then along comes Sony and there project Morpheus. Wow I thought there maybe something to this VR thing again. All of what I was seeing from Oculus and Sony were very promising and I was getting excited for VR all over again. Then John Carmack a titan in the gamming industry left ID Software to join Oculus and BAM! Drop the mic. VR IS A THING, AND WILL BE A THING! And if John Carmack just joined Oculus, VR was going to be a thing and it was going to be awesome and Oh my F-ing God just take my money NAO!!!. F-Yeah! VR is back baby! Wuhooo.

Then the news broke and the internet was set a blaze. Facebook acquires Oculus.

/facepalm Kill me now. Just, fuck off. FUCK! And I was on such a high. It was fun while it lasted I guess.” Well that was my initial reaction. You see I am not what you would call a social butterfly like billions of others. I don’t use social media because I know what it really is and it has nothing to do with being social. But that is a discussion for another blog post. After taking a deep breath and as much as I hated admitting it, Facebook acquiring Oculus was for the best. It meant Oculus now had almost limitless funding and could really invest heavily in making the best VR headset money could buy at a price that was reasonable. VR was still on track to becoming a reality and a \$2 billion investment means investors will want to see a return on that investment.

Then the unthinkable. Seemingly out of the wood work and not to be out done Microsoft announces the HoloLens a augmented reality headset. F**k, now I have to buy two devices. Grumble Grumble. I see HoloLens as the ultimate productivity tool for programming. Not just programming but programming anywhere not just sitting at my desk. And programming with multiple virtual screens hovering around me and around my house. F-Me that would be so awesome and useful. Not to mention for makers and prototyping in 3D right in front of your physical space.

With all the buzz going around with VR & AR devices being announced every other week it seemed the stink of the 90’s had completely wore off. With so many contenders in the race the future looked promising.

… Then the shit just went nuclear …

HTC announces the Vive and a partnership with Valve. Not only that but every article, YouTube video, and podcast that talked about the HTC Vive about the people who got to experience it said it was the best dam VR experience they have ever experienced, even better then what was on offer from Oculus. Just when I thought my anticipation could not get any higher I, … I may have peed a little. :P Just kidding. It wasn't just the announcement it was also the announcement of a shipping date as well. Fall of 2015. At the time Oculus has been sketchy about release dates as was every other VR, AR device maker.

Ho-ly-crap the tech for the Vive and the demos people raved about made me a believer. Sorry Oculus but you just got sent to the back of the bus. I am now leaning towards getting a Vive headset. Wicked tech and a standing experience in VR along with accurate VR controllers. But it is the one demo that made me a believer. That made my heart pulse and my palms sweat. The Portal Tech-Demo where you had to fix the broken robot blew my mind and made me want more. I can not describe in words how awesome that demo looks. It feeds into so many aspects of a tech geeks life. VR, High tech, Information rich, Programming, Engineering, Puzzle solving, accurate 1 to 1 controller interactions and tooling, simply awesome sauce. Everything I love about tech all in one demo. The kind of demo that makes you evaluate your life choices to ensure that you live long enough to experience it first hand. Hahaha!

With all the buzz in the VR, AR space and with all the various peripherals Virtuix Omni, Cyberith Virtualizer, and Sixense STEM system to name a few, there is a lot to be excited over. But then again after you calm down and take a step back, and begin reflecting upon it all, you find the ghosts from the past reaching up to grab hold of you …

#### Hardware Costs

In my opinion I think there is a strong chance we are going to see deja vu of 90's VR all over again. Yes the big 3 VR headsets Morpheus, HTC Vive, Oculus Rift & maybe OSVR are great but they are suffering the exact same problems that plagued there 90's counterparts.

For one the price. \$200->\$500-+ for a head set? Automatic fail. I suspect these companies are seeing through a haze of dollar signs as a new market is on the horizon. I’m sure it’s the same haze that over took there 90’s counter parts. They must think because they get away with selling \$700+ dollar smart phones they they can get away selling “premium” headsets.  Instead they need to be thinking critically and making investments toward the long term viability of the platform. The only way I see VR truly taking off in a reasonable time frame (IE: the next 3-5 years) with a sufficient install base is if those who can afford it Facebook, HTC/Valve, Sony sell there hardware below cost or at cost for at least the first year or so.

If they can sell a headset at cost for around \$99 then there is a chance it can be fast tracked and go main stream faster rather then slowly seeding units over the next decade as the masses slowly adopt future & cheaper revisions of the product. This is critical because without hardware being in the hands of consumers there is no VR market, and there is zero incentive for developers to spend there time making games for it. Period. You absolutely need to get headsets into the hands of people by any means necessary and plant the seeds of a future in VR that you can then profit from, and build upon in the coming decades.

Stop and think about that rumored \$300-\$500 “premium” price tag for a HTC Vive for a second. What else can you buy for \$500 or less? A Xbox One, PS4, even a decent tablet or computer for a casual PC user. Comparatively the complexity of a VR headset is a very very simple display device, where as consoles/PC's contain a motherboard, memory, graphics cards, hard drive, & a pair of controllers etc. Much larger and much more complicated devices sell for less then \$350-\$400.

That is to say nothing of how much additional cost there is for VR controllers like the Vive wands, or the PS Move wands, or older hardware like the Razer Hydra.

Consumers are not stupid. The assumption that they are stupid is stupid. A \$200-500 headset which is nothing more then a few sensors and a screen is not going to be a hot ticket item in the eyes of the main stream consumer.

Just look at Samsung's Gear VR selling for a ridiculous \$200 and it is nothing more then a hunk of plastic and 2 lenses with the standard tracking sensors, and no screen. Tracking sensors by virtually all accounts are cheap given the rise of smart phones. And you have to buy a Note 4 just to use the dam thing, bringing the total cost to use it even higher.

And the main stream consumer is who you have to convince to kick start a VR future. If VR is kept delegated to a select few dedicated gamers and the like you can expect the VR market to be a slow decade(s) long crawl to adoption. If initial headsets are at a attractive price point that a mainstream consumer can actually afford, after buying a pc or console to power it etc. then you can expect VR to take off in a big way.

UKRifter put it best when he recently stated in one of his DK2 videos that “… if there thinking of charging that kind of premium, I’m kind of out. You know I’ve got kids & expenses in my life … I love VR but I’m not going to be paying those prices. And you’ve got to realize virtual reality is for the poor…

As of this posting I have yet to see any of these companies offering preorders. I admit it is April 2015 and the earliest headsets are rumored to be available is late 2015 but as a headset maker it would make sense to start polling people to get actual numbers on how many people are planning to buy a headset at launch. It’s the same problem that plagued the Wii and other hardware with lack of stock at release and months thereafter.

Headset makers need to be smart about how many units they can expect to ship at launch and if it were up to me I would start preorders and taking peoples money by no later then July 2015 or early fall. That way you know exactly how many people are buying and exactly how many headsets you need to get ready for launch as well as how many additional headsets to prep for the main stream retail sales.

It’s 2015 and I can’t stand it when companies don’t take advantage to the global internet enabled customer base by polling or setting up preorders in order to ensure there product is going to be available to people on day one. Creating artificial scarcity or introducing “premium” headsets is I’ll advised when trying to kick start a totally new platform.

#### Software & Content

You also need to take into account content. There will be very little content available at launch and for the next year or two after launch. Dropping upwards of \$500 and having only a small handful of VR games available to play is not going to cut it. Let alone games the consumer would want to play. People are not going to justify a \$500 headset if there is no content for it especially main stream consumers. But if it was \$99? Yes you would, especially knowing that there is more content on the way.

I have to admit that it frustrates me to no end to see argument after argument on various forums and YouTube about the technical aspects of VR from people who are not technically inclined or trained. They seem to have this view that somehow they are going to see high detail high poly count AAA games for VR games and that it is going to cost a fortune in PC hardware to support or that the consoles don’t have enough horsepower to support VR. A ridiculously stupid argument.

Initial VR games are going to be low poly, cartoony, wow style graphics in order to maximize the supported hardware that is already out there. I suspect you can see the quality of VR games to be a few years behind there standard non VR counterparts.

It’s only been roughly 2-3 years since the Oculus Kickstarter so developers have not been working on VR titles for very long. Taking into account that developers have been waiting to see what becomes of the hardware. I’d say until the big three threw there hat into the ring Sony, Oculus, HTC, developers have really only just started working on new titles in the last year. It takes a good 2-5 years to develop a game and that does not even take into account the additional challenges of developing for VR. Even adapting existing titles to VR can be tricky.

I can’t imaging that there will be no more then say 12 to 24 decent VR titles at launch and a slew of half baked demos and mini games. Not a lot for a consumer to justify a \$200-\$500 price tag.

#### Conclusion

Establishing a new VR market is a huge uphill battle. On one hand you need headsets in the hands of enough consumers to make the platform viable for developers to make content for it. On the other there is technically a lot of content out there that can be adapted to VR but with no headsets in the hands of consumers developers are not likely to take the time to adapt there preexisting titles for a platform that has yet to see adoption. Chicken before the egg scenario.

For VR to be considered a success within the next 5 years and achieve widespread adoption headsets need to be priced under the \$150 range and absolutely no more. I hope I’m wrong but realistically when I take my VR blinders off and take into account all the factors I just don’t see VR going main stream and achieving mainstream adoption any time soon. Like the next decade soon. Just as I think there is a good chance the big three VR makers could poison the well once more and make VR a difficult sell for widespread adoption.

When you put it all together all I’m really seeing is very high prices to get into VR not to mention additional costs for VR controllers, a decent or high end PC depending on your gamming preferences, and a industry seemingly all to ignorant of history and setting them selves up to fail.

Maybe I’m wrong and I hope I am but time will tell if the next 5 years VR has gotten a well established foot hold and is on it’s way to becoming main stream. As someone who has been let down by the promise of VR in the 90’s I’m not holding my breath.

# Created by: X

## Just another personal website in this crazy online world

 Dean Lunz (aka Created by: X) Computer programming nerd, and tech geek. About Me -- Resume