We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Deciding on inclusion within the field of vision
Page Index Toggle Pages: 1
Deciding on inclusion within the field of vision (Read 515 times)
Deciding on inclusion within the field of vision
Dec 11th, 2007, 9:29pm
 
Hi,
I'm using Processing to create a 3D animation composed of 150 objects, each of them composed of about 100 facets.
Each object has a draw() method that does calculation before to draw the vertex.
To speed up the rendering I would like not to process the draw() method of the object if the object is not in the field of vision of the camera. I will consider the center of the object as a reference (in a next release I could compute a bounding box)
I'm a bit confused on how to decide if a point at (x,y,z) is or is not in the field of vision of the camera located at (ex,ey,ez) and targeting at (tx,ty,tz) ?
Who could help me ?
Regards
Re: Deciding on inclusion within the field of visi
Reply #1 - Dec 11th, 2007, 9:38pm
 
One quick (but not excessively accurate) method would be to do a dot product of the normalised vectors (camera position->camera target) and (camera position->object) then compare that to cos(fieldOfView + aBit);
Re: Deciding on inclusion within the field of visi
Reply #2 - Dec 11th, 2007, 10:58pm
 
Hi, thanks but I sould have missed something.

What do you mean by :
Quote:
a dot product of the normalised vectors (camera position->camera target) and (camera position->object)
??

Thanks
Re: Deciding on inclusion within the field of visi
Reply #3 - Dec 11th, 2007, 11:41pm
 
Quick vector primer:

Vector from point a->b = b.x-a.x , b.y-a.y , b.z-a.z
Normalised vector: length=sqrt(v.x*v.x+v.y*v.y+v.z*v.z); v.x=v.x/length; v.y=v.y/length; v.z=v.z/length;

Dot product of vector a and b: a.x*b.x + a.y*b.y + a.z*b.z

(All this assumes you habve some simple class that has an x/y/z variable storing positions.)
Re: Deciding on inclusion within the field of visi
Reply #4 - Dec 12th, 2007, 10:19pm
 
Thanks for refreshing my mind on vectors ! Seems that I needed it ! BTW, I was confused by the english expression "dot product" (in french, this is "scalar product")

My "scene" where object are moiving around is flat, my objects are all at z=0
My cam position is defined by the angle, alphaZ, with the Z axis (0: the camera is at the vertical of the plane, PI/2 it is at the  horizontal) and by the angle with the Y axis, alphaY, and by the distance D from origin

The target point is always at (0,0,0)
As such, I can compute the normalized vector cam->target by :
(-cos(alphaZ), -sin(alphaZ)*cos(alphaY), -sin(alphaZ)*sin(alphaY))

I compute the vector cam->object at x,y,z by :
(x-D*cos(alphaZ), y-D*sin(alphaZ)*cos(alphaY), z-D*sin(alphaZ)*sin(alphaY))

Then I can compare the dot product of normalized vector which is equals to cos(angle between the vectors) with cos(half(?) of angle of field of view)

Am I right ?

If so, unfortunately, this does not work... yet.
Re: Deciding on inclusion within the field of visi
Reply #5 - Dec 16th, 2007, 4:46pm
 
Hi, ok I got it. After fix of several mistakes, I succeed in computing the dot product and compare with angle of field of view. Great !
But... as the screen is not a square, the angle of fov is not the same in every direction. I should compute the relative direction to know the angle to compare to...

Fortunately, there is another, quick and accurate, way to do it.
I simply use screenX() and screenY() for the (x,y,z) points that I want to know if they are visible or not. I just have to  check that 0<=screenX()<=width and 0<=screenY()<=height

Page Index Toggle Pages: 1