Archive: Questions about 3D.


17th March 2005 18:53 UTC

Questions about 3D.
Ok, so far I don't seem to be doing too bad about making a scope that jumps around, changes shape, etc. The problem however, is I have no idea how to make the scope itself 3D. I can throw in PAK_9's rotation matrix (which I don't really understand so if anyone would car to explain) but when it's rotating the image, at one point or another it will turn into a line because there's only two dimensions. How (or where) do I go about learning the 3D coding?

I've managed to mess around and make a few things happen. Mostly that comes from just putting in random equations and divisions and seeing what pops out.

Sorry for the noob question but I've been playing with this thing on my own for months now and can't figure it out.


17th March 2005 22:56 UTC

Didn't you say that you used paks helpful programming guide? As far as i remember it explains pretty good what this rotation code does.

However i try to explain it a bit:
Actually that code you mentioned isn't a matrix, but it's the code that you get when you work out 3 roation matrices. But let's go back a step. At first you calculate an object in 3 dimensions. Then that code rotates it around the x axis, then around y, then around z. If you are familiar with math a bit the code is not more than this:


/ x1 \ / 1 0 0 \
| y1 | * | 0 cos(***945;) -sin(***945;) |
\ z1 / \ 0 sin(***945;) cos(***945;) /

gives you:

x2 = 1*x1 + 0*y1 + 0*z1
y2 = 0*x1 + cos(***945;)*y1 + -sin(***945;)*z1
z2 = 0*x1 + sin(***945;)*y1 + cos(***945;)*z1

or better:

x2 = x1
y2 = cos(***945;)*y1 - sin(***945;)*z1
z2 = sin(***945;)*y1 + cos(***945;)*z1


do you recognize it? This is done for the three rotations (x-,y-,z-axis).

Afterwards you have to go back to 2D in order to render that object. Here you use the fact, that objects in further distance appear smaller. So you use the z-dimension as a size-parameter:
x = x4 / (1+z4*0.5)
y = y4 / (1+z4*0.5)


Hope the mystery of 3D in AVS has been cleared up a bit more! If anything is unclear just ask again.

17th March 2005 23:28 UTC

Ok, the rotation made a little bit of sense before, and a lot now.

But I'm still having an issue with making a scope itself 3D. I can rotate it in 3D, but the scope looks like a rotating plate.

I'd like to learn how to make the actual scope itself 3D, then if necessary make it rotate in 3D.

I'll attach an example of one of my rotating plates.

While PAK_9 does a good job of explaining the rotation I didn't see (or maybe was just ignorant and didn't understand) a 3D scope.


17th March 2005 23:36 UTC

well, your problem is quite simple: you didn't specify anything for your 3rd dimension. So you don't have a 3D but a 2D object. It's an 2D-slice that is rotated!

In the beginning specify something for x1, y1 AND(!) z1


18th March 2005 00:38 UTC

I figured that much. I suppose learning what does what is a matter of math and some trial and error then huh?


18th March 2005 00:47 UTC

yes and no. actually math isn't everything. You musn't forget to keep an eye on the appearance of the preset. But you're right: most stuff concerning coding has to do with math, so it was very helpful to be familiar with mathematics. You don't have to be good in here, but if you are it's a benfit for sure!


18th March 2005 04:18 UTC

Ok, so I've come up with a few half-ass scopes that I wanna play with. Right now I'm messin around with the dynamic movement but I can't get the effect I want.

I'd like to have more of a camera angle that moves back and forth from one direction to another. But when I put in the lines of code that I think should work, the screen just goes blank on me. So, obviously, it doesn't work.

I've got a picture being rendered to so I can see how the planes are moving in DM, here's what I've got in the frame:

rotx=rotx+.01;
roty=roty+.01;
rotz=rotz+00;

rotx=if(above(rotx,.40),rotxb,rotx)
rotxb=rotx-.01;
rotxb=if(below(rotxb,-0.40),rotx,rotxb);

crotx=cos(rotx);
srotx=sin(rotx);
croty=cos(roty);
sroty=sin(roty);
crotz=cos(rotz);
srotz=sin(rotz);

I think the problem is in the bold, I was trying to have it reach .4, then start heading down to -.4 and head back up. I think there's probably some way to use the % in there but I'm not real informed on how it works.

The part in point is this.

x1=x;
y1=y;
z1=1;

x2=x1*crotz-y1*srotz;
y2=x1*srotz+y1*crotz;

x3=x2*croty+z1*sroty;
z3=-x2*sroty+z1*croty;

y1=y2*crotx-z3*srotx;
z1=y2*srotx+z3*crotx;

t=-oz/z1;
x=x3*t-ox;
y=y1*t-oy;

alpha=z1;

Yeah yeah, it's all taken from PAK_9. I'm just trying to take what he did, tweak with it and see how it works, then come up with something original.


18th March 2005 10:50 UTC

that's just what i use to do either ;)

well, perhaps you could post the complete stuff you used like:


init:
blablabla

frame:
...

beat:
bla... bla

pixel:
bla etc.

that would make it easier to reproduce the dm here. However, the easiest way to keep the variable in between max and min limits is via a pre-factor on sines/cosines. var1=sin(var2) always stays between -1 and 1, so var1=0.4*sin(var2) will always give a value between -0.4 and 0.4.
Your idea could perhaps work but is a bit complicated. On first sight the problem you have is here: rotxb=rotx-.01
If you do so, rotxb gives you rotx reduced by -0.01. But since you don't change rotx in any way, you will get the same value all the time. Spontaneously i don't know how to fix it, cause i would simply use a sin + a sizing factor like i said above. :)

18th March 2005 16:41 UTC

I dont know, you water it down and water it down, but people still cant fit it into their tiny brains.


18th March 2005 19:43 UTC

Originally posted by mIcrO_brAIn

Yeah yeah, it's all taken from PAK_9. I'm just trying to take what he did, tweak with it and see how it works, then come up with something original.
google and search forums for raytracing

[edit]
cos it has been taught and tutorialized many times, no reason to do it again.
But before you start diggin' for raytracing make clear how camera and 3D rotation works :p

28th March 2005 03:35 UTC

want to make it easy on yourself? start with 3d superscopes and get to grips with 3d space and projection. you will then find it easier to learn raytracing since vectors and rays won't be so abstract, you might even come to the conclusion of how to do it for yourself. raytracing anything in avs requires a pretty good knowledge of 3d geometry if you want to do anything not a(two) plane(s). even people like PAK-9 and UnConeD dodge using raytraced DMs and use elaborate hacks instead (see UCD - Mission to Mars/Retrosquares, PAK-9 - Tubular/Containment Breach for some good examples), because its easier and sometimes faster when you want to create a complicated terrain/shape.

Seriosuly though... start with superscope and get really used to it. make all sorts of parametric 'sphere thingies' and point to point wireframe models. thats how i started.