Page 1 of 1

[DONE] Torus command

Posted: August 31st, 2011, 11:48 pm
by M1_Abrams
Would it be possible to make a command that draws a torus (doughnut shape)?

Answer:
Image

Re: Torus commands

Posted: September 1st, 2011, 12:09 am
by fragmer
I don't know the equations for torus voxelization. If you find some, let me know, I'll implement it.

Re: Torus commands

Posted: September 1st, 2011, 12:25 am
by Hit-Girl
So, uh, I googled ''equations for torus voxelization'' I have no idea if this is of help or not, but I'ma share it none-the-less. :?

Code: Select all

S (u, v) = ( f (u, v), g(u, v), h(u, v)), where − π ≤ u ≤ π, −π ≤ v ≤ π, a > 0

Re: Torus commands

Posted: September 1st, 2011, 2:46 am
by boblol0909
I found this code online, might help idk
Show

Re: Torus commands

Posted: September 1st, 2011, 3:02 am
by Bloody_Llama
Personally, I get a lot of satisfaction building one myself. However, the enormous amount of time it takes certainly would justify a command. How you could actually implement it with less complexity than piloting a fighter jet, I don't know.

Re: Torus commands

Posted: September 1st, 2011, 3:05 am
by M1_Abrams
Fragmer I have an idea.

The user places two blocks just like cuboid, and the command does this:

1. uses ellipsoid command to make a circle along the xy-plane from x1,y1,(z1+z2)/2 to x2,y2,(z1+z2)/2

2. draws spheres from EVERY point on the circle with radius z1-[(z1+z2)/2]

3. This should approximate a torus pretty well, I'm going to test it :happycreeper:


EDIT: And Bloody_Llama, I would love to build a torus myself using this method, but the lame builders spamming spheres took sphere away from all builders. :(

Re: Torus commands

Posted: September 1st, 2011, 3:06 am
by Bloody_Llama
Good luck making a hollow one like that :twisted:
Also, don't you have to define how big the center is, and how steep (I'm sure there is a better word for that)?

And if we're going to call it a torus, shouldn't it allow more irregular shapes? Torus's aren't all perfectly circular. (LOL @ circles in a game made of cubes)

edit: M1_Abrams if you want to test out this shit, download fCraft and start up a local server on your machine, where you can use any command to your hearts content.

Re: Torus commands

Posted: September 1st, 2011, 3:10 am
by M1_Abrams
Hold on I'll have a screenie in a few minutes.

And I was just wanting a ring, but this method might work for non-circle ellipses

Re: Torus commands

Posted: September 1st, 2011, 3:30 am
by M1_Abrams
This isn't EVERY point cuz I don't have much time, but an idea:
Image

Re: Torus commands

Posted: September 1st, 2011, 3:59 am
by fragmer
Rotating a sphere around an axis would work, BUT there are a couple performance constraints to overcome before this will be practical:
  • All draw operations are applied incrementally, and must preserve their state between batches. This is optimally solved with a state machine such as the current /ehx implementation. If that ends up being too difficult (as it very well might), I'd have to fall back to creating an iterator block. That adds some overhead though.
  • All draw operations must touch any given coordinate at least once. If a block is touched twice, /undo information will be lost for that coordinate. It would also be extremely inefficient to revisit each block dozens or even hundreds of times with consecutive sphere commands. I've dealt with this limitation so far by making all drawing operations work linearly. Another solution would be to keep a list of modified coordinates, like a HashSet of resolved block array indices. But that would add a lot of memory and CPU overhead, and would not scale well - checking for duplicate coordinates will become O(n^2).

Re: Torus commands

Posted: September 2nd, 2011, 3:04 am
by M1_Abrams
Well another method would be to draw that axis in the picture above, then draw two perpendicular rings around it, and then draw a bunch of circles (not as many as the sphere idea!) parallel to the axis that contain the points on the two rings.

EDIT: Nevermind, I failed.

Re: Torus commands

Posted: September 2nd, 2011, 3:54 am
by fragmer
I would suggest an implementation that goes in slices along the z axis (top-down) like so:

Image

Each slice will have blocks between two circles - inner and outer. The radius of those circles can be figured out with a simple equation. Now all you have to do is go through each voxel within a slice and check if it's contained between those circles. Tada.

Like I said earlier, I don't plan on implementing this myself. But if someone else wants to volunteer, go ahead, I'll include your code when you're done.

Re: Torus commands

Posted: September 3rd, 2011, 2:51 am
by M1_Abrams
IT WORKS FRAGMER IT WORKS!!! :lol: :happyskeleton: :happycreeper:

EDIT:
Image
Now I just have to finish making the callback and figure out where the user should set the blocks and it's good to go! (Hopefully)
Also I have to program the Logger and the undo-er thing. Woohoo!

Re: Torus commands

Posted: September 3rd, 2011, 4:19 am
by KingCrab
Win

Re: Torus commands

Posted: September 10th, 2011, 5:57 am
by Fehzor
Can we make an alias be /donut?

Re: Torus commands

Posted: September 10th, 2011, 10:23 pm
by fragmer
Consider it done, Fehzor.

Re: Torus commands

Posted: September 11th, 2011, 1:46 am
by cdferg
Fehzor wrote:Can we make an alias be /donut?
And /bagel?

Re: Torus commands

Posted: September 11th, 2011, 3:37 am
by tomsplz3
cdferg wrote:
Fehzor wrote:Can we make an alias be /donut?
And /bagel?

how about krispy kreme lol