 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
OK, I know I'm being lazy here, but my maths isn't that hot...
Can anyone tell me how I would go about determining if a point will be
in view given its coordinates and the camera's parameters? See, I'm
making Antoine's necklace, a fractal object involving a very large
number of primitives, and they take up way too much memory, but many are
off the screen.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Andrew wrote:
>
> OK, I know I'm being lazy here, but my maths isn't that hot...
>
> Can anyone tell me how I would go about determining if a point will be
> in view given its coordinates and the camera's parameters? See, I'm
> making Antoine's necklace, a fractal object involving a very large
> number of primitives, and they take up way too much memory, but many are
> off the screen.
I wrote a macro to find the angle between two vectors.
#macro vangle(vec1,vec2)
#local len1 = vlength(vec1);
#local len2 = vlength(vec2);
#local len3 = vlength(vec2-vec1);
acos((pow(len3,2)-pow(len1,2)-pow(len2,2))/(-2*len1*len2))
#end
So find the angle between the vector
object position - camera position
and the vector
camera look_at - camera position (or just camera direction)
and check if the angle is larger than your viewing angle. Since the
camera angle goes to the edge of the pic, not the corner, you need a
bigger angle than the actual camera angle. I think this should do it:
atan(sqrt((1 + pow(image_height/image_width, 2)) *
pow(tan(camera_angle), 2)))
And of course you have to add a little padding for the width of the
objects...
Of course, this tells you if the object is in a cone around the field of
view, but it can be in the cone and outside the image. So it's not 100%
efficient, but it'll work (I think).
--
David Fontaine <dav### [at] faricy net> ICQ 55354965
My raytracing gallery: http://davidf.faricy.net/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Andrew <ast### [at] hotmail com> wrote:
: Can anyone tell me how I would go about determining if a point will be
: in view given its coordinates and the camera's parameters?
Just as a side note: This is not possible in a general case (or at least
very difficult to do accurately).
Why? Because POV-Ray accepts quite complicated camera definitions. For
instance, just the fact that you can apply a "normal modifier" pattern to
the camera rays makes it practically impossible.
Of course I know you are just talking about a regular perspective camera...
--
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}// - Warp -
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Using pow() in this context is a bad idea. Simple
multiplication (e.g. len3*len3) will do the trick while
being more efficient. Not by far due to the huge
parsing overhead, but...
As to the method in general -- what you propose is
not too accurate, and the other side of the cone is not
the only cause. Viewing frustum is not a cone.
I think, the right thing would be to build a matrix of
the transform inverse to the perspective one (i.e. such
transform that turns viewing frustum into a box; preferably
oriented along some axis) and then write a macro that
will apply that transform to projected primitive's
coordinates. If result is outside of the box -- well, hope
you got it.
BTW, this somewhat resembles what POV-Ray does
internally to each emitted ray while calculating intersections.
David Fontaine <dav### [at] faricy net> wrote in message
news:3B6DB942.CE717D93@faricy.net...
> Andrew wrote:
> >
> > OK, I know I'm being lazy here, but my maths isn't that hot...
> >
> > Can anyone tell me how I would go about determining if a point will be
> > in view given its coordinates and the camera's parameters? See, I'm
> > making Antoine's necklace, a fractal object involving a very large
> > number of primitives, and they take up way too much memory, but many are
> > off the screen.
>
> I wrote a macro to find the angle between two vectors.
>
>
> #macro vangle(vec1,vec2)
> #local len1 = vlength(vec1);
> #local len2 = vlength(vec2);
> #local len3 = vlength(vec2-vec1);
> acos((pow(len3,2)-pow(len1,2)-pow(len2,2))/(-2*len1*len2))
> #end
>
>
> So find the angle between the vector
>
> object position - camera position
>
> and the vector
>
> camera look_at - camera position (or just camera direction)
>
> and check if the angle is larger than your viewing angle. Since the
> camera angle goes to the edge of the pic, not the corner, you need a
> bigger angle than the actual camera angle. I think this should do it:
>
> atan(sqrt((1 + pow(image_height/image_width, 2)) *
> pow(tan(camera_angle), 2)))
>
> And of course you have to add a little padding for the width of the
> objects...
>
> Of course, this tells you if the object is in a cone around the field of
> view, but it can be in the cone and outside the image. So it's not 100%
> efficient, but it'll work (I think).
>
> --
> David Fontaine <dav### [at] faricy net> ICQ 55354965
> My raytracing gallery: http://davidf.faricy.net/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
In article <3b6de1fb@news.povray.org>,
"Vadim Sytnikov" <syt### [at] ru com> wrote:
> Using pow() in this context is a bad idea. Simple
> multiplication (e.g. len3*len3) will do the trick while
> being more efficient. Not by far due to the huge
> parsing overhead, but...
Actually, len3*len3 might be slower...more stuff to parse, and the time
it takes to call the C pow() function is insignificant compared to the
time it takes to parse POV code. But speed is very unlikely to be of any
concern here, readability is better, try this:
#macro Sqr(V) (V*V) #end
Sqr(Len3)
BTW, it is a good idea to always include at least one capital letter in
your macro or variable identifiers...what if some future version of POV
added len1, len2, or vangle() keywords? This code would simply fail.
--
Christopher James Huff - chr### [at] mac com, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tag povray org, http://tag.povray.org/
<><
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"more stuff to parse" -- how is that?
Chris Huff <chr### [at] mac com> wrote in message
news:chr### [at] netplex aussie org...
> In article <3b6de1fb@news.povray.org>,
> "Vadim Sytnikov" <syt### [at] ru com> wrote:
>
> > Using pow() in this context is a bad idea. Simple
> > multiplication (e.g. len3*len3) will do the trick while
> > being more efficient. Not by far due to the huge
> > parsing overhead, but...
>
> Actually, len3*len3 might be slower...more stuff to parse, and the time
> it takes to call the C pow() function is insignificant compared to the
> time it takes to parse POV code. But speed is very unlikely to be of any
> concern here, readability is better, try this:
> #macro Sqr(V) (V*V) #end
>
> Sqr(Len3)
>
>
> BTW, it is a good idea to always include at least one capital letter in
> your macro or variable identifiers...what if some future version of POV
> added len1, len2, or vangle() keywords? This code would simply fail.
>
> --
> Christopher James Huff - chr### [at] mac com,
http://homepage.mac.com/chrishuff/
> TAG: chr### [at] tag povray org, http://tag.povray.org/
>
> <><
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
David Fontaine wrote:
...
> I wrote a macro to find the angle between two vectors.
>
> #macro vangle(vec1,vec2)
> #local len1 = vlength(vec1);
> #local len2 = vlength(vec2);
> #local len3 = vlength(vec2-vec1);
> acos((pow(len3,2)-pow(len1,2)-pow(len2,2))/(-2*len1*len2))
> #end
>...
Hello again David
I haven't tested your macro, nor the one below,
but I think this one will do the same job:
#macro VAngle(v1,v2)
acos(vdot(vnormalize(v1), vnormalize(v2)))
#end // macro VAngle
(But maybe you already knew that ;)
--
Best regards,
Tor Olav
mailto:tor### [at] hotmail com
http://hjem.sol.no/t-o-k
http://www.crosswinds.net/~tok
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
> Can anyone tell me how I would go about determining if a point will be
> in view given its coordinates and the camera's parameters? See, I'm
> making Antoine's necklace, a fractal object involving a very large
> number of primitives, and they take up way too much memory, but many are
> off the screen.
I'm just doing something very similiar, creating a mesh with the level
of detail depending on the camera position. I'm quite sure there are some
packages which can do the same better, but maybe it gives you an idea.
#declare CAM_POS = <0,0,0>;
#declare CAM_TO = <0,0,10>;
#declare CAM_DIR = vnormalize(CAM_TO - CAM_POS);
#declare CAM_UP = vnormalize(vcross(CAM_DIR, x));
#declare CAM_RIGHT = vcross(CAM_UP, CAM_DIR);
camera {
location CAM_POS
direction CAM_DIR
up CAM_UP
right CAM_RIGHT * 4/3
}
// Change for other FOV, resolution
#macro Project(P, PX, PY)
#declare PX = P.x / P.z;
#declare PY = P.y / P.z;
#end
// Given any position in P, you can now get the exact position on screen
Hope this is helpful
--
#macro C(X,Y)cylinder{X*x<X,0,-Y/2>.1}#end#macro U(R,X,Y)intersection{torus{.9
.1}box{-1 0rotate y*R*90}translate<X,0,Y>scale 1-z*.5}#end union{U(0,0,0)U(1,0
,0)U(2,-1,-1)U(1,1,0)U(1,1.5,-3)U(1,2,0)U(3,1,0)U(2,2,0)U(0,3,0)U(3,2,.5)C(.1,
2)C(.8,1)C(.8,-1)C(1.1,1)C(1.9,-1)pigment{rgb 10}rotate x*90translate<-1,0,4>}
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Tor Olav Kristensen wrote:
>
> David Fontaine wrote:
> ...
> > I wrote a macro to find the angle between two vectors.
> >
> > #macro vangle(vec1,vec2)
> > #local len1 = vlength(vec1);
> > #local len2 = vlength(vec2);
> > #local len3 = vlength(vec2-vec1);
> > acos((pow(len3,2)-pow(len1,2)-pow(len2,2))/(-2*len1*len2))
> > #end
> >...
>
> Hello again David
>
> I haven't tested your macro, nor the one below,
> but I think this one will do the same job:
>
> #macro VAngle(v1,v2)
>
> acos(vdot(vnormalize(v1), vnormalize(v2)))
>
> #end // macro VAngle
>
> (But maybe you already knew that ;)
I think I tried that too but I had some reason for changing it... maybe
not?
--
David Fontaine <dav### [at] faricy net> ICQ 55354965
My raytracing gallery: http://davidf.faricy.net/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |