After reading Chase Thomas’ blog entry on Vector path movement. Moving a vector from one point to a given point along a straight line. I realised he had perhaps used the most complex solution I had seen. After leaving a little comment about how I would of done it, I decided that, to help those who need it, I wrote some HelperMethods of my own.
The helper methods themselves include a function called MoveToPoint with a version for each Vector (Vector2, Vector3, Vector4). Where you pass in your position, the point you want to move towards, the speed your moving at, and the amount of time your moving over.
The Vector2 method looks something like this:
public static Vector2 MoveToPoint(Vector2 position, Vector2 endPoint, float speed, double elapsedTime)
{
if (position == endPoint)
return position;
// Work out the direction and how far we have to go to the end point
Vector2 posToEnd = endPoint - position;
// Get the unit vector for this
Vector2 normal = posToEnd;
normal.Normalize();
// based on the amount of time passed, and the speed work out how far we would move
// in that time
float distanceModifier = speed * (float)elapsedTime;
// if the required amount of movement to reach the end of the line
// is less than the distanceModifier, then change the distance modifier to only
// be the required amount
// (We also avoid doing a square root, in the condition as square roots eat processor time)
if (posToEnd.LengthSquared() < (distanceModifier * distanceModifier))
distanceModifier = posToEnd.Length();
// Okay so we now how much we are going to move. Either as many units as the speed and time calculated
// or the exact amount to reach the end of the line
Vector2 velocity = normal * distanceModifier;
return position + velocity;
}
I’ve got two versions of them. c# 2.0 static class VectorHelpers.
For those of you using XNA 3.0 CTP with Visual Studio 2008 and C# 3.0, I’ve also made them as extension methods: VectorExtensions.
Feel free to use them as you like. They are both public domain
EDIT: Changed code where distanceModifier = posToEnd.LengthSquared() to distanceModifier = posToEnd.Length() at line 21 in the example. Changed uploaded files to reflect this.
Also, if your using the ExtensionMethods you will also require adding System.Core.dll as a reference to your XNA 3.0 library and/or XNA 3.0 game projects.
public Person GetNik()
{
Nik = new Person();
Nik.Geekiness = GeekyLevels.High;
Nik.Humor = HumorTypes.AquiredTaste | (Recipient.InsultsReception == InsultReceptionTypes.CanTakeIt ? HumorTypes.Insulting : 0);
Nik.Job = "Software Engineer / Applications Developer";
Nik.Coolness = Int.Max;
return Nik;
}
Well after yesterday’s rant, I thought about how I could make the development of my new site appealing to me, rather than just being another “website”. I decided to start a series of articles that document what I do and my processes as I work through creating the first part of my site. My new blog. This way, I can tell myself I’m informing the world, and feel good about it which should give me motivation to write what I (I can’t stress that ‘I’ enough) consider as mundane code.
So…
NikRadford.co.uk is likely to become my new home as TerminalDischarge dissolves into being more of an E-Mail host. It’s going to contain various things of mine (eventually) with all my works of creativity, as well as the no de-facto standard of a blog.
Most likely I’ll just stick a redirect here to the new one and import these posts into the new blog.
But I won’t be using Word Press.
I hear you all gasp, but I’ve decided to go to a “roll my own” solution again. As the site itself is going to be done in ASP.NET I decided to make the whole site work with that. I could download an ASP.NET blogging engine, but I thought this would be a better idea as to brush up on my code design skills.
The blog will be the first thing I’ll do for my site, before moving on to the various more complex areas, and if I can keep myself motivated I’ll work around the design process here. And so to begin, for the blog what will I require..
One thing most programmers do before starting a project is figuring out first the needs of the project then cutting it down into more manageable chunks. The idea being that you should be able to write one chunk to do something, without needing to affect the others yet all of it can be tied together.
Each chunk then may get cut down into further chunks and so on and so forth, until the programmer feels comfortable.
I’ve identified two easy chunks for this projects.
This is the bit the users will see when visiting my blog, this involves the listing page, the single posts and comments page along with various menu items, tag clouds, search boxes and results.
This is the bit I, and other people I allocate, can see. This is were posts are written, comments are managed, spam is removed, skins selected etc.
I’m going to be storing my data on a mySQL server, using mySQL .NET connector as my medium between the code and the database.
As I’ll be hosting this on a linux server, yet writing in .NET. It’s a given that’ll be using Mono, which is perhaps the most mature CLR implementation out there. I’ve had little tests with it and for the most part it behaves as it should, and it certainly will for what I’ll be using it for.
Apache of course! I’ve had many years of experience with Apache now and though I find it a pain at times, I really think it is an amazing piece of work.
The next post will be as I start work on my site, discussing various things such as my data model, database schema, various design patterns and thought processes I’m going to have to go through prior to actually writing real code.
Hopefully, at the end of this series (which will be carried over to the new blog), those of you with little more understanding of the process you have to go through when seriously coding a site. Though my Disclaimer is this: I do not profess that how I will approach this will be the right way, the correct way or the way you should do it. It will be however, the way I’ll feel happiest doing, and the way I feel comfortable doing it.
What ever you think of the result of these articles however, I hope you’ll take something away from it. New knowledge, enlightenment or whatever you please, and this doesn’t just become more noise on an already saturated network.
So i’ve decided to kill the SharpShell project. Again I let another of my projects dissolve into the ether. Why? Several reasons really. Those who wanted to help didn’t take an interest once the project started, and trying to figure out windows undocumented functions was a pain in the arse. Also why my functionally same code as litestep (though class design and actual code was different, I could tell I was doing code wise the same thing) wouldn’t work.
Basically, I don’t have the want and need to bang my head against a desk in my free time for so many weeks on end. In other words, I got stuck and all avenues I could find for questioning had long since been closed
Well as I seem to lack having any sort of creativity now, whether this be a direct result of the mild loop of uncalled for depression I fall through, or something more simple like, the right-side of my brain is not work any more doesn’t really matter, I’ll probably take a break, sit back and code what I always enjoyed coding. Games. Not huge, massively scary games with a code base of seven million lines of code, but little things, like 2D space shooters and platforms that served no purpose but to entertain myself in creating something, and to keep those who need short bursts of fun, well, also entertained.
Well strictly speaking I do have a web project sitting on the back burner of never ending projects I should do. That being the website to my new domain, aptly named, NikRadford.co.uk. I’m still working on the ideas of what I want for content in my head, none have made it to paper, let alone code. But typically I’ve gone off web development.
Why?
It’s limiting. Huh? I hear you say, what do you mean limiting? I’ll explain. What can I do on the web. Generate HTML. Great. Cool. But the html is static. I can’t do anything with it. “But there’s javascript”, great, a way to change one chunk of static HTML into well, another chunk of static HTML. I can’t produce fancy cool applications that make me sit back and think, cool, I made that. No, I just think: great, another web page. It’s boring, repetitive, even when you can be bothered to sit down and bang out a reusable framework. What’s done from there just doesn’t stretch the imagination. It is in no-way a stress on my mental capacity. I get bored, and drop the project.
And before you say flash, I would like to iterate Flash is not web development, it’s applet development. Much like Java Applets, even Silverlight falls into the same realm.
When it’s your free time, with no money to fund it, you don’t want to do something that bores you. This is why my original reason (Which I used for finding a job), I want program “whatever” because I love to code, is now fundamentally flawed. I want to code things I find intellectually stimulating. Things where I can learn. Things that challenge me.
Though with my rant on web application, I’m also going to learn Ruby this year (though I must say, I’m not so sure about the rails framework), I feel stagnated in C# recently, I need something fresh. Though that doesn’t mean I’m going to stop programming in C# (I use C# professionally so I literally can’t any way, and I do love the language), I feel I need to start expanding my knowledge further. Again.
Touching on Ruby, I’ve decided to take a look at IronRuby, .NET and Ruby rolled into one, the unfamiliar and the familiar rolled into one should make learning a much easier process.
I’m going to work on my web site, and hopefully get a version of my LodeRunner clone out the door. (Which has sat on a dark corner of my hard-drive for 6 weeks taking a back seat SharpShell)
There are other things I’m playing with the idea of, but I’ll tell them when they become more than just idle thoughts.
My new flat rocks and I happy with it. Very much enjoying the peace that comes with it. No flat mate / parents / under the stair migrant to upset my wonderful living flow. And Rainbow Six Vegas 2 is my new lover.
And by god though, do I need a holiday.
As the title of this post suggests I’ve begun an open source project, and I’ve called it SharpShell.
It’s aiming to be a shell replacement for windows, replacing the desktop area of the OS (the icons, the start bar and task tray) with a modular and customisable interface. It’s being written in C# (3) and is to be run under .NET 3.5. Doing this I was hoping to leverage the power of WPF for graphics. Currently there are 3 members on the team, Me, Ian and Dave, unfortunately I seem to be the only one active on this, and so have pretty much been going under my own steam. The project is far from even usable at the moment, the source code is currently just starting out so even if you got it and compiled it, there would be nothing to see. However, I’d be happy to for any one wishing to help to join the team. The project is hosted at google code, (http://sharpshell.googlecode.com/) and there is a rather inactive (as I’ve been the only one posting to it) mail list hosted with google groups.
So far I’m enjoying the project even if code wise theres not alot to show for it. I’ve been enjoying digging into the bowls of Win32 and fiddling with undocumented functions and seeing if it is indeed feasible to do a shell replacement in C# and WPF. So watch this space and the project page for updates ![]()
when your last block of code looks like this:
1 //TODO:: CREATE DART DATABASE FOLDER / CHECK FOR EXISTANCE
2 //TODO:: MOVE FILE IN DATABASE
3 //TODO:: CREATE WAREHOUSE FOLDER / CHECK FOR EXISTANCE
4 //TODO:: MOVE FILE PHYSICALLY
One thing that always annoyed me with C# and WinForms was the inability to update the control from another thread. And the way you could achieve this was a rather roundabout way. That being, when you want to write data to your control from another thread, you had to call Invoke on the control.
Invoke’s signiture was as so.
object Invoke(Delegate method, params object[] args)
So basically we have to pass a delegate that points to a function that does our updating. The params object[] would be any parameters needed to pass to the function. But this would result in creating delegate functions to perform simple things like to set the Text property of a TextBox. Because the type is of a specific Delegate you can’t use Anonymous Methods to make it neater, or at least so it seemed.
Thanks to Jayson Knight’s post on his .NET blog, he explains how to use Anonymous Methods with Control.Invoke thanks to a little gem hidden away in the System.Windows.Forms namespace called MethodInvoker.
To use method invoker to allow using anonymous methods in Control.Invoke is simple and the sample from Jayson’s blog looks like so:
private void DoSomeWork() { if (this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(delegate() { Console.WriteLine(“Writing to console via anonymous method. “); })); } }
Pretty self explanatory if I do say so myself.
I’ve finished writing a custom picture box control in .NET 2.0. Unlike the normal picture box, it allows panning of an image, zoom functionality (by factors) and drag selecting an area of the image (thus Selectable
). All public functions are XML documented though perhaps not brilliantly, feel free to contact me if you have problems using it
I’ve released it under GPL v2, so feel free to use and / or modify.
I do have one request, even though by the license you have to publish the code again if you’ve modified. If you do so can you let me know, so I may incorporate any improvements done into my own copy.
Download it: SelectablePictureBox.cs
Thank you,
Nik
Went paint balling at the weekend with a few guys from work, it was good fun. I have some before and after shots, though unfortunatly for the sadistic few, we don’t showcase our injuries. Nor are there any action shots
No photos in the field.
Read more to see the pictures