|
|
#1 |
|
Senior Member
|
Two raytracing problems
I've been trying to do some more advanced raytracing and I have two questions. The code can be found in the sections under each question.
--------------- Question 1: I tried making a hyperboloid from one piece using the formule x^2+y^2-z^2=1. So far no problems, but I wanted to view it from the outside. This means the point of origin must lie outside the object with the equation x^2+y^2-z^2=1. I thought that that would be pretty easy to do by changing to the origin coördinates {ox,oy,oz} to {0,2,0} and then I could find out later how to make sure that the position of origin is relative to the rotation angles in such a way that the camera always look at the object. But after I changed {ox,oy,oz} to {0,2,0} (you can do this changing the following line: code: to code: The view isn't like the object I intended at all. What have I done wrong? The code of the dynmov: code: --------------- Question 2: I wanted to do a triangular tunnel by defining three planes with the following formulas: -x+y=2 x+y=2 y=-sqrt(2) This should give you a triangle tunnel, but instead I get something very strange. There are three planes, which will form a triangle when extended, but on and around the places where the triangle sides should meet, there are some strange planes that go to infinity. Making the k1, k2 and k3 absolute solves the problem, but gives you a six-sided tunnel. I want a three-sided one. I think the problem has to do with the -infinity outcomes for k1, k2 and k3, but I can't get rid of those without making the tunnel six-sided. The code of the dynmov: code: |
|
|
|
|
|
#2 |
|
Member
Join Date: Jun 2003
Posts: 93
|
For the second problem:
code: Min takes the lowest value, so if k2=-100 and k3=-50, your math would choose k2. I changed the code so it (essentially) takes the number with the lowest positive value, but does not use that number's absolute value. At leat I think that's what I did... It kinda don't look right to me I haven't worked on the first problem much, but i'll try to figgure it out... edit: put that code in per point. edit2: Man i'm dumb... All I did was get rid of all negative k1,k2,and k3 values, I dunno what I was talking about above... Last edited by 13373571; 29th June 2003 at 14:05. |
|
|
|
|
|
#3 |
|
Senior Member
|
Wow, great, thanks a lot, I now see what I did wrong. 13373571, you'll get a word of thank when I finish my dynmov tetrahedron
.
|
|
|
|
|
|
#4 | |
|
Member
Join Date: Jun 2003
Posts: 93
|
In the first one, you use
ki=sqrt(b1*b1-4*a1*c1)/(2*a1); k1=-b1/(2*a1)+ki; k2=-b1/(2*a1)-ki; k=min(k1,k2); ... This has the same problem as the second one... if k1=-13373571 and k2=13373571, you will render the negative value... I don't know if that's your only problem though, I haven't tested because I'm sick of winamp crashing every five minutes... It's enough to make me want to try winamp 2. And by the way, I *think* you can use ki=sqrt(b1*b1-4*a1*c1)/(2*a1); k=-b1/(2*a1)-ki; k=if(below(k,0),-b1/(2*a1)+ki,k); and then blend out negative ks... Quote:
especially if you're going to be viewing it from outside...edit: Wow I use a lot of ...s, I need to try to stop doing that |
|
|
|
|
|
|
#5 |
|
Major Dude
Join Date: Jan 2003
Location: Mumbai, India
Posts: 787
|
13373571, the dm master after UnConeD
(btw, do you have a nick or something? feels funny to call you 13373571)
http://home.iitb.ac*****~shreyaspotnis |
|
|
|
|
|
#6 |
|
Member
Join Date: Jun 2003
Posts: 93
|
Some people have called me "I.P. Address" and "Numbers"...
You can say "leet" or 1337 or any variation thereof. Or just smack your keypad randomly and use the number that comes up. |
|
|
|
|
|
#7 |
|
Senior Member
|
Looks like LeetEsti to me.
|
|
|
|
|
|
#8 |
|
Major Dude
|
yeah, i thought of that too!
|
|
|
|
|
|
#9 |
|
Major Dude
Join Date: May 2003
Location: Australia
Posts: 1,353
|
i always thought it was leetest1
like "leetest one". thanks for the advise though 14234563780, from now on i shall call you 0142387134610.. |
|
|
|
|
|
#10 |
|
Senior Member
|
I made a DM tetraeder. I made it using the following formules for the sides:
code: The code for that dynmov is the following: code: But when I try to view that from the outside, it doesn't look like a tetraeder. The sides 'continue'. It looks like when you see a cube from the outside with all the sides extended infinitely. Using max() instead of min() doesn't work. If you do that, it gets all infinity. I think you have to determine the lines where two planes meet and then use an if()-function to choose min() when inside those lines and to use max() when outside those lines. I did figure out how to make the camera always point at the center of the object, after looking at UnConeD's WaterCube code. Instead of getting the origin {ox,oy,oz} from the rotation angles {rx,ry,rz}, you determine the rotation angles from the origin. You can do this with atan2(). An example is the following code, which you can paste in the frame section of the dynmov above. code: Since oz=0, there's no need to calculate ry. |
|
|
|
|
|
#11 | ||
|
Member
Join Date: Jun 2003
Posts: 93
|
Quote:
Quote:
No, I haven't fixed your tetrahedron, I told you earlier that even thinking about a dm tetrahedron made my head hurt, didn't I? It's more complex than a cube... Let's just wait for UCD to look at this. Edit: And no, six lines that intersect at the four corners of a tetrahedron don't have insides either. Last edited by 13373571; 1st July 2003 at 01:48. |
||
|
|
|
|
|
#12 |
|
Senior Member
|
I meant the pieces of the planes that are inside and outside those lines.
|
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Jul 2002
Posts: 149
|
You can also make the camera view the orgin by using :
frame: rx=rx+bx;ry=ry+by;rz=rz+bz; sx=sin(rx);sy=sin(ry);sz=sin(rz); cx=cos(rx);cy=cos(ry);cz=cos(rz); ox=cy*distance;oy=cz*sy*distance;oz=-sz*sy*distance; beat: bx=(rand(201)*0.01-1)*sp;by=(rand(201)*0.01-1)*sp;bz=(rand(201)*0.01-1)*sp; point: dx=sx*x+cx*y;dy2=cx*x-sx*y; dz=sy+cy*dx;dx=cy-sy*dx; dy=sz*dy2+cz*dz;dz=cz*dy2-sz*dz; ... .... And the rotation will stay random |
|
|
|
|
|
#14 |
|
Member
Join Date: Jun 2003
Posts: 93
|
code: It's supposed to calculate ix,iy,and iz for each plane and then if these coordinates are beyond the bounds of the triangle that each plane is going to be "cut" into, it sets k for that plane to be an arbitrary large number (1337). When this is done for all of the planes, we should have the four triangles that make up the tetrahedron. Then supposedly the closest triangle (found with min) should be the proper one. Unfortunately, it don't work. ![]() anybody know why? Last edited by 13373571; 1st July 2003 at 11:59. |
|
|
|
|
|
#15 |
|
Senior Member
|
The idea seems to be right, but like you said, it doesn't work. My guess is that the way you decide if the coordinates are outside the bounds of the triangle are somehow flawed. The sides of plane z=-sqrt(2) (k3) lie on -ix+iy+iz=2, ix+iy+iz=2, iy+iz=-sqrt(2) and ofcourse z=-sqrt(2), because that the plane itself. Yet you test for -ix+iy+iz=2, ix+iy+iz=2 and iz=-sqrt(2), but not for iy+iz=-sqrt(2). Was that meant like this and if so, why?
I think we should try to solve this first so that when you view the tetraeder from the inside, it's look normal. Then, if we did it correct, moving the origin outside the object, using nixa's code, would give us a nice DM tetraeder. |
|
|
|
|
|
#16 |
|
Member
Join Date: Jun 2003
Posts: 93
|
...... look carefully at each of the triangle cutter-upper lines. For each plane, I tested its intersection with the other three, but not its intersection with itself because that would've been just a tad redundant...
I just realized my error though... I had thought that earlier when you were listing the planes, you were putting them in order. I guess that was a kinda dumb assumption. Anyways, the fix after that is still a tad glitchy, here is the latest attempt: code: At least we have triangles now... sorta |
|
|
|
|
|
#17 |
|
Whacked Moderator
Join Date: Jun 2001
Posts: 2,104
|
skupers: this is wrong:
rz=atan2(ox,oy); rx=atan2(oy,oz); The problem with your hyperboloid is twofold: - you're not discarding points behind the camera (k<0) - you're not discarding points where there is no intersection (b^2-4*a*c < 0 for the quadratic equation). I won't bother with the tetrahedron, too much trouble :P. Essentially you just raytrace all the front-facing planes, clip all intersectionpoints with the correct triangle and then min the remaining points. A good source for a fast triangle/line intersection test should be the 3D rendering scene. Try flipcode or something. |
|
|
|
|
|
#18 | |
|
Senior Member
|
Quote:
So, this seems to be a good version of the hyperboloid from one space: code: It's really cool and looks kinda like a wormhole .
|
|
|
|
|
|
|
#19 | |
|
Member
Join Date: Jun 2003
Posts: 93
|
Quote:
I now have a fairly tetrahedral shape going on having fixed a few more obvious stupid errors (not all of which were mine for a change I actually looked at skuper's code) but one of the points of the tetrahedron always manages to stretch to infinity and both oy and oz seem to be changing the same value.The problem isn't with the triangle cutting stuff, that's working great, it's somethin about how dx,dy,dz, and/or ox,oy,oz are being used, they don't do what they're supposed to and I don't see why. code: |
|
|
|
|
|
|
#20 | |
|
Senior Member
|
Yeah, it at least looks like a tetraeder now, but I don't know why on of the points goes to infinity. It seems to me z1=-sqrt(2) is the bottom plane. I'll look into it further tommorrow, it's 0:05 AM in the Netherlands now
.Quote:
Do you mean oy and oz change per pixel? If so, that isn't happening. You can check that by adding x=x1*oy;y=y1*oz; to the end of the dynmov. They only change per frame (they're ofcourse supposed to do this), not per pixel. BTW, are you a university student like UnConeD and Jheriko, 1337? |
|
|
|
|
|
|
#21 | ||
|
Member
Join Date: Jun 2003
Posts: 93
|
Quote:
If you set everything to zero (the d's and the o's) and then add small increments to oy and then set it back to zero and do the same with oz, they seem to cause the same changes if I remember correctly. Quote:
I'm entering junior year in high school.
|
||
|
|
|
|
|
#22 |
|
Whacked Moderator
Join Date: Jun 2001
Posts: 2,104
|
1337: there's nothing wrong with raytracing the backfacing points, but if you can avoid it easily, it's another optimization staring you in the face.
For example for quadrics... the solutions to the equation are something like (-b-sqrt(d))/2a and (-b+sqrt(d))/2a. Because of the way the equation is written down, one of them is always the frontfacing point, and the other is always the backfacing point. If you never switch between inside/outside, then you can always use the same point. And in Watercube I only raytrace 3 planes rather than 6 because only 3 are ever visible at once. |
|
|
|
|
|
#23 | |
|
Major Dude
Join Date: May 2003
Location: Australia
Posts: 1,353
|
with the tetrahedron: its practiaclally impossible to perform any intelegent back-face culling in avs, due to lack of decent control structures.
When you are veiwing it from the exterior, you cant just use max or min, or comninations of both, because you are dealling with infinite planes. Imagine that there is one face of the tertrahedron dirctly flat to the camera (x,y plane), this plane will never shine as the max or min k value becaue the angled planes adjacent to stretch out to infinity, and therfore go infront of it. To get it to work properly, you would either have to write a backface culling line for each individual plane, or write a limiter for each plane, so that when it reaches the boundries of a particular face, it starts drawin the next plane. It might be easier to do one DM for each face. Quote:
|
|
|
|
|
|
|
#24 | |
|
Member
Join Date: Jun 2003
Posts: 93
|
Quote:
siddhartha: one DM for each face would require that each DM has knowledge of the locations of the other faces... and each point has to calculate four identical rotations. slow as hell and hard to code, methinks. And you can use min once you've cut the planes into triangles like we've been doing in the last few examples. |
|
|
|
|
|
|
#25 |
|
Major Dude
Join Date: Jan 2003
Location: Mumbai, India
Posts: 787
|
my eight sided dm
![]() i understand, there is an extra rotation on the z axis, which i had made for a purpose, but it is not meant to be here and i am not interested in changing it now. code: http://home.iitb.ac*****~shreyaspotnis |
|
|
|
|
|
#26 |
|
Member
Join Date: Jun 2003
Posts: 93
|
that's great, although it doesn't render from the outside and doesn't help at all with the tetrahedron
nice work
|
|
|
|
|
|
#27 | |
|
Major Dude
Join Date: May 2003
Location: Australia
Posts: 1,353
|
Quote:
|
|
|
|
|
|
|
#28 |
|
Major Dude
Join Date: Jan 2003
Location: Mumbai, India
Posts: 787
|
hehe, this thread turned into a code book
![]() btw. this shape is a hedron now, isnt it? i dont know exactly what a hedron is, leave alone a tetrahedron. http://home.iitb.ac*****~shreyaspotnis |
|
|
|
|
|
#29 | |
|
Member
Join Date: Jun 2003
Posts: 93
|
Quote:
Skupers: You ARE absolutely sure that the four planes you posted earlier form a tetrahedron, right? Because it seems to me that they form a triangle tunnel with a plane intersecting it... and it seems to me that that's what AVS is rendering... and it seems to me that improper planes is the only way to explain what AVS is doing. |
|
|
|
|
|
|
#30 |
|
Senior Member
|
I'm almost certain. I made a image to explain how I got the formulas. It's attached.
|
|
|
|
|
|
#31 |
|
Member
Join Date: Jun 2003
Posts: 93
|
wouldn't adding z on all 3 planes make all 3 planes slope downwards?
|
|
|
|
|
|
#33 |
|
Major Dude
Join Date: May 2003
Location: Australia
Posts: 1,353
|
|
|
|
|
|
|
#34 | |
|
Member
Join Date: Jun 2003
Posts: 93
|
Quote:
|
|
|
|
|
|
|
#35 | |
|
Senior Member
|
Quote:
|
|
|
|
|
|
|
#36 | |
|
Member
Join Date: Jun 2003
Posts: 93
|
Quote:
Edit: Here, i just fixed it. code: I changed the plane z+y=-sqrt(2) into the plane y=-sqrt(2). That's what was wrong, you had the wrong plane. Blargh. |
|
|
|
|
|
|
#37 |
|
Senior Member
|
Then, it should be y-z=-sqrt(2), not y=-sqrt(2). Sorry for my stupid mistake.
![]() code: This should work. |
|
|
|
|
|
#38 | |
|
Member
Join Date: Jun 2003
Posts: 93
|
Quote:
I was just getting irritated because I couldn't get something to work even though it seemed so clear that it should've been working. |
|
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|