Sign in to follow this  

Creating objects in portal engine

Recommended Posts

I will me creating a portal engine and I have a question about how objects are created in the correct portal... I know that with "major" objects like players you can create a spawn point which determines which sector they will start in. But what if a player, for example, fires a bullet while standing right next to a portal in the direction of the portal so that, because the end of the player's gun sticks out past the portal, the bullet is created past the portal even though the player isn't past it? The bullet would never cross the portal into the next sector because it was created beyond the portal. I thought of casting a ray from the player's position to the bullet's start point to check if it goes through the portal, but if the portal is at a corner and the player is standing near the corner and points the gun past the portal, the ray cast could skip the portal. I also thought of keeping track of the point on the gun where the bullet is created as the player's position, but what if the player has a "short" gun out next to a portal and switches to a "longer" gun? The new gun's length would be over the portal but wouldn't have actually passed through it. What type of solution is there to this problem?

Share this post

Link to post
Share on other sites
Most games leave the gun position as purely a graphical effect, and just make the bullets spawn from the player's center.

course this is annoying as heck in Halo3 Sniper games... where the bullets come out of the other guy's head thats peeking over a wall... no gun in sight.
But its seems largely accepted to do it that way.

Share this post

Link to post
Share on other sites
Try this. When creating an object in your world, always do it as a "possible child" of a sector. Find the world-space position of where the new object should be, and examine the spawning sector. If that point is in that sector, then the new object belongs to that sector. Otherwise, breadth-first study the sectors adjacent to the active sector, in order from nearest-the-point to furthest (simple point-plane nearest-approach calculation). When you find a sector that does contain the point, that sector is the parent.

Assuming that you have convex sectors only, you won't iterate into a sector if its nearest portal to the point is further from the point than your own nearest portal, and you never sample the portal which you followed into the current sector.

All points spawned relative to sector B.

Nearest portal planes to each point (for diagram reference only: only calculate the distances you need when running the algorithm)
1: AB
2: AB,BC

Find point 1:
B: BA,BC,BG are the nearest planes.
b->A: point is in A.
Point is in A.

Find point 2:
B: BA,BC,BG are the nearest planes.
b->A: no other portals.
b->C: CD further than BC.
b->G: GF further than BG.
No sector.

Find point 3:
Point is in B.

Find point 4:
Point is in B.

Find point 5:
B: BC,BG,BA are the nearest planes.
b->C: CD is nearest plane.
b->c->D: DE is further than CD.
b->G: GF is nearest plane.
b->g->F: point is in F.
Point is in F.

Share this post

Link to post
Share on other sites
Well I wasn't planning on making a strict portal system so I could have concave portals and z-buffering and not have to wiry so much about placing portals perfectly. Is there a way without a strict portal system?

Hmm, perhaps I can use that method, Wyrframe, though slightly altered. What I'll do is create one or more rough convex bounding meshes for each sector and check against those when creating objects. As long as the bounding meshes cover the whole sector and don't intersect any other sectors' bounding meshes, it should work fine. (For example, a square room would only use one and a hallway with one bend could use either one or two, depending on whether another sector was in the "bend".)

[Edited by - Gumgo on August 11, 2008 11:18:26 AM]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this