Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6231945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:01:42+00:00 2026-05-24T10:01:42+00:00

I have been studying about quadtrees and their usage in collision detection in videogame

  • 0

I have been studying about quadtrees and their usage in collision detection in videogame code.

However, all the implementations so far rely on object-oriented features of C++,C#, javascript and Lua to do every node, and I have absolutely no idea of how to translate that to raw C.

The objective is to test multiple objects (shots) against actors (constantly moving) and terrain (static). Then actors with terrain.
Since I cannot find an example I can read in “pure” C terms (that is, not using methods or self-referencing objects), I cannot even grasp the basic idea of how to code it, while I do understand the idea behind the algorithm. I don’t know how to set it up, how to reference it, what datatypes should I use, or anything at all. I know absolutely nothing of C++, which makes translating it to C impossible.

As well, I will be using tilemaps for terrain, and I want to do things like maps that are tall or wide, not perfect squares. A quadtree still works with such a map?

Also, there will be a number of moving elements, being the terrain the only static part in play (elements like moving blocks or doors are separate entities). Is it worth it using a quadtree if updates will be required often? Do I even need to make it global data? (could as well be forged inside some function and then passed around when collisions are enabled). Do I need to allocate memory for it in such a case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:01:43+00:00Added an answer on May 24, 2026 at 10:01 am

    Because you are asking for help with absolutely nothing to start with, I’ll show you some example data structures that might work, as well as an API.

    In C, one would implement nodes with structures. Something like this:

    struct quadtree {
        int size;
        struct node *root;
    };
    
    struct node {
        struct node *children[4];
    };
    

    And then to stick objects in the quadtree, you can add some extra fields.

    struct object {
        int x, y;
        // plus extra info not related to quadtree
    };
    
    struct node {
        struct node *children[4];
        int nobjects;
        struct object *objects;
    };
    

    The quadtree interface would give you some basic operations:

    void quadtree_insert(struct quadtree *q, struct object *obj);
    void quadtree_remove(struct quadtree *q, struct object *obj);
    // Equivalent to remove + insert, but more efficient
    void quadtree_move(struct quadtree *q, struct object *obj, int x, int y);
    int quadtree_query(struct quadtree *q, struct object **obj, int max,
                       int x0, int y0, int x1, int y1);
    

    That’s it, basically. But the implementation will not be trivial. Note that the maximum depth of this quadtree is about 32, which can simplify the implementation somewhat.

    If you’re having problems here, I suggest taking a step back and tackling a similar but simpler data structure first. For example, try implementing a Red-Black or AVL tree without using source code as a reference. If you’re not somewhat well-versed in C programming, then a quad tree may be a poor choice for a first project due to its moderate complexity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been studying DDD in-depth on my own time; reading everything about it
I have been studying this code to generate random text: from collections import defaultdict,
I have been studying as much as I can about the Module Pattern suggested
I've been studying .Net threading and have learned about the Threading.Task and Threading.Task.Parallel classes.
I have been studying the Qt Quarterly article about QGraphicsScene and OpenGL for the
Actually I am studying this algorithm and I have been exploring his code (which
these days I have been studying about NP problems, computational complexity and theory. I
I just started studying programming about 6 months ago and I have really been
Have been studying the file system related classes of Adobe AIR 1.5, but so
I have been studying SOAP and WSDL in preparation for implementing a web service.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.