• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Gavin Williams

Test for a range not being covered by a list of ranges.

6 posts in this topic

Hi,

 

I'm writing some code to do a sweeping visibility check in a rogue-like (running around in a spiral while maintaining a collection of the occluding angles and adding a tile if it is not completely occluded at that point in the scan.

 

If I have a list of floating point ranges called the occludedRanges (represented by List<Vector2>), how can I test if a range called the occludingArc (represented by Vector2) is visible in the set of occludedRanges ? After which I would either discard that tile or union the occludingArc to the occludedRanges.

0

Share this post


Link to post
Share on other sites

When you union occludingArc to the occludingRanges, merge any ranges that can be merged. That way you'll always have your occludingRanges described as a union of disjoint ranges, and checking whether a new range is contained or not is trivial (it must be contained in one of the ranges, or otherwise it will be visible).

1

Share this post


Link to post
Share on other sites

Ok, I see the advantage of that now that you've said it (about the containment of the range being tested, within one of the existing ranges, and how that makes it simple to test). But what do i do across the polar axis (the +'ve x-axis in cartesian). Currently I produce 3 results in my method ..

List<Vector2>ComputeOccludingArcsOfSegment(float x1, float y1, float x2, float y2)

1. a single range [alpha,beta]                there are 5 cases for this

2. 2 ranges, [alpha,2Pi] & [0,beta]         there are 3 cases for this (where the segment is bisected by the polar axis)

3. null                                                     there are two cases for this, point and segment intersecting the relative origin.

 

I don't see how I can measure a range that goes from negative into positive, and have it be meaningful to a range being tested. I could keep the arc starting angle and it's sweeping angle, is that one way to do it ? Or maybe as long as I know the lower angle, and understand that it's floating point value may actually be higher than the upper angle of the range, then is that ok ? Am I just then testing lower against lower and upper against upper (for containment)

 

Edit : deleted the edit.

 

Edit 2 : Ok, so here is an example of what I don't understand ..

 

Let's say I have an existing occluding range 315 to 45 degrees.

 

How do i test if the range 0 - 20 is contained ? ... 20 < 45, but what about 0 to 315. I don't see a simple comparison.

Edited by Gavin Williams
0

Share this post


Link to post
Share on other sites

I have to think about this one a bit more, but using angles is almost always a source of headaches. You probably need functions to check if an angle is in between two other angles and things like that (perhaps that's the only thing you need?). You can then implement those checks carefully.

 

I have a well-known aversion to using angles, because what you are dealing with here is a circle, and unit-length 2D vectors is usually the better representation of points in a circle. But I am not sure things would be all that much simpler than using angles in this case.

 

I'll try to write some code for you tonight.

 

[EDIT: Changed "projective line" to "circle", because you need to distinguish between a vector and its opposite, so you don't really have a projective line in the usual sense (although topologically circle and projective line are the same).]

Edited by Álvaro
0

Share this post


Link to post
Share on other sites

This is probably why i got into vectors. Maybe using vectors would be easier. I haven't actually given that any thought yet.

 

Edit : So thinking about vectors .. what about if I project the range end-points onto the unit circle. And those vectors represent the corners of a bounding box (bounding the arc range). I would have a collection of bounding boxes. The range being tested would itself have a bounding box. Then do containment checks on the bounding boxes.

 

I have just thought of that, it looks ok, but it's now 2:30am here in Canberra and I'm getting tired. Thanks in advance for looking at this for me. I'll be back on tomorrow afternoon.

 

Edit 2 : just thought, for angles sweeping across the axes, the points where the arc intersect the axes would need to be contained by the bounding box for the range. So for the range 45 to 225, not only would the end points be included, but also the points 0,1 and -1,0.

Edited by Gavin Williams
0

Share this post


Link to post
Share on other sites

Ok,

 

Bounding box idea is no good, it probably works for smaller angles but I can think of cases where larger angles produce errors.

 

I went through my collision code, because I remembered that I have previously written a method to check for the closest point on an arc to a point. I extracted the following code...

        /// <summary>
        /// Test if a point p is within an arc swept by two vectors P1 & P2 from the perspective of the given focus. [ cost = 63 ticks ]
        /// </summary>
        /// <param name="arcP1"></param>
        /// <param name="arcP2"></param>
        /// <param name="focus"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static bool PointWithinArc(Vector2 arcP1, Vector2 arcP2, Vector2 focus, Vector2 p)
        {
            float angleP1 = AngleToVector(arcP1 - focus);
            float angleP2 = AngleToVector(arcP2 - focus);
            float angleP = AngleToVector(p - focus);

            // guarantee that angleP1 is lower than angleP2
            if (angleP1 > angleP2)
                angleP1 -= 2 * (float)Math.PI;

            // if the angle to the point p is within the arc range then the closest point is on the curve of the arc
            bool arcSoln = false;
            if (angleP1 >= 0)
            {
                if (angleP >= angleP1 && angleP <= angleP2)
                    arcSoln = true;
            }
            else // (angleP1 < 0)
            {
                if (angleP < angleP2)
                    arcSoln = true;
                if (angleP - 2 * (float)Math.PI > angleP1 && angleP - 2 * (float)Math.PI < angleP2)
                    arcSoln = true;
            }
            return arcSoln;    
        }

It works for all the trivial cases i have checked so far, but i need to give it some proper thought. At 63 ticks its an OK cost, but will really add up. given a 50x33 tilemap, assuming 30% occluder coverage, a check of the total map would result in a cost of about 34,600 ticks (x2-4), not so good. However, range of visibility (radius 12 for example) would reduce this to about 28,000 ticks (x2-4). Still very expensive. Too expensive. I have read about algorithms that check by octants, I suppose once an octant is fully occluded they don't check any more tiles in that octant. That could be a way to cut it down even further.

 

I realize too, that I am thinking of a general solution, but the fact that I am working with tiles means I should probably take advantage of that fact to optimize the solution. On the other hand, I already compute wall surfaces of the entire scene. So maybe I can do something there to remove unnecessary checks. I'll get this working first and check it's overall cost

Edited by Gavin Williams
0

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  
Followers 0