Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Thu Feb 16, 2017 9:23 pm 
Offline

Joined: Tue Jan 31, 2017 11:21 am
Posts: 21
Here's a screenshot of what I am doing:

Image

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:

ImageImage

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.

Image


Last edited by paulggriffiths on Thu Feb 16, 2017 10:44 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Feb 16, 2017 9:53 pm 
Offline

Joined: Sat Jul 04, 2015 10:33 am
Posts: 345
Location: Bern, Switzerland
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".


Top
 Profile  
 
PostPosted: Thu Feb 16, 2017 10:01 pm 
Offline

Joined: Tue Jan 31, 2017 11:21 am
Posts: 21
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.


Last edited by paulggriffiths on Thu Feb 16, 2017 10:14 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Feb 16, 2017 10:11 pm 
Offline

Joined: Tue Jan 31, 2017 11:21 am
Posts: 21
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".


No, the camera may be far away from the portals but still in-between them.


Top
 Profile  
 
PostPosted: Thu Feb 16, 2017 10:12 pm 
Offline

Joined: Thu Apr 14, 2016 3:44 pm
Posts: 32
use planes to represent the portals, a single signed distance calculation can determine if the camera is inside or outside
example
Code:
float PlaneDist(vec4 plane, vec4 pt) {
    vec4 d = plane * pt;
    return d.x + d.y + d.z + d.w;
}


Top
 Profile  
 
PostPosted: Thu Feb 16, 2017 10:17 pm 
Offline

Joined: Tue Jan 31, 2017 11:21 am
Posts: 21
ktfh wrote:
use planes to represent the portals, a single signed distance calculation can determine if the camera is inside or outside


Good idea as could calculate if it is rotated more than 180 first then do the planes equation.

Probably a bit simpler than my angles idea, thanks!

This is the function I use as the corners are vec3's

Code:
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);
}


Top
 Profile  
 
PostPosted: Thu Feb 16, 2017 10:41 pm 
Offline

Joined: Sat Jul 04, 2015 10:33 am
Posts: 345
Location: Bern, Switzerland
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 ... nd-a-plane

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?


Top
 Profile  
 
PostPosted: Thu Feb 16, 2017 10:46 pm 
Offline

Joined: Tue Jan 31, 2017 11:21 am
Posts: 21
For those that are interested here a YouTube video of my portals implementation:

https://youtu.be/TtJ-1bI10po


Top
 Profile  
 
PostPosted: Fri Feb 17, 2017 5:38 am 
Offline

Joined: Tue Jan 31, 2017 11:21 am
Posts: 21
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.

Image


Top
 Profile  
 
PostPosted: Fri Feb 17, 2017 3:05 pm 
Offline

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group