Sunday, April 3, 2016

xna - Creating a 2D Line Branch


I'm looking into creating a 2D line branch, something for a "lightning effect". I did ask this question before on creating a "lightning effect" (mainly though referring to the process of the glow & after effects the lightning has & to whether it was a good method to use or not); Methods of Creating a "Lightning" effect in 2D


However i never did get around to getting it working. So i've been trying today to get a seconded attempt going but i'm getting now-were :/.


So to be clear on what i'm trying to-do, in this article posted; http://drilian.com/2009/02/25/lightning-bolts/


I'm trying to create the line segments seen in the images on the site. I'm confused mainly by this line in the pseudo code;


// Offset the midpoint by a random amount along the normal.

midPoint += Perpendicular(Normalize(endPoint-startPoint))*RandomFloat(-offsetAmount,offsetAmount);

If someone could explain this to me it would be really grateful :).



Answer



That line gets a unit vector (vector of length 1) from startPoint to endPoint


Normalize(endPoint-startPoint)

then gets a vector perpendicular to that (i.e. at right angles to the line)


Perpendicular(Normalize(endPoint-startPoint))


then multiplies it by some amount with a range (+ve or -ve).


* RandomFloat(-offsetAmount,offsetAmount)

It then adds this to midPoint thereby offsetting it.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...