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 9042019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:22:53+00:00 2026-06-16T10:22:53+00:00

I am building a racing game in OpenGL using Glut, and I’m a bit

  • 0

I am building a racing game in OpenGL using Glut, and I’m a bit lost in the details. First of all, any suggestions or a road map would be more than great.

So far what I am thinking is this:

  1. Tree implementation for transformations.
  2. Simulated dynamics.(*)
  3. Octree implementation for collision detection.
  4. Actual collision detection.(*)
  5. Modelling in Maya and export them as .OBJs.
  6. Polishing the game with GLSL or something like that for graphics quality.

(*): I am not sure the order of these two.

So I started with the simulated dynamics without a tree implementation, and it turned out to be a huge chaos for me. Is there any way you can think of something that could help me to build such a tree to use in racing game?

I thought of something like this but I have no idea how to implement it.

Reds are static, yellows are dynamic nodes
Reds are static, yellows are dynamic nodes

  • 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-06-16T10:22:54+00:00Added an answer on June 16, 2026 at 10:22 am

    I would suggest the exact opposite of @bezad.

    Start with a single car and an infinite road.

    Split the problem of rendering and dynamics into two completely different things. The common Car updates and/or is the link between the CarRenderModel and the CarPhysicsModel.

    What shapes the Car puts into the GL scene is up to the Car.

    Among other things, this means you can have a really simple Car show up on screen, and attach a really simple physics model to it, and either make the Car prettier or make it behave physically better without having to tie the two together. And, ideally, at each stage you have something playable.

    So, a car that is a rectangle, 5 long 3 wide and 1 unit high. A road that is 13 units wide, and goes on forever. A stationary camera. Maybe a horizon. The first physics model is a rocket ship, where every second you push down on an arrow key the car gains x units/second of velocity in that direction. Note that this car doesn’t rotate — it is axis aligned. If the car leaves the road, it explodes, and the “game” ends.

    You now have something on the screen that responds to user input. You could spend time making a fancier car model (wheels, etc), or you could improve the car physics and control model (direction! Angle! Breaking != speeding up!), or you could make the environment more interesting (add black-and-white stripes so you can see velocity at the edge of the road. An off-road portion near the road, and maybe trees that blow up the car), or you could make the camera more interesting (say, it stays behind the car, and looks over its shoulder).

    Now, for dynamics, I’d treat universe-car interaction using distinct code from car-car interaction, just to keep my sanity intact. The car doesn’t get to modify the environment.

    This means you can write a bunch of the car-universe interaction easier than you can the car-car interaction.

    …

    Building an arbitrary tree in C++ is easy.

    #include <vector>
    #include <memory>
    #include <string>
    struct MyTree;
    typedef std::unique_ptr<MyTree> upTree; // punt on memory management!
    struct MyBaseNode;
    typedef std::unique_ptr<MyBaseNode> upNode;
    
    struct MyTree {
      std::vector<upTree> children;
      upNode node;
      MyTree( upNode node_ ):node(std::move(node_)) {}
    private:
    // if C++11 compiler, use these:
      MyTree( MyTree const& ) = delete;
      MyTree& operator=( MyTree const& ) = delete;
    // if C++03, use these:
      // MyTree( MyTree const& ); // no implementation
      // MyTree& operator=( MyTree const& ); // no implementation
    };
    upTree make_tree(upNode node) { return upTree( new MyTree(std::move(node)) ); }
    
    enum EOrder{ eFirst, eMiddle, eLast };
    template<typename Functor>
    void walk_tree( upTree const& tree, Functor f, bool bFirst = true, bool bLast = true) {
      if (!tree) return;
      f( tree, bFirst, bLast );
      for (auto it = tree->children.begin(); it != tree->children.end(); ++it) {
        bool bChildFirst = (it == tree->children.begin());
        bool bChildLast = ((it+1) == tree->children.end());
        walk_tree( *it, f, bChildFirst, bChildLast );
      }
    }
    struct MyBaseNode {
      virtual ~MyBaseNode() {};
      // put things that your tree nodes have to be able to do here
      // as pure virtual functions...
      virtual std::string MyName() const = 0;
    };
    
    struct CarsNode : MyBaseNode {
      // cars node implementation!
      virtual std::string MyName() const /*override*/ { return "I am a bunch of CARS!"; }
    };
    upNode make_cars() { return upNode( new CarsNode() ); }
    
    struct CarNode : MyBaseNode {
      // car node implementation!
      virtual std::string MyName() const /*override*/ { return "I am a CAR!"; }
    };
    upNode make_car() { return upNode( new CarNode() ); }
    
    struct RoadNode : MyBaseNode {
      // car node implementation!
      virtual std::string MyName() const /*override*/ { return "I am a ROAD!"; }
    };
    upNode make_road() { return upNode( new RoadNode() ); }
    
    #include <iostream>
    void tree_printer_func( upTree const& tree, bool bFirst, bool bLast ) {
      if (bFirst) std::cout << "[ ";
      if (tree->node) {
        std::cout << tree->node->MyName().c_str();
      } else {
        std::cout << "nullNode";
      }
      if (bLast) {
        std::cout << " ]\n";
      } else {
        std::cout << ", ";
      }
    }
    int main() {
      upTree root = make_tree(upNode());
      upTree carsTree = make_tree(make_cars());
      carsTree->children.push_back( make_tree( make_car() ) );
      carsTree->children.push_back( make_tree( make_car() ) );
      root->children.push_back( std::move(carsTree) );
      upTree roadTree = make_tree(make_road());
      root->children.push_back( std::move(roadTree) );
      walk_tree( root, tree_printer_func );
    }
    

    the above is pretty rough (I didn’t get end-node handling quite right in the printer, for example), but it demonstrates a non-homogenious, non-leaking, n-ary tree structure in C++.

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

Sidebar

Related Questions

I am in the design stages for building a Car Racing game. Each user
I'm building an ASP.NET MVC 3 site using the code-first Entity Framework 4 approach.
Building my first web app using Yii and wondering if it is best to
I'm building a web app using EF Code First and ASP.NET MVC. I have
building a site using PHP and MySQL that needs to store a lot of
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
Building a search with some custom objects and three scopes: All , Active ,
I am building a Sudoku game for fun, written in Javascript. Everything works fine,
I'm just building the like side of it first. Basically, I just want it
Building a test web service and all was working great, so I added the

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.