Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Yesterday i asked this question on how to create a 2D line branch; Creating a 2D Line Branch

And thanks to the answered provided, i now have this nice looking main branch; *coloured to show the different segments in the final item. The 5th Generation Line (32 segments)

Now is the time now to branch things off as discussed in the article; http://drilian.com/2009/02/25/lightning-bolts/

Again however i am confused as to the meaning of the following pseudo code;

splitEnd = Rotate(direction, randomSmallAngle)*lengthScale + midPoint;

I'm unsure how to actually rotate this correctly. In all honesty i'm abit unsure what to-do completely at this part, "splitEnd" will be a Vector3, so whatever happens in the rotate function must then return some form of directional rotation which is then * by a scale to create length and then added to the midPoint.

I'm not sure. If someone could explain what i'm meant to be doing in this part that would be really grateful.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Instead of asking a series of questions on specifics (normally the right thing to do on StackExchange, yes), you would be far better served by simply learning the basics of the linear algebra that you're running up against.

To give a slightly more directed answer, the Rotate function must perform a basic 2D rotation of the direction vector by the angle randomSmallAngle. This can be done with some very simple math, explained in most of the links above, or you can just use the XNA Matrix.CreateRotationZ() method to create a rotation matrix to transform the direction vector by.

The rotation does not return "some form of directional rotation" but in fact just returns a regular vector. It's taking the original direction, rotating it slightly left or right, and returning that. The lengthScale multiplication just scales that vector, changing its lengths. Finally it's added to the midPoint, giving a vector that's a position relative to the midPoint.

share|improve this answer
    
Its defiantly something i need to improve upon, so thank you for the links :). So i've been reading the links, and i've come up with this; Vector3 splitEnd = Vector3.Transform(midPoint, Matrix.CreateRotationZ(MathHelper.ToRadians(rand.Next(-45, 45)))) * lengthScale + midPoint;. It seems to be working, just wanted to make sure however. –  dan369 Apr 15 '12 at 11:19
    
Looks reasonable. –  Sean Middleditch Apr 16 '12 at 3:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.