Archive: Question: Wireframe sphere SSC cutoff


11th June 2004 07:56 UTC

Question: Wireframe sphere SSC cutoff
Alright. I am using avs for about a month now. Learned everything from these forums - from very basics to some more complex things. I am practicing in creating 3d ssc's now and I have a question. As I see the best way to create a sphere with a superscope is using two ssc's - one for "parallels" and one for "meredians" and synchronizing them using global variables and maybe calculating them in another blank (n=0) superscope. I've hijacked a 3d engine (I use one copy pasted from these forums and I know what it does, but have no clue HOW it does it - every time I try to understand it my brain seems to start to melt, my math knowledges are limited) and made the sphere rotate around x, y and z and move along x, y and z. But I have a problem that I cant seem to be able to solve by myself. In some really advanced presets (namely Hush the Planet from Whacko Revisited :P) I noticed that the part of the superscope(s) is cut off so the sphere doesnt look transparent or wireframe any more and looks more solid. I understand how can I cut off the part of the sphere while it is not moving, but for some reason I cant figure out how can I combine it with 3d rotation. I am sure you people all know very well how it can be done. It will be great if anyone could explain me even en general how can I do it.
I was tempted to post some "Help me, d00dz, I am a nub" kind of post earlier when I just started trying to do 3d superscopes but I managed to figure it by myself (and with the help of "search" feature :P I hope my question will be answered.
By the way, if someone could post here an equation for sphere in x,y,z it would be great - I think Ive seen it somewhere in the older threads, but reading 3 pages of search threads results again doesnt make me feel happy.
Thanks.
Oh and forgive me for my poor english please :( its not my first language... Not even second actually


11th June 2004 08:39 UTC

My first advice to you would be to take some time to learn how the 3d scopes actually work. It does look a bit scary at first, but once you understand, it will make problems like this one a lot easier to attack. Lots of people have written out tutorials for it. The best place to go would probably be Atero's AVS primer. Do a forum search for "primer" and you should find it.

The basic idea is just that since perspective works by making things smaller as they get further away, you can represent 3d objects in 2d by dividing their (x,y)coordinates by how far away they are (the z coordinate). Look at the code, and youll see something similar to this:

dz=1/z1;
x=x1*dz;y=y1*dz;

That think about what that is doing. x=x1/z1; y=y1/z1 is a better way to think about it.

The next step is rotating in 3d, but ill let you read the primer for that one. :)

Ok. for "cutting off certain bits of the scope", the simplest way to do it is just change their color to whatever the background is. You say you have worked out how to do it when the scope is not moving, i think you mean that the bits you cut out move around as you rotate the object. But im not sure... so ill explain both ways. :)

For a simple shape like a sphere around the center point (0,0,0), it is very easy to work out which bits are "hidden" by other bits of the sphere. Becase every point that has a greater z coordinate than 0, must be at the back. So all you need to do is check the z coordinate and color it.

but, make sure you are getting the z coordinate of the object after it has been rotated. For example, say you specify the object with the variables x1,y1,z1. These coordinates havent been rotated yet, so if you were to make every point that has z1>0 black, the black area would move around as you rotate the sphere.

If you get the final coordinates, ie. the ones that are found in the last few lines:

dz=1/z3;
x=x3*dz;y=y3*dz;

You have coordinates (x3,y3,z3) that have already been rotated. So if did the lines:

red=below(z3,0);
blue=red;green=red;

the back part of the sphere would be black no matter how much you rotate it.

hope that helps.


12th June 2004 07:31 UTC

Alright, thank you, Sidd! My question seems to be very dumb for me now, but I have an excuse (lame one) - the engine I was using was calculating everything in 2 final strings - in final x and y so it was kinda hard for me to figure out the post-rotation "z" so I could use it to black out the neccesary parts of the scope.I am now using the engine that is re-calculating everything after rotation around every axis (and yes I understand now how it works), so now its all easy and clear for me.
Thanks alot!


12th June 2004 10:18 UTC

That, hiding the scopes back is called backface culling (do some googling on that). This can be easily be added to simple shapes (like: cube, sphere, hedrons etc.) and it can also be used to make some l33t shading, something much niced that stupid/dull depth shading.

ofcourse you can use good old simple skip-if-z-below-0 technique :)


12th June 2004 10:19 UTC


x1=sin(i*$pi)*sin(i*80);
y1=cos(i*$pi);
z1=sin(i*$pi)*cos(i*80);


Because you were so polite :). That doesn't happen very often with new users here.

12th June 2004 12:03 UTC

For a simple shape like a sphere around the center point (0,0,0), it is very easy to work out which bits are "hidden" by other bits of the sphere. Becase every point that has a greater z coordinate than 0, must be at the back. So all you need to do is check the z coordinate and color it.
This only works in orthogonal projections, not perspective. Perspective projects every point onto a plane, from the camera point out, which means that less than half of the sphere will be visible.

12th June 2004 12:07 UTC

Illustration of the above.


12th June 2004 16:41 UTC

Deamon,
this code makes crappy sphere, if you want to have sweet globe with parallel and vertical lines flowing perfectly then you must code little more =)

ucd, you happen to have any code example for perspective projection? :p


12th June 2004 20:09 UTC

Sort of like this.


12th June 2004 21:02 UTC

polite? huh? I was being myself, thats it :P
Well, I think I've read almost all the threads for the last, say, 1 month :) It happens that I can only access these forums only from this internet cafe so I cant check out the examples right now, so I am just writing them down and will try them as soon as I'll get home. Anyway... Do I get it right that the perfect (ssc) sphere is created with two synchronized superscopes? I tried to create one and it happens to be very crappy (it works right - rotates and such, but the "parallels" code is extremely crappy - I used the lamest way ever - y1=below(i,0.2)*blah+above(i,0.2)*below(i,0.4)*blah2+...). For some reason I cant come up with better one - tried alot of things. Well if anyone can give me an advice how could I do those effects better than they are done in this attachment, it would be great. By the way it is not a preset by any means and I dont pretend to be original or something, I know that it was done like a billion times before, I was just trying to figure out things by myself.
Thanks everyone.

p.s. somehow it seems that my sig isnt true all the time :)


13th June 2004 10:42 UTC

your doing this the hard way ;) well... atleast i dont understand how you do it :D but it looks quite ok, if you only would fixe your aspect ratio.

note that if you want the sphere not to be "solid", then do following,
delete line:

skip=if(below(alpha,0),1,skip);

and modify color code to something like this:
red=abs(alpha);
green=red;
blue=red;


truth be, told this sphere wasn't so easy me to figure out, now i would do it completely different tho:
I would code a grid (2 superscopes) and then i would "bend" the grid to a sphere, this is the most easy way imo

13th June 2004 13:47 UTC

Shylent: it's easiest if you don't use 'i' and make your own counters instead. Making a grid that way is dead easy.


13th June 2004 15:05 UTC

fast coded the grid version, it really is much easier


13th June 2004 19:01 UTC

Thanks again!
Yep, I've experienced some problems with "i", for some reason. Sometimes it just wont do what it is supposed to do. I will try the "grid" method. Cant wait to see your example, Jaak. Kinda hard to figure out everything at once when I use avs for like 3 weeks or so.
I am still wondering why don't you flame me out for my noob questions. Not that I am complaining (:P), just, hmm,wondering - havent expected such kind of response.


15th June 2004 05:47 UTC

This only works in orthogonal projections, not perspective. Perspective projects every point onto a plane, from the camera point out, which means that less than half of the sphere will be visible.
BAH! always complicating things ^_^