Determine if camera is between portals?

 Posts: 21
 Joined: Tue Jan 31, 2017 11:21 am
Determine if camera is between portals?
Here's a screenshot of what I am doing:
I need to know if the camera is between 2 portals regardless how far away the camera is or the orientation of the portals?
Heres the different possibilities:
I don't think it's going to be that simple though, any ideas?
Here's a screenshot of my graphics engine, spent 2 months on it so far, and can't give up now.
I need to know if the camera is between 2 portals regardless how far away the camera is or the orientation of the portals?
Heres the different possibilities:
I don't think it's going to be that simple though, any ideas?
Here's a screenshot of my graphics engine, spent 2 months on it so far, and can't give up now.
Last edited by paulggriffiths on Thu Feb 16, 2017 10:44 pm, edited 1 time in total.
Re: Any good at maths? A bit like collision detection.
Produce a convex hull out of the eight corners of both portals. In your case it basically means you create a box out of these eight corners of which two sides are the portals. Now you can use a convex hull algorithm which tells you if the point the camera is located in is within the box (or in general the convex hull). If it is within the hull, it is between the portals. There are plenty of convex hull algorithms out there, just google "check if point is in convex hull".

 Posts: 21
 Joined: Tue Jan 31, 2017 11:21 am
Re: Any good at maths? A bit like collision detection.
I think I've worked it out, some angles are positive and some are negative, got to work them out.
A bit simpler than convex hull.
If there're all positive or all negative then the camera is outside, though have to include the angles between the two portals too.
A bit simpler than convex hull.
If there're all positive or all negative then the camera is outside, though have to include the angles between the two portals too.
Last edited by paulggriffiths on Thu Feb 16, 2017 10:14 pm, edited 1 time in total.

 Posts: 21
 Joined: Tue Jan 31, 2017 11:21 am
Re: Any good at maths? A bit like collision detection.
No, the camera may be far away from the portals but still inbetween them.benelot wrote:Produce a convex hull out of the eight corners of both portals. In your case it basically means you create a box out of these eight corners of which two sides are the portals. Now you can use a convex hull algorithm which tells you if the point the camera is located in is within the box (or in general the convex hull). If it is within the hull, it is between the portals. There are plenty of convex hull algorithms out there, just google "check if point is in convex hull".
Re: Any good at maths? A bit like collision detection.
use planes to represent the portals, a single signed distance calculation can determine if the camera is inside or outside
example
example
Code: Select all
float PlaneDist(vec4 plane, vec4 pt) {
vec4 d = plane * pt;
return d.x + d.y + d.z + d.w;
}

 Posts: 21
 Joined: Tue Jan 31, 2017 11:21 am
Re: Any good at maths? A bit like collision detection.
Good idea as could calculate if it is rotated more than 180 first then do the planes equation.ktfh wrote:use planes to represent the portals, a single signed distance calculation can determine if the camera is inside or outside
Probably a bit simpler than my angles idea, thanks!
This is the function I use as the corners are vec3's
Code: Select all
float VRenderManager::getDistance(glm::vec3 p0, glm::vec3 p1, glm::vec3 p2, glm::vec3 p3)
{
GLfloat a, b, c, d;
a = (p2.y  p1.y) * (p3.z  p1.z)  (p2.z  p1.z) * (p3.y  p1.y);
b = (p2.z  p1.z) * (p3.x  p1.x)  (p2.x  p1.x) * (p3.z  p1.z);
c = (p2.x  p1.x) * (p3.y  p1.y)  (p2.y  p1.y) * (p3.x  p1.x);
d = p2.x * a  p2.y * b  p2.z * c;
return (a * p0.x + b * p0.y + c * p0.z + d) / sqrt(a * a + b * b + c * c);
}
Re: Any good at maths? A bit like collision detection.
I realized that you maybe have a different definition of inbetween. If two planes can be used, you can basically just use basic math to determine if your camera is in front or behind the planes:
The general prodecure would be this:
vec normalA;
vec AB = B  A;
double dot = dot(AB, normalA);
bool inFront = (dot > 0);
source:
https://www.opengl.org/discussion_board ... ndaplane
P.S. Can you please rename the thread (edit first post) to something meaningful like "Determine if camera is between portals" so that it is easier for others to identify what it is about?
The general prodecure would be this:
vec normalA;
vec AB = B  A;
double dot = dot(AB, normalA);
bool inFront = (dot > 0);
source:
https://www.opengl.org/discussion_board ... ndaplane
P.S. Can you please rename the thread (edit first post) to something meaningful like "Determine if camera is between portals" so that it is easier for others to identify what it is about?

 Posts: 21
 Joined: Tue Jan 31, 2017 11:21 am
Re: Determine if camera is between portals?
For those that are interested here a YouTube video of my portals implementation:
https://youtu.be/TtJ1bI10po
https://youtu.be/TtJ1bI10po

 Posts: 21
 Joined: Tue Jan 31, 2017 11:21 am
Re: Determine if camera is between portals?
Can't use distance plane equation because what if the top portal is rotated by 90?
Cam A & B positions are both inside the portals but one side would produce a not inside result. Also if the cam is above the top portal the infinite plane equation would not know this.
So think ill have to use angles?
It has to be exact because this calculation decides if a portal is hidden by another portal and then clip the portal as in the first screenshot in this thread. Cam positions A & B not clip the portal, cam positions C & D clip the portal.
Cam A & B positions are both inside the portals but one side would produce a not inside result. Also if the cam is above the top portal the infinite plane equation would not know this.
So think ill have to use angles?
It has to be exact because this calculation decides if a portal is hidden by another portal and then clip the portal as in the first screenshot in this thread. Cam positions A & B not clip the portal, cam positions C & D clip the portal.

 Posts: 21
 Joined: Tue Jan 31, 2017 11:21 am