Introducing the new PJS Object: PVector!

Well technically, I’ve already talked about this object a couple of times week alone.  There were some major issues with some of my code.  Mainly, certain parts just stopped working while I was trying to implement it from it’s lone source to the actual processing.js hub.  With a lot of help from Al (AKA F1LT3R),  I was able to debug most of my problems.  The resulting new processing.js library can be found in my repository.   The actual changes can be noted in the diff section.  Some of the additions in that section weren’t actually mine (I think they’re MinyXO’s; something about forking his repository) , but for some reason aren’t being seen by the repositories.  I’ve no clue how that happened but only the PVector part is what I’ve done (the big long green part at the bottom).

I do have some working demos; mostly just the examples given by the Processing reference page.

Add()   ver 1, ver 2
Sub()   ver 1, ver 2
Mult()  ver 1, ver 2
Div()   ver 1, ver 2

They’re definitely not as good as Andor’s 0.1 Release Demos.  I was looking for something more visual that would involve acceleration and velocity.  But, I wasn’t able to finish the whole object.  I’ve still got to work out on returning objects to be used.  Even with ideas from F1LT3R, returning objects is still giving me problems.

Earlier problems were resolved with the re-addition of “this”.  Sorry Dave, but it was simply easier to keep it in.  With the proper use of “this”, my functions started operating as normal again.

Looking ahead…

For 0.2, I’ve got to finish and work out the kinks out of PVector and I’ve also signed up for more.  Click here for the list of items that still need work.  When I finish PVector, I will probably focus on beginCamera(), camera(), and endCamera() functions.

More like release week!

I was a little presumptuous on my last post, thinking that the due date for this first release was on Monday.  I didn’t see the “week of” part on the due date.  Well that means I’m somewhat ahead of the curve.  I’ve got my working object in javascript and I’ve got the link to the actual object now that I’ve got my matrix account up and running again.  If you want to take a look at PVector in just in it’s entirety, click here.  Now that’s the semi-tested, though working, and uncommented version.  I’ll finish it soon as I finish testing, which I’ll be working on today.  It’s also the version that hasn’t been changed to stop using the “this operator” as suggested by Dave.

I can see the cause for concern with the operator… it doesn’t work the same way as I’m used to with Java and C# Object Oriented Programming.  However, there are instances where I am having trouble thinking of a way of taking them out.  Particularly, the instances when a method is referencing the main object.  Like in this particular method:

PVector.prototype.mag = function(){

	return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);

}

If I keep it to just (x*x + y*y + z*z),  I don’t think it’ll take the attributes of the prototyped object.  I’m not completely sure, as more extensive tests need to be done.  However I will for sure be taking out the “this” keyword in this sample code:

PVector.prototype.get = function(){

	return this;

}

I wasn’t sure that would work to begin with.  I have yet to see an example to show me that it does work.  So, that will be changed for sure.  Anyway, back to testing for me.  If I can get this working properly soon and all the tests pass, I’ll be looking to make a demo with hopefully some vector math (such as acceleration and velocity).  I’ve still got some work to do before then though.

0.1 Release Day!

So I’ve fallen back into old bad habits… basically, my previously closed source ways.  I procrastinated and failed to follow the mantra:  “Release early, release often”.  I did finish my object, without too much testing done, however.  I’ll give you some sample code from the actual object and then upload the code itself at the end of this post.  Despite my procrastination, I was able to finish the object in about two days.  This includes all the research for Javascript and some of the vector math needed to be implemented.  Now to show off some of my code work…

function PVector(){

	this.x = 0;
	this.y = 0;
	this.z = 0;

	if (arguments.length == 3){
		this.set(arguments[0], arguments[1], arguments[2]);
	}
	else if (arguments.length == 2){
		this.set(arguments[0], arguments[1], 0);
	}

	return this;

}

That was the main body of the PVector object.  Now, it looks a little horrible due to the formatting removal but it’ll have to do.  Now you know it’s an object, instead of a regular function, through the variables being created with the “this” command.  The variables are pretty self explanatory due to the nature of vectors.  The second part of the object are constructors or some type of overloaded constructors.  There is not a way to actually put different types of parameters into functions with the same name (which is ludicrous in my opinion because it’s a functional programming language).  However, I was able to work around that with the help of David Humphrey and Anna Sobiepanek.  They were discussing the very same thing in the #processing.js channel and Anna was kind enough to put up her findings in this post.  You will find a great many of the methods within this object require the system of using arguments because most of them are originally overloaded for many different uses.  In particular, I’ll show you one of the methods I struggled with… the mult() method.

PVector.prototype.mult = function(){

	if (arguments.length == 1){
		if (typeof (arguments[0]) == 'number'){
			this.x *= arguments[0];
			this.y *= arguments[0];
			this.z *= arguments[0];
		}
		else if (typeof (arguments[0]) == 'object'){
			var v = new PVector();
			v = arguments[0];
			this.x *= v.x;
			this.y *= v.y;
			this.z *= v.z;
		}
	}
	else if (arguments.length == 2){
		if (typeof (arguments[1]) == 'number'){
			var v = new PVector();
			v = arguments[0];
			v.mult(arguments[1]);
			return v;
		}
		else if (typeof (arguments[1]) == 'object'){
			var v1 = new PVector();
			var v2 = new PVector();
			v1 = arguments[0];
			v2 = arguments[1];
			v1.mult(v2);
			return v1;
		}
	}

}

I took some time to try and format this (I don’t know if it’ll work once I actually post it though), so that it’ll be somewhat easier to read.  Now, there were two main issues of concern for me while doing this method.  One of them was the fact of determining what kind of parameter was being passed through to the function.  This was due to the mult() function having the same number of parameters for different values.  I had to insert a nested if statement that would somehow figure out the type of parameter being passed.  I, initially, had no clue as to how to do this.  Fortunately, asking in IRC helped.  Our newest member, Daniel Hodgin, helped point me to the right direction of the typeof operator.  I, also, found a good example of usage at this site.  Now that I have that resolved, implementation wasn’t too difficult.  I, actually, had the same problem with the set() method but I decided to leave that one later and move on… but once I figured it out for mult, set was pretty simple as well.

Now, the second problem I came across is the fact that in the mult description (linking here again so you don’t have to scroll up) they were asking for two vectors to be multiplied into each other.  My first thought was “How is that even possible?”  A few years in engineering taught me that vector multiplication didn’t exist, aside from multiplying a scalar into a vector.  Research into the subject gave me the same thing.  All I kept finding were how-to’s on dot product and cross product.  Which, in the end, wasn’t what Processing was asking.  It took for me to look into the original Processing PVector source code to make sense of what was being asked.  Now, I may not be fond of what was being done, but I did it anyway because we’re only supposed to be transporting Processing to Javascript… not modifying it.  Basically, it asked to multiply each component of the vector into the components of the second vector (ie. x with x and y with y…)  to come up with a new vector.

After overcoming those two problems, the rest of the methods were pretty simple.  Some of them were as easy as a few lines like the following:

PVector.prototype.mag = function(){

	return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);

}

However, through looking at the source code, I found out that the references on the Processing site were a little outdated.  It wasn’t updated with some of the further overloaded functions that I saw and didn’t really have time to implement (ie the toString method).  I will implement these and fix any bugs found for the 0.2 release as well as taking up some more functions that need implementing.

I promised to have my source code uploaded, but I’m having trouble putting it up to Matrix at this point… so I will put it up in the near future.  As well, I will put up some sort of working demo for this as soon as I figure that out as well.  It’ll be soon, I promise.  One thing I can say about me working… once I DO eventually get started, I keep going until I have no more fight in me left.

*EDITED to make formatting easier to read.

Battle Royale – Oct 2009

So I’ve been skimping on the blogs… well on the whole work thing, to be honest.  I’ve decided to dive back in but doing more of a personal one instead of my project stuff.  Let’s face it, I haven’t really done too much work the past week and a half… so there’s not too much to write about.   Of course, I’m planning to change that this weekend.  I’m weird like that… slack off during the week only to do work during my free time.  Anyway, this blog is going to be about last weekend and my trip to Ottawa.

So, as the title suggests, I went on a trip to Ottawa to do some gaming competitions in Battle Royale.  It’s a 24 hour LAN where there’s a whole bunch of gamers doing tournaments and pretty much playing video games all day over a local area network.  It was tons of fun but I’ve never been to a 24 hour LAN before.  And not one with great sponsors like Valve, EA, Bawls, Steelseries, and many others.  Here’s a picture of me, my setup and the people around me (please note it’s been about 6-8 hours at this really hot auditorium and that’s why I look horrible):

Myself chillin at Battle Royale 3 with ukm beside me.

Myself chillin at Battle Royale 3 with Peter (ukm) beside me.

Here’s a better look at how big the actual event is:

Now, I was able to win in two tournaments that weekend.  Mostly because I was on such great teams, but I helped out here and there.  The first tournament was Counterstrike: Source.  The second tournament was for Team Fortress 2.  I’ve got pictures of both my teams that will be shown below, with some of our winnings and one of the LAN organizers (she arranged a lot of the sponsors, if not all).

left to right: Alex (lopert), Peter (ukm), Donny (Helix), Myself (aSydiK), Richard (Sharpshooter)

left to right: Alex (lopert), Peter (ukm), Donny (Helix), Myself (aSydiK), Richard (Sharpshooter)

left to right: Kurt (rambo), Myself (aSydiK), Tyler (0ptik), Jess (pinkNinja - Organizer), Alex (lopert), Peter (ukm), (hoppypotty)

left to right: Kurt (rambo), Myself (aSydiK), Tyler (0ptik), Jess (pinkNinja - Organizer), Alex (lopert), Peter (ukm), (hoppypotty)

For prizes, I got an awesome mouse pad, a little mushroom candy container that looks like it came for the Mario Bros world, a Shamwow, The Sims 3 video game, and two awesome dog tags that have TF2 and CSS Tournament Winner designed onto them courtesy of CCGgraphix.  A picture of what they look like is below:

It wasn’t all fun and games that weekend though.  I did get into a car accident the night before, which rendered my vehicle useless.  It had to be towed away and I was car-less for the whole weekend.  I was, also, stranded there until Monday… or so I thought.  At least, when I checked several Enterprise branches (the company my insurance used), most were closed by Saturday noon and wouldn’t open up again until Monday.  So, I thought I was out of luck.  Monday came rolling along and I found out that the branch I was renting from was open on Sunday.  Which meant, I stayed an extra day for pretty much nothing and missed one of my best classes.  Anyway, for anyone in the Ottawa area that needs to rent a car on Sunday, click here for the branch I rented from that’s open almost every day.  Aside from this mishap, and personal ones I’m not willing to put up on this blog, it was an awesome weekend that I would be willing to do again in a heartbeat (and might do so next year if there’s another).

Thanks to this man who put me up that weekend and let me and my friend stay with him an extra day (your hospitality is greatly appreciated):

Mike (KnightTemplar AKA KT)

Mike (KnightTemplar AKA KT)

Note:  All images courtesy of Jessica “pinkNinja” V, and more photos can be found on her BR3 Flickr page.  Thanks Jess!