Skip to content
Forum Archive

Tips & Tricks 2 -- Beginners and Intermediate Only

100 posts

nixa#
Yeah you use x=x/z;y=y/z; or something similar
Asin(1) equals pi what is 3.14159 and is a constant.
since basic arguments for sin function are from 0 to 2*pi and i goes from 0 to 1 statement i*pi*4 makes 2 sine waves and t variable(have something like t=t+0.05 in the frame section) moves the waves
Jaheckelsafar#
Here's a handy-dandy site http://mathworld.wolfram.com/RotationMatrix.html
To boils down to

x=cos(th)*x1+sin(th)*y1;
y=-sin(th)*xi+cos(th)*y1;
still, check the sight out. You might learn something.
Deamon#
I checked the site, and it explained a only very few things to me. My english is way too bad for it :P. Could you please clear those formulas a bit for me?

x=cos(th)*x1+sin(th)*y1;
y=-sin(th)*xi+cos(th)*y1;
Jaheckelsafar#
x1 and y1 are your initial x and y values
th is the angle of rotation in radians (2*pi = one full rotation)
x and y are your rotated x and y values

I can't explain anymore than that because I only half get it myself.
Deamon#
ok thanks, now it makes complete sense to me 🙂. Now I'd like to know how to add the z axis. so there is a way to add a z value just like x1, and y1. Any suggestions?

PS.

thank you very much for all the patience and explanation for me, I really appreciate all the effort.
shreyas_potnis#
i searched the sites a lot for rotation matrix but i got the same things, so these sites only explain the concepts, you need a good teacher to master it or experiance
btw.

x degrees = x * pi / 180 radians
dirkdeftly#
yes, but DON'T bother converting between degrees and radians, as el-vis does in his engine.

and you rotate around 1 axis at a time, the two axes used in the rotation matrix are the ones that define the plane perpendicular to that axis. so this rotation:
x=x1*sin(theta)+y1*cos(theta); y=x1*cos(theta)-y1*sin(theta);
rotates around the z axis, but *inside* the x/y plane perpendicular to the z axis.
Deamon#
I'm loosing it... 🙁 I understood the part that you always rotate along two axes. I know how to rotate along x-y (though I only know that with polar coords), but I don't know how to rotate along x-z and y-z.
sidd#
lol.. anyway. you wont get it unless you understand the basic trig of it. so read atero's primer. And visit ucd's thread called AVS FAQ or somehting, it has useful links..
Deamon#
ok I watched it, and I got most of it, though this piece of code is not quite clear to me:


x2=x1*sin(zt)-y1*cos(zt);
y2=x1*cos(zt)+y1*sin(zt);
x3=x2*sin(yt)-z1*cos(yt);
z2=x2*cos(yt)+z1*sin(yt);
y3=y2*sin(xt)-z2*cos(xt);
z3=y2*cos(xt)+z2*sin(xt);
I mean, I see it is neccesary, but I couldn't make it up my self. Could anybody please explain it a bit?
dirkdeftly#
well it's all there in the primer, but it is admittedly crap and the next version - which will come out sometime this century - will be clearer. for now, just search the forums, there's a couple threads on this...
the long and short of it is, those are rotation matrices and you can find the formula for them anywhere. they involve a coordinate on two axes (e.g. x2/y2) and a rotation angle in the third (zt). the derivation of this matrix is quite a bit trickier, but i hope to get that into the tutorial as well.
Deamon#edited
/me bowes to Atero, your Primer is great 🙂

[edit]
Me is googling a lot for Rotation Matrices, and finding a lot as well, though does anybody know the Dutch word for Rotation Matrices? It would be a lot easier for me to understand if it was in Dutch. Thx.
[/edit]
Deamon#
ok I get the x2 and y2 part, somebody willing to explain z2, x3, y3 and z3?

and why is there an xt, yt and zt, and not just one var ( for example zt)? Does it matter a lot when you change it?
Jaheckelsafar#
Each new set of coordinates must have a different name otherwise the first line would modify a value needed in the second line of the rotation matrix. x3,y3, and z3 could just have easilt been x1,y1, and z1. It's just easier not to get mixed up if they are x3, y3, and z3.

xt, yt, and zt are how much the shape is rotated per axis. If they are all the same varible the shape would only ever rotate in one direction unless it was recalculated between each rotation matrix. It saves a lot of clock cycles to have a different variable for each and only calculate them once per frame.
Deamon#
why are they all different? can't it be 3 times the same code line? I assume they all do the same operations, so why make it look difficult?
dirkdeftly#
Also, it makes it much easier to understand and tweak the code that way. You could theoretically save a bunch of variables like this:
a=x; x=x*sin(zt)-y*cos(zt); y=a*cos(zt)+y*sin(zt);
a=x; x=x*sin(yt)-z*cos(yt); z=a*cos(yt)+z*sin(yt);
a=y; y=y*sin(xt)-z*cos(xt); z=a*cos(xt)+z*sin(xt);
but it's rather confusing and hard to tweak or fix. Also, say (hypothetically) you wanted to rotate an object by two different angles upon the X-axis. You couldn't do that with this setup, however if you were to take the original:
x2=x1*sin(zt)-y1*cos(zt); y2=x1*cos(zt)+y1*sin(zt);
x3=x2*sin(yt)-z1*cos(yt); z2=x2*cos(yt)+z1*sin(yt);
y3a=y2*sin(xta)-z2*cos(xta); z3a=y2*cos(xta)+z2*sin(xta);
y3b=y2*sin(xtb)-z2*cos(xtb); z3b=y2*cos(xtb)+z2*sin(xtb);
y3/z3a and y3/z3b would be the same object but rotated in different ways. Dunno what use this particular trick would be, but it sort of goes to show what you can do with this system....
Myth.024#
Ok, I'm definately a noob. I have very little previous programming knowledge, and I know very little about AVS. (Wow pretty colors, and, oh look this setting changes things) However I'm determined to figure out and learn how to make my own AVS. So where can I find all the info I need to get started? I think that would be the best tip of all.
Deamon#
lol @ raz.

Ok I think I understand the code from the Primer, now what's next in learning scopes?