# Physics Simulation Forum

 All times are UTC

 Page 1 of 1 [ 10 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Determine if camera is between portals?Posted: Thu Feb 16, 2017 9:23 pm

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

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

Top

 Posted: Thu Feb 16, 2017 9:53 pm

Joined: Sat Jul 04, 2015 10:33 am
Posts: 349
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

 Posted: Thu Feb 16, 2017 10:01 pm

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

 Posted: Thu Feb 16, 2017 10:11 pm

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

 Posted: Thu Feb 16, 2017 10:12 pm

Joined: Thu Apr 14, 2016 3:44 pm
Posts: 43
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

 Posted: Thu Feb 16, 2017 10:17 pm

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

 Posted: Thu Feb 16, 2017 10:41 pm

Joined: Sat Jul 04, 2015 10:33 am
Posts: 349
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

 Post subject: Re: Determine if camera is between portals?Posted: Thu Feb 16, 2017 10:46 pm

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

 Post subject: Re: Determine if camera is between portals?Posted: Fri Feb 17, 2017 5:38 am

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.

Top

 Post subject: Re: Determine if camera is between portals?Posted: Fri Feb 17, 2017 3:05 pm

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

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 10 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 16 guests

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

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities
Powered by phpBB® Forum Software © phpBB Group