Old 28th January 2012, 18:41   #1
patipano
Junior Member
 
Join Date: Jan 2012
Posts: 20
How to create a polygon and its normal?

How to create a polygon with Superscope and its normal vector?

Thanks in advance.
patipano is offline   Reply With Quote
Old 2nd February 2012, 22:31   #2
Warrior of the Light
Forum King
 
Warrior of the Light's Avatar
 
Join Date: Aug 2002
Location: The Netherlands
Posts: 4,084
there's a list of tutorials here. I suggest you read through PAK-9's one

Jesus loves you [yes, you] so much, he even died for you so that you will not need to die, but live forever
Warrior of the Light is online now   Reply With Quote
Old 2nd February 2012, 23:18   #3
QOAL
[STILL a retard!]
 
QOAL's Avatar
 
Join Date: Apr 2002
Location: Bristol, UK
Posts: 1,168
I'd probably recommend using the triangle APE, if you want nice filled polys, rather than a superscope. (Not that I can remember how to use that ape)

count!last.fmdastylishplanner
QOAL is offline   Reply With Quote
Old 3rd February 2012, 06:23   #4
patipano
Junior Member
 
Join Date: Jan 2012
Posts: 20
The PAK-9's Tutorial didn't show me how to create polygon with Triangle(Render) .
patipano is offline   Reply With Quote
Old 3rd February 2012, 13:36   #5
Warrior of the Light
Forum King
 
Warrior of the Light's Avatar
 
Join Date: Aug 2002
Location: The Netherlands
Posts: 4,084
I never really used it myself but it's basically a SSC with 3 X's and 3 Y's instead of one I think.

Jesus loves you [yes, you] so much, he even died for you so that you will not need to die, but live forever
Warrior of the Light is online now   Reply With Quote
Old 3rd February 2012, 15:38   #6
patipano
Junior Member
 
Join Date: Jan 2012
Posts: 20
Thank you everyone! i got it! (using SSC)
Any example code for solid pentagon (SSC)?
patipano is offline   Reply With Quote
Old 3rd February 2012, 16:45   #7
Warrior of the Light
Forum King
 
Warrior of the Light's Avatar
 
Join Date: Aug 2002
Location: The Netherlands
Posts: 4,084
solids are not possible since there only is a line. There are tricks though.
The most commonly used is 'zigzagging' This is the code for a square, do your best to turn this into a pentagon:


init:
n=h

point:
linesize=2;
sw=bnot(sw);
x=sw*1-0.5;
y=i*1-0.5

Jesus loves you [yes, you] so much, he even died for you so that you will not need to die, but live forever
Warrior of the Light is online now   Reply With Quote
Old 10th February 2012, 18:14   #8
patipano
Junior Member
 
Join Date: Jan 2012
Posts: 20
Is this okay for pentagon?
"la" is amount of layer(density)
code:

Init:
la=7;n=la*6;a=72/360*2*$pi;asp=h/w;
x0=1;x1=cos(a);x2=cos(2*a);x3=x2;x4=x1;
y0=0;y1=-sin(a);y2=-sin(2*a);y3=-y2;y4=-y1;

Frame:
p=0;c=0;

Point:
x=(equal(p,0)*x0+equal(p,1)*x1+equal(p,2)*x2+equal(p,3)*x3+equal(p,4)*x4+equal(p,5)*x0);
y=(equal(p,0)*y0+equal(p,1)*y1+equal(p,2)*y2+equal(p,3)*y3+equal(p,4)*y4+equal(p,5)*y0);

sc=1-floor(c/6)*(1/la);
sc=if(below(sc,0),0,sc);
skip=if(equal(p%6,0),1,0);

x=x*asp*sc;
y=y*sc;

p=(p+1)%6;c=c+1;

patipano is offline   Reply With Quote
Old 10th February 2012, 22:36   #9
Warrior of the Light
Forum King
 
Warrior of the Light's Avatar
 
Join Date: Aug 2002
Location: The Netherlands
Posts: 4,084
Looks great! the code you managed to create is more advanced than I had expected.

I would increase la to (for instance) w*0.5 and make the linewidth 2 or 3.

some optimization tips:
You could remove the if() statement for skip; skip=equal(p%6,0); will work too.
The extra line for sc is not needed. Simply use sc=max(1-floor(c/6)*(1/la),0); instead.

Jesus loves you [yes, you] so much, he even died for you so that you will not need to die, but live forever
Warrior of the Light is online now   Reply With Quote
Old 11th February 2012, 05:41   #10
patipano
Junior Member
 
Join Date: Jan 2012
Posts: 20
Oh thank you for cleaning my code! i have to learn lots about minimizing the code.

What's the difference between longer code and shorter code? only FPS rate?
patipano is offline   Reply With Quote
Old 11th February 2012, 13:14   #11
Warrior of the Light
Forum King
 
Warrior of the Light's Avatar
 
Join Date: Aug 2002
Location: The Netherlands
Posts: 4,084
Yes. the CPU always runs at 100% with AVS and both reading the code and rendering the image is done by the processor. So the less code it has to read, the faster the image is rendered. Especially in the Point box because it is calculated for every point of the scope over and over again.

For this example it isn't really important but once your preset starts 'growing' you can see the framerate dropping fast.

Jesus loves you [yes, you] so much, he even died for you so that you will not need to die, but live forever

Last edited by Warrior of the Light; 11th February 2012 at 15:13.
Warrior of the Light is online now   Reply With Quote
Old 12th February 2012, 07:22   #12
patipano
Junior Member
 
Join Date: Jan 2012
Posts: 20
Why this scope is so mess? I just added some 3D rotation to my pentagon.
code:

Point:
x1=(equal(p,0)*x0+equal(p,1)*x1+equal(p,2)*x2+equal(p,3)*x3+equal(p,4)*x4+equal(p,5)*x0);
y1=(equal(p,0)*y0+equal(p,1)*y1+equal(p,2)*y2+equal(p,3)*y3+equal(p,4)*y4+equal(p,5)*y0);

//Additional
z1=0
y2=y1*xc-z1*xs;z2=y1*xs+z1*xc;
x2=z2*ys+x1*yc;z3=z2*yc-x1*ys;
x3=x2*zc-y2*zs;y3=y2*zc+x2*zs;
//End of additional

sc=1-floor(c/6)*(1/la);
skip=equal(p%6,0);
//Additional
z=1/(z3+1);
x=x3*asp*sc*z;
y=y3*sc*z;
//End of additional
p=(p+1)%6;c=c+1;

patipano is offline   Reply With Quote
Old 12th February 2012, 15:25   #13
Warrior of the Light
Forum King
 
Warrior of the Light's Avatar
 
Join Date: Aug 2002
Location: The Netherlands
Posts: 4,084
you forgot a ; after z1=0

Jesus loves you [yes, you] so much, he even died for you so that you will not need to die, but live forever
Warrior of the Light is online now   Reply With Quote
Old 12th February 2012, 16:19   #14
patipano
Junior Member
 
Join Date: Jan 2012
Posts: 20
It also messy. It isn't 3D pentagon
patipano is offline   Reply With Quote
Old 13th February 2012, 22:00   #15
Grandchild
Senior Member
 
Grandchild's Avatar
 
Join Date: Oct 2005
Location: Germany
Posts: 333
Small triangle tutorial

I really suggest you spend your time learning how to use Triangle. It's just that much more clean than approximating stuff with zig-zagging them in an SSC.
That being said, here's a few pointers to get you going with your pentagon:

First you have to ask, How can a <enter your shape here> be created with triangles? In the case of a pentagon that's pretty easy once you draw a pentagon on paper:

Blue numbers identify triangles and red numbers identify vertices (corners).

So you are going to have 3 triangles.
So in your Init box goes
code:
n = 3;


You also need the coordinates for those triangles, preferably in x, y and z. So I would suggest to use megabuf() since that can be indexed and you can access it more easily later with the help of counters (more about them later).
So write down the coordinates for your pentagon-triangles (or calculate them live - which I will do below) and write the values to a megabuffer array, like so:
code:
crcl5th = 2*$PI/5; // precalculate the step size around a circle
size = 1;
point1x = sin(crcl5th*0)*size; point1y = cos(crcl5th*0)*size;
point2x = sin(crcl5th*1)*size; point2y = cos(crcl5th*1)*size;
point3x = sin(crcl5th*2)*size; point3y = cos(crcl5th*2)*size;
point4x = sin(crcl5th*3)*size; point4y = cos(crcl5th*3)*size;
point5x = sin(crcl5th*4)*size; point5y = cos(crcl5th*4)*size;
// x coordinate ------------- y coordinate ------------- z coordinate
// triangle 1
assign(megabuf(00),point1x);assign(megabuf(01),point1y);assign(megabuf(02),0);
assign(megabuf(03),point4x);assign(megabuf(04),point4y);assign(megabuf(05),0);
assign(megabuf(06),point5x);assign(megabuf(07),point5y);assign(megabuf(08),0);
// triangle 2
assign(megabuf(09),point1x);assign(megabuf(10),point1y);assign(megabuf(11),0);
assign(megabuf(12),point4x);assign(megabuf(13),point4y);assign(megabuf(14),0);
assign(megabuf(15),point3x);assign(megabuf(16),point3y);assign(megabuf(17),0);
// triangle 3
assign(megabuf(18),point1x);assign(megabuf(19),point1y);assign(megabuf(20),0);
assign(megabuf(21),point2x);assign(megabuf(22),point2y);assign(megabuf(23),0);
assign(megabuf(24),point3x);assign(megabuf(25),point3y);assign(megabuf(26),0);


All this goes into your init section as well, except if you want to modify the coordinates (for example if your pentagon should rotate, or move in any other way.

Now comes the tricky part. You need to access these 3 triangles in your point/triangle code
Every time the triangle section gets evaluated it expects you to give it 3 points in 2D, that is:
code:
x1 = someval; y1 = someval;
x2 = someval; y2 = someval;
x3 = someval; y3 = someval;



Additionally you can specify the triangles color with:
code:
red1 = redval;
blue1 = blueval;
green1 = greenval;


(There is no red2/blue2/green2 and red3/blue3/green3, don't bother...)

Now how do you access the coordinates from the megabuf()?
Well you use a counter. That counter should count in steps of 9, because each time in the triangle section, you want to use 9 different values (we have Z-coordinates, but we throw them away for now, when you add 3D-rotation you will need them again). So, in the frame section set your counter to zero:
code:
counter = 0;

so that every frame the counter will be reset and the pentagon drawn correctly.

Now in the triangle section you read your values from the megabuffer into the coordinates, increase the counter and you're done:
code:
x1 = megabuf(counter); y1 = megabuf(counter+1); // you can add z1/2/3 here if needed
x2 = megabuf(counter+3); y2 = megabuf(counter+4);
x3 = megabuf(counter+6); y3 = megabuf(counter+7);
counter = counter+9;


Voila, if everything went well it should show you a white pentagon now.

I have to admit, I haven't tested this, but I've done it so many times I'm pretty sure it works. If you think something is off, tell me, but check first if you followed the steps correctly.

Last edited by Grandchild; 13th February 2012 at 22:07. Reason: typos...
Grandchild is offline   Reply With Quote
Old 14th February 2012, 07:30   #16
patipano
Junior Member
 
Join Date: Jan 2012
Posts: 20
Wow, lots of coding but I'd have to check it out! Thanks
patipano is offline   Reply With Quote
Old 15th February 2012, 18:07   #17
patipano
Junior Member
 
Join Date: Jan 2012
Posts: 20
I think this triangle coding is harder than using SSC to coloring from center (gradient).
Any idea for coloring (from center with Triangle)?
patipano is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Visualizations > AVS

Tags
calculation, normal, polygon, superscope, vector

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump